Message ID | 1592897399-24089-1-git-send-email-jprakash@codeaurora.org |
---|---|
Headers | show |
Series | iio: adc: Add support for QCOM SPMI PMIC7 ADC | expand |
On Tue, Jun 23, 2020 at 10:31 AM Jishnu Prakash <jprakash@codeaurora.org> wrote: > > Add info property under adc_data to support adding ADC variants > which may use different iio_info than the one defined for PMIC5. > FWIW, Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> > Signed-off-by: Jishnu Prakash <jprakash@codeaurora.org> > --- > drivers/iio/adc/qcom-spmi-adc5.c | 4 +++- > drivers/iio/adc/qcom-vadc-common.h | 1 + > 2 files changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c > index 21fdcde..0fa1d37 100644 > --- a/drivers/iio/adc/qcom-spmi-adc5.c > +++ b/drivers/iio/adc/qcom-spmi-adc5.c > @@ -629,6 +629,7 @@ static const struct adc5_data adc5_data_pmic = { > .full_scale_code_volt = 0x70e4, > .full_scale_code_cur = 0x2710, > .adc_chans = adc5_chans_pmic, > + .info = &adc5_info, > .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX]) > {250, 420, 840}, > .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX]) > @@ -643,6 +644,7 @@ static const struct adc5_data adc5_data_pmic_rev2 = { > .full_scale_code_volt = 0x4000, > .full_scale_code_cur = 0x1800, > .adc_chans = adc5_chans_rev2, > + .info = &adc5_info, > .decimation = (unsigned int [ADC5_DECIMATION_SAMPLES_MAX]) > {256, 512, 1024}, > .hw_settle_1 = (unsigned int [VADC_HW_SETTLE_SAMPLES_MAX]) > @@ -777,7 +779,7 @@ static int adc5_probe(struct platform_device *pdev) > indio_dev->dev.of_node = node; > indio_dev->name = pdev->name; > indio_dev->modes = INDIO_DIRECT_MODE; > - indio_dev->info = &adc5_info; > + indio_dev->info = adc->data->info; > indio_dev->channels = adc->iio_chans; > indio_dev->num_channels = adc->nchannels; > > diff --git a/drivers/iio/adc/qcom-vadc-common.h b/drivers/iio/adc/qcom-vadc-common.h > index e074902a..6a7553f 100644 > --- a/drivers/iio/adc/qcom-vadc-common.h > +++ b/drivers/iio/adc/qcom-vadc-common.h > @@ -136,6 +136,7 @@ struct adc5_data { > const u32 full_scale_code_volt; > const u32 full_scale_code_cur; > const struct adc5_channels *adc_chans; > + const struct iio_info *info; > unsigned int *decimation; > unsigned int *hw_settle_1; > unsigned int *hw_settle_2; > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project >
On Tue, Jun 23, 2020 at 10:31 AM Jishnu Prakash <jprakash@codeaurora.org> wrote: > > Clean up some return value checks to make code more compact. > FWIW, Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> > Signed-off-by: Jishnu Prakash <jprakash@codeaurora.org> > --- > drivers/iio/adc/qcom-spmi-adc5.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) > > diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c > index dcc7599..3022313 100644 > --- a/drivers/iio/adc/qcom-spmi-adc5.c > +++ b/drivers/iio/adc/qcom-spmi-adc5.c > @@ -301,7 +301,7 @@ static int adc5_configure(struct adc5_chip *adc, > > /* Read registers 0x42 through 0x46 */ > ret = adc5_read(adc, ADC5_USR_DIG_PARAM, buf, sizeof(buf)); > - if (ret < 0) > + if (ret) > return ret; > > /* Digital param selection */ > @@ -388,7 +388,7 @@ static int adc5_do_conversion(struct adc5_chip *adc, > > if (adc->poll_eoc) { > ret = adc5_poll_wait_eoc(adc); > - if (ret < 0) { > + if (ret) { > pr_err("EOC bit not set\n"); > goto unlock; > } > @@ -398,7 +398,7 @@ static int adc5_do_conversion(struct adc5_chip *adc, > if (!ret) { > pr_debug("Did not get completion timeout.\n"); > ret = adc5_poll_wait_eoc(adc); > - if (ret < 0) { > + if (ret) { > pr_err("EOC bit not set\n"); > goto unlock; > } > @@ -516,8 +516,6 @@ static int adc5_read_raw(struct iio_dev *indio_dev, > default: > return -EINVAL; > } > - > - return 0; > } > > static int adc7_read_raw(struct iio_dev *indio_dev, > @@ -761,7 +759,7 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc, > > ret = adc5_read(adc, ADC5_USR_REVISION1, dig_version, > sizeof(dig_version)); > - if (ret < 0) { > + if (ret) { > dev_err(dev, "Invalid dig version read %d\n", ret); > return ret; > } > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project >
On Tue, 23 Jun 2020 12:59:59 +0530 Jishnu Prakash <jprakash@codeaurora.org> wrote: > Add a common function used for read_raw callback for both PMIC5 > and PMIC7 ADCs. > > Signed-off-by: Jishnu Prakash <jprakash@codeaurora.org> Looks good. Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to poke at it. Thanks, Jonathan > --- > drivers/iio/adc/qcom-spmi-adc5.c | 49 ++++++++++++++++------------------------ > 1 file changed, 19 insertions(+), 30 deletions(-) > > diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c > index 0f9af66..88efadb 100644 > --- a/drivers/iio/adc/qcom-spmi-adc5.c > +++ b/drivers/iio/adc/qcom-spmi-adc5.c > @@ -449,6 +449,11 @@ static int adc7_do_conversion(struct adc5_chip *adc, > return ret; > } > > +typedef int (*adc_do_conversion)(struct adc5_chip *adc, > + struct adc5_channel_prop *prop, > + struct iio_chan_spec const *chan, > + u16 *data_volt, u16 *data_cur); > + > static irqreturn_t adc5_isr(int irq, void *dev_id) > { > struct adc5_chip *adc = dev_id; > @@ -487,9 +492,9 @@ static int adc7_of_xlate(struct iio_dev *indio_dev, > return -EINVAL; > } > > -static int adc5_read_raw(struct iio_dev *indio_dev, > +static int adc_read_raw_common(struct iio_dev *indio_dev, > struct iio_chan_spec const *chan, int *val, int *val2, > - long mask) > + long mask, adc_do_conversion do_conv) > { > struct adc5_chip *adc = iio_priv(indio_dev); > struct adc5_channel_prop *prop; > @@ -500,8 +505,8 @@ static int adc5_read_raw(struct iio_dev *indio_dev, > > switch (mask) { > case IIO_CHAN_INFO_PROCESSED: > - ret = adc5_do_conversion(adc, prop, chan, > - &adc_code_volt, &adc_code_cur); > + ret = do_conv(adc, prop, chan, > + &adc_code_volt, &adc_code_cur); > if (ret) > return ret; > > @@ -518,36 +523,20 @@ static int adc5_read_raw(struct iio_dev *indio_dev, > } > } > > -static int adc7_read_raw(struct iio_dev *indio_dev, > +static int adc5_read_raw(struct iio_dev *indio_dev, > struct iio_chan_spec const *chan, int *val, int *val2, > long mask) > { > - struct adc5_chip *adc = iio_priv(indio_dev); > - struct adc5_channel_prop *prop; > - u16 adc_code_volt, adc_code_cur; > - int ret; > - > - prop = &adc->chan_props[chan->address]; > - > - switch (mask) { > - case IIO_CHAN_INFO_PROCESSED: > - ret = adc7_do_conversion(adc, prop, chan, > - &adc_code_volt, &adc_code_cur); > - if (ret) > - return ret; > - > - ret = qcom_adc5_hw_scale(prop->scale_fn_type, > - &adc5_prescale_ratios[prop->prescale], > - adc->data, > - adc_code_volt, val); > - > - if (ret) > - return ret; > + return adc_read_raw_common(indio_dev, chan, val, val2, > + mask, adc5_do_conversion); > +} > > - return IIO_VAL_INT; > - default: > - return -EINVAL; > - } > +static int adc7_read_raw(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, int *val, int *val2, > + long mask) > +{ > + return adc_read_raw_common(indio_dev, chan, val, val2, > + mask, adc7_do_conversion); > } > > static const struct iio_info adc5_info = {