From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: MIME-Version: 1.0 In-Reply-To: <20170811143847.GA19152@localhost> References: <1501578742-4501-1-git-send-email-s.abhisit@gmail.com> <20170811143847.GA19152@localhost> From: Abhisit Sangjan Date: Fri, 18 Aug 2017 09:34:16 +0700 Message-ID: Subject: Re: [PATCH 2/5] iio: Add support for LMP92001 ADC To: jmondi Cc: Peter Meerwald-Stadler , jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, fabrice.gasnier@st.com, Lee Jones , robh@kernel.org, Akinobu Mita , marek.vasut+renesas@gmail.com, jacopo+renesas@jmondi.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org Content-Type: multipart/alternative; boundary="f403045ec4322c39780556fdf7f1" List-ID: --f403045ec4322c39780556fdf7f1 Content-Type: text/plain; charset="UTF-8" Hi Jmondi, Thank you for your recommend, I am testing the code will be send the new patch in soon. On Fri, Aug 11, 2017 at 9:38 PM, jmondi wrote: > Hi Abhisit, > > On Thu, Aug 03, 2017 at 12:40:49PM +0200, Peter Meerwald-Stadler wrote: > > > > > From: Abhisit Sangjan > > > > some more comments in addition to Jonathan's > > and some more here... As a general one, I see all code indented with > spaces O_0 > > Please run checkpatch as Jonathan said, and instruct your editor to > indent with tabs instead. > Abhisit: I have changed all space-bar to tab. > > Also, your Signed-off-by is missing (not sure it has been mentioned in > other review comments) > Abhisit: Sorry, I forget it, thanks. > > > > > > --- > > > drivers/iio/adc/Kconfig | 10 + > > > drivers/iio/adc/Makefile | 1 + > > > drivers/iio/adc/lmp92001-adc.c | 479 ++++++++++++++++++++++++++++++ > +++++++++++ > > > 3 files changed, 490 insertions(+) > > > create mode 100644 drivers/iio/adc/lmp92001-adc.c > > > > > > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig > > > index 614fa41..b623b4d 100644 > > > --- a/drivers/iio/adc/Kconfig > > > +++ b/drivers/iio/adc/Kconfig > > > @@ -857,4 +857,14 @@ config XILINX_XADC > > > The driver can also be build as a module. If so, the module will > be called > > > xilinx-xadc. > > > > > > +config LMP92001_ADC > > > + tristate "TI LMP92001 ADC Driver" > > > + depends on MFD_LMP92001 > > > + help > > > + If you say yes here you get support for TI LMP92001 ADCs > > > + conversion. > > > + > > > + This driver can also be built as a module. If so, the module > will > > > + be called lmp92001_adc. > > > + > > > endmenu > > > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile > > > index b546736a..75b24b1 100644 > > > --- a/drivers/iio/adc/Makefile > > > +++ b/drivers/iio/adc/Makefile > > > @@ -78,3 +78,4 @@ obj-$(CONFIG_VF610_ADC) += vf610_adc.o > > > obj-$(CONFIG_VIPERBOARD_ADC) += viperboard_adc.o > > > xilinx-xadc-y := xilinx-xadc-core.o xilinx-xadc-events.o > > > obj-$(CONFIG_XILINX_XADC) += xilinx-xadc.o > > > +obj-$(CONFIG_LMP92001_ADC) += lmp92001-adc.o > > > diff --git a/drivers/iio/adc/lmp92001-adc.c > b/drivers/iio/adc/lmp92001-adc.c > > > new file mode 100644 > > > index 0000000..909ff47 > > > --- /dev/null > > > +++ b/drivers/iio/adc/lmp92001-adc.c > > > @@ -0,0 +1,479 @@ > > > +/* > > > + * lmp92001-adc.c - Support for TI LMP92001 ADCs > > > + * > > > + * Copyright 2016-2017 Celestica Ltd. > > > + * > > > + * Author: Abhisit Sangjan > > > + * > > > + * Inspired by wm831x and ad5064 drivers. > > > + * > > > + * This program is free software; you can redistribute it and/or > modify > > > + * it under the terms of the GNU General Public License as published > by > > > + * the Free Software Foundation; either version 2 of the License, or > > > + * (at your option) any later version. > > > + * > > > + * This program is distributed in the hope that it will be useful, > > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > > + * GNU General Public License for more details. > > > + * > > > + */ > > > + > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > > +#include > > Keep also includes alphabetically sorted please > Abhisit: I see, thanks. > > > > + > > > +#include > > > + > > > +static int lmp92001_read_raw(struct iio_dev *indio_dev, > > > + struct iio_chan_spec const *channel, > int *val, > > > + int *val2, long mask) > > > +{ > > > + struct lmp92001 *lmp92001 = iio_device_get_drvdata(indio_ > dev); > > > + unsigned int code, cgen, sgen, try; > > > + int ret; > > > + > > > + ret = regmap_read(lmp92001->regmap, LMP92001_CGEN, &cgen); > > > + if (ret < 0) > > > + return ret; > > > + > > > + /* > > > + * Is not continuous conversion? > > > + * Lock the registers (if needed). > > > + * Triggering single-short conversion. > > > + * Waiting for conversion successfully. > > > + */ > > > + if (!(cgen & 1)) > > > + { > > > + if (!(cgen & 2)) > > > + { > > > + ret = regmap_update_bits(lmp92001->regmap, > > > + > LMP92001_CGEN, 2, 2); > > > + if (ret < 0) > > > + return ret; > > > + } > > > + > > > + ret = regmap_write(lmp92001->regmap, LMP92001_CTRIG, > 1); > > > + if (ret < 0) > > > + return ret; > > > + > > > + try = 10; > > > + do { > > > + ret = regmap_read(lmp92001->regmap, > > > + LMP92001_SGEN, &sgen); > > > + if(ret < 0) > > > > style, space after if, space around operators > > > > > + return ret; > > > + } while ((sgen & 1<<7) && (--try > 0)); > > > + > > > + if (!try) > > > + return -ETIME; > > > > most drivers use ETIMEOUT > > > > > + } > > > + > > > + ret = regmap_read(lmp92001->regmap, 0x1F + channel->channel, > &code); > > > + if (ret < 0) > > > + return ret; > > > + > > > + switch (mask) > > > + { > > > + case IIO_CHAN_INFO_RAW: > > > + switch (channel->type) { > > > + case IIO_VOLTAGE: > > > + case IIO_TEMP: > > > + *val = code; > > > + return IIO_VAL_INT; > > > + default: > > > + break; > > > + } > > > + break; > > > + default: > > > + break; > > You can remove these default cases or return -EINVAL here. > Abhisit: Okay, I will remove it. Could you tell me in detail. Sorry, I do not understand the Technical. > > > > + } > > > + > > > + return -EINVAL; > > > +} > > > + > > > +/* > > > + * TODO: do your attributes even handler for > > > + * Current limit low/high for CH 1-3, 9-11! > > > + * In case INT1 and INT2 were connected to i.MX6. > > > + */ > > Why mention the SoC here? > Abhisit: I have remove it. > > > > +static const struct iio_info lmp92001_info = { > > > + .read_raw = lmp92001_read_raw, > > > + .driver_module = THIS_MODULE, > > > +}; > > > + > > > +static ssize_t lmp92001_avref_read(struct iio_dev *indio_dev, > uintptr_t private, > > > + struct iio_chan_spec const *channel, char > *buf) > > > +{ > > > + struct lmp92001 *lmp92001 = iio_device_get_drvdata(indio_ > dev); > > > + unsigned int cref; > > > + int ret; > > > + > > > + ret = regmap_read(lmp92001->regmap, LMP92001_CREF, &cref); > > > + if (ret < 0) > > > + return ret; > > > + > > > + return sprintf(buf, "%s\n", cref & 2 ? "external" : > "internal"); > > > +} > > > + > > > +static ssize_t lmp92001_avref_write(struct iio_dev *indio_dev, > uintptr_t private, > > > + struct iio_chan_spec const *channel, const > char *buf, > > > + size_t len) > > > +{ > > > + struct lmp92001 *lmp92001 = iio_device_get_drvdata(indio_ > dev); > > > + unsigned int cref; > > > + int ret; > > > + > > > + if (strcmp("external\n", buf) == 0) > > > + cref = 2; > > > + else if (strcmp("internal\n", buf) == 0) > > > + cref = 0; > > > + else > > > + return -EINVAL; > > > + > > > + ret = regmap_update_bits(lmp92001->regmap, LMP92001_CREF, 2, > cref); > > > + if (ret < 0) > > > + return ret; > > > + > > > + return len; > > > +} > > > + > > > +static ssize_t lmp92001_enable_read(struct iio_dev *indio_dev, > uintptr_t private, > > > + struct iio_chan_spec const *channel, char > *buf) > > > +{ > > > + struct lmp92001 *lmp92001 = iio_device_get_drvdata(indio_ > dev); > > > + unsigned int reg, cad; > > > + int ret; > > > + > > > + switch (channel->channel) > > > + { > > > + case 1 ... 8: > > > + reg = LMP92001_CAD1; > > > + break; > > > + case 9 ... 16: > > > + reg = LMP92001_CAD2; > > > + break; > > > + case 17: > > > + reg = LMP92001_CAD3; > > > + break; > > > + default: > > > + return -EINVAL; > > > + } > > > + > > > + ret = regmap_read(lmp92001->regmap, reg, &cad); > > > + if (ret < 0) > > > + return ret; > > > + > > > + if (channel->channel <= 8) > > > + cad >>= channel->channel - 1; > > > + else if(channel->channel > 8) > > > + cad >>= channel->channel - 9; > > > + else if(channel->channel > 16) > > > + cad >>= channel->channel - 17; > > > + else > > > + return -EINVAL; > > > + > > > + return sprintf(buf, "%s\n", cad & 1 ? "enable" : "disable"); > > > +} > > > + > > > +static ssize_t lmp92001_enable_write(struct iio_dev *indio_dev, > uintptr_t private, > > > + struct iio_chan_spec const *channel, const > char *buf, > > > + size_t len) > > > +{ > > > + struct lmp92001 *lmp92001 = iio_device_get_drvdata(indio_ > dev); > > > + unsigned int reg, enable, shif, mask; > > > + int ret; > > > + > > > + switch (channel->channel) > > > + { > > > + case 1 ... 8: > > > + reg = LMP92001_CAD1; > > > + shif = (channel->channel - 1); > > > + break; > > > + case 9 ... 16: > > > + reg = LMP92001_CAD2; > > > + shif = (channel->channel - 9); > > > + break; > > > + case 17: > > > + reg = LMP92001_CAD3; > > > + shif = (channel->channel - 17); > > > + break; > > > + default: > > > + return -EINVAL; > > > + } > > > + > > > + if (strcmp("enable\n", buf) == 0) > > Always use the length limited version of string manipulation functions > when possible (drop the \n, also) > Abhisit: It is optimization, I got you. > > > > + enable = 1; > > > + else if (strcmp("disable\n", buf) == 0) > > > + enable = 0; > > > + else > > > + return -EINVAL; > > > + > > > + enable <<= shif; > > > + mask = 1 << shif; > > > + > > > + ret = regmap_update_bits(lmp92001->regmap, reg, mask, > enable); > > > + if (ret < 0) > > > + return ret; > > > + > > > + return len; > > > +} > > > + > > > +static ssize_t lmp92001_mode_read(struct iio_dev *indio_dev, > uintptr_t private, > > > + struct iio_chan_spec const *channel, char > *buf) > > > +{ > > > + struct lmp92001 *lmp92001 = iio_device_get_drvdata(indio_ > dev); > > > + unsigned int cgen; > > > + int ret; > > > + > > > + ret = regmap_read(lmp92001->regmap, LMP92001_CGEN, &cgen); > > > + if (ret < 0) > > > + return ret; > > > + > > > + return sprintf(buf, "%s\n", cgen & 1 ? "continuous" : > "single-shot"); > > > +} > > > + > > > +static ssize_t lmp92001_mode_write(struct iio_dev *indio_dev, > uintptr_t private, > > > + struct iio_chan_spec const *channel, const > char *buf, > > > + size_t len) > > > +{ > > > + struct lmp92001 *lmp92001 = iio_device_get_drvdata(indio_ > dev); > > > + unsigned int cgen; > > > + int ret; > > > + > > > + if (strcmp("continuous\n", buf) == 0) > > > + cgen = 1; > > > + else if (strcmp("single-shot\n", buf) == 0) > > > + cgen = 0; > > > + else > > > + return -EINVAL; > > > + > > > + /* > > > + * Unlock the registers. > > > + * Set conversion mode. > > > + * Lock the registers. > > > + */ > > > + ret = regmap_update_bits(lmp92001->regmap, LMP92001_CGEN, 2, > 0); > > > + if (ret < 0) > > > + return ret; > > > + > > > + ret = regmap_update_bits(lmp92001->regmap, LMP92001_CGEN, 1, > cgen); > > > + if (ret < 0) > > > + return ret; > > > + > > > + ret = regmap_update_bits(lmp92001->regmap, LMP92001_CGEN, 2, > 2); > > > + if (ret < 0) > > > + return ret; > > > + > > > + return len; > > > +} > > > + > > > +static const struct iio_chan_spec_ext_info lmp92001_ext_info[] = { > > > + { > > > + .name = "vref", > > > + .read = lmp92001_avref_read, > > > + .write = lmp92001_avref_write, > > > + .shared = IIO_SHARED_BY_ALL, > > > + }, > > > + { > > > + .name = "en", > > > + .read = lmp92001_enable_read, > > > + .write = lmp92001_enable_write, > > > + .shared = IIO_SEPARATE, > > > + }, > > > + { > > > + .name = "mode", > > > + .read = lmp92001_mode_read, > > > + .write = lmp92001_mode_write, > > > + .shared = IIO_SHARED_BY_ALL, > > > + }, > > > + { }, > > > +}; > > > + > > > +static const struct iio_event_spec lmp92001_events[] = { > > > + { > > > + .type = IIO_EV_TYPE_THRESH, > > > + .dir = IIO_EV_DIR_RISING, > > > + .mask_separate = BIT(IIO_EV_INFO_ENABLE) | > > > + BIT(IIO_EV_INFO_VALUE), > > > + }, > > > + { > > > + .type = IIO_EV_TYPE_THRESH, > > > + .dir = IIO_EV_DIR_FALLING, > > > + .mask_separate = BIT(IIO_EV_INFO_ENABLE) | > > > + BIT(IIO_EV_INFO_VALUE), > > > + }, > > > + { }, > > > +}; > > > + > > > +#define LMP92001_CHAN_SPEC(_ch, _type, _event, _nevent) \ > > > +{ \ > > > + .channel = _ch, \ > > > + .scan_index = _ch, \ > > > + .scan_type = { \ > > > + .sign = 'u', \ > > > + .realbits = 12, \ > > > + .storagebits = 16, \ > > > + .repeat = 1, \ > > > + .endianness = IIO_BE, \ > > > + }, \ > > > + .type = _type, \ > > > + .indexed = 1, \ > > > + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ > > > + .event_spec = _event, \ > > > + .num_event_specs = _nevent, \ > > > + .ext_info = lmp92001_ext_info, \ > > > +} > > > + > > > +/* > > > + * TODO: do your ext_info for current low/high limit. > > > + * Example driver/iio/dac/ad5064.c > > > + */ > > > +static const struct iio_chan_spec lmp92001_adc_channels[] = { > > > + LMP92001_CHAN_SPEC( 1, IIO_VOLTAGE, lmp92001_events, > ARRAY_SIZE(lmp92001_events)), > > > + LMP92001_CHAN_SPEC( 2, IIO_VOLTAGE, lmp92001_events, > ARRAY_SIZE(lmp92001_events)), > > > + LMP92001_CHAN_SPEC( 3, IIO_VOLTAGE, lmp92001_events, > ARRAY_SIZE(lmp92001_events)), > > > + LMP92001_CHAN_SPEC( 4, IIO_VOLTAGE, NULL, 0), > > > + LMP92001_CHAN_SPEC( 5, IIO_VOLTAGE, NULL, 0), > > > + LMP92001_CHAN_SPEC( 6, IIO_VOLTAGE, NULL, 0), > > > + LMP92001_CHAN_SPEC( 7, IIO_VOLTAGE, NULL, 0), > > > + LMP92001_CHAN_SPEC( 8, IIO_VOLTAGE, NULL, 0), > > > + LMP92001_CHAN_SPEC( 9, IIO_VOLTAGE, lmp92001_events, > ARRAY_SIZE(lmp92001_events)), > > > + LMP92001_CHAN_SPEC(10, IIO_VOLTAGE, lmp92001_events, > ARRAY_SIZE(lmp92001_events)), > > > + LMP92001_CHAN_SPEC(11, IIO_VOLTAGE, lmp92001_events, > ARRAY_SIZE(lmp92001_events)), > > > + LMP92001_CHAN_SPEC(12, IIO_VOLTAGE, NULL, 0), > > > + LMP92001_CHAN_SPEC(13, IIO_VOLTAGE, NULL, 0), > > > + LMP92001_CHAN_SPEC(14, IIO_VOLTAGE, NULL, 0), > > > + LMP92001_CHAN_SPEC(15, IIO_VOLTAGE, NULL, 0), > > > + LMP92001_CHAN_SPEC(16, IIO_VOLTAGE, NULL, 0), > > > + LMP92001_CHAN_SPEC(17, IIO_TEMP, NULL, 0), > > > > wondering in what unit the drivers reports _TEMP, probably _SCALE needed > > > > > +}; > > > + > > > +static int lmp92001_adc_probe(struct platform_device *pdev) > > > +{ > > > + struct lmp92001 *lmp92001 = dev_get_drvdata(pdev->dev. > parent); > > > + struct iio_dev *indio_dev; > > > + struct device_node *np = pdev->dev.of_node; > > > + const char *conversion; > > > + unsigned int cgen = 0, cad1, cad2, cad3; > > > + u32 mask; > > > + int ret; > > > + > > > + indio_dev = devm_iio_device_alloc(&pdev->dev, > sizeof(*lmp92001)); > > > + if (!indio_dev) > > > + return -ENOMEM; > > > + > > > + iio_device_set_drvdata(indio_dev, lmp92001); > > > + > > > + indio_dev->name = pdev->name; > > > + indio_dev->dev.parent = &pdev->dev; > > > + indio_dev->modes = INDIO_DIRECT_MODE; > > > + indio_dev->info = &lmp92001_info; > > > + indio_dev->channels = lmp92001_adc_channels; > > > + indio_dev->num_channels = ARRAY_SIZE(lmp92001_adc_channels); > > > + > > > + ret = regmap_update_bits(lmp92001->regmap, LMP92001_CGEN, > 0x80, 0x80); > > > + if (ret < 0) > > > + { > > > + dev_err(&pdev->dev,"failed to self reset all > registers\n"); > > > + return ret; > > > + } > > > + > > > + ret = of_property_read_u32(np, "ti,lmp92001-adc-mask", &mask); > > > + if (ret < 0) > > > + { > > > + cad1 = cad2 = cad3 = 0xFF; > > > + dev_info(&pdev->dev, "turn on all of channels by > default\n"); > > > + } > > > + else > > > + { > > > + cad1 = mask & 0xFF; > > > + cad2 = (mask >> 8) & 0xFF; > > > + cad3 = (mask >> 16) & 0xFF; > > > + } > > > + > > > + ret = regmap_update_bits(lmp92001->regmap, LMP92001_CAD1, > 0xFF, cad1); > > > + if (ret < 0) > > > + { > > > + dev_err(&pdev->dev,"failed to enable channels 1-8\n"); > > > + return ret; > > > + } > > > + > > > + ret = regmap_update_bits(lmp92001->regmap, LMP92001_CAD2, > 0xFF, cad2); > > > + if (ret < 0) > > > + { > > > + dev_err(&pdev->dev, "failed to enable channels > 9-16\n"); > > > + return ret; > > > + } > > > + > > > + ret = regmap_update_bits(lmp92001->regmap, LMP92001_CAD3, 1, > cad3); > > > + if (ret < 0) > > > + { > > > + dev_err(&pdev->dev, "failed to enable channel 17 > (temperature)\n"); > > > + return ret; > > > + } > > > + > > > + ret = of_property_read_string_index(np, > "ti,lmp92001-adc-mode", 0, > > > + &conversion); > > > + if (!ret) > > > + { > > > + if (strcmp("continuous", conversion) == 0) > > > + cgen |= 1; > > > + else if (strcmp("single-shot", conversion) == 0) > > > + { /* Okay */ } > > > + else > > > + dev_warn(&pdev->dev, > > > + "wrong adc mode! set to single-short > conversion\n"); > > > + } > > > + else > > > + dev_info(&pdev->dev, > > > + "single-short conversion was chosen by default\n"); > > > + > > > + /* > > > + * Lock the registers and set conversion mode. > > > + */ > > > + ret = regmap_update_bits(lmp92001->regmap, > > > + LMP92001_CGEN, 3, cgen | 2); > > > + if (ret < 0) > > > + return ret; > > > + > > > + platform_set_drvdata(pdev, indio_dev); > > > + > > > + return iio_device_register(indio_dev); > > You are using devm_ version of iio_device_alloc, maybe you can use > devm version of iio_device_register here as well > Abhisit: I will be changed it. > > > > +} > > > + > > > +static int lmp92001_adc_remove(struct platform_device *pdev) > > > +{ > > > + struct iio_dev *indio_dev = platform_get_drvdata(pdev); > > > + > > > + iio_device_unregister(indio_dev); > > with devm_ version of above functions, I guess you can remove this if > no other clean ups are required > Abhisit: I will do, thanks. > > Thanks > j > > > > + > > > + return 0; > > > +} > > > + > > > +static struct platform_driver lmp92001_adc_driver = { > > > + .driver.name = "lmp92001-adc", > > > + .driver.owner = THIS_MODULE, > > > + .probe = lmp92001_adc_probe, > > > + .remove = lmp92001_adc_remove, > > > +}; > > > + > > > +static int __init lmp92001_adc_init(void) > > > +{ > > > + return platform_driver_register(&lmp92001_adc_driver); > > > +} > > > +subsys_initcall(lmp92001_adc_init); > > > + > > > +static void __exit lmp92001_adc_exit(void) > > > +{ > > > + platform_driver_unregister(&lmp92001_adc_driver); > > > +} > > > +module_exit(lmp92001_adc_exit); > > > + > > > +MODULE_AUTHOR("Abhisit Sangjan "); > > > +MODULE_DESCRIPTION("IIO ADC interface for TI LMP92001"); > > > +MODULE_LICENSE("GPL"); > > > +MODULE_ALIAS("platform:lmp92001-adc"); > > > > > > > -- > > > > Peter Meerwald-Stadler > > Mobile: +43 664 24 44 418 > --f403045ec4322c39780556fdf7f1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Jmondi,

Thank you for your recommend= , I am testing the code will be send the new patch in soon.

On Fri, Aug 11, 2017 at 9:3= 8 PM, jmondi <jacopo@jmondi.org> wrote:
Hi Abhisit,

On Thu, Aug 03, 2017 at 12:40:49PM +0200, Peter Meerwald-Stadler wrote:
>
> > From: Abhisit Sangjan <= s.abhisit@gmail.com>
>
> some more comments in addition to Jonathan's

and some more here... As a general one, I see all code indented with=
spaces O_0

Please run checkpatch as Jonathan said, and instruct your editor to
indent with tabs instead.

Abhisit: I ha= ve changed all space-bar to =C2=A0tab.
=C2=A0

Also, your Signed-off-by is missing (not sure it has been mentioned in
other review comments)

Abhisit: Sorry, = I forget it, thanks.
=C2=A0
=C2=A0
>
> > ---
> >=C2=A0 drivers/iio/adc/Kconfig=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 = 10 +
> >=C2=A0 drivers/iio/adc/Makefile=C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 = =C2=A01 +
> >=C2=A0 drivers/iio/adc/lmp92001-adc.c | 479 ++++++++++++++++++++++= +++++++++++++++++++
> >=C2=A0 3 files changed, 490 insertions(+)
> >=C2=A0 create mode 100644 drivers/iio/adc/lmp92001-adc.c
> >
> > diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig > > index 614fa41..b623b4d 100644
> > --- a/drivers/iio/adc/Kconfig
> > +++ b/drivers/iio/adc/Kconfig
> > @@ -857,4 +857,14 @@ config XILINX_XADC
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0The driver can also be build as a modul= e. If so, the module will be called
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0xilinx-xadc.
> >
> > +config LMP92001_ADC
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0tristate "TI LMP92001 ADC Driver= "
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0depends on MFD_LMP92001
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0help
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0If you say yes here you get su= pport for TI LMP92001 ADCs
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0conversion.
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0This driver can also be built = as a module. If so, the module will
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0be called lmp92001_adc.
> > +
> >=C2=A0 endmenu
> > diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile<= br> > > index b546736a..75b24b1 100644
> > --- a/drivers/iio/adc/Makefile
> > +++ b/drivers/iio/adc/Makefile
> > @@ -78,3 +78,4 @@ obj-$(CONFIG_VF610_ADC) +=3D vf610_adc.o
> >=C2=A0 obj-$(CONFIG_VIPERBOARD_ADC) +=3D viperboard_adc.o
> >=C2=A0 xilinx-xadc-y :=3D xilinx-xadc-core.o xilinx-xadc-events.o<= br> > >=C2=A0 obj-$(CONFIG_XILINX_XADC) +=3D xilinx-xadc.o
> > +obj-$(CONFIG_LMP92001_ADC) +=3D lmp92001-adc.o
> > diff --git a/drivers/iio/adc/lmp92001-adc.c b/drivers/iio/ad= c/lmp92001-adc.c
> > new file mode 100644
> > index 0000000..909ff47
> > --- /dev/null
> > +++ b/drivers/iio/adc/lmp92001-adc.c
> > @@ -0,0 +1,479 @@
> > +/*
> > + * lmp92001-adc.c - Support for TI LMP92001 ADCs
> > + *
> > + * Copyright 2016-2017 Celestica Ltd.
> > + *
> > + * Author: Abhisit Sangjan <s.abhisit@gmail.com>
> > + *
> > + * Inspired by wm831x and ad5064 drivers.
> > + *
> > + * This program is free software; you can redistribute it and/or= modify
> > + * it under the terms of the GNU General Public License as publi= shed by
> > + * the Free Software Foundation; either version 2 of the License= , or
> > + * (at your option) any later version.
> > + *
> > + * This program is distributed in the hope that it will be usefu= l,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty o= f
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.=C2=A0 Se= e the
> > + * GNU General Public License for more details.
> > + *
> > + */
> > +
> > +#include <linux/kernel.h>
> > +#include <linux/module.h>
> > +#include <linux/iio/iio.h>
> > +#include <linux/mfd/core.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/interrupt.h>

Keep also includes alphabetically sorted please

Abhisit: I see, thanks.
=C2=A0

> > +
> > +#include <linux/mfd/lmp92001/core.h>
> > +
> > +static int lmp92001_read_raw(struct iio_dev *indio_dev,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 struct iio_chan_spec const= *channel, int *val,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int *val2, long mask)
> > +{
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct lmp92001 *lmp92001 =3D iio_de= vice_get_drvdata(indio_dev);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned int code, cgen, sgen, try;<= br> > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 int ret;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_read(lmp92001->reg= map, LMP92001_CGEN, &cgen);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 /*
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* Is not continuous conversion= ?
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* Lock the registers (if neede= d).
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* Triggering single-short conv= ersion.
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* Waiting for conversion succe= ssfully.
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!(cgen & 1))
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!(cg= en & 2))
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_update_bits(lmp92001->regmap, > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CGEN, = 2, 2);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return ret;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D = regmap_write(lmp92001->regmap, LMP92001_CTRIG, 1);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret = < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 return ret;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 try =3D = 10;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 do {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_read(lmp92001->regmap,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_SGEN, &sgen);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 if(ret < 0)
>
> style, space after if, space around operators
>
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return ret;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } while = ((sgen & 1<<7) && (--try > 0));
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!try= )
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 return -ETIME;
>
> most drivers use ETIMEOUT
>
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_read(lmp92001->reg= map, 0x1F + channel->channel, &code);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 switch (mask)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 case IIO_CHAN_INFO_RAW:
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 switch (= channel->type) {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 case IIO= _VOLTAGE:
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 case IIO= _TEMP:
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 *val =3D code;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 return IIO_VAL_INT;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 default:=
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 break;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break; > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 default:
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break;
You can remove these default cases or return -EINVAL here.
<= /blockquote>

Abhisit: Okay, I will remove it.
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Could you tell me in detail= . Sorry, I do not understand the Technical.
=C2=A0

> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 return -EINVAL;
> > +}
> > +
> > +/*
> > + * TODO: do your attributes even handler for
> > + * Current limit low/high for CH 1-3, 9-11!
> > + * In case INT1 and INT2 were connected to i.MX6.
> > + */

Why mention the SoC here?

Abhisi= t: I have remove it.
=C2=A0

> > +static const struct iio_info lmp92001_info =3D {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .read_raw =3D lmp92001_read_raw,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .driver_module =3D THIS_MODULE,
> > +};
> > +
> > +static ssize_t lmp92001_avref_read(struct iio_dev *indio_dev, ui= ntptr_t private,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 struct iio_chan_spec const *channel, char *buf)
> > +{
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct lmp92001 *lmp92001 =3D iio_de= vice_get_drvdata(indio_dev);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned int cref;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 int ret;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_read(lmp92001->reg= map, LMP92001_CREF, &cref);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 return sprintf(buf, "%s\n"= , cref & 2 ? "external" : "internal");
> > +}
> > +
> > +static ssize_t lmp92001_avref_write(struct iio_dev *indio_dev, u= intptr_t private,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0struct iio_chan_spec const *channel, const char = *buf,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0size_t len)
> > +{
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct lmp92001 *lmp92001 =3D iio_de= vice_get_drvdata(indio_dev);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned int cref;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 int ret;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (strcmp("external\n", b= uf) =3D=3D 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cref =3D= 2;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 else if (strcmp("internal\n&quo= t;, buf) =3D=3D 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cref =3D= 0;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 else
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -= EINVAL;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_update_bits(lmp92001-= >regmap, LMP92001_CREF, 2, cref);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 return len;
> > +}
> > +
> > +static ssize_t lmp92001_enable_read(struct iio_dev *indio_dev, u= intptr_t private,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 struct iio_chan_spec const *channel, char *buf)
> > +{
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct lmp92001 *lmp92001 =3D iio_de= vice_get_drvdata(indio_dev);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned int reg, cad;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 int ret;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 switch (channel->channel)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 case 1 ... 8:
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 reg =3D = LMP92001_CAD1;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break; > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 case 9 ... 16:
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 reg =3D = LMP92001_CAD2;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break; > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 case 17:
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 reg =3D = LMP92001_CAD3;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break; > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 default:
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -= EINVAL;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_read(lmp92001->reg= map, reg, &cad);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (channel->channel <=3D 8) > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cad >= >=3D channel->channel - 1;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 else if(channel->channel > 8)<= br> > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cad >= >=3D channel->channel - 9;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 else if(channel->channel > 16)=
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cad >= >=3D channel->channel - 17;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 else
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -= EINVAL;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 return sprintf(buf, "%s\n"= , cad & 1 ? "enable" : "disable");
> > +}
> > +
> > +static ssize_t lmp92001_enable_write(struct iio_dev *indio_dev, = uintptr_t private,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0struct iio_chan_spec const *channel, const char = *buf,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0size_t len)
> > +{
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct lmp92001 *lmp92001 =3D iio_de= vice_get_drvdata(indio_dev);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned int reg, enable, shif, mask= ;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 int ret;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 switch (channel->channel)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 case 1 ... 8:
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 reg =3D = LMP92001_CAD1;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 shif =3D= (channel->channel - 1);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break; > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 case 9 ... 16:
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 reg =3D = LMP92001_CAD2;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 shif =3D= (channel->channel - 9);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break; > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 case 17:
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 reg =3D = LMP92001_CAD3;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 shif =3D= (channel->channel - 17);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break; > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 default:
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -= EINVAL;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (strcmp("enable\n", buf= ) =3D=3D 0)

Always use the length limited version of string manipulation fu= nctions
when possible (drop the \n, also)

Abhis= it: It is optimization, I got you.
=C2=A0

> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 enable = =3D 1;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 else if (strcmp("disable\n"= ;, buf) =3D=3D 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 enable = =3D 0;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 else
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -= EINVAL;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 enable <<=3D shif;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 mask =3D 1 << shif;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_update_bits(lmp92001-= >regmap, reg, mask, enable);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 return len;
> > +}
> > +
> > +static ssize_t lmp92001_mode_read(struct iio_dev *indio_dev, uin= tptr_t private,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 struct iio_chan_spec const *channel, char *buf)
> > +{
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct lmp92001 *lmp92001 =3D iio_de= vice_get_drvdata(indio_dev);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned int cgen;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 int ret;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_read(lmp92001->reg= map, LMP92001_CGEN, &cgen);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 return sprintf(buf, "%s\n"= , cgen & 1 ? "continuous" : "single-shot");
> > +}
> > +
> > +static ssize_t lmp92001_mode_write(struct iio_dev *indio_dev, ui= ntptr_t private,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0struct iio_chan_spec const *channel, const char = *buf,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0size_t len)
> > +{
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct lmp92001 *lmp92001 =3D iio_de= vice_get_drvdata(indio_dev);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned int cgen;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 int ret;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (strcmp("continuous\n",= buf) =3D=3D 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cgen =3D= 1;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 else if (strcmp("single-shot\n&= quot;, buf) =3D=3D 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cgen =3D= 0;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 else
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -= EINVAL;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 /*
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* Unlock the registers.
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* Set conversion mode.
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* Lock the registers.
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_update_bits(lmp92001-= >regmap, LMP92001_CGEN, 2, 0);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_update_bits(lmp92001-= >regmap, LMP92001_CGEN, 1, cgen);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_update_bits(lmp92001-= >regmap, LMP92001_CGEN, 2, 2);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 return len;
> > +}
> > +
> > +static const struct iio_chan_spec_ext_info lmp92001_ext_info[] = =3D {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .name = =3D "vref",
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .read = =3D lmp92001_avref_read,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .write = =3D lmp92001_avref_write,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .shared = =3D IIO_SHARED_BY_ALL,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 },
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .name = =3D "en",
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .read = =3D lmp92001_enable_read,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .write = =3D lmp92001_enable_write,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .shared = =3D IIO_SEPARATE,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 },
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .name = =3D "mode",
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .read = =3D lmp92001_mode_read,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .write = =3D lmp92001_mode_write,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .shared = =3D IIO_SHARED_BY_ALL,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 },
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 { },
> > +};
> > +
> > +static const struct iio_event_spec lmp92001_events[] =3D {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .type = =3D IIO_EV_TYPE_THRESH,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .dir =3D= IIO_EV_DIR_RISING,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .mask_se= parate =3D BIT(IIO_EV_INFO_ENABLE) |
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 BIT(IIO_EV_INFO_VALUE),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 },
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .type = =3D IIO_EV_TYPE_THRESH,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .dir =3D= IIO_EV_DIR_FALLING,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .mask_se= parate =3D BIT(IIO_EV_INFO_ENABLE) |
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 BIT(IIO_EV_INFO_VALUE),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 },
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 { },
> > +};
> > +
> > +#define LMP92001_CHAN_SPEC(_ch, _type, _event, _nevent) \
> > +{ \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .channel =3D _ch, \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .scan_index =3D _ch, \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .scan_type =3D { \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 .sign =3D 'u', \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 .realbits =3D 12, \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 .storagebits =3D 16, \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 .repeat =3D 1, \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 .endianness =3D IIO_BE, \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }, \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .type =3D _type, \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .indexed =3D 1, \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .info_mask_separate =3D BIT(IIO_CHAN= _INFO_RAW), \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .event_spec =3D _event, \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .num_event_specs =3D _nevent, \
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .ext_info =3D lmp92001_ext_info, \ > > +}
> > +
> > +/*
> > + * TODO: do your ext_info for current low/high limit.
> > + * Example driver/iio/dac/ad5064.c
> > + */
> > +static const struct iio_chan_spec lmp92001_adc_channels[] =3D {<= br> > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC( 1, IIO_VOLTAGE, = lmp92001_events, ARRAY_SIZE(lmp92001_events)),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC( 2, IIO_VOLTAGE, = lmp92001_events, ARRAY_SIZE(lmp92001_events)),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC( 3, IIO_VOLTAGE, = lmp92001_events, ARRAY_SIZE(lmp92001_events)),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC( 4, IIO_VOLTAGE, = NULL, 0),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC( 5, IIO_VOLTAGE, = NULL, 0),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC( 6, IIO_VOLTAGE, = NULL, 0),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC( 7, IIO_VOLTAGE, = NULL, 0),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC( 8, IIO_VOLTAGE, = NULL, 0),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC( 9, IIO_VOLTAGE, = lmp92001_events, ARRAY_SIZE(lmp92001_events)),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC(10, IIO_VOLTAGE, = lmp92001_events, ARRAY_SIZE(lmp92001_events)),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC(11, IIO_VOLTAGE, = lmp92001_events, ARRAY_SIZE(lmp92001_events)),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC(12, IIO_VOLTAGE, = NULL, 0),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC(13, IIO_VOLTAGE, = NULL, 0),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC(14, IIO_VOLTAGE, = NULL, 0),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC(15, IIO_VOLTAGE, = NULL, 0),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC(16, IIO_VOLTAGE, = NULL, 0),
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 LMP92001_CHAN_SPEC(17,=C2=A0 =C2=A0 = IIO_TEMP, NULL, 0),
>
> wondering in what unit the drivers reports _TEMP, probably _SCALE need= ed
>
> > +};
> > +
> > +static int lmp92001_adc_probe(struct platform_device *pdev)
> > +{
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct lmp92001 *lmp92001 =3D dev_ge= t_drvdata(pdev->dev.parent);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct iio_dev *indio_dev;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct device_node *np =3D pdev->= dev.of_node;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 const char *conversion;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned int cgen =3D 0, cad1, cad2,= cad3;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 u32 mask;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 int ret;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev =3D devm_iio_device_alloc(= &pdev->dev, sizeof(*lmp92001));
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!indio_dev)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -= ENOMEM;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 iio_device_set_drvdata(indio_de= v, lmp92001);
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->name =3D pdev->name= ;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->dev.parent =3D &pd= ev->dev;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->modes =3D INDIO_DIRECT= _MODE;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->info =3D &lmp92001= _info;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->channels =3D lmp92001_= adc_channels;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->num_channels =3D ARRAY= _SIZE(lmp92001_adc_channels);
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_update_bits(lmp92001-= >regmap, LMP92001_CGEN, 0x80, 0x80);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dev_err(= &pdev->dev,"failed to self reset all registers\n");
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D of_property_read_u32(np, &qu= ot;ti,lmp92001-adc-mask", &mask);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cad1 =3D= cad2 =3D cad3 =3D 0xFF;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dev_info= (&pdev->dev, "turn on all of channels by default\n");
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 else
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cad1 =3D= mask & 0xFF;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cad2 =3D= (mask >> 8) & 0xFF;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cad3 =3D= (mask >> 16) & 0xFF;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_update_bits(lmp92001-= >regmap, LMP92001_CAD1, 0xFF, cad1);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dev_err(= &pdev->dev,"failed to enable channels 1-8\n");
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_update_bits(lmp92001-= >regmap, LMP92001_CAD2, 0xFF, cad2);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dev_err(= &pdev->dev, "failed to enable channels 9-16\n");
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_update_bits(lmp92001-= >regmap, LMP92001_CAD3, 1, cad3);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dev_err(= &pdev->dev, "failed to enable channel 17 (temperature)\n")= ;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D of_property_read_string_inde= x(np, "ti,lmp92001-adc-mode", 0,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &conversion);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!ret)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (strc= mp("continuous", conversion) =3D=3D 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 cgen |=3D 1;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else if = (strcmp("single-shot", conversion) =3D=3D 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 { /* Okay */ }
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 dev_warn(&pdev->dev,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 "wrong adc mode! set to single-short conversion\n= ");
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 else
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dev_info= (&pdev->dev,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "si= ngle-short conversion was chosen by default\n");
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 /*
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* Lock the registers and set c= onversion mode.
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D regmap_update_bits(lmp92001-= >regmap,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 LMP92001_CGEN, 3, cgen | 2);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ret < 0)
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return r= et;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 platform_set_drvdata(pdev, indio_dev= );
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 return iio_device_register(indio_dev= );

You are using devm_ version of iio_device_alloc, maybe you can = use
devm version of iio_device_register here as well

<= /div>
Abhisit: I will be changed it.
=C2=A0

> > +}
> > +
> > +static int lmp92001_adc_remove(struct platform_device *pdev)
> > +{
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct iio_dev *indio_dev =3D platfo= rm_get_drvdata(pdev);
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 iio_device_unregister(indio_dev= );

with devm_ version of above functions, I guess you can remove this i= f
no other clean ups are required

Abhisit= : I will do, thanks.
=C2=A0

Thanks
=C2=A0 j

> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 return 0;
> > +}
> > +
> > +static struct platform_driver lmp92001_adc_driver =3D {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .driver.name=C2=A0 =C2=A0 =3D "lm= p92001-adc",
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .driver.owner=C2=A0 =C2=A0=3D THIS_M= ODULE,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .probe=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =3D lmp92001_adc_probe,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 .remove=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0=3D lmp92001_adc_remove,
> > +};
> > +
> > +static int __init lmp92001_adc_init(void)
> > +{
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 return platform_driver_register(&= ;lmp92001_adc_driver);
> > +}
> > +subsys_initcall(lmp92001_adc_init);
> > +
> > +static void __exit lmp92001_adc_exit(void)
> > +{
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 platform_driver_unregister(&lmp92001_adc_driver);
> > +}
> > +module_exit(lmp92001_adc_exit);
> > +
> > +MODULE_AUTHOR("Abhisit Sangjan <s.abhisit@gmail.com>");
> > +MODULE_DESCRIPTION("IIO ADC interface for TI LMP92001"= );
> > +MODULE_LICENSE("GPL");
> > +MODULE_ALIAS("platform:lmp92001-adc");
> >
>
> --
>
> Peter Meerwald-Stadler
> Mobile: +43 664 24 44 418

--f403045ec4322c39780556fdf7f1--