Add memory mapped read support for ti-qspi
Subsystems (3)
Vignesh R
maintainerv2 cover Add memory mapped read support for ti-qspi
Changes since v1:
Introduce API in SPI core that MTD flash driver can call for mmap read instead of directly calling spi-master driver callback. This API makes sure that SPI core msg queue is locked during mmap transfers.
v1: https://lkml.org/lkml/2015/9/4/103
Cover letter:
This patch series adds support for memory mapped read port of ti-qspi. ti-qspi has a special memory mapped port through which SPI flash memories can be accessed directly via SoC specific memory region.
First patch adds a method to pass flash specific information like read opcode, dummy bytes etc and to request mmap read. Second patch implements mmap read method in ti-qspi driver. Patch 3 adapts m25p80 to use mmap read method before trying normal SPI transfer. Patch 4 and 5 add memory map region DT entries for DRA7xx and AM43xx SoCs.
This patch series is based on the discussions here:
http://www.spinics.net/lists/linux-spi/msg04796.html
Tested on DRA74 EVM and AM437x-SK.
Read performance increases from ~100kB/s to ~2.5MB/s.
Vignesh R (5):
spi: introduce mmap read support for spi flash devices
spi: spi-ti-qspi: add mmap mode read support
mtd: devices: m25p80: add support for mmap read request
ARM: dts: DRA7: add entry for qspi mmap region
ARM: dts: AM4372: add entry for qspi mmap region
Documentation/devicetree/bindings/spi/ti_qspi.txt | 18 ++++- arch/arm/boot/dts/am4372.dtsi | 4 +- arch/arm/boot/dts/dra7.dtsi | 6 +- drivers/mtd/devices/m25p80.c | 5 ++ drivers/spi/spi-ti-qspi.c | 92 ++++++++++++++++++++++- drivers/spi/spi.c | 35 +++++++++ include/linux/spi/spi.h | 23 ++++++ 7 files changed, 174 insertions(+), 9 deletions(-)
Signature · 1 line
2.6.2
Vignesh R
maintainerPATCH v2 1/5 spi: introduce mmap read support for spi flash devices
In addition to providing direct access to SPI bus, some spi controller hardwares (like ti-qspi) provide special memory mapped port to accesses SPI flash devices in order to increase read performance. This means the controller can automatically send the SPI signals required to read data from the SPI flash device.
For this, spi controller needs to know flash specific information like read command to use, dummy bytes and address width. Once these settings are populated in hardware registers, any read accesses to flash's memory map region(SoC specific) through memcpy (or mem-to mem DMA copy) will be handled by controller hardware. The hardware will automatically generate SPI signals required to read data from flash and present it to CPU/DMA.
Introduce spi_mtd_mmap_read() interface to support memory mapped read over SPI flash devices. SPI master drivers can implement this callback to support memory mapped read interfaces. m25p80 flash driver and other flash drivers can call this to request memory mapped read. The interface should only be used MTD flashes and cannot be used with other SPI devices.
--- drivers/spi/spi.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/spi/spi.h | 23 +++++++++++++++++++++++ 2 files changed, 58 insertions(+)
drivers/spi/spi.c +35 -0
@@ -1059,6 +1059,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread) } } +mutex_lock (&master->mmap_lock_mutex);trace_spi_message_start (master->cur_msg);if (master->prepare_message) {
@@ -1068,6 +1069,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread) "failed to prepare message: %d\n", ret); master->cur_msg->status = ret;spi_finalize_current_message (master); +mutex_unlock (&master->mmap_lock_mutex);return ; } master->cur_msg_prepared = true;
@@ -1077,6 +1079,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread)if (ret) { master->cur_msg->status = ret;spi_finalize_current_message (master); +mutex_unlock (&master->mmap_lock_mutex);return ; }
@@ -1084,8 +1087,10 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread)if (ret) {dev_err (&master->dev,"failed to transfer one message from queue\n" ); +mutex_unlock (&master->mmap_lock_mutex);return ; } +mutex_unlock (&master->mmap_lock_mutex); }/**
@@ -1732,6 +1737,7 @@ int spi_register_master(struct spi_master *master)spin_lock_init (&master->queue_lock);spin_lock_init (&master->bus_lock_spinlock);mutex_init (&master->bus_lock_mutex); +mutex_init (&master->mmap_lock_mutex); master->bus_lock_flag =0 ;init_completion (&master->xfer_completion);if (!master->max_dma_len)
@@ -2237,6 +2243,35 @@ int spi_async_locked(struct spi_device *spi, struct spi_message *message)EXPORT_SYMBOL_GPL (spi_async_locked); +int spi_mtd_mmap_read (struct spi_device *spi,loff_t from,size_t len, +size_t *retlen,u_char *buf,u8 read_opcode, +u8 addr_width,u8 dummy_bytes) + +{ +struct spi_master *master = spi->master; +int ret; + +if (master->auto_runtime_pm) { + ret =pm_runtime_get_sync (master->dev.parent); +if (ret <0 ) { +dev_err (&master->dev,"Failed to power device: %d\n" , + ret); + goto err; + } + } +mutex_lock (&master->mmap_lock_mutex); + ret = master->spi_mtd_mmap_read (spi, from, len, retlen, buf, + read_opcode, addr_width, + dummy_bytes); +mutex_unlock (&master->mmap_lock_mutex); +if (master->auto_runtime_pm) +pm_runtime_put (master->dev.parent); + +err: +return ret; +} +EXPORT_SYMBOL_GPL (spi_mtd_mmap_read); +/*-------------------------------------------------------------------------*/ /* Utility methods for SPI master protocol drivers, layered on
include/linux/spi/spi.h +23 -0
@@ -297,6 +297,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)* @flags: other constraints relevant to this driver * @bus_lock_spinlock: spinlock for SPI bus locking * @bus_lock_mutex: mutex for SPI bus locking +* @mmap_lock_mutex: mutex for locking SPI bus when mmap transfer is on. * @bus_lock_flag: indicates that the SPI bus is locked for exclusive use * @setup: updates the device mode and clocking records used by a * device's SPI controller; protocol code may call this. This
@@ -353,6 +354,11 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)* @handle_err: the subsystem calls the driver to handle an error that occurs * in the generic implementation of transfer_one_message(). * @unprepare_message: undo any work done by prepare_message(). +* @spi_mtd_mmap_read: some spi-controller hardwares provide memory. +* Flash drivers (like m25p80) can request memory +* mapped read via this method. This interface +* should only be used by mtd flashes and cannot be +* used by other spi devices. * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS * number. Any individual value may be -ENOENT for CS lines that * are not GPIOs (driven by the SPI controller itself).
@@ -420,6 +426,8 @@ struct spi_master {/* lock and mutex for SPI bus locking */ spinlock_t bus_lock_spinlock;struct mutex bus_lock_mutex; +/* mutex for SPI bus locking when mmap transfer is on */ +struct mutex mmap_lock_mutex;/* flag indicating that the SPI bus is locked for exclusive use */ bool bus_lock_flag;
@@ -499,6 +507,11 @@ struct spi_master { struct spi_message *message);int (*unprepare_message)(struct spi_master *master,struct spi_message *message); +int (*spi_mtd_mmap_read)(struct spi_device *spi, +loff_t from,size_t len, +size_t *retlen,u_char *buf, +u8 read_opcode,u8 addr_width, +u8 dummy_bytes);/* * These hooks are for drivers that use a generic implementation
@@ -985,6 +998,16 @@ static inline ssize_t spi_w8r16be(struct spi_device *spi, u8 cmd)return be16_to_cpu (result); } +/* SPI core interface for memory mapped read support */ +static inline bool spi_mmap_read_supported (struct spi_device *spi) +{ +return spi->master->spi_mtd_mmap_read ? true : false; +} + +int spi_mtd_mmap_read (struct spi_device *spi,loff_t from,size_t len, +size_t *retlen,u_char *buf,u8 read_opcode, +u8 addr_width,u8 dummy_bytes); +/*---------------------------------------------------------------------------*/ /*
Signature · 1 line
2.6.2
Re: [PATCH v2 1/5] spi: introduce mmap read support for spi flash devices
Quoted 112 lines · Vignesh R
In addition to providing direct access to SPI bus, some spi controller hardwares (like ti-qspi) provide special memory mapped port to accesses SPI flash devices in order to increase read performance. This means the controller can automatically send the SPI signals required to read data from the SPI flash device.
For this, spi controller needs to know flash specific information like read command to use, dummy bytes and address width. Once these settings are populated in hardware registers, any read accesses to flash's memory map region(SoC specific) through memcpy (or mem-to mem DMA copy) will be handled by controller hardware. The hardware will automatically generate SPI signals required to read data from flash and present it to CPU/DMA.Introduce
spi_mtd_mmap_read()interface to support memory mapped read over SPI flash devices. SPI master drivers can implement this callback to support memory mapped read interfaces. m25p80 flash driver and other flash drivers can call this to request memory mapped read. The interface should only be used MTD flashes and cannot be used with other SPI devices.Signed-off-by Vignesh R <[email protected]>--- drivers/spi/spi.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/spi/spi.h | 23 +++++++++++++++++++++++ 2 files changed, 58 insertions(+)drivers/spi/spi.c +35
-0@@ -1059,6 +1059,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread) } } +mutex_lock (&master->mmap_lock_mutex);trace_spi_message_start (master->cur_msg);if (master->prepare_message) {@@ -1068,6 +1069,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread) "failed to prepare message: %d\n", ret); master->cur_msg->status = ret;spi_finalize_current_message (master); +mutex_unlock (&master->mmap_lock_mutex);return ; } master->cur_msg_prepared = true;@@ -1077,6 +1079,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread)if (ret) { master->cur_msg->status = ret;spi_finalize_current_message (master); +mutex_unlock (&master->mmap_lock_mutex);return ; }@@ -1084,8 +1087,10 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread)if (ret) {dev_err (&master->dev,"failed to transfer one message from queue\n" ); +mutex_unlock (&master->mmap_lock_mutex);return ; } +mutex_unlock (&master->mmap_lock_mutex); }/** @@ -1732,6 +1737,7 @@ int spi_register_master(struct spi_master *master)spin_lock_init (&master->queue_lock);spin_lock_init (&master->bus_lock_spinlock);mutex_init (&master->bus_lock_mutex); +mutex_init (&master->mmap_lock_mutex); master->bus_lock_flag =0 ;init_completion (&master->xfer_completion);if (!master->max_dma_len)@@ -2237,6 +2243,35 @@ int spi_async_locked(struct spi_device *spi, struct spi_message *message)EXPORT_SYMBOL_GPL (spi_async_locked); +int spi_mtd_mmap_read (struct spi_device *spi,loff_t from,size_t len, +size_t *retlen,u_char *buf,u8 read_opcode, +u8 addr_width,u8 dummy_bytes) + +{ +struct spi_master *master = spi->master; +int ret; + +if (master->auto_runtime_pm) { + ret =pm_runtime_get_sync (master->dev.parent); +if (ret <0 ) { +dev_err (&master->dev,"Failed to power device: %d\n" , + ret); + goto err; + } + } +mutex_lock (&master->mmap_lock_mutex); + ret = master->spi_mtd_mmap_read (spi, from, len, retlen, buf, + read_opcode, addr_width, + dummy_bytes); +mutex_unlock (&master->mmap_lock_mutex); +if (master->auto_runtime_pm) +pm_runtime_put (master->dev.parent); + +err: +return ret; +} +EXPORT_SYMBOL_GPL (spi_mtd_mmap_read); +/*-------------------------------------------------------------------------*/ /* Utility methods for SPI master protocol drivers, layered on include/linux/spi/spi.h +0
-0
include/linux/spi/spi.h static inline void spi_unregister_driver(struct spi_driver *sdrv) · line 300
Quoted 4 lines
include/linux/spi/spi.h +1
-0@@ -297,6 +297,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)* @flags: other constraints relevant to this driver * @bus_lock_spinlock: spinlock for SPI bus locking * @bus_lock_mutex: mutex for SPI bus locking +* @mmap_lock_mutex: mutex for locking SPI bus when mmap transfer is on.
Any reason to not use the bus_lock_mutex here? The bus is busy as much during mmap transfer as it is during any other transfer.
Thanks
Michal
Vignesh R
maintainerRe: [PATCH v2 1/5] spi: introduce mmap read support for spi flash devices
Hi,
Quoted 107 lines · Michal Suchanek
Quoted 106 lines · Vignesh R
In addition to providing direct access to SPI bus, some spi controller hardwares (like ti-qspi) provide special memory mapped port to accesses SPI flash devices in order to increase read performance. This means the controller can automatically send the SPI signals required to read data from the SPI flash device.
For this, spi controller needs to know flash specific information like read command to use, dummy bytes and address width. Once these settings are populated in hardware registers, any read accesses to flash's memory map region(SoC specific) through memcpy (or mem-to mem DMA copy) will be handled by controller hardware. The hardware will automatically generate SPI signals required to read data from flash and present it to CPU/DMA.Introduce
spi_mtd_mmap_read()interface to support memory mapped read over SPI flash devices. SPI master drivers can implement this callback to support memory mapped read interfaces. m25p80 flash driver and other flash drivers can call this to request memory mapped read. The interface should only be used MTD flashes and cannot be used with other SPI devices.Signed-off-by Vignesh R <[email protected]>--- drivers/spi/spi.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/spi/spi.h | 23 +++++++++++++++++++++++ 2 files changed, 58 insertions(+)drivers/spi/spi.c +35
-0@@ -1059,6 +1059,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread) } } +mutex_lock (&master->mmap_lock_mutex);trace_spi_message_start (master->cur_msg);if (master->prepare_message) {@@ -1068,6 +1069,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread) "failed to prepare message: %d\n", ret); master->cur_msg->status = ret;spi_finalize_current_message (master); +mutex_unlock (&master->mmap_lock_mutex);return ; } master->cur_msg_prepared = true;@@ -1077,6 +1079,7 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread)if (ret) { master->cur_msg->status = ret;spi_finalize_current_message (master); +mutex_unlock (&master->mmap_lock_mutex);return ; }@@ -1084,8 +1087,10 @@ static void __spi_pump_messages(struct spi_master *master, bool in_kthread)if (ret) {dev_err (&master->dev,"failed to transfer one message from queue\n" ); +mutex_unlock (&master->mmap_lock_mutex);return ; } +mutex_unlock (&master->mmap_lock_mutex); }/** @@ -1732,6 +1737,7 @@ int spi_register_master(struct spi_master *master)spin_lock_init (&master->queue_lock);spin_lock_init (&master->bus_lock_spinlock);mutex_init (&master->bus_lock_mutex); +mutex_init (&master->mmap_lock_mutex); master->bus_lock_flag =0 ;init_completion (&master->xfer_completion);if (!master->max_dma_len)@@ -2237,6 +2243,35 @@ int spi_async_locked(struct spi_device *spi, struct spi_message *message)EXPORT_SYMBOL_GPL (spi_async_locked); +int spi_mtd_mmap_read (struct spi_device *spi,loff_t from,size_t len, +size_t *retlen,u_char *buf,u8 read_opcode, +u8 addr_width,u8 dummy_bytes) + +{ +struct spi_master *master = spi->master; +int ret; + +if (master->auto_runtime_pm) { + ret =pm_runtime_get_sync (master->dev.parent); +if (ret <0 ) { +dev_err (&master->dev,"Failed to power device: %d\n" , + ret); + goto err; + } + } +mutex_lock (&master->mmap_lock_mutex); + ret = master->spi_mtd_mmap_read (spi, from, len, retlen, buf, + read_opcode, addr_width, + dummy_bytes); +mutex_unlock (&master->mmap_lock_mutex); +if (master->auto_runtime_pm) +pm_runtime_put (master->dev.parent); + +err: +return ret; +} +EXPORT_SYMBOL_GPL (spi_mtd_mmap_read); +/*-------------------------------------------------------------------------*/
Quoted 13 lines
include/linux/spi/spi.h static inline void spi_unregister_driver(struct spi_driver *sdrv) · line 300
Quoted 10 lines
drivers/spi/spi.c +0
-0/* Utility methods for SPI master protocol drivers, layered on include/linux/spi/spi.h +1
-0@@ -297,6 +297,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)* @flags: other constraints relevant to this driver * @bus_lock_spinlock: spinlock for SPI bus locking * @bus_lock_mutex: mutex for SPI bus locking +* @mmap_lock_mutex: mutex for locking SPI bus when mmap transfer is on. Any reason to not use the
bus_lock_mutexhere? The bus is busy as much during mmap transfer as it is during any other transfer.
If bus_lock_mutex is used, it will unnecessarily block queueing of new messages when __spi_pump_messages() is calling transfer_one_message() even in the case where there is no mmap mode. Hence, I chose to add new mutex. But looks like it doesn't matter much as __spi_sync() anyways blocks till message is transferred. I will drop the new mutex and use bus_lock_mutex in v3. Thanks!
Signature · 2 lines
Regards Vignesh
Mark Brown
maintainerRe: [PATCH v2 1/5] spi: introduce mmap read support for spi flash devices
In reply to Vignesh Rdrivers/spi/spi.c int spi_async_locked(struct spi_device *spi, struct spi_message *message) · line 2268
Quoted 8 lines · Vignesh R
drivers/spi/spi.c +8
-0+ } +mutex_lock (&master->mmap_lock_mutex); + ret = master->spi_mtd_mmap_read (spi, from, len, retlen, buf, + read_opcode, addr_width, + dummy_bytes); +mutex_unlock (&master->mmap_lock_mutex); +if (master->auto_runtime_pm) +pm_runtime_put (master->dev.parent);
It's a bit worrying that this doesn't sync with the message queue except
via the mutex: this means that we might be out of order with respect to
any asynchronous transfers that are happening on the device. I'm not
sure that this is a practical problem, though there is some risk of
unfair scheduling that would have to be under extreme load and it might
make sense to prioritise reads anyway.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151104/71e12d1f/attachment.sig>
Vignesh R
maintainerRe: [PATCH v2 1/5] spi: introduce mmap read support for spi flash devices
Quoted 18 lines · Mark Brown
drivers/spi/spi.c int spi_async_locked(struct spi_device *spi, struct spi_message *message) · line 2268
Quoted 8 lines · Vignesh R
drivers/spi/spi.c +8
-0+ } +mutex_lock (&master->mmap_lock_mutex); + ret = master->spi_mtd_mmap_read (spi, from, len, retlen, buf, + read_opcode, addr_width, + dummy_bytes); +mutex_unlock (&master->mmap_lock_mutex); +if (master->auto_runtime_pm) +pm_runtime_put (master->dev.parent);It's a bit worrying that this doesn't sync with the message queue except via the mutex: this means that we might be out of order with respect to any asynchronous transfers that are happening on the device. I'm not sure that this is a practical problem, though there is some risk of unfair scheduling that would have to be under extreme load and it might make sense to prioritise reads anyway.
Since mmap interface is used only by mtd flash drivers and since almost all mtd flash devices use synchronous transfers (spi_sync()), IMO, there wont be out of order problem wrt mtd flashes.
But mmap read might delay transfers queued for non mtd flash devices. It is difficult to wait for all transfers already queued to be pumped out by __spi_pump_messages() and then do the mmap transfer. Do you have any thoughts on how to sync with message queue?
Signature · 2 lines
Regards Vignesh
Mark Brown
maintainerRe: [PATCH v2 1/5] spi: introduce mmap read support for spi flash devices
Quoted 9 lines · Vignesh R
Quoted 6 lines · Mark Brown
It's a bit worrying that this doesn't sync with the message queue except via the mutex: this means that we might be out of order with respect to any asynchronous transfers that are happening on the device. I'm not sure that this is a practical problem, though there is some risk of unfair scheduling that would have to be under extreme load and it might make sense to prioritise reads anyway.
Quoted 7 lines
Since mmap interface is used only by mtd flash drivers and since almost all mtd flash devices use synchronous transfers (
spi_sync()), IMO, there wont be out of order problem wrt mtd flashes.
But mmap read might delay transfers queued for non mtd flash devices. It is difficult to wait for all transfers already queued to be pumped out by__spi_pump_messages()and then do the mmap transfer. Do you have any thoughts on how to sync with message queue?
Like I say I think it probably doesn't matter. The main issue would be
with other devices sharing the bus with a flash chip.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151105/322f9a50/attachment.sig>
Vignesh R
maintainerPATCH v2 2/5 spi: spi-ti-qspi: add mmap mode read support
In reply to Vignesh Rti-qspi controller provides mmap port to read data from SPI flashes. mmap port is enabled in QSPI_SPI_SWITCH_REG. ctrl module register may also need to be accessed for some SoCs. The QSPI_SPI_SETUP_REGx needs to be populated with flash specific information like read opcode, read mode(quad, dual, normal), address width and dummy bytes. Once, controller is in mmap mode, the whole flash memory is available as a memory region at SoC specific address. This region can be accessed using normal memcpy() (or mem-to-mem dma copy). The ti-qspi controller hardware will internally communicate with SPI flash over SPI bus and get the requested data.
Implement spi_mtd_mmap_read() callback to support mmap read over SPI flash devices. With this, the read throughput increases from ~100kB/s to ~2.5 MB/s.
--- drivers/spi/spi-ti-qspi.c | 92 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 4 deletions(-)
drivers/spi/spi-ti-qspi.c +88 -4
@@ -65,11 +65,8 @@ struct ti_qspi {#define QSPI_SPI_CMD_REG (0x48)#define QSPI_SPI_STATUS_REG (0x4c)#define QSPI_SPI_DATA_REG (0x50) -#define QSPI_SPI_SETUP0_REG (0x54) +#define QSPI_SPI_SETUP_REG (n) ((0x54 + 4 * n))#define QSPI_SPI_SWITCH_REG (0x64) -#define QSPI_SPI_SETUP1_REG (0x58) -#define QSPI_SPI_SETUP2_REG (0x5c) -#define QSPI_SPI_SETUP3_REG (0x60)#define QSPI_SPI_DATA_REG_1 (0x68)#define QSPI_SPI_DATA_REG_2 (0x6c)#define QSPI_SPI_DATA_REG_3 (0x70)
@@ -109,6 +106,16 @@ struct ti_qspi {#define QSPI_AUTOSUSPEND_TIMEOUT 2000 +#define MEM_CS_EN (n) ((n + 1) << 8) + +#define MM_SWITCH 0x1 + +#define QSPI_SETUP_RD_NORMAL (0x0 << 12) +#define QSPI_SETUP_RD_DUAL (0x1 << 12) +#define QSPI_SETUP_RD_QUAD (0x3 << 12) +#define QSPI_SETUP_ADDR_SHIFT 8 +#define QSPI_SETUP_DUMMY_SHIFT 10 +static inline unsigned long ti_qspi_read (struct ti_qspi *qspi,unsigned long reg) {
@@ -366,6 +373,82 @@ static int qspi_transfer_msg(struct ti_qspi *qspi, struct spi_transfer *t)return 0 ; } +static void ti_qspi_enable_memory_map (struct spi_device *spi) +{ +struct ti_qspi *qspi =spi_master_get_devdata (spi->master); +u32 val; + +ti_qspi_write (qspi,MM_SWITCH ,QSPI_SPI_SWITCH_REG ); +if (qspi->ctrl_mod) { + val =readl (qspi->ctrl_base); + val |=MEM_CS_EN (spi->chip_select); +writel (val, qspi->ctrl_base); +/* dummy readl to ensure bus sync */ +readl (qspi->ctrl_base); + } +} + +static void ti_qspi_disable_memory_map (struct spi_device *spi) +{ +struct ti_qspi *qspi =spi_master_get_devdata (spi->master); +u32 val; + +ti_qspi_write (qspi,0 ,QSPI_SPI_SWITCH_REG ); +if (qspi->ctrl_mod) { + val =readl (qspi->ctrl_base); + val &= ~MEM_CS_EN (spi->chip_select); +writel (val, qspi->ctrl_base); + } +} + +static void ti_qspi_setup_mmap_read (struct spi_device *spi, +u8 read_opcode,u8 addr_width, +u8 dummy_bytes) +{ +struct ti_qspi *qspi =spi_master_get_devdata (spi->master); +u32 mode = spi->mode & (SPI_RX_DUAL |SPI_RX_QUAD ); +u32 memval = read_opcode; + +switch (mode) { +case SPI_RX_QUAD : + memval |=QSPI_SETUP_RD_QUAD ; +break ; +case SPI_RX_DUAL : + memval |=QSPI_SETUP_RD_DUAL ; +break ; +default : + memval |=QSPI_SETUP_RD_NORMAL ; +break ; + } + memval |= ((addr_width -1 ) <<QSPI_SETUP_ADDR_SHIFT | + dummy_bytes <<QSPI_SETUP_DUMMY_SHIFT ); +ti_qspi_write (qspi, memval, +QSPI_SPI_SETUP_REG (spi->chip_select)); +} + +static int ti_qspi_spi_mtd_mmap_read (struct spi_device *spi, +loff_t from,size_t len, +size_t *retlen,u_char *buf, +u8 read_opcode,u8 addr_width, +u8 dummy_bytes) +{ +struct ti_qspi *qspi =spi_master_get_devdata (spi->master); +int ret =0 ; + +mutex_lock (&qspi->list_lock); + +ti_qspi_enable_memory_map (spi); +ti_qspi_setup_mmap_read (spi, read_opcode, addr_width, + dummy_bytes); +memcpy_fromio (buf, qspi->mmap_base + from, len); + *retlen = len; +ti_qspi_disable_memory_map (spi); + +mutex_unlock (&qspi->list_lock); + +return ret; +} +static int ti_qspi_start_transfer_one (struct spi_master *master,struct spi_message *m) {
@@ -526,6 +609,7 @@ static int ti_qspi_probe(struct platform_device *pdev) ret =PTR_ERR (qspi->mmap_base); goto free_master; } + master->spi_mtd_mmap_read = ti_qspi_spi_mtd_mmap_read; } qspi->fclk =devm_clk_get (&pdev->dev,"fck" );
Signature · 1 line
2.6.2
Mark Brown
maintainerRe: [PATCH v2 2/5] spi: spi-ti-qspi: add mmap mode read support
drivers/spi/spi-ti-qspi.c static int qspi_transfer_msg(struct ti_qspi *qspi, struct spi_transfer *t) · line 445
Quoted 6 lines · Vignesh R
drivers/spi/spi-ti-qspi.c +6
-0+ti_qspi_enable_memory_map (spi); +ti_qspi_setup_mmap_read (spi, read_opcode, addr_width, + dummy_bytes); +memcpy_fromio (buf, qspi->mmap_base + from, len); + *retlen = len; +ti_qspi_disable_memory_map (spi);
We'll be constantly enabling and disabling memory mapping with this.
I'm not sure that's a meaningful cost given that it doesn't actually
remap anything but rather just switches hardware modes, we can always
optimise it later if it is.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151104/2ec01951/attachment.sig>
Vignesh R
maintainerRe: [PATCH v2 2/5] spi: spi-ti-qspi: add mmap mode read support
Quoted 14 lines · Mark Brown
drivers/spi/spi-ti-qspi.c static int qspi_transfer_msg(struct ti_qspi *qspi, struct spi_transfer *t) · line 445
Quoted 6 lines · Vignesh R
drivers/spi/spi-ti-qspi.c +6
-0+ti_qspi_enable_memory_map (spi); +ti_qspi_setup_mmap_read (spi, read_opcode, addr_width, + dummy_bytes); +memcpy_fromio (buf, qspi->mmap_base + from, len); + *retlen = len; +ti_qspi_disable_memory_map (spi);We'll be constantly enabling and disabling memory mapping with this. I'm not sure that's a meaningful cost given that it doesn't actually remap anything but rather just switches hardware modes, we can always optimise it later if it is.
Hmm, I will move the ti_qspi_disable_memory_map() call to ti_qspi_start_transfer_one(), so that mmap mode is disabled only when normal SPI bus transfer is requested. Further, "mmap_enabled" status flag can be used to determine whether mode switch is required or not. This should help to overcome enabling and disabling memory mapping between successive mmap read requests.
Signature · 2 lines
Regards Vignesh
Vignesh R
maintainerPATCH v2 3/5 mtd: devices: m25p80: add support for mmap read request
In reply to Vignesh RCertain spi controllers may support memory mapped interface to read from m25p80 type flash devices. This interface provides better read performance than regular SPI interface.
Call spi_mtd_mmap_read() interface, if supported, to make use of memory-mapped interface.
--- drivers/mtd/devices/m25p80.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/mtd/devices/m25p80.c +5 -0
@@ -133,6 +133,11 @@ static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,/* convert the dummy cycles to the number of bytes */ dummy /=8 ; +if (spi_mmap_read_supported (spi)) +return spi_mtd_mmap_read (spi, from, len, retlen, buf, + nor->read_opcode, + nor->addr_width, dummy); +spi_message_init (&m);memset (t,0 , (sizeof t));
Signature · 1 line
2.6.2
Vignesh R
maintainerPATCH v2 4/5 ARM: dts: DRA7: add entry for qspi mmap region
In reply to Vignesh RAdd qspi memory mapped region entries for DRA7xx based SoCs. Also, update the binding documents for the controller to document this change.
--- Documentation/devicetree/bindings/spi/ti_qspi.txt | 13 +++++++++++++ arch/arm/boot/dts/dra7.dtsi | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/spi/ti_qspi.txt +13 -0
@@ -26,3 +26,16 @@ qspi: qspi at 4b300000 { spi-max-frequency = <25000000>; ti,hwmods = "qspi"; }; + +For dra7xx: +qspi: qspi at 4b300000 { + compatible = "ti,dra7xxx-qspi"; + reg = <0x4b300000 0x100>, <0x4a002558 0x4>, + <0x5c000000 0x4000000>; + reg-names = "qspi_base", "qspi_ctrlmod", + "qspi_mmap"; + #address-cells = <1>; + #size-cells = <0>; + spi-max-frequency = <48000000>; + ti,hwmods = "qspi"; +};
arch/arm/boot/dts/dra7.dtsi +4 -2
@@ -1108,8 +1108,10 @@ qspi: qspi at 4b300000 { compatible = "ti,dra7xxx-qspi"; - reg = <0x4b300000 0x100>; - reg-names = "qspi_base"; + reg = <0x4b300000 0x100>, <0x4a002558 0x4>, + <0x5c000000 0x4000000>; + reg-names = "qspi_base", "qspi_ctrlmod", + "qspi_mmap"; #address-cells = <1>; #size-cells = <0>; ti,hwmods = "qspi";
Signature · 1 line
2.6.2
Re: [PATCH v2 4/5] ARM: dts: DRA7: add entry for qspi mmap region
Quoted 4 lines · Vignesh R
Add qspi memory mapped region entries for DRA7xx based SoCs. Also, update the binding documents for the controller to document this change.
Signed-off-by Vignesh R <[email protected]>
You don't really need an example for every possibility, but
Quoted 50 lines
--- Documentation/devicetree/bindings/spi/ti_qspi.txt | 13 +++++++++++++ arch/arm/boot/dts/dra7.dtsi | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-)Documentation/devicetree/bindings/spi/ti_qspi.txt +13
-0@@ -26,3 +26,16 @@ qspi: qspi at 4b300000 { spi-max-frequency = <25000000>; ti,hwmods = "qspi"; }; + +For dra7xx: +qspi: qspi at 4b300000 { + compatible = "ti,dra7xxx-qspi"; + reg = <0x4b300000 0x100>, <0x4a002558 0x4>, + <0x5c000000 0x4000000>; + reg-names = "qspi_base", "qspi_ctrlmod", + "qspi_mmap"; + #address-cells = <1>; + #size-cells = <0>; + spi-max-frequency = <48000000>; + ti,hwmods = "qspi"; +};arch/arm/boot/dts/dra7.dtsi +4
-2@@ -1108,8 +1108,10 @@ qspi: qspi at 4b300000 { compatible = "ti,dra7xxx-qspi"; - reg = <0x4b300000 0x100>; - reg-names = "qspi_base"; + reg = <0x4b300000 0x100>, <0x4a002558 0x4>, + <0x5c000000 0x4000000>; + reg-names = "qspi_base", "qspi_ctrlmod", + "qspi_mmap"; #address-cells = <1>; #size-cells = <0>; ti,hwmods = "qspi";Signature · 6 lines
2.6.2 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Vignesh R
maintainerPATCH v2 5/5 ARM: dts: AM4372: add entry for qspi mmap region
In reply to Vignesh RAdd qspi memory mapped region entries for AM43xx based SoCs. Also, update the binding documents for the controller to document this change.
--- Documentation/devicetree/bindings/spi/ti_qspi.txt | 5 +++-- arch/arm/boot/dts/am4372.dtsi | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/spi/ti_qspi.txt +3 -2
@@ -17,9 +17,10 @@ Recommended properties: Example: +For am4372: qspi: qspi at 4b300000 { - compatible = "ti,dra7xxx-qspi"; - reg = <0x47900000 0x100>, <0x30000000 0x3ffffff>; + compatible = "ti,am4372-qspi"; + reg = <0x47900000 0x100>, <0x30000000 0x4000000>; reg-names = "qspi_base", "qspi_mmap"; #address-cells = <1>; #size-cells = <0>;
arch/arm/boot/dts/am4372.dtsi +3 -1
@@ -962,7 +962,9 @@ qspi: qspi at 47900000 { compatible = "ti,am4372-qspi"; - reg = <0x47900000 0x100>; + reg = <0x47900000 0x100>, + <0x30000000 0x4000000>; + reg-names = "qspi_base", "qspi_mmap"; #address-cells = <1>; #size-cells = <0>; ti,hwmods = "qspi";
Signature · 1 line
2.6.2
Re: [PATCH v2 5/5] ARM: dts: AM4372: add entry for qspi mmap region
Quoted 4 lines · Vignesh R
Add qspi memory mapped region entries for AM43xx based SoCs. Also, update the binding documents for the controller to document this change.
Signed-off-by Vignesh R <[email protected]>
Quoted 44 lines
--- Documentation/devicetree/bindings/spi/ti_qspi.txt | 5 +++-- arch/arm/boot/dts/am4372.dtsi | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/spi/ti_qspi.txt +3
-2@@ -17,9 +17,10 @@ Recommended properties: Example: +For am4372: qspi: qspi at 4b300000 { - compatible = "ti,dra7xxx-qspi"; - reg = <0x47900000 0x100>, <0x30000000 0x3ffffff>; + compatible = "ti,am4372-qspi"; + reg = <0x47900000 0x100>, <0x30000000 0x4000000>; reg-names = "qspi_base", "qspi_mmap"; #address-cells = <1>; #size-cells = <0>;arch/arm/boot/dts/am4372.dtsi +3
-1@@ -962,7 +962,9 @@ qspi: qspi at 47900000 { compatible = "ti,am4372-qspi"; - reg = <0x47900000 0x100>; + reg = <0x47900000 0x100>, + <0x30000000 0x4000000>; + reg-names = "qspi_base", "qspi_mmap"; #address-cells = <1>; #size-cells = <0>; ti,hwmods = "qspi";Signature · 6 lines
2.6.2 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 5/5] ARM: dts: AM4372: add entry for qspi mmap region
Hi,
Quoted 21 lines · Rob Herring
Quoted 4 lines · Vignesh R
Add qspi memory mapped region entries for AM43xx based SoCs. Also, update the binding documents for the controller to document this change.
Signed-off-by Vignesh R <[email protected]>Acked-by Rob Herring <[email protected]>Quoted 13 lines
--- Documentation/devicetree/bindings/spi/ti_qspi.txt | 5 +++-- arch/arm/boot/dts/am4372.dtsi | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/spi/ti_qspi.txt +0
-0@@ -17,9 +17,10 @@ Recommended properties: Example:
Quoted 9 lines
Documentation/devicetree/bindings/spi/ti_qspi.txt Recommended properties: · line 26
Quoted 9 lines
Documentation/devicetree/bindings/spi/ti_qspi.txt +3
-2+For am4372: qspi: qspi at 4b300000 { - compatible = "ti,dra7xxx-qspi"; - reg = <0x47900000 0x100>, <0x30000000 0x3ffffff>; + compatible = "ti,am4372-qspi"; + reg = <0x47900000 0x100>, <0x30000000 0x4000000>; reg-names = "qspi_base", "qspi_mmap"; #address-cells = <1>; #size-cells = <0>;
and how does the user for this look like ? Don't you need to give this a proper 'ranges' binding ?
Signature · 8 lines
balbi -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 818 bytes Desc: not available URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151105/f7f380d9/attachment.sig>
Vignesh R
maintainerRe: [PATCH v2 5/5] ARM: dts: AM4372: add entry for qspi mmap region
Quoted 25 lines · Felipe Balbi
Hi,
Quoted 21 lines · Rob Herring
Quoted 4 lines · Vignesh R
Add qspi memory mapped region entries for AM43xx based SoCs. Also, update the binding documents for the controller to document this change.
Signed-off-by Vignesh R <[email protected]>Acked-by Rob Herring <[email protected]>Quoted 13 lines
--- Documentation/devicetree/bindings/spi/ti_qspi.txt | 5 +++-- arch/arm/boot/dts/am4372.dtsi | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/spi/ti_qspi.txt +0
-0@@ -17,9 +17,10 @@ Recommended properties: Example:
Quoted 13 lines
Quoted 9 lines
Documentation/devicetree/bindings/spi/ti_qspi.txt Recommended properties: · line 26
Quoted 9 lines
Documentation/devicetree/bindings/spi/ti_qspi.txt +3
-2+For am4372: qspi: qspi at 4b300000 { - compatible = "ti,dra7xxx-qspi"; - reg = <0x47900000 0x100>, <0x30000000 0x3ffffff>; + compatible = "ti,am4372-qspi"; + reg = <0x47900000 0x100>, <0x30000000 0x4000000>; reg-names = "qspi_base", "qspi_mmap"; #address-cells = <1>; #size-cells = <0>;and how does the user for this look like ? Don't you need to give this a proper 'ranges' binding ?
There are no other users of qspi_mmap region except ti-qspi driver itself:
In probe:
res_mmap = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi_mmap"); qspi->mmap_base = devm_ioremap_resource(&pdev->dev, res_mmap);
and for reading from mmap region:
memcpy_fromio(buf, qspi->mmap_base + from, len);
Signature · 2 lines
Regards Vignesh