diff mbox series

[v3,1/1] iio: chemical: atlas-ezo-sensor: Make use of device properties

Message ID 20220207124204.11658-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State Accepted
Headers show
Series [v3,1/1] iio: chemical: atlas-ezo-sensor: Make use of device properties | expand

Commit Message

Andy Shevchenko Feb. 7, 2022, 12:42 p.m. UTC
Convert the module to be property provider agnostic and allow
it to be used on non-OF platforms.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v3: reincarnated enum (Jonathan)
 drivers/iio/chemical/atlas-ezo-sensor.c | 32 +++++++++++++------------
 1 file changed, 17 insertions(+), 15 deletions(-)

Comments

Jonathan Cameron Feb. 13, 2022, 6:07 p.m. UTC | #1
On Mon,  7 Feb 2022 14:42:04 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Convert the module to be property provider agnostic and allow
> it to be used on non-OF platforms.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

+Cc: Matt

Looks straight forward to me so I'll queue it up and Matt can comment
after if he likes.

Applied to the togreg branch of iio.git and pushed out as testing for
all the normal checks.

Thanks,

Jonathan


> ---
> v3: reincarnated enum (Jonathan)
>  drivers/iio/chemical/atlas-ezo-sensor.c | 32 +++++++++++++------------
>  1 file changed, 17 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/iio/chemical/atlas-ezo-sensor.c b/drivers/iio/chemical/atlas-ezo-sensor.c
> index b1bacfe3c3ce..bbcf5a59c1f4 100644
> --- a/drivers/iio/chemical/atlas-ezo-sensor.c
> +++ b/drivers/iio/chemical/atlas-ezo-sensor.c
> @@ -6,13 +6,15 @@
>   * Author: Matt Ranostay <matt.ranostay@konsulko.com>
>   */
>  
> -#include <linux/module.h>
>  #include <linux/init.h>
>  #include <linux/delay.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>
>  #include <linux/mutex.h>
> +#include <linux/property.h>
>  #include <linux/err.h>
>  #include <linux/i2c.h>
> -#include <linux/of_device.h>
> +
>  #include <linux/iio/iio.h>
>  
>  #define ATLAS_EZO_DRV_NAME		"atlas-ezo-sensor"
> @@ -33,7 +35,7 @@ struct atlas_ezo_device {
>  
>  struct atlas_ezo_data {
>  	struct i2c_client *client;
> -	struct atlas_ezo_device *chip;
> +	const struct atlas_ezo_device *chip;
>  
>  	/* lock to avoid multiple concurrent read calls */
>  	struct mutex lock;
> @@ -184,17 +186,17 @@ static const struct iio_info atlas_info = {
>  };
>  
>  static const struct i2c_device_id atlas_ezo_id[] = {
> -	{ "atlas-co2-ezo", ATLAS_CO2_EZO },
> -	{ "atlas-o2-ezo", ATLAS_O2_EZO },
> -	{ "atlas-hum-ezo", ATLAS_HUM_EZO },
> +	{ "atlas-co2-ezo", (kernel_ulong_t)&atlas_ezo_devices[ATLAS_CO2_EZO] },
> +	{ "atlas-o2-ezo", (kernel_ulong_t)&atlas_ezo_devices[ATLAS_O2_EZO] },
> +	{ "atlas-hum-ezo", (kernel_ulong_t)&atlas_ezo_devices[ATLAS_HUM_EZO] },
>  	{}
>  };
>  MODULE_DEVICE_TABLE(i2c, atlas_ezo_id);
>  
>  static const struct of_device_id atlas_ezo_dt_ids[] = {
> -	{ .compatible = "atlas,co2-ezo", .data = (void *)ATLAS_CO2_EZO, },
> -	{ .compatible = "atlas,o2-ezo", .data = (void *)ATLAS_O2_EZO, },
> -	{ .compatible = "atlas,hum-ezo", .data = (void *)ATLAS_HUM_EZO, },
> +	{ .compatible = "atlas,co2-ezo", .data = &atlas_ezo_devices[ATLAS_CO2_EZO], },
> +	{ .compatible = "atlas,o2-ezo", .data = &atlas_ezo_devices[ATLAS_O2_EZO], },
> +	{ .compatible = "atlas,hum-ezo", .data = &atlas_ezo_devices[ATLAS_HUM_EZO], },
>  	{}
>  };
>  MODULE_DEVICE_TABLE(of, atlas_ezo_dt_ids);
> @@ -202,20 +204,20 @@ MODULE_DEVICE_TABLE(of, atlas_ezo_dt_ids);
>  static int atlas_ezo_probe(struct i2c_client *client,
>  		       const struct i2c_device_id *id)
>  {
> +	const struct atlas_ezo_device *chip;
>  	struct atlas_ezo_data *data;
> -	struct atlas_ezo_device *chip;
> -	const struct of_device_id *of_id;
>  	struct iio_dev *indio_dev;
>  
>  	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
>  	if (!indio_dev)
>  		return -ENOMEM;
>  
> -	of_id = of_match_device(atlas_ezo_dt_ids, &client->dev);
> -	if (!of_id)
> -		chip = &atlas_ezo_devices[id->driver_data];
> +	if (dev_fwnode(&client->dev))
> +		chip = device_get_match_data(&client->dev);
>  	else
> -		chip = &atlas_ezo_devices[(unsigned long)of_id->data];
> +		chip = (const struct atlas_ezo_device *)id->driver_data;
> +	if (!chip)
> +		return -EINVAL;
>  
>  	indio_dev->info = &atlas_info;
>  	indio_dev->name = ATLAS_EZO_DRV_NAME;
Andy Shevchenko Feb. 14, 2022, 9:23 a.m. UTC | #2
On Sun, Feb 13, 2022 at 06:07:57PM +0000, Jonathan Cameron wrote:
> On Mon,  7 Feb 2022 14:42:04 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> > Convert the module to be property provider agnostic and allow
> > it to be used on non-OF platforms.
> > 
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> +Cc: Matt

Maybe he wants to become a designated reviewer for this driver?
(Missing record in MAINTAINERS?)

> Looks straight forward to me so I'll queue it up and Matt can comment
> after if he likes.
> 
> Applied to the togreg branch of iio.git and pushed out as testing for
> all the normal checks.

Thanks!
diff mbox series

Patch

diff --git a/drivers/iio/chemical/atlas-ezo-sensor.c b/drivers/iio/chemical/atlas-ezo-sensor.c
index b1bacfe3c3ce..bbcf5a59c1f4 100644
--- a/drivers/iio/chemical/atlas-ezo-sensor.c
+++ b/drivers/iio/chemical/atlas-ezo-sensor.c
@@ -6,13 +6,15 @@ 
  * Author: Matt Ranostay <matt.ranostay@konsulko.com>
  */
 
-#include <linux/module.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/property.h>
 #include <linux/err.h>
 #include <linux/i2c.h>
-#include <linux/of_device.h>
+
 #include <linux/iio/iio.h>
 
 #define ATLAS_EZO_DRV_NAME		"atlas-ezo-sensor"
@@ -33,7 +35,7 @@  struct atlas_ezo_device {
 
 struct atlas_ezo_data {
 	struct i2c_client *client;
-	struct atlas_ezo_device *chip;
+	const struct atlas_ezo_device *chip;
 
 	/* lock to avoid multiple concurrent read calls */
 	struct mutex lock;
@@ -184,17 +186,17 @@  static const struct iio_info atlas_info = {
 };
 
 static const struct i2c_device_id atlas_ezo_id[] = {
-	{ "atlas-co2-ezo", ATLAS_CO2_EZO },
-	{ "atlas-o2-ezo", ATLAS_O2_EZO },
-	{ "atlas-hum-ezo", ATLAS_HUM_EZO },
+	{ "atlas-co2-ezo", (kernel_ulong_t)&atlas_ezo_devices[ATLAS_CO2_EZO] },
+	{ "atlas-o2-ezo", (kernel_ulong_t)&atlas_ezo_devices[ATLAS_O2_EZO] },
+	{ "atlas-hum-ezo", (kernel_ulong_t)&atlas_ezo_devices[ATLAS_HUM_EZO] },
 	{}
 };
 MODULE_DEVICE_TABLE(i2c, atlas_ezo_id);
 
 static const struct of_device_id atlas_ezo_dt_ids[] = {
-	{ .compatible = "atlas,co2-ezo", .data = (void *)ATLAS_CO2_EZO, },
-	{ .compatible = "atlas,o2-ezo", .data = (void *)ATLAS_O2_EZO, },
-	{ .compatible = "atlas,hum-ezo", .data = (void *)ATLAS_HUM_EZO, },
+	{ .compatible = "atlas,co2-ezo", .data = &atlas_ezo_devices[ATLAS_CO2_EZO], },
+	{ .compatible = "atlas,o2-ezo", .data = &atlas_ezo_devices[ATLAS_O2_EZO], },
+	{ .compatible = "atlas,hum-ezo", .data = &atlas_ezo_devices[ATLAS_HUM_EZO], },
 	{}
 };
 MODULE_DEVICE_TABLE(of, atlas_ezo_dt_ids);
@@ -202,20 +204,20 @@  MODULE_DEVICE_TABLE(of, atlas_ezo_dt_ids);
 static int atlas_ezo_probe(struct i2c_client *client,
 		       const struct i2c_device_id *id)
 {
+	const struct atlas_ezo_device *chip;
 	struct atlas_ezo_data *data;
-	struct atlas_ezo_device *chip;
-	const struct of_device_id *of_id;
 	struct iio_dev *indio_dev;
 
 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
 	if (!indio_dev)
 		return -ENOMEM;
 
-	of_id = of_match_device(atlas_ezo_dt_ids, &client->dev);
-	if (!of_id)
-		chip = &atlas_ezo_devices[id->driver_data];
+	if (dev_fwnode(&client->dev))
+		chip = device_get_match_data(&client->dev);
 	else
-		chip = &atlas_ezo_devices[(unsigned long)of_id->data];
+		chip = (const struct atlas_ezo_device *)id->driver_data;
+	if (!chip)
+		return -EINVAL;
 
 	indio_dev->info = &atlas_info;
 	indio_dev->name = ATLAS_EZO_DRV_NAME;