kernel: add upstream patches for pca955x led driver
[openwrt/staging/hauke.git] / target / linux / generic / backport-5.10 / 844-v5.15-leds-pca955x-switch-to-i2c-probe-new.patch
1 From 239f32b4f161c1584cd4b386d6ab8766432a6ede Mon Sep 17 00:00:00 2001
2 From: Eddie James <eajames@linux.ibm.com>
3 Date: Fri, 16 Jul 2021 17:03:31 -0500
4 Subject: [PATCH] leds: pca955x: Switch to i2c probe_new
5
6 The deprecated i2c probe functionality doesn't work with OF
7 compatible strings, as it only checks for the i2c device id. Switch
8 to the new way of probing and grab the match data to select the
9 chip type.
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 | 23 +++++++++++++++++++----
15 1 file changed, 19 insertions(+), 4 deletions(-)
16
17 diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
18 index a6aa4b9abde8c4..a6b5699aeae4fe 100644
19 --- a/drivers/leds/leds-pca955x.c
20 +++ b/drivers/leds/leds-pca955x.c
21 @@ -479,8 +479,7 @@ static const struct of_device_id of_pca955x_match[] = {
22 };
23 MODULE_DEVICE_TABLE(of, of_pca955x_match);
24
25 -static int pca955x_probe(struct i2c_client *client,
26 - const struct i2c_device_id *id)
27 +static int pca955x_probe(struct i2c_client *client)
28 {
29 struct pca955x *pca955x;
30 struct pca955x_led *pca955x_led;
31 @@ -494,8 +493,24 @@ static int pca955x_probe(struct i2c_client *client,
32 bool set_default_label = false;
33 bool keep_pwm = false;
34 char default_label[8];
35 + enum pca955x_type chip_type;
36 + const void *md = device_get_match_data(&client->dev);
37
38 - chip = &pca955x_chipdefs[id->driver_data];
39 + if (md) {
40 + chip_type = (enum pca955x_type)md;
41 + } else {
42 + const struct i2c_device_id *id = i2c_match_id(pca955x_id,
43 + client);
44 +
45 + if (id) {
46 + chip_type = (enum pca955x_type)id->driver_data;
47 + } else {
48 + dev_err(&client->dev, "unknown chip\n");
49 + return -ENODEV;
50 + }
51 + }
52 +
53 + chip = &pca955x_chipdefs[chip_type];
54 adapter = client->adapter;
55 pdata = dev_get_platdata(&client->dev);
56 if (!pdata) {
57 @@ -670,7 +685,7 @@ static struct i2c_driver pca955x_driver = {
58 .name = "leds-pca955x",
59 .of_match_table = of_pca955x_match,
60 },
61 - .probe = pca955x_probe,
62 + .probe_new = pca955x_probe,
63 .id_table = pca955x_id,
64 };