Skip to contentSkip to conversation

Use i2c_get_match_data()

PATCH In review Biju Das 4 participants 15 messages Jul 16, 2023 – Jul 22, 2023

Subsystems (5)
lore
Share & tools
lore

Biju Das

author
#0 lore raw

cover Use i2c_get_match_data()

Use i2c_get_match_data() to get match data for I2C, ACPI and DT-based matching.

This patch series is only compile tested.

Biju Das (4):
iio: accel: adxl355: Simplify probe()
iio: accel: adxl313: Use i2c_get_match_data
iio: potentiometer: mcp4531: Use i2c_get_match_data
iio: potentiometer: mcp4018: Use i2c_get_match_data

 drivers/iio/accel/adxl313_i2c.c     |  4 ++--
 drivers/iio/accel/adxl355_i2c.c     | 15 +++------------
 drivers/iio/potentiometer/mcp4018.c |  4 ++--
 drivers/iio/potentiometer/mcp4531.c |  4 ++--
 4 files changed, 9 insertions(+), 18 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/4 iio: accel: adxl355: Simplify probe()

Simplify the probe() by replacing of_device_get_match_data() and i2c_match_id() by i2c_get_match_data() as we have similar I2C and DT-based matching table.

---
 drivers/iio/accel/adxl355_i2c.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/iio/accel/adxl355_i2c.c +3 -12
index d5beea61479d..32398cde9608 100644
@@ -24,19 +24,10 @@ static int adxl355_i2c_probe(struct i2c_client *client)
 {
 	struct regmap *regmap;
 	const struct adxl355_chip_info *chip_data;
-	const struct i2c_device_id *adxl355;
 
-	chip_data = device_get_match_data(&client->dev);
-	if (!chip_data) {
-		adxl355 = to_i2c_driver(client->dev.driver)->id_table;
-		if (!adxl355)
-			return -EINVAL;
-
-		chip_data = (void *)i2c_match_id(adxl355, client)->driver_data;
-
-		if (!chip_data)
-			return -EINVAL;
-	}
+	chip_data = i2c_get_match_data(client);
+	if (!chip_data)
+		return -ENODEV;
 
 	regmap = devm_regmap_init_i2c(client, &adxl355_i2c_regmap_config);
 	if (IS_ERR(regmap)) {
Signature · 1 line
2.25.1
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] iio: accel: adxl355: Simplify probe()

Quoted 5 lines · Biju Das

Simplify the probe() by replacing of_device_get_match_data() and i2c_match_id() by i2c_get_match_data() as we have similar I2C and DT-based matching table.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Reviewed-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] iio: accel: adxl355: Simplify probe()

In reply to Biju Das
Quoted 38 lines · Biju Das

Simplify the probe() by replacing of_device_get_match_data() and i2c_match_id() by i2c_get_match_data() as we have similar I2C and DT-based matching table.

---
 drivers/iio/accel/adxl355_i2c.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/iio/accel/adxl355_i2c.c +3 -13
index d5beea61479d..32398cde9608 100644
@@ -24,19 +24,10 @@ static int adxl355_i2c_probe(struct i2c_client *client)
 {
        struct regmap *regmap;
        const struct adxl355_chip_info *chip_data;
-       const struct i2c_device_id *adxl355;
 
-       chip_data = device_get_match_data(&client->dev);
-       if (!chip_data) {
-               adxl355 = to_i2c_driver(client->dev.driver)->id_table;
-               if (!adxl355)
-                       return -EINVAL;
-
-               chip_data = (void *)i2c_match_id(adxl355, client)->driver_data;
-
-               if (!chip_data)
-                       return -EINVAL;
-       }
+       chip_data = i2c_get_match_data(client);
+       if (!chip_data)
+               return -ENODEV;
 
        regmap = devm_regmap_init_i2c(client, &adxl355_i2c_regmap_config);
        if (IS_ERR(regmap)) {
--
Quoted 2 lines

2.25.1

maintainer
#4 lore raw

Re: [PATCH 1/4] iio: accel: adxl355: Simplify probe()

In reply to Biju Das
Quoted 5 lines · On Sun, 16 Jul 2023 18:52:15 +0100 Biju Das <[email protected]> wrote:

Simplify the probe() by replacing of_device_get_match_data() and i2c_match_id() by i2c_get_match_data() as we have similar I2C and DT-based matching table.

Applied to the togreg branch of iio.git, initially pushed out as testing for 0-day to take a look at.

Thanks,

Jonathan

Quoted 31 lines
---
 drivers/iio/accel/adxl355_i2c.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/iio/accel/adxl355_i2c.c +3 -12
index d5beea61479d..32398cde9608 100644
@@ -24,19 +24,10 @@ static int adxl355_i2c_probe(struct i2c_client *client)
 {
 	struct regmap *regmap;
 	const struct adxl355_chip_info *chip_data;
-	const struct i2c_device_id *adxl355;
 
-	chip_data = device_get_match_data(&client->dev);
-	if (!chip_data) {
-		adxl355 = to_i2c_driver(client->dev.driver)->id_table;
-		if (!adxl355)
-			return -EINVAL;
-
-		chip_data = (void *)i2c_match_id(adxl355, client)->driver_data;
-
-		if (!chip_data)
-			return -EINVAL;
-	}
+	chip_data = i2c_get_match_data(client);
+	if (!chip_data)
+		return -ENODEV;
 
 	regmap = devm_regmap_init_i2c(client, &adxl355_i2c_regmap_config);
 	if (IS_ERR(regmap)) {
author
#5 lore raw

PATCH 2/4 iio: accel: adxl313: Use i2c_get_match_data

In reply to Biju Das

Replace of_device_get_match_data() and i2c_match_id() by i2c_get_match _data() as we have similar I2C and DT-based matching table.

---
 drivers/iio/accel/adxl313_i2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/accel/adxl313_i2c.c +2 -2
index 524327ea3663..6d252190207b 100644
@@ -65,9 +65,9 @@ static int adxl313_i2c_probe(struct i2c_client *client)
 	 * Retrieves device specific data as a pointer to a
 	 * adxl313_chip_info structure
 	 */
-	chip_data = device_get_match_data(&client->dev);
+	chip_data = i2c_get_match_data(client);
 	if (!chip_data)
-		chip_data = (const struct adxl313_chip_info *)i2c_match_id(adxl313_i2c_id, client)->driver_data;
+		return -ENODEV;
 
 	regmap = devm_regmap_init_i2c(client,
 				      &adxl31x_i2c_regmap_config[chip_data->type]);
Signature · 1 line
2.25.1
Reviewed-by on v1 2/4
#6 lore raw

Re: [PATCH 2/4] iio: accel: adxl313: Use i2c_get_match_data

Quoted 4 lines · Biju Das

Replace of_device_get_match_data() and i2c_match_id() by i2c_get_match _data() as we have similar I2C and DT-based matching table.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
maintainer
#7 lore raw

Re: [PATCH 2/4] iio: accel: adxl313: Use i2c_get_match_data

In reply to Biju Das
Quoted 14 lines · On Sun, 16 Jul 2023 18:52:16 +0100 Biju Das <[email protected]> wrote:

Replace of_device_get_match_data() and i2c_match_id() by i2c_get_match _data() as we have similar I2C and DT-based matching table.

---
 drivers/iio/accel/adxl313_i2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/accel/adxl313_i2c.c +0 -0
index 524327ea3663..6d252190207b 100644
@@ -65,9 +65,9 @@ static int adxl313_i2c_probe(struct i2c_client *client)
 	 * Retrieves device specific data as a pointer to a

drivers/iio/accel/adxl313_i2c.c static int adxl313_i2c_probe(struct i2c_client *client) · line 73

Quoted 10 lines
drivers/iio/accel/adxl313_i2c.c +2 -2
 	 * adxl313_chip_info structure
 	 */
-	chip_data = device_get_match_data(&client->dev);
+	chip_data = i2c_get_match_data(client);
 	if (!chip_data)
-		chip_data = (const struct adxl313_chip_info *)i2c_match_id(adxl313_i2c_id, client)->driver_data;
+		return -ENODEV;
 
 	regmap = devm_regmap_init_i2c(client,
 				      &adxl31x_i2c_regmap_config[chip_data->type]);

This driver looks buggy:

static const struct i2c_device_id adxl313_i2c_id[] = {
	{ .name = "adxl312", .driver_data = (kernel_ulong_t)&adxl31x_chip_info[ADXL312] },
	{ .name = "adxl313", .driver_data = (kernel_ulong_t)&adxl31x_chip_info[ADXL312] },
	{ .name = "adxl314", .driver_data = (kernel_ulong_t)&adxl31x_chip_info[ADXL312] },
	{ }
};

MODULE_DEVICE_TABLE(i2c, adxl313_i2c_id);

static const struct of_device_id adxl313_of_match[] = {
	{ .compatible = "adi,adxl312", .data = &adxl31x_chip_info[ADXL312] },
	{ .compatible = "adi,adxl313", .data = &adxl31x_chip_info[ADXL313] },
	{ .compatible = "adi,adxl314", .data = &adxl31x_chip_info[ADXL314] },
	{ }
};

Odd that the i2c_device_id table always uses ADXL312

That would only have previously applied if we failed to match on the of one (which only happens in somewhat obscure cases)

Can we fix that first then apply this cleanup on top?

Thanks,

Jonathan

author
#8 lore raw

RE: [PATCH 2/4] iio: accel: adxl313: Use i2c_get_match_data

Hi Jonathan Cameron,

Quoted 68 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Saturday, July 22, 2023 5:29 PM
To: Biju Das <[email protected]>
Cc: Lars-Peter Clausen <[email protected]>; Michael Hennerich <[email protected]>; Lucas Stankus <[email protected]>; [email protected]; Geert Uytterhoeven <[email protected]>; Prabhakar Mahadev Lad <[email protected]>; linux-renesas- [email protected]
Subject: Re: [PATCH 2/4] iio: accel: adxl313: Use i2c_get_match_data

drivers/iio/accel/adxl313_i2c.c static int adxl313_i2c_probe(struct i2c_client

Quoted 14 lines · On Sun, 16 Jul 2023 18:52:16 +0100 Biju Das <[email protected]> wrote:

Replace of_device_get_match_data() and i2c_match_id() by i2c_get_match _data() as we have similar I2C and DT-based matching table.

---
 drivers/iio/accel/adxl313_i2c.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/iio/accel/adxl313_i2c.c index 524327ea3663..6d252190207b 100644

drivers/iio/accel/adxl313_i2c.c +0 -0
@@ -65,9 +65,9 @@ static int adxl313_i2c_probe(struct i2c_client

*client)

drivers/iio/accel/adxl313_i2c.c static int adxl313_i2c_probe(struct i2c_client *client)

Quoted 7 lines
drivers/iio/accel/adxl313_i2c.c +1 -2
 	 * Retrieves device specific data as a pointer to a
 	 * adxl313_chip_info structure
 	 */
-	chip_data = device_get_match_data(&client->dev);
+	chip_data = i2c_get_match_data(client);
 	if (!chip_data)
-		chip_data = (const struct adxl313_chip_info

*)i2c_match_id(adxl313_i2c_id, client)->driver_data;

Quoted 5 lines
drivers/iio/accel/adxl313_i2c.c +1 -0
+		return -ENODEV;
 
 	regmap = devm_regmap_init_i2c(client,
 				      &adxl31x_i2c_regmap_config[chip_data-

type]);

This driver looks buggy:

static const struct i2c_device_id adxl313_i2c_id[] = {
	{ .name = "adxl312", .driver_data =
(kernel_ulong_t)&adxl31x_chip_info[ADXL312] },
	{ .name = "adxl313", .driver_data =
(kernel_ulong_t)&adxl31x_chip_info[ADXL312] },
	{ .name = "adxl314", .driver_data =
(kernel_ulong_t)&adxl31x_chip_info[ADXL312] },
	{ }
};

MODULE_DEVICE_TABLE(i2c, adxl313_i2c_id);

static const struct of_device_id adxl313_of_match[] = {
	{ .compatible = "adi,adxl312", .data = &adxl31x_chip_info[ADXL312]
},
	{ .compatible = "adi,adxl313", .data = &adxl31x_chip_info[ADXL313]
},
	{ .compatible = "adi,adxl314", .data = &adxl31x_chip_info[ADXL314]
},
	{ }
};
Quoted 6 lines

Odd that the i2c_device_id table always uses ADXL312

That would only have previously applied if we failed to match on the of one (which only happens in somewhat obscure cases)

Can we fix that first then apply this cleanup on top?

Sure. Will send V2.

Cheers,
Biju

author
#9 lore raw

PATCH 3/4 iio: potentiometer: mcp4531: Use i2c_get_match_data

In reply to Biju Das

Replace of_device_get_match_data() and i2c_match_id() by i2c_get_match _data() as we have similar I2C and DT-based matching table.

---
 drivers/iio/potentiometer/mcp4531.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/potentiometer/mcp4531.c +2 -2
index c513c00c8243..08e7af710e1f 100644
@@ -368,9 +368,9 @@ static int mcp4531_probe(struct i2c_client *client)
 	i2c_set_clientdata(client, indio_dev);
 	data->client = client;
 
-	data->cfg = device_get_match_data(dev);
+	data->cfg = i2c_get_match_data(client);
 	if (!data->cfg)
-		data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)->driver_data];
+		return -ENODEV;
 
 	indio_dev->info = &mcp4531_info;
 	indio_dev->channels = mcp4531_channels;
Signature · 1 line
2.25.1
author
#10 lore raw

RE: [PATCH 3/4] iio: potentiometer: mcp4531: Use i2c_get_match_data

Hi all,

I would like to drop this patch, as this driver does not have similar I2C and DT-based matching table.

Cheers,
Biju

Quoted 38 lines

-----Original Message-----
From: Biju Das <[email protected]>
Sent: Sunday, July 16, 2023 6:52 PM
To: Peter Rosin <[email protected]>; Jonathan Cameron <[email protected]>
Cc: Biju Das <[email protected]>; Lars-Peter Clausen <[email protected]>; [email protected]; Geert Uytterhoeven <[email protected]>; Prabhakar Mahadev Lad <prabhakar.mahadev- [email protected]>; [email protected]
Subject: [PATCH 3/4] iio: potentiometer: mcp4531: Use i2c_get_match_data

Replace of_device_get_match_data() and i2c_match_id() by i2c_get_match _data() as we have similar I2C and DT-based matching table.

---
 drivers/iio/potentiometer/mcp4531.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/potentiometer/mcp4531.c +2 -2
index c513c00c8243..08e7af710e1f 100644
@@ -368,9 +368,9 @@ static int mcp4531_probe(struct i2c_client *client)
 	i2c_set_clientdata(client, indio_dev);
 	data->client = client;
 
-	data->cfg = device_get_match_data(dev);
+	data->cfg = i2c_get_match_data(client);
 	if (!data->cfg)
-		data->cfg = &mcp4531_cfg[i2c_match_id(mcp4531_id, client)-
 >driver_data];
+		return -ENODEV;
 
 	indio_dev->info = &mcp4531_info;

indio_dev->channels = mcp4531_channels;
--
2.25.1

author
#11 lore raw

PATCH 4/4 iio: potentiometer: mcp4018: Use i2c_get_match_data

In reply to Biju Das

Replace of_device_get_match_data() and i2c_match_id() by i2c_get_match _data() as we have similar I2C and DT-based matching table.

---
 drivers/iio/potentiometer/mcp4018.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/potentiometer/mcp4018.c +2 -2
index 89daecc90305..a5d902845a1c 100644
@@ -157,9 +157,9 @@ static int mcp4018_probe(struct i2c_client *client)
 	i2c_set_clientdata(client, indio_dev);
 	data->client = client;
 
-	data->cfg = device_get_match_data(dev);
+	data->cfg = i2c_get_match_data(dev);
 	if (!data->cfg)
-		data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)->driver_data];
+		return -ENODEV;
 
 	indio_dev->info = &mcp4018_info;
 	indio_dev->channels = &mcp4018_channel;
Signature · 1 line
2.25.1
author
#12 lore raw

RE: [PATCH 4/4] iio: potentiometer: mcp4018: Use i2c_get_match_data

Hi All,

I would like to drop this patch, as this driver does not have similar I2C and DT-based matching table.

Cheers,
Biju

Quoted 38 lines

-----Original Message-----
From: Biju Das <[email protected]>
Sent: Sunday, July 16, 2023 6:52 PM
To: Peter Rosin <[email protected]>; Jonathan Cameron <[email protected]>
Cc: Biju Das <[email protected]>; Lars-Peter Clausen <[email protected]>; [email protected]; Geert Uytterhoeven <[email protected]>; Prabhakar Mahadev Lad <prabhakar.mahadev- [email protected]>; [email protected]
Subject: [PATCH 4/4] iio: potentiometer: mcp4018: Use i2c_get_match_data

Replace of_device_get_match_data() and i2c_match_id() by i2c_get_match _data() as we have similar I2C and DT-based matching table.

---
 drivers/iio/potentiometer/mcp4018.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/potentiometer/mcp4018.c +2 -2
index 89daecc90305..a5d902845a1c 100644
@@ -157,9 +157,9 @@ static int mcp4018_probe(struct i2c_client *client)
 	i2c_set_clientdata(client, indio_dev);
 	data->client = client;
 
-	data->cfg = device_get_match_data(dev);
+	data->cfg = i2c_get_match_data(dev);
 	if (!data->cfg)
-		data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)-
 >driver_data];
+		return -ENODEV;
 
 	indio_dev->info = &mcp4018_info;

indio_dev->channels = &mcp4018_channel;
--
2.25.1

maintainer
#13 lore raw

Re: [PATCH 4/4] iio: potentiometer: mcp4018: Use i2c_get_match_data

Quoted 4 lines · On Sun, 16 Jul 2023 18:10:13 +0000 Biju Das <[email protected]> wrote:

Hi All,

I would like to drop this patch, as this driver does not have similar I2C and DT-based matching table.

Could make it so they do ;)

Jonathan

Quoted 43 lines

Cheers,
Biju

Quoted 38 lines

-----Original Message-----
From: Biju Das <[email protected]>
Sent: Sunday, July 16, 2023 6:52 PM
To: Peter Rosin <[email protected]>; Jonathan Cameron <[email protected]>
Cc: Biju Das <[email protected]>; Lars-Peter Clausen <[email protected]>; [email protected]; Geert Uytterhoeven <[email protected]>; Prabhakar Mahadev Lad <prabhakar.mahadev- [email protected]>; [email protected]
Subject: [PATCH 4/4] iio: potentiometer: mcp4018: Use i2c_get_match_data

Replace of_device_get_match_data() and i2c_match_id() by i2c_get_match _data() as we have similar I2C and DT-based matching table.

---
 drivers/iio/potentiometer/mcp4018.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/potentiometer/mcp4018.c +2 -2
index 89daecc90305..a5d902845a1c 100644
@@ -157,9 +157,9 @@ static int mcp4018_probe(struct i2c_client *client)
 	i2c_set_clientdata(client, indio_dev);
 	data->client = client;
 
-	data->cfg = device_get_match_data(dev);
+	data->cfg = i2c_get_match_data(dev);
 	if (!data->cfg)
-		data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)-  
 >driver_data];  
+		return -ENODEV;
 
 	indio_dev->info = &mcp4018_info;

indio_dev->channels = &mcp4018_channel;
--
2.25.1

author
#14 lore raw

RE: [PATCH 4/4] iio: potentiometer: mcp4018: Use i2c_get_match_data

Hi Jonathan Cameron,

Thanks for the feedback.

Quoted 14 lines

-----Original Message-----
From: Jonathan Cameron <[email protected]>
Sent: Thursday, July 20, 2023 8:17 PM
To: Biju Das <[email protected]>
Cc: Peter Rosin <[email protected]>; Lars-Peter Clausen <[email protected]>; [email protected]; Geert Uytterhoeven <[email protected]>; Prabhakar Mahadev Lad <[email protected]>; linux- [email protected]
Subject: Re: [PATCH 4/4] iio: potentiometer: mcp4018: Use i2c_get_match_data

On Sun, 16 Jul 2023 18:10:13 +0000
Biju Das <[email protected]> wrote:

Quoted 6 lines
Quoted 4 lines

Hi All,

I would like to drop this patch, as this driver does not have similar I2C and DT-based matching table.

Could make it so they do ;)

OK, will create separate patch for similar I2C and DT-based matching table and will send V2 for this driver.

Cheers,
Biju

Quoted 48 lines
Quoted 26 lines

Cheers,
Biju

Quoted 21 lines

-----Original Message-----
From: Biju Das <[email protected]>
Sent: Sunday, July 16, 2023 6:52 PM
To: Peter Rosin <[email protected]>; Jonathan Cameron <[email protected]>
Cc: Biju Das <[email protected]>; Lars-Peter Clausen <[email protected]>; [email protected]; Geert Uytterhoeven <[email protected]>; Prabhakar Mahadev Lad <prabhakar.mahadev- [email protected]>; [email protected]
Subject: [PATCH 4/4] iio: potentiometer: mcp4018: Use i2c_get_match_data

Replace of_device_get_match_data() and i2c_match_id() by i2c_get_match
_data() as we have similar I2C and DT-based matching table.

---
 drivers/iio/potentiometer/mcp4018.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 6 lines

drivers/iio/potentiometer/mcp4018.c static int mcp4018_probe(struct i2c_client

Quoted 6 lines
drivers/iio/potentiometer/mcp4018.c +0 -0
index 89daecc90305..a5d902845a1c 100644
@@ -157,9 +157,9 @@ static int mcp4018_probe(struct i2c_client

*client)

Quoted 15 lines
Quoted 14 lines
drivers/iio/potentiometer/mcp4018.c +2 -2
 	i2c_set_clientdata(client, indio_dev);
 	data->client = client;
 
-	data->cfg = device_get_match_data(dev);
+	data->cfg = i2c_get_match_data(dev);
 	if (!data->cfg)
-		data->cfg = &mcp4018_cfg[i2c_match_id(mcp4018_id, client)-
 >driver_data];
+		return -ENODEV;
 
 	indio_dev->info = &mcp4018_info;

indio_dev->channels = &mcp4018_channel;
--
2.25.1