From: Jonathan Cameron <jic23@kernel.org>
To: Jishnu Prakash <jprakash@codeaurora.org>
Cc: agross@kernel.org, bjorn.andersson@linaro.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
mka@chromium.org, linus.walleij@linaro.org,
Jonathan.Cameron@huawei.com, andy.shevchenko@gmail.com,
amit.kucheria@verdurent.com, smohanad@codeaurora.org,
kgunda@codeaurora.org, aghayal@codeaurora.org,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org,
linux-arm-msm-owner@vger.kernel.org
Subject: Re: [PATCH V6 7/7] iio: adc: Add a common read function for PMIC5 and PMIC7
Date: Sun, 31 May 2020 11:52:24 +0100 [thread overview]
Message-ID: <20200531115224.700b11d3@archlinux> (raw)
In-Reply-To: <1590684869-15400-8-git-send-email-jprakash@codeaurora.org>
On Thu, 28 May 2020 22:24:29 +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>
Hmm. I'm not completely sold on this one. Suggestions below.
Jonathan
> ---
> drivers/iio/adc/qcom-spmi-adc5.c | 53 +++++++++++++++++++---------------------
> 1 file changed, 25 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/iio/adc/qcom-spmi-adc5.c b/drivers/iio/adc/qcom-spmi-adc5.c
> index 0f9af66..fe49741 100644
> --- a/drivers/iio/adc/qcom-spmi-adc5.c
> +++ b/drivers/iio/adc/qcom-spmi-adc5.c
> @@ -449,6 +449,13 @@ static int adc7_do_conversion(struct adc5_chip *adc,
> return ret;
> }
>
> +struct adc_do_conversion {
> + 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);
Why use a structure for this? It's just a function pointer.
If they form is too long you can always use a typedef.
This is fine if you have other stuff coming shortly that will add
to this structure but for now it's just a bit confusing.
Directly passing the function pointer will reduce the amount
of coded added here and make the argument in favour of refactoring
rather stronger.
> +};
> +
> static irqreturn_t adc5_isr(int irq, void *dev_id)
> {
> struct adc5_chip *adc = dev_id;
> @@ -487,9 +494,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, struct adc_do_conversion do_conv)
> {
> struct adc5_chip *adc = iio_priv(indio_dev);
> struct adc5_channel_prop *prop;
> @@ -500,8 +507,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_do_conversion(adc, prop, chan,
> + &adc_code_volt, &adc_code_cur);
> if (ret)
> return ret;
>
> @@ -518,36 +525,26 @@ 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;
> + struct adc_do_conversion do_conv;
>
> - ret = qcom_adc5_hw_scale(prop->scale_fn_type,
> - &adc5_prescale_ratios[prop->prescale],
> - adc->data,
> - adc_code_volt, val);
> + do_conv.adc_do_conversion = adc5_do_conversion;
> + return adc_read_raw_common(indio_dev, chan, val, val2,
> + mask, do_conv);
> +}
>
> - if (ret)
> - return ret;
> +static int adc7_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int *val, int *val2,
> + long mask)
> +{
> + struct adc_do_conversion do_conv;
>
> - return IIO_VAL_INT;
> - default:
> - return -EINVAL;
> - }
> + do_conv.adc_do_conversion = adc7_do_conversion;
> + return adc_read_raw_common(indio_dev, chan, val, val2,
> + mask, do_conv);
> }
>
> static const struct iio_info adc5_info = {
prev parent reply other threads:[~2020-05-31 10:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1590684869-15400-1-git-send-email-jprakash@codeaurora.org>
2020-05-28 16:54 ` [PATCH V6 1/7] iio: adc: Convert the QCOM SPMI ADC bindings to .yaml format Jishnu Prakash
2020-05-31 10:36 ` Jonathan Cameron
2020-05-31 10:44 ` Jonathan Cameron
2020-05-28 16:54 ` [PATCH V6 2/7] iio: adc: Add PMIC7 ADC bindings Jishnu Prakash
2020-05-31 10:45 ` Jonathan Cameron
2020-05-28 16:54 ` [PATCH V6 3/7] iio: adc: Add info property under adc_data Jishnu Prakash
2020-05-31 10:48 ` Jonathan Cameron
2020-05-28 16:54 ` [PATCH V6 4/7] iio: adc: Add support for PMIC7 ADC Jishnu Prakash
2020-05-31 10:47 ` Jonathan Cameron
2020-05-28 16:54 ` [PATCH V6 5/7] iio: adc: Update return value checks Jishnu Prakash
2020-05-31 10:49 ` Jonathan Cameron
2020-05-28 16:54 ` [PATCH V6 6/7] iio: adc: Update debug prints Jishnu Prakash
2020-05-31 10:53 ` Jonathan Cameron
2020-05-28 16:54 ` [PATCH V6 7/7] iio: adc: Add a common read function for PMIC5 and PMIC7 Jishnu Prakash
2020-05-31 10:52 ` Jonathan Cameron [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200531115224.700b11d3@archlinux \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=aghayal@codeaurora.org \
--cc=agross@kernel.org \
--cc=amit.kucheria@verdurent.com \
--cc=andy.shevchenko@gmail.com \
--cc=bjorn.andersson@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=jprakash@codeaurora.org \
--cc=kgunda@codeaurora.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-msm-owner@vger.kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mka@chromium.org \
--cc=pmeerw@pmeerw.net \
--cc=smohanad@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).