From patchwork Thu Jan 25 20:36:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13531691 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 97A23C47422 for ; Thu, 25 Jan 2024 20:37:46 +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=qJ8AcK//lrS7gYZI2YHmK8Ilww5XiSrLL2s7wTBHVcQ=; b=XLgkunh23N1reA hWQQTgrqLNNrkER41oI4lwCRKZ/WquKQbGt69xuDw91H5TYqQ4duCxp9xMeetWIervZ6Y5FZEC1a7 wGCCyXJWCNEPmHs1XMnBmFM/fQKpCvmeQDEJhzUXdgA0K+84WUii/AggPIteqRDzlpQvCuLZKtQSV pjUB/e9OSfGBWcHwxfWZN1C4275bmGD1BDKGZmjuiF4/AGjI12dn2ef+byH6P6LfY4K73Hm5jNN3P NXB3nRxB29flOf8NINy2yIqe3ZtLwjTmAn40OJbHLNqJbHWpZhNjI7sgWRxbyXuV27SUniJvBoxOs ZSodheCFJONNy7PNJpEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT6Tf-00000001oI1-2Oe5; Thu, 25 Jan 2024 20:37:35 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rT6TV-00000001oCT-22oT for linux-arm-kernel@lists.infradead.org; Thu, 25 Jan 2024 20:37:26 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40ed2333c8fso12029075e9.0 for ; Thu, 25 Jan 2024 12:37:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706215043; x=1706819843; darn=lists.infradead.org; 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=jYZjI2Tknpmm3tYZbjPO9Pae0r5NRRsVcbrpdnsJuFs=; b=fLarSp0A0u53SoIRgoPRC+Uzo74w84BCVZoela+TN6OQXH1ZMKqX7sTpaGa4SuKveD Y9Sn4pSHNVbTpazesPyWEEKeDJwBpmZKMY/FeWPTf9UJtGk/EoS+g+aMkNDUA1nhqV3q HspNQWN+1qaj6RZX2lScFQCgfGkvGIpRxpTfYeP2+UVWVyIr8ydyd6yiW8xU8zWY/01T kHpmkYtCVHCTyPlKRr/NznAOfcCre+xJxm9YMlxHGuhlUPPVZ+w2j3eYv85v3Winh6/a MZ6YCIvx1r5ib5Ox6pOfg8XhTkSCEr2Y6mRtli54gmg5E1Sh55Mn2+chzOd81zS/SnQu FzlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706215043; x=1706819843; 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=jYZjI2Tknpmm3tYZbjPO9Pae0r5NRRsVcbrpdnsJuFs=; b=fmWboeUoOFLDsBCo2PIIyQUvEpR/XmgPJ7Wqkxf2fOAcilWc6dF+RBmKYaFtC1q4Wp K//VQzrtTHJKE0dB37e5hpVIJ6smockXT/DEjpUwgbGd4IT94Av64rCSMyVj2m0jmb/1 KNOtswyvXC+tuvdoWfPkfH76koBmVeNFk5QfDRPJrK/aFEBoGFIzLAv9Wjp0xCEZpOVT PPYxgb+TCpFiG82D3eDZFWtmBoCnc9jhniOagp5iwLQnlDorrUbeKtuBntxlE9F546Bv oIWyPFsVN0H3i4GakP4hacDsGoVwhIuFCNevC9o5WtCZ3/LN1TmLY93SwfqocdHEpvU3 Ug1A== X-Gm-Message-State: AOJu0YwIw3x+h7tc/fdq724b9ICnZqtY/Qwfsau9BNZUyriwYniHhJgS IqCJnwj21tOhvEKsnXxxlhLeyd77907+Av38k8QdDVeybZvFgiUn X-Google-Smtp-Source: AGHT+IE8WEhZK1nB9SZJbuut4HrFo2ARoCLSJoqMk6QZTFKuYSRozcLC3U1GRpZjIFCcaLB5kCj+IQ== X-Received: by 2002:a05:600c:2112:b0:40e:4b49:9b0f with SMTP id u18-20020a05600c211200b0040e4b499b0fmr152473wml.239.1706215042819; Thu, 25 Jan 2024 12:37:22 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id j32-20020a05600c1c2000b0040e813f1f31sm3817700wms.25.2024.01.25.12.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 12:37:22 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , William Zhang , Anand Gore , Kursad Oney , Florian Fainelli , =?utf-8?b?UmFmYcWCIE1p?= =?utf-8?b?xYJlY2tp?= , Broadcom internal kernel review list , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Russell King , Jacek Anaszewski , =?utf-8?q?Fern=C3=A1ndez_Roj?= =?utf-8?q?as?= , Sven Schwermer , Christian Marangi , 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: [net-next PATCH v10 3/5] net: phy: add support for PHY LEDs polarity modes Date: Thu, 25 Jan 2024 21:36:59 +0100 Message-ID: <20240125203702.4552-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240125203702.4552-1-ansuelsmth@gmail.com> References: <20240125203702.4552-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240125_123725_618531_96279C3F X-CRM114-Status: GOOD ( 19.48 ) 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 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. Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- Changes v10: - Add Review tag Changes v9: - Make LED probe fail if modes asked but not supported - Fix wrong function description Changes v5: - Rework to LED modes bitmap Changes v4: - Drop for global active-low - Rework to polarity option (for marvell10g series support) Changes v3: - Out of RFC Changes v2: - Add this patch drivers/net/phy/phy_device.c | 16 ++++++++++++++++ include/linux/phy.h | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 3611ea64875e..dd778c7fde1d 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3097,6 +3097,7 @@ 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; @@ -3114,6 +3115,21 @@ static int of_phy_led(struct phy_device *phydev, if (index > U8_MAX) return -EINVAL; + if (of_property_read_bool(led, "active-low")) + set_bit(PHY_LED_ACTIVE_LOW, &modes); + if (of_property_read_bool(led, "inactive-high-impedance")) + set_bit(PHY_LED_INACTIVE_HIGH_IMPEDANCE, &modes); + + if (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; if (phydev->drv->led_brightness_set) cdev->brightness_set_blocking = phy_led_set_brightness; diff --git a/include/linux/phy.h b/include/linux/phy.h index 684efaeca07c..c9994a59ca2e 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -852,6 +852,15 @@ struct phy_plca_status { bool pst; }; +/* Modes for PHY LED configuration */ +enum phy_led_modes { + PHY_LED_ACTIVE_LOW = 0, + PHY_LED_INACTIVE_HIGH_IMPEDANCE = 1, + + /* keep it last */ + __PHY_LED_MODES_NUM, +}; + /** * struct phy_led: An LED driven by the PHY * @@ -1145,6 +1154,19 @@ struct phy_driver { int (*led_hw_control_get)(struct phy_device *dev, u8 index, unsigned long *rules); + /** + * @led_polarity_set: Set the LED polarity modes + * @dev: PHY device which has the LED + * @index: Which LED of the PHY device + * @modes: bitmap of LED polarity modes + * + * Configure LED with all the required polarity modes in @modes + * to make it correctly turn ON or OFF. + * + * Returns 0, or an error code. + */ + int (*led_polarity_set)(struct phy_device *dev, int index, + unsigned long modes); }; #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \ struct phy_driver, mdiodrv)