SPI-NOR/MTD addition
Subsystems (5)
v8 cover SPI-NOR/MTD addition
On-top-of u-boot-spi/next,
The previous series [1] [2] are added SPI-NOR on top of mtd/spi where it bypassing DM_SPI_FLASH and use the existing mtd core (which is non-dm), I feel this is moving in a reverse direction where adding new feature with the help of non-dm mtd core support and also few of the spi drivers are not fully dm-driven.
So this new design will keep the mtd/spi as it is and start adding spi-nor features separately. The idea here is to add the dm features
to MTD first and then add UCLASS_MTD spi-nor drivers so-that the commands are interfacing to spi-nor through dm-driven MTD core to spi-nor.
And this could also be a generic solutions for all MTD flash's like NAND, NOR and etc.
About this series:
------------------------------
cmd_sf.c
------------------------------
mtd-uclass
-------------------------------
SPI-NOR Core
-------------------------------m25p80.c zynq_qspi
-------------------------------
spi-uclass SPI NOR chip
-------------------------------
spi drivers
-------------------------------
SPI NOR chip
-------------------------------
drivers/mtd/spi-nor/
- Add dm mtd operations
- spi-nor.c: Add basic SPI-NOR core like erase/read/write ops and lock's will add later
- m25p80.c: spi-nor to spi divers interface layer drivers/spi-nor
- zynq_qspi.c: zynq qspi spi-nor controller driver.
CONFIG_SPI_FLASH_BAR and DUAL_FLASH code shouldn't be part of spi-nor core as these are strictly controller features. and 4-byte address width in spi-nor will handle > 16MiB flash devices.
What need to be add:
1) 'sf probe' interface:
Need to probe the chips in two directions A) one is for direct spi-nor driver (zynq_qspi here) and other B) one is for interface driver(m25p80.c). the later is bit tricky as it will also probe the UCLASS_SPI.
A)
qspi1: spi at e000d000 {
compatible = "xlnx,zynq-qspi-1.0";
status = "disabled";
}; B)
spi0: spi at e0006000 {
compatible = "xlnx,zynq-spi-r1p6";
status = "disabled";
}; alias {
mtd0 = &qspi1;
spi1 = &spi0;};
2) sf env:
same as 1)
Any ideas about this probe interface are 'Welcome'
[1] http://lists.denx.de/pipermail/u-boot/2016-March/249286.html
[2] http://lists.denx.de/pipermail/u-boot/2016-February/245418.html
Jagan Teki (16):
dm: mtd: Add dm mtd core ops
mtd: Add SPI-NOR core support
mtd: spi-nor: Kconfig: Add MTD_SPI_NOR entry
mtd: spi-nor: Kconfig: Add MTD_SPI_NOR_USE_4K_SECTORS
mtd: spi-nor: Kconfig: Add SPI_NOR_MISC entry
mtd: spi-nor: Kconfig: Add SPI_NOR_MACRONIX entry
mtd: spi-nor: Kconfig: Add SPI_NOR_SPANSION entry
mtd: spi-nor: Kconfig: Add SPI_NOR_STMICRO entry
mtd: spi-nor: Kconfig: Add SPI_NOR_SST entry
mtd: spi-nor: Kconfig: Add SPI_NOR_WINBOND entry
spi: Add spi_write_then_read
mtd: spi-nor: Add m25p80 driver
mtd: spi-nor: Kconfig: Add MTD_M25P80 entry
mtd: spi-nor: Add zynq qspi driver
mtd: spi-nor: zynq_qspi: Kconfig: Add MTD_ZYNQ
mtd: spi-nor: Add 4-byte address width support
Makefile | 1 + drivers/mtd/Kconfig | 2 + drivers/mtd/mtd-uclass.c | 72 ++++ drivers/mtd/spi-nor/Kconfig | 89 +++++ drivers/mtd/spi-nor/Makefile | 15 + drivers/mtd/spi-nor/m25p80.c | 218 ++++++++++++ drivers/mtd/spi-nor/spi-nor-ids.c | 176 ++++++++++ drivers/mtd/spi-nor/spi-nor.c | 685 ++++++++++++++++++++++++++++++++++++++ drivers/mtd/spi-nor/zynq_qspi.c | 638 +++++++++++++++++++++++++++++++++++ drivers/spi/spi-uclass.c | 24 ++ include/linux/err.h | 5 + include/linux/mtd/mtd.h | 58 ++++ include/linux/mtd/spi-nor.h | 211 ++++++++++++ include/spi.h | 20 ++ 14 files changed, 2214 insertions(+) create mode 100644 drivers/mtd/spi-nor/Kconfig create mode 100644 drivers/mtd/spi-nor/Makefile create mode 100644 drivers/mtd/spi-nor/m25p80.c create mode 100644 drivers/mtd/spi-nor/spi-nor-ids.c create mode 100644 drivers/mtd/spi-nor/spi-nor.c create mode 100644 drivers/mtd/spi-nor/zynq_qspi.c create mode 100644 include/linux/mtd/spi-nor.h
Signature · 1 line
2.7.4
RFC PATCH v8 1/16 dm: mtd: Add dm mtd core ops
- Add generic dm_mtd operations
- Add mtd_read|erase|write_dm
- Add add_mtd_device_dm
The respetive MTD_UCLASS drivers must install the hooks to these dm_mtd_ops and other core ops are act as a interface b/w drivers vs command code.
--- drivers/mtd/mtd-uclass.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/mtd.h | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+)
drivers/mtd/mtd-uclass.c +72 -0
@@ -1,4 +1,5 @@/* +* Copyright (C) 2016 Jagan Teki <[email protected]> * Copyright (C) 2015 Thomas Chou <[email protected]> * * SPDX-License-Identifier: GPL-2.0+
@@ -8,6 +9,77 @@#include <dm.h> #include <errno.h> #include <mtd.h> +#include <linux/log2.h> + +int mtd_read_dm (struct udevice *dev,loff_t from,size_t len,size_t *retlen, +u_char *buf) +{ +struct mtd_info *mtd =mtd_get_info (dev); + + *retlen =0 ; +if (from <0 || from > mtd->size || len > mtd->size - from) +return -EINVAL ; +if (!len) +return 0 ; + +return mtd_get_ops (dev)->_read (dev, from, len, retlen, buf); +} + +int mtd_erase_dm (struct udevice *dev,struct erase_info *instr) +{ +struct mtd_info *mtd =mtd_get_info (dev); + +if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr) +return -EINVAL ; +if (!(mtd->flags &MTD_WRITEABLE )) +return -EROFS ; + instr->fail_addr =MTD_FAIL_ADDR_UNKNOWN ; +if (!instr->len) { + instr->state =MTD_ERASE_DONE ; +return 0 ; + } + +return mtd_get_ops (dev)->_erase (dev, instr); +} + +int mtd_write_dm (struct udevice *dev,loff_t to,size_t len,size_t *retlen, +const u_char *buf) +{ +struct mtd_info *mtd =mtd_get_info (dev); + + *retlen =0 ; +if (to <0 || to > mtd->size || len > mtd->size - to) +return -EINVAL ; +if (!mtd->_write || !(mtd->flags &MTD_WRITEABLE )) +return -EROFS ; +if (!len) +return 0 ; + +return mtd_get_ops (dev)->_write (dev, to, len, retlen, buf); +} + +int add_mtd_device_dm (struct udevice *dev) +{ +struct mtd_info *mtd =mtd_get_info (dev); + +BUG_ON (mtd->writesize ==0 ); + mtd->usecount =0 ; + +if (is_power_of_2 (mtd->erasesize)) + mtd->erasesize_shift =ffs (mtd->erasesize) -1 ; +else + mtd->erasesize_shift =0 ; + +if (is_power_of_2 (mtd->writesize)) + mtd->writesize_shift =ffs (mtd->writesize) -1 ; +else + mtd->writesize_shift =0 ; + + mtd->erasesize_mask = (1 << mtd->erasesize_shift) -1 ; + mtd->writesize_mask = (1 << mtd->writesize_shift) -1 ; + +return 0 ; +}/* * Implement a MTD uclass which should include most flash drivers.
include/linux/mtd/mtd.h +58 -0
62 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH v8 2/16 mtd: Add SPI-NOR core support
In reply to Jagan TekiSome of the SPI device drivers at drivers/spi not a real spi controllers, Unlike normal/generic SPI controllers they operates only with SPI-NOR flash devices. these were technically termed as SPI-NOR controllers, Ex: drivers/spi/fsl_qspi.c
The problem with these were resides at drivers/spi is entire SPI layer becomes SPI-NOR flash oriented which is absolutely a wrong indication where SPI layer getting effected more with flash operations - So this SPI-NOR core will resolve this issue by separating all SPI-NOR flash operations from spi layer and creats a generic layer called SPI-NOR core which can be used to interact SPI-NOR to SPI driver interface layer and the SPI-NOR controller driver. The idea is taken from Linux spi-nor framework.
------------------------------
cmd_sf.c
------------------------------
mtd-uclass
-------------------------------
SPI-NOR Core
-------------------------------m25p80.c zynq_qspi
-------------------------------
spi-uclass SPI NOR chip
-------------------------------
spi drivers
-------------------------------
SPI NOR chip
-------------------------------
--- Makefile | 1 + drivers/mtd/spi-nor/Makefile | 9 + drivers/mtd/spi-nor/spi-nor-ids.c | 176 +++++++++++ drivers/mtd/spi-nor/spi-nor.c | 649 ++++++++++++++++++++++++++++++++++++++ include/linux/err.h | 5 + include/linux/mtd/spi-nor.h | 207 ++++++++++++ 6 files changed, 1047 insertions(+) create mode 100644 drivers/mtd/spi-nor/Makefile create mode 100644 drivers/mtd/spi-nor/spi-nor-ids.c create mode 100644 drivers/mtd/spi-nor/spi-nor.c create mode 100644 include/linux/mtd/spi-nor.h
Makefile +1 -0
@@ -642,6 +642,7 @@ libs-$(CONFIG_CMD_NAND) += drivers/mtd/nand/ libs-y += drivers/mtd/onenand/ libs-$(CONFIG_CMD_UBI) += drivers/mtd/ubi/ libs-y += drivers/mtd/spi/ +libs-y += drivers/mtd/spi-nor/ libs-y += drivers/net/ libs-y += drivers/net/phy/ libs-y += drivers/pci/
drivers/mtd/spi-nor/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# +# Copyright (C) 2016 Jagan Teki <[email protected]> +# +# SPDX-License-Identifier: GPL-2.0+ + +## spi-nor core +ifdef CONFIG_MTD_SPI_NOR +obj-y += spi-nor.o spi-nor-ids.o +endif
drivers/mtd/spi-nor/spi-nor-ids.c new file +176 -0
176 lines not on this page · raw message
drivers/mtd/spi-nor/spi-nor.c new file +649 -0
649 lines not on this page · raw message
include/linux/err.h +5 -0
@@ -36,6 +36,11 @@ static inline long IS_ERR(const void *ptr)return IS_ERR_VALUE ((unsigned long )ptr); } +static inline bool IS_ERR_OR_NULL (const void *ptr) +{ +return !ptr ||IS_ERR_VALUE ((unsigned long )ptr); +} +/** * ERR_CAST - Explicitly cast an error-valued pointer to another pointer type * @ptr: The pointer to cast.
include/linux/mtd/spi-nor.h new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH v8 3/16 mtd: spi-nor: Kconfig: Add MTD_SPI_NOR entry
In reply to Jagan TekiAdded CONFIG_MTD_SPI_NOR kconfig entry
--- drivers/mtd/Kconfig | 2 ++ drivers/mtd/spi-nor/Kconfig | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 drivers/mtd/spi-nor/Kconfig
drivers/mtd/Kconfig +2 -0
@@ -41,4 +41,6 @@ source "drivers/mtd/nand/Kconfig" source "drivers/mtd/spi/Kconfig" +source "drivers/mtd/spi-nor/Kconfig" + source "drivers/mtd/ubi/Kconfig"
drivers/mtd/spi-nor/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +menuconfig MTD_SPI_NOR + tristate "SPI-NOR device support" + depends on MTD + help + This is the core SPI NOR framework which can be used to interact SPI-NOR + to SPI driver interface layer and the SPI-NOR controller driver. + + Unlike normal/generic spi controllers, they are few controllers which are + exclusively used to connect SPI-NOR devices, called SPI-NOR controllers. + So technically these controllers shouldn't reside at drivers/spi as these + may effect the generic SPI bus functionalities, so this SPI-NOR core acts + as a common core framework between the generic SPI controller drivers vs + SPI-NOR controller drivers for SPI-NOR device access. Note that from SPI-NOR + core to SPI drivers there should be an interface layer.
Signature · 1 line
2.7.4
RFC PATCH v8 4/16 mtd: spi-nor: Kconfig: Add MTD_SPI_NOR_USE_4K_SECTORS
In reply to Jagan TekiAdded CONFIG_MTD_SPI_NOR_USE_4K_SECTORS kconfig entry
--- drivers/mtd/spi-nor/Kconfig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/mtd/spi-nor/Kconfig +18 -0
@@ -12,3 +12,21 @@ menuconfig MTD_SPI_NOR as a common core framework between the generic SPI controller drivers vs SPI-NOR controller drivers for SPI-NOR device access. Note that from SPI-NOR core to SPI drivers there should be an interface layer. + +if MTD_SPI_NOR + +config MTD_SPI_NOR_USE_4K_SECTORS + bool "Use small 4096 B erase sectors" + default y + help + Many flash memories support erasing small (4096 B) sectors. Depending + on the usage this feature may provide performance gain in comparison + to erasing whole blocks (32/64 KiB). + Changing a small part of the flash's contents is usually faster with + small sectors. On the other hand erasing should be faster when using + 64 KiB block instead of 16 ? 4 KiB sectors. + + Please note that some tools/drivers/filesystems may not work with + 4096 B erase size (e.g. UBIFS requires 15 KiB as a minimum). + +endif # MTD_SPI_NOR
Signature · 1 line
2.7.4
RFC PATCH v8 5/16 mtd: spi-nor: Kconfig: Add SPI_NOR_MISC entry
In reply to Jagan TekiAdded CONFIG_SPI_NOR_MISC kconfig entry
--- drivers/mtd/spi-nor/Kconfig | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/mtd/spi-nor/Kconfig +6 -0
@@ -29,4 +29,10 @@ config MTD_SPI_NOR_USE_4K_SECTORS Please note that some tools/drivers/filesystems may not work with 4096 B erase size (e.g. UBIFS requires 15 KiB as a minimum). +config SPI_NOR_MISC + bool "Miscellaneous SPI NOR flash's support" + help + Add SPI-NOR support for various flash chips like Atmel, EON, + GigaDevice, and ISSI. + endif # MTD_SPI_NOR
Signature · 1 line
2.7.4
RFC PATCH v8 6/16 mtd: spi-nor: Kconfig: Add SPI_NOR_MACRONIX entry
In reply to Jagan TekiAdded CONFIG_SPI_NOR_MACRONIX kconfig entry
--- drivers/mtd/spi-nor/Kconfig | 5 +++++ 1 file changed, 5 insertions(+)
drivers/mtd/spi-nor/Kconfig +5 -0
@@ -35,4 +35,9 @@ config SPI_NOR_MISC Add SPI-NOR support for various flash chips like Atmel, EON, GigaDevice, and ISSI. +config SPI_NOR_MACRONIX + bool "Macronix SPI NOR flash support" + help + Add support for various Macronix SPI flash chips (MX25Lxxx) + endif # MTD_SPI_NOR
Signature · 1 line
2.7.4
RFC PATCH v8 7/16 mtd: spi-nor: Kconfig: Add SPI_NOR_SPANSION entry
In reply to Jagan TekiAdded CONFIG_SPI_NOR_SPANSION kconfig entry
--- drivers/mtd/spi-nor/Kconfig | 5 +++++ 1 file changed, 5 insertions(+)
drivers/mtd/spi-nor/Kconfig +5 -0
@@ -40,4 +40,9 @@ config SPI_NOR_MACRONIX help Add support for various Macronix SPI flash chips (MX25Lxxx) +config SPI_NOR_SPANSION + bool "Spansion SPI NOR flash support" + help + Add support for various Spansion SPI flash chips (S25FLxxx) + endif # MTD_SPI_NOR
Signature · 1 line
2.7.4
RFC PATCH v8 8/16 mtd: spi-nor: Kconfig: Add SPI_NOR_STMICRO entry
In reply to Jagan TekiAdded CONFIG_SPI_NOR_STMICRO kconfig entry
--- drivers/mtd/spi-nor/Kconfig | 5 +++++ 1 file changed, 5 insertions(+)
drivers/mtd/spi-nor/Kconfig +5 -0
@@ -45,4 +45,9 @@ config SPI_NOR_SPANSION help Add support for various Spansion SPI flash chips (S25FLxxx) +config SPI_NOR_STMICRO + bool "STMicro SPI NOR flash support" + help + Add support for various STMicro SPI flash chips (M25Pxxx and N25Qxxx) + endif # MTD_SPI_NOR
Signature · 1 line
2.7.4
RFC PATCH v8 9/16 mtd: spi-nor: Kconfig: Add SPI_NOR_SST entry
In reply to Jagan TekiAdded CONFIG_SPI_NOR_SST kconfig entry
--- drivers/mtd/spi-nor/Kconfig | 5 +++++ 1 file changed, 5 insertions(+)
drivers/mtd/spi-nor/Kconfig +5 -0
@@ -50,4 +50,9 @@ config SPI_NOR_STMICRO help Add support for various STMicro SPI flash chips (M25Pxxx and N25Qxxx) +config SPI_NOR_SST + bool "SST SPI NOR flash support" + help + Add support for various SST SPI flash chips (SST25xxx) + endif # MTD_SPI_NOR
Signature · 1 line
2.7.4
RFC PATCH v8 10/16 mtd: spi-nor: Kconfig: Add SPI_NOR_WINBOND entry
In reply to Jagan TekiAdded CONFIG_SPI_NOR_WINBOND kconfig entry
--- drivers/mtd/spi-nor/Kconfig | 5 +++++ 1 file changed, 5 insertions(+)
drivers/mtd/spi-nor/Kconfig +5 -0
@@ -55,4 +55,9 @@ config SPI_NOR_SST help Add support for various SST SPI flash chips (SST25xxx) +config SPI_NOR_WINBOND + bool "Winbond SPI NOR flash support" + help + Add support for various Winbond SPI flash chips (W25xxx) + endif # MTD_SPI_NOR
Signature · 1 line
2.7.4
RFC PATCH v8 11/16 spi: Add spi_write_then_read
In reply to Jagan TekiAdd support for SPI synchronous write followed by read, this is common interface call from spi-nor to spi drivers.
--- drivers/spi/spi-uclass.c | 24 ++++++++++++++++++++++++ include/spi.h | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+)
drivers/spi/spi-uclass.c +24 -0
@@ -108,6 +108,30 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,return dm_spi_xfer (slave->dev, bitlen, dout, din, flags); } +int spi_write_then_read (struct spi_slave *slave,const u8 *opcode, +size_t n_opcode,const u8 *txbuf,u8 *rxbuf, +size_t n_buf) +{ +unsigned long flags =SPI_XFER_BEGIN ; +int ret; + +if (n_buf ==0 ) + flags |=SPI_XFER_END ; + + ret =spi_xfer (slave, n_opcode *8 , opcode,NULL , flags); +if (ret) { +debug ("spi: failed to send command (%zu bytes): %d\n" , + n_opcode, ret); + }else if (n_buf !=0 ) { + ret =spi_xfer (slave, n_buf *8 , txbuf, rxbuf,SPI_XFER_END ); +if (ret) +debug ("spi: failed to transfer %zu bytes of data: %d\n" , + n_buf, ret); + } + +return ret; +} +static int spi_child_post_bind (struct udevice *dev) {struct dm_spi_slave_platdata *plat =dev_get_parent_platdata (dev);
include/spi.h +20 -0
@@ -258,6 +258,26 @@ int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen);int spi_xfer (struct spi_slave *slave,unsigned int bitlen,const void *dout,void *din,unsigned long flags); +/** +* spi_write_then_read - SPI synchronous write followed by read +* +* This performs a half duplex transaction in which the first transaction +* is to send the opcode and if the length of buf is non-zero then it start +* the second transaction as tx or rx based on the need from respective slave. +* +* @slave: slave device with which opcode/data will be exchanged +* @opcode: opcode used for specific transfer +* @n_opcode: size of opcode, in bytes +* @txbuf: buffer into which data to be written +* @rxbuf: buffer into which data will be read +* @n_buf: size of buf (whether it's [tx|rx]buf), in bytes +* +* Returns: 0 on success, not 0 on failure +*/ +int spi_write_then_read (struct spi_slave *slave,const u8 *opcode, +size_t n_opcode,const u8 *txbuf,u8 *rxbuf, +size_t n_buf); +/* Copy memory mapped data */ void spi_flash_copy_mmap (void *data,void *offset,size_t len);
Signature · 1 line
2.7.4
RFC PATCH v8 12/16 mtd: spi-nor: Add m25p80 driver
In reply to Jagan TekiThis is MTD SPI-NOR driver for ST M25Pxx (and similar) serial flash chips which is written as MTD_UCLASS.
--- drivers/mtd/spi-nor/Makefile | 3 + drivers/mtd/spi-nor/m25p80.c | 217 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+) create mode 100644 drivers/mtd/spi-nor/m25p80.c
drivers/mtd/spi-nor/Makefile +3 -0
@@ -7,3 +7,6 @@ ifdef CONFIG_MTD_SPI_NOR obj-y += spi-nor.o spi-nor-ids.o endif + +## spi-nor to spi interface driver +obj-$(CONFIG_MTD_M25P80) += m25p80.o
drivers/mtd/spi-nor/m25p80.c new file +217 -0
217 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH v8 13/16 mtd: spi-nor: Kconfig: Add MTD_M25P80 entry
In reply to Jagan TekiAdd CONFIG_MTD_M25P80 kconfig entry
--- drivers/mtd/spi-nor/Kconfig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/mtd/spi-nor/Kconfig +17 -0
@@ -15,6 +15,23 @@ menuconfig MTD_SPI_NOR if MTD_SPI_NOR +config MTD_M25P80 + tristate "Support most SPI Flash chips (AT26DF, M25P, W25X, ...)" + depends on DM_SPI + help + This enables access to most modern SPI flash chips, used for + program and data storage. Series supported include Atmel AT26DF, + Spansion S25SL, SST 25VF, ST M25P, and Winbond W25X. Other chips + are supported as well. See the driver source for the current list, + or to add other chips. + + Note that the original DataFlash chips (AT45 series, not AT26DF), + need an entirely different driver. + + Set up your spi devices with the right board-specific platform data, + if you want to specify device partitioning or to use a device which + doesn't support the JEDEC ID instruction. + config MTD_SPI_NOR_USE_4K_SECTORS bool "Use small 4096 B erase sectors" default y
Signature · 1 line
2.7.4
RFC PATCH v8 14/16 mtd: spi-nor: Add zynq qspi driver
In reply to Jagan TekiZynq qspi controller is works similar way as generic spi controller with additional features that make this controller work more specific to flash chips as salve devices.
Why, zynq qspi written as spi-nor controller driver.
(1) BAR:
It operates the flash chips which are > 16MiB actual size, but with 3-byte addressing. Usually flash chips > 16MiB need to operate it on 4-byte addressing but the zynq qspi controller doesn't support 4-byte addressing.
So, it's a Job of spi-nor generic core to handle flash chips > 16MiB in 3-byte addressing using bank address reg.
This approach has some issues like spi-nor core generic operations like read/write/erase has to modify and some dificuly in adding 4-byte addressing support.
(2) dual flash:
This describes two/dual memories are connected with a single chip select line from a controller like dual stack and dual parallel connections see doc/SPI/README.dual-flash for more details.
Adding this support to spi-nor core looks quite managable and other generic code might effect and more over this is controller specific.
--- drivers/mtd/spi-nor/Makefile | 3 + drivers/mtd/spi-nor/zynq_qspi.c | 638 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 641 insertions(+) create mode 100644 drivers/mtd/spi-nor/zynq_qspi.c
drivers/mtd/spi-nor/Makefile +3 -0
@@ -10,3 +10,6 @@ endif ## spi-nor to spi interface driver obj-$(CONFIG_MTD_M25P80) += m25p80.o + +## spi-nor drivers +obj-$(CONFIG_MTD_ZYNQ_QSPI) += zynq_qspi.o
drivers/mtd/spi-nor/zynq_qspi.c new file +638 -0
638 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH v8 15/16 mtd: spi-nor: zynq_qspi: Kconfig: Add MTD_ZYNQ
In reply to Jagan TekiAdd CONFIG_MTD_ZYNQ_QSPI kconfig entry
--- drivers/mtd/spi-nor/Kconfig | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/mtd/spi-nor/Kconfig +9 -0
@@ -46,6 +46,15 @@ config MTD_SPI_NOR_USE_4K_SECTORS Please note that some tools/drivers/filesystems may not work with 4096 B erase size (e.g. UBIFS requires 15 KiB as a minimum). +config MTD_ZYNQ_QSPI + bool "Zynq QSPI NOR controller driver" + depends on ARCH_ZYNQ + help + Enable the Zynq Quad-SPI (QSPI) driver. This driver can be + used to access the SPI NOR flash on platforms embedding this + Zynq QSPI IP core. This IP is used to connect the flash in + 4-bit qspi, 8-bit dual stacked and shared 4-bit dual parallel. + config SPI_NOR_MISC bool "Miscellaneous SPI NOR flash's support" help
Signature · 1 line
2.7.4
RFC PATCH v8 16/16 mtd: spi-nor: Add 4-byte address width support
In reply to Jagan TekiAdd 4-byte address supports, so-that SPI-NOR chips has > 16MiB should accessible.
--- drivers/mtd/spi-nor/m25p80.c | 1 + drivers/mtd/spi-nor/spi-nor.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/mtd/spi-nor.h | 6 +++++- 3 files changed, 42 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/m25p80.c +1 -0
@@ -31,6 +31,7 @@ static void m25p_addr2cmd(struct spi_nor *nor, unsigned int addr, u8 *cmd) cmd[1 ] = addr >> (nor->addr_width *8 -8 ); cmd[2 ] = addr >> (nor->addr_width *8 -16 ); cmd[3 ] = addr >> (nor->addr_width *8 -24 ); + cmd[4 ] = addr >> (nor->addr_width *8 -32 ); }static int m25p_cmdsz (struct spi_nor *nor)
drivers/mtd/spi-nor/spi-nor.c +36 -0
@@ -379,6 +379,36 @@ static int sst_write_bp(struct udevice *dev, loff_t to, size_t len, }#endif +/* Enable/disable 4-byte addressing mode. */ +static int set_4byte (struct spi_nor *nor,const struct spi_nor_info *info, +int enable) +{ +int status; +bool need_wren = false; +u8 cmd; + +switch (JEDEC_MFR (info)) { +case SNOR_MFR_MICRON : +/* Some Micron need WREN command; all will accept it */ + need_wren = true; +case SNOR_MFR_MACRONIX : +case SNOR_MFR_WINBOND : +if (need_wren) +write_enable (nor); + + cmd = enable ?SNOR_OP_EN4B :SNOR_OP_EX4B ; + status = nor->write_reg (nor, cmd,NULL ,0 ); +if (need_wren) +write_disable (nor); + +return status; +default : +/* Spansion style */ + nor->cmd_buf[0 ] = enable <<7 ; +return nor->write_reg (nor,SNOR_OP_BRWR , nor->cmd_buf,1 ); + } +} +#ifdef CONFIG_SPI_NOR_MACRONIX static int macronix_quad_enable (struct spi_nor *nor) {
@@ -614,6 +644,12 @@ int spi_nor_scan(struct udevice *dev) } nor->addr_width =3 ; +if (mtd->size >SNOR_16MB_BOUN ) { + nor->addr_width =4 ; + ret =set_4byte (nor, info, true); +if (ret) +return ret; + }/* Dummy cycles for read */ switch (nor->read_opcode) {
include/linux/mtd/spi-nor.h +5 -1
@@ -62,6 +62,10 @@#define SNOR_OP_BP 0x02/* Byte program */ #define SNOR_OP_AAI_WP 0xad/* Auto addr increment word program */ +/* Used for Macronix and Winbond flashes. */ +#define SNOR_OP_EN4B 0xb7/* Enter 4-byte mode */ +#define SNOR_OP_EX4B 0xe9/* Exit 4-byte mode */ +/* Status Register bits. */ #define SR_WIP BIT(0)/* Write in progress */ #define SR_WEL BIT(1)/* Write enable latch */
@@ -83,7 +87,7 @@/* Flash timeout values */ #define SNOR_READY_WAIT_PROG (2 * CONFIG_SYS_HZ)#define SNOR_READY_WAIT_ERASE (5 * CONFIG_SYS_HZ) -#define SNOR_MAX_CMD_SIZE 4 +#define SNOR_MAX_CMD_SIZE 6#define SNOR_16MB_BOUN 0x1000000enum snor_option_flags {
Signature · 1 line
2.7.4