mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-21 22:47:56 +00:00
0a4b309f41
Backport initial LEDs hw control support. Currently this is limited to only rx/tx and link events for the netdev trigger but the API got accepted and the additional modes are working on and will be backported later. Refresh every patch and add the additional config flag for QCA8K new LEDs support. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
150 lines
4.5 KiB
Diff
150 lines
4.5 KiB
Diff
From bdec9cb83936e0ac4cb87fed5b49fad0175f7dec Mon Sep 17 00:00:00 2001
|
|
From: Christian Marangi <ansuelsmth@gmail.com>
|
|
Date: Wed, 19 Apr 2023 23:07:41 +0200
|
|
Subject: [PATCH 3/5] leds: trigger: netdev: Rename add namespace to netdev
|
|
trigger enum modes
|
|
|
|
Rename NETDEV trigger enum modes to a more symbolic name and add a
|
|
namespace to them.
|
|
|
|
Also add __TRIGGER_NETDEV_MAX to identify the max modes of the netdev
|
|
trigger.
|
|
|
|
This is a cleanup to drop the define and no behaviour change are
|
|
intended.
|
|
|
|
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
|
|
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
|
|
Signed-off-by: Lee Jones <lee@kernel.org>
|
|
Link: https://lore.kernel.org/r/20230419210743.3594-4-ansuelsmth@gmail.com
|
|
---
|
|
drivers/leds/trigger/ledtrig-netdev.c | 58 ++++++++++++---------------
|
|
1 file changed, 25 insertions(+), 33 deletions(-)
|
|
|
|
--- a/drivers/leds/trigger/ledtrig-netdev.c
|
|
+++ b/drivers/leds/trigger/ledtrig-netdev.c
|
|
@@ -51,15 +51,15 @@ struct led_netdev_data {
|
|
|
|
unsigned long mode;
|
|
bool carrier_link_up;
|
|
-#define NETDEV_LED_LINK 0
|
|
-#define NETDEV_LED_TX 1
|
|
-#define NETDEV_LED_RX 2
|
|
};
|
|
|
|
-enum netdev_led_attr {
|
|
- NETDEV_ATTR_LINK,
|
|
- NETDEV_ATTR_TX,
|
|
- NETDEV_ATTR_RX
|
|
+enum led_trigger_netdev_modes {
|
|
+ TRIGGER_NETDEV_LINK = 0,
|
|
+ TRIGGER_NETDEV_TX,
|
|
+ TRIGGER_NETDEV_RX,
|
|
+
|
|
+ /* Keep last */
|
|
+ __TRIGGER_NETDEV_MAX,
|
|
};
|
|
|
|
static void set_baseline_state(struct led_netdev_data *trigger_data)
|
|
@@ -76,7 +76,7 @@ static void set_baseline_state(struct le
|
|
if (!trigger_data->carrier_link_up) {
|
|
led_set_brightness(led_cdev, LED_OFF);
|
|
} else {
|
|
- if (test_bit(NETDEV_LED_LINK, &trigger_data->mode))
|
|
+ if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode))
|
|
led_set_brightness(led_cdev,
|
|
led_cdev->blink_brightness);
|
|
else
|
|
@@ -85,8 +85,8 @@ static void set_baseline_state(struct le
|
|
/* If we are looking for RX/TX start periodically
|
|
* checking stats
|
|
*/
|
|
- if (test_bit(NETDEV_LED_TX, &trigger_data->mode) ||
|
|
- test_bit(NETDEV_LED_RX, &trigger_data->mode))
|
|
+ if (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ||
|
|
+ test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode))
|
|
schedule_delayed_work(&trigger_data->work, 0);
|
|
}
|
|
}
|
|
@@ -146,20 +146,16 @@ static ssize_t device_name_store(struct
|
|
static DEVICE_ATTR_RW(device_name);
|
|
|
|
static ssize_t netdev_led_attr_show(struct device *dev, char *buf,
|
|
- enum netdev_led_attr attr)
|
|
+ enum led_trigger_netdev_modes attr)
|
|
{
|
|
struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
|
|
int bit;
|
|
|
|
switch (attr) {
|
|
- case NETDEV_ATTR_LINK:
|
|
- bit = NETDEV_LED_LINK;
|
|
- break;
|
|
- case NETDEV_ATTR_TX:
|
|
- bit = NETDEV_LED_TX;
|
|
- break;
|
|
- case NETDEV_ATTR_RX:
|
|
- bit = NETDEV_LED_RX;
|
|
+ case TRIGGER_NETDEV_LINK:
|
|
+ case TRIGGER_NETDEV_TX:
|
|
+ case TRIGGER_NETDEV_RX:
|
|
+ bit = attr;
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
@@ -169,7 +165,7 @@ static ssize_t netdev_led_attr_show(stru
|
|
}
|
|
|
|
static ssize_t netdev_led_attr_store(struct device *dev, const char *buf,
|
|
- size_t size, enum netdev_led_attr attr)
|
|
+ size_t size, enum led_trigger_netdev_modes attr)
|
|
{
|
|
struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
|
|
unsigned long state;
|
|
@@ -181,14 +177,10 @@ static ssize_t netdev_led_attr_store(str
|
|
return ret;
|
|
|
|
switch (attr) {
|
|
- case NETDEV_ATTR_LINK:
|
|
- bit = NETDEV_LED_LINK;
|
|
- break;
|
|
- case NETDEV_ATTR_TX:
|
|
- bit = NETDEV_LED_TX;
|
|
- break;
|
|
- case NETDEV_ATTR_RX:
|
|
- bit = NETDEV_LED_RX;
|
|
+ case TRIGGER_NETDEV_LINK:
|
|
+ case TRIGGER_NETDEV_TX:
|
|
+ case TRIGGER_NETDEV_RX:
|
|
+ bit = attr;
|
|
break;
|
|
default:
|
|
return -EINVAL;
|
|
@@ -360,21 +352,21 @@ static void netdev_trig_work(struct work
|
|
}
|
|
|
|
/* If we are not looking for RX/TX then return */
|
|
- if (!test_bit(NETDEV_LED_TX, &trigger_data->mode) &&
|
|
- !test_bit(NETDEV_LED_RX, &trigger_data->mode))
|
|
+ if (!test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) &&
|
|
+ !test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode))
|
|
return;
|
|
|
|
dev_stats = dev_get_stats(trigger_data->net_dev, &temp);
|
|
new_activity =
|
|
- (test_bit(NETDEV_LED_TX, &trigger_data->mode) ?
|
|
+ (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ?
|
|
dev_stats->tx_packets : 0) +
|
|
- (test_bit(NETDEV_LED_RX, &trigger_data->mode) ?
|
|
+ (test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode) ?
|
|
dev_stats->rx_packets : 0);
|
|
|
|
if (trigger_data->last_activity != new_activity) {
|
|
led_stop_software_blink(trigger_data->led_cdev);
|
|
|
|
- invert = test_bit(NETDEV_LED_LINK, &trigger_data->mode);
|
|
+ invert = test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode);
|
|
interval = jiffies_to_msecs(
|
|
atomic_read(&trigger_data->interval));
|
|
/* base state is ON (link present) */
|