diff mbox series

[v1,1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data

Message ID 20220829112407.74917-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State Superseded
Headers show
Series [v1,1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data | expand

Commit Message

Andy Shevchenko Aug. 29, 2022, 11:24 a.m. UTC
Unify ID tables to use pointers for driver data. It will allow
to simplify the driver later on.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/magnetometer/yamaha-yas530.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

Comments

Jonathan Cameron Aug. 29, 2022, 5 p.m. UTC | #1
On Mon, 29 Aug 2022 14:24:04 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Unify ID tables to use pointers for driver data. It will allow
> to simplify the driver later on.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/iio/magnetometer/yamaha-yas530.c | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c
> index 026f71e524f3..03e0525e6364 100644
> --- a/drivers/iio/magnetometer/yamaha-yas530.c
> +++ b/drivers/iio/magnetometer/yamaha-yas530.c
> @@ -32,6 +32,7 @@
>  #include <linux/mod_devicetable.h>
>  #include <linux/mutex.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/property.h>
>  #include <linux/regmap.h>
>  #include <linux/regulator/consumer.h>
>  #include <linux/random.h>
> @@ -1437,8 +1438,8 @@ static int yas5xx_probe(struct i2c_client *i2c,
>  		goto assert_reset;
>  	}
>  
> -	yas5xx->chip_info = &yas5xx_chip_info_tbl[id->driver_data];
> -	ci = yas5xx->chip_info;
> +	ci = device_get_match_data(dev);
> +	yas5xx->chip_info = ci;

Am I missing a path by which device_get_match_data() can use the i2c_device_id values?
I'd expect to see a fallback to that if ci == NULL to cover the non firmware causes
of probe().  I've seen a few patches without that fallback path recently so wondering
if some magic has gotten hooked up and I've missed it (something to push that via
a swnode perhaps?)


>  
>  	ret = regmap_read(yas5xx->map, YAS5XX_DEVICE_ID, &id_check);
>  	if (ret)
> @@ -1583,19 +1584,19 @@ static DEFINE_RUNTIME_DEV_PM_OPS(yas5xx_dev_pm_ops, yas5xx_runtime_suspend,
>  				 yas5xx_runtime_resume, NULL);
>  
>  static const struct i2c_device_id yas5xx_id[] = {
> -	{"yas530", yas530 },
> -	{"yas532", yas532 },
> -	{"yas533", yas533 },
> -	{"yas537", yas537 },
> +	{"yas530", (kernel_ulong_t)&yas5xx_chip_info_tbl[yas530] },
> +	{"yas532", (kernel_ulong_t)&yas5xx_chip_info_tbl[yas532] },
> +	{"yas533", (kernel_ulong_t)&yas5xx_chip_info_tbl[yas533] },
> +	{"yas537", (kernel_ulong_t)&yas5xx_chip_info_tbl[yas537] },
>  	{}
>  };
>  MODULE_DEVICE_TABLE(i2c, yas5xx_id);
>  
>  static const struct of_device_id yas5xx_of_match[] = {
> -	{ .compatible = "yamaha,yas530", },
> -	{ .compatible = "yamaha,yas532", },
> -	{ .compatible = "yamaha,yas533", },
> -	{ .compatible = "yamaha,yas537", },
> +	{ .compatible = "yamaha,yas530", &yas5xx_chip_info_tbl[yas530] },
> +	{ .compatible = "yamaha,yas532", &yas5xx_chip_info_tbl[yas532] },
> +	{ .compatible = "yamaha,yas533", &yas5xx_chip_info_tbl[yas533] },
> +	{ .compatible = "yamaha,yas537", &yas5xx_chip_info_tbl[yas537] },
>  	{}
>  };
>  MODULE_DEVICE_TABLE(of, yas5xx_of_match);
Andy Shevchenko Aug. 29, 2022, 7:23 p.m. UTC | #2
On Mon, Aug 29, 2022 at 06:00:22PM +0100, Jonathan Cameron wrote:
> On Mon, 29 Aug 2022 14:24:04 +0300
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

...

> > -	yas5xx->chip_info = &yas5xx_chip_info_tbl[id->driver_data];
> > -	ci = yas5xx->chip_info;
> > +	ci = device_get_match_data(dev);
> > +	yas5xx->chip_info = ci;
> 
> Am I missing a path by which device_get_match_data() can use the i2c_device_id values?
> I'd expect to see a fallback to that if ci == NULL to cover the non firmware causes
> of probe().  I've seen a few patches without that fallback path recently so wondering
> if some magic has gotten hooked up and I've missed it (something to push that via
> a swnode perhaps?)

No, there is no such magic behind. The idea is that we use DT / ACPI overlays when
device needs to be established. But I have got your point.
diff mbox series

Patch

diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c
index 026f71e524f3..03e0525e6364 100644
--- a/drivers/iio/magnetometer/yamaha-yas530.c
+++ b/drivers/iio/magnetometer/yamaha-yas530.c
@@ -32,6 +32,7 @@ 
 #include <linux/mod_devicetable.h>
 #include <linux/mutex.h>
 #include <linux/pm_runtime.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 #include <linux/random.h>
@@ -1437,8 +1438,8 @@  static int yas5xx_probe(struct i2c_client *i2c,
 		goto assert_reset;
 	}
 
-	yas5xx->chip_info = &yas5xx_chip_info_tbl[id->driver_data];
-	ci = yas5xx->chip_info;
+	ci = device_get_match_data(dev);
+	yas5xx->chip_info = ci;
 
 	ret = regmap_read(yas5xx->map, YAS5XX_DEVICE_ID, &id_check);
 	if (ret)
@@ -1583,19 +1584,19 @@  static DEFINE_RUNTIME_DEV_PM_OPS(yas5xx_dev_pm_ops, yas5xx_runtime_suspend,
 				 yas5xx_runtime_resume, NULL);
 
 static const struct i2c_device_id yas5xx_id[] = {
-	{"yas530", yas530 },
-	{"yas532", yas532 },
-	{"yas533", yas533 },
-	{"yas537", yas537 },
+	{"yas530", (kernel_ulong_t)&yas5xx_chip_info_tbl[yas530] },
+	{"yas532", (kernel_ulong_t)&yas5xx_chip_info_tbl[yas532] },
+	{"yas533", (kernel_ulong_t)&yas5xx_chip_info_tbl[yas533] },
+	{"yas537", (kernel_ulong_t)&yas5xx_chip_info_tbl[yas537] },
 	{}
 };
 MODULE_DEVICE_TABLE(i2c, yas5xx_id);
 
 static const struct of_device_id yas5xx_of_match[] = {
-	{ .compatible = "yamaha,yas530", },
-	{ .compatible = "yamaha,yas532", },
-	{ .compatible = "yamaha,yas533", },
-	{ .compatible = "yamaha,yas537", },
+	{ .compatible = "yamaha,yas530", &yas5xx_chip_info_tbl[yas530] },
+	{ .compatible = "yamaha,yas532", &yas5xx_chip_info_tbl[yas532] },
+	{ .compatible = "yamaha,yas533", &yas5xx_chip_info_tbl[yas533] },
+	{ .compatible = "yamaha,yas537", &yas5xx_chip_info_tbl[yas537] },
 	{}
 };
 MODULE_DEVICE_TABLE(of, yas5xx_of_match);