From patchwork Wed Dec 27 09:02:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 183441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1320085dyb; Wed, 27 Dec 2023 01:04:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxvly+QAv33pDTwJUuzyQaobiwCbcQ63Ds6DPGx4LRHNrvoG2fii1wLK1eQ9eIJNYkT45t X-Received: by 2002:a05:6a00:2354:b0:6d9:c204:51cf with SMTP id j20-20020a056a00235400b006d9c20451cfmr1445699pfj.12.1703667865572; Wed, 27 Dec 2023 01:04:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703667865; cv=none; d=google.com; s=arc-20160816; b=J9FUQyDlrLjnhOEhru/cuJzv7ctseN2LJ32jV8opZW2v54uS15ZhKW49QUzeVtjsiY WRfvZnKbXfdCi5vK0KtW5hLs3DeWXHKLRpQnrEvwDnZJDdHVhdIdIg7y8DDoRlqkK652 x1tWCRPDVRDVid16wvMlMoWXm1OqyXX0jol+qXmx4/d6IPyPjxD6STeqxYYFx+ozK0wt I3SMf9iYMaOgBU6OuBD7jRn1HSjtTOopBZ2FcvHFmWGOzC42/1vy544Yeoa05LpVr2lm +qcVINlMiKD0vh6MQvPyNAK9jCRyRZowmc/XdZwPaSXSnup9V8yppUQvIuFoerh6SqRr Baqw== 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=RraVKdn/3CtUzdc/GUkx4wIWX/WntChO7vtqlU3szKo=; fh=t/rEUYZBrjIVtJtvItkK7O2t2zLyO6TH9UCXgO6Lsag=; b=gOu9g5lMpw3BY0q29m8tVZg9Rhg9y/q9fnduC7RURkoKrEjlMaMdJgiyCvnZzbs72j CbUPel2rt71qOTyIHt0i1gQ85i3TlBtE3c5jmizHzaYsXJ+fehu4md18fQY43EJjj4yU 7dJABzYXgO5oDWD1F6wxYTvHYWLWLW8Y0tqlC+jP/YDxfgf8m00xMJYCLF1PK96ngTug hChHjV7PRlVdYcL2MvmkK01Ey3aXCMPa13ecvclI5dlwj0Gdl4SiOk3VYUjztXaYz3IJ jQ9d2Bg3VOD83ZjvbmlsRhXMPhSsFkJJAt1pK6w0PGdGm3uThh/PSAr+DRmFgCYFjzWk 1cVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CSKj3xPo; spf=pass (google.com: domain of linux-kernel+bounces-11918-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11918-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l62-20020a632541000000b005cdb0622c89si7733411pgl.16.2023.12.27.01.04.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 01:04:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11918-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=CSKj3xPo; spf=pass (google.com: domain of linux-kernel+bounces-11918-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11918-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E32B0283823 for ; Wed, 27 Dec 2023 09:04:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 068522E627; Wed, 27 Dec 2023 09:03:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CSKj3xPo" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 D3BE22DF65; Wed, 27 Dec 2023 09:03:12 +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-wr1-f43.google.com with SMTP id ffacd0b85a97d-3369ccb539aso3152890f8f.3; Wed, 27 Dec 2023 01:03:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703667791; x=1704272591; 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=RraVKdn/3CtUzdc/GUkx4wIWX/WntChO7vtqlU3szKo=; b=CSKj3xPoe0b81auFzX5J5r8+gHDtSQ8bTLHyuTSByN5ubgk4ShJnW0WabScu/PWsoO GIk3e8M6h8tqtSwzHT5DkMWLqb7v9GuGAluLL5l2PNxuaGDmeqil1mJ00JKwRJCbBIGZ OR+5SXX+NRoES0dpjTKeUehHdrMTAKHvC0KK3Qq9DOnbVTEwuSaA+J1Ftj14XiW80b0A tgCb1bz++/sdlFb5Av23VYzsyDTElaOP8wFcaHZWfW7iQYlSe5cxgfGVjgM9aWlHNTFT 4TIkzUJaThEh2f1ZQ8ZdX3FbltMnUH6fdmgyxiNiYguE0XU6YkyCOHcrHXnELhBBZp/C sdwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703667791; x=1704272591; 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=RraVKdn/3CtUzdc/GUkx4wIWX/WntChO7vtqlU3szKo=; b=Utekqe3RvOZRy4FiOZ021MFtCa8PqQavCkRm0r6I0K9mFt0Ss1697CKj59sVA6UR3R bFsxF3EIHuf083Bb0oinvkQxTndhtqyHqqthoOj0h5bwTOzBqIu4+3uCqVMhDeHD+ntr FpK8w1r95gF9jjtfzmvQPCaoPJ8Pmx1WCw/krOCeJh4MSTENJbAPRoyhLQ7Isy/cLTa6 lK+0v3GcXlB1/rzakB2ZWO00GW+XpSctFmV4PoBUwHA3L18KbYZacMIDa4sRG8fTF3Wq s/Fi9iK6GhjzuEMVJ3UAUoqSJgEe0RtcVutl3eboY0nct1teXH0jom81X5rItjWXxfkL auug== X-Gm-Message-State: AOJu0Yxgtqs1jrnvd57Y/+0b+O8ZeUJ0kYDUCyby5lHURF8bzwkTNA4Z UsNg0pmlma1uzwoUzIgQb48= X-Received: by 2002:a05:6000:1042:b0:336:73d6:b42b with SMTP id c2-20020a056000104200b0033673d6b42bmr4549978wrx.117.1703667791035; Wed, 27 Dec 2023 01:03:11 -0800 (PST) Received: from localhost.localdomain (host-95-250-248-68.retail.telecomitalia.it. [95.250.248.68]) by smtp.googlemail.com with ESMTPSA id c9-20020a056000104900b003368849129dsm13616525wrx.15.2023.12.27.01.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 01:03:10 -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 v5 3/5] net: phy: add support for PHY LEDs polarity modes Date: Wed, 27 Dec 2023 10:02:29 +0100 Message-Id: <20231227090231.4246-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231227090231.4246-1-ansuelsmth@gmail.com> References: <20231227090231.4246-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: 1786425235671451488 X-GMAIL-MSGID: 1786425235671451488 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 3611ea64875e..b99c7579d9c4 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,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 e9e85d347587..5ac54f9eee82 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -853,6 +853,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 * @@ -1146,6 +1155,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)