kernel: bump 5.10 to 5.10.124
[openwrt/openwrt.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 --- a/drivers/leds/leds-pca955x.c
18 +++ b/drivers/leds/leds-pca955x.c
19 @@ -127,10 +127,9 @@ struct pca955x_led {
20 struct pca955x *pca955x;
21 struct led_classdev led_cdev;
22 int led_num; /* 0 .. 15 potentially */
23 - char name[32];
24 u32 type;
25 int default_state;
26 - const char *default_trigger;
27 + struct fwnode_handle *fwnode;
28 };
29
30 struct pca955x_platform_data {
31 @@ -439,7 +438,6 @@ pca955x_get_pdata(struct i2c_client *cli
32 return ERR_PTR(-ENOMEM);
33
34 device_for_each_child_node(&client->dev, child) {
35 - const char *name;
36 const char *state;
37 u32 reg;
38 int res;
39 @@ -448,17 +446,10 @@ pca955x_get_pdata(struct i2c_client *cli
40 if ((res != 0) || (reg >= chip->bits))
41 continue;
42
43 - res = fwnode_property_read_string(child, "label", &name);
44 - if ((res != 0) && is_of_node(child))
45 - name = to_of_node(child)->name;
46 -
47 led = &pdata->leds[reg];
48 - snprintf(led->name, sizeof(led->name), "%s", name);
49 -
50 led->type = PCA955X_TYPE_LED;
51 + led->fwnode = child;
52 fwnode_property_read_u32(child, "type", &led->type);
53 - fwnode_property_read_string(child, "linux,default-trigger",
54 - &led->default_trigger);
55
56 if (!fwnode_property_read_string(child, "default-state",
57 &state)) {
58 @@ -495,11 +486,14 @@ static int pca955x_probe(struct i2c_clie
59 struct pca955x_led *pca955x_led;
60 struct pca955x_chipdef *chip;
61 struct led_classdev *led;
62 + struct led_init_data init_data;
63 struct i2c_adapter *adapter;
64 int i, err;
65 struct pca955x_platform_data *pdata;
66 int ngpios = 0;
67 + bool set_default_label = false;
68 bool keep_pwm = false;
69 + char default_label[8];
70
71 chip = &pca955x_chipdefs[id->driver_data];
72 adapter = client->adapter;
73 @@ -547,6 +541,9 @@ static int pca955x_probe(struct i2c_clie
74 pca955x->client = client;
75 pca955x->chipdef = chip;
76
77 + init_data.devname_mandatory = false;
78 + init_data.devicename = "pca955x";
79 +
80 for (i = 0; i < chip->bits; i++) {
81 pca955x_led = &pca955x->leds[i];
82 pca955x_led->led_num = i;
83 @@ -560,23 +557,7 @@ static int pca955x_probe(struct i2c_clie
84 ngpios++;
85 break;
86 case PCA955X_TYPE_LED:
87 - /*
88 - * Platform data can specify LED names and
89 - * default triggers
90 - */
91 - if (pdata->leds[i].name[0] == '\0')
92 - snprintf(pdata->leds[i].name,
93 - sizeof(pdata->leds[i].name), "%d", i);
94 -
95 - snprintf(pca955x_led->name, sizeof(pca955x_led->name),
96 - "pca955x:%s", pdata->leds[i].name);
97 -
98 led = &pca955x_led->led_cdev;
99 - if (pdata->leds[i].default_trigger)
100 - led->default_trigger =
101 - pdata->leds[i].default_trigger;
102 -
103 - led->name = pca955x_led->name;
104 led->brightness_set_blocking = pca955x_led_set;
105 led->brightness_get = pca955x_led_get;
106
107 @@ -592,7 +573,28 @@ static int pca955x_probe(struct i2c_clie
108 return err;
109 }
110
111 - err = devm_led_classdev_register(&client->dev, led);
112 + init_data.fwnode = pdata->leds[i].fwnode;
113 +
114 + if (is_of_node(init_data.fwnode)) {
115 + if (to_of_node(init_data.fwnode)->name[0] ==
116 + '\0')
117 + set_default_label = true;
118 + else
119 + set_default_label = false;
120 + } else {
121 + set_default_label = true;
122 + }
123 +
124 + if (set_default_label) {
125 + snprintf(default_label, sizeof(default_label),
126 + "%d", i);
127 + init_data.default_label = default_label;
128 + } else {
129 + init_data.default_label = NULL;
130 + }
131 +
132 + err = devm_led_classdev_register_ext(&client->dev, led,
133 + &init_data);
134 if (err)
135 return err;
136