add driver for Atmel QSPI controller
Subsystems (5)
v4 cover add driver for Atmel QSPI controller
ChangeLog
v4:
- add "OF && HAS_DMA" dependency in Kconfig for Atmel Quad SPI driver.
- return -ENOMEM instead of the return code of dma_mapping_error() as this function returns a boolean on ARM achitecture.
- add "Acked-by: Nicolas Ferre <[email protected]>" for Atmel Quad SPI driver and its DT binding documentation.
v3:
- reword the comment which explains that spi_nor_set_protocol() is used by the spi-nor framework to notify lower layers, especially the (Q)SPI controller about a protocol change.
- change the definitions of register/bitfield macros in the Atmel QSPI controller driver: get rid of concatenation operator and use BIT and GENMASK macros when possible.
- use #define[SPACE] instead of #define[TAB]
v2:
- remove the patches to set the "latency code" of Spansion QSPI memories (support of Spansion memories may be submitted in later series).
- rename "qspi" node into "spi" in the DT example to fit ePAPR standard.
- remove the useless "qspi0" label from the DT node example.
- remove the leading 0 from the size of the second memory region to make it consistent with the size of the first memory region.
- indent the DT bindings documentation to make it more readable.
- remove the useless ".bus = &platform_bus_type," line from the
platform driver definition.
v1:
This series of patches add support for the new Atmel QSPI controller embedded inside sama5d2x SoCs.
These patches were first developped for linux-3.18-at91 and tested on a sama5d27 Xplained ultra board, which embeds a Micron n25q128a13 QSPI NOR flash memory. Then the series was adapted for mainline.
Cyrille Pitchen (5):
mtd: spi-nor: notify (Q)SPI controller about protocol change
Documentation: mtd: add a DT property to set the number of dummy
cycles
mtd: spi-nor: allow to tune the number of dummy cycles
Documentation: atmel-quadspi: add binding file for Atmel QSPI driver
mtd: atmel-quadspi: add driver for Atmel QSPI controller
.../devicetree/bindings/mtd/atmel-quadspi.txt | 29 + .../devicetree/bindings/mtd/jedec,spi-nor.txt | 6 + drivers/mtd/spi-nor/Kconfig | 7 + drivers/mtd/spi-nor/Makefile | 1 + drivers/mtd/spi-nor/atmel-quadspi.c | 876 +++++++++++++++++++++ drivers/mtd/spi-nor/spi-nor.c | 118 ++- include/linux/mtd/spi-nor.h | 15 + 7 files changed, 1033 insertions(+), 19 deletions(-) create mode 100644 Documentation/devicetree/bindings/mtd/atmel-quadspi.txt create mode 100644 drivers/mtd/spi-nor/atmel-quadspi.c
Signature · 1 line
1.8.2.2
PATCH v4 1/5 mtd: spi-nor: notify (Q)SPI controller about protocol change
Once the Quad SPI mode has been enabled on a Micron flash memory, this device expects ALL the following commands to use the SPI 4-4-4 protocol. The (Q)SPI controller needs to be notified about the protocol change so it can adapt and keep on dialoging with the Micron memory.
--- drivers/mtd/spi-nor/spi-nor.c | 21 +++++++++++++++++++++ include/linux/mtd/spi-nor.h | 13 +++++++++++++ 2 files changed, 34 insertions(+)
drivers/mtd/spi-nor/spi-nor.c +21 -0
@@ -163,6 +163,22 @@ static inline int write_disable(struct spi_nor *nor)return nor->write_reg (nor,SPINOR_OP_WRDI ,NULL ,0 ,0 ); } +/* +* Let the spi-nor framework notify lower layers, especially the driver of the +* (Q)SPI controller, about the new protocol to be used. Indeed, once the +* spi-nor framework has sent manufacturer specific commands to a memory to +* enable its Quad SPI mode, it should immediately after tell the QSPI +* controller to use the very same Quad SPI protocol as expected by the memory. +*/ +static inline int spi_nor_set_protocol (struct spi_nor *nor, +enum spi_protocol proto) +{ +if (nor->set_protocol) +return nor->set_protocol (nor, proto); + +return 0 ; +} +static inline struct spi_nor *mtd_to_spi_nor (struct mtd_info *mtd) {return mtd->priv;
@@ -944,6 +960,11 @@ static int micron_quad_enable(struct spi_nor *nor)return ret; } +/* switch protocol to Quad CMD 4-4-4 */ + ret =spi_nor_set_protocol (nor,SPI_PROTO_4_4_4 ); +if (ret) +return ret; + ret =spi_nor_wait_till_ready (nor);if (ret)return ret;
include/linux/mtd/spi-nor.h +13 -0
@@ -87,6 +87,16 @@ enum read_mode { SPI_NOR_QUAD, }; +enum spi_protocol { +SPI_PROTO_1_1_1 ,/* SPI */ +SPI_PROTO_1_1_2 ,/* Dual Output */ +SPI_PROTO_1_1_4 ,/* Quad Output */ +SPI_PROTO_1_2_2 ,/* Dual IO */ +SPI_PROTO_1_4_4 ,/* Quad IO */ +SPI_PROTO_2_2_2 ,/* Dual Command */ +SPI_PROTO_4_4_4 ,/* Quad Command */ +}; +/** * struct spi_nor_xfer_cfg - Structure for defining a Serial Flash transfer * @wren: command for "Write Enable", or 0x00 for not required
@@ -149,6 +159,7 @@ enum spi_nor_option_flags {* read/write/erase/lock/unlock operations * @read_xfer: [OPTIONAL] the read fundamental primitive * @write_xfer: [OPTIONAL] the writefundamental primitive +* @set_protocol: [OPTIONAL] notify about protocol change * @read_reg: [DRIVER-SPECIFIC] read out the register * @write_reg: [DRIVER-SPECIFIC] write data to the register * @read: [DRIVER-SPECIFIC] read data from the SPI NOR
@@ -185,6 +196,8 @@ struct spi_nor {int (*write_reg)(struct spi_nor *nor,u8 opcode,u8 *buf,int len,int write_enable); +int (*set_protocol)(struct spi_nor *nor,enum spi_protocol proto); +int (*read)(struct spi_nor *nor,loff_t from,size_t len,size_t *retlen,u_char *read_buf); void (*write)(struct spi_nor *nor, loff_t to,
Signature · 1 line
1.8.2.2
Re: [PATCH linux-next v4 1/5] mtd: spi-nor: notify (Q)SPI controller about protocol change
Quoted 6 lines · Cyrille Pitchen
Once the Quad SPI mode has been enabled on a Micron flash memory, this device expects ALL the following commands to use the SPI 4-4-4 protocol. The (Q)SPI controller needs to be notified about the protocol change so it can adapt and keep on dialoging with the Micron memory.
Signed-off-by Cyrille Pitchen <[email protected]>
Awesome,
If this could be applied separately (since I want to use the same functionality for the Cadence QSPI driver), I'd be really happy too :)
Best regards,
Marek Vasut
PATCH v4 2/5 Documentation: mtd: add a DT property to set the number of dummy cycles
In reply to Cyrille PitchenDepending on the SPI clock frequency, the Fast Read op code and the Single/Dual Data Rate mode, the number of dummy cycles can be tuned to improve transfer speed.
The actual number of dummy cycles is specific for each memory model and is provided by the manufacturer thanks to the memory datasheet.
--- Documentation/devicetree/bindings/mtd/jedec,spi-nor.txt | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/mtd/jedec,spi-nor.txt +6 -0
@@ -19,6 +19,11 @@ Optional properties: all chips and support for it can not be detected at runtime. Refer to your chips' datasheet to check if this is supported by your chip. +- m25p,num-dummy-cycles : Set the number of dummy cycles for Fast Read commands. + Depending on the manufacturer additional dedicated + commands are sent to the flash memory so the + controller and the memory can agree on the number of + dummy cycles to use. Example:
@@ -29,4 +34,5 @@ Example: reg = <0>; spi-max-frequency = <40000000>; m25p,fast-read; + m25p,num-dummy-cycles = <8>; };
Signature · 1 line
1.8.2.2
PATCH v4 3/5 mtd: spi-nor: allow to tune the number of dummy cycles
In reply to Cyrille PitchenThe number of dummy cycles used during Fast Read commands can be reduced to improve transfer performances. Each manufacturer has a dedicated set of registers to provide the memory with the exact number of dummy cycles it should expect. Both the memory and the (Q)SPI controller must agree on this number of dummy cycles.
The number of dummy cycles can be found into the memory datasheet and mostly depends on the SPI clock frequency, the Fast Read op code and the Single/Dual Data Rate mode.
Probing JEDEC Serial Flash Discoverable Parameters (SFDP) tables would only provide the driver with a high enough number of dummy cycles for each Fast Read command to be used for all clock frequencies: this solution would not be optimized.
--- drivers/mtd/spi-nor/spi-nor.c | 97 ++++++++++++++++++++++++++++++++++--------- include/linux/mtd/spi-nor.h | 2 + 2 files changed, 80 insertions(+), 19 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +78 -19
@@ -119,24 +119,6 @@ static int read_cr(struct spi_nor *nor) }/* -* Dummy Cycle calculation for different type of read. -* It can be used to support more commands with -* different dummy cycle requirements. -*/ -static inline int spi_nor_read_dummy_cycles (struct spi_nor *nor) -{ -switch (nor->flash_read) { -case SPI_NOR_FAST : -case SPI_NOR_DUAL : -case SPI_NOR_QUAD : -return 8 ; -case SPI_NOR_NORMAL : -return 0 ; - } -return 0 ; -} - -/* * Write status register 1 byte * Returns negative if error occurred. */
@@ -1012,6 +994,81 @@ static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) } } +static int micron_set_dummy_cycles (struct spi_nor *nor) +{ +int ret; +u8 val, mask; + +/* read the Volatile Configuration Register (VCR) */ + ret = nor->read_reg (nor,SPINOR_OP_RD_VCR , &val,1 ); +if (ret <0 ) { +dev_err (nor->dev,"error %d reading VCR\n" , ret); +return ret; + } + +write_enable (nor); + +/* update the number of dummy into the VCR */ + mask =GENMASK (7 ,4 ); + val &= ~mask; + val |= (nor->read_dummy <<4 ) & mask; + ret = nor->write_reg (nor,SPINOR_OP_WR_VCR , &val,1 ,0 ); +if (ret <0 ) { +dev_err (nor->dev,"error while writing VCR register\n" ); +return ret; + } + + ret =spi_nor_wait_till_ready (nor); +if (ret) +return ret; + +return 0 ; +} + +/* +* Dummy Cycle calculation for different type of read. +* It can be used to support more commands with +* different dummy cycle requirements. +*/ +static int spi_nor_read_dummy_cycles (struct spi_nor *nor, +const struct flash_info *info) +{ +struct device_node *np = nor->dev->of_node; +u32 num_dummy_cycles; + +if (np && !of_property_read_u32 (np,"m25p,num-dummy-cycles" , + &num_dummy_cycles)) { + nor->read_dummy = num_dummy_cycles; + +/* +* This switch block might be moved after the if...then...else +* statement but it was not tested with all Spansion or Micron +* memories. +* Now the "m25p,num-dummy-cycles" property needs to be +* explicitly set in the device tree so the switch statement is +* executed. This should avoid unwanted side effects and keep +* backward compatibility. +*/ +switch (JEDEC_MFR (info)) { +case CFI_MFR_ST : +return micron_set_dummy_cycles (nor); +default : +break ; + } + }else { +switch (nor->flash_read) { +case SPI_NOR_FAST : +case SPI_NOR_DUAL : +case SPI_NOR_QUAD : + nor->read_dummy =8 ; +case SPI_NOR_NORMAL : + nor->read_dummy =0 ; + } + } + +return 0 ; +} +static int spi_nor_check (struct spi_nor *nor) { if (!nor->dev || !nor->read || !nor->write ||
@@ -1216,7 +1273,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) nor->addr_width =3 ; } - nor->read_dummy =spi_nor_read_dummy_cycles (nor); + ret =spi_nor_read_dummy_cycles (nor, info); +if (ret) +return ret;dev_info (dev,"%s (%lld Kbytes)\n" , id->name, (long long )mtd->size >>10 );
include/linux/mtd/spi-nor.h +2 -0
@@ -59,6 +59,8 @@/* Used for Micron flashes only. */ #define SPINOR_OP_RD_EVCR 0x65/* Read EVCR register */ #define SPINOR_OP_WD_EVCR 0x61/* Write EVCR register */ +#define SPINOR_OP_RD_VCR 0x85/* Read VCR register */ +#define SPINOR_OP_WR_VCR 0x81/* Write VCR register */ /* Status Register bits. */ #define SR_WIP 1/* Write in progress */
Signature · 1 line
1.8.2.2
Re: [PATCH linux-next v4 3/5] mtd: spi-nor: allow to tune the number of dummy cycles
Quoted 10 lines · Cyrille Pitchen
The number of dummy cycles used during Fast Read commands can be reduced to improve transfer performances. Each manufacturer has a dedicated set of registers to provide the memory with the exact number of dummy cycles it should expect. Both the memory and the (Q)SPI controller must agree on this number of dummy cycles.
The number of dummy cycles can be found into the memory datasheet and mostly depends on the SPI clock frequency, the Fast Read op code and the Single/Dual Data Rate mode.
Quoted 6 lines
Probing JEDEC Serial Flash Discoverable Parameters (SFDP) tables would only provide the driver with a high enough number of dummy cycles for each Fast Read command to be used for all clock frequencies: this solution would not be optimized.
Signed-off-by Cyrille Pitchen <[email protected]>
Hi!
Quoted 19 lines
drivers/mtd/spi-nor/spi-nor.c | 97 ++++++++++++++++++++++++++++++++++--------- include/linux/mtd/spi-nor.h | 2 + 2 files changed, 80 insertions(+), 19 deletions(-)drivers/mtd/spi-nor/spi-nor.c +0
-6@@ -119,24 +119,6 @@ static int read_cr(struct spi_nor *nor) }/* -* Dummy Cycle calculation for different type of read. -* It can be used to support more commands with -* different dummy cycle requirements. -*/ -static inline int spi_nor_read_dummy_cycles (struct spi_nor *nor) -{
drivers/mtd/spi-nor/spi-nor.c static int read_cr(struct spi_nor *nor) · line 137
Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +0
-10-switch (nor->flash_read) { -case SPI_NOR_FAST : -case SPI_NOR_DUAL : -case SPI_NOR_QUAD : -return 8 ; -case SPI_NOR_NORMAL : -return 0 ; - } -return 0 ; -}
You can probably just soup up this function so that it sets the nor->read_dummy, no ?
Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +0
-1-/* * Write status register 1 byte * Returns negative if error occurred. */
drivers/mtd/spi-nor/spi-nor.c static int set_quad_mode(struct spi_nor *nor, struct · line 1002
Quoted 9 lines
drivers/mtd/spi-nor/spi-nor.c +6
-0@@ -1012,6 +994,81 @@ static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) } } +static int micron_set_dummy_cycles (struct spi_nor *nor) +{ +int ret; +u8 val, mask; + +/* read the Volatile Configuration Register (VCR) */
NIT: If this is a sentence, start it with capital letter and end it with fullstop :)
drivers/mtd/spi-nor/spi-nor.c static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) · line 1011
Quoted 9 lines
drivers/mtd/spi-nor/spi-nor.c +9
-0+ ret = nor->read_reg (nor,SPINOR_OP_RD_VCR , &val,1 ); +if (ret <0 ) { +dev_err (nor->dev,"error %d reading VCR\n" , ret); +return ret; + } + +write_enable (nor); + +/* update the number of dummy into the VCR */
DTTO
Quoted 34 lines
drivers/mtd/spi-nor/spi-nor.c +34
-0+ mask =GENMASK (7 ,4 ); + val &= ~mask; + val |= (nor->read_dummy <<4 ) & mask; + ret = nor->write_reg (nor,SPINOR_OP_WR_VCR , &val,1 ,0 ); +if (ret <0 ) { +dev_err (nor->dev,"error while writing VCR register\n" ); +return ret; + } + + ret =spi_nor_wait_till_ready (nor); +if (ret) +return ret; + +return 0 ; +} + +/* +* Dummy Cycle calculation for different type of read. +* It can be used to support more commands with +* different dummy cycle requirements. +*/ +static int spi_nor_read_dummy_cycles (struct spi_nor *nor, +const struct flash_info *info) +{ +struct device_node *np = nor->dev->of_node; +u32 num_dummy_cycles; + +if (np && !of_property_read_u32 (np,"m25p,num-dummy-cycles" , + &num_dummy_cycles)) { + nor->read_dummy = num_dummy_cycles; + +/* +* This switch block might be moved after the if...then...else +* statement but it was not tested with all Spansion or Micron
drivers/mtd/spi-nor/spi-nor.c static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) · line 1055
Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +10
-0+* memories. +* Now the "m25p,num-dummy-cycles" property needs to be +* explicitly set in the device tree so the switch statement is +* executed. This should avoid unwanted side effects and keep +* backward compatibility. +*/ +switch (JEDEC_MFR (info)) { +case CFI_MFR_ST : +return micron_set_dummy_cycles (nor); +default :
If you do have m25p,num-dummy-cycles set for non-micron flash, you have a problem here I believe.
drivers/mtd/spi-nor/spi-nor.c static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) · line 1058
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +3
-0+break ; + } + }else {
The solution would be to drop this else {} bit here, so that if you fail in the DT-based configuration, you fall back to this old behavior. What do you think please ? :)
Quoted 12 lines
drivers/mtd/spi-nor/spi-nor.c +12
-0+switch (nor->flash_read) { +case SPI_NOR_FAST : +case SPI_NOR_DUAL : +case SPI_NOR_QUAD : + nor->read_dummy =8 ; +case SPI_NOR_NORMAL : + nor->read_dummy =0 ; + } + } + +return 0 ; +}
[...]
Re: [PATCH linux-next v4 3/5] mtd: spi-nor: allow to tune the number of dummy cycles
Hi Marek,
Le 24/08/2015 12:48, Marek Vasut a ?crit :
Quoted 44 lines · Cyrille Pitchen
Quoted 10 lines
The number of dummy cycles used during Fast Read commands can be reduced to improve transfer performances. Each manufacturer has a dedicated set of registers to provide the memory with the exact number of dummy cycles it should expect. Both the memory and the (Q)SPI controller must agree on this number of dummy cycles.
The number of dummy cycles can be found into the memory datasheet and mostly depends on the SPI clock frequency, the Fast Read op code and the Single/Dual Data Rate mode.
Quoted 6 lines
Probing JEDEC Serial Flash Discoverable Parameters (SFDP) tables would only provide the driver with a high enough number of dummy cycles for each Fast Read command to be used for all clock frequencies: this solution would not be optimized.
Signed-off-by Cyrille Pitchen <[email protected]>Hi!
Quoted 24 lines
drivers/mtd/spi-nor/spi-nor.c | 97 ++++++++++++++++++++++++++++++++++--------- include/linux/mtd/spi-nor.h | 2 + 2 files changed, 80 insertions(+), 19 deletions(-)drivers/mtd/spi-nor/spi-nor.c +0
-11@@ -119,24 +119,6 @@ static int read_cr(struct spi_nor *nor) }/* -* Dummy Cycle calculation for different type of read. -* It can be used to support more commands with -* different dummy cycle requirements. -*/ -static inline int spi_nor_read_dummy_cycles (struct spi_nor *nor) -{ -switch (nor->flash_read) { -case SPI_NOR_FAST : -case SPI_NOR_DUAL : -case SPI_NOR_QUAD : -return 8 ;
Quoted 9 lines
drivers/mtd/spi-nor/spi-nor.c static int read_cr(struct spi_nor *nor) · line 137
Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +0
-5-case SPI_NOR_NORMAL : -return 0 ; - } -return 0 ; -}You can probably just soup up this function so that it sets the
nor->read_dummy, no ?
Actually, this is what the patch does: spi_nor_read_dummy_cycles() was reused and enhanced few lines below where you've pointed out the
"switch (nor->flash_read)" block should be move after the else block.
I think when I wrote the code I've chosen to move the definition of this function instead of adding forward declarations of functions such as read_cr() or write_sr_cr(), which are now called by micron_set_dummy_cycles().
Quoted 8 lines
Quoted 8 lines
drivers/mtd/spi-nor/spi-nor.c +0
-1-/* * Write status register 1 byte * Returns negative if error occurred. */ @@ -1012,6 +994,81 @@ static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) } }
Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) · line 1002
Quoted 6 lines
drivers/mtd/spi-nor/spi-nor.c +6
-0+static int micron_set_dummy_cycles (struct spi_nor *nor) +{ +int ret; +u8 val, mask; + +/* read the Volatile Configuration Register (VCR) */ NIT: If this is a sentence, start it with capital letter and end it with fullstop :)
done for the next version
Quoted 12 lines
drivers/mtd/spi-nor/spi-nor.c static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) · line 1011
Quoted 9 lines
drivers/mtd/spi-nor/spi-nor.c +9
-0+ ret = nor->read_reg (nor,SPINOR_OP_RD_VCR , &val,1 ); +if (ret <0 ) { +dev_err (nor->dev,"error %d reading VCR\n" , ret); +return ret; + } + +write_enable (nor); + +/* update the number of dummy into the VCR */ DTTO
done for the next version
Quoted 48 lines
Quoted 34 lines
drivers/mtd/spi-nor/spi-nor.c +34
-0+ mask =GENMASK (7 ,4 ); + val &= ~mask; + val |= (nor->read_dummy <<4 ) & mask; + ret = nor->write_reg (nor,SPINOR_OP_WR_VCR , &val,1 ,0 ); +if (ret <0 ) { +dev_err (nor->dev,"error while writing VCR register\n" ); +return ret; + } + + ret =spi_nor_wait_till_ready (nor); +if (ret) +return ret; + +return 0 ; +} + +/* +* Dummy Cycle calculation for different type of read. +* It can be used to support more commands with +* different dummy cycle requirements. +*/ +static int spi_nor_read_dummy_cycles (struct spi_nor *nor, +const struct flash_info *info) +{ +struct device_node *np = nor->dev->of_node; +u32 num_dummy_cycles; + +if (np && !of_property_read_u32 (np,"m25p,num-dummy-cycles" , + &num_dummy_cycles)) { + nor->read_dummy = num_dummy_cycles; + +/* +* This switch block might be moved after the if...then...else +* statement but it was not tested with all Spansion or Micron drivers/mtd/spi-nor/spi-nor.c static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) · line 1055
Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +10
-0+* memories. +* Now the "m25p,num-dummy-cycles" property needs to be +* explicitly set in the device tree so the switch statement is +* executed. This should avoid unwanted side effects and keep +* backward compatibility. +*/ +switch (JEDEC_MFR (info)) { +case CFI_MFR_ST : +return micron_set_dummy_cycles (nor); +default :If you do have m25p,num-dummy-cycles set for non-micron flash, you have a problem here I believe.
Quoted 8 lines
drivers/mtd/spi-nor/spi-nor.c static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) · line 1058
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +3
-0+break ; + } + }else {The solution would be to drop this else {} bit here, so that if you fail in the DT-based configuration, you fall back to this old behavior. What do you think please ? :)
Good idea!
I also add a trace for the default case of "switch (JEDEC_MFR(info))":
dev_warn(dev, "can't set the number of dummy cycles\n");
So the user is notified that the driver could not use the value of "m25p,num-dummy-cycles" from the DT before falling back to the legacy code.
Quoted 6 lines
Quoted 6 lines
drivers/mtd/spi-nor/spi-nor.c +6
-0+switch (nor->flash_read) { +case SPI_NOR_FAST : +case SPI_NOR_DUAL : +case SPI_NOR_QUAD : + nor->read_dummy =8 ; +case SPI_NOR_NORMAL :
Quoted 9 lines
Quoted 6 lines
drivers/mtd/spi-nor/spi-nor.c +6
-0+ nor->read_dummy =0 ; + } + } + +return 0 ; +}[...]
thanks for the review!
Best regards,
Cyrille
Re: [PATCH linux-next v4 3/5] mtd: spi-nor: allow to tune the number of dummy cycles
Quoted 1 line · Cyrille Pitchen
Hi Marek,
Hi!
[...]
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
- * Dummy Cycle calculation for different type of read.
- * It can be used to support more commands with
- * different dummy cycle requirements.
- */drivers/mtd/spi-nor/spi-nor.c +0
-7-static inline int spi_nor_read_dummy_cycles (struct spi_nor *nor) -{ -switch (nor->flash_read) { -case SPI_NOR_FAST : -case SPI_NOR_DUAL : -case SPI_NOR_QUAD : -return 8 ;Quoted 8 lines
drivers/mtd/spi-nor/spi-nor.c static int read_cr(struct spi_nor *nor) · line 137
Quoted 5 lines
drivers/mtd/spi-nor/spi-nor.c +0
-5-case SPI_NOR_NORMAL : -return 0 ; - } -return 0 ; -}You can probably just soup up this function so that it sets the
nor->read_dummy, no ?
Quoted 3 lines
Actually, this is what the patch does:
spi_nor_read_dummy_cycles()was reused and enhanced few lines below where you've pointed out the "switch (nor->flash_read)" block should be move after the else block.
You know what? I'll go get some sleep, coffee doesn't cut it anymore :)
Quoted 4 lines
I think when I wrote the code I've chosen to move the definition of this function instead of adding forward declarations of functions such as
read_cr()orwrite_sr_cr(), which are now called bymicron_set_dummy_cycles().
Yep, that's all right, sorry for the confusion.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +0
-1-/* * Write status register 1 byte * Returns negative if error occurred. */ @@ -1012,6 +994,81 @@ static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) } }
[...]
Quoted 40 lines
Quoted 32 lines
Quoted 19 lines
drivers/mtd/spi-nor/spi-nor.c +19
-0+/* +* Dummy Cycle calculation for different type of read. +* It can be used to support more commands with +* different dummy cycle requirements. +*/ +static int spi_nor_read_dummy_cycles (struct spi_nor *nor, +const struct flash_info *info) +{ +struct device_node *np = nor->dev->of_node; +u32 num_dummy_cycles; + +if (np && !of_property_read_u32 (np,"m25p,num-dummy-cycles" , + &num_dummy_cycles)) { + nor->read_dummy = num_dummy_cycles; + +/* +* This switch block might be moved after the if...then...else +* statement but it was not tested with all Spansion or Micron +* memories. drivers/mtd/spi-nor/spi-nor.c static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) · line 1055
Quoted 10 lines
drivers/mtd/spi-nor/spi-nor.c +9
-0+* Now the "m25p,num-dummy-cycles" property needs to be +* explicitly set in the device tree so the switch statement is +* executed. This should avoid unwanted side effects and keep +* backward compatibility. +*/ +switch (JEDEC_MFR (info)) { +case CFI_MFR_ST : +return micron_set_dummy_cycles (nor); +default :If you do have m25p,num-dummy-cycles set for non-micron flash, you have a problem here I believe.
Quoted 7 lines
drivers/mtd/spi-nor/spi-nor.c static int set_quad_mode(struct spi_nor *nor, struct flash_info *info) · line 1058
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +3
-0+break ; + } + }else {The solution would be to drop this else {} bit here, so that if you fail in the DT-based configuration, you fall back to this old behavior. What do you think please ? :)
Quoted 4 lines
Good idea!
I also add a trace for the default case of "switch (JEDEC_MFR(info))":
dev_warn(dev, "can't set the number of dummy cycles\n");
Maybe change this to "setting the number of dummy cycles not supported by chip, ignoring" or something, to be explicit about the fallback and that this is not supported by the chip. But this is just an idea, feel free to ignore it.
Quoted 3 lines
So the user is notified that the driver could not use the value of "m25p,num-dummy-cycles" from the DT before falling back to the legacy code.
Yup.
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/mtd/spi-nor/spi-nor.c +6
-0+switch (nor->flash_read) { +case SPI_NOR_FAST : +case SPI_NOR_DUAL : +case SPI_NOR_QUAD : + nor->read_dummy =8 ; +case SPI_NOR_NORMAL :Quoted 8 lines
Quoted 6 lines
drivers/mtd/spi-nor/spi-nor.c +6
-0+ nor->read_dummy =0 ; + } + } + +return 0 ; +}[...]
Quoted 1 line
thanks for the review!
Im glad it helped ;-)
PATCH v4 4/5 Documentation: atmel-quadspi: add binding file for Atmel QSPI driver
In reply to Cyrille PitchenThis patch documents the DT bindings for the driver of the Atmel QSPI controller embedded inside sama5d2x SoCs.
--- .../devicetree/bindings/mtd/atmel-quadspi.txt | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/atmel-quadspi.txt
Documentation/devicetree/bindings/mtd/atmel-quadspi.txt new file +29 -0
@@ -0,0 +1,29 @@ +* Atmel Quad Serial Peripheral Interface (QSPI) + +Required properties: +- compatible: should be "atmel,sama5d2-qspi" +- reg: the first contains the register location and length, + the second contains the memory mapping address and length +- interrupts: should contain the interrupt for the device +- clocks: the phandle of the clock needed by the QSPI controller +- #address-cells: should be <1> +- #size-cells: should be <0> + +Example: + +spi at f0020000 { + compatible = "atmel,sama5d2-qspi"; + reg = <0xf0020000 0x100>, + <0xd0000000 0x8000000>; + interrupts = <52 IRQ_TYPE_LEVEL_HIGH 7>; + clocks = <&spi0_clk>; + #address-cells = <1>; + #size-cells = <0>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_spi0_default>; + status = "okay"; + + m25p80 at 0 { + ... + }; +};
Signature · 1 line
1.8.2.2
Re: [PATCH linux-next v4 4/5] Documentation: atmel-quadspi: add binding file for Atmel QSPI driver
Quoted 5 lines · Cyrille Pitchen
This patch documents the DT bindings for the driver of the Atmel QSPI controller embedded inside sama5d2x SoCs.
Signed-off-by Cyrille Pitchen <[email protected]>Acked-by Nicolas Ferre <[email protected]>
If my ack has any value in here, feel free to add it, the bindings look pretty standard anyway:
Best regards,
Marek Vasut
PATCH v4 5/5 mtd: atmel-quadspi: add driver for Atmel QSPI controller
In reply to Cyrille PitchenThis driver add support to the new Atmel QSPI controller embedded into sama5d2x SoCs. It expects a NOR memory to be connected to the QSPI controller.
--- drivers/mtd/spi-nor/Kconfig | 7 + drivers/mtd/spi-nor/Makefile | 1 + drivers/mtd/spi-nor/atmel-quadspi.c | 876 ++++++++++++++++++++++++++++++++++++ 3 files changed, 884 insertions(+) create mode 100644 drivers/mtd/spi-nor/atmel-quadspi.c
drivers/mtd/spi-nor/Kconfig +7 -0
@@ -29,6 +29,13 @@ config SPI_FSL_QUADSPI This controller does not support generic SPI. It only supports SPI NOR. +config SPI_ATMEL_QUADSPI + tristate "Atmel Quad SPI Controller" + depends on OF && HAS_DMA && (ARCH_AT91 || COMPILE_TEST) + help + This enables support for the Quad SPI controller in master mode. + We only connect the NOR to this controller now. + config SPI_NXP_SPIFI tristate "NXP SPI Flash Interface (SPIFI)" depends on OF && (ARCH_LPC18XX || COMPILE_TEST)
drivers/mtd/spi-nor/Makefile +1 -0
@@ -1,3 +1,4 @@ obj-$(CONFIG_MTD_SPI_NOR) += spi-nor.o obj-$(CONFIG_SPI_FSL_QUADSPI) += fsl-quadspi.o +obj-$(CONFIG_SPI_ATMEL_QUADSPI) += atmel-quadspi.o obj-$(CONFIG_SPI_NXP_SPIFI) += nxp-spifi.o
drivers/mtd/spi-nor/atmel-quadspi.c new file +876 -0
876 lines not on this page · raw message
Signature · 1 line
1.8.2.2
Re: [PATCH linux-next v4 5/5] mtd: atmel-quadspi: add driver for Atmel QSPI controller
Quoted 6 lines · Cyrille Pitchen
This driver add support to the new Atmel QSPI controller embedded into sama5d2x SoCs. It expects a NOR memory to be connected to the QSPI controller.
Signed-off-by Cyrille Pitchen <[email protected]>Acked-by Nicolas Ferre <[email protected]>
Hi,
[...]
Quoted 1 line
+/* Register access macros */
These are functions, not macros :)
btw is there any reason for these ? I'd say, just put the read*() and write*() functions directly into the code and be done with it, it is much less confusing.
Also, why do you use the _relaxed() versions of the functions ?
Quoted 29 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +29
-0+static inline u32 qspi_readl (struct atmel_qspi *aq,u32 reg) +{ +return readl_relaxed (aq->regs + reg); +} + +static inline void qspi_writel (struct atmel_qspi *aq,u32 reg,u32 value) +{ +writel_relaxed (value, aq->regs + reg); +} + +static inline u16 qspi_readw (struct atmel_qspi *aq,u32 reg) +{ +return readw_relaxed (aq->regs + reg); +} + +static inline void qspi_writew (struct atmel_qspi *aq,u32 reg,u16 value) +{ +writew_relaxed (value, aq->regs + reg); +} + +static inline u8 qspi_readb (struct atmel_qspi *aq,u32 reg) +{ +return readb_relaxed (aq->regs + reg); +} + +static inline void qspi_writeb (struct atmel_qspi *aq,u32 reg,u8 value) +{ +writeb_relaxed (value, aq->regs + reg); +}
[...]
Quoted 11 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +11
-0+static int atmel_qspi_run_command (struct atmel_qspi *aq, +const struct atmel_qspi_command *cmd) +{ +u32 iar, icr, ifr, sr; +int err =0 ; + + iar =0 ; + icr =0 ; + ifr = aq->ifr_width | cmd->ifr_tfrtyp; + +/* Compute instruction parameters */
drivers/mtd/spi-nor/atmel-quadspi.c line 407
Quoted 10 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +10
-0+if (cmd->enable.bits.instruction) { + icr |=QSPI_ICR_INST (cmd->instruction); + ifr |=QSPI_IFR_INSTEN ; + } + +/* Compute address parameters */ +switch (cmd->enable.bits.address) { +case 4 : + ifr |=QSPI_IFR_ADDRL ; +/*break;*/ /* fallback to the 24bit address case */
What's this commented out bit of code for ? :-)
Quoted 9 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +9
-0+case 3 : + iar = (cmd->enable.bits.data) ?0 : cmd->address; + ifr |=QSPI_IFR_ADDREN ; +break ; +case 0 : +break ; +default : +return -EINVAL ; + }
[...]
drivers/mtd/spi-nor/atmel-quadspi.c line 520
Quoted 8 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +8
-0+no_data: +/* Poll INSTRuction End status */ + sr =qspi_readl (aq,QSPI_SR ); +if (sr &QSPI_SR_INSTRE ) +return err; + +/* Wait for INSTRuction End interrupt */ +init_completion (&aq->completion);
You should use reinit_completion() in the code. init_completion() should be used only in the probe() function and nowhere else.
drivers/mtd/spi-nor/atmel-quadspi.c line 529
Quoted 9 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +9
-0+ aq->pending =0 ; +qspi_writel (aq,QSPI_IER ,QSPI_SR_INSTRE ); +if (!wait_for_completion_timeout (&aq->completion, +msecs_to_jiffies (1000 ))) + err = -ETIMEDOUT ; +qspi_writel (aq,QSPI_IDR ,QSPI_SR_INSTRE ); + +return err; +}
[...]
Hope this helps :)
Re: [PATCH linux-next v4 5/5] mtd: atmel-quadspi: add driver for Atmel QSPI controller
Quoted 7 lines · Marek Vasut
These are functions, not macros :)
btw is there any reason for these ? I'd say, just put the read*() and write*() functions directly into the code and be done with it, it is much less confusing.
Also, why do you use the
_relaxed()versions of the functions ?
Now that the _relaxed() accessors are available throughout the kernel, everyone should be using the _relaxed() versions unless they need the properties of the non-relaxed versions. Remember that the non-relaxed versions are rather expensive on ARM due to the need to go all the way out to the L2 cache - it at least doubles the number of accesses for every read*/write*().
Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up according to speedtest.net.
Re: [PATCH linux-next v4 5/5] mtd: atmel-quadspi: add driver for Atmel QSPI controller
On Monday, August 24, 2015 at 02:49:24 PM, Russell King - ARM Linux wrote:
Hi Russell,
Quoted 7 lines · Marek Vasut
Quoted 6 lines
These are functions, not macros :)
btw is there any reason for these ? I'd say, just put the read*() and write*() functions directly into the code and be done with it, it is much less confusing.
Quoted 5 lines
Quoted 1 line
Also, why do you use the
_relaxed()versions of the functions ?Now that the
_relaxed()accessors are available throughout the kernel, everyone should be using the_relaxed()versions unless they need the properties of the non-relaxed versions.
You mean the memory barrier, right ?
Quoted 4 lines
Remember that the non-relaxed
versions are rather expensive on ARM due to the need to go all the way out to the L2 cache - it at least doubles the number of accesses for every read*/write*().
I think in case of this driver, we don't need the non-relaxed version anywhere, right ? Thanks for the educational writeup :)
btw. is [1] still the current study material on the I/O accessor best practices please ?
[1] http://permalink.gmane.org/gmane.linux.ports.arm.kernel/117644
Best regards,
Marek Vasut
Re: [PATCH linux-next v4 5/5] mtd: atmel-quadspi: add driver for Atmel QSPI controller
In reply to Marek VasutHi Marek,
Le 24/08/2015 13:03, Marek Vasut a ?crit :
Quoted 69 lines · Cyrille Pitchen
Quoted 6 lines
This driver add support to the new Atmel QSPI controller embedded into sama5d2x SoCs. It expects a NOR memory to be connected to the QSPI controller.
Signed-off-by Cyrille Pitchen <[email protected]>Acked-by Nicolas Ferre <[email protected]>Hi,
[...]
Quoted 1 line
+/* Register access macros */
These are functions, not macros :)
btw is there any reason for these ? I'd say, just put the read*() and write*() functions directly into the code and be done with it, it is much less confusing.
Also, why do you use the
_relaxed()versions of the functions ?Quoted 29 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +29
-0+static inline u32 qspi_readl (struct atmel_qspi *aq,u32 reg) +{ +return readl_relaxed (aq->regs + reg); +} + +static inline void qspi_writel (struct atmel_qspi *aq,u32 reg,u32 value) +{ +writel_relaxed (value, aq->regs + reg); +} + +static inline u16 qspi_readw (struct atmel_qspi *aq,u32 reg) +{ +return readw_relaxed (aq->regs + reg); +} + +static inline void qspi_writew (struct atmel_qspi *aq,u32 reg,u16 value) +{ +writew_relaxed (value, aq->regs + reg); +} + +static inline u8 qspi_readb (struct atmel_qspi *aq,u32 reg) +{ +return readb_relaxed (aq->regs + reg); +} + +static inline void qspi_writeb (struct atmel_qspi *aq,u32 reg,u8 value) +{ +writeb_relaxed (value, aq->regs + reg); +}[...]
Quoted 15 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +15
-0+static int atmel_qspi_run_command (struct atmel_qspi *aq, +const struct atmel_qspi_command *cmd) +{ +u32 iar, icr, ifr, sr; +int err =0 ; + + iar =0 ; + icr =0 ; + ifr = aq->ifr_width | cmd->ifr_tfrtyp; + +/* Compute instruction parameters */ +if (cmd->enable.bits.instruction) { + icr |=QSPI_ICR_INST (cmd->instruction); + ifr |=QSPI_IFR_INSTEN ; + }
Quoted 8 lines
drivers/mtd/spi-nor/atmel-quadspi.c line 407
Quoted 6 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +6
-0+ +/* Compute address parameters */ +switch (cmd->enable.bits.address) { +case 4 : + ifr |=QSPI_IFR_ADDRL ; +/*break;*/ /* fallback to the 24bit address case */ What's this commented out bit of code for ? :-)
I just wanted to stress out there was no missing "break;". I've reworded the comment to:
/* No "break" on purpose: fallback to the 24bit address case. */
Quoted 13 lines
Quoted 10 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +9
-0+case 3 : + iar = (cmd->enable.bits.data) ?0 : cmd->address; + ifr |=QSPI_IFR_ADDREN ; +break ; +case 0 : +break ; +default : +return -EINVAL ; + }[...]
Quoted 11 lines
drivers/mtd/spi-nor/atmel-quadspi.c line 520
Quoted 8 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +8
-0+no_data: +/* Poll INSTRuction End status */ + sr =qspi_readl (aq,QSPI_SR ); +if (sr &QSPI_SR_INSTRE ) +return err; + +/* Wait for INSTRuction End interrupt */ +init_completion (&aq->completion);You should use
reinit_completion()in the code.init_completion()should be used only in theprobe()function and nowhere else.
Alright. In the next version I'll rename the "completion" member of struct atmel_qspi into "cmd_completion". Also I'll add another dma_completion member in this very same structure to replace the local
"struct completion completion" in atmel_qspi_run_dma_transfer().
Then I'll call init_completion() on both cmd_completion and dma_completion only from atmel_qspi_probe() and reinit_completion() elsewhere.
Quoted 13 lines
Quoted 10 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +9
-0+ aq->pending =0 ; +qspi_writel (aq,QSPI_IER ,QSPI_SR_INSTRE ); +if (!wait_for_completion_timeout (&aq->completion, +msecs_to_jiffies (1000 ))) + err = -ETIMEDOUT ; +qspi_writel (aq,QSPI_IDR ,QSPI_SR_INSTRE ); + +return err; +}[...]
Quoted 2 lines
Hope this helps :)
Indeed, it does! I still work on the next version of this series to take all your comments into account.
Best regards,
Cyrille
Re: [PATCH linux-next v4 5/5] mtd: atmel-quadspi: add driver for Atmel QSPI controller
Quoted 1 line · Cyrille Pitchen
Hi Marek,
Hi!
Quoted 5 lines
Le 24/08/2015 13:03, Marek Vasut a ?crit :
Quoted 4 lines · Cyrille Pitchen
Quoted 3 lines
This driver add support to the new Atmel QSPI controller embedded into sama5d2x SoCs. It expects a NOR memory to be connected to the QSPI controller.
[...]
Quoted 11 lines
Quoted 7 lines
drivers/mtd/spi-nor/atmel-quadspi.c line 407
Quoted 5 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +5
-0+/* Compute address parameters */ +switch (cmd->enable.bits.address) { +case 4 : + ifr |=QSPI_IFR_ADDRL ; +/*break;*/ /* fallback to the 24bit address case */ What's this commented out bit of code for ? :-)
I just wanted to stress out there was no missing "break;". I've reworded the comment to:
/* No "break" on purpose: fallback to the 24bit address case. */
Oh, the address is in bytes . I see, yes, it makes sense to be more explicit here about the purpose of the fallback. I think this change in the comment will make it easier for everyone who comes back in a few years and reads this code.
Quoted 44 lines
Quoted 12 lines
Quoted 9 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +9
-0+case 3 : + iar = (cmd->enable.bits.data) ?0 : cmd->address; + ifr |=QSPI_IFR_ADDREN ; +break ; +case 0 : +break ; +default : +return -EINVAL ; + }[...]
Quoted 11 lines
drivers/mtd/spi-nor/atmel-quadspi.c line 520
Quoted 8 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +8
-0+no_data: +/* Poll INSTRuction End status */ + sr =qspi_readl (aq,QSPI_SR ); +if (sr &QSPI_SR_INSTRE ) +return err; + +/* Wait for INSTRuction End interrupt */ +init_completion (&aq->completion);You should use
reinit_completion()in the code.init_completion()should be used only in theprobe()function and nowhere else.Alright. In the next version I'll rename the "completion" member of struct
atmel_qspiinto "cmd_completion". Also I'll add anotherdma_completionmember in this very same structure to replace the local "struct completion completion" inatmel_qspi_run_dma_transfer().Then I'll call
init_completion()on bothcmd_completionanddma_completiononly fromatmel_qspi_probe()andreinit_completion()elsewhere.Quoted 12 lines
Quoted 9 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +9
-0+ aq->pending =0 ; +qspi_writel (aq,QSPI_IER ,QSPI_SR_INSTRE ); +if (!wait_for_completion_timeout (&aq->completion, +msecs_to_jiffies (1000 ))) + err = -ETIMEDOUT ; +qspi_writel (aq,QSPI_IDR ,QSPI_SR_INSTRE ); + +return err; +}[...]
Quoted 4 lines
Quoted 1 line
Hope this helps :)
Indeed, it does! I still work on the next version of this series to take all your comments into account.
Thanks :)
Re: [PATCH linux-next v4 5/5] mtd: atmel-quadspi: add driver for Atmel QSPI controller
Quoted 21 lines · Marek Vasut
Quoted 1 line · Cyrille Pitchen
Hi Marek,
Hi!
Quoted 5 lines
Le 24/08/2015 13:03, Marek Vasut a ?crit :
Quoted 4 lines · Cyrille Pitchen
Quoted 3 lines
This driver add support to the new Atmel QSPI controller embedded into sama5d2x SoCs. It expects a NOR memory to be connected to the QSPI controller.
[...]
Quoted 8 lines
Quoted 7 lines
drivers/mtd/spi-nor/atmel-quadspi.c line 407
Quoted 5 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +5
-0+/* Compute address parameters */ +switch (cmd->enable.bits.address) { +case 4 : + ifr |=QSPI_IFR_ADDRL ; +/*break;*/ /* fallback to the 24bit address case */ What's this commented out bit of code for ? :-)
Quoted 8 lines
Quoted 3 lines
I just wanted to stress out there was no missing "break;". I've reworded the comment to:
/* No "break" on purpose: fallback to the 24bit address case. */Oh, the address is in bytes . I see, yes, it makes sense to be more explicit here about the purpose of the fallback. I think this change in the comment will make it easier for everyone who comes back in a few years and reads this code.
I think you are looking for the term "(switch case) fallthrough", not "fallback". "Fallback" makes it sound like there is something missing, or an invalid state.
Jonas
Re: [PATCH linux-next v4 5/5] mtd: atmel-quadspi: add driver for Atmel QSPI controller
Le 25/08/2015 11:46, Jonas Gorski a ?crit :
Quoted 31 lines · Marek Vasut
Quoted 21 lines · Cyrille Pitchen
Quoted 1 line
Hi Marek,
Hi!
Quoted 5 lines
Le 24/08/2015 13:03, Marek Vasut a ?crit :
Quoted 4 lines · Cyrille Pitchen
Quoted 3 lines
This driver add support to the new Atmel QSPI controller embedded into sama5d2x SoCs. It expects a NOR memory to be connected to the QSPI controller.
[...]
Quoted 8 lines
Quoted 7 lines
drivers/mtd/spi-nor/atmel-quadspi.c line 407
Quoted 5 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +5
-0+/* Compute address parameters */ +switch (cmd->enable.bits.address) { +case 4 : + ifr |=QSPI_IFR_ADDRL ; +/*break;*/ /* fallback to the 24bit address case */ What's this commented out bit of code for ? :-)
Quoted 8 lines
Quoted 3 lines
I just wanted to stress out there was no missing "break;". I've reworded the comment to:
/* No "break" on purpose: fallback to the 24bit address case. */Oh, the address is in bytes . I see, yes, it makes sense to be more explicit here about the purpose of the fallback. I think this change in the comment will make it easier for everyone who comes back in a few years and reads this code.
Quoted 7 lines
I think you are looking for the term "(switch case) fallthrough", not "fallback". "Fallback" makes it sound like there is something missing, or an invalid state.
Jonas
will be modified in the next series, thanks for the review!
Re: [PATCH linux-next v4 5/5] mtd: atmel-quadspi: add driver for Atmel QSPI controller
In reply to Marek VasutHi Marek,
Le 24/08/2015 13:03, Marek Vasut a ?crit :
Quoted 12 lines · Cyrille Pitchen
Quoted 6 lines
This driver add support to the new Atmel QSPI controller embedded into sama5d2x SoCs. It expects a NOR memory to be connected to the QSPI controller.
Signed-off-by Cyrille Pitchen <[email protected]>Acked-by Nicolas Ferre <[email protected]>Hi,
[...]
Quoted 7 lines
Quoted 1 line
+/* Register access macros */
These are functions, not macros :)
btw is there any reason for these ? I'd say, just put the read*() and write*() functions directly into the code and be done with it, it is much less confusing.
If you don't mind, I'd rather keep some of these inline functions. I have no strong justification, it's more a personal taste: it makes lines shorter as it avoids the need to add "->regs + ".
Also it makes the code consistent with other Atmel drivers which already use such wrappers.
However I'll fix the comment and remove the byte and word versions, which are not used. So only qspi_readl() and qspi_writel() are left.
Does it sound good to you?
Quoted 35 lines
Also, why do you use the
_relaxed()versions of the functions ?Quoted 29 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +29
-0+static inline u32 qspi_readl (struct atmel_qspi *aq,u32 reg) +{ +return readl_relaxed (aq->regs + reg); +} + +static inline void qspi_writel (struct atmel_qspi *aq,u32 reg,u32 value) +{ +writel_relaxed (value, aq->regs + reg); +} + +static inline u16 qspi_readw (struct atmel_qspi *aq,u32 reg) +{ +return readw_relaxed (aq->regs + reg); +} + +static inline void qspi_writew (struct atmel_qspi *aq,u32 reg,u16 value) +{ +writew_relaxed (value, aq->regs + reg); +} + +static inline u8 qspi_readb (struct atmel_qspi *aq,u32 reg) +{ +return readb_relaxed (aq->regs + reg); +} + +static inline void qspi_writeb (struct atmel_qspi *aq,u32 reg,u8 value) +{ +writeb_relaxed (value, aq->regs + reg); +}[...]
Quoted 2 lines
Hope this helps :)
Best regards,
Cyrille
Re: [PATCH linux-next v4 5/5] mtd: atmel-quadspi: add driver for Atmel QSPI controller
Quoted 1 line · Cyrille Pitchen
Hi Marek,
Hi!
Quoted 27 lines
Le 24/08/2015 13:03, Marek Vasut a ?crit :
Quoted 12 lines · Cyrille Pitchen
Quoted 6 lines
This driver add support to the new Atmel QSPI controller embedded into sama5d2x SoCs. It expects a NOR memory to be connected to the QSPI controller.
Signed-off-by Cyrille Pitchen <[email protected]>Acked-by Nicolas Ferre <[email protected]>Hi,
[...]
Quoted 7 lines
Quoted 1 line
+/* Register access macros */
These are functions, not macros :)
btw is there any reason for these ? I'd say, just put the read*() and write*() functions directly into the code and be done with it, it is much less confusing.
If you don't mind, I'd rather keep some of these inline functions. I have no strong justification, it's more a personal taste: it makes lines shorter as it avoids the need to add "->regs + ".
Also it makes the code consistent with other Atmel drivers which already use such wrappers.
Quoted 4 lines
However I'll fix the comment and remove the byte and word versions, which are not used. So only
qspi_readl()andqspi_writel()are left.Does it sound good to you?
In my mind, seeing explicit readl_relaxed() somewhere is much easier to digest than seeing some wrapper, which I have to look up. But please do wait for others to voice their concern too, I might not be the best person to tell you what to do when it comes to wrapping IO accessors ;-)
Best regards,
Marek Vasut
Re: [PATCH linux-next v4 5/5] mtd: atmel-quadspi: add driver for Atmel QSPI controller
Quoted 10 lines · Marek Vasut
Quoted 9 lines · Cyrille Pitchen
If you don't mind, I'd rather keep some of these inline functions. I have no strong justification, it's more a personal taste: it makes lines shorter as it avoids the need to add "->regs + ".
Also it makes the code consistent with other Atmel drivers which already use such wrappers.However I'll fix the comment and remove the byte and word versions, which are not used. So only
qspi_readl()andqspi_writel()are left.
Quoted 6 lines
Quoted 1 line
Does it sound good to you?
In my mind, seeing explicit
readl_relaxed()somewhere is much easier to digest than seeing some wrapper, which I have to look up. But please do wait for others to voice their concern too, I might not be the best person to tell you what to do when it comes to wrapping IO accessors ;-)
I could go either way, but there are times where local wrapper I/O accessors are useful. Case in point: it makes it really easy to make the choice between readl() and readl_relaxed() in one place (i.e., the discussion you had in another branch of this thread). That's been useful for me on brcmnand, where certain platforms (big-endian MIPS) have different assumptions about endianness than your average platform. Also, it helps with things like what Robert Jarzmik is trying to do on pxa3xx_nand -- add debug info to print every register read/write.
Also as Cyrille mentioned, personal taste is a factor.
Anyway, I'll go with whatever makes sense between y'all. I don't mind.
Brian
RE: [PATCH linux-next v4 5/5] mtd: atmel-quadspi: add driver for Atmel QSPI controller
In reply to Cyrille Pitchendrivers/mtd/spi-nor/atmel-quadspi.c line 803
Quoted 7 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +6
-0+ nor->read_reg = atmel_qspi_read_reg; + nor->write_reg = atmel_qspi_write_reg; + nor->read = atmel_qspi_read; + nor->write = atmel_qspi_write; + nor->erase = atmel_qspi_erase; + nor->set_protocol = atmel_qspi_set_protocol;
This is very good, the structure of spi_nor should add a hook function to notify spi controller That spi nor transfer protocol already changed.
Quoted 18 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +16
-0+ +if (of_modalias_node (child, modalias,sizeof (modalias)) <0 ) { + err = -ENODEV ; + goto release_channel; + } + + err =of_property_read_u32 (child,"spi-max-frequency" , &aq->clk_rate); +if (err <0 ) + goto release_channel; + + err =atmel_qspi_init (aq); +if (err) + goto release_channel; + + nor->dev->of_node = child; + err =spi_nor_scan (nor, modalias,SPI_NOR_QUAD );goto release_channel;+
.......
Quoted 1 line
static inline struct
spi_nor*mtd_to_spi_nor(structmtd_info*mtd) {
return mtd->priv;
Review static int micron_quad_enable(struct spi_nor *nor) · line 967
Quoted 9 lines
(quoted diff) +5
-0@@ -944,6 +960,11 @@ static int micron_quad_enable(struct spi_nor *nor) return ret; } + /* switch protocol to Quad CMD 4-4-4 */ + ret = spi_nor_set_protocol(nor, SPI_PROTO_4_4_4); + if (ret) + return ret; +
This make sense,from spi nor side,once its protocol being changed, Mtd layer must notify this status to spi nor controller immediately, And spi nor controller also should re-adjust its protocol. Otherwise, following reading SR operation will fail.
Review static int micron_quad_enable(struct spi_nor *nor) · line 970
Quoted 4 lines
(quoted diff) +0
-0ret = spi_nor_wait_till_ready(nor); if (ret) return ret;
If my ack has any value in here, feel free to add it.
Re: [PATCH linux-next v4 5/5] mtd: atmel-quadspi: add driver for Atmel QSPI controller
Hi!
Le 25/08/2015 03:44, Bean Huo ??? (beanhuo) a ?crit :
Quoted 51 lines
drivers/mtd/spi-nor/atmel-quadspi.c line 803
Quoted 7 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +6
-0+ nor->read_reg = atmel_qspi_read_reg; + nor->write_reg = atmel_qspi_write_reg; + nor->read = atmel_qspi_read; + nor->write = atmel_qspi_write; + nor->erase = atmel_qspi_erase; + nor->set_protocol = atmel_qspi_set_protocol;This is very good, the structure of
spi_norshould add a hook function to notify spi controller That spi nor transfer protocol already changed.Quoted 18 lines
drivers/mtd/spi-nor/atmel-quadspi.c new file +16
-0+ +if (of_modalias_node (child, modalias,sizeof (modalias)) <0 ) { + err = -ENODEV ; + goto release_channel; + } + + err =of_property_read_u32 (child,"spi-max-frequency" , &aq->clk_rate); +if (err <0 ) + goto release_channel; + + err =atmel_qspi_init (aq); +if (err) + goto release_channel; + + nor->dev->of_node = child; + err =spi_nor_scan (nor, modalias,SPI_NOR_QUAD );goto release_channel;+
.......
Quoted 1 line
static inline struct
spi_nor*mtd_to_spi_nor(structmtd_info*mtd) {return
mtd->priv;Review static int micron_quad_enable(struct spi_nor *nor) · line 967
Quoted 9 lines
(quoted diff) +5
-0@@ -944,6 +960,11 @@ static int micron_quad_enable(struct spi_nor *nor) return ret; } + /* switch protocol to Quad CMD 4-4-4 */ + ret = spi_nor_set_protocol(nor, SPI_PROTO_4_4_4); + if (ret) + return ret; +This make sense,from spi nor side,once its protocol being changed, Mtd layer must notify this status to spi nor controller immediately, And spi nor controller also should re-adjust its protocol. Otherwise, following reading SR operation will fail.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
ret = spi_nor_wait_till_ready(nor); if (ret) return ret;If my ack has any value in here, feel free to add it.
Acked-by Bean Huo <[email protected]>
Since your comments deal with the protocol change, I'll add your ack to the first patch of the series:
"mtd: spi-nor: notify (Q)SPI controller about protocol change"
Thanks for your review!
Best regards,
Cyrille