From patchwork Wed Dec 13 11:13:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13490721 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jVbpzKJ2" Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FC9DA0; Wed, 13 Dec 2023 03:13:36 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40c39e936b4so43966955e9.1; Wed, 13 Dec 2023 03:13:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702466014; x=1703070814; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=pseVIGzd7eyiYVBzBkDesQe+yf2EQsf+aQtmWaQTTlc=; b=jVbpzKJ2HeirdAUssUGlLqzX6mnw7TBGNMdW65A/qccraMHGtg8xfKZUA/ALJpWd2i tNt4rxmaKQMxfEPZ7jvR84rNOWX82qR7d2acKn0AZKl4xIvu2PrlV/J1LxkO2+Ypxm3z F2shT2atyBl+HUkrGT25nf69bCNmosvSBK5S5EsKPvFD/zx2B8LEXDVTyyAfdu4xwm0G pRwU4hcBmiA7uHpAROohDwQxcGJaUvA4QjuUri94ZYHkgy/bF9cpJKAXuGvok6ZLwhS5 h8bMZmzNIlsRI8HALDsCf9yuj73g6O5ez52Ne8Vg9ZHzRR3TLt7bPr1Z6tjb8+9N9sF1 CyyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702466014; x=1703070814; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pseVIGzd7eyiYVBzBkDesQe+yf2EQsf+aQtmWaQTTlc=; b=DKLHOvE45QPCdtUKLwW5TLrVfZRoAXyZyJQyDaRcmZ6VYq4q4sQwNuMGAMVkSCsIfa ocRO1RaiH6wri0WDGIRZteeO4L+4mxZtGrpQ7pvAc0K651XZzpmFUq4sFPY4NgUrjE+e +NH5iWp03xiBdgXw96hDkrVOHqqMFd+mPpYFLFeE1c6dM+9C9bqIQ1asZfidWrFU7IhD NRDTj3aCon/gFCVdq9imzEHQx2pATKVWuyqt/AN9bkzp8pLwfL9a7SU3dSxMF7CXq50F jfUx2c+Vuj7tY7H0CicFuXYHh0XDF4RIUXWJ1nmkCWLY18cjN1yryalDWnParYK2mSg5 EGfA== X-Gm-Message-State: AOJu0YzQEajUjjQ78YljHd1PG+LZsoowFuW1/KVMiaxxD6TZLvsl3V0k elV62ygp5/otYPhb0zg0iNs= X-Google-Smtp-Source: AGHT+IGBrr1sn7Nn9IZUticHEuMeE7EOrZvAcKt6aGuXAw9tCvZbxWx8/SBrAm7sDlVUNks2+mZtHQ== X-Received: by 2002:a05:600c:21c7:b0:40c:251a:101a with SMTP id x7-20020a05600c21c700b0040c251a101amr2010600wmj.311.1702466014389; Wed, 13 Dec 2023 03:13:34 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id fc7-20020a05600c524700b0040c44cb251dsm12388301wmb.46.2023.12.13.03.13.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 03:13:34 -0800 (PST) From: Christian Marangi To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Florian Fainelli , Christian Marangi , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v3 1/4] dt-bindings: net: phy: Document new LEDs active-low property Date: Wed, 13 Dec 2023 12:13:19 +0100 Message-Id: <20231213111322.6152-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Document new LEDs active-low property to define if the LED require to be set low to be turned on. active-low can be defined in the leds node for PHY that apply the LED polarity globally for each attached LED or in the specific led node for PHY that supports setting the LED polarity per LED. Declaring both way is not supported and will result in the schema getting rejected. Signed-off-by: Christian Marangi --- Changes v3: - Out of RFC Changes v2: - Add this patch .../devicetree/bindings/net/ethernet-phy.yaml | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Documentation/devicetree/bindings/net/ethernet-phy.yaml b/Documentation/devicetree/bindings/net/ethernet-phy.yaml index 8fb2a6ee7e5b..9cb3981fed2a 100644 --- a/Documentation/devicetree/bindings/net/ethernet-phy.yaml +++ b/Documentation/devicetree/bindings/net/ethernet-phy.yaml @@ -213,6 +213,11 @@ properties: '#size-cells': const: 0 + 'active-low': + type: boolean + description: + This define whether all LEDs needs to be low to be turned on. + patternProperties: '^led@[a-f0-9]+$': $ref: /schemas/leds/common.yaml# @@ -225,11 +230,26 @@ properties: driver dependent and required for ports that define multiple LED for the same port. + 'active-low': + type: boolean + description: + This define whether the LED needs to be low to be turned on. + required: - reg unevaluatedProperties: false + allOf: + - if: + required: + - active-low + then: + patternProperties: + '^led@[a-f0-9]+$': + properties: + 'active-low': false + additionalProperties: false required: From patchwork Wed Dec 13 11:13:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13490722 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IPW21o2F" Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61C2CB0; Wed, 13 Dec 2023 03:13:37 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40c317723a8so58052795e9.3; Wed, 13 Dec 2023 03:13:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702466016; x=1703070816; 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=y3zKCeCRkldFKgWiWSKXv43mAIMprUIreQLunV+AG6M=; b=IPW21o2FDwKdvk4PY75RmpLcnLjIdrLmnt3ejPUD2a0hzpV/yunFmOnw21tqVWS5ko R3/+2SKmLYbIB8hfbgF+w0VcI45oSYO+PKKAm3wNqB94n3kDi8+gFvp/8JSTAjbtVCUM cAERAv+LXGBqlp06TavW+/kk7jppSiY3Z51p7+a+RAWdJOV7ppK0RPhDw/bEf01LjfCF QiZlLHVnxX6KMvI22rzF9L8HCr4dZzhf2FKiHSGpgXaR7jxdzx3gwiGVPfpDtoGfp1NM hevo7m1/1+tgqtTDbcdMAVei7db2BR3Q6vzCj7V7MYEhilm4WX2iWA0CKnGVWa7BRS+K aApA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702466016; x=1703070816; 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=y3zKCeCRkldFKgWiWSKXv43mAIMprUIreQLunV+AG6M=; b=bdUy8R7a7eGKET6JZPa2CsWS7d728IuYIgIuH+4XNi4rPG45DR7oWQ6URIAxG78J2l Q4jJVgA8T3Esota+cyKp9b/uRW2hzqLUuImOYpZwQloBd4d5mP4ical+VXwMz93TBDyY ft6VtO3qxbOH2zZLEi9YjdeVfkX9b+CKgkfbsv7eHupgVz7V41bvY9/JO1KdECngBJTM btXyNOIE4scQyihFbBt5raNM/aGULTtmBBbJIGT5iuc+q61KhKuaX++hctx3znGJHBO+ 5K88m2PwoeanzPDsb9BoX6rsL9t9g8cjp339PslqlfW2WHXVa9hHtHEm1n/wEhvQePP9 4xXA== X-Gm-Message-State: AOJu0YxozQ03ybdd58StBWgoSsO+sGsuSD8/aqORDfO6ym7Mo8gg2Nkx og9gn0Q8YBZoldV4cDMAhCc= X-Google-Smtp-Source: AGHT+IFmjUcxlJV7nVqHKgM6Rw4FHKWyvXxORWOouigwe4TobMBzL9ED0gS4J25FX5HEvMyZ18fUxg== X-Received: by 2002:a05:600c:4749:b0:40c:31e6:cae3 with SMTP id w9-20020a05600c474900b0040c31e6cae3mr3821510wmo.115.1702466015371; Wed, 13 Dec 2023 03:13:35 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id fc7-20020a05600c524700b0040c44cb251dsm12388301wmb.46.2023.12.13.03.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 03:13:35 -0800 (PST) From: Christian Marangi To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Florian Fainelli , Christian Marangi , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v3 2/4] net: phy: add support for PHY LEDs active-low Date: Wed, 13 Dec 2023 12:13:20 +0100 Message-Id: <20231213111322.6152-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231213111322.6152-1-ansuelsmth@gmail.com> References: <20231213111322.6152-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add support for PHY LEDs active-low. 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. Active-low can be defined in 2 different way: - In leds node to apply the active low setting globally for every LED. - In each led to apply the active low setting per LED (if supported). PHY driver needs to declare .led_polarity_set() to configure LED polarity. Index will be -1 if the option is set globally or will indicate the LED to apply the polarity settings. Function finally pass a bool to indicate if LED has to be set active low. .led_polarity_set() is called for both leds node and for each led subnode. PHY driver will ignore the additional call based on the passed index value if global setting or per LED setting is supported. Signed-off-by: Christian Marangi --- Changes v3: - Out of RFC Changes v2: - Add this patch drivers/net/phy/phy_device.c | 18 ++++++++++++++++++ include/linux/phy.h | 15 +++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index d8e9335d415c..a9f5d250abff 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3093,6 +3093,7 @@ static int of_phy_led(struct phy_device *phydev, struct led_init_data init_data = {}; struct led_classdev *cdev; struct phy_led *phyled; + bool active_low; u32 index; int err; @@ -3109,6 +3110,13 @@ static int of_phy_led(struct phy_device *phydev, if (index > U8_MAX) return -EINVAL; + active_low = of_property_read_bool(led, "active-low"); + if (phydev->drv->led_polarity_set) { + err = phydev->drv->led_polarity_set(phydev, index, active_low); + if (err) + return err; + } + phyled->index = index; if (phydev->drv->led_brightness_set) cdev->brightness_set_blocking = phy_led_set_brightness; @@ -3145,6 +3153,7 @@ static int of_phy_leds(struct phy_device *phydev) { struct device_node *node = phydev->mdio.dev.of_node; struct device_node *leds, *led; + bool active_low; int err; if (!IS_ENABLED(CONFIG_OF_MDIO)) @@ -3157,6 +3166,15 @@ static int of_phy_leds(struct phy_device *phydev) if (!leds) return 0; + active_low = of_property_read_bool(leds, "active-low"); + if (phydev->drv->led_polarity_set) { + err = phydev->drv->led_polarity_set(phydev, -1, active_low); + if (err) { + of_node_put(leds); + return err; + } + } + for_each_available_child_of_node(leds, led) { err = of_phy_led(phydev, led); if (err) { diff --git a/include/linux/phy.h b/include/linux/phy.h index 6e7ebcc50b85..cbdebf174361 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1145,6 +1145,21 @@ 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 + * @active_low: LED needs to be set low to turn on + * + * Set the PHY to require the LED low to turn on. + * index can be the LED of the PHY device or -1 whether the + * LED polatiry is global and applied to every LED or polarity + * is set per LED. + * + * Returns 0, or an error code. + */ + int (*led_polarity_set)(struct phy_device *dev, int index, + bool active_low); }; #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \ struct phy_driver, mdiodrv) From patchwork Wed Dec 13 11:13:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13490723 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NLwzBxxg" Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80F5FD0; Wed, 13 Dec 2023 03:13:38 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-336417c565eso231048f8f.3; Wed, 13 Dec 2023 03:13:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702466017; x=1703070817; 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=Jbp9q33bbrLugJBFpEcvsBQj4/TK8c9t0fvxH3F0ISo=; b=NLwzBxxghCP0QnwwoHZrt6A3YdNgJANsI3JcQHae++tW606e8sTNll0yhuiwwU3zBI fLvjzWElTYdF2zfnHsLHN13GKi5HeB73w2nioOG3I3sSNOhD2VBF5SKYUzcj5IdZJ5kw JlqIqqxPazUSf/emfYrfk9HEKNliE+pV5vC/gGENWAWfybfh2MYT8q+LBJ/Ol6e/HCb1 24ASg2yoBAhvnuFjubcKY4tEIulBBgvSMqLUZYo3r9NGVs5wA+AN1TvleLeG3mN6Gr4r 04D3r4YiLTF1XludD/gBYBuPqGxwOvYbU3kGYBmSxceJPQ5fdfdBBzBVXErbwrDi+2rU s18Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702466017; x=1703070817; 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=Jbp9q33bbrLugJBFpEcvsBQj4/TK8c9t0fvxH3F0ISo=; b=lEb7AmKU3AAVUY5W8b7gOTS4v8TaMvMC4172zgr0P0z28zcjioYOyqfL+svRXCeJYC UyXvhrCQsoYCDBJDN6kMLwyACNlls++6nu0dCYT8PAMoi500ht8sNIaYxDTK7FaEGMIN FP05Yg2T186auvSDosqFnXed6MQP8jojI8jNmnmg39qCatwWzprDmBuPF1/orId5jygk uPOi92GJUqyMobA0OlRPoFN2UQepybGe3jJl6H2f4zpEQoBO79HTmf7W6jDs608Jdm3F 7sDmgfKgMiISp6qx+0BYcKJrD6Cl8dCPJ89G9eFN57xUyVv4kiJYq8w6to0ZPypQNLgm hjjQ== X-Gm-Message-State: AOJu0Yx/x2AGaVTaJPQRTQdaRYIubsDTgyQqtFby7wNWhl610XQHk91t YxZcT9w+aOFdSDwG8ArLEjA= X-Google-Smtp-Source: AGHT+IFWkPO9Nss0vhFpGA57iic9MYUJdCpaj7kHQAJBo0ABhra1nTjDGWoPQ09dOzJIFDE3iCFdWA== X-Received: by 2002:a05:600c:511f:b0:40b:5e1a:db8b with SMTP id o31-20020a05600c511f00b0040b5e1adb8bmr2719903wms.44.1702466016445; Wed, 13 Dec 2023 03:13:36 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id fc7-20020a05600c524700b0040c44cb251dsm12388301wmb.46.2023.12.13.03.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 03:13:36 -0800 (PST) From: Christian Marangi To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Florian Fainelli , Christian Marangi , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v3 3/4] dt-bindings: net: Document QCA808x PHYs Date: Wed, 13 Dec 2023 12:13:21 +0100 Message-Id: <20231213111322.6152-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231213111322.6152-1-ansuelsmth@gmail.com> References: <20231213111322.6152-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add Documentation for QCA808x PHYs for the additional LED configuration for this PHY. Signed-off-by: Christian Marangi Reviewed-by: Rob Herring --- For Rob, I used enum instead of const as I assume more PHY will come in the future for the qca808x family. Currently only qca8081 has seen around. Changes v3: - Use compatible instead of select - Out of RFC Changes v2: - Fix License warning from checkpatch - Drop redundant Description phrase - Improve commit tile - Drop special property (generalized) .../devicetree/bindings/net/qca,qca808x.yaml | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/qca,qca808x.yaml diff --git a/Documentation/devicetree/bindings/net/qca,qca808x.yaml b/Documentation/devicetree/bindings/net/qca,qca808x.yaml new file mode 100644 index 000000000000..e2552655902a --- /dev/null +++ b/Documentation/devicetree/bindings/net/qca,qca808x.yaml @@ -0,0 +1,54 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/qca,qca808x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Qualcomm Atheros QCA808X PHY + +maintainers: + - Christian Marangi + +description: + QCA808X PHYs can have up to 3 LEDs attached. + All 3 LEDs are disabled by default. + 2 LEDs have dedicated pins with the 3rd LED having the + double function of Interrupt LEDs/GPIO or additional LED. + + By default this special PIN is set to LED function. + +allOf: + - $ref: ethernet-phy.yaml# + +properties: + compatible: + enum: + - ethernet-phy-id004d.d101 + +unevaluatedProperties: false + +examples: + - | + #include + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-phy@0 { + compatible = "ethernet-phy-id004d.d101"; + reg = <0>; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_WAN; + default-state = "keep"; + }; + }; + }; + }; From patchwork Wed Dec 13 11:13:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13490724 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="L0qQrMym" Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C6D9A0; Wed, 13 Dec 2023 03:13:39 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40c3f68b649so44014715e9.0; Wed, 13 Dec 2023 03:13:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702466017; x=1703070817; 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=iZeodouXCxjXC5HG8L3ZXr6Z5BBeR9v4nmWTsbrew50=; b=L0qQrMymRo5zx7lDcDuk1+a4BL8YEHsVPbxzKOXhUEd8xtZdcyDZD+eWpLTFDyrEl2 aWrv6b7YmrEyC/JNWCXrT/Xcst2v9KMyMA9wrc6H1s3dXG4sDnbuUkMk37zT+zHEYJCO ruweIQPja0WS8aEXhkwzs3MgAZAEFYhzL88xwUGkVMhBZf3nWV7ZiGC46TDu1lQSVBZs 65zi0JB4fd7UDLBtcJLgyLLOtS56g78jTtd6gBjO5P8ThLryQcQbo9Wuwq6Ffi0572hV 6XizWAFJrn+ujsKTX6VBt+hluoGtpiDBIj3Erad41nJ8+aaw+J73D6n+Nu4Ral7565KQ QP9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702466017; x=1703070817; 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=iZeodouXCxjXC5HG8L3ZXr6Z5BBeR9v4nmWTsbrew50=; b=nh1J5kddSv5cBVbYuIYV8J6UYC4pN0SkWzlFN9Wb6kQV5mXpnGJf/eiaMFJOKkIAkZ wnX+ouArnqcJNCkNlR3pkamL/BxClYqZLLaZjIFvJfAIWbbWapch+bxcWuk7vokGL5ub WQ+qPoXVvnBoCei858mIHlfXPi8nk66KcUnsB2ZAg4AiMNjpVjTWgDNnmQjHRlJlq9qv yUSUkkfoLMP0Qbf3LgY6pwJDwdr1Z7UqOXi2+37Whz0frk32KNByHgFEWJmo6jPlDklA fUKPOqT0Evp7gMvLDFRC+Rd6spvoi4LkKrPJ3PRJp1jHHSEuU++eQxLw5sIKP919lgY0 Tk/g== X-Gm-Message-State: AOJu0YyTkNTcv2cyy9JY1LFDU83UlJeAClePV6tkc/JSOM3C7MXaDalN o+33w181fM2eRr73bSuHHxFeolTf5Yc= X-Google-Smtp-Source: AGHT+IFQKSl9n4TYl62M8nM8yYnZMCSCw6LyxgfxewxKPLSTipo7xIx7sM9ojzOf4Tta4JOrSmlcbQ== X-Received: by 2002:a05:600c:1d12:b0:40c:236b:6737 with SMTP id l18-20020a05600c1d1200b0040c236b6737mr2860971wms.171.1702466017532; Wed, 13 Dec 2023 03:13:37 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id fc7-20020a05600c524700b0040c44cb251dsm12388301wmb.46.2023.12.13.03.13.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 03:13:37 -0800 (PST) From: Christian Marangi To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Florian Fainelli , Christian Marangi , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v3 4/4] net: phy: at803x: add LED support for qca808x Date: Wed, 13 Dec 2023 12:13:22 +0100 Message-Id: <20231213111322.6152-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231213111322.6152-1-ansuelsmth@gmail.com> References: <20231213111322.6152-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Add LED support for QCA8081 PHY. Documentation for this LEDs PHY is very scarce even with NDA access to Documentation for OEMs. Only the blink pattern are documented and are very confusing most of the time. No documentation is present about forcing the LED on/off or to always blink. Those settings were reversed by poking the regs and trying to find the correct bits to trigger these modes. Some bits mode are not clear and maybe the documentation option are not 100% correct. For the sake of LED support the reversed option are enough to add support for current LED APIs. Supported HW control modes are: - tx - rx - link10 - link100 - link1000 - half_duplex - full_duplex Also add support for LED polarity set to set LED polarity to active high or low. QSDK sets this value to high by default but PHY reset value doesn't have this enabled by default. QSDK also sets 2 additional bits but their usage is not clear, info about this is added in the header. It was verified that for correct function of the LED if active high is needed, only BIT 6 is needed. Signed-off-by: Christian Marangi --- Changes v3: - Out of RFC - Drop link_25000 and add TODO commends waiting for the netdev trigger thing to be merged (I will take care of sending a followup patch later) Changes v2: - Move to new led_polarity_set implementation - Drop special probe drivers/net/phy/at803x.c | 281 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index b9d3a26cf6dc..7c3c4df65787 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -272,6 +272,69 @@ #define QCA808X_CDT_STATUS_STAT_OPEN 2 #define QCA808X_CDT_STATUS_STAT_SHORT 3 +#define QCA808X_MMD7_LED2_CTRL 0x8074 +#define QCA808X_MMD7_LED2_FORCE_CTRL 0x8075 +#define QCA808X_MMD7_LED1_CTRL 0x8076 +#define QCA808X_MMD7_LED1_FORCE_CTRL 0x8077 +#define QCA808X_MMD7_LED0_CTRL 0x8078 +#define QCA808X_MMD7_LED_CTRL(x) (0x8078 - ((x) * 2)) + +/* LED hw control pattern is the same for every LED */ +#define QCA808X_LED_PATTERN_MASK GENMASK(15, 0) +#define QCA808X_LED_SPEED2500_ON BIT(15) +#define QCA808X_LED_SPEED2500_BLINK BIT(14) +/* Follow blink trigger even if duplex or speed condition doesn't match */ +#define QCA808X_LED_BLINK_CHECK_BYPASS BIT(13) +#define QCA808X_LED_FULL_DUPLEX_ON BIT(12) +#define QCA808X_LED_HALF_DUPLEX_ON BIT(11) +#define QCA808X_LED_TX_BLINK BIT(10) +#define QCA808X_LED_RX_BLINK BIT(9) +#define QCA808X_LED_TX_ON_10MS BIT(8) +#define QCA808X_LED_RX_ON_10MS BIT(7) +#define QCA808X_LED_SPEED1000_ON BIT(6) +#define QCA808X_LED_SPEED100_ON BIT(5) +#define QCA808X_LED_SPEED10_ON BIT(4) +#define QCA808X_LED_COLLISION_BLINK BIT(3) +#define QCA808X_LED_SPEED1000_BLINK BIT(2) +#define QCA808X_LED_SPEED100_BLINK BIT(1) +#define QCA808X_LED_SPEED10_BLINK BIT(0) + +#define QCA808X_MMD7_LED0_FORCE_CTRL 0x8079 +#define QCA808X_MMD7_LED_FORCE_CTRL(x) (0x8079 - ((x) * 2)) + +/* LED force ctrl is the same for every LED + * No documentation exist for this, not even internal one + * with NDA as QCOM gives only info about configuring + * hw control pattern rules and doesn't indicate any way + * to force the LED to specific mode. + * These define comes from reverse and testing and maybe + * lack of some info or some info are not entirely correct. + * For the basic LED control and hw control these finding + * are enough to support LED control in all the required APIs. + */ +#define QCA808X_LED_FORCE_MASK GENMASK(15, 13) +#define QCA808X_LED_FORCE_BLINK_8HZ FIELD_PREP(QCA808X_LED_FORCE_MASK, 0x7) +#define QCA808X_LED_FORCE_BLINK_4HZ FIELD_PREP(QCA808X_LED_FORCE_MASK, 0x6) +#define QCA808X_LED_FORCE_ON FIELD_PREP(QCA808X_LED_FORCE_MASK, 0x5) +#define QCA808X_LED_FORCE_OFF FIELD_PREP(QCA808X_LED_FORCE_MASK, 0x4) +/* HW control option are confusing: + * - 0x3 is 50% on 50% off at 4hz + * - 0x2 is 75% on 25% off at 4hz + * - 0x1 is 25% on 75% off at 4hz + * - 0x0 is 50% on 50% off at 8hz and is set by default + * This comes from visual check and may not be 100% correct. + */ +#define QCA808X_LED_HW_CONTROL_50_50_4HZ FIELD_PREP(QCA808X_LED_FORCE_MASK, 0x3) +#define QCA808X_LED_HW_CONTROL_75_25 FIELD_PREP(QCA808X_LED_FORCE_MASK, 0x2) +#define QCA808X_LED_HW_CONTROL_25_75 FIELD_PREP(QCA808X_LED_FORCE_MASK, 0x1) +#define QCA808X_LED_HW_CONTROL_50_50_8HZ FIELD_PREP(QCA808X_LED_FORCE_MASK, 0x0) + +#define QCA808X_MMD7_LED_POLARITY_CTRL 0x901a +/* QSDK sets by default 0x46 to this reg that sets BIT 6 for + * LED to active high. It's not clear what BIT 3 and BIT 4 does. + */ +#define QCA808X_LED_ACTIVE_HIGH BIT(6) + /* QCA808X 1G chip type */ #define QCA808X_PHY_MMD7_CHIP_TYPE 0x901d #define QCA808X_PHY_CHIP_TYPE_1G BIT(0) @@ -2128,6 +2191,218 @@ static void qca808x_link_change_notify(struct phy_device *phydev) QCA8081_PHY_FIFO_RSTN, phydev->link ? QCA8081_PHY_FIFO_RSTN : 0); } +static int qca808x_led_parse_netdev(struct phy_device *phydev, unsigned long rules, + u16 *offload_trigger) +{ + /* TODO: add link_2500 when added to netdev trigger */ + /* Parsing specific to netdev trigger */ + if (test_bit(TRIGGER_NETDEV_TX, &rules)) + *offload_trigger |= QCA808X_LED_TX_BLINK; + if (test_bit(TRIGGER_NETDEV_RX, &rules)) + *offload_trigger |= QCA808X_LED_RX_BLINK; + if (test_bit(TRIGGER_NETDEV_LINK_10, &rules)) + *offload_trigger |= QCA808X_LED_SPEED10_ON; + if (test_bit(TRIGGER_NETDEV_LINK_100, &rules)) + *offload_trigger |= QCA808X_LED_SPEED100_ON; + if (test_bit(TRIGGER_NETDEV_LINK_1000, &rules)) + *offload_trigger |= QCA808X_LED_SPEED1000_ON; + if (test_bit(TRIGGER_NETDEV_HALF_DUPLEX, &rules)) + *offload_trigger |= QCA808X_LED_HALF_DUPLEX_ON; + if (test_bit(TRIGGER_NETDEV_FULL_DUPLEX, &rules)) + *offload_trigger |= QCA808X_LED_FULL_DUPLEX_ON; + + if (rules && !*offload_trigger) + return -EOPNOTSUPP; + + /* Enable BLINK_CHECK_BYPASS by default to make the LED + * blink even with duplex or speed mode not enabled. + */ + *offload_trigger |= QCA808X_LED_BLINK_CHECK_BYPASS; + + return 0; +} + +static int qca808x_led_hw_control_enable(struct phy_device *phydev, u8 index) +{ + u16 reg; + + if (index > 2) + return -EINVAL; + + reg = QCA808X_MMD7_LED_FORCE_CTRL(index); + + return phy_clear_bits_mmd(phydev, MDIO_MMD_AN, reg, + QCA808X_LED_FORCE_MASK); +} + +static int qca808x_led_hw_is_supported(struct phy_device *phydev, u8 index, + unsigned long rules) +{ + u16 offload_trigger = 0; + + if (index > 2) + return -EINVAL; + + return qca808x_led_parse_netdev(phydev, rules, &offload_trigger); +} + +static int qca808x_led_hw_control_set(struct phy_device *phydev, u8 index, + unsigned long rules) +{ + u16 reg, offload_trigger = 0; + int ret; + + if (index > 2) + return -EINVAL; + + reg = QCA808X_MMD7_LED_CTRL(index); + + ret = qca808x_led_parse_netdev(phydev, rules, &offload_trigger); + if (ret) + return ret; + + ret = qca808x_led_hw_control_enable(phydev, index); + if (ret) + return ret; + + return phy_modify_mmd(phydev, MDIO_MMD_AN, reg, + QCA808X_LED_PATTERN_MASK, + offload_trigger); +} + +static bool qca808x_led_hw_control_status(struct phy_device *phydev, u8 index) +{ + u16 reg; + int val; + + if (index > 2) + return false; + + reg = QCA808X_MMD7_LED_FORCE_CTRL(index); + + val = phy_read_mmd(phydev, MDIO_MMD_AN, reg); + + return !(val & QCA808X_LED_FORCE_MASK); +} + +static int qca808x_led_hw_control_get(struct phy_device *phydev, u8 index, + unsigned long *rules) +{ + u16 reg; + int val; + + if (index > 2) + return -EINVAL; + + /* Check if we have hw control enabled */ + if (qca808x_led_hw_control_status(phydev, index)) + return -EINVAL; + + reg = QCA808X_MMD7_LED_CTRL(index); + + /* TODO: add link_2500 when added to netdev trigger */ + val = phy_read_mmd(phydev, MDIO_MMD_AN, reg); + if (val & QCA808X_LED_TX_BLINK) + set_bit(TRIGGER_NETDEV_TX, rules); + if (val & QCA808X_LED_RX_BLINK) + set_bit(TRIGGER_NETDEV_RX, rules); + if (val & QCA808X_LED_SPEED10_ON) + set_bit(TRIGGER_NETDEV_LINK_10, rules); + if (val & QCA808X_LED_SPEED100_ON) + set_bit(TRIGGER_NETDEV_LINK_100, rules); + if (val & QCA808X_LED_SPEED1000_ON) + set_bit(TRIGGER_NETDEV_LINK_1000, rules); + if (val & QCA808X_LED_HALF_DUPLEX_ON) + set_bit(TRIGGER_NETDEV_HALF_DUPLEX, rules); + if (val & QCA808X_LED_FULL_DUPLEX_ON) + set_bit(TRIGGER_NETDEV_FULL_DUPLEX, rules); + + return 0; +} + +static int qca808x_led_hw_control_reset(struct phy_device *phydev, u8 index) +{ + u16 reg; + + if (index > 2) + return -EINVAL; + + reg = QCA808X_MMD7_LED_CTRL(index); + + return phy_clear_bits_mmd(phydev, MDIO_MMD_AN, reg, + QCA808X_LED_PATTERN_MASK); +} + +static int qca808x_led_brightness_set(struct phy_device *phydev, + u8 index, enum led_brightness value) +{ + u16 reg; + int ret; + + if (index > 2) + return -EINVAL; + + if (!value) { + ret = qca808x_led_hw_control_reset(phydev, index); + if (ret) + return ret; + } + + reg = QCA808X_MMD7_LED_FORCE_CTRL(index); + + return phy_modify_mmd(phydev, MDIO_MMD_AN, reg, + QCA808X_LED_FORCE_MASK, + value ? QCA808X_LED_FORCE_ON : + QCA808X_LED_FORCE_OFF); +} + +static int qca808x_led_blink_set(struct phy_device *phydev, u8 index, + unsigned long *delay_on, + unsigned long *delay_off) +{ + u16 reg; + int ret; + + if (index > 2) + return -EINVAL; + + reg = QCA808X_MMD7_LED_FORCE_CTRL(index); + + ret = phy_modify_mmd(phydev, MDIO_MMD_AN, reg, + QCA808X_LED_FORCE_MASK, + QCA808X_LED_FORCE_BLINK_4HZ); + if (ret) + return ret; + + /* We set blink to 4Hz, aka 250ms */ + *delay_on = 250 / 2; + *delay_off = 250 / 2; + + return 0; +} + +static int qca808x_led_polarity_set(struct phy_device *phydev, int index, + bool active_low) +{ + int ret; + + /* Ignore calling LED polarity set for LED node */ + if (index >= 0) + return 0; + + if (active_low) { + ret = phy_clear_bits_mmd(phydev, MDIO_MMD_AN, + QCA808X_MMD7_LED_POLARITY_CTRL, + QCA808X_LED_ACTIVE_HIGH); + } else { + ret = phy_set_bits_mmd(phydev, MDIO_MMD_AN, + QCA808X_MMD7_LED_POLARITY_CTRL, + QCA808X_LED_ACTIVE_HIGH); + } + + return ret; +} + static struct phy_driver at803x_driver[] = { { /* Qualcomm Atheros AR8035 */ @@ -2304,6 +2579,12 @@ static struct phy_driver at803x_driver[] = { .cable_test_start = qca808x_cable_test_start, .cable_test_get_status = qca808x_cable_test_get_status, .link_change_notify = qca808x_link_change_notify, + .led_brightness_set = qca808x_led_brightness_set, + .led_blink_set = qca808x_led_blink_set, + .led_hw_is_supported = qca808x_led_hw_is_supported, + .led_hw_control_set = qca808x_led_hw_control_set, + .led_hw_control_get = qca808x_led_hw_control_get, + .led_polarity_set = qca808x_led_polarity_set, }, }; module_phy_driver(at803x_driver);