From patchwork Tue Jan 2 18:38:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13509268 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 F0E8CC4707B for ; Tue, 2 Jan 2024 18:39:37 +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=SUC2xeJz0yBha7c6fhzb3/xhtq+YEeEgFk4iMm+SRmg=; b=HqiEpCj69e68ut f45Q7Zcbatw+m+cZ78rHeDG3n7bHJUVzvFeL+T7LjRpFZ9Z0GZt4zsfKqL8diH7TJhGp3U5zoyptn UJMPjbyz0/YcjT3CPGGz/PLPvFeU0SswmgVfI7xdL9r1/q3T6quyXjd6q1+5Hk0ISgISsxf4VZDZ9 edlpRCwT3siFUGX/BKMzwki6QM/FgooVDRiTX2Q3ktRGfzRBnyxdFUS5fIxw4Wt/A3WBWQ3oy8KER t2rjEvwtvojax2gLsmzd2RPNbsdjk0gtoJBpyjm5e1/HgklMoPXN5GXZLN4Zp28WDyO4RIZWc8SCD T0A5yGYQJmxY+a1ByLyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rKjfS-008jeZ-0v; Tue, 02 Jan 2024 18:39:10 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rKjfM-008jWd-27 for linux-arm-kernel@lists.infradead.org; Tue, 02 Jan 2024 18:39:06 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40d3c4bfe45so102786645e9.1 for ; Tue, 02 Jan 2024 10:38:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704220737; x=1704825537; 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=fQabVWmpmoZU8yQyfqwraJ/6CaCvr56KIOoajwAPETc=; b=MGWNtbQ+VSpBNVGVQRiSBruHdxsnwk/3pxhEVEEiMwKYgzv1WXI+HDWJ9ttiv2z8Id 5OcNW4TOzMLXjwyIgg8cTG8mt2VuU1u05IB+Uf6H/9/xCGciKnT+2wc9PhgOjw9oBfyD ylk2tTvmA+ouWuepONsEZmF6dwVFfIZeE+KCfpL8VMZnjMG4PB6x9UgNuE4siJ+8TdmK Y7iNepPK/g/45m0XAq/1AC8jw9g5zjD+mi5jbkOZadoHnnJLRQJXF+HT8etDTJq94iW7 2aJP4e8RbiMr4v5PbNkfAMs2P9mvA3Oi6rNm16NFwop5/gpb5HJs7lUBdLvwRcyBm2UR 3GyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704220737; x=1704825537; 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=fQabVWmpmoZU8yQyfqwraJ/6CaCvr56KIOoajwAPETc=; b=fbi5vi5vi8UHWkVqaSOG3qZUoF5gL8YEDgvuMH6GBWLpbW7C0GdK4jNornkMt+i8BN CgCHGux9ZBcKb0zYcDzg1OLBVk5zc8BUl2BKIH5Z7snoYp3n1OyxrRkrPcMdwY8Whqqq wyx/fEG+hYGtN2i6rv/GpZKiB8TPhbPDCLWk+iKP9oASTxFkQBKo9grSRp/regSWMqoY 2PykR63ZQ0n2r2fuP4hTpzOTR5BWit7HQv8chCRHyWs9Pqjv95hK4sAxEl4CTDZgWY81 geqHYyoJmH82ShkLTD7esebPcSvwPWZancU/pLqfBxSeDXJvp3sFx/U0d/5wgx7BHCjl XlBQ== X-Gm-Message-State: AOJu0YybF7XcJ647CoAubKsIBCmht7q6RbA1+RpV2t7YZ9D6rg3t9vPv 6H73+V9P6/V2/LYoc+lmsf0= X-Google-Smtp-Source: AGHT+IGQC9+CQvDnBiBdOXBnI5j7MRwisqOyk1s/BOS7UyEMNf8U0uxdScgydq6ztUjR6kyzFqMFfw== X-Received: by 2002:a05:600c:2201:b0:40d:35c9:7b6b with SMTP id z1-20020a05600c220100b0040d35c97b6bmr5341006wml.234.1704220736651; Tue, 02 Jan 2024 10:38:56 -0800 (PST) Received: from localhost.localdomain (host-87-10-250-100.retail.telecomitalia.it. [87.10.250.100]) by smtp.googlemail.com with ESMTPSA id p15-20020a05600c468f00b0040d4e1393dcsm37963071wmo.20.2024.01.02.10.38.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 10:38:56 -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 v6 3/5] net: phy: add support for PHY LEDs polarity modes Date: Tue, 2 Jan 2024 19:38:32 +0100 Message-ID: <20240102183835.5332-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240102183835.5332-1-ansuelsmth@gmail.com> References: <20240102183835.5332-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240102_103904_796759_4DFAF576 X-CRM114-Status: GOOD ( 19.92 ) 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 --- 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 | 12 ++++++++++++ include/linux/phy.h | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 1e595762afea..437a1c6046ab 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3152,6 +3152,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; @@ -3169,6 +3170,17 @@ static int of_phy_led(struct phy_device *phydev, if (index > U8_MAX) return -EINVAL; + if (phydev->drv->led_polarity_set) { + 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); + + 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 ac22b8e28a85..da0a15a6d638 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -860,6 +860,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 * @@ -1153,6 +1162,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 if active low + * @dev: PHY device which has the LED + * @index: Which LED of the PHY device or -1 + * @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)