Skip to contentSkip to conversation

Add the Renesas X9250 potentiometers IIO support

PATCH In review Herve Codina 4 participants 14 messages May 9, 2023 – Jun 4, 2023

Subsystems (3)
lore
Share & tools
lore

Herve Codina

author maintainer
#0 lore raw

v4 cover Add the Renesas X9250 potentiometers IIO support

Hi,

The Renesas X9250 integrated four digitally controlled potentiometers. On each potentiometer, the X9250T has a 100 kOhms total resistance and the X9250U has a 50 kOhms total resistance.

Compare to the previous iteration
https://lore.kernel.org/linux-kernel/[email protected]/
This v4 series updates the binding, introduced the power-supply regulators and the write-protect gpio, uses spi_write_then_read(), removes spi_get_device_id(spi)->name, removes spi_set_drvdata() call.

Best regards,
Herve Codina

Changes v3 -> v4
- Patch 1
Remove iio.yaml.
Add 'vcc-supply', 'avp-supply' and 'avn-supply'. Add 'wp-gpios'

- Patch 2
Get and enable the regulators.
Manage the write-protect gpio.
Use spi_write_then_read().
Remove the unneeded spi_setup() call.
Get name from field added in struct x9250_cfg instead of spi_get_device_id(spi)->name.

- Patch 3
No changes

Changes v2 -> v3
- Patch 1
Remove the reg property description
Use 'potentiometer' for the node name in the example.

- Patch 2 and 3
No changes

Changes v1 -> v2
- Patch 1
No changes

- Patch 2

    Use a define for the 0x50 value used multiple times.

- Patch 3
No changes

Herve Codina (3):
dt-bindings: iio: potentiometer: Add the Renesas X9250 potentiometers
iio: potentiometer: Add support for the Renesas X9250 potentiometers
MAINTAINERS: add the Renesas X9250 driver entry

 .../iio/potentiometer/renesas,x9250.yaml      |  78 ++++++
 MAINTAINERS                                   |   7 +
 drivers/iio/potentiometer/Kconfig             |  10 +
 drivers/iio/potentiometer/Makefile            |   1 +
 drivers/iio/potentiometer/x9250.c             | 223 ++++++++++++++++++
 5 files changed, 319 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/renesas,x9250.yaml
 create mode 100644 drivers/iio/potentiometer/x9250.c
Signature · 1 line
2.40.1
author maintainer
#1 lore raw

PATCH v4 1/3 dt-bindings: iio: potentiometer: Add the Renesas X9250 potentiometers

The Renesas X9250 is a quad digitally controlled potentiometers.

---
 .../iio/potentiometer/renesas,x9250.yaml      | 78 +++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/renesas,x9250.yaml
Documentation/devicetree/bindings/iio/potentiometer/renesas,x9250.yaml new file +78 -0
new file mode 100644
index 000000000000..ab5c09c00ff4
@@ -0,0 +1,78 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/potentiometer/renesas,x9250.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Renesas X9250 quad potentiometers
+
+maintainers:
+  - Herve Codina <[email protected]>
+
+description:
+  The Renesas X9250 integrates four digitally controlled potentiometers.
+  On each potentiometer, the X9250T has a 100 kOhms total resistance and the
+  X9250U has a 50 kOhms total resistance.
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml
+
+properties:
+  compatible:
+    enum:
+      - renesas,x9250t
+      - renesas,x9250u
+
+  reg:
+    maxItems: 1
+
+  vcc-supply:
+    description:
+      Regulator for the VCC power supply.
+
+  avp-supply:
+    description:
+      Regulator for the analog V+ power supply.
+
+  avn-supply:
+    description:
+      Regulator for the analog V- power supply.
+
+  '#io-channel-cells':
+    const: 1
+
+  spi-max-frequency:
+    maximum: 2000000
+
+  wp-gpios:
+    maxItems: 1
+    description:
+      GPIO connected to the write-protect pin.
+
+required:
+  - compatible
+  - reg
+  - vcc-supply
+  - avp-supply
+  - avn-supply
+  - '#io-channel-cells'
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        potentiometer@0 {
+            compatible = "renesas,x9250t";
+            reg = <0>;
+            vcc-supply = <&vcc_regulator>;
+            avp-supply = <&avp_regulator>;
+            avn-supply = <&avp_regulator>;
+            wp-gpios = <&gpio 1 GPIO_ACTIVE_LOW>;
+            spi-max-frequency = <2000000>;
+            #io-channel-cells = <1>;
+        };
+    };
Signature · 1 line
2.40.1
Reviewed-by on v4 1/3
#2 lore raw

Re: [PATCH v4 1/3] dt-bindings: iio: potentiometer: Add the Renesas X9250 potentiometers

Quoted 8 lines · Herve Codina

The Renesas X9250 is a quad digitally controlled potentiometers.

---
 .../iio/potentiometer/renesas,x9250.yaml      | 78 +++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/renesas,x9250.yaml

Best regards,
Krzysztof

author maintainer
#3 lore raw

PATCH v4 2/3 iio: potentiometer: Add support for the Renesas X9250 potentiometers

In reply to Herve Codina

The Renesas X9250 integrates four digitally controlled potentiometers. On each potentiometer, the X9250T has a 100 kOhms total resistance and the X9250U has a 50 kOhms total resistance.

---
 drivers/iio/potentiometer/Kconfig  |  10 ++
 drivers/iio/potentiometer/Makefile |   1 +
 drivers/iio/potentiometer/x9250.c  | 223 +++++++++++++++++++++++++++++
 3 files changed, 234 insertions(+)
 create mode 100644 drivers/iio/potentiometer/x9250.c
drivers/iio/potentiometer/Kconfig +10 -0
index 01dd3f858d99..e6a9a3c67845 100644
@@ -136,4 +136,14 @@ config TPL0102
 	  To compile this driver as a module, choose M here: the
 	  module will be called tpl0102.
 
+config X9250
+	tristate "Renesas X9250 quad controlled potentiometers"
+	depends on SPI
+	help
+	  Enable support for the Renesas X9250 quad controlled
+	  potentiometers.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called x9250.
+
 endmenu
drivers/iio/potentiometer/Makefile +1 -0
index 5ebb8e3bbd76..d11fb739176c 100644
@@ -15,3 +15,4 @@ obj-$(CONFIG_MCP4131) += mcp4131.o
 obj-$(CONFIG_MCP4531) += mcp4531.o
 obj-$(CONFIG_MCP41010) += mcp41010.o
 obj-$(CONFIG_TPL0102) += tpl0102.o
+obj-$(CONFIG_X9250) += x9250.o
drivers/iio/potentiometer/x9250.c new file +223 -0

223 lines not on this page · raw message

Signature · 1 line
2.40.1
maintainer
#4 lore raw

Re: [PATCH v4 2/3] iio: potentiometer: Add support for the Renesas X9250 potentiometers

Quoted 5 lines · On Tue, 9 May 2023 18:08:51 +0200 Herve Codina <[email protected]>…

The Renesas X9250 integrates four digitally controlled potentiometers. On each potentiometer, the X9250T has a 100 kOhms total resistance and the X9250U has a 50 kOhms total resistance.

As I only noticed one trivial thing I made the change whilst applying.

drivers/iio/potentiometer/x9250.c +1 -4
index 3d4ca18d1f14..7e145d7d14f1 100644
@@ -176,10 +176,7 @@ static int x9250_probe(struct spi_device *spi)
 
        x9250 = iio_priv(indio_dev);
        x9250->spi = spi;
-       x9250->cfg = device_get_match_data(&spi->dev);
-       if (!x9250->cfg)
-               x9250->cfg = &x9250_cfg[spi_get_device_id(spi)->driver_data];
-
+       x9250->cfg = spi_get_device_match_data(spi);
        x9250->wp_gpio = devm_gpiod_get_optional(&spi->dev, "wp", GPIOD_OUT_LOW);
        if (IS_ERR(x9250->wp_gpio))
                return dev_err_probe(&spi->dev, PTR_ERR(x9250->wp_gpio),
author maintainer
#5 lore raw

Re: [PATCH v4 2/3] iio: potentiometer: Add support for the Renesas X9250 potentiometers

Hi Jonathan,

Quoted 17 lines · On Sat, 13 May 2023 19:35:25 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 5 lines · On Tue, 9 May 2023 18:08:51 +0200 Herve Codina <[email protected]>…

The Renesas X9250 integrates four digitally controlled potentiometers. On each potentiometer, the X9250T has a 100 kOhms total resistance and the X9250U has a 50 kOhms total resistance.

As I only noticed one trivial thing I made the change whilst applying.

drivers/iio/potentiometer/x9250.c +0 -0
index 3d4ca18d1f14..7e145d7d14f1 100644
@@ -176,10 +176,7 @@ static int x9250_probe(struct spi_device *spi)
 

drivers/iio/potentiometer/x9250.c static int x9250_probe(struct spi_device *spi) · line 182

Quoted 10 lines
drivers/iio/potentiometer/x9250.c +1 -4
        x9250 = iio_priv(indio_dev);
        x9250->spi = spi;
-       x9250->cfg = device_get_match_data(&spi->dev);
-       if (!x9250->cfg)
-               x9250->cfg = &x9250_cfg[spi_get_device_id(spi)->driver_data];
-
+       x9250->cfg = spi_get_device_match_data(spi);
        x9250->wp_gpio = devm_gpiod_get_optional(&spi->dev, "wp", GPIOD_OUT_LOW);
        if (IS_ERR(x9250->wp_gpio))
                return dev_err_probe(&spi->dev, PTR_ERR(x9250->wp_gpio),

Are you sure about your modification ?

I am not sure (maybe I am wrong) that
x9250->cfg = spi_get_device_match_data(spi);
is equivalent to
x9250->cfg = &x9250_cfg[spi_get_device_id(spi)->driver_data];

The spi_get_device_id(spi)->driver_data value I used is a simple integer (X9250T or X9250U) and not the x9250_cfg item.
Maybe the x9250_id_table should be modified to replace X9250T by &x9250_cfg[X9250T] to have your modification working.

The data defined in the driver are the following:
--- 8< ---

static const struct x9250_cfg x9250_cfg[] = {
	[X9250T] = { .name = "x9250t", .kohms =  100, },
	[X9250U] = { .name = "x9250u", .kohms =  50, },
};

...

static const struct of_device_id x9250_of_match[] = {
	{ .compatible = "renesas,x9250t", &x9250_cfg[X9250T]},
	{ .compatible = "renesas,x9250u", &x9250_cfg[X9250U]},
	{ }
};

MODULE_DEVICE_TABLE(of, x9250_of_match);

static const struct spi_device_id x9250_id_table[] = {
	{ "x9250t", X9250T },
	{ "x9250u", X9250U },
	{ }
};

MODULE_DEVICE_TABLE(spi, x9250_id_table);

static struct spi_driver x9250_spi_driver = {
	.driver  = {
		.name = "x9250",
		.of_match_table = x9250_of_match,
	},
	.id_table = x9250_id_table,
	.probe  = x9250_probe,
};

--- 8< ---

Best regards,
Hervé

Signature · 3 lines
Hervé Codina, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer
#6 lore raw

Re: [PATCH v4 2/3] iio: potentiometer: Add support for the Renesas X9250 potentiometers

Quoted 40 lines · On Sun, 14 May 2023 16:32:33 +0200 Herve Codina <[email protected]>…

Hi Jonathan,

Quoted 17 lines · On Sat, 13 May 2023 19:35:25 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 5 lines · On Tue, 9 May 2023 18:08:51 +0200 Herve Codina <[email protected]>…

The Renesas X9250 integrates four digitally controlled potentiometers. On each potentiometer, the X9250T has a 100 kOhms total resistance and the X9250U has a 50 kOhms total resistance.

As I only noticed one trivial thing I made the change whilst applying.

drivers/iio/potentiometer/x9250.c +0 -0
index 3d4ca18d1f14..7e145d7d14f1 100644
@@ -176,10 +176,7 @@ static int x9250_probe(struct spi_device *spi)
 

drivers/iio/potentiometer/x9250.c static int x9250_probe(struct spi_device *spi) · line 182

Quoted 10 lines
drivers/iio/potentiometer/x9250.c +1 -4
        x9250 = iio_priv(indio_dev);
        x9250->spi = spi;
-       x9250->cfg = device_get_match_data(&spi->dev);
-       if (!x9250->cfg)
-               x9250->cfg = &x9250_cfg[spi_get_device_id(spi)->driver_data];
-
+       x9250->cfg = spi_get_device_match_data(spi);
        x9250->wp_gpio = devm_gpiod_get_optional(&spi->dev, "wp", GPIOD_OUT_LOW);
        if (IS_ERR(x9250->wp_gpio))
                return dev_err_probe(&spi->dev, PTR_ERR(x9250->wp_gpio),

Are you sure about your modification ?

I am not sure (maybe I am wrong) that
x9250->cfg = spi_get_device_match_data(spi);
is equivalent to
x9250->cfg = &x9250_cfg[spi_get_device_id(spi)->driver_data];

Quoted 4 lines

The spi_get_device_id(spi)->driver_data value I used is a simple integer (X9250T or X9250U) and not the x9250_cfg item.
Maybe the x9250_id_table should be modified to replace X9250T by &x9250_cfg[X9250T] to have your modification working.

Excellent point. I'm was clearly half asleep. The mod should have included switching them over to be pointers.

Quoted 15 lines

The data defined in the driver are the following:
--- 8< ---

static const struct x9250_cfg x9250_cfg[] = {
	[X9250T] = { .name = "x9250t", .kohms =  100, },
	[X9250U] = { .name = "x9250u", .kohms =  50, },
};

...

static const struct of_device_id x9250_of_match[] = {
	{ .compatible = "renesas,x9250t", &x9250_cfg[X9250T]},
	{ .compatible = "renesas,x9250u", &x9250_cfg[X9250U]},
	{ }
};
Quoted 5 lines

MODULE_DEVICE_TABLE(of, x9250_of_match);

static const struct spi_device_id x9250_id_table[] = {
	{ "x9250t", X9250T },
	{ "x9250u", X9250U },

So these should be (kernel_ulong_t)&x9250_cfg[X9250T] etc for the data. I've tweaked it so that is now the case. Oops and thanks for sanity checking. Sometimes we see what we expect to see rather than what is there.

Tweak on top of original tweak is:

drivers/iio/potentiometer/x9250.c +2 -2
index 7e145d7d14f1..0cc7f72529be 100644
@@ -198,8 +198,8 @@ static const struct of_device_id x9250_of_match[] = {
 MODULE_DEVICE_TABLE(of, x9250_of_match);
 
 static const struct spi_device_id x9250_id_table[] = {
-       { "x9250t", X9250T },
-       { "x9250u", X9250U },
+       { "x9250t", (kernel_ulong_t)&x9250_cfg[X9250T] },
+       { "x9250u", (kernel_ulong_t)&x9250_cfg[X9250U] },
        { }
 };
 

Jonathan

Quoted 18 lines
	{ }
};

MODULE_DEVICE_TABLE(spi, x9250_id_table);

static struct spi_driver x9250_spi_driver = {
	.driver  = {
		.name = "x9250",
		.of_match_table = x9250_of_match,
	},
	.id_table = x9250_id_table,
	.probe  = x9250_probe,
};

--- 8< ---

Best regards,
Hervé

author maintainer
#7 lore raw

Re: [PATCH v4 2/3] iio: potentiometer: Add support for the Renesas X9250 potentiometers

Quoted 82 lines · On Sun, 14 May 2023 18:19:12 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 40 lines · On Sun, 14 May 2023 16:32:33 +0200 Herve Codina <[email protected]>…

Hi Jonathan,

Quoted 17 lines · On Sat, 13 May 2023 19:35:25 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 5 lines · On Tue, 9 May 2023 18:08:51 +0200 Herve Codina <[email protected]>…

The Renesas X9250 integrates four digitally controlled potentiometers. On each potentiometer, the X9250T has a 100 kOhms total resistance and the X9250U has a 50 kOhms total resistance.

As I only noticed one trivial thing I made the change whilst applying.

drivers/iio/potentiometer/x9250.c +0 -0
index 3d4ca18d1f14..7e145d7d14f1 100644
@@ -176,10 +176,7 @@ static int x9250_probe(struct spi_device *spi)
 

drivers/iio/potentiometer/x9250.c static int x9250_probe(struct spi_device *spi) · line 182

Quoted 10 lines
drivers/iio/potentiometer/x9250.c +1 -4
        x9250 = iio_priv(indio_dev);
        x9250->spi = spi;
-       x9250->cfg = device_get_match_data(&spi->dev);
-       if (!x9250->cfg)
-               x9250->cfg = &x9250_cfg[spi_get_device_id(spi)->driver_data];
-
+       x9250->cfg = spi_get_device_match_data(spi);
        x9250->wp_gpio = devm_gpiod_get_optional(&spi->dev, "wp", GPIOD_OUT_LOW);
        if (IS_ERR(x9250->wp_gpio))
                return dev_err_probe(&spi->dev, PTR_ERR(x9250->wp_gpio),

Are you sure about your modification ?

I am not sure (maybe I am wrong) that
x9250->cfg = spi_get_device_match_data(spi);
is equivalent to
x9250->cfg = &x9250_cfg[spi_get_device_id(spi)->driver_data];

Quoted 4 lines

The spi_get_device_id(spi)->driver_data value I used is a simple integer (X9250T or X9250U) and not the x9250_cfg item.
Maybe the x9250_id_table should be modified to replace X9250T by &x9250_cfg[X9250T] to have your modification working.

Excellent point. I'm was clearly half asleep. The mod should have included switching them over to be pointers.

Quoted 15 lines

The data defined in the driver are the following:
--- 8< ---

static const struct x9250_cfg x9250_cfg[] = {
	[X9250T] = { .name = "x9250t", .kohms =  100, },
	[X9250U] = { .name = "x9250u", .kohms =  50, },
};

...

static const struct of_device_id x9250_of_match[] = {
	{ .compatible = "renesas,x9250t", &x9250_cfg[X9250T]},
	{ .compatible = "renesas,x9250u", &x9250_cfg[X9250U]},
	{ }
};
Quoted 5 lines

MODULE_DEVICE_TABLE(of, x9250_of_match);

static const struct spi_device_id x9250_id_table[] = {
	{ "x9250t", X9250T },
	{ "x9250u", X9250U },  

So these should be (kernel_ulong_t)&x9250_cfg[X9250T] etc for the data. I've tweaked it so that is now the case. Oops and thanks for sanity checking. Sometimes we see what we expect to see rather than what is there.

Tweak on top of original tweak is:

drivers/iio/potentiometer/x9250.c +0 -0
index 7e145d7d14f1..0cc7f72529be 100644

drivers/iio/potentiometer/x9250.c static const struct of_device_id x9250_of_match[] = { · line 205

Quoted 10 lines
drivers/iio/potentiometer/x9250.c +2 -2
@@ -198,8 +198,8 @@ static const struct of_device_id x9250_of_match[] = {
 MODULE_DEVICE_TABLE(of, x9250_of_match);
 
 static const struct spi_device_id x9250_id_table[] = {
-       { "x9250t", X9250T },
-       { "x9250u", X9250U },
+       { "x9250t", (kernel_ulong_t)&x9250_cfg[X9250T] },
+       { "x9250u", (kernel_ulong_t)&x9250_cfg[X9250U] },
        { }
 };
 

Pefect, thanks.

Also can you add a last modification (my bad, I should see that before):

static const struct of_device_id x9250_of_match[] = {

-       { .compatible = "renesas,x9250t", &x9250_cfg[X9250T]},
-       { .compatible = "renesas,x9250u", &x9250_cfg[X9250U]},
+       { .compatible = "renesas,x9250t", .data = &x9250_cfg[X9250T]},
+       { .compatible = "renesas,x9250u", .data = &x9250_cfg[X9250U]},
        { }

};

I think adding '.data = ' would be better and avoid to have some quite tricky bug in case of struct of_device_id modification.

Regards,
Hervé

Quoted 21 lines

Jonathan

Quoted 18 lines
	{ }
};

MODULE_DEVICE_TABLE(spi, x9250_id_table);

static struct spi_driver x9250_spi_driver = {
	.driver  = {
		.name = "x9250",
		.of_match_table = x9250_of_match,
	},
	.id_table = x9250_id_table,
	.probe  = x9250_probe,
};

--- 8< ---

Best regards,
Hervé

maintainer
#8 lore raw

Re: [PATCH v4 2/3] iio: potentiometer: Add support for the Renesas X9250 potentiometers

Quoted 108 lines · On Mon, 15 May 2023 08:44:16 +0200 Herve Codina <[email protected]>…
Quoted 82 lines · On Sun, 14 May 2023 18:19:12 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 40 lines · On Sun, 14 May 2023 16:32:33 +0200 Herve Codina <[email protected]>…

Hi Jonathan,

Quoted 17 lines · On Sat, 13 May 2023 19:35:25 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 5 lines · On Tue, 9 May 2023 18:08:51 +0200 Herve Codina <[email protected]>…

The Renesas X9250 integrates four digitally controlled potentiometers. On each potentiometer, the X9250T has a 100 kOhms total resistance and the X9250U has a 50 kOhms total resistance.

As I only noticed one trivial thing I made the change whilst applying.

drivers/iio/potentiometer/x9250.c +0 -0
index 3d4ca18d1f14..7e145d7d14f1 100644
@@ -176,10 +176,7 @@ static int x9250_probe(struct spi_device *spi)
 

drivers/iio/potentiometer/x9250.c static int x9250_probe(struct spi_device *spi) · line 182

Quoted 10 lines
drivers/iio/potentiometer/x9250.c +1 -4
        x9250 = iio_priv(indio_dev);
        x9250->spi = spi;
-       x9250->cfg = device_get_match_data(&spi->dev);
-       if (!x9250->cfg)
-               x9250->cfg = &x9250_cfg[spi_get_device_id(spi)->driver_data];
-
+       x9250->cfg = spi_get_device_match_data(spi);
        x9250->wp_gpio = devm_gpiod_get_optional(&spi->dev, "wp", GPIOD_OUT_LOW);
        if (IS_ERR(x9250->wp_gpio))
                return dev_err_probe(&spi->dev, PTR_ERR(x9250->wp_gpio),

Are you sure about your modification ?

I am not sure (maybe I am wrong) that
x9250->cfg = spi_get_device_match_data(spi);
is equivalent to
x9250->cfg = &x9250_cfg[spi_get_device_id(spi)->driver_data];

Quoted 4 lines

The spi_get_device_id(spi)->driver_data value I used is a simple integer (X9250T or X9250U) and not the x9250_cfg item.
Maybe the x9250_id_table should be modified to replace X9250T by &x9250_cfg[X9250T] to have your modification working.

Excellent point. I'm was clearly half asleep. The mod should have included switching them over to be pointers.

Quoted 15 lines

The data defined in the driver are the following:
--- 8< ---

static const struct x9250_cfg x9250_cfg[] = {
	[X9250T] = { .name = "x9250t", .kohms =  100, },
	[X9250U] = { .name = "x9250u", .kohms =  50, },
};

...

static const struct of_device_id x9250_of_match[] = {
	{ .compatible = "renesas,x9250t", &x9250_cfg[X9250T]},
	{ .compatible = "renesas,x9250u", &x9250_cfg[X9250U]},
	{ }
};
Quoted 5 lines

MODULE_DEVICE_TABLE(of, x9250_of_match);

static const struct spi_device_id x9250_id_table[] = {
	{ "x9250t", X9250T },
	{ "x9250u", X9250U },    

So these should be (kernel_ulong_t)&x9250_cfg[X9250T] etc for the data. I've tweaked it so that is now the case. Oops and thanks for sanity checking. Sometimes we see what we expect to see rather than what is there.

Tweak on top of original tweak is:

drivers/iio/potentiometer/x9250.c +0 -0
index 7e145d7d14f1..0cc7f72529be 100644

drivers/iio/potentiometer/x9250.c static const struct of_device_id x9250_of_match[] = { · line 205

Quoted 10 lines
drivers/iio/potentiometer/x9250.c +2 -2
@@ -198,8 +198,8 @@ static const struct of_device_id x9250_of_match[] = {
 MODULE_DEVICE_TABLE(of, x9250_of_match);
 
 static const struct spi_device_id x9250_id_table[] = {
-       { "x9250t", X9250T },
-       { "x9250u", X9250U },
+       { "x9250t", (kernel_ulong_t)&x9250_cfg[X9250T] },
+       { "x9250u", (kernel_ulong_t)&x9250_cfg[X9250U] },
        { }
 };
 

Pefect, thanks.

Also can you add a last modification (my bad, I should see that before):

static const struct of_device_id x9250_of_match[] = {

(quoted diff) +2 -2
-       { .compatible = "renesas,x9250t", &x9250_cfg[X9250T]},
-       { .compatible = "renesas,x9250u", &x9250_cfg[X9250U]},
+       { .compatible = "renesas,x9250t", .data = &x9250_cfg[X9250T]},
+       { .compatible = "renesas,x9250u", .data = &x9250_cfg[X9250U]},
        { }
 };
Quoted 5 lines

I think adding '.data = ' would be better and avoid to have some quite tricky bug in case of struct of_device_id modification.

Regards,
Hervé

Done

Quoted 23 lines
Quoted 23 lines

Jonathan

Quoted 18 lines
	{ }
};

MODULE_DEVICE_TABLE(spi, x9250_id_table);

static struct spi_driver x9250_spi_driver = {
	.driver  = {
		.name = "x9250",
		.of_match_table = x9250_of_match,
	},
	.id_table = x9250_id_table,
	.probe  = x9250_probe,
};

--- 8< ---

Best regards,
Hervé

#9 lore raw

Re: [PATCH v4 2/3] iio: potentiometer: Add support for the Renesas X9250 potentiometers

Sat, May 20, 2023 at 05:30:57PM +0100, Jonathan Cameron kirjoitti:

...

Quoted 1 line

Done

Not sure if my comments can be addressed.

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

Re: [PATCH v4 2/3] iio: potentiometer: Add support for the Renesas X9250 potentiometers

Quoted 8 lines · On Mon, 29 May 2023 18:57:45 +0300 [email protected] wrote:

Sat, May 20, 2023 at 05:30:57PM +0100, Jonathan Cameron kirjoitti:

...

Quoted 1 line

Done

Not sure if my comments can be addressed.

Hi Andy,

I've pushed it out as togreg (which is more or less non rebasing - except when something goes horribly wrong) now so I'd rather handle your suggestions as a follow up cleanup patch / series.

Thanks,

Jonathan

#11 lore raw

Re: [PATCH v4 2/3] iio: potentiometer: Add support for the Renesas X9250 potentiometers

In reply to Herve Codina

Tue, May 09, 2023 at 06:08:51PM +0200, Herve Codina kirjoitti:

Quoted 3 lines

The Renesas X9250 integrates four digitally controlled potentiometers. On each potentiometer, the X9250T has a 100 kOhms total resistance and the X9250U has a 50 kOhms total resistance.

...

Quoted 3 lines

+/*

+ *

Redundant blank line.

Quoted 1 line

+ * x9250.c -- Renesas X9250 potentiometers IIO driver

Please, no filename in the file itself. It adds an additional burden in case the module will be renamed in the future.

Quoted 13 lines

+ * Copyright 2023 CS GROUP France
+ *
+ * Author: Herve Codina <[email protected]>
+ */

drivers/iio/potentiometer/x9250.c new file +8 -0
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/iio/iio.h>
+#include <linux/limits.h>
+#include <linux/module.h>
+#include <linux/regulator/consumer.h>
+#include <linux/slab.h>
+#include <linux/spi/spi.h>

...

drivers/iio/potentiometer/x9250.c line 43

Quoted 1 line
drivers/iio/potentiometer/x9250.c new file +1 -0
+	return spi_write_then_read(x9250->spi, txbuf, ARRAY_SIZE(txbuf), NULL, 0);

sizeof() suffice.

...

drivers/iio/potentiometer/x9250.c line 53

Quoted 1 line
drivers/iio/potentiometer/x9250.c new file +1 -0
+	return spi_write_then_read(x9250->spi, txbuf, ARRAY_SIZE(txbuf), val, 1);

Ditto.

...

Quoted 5 lines
drivers/iio/potentiometer/x9250.c new file +5 -0
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = x9250_read8(x9250, X9250_CMD_RD_WCR(ch), &v);
+		if (ret)
+			return ret;

drivers/iio/potentiometer/x9250.c line 95

Quoted 10 lines
drivers/iio/potentiometer/x9250.c new file +9 -0
+		*val = v;
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_SCALE:
+		*val = 1000 * x9250->cfg->kohms;
+		*val2 = U8_MAX;
+		return IIO_VAL_FRACTIONAL;
+	}
 
+	return -EINVAL;

Just make it part of default: case.

...

drivers/iio/potentiometer/x9250.c line 111

Quoted 9 lines
drivers/iio/potentiometer/x9250.c new file +9 -0
+	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		*length = ARRAY_SIZE(range);
+		*vals = range;
+		*type = IIO_VAL_INT;
+		return IIO_AVAIL_RANGE;
+	}
+
+	return -EINVAL;

Same.

...

drivers/iio/potentiometer/x9250.c line 125

Quoted 2 lines
drivers/iio/potentiometer/x9250.c new file +2 -0
+	if (val > U8_MAX || val < 0)
+		return -EINVAL;

ERANGE ?

...

Quoted 1 line

+

Redundant blank line.

Quoted 1 line

+module_spi_driver(x9250_spi_driver);

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

PATCH v4 3/3 MAINTAINERS: add the Renesas X9250 driver entry

In reply to Herve Codina

After contributing the driver, add myself as the maintainer for the Renesas X9250 IIO driver.

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 7517002b7735..159b3e7ce566 100644
@@ -18046,6 +18046,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/clock/renesas,versaclock7.yaml
 F:	drivers/clk/clk-versaclock7.c
 
+RENESAS X9250 DIGITAL POTENTIOMETERS DRIVER
+M:	Herve Codina <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/potentiometer/renesas,x9250.yaml
+F:	drivers/iio/potentiometer/x9250.c
+
 RESET CONTROLLER FRAMEWORK
 M:	Philipp Zabel <[email protected]>
 S:	Maintained
Signature · 1 line
2.40.1
maintainer
#13 lore raw
In reply to Herve Codina
Quoted 6 lines · On Tue, 9 May 2023 18:08:49 +0200 Herve Codina <[email protected]>…

Hi,

The Renesas X9250 integrated four digitally controlled potentiometers. On each potentiometer, the X9250T has a 100 kOhms total resistance and the X9250U has a 50 kOhms total resistance.

Quoted 8 lines

Compare to the previous iteration
https://lore.kernel.org/linux-kernel/[email protected]/
This v4 series updates the binding, introduced the power-supply regulators and the write-protect gpio, uses spi_write_then_read(), removes spi_get_device_id(spi)->name, removes spi_set_drvdata() call.

Best regards,
Herve Codina

Series applied to the togreg branch of iio.git with one tweak as per reply to patch 2.

Thanks,

Jonathan

Quoted 50 lines

Changes v3 -> v4
- Patch 1
Remove iio.yaml.
Add 'vcc-supply', 'avp-supply' and 'avn-supply'. Add 'wp-gpios'

- Patch 2
Get and enable the regulators.
Manage the write-protect gpio.
Use spi_write_then_read().
Remove the unneeded spi_setup() call.
Get name from field added in struct x9250_cfg instead of spi_get_device_id(spi)->name.

- Patch 3
No changes

Changes v2 -> v3
- Patch 1
Remove the reg property description
Use 'potentiometer' for the node name in the example.

- Patch 2 and 3
No changes

Changes v1 -> v2
- Patch 1
No changes

- Patch 2

    Use a define for the 0x50 value used multiple times.

- Patch 3
No changes

Herve Codina (3):
dt-bindings: iio: potentiometer: Add the Renesas X9250 potentiometers
iio: potentiometer: Add support for the Renesas X9250 potentiometers
MAINTAINERS: add the Renesas X9250 driver entry

 .../iio/potentiometer/renesas,x9250.yaml      |  78 ++++++
 MAINTAINERS                                   |   7 +
 drivers/iio/potentiometer/Kconfig             |  10 +
 drivers/iio/potentiometer/Makefile            |   1 +
 drivers/iio/potentiometer/x9250.c             | 223 ++++++++++++++++++
 5 files changed, 319 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/potentiometer/renesas,x9250.yaml
 create mode 100644 drivers/iio/potentiometer/x9250.c