All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data
@ 2022-08-29 11:24 Andy Shevchenko
  2022-08-29 11:24 ` [PATCH v1 2/4] iio: magnetometer: yamaha-yas530: Make strings const in chip info Andy Shevchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Andy Shevchenko @ 2022-08-29 11:24 UTC (permalink / raw)
  To: Jonathan Cameron, Andy Shevchenko, Linus Walleij, Jakob Hauser,
	linux-iio, linux-kernel
  Cc: Jonathan Cameron, Lars-Peter Clausen

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;
 
 	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);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 2/4] iio: magnetometer: yamaha-yas530: Make strings const in chip info
  2022-08-29 11:24 [PATCH v1 1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data Andy Shevchenko
@ 2022-08-29 11:24 ` Andy Shevchenko
  2022-08-29 11:24 ` [PATCH v1 3/4] iio: magnetometer: yamaha-yas530: Switch to new style i2c-driver probe function Andy Shevchenko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2022-08-29 11:24 UTC (permalink / raw)
  To: Jonathan Cameron, Andy Shevchenko, Linus Walleij, Jakob Hauser,
	linux-iio, linux-kernel
  Cc: Jonathan Cameron, Lars-Peter Clausen

For better compiler coverage mark strings consts in the chip info.

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

diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c
index 03e0525e6364..8cfe1ef9c5b4 100644
--- a/drivers/iio/magnetometer/yamaha-yas530.c
+++ b/drivers/iio/magnetometer/yamaha-yas530.c
@@ -189,8 +189,8 @@ struct yas5xx;
  */
 struct yas5xx_chip_info {
 	unsigned int devid;
-	char *product_name;
-	char *version_names[2];
+	const char *product_name;
+	const char *version_names[2];
 	const int *volatile_reg;
 	int volatile_reg_qty;
 	u32 scaling_val2;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 3/4] iio: magnetometer: yamaha-yas530: Switch to new style i2c-driver probe function
  2022-08-29 11:24 [PATCH v1 1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data Andy Shevchenko
  2022-08-29 11:24 ` [PATCH v1 2/4] iio: magnetometer: yamaha-yas530: Make strings const in chip info Andy Shevchenko
@ 2022-08-29 11:24 ` Andy Shevchenko
  2022-08-29 11:24 ` [PATCH v1 4/4] iio: magnetometer: yamaha-yas530: Use dev_err_probe() Andy Shevchenko
  2022-08-29 17:00 ` [PATCH v1 1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data Jonathan Cameron
  3 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2022-08-29 11:24 UTC (permalink / raw)
  To: Jonathan Cameron, Andy Shevchenko, Linus Walleij, Jakob Hauser,
	linux-iio, linux-kernel
  Cc: Jonathan Cameron, Lars-Peter Clausen

Switch to the new style i2c-driver probe_new probe function.
Note we do not have any old style board files using this but
user still has a possibility to instantiate device from sysfs.

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

diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c
index 8cfe1ef9c5b4..bacd2b783113 100644
--- a/drivers/iio/magnetometer/yamaha-yas530.c
+++ b/drivers/iio/magnetometer/yamaha-yas530.c
@@ -168,6 +168,7 @@ struct yas5xx;
 /**
  * struct yas5xx_chip_info - device-specific data and function pointers
  * @devid: device ID number
+ * @product_label: product label used in Linux
  * @product_name: product name of the YAS variant
  * @version_names: version letters or namings
  * @volatile_reg: device-specific volatile registers
@@ -189,6 +190,7 @@ struct yas5xx;
  */
 struct yas5xx_chip_info {
 	unsigned int devid;
+	const char *product_label;
 	const char *product_name;
 	const char *version_names[2];
 	const int *volatile_reg;
@@ -1324,6 +1326,7 @@ static int yas537_power_on(struct yas5xx *yas5xx)
 static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
 	[yas530] = {
 		.devid = YAS530_DEVICE_ID,
+		.product_label = "yas530",
 		.product_name = "YAS530 MS-3E",
 		.version_names = { "A", "B" },
 		.volatile_reg = yas530_volatile_reg,
@@ -1339,6 +1342,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
 	},
 	[yas532] = {
 		.devid = YAS532_DEVICE_ID,
+		.product_label = "yas532",
 		.product_name = "YAS532 MS-3R",
 		.version_names = { "AB", "AC" },
 		.volatile_reg = yas530_volatile_reg,
@@ -1354,6 +1358,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
 	},
 	[yas533] = {
 		.devid = YAS532_DEVICE_ID,
+		.product_label = "yas533",
 		.product_name = "YAS533 MS-3F",
 		.version_names = { "AB", "AC" },
 		.volatile_reg = yas530_volatile_reg,
@@ -1369,6 +1374,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
 	},
 	[yas537] = {
 		.devid = YAS537_DEVICE_ID,
+		.product_label = "yas537",
 		.product_name = "YAS537 MS-3T",
 		.version_names = { "v0", "v1" }, /* version naming unknown */
 		.volatile_reg = yas537_volatile_reg,
@@ -1384,8 +1390,7 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = {
 	},
 };
 
-static int yas5xx_probe(struct i2c_client *i2c,
-			const struct i2c_device_id *id)
+static int yas5xx_probe(struct i2c_client *i2c)
 {
 	struct iio_dev *indio_dev;
 	struct device *dev = &i2c->dev;
@@ -1448,7 +1453,7 @@ static int yas5xx_probe(struct i2c_client *i2c,
 	if (id_check != ci->devid) {
 		ret = dev_err_probe(dev, -ENODEV,
 				    "device ID %02x doesn't match %s\n",
-				    id_check, id->name);
+				    id_check, ci->product_label);
 		goto assert_reset;
 	}
 
@@ -1474,7 +1479,7 @@ static int yas5xx_probe(struct i2c_client *i2c,
 	indio_dev->info = &yas5xx_info;
 	indio_dev->available_scan_masks = yas5xx_scan_masks;
 	indio_dev->modes = INDIO_DIRECT_MODE;
-	indio_dev->name = id->name;
+	indio_dev->name = ci->product_label;
 	indio_dev->channels = yas5xx_channels;
 	indio_dev->num_channels = ARRAY_SIZE(yas5xx_channels);
 
@@ -1607,7 +1612,7 @@ static struct i2c_driver yas5xx_driver = {
 		.of_match_table = yas5xx_of_match,
 		.pm = pm_ptr(&yas5xx_dev_pm_ops),
 	},
-	.probe	  = yas5xx_probe,
+	.probe_new = yas5xx_probe,
 	.remove	  = yas5xx_remove,
 	.id_table = yas5xx_id,
 };
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 4/4] iio: magnetometer: yamaha-yas530: Use dev_err_probe()
  2022-08-29 11:24 [PATCH v1 1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data Andy Shevchenko
  2022-08-29 11:24 ` [PATCH v1 2/4] iio: magnetometer: yamaha-yas530: Make strings const in chip info Andy Shevchenko
  2022-08-29 11:24 ` [PATCH v1 3/4] iio: magnetometer: yamaha-yas530: Switch to new style i2c-driver probe function Andy Shevchenko
@ 2022-08-29 11:24 ` Andy Shevchenko
  2022-08-29 17:00 ` [PATCH v1 1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data Jonathan Cameron
  3 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2022-08-29 11:24 UTC (permalink / raw)
  To: Jonathan Cameron, Andy Shevchenko, Linus Walleij, Jakob Hauser,
	linux-iio, linux-kernel
  Cc: Jonathan Cameron, Lars-Peter Clausen

Unify error message format by using dev_err_probe().

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

diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c
index bacd2b783113..63bb743dc4f6 100644
--- a/drivers/iio/magnetometer/yamaha-yas530.c
+++ b/drivers/iio/magnetometer/yamaha-yas530.c
@@ -1420,10 +1420,8 @@ static int yas5xx_probe(struct i2c_client *i2c)
 		return dev_err_probe(dev, ret, "cannot get regulators\n");
 
 	ret = regulator_bulk_enable(ARRAY_SIZE(yas5xx->regs), yas5xx->regs);
-	if (ret) {
-		dev_err(dev, "cannot enable regulators\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(dev, ret, "cannot enable regulators\n");
 
 	/* See comment in runtime resume callback */
 	usleep_range(31000, 40000);
@@ -1431,15 +1429,13 @@ static int yas5xx_probe(struct i2c_client *i2c)
 	/* This will take the device out of reset if need be */
 	yas5xx->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
 	if (IS_ERR(yas5xx->reset)) {
-		ret = dev_err_probe(dev, PTR_ERR(yas5xx->reset),
-				    "failed to get reset line\n");
+		ret = dev_err_probe(dev, PTR_ERR(yas5xx->reset), "failed to get reset line\n");
 		goto reg_off;
 	}
 
 	yas5xx->map = devm_regmap_init_i2c(i2c, &yas5xx_regmap_config);
 	if (IS_ERR(yas5xx->map)) {
-		dev_err(dev, "failed to allocate register map\n");
-		ret = PTR_ERR(yas5xx->map);
+		ret = dev_err_probe(dev, PTR_ERR(yas5xx->map), "failed to allocate register map\n");
 		goto assert_reset;
 	}
 
@@ -1487,13 +1483,13 @@ static int yas5xx_probe(struct i2c_client *i2c)
 					 yas5xx_handle_trigger,
 					 NULL);
 	if (ret) {
-		dev_err(dev, "triggered buffer setup failed\n");
+		dev_err_probe(dev, ret, "triggered buffer setup failed\n");
 		goto assert_reset;
 	}
 
 	ret = iio_device_register(indio_dev);
 	if (ret) {
-		dev_err(dev, "device register failed\n");
+		dev_err_probe(dev, ret, "device register failed\n");
 		goto cleanup_buffer;
 	}
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data
  2022-08-29 11:24 [PATCH v1 1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data Andy Shevchenko
                   ` (2 preceding siblings ...)
  2022-08-29 11:24 ` [PATCH v1 4/4] iio: magnetometer: yamaha-yas530: Use dev_err_probe() Andy Shevchenko
@ 2022-08-29 17:00 ` Jonathan Cameron
  2022-08-29 19:23   ` Andy Shevchenko
  3 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2022-08-29 17:00 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jonathan Cameron, Linus Walleij, Jakob Hauser, linux-iio,
	linux-kernel, Lars-Peter Clausen

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);


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data
  2022-08-29 17:00 ` [PATCH v1 1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data Jonathan Cameron
@ 2022-08-29 19:23   ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2022-08-29 19:23 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Jonathan Cameron, Linus Walleij, Jakob Hauser, linux-iio,
	linux-kernel, Lars-Peter Clausen

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.


-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-08-29 19:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-29 11:24 [PATCH v1 1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data Andy Shevchenko
2022-08-29 11:24 ` [PATCH v1 2/4] iio: magnetometer: yamaha-yas530: Make strings const in chip info Andy Shevchenko
2022-08-29 11:24 ` [PATCH v1 3/4] iio: magnetometer: yamaha-yas530: Switch to new style i2c-driver probe function Andy Shevchenko
2022-08-29 11:24 ` [PATCH v1 4/4] iio: magnetometer: yamaha-yas530: Use dev_err_probe() Andy Shevchenko
2022-08-29 17:00 ` [PATCH v1 1/4] iio: magnetometer: yamaha-yas530: Use pointers as driver data Jonathan Cameron
2022-08-29 19:23   ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.