mtd: spi-nor-core: add xSPI Octal DTR support
Subsystems (4)
cover mtd: spi-nor-core: add xSPI Octal DTR support
Hi,
This series adds support for octal DTR flashes in the spi-nor framework, and then adds hooks for the Cypress Semper flash which is an xSPI compliant Octal DTR flash.
The Cadence QSPI controller driver is also updated to run in Octal DTR mode.
Tested on TI J721e EVM with 1-bit ECC on the Cypress flash on top of u-boot-ti/next.
This series depends on [0].
[0] cf. <[email protected]>
[0] https://lists.denx.de/pipermail/u-boot/2020-February/401192.html
Pratyush Yadav (15):
dt-bindings: spi: allow expressing DTR capability
spi: set mode bits for "spi-rx-dtr" and "spi-tx-dtr"
spi: spi-mem: allow specifying whether an op is DTR or not
spi: spi-mem: allow specifying a command's extension
spi: cadence-qspi: Do not calibrate when device tree sets read delay
spi: cadence-qspi: Add support for octal DTR flashes
mtd: spi-nor-core: Add a ->setup() hook
mtd: spi-nor-core: Move SFDP related declarations to top
mtd: spi-nor-core: Introduce flash-specific fixup hooks
mtd: spi-nor-core: Add support for DTR protocol
mtd: spi-nor-core: Get command opcode extension type from BFPT
mtd: spi-nor-core: Parse xSPI Profile 1.0 table
mtd: spi-nor-core: Use Read SR dummy cycle and address width from SFDP
mtd: spi-nor-core: Enable octal DTR mode when possible
mtd: spi-nor-core: Add support for Cypress Semper flash
doc/device-tree-bindings/spi/spi-bus.txt | 4 + drivers/mtd/spi/sf_internal.h | 8 + drivers/mtd/spi/spi-nor-core.c | 804 +++++++++++++++++------ drivers/mtd/spi/spi-nor-ids.c | 1 + drivers/mtd/spi/spi-nor-tiny.c | 22 - drivers/spi/cadence_qspi.c | 59 +- drivers/spi/cadence_qspi.h | 15 +- drivers/spi/cadence_qspi_apb.c | 255 ++++++- drivers/spi/spi-mem.c | 47 ++ drivers/spi/spi-uclass.c | 9 + include/linux/mtd/spi-nor.h | 223 +++++-- include/spi-mem.h | 32 + include/spi.h | 2 + 13 files changed, 1171 insertions(+), 310 deletions(-)
--
2.25.0
PATCH 1/15 dt-bindings: spi: allow expressing DTR capability
Allow spi devices to express DTR receive and transmit capabilities via the properties "spi-rx-dtr" and "spi-tx-dtr".
---
Corresponding Kernel DT patch at
https://lore.kernel.org/linux-mtd/20200226093703.19765-2-p.yadav at ti.com/
doc/device-tree-bindings/spi/spi-bus.txt | 4 ++++ 1 file changed, 4 insertions(+)
doc/device-tree-bindings/spi/spi-bus.txt +4 -0
@@ -59,6 +59,10 @@ contain the following properties. used for MOSI. Defaults to 1 if not present. - spi-rx-bus-width - (optional) The bus width(number of data wires) that used for MISO. Defaults to 1 if not present. +- spi-tx-dtr - (optional) Its presence indicates bus can transmit in DTR + protocol. +- spi-rx-dtr - (optional) Its presence indicates bus can receive in DTR + protocol. - spi-half-duplex - (optional) Indicates that the SPI bus should wait for a header byte before reading data from the slave.
--
2.25.0
PATCH 2/15 spi: set mode bits for "spi-rx-dtr" and "spi-tx-dtr"
In reply to Pratyush YadavThese two DT properties express DTR receive and transmit capabilities of a SPI flash and controller. Introduce two new mode bits: SPI_RX_DTR and SPI_TX_DTR which correspond to the new DT properties. Set these bits when the two corresponding properties are present in the device tree.
--- drivers/spi/spi-uclass.c | 9 +++++++++ include/spi.h | 2 ++ 2 files changed, 11 insertions(+)
drivers/spi/spi-uclass.c +9 -0
@@ -435,6 +435,7 @@ int spi_slave_ofdata_to_platdata(struct udevice *dev, {int mode =0 ;int value; +bool dtr; plat->cs =dev_read_u32_default (dev,"reg" ,-1 ); plat->max_hz = dev_read_u32_default(dev, "spi-max-frequency",
@@ -487,6 +488,14 @@ int spi_slave_ofdata_to_platdata(struct udevice *dev,break ; } + dtr =dev_read_bool (dev,"spi-rx-dtr" ); +if (dtr) + mode |=SPI_RX_DTR ; + + dtr =dev_read_bool (dev,"spi-tx-dtr" ); +if (dtr) + mode |=SPI_TX_DTR ; + plat->mode = mode;return 0 ;
include/spi.h +2 -0
@@ -32,6 +32,8 @@#define SPI_RX_QUAD BIT(13)/* receive with 4 wires */ #define SPI_TX_OCTAL BIT(14)/* transmit with 8 wires */ #define SPI_RX_OCTAL BIT(15)/* receive with 8 wires */ +#define SPI_TX_DTR BIT(16)/* transmit in DTR protocol */ +#define SPI_RX_DTR BIT(17)/* receive in DTR protocol */ /* Header byte that marks the start of the message */ #define SPI_PREAMBLE_END_BYTE 0xec
Signature · 1 line
2.25.0
PATCH 3/15 spi: spi-mem: allow specifying whether an op is DTR or not
In reply to Pratyush YadavEach phase is given a separate 'is_dtr' field so mixed protocols like 4S-4D-4D can be supported.
--- drivers/spi/spi-mem.c | 24 ++++++++++++++++++++++++ include/spi-mem.h | 8 ++++++++ 2 files changed, 32 insertions(+)
drivers/spi/spi-mem.c +24 -0
@@ -104,6 +104,16 @@ void spi_controller_dma_unmap_mem_op_data(struct spi_controller *ctlr,EXPORT_SYMBOL_GPL (spi_controller_dma_unmap_mem_op_data);#endif /* __UBOOT__ */ +static int spi_check_dtr_req (struct spi_slave *slave,bool tx) +{ +u32 mode = slave->mode; + +if ((tx && (mode &SPI_TX_DTR )) || (!tx && (mode &SPI_RX_DTR ))) +return 0 ; + +return -ENOTSUPP ; +} +static int spi_check_buswidth_req (struct spi_slave *slave,u8 buswidth,bool tx) {u32 mode = slave->mode;
@@ -158,6 +168,20 @@ bool spi_mem_default_supports_op(struct spi_slave *slave, op->data.dir == SPI_MEM_DATA_OUT))return false; +if (op->cmd.is_dtr &&spi_check_dtr_req (slave, true)) +return false; + +if (op->addr.is_dtr &&spi_check_dtr_req (slave, true)) +return false; + +if (op->dummy.is_dtr && +spi_check_dtr_req (slave, true)) +return false; + +if (op->data.is_dtr && +spi_check_dtr_req (slave, op->data.dir ==SPI_MEM_DATA_OUT )) +return false; +return true; }EXPORT_SYMBOL_GPL (spi_mem_default_supports_op);
include/spi-mem.h +8 -0
@@ -72,6 +72,7 @@ enum spi_mem_data_dir {* struct spi_mem_op - describes a SPI memory operation * @cmd.buswidth: number of IO lines used to transmit the command * @cmd.opcode: operation opcode +* @cmd.is_dtr: whether the command opcode should be sent in DTR mode or not * @addr.nbytes: number of address bytes to send. Can be zero if the operation * does not need to send an address * @addr.buswidth: number of IO lines used to transmit the address cycles
@@ -79,11 +80,14 @@ enum spi_mem_data_dir {* Note that only @addr.nbytes are taken into account in this * address value, so users should make sure the value fits in the * assigned number of bytes. +* @addr.is_dtr: whether the address should be sent in DTR mode or not * @dummy.nbytes: number of dummy bytes to send after an opcode or address. Can * be zero if the operation does not require dummy bytes * @dummy.buswidth: number of IO lanes used to transmit the dummy bytes +* @dummy.is_dtr: whether the dummy bytes should be sent in DTR mode or not * @data.buswidth: number of IO lanes used to send/receive the data * @data.dir: direction of the transfer +* @data.is_dtr: whether the data should be sent in DTR mode or not * @data.buf.in: input buffer * @data.buf.out: output buffer */
@@ -91,23 +95,27 @@ struct spi_mem_op {struct {u8 buswidth;u8 opcode; +bool is_dtr; } cmd;struct {u8 nbytes;u8 buswidth;u64 val; +bool is_dtr; } addr;struct {u8 nbytes;u8 buswidth; +bool is_dtr; } dummy;struct {u8 buswidth;enum spi_mem_data_dir dir;unsigned int nbytes; +bool is_dtr;/* buf.{in,out} must be DMA-able. */ union {void *in;
Signature · 1 line
2.25.0
PATCH 4/15 spi: spi-mem: allow specifying a command's extension
In reply to Pratyush YadavIn xSPI mode, flashes expect 2-byte opcodes. The second byte is called the "command extension". There can be 3 types of extensions in xSPI:
repeat, invert, and hex. When the extension type is "repeat", the same opcode is sent twice. When it is "invert", the second byte is the inverse of the opcode. When it is "hex" an additional opcode byte based is sent with the command whose value can be anything.
--- drivers/spi/spi-mem.c | 23 +++++++++++++++++++++++ include/spi-mem.h | 24 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+)
drivers/spi/spi-mem.c +23 -0
@@ -479,6 +479,29 @@ int spi_mem_adjust_op_size(struct spi_slave *slave, struct spi_mem_op *op) }EXPORT_SYMBOL_GPL (spi_mem_adjust_op_size); +int spi_mem_get_cmd_ext (const struct spi_mem_op *op,u8 *ext) +{ +switch (op->cmd.ext_type) { +case SPI_MEM_EXT_INVERT : + *ext = ~op->cmd.opcode; +break ; + +case SPI_MEM_EXT_REPEAT : + *ext = op->cmd.opcode; +break ; + +case SPI_MEM_EXT_HEX : + *ext = op->cmd.ext; +break ; + +default : +return -EINVAL ; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (spi_mem_get_cmd_ext); +#ifndef __UBOOT__static inline struct spi_mem_driver *to_spi_mem_drv (struct device_driver *drv) {
include/spi-mem.h +24 -0
@@ -68,11 +68,31 @@ enum spi_mem_data_dir { SPI_MEM_DATA_OUT, }; +/** +* enum spi_mem_cmd_ext - describes the command opcode extension in DTR mode +* @SPI_MEM_EXT_NONE: no extension. This is the default, and is used in Legacy +* SPI mode +* @SPI_MEM_EXT_REPEAT: the extension is same as the opcode +* @SPI_MEM_EXT_INVERT: the extension is the bitwise inverse of the opcode +* @SPI_MEM_EXT_HEX: the extension is any hex value. The command and opcode +* combine to form a 16-bit opcode. +*/ +enum spi_mem_cmd_ext { +SPI_MEM_EXT_NONE =0 , +SPI_MEM_EXT_REPEAT , +SPI_MEM_EXT_INVERT , +SPI_MEM_EXT_HEX , +}; +/** * struct spi_mem_op - describes a SPI memory operation * @cmd.buswidth: number of IO lines used to transmit the command * @cmd.opcode: operation opcode * @cmd.is_dtr: whether the command opcode should be sent in DTR mode or not +* @cmd.ext_type: type of the command opcode extension in DTR mode +* @cmd.ext: value of the command opcode extension in DTR mode. It is +* only set when 'ext_type' is 'SPI_MEM_EXT_HEX'. In all other +* cases, the extension can be directly derived from the opcode. * @addr.nbytes: number of address bytes to send. Can be zero if the operation * does not need to send an address * @addr.buswidth: number of IO lines used to transmit the address cycles
@@ -96,6 +116,8 @@ struct spi_mem_op {u8 buswidth;u8 opcode;bool is_dtr; +enum spi_mem_cmd_ext ext_type; +u8 ext; } cmd;struct {
@@ -249,6 +271,8 @@ bool spi_mem_supports_op(struct spi_slave *slave, const struct spi_mem_op *op);int spi_mem_exec_op (struct spi_slave *slave,const struct spi_mem_op *op); +int spi_mem_get_cmd_ext (const struct spi_mem_op *op,u8 *ext); +#ifndef __UBOOT__int spi_mem_driver_register_with_owner (struct spi_mem_driver *drv,struct module *owner);
Signature · 1 line
2.25.0
PATCH 5/15 spi: cadence-qspi: Do not calibrate when device tree sets read delay
In reply to Pratyush YadavIf the device tree provides a read delay value, use that directly and do not perform the calibration procedure.
This allows the device tree to over-ride the read delay value in cases where the read delay value obtained via calibration is incorrect. One such example is the Cypress Semper flash. It needs a read delay of 4 in octal DTR mode. But since the calibration procedure is run before the flash is switched in octal DTR mode, it yields a read delay of 2. A value of 4 works for both octal DTR and legacy modes.
--- drivers/spi/cadence_qspi.c | 26 +++++++++++++++++++++----- drivers/spi/cadence_qspi.h | 1 + 2 files changed, 22 insertions(+), 5 deletions(-)
drivers/spi/cadence_qspi.c +21 -5
@@ -140,12 +140,20 @@ static int cadence_spi_set_speed(struct udevice *bus, uint hz)cadence_qspi_apb_controller_disable (priv->regbase);/* -* Calibration required for different current SCLK speed, requested -* SCLK speed or chip select +* If the device tree already provides a read delay value, use that +* instead of calibrating. */ -if (priv->previous_hz != hz || - priv->qspi_calibrated_hz != hz || - priv->qspi_calibrated_cs !=spi_chip_select (bus)) { +if (plat->read_delay >=0 ) { +cadence_spi_write_speed (bus, hz); +cadence_qspi_apb_readdata_capture (priv->regbase,1 , + plat->read_delay); + }else if (priv->previous_hz != hz || + priv->qspi_calibrated_hz != hz || + priv->qspi_calibrated_cs !=spi_chip_select (bus)) { +/* +* Calibration required for different current SCLK speed, +* requested SCLK speed or chip select +*/ err =spi_calibration (bus, hz);if (err)return err;
@@ -319,6 +327,14 @@ static int cadence_spi_ofdata_to_platdata(struct udevice *bus) 255); plat->tchsh_ns =ofnode_read_u32_default (subnode,"cdns,tchsh-ns" ,20 ); plat->tslch_ns =ofnode_read_u32_default (subnode,"cdns,tslch-ns" ,20 ); +/* +* Read delay should be an unsigned value but we use a signed integer +* so that negative values can indicate that the device tree did not +* specify any signed values and we need to perform the calibration +* sequence to find it out. +*/ + plat->read_delay =ofnode_read_s32_default (subnode,"cdns,read-delay" , +-1 ); debug("%s: regbase=%p ahbbase=%p max-frequency=%d page-size=%d\n", __func__, plat->regbase, plat->ahbbase, plat->max_hz,
drivers/spi/cadence_qspi.h +1 -0
@@ -26,6 +26,7 @@ struct cadence_spi_platdata {u32 trigger_address;fdt_addr_t ahbsize;bool use_dac_mode; +int read_delay;/* Flash parameters */ u32 page_size;
Signature · 1 line
2.25.0
PATCH 6/15 spi: cadence-qspi: Add support for octal DTR flashes
In reply to Pratyush YadavSet up opcode extension and enable/disable DTR mode based on whether the command is DTR or not.
xSPI flashes can have a 4-byte dummy address associated with some commands like the Read Status Register command in octal DTR mode. Since the flash does not support sending the dummy address, we can not use automatic write completion polling in DTR mode. Further, no write completion polling makes it impossible to use DAC mode for DTR writes. In that mode, the controller does not know beforehand how long a write will be and so it can de-assert Chip Select (CS#) at any time. Once CS# is de-assert, the flash will go into burning phase. But since the controller does not do write completion polling, it does not know when the flash is busy and might send in writes while the flash is not ready.
So, disable write completion polling and make writes go through indirect mode for DTR writes and let spi-mem take care of polling the SR.
--- drivers/spi/cadence_qspi.c | 33 ++++- drivers/spi/cadence_qspi.h | 14 +- drivers/spi/cadence_qspi_apb.c | 255 +++++++++++++++++++++++++++++++-- 3 files changed, 279 insertions(+), 23 deletions(-)
drivers/spi/cadence_qspi.c +27 -6
@@ -40,20 +40,22 @@ static int cadence_spi_write_speed(struct udevice *bus, uint hz)return 0 ; } -static int cadence_spi_read_id (void *reg_base,u8 len,u8 *idcode) +static int cadence_spi_read_id (struct cadence_spi_platdata *plat,u8 len, +u8 *idcode) {struct spi_mem_op op =SPI_MEM_OP (SPI_MEM_OP_CMD (0x9F ,1 ),SPI_MEM_OP_NO_ADDR ,SPI_MEM_OP_NO_DUMMY ,SPI_MEM_OP_DATA_IN (len, idcode,1 )); -return cadence_qspi_apb_command_read (reg_base, &op); +return cadence_qspi_apb_command_read (plat, &op); }/* Calibration sequence to determine the read data capture delay register */ static int spi_calibration (struct udevice *bus,uint hz) {struct cadence_spi_priv *priv =dev_get_priv (bus); +struct cadence_spi_platdata *plat = bus->platdata;void *base = priv->regbase;unsigned int idcode =0 , temp =0 ;int err =0 , i, range_lo =-1 , range_hi =-1 ;
@@ -68,7 +70,7 @@ static int spi_calibration(struct udevice *bus, uint hz)cadence_qspi_apb_controller_enable (base);/* read the ID which will be our golden value */ - err =cadence_spi_read_id (base,3 , (u8 *)&idcode); + err =cadence_spi_read_id (plat,3 , (u8 *)&idcode);if (err) {puts ("SF: Calibration failed (read)\n" );return err;
@@ -87,7 +89,7 @@ static int spi_calibration(struct udevice *bus, uint hz)cadence_qspi_apb_controller_enable (base);/* issue a RDID to get the ID value */ - err =cadence_spi_read_id (base,3 , (u8 *)&temp); + err =cadence_spi_read_id (plat,3 , (u8 *)&temp);if (err) {puts ("SF: Calibration failed (read)\n" );return err;
@@ -266,10 +268,14 @@ static int cadence_spi_mem_exec_op(struct spi_slave *spi,switch (mode) {case CQSPI_STIG_READ : - err =cadence_qspi_apb_command_read (base, op); + err =cadence_qspi_apb_command_read_setup (plat, op); +if (!err) + err =cadence_qspi_apb_command_read (plat, op);break ;case CQSPI_STIG_WRITE : - err =cadence_qspi_apb_command_write (base, op); + err =cadence_qspi_apb_command_write_setup (plat, op); +if (!err) + err =cadence_qspi_apb_command_write (plat, op);break ;case CQSPI_READ : err =cadence_qspi_apb_read_setup (plat, op);
@@ -289,6 +295,20 @@ static int cadence_spi_mem_exec_op(struct spi_slave *spi,return err; } +static bool cadence_spi_mem_supports_op (struct spi_slave *slave, +const struct spi_mem_op *op) +{ +bool all_true, all_false; + + all_true = op->cmd.is_dtr && op->addr.is_dtr && op->dummy.is_dtr && + op->data.is_dtr; + all_false = !op->cmd.is_dtr && !op->addr.is_dtr && !op->dummy.is_dtr && + !op->data.is_dtr; + +/* Mixed DTR modes not supported. */ +return all_true || all_false; +} +static int cadence_spi_ofdata_to_platdata (struct udevice *bus) {struct cadence_spi_platdata *plat = bus->platdata;
@@ -345,6 +365,7 @@ static int cadence_spi_ofdata_to_platdata(struct udevice *bus)static const struct spi_controller_mem_ops cadence_spi_mem_ops = { .exec_op = cadence_spi_mem_exec_op, + .supports_op = cadence_spi_mem_supports_op, };static const struct dm_spi_ops cadence_spi_ops = {
drivers/spi/cadence_qspi.h +12 -2
@@ -35,6 +35,12 @@ struct cadence_spi_platdata {u32 tsd2d_ns;u32 tchsh_ns;u32 tslch_ns; + +/* Transaction protocol parameters. */ +u8 inst_width; +u8 addr_width; +u8 data_width; +bool is_dtr; };struct cadence_spi_priv {
@@ -58,9 +64,13 @@ void cadence_qspi_apb_controller_enable(void *reg_base_addr);void cadence_qspi_apb_controller_disable (void *reg_base_addr);void cadence_qspi_apb_dac_mode_enable (void *reg_base); -int cadence_qspi_apb_command_read (void *reg_base_addr, +int cadence_qspi_apb_command_read_setup (struct cadence_spi_platdata *plat, +const struct spi_mem_op *op); +int cadence_qspi_apb_command_read (struct cadence_spi_platdata *plat,const struct spi_mem_op *op); -int cadence_qspi_apb_command_write (void *reg_base_addr, +int cadence_qspi_apb_command_write_setup (struct cadence_spi_platdata *plat, +const struct spi_mem_op *op); +int cadence_qspi_apb_command_write (struct cadence_spi_platdata *plat,const struct spi_mem_op *op); int cadence_qspi_apb_read_setup(struct cadence_spi_platdata *plat,
drivers/spi/cadence_qspi_apb.c +240 -15
362 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH 7/15 mtd: spi-nor-core: Add a ->setup() hook
In reply to Pratyush Yadavnor->setup() can be used by flashes to configure settings in case they have any peculiarities that can't be easily expressed by the generic spi-nor framework. This includes things like different opcodes, dummy cycles, page size, uniform/non-uniform sector sizes, etc.
Move related declarations to avoid forward declarations.
Inspired by the Linux kernel's setup() hook.
--- drivers/mtd/spi/spi-nor-core.c | 84 +++------------ drivers/mtd/spi/spi-nor-tiny.c | 22 ---- include/linux/mtd/spi-nor.h | 192 ++++++++++++++++++++++----------- 3 files changed, 147 insertions(+), 151 deletions(-)
drivers/mtd/spi/spi-nor-core.c +16 -68
@@ -1441,71 +1441,6 @@ static int spansion_no_read_cr_quad_enable(struct spi_nor *nor)#endif /* CONFIG_SPI_FLASH_SFDP_SUPPORT */ #endif /* CONFIG_SPI_FLASH_SPANSION */ -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 , - -/* Octo 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 , - -/* Octo 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 ]; - -int (*quad_enable)(struct spi_nor *nor); -}; - static void spi_nor_set_read_settings(struct spi_nor_read_command *read, u8 num_mode_clocks,
@@ -2363,9 +2298,10 @@ static int spi_nor_select_erase(struct spi_nor *nor,return 0 ; } -static int spi_nor_setup (struct spi_nor *nor,const struct flash_info *info, -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 flash_info *info, +const struct spi_nor_flash_parameter *params, +const struct spi_nor_hwcaps *hwcaps) {u32 ignored_mask, shared_mask;bool enable_quad_io;
@@ -2424,6 +2360,16 @@ static int spi_nor_setup(struct spi_nor *nor, const struct flash_info *info,return 0 ; } +static int spi_nor_setup (struct spi_nor *nor,const struct flash_info *info, +const struct spi_nor_flash_parameter *params, +const struct spi_nor_hwcaps *hwcaps) +{ +if (!nor->setup) +return 0 ; + +return nor->setup (nor, info, params, hwcaps); +} +static int spi_nor_init (struct spi_nor *nor) {int err;
@@ -2489,6 +2435,8 @@ int spi_nor_scan(struct spi_nor *nor) nor->read_reg = spi_nor_read_reg; nor->write_reg = spi_nor_write_reg; + nor->setup = spi_nor_default_setup; +if (spi->mode &SPI_RX_OCTAL ) { hwcaps.mask |=SNOR_HWCAPS_READ_1_1_8 ;
drivers/mtd/spi/spi-nor-tiny.c +0 -22
@@ -543,28 +543,6 @@ static int spansion_read_cr_quad_enable(struct spi_nor *nor) }#endif /* CONFIG_SPI_FLASH_SPANSION */ -struct spi_nor_read_command { -u8 num_mode_clocks; -u8 num_wait_states; -u8 opcode; -enum spi_nor_protocol proto; -}; - -enum spi_nor_read_command_index { -SNOR_CMD_READ , -SNOR_CMD_READ_FAST , - -/* Quad SPI */ -SNOR_CMD_READ_1_1_4 , - -SNOR_CMD_READ_MAX -}; - -struct spi_nor_flash_parameter { -struct spi_nor_hwcaps hwcaps; -struct spi_nor_read_command reads[SNOR_CMD_READ_MAX ]; -}; - static void spi_nor_set_read_settings(struct spi_nor_read_command *read, u8 num_mode_clocks,
include/linux/mtd/spi-nor.h +131 -61
210 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH 8/15 mtd: spi-nor-core: Move SFDP related declarations to top
In reply to Pratyush YadavThese structures will be used in a later commit inside another structure definition.
--- drivers/mtd/spi/spi-nor-core.c | 226 +++++++++++++++++---------------- 1 file changed, 114 insertions(+), 112 deletions(-)
drivers/mtd/spi/spi-nor-core.c +114 -112
@@ -36,6 +36,120 @@#define DEFAULT_READY_WAIT_JIFFIES (40UL * HZ) +#if CONFIG_IS_ENABLED (SPI_FLASH_SFDP_SUPPORT ) +struct sfdp_parameter_header { +u8 id_lsb; +u8 minor; +u8 major; +u8 length;/* in double words */ +u8 parameter_table_pointer[3 ];/* byte address */ +u8 id_msb; +}; + +#define SFDP_PARAM_HEADER_ID (p) (((p)->id_msb << 8) | (p)->id_lsb) +#define SFDP_PARAM_HEADER_PTP (p) \ + (((p)->parameter_table_pointer[2] << 16) | \ + ((p)->parameter_table_pointer[1] << 8) | \ + ((p)->parameter_table_pointer[0] << 0)) + +#define SFDP_BFPT_ID 0xff00/* Basic Flash Parameter Table */ +#define SFDP_SECTOR_MAP_ID 0xff81/* Sector Map Table */ +#define SFDP_SST_ID 0x01bf/* Manufacturer specific Table */ + +#define SFDP_SIGNATURE 0x50444653U +#define SFDP_JESD216_MAJOR 1 +#define SFDP_JESD216_MINOR 0 +#define SFDP_JESD216A_MINOR 5 +#define SFDP_JESD216B_MINOR 6 + +struct sfdp_header { +u32 signature;/* Ox50444653U <=> "SFDP" */ +u8 minor; +u8 major; +u8 nph;/* 0-base number of parameter headers */ +u8 unused; + +/* Basic Flash Parameter Table. */ +struct sfdp_parameter_header bfpt_header; +}; + +/* Basic Flash Parameter Table */ + +/* +* JESD216 rev B defines a Basic Flash Parameter Table of 16 DWORDs. +* They are indexed from 1 but C arrays are indexed from 0. +*/ +#define BFPT_DWORD (i) ((i) - 1) +#define BFPT_DWORD_MAX 16 + +/* The first version of JESB216 defined only 9 DWORDs. */ +#define BFPT_DWORD_MAX_JESD216 9 + +/* 1st DWORD. */ +#define BFPT_DWORD1_FAST_READ_1_1_2 BIT(16) +#define BFPT_DWORD1_ADDRESS_BYTES_MASK GENMASK(18, 17) +#define BFPT_DWORD1_ADDRESS_BYTES_3_ONLY (0x0UL << 17) +#define BFPT_DWORD1_ADDRESS_BYTES_3_OR_4 (0x1UL << 17) +#define BFPT_DWORD1_ADDRESS_BYTES_4_ONLY (0x2UL << 17) +#define BFPT_DWORD1_DTR BIT(19) +#define BFPT_DWORD1_FAST_READ_1_2_2 BIT(20) +#define BFPT_DWORD1_FAST_READ_1_4_4 BIT(21) +#define BFPT_DWORD1_FAST_READ_1_1_4 BIT(22) + +/* 5th DWORD. */ +#define BFPT_DWORD5_FAST_READ_2_2_2 BIT(0) +#define BFPT_DWORD5_FAST_READ_4_4_4 BIT(4) + +/* 11th DWORD. */ +#define BFPT_DWORD11_PAGE_SIZE_SHIFT 4 +#define BFPT_DWORD11_PAGE_SIZE_MASK GENMASK(7, 4) + +/* 15th DWORD. */ + +/* +* (from JESD216 rev B) +* Quad Enable Requirements (QER): +* - 000b: Device does not have a QE bit. Device detects 1-1-4 and 1-4-4 +* reads based on instruction. DQ3/HOLD# functions are hold during +* instruction phase. +* - 001b: QE is bit 1 of status register 2. It is set via Write Status with +* two data bytes where bit 1 of the second byte is one. +* [...] +* Writing only one byte to the status register has the side-effect of +* clearing status register 2, including the QE bit. The 100b code is +* used if writing one byte to the status register does not modify +* status register 2. +* - 010b: QE is bit 6 of status register 1. It is set via Write Status with +* one data byte where bit 6 is one. +* [...] +* - 011b: QE is bit 7 of status register 2. It is set via Write status +* register 2 instruction 3Eh with one data byte where bit 7 is one. +* [...] +* The status register 2 is read using instruction 3Fh. +* - 100b: QE is bit 1 of status register 2. It is set via Write Status with +* two data bytes where bit 1 of the second byte is one. +* [...] +* In contrast to the 001b code, writing one byte to the status +* register does not modify status register 2. +* - 101b: QE is bit 1 of status register 2. Status register 1 is read using +* Read Status instruction 05h. Status register2 is read using +* instruction 35h. QE is set via Writ Status instruction 01h with +* two data bytes where bit 1 of the second byte is one. +* [...] +*/ +#define BFPT_DWORD15_QER_MASK GENMASK(22, 20) +#define BFPT_DWORD15_QER_NONE (0x0UL << 20)/* Micron */ +#define BFPT_DWORD15_QER_SR2_BIT1_BUGGY (0x1UL << 20) +#define BFPT_DWORD15_QER_SR1_BIT6 (0x2UL << 20)/* Macronix */ +#define BFPT_DWORD15_QER_SR2_BIT7 (0x3UL << 20) +#define BFPT_DWORD15_QER_SR2_BIT1_NO_RD (0x4UL << 20) +#define BFPT_DWORD15_QER_SR2_BIT1 (0x5UL << 20)/* Spansion */ + +struct sfdp_bfpt { +u32 dwords[BFPT_DWORD_MAX ]; +}; +#endif /* SPI_FLASH_SFDP_SUPPORT */ +static int spi_nor_read_write_reg (struct spi_nor *nor,struct spi_mem_op *op,void *buf) {
@@ -1518,118 +1632,6 @@ read_err:return ret; } -struct sfdp_parameter_header { -u8 id_lsb; -u8 minor; -u8 major; -u8 length;/* in double words */ -u8 parameter_table_pointer[3 ];/* byte address */ -u8 id_msb; -}; - -#define SFDP_PARAM_HEADER_ID (p) (((p)->id_msb << 8) | (p)->id_lsb) -#define SFDP_PARAM_HEADER_PTP (p) \ - (((p)->parameter_table_pointer[2] << 16) | \ - ((p)->parameter_table_pointer[1] << 8) | \ - ((p)->parameter_table_pointer[0] << 0)) - -#define SFDP_BFPT_ID 0xff00/* Basic Flash Parameter Table */ -#define SFDP_SECTOR_MAP_ID 0xff81/* Sector Map Table */ -#define SFDP_SST_ID 0x01bf/* Manufacturer specific Table */ - -#define SFDP_SIGNATURE 0x50444653U -#define SFDP_JESD216_MAJOR 1 -#define SFDP_JESD216_MINOR 0 -#define SFDP_JESD216A_MINOR 5 -#define SFDP_JESD216B_MINOR 6 - -struct sfdp_header { -u32 signature;/* Ox50444653U <=> "SFDP" */ -u8 minor; -u8 major; -u8 nph;/* 0-base number of parameter headers */ -u8 unused; - -/* Basic Flash Parameter Table. */ -struct sfdp_parameter_header bfpt_header; -}; - -/* Basic Flash Parameter Table */ - -/* -* JESD216 rev B defines a Basic Flash Parameter Table of 16 DWORDs. -* They are indexed from 1 but C arrays are indexed from 0. -*/ -#define BFPT_DWORD (i) ((i) - 1) -#define BFPT_DWORD_MAX 16 - -/* The first version of JESB216 defined only 9 DWORDs. */ -#define BFPT_DWORD_MAX_JESD216 9 - -/* 1st DWORD. */ -#define BFPT_DWORD1_FAST_READ_1_1_2 BIT(16) -#define BFPT_DWORD1_ADDRESS_BYTES_MASK GENMASK(18, 17) -#define BFPT_DWORD1_ADDRESS_BYTES_3_ONLY (0x0UL << 17) -#define BFPT_DWORD1_ADDRESS_BYTES_3_OR_4 (0x1UL << 17) -#define BFPT_DWORD1_ADDRESS_BYTES_4_ONLY (0x2UL << 17) -#define BFPT_DWORD1_DTR BIT(19) -#define BFPT_DWORD1_FAST_READ_1_2_2 BIT(20) -#define BFPT_DWORD1_FAST_READ_1_4_4 BIT(21) -#define BFPT_DWORD1_FAST_READ_1_1_4 BIT(22) - -/* 5th DWORD. */ -#define BFPT_DWORD5_FAST_READ_2_2_2 BIT(0) -#define BFPT_DWORD5_FAST_READ_4_4_4 BIT(4) - -/* 11th DWORD. */ -#define BFPT_DWORD11_PAGE_SIZE_SHIFT 4 -#define BFPT_DWORD11_PAGE_SIZE_MASK GENMASK(7, 4) - -/* 15th DWORD. */ - -/* -* (from JESD216 rev B) -* Quad Enable Requirements (QER): -* - 000b: Device does not have a QE bit. Device detects 1-1-4 and 1-4-4 -* reads based on instruction. DQ3/HOLD# functions are hold during -* instruction phase. -* - 001b: QE is bit 1 of status register 2. It is set via Write Status with -* two data bytes where bit 1 of the second byte is one. -* [...] -* Writing only one byte to the status register has the side-effect of -* clearing status register 2, including the QE bit. The 100b code is -* used if writing one byte to the status register does not modify -* status register 2. -* - 010b: QE is bit 6 of status register 1. It is set via Write Status with -* one data byte where bit 6 is one. -* [...] -* - 011b: QE is bit 7 of status register 2. It is set via Write status -* register 2 instruction 3Eh with one data byte where bit 7 is one. -* [...] -* The status register 2 is read using instruction 3Fh. -* - 100b: QE is bit 1 of status register 2. It is set via Write Status with -* two data bytes where bit 1 of the second byte is one. -* [...] -* In contrast to the 001b code, writing one byte to the status -* register does not modify status register 2. -* - 101b: QE is bit 1 of status register 2. Status register 1 is read using -* Read Status instruction 05h. Status register2 is read using -* instruction 35h. QE is set via Writ Status instruction 01h with -* two data bytes where bit 1 of the second byte is one. -* [...] -*/ -#define BFPT_DWORD15_QER_MASK GENMASK(22, 20) -#define BFPT_DWORD15_QER_NONE (0x0UL << 20)/* Micron */ -#define BFPT_DWORD15_QER_SR2_BIT1_BUGGY (0x1UL << 20) -#define BFPT_DWORD15_QER_SR1_BIT6 (0x2UL << 20)/* Macronix */ -#define BFPT_DWORD15_QER_SR2_BIT7 (0x3UL << 20) -#define BFPT_DWORD15_QER_SR2_BIT1_NO_RD (0x4UL << 20) -#define BFPT_DWORD15_QER_SR2_BIT1 (0x5UL << 20)/* Spansion */ - -struct sfdp_bfpt { -u32 dwords[BFPT_DWORD_MAX ]; -}; -/* Fast Read settings. */ static void
Signature · 1 line
2.25.0
PATCH 9/15 mtd: spi-nor-core: Introduce flash-specific fixup hooks
In reply to Pratyush YadavSometimes the information in a flash's SFDP tables is wrong. Sometimes some information just can't be expressed in the SFDP table. So, introduce the fixup hooks to allow tailoring settings for a specific flash.
Three hooks are added: default_init, post_sfdp, and post_bfpt. These allow tweaking the flash settings at different point in the probe sequence. Since the hooks reside in nor->info, set that value just before the call to spi_nor_init_params().
The hooks and at what points they are executed mimics Linux's spi-nor framework.
--- drivers/mtd/spi/sf_internal.h | 3 ++ drivers/mtd/spi/spi-nor-core.c | 70 +++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-)
drivers/mtd/spi/sf_internal.h +3 -0
@@ -67,6 +67,9 @@ struct flash_info {#define USE_CLSR BIT(14)/* use CLSR command */ #define SPI_NOR_HAS_SST26LOCK BIT(15)/* Flash supports lock/unlock via BPR */ #define SPI_NOR_OCTAL_READ BIT(16)/* Flash supports Octal Read */ + +/* Part specific fixup hooks. */ +const struct spi_nor_fixups *fixups; };extern const struct flash_info spi_nor_ids[];
drivers/mtd/spi/spi-nor-core.c +68 -2
118 lines not on this page · raw message
Signature · 1 line
2.25.0
Vignesh Raghavendra
maintainerPATCH 9/15 mtd: spi-nor-core: Introduce flash-specific fixup hooks
Quoted 77 lines · Pratyush Yadav
drivers/mtd/spi/spi-nor-core.c +47
-1@@ -148,6 +148,32 @@ struct sfdp_header {struct sfdp_bfpt {u32 dwords[BFPT_DWORD_MAX ]; }; + +/** +* struct spi_nor_fixups - SPI NOR fixup hooks +* @default_init: called after default flash parameters init. Used to tweak +* 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. +*/ +struct spi_nor_fixups { +void (*default_init)(struct spi_nor *nor); +int (*post_bfpt)(struct spi_nor *nor, +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); +}; +#endif /* SPI_FLASH_SFDP_SUPPORT */ static int spi_nor_read_write_reg(struct spi_nor *nor, struct spi_mem_op@@ -1743,6 +1769,19 @@ static const struct sfdp_bfpt_erase sfdp_bfpt_erases[] = {static int spi_nor_hwcaps_read2cmd (u32 hwcaps); +static int +spi_nor_post_bfpt_fixups (struct spi_nor *nor, +const struct sfdp_parameter_header *bfpt_header, +const struct sfdp_bfpt *bfpt, +struct spi_nor_flash_parameter *params) +{ +if (nor->info->fixups && nor->info->fixups->post_bfpt) +return nor->info->fixups->post_bfpt (nor, bfpt_header, bfpt, + params); + +return 0 ; +} +/** * spi_nor_parse_bfpt() - read and parse the Basic Flash Parameter Table. * @nor: pointer to a 'struct spi_nor' @@ -1914,7 +1953,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,return -EINVAL ; } -return 0 ; +return spi_nor_post_bfpt_fixups (nor, bfpt_header, &bfpt, params); }/** @@ -2074,6 +2113,29 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor, }#endif /* SPI_FLASH_SFDP_SUPPORT */ +/** +* spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings +* after SFDP has been parsed (is also called for SPI NORs that do not +* support RDSFDP). +* @nor: pointer to a 'struct spi_nor' +* +* Typically used to tweak various parameters that could not be extracted by
drivers/mtd/spi/spi-nor-core.c static int spi_nor_parse_sfdp(struct spi_nor *nor, · line 2132
Quoted 10 lines
drivers/mtd/spi/spi-nor-core.c +10
-0+* other means (i.e. when information provided by the SFDP/flash_info tables +* are incomplete or wrong). +*/ +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) + nor->info->fixups->post_sfdp (nor, params); +} +
This would cause build failure as spi_nor_fixups is only available when SFDP support is enabled:
drivers/mtd/spi/spi-nor-core.c: In function ?spi_nor_post_sfdp_fixups?:drivers/mtd/spi/spi-nor-core.c:2280:44: error: dereferencing pointer to incomplete type ?const struct spi_nor_fixups?
2280 | if (nor->info->fixups && nor->info->fixups->post_sfdp)
May be move all definitions of out the #ifdef
Regards
Vignesh
PATCH 9/15 mtd: spi-nor-core: Introduce flash-specific fixup hooks
Quoted 94 lines · Vignesh Raghavendra
Quoted 77 lines · Pratyush Yadav
drivers/mtd/spi/spi-nor-core.c +47
-1@@ -148,6 +148,32 @@ struct sfdp_header {struct sfdp_bfpt {u32 dwords[BFPT_DWORD_MAX ]; }; + +/** +* struct spi_nor_fixups - SPI NOR fixup hooks +* @default_init: called after default flash parameters init. Used to tweak +* 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. +*/ +struct spi_nor_fixups { +void (*default_init)(struct spi_nor *nor); +int (*post_bfpt)(struct spi_nor *nor, +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); +}; +#endif /* SPI_FLASH_SFDP_SUPPORT */ static int spi_nor_read_write_reg(struct spi_nor *nor, struct spi_mem_op@@ -1743,6 +1769,19 @@ static const struct sfdp_bfpt_erase sfdp_bfpt_erases[] = {static int spi_nor_hwcaps_read2cmd (u32 hwcaps); +static int +spi_nor_post_bfpt_fixups (struct spi_nor *nor, +const struct sfdp_parameter_header *bfpt_header, +const struct sfdp_bfpt *bfpt, +struct spi_nor_flash_parameter *params) +{ +if (nor->info->fixups && nor->info->fixups->post_bfpt) +return nor->info->fixups->post_bfpt (nor, bfpt_header, bfpt, + params); + +return 0 ; +} +/** * spi_nor_parse_bfpt() - read and parse the Basic Flash Parameter Table. * @nor: pointer to a 'struct spi_nor' @@ -1914,7 +1953,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,return -EINVAL ; } -return 0 ; +return spi_nor_post_bfpt_fixups (nor, bfpt_header, &bfpt, params); }/** @@ -2074,6 +2113,29 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor, }#endif /* SPI_FLASH_SFDP_SUPPORT */ +/** +* spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings +* after SFDP has been parsed (is also called for SPI NORs that do not +* support RDSFDP). +* @nor: pointer to a 'struct spi_nor' +* +* Typically used to tweak various parameters that could not be extracted by drivers/mtd/spi/spi-nor-core.c static int spi_nor_parse_sfdp(struct spi_nor *nor, · line 2132
Quoted 10 lines
drivers/mtd/spi/spi-nor-core.c +10
-0+* other means (i.e. when information provided by the SFDP/flash_info tables +* are incomplete or wrong). +*/ +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) + nor->info->fixups->post_sfdp (nor, params); +} +This would cause build failure as
spi_nor_fixupsis only available when SFDP support is enabled:
Quoted 5 lines
drivers/mtd/spi/spi-nor-core.c: In function ?spi_nor_post_sfdp_fixups?:drivers/mtd/spi/spi-nor-core.c:2280:44: error: dereferencing pointer to incomplete type ?const structspi_nor_fixups?
2280 | if (nor->info->fixups&&nor->info->fixups->post_sfdp)May be move all definitions of out the #ifdef
Thanks for catching this. Will fix.
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments India
PATCH 10/15 mtd: spi-nor-core: Add support for DTR protocol
In reply to Pratyush YadavDouble Transfer Rate (DTR) is SPI protocol in which data is transferred on each clock edge as opposed to on each clock cycle. Make framework-level changes to allow supporting flashes in DTR mode.
Right now, mixed DTR modes are not supported. So, for example a mode like 4S-4D-4D will not work. All phases need to be either DTR or STR.
--- drivers/mtd/spi/sf_internal.h | 1 + drivers/mtd/spi/spi-nor-core.c | 90 ++++++++++++++++++++++++++++------ include/linux/mtd/spi-nor.h | 32 +++++++----- 3 files changed, 95 insertions(+), 28 deletions(-)
drivers/mtd/spi/sf_internal.h +1 -0
@@ -67,6 +67,7 @@ struct flash_info {#define USE_CLSR BIT(14)/* use CLSR command */ #define SPI_NOR_HAS_SST26LOCK BIT(15)/* Flash supports lock/unlock via BPR */ #define SPI_NOR_OCTAL_READ BIT(16)/* Flash supports Octal Read */ +#define SPI_NOR_OCTAL_DTR_READ BIT(17)/* Flash supports Octal DTR Read */ /* Part specific fixup hooks. */ const struct spi_nor_fixups *fixups;
drivers/mtd/spi/spi-nor-core.c +74 -16
185 lines not on this page · raw message
include/linux/mtd/spi-nor.h +20 -12
@@ -10,6 +10,7 @@#include <linux/bitops.h> #include <linux/mtd/cfi.h> #include <linux/mtd/mtd.h> +#include <spi-mem.h> /* * Manufacturer IDs
@@ -199,6 +200,7 @@ enum spi_nor_protocol {SNOR_PROTO_1_2_2_DTR =SNOR_PROTO_DTR (1 ,2 ,2 ),SNOR_PROTO_1_4_4_DTR =SNOR_PROTO_DTR (1 ,4 ,4 ),SNOR_PROTO_1_8_8_DTR =SNOR_PROTO_DTR (1 ,8 ,8 ), + SNOR_PROTO_8_8_8_DTR = SNOR_PROTO_DTR(8, 8, 8), };static inline bool spi_nor_protocol_is_dtr (enum spi_nor_protocol proto)
@@ -266,7 +268,7 @@ struct spi_nor_hwcaps {* then Quad SPI protocols before Dual SPI protocols, Fast Read and lastly * (Slow) Read. */ -#define SNOR_HWCAPS_READ_MASK GENMASK(14, 0) +#define SNOR_HWCAPS_READ_MASK GENMASK(15, 0)#define SNOR_HWCAPS_READ BIT(0)#define SNOR_HWCAPS_READ_FAST BIT(1)#define SNOR_HWCAPS_READ_1_1_1_DTR BIT(2)
@@ -283,11 +285,12 @@ struct spi_nor_hwcaps {#define SNOR_HWCAPS_READ_4_4_4 BIT(9)#define SNOR_HWCAPS_READ_1_4_4_DTR BIT(10) -#define SNOR_HWCPAS_READ_OCTO GENMASK(14, 11) +#define SNOR_HWCPAS_READ_OCTO GENMASK(15, 11)#define SNOR_HWCAPS_READ_1_1_8 BIT(11)#define SNOR_HWCAPS_READ_1_8_8 BIT(12)#define SNOR_HWCAPS_READ_8_8_8 BIT(13)#define SNOR_HWCAPS_READ_1_8_8_DTR BIT(14) +#define SNOR_HWCAPS_READ_8_8_8_DTR BIT(15)/* * Page Program capabilities.
@@ -298,18 +301,19 @@ struct spi_nor_hwcaps {* JEDEC/SFDP standard to define them. Also at this moment no SPI flash memory * implements such commands. */ -#define SNOR_HWCAPS_PP_MASK GENMASK(22, 16) -#define SNOR_HWCAPS_PP BIT(16) +#define SNOR_HWCAPS_PP_MASK GENMASK(23, 16) +#define SNOR_HWCAPS_PP BIT(16) -#define SNOR_HWCAPS_PP_QUAD GENMASK(19, 17) -#define SNOR_HWCAPS_PP_1_1_4 BIT(17) -#define SNOR_HWCAPS_PP_1_4_4 BIT(18) -#define SNOR_HWCAPS_PP_4_4_4 BIT(19) +#define SNOR_HWCAPS_PP_QUAD GENMASK(19, 17) +#define SNOR_HWCAPS_PP_1_1_4 BIT(17) +#define SNOR_HWCAPS_PP_1_4_4 BIT(18) +#define SNOR_HWCAPS_PP_4_4_4 BIT(19) -#define SNOR_HWCAPS_PP_OCTO GENMASK(22, 20) -#define SNOR_HWCAPS_PP_1_1_8 BIT(20) -#define SNOR_HWCAPS_PP_1_8_8 BIT(21) -#define SNOR_HWCAPS_PP_8_8_8 BIT(22) +#define SNOR_HWCAPS_PP_OCTO GENMASK(23, 20) +#define SNOR_HWCAPS_PP_1_1_8 BIT(20) +#define SNOR_HWCAPS_PP_1_8_8 BIT(21) +#define SNOR_HWCAPS_PP_8_8_8 BIT(22) +#define SNOR_HWCAPS_PP_8_8_8_DTR BIT(23)struct spi_nor_read_command {u8 num_mode_clocks;
@@ -345,6 +349,7 @@ enum spi_nor_read_command_index {SNOR_CMD_READ_1_8_8 ,SNOR_CMD_READ_8_8_8 ,SNOR_CMD_READ_1_8_8_DTR , +SNOR_CMD_READ_8_8_8_DTR , SNOR_CMD_READ_MAX };
@@ -361,6 +366,7 @@ enum spi_nor_pp_command_index {SNOR_CMD_PP_1_1_8 ,SNOR_CMD_PP_1_8_8 ,SNOR_CMD_PP_8_8_8 , +SNOR_CMD_PP_8_8_8_DTR , SNOR_CMD_PP_MAX };
@@ -413,6 +419,7 @@ struct flash_info;* @write_proto: the SPI protocol for write operations * @reg_proto the SPI protocol for read_reg/write_reg/erase operations * @cmd_buf: used by the write_reg +* @cmd_ext: the command opcode extension for DTR mode. * @prepare: [OPTIONAL] do some preparations for the * read/write/erase/lock/unlock operations * @unprepare: [OPTIONAL] do some post work after the
@@ -454,6 +461,7 @@ struct spi_nor {bool sst_write_second;u32 flags;u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE ]; +enum spi_mem_cmd_ext cmd_ext; int (*setup)(struct spi_nor *nor, const struct flash_info *info, const struct spi_nor_flash_parameter *params,
Signature · 1 line
2.25.0
PATCH 11/15 mtd: spi-nor-core: Get command opcode extension type from BFPT
In reply to Pratyush YadavSome devices in DTR mode expect an extra command byte called the extension. The extension can either be same as the opcode, bitwise inverse of the opcode, or another additional byte forming a 16-byte opcode. Get the extension type from the BFPT. For now, only flashes with "repeat" and "inverse" extensions are supported.
As of JESD216D.01, BFPT is 20 DWORDs, so update the table size to reflect that.
--- drivers/mtd/spi/spi-nor-core.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-)
drivers/mtd/spi/spi-nor-core.c +26 -2
@@ -76,11 +76,11 @@ struct sfdp_header {/* Basic Flash Parameter Table */ /* -* JESD216 rev B defines a Basic Flash Parameter Table of 16 DWORDs. +* JESD216 rev D defines a Basic Flash Parameter Table of 20 DWORDs. * They are indexed from 1 but C arrays are indexed from 0. */ #define BFPT_DWORD (i) ((i) - 1) -#define BFPT_DWORD_MAX 16 +#define BFPT_DWORD_MAX 20/* The first version of JESB216 defined only 9 DWORDs. */ #define BFPT_DWORD_MAX_JESD216 9
@@ -145,6 +145,12 @@ struct sfdp_header {#define BFPT_DWORD15_QER_SR2_BIT1_NO_RD (0x4UL << 20)#define BFPT_DWORD15_QER_SR2_BIT1 (0x5UL << 20)/* Spansion */ +#define BFPT_DWORD18_CMD_EXT_MASK GENMASK(30, 29) +#define BFPT_DWORD18_CMD_EXT_REP (0x0UL << 29)/* Repeat */ +#define BFPT_DWORD18_CMD_EXT_INV (0x1UL << 29)/* Invert */ +#define BFPT_DWORD18_CMD_EXT_RES (0x2UL << 29)/* Reserved */ +#define BFPT_DWORD18_CMD_EXT_16B (0x3UL << 29)/* 16-bit opcode */ +struct sfdp_bfpt {u32 dwords[BFPT_DWORD_MAX ]; };
@@ -1993,6 +1999,24 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,return -EINVAL ; } +/* 8D-8D-8D command extension. */ +switch (bfpt.dwords[BFPT_DWORD (18 )] &BFPT_DWORD18_CMD_EXT_MASK ) { +case BFPT_DWORD18_CMD_EXT_REP : + nor->cmd_ext =SPI_MEM_EXT_REPEAT ; +break ; + +case BFPT_DWORD18_CMD_EXT_INV : + nor->cmd_ext =SPI_MEM_EXT_INVERT ; +break ; + +case BFPT_DWORD18_CMD_EXT_RES : +return -EINVAL ; + +case BFPT_DWORD18_CMD_EXT_16B : +dev_err (nor->dev,"16-bit opcodes not supported\n" ); +return -ENOTSUPP ; + } +return spi_nor_post_bfpt_fixups (nor, bfpt_header, &bfpt, params); }
Signature · 1 line
2.25.0
PATCH 12/15 mtd: spi-nor-core: Parse xSPI Profile 1.0 table
In reply to Pratyush YadavThis table is indication that the flash is xSPI compliant and hence supports octal DTR mode. Extract information like the fast read opcode, the number of dummy cycles needed for a Read Status Register command, and the number of address bytes needed for a Read Status Register command.
The default dummy cycles for a fast octal DTR read are set to 20. Since there is no simple way of determining the dummy cycles needed for the fast read command, flashes that use a different value should update it in their flash-specific hooks.
--- drivers/mtd/spi/spi-nor-core.c | 81 ++++++++++++++++++++++++++++++++++ include/linux/mtd/spi-nor.h | 7 +++ 2 files changed, 88 insertions(+)
drivers/mtd/spi/spi-nor-core.c +81 -0
@@ -17,6 +17,7 @@#include <linux/log2.h> #include <linux/math64.h> #include <linux/sizes.h> +#include <linux/bitfield.h> #include <linux/mtd/mtd.h> #include <linux/mtd/spi-nor.h>
@@ -55,6 +56,7 @@ struct sfdp_parameter_header {#define SFDP_BFPT_ID 0xff00/* Basic Flash Parameter Table */ #define SFDP_SECTOR_MAP_ID 0xff81/* Sector Map Table */ #define SFDP_SST_ID 0x01bf/* Manufacturer specific Table */ +#define SFDP_PROFILE1_ID 0xff05/* xSPI Profile 1.0 Table */ #define SFDP_SIGNATURE 0x50444653U#define SFDP_JESD216_MAJOR 1
@@ -151,6 +153,11 @@ struct sfdp_header {#define BFPT_DWORD18_CMD_EXT_RES (0x2UL << 29)/* Reserved */ #define BFPT_DWORD18_CMD_EXT_16B (0x3UL << 29)/* 16-bit opcode */ +/* xSPI Profile 1.0 table (from JESD216D.01). */ +#define PROFILE1_DWORD1_RD_FAST_CMD GENMASK(15, 8) +#define PROFILE1_DWORD1_RDSR_DUMMY BIT(28) +#define PROFILE1_DWORD1_RDSR_ADDR_BYTES BIT(29) +struct sfdp_bfpt {u32 dwords[BFPT_DWORD_MAX ]; };
@@ -2020,6 +2027,74 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,return spi_nor_post_bfpt_fixups (nor, bfpt_header, &bfpt, params); } +/** +* spi_nor_parse_profile1() - parse the xSPI Profile 1.0 table +* @nor: pointer to a 'struct spi_nor' +* @param_header: pointer to the 'struct sfdp_parameter_header' describing +* the 4-Byte Address Instruction Table length and version. +* @params: pointer to the 'struct spi_nor_flash_parameter' to be. +* +* Return: 0 on success, -errno otherwise. +*/ +static int spi_nor_parse_profile1 (struct spi_nor *nor, +const struct sfdp_parameter_header *profile1_header, +struct spi_nor_flash_parameter *params) +{ +u32 *table, opcode, addr; +size_t len; +int ret, i; + + len = profile1_header->length *sizeof (*table); + table =kmalloc (len,GFP_KERNEL ); +if (!table) +return -ENOMEM ; + + addr =SFDP_PARAM_HEADER_PTP (profile1_header); + ret =spi_nor_read_sfdp (nor, addr, len, table); +if (ret) + goto out; + +/* Fix endianness of the table DWORDs. */ +for (i =0 ; i < profile1_header->length; i++) + table[i] =le32_to_cpu (table[i]); + +/* Get 8D-8D-8D fast read opcode and dummy cycles. */ + opcode =FIELD_GET (PROFILE1_DWORD1_RD_FAST_CMD , table[0 ]); + +/* +* Update the fast read settings. We set the default dummy cycles to 20 +* here. Flashes can change this value if they need to when enabling +* octal mode. +*/ + params->hwcaps.mask |=SNOR_HWCAPS_READ_8_8_8_DTR ; +spi_nor_set_read_settings (¶ms->reads[SNOR_CMD_READ_8_8_8_DTR ], +0 ,20 , opcode, +SNOR_PROTO_8_8_8_DTR ); + +/* +* Since the flash supports xSPI DTR reads, it should also support DTR +* Page Program opcodes. +*/ + params->hwcaps.mask |=SNOR_HWCAPS_PP_8_8_8_DTR ; + +/* +* Set the Read Status Register dummy cycles and dummy address bytes. +*/ +if (table[0 ] &PROFILE1_DWORD1_RDSR_DUMMY ) + params->rdsr_dummy =8 ; +else + params->rdsr_dummy =4 ; + +if (table[0 ] &PROFILE1_DWORD1_RDSR_ADDR_BYTES ) + params->rdsr_addr_nbytes =4 ; +else + params->rdsr_addr_nbytes =0 ; + +out: +kfree (table); +return ret; +} +/** * spi_nor_parse_microchip_sfdp() - parse the Microchip manufacturer specific * SFDP table.
@@ -2148,6 +2223,10 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor, err =spi_nor_parse_microchip_sfdp (nor, param_header);break ; +case SFDP_PROFILE1_ID : + err =spi_nor_parse_profile1 (nor, param_header, params); +break ; +default :break ; }
@@ -2720,6 +2799,8 @@ int spi_nor_scan(struct spi_nor *nor)if (ret)return ret; + nor->rdsr_dummy = params.rdsr_dummy; + nor->rdsr_addr_nbytes = params.rdsr_addr_nbytes; nor->name = mtd->name; nor->size = mtd->size; nor->erase_size = mtd->erasesize;
include/linux/mtd/spi-nor.h +7 -0
@@ -374,6 +374,8 @@ enum spi_nor_pp_command_index {struct spi_nor_flash_parameter {u64 size;u32 page_size; +u8 rdsr_dummy; +u8 rdsr_addr_nbytes;struct spi_nor_hwcaps hwcaps;struct spi_nor_read_command reads[SNOR_CMD_READ_MAX ];
@@ -410,6 +412,9 @@ struct flash_info;* @read_opcode: the read opcode * @read_dummy: the dummy needed by the read operation * @program_opcode: the program opcode +* @rdsr_dummy dummy cycles needed for Read Status Register command. +* @rdsr_addr_nbytes: dummy address bytes needed for Read Status Register +* command. * @bank_read_cmd: Bank read cmd * @bank_write_cmd: Bank write cmd * @bank_curr: Current flash bank
@@ -450,6 +455,8 @@ struct spi_nor {u8 read_opcode;u8 read_dummy;u8 program_opcode; +u8 rdsr_dummy; +u8 rdsr_addr_nbytes;#ifdef CONFIG_SPI_FLASH_BAR u8 bank_read_cmd;u8 bank_write_cmd;
Signature · 1 line
2.25.0
PATCH 13/15 mtd: spi-nor-core: Use Read SR dummy cycle and address width from SFDP
In reply to Pratyush YadavThe xSPI Profile 1.0 table specifies how many dummy cycles and address bytes are needed for the Read Status Register command in octal DTR mode. Use that information to send the correct Read SR command.
--- drivers/mtd/spi/spi-nor-core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/mtd/spi/spi-nor-core.c +9 -1
@@ -340,8 +340,16 @@ static int read_sr(struct spi_nor *nor) {int ret;u8 val; +u8 addr_nbytes = nor->rdsr_addr_nbytes; +u8 dummy = nor->rdsr_dummy; +struct spi_mem_op op =SPI_MEM_OP (SPI_MEM_OP_CMD (SPINOR_OP_RDSR ,1 ), +SPI_MEM_OP_ADDR (addr_nbytes,0 ,1 ), +SPI_MEM_OP_DUMMY (dummy,1 ), +SPI_MEM_OP_DATA_IN (1 ,NULL ,1 )); - ret = nor->read_reg (nor,SPINOR_OP_RDSR , &val,1 ); +spi_nor_setup_op (nor, &op, nor->reg_proto); + + ret =spi_nor_read_write_reg (nor, &op, &val);if (ret <0 ) {pr_debug ("error %d reading SR\n" , (int )ret);return ret;
Signature · 1 line
2.25.0
PATCH 14/15 mtd: spi-nor-core: Enable octal DTR mode when possible
In reply to Pratyush YadavAllow flashes to specify a hook to enable octal DTR mode. Use this hook whenever possible to get optimal transfer speeds.
--- drivers/mtd/spi/spi-nor-core.c | 31 +++++++++++++++++++++++++++++++ include/linux/mtd/spi-nor.h | 2 ++ 2 files changed, 33 insertions(+)
drivers/mtd/spi/spi-nor-core.c +31 -0
@@ -2597,10 +2597,41 @@ static int spi_nor_setup(struct spi_nor *nor, const struct flash_info *info,return nor->setup (nor, info, params, hwcaps); } +/** spi_nor_octal_dtr_enable() - enable Octal DTR I/O if needed +* @nor: pointer to a 'struct spi_nor' +* +* Return: 0 on success, -errno otherwise. +*/ +static int spi_nor_octal_dtr_enable (struct spi_nor *nor) +{ +int ret; + +if (!nor->octal_dtr_enable) +return 0 ; + +if (!(spi_nor_get_protocol_width (nor->read_proto) ==8 || +spi_nor_get_protocol_width (nor->write_proto) ==8 )) +return 0 ; + + ret = nor->octal_dtr_enable (nor); +if (ret) +return ret; + + nor->reg_proto =SNOR_PROTO_8_8_8_DTR ; + +return 0 ; +} +static int spi_nor_init (struct spi_nor *nor) {int err; + err =spi_nor_octal_dtr_enable (nor); +if (err) { +dev_dbg (nor->dev,"Octal DTR mode not supported\n" ); +return err; + } +/* * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up * with the software protection bits set
include/linux/mtd/spi-nor.h +2 -0
@@ -441,6 +441,7 @@ struct flash_info;* @flash_is_locked: [FLASH-SPECIFIC] check if a region of the SPI NOR is * @quad_enable: [FLASH-SPECIFIC] enables SPI NOR quad mode * completely locked +* @octal_dtr_enable: [FLASH-SPECIFIC] enables SPI NOR octal DTR mode. * @priv: the private data */ struct spi_nor {
@@ -488,6 +489,7 @@ struct spi_nor {int (*flash_unlock)(struct spi_nor *nor,loff_t ofs,uint64_t len);int (*flash_is_locked)(struct spi_nor *nor,loff_t ofs,uint64_t len);int (*quad_enable)(struct spi_nor *nor); +int (*octal_dtr_enable)(struct spi_nor *nor);void *priv;/* Compatibility for spi_flash, remove once sf layer is merged with mtd */
Signature · 1 line
2.25.0
PATCH 15/15 mtd: spi-nor-core: Add support for Cypress Semper flash
In reply to Pratyush YadavThe Cypress Semper flash is an xSPI compliant octal DTR flash. Add support for using it in octal DTR mode.
The flash by default boots in a hybrid sector mode. Switch to uniform sector mode on boot. Use the default 20 dummy cycles for a read fast command.
The SFDP programming on some older versions of the flash was incorrect. Fixes for that are included in the fixup hooks.
--- drivers/mtd/spi/sf_internal.h | 4 + drivers/mtd/spi/spi-nor-core.c | 188 +++++++++++++++++++++++++++++++++ drivers/mtd/spi/spi-nor-ids.c | 1 + include/linux/mtd/spi-nor.h | 14 +++ 4 files changed, 207 insertions(+)
drivers/mtd/spi/sf_internal.h +4 -0
@@ -75,6 +75,10 @@ struct flash_info {extern const struct flash_info spi_nor_ids[]; +#ifdef CONFIG_SPI_FLASH_SPANSION +extern struct spi_nor_fixups s28hs512t_fixups; +#endif +#define JEDEC_MFR (info) ((info)->id[0])#define JEDEC_ID (info) (((info)->id[1]) << 8 | ((info)->id[2]))
drivers/mtd/spi/spi-nor-core.c +188 -0
194 lines not on this page · raw message
drivers/mtd/spi/spi-nor-ids.c +1 -0
@@ -211,6 +211,7 @@ const struct flash_info spi_nor_ids[] = { { INFO("s25fl208k", 0x014014, 0, 64 * 1024, 16, SECT_4K | SPI_NOR_DUAL_READ) }, { INFO("s25fl064l", 0x016017, 0, 64 * 1024, 128, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) }, { INFO("s25fl128l", 0x016018, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) }, + { INFO("s28hs512t", 0x345b1a, 0, 256 * 1024, 256, SPI_NOR_OCTAL_DTR_READ) .fixups = &s28hs512t_fixups }, #endif #ifdef CONFIG_SPI_FLASH_SST /* SST */ /* SST -- large erase sizes are "overlays", "sectors" are 4K */
include/linux/mtd/spi-nor.h +14 -0
@@ -155,6 +155,20 @@/* Status Register 2 bits. */ #define SR2_QUAD_EN_BIT7 BIT(7) +/* For Cypress flash. */ +#define SPINOR_OP_RD_ANY_REG 0x65/* Read any register */ +#define SPINOR_OP_WR_ANY_REG 0x71/* Write any register */ +#define SPINOR_REG_CYPRESS_CFR2V 0x00800003 +#define SPINOR_REG_CYPRESS_CFR2V_MEMLAT_8_20 0x8 +#define SPINOR_REG_CYPRESS_CFR3N 0x00000004 +#define SPINOR_REG_CYPRESS_CFR3V 0x00800004 +#define SPINOR_REG_CYPRESS_CFR3V_PGSZ BIT(4)/* Page size. */ +#define SPINOR_REG_CYPRESS_CFR3N_UNISECT BIT(3)/* Uniform sector mode */ +#define SPINOR_REG_CYPRESS_CFR4V 0x00800005 +#define SPINOR_REG_CYPRESS_CFR5V 0x00800006 +#define SPINOR_REG_CYPRESS_CFR5V_OCT_DTR_EN 0x3 +#define SPINOR_OP_CYPRESS_RD_FAST 0xee +/* Supported SPI protocols */ #define SNOR_PROTO_INST_MASK GENMASK(23, 16)#define SNOR_PROTO_INST_SHIFT 16
Signature · 1 line
2.25.0
[NOT FOR MERGE PATCH 16/15] arm: dts: k3-j721e: Update OSPI settings for octal DTR mode
In reply to Pratyush YadavThe Cypress Semper flash supports octal DTR mode, so update the device tree settings to use 8 data lines for both Rx and Tx and allow using DTR mode on both lines.
The read delay is set to 4. The calibration sequence yields a value of 2 but since the sequence is run before the flash is switched to octal DTR mode, it gets that value for legacy mode. In octal DTR mode the flash needs a read delay of 4. Setting read delay here over-rides the calibrated value.
---
These are the DT changes made on top of u-boot-ti/next to test these changes.
arch/arm/dts/k3-j721e-som-p0.dtsi | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
arch/arm/dts/k3-j721e-som-p0.dtsi +5 -3
@@ -85,14 +85,16 @@ flash at 0{ compatible = "jedec,spi-nor"; reg = <0x0>; - spi-tx-bus-width = <1>; + spi-tx-bus-width = <8>; spi-rx-bus-width = <8>; - spi-max-frequency = <40000000>; + spi-tx-dtr = <1>; + spi-rx-dtr = <1>; + spi-max-frequency = <25000000>; cdns,tshsl-ns = <60>; cdns,tsd2d-ns = <60>; cdns,tchsh-ns = <60>; cdns,tslch-ns = <60>; - cdns,read-delay = <0>; + cdns,read-delay = <4>; #address-cells = <1>; #size-cells = <1>; };
--
2.25.0