dt-bindings: iio: adc: mcp3911: add support for the whole MCP39xx family
Subsystems (3)
Marcus Folkesson
maintainerPATCH v4 1/4 dt-bindings: iio: adc: mcp3911: add support for the whole MCP39xx family
Microchip does have many similar chips, add those to the compatible string as the driver support is extended.
The new supported chips are:
- microchip,mcp3910
- microchip,mcp3912
- microchip,mcp3913
- microchip,mcp3914
- microchip,mcp3918
- microchip,mcp3919
---
Notes:
v2:
- No changes
v3:
- No changes
v4:
- No changes
.../devicetree/bindings/iio/adc/microchip,mcp3911.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/iio/adc/microchip,mcp3911.yaml +6 -0
@@ -18,7 +18,13 @@ description: | properties: compatible: enum: + - microchip,mcp3910 - microchip,mcp3911 + - microchip,mcp3912 + - microchip,mcp3913 + - microchip,mcp3914 + - microchip,mcp3918 + - microchip,mcp3919 reg: maxItems: 1
Signature · 1 line
2.40.1
Marcus Folkesson
maintainerPATCH v4 2/4 iio: adc: mcp3911: simplify usage of spi->dev in probe function
Replace the usage of adc->spi->dev with spi->dev to make the code prettier.
---
Notes:
v4:
- New patch in this series
drivers/iio/adc/mcp3911.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/adc/mcp3911.c +6 -6
@@ -477,12 +477,12 @@ static int mcp3911_probe(struct spi_device *spi) adc =iio_priv (indio_dev); adc->spi = spi; - adc->vref =devm_regulator_get_optional (&adc->spi->dev,"vref" ); + adc->vref =devm_regulator_get_optional (&spi->dev,"vref" );if (IS_ERR (adc->vref)) {if (PTR_ERR (adc->vref) == -ENODEV ) { adc->vref =NULL ; }else { -dev_err (&adc->spi->dev, +dev_err (&spi->dev,"failed to get regulator (%ld)\n" ,PTR_ERR (adc->vref));return PTR_ERR (adc->vref);
@@ -499,12 +499,12 @@ static int mcp3911_probe(struct spi_device *spi)return ret; } - adc->clki =devm_clk_get_enabled (&adc->spi->dev,NULL ); + adc->clki =devm_clk_get_enabled (&spi->dev,NULL );if (IS_ERR (adc->clki)) {if (PTR_ERR (adc->clki) == -ENOENT ) { adc->clki =NULL ; }else { -dev_err (&adc->spi->dev, +dev_err (&spi->dev,"failed to get adc clk (%ld)\n" ,PTR_ERR (adc->clki));return PTR_ERR (adc->clki);
@@ -515,7 +515,7 @@ static int mcp3911_probe(struct spi_device *spi)if (ret)return ret; -if (device_property_read_bool (&adc->spi->dev,"microchip,data-ready-hiz" )) +if (device_property_read_bool (&spi->dev,"microchip,data-ready-hiz" )) ret =mcp3911_update (adc,MCP3911_REG_STATUSCOM ,MCP3911_STATUSCOM_DRHIZ ,0 ,2 );else
@@ -579,7 +579,7 @@ static int mcp3911_probe(struct spi_device *spi)if (ret)return ret; -return devm_iio_device_register (&adc->spi->dev, indio_dev); +return devm_iio_device_register (&spi->dev, indio_dev); }static const struct of_device_id mcp3911_dt_ids[] = {
Signature · 1 line
2.40.1
Re: [PATCH v4 2/4] iio: adc: mcp3911: simplify usage of spi->dev in probe function
Quoted 1 line · Marcus Folkesson
Replace the usage of
adc->spi->devwithspi->devto make the code prettier.
Quoted 1 line
Signed-off-by Marcus Folkesson <[email protected]>
...
drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 480
Quoted 2 lines
drivers/iio/adc/mcp3911.c +1
-1- adc->vref =devm_regulator_get_optional (&adc->spi->dev,"vref" ); + adc->vref =devm_regulator_get_optional (&spi->dev,"vref" );
Why not
struct device *dev = &spi->dev;
and all the rest accordingly?
drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 488
Quoted 9 lines
drivers/iio/adc/mcp3911.c +1
-1if (IS_ERR (adc->vref)) {if (PTR_ERR (adc->vref) == -ENODEV ) { adc->vref =NULL ; }else { -dev_err (&adc->spi->dev, +dev_err (&spi->dev,"failed to get regulator (%ld)\n" ,PTR_ERR (adc->vref));return PTR_ERR (adc->vref);
Actually, you may first to switch to dev_err_probe() with the above introduced
struct device *dev = &spi->dev; ... return dev_err_probe(dev, PTR_ERR(adc->vref), "failed to get regulator\n",
and in the second patch do what you are doing here.
Will be much less changes and neater code at the end.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Marcus Folkesson
maintainerPATCH v4 3/4 iio: adc: mcp3911: fix indentation
In reply to Marcus FolkessonThe file does not make use of indentation properly. Fix that.
---
Notes:
v4:
- New patch in this series
drivers/iio/adc/mcp3911.c | 97 ++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 48 deletions(-)
drivers/iio/adc/mcp3911.c +49 -48
@@ -33,7 +33,7 @@#define MCP3911_GAIN_VAL (ch, val) ((val << 3 * ch) & MCP3911_GAIN_MASK(ch))#define MCP3911_REG_STATUSCOM 0x0a -#define MCP3911_STATUSCOM_DRHIZ BIT(12) +#define MCP3911_STATUSCOM_DRHIZ BIT(12)#define MCP3911_STATUSCOM_READ GENMASK(7, 6)#define MCP3911_STATUSCOM_CH1_24WIDTH BIT(4)#define MCP3911_STATUSCOM_CH0_24WIDTH BIT(3)
@@ -112,7 +112,7 @@ static int mcp3911_write(struct mcp3911 *adc, u8 reg, u32 val, u8 len) }static int mcp3911_update (struct mcp3911 *adc,u8 reg,u32 mask, -u32 val,u8 len) +u32 val,u8 len) {u32 tmp;int ret;
@@ -127,8 +127,8 @@ static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, }static int mcp3911_write_raw_get_fmt (struct iio_dev *indio_dev, -struct iio_chan_spec const *chan, -long mask) +struct iio_chan_spec const *chan, +long mask) {switch (mask) {case IIO_CHAN_INFO_SCALE :
@@ -141,9 +141,9 @@ static int mcp3911_write_raw_get_fmt(struct iio_dev *indio_dev, }static int mcp3911_read_avail (struct iio_dev *indio_dev, -struct iio_chan_spec const *chan, -const int **vals,int *type,int *length, -long info) +struct iio_chan_spec const *chan, +const int **vals,int *type,int *length, +long info) {switch (info) {case IIO_CHAN_INFO_OVERSAMPLING_RATIO :
@@ -212,8 +212,8 @@ static int mcp3911_read_raw(struct iio_dev *indio_dev, }static int mcp3911_write_raw (struct iio_dev *indio_dev, -struct iio_chan_spec const *channel,int val, -int val2,long mask) +struct iio_chan_spec const *channel,int val, +int val2,long mask) {struct mcp3911 *adc =iio_priv (indio_dev);int ret = -EINVAL ;
@@ -223,12 +223,12 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev,case IIO_CHAN_INFO_SCALE :for (int i =0 ; i <MCP3911_NUM_SCALES ; i++) {if (val == mcp3911_scale_table[i][0 ] && - val2 == mcp3911_scale_table[i][1 ]) { + val2 == mcp3911_scale_table[i][1 ]) { adc->gain[channel->channel] =BIT (i); ret =mcp3911_update (adc,MCP3911_REG_GAIN , -MCP3911_GAIN_MASK (channel->channel), -MCP3911_GAIN_VAL (channel->channel, i),1 ); +MCP3911_GAIN_MASK (channel->channel), +MCP3911_GAIN_VAL (channel->channel, i),1 ); } }break ;
@@ -246,8 +246,8 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev,/* Enable offset*/ ret =mcp3911_update (adc,MCP3911_REG_STATUSCOM , -MCP3911_STATUSCOM_EN_OFFCAL , -MCP3911_STATUSCOM_EN_OFFCAL ,2 ); +MCP3911_STATUSCOM_EN_OFFCAL , +MCP3911_STATUSCOM_EN_OFFCAL ,2 );break ;case IIO_CHAN_INFO_OVERSAMPLING_RATIO :
@@ -255,7 +255,7 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev,if (val == mcp3911_osr_table[i]) { val =FIELD_PREP (MCP3911_CONFIG_OSR , i); ret =mcp3911_update (adc,MCP3911_REG_CONFIG ,MCP3911_CONFIG_OSR , - val,2 ); + val,2 );break ; } }
@@ -279,7 +279,7 @@ static int mcp3911_calc_scale_table(struct mcp3911 *adc)if (ret <0 ) {dev_err (&adc->spi->dev,"failed to get vref voltage: %d\n" , - ret); + ret);return ret; }
@@ -305,25 +305,25 @@ static int mcp3911_calc_scale_table(struct mcp3911 *adc)return 0 ; } -#define MCP3911_CHAN (idx) { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .channel = idx, \ - .scan_index = idx, \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_OFFSET) | \ - BIT(IIO_CHAN_INFO_SCALE), \ - .info_mask_shared_by_type_available = \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ - .info_mask_separate_available = \ - BIT(IIO_CHAN_INFO_SCALE), \ - .scan_type = { \ - .sign = 's', \ - .realbits = 24, \ - .storagebits = 32, \ - .endianness = IIO_BE, \ - }, \ +#define MCP3911_CHAN (idx) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .channel = idx, \ + .scan_index = idx, \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_OFFSET) | \ + BIT(IIO_CHAN_INFO_SCALE), \ + .info_mask_shared_by_type_available = \ + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ + .info_mask_separate_available = \ + BIT(IIO_CHAN_INFO_SCALE), \ + .scan_type = { \ + .sign = 's', \ + .realbits = 24, \ + .storagebits = 32, \ + .endianness = IIO_BE, \ + }, \ }static const struct iio_chan_spec mcp3911_channels[] = {
@@ -355,7 +355,7 @@ static irqreturn_t mcp3911_trigger_handler(int irq, void *p) ret =spi_sync_transfer (adc->spi, xfer,ARRAY_SIZE (xfer));if (ret <0 ) {dev_warn (&adc->spi->dev, -"failed to get conversion data\n" ); +"failed to get conversion data\n" ); goto out; }
@@ -494,7 +494,7 @@ static int mcp3911_probe(struct spi_device *spi)return ret; ret =devm_add_action_or_reset (&spi->dev, - mcp3911_cleanup_regulator, adc->vref); + mcp3911_cleanup_regulator, adc->vref);if (ret)return ret; }
@@ -517,10 +517,10 @@ static int mcp3911_probe(struct spi_device *spi)if (device_property_read_bool (&spi->dev,"microchip,data-ready-hiz" )) ret =mcp3911_update (adc,MCP3911_REG_STATUSCOM ,MCP3911_STATUSCOM_DRHIZ , -0 ,2 ); +0 ,2 );else ret =mcp3911_update (adc,MCP3911_REG_STATUSCOM ,MCP3911_STATUSCOM_DRHIZ , -MCP3911_STATUSCOM_DRHIZ ,2 ); +MCP3911_STATUSCOM_DRHIZ ,2 );if (ret)return ret;
@@ -528,12 +528,12 @@ static int mcp3911_probe(struct spi_device *spi)if (ret)return ret; -/* Set gain to 1 for all channels */ +/* Set gain to 1 for all channels */ for (int i =0 ; i <MCP3911_NUM_CHANNELS ; i++) { adc->gain[i] =1 ; ret =mcp3911_update (adc,MCP3911_REG_GAIN , -MCP3911_GAIN_MASK (i), -MCP3911_GAIN_VAL (i,0 ),1 ); +MCP3911_GAIN_MASK (i), +MCP3911_GAIN_VAL (i,0 ),1 );if (ret)return ret; }
@@ -550,8 +550,8 @@ static int mcp3911_probe(struct spi_device *spi)if (spi->irq >0 ) { adc->trig =devm_iio_trigger_alloc (&spi->dev,"%s-dev%d" , - indio_dev->name, -iio_device_id (indio_dev)); + indio_dev->name, +iio_device_id (indio_dev));if (!adc->trig)return -ENOMEM ;
@@ -567,15 +567,16 @@ static int mcp3911_probe(struct spi_device *spi)* don't enable the interrupt to avoid extra load on the system. */ ret =devm_request_irq (&spi->dev, spi->irq, - &iio_trigger_generic_data_rdy_poll,IRQF_NO_AUTOEN |IRQF_ONESHOT , - indio_dev->name, adc->trig); + &iio_trigger_generic_data_rdy_poll, +IRQF_NO_AUTOEN |IRQF_ONESHOT , + indio_dev->name, adc->trig);if (ret)return ret; } ret =devm_iio_triggered_buffer_setup (&spi->dev, indio_dev, -NULL , - mcp3911_trigger_handler,NULL ); +NULL , + mcp3911_trigger_handler,NULL );if (ret)return ret;
Signature · 1 line
2.40.1
Re: [PATCH v4 3/4] iio: adc: mcp3911: fix indentation
Quoted 2 lines · Marcus Folkesson
The file does not make use of indentation properly. Fix that.
...
drivers/iio/adc/mcp3911.c static int mcp3911_write(struct mcp3911 *adc, u8 reg, u32 val, u8 len) · line 115
Quoted 3 lines
static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask,
drivers/iio/adc/mcp3911.c +1
-1- u32 val, u8 len) + u32 val, u8 len)
Can val be moved to the previous line?
...
drivers/iio/adc/mcp3911.c static int mcp3911_calc_scale_table(struct mcp3911 *adc) · line 283
Quoted 6 lines
drivers/iio/adc/mcp3911.c +1
-1if (ret <0 ) {dev_err (&adc->spi->dev,"failed to get vref voltage: %d\n" , - ret); + ret);return ret;
With
struct device *dev = &adc->spi->dev;
this becomes
dev_err(dev, "failed to get vref voltage: %d\n", ret);
and one change less here.
Quoted 1 line
}
...
Quoted 11 lines
drivers/iio/adc/mcp3911.c +0
-11-#define MCP3911_CHAN (idx) { \ - .type = IIO_VOLTAGE, \ - .indexed = 1, \ - .channel = idx, \ - .scan_index = idx, \ - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ - BIT(IIO_CHAN_INFO_OFFSET) | \ - BIT(IIO_CHAN_INFO_SCALE), \ - .info_mask_shared_by_type_available = \ - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
drivers/iio/adc/mcp3911.c static int mcp3911_calc_scale_table(struct mcp3911 *adc)
Quoted 10 lines
drivers/iio/adc/mcp3911.c +0
-8- .info_mask_separate_available = \ - BIT(IIO_CHAN_INFO_SCALE), \ - .scan_type = { \ - .sign = 's', \ - .realbits = 24, \ - .storagebits = 32, \ - .endianness = IIO_BE, \ - }, \ }
This looks like unneeded churn to me.
...
drivers/iio/adc/mcp3911.c static irqreturn_t mcp3911_trigger_handler(int irq, void *p) · line 360
Quoted 6 lines
drivers/iio/adc/mcp3911.c +1
-1if (ret <0 ) {dev_warn (&adc->spi->dev, -"failed to get conversion data\n" ); +"failed to get conversion data\n" ); goto out; }
Same as above with temporary variable for struct device.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Marcus Folkesson
maintainerPATCH v4 4/4 iio: adc: mcp3911: add support for the whole MCP39xx family
In reply to Marcus FolkessonMicrochip does have many similar chips, add support for those.
The new supported chips are:
- microchip,mcp3910
- microchip,mcp3912
- microchip,mcp3913
- microchip,mcp3914
- microchip,mcp3918
- microchip,mcp3919
---
Notes:
v2:
- Use callbacks rather than matching against enum for determine chip variants
v3:
- Fix cosmetics
v4:
- Do not pollute output variable upon error in *_get_osr() functions.
- Fix cosmetics
drivers/iio/adc/Kconfig | 5 +- drivers/iio/adc/mcp3911.c | 459 +++++++++++++++++++++++++++++++++----- 2 files changed, 405 insertions(+), 59 deletions(-)
drivers/iio/adc/Kconfig +3 -2
@@ -774,8 +774,9 @@ config MCP3911 select IIO_BUFFER select IIO_TRIGGERED_BUFFER help - Say yes here to build support for Microchip Technology's MCP3911 - analog to digital converter. + Say yes here to build support for Microchip Technology's MCP3910, + MCP3911, MCP3912, MCP3913, MCP3914, MCP3918 and MCP3919 + analog to digital converters. This driver can also be built as a module. If so, the module will be called mcp3911.
drivers/iio/adc/mcp3911.c +402 -57
590 lines not on this page · raw message
Signature · 1 line
2.40.1
Re: [PATCH v4 4/4] iio: adc: mcp3911: add support for the whole MCP39xx family
Quoted 1 line · Marcus Folkesson
Microchip does have many similar chips, add support for those.
...
drivers/iio/adc/Kconfig config MCP3911 · line 779
Quoted 6 lines
drivers/iio/adc/Kconfig +3
-2help - Say yes here to build support for Microchip Technology's MCP3911 - analog to digital converter. + Say yes here to build support for Microchip Technology's MCP3910, + MCP3911, MCP3912, MCP3913, MCP3914, MCP3918 and MCP3919 + analog to digital converters.
For maintenance this can be written as
Say yes here to build support for one of the following Microchip Technology's analog to digital converters: MCP3910, MCP3911, MCP3912, MCP3913, MCP3914, MCP3918, MCP3919
Quoted 2 lines
drivers/iio/adc/Kconfig +0
-0This driver can also be built as a module. If so, the module will be called mcp3911.
...
Quoted 1 line
+#define
MCP3910_OFFCAL(x)(MCP3910_REG_OFFCAL_CH0+ x * 6)
Inconsistent macro implementation, i.e. you need to use (x).
...
drivers/iio/adc/mcp3911.c static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, · line 215
Quoted 3 lines
drivers/iio/adc/mcp3911.c +3
-0+static int mcp3910_get_osr (struct mcp3911 *adc,int *val) +{ +int ret, osr;
Strictly speaking osr can't be negative, otherwise it's a UB below.
u32 osr = FIELD_GET(MCP3910_CONFIG0_OSR, *val); int ret;
and why val is int?
Quoted 8 lines
drivers/iio/adc/mcp3911.c +8
-0+ ret =mcp3911_read (adc,MCP3910_REG_CONFIG0 , val,3 ); +if (ret) +return ret; + + osr =FIELD_GET (MCP3910_CONFIG0_OSR , *val); + *val =32 << osr; +return ret; +}
...
drivers/iio/adc/mcp3911.c static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, · line 230
Quoted 6 lines
drivers/iio/adc/mcp3911.c +5
-0+static int mcp3910_set_osr (struct mcp3911 *adc,int val) +{ +int osr; + + osr =FIELD_PREP (MCP3910_CONFIG0_OSR , val);
Can be on one line.
Quoted 3 lines
drivers/iio/adc/mcp3911.c +3
-0+return mcp3911_update (adc,MCP3910_REG_CONFIG0 , +MCP3910_CONFIG0_OSR , osr,3 ); +}
...
drivers/iio/adc/mcp3911.c static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, · line 244
Quoted 2 lines
drivers/iio/adc/mcp3911.c +2
-0+static int mcp3911_set_osr(struct mcp3911 *adc, int val) +static int mcp3911_get_osr(struct mcp3911 *adc, int *val)
As per above comments.
...
drivers/iio/adc/mcp3911.c static int mcp3911_config(struct mcp3911 *adc)
Quoted 7 lines
drivers/iio/adc/mcp3911.c +6
-0+if (adc->vref) { +dev_dbg (&adc->spi->dev,"use external voltage reference\n" ); + regval |=FIELD_PREP (MCP3910_CONFIG1_VREFEXT ,1 ); + }else { +dev_dbg (&adc->spi->dev, +"use internal voltage reference (1.2V)\n" );
As per previous patch comments
dev_dbg(dev, "use internal voltage reference (1.2V)\n");
Quoted 2 lines
(quoted diff) +2
-0+ regval |= FIELD_PREP(MCP3910_CONFIG1_VREFEXT, 0); + }
...
drivers/iio/adc/mcp3911.c static int mcp3911_config(struct mcp3911 *adc) · line 651
Quoted 6 lines
drivers/iio/adc/mcp3911.c +6
-0+if (adc->clki) { +dev_dbg (&adc->spi->dev,"use external clock as clocksource\n" ); + regval |=FIELD_PREP (MCP3910_CONFIG1_CLKEXT ,1 ); + }else { +dev_dbg (&adc->spi->dev, +"use crystal oscillator as clocksource\n" );
Ditto.
Quoted 2 lines
(quoted diff) +2
-0+ regval |= FIELD_PREP(MCP3910_CONFIG1_CLKEXT, 0); + }
...
Review
Quoted 1 line
(quoted diff) +1
-0+ if (device_property_read_bool(&adc->spi->dev, "microchip,data-ready-hiz"))
This also becomes shorter.
One trick to make it even shorter:
if (device_property_present(dev, "microchip,data-ready-hiz"))
Quoted 3 lines
drivers/iio/adc/mcp3911.c +3
-0+ regval |=FIELD_PREP (MCP3910_STATUSCOM_DRHIZ ,0 ); + else + regval |= FIELD_PREP(MCP3910_STATUSCOM_DRHIZ, 1);
...
drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 767
Quoted 1 line
drivers/iio/adc/mcp3911.c +1
-0+ ret =device_property_read_u32 (&spi->dev,"microchip,device-addr" , &adc->dev_addr);
I would move it after the comment. It will be more visible what we are expecting and what the legacy is.
drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 772
Quoted 4 lines
drivers/iio/adc/mcp3911.c +4
-0+/* +* Fallback to "device-addr" due to historical mismatch between +* dt-bindings and implementation. +*/
ret = device_property_read_u32(dev, "microchip,device-addr", &adc->dev_addr);
drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 779
Quoted 9 lines
drivers/iio/adc/mcp3911.c +6
-1if (ret) -return ret; +device_property_read_u32 (&spi->dev,"device-addr" , &adc->dev_addr); +if (adc->dev_addr >3 ) { +dev_err (&spi->dev, +"invalid device address (%i). Must be in range 0-3.\n" , + adc->dev_addr); +return -EINVAL ;
return dev_err_probe(...);
Quoted 1 line
(quoted diff) +1
-0+ }
...
drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 781
Quoted 1 line
drivers/iio/adc/mcp3911.c +1
-0+dev_dbg (&spi->dev,"use device address %i\n" , adc->dev_addr);
Is it useful?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Marcus Folkesson
maintainerRe: [PATCH v4 4/4] iio: adc: mcp3911: add support for the whole MCP39xx family
Quoted 5 lines
...
Quoted 1 line
+#define
MCP3910_OFFCAL(x)(MCP3910_REG_OFFCAL_CH0+ x * 6)Inconsistent macro implementation, i.e. you need to use (x).
Sorry, I do not get you
[...]
Quoted 10 lines
drivers/iio/adc/mcp3911.c static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, · line 215
Quoted 3 lines
drivers/iio/adc/mcp3911.c +3
-0+static int mcp3910_get_osr (struct mcp3911 *adc,int *val) +{ +int ret, osr;Strictly speaking osr can't be negative, otherwise it's a UB below.
u32 osr = FIELD_GET(MCP3910_CONFIG0_OSR, *val); int ret;and why val is int?
I will change val to u32 for *_get_osr(), *_set_osr() and *_set_scale().
[...]
Quoted 7 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ if (device_property_read_bool(&adc->spi->dev, "microchip,data-ready-hiz"))This also becomes shorter.
One trick to make it even shorter:
if (
device_property_present(dev, "microchip,data-ready-hiz"))
Thank you, I wasn't aware of device_property_present().
[...]
Quoted 4 lines
drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 781
Quoted 2 lines
drivers/iio/adc/mcp3911.c +1
-0+dev_dbg (&spi->dev,"use device address %i\n" , adc->dev_addr);Is it useful?
Yes, I think so.
Quoted 6 lines
Signature · 3 lines
-- With Best Regards, Andy Shevchenko
Best regards,
Marcus Folkesson
Jonathan Cameron
maintainerRe: [PATCH v4 4/4] iio: adc: mcp3911: add support for the whole MCP39xx family
Quoted 30 lines · On Wed, 9 Aug 2023 08:41:05 +0200 Marcus Folkesson…
Quoted 5 lines
...
Quoted 1 line
+#define
MCP3910_OFFCAL(x)(MCP3910_REG_OFFCAL_CH0+ x * 6)Inconsistent macro implementation, i.e. you need to use (x).
Sorry, I do not get you
[...]
Quoted 10 lines
drivers/iio/adc/mcp3911.c static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, · line 215
Quoted 3 lines
drivers/iio/adc/mcp3911.c +3
-0+static int mcp3910_get_osr (struct mcp3911 *adc,int *val) +{ +int ret, osr;Strictly speaking osr can't be negative, otherwise it's a UB below.
u32 osr = FIELD_GET(MCP3910_CONFIG0_OSR, *val); int ret;and why val is int?
I will change val to u32 for
*_get_osr(),*_set_osr()and*_set_scale().[...]
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ if (device_property_read_bool(&adc->spi->dev, "microchip,data-ready-hiz"))This also becomes shorter.
Quoted 5 lines
Quoted 3 lines
One trick to make it even shorter:
if (
device_property_present(dev, "microchip,data-ready-hiz"))Thank you, I wasn't aware of
device_property_present().
I know the read_bool function is direct equivalent of this but where a property is a flag, it feels more natural to me to check it with that one. read_present() feels more appropriate for where you want to know a more complex property is present.
Doesn't matter that much either way however so up to you.
Quoted 19 lines
[...]
Quoted 4 lines
drivers/iio/adc/mcp3911.c static int mcp3911_probe(struct spi_device *spi) · line 781
Quoted 2 lines
drivers/iio/adc/mcp3911.c +1
-0+dev_dbg (&spi->dev,"use device address %i\n" , adc->dev_addr);Is it useful?
Yes, I think so.
Quoted 6 lines
Signature · 3 lines
-- With Best Regards, Andy ShevchenkoBest regards,
Marcus Folkesson
Re: [PATCH v4 4/4] iio: adc: mcp3911: add support for the whole MCP39xx family
Quoted 37 lines · Jonathan Cameron
Quoted 34 lines · On Wed, 9 Aug 2023 08:41:05 +0200 Marcus Folkesson…
Quoted 5 lines
...
Quoted 1 line
+#define
MCP3910_OFFCAL(x)(MCP3910_REG_OFFCAL_CH0+ x * 6)Inconsistent macro implementation, i.e. you need to use (x).
Sorry, I do not get you
[...]
Quoted 10 lines
drivers/iio/adc/mcp3911.c static int mcp3911_update(struct mcp3911 *adc, u8 reg, u32 mask, · line 215
Quoted 3 lines
drivers/iio/adc/mcp3911.c +3
-0+static int mcp3910_get_osr (struct mcp3911 *adc,int *val) +{ +int ret, osr;Strictly speaking osr can't be negative, otherwise it's a UB below.
u32 osr = FIELD_GET(MCP3910_CONFIG0_OSR, *val); int ret;and why val is int?
I will change val to u32 for
*_get_osr(),*_set_osr()and*_set_scale().[...]
Quoted 7 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ if (device_property_read_bool(&adc->spi->dev, "microchip,data-ready-hiz"))This also becomes shorter.
One trick to make it even shorter:
if (
device_property_present(dev, "microchip,data-ready-hiz"))
Quoted 8 lines
Quoted 1 line
Thank you, I wasn't aware of
device_property_present().I know the
read_boolfunction is direct equivalent of this but where a property is a flag, it feels more natural to me to check it with that one.read_present()feels more appropriate for where you want to know a more complex property is present.Doesn't matter that much either way however so up to you.
For the OF, of_property_read_bool() is indeed preferred. Is there device-xxx() equivalent?
Best regards,
Krzysztof
Re: [PATCH v4 4/4] iio: adc: mcp3911: add support for the whole MCP39xx family
Quoted 3 lines · Krzysztof Kozlowski
Quoted 2 lines · Jonathan Cameron
On Wed, 9 Aug 2023 08:41:05 +0200
Marcus Folkesson <[email protected]> wrote:
...
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Inconsistent macro implementation, i.e. you need to use (x).
Sorry, I do not get you
In other macros you avoid ambiguity of the parameter, so they can be evaluated properly, and not here.
...
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +1
-0+ if (device_property_read_bool(&adc->spi->dev, "microchip,data-ready-hiz"))
(1)
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
Quoted 5 lines
This also becomes shorter.
One trick to make it even shorter:
if (
device_property_present(dev, "microchip,data-ready-hiz"))Thank you, I wasn't aware of
device_property_present().I know the
read_boolfunction is direct equivalent of this but where a property is a flag, it feels more natural to me to check it with that one.read_present()feels more appropriate for where you want to know a more complex property is present.
Quoted 4 lines
Quoted 1 line
Doesn't matter that much either way however so up to you.
For the OF,
of_property_read_bool()is indeed preferred. Is there device-xxx() equivalent?
See (1) above ?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Marcus Folkesson
maintainerRe: [PATCH v4 4/4] iio: adc: mcp3911: add support for the whole MCP39xx family
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Krzysztof Kozlowski
Quoted 2 lines · Jonathan Cameron
On Wed, 9 Aug 2023 08:41:05 +0200
Marcus Folkesson <[email protected]> wrote:
Quoted 8 lines
...
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Inconsistent macro implementation, i.e. you need to use (x).
Sorry, I do not get you
In other macros you avoid ambiguity of the parameter, so they can be evaluated properly, and not here.
Hrmf, I missed that I had asked about this before I sent out v5. Such a shame.
I got you now, thanks.
I agree that maybe it should be 'ch' instead.
Already existing macros for channel and offcal use 'x' though, so in that case should be changed as well.
#define MCP3911_CHANNEL(x) (MCP3911_REG_CHANNEL0 + x * 3)
#define MCP3911_OFFCAL(x) (MCP3911_REG_OFFCAL_CH0 + x * 6)
[...]
Quoted 8 lines
See (1) above ?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Best regards,
Marcus Folkesson