Skip to content

Commit 5927318

Browse files
miquelraynalambarus
authored andcommitted
mtd: spi-nor: Create macros to define chip IDs and geometries
The INFO() macro defines an ID array and a couple of geometry properties. Right now all its lines are duplicated twice because of the INFO6() macro (for extended IDs) and soon as well we will need to add a geometry parameter to include the number of banks. In order to limit the code duplication, let's create a number of intermediate macros which will facilitate defining high-level INFOX() macros. There is no functional change. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Link: https://lore.kernel.org/r/20221215081241.407098-2-miquel.raynal@bootlin.com Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
1 parent ca5a16d commit 5927318

1 file changed

Lines changed: 20 additions & 23 deletions

File tree

drivers/mtd/spi-nor/core.h

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -529,33 +529,30 @@ struct flash_info {
529529
const struct spi_nor_fixups *fixups;
530530
};
531531

532+
#define SPI_NOR_ID_2ITEMS(_id) ((_id) >> 8) & 0xff, (_id) & 0xff
533+
#define SPI_NOR_ID_3ITEMS(_id) ((_id) >> 16) & 0xff, SPI_NOR_ID_2ITEMS(_id)
534+
535+
#define SPI_NOR_ID(_jedec_id, _ext_id) \
536+
.id = { SPI_NOR_ID_3ITEMS(_jedec_id), SPI_NOR_ID_2ITEMS(_ext_id) }, \
537+
.id_len = !(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0))
538+
539+
#define SPI_NOR_ID6(_jedec_id, _ext_id) \
540+
.id = { SPI_NOR_ID_3ITEMS(_jedec_id), SPI_NOR_ID_3ITEMS(_ext_id) }, \
541+
.id_len = 6
542+
543+
#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors) \
544+
.sector_size = (_sector_size), \
545+
.n_sectors = (_n_sectors), \
546+
.page_size = 256
547+
532548
/* Used when the "_ext_id" is two bytes at most */
533549
#define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors) \
534-
.id = { \
535-
((_jedec_id) >> 16) & 0xff, \
536-
((_jedec_id) >> 8) & 0xff, \
537-
(_jedec_id) & 0xff, \
538-
((_ext_id) >> 8) & 0xff, \
539-
(_ext_id) & 0xff, \
540-
}, \
541-
.id_len = (!(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0))), \
542-
.sector_size = (_sector_size), \
543-
.n_sectors = (_n_sectors), \
544-
.page_size = 256, \
550+
SPI_NOR_ID((_jedec_id), (_ext_id)), \
551+
SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
545552

546553
#define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors) \
547-
.id = { \
548-
((_jedec_id) >> 16) & 0xff, \
549-
((_jedec_id) >> 8) & 0xff, \
550-
(_jedec_id) & 0xff, \
551-
((_ext_id) >> 16) & 0xff, \
552-
((_ext_id) >> 8) & 0xff, \
553-
(_ext_id) & 0xff, \
554-
}, \
555-
.id_len = 6, \
556-
.sector_size = (_sector_size), \
557-
.n_sectors = (_n_sectors), \
558-
.page_size = 256, \
554+
SPI_NOR_ID6((_jedec_id), (_ext_id)), \
555+
SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)),
559556

560557
#define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_nbytes) \
561558
.sector_size = (_sector_size), \

0 commit comments

Comments
 (0)