Linux-IIO Archive on lore.kernel.org
 help / color / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Jishnu Prakash <jprakash@codeaurora.org>
Cc: agross@kernel.org, Bjorn Andersson <bjorn.andersson@linaro.org>,
	devicetree <devicetree@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Matthias Kaehlcke <mka@chromium.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Stephen Boyd <sboyd@codeaurora.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	smohanad@codeaurora.org, kgunda@codeaurora.org,
	aghayal@codeaurora.org, Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	linux-arm-msm@vger.kernel.org,
	linux-iio <linux-iio@vger.kernel.org>,
	linux-arm-msm-owner@vger.kernel.org
Subject: Re: [PATCH 3/3] iio: adc: Add support for PMIC7 ADC
Date: Tue, 24 Mar 2020 18:33:31 +0200
Message-ID: <CAHp75Vfk1DZ+bz6h_prm6Tp7kXos6jio5JCpg6=wvGRmDPTBsw@mail.gmail.com> (raw)
In-Reply-To: <1585064650-16235-4-git-send-email-jprakash@codeaurora.org>

On Tue, Mar 24, 2020 at 5:46 PM Jishnu Prakash <jprakash@codeaurora.org> wrote:
>
> The ADC architecture on PMIC7 is changed as compared to PMIC5. The
> major change from PMIC5 is that all SW communication to ADC goes through
> PMK8350, which communicates with other PMICs through PBS when the ADC
> on PMK8350 works in master mode. The SID register is used to identify the
> PMICs with which the PBS needs to communicate. Add support for the same.
>
> In addition, add definitions for ADC channels and virtual channel
> definitions per PMIC, to be used by ADC clients for PMIC7.

...

> +#define ADC_CHANNEL_OFFSET                     0x8
> +#define ADC_CHANNEL_MASK                       0xff

GENMASK()

...

> +#define ADC_APP_SID                            0x40
> +#define ADC_APP_SID_MASK                       0xf

GENMASK()

> +#define ADC7_CONV_TIMEOUT                      msecs_to_jiffies(10)

Useless.

...

> +       buf[1] &= (u8) ~ADC5_USR_FAST_AVG_CTL_SAMPLES_MASK;

Use '0xFF ^ _MASK' instead of casting.

...

> +       buf[3] &= (u8) ~ADC5_USR_HW_SETTLE_DELAY_MASK;

Ditto.

...

> +       ret = adc5_write(adc, ADC5_USR_CONV_REQ, &conv_req, 1);
> +
> +       return ret;

return adc5_write(...);

...

> +               pr_err("ADC configure failed with %d\n", ret);

Use dev_*() instead everywhere.

...

> +       /* No support for polling mode at present*/
> +       wait_for_completion_timeout(&adc->complete,
> +                                       ADC7_CONV_TIMEOUT);

One line. The limit is 80 and it can be bend in some cases a little bit.

...

> +               v_channel = ((adc->chan_props[i].sid << ADC_CHANNEL_OFFSET) |
> +                       adc->chan_props[i].channel);

Too many parentheses.

...

> +               sid = (chan >> ADC_CHANNEL_OFFSET);
> +               chan = (chan & ADC_CHANNEL_MASK);

Ditto.

...

> +                       (adc->is_pmic7))

Ditto.

...

> +       if (of_device_is_compatible(node, "qcom,spmi-adc7")) {
> +               indio_dev->info = &adc7_info;
> +               adc->is_pmic7 = true;
> +       } else {
> +               indio_dev->info = &adc5_info;
> +       }

Hmm... I would rather put this as driver_data in ID structure(s).

...

> +static int adc5_exit(struct platform_device *pdev)
> +{
> +       struct adc5_chip *adc = platform_get_drvdata(pdev);
> +

> +       mutex_destroy(&adc->lock);

Are you sure you will have no race conditions? Does this driver use IRQs?

> +       return 0;
> +}

...

> +       s64 resistance = 0;

= adc_code  // or sign extended variant if needed.

> +       /* (ADC code * R_PULLUP (100Kohm)) / (full_scale_code - ADC code)*/

> +       resistance = (s64) adc_code * R_PU_100K;
> +       resistance = div64_s64(resistance, (RATIO_MAX_ADC7 - adc_code));

 resistance *= R_PU_100K;
 resistance = div64_s64(resistance, RATIO_MAX_ADC7 - adc_code);

...

> +       int voltage, vtemp0, temp, i = 0;

> +       while (i < ARRAY_SIZE(adcmap7_die_temp)) {
> +               if (adcmap7_die_temp[i].x > voltage)
> +                       break;
> +               i++;
> +       }

for loop (one line less, more explicit initial value assignment)?

-- 
With Best Regards,
Andy Shevchenko

  reply index

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1585064650-16235-1-git-send-email-jprakash@codeaurora.org>
2020-03-24 15:44 ` [PATCH 1/3] iio: adc: Convert the QCOM SPMI ADC bindings to .yaml format Jishnu Prakash
2020-03-28 16:51   ` Jonathan Cameron
2020-04-06 11:41     ` Jishnu Prakash
2020-03-30 15:38   ` Rob Herring
2020-04-06 11:43     ` Jishnu Prakash
2020-04-03 12:04   ` Amit Kucheria
2020-04-06 11:44     ` Jishnu Prakash
2020-04-14  9:09       ` Amit Kucheria
2020-03-24 15:44 ` [PATCH 2/3] iio: adc: Add PMIC7 ADC bindings Jishnu Prakash
2020-03-28 16:54   ` Jonathan Cameron
2020-04-06 11:45     ` Jishnu Prakash
2020-04-06 16:05       ` Jonathan Cameron
2020-04-03 12:11   ` Amit Kucheria
2020-04-06 11:45     ` Jishnu Prakash
2020-03-24 15:44 ` [PATCH 3/3] iio: adc: Add support for PMIC7 ADC Jishnu Prakash
2020-03-24 16:33   ` Andy Shevchenko [this message]
2020-04-06 11:46     ` Jishnu Prakash
2020-03-28 17:04   ` Jonathan Cameron
2020-04-06 11:46     ` Jishnu Prakash
2020-03-31 20:06   ` Rob Herring
2020-04-06 11:47     ` Jishnu Prakash

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='CAHp75Vfk1DZ+bz6h_prm6Tp7kXos6jio5JCpg6=wvGRmDPTBsw@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=aghayal@codeaurora.org \
    --cc=agross@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@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=mark.rutland@arm.com \
    --cc=mka@chromium.org \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@codeaurora.org \
    --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

Linux-IIO Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-iio/0 linux-iio/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-iio linux-iio/ https://lore.kernel.org/linux-iio \
		linux-iio@vger.kernel.org
	public-inbox-index linux-iio

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-iio


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git