mirror of
https://github.com/openwrt/openwrt.git
synced 2025-03-23 04:25:21 +00:00
kernel: ar8327: support LED device tree bindings
The ar8216 switch driver supports exposing configuration of AR8327 and AR8337 switch LEDs to the userspace, however it is only configurable through platform data, causing the devices ported from ar71xx target to lack the support. Since there is still a long way to go until we can migrate the target to qca8k, an interim solution is needed. Extend ar8327_hw_config_of function to parse a "leds" subnode, which will populate the missing platform data based on device tree contents, and restore the existing support for the LEDs. Standard bindings apply, mapping "reg" property to LED index, with addition of "qca,led-mode" property, which selects HW (0) or SW (1) mode, defaulting to HW mode. Signed-off-by: Lech Perczak <lech.perczak@gmail.com> Link: https://github.com/openwrt/openwrt/pull/12487 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
This commit is contained in:
parent
5a4f8b26f0
commit
3ba4a4e32c
target/linux/generic/files
@ -392,8 +392,11 @@ static int
|
||||
ar8327_led_register(struct ar8327_led *aled)
|
||||
{
|
||||
int ret;
|
||||
struct led_init_data init_data = {
|
||||
.fwnode = aled->fwnode
|
||||
};
|
||||
|
||||
ret = led_classdev_register(NULL, &aled->cdev);
|
||||
ret = led_classdev_register_ext(NULL, &aled->cdev, &init_data);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
@ -447,6 +450,7 @@ ar8327_led_create(struct ar8xxx_priv *priv,
|
||||
aled->led_num = led_info->led_num;
|
||||
aled->active_low = led_info->active_low;
|
||||
aled->mode = led_info->mode;
|
||||
aled->fwnode = led_info->fwnode;
|
||||
|
||||
if (aled->mode == AR8327_LED_MODE_HW)
|
||||
aled->enable_hw_mode = true;
|
||||
@ -616,6 +620,7 @@ ar8327_hw_config_of(struct ar8xxx_priv *priv, struct device_node *np)
|
||||
const __be32 *paddr;
|
||||
int len;
|
||||
int i;
|
||||
struct device_node *leds, *child;
|
||||
|
||||
paddr = of_get_property(np, "qca,ar8327-initvals", &len);
|
||||
if (!paddr || len < (2 * sizeof(*paddr)))
|
||||
@ -643,6 +648,39 @@ ar8327_hw_config_of(struct ar8xxx_priv *priv, struct device_node *np)
|
||||
}
|
||||
}
|
||||
|
||||
leds = of_get_child_by_name(np, "leds");
|
||||
if (!leds)
|
||||
return 0;
|
||||
|
||||
data->leds = kvcalloc(of_get_child_count(leds), sizeof(void *),
|
||||
GFP_KERNEL);
|
||||
if (!data->leds)
|
||||
return -ENOMEM;
|
||||
|
||||
for_each_available_child_of_node(leds, child) {
|
||||
u32 reg = 0, mode = 0;
|
||||
struct ar8327_led_info info;
|
||||
int ret;
|
||||
|
||||
ret = of_property_read_u32(child, "reg", ®);
|
||||
if (ret) {
|
||||
pr_err("ar8327: LED %s is missing reg node\n", child->name);
|
||||
continue;
|
||||
}
|
||||
|
||||
of_property_read_u32(child, "qca,led-mode", &mode);
|
||||
|
||||
info = (struct ar8327_led_info) {
|
||||
.name = of_get_property(child, "label", NULL) ? : child->name,
|
||||
.fwnode = of_fwnode_handle(child),
|
||||
.active_low = of_property_read_bool(child, "active-low"),
|
||||
.led_num = (enum ar8327_led_num) reg,
|
||||
.mode = (enum ar8327_led_mode) mode
|
||||
};
|
||||
ar8327_led_create(priv, &info);
|
||||
}
|
||||
|
||||
of_node_put(leds);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
@ -317,6 +317,7 @@ struct ar8327_led {
|
||||
struct work_struct led_work;
|
||||
bool enable_hw_mode;
|
||||
enum ar8327_led_pattern pattern;
|
||||
struct fwnode_handle *fwnode;
|
||||
};
|
||||
|
||||
struct ar8327_data {
|
||||
|
@ -106,6 +106,7 @@ struct ar8327_led_info {
|
||||
bool active_low;
|
||||
enum ar8327_led_num led_num;
|
||||
enum ar8327_led_mode mode;
|
||||
struct fwnode_handle *fwnode;
|
||||
};
|
||||
|
||||
#define AR8327_LED_INFO(_led, _mode, _name) { \
|
||||
|
Loading…
x
Reference in New Issue
Block a user