Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp807099lqo; Fri, 10 May 2024 16:15:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXGQ/ABajA4PXwpV7MWHVniNb+bEEONBWm3v2L5IQhLYbF4s75B7S+he6AZsC6c2+xsv5SMkwGAPGOAkLCw77gTYaLJDq1FSJWUNkuWEg== X-Google-Smtp-Source: AGHT+IGvC2urHaohIG+iO76pCsgllTi/Fgjy3eGpgCdEYBS81wc/lHNrlWd2hKlUpe5xrHoFtgqF X-Received: by 2002:a17:906:370c:b0:a59:b730:59d7 with SMTP id a640c23a62f3a-a5a2d55aee2mr273222966b.25.1715382905623; Fri, 10 May 2024 16:15:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715382905; cv=pass; d=google.com; s=arc-20160816; b=PuvkEPlZL4iC4BEUjzigM6reML9dmK1FaK0iyAiLLt8D4pixSBtek+igOmTEF/Q8u1 5/mmLxvw+ucQaIvXtAwhImncAa2tGiWdBYBZ9xfBepuYJVXj8ZHxJOHcLW6lfHd24BWp R1omf2bx9fzcWp/c6quOucWh3kFIbDsYvw7tmUvbZrGOCMU5vOptpQnuNLeE9ck13JzL SDBUJDJdAX72oMf2Gv0qiqP73IMadGsNxxsFRqT5DnEsYiCZPX8tUug9aDROwYwQm42x 6LAqzLVBfA5w09zynGCWdzQwMpHN2LZ3Civz0+NlzQpjaW7+NJX+dCy1iFo3Va5Hzq/T yo3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=Hnykkl55+GOD7Ggxy2HtvIuE4OYXMYpYynxaOk1Rr5E=; fh=FWK3nvrgtfLI2Dn9gMmO3v/QNvvY0aC7DfxxhVHMMG0=; b=W19BSWlixR9iRdQ6FB529yVk2hwKldNey5rVOx5VVfa1IxgweOB7SLF3V/tsr4pnfE KPYWLZVTGcOLFLD/5Qm8xuRM7Aq3vSnNec5t1BIlAP9YarRda+y8bDQyTmzVOsE0f64e NaGx5TnI/5kjubYIim1QozOSUrJRJLUqw+vSuAmmf6mdV6vBdJ4uLpchfopnKK6xxBOo KuJnWyeiKVxjSp7HCJB6B5TrSg0DTSe4jDf6pmTW3h8fg492xtxwxZV1P86ALiRCX8v3 UGc/7FqxzWrNsmouJninF/IH4ZBnK6tMndPxmc9THURHuMmNRTUIWpWaCIys3KVpFJac 8COA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-176282-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176282-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17be6cf8si230307466b.814.2024.05.10.16.15.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 16:15:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176282-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-176282-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176282-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5D8421F2334C for ; Fri, 10 May 2024 23:15:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F3C817556F; Fri, 10 May 2024 23:14:53 +0000 (UTC) Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D10B013D24E; Fri, 10 May 2024 23:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715382892; cv=none; b=SmR32djcgS4atCqo9PyNvVYr9tiNQL7+HhbUg+Ba8lmZeJWKzoRj3AWGlo/ULbOLz2M/5n2Ul36fCEtpJRdBhmUqTPbKn9QgMrYFysjl+5WWQ/it39Ayg0YOBJlU6uB3J2FgHjtDqya35WxEDjWxPpmW7MTAT9cPUMfPVBlF8ik= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715382892; c=relaxed/simple; bh=Pc7GFzBDdxx+C5kRi7y59nePkuWmI3j6CE75W4o17Oc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dho7QYYybktbZ+sbFPzu5q3DizBl1Ub1jVBCIfqwofoODPoP8yb5dTxWj+M/tUKYrWVATu+aQGVhWrYBc9UDWjiXmnWELTwajmz48K4GdL5qaBCydnFMWCZzppLdh0yU+Q/L48GVjl0tivcYe1AVTO26aAC0gkji6DVPTAbAIPc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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; };