From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: David Lechner <dlechner@baylibre.com>
Cc: "Duje Mihanović" <duje@dujemihanovic.xyz>,
"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: Sat, 30 Aug 2025 07:37:27 +0300 [thread overview]
Message-ID: <CAHp75Ve=xJ6vTUydaTw9GuYr22ZXp3HFA5N0tP7NET=CvZJB8Q@mail.gmail.com> (raw)
In-Reply-To: <4f93d53a-3dfa-4b9f-8c09-73703888d263@baylibre.com>
On Fri, Aug 29, 2025 at 2:41 AM David Lechner <dlechner@baylibre.com> wrote:
> On 8/28/25 5:17 PM, Duje Mihanović wrote:
...
> > +#include <linux/device.h>
See below about kernel.h, TL;DR: with device.h check carefully that
you are really using it and not something from linux/device/* and/or
linux/dev_printk.h.
> > +#include <linux/i2c.h>
> > +#include <linux/iio/driver.h>
> > +#include <linux/iio/iio.h>
> > +#include <linux/iio/types.h>
> > +#include <linux/kernel.h>
>
> We usually try to avoid including kernel.h because it includes too much.
> There are some recent-ish messages on the iio mailing list discussing
> include-what-you-use with some tips on how to pick the headers that are
> actually being used for inclusion.
+100
In new code no driver should use kernel.h. Use proper headers from day 1.
> > +#include <linux/mod_devicetable.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/pm_runtime.h>
> > +#include <linux/regmap.h>
> > +
> > +#include <linux/mfd/88pm886.h>
>
> Odd to have this one not grouped with the rest.
Actually it's fine, as it is almost private to this driver, but for
the sake of consistency I would also like to see the linux/iio/* be
grouped.
...
> > + u8 buf[2];
Can't we use proper type, i.e. __be16 here?
...
> > + ret = regmap_bulk_read(*map, regs[chan], buf, 2);
sizeof()
> > +
Redundant blank line.
> > + if (ret)
> > + return ret;
> > +
> > + val = ((buf[0] & 0xff) << 4) | (buf[1] & 0xf);
> > + val &= 0xfff;
>
> This line seems reduandant as mask was already applied in previous line.
With the previous suggestions this will be as simple as
be16_to_cpu() >> 4 no masks needed at all!
...
> > + if (adcnum < 0 || adcnum > 3)
> > + return -EINVAL;
in_range()
...
> > + for (int i = 0; i < 16; i++) {
Why signed? What is the magic value here?
> > + ret = regmap_update_bits(*map, reg, 0xf, i);
GENMASK() or even better to have a definitive constant.
> > + if (ret)
> > + return ret;
...
> > + raw = gpadc_get_raw(iio, chan->channel);
> > + if (raw < 0) {
> > + ret = raw;
> > + goto out;
> > + }
Instead just assign to ret and if okay, reassign to raw.
...
> > + const u8 config[] = {0xff, 0xfd, 0x1};
>
> IIRC, IIO subsystem prefers spaces around the braces.
>
> { 0xff, 0xfd, 0x1 };
Also make them fixed width, i.e. 0x01
> Also, could use some macros to explain what these values are.
...
> > + /* Enable/disable the ADC block */
> > + ret = regmap_assign_bits(map, PM886_REG_GPADC_CONFIG6, BIT(0), enable);
> > + if (ret || !enable)
> > + return ret;
It's implicit that when "!enable" we return 0, this should be written
explicitly because it's a special case.
...
> > + iio->dev.parent = dev;
> > + iio->dev.of_node = parent->of_node;
It's incomplete and IIO already does it for you. IIRC the parent is
set also, but please double check that.
...
> > + devm_pm_runtime_enable(dev);
Why use devm if not checking for the returned code?
...
> > +config 88PM886_GPADC
> > + tristate "Marvell 88PM886 GPADC driver"
> > + depends on MFD_88PM886_PMIC
> > + default y
Really? Why tristate then?
I would expect default MFD_88PM886_PMIC instead,
> > + help
> > + Say Y here to enable support for the GPADC (General Purpose ADC)
> > + found on the Marvell 88PM886 PMIC. The GPADC measures various
> > + internal voltages and temperatures, including (but not limited to)
> > + system, battery and USB.
Please, add a line about the module name if one chooses 'm'. Or see
above — drop the "tristate" and explain why this driver may not be a
module in the commit message.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-08-30 4:38 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ć
2025-08-29 15:52 ` David Lechner
2025-08-30 4:37 ` Andy Shevchenko [this message]
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='CAHp75Ve=xJ6vTUydaTw9GuYr22ZXp3HFA5N0tP7NET=CvZJB8Q@mail.gmail.com' \
--to=andy.shevchenko@gmail.com \
--cc=andy@kernel.org \
--cc=balejk@matfyz.cz \
--cc=david@mainlining.org \
--cc=dlechner@baylibre.com \
--cc=duje@dujemihanovic.xyz \
--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 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).