From patchwork Sun Mar 10 04:51:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 13588011 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 967861BC49; Sun, 10 Mar 2024 04:52:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710046339; cv=none; b=qk8j/0uk7WMzo04EPfNYvVdZMLFvmvlYmCZSDc/b/Xl1QRX9ki46yle3NFMljD5QmejzPf8u3qoKXS1odNYd8kKVilHI+ipqu3SrG9viGO4zF3EYFxXWZ7OGDE/H+FHBDpE3lgu7Vh55PzOL4x7C9MTLvA1uM2Viswd960x7WBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710046339; c=relaxed/simple; bh=Lg3ikMyb6Y/X2LET7wpSXls/MYqnJ4AFCGUo2fqpRjs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qnPX135xM/PJtl1xz0NWTAGnmWVsilUQpQYy0lbBCz2XA+3KabBHn3tuKS5dkWeMZxLDNYfG9eEPEWzVzDa/o5g9hwa20tv4fidh3rLgugc4j0YcGRRuySz5YJGWgBS7t829Uhk3JcSJfoFJz+IwUOFxj/QGKyLtE584mLDRdAk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JYF0x9Md; arc=none smtp.client-ip=209.85.210.171 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JYF0x9Md" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6e64647af39so3276057b3a.1; Sat, 09 Mar 2024 20:52:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710046336; x=1710651136; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=wcSs9B8AJsk0OCQxTFxaDtnnoShMSQH+cox1ftjSnF4=; b=JYF0x9Md2iaFfqnIysb2T2F3xhGpDZcDL/lzs2C0NMJK0Odm8Dl+th7RErT4GN7OQW RJbF3mw7bcu1Cr82pOiMYWJl1m+DDFhxVGlCnTMGI8w4MVQcEPhFFm3FOkMqY0P9zizc KELd8teuK3fa2gyyZ1pvESgeCP+MBxS45n34DvpDWiqm+udnVQYUcybi2TkaCYh9/SK8 EXkIOX5sw02ps/h/J0ySHeSC3+eiEwqjvR1DNuaj2sLJm/wzIx/pKTxp6zNRp4hXY3Xj 5xqHWKNl6ngymPzleTfecKp4ufx3C8n1PoW/USY12e4TqP8k5xcynrviFBGUCedznRXD tyuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710046336; x=1710651136; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wcSs9B8AJsk0OCQxTFxaDtnnoShMSQH+cox1ftjSnF4=; b=TUbNh2zMXt2X21APTDnnsjRew/eD36Ca9VBso90uCmFEpI2WY1TNvyW1kYfSPWzZfY cauoKRIREnC7JvJQJuEFZ2Bxw11cBrwv5/PDw/XmiTn0oD/Y+d0/o7r68cOw4admqGz1 hr55vURfb3XCy67xf1K+7NfYOnan+uQY+ZMWcUDxRvhiOR7wnv2ezM3kb+/5LVcIAmxs 43f2wnU3+xagN9TExF+wkIJiGfcdqpoe1MV8X5+PV+hQLVCHnBnr6aLhHy7aGNvBpDcX C4HrrzALPGs0EOTNXtyZY9V0SuOye+KVnye6M81I8o5Tj40SiQJUdhBBtJxYqia9oORw BJ3Q== X-Forwarded-Encrypted: i=1; AJvYcCWEbjWmQqhySZNi7vH6mNzEE30vYMtaC60rNzATD7L4As4wS+GbjOE/R8aZeSYJvSJv08JhmGClC+5FhaiCddD8OE6748lRHfmH8f8WoamgYYDztKhYKk2YC+OKGTdN0gbO8jMM1GjxWg== X-Gm-Message-State: AOJu0YxT2lNIMR/LaVi7vSqaumD4uF/TBaY2aOeJk/ryLRskLN5jZGiZ OP6YWAt/0rd5bTnrexBltkKb3/gRUh3JqQjffe9oEZ9Gem7eUSk7 X-Google-Smtp-Source: AGHT+IFZK4geDB+uozIuL/rNFQyyInWu8kAKb7Hxsvs6ROkg35n8eQLESZaZE/doTvOMEyVTSb4SNQ== X-Received: by 2002:a05:6a20:b393:b0:1a1:1e8b:9044 with SMTP id eg19-20020a056a20b39300b001a11e8b9044mr3164025pzb.50.1710046335938; Sat, 09 Mar 2024 20:52:15 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:3b0:4104:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id e11-20020a63e00b000000b005dc48e56191sm1984659pgh.11.2024.03.09.20.52.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 20:52:15 -0800 (PST) From: Luiz Angelo Daros de Luca Date: Sun, 10 Mar 2024 01:51:58 -0300 Subject: [PATCH net-next 1/4] dt-bindings: net: dsa: realtek: describe LED usage Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240310-realtek-led-v1-1-4d9813ce938e@gmail.com> References: <20240310-realtek-led-v1-0-4d9813ce938e@gmail.com> In-Reply-To: <20240310-realtek-led-v1-0-4d9813ce938e@gmail.com> To: Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca , devicetree@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3132; i=luizluca@gmail.com; h=from:subject:message-id; bh=Lg3ikMyb6Y/X2LET7wpSXls/MYqnJ4AFCGUo2fqpRjs=; b=owEBbQGS/pANAwAIAbsR27rRBztWAcsmYgBl7Tx2DwXtTTbtEDUXMGQQZ7Qy1ZbbDuH27e4LP hebubB6VvKJATMEAAEIAB0WIQQRByhHhc1bOhL6L/i7Edu60Qc7VgUCZe08dgAKCRC7Edu60Qc7 ViFQCACwHVxnDIWkyLk2D14MWfEUPX7VYntTLBPmrNgpXxXRzQ2XMrEIEoYTk94OcgEP/Mw2/zj YwVTWzYjNQdfKsKWOjh72w2Pw5D3BxNxlK/g20bKK6NDD2PFIDJyBJHWfUjS7b/olLkTxCBZLcq Al7fOdirqMpk/qS5TAIAa61UB/Es3KNQl2wORY6vPR9pvbdmr6EDNRqNXE/g6U5hOejCLlECVSY H/Wh4LPDfH+hWdBN54cjYm63wBWKaiao6y23YHI17fOwY4/ODyFZbRZjMylXXITV+R1uGQ5PmzI IO8uu+GcPsrk1v5HMuxV6SZK9bBFpdzX42SUybtkoS2U4LV2 X-Developer-Key: i=luizluca@gmail.com; a=openpgp; fpr=1107284785CD5B3A12FA2FF8BB11DBBAD1073B56 X-Patchwork-Delegate: kuba@kernel.org Each port can have up to 4 LEDs (3 for current rtl8365mb devices). The LED reg property will indicate its LED group. An example of LED usage was included in an existing switch example. Cc: devicetree@vger.kernel.org Signed-off-by: Luiz Angelo Daros de Luca --- .../devicetree/bindings/net/dsa/realtek.yaml | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Documentation/devicetree/bindings/net/dsa/realtek.yaml b/Documentation/devicetree/bindings/net/dsa/realtek.yaml index 70b6bda3cf98..45c1656b3fae 100644 --- a/Documentation/devicetree/bindings/net/dsa/realtek.yaml +++ b/Documentation/devicetree/bindings/net/dsa/realtek.yaml @@ -108,6 +108,32 @@ properties: compatible: const: realtek,smi-mdio +patternProperties: + '^(ethernet-)?ports$': + type: object + additionalProperties: true + + patternProperties: + '^(ethernet-)?port@[0-6]$': + type: object + additionalProperties: true + + properties: + leds: + description: + "LEDs associated with this port" + + patternProperties: + '^led@[a-f0-9]+$': + type: object + additionalProperties: true + + properties: + reg: + description: + "reg indicates the LED group for this LED" + enum: [0, 1, 2, 3] + if: required: - reg @@ -144,6 +170,7 @@ unevaluatedProperties: false examples: - | #include + #include #include platform { @@ -190,6 +217,25 @@ examples: reg = <4>; label = "wan"; phy-handle = <&phy4>; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_WAN; + default-state = "keep"; + }; + + led@3 { + reg = <3>; + color = ; + function = LED_FUNCTION_WAN; + default-state = "keep"; + }; + }; }; port@5 { reg = <5>; From patchwork Sun Mar 10 04:51:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 13588012 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) (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 028711EB22; Sun, 10 Mar 2024 04:52:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710046342; cv=none; b=gUgsy3IAHfRe/njgaSN5158hww0/GZCRtNXEu/S4ceyAfYkYdVnPx5oXzcM9nccOxAnE3OGOcAhDTKJGX+HJcLA5YmnB7KsyzabSIUHS4n+/ugO3c2Shtg0HIwzKFMFUh/9aHeudzViouYUhWQcynBoTWApRy3/pa0llB/GfXP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710046342; c=relaxed/simple; bh=9ZKWPMfna0jwv6fGXFjbpfO9PS9iN4T7q95CeiGCuwg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Cm5blVILi/w+T3QaG7ZPEIjTZuPvGLaeb8OT6Z1isRu+69fxVeiuZKm0N4s7NF9hz8L2F10nhO46OnCAE/VouhpnW7hL9bGidrxytcvFIXwRMa94RouirwG5jL5y3X1d7bqpSniL24kKsPtpygSk0olYrSroLA9KoXcCnWrdzxA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MAQWroAu; arc=none smtp.client-ip=209.85.160.47 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MAQWroAu" Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-2210a266118so1532990fac.1; Sat, 09 Mar 2024 20:52:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710046340; x=1710651140; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9F4InxFahtIzBCiasX92apB/V4CV7bosSvWP44yKEb4=; b=MAQWroAuZc+y5sXQme4YymWc5TUsoVawer/bifwrin6kZf1g6z/6mIpr5lXpKf0WvF 7XyNgARGXfLOTUnxANzHUwy5So4zJX6+3k2J80GqKVgU8P57od/fdCqIImyS3LEF9C3c kAVAistN/lf6TPgKQVwVgALha4aReSzVxzFVLvXf/sMQDGRLQu0420nGN1QWRr8iUIoM 5sXKjA3cGt2t4+qvm+yiOQywgkkTJEZWmNMkCg3K+IOfJZhc9RUvTET0ifWIUUMdabKE 6kHBlHYpf3tkL+Mf6FewbBipIRTV5g2UxU1ON74WvpWYxEPTk61KPtdCoQ/BQndgwIpE cWAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710046340; x=1710651140; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9F4InxFahtIzBCiasX92apB/V4CV7bosSvWP44yKEb4=; b=AZF5k65fkC0eSTWtNISFzLisDUaOGkRbEbIvWzmHqjPqJoswOw28RCLpcIjr4KSj37 H2/g/IRnfwrd40DhvmN0VItoUuXdakdtCyKFNDh8wvUkTBtEe2FoB6kbBQ/Nue+Msw3i +SX4bwnADgYdbh/62op/uvxskvgaUxTrWFrhF1qObgGDyLmGtg5ImRbO0J3/eDQShPEc 2ir61amuO/WAv/pa3Li4R0PnUUP+pph83TPJoed6yZZxgxTwsmZ2iew30ayWsIFvwTL9 YLS8oci5qAY6xMhBhnX++WnolHuARBpaVBHlOYS7pd93i+EgxJ8uvYOIQ/mI4L+CK4p4 fhXg== X-Forwarded-Encrypted: i=1; AJvYcCUl2SUvYSm5Y0lo8EoRrHlee9djq8MCEl2UcymDHjv//ZebPf7uK3Awxw50G4uKK0IuHa1hLaqggc5Vd6RL2VlxMQSlDp/40AxHGY2s X-Gm-Message-State: AOJu0Yx60rg2iANCT2mvZ2JkNlE/K3whgONHHrdyLScud0gStDwz/ar9 7W0pjS/JjMvvvm2CmLrXNNpZAJkZpUIF4ihGVS8bDpRfpiCmhgWr X-Google-Smtp-Source: AGHT+IHLqjp9RdoDu8wQRcjHXyF6C0gN0BIUqlGl2sP89zlfCJ2CAAWXLS5KDTMSrK6LJ34m6g7CVA== X-Received: by 2002:a05:6359:7604:b0:17b:a0d0:5678 with SMTP id wg4-20020a056359760400b0017ba0d05678mr4670132rwc.9.1710046340149; Sat, 09 Mar 2024 20:52:20 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:3b0:4104:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id e11-20020a63e00b000000b005dc48e56191sm1984659pgh.11.2024.03.09.20.52.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 20:52:19 -0800 (PST) From: Luiz Angelo Daros de Luca Date: Sun, 10 Mar 2024 01:51:59 -0300 Subject: [PATCH net-next 2/4] net: dsa: realtek: keep default LED state in rtl8366rb Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240310-realtek-led-v1-2-4d9813ce938e@gmail.com> References: <20240310-realtek-led-v1-0-4d9813ce938e@gmail.com> In-Reply-To: <20240310-realtek-led-v1-0-4d9813ce938e@gmail.com> To: Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6278; i=luizluca@gmail.com; h=from:subject:message-id; bh=9ZKWPMfna0jwv6fGXFjbpfO9PS9iN4T7q95CeiGCuwg=; b=owEBbAGT/pANAwAIAbsR27rRBztWAcsmYgBl7Tx26yS+c8GdKfYNxhAiMu87GEDgJ9bp5iBzg 6NPY7pYdg+JATIEAAEIAB0WIQQRByhHhc1bOhL6L/i7Edu60Qc7VgUCZe08dgAKCRC7Edu60Qc7 VleeB/jJndP1mleQvrIlnbR1mFWnnzeZAfFk+DpGp6vBNsLiMQEPUfMIWUeXYpKi8rHGdq8DaeE HKpWo+/WIkRXbLSmd5XHFsqmD8kqiQM34+rsI9JmVZEPCuTfs8ZquTXKeNRm2O/GBQQrQBHVXy5 TFqZB4IqlOh69liee+z9plr5uBP5eexyF+gi1V+701gkAZkO8DePKJSqLaI6yTfqgsYOM7+MPCH ras13acIBpqACe9O0hRxhLAm3ucTgoWetpJZon6SLKEOLTc2sPPhTE1sukKnOzDCJ3TWLCzb4oN zdFVWPJGwLxuIEwDp001ItHTWE1RiVdyujh1Tp5bd72RfTo= X-Developer-Key: i=luizluca@gmail.com; a=openpgp; fpr=1107284785CD5B3A12FA2FF8BB11DBBAD1073B56 X-Patchwork-Delegate: kuba@kernel.org This switch family supports four LEDs for each of its six ports. Each LED group is composed of one of these four LEDs from all six ports. LED groups can be configured to display hardware information, such as link activity, or manually controlled through a bitmap in registers RTL8366RB_LED_0_1_CTRL_REG and RTL8366RB_LED_2_3_CTRL_REG. After a reset, the default LED group configuration for groups 0 to 3 indicates, respectively, link activity, link at 1000M, 100M, and 10M, or RTL8366RB_LED_CTRL_REG as 0x5432. These configurations are commonly used for LED indications. However, the driver was replacing that configuration to use manually controlled LEDs (RTL8366RB_LED_FORCE) without providing a way for the OS to control them. The default configuration is deemed more useful than fixed, uncontrollable turned-on LEDs. The driver was enabling/disabling LEDs during port_enable/disable. However, these events occur when the port is administratively controlled (up or down) and are not related to link presence. Additionally, when a port N was disabled, the driver was turning off all LEDs for group N, not only the corresponding LED for port N in any of those 4 groups. In such cases, if port 0 was brought down, the LEDs for all ports in LED group 0 would be turned off. As another side effect, the driver was wrongly warning that port 5 didn't have an LED ("no LED for port 5"). Since showing the administrative state of ports is not an orthodox way to use LEDs, it was not worth it to fix it and all this code was dropped. The code to disable LEDs was simplified only changing each LED group to the RTL8366RB_LED_OFF state. Registers RTL8366RB_LED_0_1_CTRL_REG and RTL8366RB_LED_2_3_CTRL_REG are only used when the corresponding LED group is configured with RTL8366RB_LED_FORCE and they don't need to be cleaned. The code still references an LED controlled by RTL8366RB_INTERRUPT_CONTROL_REG, but as of now, no test device has actually used it. Also, some magic numbers were replaced by macros. Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Linus Walleij --- drivers/net/dsa/realtek/rtl8366rb.c | 87 +++++++++---------------------------- 1 file changed, 20 insertions(+), 67 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c index e10ae94cf771..5ccb1a3a149d 100644 --- a/drivers/net/dsa/realtek/rtl8366rb.c +++ b/drivers/net/dsa/realtek/rtl8366rb.c @@ -185,7 +185,12 @@ #define RTL8366RB_LED_BLINKRATE_222MS 0x0004 #define RTL8366RB_LED_BLINKRATE_446MS 0x0005 +/* LED trigger event for each group */ #define RTL8366RB_LED_CTRL_REG 0x0431 +#define RTL8366RB_LED_CTRL_OFFSET(led_group) \ + (4 * (led_group)) +#define RTL8366RB_LED_CTRL_MASK(led_group) \ + (0xf << RTL8366RB_LED_CTRL_OFFSET(led_group)) #define RTL8366RB_LED_OFF 0x0 #define RTL8366RB_LED_DUP_COL 0x1 #define RTL8366RB_LED_LINK_ACT 0x2 @@ -202,6 +207,11 @@ #define RTL8366RB_LED_LINK_TX 0xd #define RTL8366RB_LED_MASTER 0xe #define RTL8366RB_LED_FORCE 0xf + +/* The RTL8366RB_LED_X_X registers are used to manually set the LED state only + * when the corresponding LED group in RTL8366RB_LED_CTRL_REG is + * RTL8366RB_LED_FORCE. Otherwise, it is ignored. + */ #define RTL8366RB_LED_0_1_CTRL_REG 0x0432 #define RTL8366RB_LED_1_OFFSET 6 #define RTL8366RB_LED_2_3_CTRL_REG 0x0433 @@ -1001,28 +1011,20 @@ static int rtl8366rb_setup(struct dsa_switch *ds) */ if (priv->leds_disabled) { /* Turn everything off */ - regmap_update_bits(priv->map, - RTL8366RB_LED_0_1_CTRL_REG, - 0x0FFF, 0); - regmap_update_bits(priv->map, - RTL8366RB_LED_2_3_CTRL_REG, - 0x0FFF, 0); regmap_update_bits(priv->map, RTL8366RB_INTERRUPT_CONTROL_REG, RTL8366RB_P4_RGMII_LED, 0); - val = RTL8366RB_LED_OFF; - } else { - /* TODO: make this configurable per LED */ - val = RTL8366RB_LED_FORCE; - } - for (i = 0; i < 4; i++) { - ret = regmap_update_bits(priv->map, - RTL8366RB_LED_CTRL_REG, - 0xf << (i * 4), - val << (i * 4)); - if (ret) - return ret; + + for (i = 0; i < RTL8366RB_NUM_LEDGROUPS; i++) { + val = RTL8366RB_LED_OFF << RTL8366RB_LED_CTRL_OFFSET(i); + ret = regmap_update_bits(priv->map, + RTL8366RB_LED_CTRL_REG, + RTL8366RB_LED_CTRL_MASK(i), + val); + if (ret) + return ret; + } } ret = rtl8366_reset_vlan(priv); @@ -1167,52 +1169,6 @@ rtl8366rb_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode, } } -static void rb8366rb_set_port_led(struct realtek_priv *priv, - int port, bool enable) -{ - u16 val = enable ? 0x3f : 0; - int ret; - - if (priv->leds_disabled) - return; - - switch (port) { - case 0: - ret = regmap_update_bits(priv->map, - RTL8366RB_LED_0_1_CTRL_REG, - 0x3F, val); - break; - case 1: - ret = regmap_update_bits(priv->map, - RTL8366RB_LED_0_1_CTRL_REG, - 0x3F << RTL8366RB_LED_1_OFFSET, - val << RTL8366RB_LED_1_OFFSET); - break; - case 2: - ret = regmap_update_bits(priv->map, - RTL8366RB_LED_2_3_CTRL_REG, - 0x3F, val); - break; - case 3: - ret = regmap_update_bits(priv->map, - RTL8366RB_LED_2_3_CTRL_REG, - 0x3F << RTL8366RB_LED_3_OFFSET, - val << RTL8366RB_LED_3_OFFSET); - break; - case 4: - ret = regmap_update_bits(priv->map, - RTL8366RB_INTERRUPT_CONTROL_REG, - RTL8366RB_P4_RGMII_LED, - enable ? RTL8366RB_P4_RGMII_LED : 0); - break; - default: - dev_err(priv->dev, "no LED for port %d\n", port); - return; - } - if (ret) - dev_err(priv->dev, "error updating LED on port %d\n", port); -} - static int rtl8366rb_port_enable(struct dsa_switch *ds, int port, struct phy_device *phy) @@ -1226,7 +1182,6 @@ rtl8366rb_port_enable(struct dsa_switch *ds, int port, if (ret) return ret; - rb8366rb_set_port_led(priv, port, true); return 0; } @@ -1241,8 +1196,6 @@ rtl8366rb_port_disable(struct dsa_switch *ds, int port) BIT(port)); if (ret) return; - - rb8366rb_set_port_led(priv, port, false); } static int From patchwork Sun Mar 10 04:52:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 13588013 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 F24877470; Sun, 10 Mar 2024 04:52:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710046346; cv=none; b=W4XofIEjMjQQyEPAw+Dyh45/oHF74LgPmbe6//GJqh+Q9x7UG/H4853AsjcWav3EzBmcZ+n5IvTFq352aPG8PlUvXNN07rUcA5e98cz5ow79vdUQI/ktfC4grf/Hrv832Zc1em7B5L217u0+w1rNfvIoRQiUVF91/5X+nP8o3T8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710046346; c=relaxed/simple; bh=7f/5d43WPVEjlJpJuyxvmDK6WGVzj/6ZalhsBvLwlco=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sczYN6hCwt+Dmda0/1asEXxro9sj1qJdPy5FJkPxnzo/49z/fkG0C8r53yacahQSc00R5F7jXXeqdE7dsjPueKJUBKWQfjalZzkMKaP0RC4YOM5jKz1ub8l6ZNS9JOyx2wZ0/1UzZntDUWNANGpTHdCQ0MMnv3Z3hyjzN2bpRFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=A3Bp7kMW; arc=none smtp.client-ip=209.85.210.180 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A3Bp7kMW" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6e655a12c81so2477989b3a.1; Sat, 09 Mar 2024 20:52:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710046344; x=1710651144; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=lfntijmQgp1O3WIpkJBpEgwRwttiIgBYxL9mf5xJS3A=; b=A3Bp7kMWlDRZG4SSAkuREufrIIO420Z6tFrJUHcOYzmXHArSS+WcT06Q1gynr8VfLP +OFytZDr5Ltqhe2G21RbupfJOdEfWiZmQgPHohghbKwPiM2kMrc/D9bhc2oWgs2unK+R I12XpXV7X70f5vwlWKO83itHLTKCujNY8BjH/D9B+bg6nFuC0QhynFVb9khE4IKmNra+ FDeALZUMEicIEas/OPMql0nRvxVPZnaO55tRAnCfgW0SReH2AIJpBjQo0ogrsgnqj7vT E4t0SrbMQyC8laNNC0Y8zWx4AK8pWfP4azbQHI2MzyEH8Z5SB+NiZKrGPyPu+q55vfzD C0KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710046344; x=1710651144; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lfntijmQgp1O3WIpkJBpEgwRwttiIgBYxL9mf5xJS3A=; b=NNoxSgn6Os4Uym6YGDM3j0Znl+lGuxZUdaKd3g6khHXmhdJcmChmWpxaZy0mTFQsU1 19zV+R0+/Wv5dL6YQgzDCHP8UXgIk0L/Iv7b2sVOAabZLdiFSbNv3Wr8a71qBLNC1RhD bCMzserGAbABnteuHYU8BvPeqTXJh115zDfK3Wt9nLixbVGE75qcwzhNowcrdQpAsyvk 98lxzJ5Jj9Gc/8CybokdpNUAniNkv7G0S0CexKmWBk+qNFW9BPt/6heRRaBbveS+Dv2H qHmQMkmN0YuW+fM8v8yrP8bM8OXcjAxd6ZHutzHUVc7C2ZxO64Kpc1YhJYurSAiaR0dx grwQ== X-Forwarded-Encrypted: i=1; AJvYcCXQaBqvcEJ/GvkJ+oW2g+QqDeIch9TpDpKJOWBWJTPEctS92Dc1D/Pa/NJIdmWn0KRW+pE/wC8YnVDZmGrxa5qRLIsYieQX4qN6PI5P X-Gm-Message-State: AOJu0Yyl2wagZ9uNACZyS6WpG6UCWuCN9UizaAnx21UYPR2XnkXzmGAI qDr3IMjuCEMMtdxBF4+EhklxlwHMI71eWHYaQ8ox+ha0gKiUKj2z X-Google-Smtp-Source: AGHT+IGlO5NG5Z6lacAc90S8PbqOJsioRUsqZHEizpzjZ7cuHLUqCa1+RBoaiYIQchK/SsCkmnEb3Q== X-Received: by 2002:a05:6a21:328b:b0:1a1:89e3:9550 with SMTP id yt11-20020a056a21328b00b001a189e39550mr3875264pzb.10.1710046344325; Sat, 09 Mar 2024 20:52:24 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:3b0:4104:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id e11-20020a63e00b000000b005dc48e56191sm1984659pgh.11.2024.03.09.20.52.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 20:52:23 -0800 (PST) From: Luiz Angelo Daros de Luca Date: Sun, 10 Mar 2024 01:52:00 -0300 Subject: [PATCH net-next 3/4] net: dsa: realtek: do not assert reset on remove Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240310-realtek-led-v1-3-4d9813ce938e@gmail.com> References: <20240310-realtek-led-v1-0-4d9813ce938e@gmail.com> In-Reply-To: <20240310-realtek-led-v1-0-4d9813ce938e@gmail.com> To: Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1590; i=luizluca@gmail.com; h=from:subject:message-id; bh=7f/5d43WPVEjlJpJuyxvmDK6WGVzj/6ZalhsBvLwlco=; b=owGbwMvMwMG4W/D2rovs1mGMp9WSGFLf2pQt+X0jyVh9Bes/wcD0V7un5v0tlV/gymlkcTI1/ ZardOCsTkZjFgZGDgZZMUUWQXYN99az0VZCv/R/wAxiZQKZwsDFKQATiVvF/j+mTPf0T5c0r+R/ lV/O865d9tsv5sW6WQ83GG6VY9tRmJBrtSugv9Jzoud8hV5+jZo6lvxat1Tex/enJ+xqEN764Of EYMVrtVPDZ6QbxaQ2sKYqXZrbJcv4zerUJ5mi5wZLZ2dVffM0cDfeKlwVvCjwf1RTxM7Pvunsqx MZTkhr3Ha1MCj4w3dI/+iEhdxJr1j0fXRnWAi2cf0Le//xd/z1yCv11YK/ig8IfF2bYRDdf1+/N eb9AT62Z0q9uwW4/87M3nHVQOLs4lxjEQ6eCWHTGoSebVDNkE7WmSohNruGWeuDe23fin3X3vQ9 FFdbofavSsM36xcP5wWOrq039K/e2Xx77WG1CbXyHn4NAA== X-Developer-Key: i=luizluca@gmail.com; a=openpgp; fpr=1107284785CD5B3A12FA2FF8BB11DBBAD1073B56 X-Patchwork-Delegate: kuba@kernel.org The necessity of asserting the reset on removal was previously questioned, as DSA's own cleanup methods should suffice to prevent traffic leakage[1]. When a driver has subdrivers controlled by devres, they will be unregistered after the main driver's .remove is executed. If it asserts a reset, the subdrivers will be unable to communicate with the hardware during their cleanup. For LEDs, this means that they will fail to turn off, resulting in a timeout error. [1] https://lore.kernel.org/r/20240123215606.26716-9-luizluca@gmail.com/ Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Linus Walleij --- drivers/net/dsa/realtek/rtl83xx.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl83xx.c b/drivers/net/dsa/realtek/rtl83xx.c index d2e876805393..a9c1702431ef 100644 --- a/drivers/net/dsa/realtek/rtl83xx.c +++ b/drivers/net/dsa/realtek/rtl83xx.c @@ -290,16 +290,13 @@ EXPORT_SYMBOL_NS_GPL(rtl83xx_shutdown, REALTEK_DSA); * rtl83xx_remove() - Cleanup a realtek switch driver * @priv: realtek_priv pointer * - * If a method is provided, this function asserts the hard reset of the switch - * in order to avoid leaking traffic when the driver is gone. + * Placehold for common cleanup procedures. * - * Context: Might sleep if priv->gdev->chip->can_sleep. + * Context: Any * Return: nothing */ void rtl83xx_remove(struct realtek_priv *priv) { - /* leave the device reset asserted */ - rtl83xx_reset_assert(priv); } EXPORT_SYMBOL_NS_GPL(rtl83xx_remove, REALTEK_DSA); From patchwork Sun Mar 10 04:52:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 13588014 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 4E4472943C; Sun, 10 Mar 2024 04:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710046351; cv=none; b=WxstoDnO2Q2s8epG1zhT8eZf1wi56LhXIGsrAfUKBVSPwZtDMJ6E6+aJGW3C4A4Ac/O2JoxKKI281MAGH9ZLTc9G9IZvRv7dFHCMu20yfC7maZD03ThlpLvQ7g624ICDDklDAp5KQVnu8xw7hX7r9Ux1DTy1gpyy5LR4l/wPSIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710046351; c=relaxed/simple; bh=l4BGuQaSazeqlAvJgyULvmoJ+R4pGF6EhnlCeNvnzKo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fVXiQ3+vvxpdPrfg2zr0piZ2pmdrHVCBsjPThGD/aLRO2fhNcv0dRCYpPHuP3PxGUbqO0rO2SbQ8gUxANZRiID9/kPgz1JLCb4sl2fJ9kbtmk35EVtOgEOEi8YW8OzxJVL6PDPXxLE/WCZsUfU1BszFQ3KbVkNvBITMbLIWiRCw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QF02ln/q; arc=none smtp.client-ip=209.85.215.174 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QF02ln/q" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-5dbd519bde6so2842146a12.1; Sat, 09 Mar 2024 20:52:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710046348; x=1710651148; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OoZ0T/xvHWDAJteyB6NrD7pWluK6onYNLLkR78ehmyc=; b=QF02ln/qIcavlT6ZqqF0fKCmUHTvipihk9sJFcZhDaskPek5ahZoApfFXaJM59PIJz 43gUAKsMDq70a3Y+kTvg67XfihtM8Rp8j1WeqQKCpIUtH6PdZHYNrwgNRJ7S/REic664 APqYWlclVDQYOZSeRbf8l/Itxuro7BAQLyJiAonKCIpNb6LSY5ot+l/S0NemtRLr8VgR FThj57QcHz4xs4tKWhxi7v0gJfiigmkSxfSs0usOySQ4zjTzn0RMssVCTJVw/LiGxOd2 DCZ/gWwQ5IZ81SAjD6oPAZp3VRUUFXbYduMavxNFZGBGAQpt+Pr7UjrJYrJOiwgbXc6l p0gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710046348; x=1710651148; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OoZ0T/xvHWDAJteyB6NrD7pWluK6onYNLLkR78ehmyc=; b=FmiU+hwSjuonJYI2zwZ7ursHKtIlmAiS9O4Fk0cD8944hXoazTHGTaKFMUmENRTbYy DNclm5un9sdM6bKXbIYDir8jSy3e1f0mWTa3T9pWyE75znQWvMj0Syss/r8lTK7IUMMQ iCODIbgH4FkXYsXUawQqzCSxWVDTVWmT+FWSGxgbzzuLgcTBO6Iac7R/ymllz+jLjZSG KcjQsk2XIu6sJxEi/KtkPNDipaT9dKoh4TPoiWfyrAQFRCFK8spVyC8snz9z2HT8mJwo 3c6c2/IijDHSDE9DfqmXfPNG1ReI1txc5JMsC4Lq9UCHr2RFQ+7zLDhCqjkBlFud5N9j CPQg== X-Forwarded-Encrypted: i=1; AJvYcCVTEgNa/Ahzi8RJohHMBLAumIFhqfcoq722a//FR7+cl5GMnldhFxsH+1Dk2dAuW0oYb3hZauhrWROdOBV3IJ+Dn8mcramyKolaw7tp X-Gm-Message-State: AOJu0Yyr14g2WGkTH0IdZ5UClh68wKCwQtl2RuKYEdjDvIa0pTrsMS4T 0w28iVj+X8+KDjqsPCI5oCVTIn/MOQY5VYSF/dSbXtiZnH4RmABR X-Google-Smtp-Source: AGHT+IHs+R8RwvPm4akdgBCZNO2ON1Vxa/lz9eEIk1B/kcxVscq9dK1G2laWbgM/kefti+VVkZ+c8g== X-Received: by 2002:a05:6a00:1898:b0:6e6:4e6b:5a16 with SMTP id x24-20020a056a00189800b006e64e6b5a16mr4551598pfh.4.1710046348502; Sat, 09 Mar 2024 20:52:28 -0800 (PST) Received: from tresc054937.tre-sc.gov.br ([2804:3b0:4104:200:2be:43ff:febc:c2fb]) by smtp.gmail.com with ESMTPSA id e11-20020a63e00b000000b005dc48e56191sm1984659pgh.11.2024.03.09.20.52.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 20:52:27 -0800 (PST) From: Luiz Angelo Daros de Luca Date: Sun, 10 Mar 2024 01:52:01 -0300 Subject: [PATCH net-next 4/4] net: dsa: realtek: add LED drivers for rtl8366rb Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240310-realtek-led-v1-4-4d9813ce938e@gmail.com> References: <20240310-realtek-led-v1-0-4d9813ce938e@gmail.com> In-Reply-To: <20240310-realtek-led-v1-0-4d9813ce938e@gmail.com> To: Linus Walleij , =?utf-8?q?Alvin_=C5=A0ipraga?= , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=10066; i=luizluca@gmail.com; h=from:subject:message-id; bh=l4BGuQaSazeqlAvJgyULvmoJ+R4pGF6EhnlCeNvnzKo=; b=owEBbQGS/pANAwAIAbsR27rRBztWAcsmYgBl7Tx2lmdamXCVs5ALeJxgsnxY8F7oaIWMmT9rO g0ygxuXwnaJATMEAAEIAB0WIQQRByhHhc1bOhL6L/i7Edu60Qc7VgUCZe08dgAKCRC7Edu60Qc7 Vm9mB/9kyLWVn4upz2Kkt8piFqPYC0ao6sBZIwOuLTCjxWtrs8L8Qrc+RnJCQqvbejdo86TbmmE a8oTCGY/ydl0YVDvApoW4NXOGtuoaEYRqIr+KhD5MdO0jfgnZVTtFsal1GhxOnteL0lH/JKGU0R gjdXNdEu/tRdsX+vSCuus/zKlN+B3I0BiYE5LAFGSSgFRAA8ltsedrdd4XKFpq6Yd0Y8rp1G9Mi pH1loaAeeF8e1j4CawuY6371VQVc+ptXNbr+2qVEPG02bEKThrYCmN2OwGi7Ci+z0c1QBh8uLtV rQ1SpAdLIKsiFkqIVJ2nG0CxbHezTWscMHd0Rg5duDUyb9Hf X-Developer-Key: i=luizluca@gmail.com; a=openpgp; fpr=1107284785CD5B3A12FA2FF8BB11DBBAD1073B56 X-Patchwork-Delegate: kuba@kernel.org This commit introduces LED drivers for rtl8366rb, enabling LEDs to be described in the device tree using the same format as qca8k. Each port can configure up to 4 LEDs. If all LEDs in a group use the default state "keep", they will use the default behavior after a reset. Changing the brightness of one LED, either manually or by a trigger, will disable the default hardware trigger and switch the entire LED group to manually controlled LEDs. Once in this mode, there is no way to revert to hardware-controlled LEDs (except by resetting the switch). Software triggers function as expected with manually controlled LEDs. Signed-off-by: Luiz Angelo Daros de Luca Reviewed-by: Linus Walleij --- drivers/net/dsa/realtek/rtl8366rb.c | 270 ++++++++++++++++++++++++++++++++---- 1 file changed, 246 insertions(+), 24 deletions(-) diff --git a/drivers/net/dsa/realtek/rtl8366rb.c b/drivers/net/dsa/realtek/rtl8366rb.c index 5ccb1a3a149d..e45773fec17e 100644 --- a/drivers/net/dsa/realtek/rtl8366rb.c +++ b/drivers/net/dsa/realtek/rtl8366rb.c @@ -191,31 +191,21 @@ (4 * (led_group)) #define RTL8366RB_LED_CTRL_MASK(led_group) \ (0xf << RTL8366RB_LED_CTRL_OFFSET(led_group)) -#define RTL8366RB_LED_OFF 0x0 -#define RTL8366RB_LED_DUP_COL 0x1 -#define RTL8366RB_LED_LINK_ACT 0x2 -#define RTL8366RB_LED_SPD1000 0x3 -#define RTL8366RB_LED_SPD100 0x4 -#define RTL8366RB_LED_SPD10 0x5 -#define RTL8366RB_LED_SPD1000_ACT 0x6 -#define RTL8366RB_LED_SPD100_ACT 0x7 -#define RTL8366RB_LED_SPD10_ACT 0x8 -#define RTL8366RB_LED_SPD100_10_ACT 0x9 -#define RTL8366RB_LED_FIBER 0xa -#define RTL8366RB_LED_AN_FAULT 0xb -#define RTL8366RB_LED_LINK_RX 0xc -#define RTL8366RB_LED_LINK_TX 0xd -#define RTL8366RB_LED_MASTER 0xe -#define RTL8366RB_LED_FORCE 0xf /* The RTL8366RB_LED_X_X registers are used to manually set the LED state only * when the corresponding LED group in RTL8366RB_LED_CTRL_REG is * RTL8366RB_LED_FORCE. Otherwise, it is ignored. */ #define RTL8366RB_LED_0_1_CTRL_REG 0x0432 -#define RTL8366RB_LED_1_OFFSET 6 #define RTL8366RB_LED_2_3_CTRL_REG 0x0433 -#define RTL8366RB_LED_3_OFFSET 6 +#define RTL8366RB_LED_X_X_CTRL_REG(led_group) \ + ((led_group) <= 1 ? \ + RTL8366RB_LED_0_1_CTRL_REG : \ + RTL8366RB_LED_2_3_CTRL_REG) +#define RTL8366RB_LED_0_X_CTRL_MASK GENMASK(5, 0) +#define RTL8366RB_LED_X_1_CTRL_MASK GENMASK(11, 6) +#define RTL8366RB_LED_2_X_CTRL_MASK GENMASK(5, 0) +#define RTL8366RB_LED_X_3_CTRL_MASK GENMASK(11, 6) #define RTL8366RB_MIB_COUNT 33 #define RTL8366RB_GLOBAL_MIB_COUNT 1 @@ -359,14 +349,44 @@ #define RTL8366RB_GREEN_FEATURE_TX BIT(0) #define RTL8366RB_GREEN_FEATURE_RX BIT(2) +enum rtl8366_led_mode { + RTL8366RB_LED_OFF = 0x0, + RTL8366RB_LED_DUP_COL = 0x1, + RTL8366RB_LED_LINK_ACT = 0x2, + RTL8366RB_LED_SPD1000 = 0x3, + RTL8366RB_LED_SPD100 = 0x4, + RTL8366RB_LED_SPD10 = 0x5, + RTL8366RB_LED_SPD1000_ACT = 0x6, + RTL8366RB_LED_SPD100_ACT = 0x7, + RTL8366RB_LED_SPD10_ACT = 0x8, + RTL8366RB_LED_SPD100_10_ACT = 0x9, + RTL8366RB_LED_FIBER = 0xa, + RTL8366RB_LED_AN_FAULT = 0xb, + RTL8366RB_LED_LINK_RX = 0xc, + RTL8366RB_LED_LINK_TX = 0xd, + RTL8366RB_LED_MASTER = 0xe, + RTL8366RB_LED_FORCE = 0xf, + + __RTL8366RB_LED_MAX +}; + +struct rtl8366rb_led { + u8 port_num; + u8 led_group; + struct realtek_priv *priv; + struct led_classdev cdev; +}; + /** * struct rtl8366rb - RTL8366RB-specific data * @max_mtu: per-port max MTU setting * @pvid_enabled: if PVID is set for respective port + * @leds: per-port and per-ledgroup led info */ struct rtl8366rb { unsigned int max_mtu[RTL8366RB_NUM_PORTS]; bool pvid_enabled[RTL8366RB_NUM_PORTS]; + struct rtl8366rb_led leds[RTL8366RB_NUM_PORTS][RTL8366RB_NUM_LEDGROUPS]; }; static struct rtl8366_mib_counter rtl8366rb_mib_counters[] = { @@ -809,6 +829,208 @@ static int rtl8366rb_jam_table(const struct rtl8366rb_jam_tbl_entry *jam_table, return 0; } +static int rb8366rb_set_ledgroup_mode(struct realtek_priv *priv, + u8 led_group, + enum rtl8366_led_mode mode) +{ + int ret; + u32 val; + + val = mode << RTL8366RB_LED_CTRL_OFFSET(led_group); + + ret = regmap_update_bits(priv->map, + RTL8366RB_LED_CTRL_REG, + RTL8366RB_LED_CTRL_MASK(led_group), + val); + if (ret) + return ret; + + return 0; +} + +static inline u32 rtl8366rb_led_group_port_mask(u8 led_group, u8 port) +{ + switch (led_group) { + case 0: + return FIELD_PREP(RTL8366RB_LED_0_X_CTRL_MASK, BIT(port)); + case 1: + return FIELD_PREP(RTL8366RB_LED_0_X_CTRL_MASK, BIT(port)); + case 2: + return FIELD_PREP(RTL8366RB_LED_0_X_CTRL_MASK, BIT(port)); + case 3: + return FIELD_PREP(RTL8366RB_LED_0_X_CTRL_MASK, BIT(port)); + default: + return 0; + } +} + +static int rb8366rb_get_port_led(struct rtl8366rb_led *led, bool enable) +{ + struct realtek_priv *priv = led->priv; + u8 led_group = led->led_group; + u8 port_num = led->port_num; + int ret; + u32 val; + + if (led_group >= RTL8366RB_NUM_LEDGROUPS) { + dev_err(priv->dev, "Invalid LED group %d for port %d", + led_group, port_num); + return -EINVAL; + } + + ret = regmap_read(priv->map, RTL8366RB_LED_X_X_CTRL_REG(led_group), + &val); + if (ret) { + dev_err(priv->dev, "error reading LED on port %d group %d\n", + led_group, port_num); + return ret; + } + + return !!(val & rtl8366rb_led_group_port_mask(led_group, port_num)); +} + +static int rb8366rb_set_port_led(struct rtl8366rb_led *led, bool enable) +{ + struct realtek_priv *priv = led->priv; + u8 led_group = led->led_group; + u8 port_num = led->port_num; + int ret; + + if (led_group >= RTL8366RB_NUM_LEDGROUPS) { + dev_err(priv->dev, "Invalid LED group %d for port %d", + led_group, port_num); + return -EINVAL; + } + + ret = regmap_update_bits(priv->map, + RTL8366RB_LED_X_X_CTRL_REG(led_group), + rtl8366rb_led_group_port_mask(led_group, + port_num), + enable ? 0xffff : 0); + if (ret) { + dev_err(priv->dev, "error updating LED on port %d group %d\n", + led_group, port_num); + return ret; + } + + /* Change the LED group to manual controlled LEDs if required */ + ret = rb8366rb_set_ledgroup_mode(priv, led_group, RTL8366RB_LED_FORCE); + + if (ret) { + dev_err(priv->dev, "error updating LED GROUP group %d\n", + led_group); + return ret; + } + + return 0; +} + +static int +rtl8366rb_cled_brightness_set_blocking(struct led_classdev *ldev, + enum led_brightness brightness) +{ + struct rtl8366rb_led *led = container_of(ldev, struct rtl8366rb_led, + cdev); + + return rb8366rb_set_port_led(led, brightness == LED_ON); +} + +static int rtl8366rb_setup_led(struct realtek_priv *priv, struct dsa_port *dp, + struct fwnode_handle *led_fwnode) +{ + struct rtl8366rb *rb = priv->chip_data; + struct led_init_data init_data = { }; + struct rtl8366rb_led *led; + enum led_default_state state; + u32 led_group; + int ret; + + ret = fwnode_property_read_u32(led_fwnode, "reg", &led_group); + if (ret) + return ret; + + if (led_group >= RTL8366RB_NUM_LEDGROUPS) { + dev_warn(priv->dev, "Invalid LED reg %d defined for port %d", + led_group, dp->index); + return -EINVAL; + } + + led = &rb->leds[dp->index][led_group]; + led->port_num = dp->index; + led->led_group = led_group; + led->priv = priv; + + state = led_init_default_state_get(led_fwnode); + switch (state) { + case LEDS_DEFSTATE_ON: + led->cdev.brightness = 1; + rb8366rb_set_port_led(led, 1); + break; + case LEDS_DEFSTATE_KEEP: + led->cdev.brightness = + rb8366rb_get_port_led(led, 1); + break; + case LEDS_DEFSTATE_OFF: + default: + led->cdev.brightness = 0; + rb8366rb_set_port_led(led, 0); + } + + led->cdev.max_brightness = 1; + led->cdev.brightness_set_blocking = + rtl8366rb_cled_brightness_set_blocking; + init_data.fwnode = led_fwnode; + init_data.devname_mandatory = true; + + init_data.devicename = kasprintf(GFP_KERNEL, "Realtek-%d:0%d:%d", + dp->ds->index, dp->index, led_group); + if (!init_data.devicename) + return -ENOMEM; + + ret = devm_led_classdev_register_ext(priv->dev, &led->cdev, &init_data); + if (ret) { + dev_warn(priv->dev, "Failed to init LED %d for port %d", + led_group, dp->index); + return ret; + } + + return 0; +} + +static int rtl8366rb_setup_leds(struct realtek_priv *priv) +{ + struct device_node *leds_np, *led_np; + struct dsa_switch *ds = &priv->ds; + struct dsa_port *dp; + int ret; + + dsa_switch_for_each_port(dp, ds) { + if (!dp->dn) + continue; + + leds_np = of_get_child_by_name(dp->dn, "leds"); + if (!leds_np) { + dev_dbg(priv->dev, "No leds defined for port %d", + dp->index); + continue; + } + + for_each_child_of_node(leds_np, led_np) { + ret = rtl8366rb_setup_led(priv, dp, + of_fwnode_handle(led_np)); + if (ret) { + of_node_put(led_np); + break; + } + } + + of_node_put(leds_np); + if (ret) + return ret; + } + return 0; +} + static int rtl8366rb_setup(struct dsa_switch *ds) { struct realtek_priv *priv = ds->priv; @@ -817,7 +1039,6 @@ static int rtl8366rb_setup(struct dsa_switch *ds) u32 chip_ver = 0; u32 chip_id = 0; int jam_size; - u32 val; int ret; int i; @@ -1017,14 +1238,15 @@ static int rtl8366rb_setup(struct dsa_switch *ds) 0); for (i = 0; i < RTL8366RB_NUM_LEDGROUPS; i++) { - val = RTL8366RB_LED_OFF << RTL8366RB_LED_CTRL_OFFSET(i); - ret = regmap_update_bits(priv->map, - RTL8366RB_LED_CTRL_REG, - RTL8366RB_LED_CTRL_MASK(i), - val); + ret = rb8366rb_set_ledgroup_mode(priv, i, + RTL8366RB_LED_OFF); if (ret) return ret; } + } else { + ret = rtl8366rb_setup_leds(priv); + if (ret) + return ret; } ret = rtl8366_reset_vlan(priv);