From patchwork Thu Jan 4 11:01:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 184975 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5537807dyb; Thu, 4 Jan 2024 03:03:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZlQXQbyfMspH8fbIeM6ekz+2QAKXrqoEbA4OwdQRQh8EkfKAkIgypCEfwuftXjNWN2CUi X-Received: by 2002:a05:6808:1813:b0:3bb:c774:565e with SMTP id bh19-20020a056808181300b003bbc774565emr510716oib.24.1704366186542; Thu, 04 Jan 2024 03:03:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704366186; cv=none; d=google.com; s=arc-20160816; b=z5L9C5tu+2BmmKVoUzp8hs/7vjgpc/pg54RVEQrsg66YENJ998drfo3J5S8tIJ80EA gE9V9rbZBZ7Dm5VrjsIVBBzhJ0JLGYGBifx7pLsIZf5TM2tf7dkzc6xCMOwI4uk9Ofua bN6tx+wJgHKhjqy+oH404RMKTW+hsIBc+M1aRikapdXJjdddVcHJ5WpcySypTzeUoEmS Da9mKQZaQDbxx1A3dYPWUNxVslKK6gvZGXZMzphhWpxmQMpWPcAcKEAsOzmAppPeTxnT owDmEWokAml4iYOQLCCH4tlchbskqLdfCcxUDrPjSd5GIOeCIq2V1Zj1pp5TCo17jlpy Wwbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=fQabVWmpmoZU8yQyfqwraJ/6CaCvr56KIOoajwAPETc=; fh=t/rEUYZBrjIVtJtvItkK7O2t2zLyO6TH9UCXgO6Lsag=; b=0mnyu3Edlq/BtGrrwPUvcWiafSGG80IqFC17bKhYl09jQtrRAljqiFMwSj+XAMFjjh WKUC/jXfAq4ruoyvKog6rxaKU9AcalAV6Hmv8dGsKoRTLvetXk4TU/2OUAE2cdiAd78M qGpaYvp4yuP1A6aqBwPTIqF61ZHrH7LVx7vLapgsPgIKc46Z9FXsWNPqBasOwB+w0vmY 4BX1SVlE3bKk5Vp+eZMKHeKTYBwMnIzdFhm1Hk1zgQ4UU+aqP+NDHEWL1MYJaSUz6Qc7 DkNFGFqBcksM+l4K6q/tD90ltlFXBF0Uh5AD1imUnJkq+0390RgGGgxC/csDZ67mzm/e nZYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nCcQCLfY; spf=pass (google.com: domain of linux-kernel+bounces-16553-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16553-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id fq11-20020a056214258b00b0068029869c22si23123804qvb.539.2024.01.04.03.03.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 03:03:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16553-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nCcQCLfY; spf=pass (google.com: domain of linux-kernel+bounces-16553-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16553-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 41BB91C2136E for ; Thu, 4 Jan 2024 11:03:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BE0AD2230C; Thu, 4 Jan 2024 11:01:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nCcQCLfY" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90CC2219EE; Thu, 4 Jan 2024 11:01:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-40d3352b525so3396795e9.1; Thu, 04 Jan 2024 03:01:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704366092; x=1704970892; darn=vger.kernel.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=nCcQCLfY4FhcUI6ECGIhK8qyK1dmtsM1q4cuwUAz3TOP+lZZzQKIU1CGmmtLHPSyGk WLbhfpOD37UPmrvcN2QoXL3oq78o5cfseQ4bRNR55liSzLGdaTVUFVbQ5EPv1D3cGSFo nN0DBrx5YMCxq78Dsw//JJyj+S2mIR6fuCoymfts9evj8MXvJQKGdOrpo7Owqu+/gAZc 8+PX+zsaHYSqVTXi5YOaNeFuFTW3MPnfS1V9P+oFVOSoAO8or4YU+FaeWOvCrz2i4S2C 5y+ArPWsL07WsyvpIR+SyuvBjiHyoCLB/2jnbyC2FfEMSOZbCUOazm/xn10o4uTiBmsD hqMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704366092; x=1704970892; 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=KmMi0sAuKHJT9NPoeOcn6B1+u6E68o333ENFsuLzDULsUUbbbvK95YSOrl7iW4eiCY uYjWNgwzA166urUzbX4kinpchfMjVrZ479vEeZblsF5OvhIABvfwyzZ3B7uRILpWxcl5 WTRmMHuXX7vfZVN4TDU8d1D5yplUqS/pNDImJ25ZGv2fi9ZgUWl9YHRBLQ6wDjddS5bm aGRhut1yOlg4L/6WvD6FoOjQw5QcfjZywOOKTucQso2TW+4evgOqsgtIJ/aU4CdMoOZc iMnBeZNdFia54QnLNkWVmaGP7YROIwc4EySjZpa2eIdAyhr1rZ+6U7sVEh+q1zhV2wbi /pPQ== X-Gm-Message-State: AOJu0YxwCPAWd7jWkLQApv9J1VVv8G8/k/QV3Eo+CU5tCWNk5L2GHo9K cXhxqAU8bdlUBt908W/nrh8= X-Received: by 2002:a7b:cbc2:0:b0:40c:692e:2576 with SMTP id n2-20020a7bcbc2000000b0040c692e2576mr226262wmi.136.1704366091542; Thu, 04 Jan 2024 03:01:31 -0800 (PST) Received: from localhost.localdomain (host-80-116-159-187.retail.telecomitalia.it. [80.116.159.187]) by smtp.googlemail.com with ESMTPSA id b14-20020adff90e000000b003373fe3d345sm9550242wrr.65.2024.01.04.03.01.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 03:01:31 -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 v8 3/5] net: phy: add support for PHY LEDs polarity modes Date: Thu, 4 Jan 2024 12:01:10 +0100 Message-ID: <20240104110114.2020-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240104110114.2020-1-ansuelsmth@gmail.com> References: <20240104110114.2020-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787157478538187228 X-GMAIL-MSGID: 1787157478538187228 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)