diff mbox series

[v2,15/41] mtd: spi-nor: add SNOR_ID() and SNOR_OTP()

Message ID 20230807-mtd-flash-info-db-rework-v2-15-291a0f39f8d8@kernel.org
State Changes Requested
Delegated to: Ambarus Tudor
Headers show
Series mtd: spi-nor: clean the flash_info database up | expand

Commit Message

Michael Walle Aug. 22, 2023, 7:09 a.m. UTC
After all the preparation, it is now time to introduce the new macros to
specify flashes in our database: SNOR_ID() and SNOR_OTP(). An flash_info
entry might now look like:
    {
        .id = SNOR_ID(0xef, 0x60, 0x16),
        .otp = SNOR_OTP(256, 3, 0x1000, 0x1000),
        .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
    }

Signed-off-by: Michael Walle <mwalle@kernel.org>
---
 drivers/mtd/spi-nor/core.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Tudor Ambarus Sept. 6, 2023, 7:28 a.m. UTC | #1
On 22.08.2023 10:09, Michael Walle wrote:
> After all the preparation, it is now time to introduce the new macros to
> specify flashes in our database: SNOR_ID() and SNOR_OTP(). An flash_info
> entry might now look like:
>     {
>         .id = SNOR_ID(0xef, 0x60, 0x16),
>         .otp = SNOR_OTP(256, 3, 0x1000, 0x1000),
>         .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
>     }
> 
> Signed-off-by: Michael Walle <mwalle@kernel.org>


Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org>


> ---
>  drivers/mtd/spi-nor/core.h | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
> index c22f5cf65a58..420e5ca2cfe1 100644
> --- a/drivers/mtd/spi-nor/core.h
> +++ b/drivers/mtd/spi-nor/core.h
> @@ -559,6 +559,20 @@ struct flash_info {
>  	const struct spi_nor_fixups *fixups;
>  };
>  
> +#define SNOR_ID(...)							\
> +	(&(const struct spi_nor_id){					\
> +		.bytes = (const u8[]){ __VA_ARGS__ },			\
> +		.len = sizeof((u8[]){ __VA_ARGS__ }),			\
> +	})
> +
> +#define SNOR_OTP(_len, _n_regions, _base, _offset)			\
> +	(&(const struct spi_nor_otp_organization){			\
> +		.len = (_len),						\
> +		.base = (_base),					\
> +		.offset = (_offset),					\
> +		.n_regions = (_n_regions),				\
> +	})
> +
>  #define SPI_NOR_ID_2ITEMS(_id) ((_id) >> 8) & 0xff, (_id) & 0xff
>  #define SPI_NOR_ID_3ITEMS(_id) ((_id) >> 16) & 0xff, SPI_NOR_ID_2ITEMS(_id)
>  
>
diff mbox series

Patch

diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index c22f5cf65a58..420e5ca2cfe1 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -559,6 +559,20 @@  struct flash_info {
 	const struct spi_nor_fixups *fixups;
 };
 
+#define SNOR_ID(...)							\
+	(&(const struct spi_nor_id){					\
+		.bytes = (const u8[]){ __VA_ARGS__ },			\
+		.len = sizeof((u8[]){ __VA_ARGS__ }),			\
+	})
+
+#define SNOR_OTP(_len, _n_regions, _base, _offset)			\
+	(&(const struct spi_nor_otp_organization){			\
+		.len = (_len),						\
+		.base = (_base),					\
+		.offset = (_offset),					\
+		.n_regions = (_n_regions),				\
+	})
+
 #define SPI_NOR_ID_2ITEMS(_id) ((_id) >> 8) & 0xff, (_id) & 0xff
 #define SPI_NOR_ID_3ITEMS(_id) ((_id) >> 16) & 0xff, SPI_NOR_ID_2ITEMS(_id)