Skip to contentSkip to conversation

iio: proximity: sx_common: Don't use IIO device for properties

PATCH In review Andy Shevchenko 4 participants 8 messages Jun 15, 2022 – Jul 16, 2022 IIO

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 iio: proximity: sx_common: Don't use IIO device for properties

It's not correct to use artificial device created by IIO core to retrieve device properties. Even ->get_default_reg() callback takes a simple struct device pointer which suggests it wants to operate on the real device.

Correct this by replacing pointer to IIO device by a real device pointer in the caller of ->get_default_reg().

---
v2: new patch (necessary prerequisite for the following change)

 drivers/iio/proximity/sx_common.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/iio/proximity/sx_common.c +3 -4
index 8ad814d96b7e..9f2e47385198 100644
@@ -434,7 +434,7 @@ static void sx_common_regulator_disable(void *_data)
 
 #define SX_COMMON_SOFT_RESET				0xde
 
-static int sx_common_init_device(struct iio_dev *indio_dev)
+static int sx_common_init_device(struct device *dev, struct iio_dev *indio_dev)
 {
 	struct sx_common_data *data = iio_priv(indio_dev);
 	struct sx_common_reg_default tmp;
@@ -456,8 +456,7 @@ static int sx_common_init_device(struct iio_dev *indio_dev)
 
 	/* Program defaults from constant or BIOS. */
 	for (i = 0; i < data->chip_info->num_default_regs; i++) {
-		initval = data->chip_info->ops.get_default_reg(&indio_dev->dev,
-							       i, &tmp);
+		initval = data->chip_info->ops.get_default_reg(dev, i, &tmp);
 		ret = regmap_write(data->regmap, initval->reg, initval->def);
 		if (ret)
 			return ret;
@@ -530,7 +529,7 @@ int sx_common_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, indio_dev);
 
-	ret = sx_common_init_device(indio_dev);
+	ret = sx_common_init_device(dev, indio_dev);
 	if (ret)
 		return dev_err_probe(dev, ret, "Unable to initialize sensor\n");
 
Signature · 1 line
2.35.1
#1 lore raw

PATCH v2 2/2 iio: proximity: sx_common: Allow IIO core to take care of firmware node

IIO core correctly will take care of firmware node if it's not set in the driver. Drop ACPI and OF specifics from the driver and allow IIO core to handle this.

---
v2: no changes

 drivers/iio/proximity/sx_common.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/iio/proximity/sx_common.c +0 -3
index 9f2e47385198..d70a6b4f0bf8 100644
@@ -5,7 +5,6 @@
  * Common part of most Semtech SAR sensor.
  */
 
-#include <linux/acpi.h>
 #include <linux/bitops.h>
 #include <linux/byteorder/generic.h>
 #include <linux/delay.h>
@@ -519,8 +518,6 @@ int sx_common_probe(struct i2c_client *client,
 	if (ret)
 		return dev_err_probe(dev, ret, "error reading WHOAMI\n");
 
-	ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(dev));
-	indio_dev->dev.of_node = client->dev.of_node;
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
 	indio_dev->channels =  data->chip_info->iio_channels;
Signature · 1 line
2.35.1
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] iio: proximity: sx_common: Allow IIO core to take care of firmware node

Quoted 6 lines · Andy Shevchenko

IIO core correctly will take care of firmware node if it's not set in the driver. Drop ACPI and OF specifics from the driver and allow IIO core to handle this.

Quoted 29 lines

---
v2: no changes

 drivers/iio/proximity/sx_common.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/iio/proximity/sx_common.c +0 -4
index 9f2e47385198..d70a6b4f0bf8 100644
@@ -5,7 +5,6 @@
  * Common part of most Semtech SAR sensor.
  */
 
-#include <linux/acpi.h>
 #include <linux/bitops.h>
 #include <linux/byteorder/generic.h>
 #include <linux/delay.h>
@@ -519,8 +518,6 @@ int sx_common_probe(struct i2c_client *client,
        if (ret)
                return dev_err_probe(dev, ret, "error reading WHOAMI\n");
 
-       ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(dev));
-       indio_dev->dev.of_node = client->dev.of_node;
        indio_dev->modes = INDIO_DIRECT_MODE;
 
        indio_dev->channels =  data->chip_info->iio_channels;
--

2.35.1

#3 lore raw

Re: [PATCH v2 2/2] iio: proximity: sx_common: Allow IIO core to take care of firmware node

Quoted 9 lines · Gwendal Grignou
Quoted 6 lines · Andy Shevchenko

IIO core correctly will take care of firmware node if it's not set in the driver. Drop ACPI and OF specifics from the driver and allow IIO core to handle this.

Thanks!

Jonathan, I guess we are ready with this series. What do you think?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw

Re: [PATCH v2 2/2] iio: proximity: sx_common: Allow IIO core to take care of firmware node

Quoted 8 lines · On Sun, 3 Jul 2022 18:45:44 +0300 Andy Shevchenko…
Quoted 7 lines · Gwendal Grignou
Quoted 5 lines · Andy Shevchenko

IIO core correctly will take care of firmware node if it's not set in the driver. Drop ACPI and OF specifics from the driver and allow IIO core to handle this.

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

Thanks!

Jonathan, I guess we are ready with this series. What do you think?

Gwendal's happy and seems straight forwards to me.

Applied to the togreg branch of iio.git and pushed out as testing. Note, unlikely to make this cycle so I'll probably hold it in testing only until I can rebase on rc1.

Thanks,

Jonathan

#5 lore raw
In reply to Andy Shevchenko
Quoted 7 lines · Andy Shevchenko

It's not correct to use artificial device created by IIO core to retrieve device properties. Even ->get_default_reg() callback takes a simple struct device pointer which suggests it wants to operate on the real device.

Correct this by replacing pointer to IIO device by a real device pointer in the caller of ->get_default_reg().

Gwendal, any comments on this version?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by
#6 lore raw
Quoted 11 lines · Andy Shevchenko
Quoted 7 lines · Andy Shevchenko

It's not correct to use artificial device created by IIO core to retrieve device properties. Even ->get_default_reg() callback takes a simple struct device pointer which suggests it wants to operate on the real device.

Correct this by replacing pointer to IIO device by a real device pointer in the caller of ->get_default_reg().

Gwendal, any comments on this version?

We can also replace '&indio_dev->dev' with 'dev' when setting ACPI_COMPANION_SET() in the probe routine.

Quoted 6 lines

--
With Best Regards,
Andy Shevchenko

#7 lore raw
Quoted 10 lines · Gwendal Grignou
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Andy Shevchenko

It's not correct to use artificial device created by IIO core to retrieve device properties. Even ->get_default_reg() callback takes a simple struct device pointer which suggests it wants to operate on the real device.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Correct this by replacing pointer to IIO device by a real device pointer in the caller of ->get_default_reg().

Gwendal, any comments on this version?

We can also replace '&indio_dev->dev' with 'dev' when setting ACPI_COMPANION_SET() in the probe routine.

It would make no sense, IIUC. In any case, the second patch in the series, which was the same in v1 removes that completely.

Quoted 1 line

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko