[1/3] iio: adc: ad7192: Use device api
Commit Message
From: Alisa-Dariana Roman <alisa.roman@analog.com>
Replace of.h and corresponding functions with preferred device specific
functions.
Also replace of_device_get_match_data function with
spi_get_device_match_data.
Signed-off-by: Alisa-Dariana Roman <alisa.roman@analog.com>
---
drivers/iio/adc/ad7192.c | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
Comments
On 05/11/2023 20:31, alisadariana@gmail.com wrote:
> From: Alisa-Dariana Roman <alisa.roman@analog.com>
>
> Replace of.h and corresponding functions with preferred device specific
> functions.
>
> Also replace of_device_get_match_data function with
> spi_get_device_match_data.
>
> Signed-off-by: Alisa-Dariana Roman <alisa.roman@analog.com>
> ---
> drivers/iio/adc/ad7192.c | 32 +++++++++++++++-----------------
> 1 file changed, 15 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
> index adc3cbe92d6e..48e0357564af 100644
> --- a/drivers/iio/adc/ad7192.c
> +++ b/drivers/iio/adc/ad7192.c
> @@ -17,7 +17,6 @@
> #include <linux/err.h>
> #include <linux/sched.h>
> #include <linux/delay.h>
> -#include <linux/of.h>
>
> #include <linux/iio/iio.h>
> #include <linux/iio/sysfs.h>
> @@ -364,19 +363,19 @@ static inline bool ad7192_valid_external_frequency(u32 freq)
> freq <= AD7192_EXT_FREQ_MHZ_MAX);
> }
>
> -static int ad7192_of_clock_select(struct ad7192_state *st)
> +static int ad7192_device_clock_select(struct ad7192_state *st)
> {
> - struct device_node *np = st->sd.spi->dev.of_node;
> + struct device *dev = &st->sd.spi->dev;
> unsigned int clock_sel;
>
> clock_sel = AD7192_CLK_INT;
>
> /* use internal clock */
> if (!st->mclk) {
> - if (of_property_read_bool(np, "adi,int-clock-output-enable"))
> + if (device_property_read_bool(dev, "adi,int-clock-output-enable"))
> clock_sel = AD7192_CLK_INT_CO;
> } else {
> - if (of_property_read_bool(np, "adi,clock-xtal"))
> + if (device_property_read_bool(dev, "adi,clock-xtal"))
> clock_sel = AD7192_CLK_EXT_MCLK1_2;
> else
> clock_sel = AD7192_CLK_EXT_MCLK2;
> @@ -385,9 +384,10 @@ static int ad7192_of_clock_select(struct ad7192_state *st)
> return clock_sel;
> }
>
> -static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
> +static int ad7192_setup(struct iio_dev *indio_dev)
> {
> struct ad7192_state *st = iio_priv(indio_dev);
> + struct device *dev = &st->sd.spi->dev;
> bool rej60_en, refin2_en;
> bool buf_en, bipolar, burnout_curr_en;
> unsigned long long scale_uv;
> @@ -416,26 +416,26 @@ static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
>
> st->conf = FIELD_PREP(AD7192_CONF_GAIN_MASK, 0);
>
> - rej60_en = of_property_read_bool(np, "adi,rejection-60-Hz-enable");
> + rej60_en = device_property_read_bool(dev, "adi,rejection-60-Hz-enable");
Not strictly related to your patch, but where are these properties
documented?
Best regards,
Krzysztof
On Sun, Nov 05, 2023 at 09:31:29PM +0200, alisadariana@gmail.com wrote:
> From: Alisa-Dariana Roman <alisa.roman@analog.com>
>
> Replace of.h and corresponding functions with preferred device specific
> functions.
>
> Also replace of_device_get_match_data function with
of_device_get_match_data()
> spi_get_device_match_data.
spi_get_device_match_data()
With the above fixed,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
The first patch should be documentation of the properties as Krzysztof noted.
P.S. Also consider using or taking an ideas from the "smart" script [1] I wrote
to send patches, it will put the better list of people into the proper places,
including maintainers and mailing lists.
[1]: https://github.com/andy-shev/home-bin-tools/blob/master/ge2maintainer.sh
On 06.11.2023 11:24, Krzysztof Kozlowski wrote:
> On 05/11/2023 20:31, alisadariana@gmail.com wrote:
>> From: Alisa-Dariana Roman <alisa.roman@analog.com>
>>
>> Replace of.h and corresponding functions with preferred device specific
>> functions.
>>
>> Also replace of_device_get_match_data function with
>> spi_get_device_match_data.
>>
>> Signed-off-by: Alisa-Dariana Roman <alisa.roman@analog.com>
>> ---
>> drivers/iio/adc/ad7192.c | 32 +++++++++++++++-----------------
>> 1 file changed, 15 insertions(+), 17 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
>> index adc3cbe92d6e..48e0357564af 100644
>> --- a/drivers/iio/adc/ad7192.c
>> +++ b/drivers/iio/adc/ad7192.c
>> @@ -17,7 +17,6 @@
>> #include <linux/err.h>
>> #include <linux/sched.h>
>> #include <linux/delay.h>
>> -#include <linux/of.h>
>>
>> #include <linux/iio/iio.h>
>> #include <linux/iio/sysfs.h>
>> @@ -364,19 +363,19 @@ static inline bool ad7192_valid_external_frequency(u32 freq)
>> freq <= AD7192_EXT_FREQ_MHZ_MAX);
>> }
>>
>> -static int ad7192_of_clock_select(struct ad7192_state *st)
>> +static int ad7192_device_clock_select(struct ad7192_state *st)
>> {
>> - struct device_node *np = st->sd.spi->dev.of_node;
>> + struct device *dev = &st->sd.spi->dev;
>> unsigned int clock_sel;
>>
>> clock_sel = AD7192_CLK_INT;
>>
>> /* use internal clock */
>> if (!st->mclk) {
>> - if (of_property_read_bool(np, "adi,int-clock-output-enable"))
>> + if (device_property_read_bool(dev, "adi,int-clock-output-enable"))
>> clock_sel = AD7192_CLK_INT_CO;
>> } else {
>> - if (of_property_read_bool(np, "adi,clock-xtal"))
>> + if (device_property_read_bool(dev, "adi,clock-xtal"))
>> clock_sel = AD7192_CLK_EXT_MCLK1_2;
>> else
>> clock_sel = AD7192_CLK_EXT_MCLK2;
>> @@ -385,9 +384,10 @@ static int ad7192_of_clock_select(struct ad7192_state *st)
>> return clock_sel;
>> }
>>
>> -static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
>> +static int ad7192_setup(struct iio_dev *indio_dev)
>> {
>> struct ad7192_state *st = iio_priv(indio_dev);
>> + struct device *dev = &st->sd.spi->dev;
>> bool rej60_en, refin2_en;
>> bool buf_en, bipolar, burnout_curr_en;
>> unsigned long long scale_uv;
>> @@ -416,26 +416,26 @@ static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
>>
>> st->conf = FIELD_PREP(AD7192_CONF_GAIN_MASK, 0);
>>
>> - rej60_en = of_property_read_bool(np, "adi,rejection-60-Hz-enable");
>> + rej60_en = device_property_read_bool(dev, "adi,rejection-60-Hz-enable");
>
> Not strictly related to your patch, but where are these properties
> documented?
>
>
> Best regards,
> Krzysztof
>
Thank you for the feedback! The properties are documented in
Documentation/devicetree/bindings/iio/adc/adi,ad7192.yaml. But the
properties related to the clock configuration are indeed missing. I will
add them.
Kind regards,
Alisa-Dariana Roman
@@ -17,7 +17,6 @@
#include <linux/err.h>
#include <linux/sched.h>
#include <linux/delay.h>
-#include <linux/of.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
@@ -364,19 +363,19 @@ static inline bool ad7192_valid_external_frequency(u32 freq)
freq <= AD7192_EXT_FREQ_MHZ_MAX);
}
-static int ad7192_of_clock_select(struct ad7192_state *st)
+static int ad7192_device_clock_select(struct ad7192_state *st)
{
- struct device_node *np = st->sd.spi->dev.of_node;
+ struct device *dev = &st->sd.spi->dev;
unsigned int clock_sel;
clock_sel = AD7192_CLK_INT;
/* use internal clock */
if (!st->mclk) {
- if (of_property_read_bool(np, "adi,int-clock-output-enable"))
+ if (device_property_read_bool(dev, "adi,int-clock-output-enable"))
clock_sel = AD7192_CLK_INT_CO;
} else {
- if (of_property_read_bool(np, "adi,clock-xtal"))
+ if (device_property_read_bool(dev, "adi,clock-xtal"))
clock_sel = AD7192_CLK_EXT_MCLK1_2;
else
clock_sel = AD7192_CLK_EXT_MCLK2;
@@ -385,9 +384,10 @@ static int ad7192_of_clock_select(struct ad7192_state *st)
return clock_sel;
}
-static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
+static int ad7192_setup(struct iio_dev *indio_dev)
{
struct ad7192_state *st = iio_priv(indio_dev);
+ struct device *dev = &st->sd.spi->dev;
bool rej60_en, refin2_en;
bool buf_en, bipolar, burnout_curr_en;
unsigned long long scale_uv;
@@ -416,26 +416,26 @@ static int ad7192_setup(struct iio_dev *indio_dev, struct device_node *np)
st->conf = FIELD_PREP(AD7192_CONF_GAIN_MASK, 0);
- rej60_en = of_property_read_bool(np, "adi,rejection-60-Hz-enable");
+ rej60_en = device_property_read_bool(dev, "adi,rejection-60-Hz-enable");
if (rej60_en)
st->mode |= AD7192_MODE_REJ60;
- refin2_en = of_property_read_bool(np, "adi,refin2-pins-enable");
+ refin2_en = device_property_read_bool(dev, "adi,refin2-pins-enable");
if (refin2_en && st->chip_info->chip_id != CHIPID_AD7195)
st->conf |= AD7192_CONF_REFSEL;
st->conf &= ~AD7192_CONF_CHOP;
- buf_en = of_property_read_bool(np, "adi,buffer-enable");
+ buf_en = device_property_read_bool(dev, "adi,buffer-enable");
if (buf_en)
st->conf |= AD7192_CONF_BUF;
- bipolar = of_property_read_bool(np, "bipolar");
+ bipolar = device_property_read_bool(dev, "bipolar");
if (!bipolar)
st->conf |= AD7192_CONF_UNIPOLAR;
- burnout_curr_en = of_property_read_bool(np,
- "adi,burnout-currents-enable");
+ burnout_curr_en =
+ device_property_read_bool(dev, "adi,burnout-currents-enable");
if (burnout_curr_en && buf_en) {
st->conf |= AD7192_CONF_BURN;
} else if (burnout_curr_en) {
@@ -1117,9 +1117,7 @@ static int ad7192_probe(struct spi_device *spi)
}
st->int_vref_mv = ret / 1000;
- st->chip_info = of_device_get_match_data(&spi->dev);
- if (!st->chip_info)
- st->chip_info = (void *)spi_get_device_id(spi)->driver_data;
+ st->chip_info = spi_get_device_match_data(spi);
indio_dev->name = st->chip_info->name;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = st->chip_info->channels;
@@ -1140,7 +1138,7 @@ static int ad7192_probe(struct spi_device *spi)
if (IS_ERR(st->mclk))
return PTR_ERR(st->mclk);
- st->clock_sel = ad7192_of_clock_select(st);
+ st->clock_sel = ad7192_device_clock_select(st);
if (st->clock_sel == AD7192_CLK_EXT_MCLK1_2 ||
st->clock_sel == AD7192_CLK_EXT_MCLK2) {
@@ -1152,7 +1150,7 @@ static int ad7192_probe(struct spi_device *spi)
}
}
- ret = ad7192_setup(indio_dev, spi->dev.of_node);
+ ret = ad7192_setup(indio_dev);
if (ret)
return ret;