mbox series

[v2,0/2] spi: Introduce and use spi_bpw_to_bytes()

Message ID 20250417151958.490174-1-andriy.shevchenko@linux.intel.com
Headers show
Series spi: Introduce and use spi_bpw_to_bytes() | expand

Message

Andy Shevchenko April 17, 2025, 3:17 p.m. UTC
Recently in the discussion with David the idea of having
a common helper popped up. The helper converts the given
bits per word to bytes. The result will always be power-of-two
(e.g. for 37 bits it returns 8 bytes) or 0 for 0 input.
More details are in the respective code comment.

This mini-series introduces it and replaces current users
under drivers/spi and we expect more (and possibly some
lurking in other subsystems).

Mark, if you okay with the idea, please, make this to be
an immutable branch or tag for others to pull.

In v2:
- improved examples in the code comment and commit message (David)

Andy Shevchenko (2):
  spi: Add spi_bpw_to_bytes() helper and use it
  spi: dw: Use spi_bpw_to_bytes() helper

 drivers/spi/spi-dw-core.c |  2 +-
 drivers/spi/spi.c         |  2 +-
 include/linux/spi/spi.h   | 25 +++++++++++++++++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)

Comments

Andy Shevchenko April 17, 2025, 3:22 p.m. UTC | #1
On Thu, Apr 17, 2025 at 06:17:52PM +0300, Andy Shevchenko wrote:
> This helper converts the given bits per word to bytes. The result
> will always be power-of-two, e.g.,
> 
>     ===============    =================
>     Input (in bits)    Output (in bytes)
>     ===============    =================
>             0                   0
>             5                   1
>             9                   2

>             2                   4
>             3                   8

My gosh, it lost the couple of characters here, should be 21 and 37 respectively...
I'll fix this in v3.

>     ===============    =================

...

> + * This function converts the given @bpw to bytes. The result is always
> + * power-of-two, e.g.,
> + *
> + *  ===============    =================
> + *  Input (in bits)    Output (in bytes)
> + *  ===============    =================
> + *          0                   0
> + *          5                   1
> + *          9                   2

> + *          2                   4
> + *          3                   8

As per above,

> + *  ===============    =================
David Lechner April 17, 2025, 3:29 p.m. UTC | #2
On 4/17/25 10:17 AM, Andy Shevchenko wrote:
> Recently in the discussion with David the idea of having
> a common helper popped up. The helper converts the given
> bits per word to bytes. The result will always be power-of-two
> (e.g. for 37 bits it returns 8 bytes) or 0 for 0 input.
> More details are in the respective code comment.
> 
> This mini-series introduces it and replaces current users
> under drivers/spi and we expect more (and possibly some
> lurking in other subsystems).
> 
> Mark, if you okay with the idea, please, make this to be
> an immutable branch or tag for others to pull.
> 
> In v2:
> - improved examples in the code comment and commit message (David)

With the typos fixed:

Reviewed-by: David Lechner <dlechner@baylibre.com>