mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Clark <james.clark@linaro.org>
To: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: linux-spi@vger.kernel.org, imx@lists.linux.dev,
	linux-kernel@vger.kernel.org, kernel@pengutronix.de,
	Frank Li <Frank.Li@nxp.com>, Mark Brown <broonie@kernel.org>
Subject: Re: [PATCH spi-next 11/11] spi: spi-fsl-lpspi: fsl_lpspi_set_bitrate(): don't treat devtype_data->prescale_max == 0 as a special case
Date: Mon, 16 Mar 2026 12:08:13 +0000	[thread overview]
Message-ID: <2b1eecef-9da4-45a7-9401-425715de4624@linaro.org> (raw)
In-Reply-To: <20260316-statuesque-effective-silkworm-011ed8-mkl@pengutronix.de>



On 16/03/2026 11:19 am, Marc Kleine-Budde wrote:
> Hello James,
> 
> I've no strong feelings about this patch, I can drop it in the v2.
> 
> On 16.03.2026 09:57:15, James Clark wrote:
>> On 16/03/2026 8:39 am, Marc Kleine-Budde wrote:
>>> The i.MX93 is affected by erratum ERR051608, the maximum prescaler value is
>>> 1 not 7 as in the original datasheet.
>>>
>>> On unaffected SoC the maximum prescaler is 7. Commit 783bf5d09f86 ("spi:
>>> spi-fsl-lpspi: limit PRESCALE bit in TCR register") added struct
>>> fsl_lpspi_devtype_data to hold the system dependent prescale_max value.
>>>
>>> Commit 9bbfb1ec959c ("spi: spi-fsl-lpspi: Treat prescale_max == 0 as no
>>> erratum") introduced the special value 0 to signal the default and
>>> corresponding run-time check with a conditional operator.
>>>
>>> To simplify the code, set the prescale_max of imx7ulp_lpspi_devtype_data
>>
>> The whole point of the original change was to not repeat the normal value
>> for every device in the config just because one device has an errata. This
>> new change is exactly the opposite of simplification IMO.
> 
> Interesting point of view.
> 
> My reasoning is: When I look at the fsl_lpspi_set_bitrate() function,
> there's the special case handling with the ternary for the "0".
> 
> I asked myself directly special case, why? Why not directly use the
> value as it's provided by the devtype_data?
> 

Those structs are configuration for different devices though. Having a 7 
in there implies that it's something that is configurable to different 
values. When I was adding a new device that made be crawl through a load 
of datasheets to see why arbitrary values were needed only to find out 
that it's only for one errata where it's 1 and actually every other 
device should be 7.

I tried to change it to a bool "has the errata" or "doesn't have it", as 
that's the extent of the valid configurations that should be exposed. 
But Frank said he preferred a number with 0 as the default. That seemed 
like a slight improvement to me so that's how it ended up like that.

>>> and s32g_lpspi_devtype_data to 7 and in fsl_lpspi_set_bitrate() directly
>>> use the fsl_lpspi->devtype_data->prescale_max.
>>>
>>> On ARM64 this leads to a reduction of the code of 52 bytes:
>>>
>>> | add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-52 (-52)
>>> | Function                                     old     new   delta
>>> | fsl_lpspi_setup_transfer.isra                956     936     -20
>>> | $x                                          7144    7112     -32
> 
>> On clang 15 this change makes it bigger by 220 bytes rather than
>> smaller.
> 
> Quite interesting, with llvm-21 the size increases, too:
> 
> | add/remove: 0/0 grow/shrink: 3/1 up/down: 432/-32 (400)
> | Function                                     old     new   delta
> | fsl_lpspi_setup_transfer                    1072    1216    +144
> | .Ltmp1                                      7116    7260    +144
> | $x                                          7196    7340    +144
> | $d                                          5659    5627     -32
> | Total: Before=28126, After=28526, chg +1.42%
> 
>> I
>> checked because I was suspicious that removing a single ternary could save
>> 52 bytes, but it looks like the outcome after all the optimisations is just
>> unpredictable so there isn't much point in making changes like this.
>>
>> You also didn't say _why_ we need to save 50 bytes, or what the performance
>> impact is.
> 
> I just checked the impact on the code size with gcc and was positively
> surprised. :) I don't need to save 50 bytes and there's probably no
> measurable performance impact.
> 
> regards,
> Marc
> 


  reply	other threads:[~2026-03-16 12:08 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-16  8:39 [PATCH spi-next 00/11] spi: spi-fsl-lpspi: various cleanup and enhancement patches Marc Kleine-Budde
2026-03-16  8:39 ` [PATCH spi-next 01/11] spi: spi-fsl-lpspi: adapt to kernel coding style Marc Kleine-Budde
2026-03-16  8:39 ` [PATCH spi-next 02/11] spi: spi-fsl-lpspi: fsl_lpspi_probe(): use FIELD_GET to decode Parameter register Marc Kleine-Budde
2026-03-17  1:05   ` Frank Li
2026-03-17  9:04     ` Marc Kleine-Budde
2026-03-16  8:39 ` [PATCH spi-next 03/11] spi: spi-fsl-lpspi: fsl_lpspi_set_cmd(): use FIELD_PREP to encode Transmit Command register Marc Kleine-Budde
2026-03-16  8:39 ` [PATCH spi-next 04/11] spi: spi-fsl-lpspi: fsl_lpspi_set_watermark(): use FIELD_PREP() to encode FIFO Status register Marc Kleine-Budde
2026-03-16 14:39   ` Mark Brown
2026-03-16 16:49     ` Marc Kleine-Budde
2026-03-16 17:37       ` Mark Brown
2026-03-16 17:59         ` Marc Kleine-Budde
2026-03-16 18:16           ` Mark Brown
2026-03-16 18:31             ` Marc Kleine-Budde
2026-03-16 18:49               ` Mark Brown
2026-03-17  9:44                 ` Marc Kleine-Budde
2026-03-19 18:17                   ` Marc Kleine-Budde
2026-03-16  8:39 ` [PATCH spi-next 05/11] spi: spi-fsl-lpspi: fsl_lpspi_setup_transfer(): remove useless spi_transfer NULL pointer check Marc Kleine-Budde
2026-03-16  8:39 ` [PATCH spi-next 06/11] spi: spi-fsl-lpspi: fsl_lpspi_can_dma(): directly assign return value to fsl_lpspi->usedma Marc Kleine-Budde
2026-03-16  8:39 ` [PATCH spi-next 07/11] spi: spi-fsl-lpspi: fsl_lpspi_reset(): convert to void Marc Kleine-Budde
2026-03-16  8:39 ` [PATCH spi-next 08/11] spi: spi-fsl-lpspi: fsl_lpspi_write_tx_fifo(): simplify while() loop check Marc Kleine-Budde
2026-03-16  8:39 ` [PATCH spi-next 09/11] spi: spi-fsl-lpspi: make struct lpspi_config::mode u32 Marc Kleine-Budde
2026-03-16  8:39 ` [PATCH spi-next 10/11] spi: spi-fsl-lpspi: fsl_lpspi_set_cmd(): use mode from (struct fsl_lpspi_data::config::mode Marc Kleine-Budde
2026-03-16 11:51   ` Marek Vasut
2026-03-16  8:39 ` [PATCH spi-next 11/11] spi: spi-fsl-lpspi: fsl_lpspi_set_bitrate(): don't treat devtype_data->prescale_max == 0 as a special case Marc Kleine-Budde
2026-03-16  9:57   ` James Clark
2026-03-16 11:19     ` Marc Kleine-Budde
2026-03-16 12:08       ` James Clark [this message]
2026-03-16 12:11         ` Marc Kleine-Budde
2026-04-07 16:45 ` [PATCH spi-next 00/11] spi: spi-fsl-lpspi: various cleanup and enhancement patches Mark Brown

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=2b1eecef-9da4-45a7-9401-425715de4624@linaro.org \
    --to=james.clark@linaro.org \
    --cc=Frank.Li@nxp.com \
    --cc=broonie@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    /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

all inboxes | Powered by JetHome®