From mboxrd@z Thu Jan 1 00:00:00 1970 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 88FF1C25B10 for ; Fri, 10 May 2024 23:15:16 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RUdy0lkEgspONONQ+iIK2S+tcAgbfk8K0bNCzPzzdJM=; b=OC+7qio60DbvZj Vs+Dk0UF4gIHo5uZi+KpAS+tEfqAd9qNefwTmTXTialS7Mf2oRM8sxZFo/A2SCRX7BTJ1BrgLJtsw 5QQSdRjotKwNOw/CwA3Yhurm/Hx7vD3VB4ahAHLWJ0EnmW29svmxOVkjbcf5W3arSCB67QjevD+KV TJWcYO4Agoj42f+GJhyDe5k4Gm7aWnXVjRUJwNnXq0AlRZPYJbGFAHvgAZT8fvE41r5MXBA3rnj2p Gxd2f0s7akWTzz3KtrqtjdwNnuzY4i0c0nZT1Vzt0KVXJr8mCtBe/wyZom2plBfrOnuF9NQDk/Cdr ZzhYRJfeXKkathSPlpPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s5ZS2-00000006jiY-0GEb; Fri, 10 May 2024 23:14:54 +0000 Received: from pidgin.makrotopia.org ([2a07:2ec0:3002::65]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s5ZRy-00000006jhL-3Gyb for linux-arm-kernel@lists.infradead.org; Fri, 10 May 2024 23:14:52 +0000 Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.97.1) (envelope-from ) id 1s5ZRe-000000000Jm-01WF; Fri, 10 May 2024 23:14:30 +0000 Date: Sat, 11 May 2024 00:14:25 +0100 From: Daniel Golle To: Christian Marangi Cc: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , William Zhang , Anand Gore , Kursad Oney , Florian Fainelli , =?utf-8?B?UmFmYcWCIE1pxYJlY2tp?= , Broadcom internal kernel review list , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Russell King , Jacek Anaszewski , =?iso-8859-1?Q?Fern=E1ndez?= Rojas , Sven Schwermer , 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 Message-ID: References: <20240125203702.4552-1-ansuelsmth@gmail.com> <20240125203702.4552-4-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240125203702.4552-4-ansuelsmth@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240510_161450_890953_D94C5ADC X-CRM114-Status: GOOD ( 26.37 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; }; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel