mtd: spi-nor: move manuf out of the core - batch 2
Subsystems (2)
cover mtd: spi-nor: move manuf out of the core - batch 2
From: Tudor Ambarus <[email protected]>
Add post_sfdp() hook to tweak flash config.
In the quest of moving the manufacturer code out of the spi-nor core, we want to impose the following sequence of calls:
1/ spi-nor core legacy flash parameters init:
spi_nor_default_init_params()
2/ MFR-based manufacturer flash parameters init:
nor->manufacturer->fixups->default_init()
3/ specific flash_info tweeks done when decisions can not be done just on
MFR:
nor->info->fixups->default_init()
4/ SFDP tables flash parameters init - SFDP knows better:
spi_nor_sfdp_init_params()
5/ post SFDP tables flash parameters updates - in case manufacturers get
the serial flash tables wrong or incomplete.
nor->info->fixups->post_sfdp()
The later can be extended to nor->manufacturer->fixups->post_sfdp() if needed.
This series opens doors for 5/.
Tested on sst26vf064b with atmel-quadspi SPIMEM driver.
Depends on:
https://patchwork.ozlabs.org/project/linux-mtd/list/?series=122420
Boris Brezillon (4):
mtd: spi-nor: Add post_sfdp() hook to tweak flash config
mtd: spi-nor: Add spansion_post_sfdp_fixups()
mtd: spi-nor: Add a ->convert_addr() method
mtd: spi-nor: Add the SPI_NOR_XSR_RDY flag
Tudor Ambarus (2):
mtd: spi_nor: Add nor->setup() method
mtd: spi-nor: Add s3an_post_sfdp_fixups()
drivers/mtd/spi-nor/spi-nor.c | 192 +++++++++++++++++----------------- include/linux/mtd/spi-nor.h | 232 +++++++++++++++++++++++++++--------------- 2 files changed, 245 insertions(+), 179 deletions(-)
Signature · 1 line
2.9.5
PATCH 1/6 mtd: spi-nor: Add post_sfdp() hook to tweak flash config
From: Boris Brezillon <[email protected]>
SFDP tables are sometimes wrong and we need a way to override the config chosen by the SFDP parsing logic without discarding all of it.
Add a new hook called after the SFDP parsing has taken place to deal with such problems.
--- drivers/mtd/spi-nor/spi-nor.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/mtd/spi-nor/spi-nor.c +16 -0
@@ -221,6 +221,11 @@ struct sfdp_bfpt {* flash parameters when information provided by the flash_info * table is incomplete or wrong. * @post_bfpt: called after the BFPT table has been parsed +* @post_sfdp: called after SFDP has been parsed (is also called for SPI NORs +* that do not support RDSFDP). Typically used to tweak various +* parameters that could not be extracted by other means (i.e. +* when information provided by the SFDP/flash_info tables are +* incomplete or wrong). * * Those hooks can be used to tweak the SPI NOR configuration when the SFDP * table is broken or not available.
@@ -232,6 +237,8 @@ struct spi_nor_fixups {const struct sfdp_parameter_header *bfpt_header, const struct sfdp_bfpt *bfpt, struct spi_nor_flash_parameter *params); +void (*post_sfdp)(struct spi_nor *nor, +struct spi_nor_flash_parameter *params); };struct flash_info {
@@ -4444,6 +4451,13 @@ static void spi_nor_default_init_params(struct spi_nor *nor,spi_nor_init_uniform_erase_map (map, erase_mask, params->size); } +static void spi_nor_post_sfdp_fixups (struct spi_nor *nor, +struct spi_nor_flash_parameter *params) +{ +if (nor->info->fixups && nor->info->fixups->post_sfdp) +return nor->info->fixups->post_sfdp (nor, params); +} +static void spi_nor_init_params (struct spi_nor *nor,struct spi_nor_flash_parameter *params) {
@@ -4454,6 +4468,8 @@ static void spi_nor_init_params(struct spi_nor *nor,if ((nor->info->flags & (SPI_NOR_DUAL_READ |SPI_NOR_QUAD_READ )) && !(nor->info->flags &SPI_NOR_SKIP_SFDP ))spi_nor_sfdp_init_params (nor, params); + +spi_nor_post_sfdp_fixups (nor, params); } static int spi_nor_select_read(struct spi_nor *nor,
Signature · 1 line
2.9.5
PATCH 2/6 mtd: spi-nor: Add spansion_post_sfdp_fixups()
In reply to [email protected]From: Boris Brezillon <[email protected]>
Add a spansion_post_sfdp_fixups() function to fix the erase opcode, erase sector size and set the SNOR_F_4B_OPCODES flag. This way, all spansion related quirks are placed in the spansion_post_sfdp_fixups() function.
--- drivers/mtd/spi-nor/spi-nor.c | 44 +++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +30 -14
@@ -737,18 +737,6 @@ static u8 spi_nor_convert_3to4_erase(u8 opcode)static void spi_nor_set_4byte_opcodes (struct spi_nor *nor) { -/* Do some manufacturer fixups first */ -switch (JEDEC_MFR (nor->info)) { -case SNOR_MFR_SPANSION : -/* No small sector erase for 4-byte command set */ - nor->erase_opcode =SPINOR_OP_SE ; - nor->mtd.erasesize = nor->info->sector_size; -break ; - -default : -break ; - } - nor->read_opcode =spi_nor_convert_3to4_read (nor->read_opcode); nor->program_opcode =spi_nor_convert_3to4_program (nor->program_opcode); nor->erase_opcode =spi_nor_convert_3to4_erase (nor->erase_opcode);
@@ -4451,9 +4439,38 @@ static void spi_nor_default_init_params(struct spi_nor *nor,spi_nor_init_uniform_erase_map (map, erase_mask, params->size); } +static void spansion_post_sfdp_fixups (struct spi_nor *nor) +{ +struct mtd_info *mtd = &nor->mtd; + +if (mtd->size <=SZ_16M ) +return ; + + nor->flags |=SNOR_F_4B_OPCODES ; +/* No small sector erase for 4-byte command set */ + nor->erase_opcode =SPINOR_OP_SE ; + nor->mtd.erasesize = nor->info->sector_size; +} + +static void +spi_nor_manufacturer_post_sfdp_fixups (struct spi_nor *nor, +struct spi_nor_flash_parameter *params) +{ +switch (JEDEC_MFR (nor->info)) { +case SNOR_MFR_SPANSION : +spansion_post_sfdp_fixups (nor); +break ; + +default : +break ; + } +} +static void spi_nor_post_sfdp_fixups (struct spi_nor *nor,struct spi_nor_flash_parameter *params) { +spi_nor_manufacturer_post_sfdp_fixups (nor, params); +if (nor->info->fixups && nor->info->fixups->post_sfdp)return nor->info->fixups->post_sfdp (nor, params); }
@@ -4934,8 +4951,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->addr_width =3 ; } -if (info->flags &SPI_NOR_4B_OPCODES || - (JEDEC_MFR (info) ==SNOR_MFR_SPANSION && mtd->size >SZ_16M )) +if (info->flags &SPI_NOR_4B_OPCODES ) nor->flags |=SNOR_F_4B_OPCODES ; if (nor->addr_width == 4 && nor->flags & SNOR_F_4B_OPCODES &&
Signature · 1 line
2.9.5
PATCH 3/6 mtd: spi-nor: Add a ->convert_addr() method
In reply to [email protected]From: Boris Brezillon <[email protected]>
In order to separate manufacturer quirks from the core we need to get rid of all the manufacturer specific flags, like the SNOR_F_S3AN_ADDR_DEFAULT one.
This can easily be replaced by a ->convert_addr() hook, which when implemented will provide the core with an easy way to convert an absolute address into something the flash understands.
Right now the only user are the S3AN chips, but other manufacturers can implement it if needed.
--- drivers/mtd/spi-nor/spi-nor.c | 24 ++++++++++++++---------- include/linux/mtd/spi-nor.h | 15 +++++++++------ 2 files changed, 23 insertions(+), 16 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +14 -10
@@ -1045,10 +1045,9 @@ static void spi_nor_unlock_and_unprep(struct spi_nor *nor, enum spi_nor_ops ops)* Addr can safely be unsigned int, the biggest S3AN device is smaller than * 4 MiB. */ -static loff_t spi_nor_s3an_addr_convert (struct spi_nor *nor,unsigned int addr) +static u32 s3an_convert_addr (struct spi_nor *nor,u32 addr) { -unsigned int offset; -unsigned int page; +u32 offset, page; offset = addr % nor->page_size; page = addr / nor->page_size;
@@ -1057,6 +1056,14 @@ static loff_t spi_nor_s3an_addr_convert(struct spi_nor *nor, unsigned int addr)return page | offset; } +static u32 spi_nor_convert_addr (struct spi_nor *nor,loff_t addr) +{ +if (!nor->convert_addr) +return addr; + +return nor->convert_addr (nor, addr); +} +/* * Initiate the erasure of a single sector */
@@ -1065,8 +1072,7 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)u8 buf[SPI_NOR_MAX_ADDR_WIDTH ];int i; -if (nor->flags &SNOR_F_S3AN_ADDR_DEFAULT ) - addr =spi_nor_s3an_addr_convert (nor, addr); + addr =spi_nor_convert_addr (nor, addr);if (nor->erase)return nor->erase (nor, addr);
@@ -2675,8 +2681,7 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,while (len) {loff_t addr = from; -if (nor->flags &SNOR_F_S3AN_ADDR_DEFAULT ) - addr =spi_nor_s3an_addr_convert (nor, addr); + addr =spi_nor_convert_addr (nor, addr); ret =spi_nor_read_data (nor, addr, len, buf);if (ret ==0 ) {
@@ -2820,8 +2825,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, page_remain =min_t (size_t, nor->page_size - page_offset, len - i); -if (nor->flags &SNOR_F_S3AN_ADDR_DEFAULT ) - addr =spi_nor_s3an_addr_convert (nor, addr); + addr =spi_nor_convert_addr (nor, addr);write_enable (nor); ret =spi_nor_write_data (nor, addr, page_remain, buf + i);
@@ -2889,7 +2893,7 @@ static int s3an_nor_scan(struct spi_nor *nor) nor->mtd.erasesize =8 * nor->page_size; }else {/* Flash in Default addressing mode */ - nor->flags |=SNOR_F_S3AN_ADDR_DEFAULT ; + nor->convert_addr = s3an_convert_addr; }return 0 ;
include/linux/mtd/spi-nor.h +9 -6
@@ -238,12 +238,11 @@ enum spi_nor_option_flags {SNOR_F_USE_FSR =BIT (0 ),SNOR_F_HAS_SR_TB =BIT (1 ),SNOR_F_NO_OP_CHIP_ERASE =BIT (2 ), -SNOR_F_S3AN_ADDR_DEFAULT =BIT (3 ), -SNOR_F_READY_XSR_RDY =BIT (4 ), -SNOR_F_USE_CLSR =BIT (5 ), -SNOR_F_BROKEN_RESET =BIT (6 ), -SNOR_F_4B_OPCODES =BIT (7 ), - SNOR_F_HAS_4BAIT = BIT(8), +SNOR_F_READY_XSR_RDY =BIT (3 ), +SNOR_F_USE_CLSR =BIT (4 ), +SNOR_F_BROKEN_RESET =BIT (5 ), +SNOR_F_4B_OPCODES =BIT (6 ), + SNOR_F_HAS_4BAIT = BIT(7), };/**
@@ -380,6 +379,9 @@ struct flash_info;* @quad_enable: [FLASH-SPECIFIC] enables SPI NOR quad mode * @set_4byte: [FLASH-SPECIFIC] puts the SPI NOR in 4 byte addressing * mode +* @convert_addr: [FLASH-SPECIFIC] convert an absolute address into +* something the flash will understand. Particularly +* useful when pagesize is not a power-of-2 * @disable_write_protection: [FLASH-SPECIFIC] disable write protection during * power-up * completely locked
@@ -423,6 +425,7 @@ struct spi_nor {int (*flash_is_locked)(struct spi_nor *nor,loff_t ofs,uint64_t len);int (*quad_enable)(struct spi_nor *nor);int (*set_4byte)(struct spi_nor *nor,bool enable); +u32 (*convert_addr)(struct spi_nor *nor,u32 addr);int (*disable_write_protection)(struct spi_nor *nor);const struct spi_nor_locking_ops *locking_ops;
Signature · 1 line
2.9.5
PATCH 4/6 mtd: spi_nor: Add nor->setup() method
In reply to [email protected]From: Tudor Ambarus <[email protected]>
To be used by some manufacturers to configure the spi-nor flash memory. Right now the only user will be the S3AN chips, but other manufacturers can implement it if needed.
Move spi_nor_flash_parameter and spi_nor_hwcaps related code to avoid forward declarations.
--- drivers/mtd/spi-nor/spi-nor.c | 63 ------------ include/linux/mtd/spi-nor.h | 217 +++++++++++++++++++++++++++--------------- 2 files changed, 142 insertions(+), 138 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +0 -63
@@ -40,69 +40,6 @@#define SPI_NOR_MAX_ID_LEN 6#define SPI_NOR_MAX_ADDR_WIDTH 4 -struct spi_nor_read_command { -u8 num_mode_clocks; -u8 num_wait_states; -u8 opcode; -enum spi_nor_protocol proto; -}; - -struct spi_nor_pp_command { -u8 opcode; -enum spi_nor_protocol proto; -}; - -enum spi_nor_read_command_index { -SNOR_CMD_READ , -SNOR_CMD_READ_FAST , -SNOR_CMD_READ_1_1_1_DTR , - -/* Dual SPI */ -SNOR_CMD_READ_1_1_2 , -SNOR_CMD_READ_1_2_2 , -SNOR_CMD_READ_2_2_2 , -SNOR_CMD_READ_1_2_2_DTR , - -/* Quad SPI */ -SNOR_CMD_READ_1_1_4 , -SNOR_CMD_READ_1_4_4 , -SNOR_CMD_READ_4_4_4 , -SNOR_CMD_READ_1_4_4_DTR , - -/* Octal SPI */ -SNOR_CMD_READ_1_1_8 , -SNOR_CMD_READ_1_8_8 , -SNOR_CMD_READ_8_8_8 , -SNOR_CMD_READ_1_8_8_DTR , - -SNOR_CMD_READ_MAX -}; - -enum spi_nor_pp_command_index { -SNOR_CMD_PP , - -/* Quad SPI */ -SNOR_CMD_PP_1_1_4 , -SNOR_CMD_PP_1_4_4 , -SNOR_CMD_PP_4_4_4 , - -/* Octal SPI */ -SNOR_CMD_PP_1_1_8 , -SNOR_CMD_PP_1_8_8 , -SNOR_CMD_PP_8_8_8 , - -SNOR_CMD_PP_MAX -}; - -struct spi_nor_flash_parameter { -u64 size; -u32 page_size; - -struct spi_nor_hwcaps hwcaps; -struct spi_nor_read_command reads[SNOR_CMD_READ_MAX ]; -struct spi_nor_pp_command page_programs[SNOR_CMD_PP_MAX ]; -}; -struct sfdp_parameter_header {u8 id_lsb;u8 minor;
include/linux/mtd/spi-nor.h +142 -75
241 lines not on this page · raw message
Signature · 1 line
2.9.5
PATCH 5/6 mtd: spi-nor: Add s3an_post_sfdp_fixups()
In reply to [email protected]From: Tudor Ambarus <[email protected]>
s3an_nor_scan() was overriding the opcode selection done in spi_nor_default_setup(). Set nor->setup() method in order to avoid unnecessary call to spi_nor_default_setup().
--- drivers/mtd/spi-nor/spi-nor.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +25 -10
@@ -2795,7 +2795,9 @@ static int spi_nor_check(struct spi_nor *nor)return 0 ; } -static int s3an_nor_scan (struct spi_nor *nor) +static int s3an_nor_setup (struct spi_nor *nor, +const struct spi_nor_flash_parameter *params, +const struct spi_nor_hwcaps *hwcaps) {int ret;u8 val;
@@ -4393,6 +4395,11 @@ static void spansion_post_sfdp_fixups(struct spi_nor *nor) nor->mtd.erasesize = nor->info->sector_size; } +static void s3an_post_sfdp_fixups (struct spi_nor *nor) +{ + nor->setup = s3an_nor_setup; +} +static void spi_nor_manufacturer_post_sfdp_fixups (struct spi_nor *nor,struct spi_nor_flash_parameter *params)
@@ -4405,6 +4412,9 @@ spi_nor_manufacturer_post_sfdp_fixups(struct spi_nor *nor,default :break ; } + +if (nor->info->flags &SPI_S3AN ) +s3an_post_sfdp_fixups (nor); } static void spi_nor_post_sfdp_fixups(struct spi_nor *nor,
@@ -4582,9 +4592,9 @@ static int spi_nor_select_erase(struct spi_nor *nor, u32 wanted_size)return 0 ; } -static int spi_nor_setup (struct spi_nor *nor, -const struct spi_nor_flash_parameter *params, -const struct spi_nor_hwcaps *hwcaps) +static int spi_nor_default_setup (struct spi_nor *nor, +const struct spi_nor_flash_parameter *params, +const struct spi_nor_hwcaps *hwcaps) {u32 ignored_mask, shared_mask;int err;
@@ -4641,6 +4651,16 @@ static int spi_nor_setup(struct spi_nor *nor,return err; } +static int spi_nor_setup (struct spi_nor *nor, +const struct spi_nor_flash_parameter *params, +const struct spi_nor_hwcaps *hwcaps) +{ +if (!nor->setup) +return 0 ; + +return nor->setup (nor, params, hwcaps); +} +static int spi_nor_disable_write_protection (struct spi_nor *nor) {if (!nor->disable_write_protection)
@@ -4804,6 +4824,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,/* Kept only for backward compatibility purpose. */ nor->quad_enable = spansion_quad_enable; nor->set_4byte = spansion_set_4byte; + nor->setup = spi_nor_default_setup;/* Default locking operations. */ if (info->flags &SPI_NOR_HAS_LOCK ) {
@@ -4905,12 +4926,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,return -EINVAL ; } -if (info->flags &SPI_S3AN ) { - ret =s3an_nor_scan (nor); -if (ret) -return ret; - } -/* Send all the required SPI flash commands to initialize device */ ret =spi_nor_init (nor);if (ret)
Signature · 1 line
2.9.5
PATCH 6/6 mtd: spi-nor: Add the SPI_NOR_XSR_RDY flag
In reply to [email protected]From: Boris Brezillon <[email protected]>
S3AN flashes use a specific opcode to read the status register. We currently use the SPI_S3AN flag to decide whether this specific SR read opcode should be used, but SPI_S3AN is about to disappear, so let's add a new flag.
Note that we use the same bit as SPI_S3AN implies SPI_NOR_XSR_RDY and vice versa.
--- drivers/mtd/spi-nor/spi-nor.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/spi-nor.c +9 -1
@@ -213,6 +213,14 @@ struct flash_info {* bit. Must be used with * SPI_NOR_HAS_LOCK. */ +#define SPI_NOR_XSR_RDY BIT(10)/* +* S3AN flashes have specific opcode to +* read the status register. +* Flags SPI_NOR_XSR_RDY and SPI_S3AN +* use the same bit as one implies the +* other, but we will get rid of +* SPI_S3AN soon. +*/ #define SPI_S3AN BIT(10)/* * Xilinx Spartan 3AN In-System Flash * (MFR cannot be used for probing
@@ -4818,7 +4826,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,* spi_nor_wait_till_ready(). Xilinx S3AN share MFR * with Atmel spi-nor */ -if (info->flags &SPI_S3AN ) +if (info->flags &SPI_NOR_XSR_RDY ) nor->flags |=SNOR_F_READY_XSR_RDY ;/* Kept only for backward compatibility purpose. */
Signature · 1 line
2.9.5
RE: [PATCH 5/6] mtd: spi-nor: Add s3an_post_sfdp_fixups()
In reply to [email protected]Hi Tudor,
Thanks for the updates. With these kind of updates, we can add Vendor specific Code easily, like Xilinx Dual parallel and stacked modes.
In these configurations we need to tweak the nor parameters like page_size, sectors etc. So with the help of these patches. we can easily update these parameters.
Quoted 48 lines
-----Original Message-----
From: linux-mtd <[email protected]> On Behalf Of [email protected]
Sent: Wednesday, July 31, 2019 2:42 PM
To: [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH 5/6] mtd: spi-nor: Adds3an_post_sfdp_fixups()From: Tudor Ambarus <[email protected]>
s3an_nor_scan()was overriding the opcode selection done inspi_nor_default_setup(). Set nor-Quoted 1 line
setup()method in order to avoid unnecessary call tospi_nor_default_setup().Signed-off-by Tudor Ambarus <[email protected]>--- drivers/mtd/spi-nor/spi-nor.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-)drivers/mtd/spi-nor/spi-nor.c index renamed from drivers/mtd/spi-nor/spi-nor.c +0
-0
0ff474e5e4f5..5fea5d7ce2cb100644drivers/mtd/spi-nor/spi-nor.c +8
-1@@ -2795,7 +2795,9 @@ static int spi_nor_check(struct spi_nor *nor)return 0 ; } -static int s3an_nor_scan (struct spi_nor *nor) +static int s3an_nor_setup (struct spi_nor *nor, +const struct spi_nor_flash_parameter *params, +const struct spi_nor_hwcaps *hwcaps) {int ret;u8 val;@@ -4393,6 +4395,11 @@ static void spansion_post_sfdp_fixups(struct spi_nor *nor) nor->mtd.erasesize = nor->info->sector_size; } +static void s3an_post_sfdp_fixups (struct spi_nor *nor) { + nor->setup = s3an_nor_setup; +} + static void spi_nor_manufacturer_post_sfdp_fixups(struct spi_nor *nor, struct spi_nor_flash_parameter *params) @@ -4405,6 +4412,9 @@ spi_nor_manufacturer_post_sfdp_fixups(struct spi_nor *nor, default:
drivers/mtd/spi-nor/spi-nor.c spi_nor_manufacturer_post_sfdp_fixups(struct spi_nor *nor, · line 4418
Quoted 6 lines
drivers/mtd/spi-nor/spi-nor.c +3
-0break ; } + +if (nor->info->flags &SPI_S3AN ) +s3an_post_sfdp_fixups (nor); }
Instead of checking the flags, why can't we call directly the nor_fixups? like Boris implementation nor->info->fixups->post_sfdp()
https://patchwork.ozlabs.org/patch/1009291/
Thanks,
Naga Sureshkumar Relli
Quoted 56 lines
static void spi_nor_post_sfdp_fixups(struct
spi_nor*nor, @@ -4582,9 +4592,9 @@ static
intspi_nor_select_erase(struct spi_nor *nor, u32 wanted_size)drivers/mtd/spi-nor/spi-nor.c +12
-10return 0 ; } -static int spi_nor_setup (struct spi_nor *nor, -const struct spi_nor_flash_parameter *params, -const struct spi_nor_hwcaps *hwcaps) +static int spi_nor_default_setup (struct spi_nor *nor, +const struct spi_nor_flash_parameter *params, +const struct spi_nor_hwcaps *hwcaps) {u32 ignored_mask, shared_mask;int err;@@ -4641,6 +4651,16 @@ static int spi_nor_setup(struct spi_nor *nor,return err; } +static int spi_nor_setup (struct spi_nor *nor, +const struct spi_nor_flash_parameter *params, +const struct spi_nor_hwcaps *hwcaps) { +if (!nor->setup) +return 0 ; + +return nor->setup (nor, params, hwcaps); } +static int spi_nor_disable_write_protection (struct spi_nor *nor) {if (!nor->disable_write_protection)@@ -4804,6 +4824,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,/* Kept only for backward compatibility purpose. */ nor->quad_enable = spansion_quad_enable; nor->set_4byte = spansion_set_4byte; + nor->setup = spi_nor_default_setup;/* Default locking operations. */ if (info->flags &SPI_NOR_HAS_LOCK ) {@@ -4905,12 +4926,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,return -EINVAL ; } -if (info->flags &SPI_S3AN ) { - ret =s3an_nor_scan (nor); -if (ret) -return ret; - } -/* Send all the required SPI flash commands to initialize device */ ret =spi_nor_init (nor);if (ret) --2.9.5
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH 5/6] mtd: spi-nor: Add s3an_post_sfdp_fixups()
Quoted 6 lines · On Wed, 31 Jul 2019 12:31:19 +0000 Naga Sureshkumar Relli…
Hi Tudor,
Thanks for the updates. With these kind of updates, we can add Vendor specific Code easily, like Xilinx Dual parallel and stacked modes.
In these configurations we need to tweak the nor parameters likepage_size, sectors etc. So with the help of these patches. we can easily update these parameters.
Absolutely not. This is just a solution to recover from broken SFDP tables.
Re: [PATCH 5/6] mtd: spi-nor: Add s3an_post_sfdp_fixups()
In reply to Naga Sureshkumar RelliHi, Naga,
Quoted 7 lines · Naga Sureshkumar Relli
drivers/mtd/spi-nor/spi-nor.c spi_nor_manufacturer_post_sfdp_fixups(struct spi_nor *nor, · line 4418
Quoted 4 lines
drivers/mtd/spi-nor/spi-nor.c +2
-0+if (nor->info->flags &SPI_S3AN ) +s3an_post_sfdp_fixups (nor); }Instead of checking the flags, why can't we call directly the
nor_fixups? like Boris implementationnor->info->fixups->post_sfdp()
https://patchwork.ozlabs.org/patch/1009291/
This check will vanish and nor->info->fixups->post_sfdp() will be called directly once I'll respin the manufacturer driver part. post_sfdp() will set just flash parameters. Check Boris' patch at
https://patchwork.ozlabs.org/patch/1009295/
I'll try to respin the rest of Boris' patches sometime at the beginning of the next week.
Cheers,
ta
RE: [PATCH 5/6] mtd: spi-nor: Add s3an_post_sfdp_fixups()
In reply to Boris BrezillonQuoted 14 lines
-----Original Message-----
From: Boris Brezillon <[email protected]>
Sent: Wednesday, July 31, 2019 6:08 PM
To: Naga Sureshkumar Relli <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/6] mtd: spi-nor: Adds3an_post_sfdp_fixups()On Wed, 31 Jul 2019 12:31:19 +0000
Naga Sureshkumar Relli <[email protected]> wrote:
Quoted 8 lines
Quoted 6 lines
Hi Tudor,
Thanks for the updates. With these kind of updates, we can add Vendor specific Code easily, like Xilinx Dual parallel and stacked modes.
In these configurations we need to tweak the nor parameters likepage_size, sectors etc. So with the help of these patches. we can easily update these parameters.Absolutely not. This is just a solution to recover from broken SFDP tables.
Ok.
Thanks,
Naga Sureshkumar Relli
RE: [PATCH 5/6] mtd: spi-nor: Add s3an_post_sfdp_fixups()
In reply to [email protected]Hi Tudor,
Quoted 20 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Wednesday, July 31, 2019 6:37 PM
To: Naga Sureshkumar Relli <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/6] mtd: spi-nor: Adds3an_post_sfdp_fixups()Hi, Naga,
Quoted 7 lines · Naga Sureshkumar Relli
drivers/mtd/spi-nor/spi-nor.c spi_nor_manufacturer_post_sfdp_fixups(struct spi_nor *nor, · line 4418
Quoted 4 lines
drivers/mtd/spi-nor/spi-nor.c +2
-0+if (nor->info->flags &SPI_S3AN ) +s3an_post_sfdp_fixups (nor); }Instead of checking the flags, why can't we call directly the
nor_fixups? like Boris implementationnor->info->fixups->post_sfdp()
https://patchwork.ozlabs.org/patch/1009291/
Quoted 5 lines
This check will vanish and
nor->info->fixups->post_sfdp()will be called directly once I'll respin the manufacturer driver part.post_sfdp()will set just flash parameters. Check Boris' patch at https://patchwork.ozlabs.org/patch/1009295/I'll try to respin the rest of Boris' patches sometime at the beginning of the next week.
Ok, Thanks.
Regards,
Naga Sureshkumar Relli
Quoted 3 lines
Cheers,
ta
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH 4/6] mtd: spi_nor: Add nor->setup() method
In reply to [email protected]include/linux/mtd/spi-nor.h struct flash_info; · line 525
Quoted 8 lines · On Wed, 31 Jul 2019 09:12:14 +0000 <[email protected]> wrote:
static inline bool
spi_nor_protocol_is_dtr(enum spi_nor_protocol proto){include/linux/mtd/spi-nor.h +1
-0return !!(proto &SNOR_PROTO_IS_DTR );@@ -384,6 +522,7 @@ struct flash_info;* useful when pagesize is not a power-of-2 * @disable_write_protection: [FLASH-SPECIFIC] disable write protection during * power-up +* @setup: [FLASH-SPECIFIC] configure the spi-nor memory
Might be worth giving a example of the type of configuration that can be done here.
The patch looks good otherwise.
include/linux/mtd/spi-nor.h struct flash_info; · line 526
Quoted 1 line
include/linux/mtd/spi-nor.h +0
-0* completely locked
Looks like this 'completely locked' is a leftover from a previous move (lock functions were move to a separate _ops struct IIRC). Can you fix that?
Quoted 15 lines
include/linux/mtd/spi-nor.h +3
-0* @priv: the private data */ @@ -427,6 +566,9 @@ struct spi_nor {int (*set_4byte)(struct spi_nor *nor,bool enable);u32 (*convert_addr)(struct spi_nor *nor,u32 addr);int (*disable_write_protection)(struct spi_nor *nor); +int (*setup)(struct spi_nor *nor, +const struct spi_nor_flash_parameter *params, +const struct spi_nor_hwcaps *hwcaps);const struct spi_nor_locking_ops *locking_ops;@@ -486,81 +628,6 @@ static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor) }
Re: [PATCH 5/6] mtd: spi-nor: Add s3an_post_sfdp_fixups()
In reply to [email protected]Quoted 89 lines · On Wed, 31 Jul 2019 09:12:16 +0000 <[email protected]> wrote:
From: Tudor Ambarus <[email protected]>
s3an_nor_scan()was overriding the opcode selection done inspi_nor_default_setup(). Setnor->setup()method in order to avoid unnecessary call tospi_nor_default_setup().Signed-off-by Tudor Ambarus <[email protected]>--- drivers/mtd/spi-nor/spi-nor.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-)drivers/mtd/spi-nor/spi-nor.c +25
-4@@ -2795,7 +2795,9 @@ static int spi_nor_check(struct spi_nor *nor)return 0 ; } -static int s3an_nor_scan (struct spi_nor *nor) +static int s3an_nor_setup (struct spi_nor *nor, +const struct spi_nor_flash_parameter *params, +const struct spi_nor_hwcaps *hwcaps) {int ret;u8 val;@@ -4393,6 +4395,11 @@ static void spansion_post_sfdp_fixups(struct spi_nor *nor) nor->mtd.erasesize = nor->info->sector_size; } +static void s3an_post_sfdp_fixups (struct spi_nor *nor) +{ + nor->setup = s3an_nor_setup; +} +static void spi_nor_manufacturer_post_sfdp_fixups (struct spi_nor *nor,struct spi_nor_flash_parameter *params)@@ -4405,6 +4412,9 @@ spi_nor_manufacturer_post_sfdp_fixups(struct spi_nor *nor,default :break ; } + +if (nor->info->flags &SPI_S3AN ) +s3an_post_sfdp_fixups (nor); } static void spi_nor_post_sfdp_fixups(struct spi_nor *nor,@@ -4582,9 +4592,9 @@ static int spi_nor_select_erase(struct spi_nor *nor, u32 wanted_size)return 0 ; } -static int spi_nor_setup (struct spi_nor *nor, -const struct spi_nor_flash_parameter *params, -const struct spi_nor_hwcaps *hwcaps) +static int spi_nor_default_setup (struct spi_nor *nor, +const struct spi_nor_flash_parameter *params, +const struct spi_nor_hwcaps *hwcaps) {u32 ignored_mask, shared_mask;int err;@@ -4641,6 +4651,16 @@ static int spi_nor_setup(struct spi_nor *nor,return err; } +static int spi_nor_setup (struct spi_nor *nor, +const struct spi_nor_flash_parameter *params, +const struct spi_nor_hwcaps *hwcaps) +{ +if (!nor->setup) +return 0 ; + +return nor->setup (nor, params, hwcaps); +} +static int spi_nor_disable_write_protection (struct spi_nor *nor) {if (!nor->disable_write_protection)@@ -4804,6 +4824,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,/* Kept only for backward compatibility purpose. */ nor->quad_enable = spansion_quad_enable; nor->set_4byte = spansion_set_4byte; + nor->setup = spi_nor_default_setup;/* Default locking operations. */ if (info->flags &SPI_NOR_HAS_LOCK ) {@@ -4905,12 +4926,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,return -EINVAL ; }
drivers/mtd/spi-nor/spi-nor.c int spi_nor_scan(struct spi_nor *nor, const char *name, · line 4931
Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +0
-6-if (info->flags &SPI_S3AN ) { - ret =s3an_nor_scan (nor); -if (ret) -return ret; - } -/* Send all the required SPI flash commands to initialize device */ ret =spi_nor_init (nor);if (ret)
Almost all of this (except the s3an specific bits) should be done in the previous patch. So I'll put a condition on the R-b I placed on patch 4: some of this code should be moved there.
Vignesh Raghavendra
maintainerRe: [PATCH 6/6] mtd: spi-nor: Add the SPI_NOR_XSR_RDY flag
In reply to [email protected]Quoted 7 lines · On 31/07/19 2:42 PM, [email protected] wrote:
From: Boris Brezillon <[email protected]>
S3AN flashes use a specific opcode to read the status register. We currently use the
SPI_S3ANflag to decide whether this specific SR read opcode should be used, butSPI_S3ANis about to disappear, so let's add a new flag.
I think you can drop SPI_S3AN right away either as separate patch in this series or as part of this patch itself.
Regards
Vignesh
Quoted 38 lines
Note that we use the same bit as
SPI_S3ANimpliesSPI_NOR_XSR_RDYand vice versa.Signed-off-by Boris Brezillon <[email protected]>Signed-off-by Tudor Ambarus <[email protected]>--- drivers/mtd/spi-nor/spi-nor.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/mtd/spi-nor/spi-nor.c +9
-1@@ -213,6 +213,14 @@ struct flash_info {* bit. Must be used with * SPI_NOR_HAS_LOCK. */ +#define SPI_NOR_XSR_RDY BIT(10)/* +* S3AN flashes have specific opcode to +* read the status register. +* Flags SPI_NOR_XSR_RDY and SPI_S3AN +* use the same bit as one implies the +* other, but we will get rid of +* SPI_S3AN soon. +*/ #define SPI_S3AN BIT(10)/* * Xilinx Spartan 3AN In-System Flash * (MFR cannot be used for probing @@ -4818,7 +4826,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,* spi_nor_wait_till_ready(). Xilinx S3AN share MFR * with Atmel spi-nor */ -if (info->flags &SPI_S3AN ) +if (info->flags &SPI_NOR_XSR_RDY ) nor->flags |=SNOR_F_READY_XSR_RDY ;/* Kept only for backward compatibility purpose. */
Signature · 2 lines
Regards Vignesh
Re: [PATCH 4/6] mtd: spi_nor: Add nor->setup() method
In reply to Boris BrezillonQuoted 4 lines · Boris Brezillon
On Wed, 31 Jul 2019 09:12:14 +0000
<[email protected]> wrote:
Quoted 11 lines
include/linux/mtd/spi-nor.h struct flash_info; · line 525
Quoted 8 lines
static inline bool
spi_nor_protocol_is_dtr(enum spi_nor_protocol proto){include/linux/mtd/spi-nor.h +1
-0return !!(proto &SNOR_PROTO_IS_DTR );@@ -384,6 +522,7 @@ struct flash_info;* useful when pagesize is not a power-of-2 * @disable_write_protection: [FLASH-SPECIFIC] disable write protection during * power-up +* @setup: [FLASH-SPECIFIC] configure the spi-nor memory Might be worth giving a example of the type of configuration that can be done here.
will do
Quoted 10 lines
The patch looks good otherwise.
Reviewed-by Boris Brezillon <[email protected]>include/linux/mtd/spi-nor.h struct flash_info; · line 526
Quoted 1 line
include/linux/mtd/spi-nor.h +0
-0* completely locked Looks like this 'completely locked' is a leftover from a previous move (lock functions were move to a separate
_opsstruct IIRC). Can you fix that?
there's already a patch on ML for this, I'll apply it.
Thanks,
ta
Re: [PATCH 5/6] mtd: spi-nor: Add s3an_post_sfdp_fixups()
In reply to Boris BrezillonQuoted 3 lines · Boris Brezillon
Almost all of this (except the s3an specific bits) should be done in the previous patch. So I'll put a condition on the R-b I placed on patch 4: some of this code should be moved there.
You're right, will do.
Cheers,
ta
Re: [PATCH 6/6] mtd: spi-nor: Add the SPI_NOR_XSR_RDY flag
In reply to Vignesh RaghavendraQuoted 7 lines · Vignesh Raghavendra
External E-Mail
Quoted 2 lines · On 31/07/19 2:42 PM, [email protected] wrote:
From: Boris Brezillon <[email protected]>
Quoted 9 lines
Quoted 5 lines
S3AN flashes use a specific opcode to read the status register. We currently use the
SPI_S3ANflag to decide whether this specific SR read opcode should be used, butSPI_S3ANis about to disappear, so let's add a new flag.I think you can drop
SPI_S3ANright away either as separate patch in this series or as part of this patch itself.
SPI_NOR_XSR_RDY is more generic than SPI_S3AN, and lets other flashes use SPINOR_OP_XRDSR SR read opcode if needed.
If I drop SPI_S3AN now, I'll have to select the s3an_nor_setup() method based on SPI_NOR_XSR_RDY/SNOR_F_READY_XSR_RDY which might not be correct. There might be flashes that use SPINOR_OP_XRDSR but have a different setup call.
Of course there are a lot of "might" here (because I couldn't find some other NORs that use this opcode), and if you have a strong opinion I can change as you suggested. I prefer to drop SPI_S3AN when moving the xillinx bits out of the core, as in https://patchwork.ozlabs.org/patch/1009295/.
Cheers,
ta