mtd: spi: spi-nor-core: Add SST vendor specific SFDP parser
Subsystems (5)
v2 cover mtd: spi: spi-nor-core: Add SST vendor specific SFDP parser
From: Tudor Ambarus <[email protected]>
Parse manufacturer specific SFDP table. The SST SFDP table contains pre-programmed globally unique MAC addresses. Retrieve the MAC address from the SPI NOR flash and set it in ethaddr in env.
v2:
- s/SFDP_MICROCHIP_ID/SFDP_SST_ID
- don't drop all information we extracted from BFPT if optional table parsers fail. In case of failing, each optional SFDP parser is responsible to roll back to the previously known spi_nor data.
Tudor Ambarus (4):
mtd: spi: spi-nor-core: Add SST vendor specific SFDP parser
board: atmel: sama5d27_wlsom1_ek: Set ethaddr from spi-nor flash
configs: sama5d27_wlsom1_ek: qspiflash: Enable SPI NOR ethaddr
retrieval
configs: sama5d27_wlsom1_ek: mmc: Enable SPI NOR ethaddr retrieval
arch/arm/mach-at91/include/mach/at91_common.h | 1 + board/atmel/common/Makefile | 1 + board/atmel/common/mac-spi-nor.c | 127 +++++++++++++++++++++ .../atmel/sama5d27_wlsom1_ek/sama5d27_wlsom1_ek.c | 3 + configs/sama5d27_wlsom1_ek_mmc_defconfig | 5 + configs/sama5d27_wlsom1_ek_qspiflash_defconfig | 1 + drivers/mtd/spi/spi-nor-core.c | 46 +++++++- include/linux/mtd/spi-nor.h | 2 + 8 files changed, 184 insertions(+), 2 deletions(-) create mode 100644 board/atmel/common/mac-spi-nor.c
Signature · 1 line
2.9.5
PATCH v2 1/4 mtd: spi: spi-nor-core: Add SST vendor specific SFDP parser
From: Tudor Ambarus <[email protected]>
JESD216 allow vendors to define their own SFDP tables.
Add SST SFDP parser. The vendor table is allocated using resource-managed kmalloc - the table will be freed on driver detach. It will be accessible by getting the UCLASS_SPI_FLASH's private data.
The SST's SFDP table is particularly of interest because contains pre-programmed globally unique EUI-48 and EUI-64 identifiers.
--- drivers/mtd/spi/spi-nor-core.c | 46 ++++++++++++++++++++++++++++++++++++++++-- include/linux/mtd/spi-nor.h | 2 ++ 2 files changed, 46 insertions(+), 2 deletions(-)
drivers/mtd/spi/spi-nor-core.c +44 -2
@@ -1588,6 +1588,7 @@ struct sfdp_parameter_header {#define SFDP_BFPT_ID 0xff00/* Basic Flash Parameter Table */ #define SFDP_SECTOR_MAP_ID 0xff81/* Sector Map Table */ +#define SFDP_SST_ID 0x01bf/* Manufacturer specific Table */ #define SFDP_SIGNATURE 0x50444653U#define SFDP_JESD216_MAJOR 1
@@ -1968,6 +1969,34 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, }/** +* spi_nor_parse_microchip_sfdp() - parse the Microchip manufacturer specific +* SFDP table. +* @nor: pointer to a 'struct spi_nor'. +* @param_header: pointer to the SFDP parameter header. +* +* Return: 0 on success, -errno otherwise. +*/ +static int +spi_nor_parse_microchip_sfdp (struct spi_nor *nor, +const struct sfdp_parameter_header *param_header) +{ +size_t size; +u32 addr; +int ret; + + size = param_header->length *sizeof (u32); + addr =SFDP_PARAM_HEADER_PTP (param_header); + + nor->manufacturer_sfdp =devm_kmalloc (nor->dev, size,GFP_KERNEL ); +if (!nor->manufacturer_sfdp) +return -ENOMEM ; + + ret =spi_nor_read_sfdp (nor, addr, size, nor->manufacturer_sfdp); + +return ret; +} + +/** * spi_nor_parse_sfdp() - parse the Serial Flash Discoverable Parameters. * @nor: pointer to a 'struct spi_nor' * @params: pointer to the 'struct spi_nor_flash_parameter' to be
@@ -2063,12 +2092,25 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor,dev_info (dev,"non-uniform erase sector maps are not supported yet.\n" );break ; +case SFDP_SST_ID : + err =spi_nor_parse_microchip_sfdp (nor, param_header); +break ; +default :break ; } -if (err) - goto exit; +if (err) { +dev_warn (dev,"Failed to parse optional parameter table: %04x\n" , +SFDP_PARAM_HEADER_ID (param_header)); +/* +* Let's not drop all information we extracted so far +* if optional table parsers fail. In case of failing, +* each optional parser is responsible to roll back to +* the previously known spi_nor data. +*/ + err =0 ; + } } exit:
include/linux/mtd/spi-nor.h +2 -0
@@ -261,6 +261,7 @@ struct flash_info;* @lock: the lock for the read/write/erase/lock/unlock operations * @dev: point to a spi device, or a spi nor controller device. * @info: spi-nor part JDEC MFR id and other info +* @manufacturer_sfdp: manufacturer specific SFDP table * @page_size: the page size of the SPI NOR * @addr_width: number of address bytes * @erase_opcode: the opcode for erasing a sector
@@ -299,6 +300,7 @@ struct spi_nor {struct udevice *dev;struct spi_slave *spi;const struct flash_info *info; +u8 *manufacturer_sfdp;u32 page_size;u8 addr_width;u8 erase_opcode;
Signature · 1 line
2.9.5
Vignesh Raghavendra
maintainerPATCH v2 1/4 mtd: spi: spi-nor-core: Add SST vendor specific SFDP parser
Hi
Quoted 8 lines · Tudor.Ambarus at microchip.com
From: Tudor Ambarus <[email protected]>
JESD216 allow vendors to define their own SFDP tables.
Add SST SFDP parser. The vendor table is allocated using resource-managed kmalloc - the table will be freed on driver detach. It will be accessible by getting the UCLASS_SPI_FLASH's private data.
Quoted 5 lines
The SST's SFDP table is particularly of interest because contains pre-programmed globally unique EUI-48 and EUI-64 identifiers.
Signed-off-by Tudor Ambarus <[email protected]>---
Regards
Vignesh
Quoted 100 lines
drivers/mtd/spi/spi-nor-core.c | 46 ++++++++++++++++++++++++++++++++++++++++-- include/linux/mtd/spi-nor.h | 2 ++ 2 files changed, 46 insertions(+), 2 deletions(-)drivers/mtd/spi/spi-nor-core.c +44
-2@@ -1588,6 +1588,7 @@ struct sfdp_parameter_header {#define SFDP_BFPT_ID 0xff00/* Basic Flash Parameter Table */ #define SFDP_SECTOR_MAP_ID 0xff81/* Sector Map Table */ +#define SFDP_SST_ID 0x01bf/* Manufacturer specific Table */ #define SFDP_SIGNATURE 0x50444653U#define SFDP_JESD216_MAJOR 1@@ -1968,6 +1969,34 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, }/** +* spi_nor_parse_microchip_sfdp() - parse the Microchip manufacturer specific +* SFDP table. +* @nor: pointer to a 'struct spi_nor'. +* @param_header: pointer to the SFDP parameter header. +* +* Return: 0 on success, -errno otherwise. +*/ +static int +spi_nor_parse_microchip_sfdp (struct spi_nor *nor, +const struct sfdp_parameter_header *param_header) +{ +size_t size; +u32 addr; +int ret; + + size = param_header->length *sizeof (u32); + addr =SFDP_PARAM_HEADER_PTP (param_header); + + nor->manufacturer_sfdp =devm_kmalloc (nor->dev, size,GFP_KERNEL ); +if (!nor->manufacturer_sfdp) +return -ENOMEM ; + + ret =spi_nor_read_sfdp (nor, addr, size, nor->manufacturer_sfdp); + +return ret; +} + +/** * spi_nor_parse_sfdp() - parse the Serial Flash Discoverable Parameters. * @nor: pointer to a 'struct spi_nor' * @params: pointer to the 'struct spi_nor_flash_parameter' to be @@ -2063,12 +2092,25 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor,dev_info (dev,"non-uniform erase sector maps are not supported yet.\n" );break ; +case SFDP_SST_ID : + err =spi_nor_parse_microchip_sfdp (nor, param_header); +break ; +default :break ; } -if (err) - goto exit; +if (err) { +dev_warn (dev,"Failed to parse optional parameter table: %04x\n" , +SFDP_PARAM_HEADER_ID (param_header)); +/* +* Let's not drop all information we extracted so far +* if optional table parsers fail. In case of failing, +* each optional parser is responsible to roll back to +* the previously known spi_nor data. +*/ + err =0 ; + } } exit:include/linux/mtd/spi-nor.h +2
-0@@ -261,6 +261,7 @@ struct flash_info;* @lock: the lock for the read/write/erase/lock/unlock operations * @dev: point to a spi device, or a spi nor controller device. * @info: spi-nor part JDEC MFR id and other info +* @manufacturer_sfdp: manufacturer specific SFDP table * @page_size: the page size of the SPI NOR * @addr_width: number of address bytes * @erase_opcode: the opcode for erasing a sector @@ -299,6 +300,7 @@ struct spi_nor {struct udevice *dev;struct spi_slave *spi;const struct flash_info *info; +u8 *manufacturer_sfdp;u32 page_size;u8 addr_width;u8 erase_opcode;
Signature · 2 lines
Regards Vignesh
PATCH v2 2/4 board: atmel: sama5d27_wlsom1_ek: Set ethaddr from spi-nor flash
In reply to Tudor.Ambarus at microchip.comFrom: Tudor Ambarus <[email protected]>
The SST26VF064BEUI spi-nor flash is programmed at the factory with a globally unique address stored in the SFDP vendor parameter table and it is permanently writeprotected. Retrieve the EUI-48 address and set it as ethaddr env.
--- arch/arm/mach-at91/include/mach/at91_common.h | 1 + board/atmel/common/Makefile | 1 + board/atmel/common/mac-spi-nor.c | 127 +++++++++++++++++++++ .../atmel/sama5d27_wlsom1_ek/sama5d27_wlsom1_ek.c | 3 + 4 files changed, 132 insertions(+) create mode 100644 board/atmel/common/mac-spi-nor.c
arch/arm/mach-at91/include/mach/at91_common.h +1 -0
@@ -40,6 +40,7 @@ void configure_ddrcfg_input_buffers(bool open);#endif int at91_set_ethaddr (int offset); +void at91_spi_nor_set_ethaddr (void );int at91_video_show_board_info (void );#endif /* AT91_COMMON_H */
board/atmel/common/Makefile +1 -0
@@ -5,4 +5,5 @@ obj-y += board.o obj-$(CONFIG_I2C_EEPROM) += mac_eeprom.o +obj-$(CONFIG_SPI_FLASH_SFDP_SUPPORT) += mac-spi-nor.o obj-$(CONFIG_DM_VIDEO) += video_display.o
board/atmel/common/mac-spi-nor.c new file +127 -0
127 lines not on this page · raw message
board/atmel/sama5d27_wlsom1_ek/sama5d27_wlsom1_ek.c +3 -0
@@ -68,6 +68,9 @@ int board_init(void)#ifdef CONFIG_MISC_INIT_R int misc_init_r (void ) { +#ifdef CONFIG_SPI_FLASH_SFDP_SUPPORT +at91_spi_nor_set_ethaddr (); +#endif return 0 ; }#endif
Signature · 1 line
2.9.5
PATCH v2 3/4 configs: sama5d27_wlsom1_ek: qspiflash: Enable SPI NOR ethaddr retrieval
In reply to Tudor.Ambarus at microchip.comFrom: Tudor Ambarus <[email protected]>
CONFIG_SPI_FLASH_SFDP_SUPPORT enables the SFDP Vendor parser, and for the SST case, the retrieval of the ethaddr from the SPI NOR flash.
--- configs/sama5d27_wlsom1_ek_qspiflash_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/sama5d27_wlsom1_ek_qspiflash_defconfig +1 -0
@@ -78,6 +78,7 @@ CONFIG_MMC_SDHCI_ATMEL=y CONFIG_DM_SPI_FLASH=y CONFIG_SF_DEFAULT_BUS=2 CONFIG_SF_DEFAULT_SPEED=50000000 +CONFIG_SPI_FLASH_SFDP_SUPPORT=y CONFIG_SPI_FLASH_ATMEL=y CONFIG_SPI_FLASH_MACRONIX=y CONFIG_SPI_FLASH_SPANSION=y
Signature · 1 line
2.9.5
PATCH v2 4/4 configs: sama5d27_wlsom1_ek: mmc: Enable SPI NOR ethaddr retrieval
In reply to Tudor.Ambarus at microchip.comFrom: Tudor Ambarus <[email protected]>
Enable the SPI NOR SFDP support and the Microchip QSPI driver. CONFIG_SPI_FLASH_SFDP_SUPPORT enables the SFDP Vendor parser, and for the SST case, the retrieval of the ethaddr from the SPI NOR flash.
While touching the SPI NOR logic, sync with thesama5d27_wlsom1_ek_qspiflash_defconfig and enableCONFIG_SPI_FLASH_SPANSION.
--- configs/sama5d27_wlsom1_ek_mmc_defconfig | 5 +++++ 1 file changed, 5 insertions(+)
configs/sama5d27_wlsom1_ek_mmc_defconfig +5 -0
@@ -65,8 +65,12 @@ CONFIG_DM_MMC=y CONFIG_MMC_SDHCI=y CONFIG_MMC_SDHCI_ATMEL=y CONFIG_DM_SPI_FLASH=y +CONFIG_SF_DEFAULT_BUS=2 +CONFIG_SF_DEFAULT_SPEED=50000000 +CONFIG_SPI_FLASH_SFDP_SUPPORT=y CONFIG_SPI_FLASH_ATMEL=y CONFIG_SPI_FLASH_MACRONIX=y +CONFIG_SPI_FLASH_SPANSION=y CONFIG_SPI_FLASH_STMICRO=y CONFIG_SPI_FLASH_SST=y CONFIG_PHY_MICREL=y
@@ -81,6 +85,7 @@ CONFIG_DEBUG_UART_ANNOUNCE=y CONFIG_ATMEL_USART=y CONFIG_SPI=y CONFIG_DM_SPI=y +CONFIG_ATMEL_QSPI=y CONFIG_TIMER=y CONFIG_SPL_TIMER=y CONFIG_ATMEL_PIT_TIMER=y
Signature · 1 line
2.9.5
v2 cover mtd: spi: spi-nor-core: Add SST vendor specific SFDP parser
In reply to Tudor.Ambarus at microchip.comQuoted 28 lines · On 13.11.2019 17:42, Tudor Ambarus - M18064 wrote:
From: Tudor Ambarus <[email protected]>
Parse manufacturer specific SFDP table. The SST SFDP table contains pre-programmed globally unique MAC addresses. Retrieve the MAC address from the SPI NOR flash and set it in ethaddr in env.
v2:
- s/SFDP_MICROCHIP_ID/SFDP_SST_ID
- don't drop all information we extracted from BFPT if optional table parsers fail. In case of failing, each optional SFDP parser is responsible to roll back to the previously knownspi_nordata.Tudor Ambarus (4):
mtd: spi: spi-nor-core: Add SST vendor specific SFDP parser
board: atmel:sama5d27_wlsom1_ek: Set ethaddr from spi-nor flash
configs:sama5d27_wlsom1_ek: qspiflash: Enable SPI NOR ethaddr
retrieval
configs:sama5d27_wlsom1_ek: mmc: Enable SPI NOR ethaddr retrievalarch/arm/mach-at91/include/mach/at91_common.h | 1 + board/atmel/common/Makefile | 1 + board/atmel/common/mac-spi-nor.c | 127 +++++++++++++++++++++ .../atmel/sama5d27_wlsom1_ek/sama5d27_wlsom1_ek.c | 3 + configs/sama5d27_wlsom1_ek_mmc_defconfig | 5 + configs/sama5d27_wlsom1_ek_qspiflash_defconfig | 1 + drivers/mtd/spi/spi-nor-core.c | 46 +++++++- include/linux/mtd/spi-nor.h | 2 + 8 files changed, 184 insertions(+), 2 deletions(-)
Quoted 2 lines
create mode 100644
board/atmel/common/mac-spi-nor.c
Applied series to u-boot-atmel/next
Thanks !