Add devicetree support for ad5933
Subsystems (5)
cover Add devicetree support for ad5933
This series of patches change voltage regulator error handling for the ad5933.
It also add an option to specify external clock reference using a clock framework and remove the old platform data structure. Finally it adds binding documentation for devicetree.
Marcelo Schmitt (3):
staging: iio: ad5933: change regulator binging for vref
staging: iio: ad5933: use clock framework for clock reference
staging: iio: ad5933: add binding doc for ad5933
.../iio/impedance-analyzer/ad5933.txt | 26 +++++++++ .../staging/iio/impedance-analyzer/ad5933.c | 57 +++++++++---------- 2 files changed, 54 insertions(+), 29 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt
Signature · 1 line
2.17.1
PATCH 1/3 staging: iio: ad5933: change regulator binging for vref
Set a single voltage regulator for all voltage references. Remove voltage reference value from default platafrom data struct.
--- drivers/staging/iio/impedance-analyzer/ad5933.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/staging/iio/impedance-analyzer/ad5933.c +6 -8
@@ -91,7 +91,6 @@struct ad5933_platform_data {unsigned long ext_clk_hz; -unsigned short vref_mv; };struct ad5933_state {
@@ -113,7 +112,6 @@ struct ad5933_state { };static struct ad5933_platform_data ad5933_default_pdata = { - .vref_mv =3300 , }; #define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \
@@ -691,7 +689,7 @@ static void ad5933_work(struct work_struct *work)static int ad5933_probe (struct i2c_client *client,const struct i2c_device_id *id) { -int ret, voltage_uv =0 ; +int ret;struct ad5933_platform_data *pdata =dev_get_platdata (&client->dev);struct ad5933_state *st;struct iio_dev *indio_dev;
@@ -718,12 +716,12 @@ static int ad5933_probe(struct i2c_client *client,dev_err (&client->dev,"Failed to enable specified VDD supply\n" );return ret; } - voltage_uv =regulator_get_voltage (st->reg); + ret =regulator_get_voltage (st->reg); + +if (ret <0 ) + goto error_disable_reg; -if (voltage_uv) - st->vref_mv = voltage_uv /1000 ; -else - st->vref_mv = pdata->vref_mv; + st->vref_mv = ret /1000 ;if (pdata->ext_clk_hz) { st->mclk_hz = pdata->ext_clk_hz;
Signature · 1 line
2.17.1
Jonathan Cameron
maintainerRe: [PATCH 1/3] staging: iio: ad5933: change regulator binging for vref
Quoted 6 lines · On Sat, 8 Dec 2018 16:19:08 -0200 Marcelo Schmitt <[email protected]>…
Set a single voltage regulator for all voltage references. Remove voltage reference value from default platafrom data struct.
Signed-off-by Marcelo Schmitt <[email protected]>Signed-off-by Gabriel Capella <[email protected]>Co-Developed-by Gabriel Capella <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 51 lines
--- drivers/staging/iio/impedance-analyzer/ad5933.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)drivers/staging/iio/impedance-analyzer/ad5933.c +6
-8@@ -91,7 +91,6 @@struct ad5933_platform_data {unsigned long ext_clk_hz; -unsigned short vref_mv; };struct ad5933_state {@@ -113,7 +112,6 @@ struct ad5933_state { };static struct ad5933_platform_data ad5933_default_pdata = { - .vref_mv =3300 , }; #define AD5933_CHANNEL(_type, _extend_name, _info_mask_separate, _address, \@@ -691,7 +689,7 @@ static void ad5933_work(struct work_struct *work)static int ad5933_probe (struct i2c_client *client,const struct i2c_device_id *id) { -int ret, voltage_uv =0 ; +int ret;struct ad5933_platform_data *pdata =dev_get_platdata (&client->dev);struct ad5933_state *st;struct iio_dev *indio_dev;@@ -718,12 +716,12 @@ static int ad5933_probe(struct i2c_client *client,dev_err (&client->dev,"Failed to enable specified VDD supply\n" );return ret; } - voltage_uv =regulator_get_voltage (st->reg); + ret =regulator_get_voltage (st->reg); + +if (ret <0 ) + goto error_disable_reg; -if (voltage_uv) - st->vref_mv = voltage_uv /1000 ; -else - st->vref_mv = pdata->vref_mv; + st->vref_mv = ret /1000 ;if (pdata->ext_clk_hz) { st->mclk_hz = pdata->ext_clk_hz;
PATCH 2/3 staging: iio: ad5933: use clock framework for clock reference
In reply to Marcelo SchmittAdd the option to specify the external clock (MCLK) using the clock framework.
Also remove the old platform data structure.
--- .../staging/iio/impedance-analyzer/ad5933.c | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-)
drivers/staging/iio/impedance-analyzer/ad5933.c +22 -21
@@ -16,6 +16,7 @@#include <linux/err.h> #include <linux/delay.h> #include <linux/module.h> +#include <linux/clk.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h>
@@ -82,20 +83,10 @@#define AD5933_POLL_TIME_ms 10#define AD5933_INIT_EXCITATION_TIME_ms 100 -/** -* struct ad5933_platform_data - platform specific data -* @ext_clk_hz: the external clock frequency in Hz, if not set -* the driver uses the internal clock (16.776 MHz) -* @vref_mv: the external reference voltage in millivolt -*/ - -struct ad5933_platform_data { -unsigned long ext_clk_hz; -}; -struct ad5933_state {struct i2c_client *client;struct regulator *reg; +struct clk *mclk;struct delayed_work work;struct mutex lock;/* Protect sensor state */ unsigned long mclk_hz;
@@ -111,9 +102,6 @@ struct ad5933_state {unsigned int poll_time_jiffies; }; -static struct ad5933_platform_data ad5933_default_pdata = { -}; -#define AD5933_CHANNEL (_type, _extend_name, _info_mask_separate, _address, \ _scan_index, _realbits) { \ .type = (_type), \
@@ -690,9 +678,9 @@ static int ad5933_probe(struct i2c_client *client, const struct i2c_device_id *id) {int ret; -struct ad5933_platform_data *pdata =dev_get_platdata (&client->dev);struct ad5933_state *st;struct iio_dev *indio_dev; +unsigned long ext_clk_hz =0 ; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*st));if (!indio_dev)
@@ -704,9 +692,6 @@ static int ad5933_probe(struct i2c_client *client,mutex_init (&st->lock); -if (!pdata) - pdata = &ad5933_default_pdata; - st->reg =devm_regulator_get (&client->dev,"vdd" );if (IS_ERR (st->reg))return PTR_ERR (st->reg);
@@ -723,8 +708,21 @@ static int ad5933_probe(struct i2c_client *client, st->vref_mv = ret /1000 ; -if (pdata->ext_clk_hz) { - st->mclk_hz = pdata->ext_clk_hz; + st->mclk =devm_clk_get (&client->dev,"mclk" ); +if (IS_ERR (st->mclk) &&PTR_ERR (st->mclk) != -ENOENT ) { + ret =PTR_ERR (st->mclk); + goto error_disable_reg; + } + +if (!IS_ERR (st->mclk)) { + ret =clk_prepare_enable (st->mclk); +if (ret <0 ) + goto error_disable_reg; + ext_clk_hz =clk_get_rate (st->mclk); + } + +if (ext_clk_hz) { + st->mclk_hz = ext_clk_hz; st->ctrl_lb =AD5933_CTRL_EXT_SYSCLK ; }else { st->mclk_hz = AD5933_INT_OSC_FREQ_Hz;
@@ -744,7 +742,7 @@ static int ad5933_probe(struct i2c_client *client, ret =ad5933_register_ring_funcs_and_init (indio_dev);if (ret) - goto error_disable_reg; + goto error_disable_mclk; ret =ad5933_setup (st);if (ret)
@@ -758,6 +756,8 @@ static int ad5933_probe(struct i2c_client *client, error_unreg_ring:iio_kfifo_free (indio_dev->buffer); +error_disable_mclk: +clk_disable_unprepare (st->mclk); error_disable_reg:regulator_disable (st->reg);
@@ -772,6 +772,7 @@ static int ad5933_remove(struct i2c_client *client)iio_device_unregister (indio_dev);iio_kfifo_free (indio_dev->buffer);regulator_disable (st->reg); +clk_disable_unprepare (st->mclk);return 0 ; }
Signature · 1 line
2.17.1
Jonathan Cameron
maintainerRe: [PATCH 2/3] staging: iio: ad5933: use clock framework for clock reference
Quoted 7 lines · On Sat, 8 Dec 2018 16:19:38 -0200 Marcelo Schmitt <[email protected]>…
Add the option to specify the external clock (MCLK) using the clock framework.
Also remove the old platform data structure.Signed-off-by Marcelo Schmitt <[email protected]>Signed-off-by Gabriel Capella <[email protected]>Co-Developed-by Gabriel Capella <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 119 lines
--- .../staging/iio/impedance-analyzer/ad5933.c | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-)drivers/staging/iio/impedance-analyzer/ad5933.c +22
-21@@ -16,6 +16,7 @@#include <linux/err.h> #include <linux/delay.h> #include <linux/module.h> +#include <linux/clk.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> @@ -82,20 +83,10 @@#define AD5933_POLL_TIME_ms 10#define AD5933_INIT_EXCITATION_TIME_ms 100 -/** -* struct ad5933_platform_data - platform specific data -* @ext_clk_hz: the external clock frequency in Hz, if not set -* the driver uses the internal clock (16.776 MHz) -* @vref_mv: the external reference voltage in millivolt -*/ - -struct ad5933_platform_data { -unsigned long ext_clk_hz; -}; -struct ad5933_state {struct i2c_client *client;struct regulator *reg; +struct clk *mclk;struct delayed_work work;struct mutex lock;/* Protect sensor state */ unsigned long mclk_hz;@@ -111,9 +102,6 @@ struct ad5933_state {unsigned int poll_time_jiffies; }; -static struct ad5933_platform_data ad5933_default_pdata = { -}; -#define AD5933_CHANNEL (_type, _extend_name, _info_mask_separate, _address, \ _scan_index, _realbits) { \ .type = (_type), \@@ -690,9 +678,9 @@ static int ad5933_probe(struct i2c_client *client, const struct i2c_device_id *id) {int ret; -struct ad5933_platform_data *pdata =dev_get_platdata (&client->dev);struct ad5933_state *st;struct iio_dev *indio_dev; +unsigned long ext_clk_hz =0 ; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*st));if (!indio_dev)@@ -704,9 +692,6 @@ static int ad5933_probe(struct i2c_client *client,mutex_init (&st->lock); -if (!pdata) - pdata = &ad5933_default_pdata; - st->reg =devm_regulator_get (&client->dev,"vdd" );if (IS_ERR (st->reg))return PTR_ERR (st->reg);@@ -723,8 +708,21 @@ static int ad5933_probe(struct i2c_client *client, st->vref_mv = ret /1000 ; -if (pdata->ext_clk_hz) { - st->mclk_hz = pdata->ext_clk_hz; + st->mclk =devm_clk_get (&client->dev,"mclk" ); +if (IS_ERR (st->mclk) &&PTR_ERR (st->mclk) != -ENOENT ) { + ret =PTR_ERR (st->mclk); + goto error_disable_reg; + } + +if (!IS_ERR (st->mclk)) { + ret =clk_prepare_enable (st->mclk); +if (ret <0 ) + goto error_disable_reg; + ext_clk_hz =clk_get_rate (st->mclk); + } + +if (ext_clk_hz) { + st->mclk_hz = ext_clk_hz; st->ctrl_lb =AD5933_CTRL_EXT_SYSCLK ; }else { st->mclk_hz = AD5933_INT_OSC_FREQ_Hz;@@ -744,7 +742,7 @@ static int ad5933_probe(struct i2c_client *client, ret =ad5933_register_ring_funcs_and_init (indio_dev);if (ret) - goto error_disable_reg; + goto error_disable_mclk; ret =ad5933_setup (st);if (ret)@@ -758,6 +756,8 @@ static int ad5933_probe(struct i2c_client *client, error_unreg_ring:iio_kfifo_free (indio_dev->buffer); +error_disable_mclk: +clk_disable_unprepare (st->mclk); error_disable_reg:regulator_disable (st->reg);@@ -772,6 +772,7 @@ static int ad5933_remove(struct i2c_client *client)iio_device_unregister (indio_dev);iio_kfifo_free (indio_dev->buffer);regulator_disable (st->reg); +clk_disable_unprepare (st->mclk);return 0 ; }
PATCH 3/3 staging: iio: ad5933: add binding doc for ad5933
In reply to Marcelo SchmittAdd a devicetree documentation for the ad5933 and ad5934 impedance converter, network analyzer.
--- .../iio/impedance-analyzer/ad5933.txt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt
Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt new file +26 -0
@@ -0,0 +1,26 @@ +Analog Devices AD5933/AD5934 Impedance Converter, Network Analyzer + +https://www.analog.com/media/en/technical-documentation/data-sheets/AD5933.pdf +https://www.analog.com/media/en/technical-documentation/data-sheets/AD5934.pdf + +Required properties: + - compatible : should be one of + "adi,ad5933" + "adi,ad5934" + - reg : the I2C address. + - vdd-supply : The regulator supply for DVDD, AVDD1 and AVDD2 when they + are connected together. + +Optional properties: +- clocks : external clock reference. +- clock-names : must be "mclk" if clocks is set. + +Example for a I2C device node: + + impedance-analyzer@0d { + compatible = "adi,adxl345"; + reg = <0x0d>; + vdd-supply = <&vdd_supply>; + clocks = <&ref_clk>; + clock-names = "mclk"; + };
Signature · 1 line
2.17.1
Jonathan Cameron
maintainerRe: [PATCH 3/3] staging: iio: ad5933: add binding doc for ad5933
Quoted 6 lines · On Sat, 8 Dec 2018 16:19:59 -0200 Marcelo Schmitt <[email protected]>…
Add a devicetree documentation for the ad5933 and ad5934 impedance converter, network analyzer.
Signed-off-by Marcelo Schmitt <[email protected]>Signed-off-by Gabriel Capella <[email protected]>Co-Developed-by Gabriel Capella <[email protected]>
Device tree binding patches need to also go to the DT maintainers and list for review.
This looks fine to me but they are the specialists in these!
+cc Rob, Mark and DT list.
Jonathan
Quoted 37 lines
--- .../iio/impedance-analyzer/ad5933.txt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txtDocumentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt new file +26
-0@@ -0,0 +1,26 @@ +Analog Devices AD5933/AD5934 Impedance Converter, Network Analyzer + +https://www.analog.com/media/en/technical-documentation/data-sheets/AD5933.pdf +https://www.analog.com/media/en/technical-documentation/data-sheets/AD5934.pdf + +Required properties: + - compatible : should be one of + "adi,ad5933" + "adi,ad5934" + - reg : the I2C address. + - vdd-supply : The regulator supply for DVDD, AVDD1 and AVDD2 when they + are connected together. + +Optional properties: +- clocks : external clock reference. +- clock-names : must be "mclk" if clocks is set. + +Example for a I2C device node: + + impedance-analyzer@0d { + compatible = "adi,adxl345"; + reg = <0x0d>; + vdd-supply = <&vdd_supply>; + clocks = <&ref_clk>; + clock-names = "mclk"; + };
Re: [PATCH 3/3] staging: iio: ad5933: add binding doc for ad5933
Quoted 9 lines · On Mon, 10 Dec 2018 21:27:02 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 6 lines · On Sat, 8 Dec 2018 16:19:59 -0200 Marcelo Schmitt <[email protected]>…
Add a devicetree documentation for the ad5933 and ad5934 impedance converter, network analyzer.
Signed-off-by Marcelo Schmitt <[email protected]>Signed-off-by Gabriel Capella <[email protected]>Co-Developed-by Gabriel Capella <[email protected]>
Quoted 6 lines
Device tree binding patches need to also go to the DT maintainers and list for review.
This looks fine to me but they are the specialists in these!
+cc Rob, Mark and DT list.
Long enough I think. This will be in my tree in a fashion I can rebase for a week or so anyway so please still feel free to comment.
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 40 lines
Jonathan
Quoted 37 lines
--- .../iio/impedance-analyzer/ad5933.txt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txtDocumentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt new file +26
-0@@ -0,0 +1,26 @@ +Analog Devices AD5933/AD5934 Impedance Converter, Network Analyzer + +https://www.analog.com/media/en/technical-documentation/data-sheets/AD5933.pdf +https://www.analog.com/media/en/technical-documentation/data-sheets/AD5934.pdf + +Required properties: + - compatible : should be one of + "adi,ad5933" + "adi,ad5934" + - reg : the I2C address. + - vdd-supply : The regulator supply for DVDD, AVDD1 and AVDD2 when they + are connected together. + +Optional properties: +- clocks : external clock reference. +- clock-names : must be "mclk" if clocks is set. + +Example for a I2C device node: + + impedance-analyzer@0d { + compatible = "adi,adxl345"; + reg = <0x0d>; + vdd-supply = <&vdd_supply>; + clocks = <&ref_clk>; + clock-names = "mclk"; + };
Parts of this work came from contributions of Alexandru Ardelean and Dragos Bogdan, I and Gabriel would like to thank for the insights provided by their previous patches. Maybe it would be the case to add them as co-authors of this patch set.
We also wanted to thank Jhonatan Cameron for giving us the pieces of advice needed for this work.
Thanks,
Marcelo
Em sáb, 8 de dez de 2018 às 16:18, Marcelo Schmitt <[email protected]> escreveu:
Quoted 20 lines
This series of patches change voltage regulator error handling for the ad5933.
It also add an option to specify external clock reference using a clock framework and remove the old platform data structure. Finally it adds binding documentation for devicetree.Marcelo Schmitt (3):
staging: iio: ad5933: change regulator binging for vref
staging: iio: ad5933: use clock framework for clock reference
staging: iio: ad5933: add binding doc for ad5933.../iio/impedance-analyzer/ad5933.txt | 26 +++++++++ .../staging/iio/impedance-analyzer/ad5933.c | 57 +++++++++---------- 2 files changed, 54 insertions(+), 29 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/impedance-analyzer/ad5933.txt--
2.17.1
Greg KH
maintainerQuoted 4 lines · Marcelo Schmitt
Parts of this work came from contributions of Alexandru Ardelean and Dragos Bogdan, I and Gabriel would like to thank for the insights provided by their previous patches. Maybe it would be the case to add them as co-authors of this patch set.
That's what the Co-developed-by: tag is for, please use it :)
Jonathan Cameron
maintainerQuoted 8 lines · On Sat, 8 Dec 2018 22:10:43 +0100 Greg KH <[email protected]> wrote:
Quoted 4 lines · Marcelo Schmitt
Parts of this work came from contributions of Alexandru Ardelean and Dragos Bogdan, I and Gabriel would like to thank for the insights provided by their previous patches. Maybe it would be the case to add them as co-authors of this patch set.
That's what the Co-developed-by: tag is for, please use it :)
Alexandru, Dragos. No idea how involved you were in the actual patch...
Work amongst amongst the 4 of you what you would like to do and let us know!
Patches look fine, though we need to let the DT maintainers have a few days at least to get around to looking if they want to (they don't always on simple bindings like these).
Jonathan
Quoted 9 lines · Jonathan Cameron
Quoted 6 lines · On Sat, 8 Dec 2018 22:10:43 +0100 Greg KH <[email protected]> wrote:
Quoted 4 lines · Marcelo Schmitt
Parts of this work came from contributions of Alexandru Ardelean and Dragos Bogdan, I and Gabriel would like to thank for the insights provided by their previous patches. Maybe it would be the case to add them as co-authors of this patch set.
Quoted 9 lines
Quoted 2 lines
That's what the Co-developed-by: tag is for, please use it :)
Alexandru, Dragos. No idea how involved you were in the actual patch...
Work amongst amongst the 4 of you what you would like to do and let us know!
Hey,
To give a bit of context, I sent some patches some time ago that deal with this, but haven't had time to re-spin them [based on Jonathan's comments].
I've discussed with Dragos.
From our side, any version that is decided with respect to the Co- developed-by: tag is fine. i.e. we don't need to be mentioned in the commits.
I hope this is a sufficiently good answer [for the whole legal stuff].
Quoted 4 lines
Patches look fine, though we need to let the DT maintainers have a few days at least to get around to looking if they want to (they don't always on simple bindings like these).
Thanks
Alex
Quoted 2 lines
Jonathan