devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Petre Rodan <petre.rodan@subdimension.ro>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] iio: pressure: add Honeywell ABP2 driver
Date: Tue, 25 Nov 2025 00:54:15 +0200	[thread overview]
Message-ID: <aSTiFxAolJ0JeUTj@smile.fi.intel.com> (raw)
In-Reply-To: <aSTJML3fxp0sSeCq@lipo.home.arpa>

On Mon, Nov 24, 2025 at 11:08:00PM +0200, Petre Rodan wrote:
> On Mon, Nov 24, 2025 at 08:41:32PM +0200, Andy Shevchenko wrote:
> > On Mon, Nov 24, 2025 at 07:29:06PM +0200, Petre Rodan wrote:

...

> > > > Why explicit assignments? Is it related to some HW register?
> > > 
> > > no registers, I just need to ensure the two arrays
> > > 
> > > static const char * const abp2_triplet_variants[ABP2_VARIANTS_MAX] = {
> > > 	[ABP2001BA] = "001BA", [ABP21_6BA] = "1.6BA", [ABP22_5BA] = "2.5BA", ..
> > > 
> > > static const struct abp2_range_config abp2_range_config[ABP2_VARIANTS_MAX] = {
> > > 	[ABP2001BA] = { .pmin =       0, .pmax =  100000 },
> > >    	[ABP21_6BA] = { .pmin =       0, .pmax =  160000 }, ..
> > > 
> > > keep being consistent and are resistant to later editing.
> > 
> > So, if it's pure software numbering, just drop assignments in the enum.
> 
> so you want the consistency check to be dropped? we have data in two
> different arrays and they must be kept in perfect sync. if I were to remove
> the assignments someone comes a few years in the future, inserts a new device
> in the abp2_triplet_variants array at position 84 out of 113, also inserts a
> new {pmin, pmax} into the abp2_range_config array accidentally at position 83
> and the compiler will be none the wiser.

That's why enum is there. Had I told you to remove it? No! enum should stay
as well as the explicit indexed assignments, assignments in _enum_ should go.
Just look around how other drivers do with enums which are not related to
the HW registers.

> just the day before I had to remove
> a variant because of a typo in the datasheet. I cheat and use a script to
> generate the structs [1], but if I had to modify them by hand, the
> assignments would make sure I delete the proper line.
> 
> am I proud of this? no, and I told you my preference. this is just a
> compromise that uses the non-specific match function and still provides a
> guardrail for future editing.
> 
> [1] https://codeberg.org/subDIMENSION/lkm_sandbox/src/branch/main/honeywell_abp2030pa/scripts/parse_variants_table.sh

[..]

> > > > So, why can't regmap SPI be used?
> > > 
> > > there are no registers, no memory map, just a 'start conversion' and the
> > > equivalent of a 'read conversion' command.
> > > any reason one would use the regmap API in this case?
> > 
> > At bare minimum the commit message should have a justification for the choice
> > explaining all this.
> 
> I had the justification in the cover letter instead, my bad, will include it in
> the commit message instead.

It's good to have in both.

> > Ideally, try to find a way how to use regmap API. We have several weeks of
> > time for this exercise.
> 
> you did not mention why use an API designed for devices with registers and a
> memory map on an IC that has neither.

The regmap provides several facilities that we would like to use in the drivers:
- the generic interface to access to the HW
- the common locking schema that allows to share the same regmap among
different drivers (depends on the functionality of the parts of the HW)
- debugging facilities are available out-of-the-box

> I also have a bughunt in the spi-omap2-mcspi driver related to improper CS
> delays in queued transfers, regmap will probably just be an extra layer of
> abstraction I will have to go thru :/

[..]

> oh, and
> 
> struct abp2_spi_buf {
> 	u8 tx[ABP2_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN);
> };
> 
> static int abp2_spi_init(struct device *dev)
> {
> 	struct spi_device *spi = to_spi_device(dev);
> 	struct abp2_spi_buf *buf;
> 
> 	buf = devm_kzalloc(dev, sizeof(*buf), GFP_KERNEL);
> 
> > Using devm_*() here is most likely a mistake. What is the object lifetime in
> > comparison to the used device?
> 
> I did think that placing this into the abp2_data struct would be a better
> idea, but I was not sure how to handle the alignment issue since there is
> already the read buffer there:

We have drivers in the kernel with two buffers in the same structure.

> #define ABP2_MEASUREMENT_RD_SIZE 7
> 
> struct abp2_data {
> 	struct device *dev;
> 	const struct abp2_ops *ops;
> 	s32 pmin;
> 	s32 pmax;
[..]
> 	struct {
> 		u32 chan[2];
> 		aligned_s64 timestamp;
> 	} scan;
> +	u8 spi_tx_buffer[ABP2_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN);
> 	u8 buffer[ABP2_MEASUREMENT_RD_SIZE] __aligned(IIO_DMA_MINALIGN);
> };
> 
> how do I make sure both 7byte buffers are aligned? can I __align twice in a
> struct as above? or should I align only the first buffer and make it 8bytes
> long?  I had a close look and even if the SoC's SPI driver supports both DMA
> and PIO, I've seen it pick PIO every single time while talking to my pressure
> sensor.

You told you read books about C language...

Alignment is a property of a single member and a data type in general. Each
field of each data type may have it's own (non-default) alignment along with
the object alignment.

...

Homework:
Why do we need both to be aligned? Do you get the idea what is this all about?

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-11-24 22:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-22 21:42 [PATCH 0/2] iio: pressure: add Honeywell ABP2 driver Petre Rodan
2025-11-22 21:42 ` [PATCH 1/2] dt-bindings: iio: pressure: add honeywell,abp2030pa Petre Rodan
2025-11-23 10:25   ` Krzysztof Kozlowski
2025-11-22 21:42 ` [PATCH 2/2] iio: pressure: add Honeywell ABP2 driver Petre Rodan
2025-11-24 11:48   ` Andy Shevchenko
2025-11-24 17:29     ` Petre Rodan
2025-11-24 18:41       ` Andy Shevchenko
2025-11-24 21:08         ` Petre Rodan
2025-11-24 22:54           ` Andy Shevchenko [this message]
2025-11-27  7:01             ` Petre Rodan
2025-11-27  8:37               ` Andy Shevchenko
2025-12-06 20:29                 ` Jonathan Cameron
2025-12-06 20:13     ` Jonathan Cameron

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=aSTiFxAolJ0JeUTj@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=petre.rodan@subdimension.ro \
    --cc=robh@kernel.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).