linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: nuno.sa@analog.com, linux-gpio@vger.kernel.org,
	linux-pwm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-input@vger.kernel.org, "Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Uwe Kleine-König" <ukleinek@kernel.org>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Liu Ying" <victor.liu@nxp.com>
Subject: Re: [PATCH v2 06/17] mfd: adp5585: add support for adp5589
Date: Fri, 25 Apr 2025 10:23:38 +0100	[thread overview]
Message-ID: <20250425092338.GA1567507@google.com> (raw)
In-Reply-To: <20250425091351.GO18085@pendragon.ideasonboard.com>

On Fri, 25 Apr 2025, Laurent Pinchart wrote:

> Hi Lee,
> 
> On Fri, Apr 25, 2025 at 08:58:59AM +0100, Lee Jones wrote:
> > On Thu, 24 Apr 2025, Laurent Pinchart wrote:
> > > On Thu, Apr 24, 2025 at 05:38:30PM +0100, Lee Jones wrote:
> > > > On Thu, 24 Apr 2025, Laurent Pinchart wrote:
> > > > > On Thu, Apr 24, 2025 at 05:18:38PM +0100, Lee Jones wrote:
> > > > > > On Tue, 15 Apr 2025, Nuno Sá via B4 Relay wrote:
> > > > > > 
> > > > > > > From: Nuno Sá <nuno.sa@analog.com>
> > > > > > > 
> > > > > > > The ADP5589 is a 19 I/O port expander with built-in keypad matrix decoder,
> > > > > > > programmable logic, reset generator, and PWM generator.
> > > > > > > 
> > > > > > > This patch adds the foundation to add support for the adp5589 gpio and pwm
> > > > > > > drivers. Most importantly, we need to differentiate between some
> > > > > > > registers addresses. It also hints to future keymap support.
> > > > > > > 
> > > > > > > Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> > > > > > > ---
> > > > > > >  drivers/mfd/adp5585.c       | 223 +++++++++++++++++++++++++++++++++++++++++---
> > > > > > >  include/linux/mfd/adp5585.h |  57 ++++++++++-
> > > > > > >  2 files changed, 268 insertions(+), 12 deletions(-)
> > > > > > 
> > > > > > [...]
> > > > > > 
> > > > > > > + * Bank 0 covers pins "GPIO 1/R0" to "GPIO 8/R7", numbered 0 to 7 by the
> > > > > > > + * driver, bank 1 covers pins "GPIO 9/C0" to "GPIO 16/C7", numbered 8 to
> > > > > > > + * 15 and bank 3 covers pins "GPIO 17/C8" to "GPIO 19/C10", numbered 16 to 18.
> > > > > > > + */
> > > > > > > +#define ADP5589_BANK(n)			((n) >> 3)
> > > > > > > +#define ADP5589_BIT(n)			BIT((n) & 0x7)
> > > > > > > +
> > > > > > > +struct adp5585_regs {
> > > > > > > +	unsigned int debounce_dis_a;
> > > > > > > +	unsigned int rpull_cfg_a;
> > > > > > > +	unsigned int gpo_data_a;
> > > > > > > +	unsigned int gpo_out_a;
> > > > > > > +	unsigned int gpio_dir_a;
> > > > > > > +	unsigned int gpi_stat_a;
> > > > > > > +	unsigned int pwm_cfg;
> > > > > > > +	unsigned int pwm_offt_low;
> > > > > > > +	unsigned int pwm_ont_low;
> > > > > > > +	unsigned int gen_cfg;
> > > > > > > +	unsigned int ext_cfg;
> > > > > > > +};
> > > > > > > +
> > > > > > > +struct adp5585_info {
> > > > > > > +	const struct mfd_cell *adp5585_devs;
> > > > > > 
> > > > > > Okay, we are never doing this.  Either use OF for platform registration
> > > > > > or use MFD (or ACPI or PCI), but please do not pass MFD data through OF.
> > > > > 
> > > > > When I upstreamed the initial driver, I modelled the different functions
> > > > > through child nodes in DT, with a compatible string for each child. I
> > > > > was told very strongly to remove that. We have therefore no other choice
> > > > > than constructing the name of the cells based on the model of the main
> > > > > device.
> > > > 
> > > > It's okay to add this information statically in this driver.  It's not
> > > > okay to then pass it through the OF API.  You can pass an identifier
> > > > through the .data attribute to match on, but we are not passing MFD cell
> > > > data through like this.
> > > 
> > > Sorry, I'm not following you. What's the issue with the .data field
> > > pointing to an instance of a structure that lists properties related to
> > > the device model ?
> > 
> > There isn't one.  By all means place any type of platform data you want
> > in there.  Similar to the information you'd find in Device Tree or the
> > old board-files type pdata.  You can even extract the platform data you
> > pass through the OF API and place it into MFD platform data.  The line
> > is being drawn on passing through one type of initialisation API with
> > another, MFD through OF in this case.  MFD cells containing device
> > registration data (including platform data!) is not itself platform
> > data.
> 
> I'm still not following you. The issue will likely go away in the next
> version anyway, as the MFD cells registration code needs to be rewritten
> to be more dynamic.
> 
> > > > > > > +	const struct regmap_config *regmap_config;
> > > > > > > +	const struct adp5585_regs *regs;
> > > > > > > +	unsigned int n_devs;
> > > > > > > +	unsigned int id;
> > > > > > 
> > > > > > What ID is this?  We already have platform IDs and MFD cell IDs.
> > > > > 
> > > > > That's the value of the hardware model ID read-only register, it is used
> > > > > as a safety check to verify that the connected device corresponds to the
> > > > > compatible string.
> > > > 
> > > > I suggest changing the nomenclature to be more forthcoming.
> > > > 
> > > > 'model', 'version', 'hwid', 'chipid', etc.
> > > > 
> > > > Why is it being stored?  Is it used to match on at a later date?
> > > 
> > > The adp5585_info structure contains static information the describe each
> > > device model. There's one global static const instance per device model,
> > > and they are referenced from device id structures (e.g. of_device_id).
> > > The driver gets an info pointer corresponding to the model reported by
> > > the platform firmware (e.g. DT). It reads the device ID from the device
> > > at probe time, and compares it with the value stored in the structure as
> > > a safety check to ensure there's no mismatch.
> > 
> > I think the current implementation (as a whole, not just the IDs) needs
> > a rethink.  Very few attributes are changing here, both between the 2
> > platforms and the several variants you're trying to support, leading to
> > masses of repetition.
> > 
> > Looking at the static configuration here, this is starting to look like
> > 2 pieces of hardware with the only variation within each being the
> > default register values.  Is that a correct assumption?
> 
> The variants of the ADP5585 differ mainly by how they handle the default
> configuration of pull-up and pull-down resistors. The consequence on the
> driver side is limited to default register values, yes.
> 
> ADP5589 differs more significantly from the ADP5585. Differences between
> the ADP5589 variants are small as far as I understand (datasheets are
> public, should you want to have a look).
> 
> > If so, does
> > mean all of this added complexity is just to configure a few register
> > values such that the two platforms can be used for different things?  Or
> > are these really 6 true hardware variants of one another?
> 
> They are different physical chips with different product numbers.
> 
> > Either way, this approach doesn't scale.  Instead of multiplying the
> > amount of platforms / variants together and creating that number of
> > static structs, I'd suggest using templating and only adapting what
> > actually changes.
> > 
> > For instance, the following attributes in 'struct regmap_config' never
> > change; reg_bits, val_bits, and cache_type.  And max_register only
> > changes between the 2 hardware platforms.  The reg_defaults_raw values
> > can be changed in a switch statement.
> 
> All the fields of the adp5585_info structure that you would like to
> dynamically set would then need to be stored in the adp5585 structure.
> The would essentially trade static const data for dynamic data and more
> code. Is that a personal coding style preference, or are there clear
> advantages ?
> 
> > Same goes for 'struct adp5585_info'.  Only regmap_config changes between
> > variants.  Everything else is exactly the same.
> 
> I assume this comment relates only to the different variants of the info
> structure for the same model (e.g. ADP5585 or ADP5589). There are more
> differences between the ADP5585 and ADP5589 entries.
> 
> > So, with the use of a
> > few of templates and a couple of succinct switch cases, you can control
> > all of the differentiation you need.  And for every variant you wish to
> > add, it's a couple of extra lines rather than many, leading to a
> > much more scaleable implementation.
> 
> That also seems like a personal coding style preference :-) Adding a new
> compatible variant with the existing approach only requires adding an
> instance of the info structure, while your proposal would require
> changes in multiple places. It seems more work to me (from a personal
> preference point of view).
> 
> Of course, if the new variant requires developing abstractions that
> don't exist (such as supporting large differences in the registers
> layout as needed for the ADP5589), refactoring of the code will always
> be required. This seems a bit of a theoretical concern though, as I'm
> not aware of any other chip that would require such development.
> 
> In any case, let's see how the next version will look like, after
> reworking the MFD cells registration code. Maybe it will make everybody
> happy :-)

Let's hope. =:)

-- 
Lee Jones [李琼斯]

  reply	other threads:[~2025-04-25  9:23 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-15 14:49 [PATCH v2 00/17] mfd: adp5585: support keymap events and drop legacy Input driver Nuno Sá via B4 Relay
2025-04-15 14:49 ` [PATCH v2 01/17] dt-bindings: mfd: adp5585: ease on the required properties Nuno Sá via B4 Relay
2025-04-21  8:56   ` Laurent Pinchart
2025-04-21 12:12     ` Nuno Sá
2025-04-21 12:29       ` Laurent Pinchart
2025-04-21 12:45         ` Nuno Sá
2025-04-21 18:57   ` Rob Herring (Arm)
2025-04-15 14:49 ` [PATCH v2 02/17] mfd: adp5585: enable oscilator during probe Nuno Sá via B4 Relay
2025-04-21  8:57   ` Laurent Pinchart
2025-04-21 12:14     ` Nuno Sá
2025-04-21 22:03       ` Laurent Pinchart
2025-04-22  7:50         ` Nuno Sá
2025-04-15 14:49 ` [PATCH v2 03/17] pwm: adp5585: don't control OSC_EN in the pwm driver Nuno Sá via B4 Relay
2025-04-15 14:49 ` [PATCH v2 04/17] mfd: adp5585: make use of MFD_CELL_NAME() Nuno Sá via B4 Relay
2025-04-21  9:03   ` Laurent Pinchart
2025-04-24 15:55   ` Lee Jones
2025-04-15 14:49 ` [PATCH v2 05/17] dt-bindings: mfd: adp5585: document adp5589 I/O expander Nuno Sá via B4 Relay
2025-04-21  9:07   ` Laurent Pinchart
2025-04-21 18:59   ` Rob Herring (Arm)
2025-04-15 14:49 ` [PATCH v2 06/17] mfd: adp5585: add support for adp5589 Nuno Sá via B4 Relay
2025-04-21  9:15   ` Laurent Pinchart
2025-04-21 12:21     ` Nuno Sá
2025-04-21 22:06       ` Laurent Pinchart
2025-04-22  7:51         ` Nuno Sá
2025-04-24 16:01         ` Lee Jones
2025-04-24 16:18   ` Lee Jones
2025-04-24 16:30     ` Laurent Pinchart
2025-04-24 16:38       ` Lee Jones
2025-04-24 19:39         ` Laurent Pinchart
2025-04-25  7:58           ` Lee Jones
2025-04-25  9:13             ` Laurent Pinchart
2025-04-25  9:23               ` Lee Jones [this message]
2025-04-28  9:24               ` Nuno Sá
2025-04-15 14:49 ` [PATCH v2 07/17] gpio: adp5585: add support for the ad5589 expander Nuno Sá via B4 Relay
2025-04-17 12:27   ` Bartosz Golaszewski
2025-04-21  9:23   ` Laurent Pinchart
2025-04-21 12:22     ` Nuno Sá
2025-04-15 14:49 ` [PATCH v2 08/17] pwm: adp5585: add support for adp5589 Nuno Sá via B4 Relay
2025-04-15 14:49 ` [PATCH v2 09/17] dt-bindings: mfd: adp5585: add properties for input events Nuno Sá via B4 Relay
2025-04-21  9:28   ` Laurent Pinchart
2025-04-21 12:24     ` Nuno Sá
2025-04-29 15:03   ` Rob Herring (Arm)
2025-04-15 14:49 ` [PATCH v2 10/17] mfd: adp5585: add support for key events Nuno Sá via B4 Relay
2025-04-21  9:33   ` Laurent Pinchart
2025-04-21 12:32     ` Nuno Sá
2025-04-21 22:13       ` Laurent Pinchart
2025-04-24 16:07     ` Lee Jones
2025-04-24 16:24       ` Laurent Pinchart
2025-04-24 16:28         ` Lee Jones
2025-04-15 14:49 ` [PATCH v2 11/17] gpio: adp5585: support gpi events Nuno Sá via B4 Relay
2025-04-17 12:28   ` Bartosz Golaszewski
2025-04-15 14:49 ` [PATCH v2 12/17] Input: adp5585: Add Analog Devices ADP5585/89 support Nuno Sá via B4 Relay
2025-04-19  2:44   ` Dmitry Torokhov
2025-04-21  9:35   ` Laurent Pinchart
2025-04-21 12:33     ` Nuno Sá
2025-04-15 14:49 ` [PATCH v2 13/17] Input: adp5589: remove the driver Nuno Sá via B4 Relay
2025-04-19  2:45   ` Dmitry Torokhov
2025-04-21  9:40   ` Laurent Pinchart
2025-04-21 12:34     ` Nuno Sá
2025-04-15 14:49 ` [PATCH v2 14/17] mfd: adp5585: support getting vdd regulator Nuno Sá via B4 Relay
2025-04-21  9:48   ` Laurent Pinchart
2025-04-21 12:38     ` Nuno Sá
2025-04-21 22:09       ` Laurent Pinchart
2025-04-22  8:12         ` Nuno Sá
2025-04-15 14:49 ` [PATCH v2 15/17] dt-bindings: mfd: adp5585: document reset gpio Nuno Sá via B4 Relay
2025-04-21  9:36   ` Laurent Pinchart
2025-04-15 14:49 ` [PATCH v2 16/17] mfd: adp5585: add support for a reset pin Nuno Sá via B4 Relay
2025-04-21  9:46   ` Laurent Pinchart
2025-04-21 12:42     ` Nuno Sá
2025-04-21 22:10       ` Laurent Pinchart
2025-04-15 14:49 ` [PATCH v2 17/17] pwm: adp5585: make sure to include mod_devicetable.h Nuno Sá via B4 Relay
2025-04-21  9:50   ` Laurent Pinchart
2025-04-15 15:56 ` [PATCH v2 00/17] mfd: adp5585: support keymap events and drop legacy Input driver Laurent Pinchart
2025-04-21 10:08   ` Laurent Pinchart
2025-04-16  9:02 ` Liu Ying
2025-04-16 10:03   ` Nuno Sá
2025-05-01 12:00 ` Lee Jones
2025-05-01 14:09   ` Laurent Pinchart
2025-05-02  7:13     ` Lee Jones
2025-05-02  7:35       ` Nuno Sá
2025-05-02  8:30         ` Lee Jones

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=20250425092338.GA1567507@google.com \
    --to=lee@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    --cc=ukleinek@kernel.org \
    --cc=victor.liu@nxp.com \
    /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).