linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: Pavel Machek <pavel@ucw.cz>, Lee Jones <lee@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>, Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Vladimir Oltean <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Christian Marangi <ansuelsmth@gmail.com>,
	linux-leds@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [net-next PATCH v4 13/13] net: dsa: qca8k: add op to get ports netdev
Date: Mon, 29 May 2023 18:32:43 +0200	[thread overview]
Message-ID: <20230529163243.9555-14-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com>

From: Andrew Lunn <andrew@lunn.ch>

In order that the LED trigger can blink the switch MAC ports LED, it
needs to know the netdev associated to the port. Add the callback to
return the struct device of the netdev.

Add an helper function qca8k_phy_to_port() to convert the phy back to
dsa_port index, as we reference LED port based on the internal PHY
index and needs to be converted back.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/net/dsa/qca/qca8k-leds.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/net/dsa/qca/qca8k-leds.c b/drivers/net/dsa/qca/qca8k-leds.c
index 1e0c61726487..6f02029b454b 100644
--- a/drivers/net/dsa/qca/qca8k-leds.c
+++ b/drivers/net/dsa/qca/qca8k-leds.c
@@ -5,6 +5,18 @@
 #include "qca8k.h"
 #include "qca8k_leds.h"
 
+static u32 qca8k_phy_to_port(int phy)
+{
+	/* Internal PHY 0 has port at index 1.
+	 * Internal PHY 1 has port at index 2.
+	 * Internal PHY 2 has port at index 3.
+	 * Internal PHY 3 has port at index 4.
+	 * Internal PHY 4 has port at index 5.
+	 */
+
+	return phy + 1;
+}
+
 static int
 qca8k_get_enable_led_reg(int port_num, int led_num, struct qca8k_led_pattern_en *reg_info)
 {
@@ -314,6 +326,20 @@ qca8k_cled_hw_control_get(struct led_classdev *ldev, unsigned long *rules)
 	return 0;
 }
 
+static struct device *qca8k_cled_hw_control_get_device(struct led_classdev *ldev)
+{
+	struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev);
+	struct qca8k_priv *priv = led->priv;
+	struct dsa_port *dp;
+
+	dp = dsa_to_port(priv->ds, qca8k_phy_to_port(led->port_num));
+	if (!dp)
+		return NULL;
+	if (dp->slave)
+		return &dp->slave->dev;
+	return NULL;
+}
+
 static int
 qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int port_num)
 {
@@ -377,6 +403,7 @@ qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p
 		port_led->cdev.hw_control_is_supported = qca8k_cled_hw_control_is_supported;
 		port_led->cdev.hw_control_set = qca8k_cled_hw_control_set;
 		port_led->cdev.hw_control_get = qca8k_cled_hw_control_get;
+		port_led->cdev.hw_control_get_device = qca8k_cled_hw_control_get_device;
 		port_led->cdev.hw_control_trigger = "netdev";
 		init_data.default_label = ":port";
 		init_data.fwnode = led;
-- 
2.39.2


  parent reply	other threads:[~2023-05-29 16:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-29 16:32 [net-next PATCH v4 00/13] leds: introduce new LED hw control APIs Christian Marangi
2023-05-29 16:32 ` [net-next PATCH v4 01/13] leds: add APIs for LEDs hw control Christian Marangi
2023-05-29 16:32 ` [net-next PATCH v4 02/13] leds: add API to get attached device for LED " Christian Marangi
2023-05-29 16:32 ` [net-next PATCH v4 03/13] Documentation: leds: leds-class: Document new Hardware driven LEDs APIs Christian Marangi
2023-05-29 17:07   ` Andrew Lunn
2023-05-29 16:32 ` [net-next PATCH v4 04/13] leds: trigger: netdev: refactor code setting device name Christian Marangi
2023-05-29 16:32 ` [net-next PATCH v4 05/13] leds: trigger: netdev: introduce check for possible hw control Christian Marangi
2023-05-29 16:32 ` [net-next PATCH v4 06/13] leds: trigger: netdev: add basic check for hw control support Christian Marangi
2023-05-29 16:32 ` [net-next PATCH v4 07/13] leds: trigger: netdev: reject interval store for hw_control Christian Marangi
2023-05-29 16:32 ` [net-next PATCH v4 08/13] leds: trigger: netdev: add support for LED hw control Christian Marangi
2023-05-29 16:32 ` [net-next PATCH v4 09/13] leds: trigger: netdev: validate configured netdev Christian Marangi
2023-05-29 16:32 ` [net-next PATCH v4 10/13] leds: trigger: netdev: init mode if hw control already active Christian Marangi
2023-05-29 16:32 ` [net-next PATCH v4 11/13] leds: trigger: netdev: expose netdev trigger modes in linux include Christian Marangi
2023-05-29 16:32 ` [net-next PATCH v4 12/13] net: dsa: qca8k: implement hw_control ops Christian Marangi
2023-05-29 16:32 ` Christian Marangi [this message]
2023-05-30  5:17 ` [net-next PATCH v4 00/13] leds: introduce new LED hw control APIs Jakub Kicinski
2023-05-30 12:54   ` Andrew Lunn
2023-05-31  9:10 ` patchwork-bot+netdevbpf
2023-05-31 10:46   ` Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230529163243.9555-14-ansuelsmth@gmail.com \
    --to=ansuelsmth@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).