sf: ops: Squash the malloc+memset combo
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v4 1/5 sf: ops: Squash the malloc+memset combo
Squash the malloc()+memset() combo in favor of calloc().
--- drivers/mtd/spi/sf_ops.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/mtd/spi/sf_ops.c +6 -2
@@ -9,6 +9,7 @@*/ #include <common.h> +#include <errno.h> #include <malloc.h> #include <spi.h> #include <spi_flash.h>
@@ -381,8 +382,11 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, } cmdsz =SPI_FLASH_CMD_LEN + flash->dummy_byte; - cmd =malloc (cmdsz); -memset (cmd,0 , cmdsz); + cmd =calloc (1 , cmdsz); +if (!cmd) { +debug ("SF: Failed to allocate cmd\n" ); +return -ENOMEM ; + } cmd[0 ] = flash->read_cmd;while (len) {
Signature · 1 line
1.8.3
PATCH v4 1/5 sf: ops: Squash the malloc+memset combo
Quoted 3 lines · Jagannadha Sutradharudu Teki
Squash the malloc()+memset() combo in favor of
calloc().Signed-off-by Jagannadha Sutradharudu Teki <[email protected]>
btw your CC list seems bugged for some reason ...
Best regards,
Marek Vasut
PATCH v4 2/5 sf: Optimize flash features code
In reply to a message not in the archive- Shrink spi_slave {}
- Shrink spi_flash_params {}
- Documentation for sf features
--- doc/SPI/README.sf-features | 121 +++++++++++++++++++++++++++++ drivers/mtd/spi/sf.c | 4 +- drivers/mtd/spi/sf_internal.h | 1 - drivers/mtd/spi/sf_ops.c | 8 +- drivers/mtd/spi/sf_params.c | 172 +++++++++++++++++++++--------------------- drivers/mtd/spi/sf_probe.c | 71 ++++++++--------- include/spi.h | 42 ++++------- include/spi_flash.h | 34 ++++----- 8 files changed, 272 insertions(+), 181 deletions(-) create mode 100644 doc/SPI/README.sf-features
doc/SPI/README.sf-features new file +121 -0
@@ -0,0 +1,121 @@ +SPI FLASH feature enhancements: +============================== + +This document describes how to extend the current data structures in spi subsystem +for making use of new flash features/operations w.r.t to controller driver support. + +1. spi_slave: + +struct spi_slave { + .......... + u32 mode; + ........ +}; + + at mode can be used to expose the SPI RX/TX operation modes, bus options and +few flags which are used to extended the flash specific features/operations +- include/spi.h + +mode: +- SPI_TX_QPP: 4-wire tx transfer +- SPI_RX_SLOW: 1-wire rx transfer +- SPI_RX_DUAL: 2-wire rx transfer +- SPI_RX_DUAL_IO: 2-wire io rx transfer +- SPI_RX_QUAD: 4-wire rx transfer +- SPI_RX_QUAD_IO: 4-wire io rx transfer +- SPI_SHARED: bus shared with two slaves +- SPI_SEPARATED: bus parallel with two slaves +- SPI_U_PAGE: access second slave in bus shared + +2. spi_flash_params: + +struct spi_flash_params { + ................ + u16 flags; + .............. +}; + + at flags can be use to verify the flash supported features/operations with respect +to controller driven through @mode and also some internal flash specific +operations - include/spi_flash.h + +flags: +- SST_WP: SST flash write protection +- SECT_4K: 4K erase sector +- SECT_32K: 32 erase sector +- E_FSR: Flag status register for erase/write for micron < 256MB flash +- WR_QPP: Quad page program +- RD_SLOW: Array slow read +- RD_DUAL: Dual fast read +- RD_DUAL_IO: Dual IO read +- RD_QUAD: Quad fast read +- RD_QUAD_IO: Quad IO read +- RD_2WIRE: All 2-wire read commands +- RD_FULL: All read commands +- ALL_CMDS: All read and write commands [1] + +3. spi_flash: + +struct spi_flash { + ............... + u8 dual_flash; + u8 shift; + u8 poll_cmd; + u8 erase_cmd; + u8 read_cmd; + u8 write_cmd; + u8 dummy_byte; + ................ +}; + +Few varibles from spi_flash {} can be used to perform the internal operations +based on the selected flash features/operations from spi_slave {} and +spi_flash_params {} - include/spi_flash.h + + at dual_flash: flash can be operated in dual flash [2] + at shift: variable shift operator useful for dual parallel + at poll_cmd: find the read_status or flag_status for polling erase/write operations + at erase_cmd: discovered erase command + at read_cmd: discovered read command + at write_cmd: discovered write command +@dummy_byte: read dummy_byte based on read dummy_cycles. + +dummy byte is determined based on the dummy cycles of a particular command. +Fast commands - dummy_byte = dummy_cycles/8 +I/O commands- dummy_byte = (dummy_cycles * no.of lines)/8 +For I/O commands except cmd[0] everything goes on no.of lines based on +particular command but in case of fast commands except data all go on +single line irrespective of command. + +4. Usage: + +In drivers/spi/*.c assign spi_slave {} with supported features through mode. +Ex: drivers/spi/ti_qspi.c + +struct ti_qspi_slave { + ................ + struct spi_slave slave; + .............. +} + +struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, + unsigned int max_hz, unsigned int mode) +{ + ......... + + qslave = spi_alloc_slave(struct ti_qspi_slave, bus, cs); + if (!qslave) { + printf("SPI_error: Fail to allocate ti_qspi_slave\n"); + return NULL; + } + + qslave->slave.mode = SPI_TX_QPP | SPI_RX_QUAD; + ........ +} + +[1] http://www.spansion.com/Support/Datasheets/S25FL128S_256S_00.pdf +[2] doc/SPI/README.dual-flash + +-- +Jagannadha Sutradharudu Teki <[email protected]> +Sat Jan 18 14:44:28 IST 2014
drivers/mtd/spi/sf.c +2 -2
@@ -19,8 +19,8 @@ static int spi_flash_read_write(struct spi_slave *spi,int ret;#ifdef CONFIG_SF_DUAL_FLASH -if (spi->flags &SPI_XFER_U_PAGE ) - flags |=SPI_XFER_U_PAGE ; +if (spi->mode &SPI_U_PAGE ) + flags |=SPI_U_PAGE ;#endif if (data_len ==0 ) flags |=SPI_XFER_END ;
drivers/mtd/spi/sf_internal.h +0 -1
@@ -67,7 +67,6 @@/* SST specific */ #ifdef CONFIG_SPI_FLASH_SST -# define SST_WP 0x01/* Supports AAI word program */ # define CMD_SST_BP 0x02/* Byte Program */ # define CMD_SST_AAI_WP 0xAD/* Auto Address Incr Word Program */
drivers/mtd/spi/sf_ops.c +4 -4
@@ -139,9 +139,9 @@ static void spi_flash_dual_flash(struct spi_flash *flash, u32 *addr)case SF_DUAL_STACKED_FLASH :if (*addr >= (flash->size >>1 )) { *addr -= flash->size >>1 ; - flash->spi->flags |=SPI_XFER_U_PAGE ; + flash->spi->mode |=SPI_U_PAGE ; }else { - flash->spi->flags &= ~SPI_XFER_U_PAGE ; + flash->spi->mode &= ~SPI_U_PAGE ; }break ;case SF_DUAL_PARALLEL_FLASH :
@@ -171,8 +171,8 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout) }#ifdef CONFIG_SF_DUAL_FLASH -if (spi->flags &SPI_XFER_U_PAGE ) - flags |=SPI_XFER_U_PAGE ; +if (spi->mode &SPI_U_PAGE ) + flags |=SPI_U_PAGE ;#endif ret =spi_xfer (spi,8 , &cmd,NULL , flags);if (ret) {
drivers/mtd/spi/sf_params.c +86 -86
192 lines not on this page · raw message
drivers/mtd/spi/sf_probe.c +31 -40
109 lines not on this page · raw message
include/spi.h +14 -28
68 lines not on this page · raw message
include/spi_flash.h +14 -20
@@ -19,23 +19,6 @@#include <linux/types.h> #include <linux/compiler.h> -/* sf param flags */ -#define SECT_4K 1 << 1 -#define SECT_32K 1 << 2 -#define E_FSR 1 << 3 -#define WR_QPP 1 << 4 - -/* Enum list - Full read commands */ -enum spi_read_cmds { -ARRAY_SLOW =1 <<0 , -DUAL_OUTPUT_FAST =1 <<1 , -DUAL_IO_FAST =1 <<2 , -QUAD_OUTPUT_FAST =1 <<3 , -QUAD_IO_FAST =1 <<4 , -}; -#define RD_EXTN ARRAY_SLOW | DUAL_OUTPUT_FAST | DUAL_IO_FAST -#define RD_FULL RD_EXTN | QUAD_OUTPUT_FAST | QUAD_IO_FAST -/* Dual SPI flash memories */ enum spi_dual_flash {SF_SINGLE_FLASH =0 ,
@@ -51,8 +34,7 @@ enum spi_dual_flash {* @ext_jedec: Device ext_jedec ID * @sector_size: Sector size of this device * @nr_sectors: No.of sectors on this device -* @e_rd_cmd: Enum list for read commands -* @flags: Importent param, for flash specific behaviour +* @flags: Importent params, for flash specific behaviour */ struct spi_flash_params {const char *name;
@@ -60,8 +42,20 @@ struct spi_flash_params {u16 ext_jedec;u32 sector_size;u32 nr_sectors; -u8 e_rd_cmd;u16 flags; +#define SST_WP (1 << 0)/* SST write protection */ +#define SECT_4K (1 << 1)/* 4K erase sector */ +#define SECT_32K (1 << 2)/* 32K erase sector */ +#define E_FSR (1 << 3)/* Enable Flag status register */ +#define WR_QPP (1 << 4)/* Quad page program */ +#define RD_SLOW (1 << 5)/* Array slow read */ +#define RD_DUAL (1 << 6)/* Dual fast read */ +#define RD_DUAL_IO (1 << 7)/* Dual IO fast read */ +#define RD_QUAD (1 << 8)/* Quad fast read */ +#define RD_QUAD_IO (1 << 9)/* Quad IO fast read */ +#define RD_2WIRE (RD_SLOW | RD_DUAL | RD_DUAL_IO) +#define RD_FULL (RD_2WIRE | RD_QUAD | RD_QUAD_IO) +#define ALL_CMDS (WR_QPP | RD_FULL) };extern const struct spi_flash_params spi_flash_params_table[];
Signature · 1 line
1.8.3
PATCH v4 2/5 sf: Optimize flash features code
Quoted 24 lines · Jagannadha Sutradharudu Teki
- Shrink
spi_slave{}
- Shrinkspi_flash_params{}
- Documentation for sf featuresSigned-off-by Jagannadha Sutradharudu Teki <[email protected]>--- doc/SPI/README.sf-features | 121 +++++++++++++++++++++++++++++ drivers/mtd/spi/sf.c | 4 +- drivers/mtd/spi/sf_internal.h | 1 - drivers/mtd/spi/sf_ops.c | 8 +- drivers/mtd/spi/sf_params.c | 172 +++++++++++++++++++++--------------------- drivers/mtd/spi/sf_probe.c | 71 ++++++++--------- include/spi.h | 42 ++++------- include/spi_flash.h | 34 ++++----- 8 files changed, 272 insertions(+), 181 deletions(-) create mode 100644 doc/SPI/README.sf-featuresdoc/SPI/README.sf-features new file +0
-0
doc/SPI/README.sf-features line 2
Quoted 2 lines
doc/SPI/README.sf-features new file +2
-0@@ -0,0 +1,121 @@ +SPI FLASH feature enhancements: +==============================
You're talking about SPI FLASH and the first thing you describe is struct spi_slave {} ? There should be a foreword about this being deprecated in this MW already and that such "extended" stuff is moving over to dedicated SPI NOR framework.
Quoted 14 lines
doc/SPI/README.sf-features new file +1
-0+This document describes how to extend the current data structures in spisubsystem +for making use of new flash features/operations w.r.t to controller driver support. +
+1.spi_slave:doc/SPI/README.sf-features new file +9
-0+ +struct spi_slave { + .......... + u32 mode; + ........ +}; + + at mode can be used to expose the SPI RX/TX operation modes, bus options and +few flags which are used to extended the flash specificfeatures/operations +-
include/spi.h
doc/SPI/README.sf-features line 20
Quoted 3 lines
doc/SPI/README.sf-features new file +3
-0+ +mode: +- SPI_TX_QPP: 4-wire tx transfer
Quad Page Program ... should not ever have anything to do with generic SPI slave. See foreword above ...
Quoted 38 lines
+- SPI_RX_SLOW: 1-wire rx transfer +- SPI_RX_DUAL: 2-wire rx transfer +- SPI_RX_DUAL_IO: 2-wire io rx transfer +- SPI_RX_QUAD: 4-wire rx transfer +- SPI_RX_QUAD_IO: 4-wire io rx transfer +- SPI_SHARED: bus shared with two slaves +- SPI_SEPARATED: bus parallel with two slaves +- SPI_U_PAGE: access second slave in bus shareddoc/SPI/README.sf-features new file +10
-0+ +2. spi_flash_params: + +struct spi_flash_params { + ................ + u16 flags; + .............. +}; + + at flags can be use to verify the flash supported features/operations withrespect +to controller driven through @mode and also some internal flash specific +operations -
include/spi_flash.hdoc/SPI/README.sf-features new file +18
-0+ +flags: +- SST_WP: SST flash write protection +- SECT_4K: 4K erase sector +- SECT_32K: 32 erase sector +- E_FSR: Flag status register for erase/write for micron < 256MB flash +- WR_QPP: Quad page program +- RD_SLOW: Array slow read +- RD_DUAL: Dual fast read +- RD_DUAL_IO: Dual IO read +- RD_QUAD: Quad fast read +- RD_QUAD_IO: Quad IO read +- RD_2WIRE: All 2-wire read commands +- RD_FULL: All read commands +- ALL_CMDS: All read and write commands [1] + +3. spi_flash: +
doc/SPI/README.sf-features line 68
Quoted 10 lines
doc/SPI/README.sf-features new file +10
-0+struct spi_flash { + ............... + u8 dual_flash; + u8 shift; + u8 poll_cmd; + u8 erase_cmd; + u8 read_cmd; + u8 write_cmd; + u8 dummy_byte; + ................
Please use spaces and tabs consistently.
Quoted 36 lines
doc/SPI/README.sf-features new file +3
-0+}; + +Few varibles from spi_flash {} can be used to perform the internaloperations +based on the selected flash features/operations from
spi_slave{} and +spi_flash_params {} -include/spi_flash.h
+
+ atdual_flash: flash can be operated in dual flash [2]
+ at shift: variable shift operator useful for dual parallel
+ atpoll_cmd: find theread_statusorflag_statusfor polling erase/write operations + aterase_cmd: discovered erase command
+ atread_cmd: discovered read command
+ atwrite_cmd: discovered write command
+ atdummy_byte: readdummy_bytebased on readdummy_cycles.doc/SPI/README.sf-features new file +2
-0+ +dummy byte is determined based on the dummy cycles of a particularcommand. +Fast commands -
dummy_byte= dummy_cycles/8doc/SPI/README.sf-features new file +8
-0+I/O commands- dummy_byte = (dummy_cycles * no.of lines)/8 +For I/O commands except cmd[0] everything goes on no.of lines based on +particular command but in case of fast commands except data all go on +single line irrespective of command. + +4. Usage: + +In drivers/spi/*.c assign spi_slave {} with supported features throughmode. +Ex:
drivers/spi/ti_qspi.cdoc/SPI/README.sf-features new file +11
-0+ +struct ti_qspi_slave { + ................ + struct spi_slave slave; + .............. +} + +struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, + unsigned int max_hz, unsigned int mode) +{ + .........
doc/SPI/README.sf-features line 114
Quoted 10 lines
doc/SPI/README.sf-features new file +10
-0+ + qslave = spi_alloc_slave(struct ti_qspi_slave, bus, cs); + if (!qslave) { + printf("SPI_error: Fail to allocate ti_qspi_slave\n"); + return NULL; + } + + qslave->slave.mode = SPI_TX_QPP | SPI_RX_QUAD; + ........ +}
Sigh, looks like this document instructs people to abuse the SPI framework :-(
You need a BIG FAT WARNING that this was a design mistake here , really.
Quoted 11 lines
+[1] http://www.spansion.com/Support/Datasheets/S25FL128S_256S_00.pdf
+[2] doc/SPI/README.dual-flashdoc/SPI/README.sf-features new file +4
-0+ +-- +Jagannadha Sutradharudu Teki <[email protected]> +Sat Jan 18 14:44:28 IST 2014drivers/mtd/spi/sf.c +0
-0
drivers/mtd/spi/sf.c static int spi_flash_read_write(struct spi_slave *spi, · line 23
Quoted 7 lines
drivers/mtd/spi/sf.c +2
-2@@ -19,8 +19,8 @@ static int spi_flash_read_write(struct spi_slave *spi,int ret;#ifdef CONFIG_SF_DUAL_FLASH -if (spi->flags &SPI_XFER_U_PAGE ) - flags |=SPI_XFER_U_PAGE ; +if (spi->mode &SPI_U_PAGE ) + flags |=SPI_U_PAGE ;
This change makes no sense, really, you're renaming flag and that's pointless. Please remove this globally.
[...]
PATCH v4 3/5 sf: Use slave mode for dual_flash connection
In reply to a message not in the archiveSF uses mode from driver side for informing whether flash can operated in single or dual connections.
--- drivers/mtd/spi/sf_probe.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/mtd/spi/sf_probe.c +7 -2
@@ -123,7 +123,6 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi, flash->spi = spi; flash->name = params->name; flash->memory_map = spi->memory_map; - flash->dual_flash = flash->spi->option;/* Assign spi_flash ops */ flash->read = spi_flash_cmd_read_ops;
@@ -133,7 +132,13 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,if (params->flags &SST_WP ) flash->write = sst_write_wp;#endif - +/* Get the dual flash connection modes */ +#ifdef CONFIG_SF_DUAL_FLASH +if (flash->spi->mode &SPI_SHARED ) + flash->dual_flash =SF_DUAL_STACKED_FLASH ; +else if (flash->spi->mode &SPI_SEPARATED ) + flash->dual_flash =SF_DUAL_PARALLEL_FLASH ; +#endif /* Compute the flash size */ flash->shift = (flash->dual_flash &SF_DUAL_PARALLEL_FLASH ) ?1 :0 ; flash->page_size = ((ext_jedec ==0x4d00 ) ?512 :256 ) << flash->shift;
Signature · 1 line
1.8.3
PATCH v4 4/5 doc: SPI: Update the dual_flash info
In reply to a message not in the archiveUpdated the dual_flash documentation as it uses
mode from spi drivers to inform the sf framework.
--- doc/SPI/README.dual-flash | 5 +++-- doc/SPI/README.sf-features | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-)
doc/SPI/README.dual-flash +3 -2
@@ -9,7 +9,8 @@ to a given controller with single chip select line, but there are some hw logics(ex: xilinx zynq qspi) that describes two/dual memories are connected with a single chip select line from a controller. -"dual_flash" from include/spi.h describes these types of connection mode +"dual_flash" from include/spi_flash.h describes these types of connection mode +in spi flash side and "mode" options for controller driver. Possible connections: --------------------
@@ -54,7 +55,7 @@ SF_DUAL_STACKED_FLASH: by default, if U_PAGE is unset lower memory should accessible, once user wants to access upper memory need to set U_PAGE. -SPI_FLASH_CONN_DUALPARALLEL: +SF_DUAL_PARALLEL_FLASH: - dual spi/qspi flash memories are connected with a single chipselect line and these two memories are operating parallel with separate buses. - xilinx zynq qspi controller has implemented this feature [1]
doc/SPI/README.sf-features +3 -0
@@ -73,6 +73,9 @@ based on the selected flash features/operations from spi_slave {} and spi_flash_params {} - include/spi_flash.h @dual_flash: flash can be operated in dual flash [2] +- SF_SINGLE_FLASH: default connection single flash +- SF_DUAL_STACKED_FLASH: dual flash with dual stacked connection +- SF_DUAL_PARALLEL_FLASH: dual flash with dual parallel connection @shift: variable shift operator useful for dual parallel @poll_cmd: find the read_status or flag_status for polling erase/write operations @erase_cmd: discovered erase command
Signature · 1 line
1.8.3
PATCH v4 5/5 sf: Update bank configuration
In reply to a message not in the archiveUpdated bank configuration code to more readable.
--- drivers/mtd/spi/sf_probe.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/mtd/spi/sf_probe.c +11 -10
@@ -217,21 +217,22 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,/* Configure the BAR - discover bank cmds and read current bank */ #ifdef CONFIG_SPI_FLASH_BAR -u8 curr_bank =0 ;if (flash->size >SPI_FLASH_16MB_BOUN ) { - flash->bank_read_cmd = (idcode[0 ] ==0x01 ) ? -CMD_BANKADDR_BRRD :CMD_EXTNADDR_RDEAR ; - flash->bank_write_cmd = (idcode[0 ] ==0x01 ) ? -CMD_BANKADDR_BRWR :CMD_EXTNADDR_WREAR ; +switch (idcode[0 ]) { +case SPI_FLASH_CFI_MFR_SPANSION : + flash->bank_read_cmd =CMD_BANKADDR_BRRD ; + flash->bank_write_cmd =CMD_BANKADDR_BRWR ; +break ; +default : + flash->bank_read_cmd =CMD_EXTNADDR_RDEAR ; + flash->bank_write_cmd =CMD_EXTNADDR_WREAR ; + }if (spi_flash_read_common (flash, &flash->bank_read_cmd,1 , - &curr_bank,1 )) { -debug ("SF: fail to read bank addr register\n" ); + &flash->bank_curr,1 )) { +debug ("SF: Fail to read bank addr register\n" );return NULL ; } - flash->bank_curr = curr_bank; - }else { - flash->bank_curr = curr_bank; }#endif
Signature · 1 line
1.8.3