kernel: add upstream patches for pca955x led driver
[openwrt/staging/dedeckeh.git] / target / linux / generic / backport-5.10 / 843-v5.15-leds-pca955x-let-the-core-process-the-fwnode.patch
1 From 7c4815929276b2e223eb6f2e49afe5071d4294a5 Mon Sep 17 00:00:00 2001
2 From: Eddie James <eajames@linux.ibm.com>
3 Date: Fri, 16 Jul 2021 17:03:30 -0500
4 Subject: [PATCH] leds: pca955x: Let the core process the fwnode
5
6 Much of the fwnode processing in the PCA955x driver is now in the
7 LEDs core driver, so pass the fwnode in the init data when
8 registering the LED device. In order to preserve the existing naming
9 scheme, check for an empty name and set it to the LED number.
10
11 Signed-off-by: Eddie James <eajames@linux.ibm.com>
12 Signed-off-by: Pavel Machek <pavel@ucw.cz>
13 ---
14 drivers/leds/leds-pca955x.c | 58 +++++++++++++++++++------------------
15 1 file changed, 30 insertions(+), 28 deletions(-)
16
17 diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
18 index fa1d77d86ef67b..a6aa4b9abde8c4 100644
19 --- a/drivers/leds/leds-pca955x.c
20 +++ b/drivers/leds/leds-pca955x.c
21 @@ -127,10 +127,9 @@ struct pca955x_led {
22 struct pca955x *pca955x;
23 struct led_classdev led_cdev;
24 int led_num; /* 0 .. 15 potentially */
25 - char name[32];
26 u32 type;
27 int default_state;
28 - const char *default_trigger;
29 + struct fwnode_handle *fwnode;
30 };
31
32 struct pca955x_platform_data {
33 @@ -439,7 +438,6 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
34 return ERR_PTR(-ENOMEM);
35
36 device_for_each_child_node(&client->dev, child) {
37 - const char *name;
38 const char *state;
39 u32 reg;
40 int res;
41 @@ -448,17 +446,10 @@ pca955x_get_pdata(struct i2c_client *client, struct pca955x_chipdef *chip)
42 if ((res != 0) || (reg >= chip->bits))
43 continue;
44
45 - res = fwnode_property_read_string(child, "label", &name);
46 - if ((res != 0) && is_of_node(child))
47 - name = to_of_node(child)->name;
48 -
49 led = &pdata->leds[reg];
50 - snprintf(led->name, sizeof(led->name), "%s", name);
51 -
52 led->type = PCA955X_TYPE_LED;
53 + led->fwnode = child;
54 fwnode_property_read_u32(child, "type", &led->type);
55 - fwnode_property_read_string(child, "linux,default-trigger",
56 - &led->default_trigger);
57
58 if (!fwnode_property_read_string(child, "default-state",
59 &state)) {
60 @@ -495,11 +486,14 @@ static int pca955x_probe(struct i2c_client *client,
61 struct pca955x_led *pca955x_led;
62 struct pca955x_chipdef *chip;
63 struct led_classdev *led;
64 + struct led_init_data init_data;
65 struct i2c_adapter *adapter;
66 int i, err;
67 struct pca955x_platform_data *pdata;
68 int ngpios = 0;
69 + bool set_default_label = false;
70 bool keep_pwm = false;
71 + char default_label[8];
72
73 chip = &pca955x_chipdefs[id->driver_data];
74 adapter = client->adapter;
75 @@ -547,6 +541,9 @@ static int pca955x_probe(struct i2c_client *client,
76 pca955x->client = client;
77 pca955x->chipdef = chip;
78
79 + init_data.devname_mandatory = false;
80 + init_data.devicename = "pca955x";
81 +
82 for (i = 0; i < chip->bits; i++) {
83 pca955x_led = &pca955x->leds[i];
84 pca955x_led->led_num = i;
85 @@ -560,23 +557,7 @@ static int pca955x_probe(struct i2c_client *client,
86 ngpios++;
87 break;
88 case PCA955X_TYPE_LED:
89 - /*
90 - * Platform data can specify LED names and
91 - * default triggers
92 - */
93 - if (pdata->leds[i].name[0] == '\0')
94 - snprintf(pdata->leds[i].name,
95 - sizeof(pdata->leds[i].name), "%d", i);
96 -
97 - snprintf(pca955x_led->name, sizeof(pca955x_led->name),
98 - "pca955x:%s", pdata->leds[i].name);
99 -
100 led = &pca955x_led->led_cdev;
101 - if (pdata->leds[i].default_trigger)
102 - led->default_trigger =
103 - pdata->leds[i].default_trigger;
104 -
105 - led->name = pca955x_led->name;
106 led->brightness_set_blocking = pca955x_led_set;
107 led->brightness_get = pca955x_led_get;
108
109 @@ -592,7 +573,28 @@ static int pca955x_probe(struct i2c_client *client,
110 return err;
111 }
112
113 - err = devm_led_classdev_register(&client->dev, led);
114 + init_data.fwnode = pdata->leds[i].fwnode;
115 +
116 + if (is_of_node(init_data.fwnode)) {
117 + if (to_of_node(init_data.fwnode)->name[0] ==
118 + '\0')
119 + set_default_label = true;
120 + else
121 + set_default_label = false;
122 + } else {
123 + set_default_label = true;
124 + }
125 +
126 + if (set_default_label) {
127 + snprintf(default_label, sizeof(default_label),
128 + "%d", i);
129 + init_data.default_label = default_label;
130 + } else {
131 + init_data.default_label = NULL;
132 + }
133 +
134 + err = devm_led_classdev_register_ext(&client->dev, led,
135 + &init_data);
136 if (err)
137 return err;
138