[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231128232135.358638-6-andrew@lunn.ch>
Date: Wed, 29 Nov 2023 00:21:32 +0100
From: Andrew Lunn <andrew@...n.ch>
To: netdev <netdev@...r.kernel.org>
Cc: Linus Walleij <linus.walleij@...aro.org>,
Christian Marangi <ansuelsmth@...il.com>,
Vladimir Oltean <vladimir.oltean@....com>,
Florian Fainelli <f.fainelli@...il.com>,
Andrew Lunn <andrew@...n.ch>
Subject: [PATCH RFC net-next 5/8] dsa: Plumb in LED calls needed for hardware offload
In order to offload blinking of the LED to hardware, additional calls
are needed into the LED driver. Add them to the DSA core abstraction.
Signed-off-by: Andrew Lunn <andrew@...n.ch>
---
include/net/dsa.h | 6 +++++
net/dsa/dsa.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index 2e05e4fd0b76..19f1338ac604 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -1249,6 +1249,12 @@ struct dsa_switch_ops {
u8 led, enum led_brightness value);
int (*led_blink_set)(struct dsa_switch *ds, int port, u8 led,
unsigned long *delay_on, unsigned long *delay_off);
+ int (*led_hw_control_is_supported)(struct dsa_switch *ds, int port,
+ u8 led, unsigned long flags);
+ int (*led_hw_control_set)(struct dsa_switch *ds, int port, u8 led,
+ unsigned long flags);
+ int (*led_hw_control_get)(struct dsa_switch *ds, int port, u8 led,
+ unsigned long *flags);
};
#define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index b13748f9b519..16e51020bc5e 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -492,6 +492,52 @@ static int dsa_led_blink_set(struct led_classdev *led_cdev,
delay_on, delay_off);
}
+static __maybe_unused int
+dsa_led_hw_control_is_supported(struct led_classdev *led_cdev,
+ unsigned long flags)
+{
+ struct dsa_led *dsa_led = to_dsa_led(led_cdev);
+ struct dsa_port *dp = dsa_led->dp;
+ struct dsa_switch *ds = dp->ds;
+
+ return ds->ops->led_hw_control_is_supported(ds, dp->index,
+ dsa_led->index,
+ flags);
+}
+
+static __maybe_unused int dsa_led_hw_control_set(struct led_classdev *led_cdev,
+ unsigned long flags)
+{
+ struct dsa_led *dsa_led = to_dsa_led(led_cdev);
+ struct dsa_port *dp = dsa_led->dp;
+ struct dsa_switch *ds = dp->ds;
+
+ return ds->ops->led_hw_control_set(ds, dp->index, dsa_led->index,
+ flags);
+}
+
+static __maybe_unused int dsa_led_hw_control_get(struct led_classdev *led_cdev,
+ unsigned long *flags)
+{
+ struct dsa_led *dsa_led = to_dsa_led(led_cdev);
+ struct dsa_port *dp = dsa_led->dp;
+ struct dsa_switch *ds = dp->ds;
+
+ return ds->ops->led_hw_control_get(ds, dp->index, dsa_led->index,
+ flags);
+}
+
+static struct device *
+dsa_led_hw_control_get_device(struct led_classdev *led_cdev)
+{
+ struct dsa_led *dsa_led = to_dsa_led(led_cdev);
+ struct dsa_port *dp = dsa_led->dp;
+
+ if (dp->user)
+ return &dp->user->dev;
+ return NULL;
+}
+
static int dsa_port_led_setup(struct dsa_port *dp,
struct device_node *led)
{
@@ -521,7 +567,16 @@ static int dsa_port_led_setup(struct dsa_port *dp,
cdev->brightness_set_blocking = dsa_led_brightness_set;
if (ds->ops->led_blink_set)
cdev->blink_set = dsa_led_blink_set;
-
+#ifdef CONFIG_LEDS_TRIGGERS
+ if (ds->ops->led_hw_control_is_supported)
+ cdev->hw_control_is_supported = dsa_led_hw_control_is_supported;
+ if (ds->ops->led_hw_control_set)
+ cdev->hw_control_set = dsa_led_hw_control_set;
+ if (ds->ops->led_hw_control_get)
+ cdev->hw_control_get = dsa_led_hw_control_get;
+ cdev->hw_control_trigger = "netdev";
+#endif
+ cdev->hw_control_get_device = dsa_led_hw_control_get_device;
cdev->max_brightness = 1;
init_data.fwnode = of_fwnode_handle(led);
--
2.42.0
Powered by blists - more mailing lists