From: "Duje Mihanović" <duje@dujemihanovic.xyz>
To: David Lechner <dlechner@baylibre.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Karel Balej" <balejk@matfyz.cz>, "Lee Jones" <lee@kernel.org>,
"David Wronek" <david@mainlining.org>,
phone-devel@vger.kernel.org,
~postmarketos/upstreaming@lists.sr.ht,
linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH 1/2] iio: adc: Add driver for Marvell 88PM886 PMIC ADC
Date: Fri, 29 Aug 2025 17:20:17 +0200 [thread overview]
Message-ID: <2250556.Mh6RI2rZIc@radijator> (raw)
In-Reply-To: <4f93d53a-3dfa-4b9f-8c09-73703888d263@baylibre.com>
On Friday, 29 August 2025 01:40:56 Central European Summer Time David Lechner wrote:
> > +#define ADC_CHANNEL(index, lsb, _type, name) { \
> > + .type = _type, \
> > + .indexed = 1, \
> > + .channel = index, \
> > + .address = lsb, \
> > + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
> > + BIT(IIO_CHAN_INFO_PROCESSED), \
> > + .datasheet_name = name, \
>
> Do you have a link for the datasheet?
No, unfortunately. The only reference I have for the ADC itself is this
vendor driver:
https://github.com/acorn-marvell/brillo_pxa_kernel/blob/master/drivers/iio/adc/88pm88x-gpadc.c
> > + ADC_CHANNEL(VSC_CHAN, 1367, IIO_VOLTAGE, "vsc"),
> > + ADC_CHANNEL(VCHG_PWR_CHAN, 1709, IIO_VOLTAGE, "vchg_pwr"),
> > + ADC_CHANNEL(VCF_OUT_CHAN, 1367, IIO_VOLTAGE, "vcf_out"),
> > + ADC_CHANNEL(TINT_CHAN, 104, IIO_TEMP, "tint"),
> > +
> > + ADC_CHANNEL(GPADC0_CHAN, 342, IIO_VOLTAGE, "gpadc0"),
> > + ADC_CHANNEL(GPADC1_CHAN, 342, IIO_VOLTAGE, "gpadc1"),
> > + ADC_CHANNEL(GPADC2_CHAN, 342, IIO_VOLTAGE, "gpadc2"),
> > +
> > + ADC_CHANNEL(VBAT_CHAN, 1367, IIO_VOLTAGE, "vbat"),
> > + ADC_CHANNEL(GNDDET1_CHAN, 342, IIO_VOLTAGE, "gnddet1"),
> > + ADC_CHANNEL(GNDDET2_CHAN, 342, IIO_VOLTAGE, "gnddet2"),
> > + ADC_CHANNEL(VBUS_CHAN, 1709, IIO_VOLTAGE, "vbus"),
> > + ADC_CHANNEL(GPADC3_CHAN, 342, IIO_VOLTAGE, "gpadc3"),
> > + ADC_CHANNEL(MIC_DET_CHAN, 1367, IIO_VOLTAGE, "mic_det"),
> > + ADC_CHANNEL(VBAT_SLP_CHAN, 1367, IIO_VOLTAGE, "vbat_slp"),
> > +
> > + ADC_CHANNEL(GPADC0_RES_CHAN, 342, IIO_RESISTANCE, "gpadc0_res"),
> > + ADC_CHANNEL(GPADC1_RES_CHAN, 342, IIO_RESISTANCE, "gpadc1_res"),
> > + ADC_CHANNEL(GPADC2_RES_CHAN, 342, IIO_RESISTANCE, "gpadc2_res"),
> > + ADC_CHANNEL(GPADC3_RES_CHAN, 342, IIO_RESISTANCE, "gpadc3_res"),
>
> Is it safe (or sensible) to have both voltage and resistance channels
> for the same input at the same time? It seems like if a voltage
> channel was connected to an active circuit, we would not want to be
> supplying current to it to take a resistance reading (this doesn't
> sound safe). Likewise, if a voltage input has a passive load on it,
> wouldn't the voltage channel always return 0 because no current was
> supplied to induce a voltate (doesn't seem sensible to have a channel
> that does notthing useful).
>
> It might make sense to have some firmware (e.g. devicetree) to describe
> if the input is active or passive on the voltage inputs and set up the
> channels accordingly.
>
> I'm also wondering if the other channels like vbat and vbus are always
> wired up to these things internally or if this channel usage is only for
> a specific system.
Looking at the vendor kernel, I am fairly confident that the channels
labeled gpadc are indeed general-purpose and connected to arbitrary
resistances (thermistors and battery detection depending on the board),
while the rest are fixed-function as their names imply.
The above most likely is safe as my board is still functional, but it
probably doesn't make sense to keep the voltage channels so I suppose
I'll drop these in v2.
> > + int val, ret;
> > + u8 buf[2];
> > +
> > + if (chan >= GPADC0_RES_CHAN)
> > + /* Resistor voltage drops are read from the corresponding voltage channel
> > */ + chan -= GPADC0_RES_CHAN - GPADC0_CHAN;
>
> Does this actually work for GPADC3_RES_CHAN?
>
> GPADC3_RES_CHAN == GPADC0_RES_CHAN + 3 but GPADC3_CHAN != GPADC0_CHAN + 3
Good catch. Upon closer inspection, the order of the channel enum
doesn't matter much and I'll fix this by simply ordering the enum more
wisely.
> > + long mask)
> > +{
> > + struct device *dev = iio->dev.parent;
> > + int raw, ret;
> > +
> > + ret = pm_runtime_resume_and_get(dev);
> > + if (ret)
> > + return ret;
> > +
> > + if (chan->type == IIO_RESISTANCE) {
> > + raw = gpadc_get_resistor(iio, chan);
> > + if (raw < 0) {
> > + ret = raw;
> > + goto out;
> > + }
> > +
> > + *val = raw;
> > + dev_dbg(&iio->dev, "chan: %d, %d Ohm\n", chan->channel, *val);
> > + ret = IIO_VAL_INT;
> > + goto out;
> > + }
> > +
> > + raw = gpadc_get_raw(iio, chan->channel);
> > + if (raw < 0) {
> > + ret = raw;
> > + goto out;
> > + }
> > +
> > + switch (mask) {
> > + case IIO_CHAN_INFO_RAW:
>
> If there is IIO_CHAN_INFO_RAW, then we also should have IIO_CHAN_INFO_SCALE.
>
> > + *val = raw;
> > + dev_dbg(&iio->dev, "chan: %d, raw: %d\n", chan->channel, *val);
> > + ret = IIO_VAL_INT;
> > + break;
> > + case IIO_CHAN_INFO_PROCESSED: {
>
> Unusual to have both raw and processed. What is the motivation?
I was following what ab8500-gpadc does, no particular motivation.
Considering the above, to me it makes the most sense to limit it to
processed.
> > @@ -67,6 +68,35 @@
> >
> > #define PM886_REG_BUCK4_VOUT 0xcf
> > #define PM886_REG_BUCK5_VOUT 0xdd
> >
> > +/* GPADC enable/disable registers */
> > +#define PM886_REG_GPADC_CONFIG1 0x1
> > +#define PM886_REG_GPADC_CONFIG2 0x2
> > +#define PM886_REG_GPADC_CONFIG3 0x3
> > +#define PM886_REG_GPADC_CONFIG6 0x6
>
> Could just write this as:
>
> #define PM886_REG_GPADC_CONFIG(n) (n)
>
> > +
> > +/* GPADC bias current configuration registers */
> > +#define PM886_REG_GPADC_CONFIG11 0xb
> > +#define PM886_REG_GPADC_CONFIG12 0xc
> > +#define PM886_REG_GPADC_CONFIG13 0xd
> > +#define PM886_REG_GPADC_CONFIG14 0xe
> > +#define PM886_REG_GPADC_CONFIG20 0x14
>
> which covers these too.
>
> Most of these aren't used anyway.
>
> Also suspicious that there are 5 registers listed here
> but only 4 channels for resistance.
The last one is used to enable the bias generators, the rest only set
the bias current for their respective channel.
Regards,
--
Duje
next prev parent reply other threads:[~2025-08-29 15:20 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-28 22:17 [PATCH 0/2] Marvell 88PM886 PMIC GPADC driver Duje Mihanović
2025-08-28 22:17 ` [PATCH 1/2] iio: adc: Add driver for Marvell 88PM886 PMIC ADC Duje Mihanović
2025-08-28 23:40 ` David Lechner
2025-08-29 15:20 ` Duje Mihanović [this message]
2025-08-29 15:52 ` David Lechner
2025-08-30 4:37 ` Andy Shevchenko
2025-08-30 4:41 ` Andy Shevchenko
2025-08-30 13:07 ` Duje Mihanović
2025-08-30 15:05 ` Andy Shevchenko
2025-08-30 19:41 ` Jonathan Cameron
2025-08-30 13:03 ` Duje Mihanović
2025-08-30 14:53 ` Andy Shevchenko
2025-08-30 16:29 ` Duje Mihanović
2025-08-29 16:27 ` Jonathan Cameron
2025-08-29 17:40 ` Duje Mihanović
2025-08-29 20:38 ` Karel Balej
2025-08-28 22:17 ` [PATCH 2/2] mfd: 88pm886: Add GPADC cell Duje Mihanović
2025-08-29 15:47 ` Andy Shevchenko
2025-08-29 20:30 ` Karel Balej
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=2250556.Mh6RI2rZIc@radijator \
--to=duje@dujemihanovic.xyz \
--cc=andy@kernel.org \
--cc=balejk@matfyz.cz \
--cc=david@mainlining.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=lee@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=phone-devel@vger.kernel.org \
--cc=~postmarketos/upstreaming@lists.sr.ht \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.