Linux-LEDs Archive mirror
 help / color / mirror / Atom feed
From: Daniel Golle <daniel@makrotopia.org>
To: Christian Marangi <ansuelsmth@gmail.com>
Cc: "Pavel Machek" <pavel@ucw.cz>, "Lee Jones" <lee@kernel.org>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"William Zhang" <william.zhang@broadcom.com>,
	"Anand Gore" <anand.gore@broadcom.com>,
	"Kursad Oney" <kursad.oney@broadcom.com>,
	"Florian Fainelli" <florian.fainelli@broadcom.com>,
	"Rafał Miłecki" <rafal@milecki.pl>,
	"Broadcom internal kernel review list"
	<bcm-kernel-feedback-list@broadcom.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>, "Andrew Lunn" <andrew@lunn.ch>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Jacek Anaszewski" <jacek.anaszewski@gmail.com>,
	"Fernández Rojas" <noltari@gmail.com>,
	"Sven Schwermer" <sven.schwermer@disruptive-technologies.com>,
	linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org
Subject: Re: [net-next PATCH v10 3/5] net: phy: add support for PHY LEDs polarity modes
Date: Sat, 11 May 2024 00:14:25 +0100	[thread overview]
Message-ID: <Zj6qURAmoED2QywF@makrotopia.org> (raw)
In-Reply-To: <20240125203702.4552-4-ansuelsmth@gmail.com>

Hi Christian,
Hi Andrew,

On Thu, Jan 25, 2024 at 09:36:59PM +0100, Christian Marangi wrote:
> Add support for PHY LEDs polarity modes. Some PHY require LED to be set
> to active low to be turned ON. Adds support for this by declaring
> active-low property in DT.
> 
> PHY driver needs to declare .led_polarity_set() to configure LED
> polarity modes. Function will pass the index with the LED index and a
> bitmap with all the required modes to set.
> 
> Current supported modes are:
> - active-low with the flag PHY_LED_ACTIVE_LOW. LED is set to active-low
>   to turn it ON.
> - inactive-high-impedance with the flag PHY_LED_INACTIVE_HIGH_IMPEDANCE.
>   LED is set to high impedance to turn it OFF.

Wanting to make use of this I noticed that polarity settings are only
applied once in of_phy_led(), which is not sufficient for my use-case:

I'm writing a LED driver for Aquantia PHYs and those PHYs reset the
polarity mode every time a PHY reset is triggered.

I ended up writing the patch below, but I'm not sure if phy_init_hw
should take care of this or if the polarity modes should be stored in
memory allocated by the PHY driver and re-applied by the driver after
reset (eg. in .config_init). Kinda depends on taste and on how common
this behavior is in practise, so I thought the best is to reach out to
discuss.

Let me know what you think.

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 616bd7ba46cb..1624884fd627 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1251,6 +1251,7 @@ static int phy_poll_reset(struct phy_device *phydev)
 int phy_init_hw(struct phy_device *phydev)
 {
 	int ret = 0;
+	struct phy_led *phyled;
 
 	/* Deassert the reset signal */
 	phy_device_reset(phydev, 0);
@@ -1285,6 +1286,17 @@ int phy_init_hw(struct phy_device *phydev)
 			return ret;
 	}
 
+	if (phydev->drv->led_polarity_set) {
+		list_for_each_entry(phyled, &phydev->leds, list) {
+			if (!phyled->polarity_modes)
+				continue;
+
+			ret = phydev->drv->led_polarity_set(phydev, phyled->index, phyled->polarity_modes);
+			if (ret)
+				return ret;
+		}
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL(phy_init_hw);
@@ -3316,7 +3328,6 @@ static int of_phy_led(struct phy_device *phydev,
 	struct device *dev = &phydev->mdio.dev;
 	struct led_init_data init_data = {};
 	struct led_classdev *cdev;
-	unsigned long modes = 0;
 	struct phy_led *phyled;
 	u32 index;
 	int err;
@@ -3335,18 +3346,14 @@ static int of_phy_led(struct phy_device *phydev,
 		return -EINVAL;
 
 	if (of_property_read_bool(led, "active-low"))
-		set_bit(PHY_LED_ACTIVE_LOW, &modes);
+		set_bit(PHY_LED_ACTIVE_LOW, &phyled->polarity_modes);
 	if (of_property_read_bool(led, "inactive-high-impedance"))
-		set_bit(PHY_LED_INACTIVE_HIGH_IMPEDANCE, &modes);
+		set_bit(PHY_LED_INACTIVE_HIGH_IMPEDANCE, &phyled->polarity_modes);
 
-	if (modes) {
+	if (phyled->polarity_modes) {
 		/* Return error if asked to set polarity modes but not supported */
 		if (!phydev->drv->led_polarity_set)
 			return -EINVAL;
-
-		err = phydev->drv->led_polarity_set(phydev, index, modes);
-		if (err)
-			return err;
 	}
 
 	phyled->index = index;
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 3ddfe7fe781a..7c8bd72e6fee 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -888,6 +888,7 @@ struct phy_led {
 	struct list_head list;
 	struct phy_device *phydev;
 	struct led_classdev led_cdev;
+	unsigned long polarity_modes;
 	u8 index;
 };
 

  reply	other threads:[~2024-05-10 23:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-25 20:36 [net-next PATCH v10 0/5] net: phy: generic polarity + LED support for qca808x Christian Marangi
2024-01-25 20:36 ` [net-next PATCH v10 1/5] dt-bindings: net: phy: Make LED active-low property common Christian Marangi
2024-01-25 20:36 ` [net-next PATCH v10 2/5] dt-bindings: net: phy: Document LED inactive high impedance mode Christian Marangi
2024-01-25 20:36 ` [net-next PATCH v10 3/5] net: phy: add support for PHY LEDs polarity modes Christian Marangi
2024-05-10 23:14   ` Daniel Golle [this message]
2024-05-10 23:58     ` Andrew Lunn
2024-05-11  9:35       ` Russell King (Oracle)
2024-01-25 20:37 ` [net-next PATCH v10 4/5] dt-bindings: net: Document QCA808x PHYs Christian Marangi
2024-01-25 20:37 ` [net-next PATCH v10 5/5] net: phy: at803x: add LED support for qca808x Christian Marangi
2024-01-27  5:10 ` [net-next PATCH v10 0/5] net: phy: generic polarity + " patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zj6qURAmoED2QywF@makrotopia.org \
    --to=daniel@makrotopia.org \
    --cc=anand.gore@broadcom.com \
    --cc=andrew@lunn.ch \
    --cc=ansuelsmth@gmail.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=hkallweit1@gmail.com \
    --cc=jacek.anaszewski@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuba@kernel.org \
    --cc=kursad.oney@broadcom.com \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=noltari@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=pavel@ucw.cz \
    --cc=rafal@milecki.pl \
    --cc=robh+dt@kernel.org \
    --cc=sven.schwermer@disruptive-technologies.com \
    --cc=william.zhang@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).