From patchwork Fri Mar 17 02:31:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13178510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50A75C74A5B for ; Fri, 17 Mar 2023 03:46:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kHibAF1RH30lnR62e1KppwO8nO/Gg/QIJnbJwHIOz50=; b=eqg9pr7BUeO0f5 I2ze5sxntxmqeAyIj82v2BLCQ7pEdphRxmms/L4KO70N/4E/w9XARHeve2fzVLd7kunZRWn3WhIX9 o0t3TJQF+pt+6uK6VTX6p4HvxstD0jrrnnCz3SGG5TXltGvQDsZxEqtuWGDHFQn/VwWW3+ld/RZrA guJry0+Mcr6CN3sUBk3f2KSYWAFUSUeY7GlbAHTyonCmgl9kD4qqfer7u7NT4L4s3gIv+CJzIAARe kAqIJF2eB9gR8L3Tb94cL0JV0tLs5J4BdUDXn0TYG0tJsjgTC9t/eV3kBTZNcS0U3bVNNvtNVMtvx 98o+XfvWEitd9Ib/KcKQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pd12n-000q94-0a; Fri, 17 Mar 2023 03:46:17 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pczuU-000f4I-0T for linux-arm-kernel@lists.infradead.org; Fri, 17 Mar 2023 02:33:42 +0000 Received: by mail-wm1-x32c.google.com with SMTP id m35so2458153wms.4 for ; Thu, 16 Mar 2023 19:33:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679020405; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=VM3DoNMLu3F/k6wPO3qYiXVgdAsBr9H+lF3WwRw8JHY=; b=GI3I0nTOe0aBeLI0l3/lUpIAY7Pet947XD0nFynMbOz6OX8jfYop8gvJZHiLq1O3Xo rcHANTn9UTVOALoTXuXcKBprhvxFjsmTK3W72xmyTFGPfERQj6rg2Fz7N1I3iCG8a30e Gyz0o2jBWMN4XUnPY0qsSFkk8CogUxAZsdiIrl9ObI0TVov2j2i6l37Ftwtnjdl2s9ei 6n/MEl+U4oEGOoygSea+KB9B9/7ccQYCNDBI5eXRQLyi1nPxMZ3voYJLEJnyrszEXhFX fHmHGKqsc4SM8MJo2Eu659xoog8RDZ+D5EuQ8mW+nSqjIORg/cbzza7H+xNx3Z0R+GR8 KcTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679020405; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VM3DoNMLu3F/k6wPO3qYiXVgdAsBr9H+lF3WwRw8JHY=; b=kBvRXjK0yFxotM17/rY995ls80tvi3HpD/gZQkGM+uv3ebLBUmGW4djK3LwFUn05ZR 38aKSWSQ3wsSbOBRLIa0MLX/sLAkCct07qGR87YbF+kcApdDcsI7HhwqcCdW6M8qrtnV dF66YL4D9tD02JQ2nvEhcUpXM0ZGzt48jjodULvhmLYm0LY66gMvOTqye36ul6IdKqLw d0uhG2n1dg8cdhhD6my3N0xhotwnZprVaOdr3j3aA8Ge9J0TTjQvURDl23EuBjGMzBuo RLceP+t0eUuP2FiOC+U0ZbYnhP3Ke7/FkmrvirmOvGfoLXhX4Xeq3Y4baX6eOv3774ji Dykw== X-Gm-Message-State: AO0yUKXuB0WlwPXJ1fZmdnF4P+j3INOWMlCstaCsQjbrppvHl1Pkb+dt 3mKtHPWKlF8JJNUhBDYxE/Y= X-Google-Smtp-Source: AK7set8En2UX5kQiJ8dea62WOoksLYAyaSxUNMq66Q16vu1obaE5O124QZhmeoMBq8MFnUSQ1UeOsw== X-Received: by 2002:a1c:f701:0:b0:3ed:809b:79ac with SMTP id v1-20020a1cf701000000b003ed809b79acmr405573wmh.19.1679020405234; Thu, 16 Mar 2023 19:33:25 -0700 (PDT) Received: from localhost.localdomain (93-34-89-197.ip49.fastwebnet.it. [93.34.89.197]) by smtp.googlemail.com with ESMTPSA id z15-20020a5d44cf000000b002ce9f0e4a8fsm782313wrr.84.2023.03.16.19.33.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 19:33:24 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Heiner Kallweit , Russell King , Gregory Clement , Sebastian Hesselbarth , Andy Gross , Bjorn Andersson , Konrad Dybcio , Christian Marangi , John Crispin , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, Lee Jones , linux-leds@vger.kernel.org Subject: [net-next PATCH v4 04/14] net: phy: Add a binding for PHY LEDs Date: Fri, 17 Mar 2023 03:31:15 +0100 Message-Id: <20230317023125.486-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230317023125.486-1-ansuelsmth@gmail.com> References: <20230317023125.486-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230316_193338_211135_65A906A0 X-CRM114-Status: GOOD ( 23.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Andrew Lunn Define common binding parsing for all PHY drivers with LEDs using phylib. Parse the DT as part of the phy_probe and add LEDs to the linux LED class infrastructure. For the moment, provide a dummy brightness function, which will later be replaced with a call into the PHY driver. Signed-off-by: Andrew Lunn Signed-off-by: Christian Marangi --- drivers/net/phy/Kconfig | 1 + drivers/net/phy/phy_device.c | 75 ++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 16 ++++++++ 3 files changed, 92 insertions(+) diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index f5df2edc94a5..666efa6b1c8e 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -16,6 +16,7 @@ config PHYLINK menuconfig PHYLIB tristate "PHY Device support and infrastructure" depends on NETDEVICES + depends on LEDS_CLASS select MDIO_DEVICE select MDIO_DEVRES help diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 9ba8f973f26f..ee800f93c8c3 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -19,10 +19,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -658,6 +660,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, device_initialize(&mdiodev->dev); dev->state = PHY_DOWN; + INIT_LIST_HEAD(&dev->leds); mutex_init(&dev->lock); INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); @@ -2964,6 +2967,73 @@ static bool phy_drv_supports_irq(struct phy_driver *phydrv) return phydrv->config_intr && phydrv->handle_interrupt; } +/* Dummy implementation until calls into PHY driver are added */ +static int phy_led_set_brightness(struct led_classdev *led_cdev, + enum led_brightness value) +{ + return 0; +} + +static int of_phy_led(struct phy_device *phydev, + struct device_node *led) +{ + struct device *dev = &phydev->mdio.dev; + struct led_init_data init_data = {}; + struct led_classdev *cdev; + struct phy_led *phyled; + int err; + + phyled = devm_kzalloc(dev, sizeof(*phyled), GFP_KERNEL); + if (!phyled) + return -ENOMEM; + + cdev = &phyled->led_cdev; + + err = of_property_read_u32(led, "reg", &phyled->index); + if (err) + return err; + + cdev->brightness_set_blocking = phy_led_set_brightness; + cdev->max_brightness = 1; + init_data.devicename = dev_name(&phydev->mdio.dev); + init_data.fwnode = of_fwnode_handle(led); + + err = devm_led_classdev_register_ext(dev, cdev, &init_data); + if (err) + return err; + + list_add(&phyled->list, &phydev->leds); + + return 0; +} + +static int of_phy_leds(struct phy_device *phydev) +{ + struct device_node *node = phydev->mdio.dev.of_node; + struct device_node *leds, *led; + int err; + + if (!IS_ENABLED(CONFIG_OF_MDIO)) + return 0; + + if (!node) + return 0; + + leds = of_get_child_by_name(node, "leds"); + if (!leds) + return 0; + + for_each_available_child_of_node(leds, led) { + err = of_phy_led(phydev, led); + if (err) { + of_node_put(led); + return err; + } + } + + return 0; +} + /** * fwnode_mdio_find_device - Given a fwnode, find the mdio_device * @fwnode: pointer to the mdio_device's fwnode @@ -3142,6 +3212,11 @@ static int phy_probe(struct device *dev) /* Set the state to READY by default */ phydev->state = PHY_READY; + /* Get the LEDs from the device tree, and instantiate standard + * LEDs for them. + */ + err = of_phy_leds(phydev); + out: /* Assert the reset signal */ if (err) diff --git a/include/linux/phy.h b/include/linux/phy.h index fbeba4fee8d4..88a77ff60be9 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -595,6 +596,7 @@ struct macsec_ops; * @phy_num_led_triggers: Number of triggers in @phy_led_triggers * @led_link_trigger: LED trigger for link up/down * @last_triggered: last LED trigger for link speed + * @leds: list of PHY LED structures * @master_slave_set: User requested master/slave configuration * @master_slave_get: Current master/slave advertisement * @master_slave_state: Current master/slave configuration @@ -690,6 +692,7 @@ struct phy_device { struct phy_led_trigger *led_link_trigger; #endif + struct list_head leds; /* * Interrupt number for this PHY @@ -825,6 +828,19 @@ struct phy_plca_status { bool pst; }; +/** + * struct phy_led: An LED driven by the PHY + * + * @list: List of LEDs + * @led_cdev: Standard LED class structure + * @index: Number of the LED + */ +struct phy_led { + struct list_head list; + struct led_classdev led_cdev; + u32 index; +}; + /** * struct phy_driver - Driver structure for a particular PHY type *