spi: Extend the framework to generically support memory devices
Subsystems (5)
v2 cover spi: Extend the framework to generically support memory devices
Hello,
Shrinking a bit the explanation on why the spi-mem abstraction is needed (a detailed explanation is available here [2]). In addition to what as been said in my initial explanation I'll add that making it part of the SPI framework instead of as an extra independent layer is justified by the fact that some controllers support both SPI memory operations and regular SPI transfers, and it's cleaner to have both features exposed through a single driver.
In this v2, I think I addressed all the comments I had except the advanced direct memory mapping stuff mentioned by Cyrille, but I don't think any of the work done in this series prevents us from adding this feature later on.
For those who want to have the full picture, here is a branch [1] containing the SPI NAND framework based on top of this spi-mem layer.
Thanks,
Boris
[1]https://github.com/bbrezillon/linux/tree/spi-mem [2]https://www.spinics.net/lists/linux-spi/msg12058.html
Boris Brezillon (10):
spi: Check presence the of ->transfer[_xxx]() before registering a
controller
spi: Expose spi_{map,unmap}_buf() for internal use
spi: Add an helper to flush the message queue
spi: Extend the core to ease integration of SPI memory controllers
spi: Make support for regular transfers optional when ->mem_ops !=
NULL
spi: bcm-qspi: Implement the spi_mem interface
spi: bcm53xx: Implement the spi_mem interface
spi: ti-qspi: Implement the spi_mem interface
mtd: spi-nor: Use the spi_mem_xx() API
spi: Get rid of the spi_flash_read() API
drivers/mtd/devices/Kconfig | 1 + drivers/mtd/devices/m25p80.c | 236 +++++++++---------------- drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/spi-bcm-qspi.c | 162 ++++++++--------- drivers/spi/spi-bcm2835.c | 1 + drivers/spi/spi-bcm53xx.c | 36 ++-- drivers/spi/spi-mem.c | 408 +++++++++++++++++++++++++++++++++++++++++++ drivers/spi/spi-ti-qspi.c | 85 +++++---- drivers/spi/spi.c | 142 +++++++-------- include/linux/spi/spi-mem.h | 249 ++++++++++++++++++++++++++ include/linux/spi/spi.h | 88 ++++------ 12 files changed, 1005 insertions(+), 411 deletions(-) create mode 100644 drivers/spi/spi-mem.c create mode 100644 include/linux/spi/spi-mem.h
Signature · 6 lines
2.14.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 1/10 spi: Check presence the of ->transfer[_xxx]() before registering a controller
Right now, no checks are done on the presence of a ->transfer[_xxx]() method, which can lead to a NULL pointer dereference when someone starts sending something on the bus.
Do the check at registration time and refuse to add the controller if all ->transfer[_xxx]() pointers are NULL.
--- drivers/spi/spi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/spi/spi.c +21 -0
@@ -2063,6 +2063,19 @@ static int of_spi_register_master(struct spi_controller *ctlr) }#endif +static int spi_controller_check_ops (struct spi_controller *ctlr) +{ +/* +* The controller must at least implement one of the ->transfer() +* hooks. +*/ +if (!ctlr->transfer && !ctlr->transfer_one && + !ctlr->transfer_one_message) +return -EINVAL ; + +return 0 ; +} +/** * spi_register_controller - register SPI master or slave controller * @ctlr: initialized master, originally from spi_alloc_master() or
@@ -2096,6 +2109,14 @@ int spi_register_controller(struct spi_controller *ctlr)if (!dev)return -ENODEV ; +/* +* Make sure all necessary hooks are implemented before registering +* the SPI controller. +*/ + status =spi_controller_check_ops (ctlr); +if (status) +return status; +if (!spi_controller_is_slave (ctlr)) { status =of_spi_register_master (ctlr);if (status)
Signature · 6 lines
2.14.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Mark Brown
maintainerApplied "spi: Check presence the of ->transfer[_xxx]() before registering a controller" to the spi tree
The patch
spi: Check presence the of ->transfer[_xxx]() before registering a controller
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
bd40560ac3365e3a2d512d0ad03ceb6c7f603c0cMon Sep 17 00:00:00 2001
From: Boris Brezillon <[email protected]>
Date: Wed, 11 Apr 2018 00:44:30 +0200
Subject: [PATCH] spi: Check presence the of ->transfer[_xxx]() before
registering a controller
Right now, no checks are done on the presence of a ->transfer[_xxx]() method, which can lead to a NULL pointer dereference when someone starts sending something on the bus.
Do the check at registration time and refuse to add the controller if all ->transfer[_xxx]() pointers are NULL.
--- drivers/spi/spi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/spi/spi.c +21 -0
@@ -2063,6 +2063,19 @@ static int of_spi_register_master(struct spi_controller *ctlr) }#endif +static int spi_controller_check_ops (struct spi_controller *ctlr) +{ +/* +* The controller must at least implement one of the ->transfer() +* hooks. +*/ +if (!ctlr->transfer && !ctlr->transfer_one && + !ctlr->transfer_one_message) +return -EINVAL ; + +return 0 ; +} +/** * spi_register_controller - register SPI master or slave controller * @ctlr: initialized master, originally from spi_alloc_master() or
@@ -2096,6 +2109,14 @@ int spi_register_controller(struct spi_controller *ctlr)if (!dev)return -ENODEV ; +/* +* Make sure all necessary hooks are implemented before registering +* the SPI controller. +*/ + status =spi_controller_check_ops (ctlr); +if (status) +return status; +if (!spi_controller_is_slave (ctlr)) { status =of_spi_register_master (ctlr);if (status)
Signature · 6 lines
2.17.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: Applied "spi: Check presence the of ->transfer[_xxx]() before registering a controller" to the spi tree
Hi Mark,
Quoted 8 lines · On Mon, 16 Apr 2018 13:13:24 +0100 Mark Brown <[email protected]> wrote:
The patch
spi: Check presence the of ->transfer[_xxx]() before registering a controller
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
I can't find this patch in any of your spi branches. Has it been intentionally dropped, and if it was, do you remember why?
Regards,
Boris
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Mark Brown
maintainerRe: Applied "spi: Check presence the of ->transfer[_xxx]() before registering a controller" to the spi tree
Quoted 2 lines · Boris Brezillon
I can't find this patch in any of your spi branches. Has it been intentionally dropped, and if it was, do you remember why?
No, not dropped intentionally.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Mark Brown
maintainerApplied "spi: Check presence the of ->transfer[_xxx]() before registering a controller" to the spi tree
In reply to Boris BrezillonThe patch
spi: Check presence the of ->transfer[_xxx]() before registering a controller
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
bdf3a3b59a7ab1972e7d2242c9466ba7e79f0004Mon Sep 17 00:00:00 2001
From: Boris Brezillon <[email protected]>
Date: Wed, 11 Apr 2018 00:44:30 +0200
Subject: [PATCH] spi: Check presence the of ->transfer[_xxx]() before
registering a controller
Right now, no checks are done on the presence of a ->transfer[_xxx]() method, which can lead to a NULL pointer dereference when someone starts sending something on the bus.
Do the check at registration time and refuse to add the controller if all ->transfer[_xxx]() pointers are NULL.
--- drivers/spi/spi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/spi/spi.c +21 -0
@@ -2068,6 +2068,19 @@ static int of_spi_register_master(struct spi_controller *ctlr) }#endif +static int spi_controller_check_ops (struct spi_controller *ctlr) +{ +/* +* The controller must at least implement one of the ->transfer() +* hooks. +*/ +if (!ctlr->transfer && !ctlr->transfer_one && + !ctlr->transfer_one_message) +return -EINVAL ; + +return 0 ; +} +/** * spi_register_controller - register SPI master or slave controller * @ctlr: initialized master, originally from spi_alloc_master() or
@@ -2101,6 +2114,14 @@ int spi_register_controller(struct spi_controller *ctlr)if (!dev)return -ENODEV ; +/* +* Make sure all necessary hooks are implemented before registering +* the SPI controller. +*/ + status =spi_controller_check_ops (ctlr); +if (status) +return status; +if (!spi_controller_is_slave (ctlr)) { status =of_spi_register_master (ctlr);if (status)
Signature · 6 lines
2.17.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 2/10 spi: Expose spi_{map,unmap}_buf() for internal use
In reply to Boris Brezillonspi_{map,unmap}_buf() are needed by the spi-mem logic that is about to be introduced to prepare data buffer for DMA operations.
Remove the static specifier on these functions and add their prototypes to include/linux/spi/spi.h. We do not export the symbols here because both SPI_MEM and SPI can't be enabled as modules and we'd like to prevent controller/device drivers from using these functions.
---
I see 2 other options to not expose internal stuff to spi users or controller drivers:
1/ we do not expose spi_map/unmap_buf() and instead implement
spi_controller_dma_map/unmap_mem_op_data() directly in spi.c
2/ we create a new header (drivers/spi/internals.h?) for all
definitions that are meant for internal use (shared between spi.c and spi-mem.c)
I personally prefer #2 as it provides a better separation between spi and spi-mem code.
--- drivers/spi/spi.c | 23 +++++------------------ include/linux/spi/spi.h | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 18 deletions(-)
drivers/spi/spi.c +5 -18
@@ -740,9 +740,9 @@ static void spi_set_cs(struct spi_device *spi, bool enable) }#ifdef CONFIG_HAS_DMA -static int spi_map_buf (struct spi_controller *ctlr,struct device *dev, -struct sg_table *sgt,void *buf,size_t len, -enum dma_data_direction dir) +int spi_map_buf (struct spi_controller *ctlr,struct device *dev, +struct sg_table *sgt,void *buf,size_t len, +enum dma_data_direction dir) {const bool vmalloced_buf =is_vmalloc_addr (buf);unsigned int max_seg_size =dma_get_max_seg_size (dev);
@@ -821,8 +821,8 @@ static int spi_map_buf(struct spi_controller *ctlr, struct device *dev,return 0 ; } -static void spi_unmap_buf (struct spi_controller *ctlr,struct device *dev, -struct sg_table *sgt,enum dma_data_direction dir) +void spi_unmap_buf (struct spi_controller *ctlr,struct device *dev, +struct sg_table *sgt,enum dma_data_direction dir) {if (sgt->orig_nents) {dma_unmap_sg (dev, sgt->sgl, sgt->orig_nents, dir);
@@ -907,19 +907,6 @@ static int __spi_unmap_msg(struct spi_controller *ctlr, struct spi_message *msg) return 0; }#else /* !CONFIG_HAS_DMA */ -static inline int spi_map_buf (struct spi_controller *ctlr,struct device *dev, -struct sg_table *sgt,void *buf,size_t len, -enum dma_data_direction dir) -{ -return -EINVAL ; -} - -static inline void spi_unmap_buf (struct spi_controller *ctlr, -struct device *dev,struct sg_table *sgt, -enum dma_data_direction dir) -{ -} -static inline int __spi_map_msg (struct spi_controller *ctlr,struct spi_message *msg) {
include/linux/spi/spi.h +26 -0
@@ -16,6 +16,7 @@#define __LINUX_SPI_H#include <linux/device.h> +#include <linux/dma-direction.h> #include <linux/mod_devicetable.h> #include <linux/slab.h> #include <linux/kthread.h>
@@ -614,6 +615,31 @@ static inline bool spi_controller_is_slave(struct spi_controller *ctlr)extern int spi_controller_suspend (struct spi_controller *ctlr);extern int spi_controller_resume (struct spi_controller *ctlr); +/* +* Helpers needed by the spi-mem logic. Should not be used outside of +* spi-mem.c +*/ +#ifdef CONFIG_HAS_DMA +int spi_map_buf (struct spi_controller *ctlr,struct device *dev, +struct sg_table *sgt,void *buf,size_t len, +enum dma_data_direction dir); +void spi_unmap_buf (struct spi_controller *ctlr,struct device *dev, +struct sg_table *sgt,enum dma_data_direction dir); +#else /* !CONFIG_HAS_DMA */ +static inline int spi_map_buf (struct spi_controller *ctlr,struct device *dev, +struct sg_table *sgt,void *buf,size_t len, +enum dma_data_direction dir) +{ +return -EINVAL ; +} + +static inline void spi_unmap_buf (struct spi_controller *ctlr, +struct device *dev,struct sg_table *sgt, +enum dma_data_direction dir) +{ +} +#endif /* CONFIG_HAS_DMA */ +/* Calls the driver make to interact with the message queue */ extern struct spi_message *spi_get_next_queued_message (struct spi_controller *ctlr);extern void spi_finalize_current_message (struct spi_controller *ctlr);
Signature · 6 lines
2.14.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Mark Brown
maintainerRe: [PATCH v2 02/10] spi: Expose spi_{map,unmap}_buf() for internal use
Quoted 10 lines · Boris Brezillon
2/ we create a new header (
drivers/spi/internals.h?) for all
definitions that are meant for internal use (shared betweenspi.candspi-mem.c)I personally prefer #2 as it provides a better separation between spi and spi-mem code.
--- drivers/spi/spi.c | 23 +++++------------------ include/linux/spi/spi.h | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 18 deletions(-)
I prefer that too (if you prefer it you should go with it so it's the option on the table!). I'd go with drivers/spi/internals.h though so that it's even more obvious if something is being silly trying to use it when they shouldn't.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 02/10] spi: Expose spi_{map,unmap}_buf() for internal use
Hi Mark,
Quoted 13 lines · On Mon, 16 Apr 2018 13:11:27 +0100 Mark Brown <[email protected]> wrote:
Quoted 10 lines · Boris Brezillon
2/ we create a new header (
drivers/spi/internals.h?) for all
definitions that are meant for internal use (shared betweenspi.candspi-mem.c)I personally prefer #2 as it provides a better separation between spi and spi-mem code.
--- drivers/spi/spi.c | 23 +++++------------------ include/linux/spi/spi.h | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 18 deletions(-)
Quoted 2 lines
I prefer that too (if you prefer it you should go with it so it's the option on the table!).
I hesitated for long and went for the solution I didn't like, mainly because everything is already put in a single header file so I thought you would prefer that approach.
Quoted 3 lines
I'd go with
drivers/spi/internals.hthough so
that it's even more obvious if something is being silly trying to use it when they shouldn't.
Okay, I'll move those definitions to drivers/spi/internals.h.
Thanks,
Boris
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 3/10 spi: Add an helper to flush the message queue
In reply to Boris BrezillonThis is needed by the spi-mem logic to force all messages that have been queued before a memory operation to be sent before we start the memory operation. We do that in order to guarantee that spi-mem operations do not preempt regular SPI transfers.
---
As for the spi_map/unmap_buf() I'd suggest to move the prototype definition to an internal header file.
--- drivers/spi/spi.c | 16 ++++++++++++++++ include/linux/spi/spi.h | 2 ++ 2 files changed, 18 insertions(+)
drivers/spi/spi.c +16 -0
@@ -1520,6 +1520,22 @@ static int spi_controller_initialize_queue(struct spi_controller *ctlr)return ret; } +/** +* spi_flush_queue - Send all pending messages in the queue from the callers' +* context +* @ctlr: controller to process queue for +* +* This should be used when one wants to ensure all pending messages have been +* sent before doing something. Is used by the spi-mem code to make sure SPI +* memory operations do not preempt regular SPI transfers that have been queued +* before the spi-mem operation. +*/ +void spi_flush_queue (struct spi_controller *ctlr) +{ +if (ctlr->transfer == spi_queued_transfer) +__spi_pump_messages (ctlr, false); +} +/*-------------------------------------------------------------------------*/ #if defined(CONFIG_OF )
include/linux/spi/spi.h +2 -0
@@ -619,6 +619,8 @@ extern int spi_controller_resume(struct spi_controller *ctlr);* Helpers needed by the spi-mem logic. Should not be used outside of * spi-mem.c */ +void spi_flush_queue (struct spi_controller *ctrl); +#ifdef CONFIG_HAS_DMA int spi_map_buf(struct spi_controller *ctlr, struct device *dev, struct sg_table *sgt, void *buf, size_t len,
Signature · 6 lines
2.14.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 4/10 spi: Extend the core to ease integration of SPI memory controllers
In reply to Boris BrezillonSome controllers are exposing high-level interfaces to access various kind of SPI memories. Unfortunately they do not fit in the current spi_controller model and usually have drivers placed in drivers/mtd/spi-nor which are only supporting SPI NORs and not SPI memories in general.
This is an attempt at defining a SPI memory interface which works for all kinds of SPI memories (NORs, NANDs, SRAMs).
---
Changes in v2:
- Move all changes not directly related to spi_mem out of this commit
- Do not abuse ternary operation
- Reword a few comments and fix typos
- Do not make the default buswidth check in spi_mem_support_ops() if the controller implements this hook
- Make the addr value an u64 instead of an array of byte
- Move all spi-mem code/defs to separate header/source files and add a new Kconfig option to enable this interface
--- drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/spi-mem.c | 408 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/spi/spi-mem.h | 249 +++++++++++++++++++++++++++ include/linux/spi/spi.h | 7 + 5 files changed, 672 insertions(+) create mode 100644 drivers/spi/spi-mem.c create mode 100644 include/linux/spi/spi-mem.h
drivers/spi/Kconfig +7 -0
@@ -47,6 +47,13 @@ config SPI_MASTER if SPI_MASTER +config SPI_MEM + bool "SPI memory extension" + help + Enable this option if you want to enable the SPI memory extension. + This extension is meant to simplify interaction with SPI memories + by providing an high-level interface to send memory-like commands. + comment "SPI Master Controller Drivers" config SPI_ALTERA
drivers/spi/Makefile +1 -0
@@ -8,6 +8,7 @@ ccflags-$(CONFIG_SPI_DEBUG) := -DDEBUG # small core, mostly translating board-specific # config declarations into driver model code obj-$(CONFIG_SPI_MASTER) += spi.o +obj-$(CONFIG_SPI_MEM) += spi-mem.o obj-$(CONFIG_SPI_SPIDEV) += spidev.o obj-$(CONFIG_SPI_LOOPBACK_TEST) += spi-loopback-test.o
drivers/spi/spi-mem.c new file +408 -0
408 lines not on this page · raw message
include/linux/spi/spi-mem.h new file +249 -0
249 lines not on this page · raw message
include/linux/spi/spi.h +7 -0
@@ -28,6 +28,7 @@ struct property_entry;struct spi_controller ;struct spi_transfer ;struct spi_flash_read_message ; +struct spi_controller_mem_ops ;/* * INTERFACES between SPI master-side drivers and SPI slave protocol handlers,
@@ -377,6 +378,9 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)* transfer_one callback. * @handle_err: the subsystem calls the driver to handle an error that occurs * in the generic implementation of transfer_one_message(). +* @mem_ops: optimized/dedicated operations for interactions with SPI memory. +* This field is optional and should only be implemented if the +* controller has native support for memory like operations. * @unprepare_message: undo any work done by prepare_message(). * @slave_abort: abort the ongoing transfer request on an SPI slave controller * @spi_flash_read: to support spi-controller hardwares that provide
@@ -565,6 +569,9 @@ struct spi_controller {void (*handle_err)(struct spi_controller *ctlr,struct spi_message *message); +/* Optimized handlers for SPI memory-like operations. */ +const struct spi_controller_mem_ops *mem_ops; +/* gpio chip select */ int *cs_gpios;
Signature · 6 lines
2.14.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Vignesh R
maintainerRe: [PATCH v2 04/10] spi: Extend the core to ease integration of SPI memory controllers
Hi,
- Sourav Poddar <[email protected]> mail ID no longer valid.
Quoted 11 lines · Boris Brezillon
Some controllers are exposing high-level interfaces to access various kind of SPI memories. Unfortunately they do not fit in the current
spi_controllermodel and usually have drivers placed indrivers/mtd/spi-norwhich are only supporting SPI NORs and not SPI memories in general.This is an attempt at defining a SPI memory interface which works for all kinds of SPI memories (NORs, NANDs, SRAMs).
Signed-off-by Boris Brezillon <[email protected]>---
[...]
Quoted 19 lines
include/linux/spi/spi-mem.h new file +19
-0+/** +* struct spi_mem_op - describes a SPI memory operation +* @cmd.buswidth: number of IO lines used to transmit the command +* @cmd.opcode: operation 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 +* @addr.val: address value. This value is always sent MSB first on the bus. +* 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. +* @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 +* @data.buswidth: number of IO lanes used to send/receive the data +* @data.dir: direction of the transfer +* @data.buf.in: input buffer +* @data.buf.out: output buffer +*/
include/linux/spi/spi-mem.h line 94
Quoted 10 lines
include/linux/spi/spi-mem.h new file +10
-0+struct spi_mem_op { +struct { +u8 buswidth; +u8 opcode; + } cmd; + +struct { +u8 nbytes; +u8 buswidth; +u64 val;
You could consider using loff_t here and be consistent with spi_nor_read/write() API as well as mtd->_read().
Quoted 9 lines
include/linux/spi/spi-mem.h new file +9
-0+ } addr; + +struct { +u8 nbytes; +u8 buswidth; + } dummy; + +struct { +u8 buswidth;
include/linux/spi/spi-mem.h line 113
Quoted 10 lines
include/linux/spi/spi-mem.h new file +10
-0+enum spi_mem_data_dir dir; +unsigned int nbytes; +/* buf.{in,out} must be DMA-able. */ +union { +void *in; +const void *out; + } buf; + } data; +}; +
Some flash devices support Dual/Quad DDR (Double Data Rate) mode and the SPI controller driver would need to know this information. We will need to add a field for that.
Currently, there are drivers under mtd/spi-nor/ that need to know page/sector/total size of flash memory(info available in -`struct spi_nor). We would need a way to provide this info to spi_mem drivers, if we ever plan to move drivers under mtd/spi-nor to spi/
[...]
Signature · 2 lines
Regards Vignesh
Re: [PATCH v2 04/10] spi: Extend the core to ease integration of SPI memory controllers
Quoted 43 lines · On Thu, 12 Apr 2018 20:08:28 +0530 Vignesh R <[email protected]> wrote:
Hi,
- Sourav Poddar <[email protected]> mail ID no longer valid.
Quoted 11 lines · Boris Brezillon
Some controllers are exposing high-level interfaces to access various kind of SPI memories. Unfortunately they do not fit in the current
spi_controllermodel and usually have drivers placed indrivers/mtd/spi-norwhich are only supporting SPI NORs and not SPI memories in general.This is an attempt at defining a SPI memory interface which works for all kinds of SPI memories (NORs, NANDs, SRAMs).
Signed-off-by Boris Brezillon <[email protected]>---
[...]
Quoted 24 lines
include/linux/spi/spi-mem.h new file +24
-0+/** +* struct spi_mem_op - describes a SPI memory operation +* @cmd.buswidth: number of IO lines used to transmit the command +* @cmd.opcode: operation 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 +* @addr.val: address value. This value is always sent MSB first on the bus. +* 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. +* @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 +* @data.buswidth: number of IO lanes used to send/receive the data +* @data.dir: direction of the transfer +* @data.buf.in: input buffer +* @data.buf.out: output buffer +*/ +struct spi_mem_op { +struct { +u8 buswidth; +u8 opcode; + } cmd;
Quoted 8 lines
include/linux/spi/spi-mem.h line 94
Quoted 5 lines
include/linux/spi/spi-mem.h new file +5
-0+ +struct { +u8 nbytes; +u8 buswidth; +u64 val;You could consider using
loff_there and be consistent with spi_nor_read/write() API as well asmtd->_read().
Hm, I always have a hard time using types which does not clearly say how large they are, but okay.
Quoted 16 lines
Quoted 16 lines
include/linux/spi/spi-mem.h new file +15
-0+ } addr; + +struct { +u8 nbytes; +u8 buswidth; + } dummy; + +struct { +u8 buswidth; +enum spi_mem_data_dir dir; +unsigned int nbytes; +/* buf.{in,out} must be DMA-able. */ +union { +void *in; +const void *out;
Quoted 8 lines
include/linux/spi/spi-mem.h line 113
Quoted 4 lines
include/linux/spi/spi-mem.h new file +4
-0+ } buf; + } data; +}; +Some flash devices support Dual/Quad DDR (Double Data Rate) mode and the SPI controller driver would need to know this information. We will need to add a field for that.
Well, let's wait until we actually need that.
Quoted 5 lines
Currently, there are drivers under mtd/spi-nor/ that need to know page/sector/total size of flash memory(info available in -`struct
spi_nor). We would need a way to provide this info tospi_memdrivers, if we ever plan to move drivers under mtd/spi-nor to spi/
Again, we'll see when we'll try to move them, but I hope still we won't need that. Looks like the kind of information I'd like to keep away from spi controller drivers.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 04/10] spi: Extend the core to ease integration of SPI memory controllers
Quoted 55 lines · On Thu, 12 Apr 2018 17:10:05 +0200 Boris Brezillon…
Quoted 43 lines · On Thu, 12 Apr 2018 20:08:28 +0530 Vignesh R <[email protected]> wrote:
Hi,
- Sourav Poddar <[email protected]> mail ID no longer valid.
Quoted 11 lines · Boris Brezillon
Some controllers are exposing high-level interfaces to access various kind of SPI memories. Unfortunately they do not fit in the current
spi_controllermodel and usually have drivers placed indrivers/mtd/spi-norwhich are only supporting SPI NORs and not SPI memories in general.This is an attempt at defining a SPI memory interface which works for all kinds of SPI memories (NORs, NANDs, SRAMs).
Signed-off-by Boris Brezillon <[email protected]>---
[...]
Quoted 24 lines
include/linux/spi/spi-mem.h new file +24
-0+/** +* struct spi_mem_op - describes a SPI memory operation +* @cmd.buswidth: number of IO lines used to transmit the command +* @cmd.opcode: operation 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 +* @addr.val: address value. This value is always sent MSB first on the bus. +* 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. +* @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 +* @data.buswidth: number of IO lanes used to send/receive the data +* @data.dir: direction of the transfer +* @data.buf.in: input buffer +* @data.buf.out: output buffer +*/ +struct spi_mem_op { +struct { +u8 buswidth; +u8 opcode; + } cmd;Quoted 8 lines
include/linux/spi/spi-mem.h line 94
Quoted 5 lines
include/linux/spi/spi-mem.h new file +5
-0+ +struct { +u8 nbytes; +u8 buswidth; +u64 val;You could consider using
loff_there and be consistent with spi_nor_read/write() API as well asmtd->_read().
Quoted 2 lines
Hm, I always have a hard time using types which does not clearly say how large they are, but okay.
BTW, loff_t is signed, which doesn't really make sense here, so I'd like to keep an u64 unless you have a strong reason not to.
Quoted 29 lines
Quoted 17 lines
Quoted 17 lines
include/linux/spi/spi-mem.h new file +15
-0+ } addr; + +struct { +u8 nbytes; +u8 buswidth; + } dummy; + +struct { +u8 buswidth; +enum spi_mem_data_dir dir; +unsigned int nbytes; +/* buf.{in,out} must be DMA-able. */ +union { +void *in; +const void *out;Quoted 8 lines
include/linux/spi/spi-mem.h line 113
Quoted 4 lines
include/linux/spi/spi-mem.h new file +4
-0+ } buf; + } data; +}; +Some flash devices support Dual/Quad DDR (Double Data Rate) mode and the SPI controller driver would need to know this information. We will need to add a field for that.
Well, let's wait until we actually need that.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Currently, there are drivers under mtd/spi-nor/ that need to know page/sector/total size of flash memory(info available in -`struct
spi_nor). We would need a way to provide this info tospi_memdrivers, if we ever plan to move drivers under mtd/spi-nor to spi/Again, we'll see when we'll try to move them, but I hope still we won't need that. Looks like the kind of information I'd like to keep away from spi controller drivers.
Let me clarify this part. I already thought a bit about this problem, and that's the very reason we have an intermediate layer with a spi_mem struct pointing to the real spi_device object. The idea is to add new fields to spi_mem object if/when we really have to. We'd also have to add ->attach/detach() methods to spi_mem_ops so that SPI mem controller can know when a new device is about to be accessed by a spi-mem driver, can parse the information provided in spi_mem and configure the controller accordingly.
Now, even if that's something I considered when designing the spi-mem interface, I'd like to stay away from this sort of specialization as long as possible. Why? Simply because dealing with memory specificities like "is it a NOR, a NAND or an SRAM? Should I erase blocks before writing data? What's the page size, sector size, eraseblock size? ..." is not something that belongs in the SPI framework. IMHO, it should stay in SPI mem drivers (the SPI NOR or SPI NAND framework are such SPI mem drivers).
This being said, I see a real need for advanced features. One example I have in mind is a "direct-mapping API", where a spi_mem user could ask for a specific region of the memory to be directly mapped (if the feature is supported by the controller of course). And that's something I think we can make generic enough to consider adding it to the spi_mem_ops interface. All we'll need is a way to say "I want to map this portion of the memory in R, W or RW and when you need to read/write use this spi_mem_op and patch the address based on the actual memory address that is being accessed".
Maybe I'm wrong and some controllers actually need to know which type of device they are dealing with, but in that case, I'm not so sure they belong in the SPI framework at all, unless they provide a dummy mode in which they can act as a regular SPI/SPI mem controller (i.e. send SPI mem operations without trying to be smart and do things behind our back).
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Vignesh R
maintainerRe: [PATCH v2 04/10] spi: Extend the core to ease integration of SPI memory controllers
On Friday 13 April 2018 01:29 AM, Boris Brezillon wrote:
[...]
Quoted 33 lines
Quoted 33 lines
Quoted 32 lines
Quoted 19 lines
include/linux/spi/spi-mem.h new file +19
-0+/** +* struct spi_mem_op - describes a SPI memory operation +* @cmd.buswidth: number of IO lines used to transmit the command +* @cmd.opcode: operation 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 +* @addr.val: address value. This value is always sent MSB first on the bus. +* 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. +* @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 +* @data.buswidth: number of IO lanes used to send/receive the data +* @data.dir: direction of the transfer +* @data.buf.in: input buffer +* @data.buf.out: output buffer +*/ include/linux/spi/spi-mem.h line 94
Quoted 10 lines
include/linux/spi/spi-mem.h new file +10
-0+struct spi_mem_op { +struct { + u8 buswidth; + u8 opcode; + } cmd; + +struct { + u8 nbytes; + u8 buswidth; + u64 val;You could consider using
loff_there and be consistent with spi_nor_read/write() API as well asmtd->_read().
Quoted 6 lines
Quoted 2 lines
Hm, I always have a hard time using types which does not clearly say how large they are, but okay.
BTW,
loff_tis signed, which doesn't really make sense here, so I'd like to keep an u64 unless you have a strong reason not to.
Okay.
Quoted 56 lines
Quoted 29 lines
Quoted 17 lines
Quoted 15 lines
+ } addr;
include/linux/spi/spi-mem.h new file +14
-0+ +struct { + u8 nbytes; + u8 buswidth; + } dummy; + +struct { + u8 buswidth; + enum spi_mem_data_dir dir; + unsigned int nbytes; + /* buf.{in,out} must be DMA-able. */ + union { + void *in; + const void *out;Quoted 8 lines
Quoted 4 lines
+ } buf;
+ } data;
+};
+Some flash devices support Dual/Quad DDR (Double Data Rate) mode and the SPI controller driver would need to know this information. We will need to add a field for that.
Well, let's wait until we actually need that.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Currently, there are drivers under mtd/spi-nor/ that need to know page/sector/total size of flash memory(info available in -`struct
spi_nor). We would need a way to provide this info tospi_memdrivers, if we ever plan to move drivers under mtd/spi-nor to spi/Again, we'll see when we'll try to move them, but I hope still we won't need that. Looks like the kind of information I'd like to keep away from spi controller drivers.
Let me clarify this part. I already thought a bit about this problem, and that's the very reason we have an intermediate layer with a
spi_memstruct pointing to the realspi_deviceobject. The idea is to add new fields tospi_memobject if/when we really have to. We'd also have to add ->attach/detach() methods tospi_mem_opsso that SPI mem controller can know when a new device is about to be accessed by a spi-mem driver, can parse the information provided inspi_memand configure the controller accordingly.Now, even if that's something I considered when designing the spi-mem interface, I'd like to stay away from this sort of specialization as long as possible. Why? Simply because dealing with memory specificities like "is it a NOR, a NAND or an SRAM? Should I erase blocks before writing data? What's the page size, sector size, eraseblock size? ..." is not something that belongs in the SPI framework. IMHO, it should stay in SPI mem drivers (the SPI NOR or SPI NAND framework are such SPI mem drivers).
Quoted 10 lines
This being said, I see a real need for advanced features. One example I have in mind is a "direct-mapping API", where a
spi_memuser could ask for a specific region of the memory to be directly mapped (if the feature is supported by the controller of course). And that's something I think we can make generic enough to consider adding it to thespi_mem_opsinterface. All we'll need is a way to say "I want to map this portion of the memory in R, W or RW and when you need to read/write use thisspi_mem_opand patch the address based on the actual memory address that is being accessed".
Many of the SPI NOR controllers, especially the ones that support direct mapping are smart and need more flash specific data. For example, cadence-quadspi needs to know pagesize as this controller automatically sends write enable when writes cross page boundary. I guess, such controllers pose a problem to spi_mem_ops in passing spi_nor internal data to drivers. Or such controllers may need to be continued to be supported directly under spi-nor framework?
I am okay with this series in general. But, was trying to understand which drivers will fall under spi_mem and which will continue to remain under mtd/spi-nor
Quoted 7 lines
Maybe I'm wrong and some controllers actually need to know which type of device they are dealing with, but in that case, I'm not so sure they belong in the SPI framework at all, unless they provide a dummy mode in which they can act as a regular SPI/SPI mem controller (i.e. send SPI mem operations without trying to be smart and do things behind our back).
Signature · 2 lines
Regards Vignesh
Re: [PATCH v2 04/10] spi: Extend the core to ease integration of SPI memory controllers
Hi Vignesh,
Quoted 68 lines · On Tue, 17 Apr 2018 09:42:18 +0530 Vignesh R <[email protected]> wrote:
Quoted 56 lines
Quoted 29 lines
Quoted 17 lines
Quoted 15 lines
+ } addr;
include/linux/spi/spi-mem.h new file +14
-0+ +struct { + u8 nbytes; + u8 buswidth; + } dummy; + +struct { + u8 buswidth; + enum spi_mem_data_dir dir; + unsigned int nbytes; + /* buf.{in,out} must be DMA-able. */ + union { + void *in; + const void *out;Quoted 8 lines
Quoted 4 lines
+ } buf;
+ } data;
+};
+Some flash devices support Dual/Quad DDR (Double Data Rate) mode and the SPI controller driver would need to know this information. We will need to add a field for that.
Well, let's wait until we actually need that.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Currently, there are drivers under mtd/spi-nor/ that need to know page/sector/total size of flash memory(info available in -`struct
spi_nor). We would need a way to provide this info tospi_memdrivers, if we ever plan to move drivers under mtd/spi-nor to spi/Again, we'll see when we'll try to move them, but I hope still we won't need that. Looks like the kind of information I'd like to keep away from spi controller drivers.
Let me clarify this part. I already thought a bit about this problem, and that's the very reason we have an intermediate layer with a
spi_memstruct pointing to the realspi_deviceobject. The idea is to add new fields tospi_memobject if/when we really have to. We'd also have to add ->attach/detach() methods tospi_mem_opsso that SPI mem controller can know when a new device is about to be accessed by a spi-mem driver, can parse the information provided inspi_memand configure the controller accordingly.Now, even if that's something I considered when designing the spi-mem interface, I'd like to stay away from this sort of specialization as long as possible. Why? Simply because dealing with memory specificities like "is it a NOR, a NAND or an SRAM? Should I erase blocks before writing data? What's the page size, sector size, eraseblock size? ..." is not something that belongs in the SPI framework. IMHO, it should stay in SPI mem drivers (the SPI NOR or SPI NAND framework are such SPI mem drivers).
Quoted 10 lines
This being said, I see a real need for advanced features. One example I have in mind is a "direct-mapping API", where a
spi_memuser could ask for a specific region of the memory to be directly mapped (if the feature is supported by the controller of course). And that's something I think we can make generic enough to consider adding it to thespi_mem_opsinterface. All we'll need is a way to say "I want to map this portion of the memory in R, W or RW and when you need to read/write use thisspi_mem_opand patch the address based on the actual memory address that is being accessed".
Quoted 7 lines
Many of the SPI NOR controllers, especially the ones that support direct mapping are smart and need more flash specific data. For example, cadence-quadspi needs to know pagesize as this controller automatically sends write enable when writes cross page boundary. I guess, such controllers pose a problem to
spi_mem_opsin passingspi_norinternal data to drivers. Or such controllers may need to be continued to be supported directly under spi-nor framework?
It's not decided yet. I'm not closing the door to any of those advanced controllers yet, just need to have a closer look before taking a decision. To me, it sounds like information that might be needed to handle direct mapping in write mode for SPI NORs and we're not there yet.
Quoted 4 lines
I am okay with this series in general. But, was trying to understand which drivers will fall under
spi_memand which will continue to remain under mtd/spi-nor
Ideally, all of them, but maybe not with all the advanced features supported at the beginning. The only things I'd like to keep outside of drivers/spi are controllers that are only able to send commands for a specific type of memory (like only commands to address SPI NORs).
I'm fine discussing all of this, with real use cases to explain why we need to expose the memory type, and the memory organization information to SPI controller drivers, but I'd prefer to do that in a separate thread if you don't mind.
Regards,
Boris
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 04/10] spi: Extend the core to ease integration of SPI memory controllers
In reply to Boris BrezillonHi Boris,
Quoted 11 lines · Boris Brezillon
Some controllers are exposing high-level interfaces to access various kind of SPI memories. Unfortunately they do not fit in the current
spi_controllermodel and usually have drivers placed indrivers/mtd/spi-norwhich are only supporting SPI NORs and not SPI memories in general.This is an attempt at defining a SPI memory interface which works for all kinds of SPI memories (NORs, NANDs, SRAMs).
Signed-off-by Boris Brezillon <[email protected]>---
[...]
Quoted 11 lines
drivers/spi/spi-mem.c new file +11
-0+ +/** +* spi_mem_supports_op() - Check if a memory device and the controller it is +* connected to support a specific memory operation +* @mem: the SPI memory +* @op: the memory operation to check +* +* Some controllers are only supporting Single or Dual IOs, others might only +* support specific opcodes, or it can even be that the controller and device +* both support Quad IOs but the hardware prevents you from using it because +* only 2 IO lines are connected.
drivers/spi/spi-mem.c line 169
Quoted 10 lines
drivers/spi/spi-mem.c new file +10
-0+* +* This function checks whether a specific operation is supported. +* +* Return: true if @op is supported, false otherwise. +*/ +bool spi_mem_supports_op (struct spi_mem *mem,const struct spi_mem_op *op) +{ +struct spi_controller *ctlr = mem->spi->controller; + +if (ctlr->mem_ops->supports_op)
this misses a null check for mem_ops:
if (ctlr->mem_ops && ctlr->mem_ops->supports_op)
drivers/spi/spi-mem.c line 173
Quoted 4 lines
drivers/spi/spi-mem.c new file +4
-0+return ctlr->mem_ops->supports_op (mem, op); + +return spi_mem_default_supports_op (mem, op); +}
[...]
Regards,
Frieder
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 04/10] spi: Extend the core to ease integration of SPI memory controllers
Hi Frieder,
Quoted 23 lines · On Mon, 16 Apr 2018 12:33:54 +0200 Frieder Schrempf…
Quoted 11 lines
drivers/spi/spi-mem.c new file +11
-0+ +/** +* spi_mem_supports_op() - Check if a memory device and the controller it is +* connected to support a specific memory operation +* @mem: the SPI memory +* @op: the memory operation to check +* +* Some controllers are only supporting Single or Dual IOs, others might only +* support specific opcodes, or it can even be that the controller and device +* both support Quad IOs but the hardware prevents you from using it because +* only 2 IO lines are connected. drivers/spi/spi-mem.c line 169
Quoted 10 lines
drivers/spi/spi-mem.c new file +10
-0+* +* This function checks whether a specific operation is supported. +* +* Return: true if @op is supported, false otherwise. +*/ +bool spi_mem_supports_op (struct spi_mem *mem,const struct spi_mem_op *op) +{ +struct spi_controller *ctlr = mem->spi->controller; + +if (ctlr->mem_ops->supports_op)this misses a null check for
mem_ops:
Quoted 1 line
if (ctlr->mem_ops && ctlr->mem_ops->supports_op)
Yep. I'll fix that in v3.
Thanks,
Boris
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 5/10 spi: Make support for regular transfers optional when ->mem_ops != NULL
In reply to Boris BrezillonSome SPI/QuadSPI controllers only expose a high-level SPI memory interface, thus preventing any regular SPI transfers from being done.
In that case, SPI controller drivers can leave all ->transfer_xxx() hooks empty and only implement the spi_mem_ops interface.
Adjust the core to allow such situations:
- extend spi_controller_check_ops() to accept situations where all ->transfer_xxx() pointers are NULL only if ->mem_ops != NULL
- make sure we do not initialize the SPI message queue if ctlr->transfer_one and ctlr->transfer_one_message are missing
- return -ENOTSUPP if someone tries to do a regular SPI transfer on a controller that does not support it
--- drivers/spi/spi.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-)
drivers/spi/spi.c +26 -7
@@ -28,6 +28,7 @@#include <linux/slab.h> #include <linux/mod_devicetable.h> #include <linux/spi/spi.h> +#include <linux/spi/spi-mem.h> #include <linux/of_gpio.h> #include <linux/pm_runtime.h> #include <linux/pm_domain.h>
@@ -2069,12 +2070,19 @@ static int of_spi_register_master(struct spi_controller *ctlr)static int spi_controller_check_ops (struct spi_controller *ctlr) {/* -* The controller must at least implement one of the ->transfer() -* hooks. +* The controller may implement only the high-level SPI-memory like +* operations if it does not support regular SPI transfers, and this is +* valid use case. +* If ->mem_ops is NULL, we request that at least one of the +* ->transfer_xxx() method be implemented. */ -if (!ctlr->transfer && !ctlr->transfer_one && - !ctlr->transfer_one_message) +if (ctlr->mem_ops) { +if (!ctlr->mem_ops->exec_op) +return -EINVAL ; + }else if (!ctlr->transfer && !ctlr->transfer_one && + !ctlr->transfer_one_message) {return -EINVAL ; + }return 0 ; }
@@ -2185,10 +2193,14 @@ int spi_register_controller(struct spi_controller *ctlr)spi_controller_is_slave (ctlr) ?"slave" :"master" , dev_name(&ctlr->dev)); -/* If we're using a queued driver, start the queue */ -if (ctlr->transfer) +/* +* If we're using a queued driver, start the queue. Note that we don't +* need the queueing logic if the driver is only supporting high-level +* memory operations. +*/ +if (ctlr->transfer) {dev_info (dev,"controller is unqueued, this is deprecated\n" ); -else { + }else if (ctlr->transfer_one || ctlr->transfer_one_message) { status =spi_controller_initialize_queue (ctlr);if (status) {device_del (&ctlr->dev);
@@ -2918,6 +2930,13 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message) {struct spi_controller *ctlr = spi->controller; +/* +* Some controllers do not support doing regular SPI transfers. Return +* ENOTSUPP when this is the case. +*/ +if (!ctlr->transfer) +return -ENOTSUPP ; + message->spi = spi;SPI_STATISTICS_INCREMENT_FIELD (&ctlr->statistics, spi_async);
Signature · 6 lines
2.14.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 6/10 spi: bcm-qspi: Implement the spi_mem interface
In reply to Boris BrezillonThe spi_mem interface is meant to replace the ->spi_flash_read() one. Implement the ->exec_op() method to ease removal of the old interface.
Not that ->spi_flash_read() is now implemented as a wrapper around the new bcm_qspi_exec_mem_op() function so that we can easily get rid of it when ->spi_flash_read() is removed.
---
Changes in v2:
- include spi-mem.h
- treat op->addr.val differently since it's now an u64
--- drivers/spi/spi-bcm-qspi.c | 190 ++++++++++++++++++++++++++------------------- 1 file changed, 111 insertions(+), 79 deletions(-)
drivers/spi/spi-bcm-qspi.c +111 -79
@@ -30,6 +30,7 @@#include <linux/platform_device.h> #include <linux/slab.h> #include <linux/spi/spi.h> +#include <linux/spi/spi-mem.h> #include <linux/sysfs.h> #include <linux/types.h> #include "spi-bcm-qspi.h"
@@ -215,10 +216,10 @@ struct bcm_qspi {int bspi_maj_rev;int bspi_min_rev;int bspi_enabled; -struct spi_flash_read_message *bspi_rf_msg; -u32 bspi_rf_msg_idx; -u32 bspi_rf_msg_len; -u32 bspi_rf_msg_status; +const struct spi_mem_op *bspi_rf_op; +u32 bspi_rf_op_idx; +u32 bspi_rf_op_len; +u32 bspi_rf_op_status;struct bcm_xfer_mode xfer_mode;u32 s3_strap_override_ctrl;bool bspi_mode;
@@ -313,26 +314,26 @@ static inline void bcm_qspi_bspi_lr_clear(struct bcm_qspi *qspi)static void bcm_qspi_bspi_lr_data_read (struct bcm_qspi *qspi) { -u32 *buf = (u32 *)qspi->bspi_rf_msg->buf; +u32 *buf = (u32 *)qspi->bspi_rf_op->data.buf.in;u32 data =0 ; -dev_dbg (&qspi->pdev->dev,"xfer %p rx %p rxlen %d\n" , qspi->bspi_rf_msg, - qspi->bspi_rf_msg->buf, qspi->bspi_rf_msg_len); +dev_dbg (&qspi->pdev->dev,"xfer %p rx %p rxlen %d\n" , qspi->bspi_rf_op, + qspi->bspi_rf_op->data.buf.in, qspi->bspi_rf_op_len);while (!bcm_qspi_bspi_lr_is_fifo_empty (qspi)) { data =bcm_qspi_bspi_lr_read_fifo (qspi); -if (likely (qspi->bspi_rf_msg_len >=4 ) && +if (likely (qspi->bspi_rf_op_len >=4 ) &&IS_ALIGNED ((uintptr_t )buf,4 )) { - buf[qspi->bspi_rf_msg_idx++] = data; - qspi->bspi_rf_msg_len -=4 ; + buf[qspi->bspi_rf_op_idx++] = data; + qspi->bspi_rf_op_len -=4 ; }else {/* Read out remaining bytes, make sure*/ -u8 *cbuf = (u8 *)&buf[qspi->bspi_rf_msg_idx]; +u8 *cbuf = (u8 *)&buf[qspi->bspi_rf_op_idx]; data =cpu_to_le32 (data); -while (qspi->bspi_rf_msg_len) { +while (qspi->bspi_rf_op_len) { *cbuf++ = (u8 )data; data >>=8 ; - qspi->bspi_rf_msg_len--; + qspi->bspi_rf_op_len--; } } }
@@ -349,14 +350,12 @@ static void bcm_qspi_bspi_set_xfer_params(struct bcm_qspi *qspi, u8 cmd_byte, }static int bcm_qspi_bspi_set_flex_mode (struct bcm_qspi *qspi, -struct spi_flash_read_message *msg, -int hp) +const struct spi_mem_op *op,int hp) {int bpc =0 , bpp =0 ; -u8 command = msg->read_opcode; -int width = msg->data_nbits ? msg->data_nbits :SPI_NBITS_SINGLE ; -int addrlen = msg->addr_width; -int addr_nbits = msg->addr_nbits ? msg->addr_nbits :SPI_NBITS_SINGLE ; +u8 command = op->cmd.opcode; +int width = op->cmd.buswidth ? op->cmd.buswidth :SPI_NBITS_SINGLE ; +int addrlen = op->addr.nbytes *8 ;int flex_mode =1 ; dev_dbg(&qspi->pdev->dev, "set flex mode w %x addrlen %x hp %d\n",
@@ -365,7 +364,7 @@ static int bcm_qspi_bspi_set_flex_mode(struct bcm_qspi *qspi,if (addrlen ==BSPI_ADDRLEN_4BYTES ) bpp =BSPI_BPP_ADDR_SELECT_MASK ; - bpp |= msg->dummy_bytes * (8 /addr_nbits); + bpp |= (op->dummy.nbytes *8 ) / op->dummy.buswidth;switch (width) {case SPI_NBITS_SINGLE :
@@ -397,11 +396,10 @@ static int bcm_qspi_bspi_set_flex_mode(struct bcm_qspi *qspi, }static int bcm_qspi_bspi_set_override (struct bcm_qspi *qspi, -struct spi_flash_read_message *msg, -int hp) +const struct spi_mem_op *op,int hp) { -int width = msg->data_nbits ? msg->data_nbits :SPI_NBITS_SINGLE ; -int addrlen = msg->addr_width; +int width = op->data.buswidth ? op->data.buswidth :SPI_NBITS_SINGLE ; +int addrlen = op->addr.nbytes;u32 data =bcm_qspi_read (qspi,BSPI ,BSPI_STRAP_OVERRIDE_CTRL ); dev_dbg(&qspi->pdev->dev, "set override mode w %x addrlen %x hp %d\n",
@@ -437,17 +435,17 @@ static int bcm_qspi_bspi_set_override(struct bcm_qspi *qspi,/* set the override mode */ data |=BSPI_STRAP_OVERRIDE_CTRL_OVERRIDE ;bcm_qspi_write (qspi,BSPI ,BSPI_STRAP_OVERRIDE_CTRL , data); -bcm_qspi_bspi_set_xfer_params (qspi, msg->read_opcode,0 ,0 ,0 ); +bcm_qspi_bspi_set_xfer_params (qspi, op->cmd.opcode,0 ,0 ,0 );return 0 ; }static int bcm_qspi_bspi_set_mode (struct bcm_qspi *qspi, -struct spi_flash_read_message *msg,int hp) +const struct spi_mem_op *op,int hp) {int error =0 ; -int width = msg->data_nbits ? msg->data_nbits :SPI_NBITS_SINGLE ; -int addrlen = msg->addr_width; +int width = op->data.buswidth ? op->data.buswidth :SPI_NBITS_SINGLE ; +int addrlen = op->addr.nbytes;/* default mode */ qspi->xfer_mode.flex_mode = true;
@@ -460,12 +458,12 @@ static int bcm_qspi_bspi_set_mode(struct bcm_qspi *qspi,if (val & mask || qspi->s3_strap_override_ctrl & mask) { qspi->xfer_mode.flex_mode = false;bcm_qspi_write (qspi,BSPI ,BSPI_FLEX_MODE_ENABLE ,0 ); - error =bcm_qspi_bspi_set_override (qspi, msg, hp); + error =bcm_qspi_bspi_set_override (qspi, op, hp); } }if (qspi->xfer_mode.flex_mode) - error =bcm_qspi_bspi_set_flex_mode (qspi, msg, hp); + error =bcm_qspi_bspi_set_flex_mode (qspi, op, hp);if (error) { dev_warn(&qspi->pdev->dev,
@@ -794,19 +792,20 @@ static int write_to_hw(struct bcm_qspi *qspi, struct spi_device *spi)return slot; } -static int bcm_qspi_bspi_flash_read (struct spi_device *spi, -struct spi_flash_read_message *msg) +static int bcm_qspi_bspi_exec_mem_op (struct spi_device *spi, +const struct spi_mem_op *op) {struct bcm_qspi *qspi =spi_master_get_devdata (spi->master); -u32 addr =0 , len, rdlen, len_words; +u32 addr =0 , len, rdlen, len_words, from =0 ;int ret =0 ;unsigned long timeo =msecs_to_jiffies (100 );struct bcm_qspi_soc_intc *soc_intc = qspi->soc_intc;if (bcm_qspi_bspi_ver_three (qspi)) -if (msg->addr_width ==BSPI_ADDRLEN_4BYTES ) +if (op->addr.nbytes ==BSPI_ADDRLEN_4BYTES )return -EIO ; + from = op->addr.val;bcm_qspi_chip_select (qspi, spi->chip_select);bcm_qspi_write (qspi,MSPI ,MSPI_WRITE_LOCK ,0 );
@@ -815,15 +814,15 @@ static int bcm_qspi_bspi_flash_read(struct spi_device *spi,* the upper address byte to bspi */ if (bcm_qspi_bspi_ver_three (qspi) == false) { - addr = msg->from &0xff000000 ; + addr = from &0xff000000 ;bcm_qspi_write (qspi,BSPI ,BSPI_BSPI_FLASH_UPPER_ADDR_BYTE , addr); }if (!qspi->xfer_mode.flex_mode) - addr = msg->from; + addr = from;else - addr = msg->from &0x00ffffff ; + addr = from &0x00ffffff ;if (bcm_qspi_bspi_ver_three (qspi) == true) addr = (addr +0xc00000 ) &0xffffff ;
@@ -832,8 +831,8 @@ static int bcm_qspi_bspi_flash_read(struct spi_device *spi,* read into the entire buffer by breaking the reads * into RAF buffer read lengths */ - len = msg->len; - qspi->bspi_rf_msg_idx =0 ; + len = op->data.nbytes; + qspi->bspi_rf_op_idx =0 ; do { if (len > BSPI_READ_LENGTH)
@@ -844,9 +843,9 @@ static int bcm_qspi_bspi_flash_read(struct spi_device *spi,reinit_completion (&qspi->bspi_done);bcm_qspi_enable_bspi (qspi); len_words = (rdlen +3 ) >>2 ; - qspi->bspi_rf_msg = msg; - qspi->bspi_rf_msg_status =0 ; - qspi->bspi_rf_msg_len = rdlen; + qspi->bspi_rf_op = op; + qspi->bspi_rf_op_status =0 ; + qspi->bspi_rf_op_len = rdlen;dev_dbg (&qspi->pdev->dev,"bspi xfr addr 0x%x len 0x%x" , addr, rdlen);bcm_qspi_write (qspi,BSPI ,BSPI_RAF_START_ADDR , addr);
@@ -871,7 +870,6 @@ static int bcm_qspi_bspi_flash_read(struct spi_device *spi, }/* set msg return length */ - msg->retlen += rdlen; addr += rdlen; len -= rdlen; }while (len);
@@ -906,61 +904,62 @@ static int bcm_qspi_transfer_one(struct spi_master *master,return 0 ; } -static int bcm_qspi_mspi_flash_read (struct spi_device *spi, -struct spi_flash_read_message *msg) +static int bcm_qspi_mspi_exec_mem_op (struct spi_device *spi, +const struct spi_mem_op *op) { -struct bcm_qspi *qspi =spi_master_get_devdata (spi->master); +struct spi_master *master = spi->master; +struct bcm_qspi *qspi =spi_master_get_devdata (master);struct spi_transfer t[2 ]; -u8 cmd[6 ]; -int ret; +u8 cmd[6 ] = { }; +int ret, i;memset (cmd,0 ,sizeof (cmd));memset (t,0 ,sizeof (t));/* tx */ /* opcode is in cmd[0] */ - cmd[0 ] = msg->read_opcode; - cmd[1 ] = msg->from >> (msg->addr_width *8 -8 ); - cmd[2 ] = msg->from >> (msg->addr_width *8 -16 ); - cmd[3 ] = msg->from >> (msg->addr_width *8 -24 ); - cmd[4 ] = msg->from >> (msg->addr_width *8 -32 ); + cmd[0 ] = op->cmd.opcode; +for (i =0 ; i < op->addr.nbytes; i++) + cmd[1 + i] = op->addr.val >> (8 * (op->addr.nbytes - i -1 )); + t[0 ].tx_buf = cmd; - t[0 ].len = msg->addr_width + msg->dummy_bytes +1 ; + t[0 ].len = op->addr.nbytes + op->dummy.nbytes +1 ; t[0 ].bits_per_word = spi->bits_per_word; - t[0 ].tx_nbits = msg->opcode_nbits; + t[0 ].tx_nbits = op->cmd.buswidth;/* lets mspi know that this is not last transfer */ qspi->trans_pos.mspi_last_trans = false; - ret =bcm_qspi_transfer_one (spi->master, spi, &t[0 ]); + ret =bcm_qspi_transfer_one (master, spi, &t[0 ]);/* rx */ qspi->trans_pos.mspi_last_trans = true;if (!ret) {/* rx */ - t[1 ].rx_buf = msg->buf; - t[1 ].len = msg->len; - t[1 ].rx_nbits = msg->data_nbits; + t[1 ].rx_buf = op->data.buf.in; + t[1 ].len = op->data.nbytes; + t[1 ].rx_nbits = op->data.buswidth; t[1 ].bits_per_word = spi->bits_per_word; - ret =bcm_qspi_transfer_one (spi->master, spi, &t[1 ]); + ret =bcm_qspi_transfer_one (master, spi, &t[1 ]); } -if (!ret) - msg->retlen = msg->len; -return ret; } -static int bcm_qspi_flash_read (struct spi_device *spi, -struct spi_flash_read_message *msg) +static int bcm_qspi_exec_mem_op (struct spi_device *spi, +const struct spi_mem_op *op) {struct bcm_qspi *qspi =spi_master_get_devdata (spi->master);int ret =0 ;bool mspi_read = false; -u32 addr, len; +u32 addr =0 , len;u_char *buf; - buf = msg->buf; - addr = msg->from; - len = msg->len; +if (!op->data.nbytes || !op->addr.nbytes || op->addr.nbytes >4 || + op->data.dir !=SPI_MEM_DATA_IN ) +return -ENOTSUPP ; + + buf = op->data.buf.in; + addr = op->addr.val; + len = op->data.nbytes;if (bcm_qspi_bspi_ver_three (qspi) == true) {/*
@@ -982,12 +981,40 @@ static int bcm_qspi_flash_read(struct spi_device *spi, mspi_read = true;if (mspi_read) -return bcm_qspi_mspi_flash_read (spi, msg); +return bcm_qspi_mspi_exec_mem_op (spi, op); - ret =bcm_qspi_bspi_set_mode (qspi, msg,-1 ); + ret =bcm_qspi_bspi_set_mode (qspi, op,-1 );if (!ret) - ret =bcm_qspi_bspi_flash_read (spi, msg); + ret =bcm_qspi_bspi_exec_mem_op (spi, op); + +return ret; +} + +static int bcm_qspi_exec_mem_op_wrapper (struct spi_mem *mem, +const struct spi_mem_op *op) +{ +return bcm_qspi_exec_mem_op (mem->spi, op); +} + +static int bcm_qspi_flash_read_wrapper (struct spi_device *spi, +struct spi_flash_read_message *msg) +{ +int ret; +struct spi_mem_op op =SPI_MEM_OP (SPI_MEM_OP_CMD (msg->read_opcode,1 ), +SPI_MEM_OP_ADDR (msg->addr_width, + msg->from, + msg->addr_nbits), +SPI_MEM_OP_DUMMY (msg->dummy_bytes, + msg->addr_nbits), +SPI_MEM_OP_DATA_IN (msg->len, + msg->buf, + msg->data_nbits)); + + msg->retlen =0 ; + ret =bcm_qspi_exec_mem_op (spi, &op); +if (!ret) + msg->retlen = msg->len;return ret; }
@@ -1026,10 +1053,10 @@ static irqreturn_t bcm_qspi_bspi_lr_l2_isr(int irq, void *dev_id)struct bcm_qspi_soc_intc *soc_intc = qspi->soc_intc;u32 status = qspi_dev_id->irqp->mask; -if (qspi->bspi_enabled && qspi->bspi_rf_msg) { +if (qspi->bspi_enabled && qspi->bspi_rf_op) {bcm_qspi_bspi_lr_data_read (qspi); -if (qspi->bspi_rf_msg_len ==0 ) { - qspi->bspi_rf_msg =NULL ; +if (qspi->bspi_rf_op_len ==0 ) { + qspi->bspi_rf_op =NULL ;if (qspi->soc_intc) {/* disable soc BSPI interrupt */ soc_intc->bcm_qspi_int_set(soc_intc, BSPI_DONE,
@@ -1038,7 +1065,7 @@ static irqreturn_t bcm_qspi_bspi_lr_l2_isr(int irq, void *dev_id) status =INTR_BSPI_LR_SESSION_DONE_MASK ; } -if (qspi->bspi_rf_msg_status) +if (qspi->bspi_rf_op_status)bcm_qspi_bspi_lr_clear (qspi);else bcm_qspi_bspi_flush_prefetch_buffers (qspi);
@@ -1050,7 +1077,7 @@ static irqreturn_t bcm_qspi_bspi_lr_l2_isr(int irq, void *dev_id) } status &=INTR_BSPI_LR_SESSION_DONE_MASK ; -if (qspi->bspi_enabled && status && qspi->bspi_rf_msg_len ==0 ) +if (qspi->bspi_enabled && status && qspi->bspi_rf_op_len ==0 )complete (&qspi->bspi_done);return IRQ_HANDLED ;
@@ -1063,7 +1090,7 @@ static irqreturn_t bcm_qspi_bspi_lr_err_l2_isr(int irq, void *dev_id)struct bcm_qspi_soc_intc *soc_intc = qspi->soc_intc;dev_err (&qspi->pdev->dev,"BSPI INT error\n" ); - qspi->bspi_rf_msg_status = -EIO ; + qspi->bspi_rf_op_status = -EIO ;if (qspi->soc_intc)/* clear soc interrupt */ soc_intc->bcm_qspi_int_ack (soc_intc,BSPI_ERR );
@@ -1186,6 +1213,10 @@ static void bcm_qspi_hw_uninit(struct bcm_qspi *qspi) } +static const struct spi_controller_mem_ops bcm_qspi_mem_ops = { + .exec_op = bcm_qspi_exec_mem_op_wrapper, +}; +static const struct of_device_id bcm_qspi_of_match[] = { { .compatible ="brcm,spi-bcm-qspi" }, {},
@@ -1228,7 +1259,8 @@ int bcm_qspi_probe(struct platform_device *pdev, master->mode_bits =SPI_CPHA |SPI_CPOL |SPI_RX_DUAL |SPI_RX_QUAD ; master->setup = bcm_qspi_setup; master->transfer_one = bcm_qspi_transfer_one; - master->spi_flash_read = bcm_qspi_flash_read; + master->spi_flash_read = bcm_qspi_flash_read_wrapper; + master->mem_ops = &bcm_qspi_mem_ops; master->cleanup = bcm_qspi_cleanup; master->dev.of_node = dev->of_node; master->num_chipselect =NUM_CHIPSELECT ;
Signature · 6 lines
2.14.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Mark Brown
maintainerApplied "spi: bcm-qspi: Implement the spi_mem interface" to the spi tree
The patch
spi: bcm-qspi: Implement the spi_mem interface
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
5f195ee7d830c271af6fca979b0106b9a053e2c0Mon Sep 17 00:00:00 2001
From: Boris Brezillon <[email protected]>
Date: Thu, 26 Apr 2018 18:18:16 +0200
Subject: [PATCH] spi: bcm-qspi: Implement the spi_mem interface
The spi_mem interface is meant to replace the ->spi_flash_read() one. Implement the ->exec_op() method to ease removal of the old interface.
Not that ->spi_flash_read() is now implemented as a wrapper around the new bcm_qspi_exec_mem_op() function so that we can easily get rid of it when ->spi_flash_read() is removed.
--- drivers/spi/spi-bcm-qspi.c | 190 ++++++++++++++++++++++--------------- 1 file changed, 111 insertions(+), 79 deletions(-)
drivers/spi/spi-bcm-qspi.c +111 -79
@@ -30,6 +30,7 @@#include <linux/platform_device.h> #include <linux/slab.h> #include <linux/spi/spi.h> +#include <linux/spi/spi-mem.h> #include <linux/sysfs.h> #include <linux/types.h> #include "spi-bcm-qspi.h"
@@ -215,10 +216,10 @@ struct bcm_qspi {int bspi_maj_rev;int bspi_min_rev;int bspi_enabled; -struct spi_flash_read_message *bspi_rf_msg; -u32 bspi_rf_msg_idx; -u32 bspi_rf_msg_len; -u32 bspi_rf_msg_status; +const struct spi_mem_op *bspi_rf_op; +u32 bspi_rf_op_idx; +u32 bspi_rf_op_len; +u32 bspi_rf_op_status;struct bcm_xfer_mode xfer_mode;u32 s3_strap_override_ctrl;bool bspi_mode;
@@ -313,26 +314,26 @@ static inline void bcm_qspi_bspi_lr_clear(struct bcm_qspi *qspi)static void bcm_qspi_bspi_lr_data_read (struct bcm_qspi *qspi) { -u32 *buf = (u32 *)qspi->bspi_rf_msg->buf; +u32 *buf = (u32 *)qspi->bspi_rf_op->data.buf.in;u32 data =0 ; -dev_dbg (&qspi->pdev->dev,"xfer %p rx %p rxlen %d\n" , qspi->bspi_rf_msg, - qspi->bspi_rf_msg->buf, qspi->bspi_rf_msg_len); +dev_dbg (&qspi->pdev->dev,"xfer %p rx %p rxlen %d\n" , qspi->bspi_rf_op, + qspi->bspi_rf_op->data.buf.in, qspi->bspi_rf_op_len);while (!bcm_qspi_bspi_lr_is_fifo_empty (qspi)) { data =bcm_qspi_bspi_lr_read_fifo (qspi); -if (likely (qspi->bspi_rf_msg_len >=4 ) && +if (likely (qspi->bspi_rf_op_len >=4 ) &&IS_ALIGNED ((uintptr_t )buf,4 )) { - buf[qspi->bspi_rf_msg_idx++] = data; - qspi->bspi_rf_msg_len -=4 ; + buf[qspi->bspi_rf_op_idx++] = data; + qspi->bspi_rf_op_len -=4 ; }else {/* Read out remaining bytes, make sure*/ -u8 *cbuf = (u8 *)&buf[qspi->bspi_rf_msg_idx]; +u8 *cbuf = (u8 *)&buf[qspi->bspi_rf_op_idx]; data =cpu_to_le32 (data); -while (qspi->bspi_rf_msg_len) { +while (qspi->bspi_rf_op_len) { *cbuf++ = (u8 )data; data >>=8 ; - qspi->bspi_rf_msg_len--; + qspi->bspi_rf_op_len--; } } }
@@ -349,14 +350,12 @@ static void bcm_qspi_bspi_set_xfer_params(struct bcm_qspi *qspi, u8 cmd_byte, }static int bcm_qspi_bspi_set_flex_mode (struct bcm_qspi *qspi, -struct spi_flash_read_message *msg, -int hp) +const struct spi_mem_op *op,int hp) {int bpc =0 , bpp =0 ; -u8 command = msg->read_opcode; -int width = msg->data_nbits ? msg->data_nbits :SPI_NBITS_SINGLE ; -int addrlen = msg->addr_width; -int addr_nbits = msg->addr_nbits ? msg->addr_nbits :SPI_NBITS_SINGLE ; +u8 command = op->cmd.opcode; +int width = op->cmd.buswidth ? op->cmd.buswidth :SPI_NBITS_SINGLE ; +int addrlen = op->addr.nbytes *8 ;int flex_mode =1 ; dev_dbg(&qspi->pdev->dev, "set flex mode w %x addrlen %x hp %d\n",
@@ -365,7 +364,7 @@ static int bcm_qspi_bspi_set_flex_mode(struct bcm_qspi *qspi,if (addrlen ==BSPI_ADDRLEN_4BYTES ) bpp =BSPI_BPP_ADDR_SELECT_MASK ; - bpp |= msg->dummy_bytes * (8 /addr_nbits); + bpp |= (op->dummy.nbytes *8 ) / op->dummy.buswidth;switch (width) {case SPI_NBITS_SINGLE :
@@ -397,11 +396,10 @@ static int bcm_qspi_bspi_set_flex_mode(struct bcm_qspi *qspi, }static int bcm_qspi_bspi_set_override (struct bcm_qspi *qspi, -struct spi_flash_read_message *msg, -int hp) +const struct spi_mem_op *op,int hp) { -int width = msg->data_nbits ? msg->data_nbits :SPI_NBITS_SINGLE ; -int addrlen = msg->addr_width; +int width = op->data.buswidth ? op->data.buswidth :SPI_NBITS_SINGLE ; +int addrlen = op->addr.nbytes;u32 data =bcm_qspi_read (qspi,BSPI ,BSPI_STRAP_OVERRIDE_CTRL ); dev_dbg(&qspi->pdev->dev, "set override mode w %x addrlen %x hp %d\n",
@@ -437,17 +435,17 @@ static int bcm_qspi_bspi_set_override(struct bcm_qspi *qspi,/* set the override mode */ data |=BSPI_STRAP_OVERRIDE_CTRL_OVERRIDE ;bcm_qspi_write (qspi,BSPI ,BSPI_STRAP_OVERRIDE_CTRL , data); -bcm_qspi_bspi_set_xfer_params (qspi, msg->read_opcode,0 ,0 ,0 ); +bcm_qspi_bspi_set_xfer_params (qspi, op->cmd.opcode,0 ,0 ,0 );return 0 ; }static int bcm_qspi_bspi_set_mode (struct bcm_qspi *qspi, -struct spi_flash_read_message *msg,int hp) +const struct spi_mem_op *op,int hp) {int error =0 ; -int width = msg->data_nbits ? msg->data_nbits :SPI_NBITS_SINGLE ; -int addrlen = msg->addr_width; +int width = op->data.buswidth ? op->data.buswidth :SPI_NBITS_SINGLE ; +int addrlen = op->addr.nbytes;/* default mode */ qspi->xfer_mode.flex_mode = true;
@@ -460,12 +458,12 @@ static int bcm_qspi_bspi_set_mode(struct bcm_qspi *qspi,if (val & mask || qspi->s3_strap_override_ctrl & mask) { qspi->xfer_mode.flex_mode = false;bcm_qspi_write (qspi,BSPI ,BSPI_FLEX_MODE_ENABLE ,0 ); - error =bcm_qspi_bspi_set_override (qspi, msg, hp); + error =bcm_qspi_bspi_set_override (qspi, op, hp); } }if (qspi->xfer_mode.flex_mode) - error =bcm_qspi_bspi_set_flex_mode (qspi, msg, hp); + error =bcm_qspi_bspi_set_flex_mode (qspi, op, hp);if (error) { dev_warn(&qspi->pdev->dev,
@@ -794,19 +792,20 @@ static int write_to_hw(struct bcm_qspi *qspi, struct spi_device *spi)return slot; } -static int bcm_qspi_bspi_flash_read (struct spi_device *spi, -struct spi_flash_read_message *msg) +static int bcm_qspi_bspi_exec_mem_op (struct spi_device *spi, +const struct spi_mem_op *op) {struct bcm_qspi *qspi =spi_master_get_devdata (spi->master); -u32 addr =0 , len, rdlen, len_words; +u32 addr =0 , len, rdlen, len_words, from =0 ;int ret =0 ;unsigned long timeo =msecs_to_jiffies (100 );struct bcm_qspi_soc_intc *soc_intc = qspi->soc_intc;if (bcm_qspi_bspi_ver_three (qspi)) -if (msg->addr_width ==BSPI_ADDRLEN_4BYTES ) +if (op->addr.nbytes ==BSPI_ADDRLEN_4BYTES )return -EIO ; + from = op->addr.val;bcm_qspi_chip_select (qspi, spi->chip_select);bcm_qspi_write (qspi,MSPI ,MSPI_WRITE_LOCK ,0 );
@@ -815,15 +814,15 @@ static int bcm_qspi_bspi_flash_read(struct spi_device *spi,* the upper address byte to bspi */ if (bcm_qspi_bspi_ver_three (qspi) == false) { - addr = msg->from &0xff000000 ; + addr = from &0xff000000 ;bcm_qspi_write (qspi,BSPI ,BSPI_BSPI_FLASH_UPPER_ADDR_BYTE , addr); }if (!qspi->xfer_mode.flex_mode) - addr = msg->from; + addr = from;else - addr = msg->from &0x00ffffff ; + addr = from &0x00ffffff ;if (bcm_qspi_bspi_ver_three (qspi) == true) addr = (addr +0xc00000 ) &0xffffff ;
@@ -832,8 +831,8 @@ static int bcm_qspi_bspi_flash_read(struct spi_device *spi,* read into the entire buffer by breaking the reads * into RAF buffer read lengths */ - len = msg->len; - qspi->bspi_rf_msg_idx =0 ; + len = op->data.nbytes; + qspi->bspi_rf_op_idx =0 ; do { if (len > BSPI_READ_LENGTH)
@@ -844,9 +843,9 @@ static int bcm_qspi_bspi_flash_read(struct spi_device *spi,reinit_completion (&qspi->bspi_done);bcm_qspi_enable_bspi (qspi); len_words = (rdlen +3 ) >>2 ; - qspi->bspi_rf_msg = msg; - qspi->bspi_rf_msg_status =0 ; - qspi->bspi_rf_msg_len = rdlen; + qspi->bspi_rf_op = op; + qspi->bspi_rf_op_status =0 ; + qspi->bspi_rf_op_len = rdlen;dev_dbg (&qspi->pdev->dev,"bspi xfr addr 0x%x len 0x%x" , addr, rdlen);bcm_qspi_write (qspi,BSPI ,BSPI_RAF_START_ADDR , addr);
@@ -871,7 +870,6 @@ static int bcm_qspi_bspi_flash_read(struct spi_device *spi, }/* set msg return length */ - msg->retlen += rdlen; addr += rdlen; len -= rdlen; }while (len);
@@ -906,61 +904,62 @@ static int bcm_qspi_transfer_one(struct spi_master *master,return 0 ; } -static int bcm_qspi_mspi_flash_read (struct spi_device *spi, -struct spi_flash_read_message *msg) +static int bcm_qspi_mspi_exec_mem_op (struct spi_device *spi, +const struct spi_mem_op *op) { -struct bcm_qspi *qspi =spi_master_get_devdata (spi->master); +struct spi_master *master = spi->master; +struct bcm_qspi *qspi =spi_master_get_devdata (master);struct spi_transfer t[2 ]; -u8 cmd[6 ]; -int ret; +u8 cmd[6 ] = { }; +int ret, i;memset (cmd,0 ,sizeof (cmd));memset (t,0 ,sizeof (t));/* tx */ /* opcode is in cmd[0] */ - cmd[0 ] = msg->read_opcode; - cmd[1 ] = msg->from >> (msg->addr_width *8 -8 ); - cmd[2 ] = msg->from >> (msg->addr_width *8 -16 ); - cmd[3 ] = msg->from >> (msg->addr_width *8 -24 ); - cmd[4 ] = msg->from >> (msg->addr_width *8 -32 ); + cmd[0 ] = op->cmd.opcode; +for (i =0 ; i < op->addr.nbytes; i++) + cmd[1 + i] = op->addr.val >> (8 * (op->addr.nbytes - i -1 )); + t[0 ].tx_buf = cmd; - t[0 ].len = msg->addr_width + msg->dummy_bytes +1 ; + t[0 ].len = op->addr.nbytes + op->dummy.nbytes +1 ; t[0 ].bits_per_word = spi->bits_per_word; - t[0 ].tx_nbits = msg->opcode_nbits; + t[0 ].tx_nbits = op->cmd.buswidth;/* lets mspi know that this is not last transfer */ qspi->trans_pos.mspi_last_trans = false; - ret =bcm_qspi_transfer_one (spi->master, spi, &t[0 ]); + ret =bcm_qspi_transfer_one (master, spi, &t[0 ]);/* rx */ qspi->trans_pos.mspi_last_trans = true;if (!ret) {/* rx */ - t[1 ].rx_buf = msg->buf; - t[1 ].len = msg->len; - t[1 ].rx_nbits = msg->data_nbits; + t[1 ].rx_buf = op->data.buf.in; + t[1 ].len = op->data.nbytes; + t[1 ].rx_nbits = op->data.buswidth; t[1 ].bits_per_word = spi->bits_per_word; - ret =bcm_qspi_transfer_one (spi->master, spi, &t[1 ]); + ret =bcm_qspi_transfer_one (master, spi, &t[1 ]); } -if (!ret) - msg->retlen = msg->len; -return ret; } -static int bcm_qspi_flash_read (struct spi_device *spi, -struct spi_flash_read_message *msg) +static int bcm_qspi_exec_mem_op (struct spi_device *spi, +const struct spi_mem_op *op) {struct bcm_qspi *qspi =spi_master_get_devdata (spi->master);int ret =0 ;bool mspi_read = false; -u32 addr, len; +u32 addr =0 , len;u_char *buf; - buf = msg->buf; - addr = msg->from; - len = msg->len; +if (!op->data.nbytes || !op->addr.nbytes || op->addr.nbytes >4 || + op->data.dir !=SPI_MEM_DATA_IN ) +return -ENOTSUPP ; + + buf = op->data.buf.in; + addr = op->addr.val; + len = op->data.nbytes;if (bcm_qspi_bspi_ver_three (qspi) == true) {/*
@@ -982,12 +981,40 @@ static int bcm_qspi_flash_read(struct spi_device *spi, mspi_read = true;if (mspi_read) -return bcm_qspi_mspi_flash_read (spi, msg); +return bcm_qspi_mspi_exec_mem_op (spi, op); - ret =bcm_qspi_bspi_set_mode (qspi, msg,-1 ); + ret =bcm_qspi_bspi_set_mode (qspi, op,-1 );if (!ret) - ret =bcm_qspi_bspi_flash_read (spi, msg); + ret =bcm_qspi_bspi_exec_mem_op (spi, op); + +return ret; +} + +static int bcm_qspi_exec_mem_op_wrapper (struct spi_mem *mem, +const struct spi_mem_op *op) +{ +return bcm_qspi_exec_mem_op (mem->spi, op); +} + +static int bcm_qspi_flash_read_wrapper (struct spi_device *spi, +struct spi_flash_read_message *msg) +{ +int ret; +struct spi_mem_op op =SPI_MEM_OP (SPI_MEM_OP_CMD (msg->read_opcode,1 ), +SPI_MEM_OP_ADDR (msg->addr_width, + msg->from, + msg->addr_nbits), +SPI_MEM_OP_DUMMY (msg->dummy_bytes, + msg->addr_nbits), +SPI_MEM_OP_DATA_IN (msg->len, + msg->buf, + msg->data_nbits)); + + msg->retlen =0 ; + ret =bcm_qspi_exec_mem_op (spi, &op); +if (!ret) + msg->retlen = msg->len;return ret; }
@@ -1026,10 +1053,10 @@ static irqreturn_t bcm_qspi_bspi_lr_l2_isr(int irq, void *dev_id)struct bcm_qspi_soc_intc *soc_intc = qspi->soc_intc;u32 status = qspi_dev_id->irqp->mask; -if (qspi->bspi_enabled && qspi->bspi_rf_msg) { +if (qspi->bspi_enabled && qspi->bspi_rf_op) {bcm_qspi_bspi_lr_data_read (qspi); -if (qspi->bspi_rf_msg_len ==0 ) { - qspi->bspi_rf_msg =NULL ; +if (qspi->bspi_rf_op_len ==0 ) { + qspi->bspi_rf_op =NULL ;if (qspi->soc_intc) {/* disable soc BSPI interrupt */ soc_intc->bcm_qspi_int_set(soc_intc, BSPI_DONE,
@@ -1038,7 +1065,7 @@ static irqreturn_t bcm_qspi_bspi_lr_l2_isr(int irq, void *dev_id) status =INTR_BSPI_LR_SESSION_DONE_MASK ; } -if (qspi->bspi_rf_msg_status) +if (qspi->bspi_rf_op_status)bcm_qspi_bspi_lr_clear (qspi);else bcm_qspi_bspi_flush_prefetch_buffers (qspi);
@@ -1050,7 +1077,7 @@ static irqreturn_t bcm_qspi_bspi_lr_l2_isr(int irq, void *dev_id) } status &=INTR_BSPI_LR_SESSION_DONE_MASK ; -if (qspi->bspi_enabled && status && qspi->bspi_rf_msg_len ==0 ) +if (qspi->bspi_enabled && status && qspi->bspi_rf_op_len ==0 )complete (&qspi->bspi_done);return IRQ_HANDLED ;
@@ -1063,7 +1090,7 @@ static irqreturn_t bcm_qspi_bspi_lr_err_l2_isr(int irq, void *dev_id)struct bcm_qspi_soc_intc *soc_intc = qspi->soc_intc;dev_err (&qspi->pdev->dev,"BSPI INT error\n" ); - qspi->bspi_rf_msg_status = -EIO ; + qspi->bspi_rf_op_status = -EIO ;if (qspi->soc_intc)/* clear soc interrupt */ soc_intc->bcm_qspi_int_ack (soc_intc,BSPI_ERR );
@@ -1186,6 +1213,10 @@ static void bcm_qspi_hw_uninit(struct bcm_qspi *qspi) } +static const struct spi_controller_mem_ops bcm_qspi_mem_ops = { + .exec_op = bcm_qspi_exec_mem_op_wrapper, +}; +static const struct of_device_id bcm_qspi_of_match[] = { { .compatible ="brcm,spi-bcm-qspi" }, {},
@@ -1228,7 +1259,8 @@ int bcm_qspi_probe(struct platform_device *pdev, master->mode_bits =SPI_CPHA |SPI_CPOL |SPI_RX_DUAL |SPI_RX_QUAD ; master->setup = bcm_qspi_setup; master->transfer_one = bcm_qspi_transfer_one; - master->spi_flash_read = bcm_qspi_flash_read; + master->spi_flash_read = bcm_qspi_flash_read_wrapper; + master->mem_ops = &bcm_qspi_mem_ops; master->cleanup = bcm_qspi_cleanup; master->dev.of_node = dev->of_node; master->num_chipselect =NUM_CHIPSELECT ;
Signature · 6 lines
2.17.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 7/10 spi: bcm53xx: Implement the spi_mem interface
In reply to Boris BrezillonThe spi_mem interface is meant to replace the spi_flash_read() one. Implement the ->exec_op() method so that we can smoothly get rid of the old interface.
Note that the current ->flash_read() implementation looks a bit fragile since it does not take the ->read_opcode passed by the spi-nor layer into account, which means if might not work with all kind of NORs.
Anyway, I left the logic unchanged and added a few extra checks to make sure we're receiving something that looks like a NOR read operation.
---
Changes in v2:
- include spi-mem.h
- treat op->addr.val differently since it's now an u64
--- drivers/spi/spi-bcm2835.c | 1 + drivers/spi/spi-bcm53xx.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-)
drivers/spi/spi-bcm2835.c +1 -0
@@ -37,6 +37,7 @@#include <linux/of_gpio.h> #include <linux/of_irq.h> #include <linux/spi/spi.h> +#include <linux/spi/spi-mem.h> /* SPI register offsets */ #define BCM2835_SPI_CS 0x00
drivers/spi/spi-bcm53xx.c +35 -1
@@ -257,6 +257,38 @@ static int bcm53xxspi_transfer_one(struct spi_master *master,return 0 ; } +static int bcm53xxspi_exec_mem_op (struct spi_mem *mem, +const struct spi_mem_op *op) +{ +struct bcm53xxspi *b53spi =spi_master_get_devdata (mem->spi->master); +u32 from; + +/* +* FIXME: There's nothing in this driver programming the opcode and +* buswidth to be used when a read is done on the mmio window, but it +* seems to be used to access a SPI NOR device, so restrict access +* access to SPINOR_OP_READ commands. +*/ +if (!op->data.nbytes || op->data.dir !=SPI_MEM_DATA_IN || + op->addr.nbytes !=3 || op->cmd.opcode !=0x3 ) +return -ENOTSUPP ; + +/* Return -ENOTSUPP so that the core can fall back to normal reads. */ + from = op->addr.val; +if (from + op->data.nbytes >BCM53XXSPI_FLASH_WINDOW ) +return -ENOTSUPP ; + +bcm53xxspi_enable_bspi (b53spi); +memcpy_fromio (op->data.buf.in, b53spi->mmio_base + from, + op->data.nbytes); + +return 0 ; +} + +static const struct spi_controller_mem_ops bcm53xxspi_mem_ops = { + .exec_op = bcm53xxspi_exec_mem_op, +}; +static int bcm53xxspi_flash_read (struct spi_device *spi,struct spi_flash_read_message *msg) {
@@ -311,8 +343,10 @@ static int bcm53xxspi_bcma_probe(struct bcma_device *core) master->dev.of_node = dev->of_node; master->transfer_one = bcm53xxspi_transfer_one; -if (b53spi->mmio_base) +if (b53spi->mmio_base) { + master->mem_ops = &bcm53xxspi_mem_ops; master->spi_flash_read = bcm53xxspi_flash_read; + }bcma_set_drvdata (core, b53spi);
Signature · 6 lines
2.14.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 07/10] spi: bcm53xx: Implement the spi_mem interface
Quoted 26 lines · On Wed, 11 Apr 2018 00:44:36 +0200 Boris Brezillon…
The
spi_meminterface is meant to replace thespi_flash_read()one. Implement the ->exec_op() method so that we can smoothly get rid of the old interface.Note that the current ->flash_read() implementation looks a bit fragile since it does not take the ->read_opcode passed by the spi-nor layer into account, which means if might not work with all kind of NORs.
Anyway, I left the logic unchanged and added a few extra checks to make sure we're receiving something that looks like a NOR read operation.
Signed-off-by Boris Brezillon <[email protected]>---
Changes in v2:
- includespi-mem.h
- treatop->addr.valdifferently since it's now an u64--- drivers/spi/spi-bcm2835.c | 1 + drivers/spi/spi-bcm53xx.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-)drivers/spi/spi-bcm2835.c +0
-0
drivers/spi/spi-bcm2835.c line 40
Quoted 4 lines
drivers/spi/spi-bcm2835.c +1
-0@@ -37,6 +37,7 @@#include <linux/of_gpio.h> #include <linux/of_irq.h> #include <linux/spi/spi.h> +#include <linux/spi/spi-mem.h>
Oops, I didn't modify the appropriate file. This line should be added in drivers/spi/spi-bcm53xx.c. I'll fix that in the next version.
Quoted 48 lines
drivers/spi/spi-bcm2835.c +0
-0/* SPI register offsets */ #define BCM2835_SPI_CS 0x00drivers/spi/spi-bcm53xx.c +32
-0@@ -257,6 +257,38 @@ static int bcm53xxspi_transfer_one(struct spi_master *master,return 0 ; } +static int bcm53xxspi_exec_mem_op (struct spi_mem *mem, +const struct spi_mem_op *op) +{ +struct bcm53xxspi *b53spi =spi_master_get_devdata (mem->spi->master); +u32 from; + +/* +* FIXME: There's nothing in this driver programming the opcode and +* buswidth to be used when a read is done on the mmio window, but it +* seems to be used to access a SPI NOR device, so restrict access +* access to SPINOR_OP_READ commands. +*/ +if (!op->data.nbytes || op->data.dir !=SPI_MEM_DATA_IN || + op->addr.nbytes !=3 || op->cmd.opcode !=0x3 ) +return -ENOTSUPP ; + +/* Return -ENOTSUPP so that the core can fall back to normal reads. */ + from = op->addr.val; +if (from + op->data.nbytes >BCM53XXSPI_FLASH_WINDOW ) +return -ENOTSUPP ; + +bcm53xxspi_enable_bspi (b53spi); +memcpy_fromio (op->data.buf.in, b53spi->mmio_base + from, + op->data.nbytes); + +return 0 ; +} + +static const struct spi_controller_mem_ops bcm53xxspi_mem_ops = { + .exec_op = bcm53xxspi_exec_mem_op, +}; +static int bcm53xxspi_flash_read (struct spi_device *spi,struct spi_flash_read_message *msg) {@@ -311,8 +343,10 @@ static int bcm53xxspi_bcma_probe(struct bcma_device *core)
drivers/spi/spi-bcm53xx.c static int bcm53xxspi_bcma_probe(struct bcma_device *core) · line 352
Quoted 10 lines
drivers/spi/spi-bcm53xx.c +3
-1master->dev.of_node = dev->of_node; master->transfer_one = bcm53xxspi_transfer_one; -if (b53spi->mmio_base) +if (b53spi->mmio_base) { + master->mem_ops = &bcm53xxspi_mem_ops; master->spi_flash_read = bcm53xxspi_flash_read; + }bcma_set_drvdata (core, b53spi);
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 07/10] spi: bcm53xx: Implement the spi_mem interface
In reply to Boris BrezillonQuoted 4 lines · Boris Brezillon
The
spi_meminterface is meant to replace thespi_flash_read()one. Implement the ->exec_op() method so that we can smoothly get rid of the old interface.
Quoted 8 lines
Note that the current ->flash_read() implementation looks a bit fragile since it does not take the ->read_opcode passed by the spi-nor layer into account, which means if might not work with all kind of NORs.
Anyway, I left the logic unchanged and added a few extra checks to make sure we're receiving something that looks like a NOR read operation.
Signed-off-by Boris Brezillon <[email protected]>
Actually, I've just sent
[PATCH] spi: remove the older/duplicated bcm53xx driver
https://patchwork.kernel.org/patch/10383719/
This patch can be probably dropped, as I expect spi-bcm53xx.c to disappear soon.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 8/10 spi: ti-qspi: Implement the spi_mem interface
In reply to Boris BrezillonThe spi_mem interface is meant to replace the spi_flash_read() one. Implement the ->exec_op() method so that we can smoothly get rid of the old interface.
---
Changes in v2:
- include spi-mem.h
- treat op->addr.val differently since it's now an u64
- Fix 'buf is DMA-able' check
- Extract max mmap size from resource_size()
--- drivers/spi/spi-ti-qspi.c | 84 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 13 deletions(-)
drivers/spi/spi-ti-qspi.c +71 -13
@@ -36,6 +36,7 @@#include <linux/sizes.h> #include <linux/spi/spi.h> +#include <linux/spi/spi-mem.h> struct ti_qspi_regs {u32 clkctrl;
@@ -50,6 +51,7 @@ struct ti_qspi {struct spi_master *master;void __iomem *base;void __iomem *mmap_base; +size_t mmap_size;struct regmap *ctrl_base;unsigned int ctrl_reg;struct clk *fclk;
@@ -434,12 +436,10 @@ static int ti_qspi_dma_xfer(struct ti_qspi *qspi, dma_addr_t dma_dst,return 0 ; } -static int ti_qspi_dma_bounce_buffer (struct ti_qspi *qspi, -struct spi_flash_read_message *msg) +static int ti_qspi_dma_bounce_buffer (struct ti_qspi *qspi,loff_t offs, +void *to,size_t readsize) { -size_t readsize = msg->len; -void *to = msg->buf; -dma_addr_t dma_src = qspi->mmap_phys_base + msg->from; +dma_addr_t dma_src = qspi->mmap_phys_base + offs;int ret =0 ;/*
@@ -507,13 +507,14 @@ static void ti_qspi_disable_memory_map(struct spi_device *spi) qspi->mmap_enabled = false; } -static void ti_qspi_setup_mmap_read (struct spi_device *spi, -struct spi_flash_read_message *msg) +static void ti_qspi_setup_mmap_read (struct spi_device *spi,u8 opcode, +u8 data_nbits,u8 addr_width, +u8 dummy_bytes) {struct ti_qspi *qspi =spi_master_get_devdata (spi->master); -u32 memval = msg->read_opcode; +u32 memval = opcode; -switch (msg->data_nbits) { +switch (data_nbits) {case SPI_NBITS_QUAD : memval |=QSPI_SETUP_RD_QUAD ;break ;
@@ -524,8 +525,8 @@ static void ti_qspi_setup_mmap_read(struct spi_device *spi, memval |=QSPI_SETUP_RD_NORMAL ;break ; } - memval |= ((msg->addr_width -1 ) <<QSPI_SETUP_ADDR_SHIFT | - msg->dummy_bytes <<QSPI_SETUP_DUMMY_SHIFT ); + 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)); }
@@ -546,13 +547,15 @@ static int ti_qspi_spi_flash_read(struct spi_device *spi,if (!qspi->mmap_enabled)ti_qspi_enable_memory_map (spi); -ti_qspi_setup_mmap_read (spi, msg); +ti_qspi_setup_mmap_read (spi, msg->read_opcode, msg->data_nbits, + msg->addr_width, msg->dummy_bytes);if (qspi->rx_chan) {if (msg->cur_msg_mapped) ret =ti_qspi_dma_xfer_sg (qspi, msg->rx_sg, msg->from);else - ret =ti_qspi_dma_bounce_buffer (qspi, msg); + ret =ti_qspi_dma_bounce_buffer (qspi, msg->from, + msg->buf, msg->len);if (ret) goto err_unlock; }else {
@@ -566,6 +569,58 @@ static int ti_qspi_spi_flash_read(struct spi_device *spi,return ret; } +static int ti_qspi_exec_mem_op (struct spi_mem *mem, +const struct spi_mem_op *op) +{ +struct ti_qspi *qspi =spi_master_get_devdata (mem->spi->master); +u32 from =0 ; +int ret =0 ; + +/* Only optimize read path. */ +if (!op->data.nbytes || op->data.dir !=SPI_MEM_DATA_IN || + !op->addr.nbytes || op->addr.nbytes >4 ) +return -ENOTSUPP ; + +/* Address exceeds MMIO window size, fall back to regular mode. */ + from = op->addr.val; +if (from + op->data.nbytes > qspi->mmap_size) +return -ENOTSUPP ; + +mutex_lock (&qspi->list_lock); + +if (!qspi->mmap_enabled) +ti_qspi_enable_memory_map (mem->spi); +ti_qspi_setup_mmap_read (mem->spi, op->cmd.opcode, op->data.buswidth, + op->addr.nbytes, op->dummy.nbytes); + +if (qspi->rx_chan) { +struct sg_table sgt; + +if (virt_addr_valid (op->data.buf.in) && + !spi_controller_dma_map_mem_op_data (mem->spi->master, op, + &sgt)) { + ret =ti_qspi_dma_xfer_sg (qspi, sgt, from); +spi_controller_dma_unmap_mem_op_data (mem->spi->master, + op, &sgt); + }else { + ret =ti_qspi_dma_bounce_buffer (qspi, from, + op->data.buf.in, + op->data.nbytes); + } + }else { +memcpy_fromio (op->data.buf.in, qspi->mmap_base + from, + op->data.nbytes); + } + +mutex_unlock (&qspi->list_lock); + +return ret; +} + +static const struct spi_controller_mem_ops ti_qspi_mem_ops = { + .exec_op = ti_qspi_exec_mem_op, +}; +static int ti_qspi_start_transfer_one (struct spi_master *master,struct spi_message *m) {
@@ -673,6 +728,7 @@ static int ti_qspi_probe(struct platform_device *pdev) master->bits_per_word_mask =SPI_BPW_MASK (32 ) |SPI_BPW_MASK (16 ) |SPI_BPW_MASK (8 ); master->spi_flash_read = ti_qspi_spi_flash_read; + master->mem_ops = &ti_qspi_mem_ops;if (!of_property_read_u32 (np,"num-cs" , &num_cs)) master->num_chipselect = num_cs;
@@ -778,6 +834,7 @@ static int ti_qspi_probe(struct platform_device *pdev) no_dma:if (!qspi->rx_chan && res_mmap) { + qspi->mmap_size =resource_size (res_mmap); qspi->mmap_base =devm_ioremap_resource (&pdev->dev, res_mmap);if (IS_ERR (qspi->mmap_base)) { dev_info(&pdev->dev,
@@ -785,6 +842,7 @@ static int ti_qspi_probe(struct platform_device *pdev) PTR_ERR(qspi->mmap_base)); qspi->mmap_base =NULL ; master->spi_flash_read =NULL ; + master->mem_ops =NULL ; } } qspi->mmap_enabled = false;
Signature · 6 lines
2.14.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 9/10 mtd: spi-nor: Use the spi_mem_xx() API
In reply to Boris BrezillonThe spi_mem_xxx() API has been introduced to replace the spi_flash_read() one. Make use of it so we can get rid of spi_flash_read().
Note that using spi_mem_xx() also simplifies the code because this API takes care of using the regular spi_sync() interface when the optimized ->mem_ops interface is not implemented by the controller.
---
Changes in v2:
- include spi-mem.h
- treat op->addr.val differently since it's now an u64
- Replace SPI_MEM_OP_DATA_OUT() by SPI_MEM_OP_DATA_IN() in m25p80_read()
--- drivers/mtd/devices/Kconfig | 1 + drivers/mtd/devices/m25p80.c | 236 +++++++++++++++---------------------------- 2 files changed, 80 insertions(+), 157 deletions(-)
drivers/mtd/devices/Kconfig +1 -0
@@ -81,6 +81,7 @@ config MTD_DATAFLASH_OTP config MTD_M25P80 tristate "Support most SPI Flash chips (AT26DF, M25P, W25X, ...)" depends on SPI_MASTER && MTD_SPI_NOR + select SPI_MEM help This enables access to most modern SPI flash chips, used for program and data storage. Series supported include Atmel AT26DF,
drivers/mtd/devices/m25p80.c +79 -157
346 lines not on this page · raw message
Signature · 6 lines
2.14.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Mark Brown
maintainerApplied "mtd: spi-nor: Use the spi_mem_xx() API" to the spi tree
The patch
mtd: spi-nor: Use the spi_mem_xx() API
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
4120f8d158ef904fb305b27e4a4524649faf3096Mon Sep 17 00:00:00 2001
From: Boris Brezillon <[email protected]>
Date: Thu, 26 Apr 2018 18:18:19 +0200
Subject: [PATCH] mtd: spi-nor: Use the spi_mem_xx() API
The spi_mem_xxx() API has been introduced to replace the spi_flash_read() one. Make use of it so we can get rid of spi_flash_read().
Note that using spi_mem_xx() also simplifies the code because this API takes care of using the regular spi_sync() interface when the optimized ->mem_ops interface is not implemented by the controller.
--- drivers/mtd/devices/Kconfig | 1 + drivers/mtd/devices/m25p80.c | 236 ++++++++++++----------------------- 2 files changed, 80 insertions(+), 157 deletions(-)
drivers/mtd/devices/Kconfig +1 -0
@@ -81,6 +81,7 @@ config MTD_DATAFLASH_OTP config MTD_M25P80 tristate "Support most SPI Flash chips (AT26DF, M25P, W25X, ...)" depends on SPI_MASTER && MTD_SPI_NOR + select SPI_MEM help This enables access to most modern SPI flash chips, used for program and data storage. Series supported include Atmel AT26DF,
drivers/mtd/devices/m25p80.c +79 -157
346 lines not on this page · raw message
Signature · 6 lines
2.17.0 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v2 10/10 spi: Get rid of the spi_flash_read() API
In reply to Boris BrezillonThis API has been replaced by the spi_mem_xx() one, its only user (spi-nor) has been converted to spi_mem_xx() and all SPI controller drivers that were implementing the ->spi_flash_xxx() hooks are also implementing the spi_mem ones. So we can safely get rid of this API.
--- drivers/spi/spi-bcm-qspi.c | 34 +++------------------------ drivers/spi/spi-bcm53xx.c | 20 +--------------- drivers/spi/spi-ti-qspi.c | 41 --------------------------------- drivers/spi/spi.c | 57 ---------------------------------------------- include/linux/spi/spi.h | 53 ------------------------------------------ 5 files changed, 4 insertions(+), 201 deletions(-)
drivers/spi/spi-bcm-qspi.c +3 -31
@@ -944,9 +944,10 @@ static int bcm_qspi_mspi_exec_mem_op(struct spi_device *spi,return ret; } -static int bcm_qspi_exec_mem_op (struct spi_device *spi, +static int bcm_qspi_exec_mem_op (struct spi_mem *mem,const struct spi_mem_op *op) { +struct spi_device *spi = mem->spi;struct bcm_qspi *qspi =spi_master_get_devdata (spi->master);int ret =0 ;bool mspi_read = false;
@@ -991,34 +992,6 @@ static int bcm_qspi_exec_mem_op(struct spi_device *spi,return ret; } -static int bcm_qspi_exec_mem_op_wrapper (struct spi_mem *mem, -const struct spi_mem_op *op) -{ -return bcm_qspi_exec_mem_op (mem->spi, op); -} - -static int bcm_qspi_flash_read_wrapper (struct spi_device *spi, -struct spi_flash_read_message *msg) -{ -int ret; -struct spi_mem_op op =SPI_MEM_OP (SPI_MEM_OP_CMD (msg->read_opcode,1 ), -SPI_MEM_OP_ADDR (msg->addr_width, - msg->from, - msg->addr_nbits), -SPI_MEM_OP_DUMMY (msg->dummy_bytes, - msg->addr_nbits), -SPI_MEM_OP_DATA_IN (msg->len, - msg->buf, - msg->data_nbits)); - - msg->retlen =0 ; - ret =bcm_qspi_exec_mem_op (spi, &op); -if (!ret) - msg->retlen = msg->len; - -return ret; -} -static void bcm_qspi_cleanup (struct spi_device *spi) {struct bcm_qspi_parms *xp =spi_get_ctldata (spi);
@@ -1214,7 +1187,7 @@ static void bcm_qspi_hw_uninit(struct bcm_qspi *qspi) }static const struct spi_controller_mem_ops bcm_qspi_mem_ops = { - .exec_op = bcm_qspi_exec_mem_op_wrapper, + .exec_op = bcm_qspi_exec_mem_op, };static const struct of_device_id bcm_qspi_of_match[] = {
@@ -1259,7 +1232,6 @@ int bcm_qspi_probe(struct platform_device *pdev, master->mode_bits =SPI_CPHA |SPI_CPOL |SPI_RX_DUAL |SPI_RX_QUAD ; master->setup = bcm_qspi_setup; master->transfer_one = bcm_qspi_transfer_one; - master->spi_flash_read = bcm_qspi_flash_read_wrapper; master->mem_ops = &bcm_qspi_mem_ops; master->cleanup = bcm_qspi_cleanup; master->dev.of_node = dev->of_node;
drivers/spi/spi-bcm53xx.c +1 -19
@@ -289,22 +289,6 @@ static const struct spi_controller_mem_ops bcm53xxspi_mem_ops = { .exec_op = bcm53xxspi_exec_mem_op, }; -static int bcm53xxspi_flash_read (struct spi_device *spi, -struct spi_flash_read_message *msg) -{ -struct bcm53xxspi *b53spi =spi_master_get_devdata (spi->master); -int ret =0 ; - -if (msg->from + msg->len >BCM53XXSPI_FLASH_WINDOW ) -return -EINVAL ; - -bcm53xxspi_enable_bspi (b53spi); -memcpy_fromio (msg->buf, b53spi->mmio_base + msg->from, msg->len); - msg->retlen = msg->len; - -return ret; -} -/************************************************** * BCMA **************************************************/
@@ -343,10 +327,8 @@ static int bcm53xxspi_bcma_probe(struct bcma_device *core) master->dev.of_node = dev->of_node; master->transfer_one = bcm53xxspi_transfer_one; -if (b53spi->mmio_base) { +if (b53spi->mmio_base) master->mem_ops = &bcm53xxspi_mem_ops; - master->spi_flash_read = bcm53xxspi_flash_read; - }bcma_set_drvdata (core, b53spi);
drivers/spi/spi-ti-qspi.c +0 -41
65 lines not on this page · raw message
drivers/spi/spi.c +0 -57
63 lines not on this page · raw message
include/linux/spi/spi.h +0 -53
77 lines not on this page · raw message
Signature · 6 lines
2.14.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Mark Brown
maintainerQuoted 4 lines · Boris Brezillon
In this v2, I think I addressed all the comments I had except the advanced direct memory mapping stuff mentioned by Cyrille, but I don't think any of the work done in this series prevents us from adding this feature later on.
I'm pretty much OK with this, there's a few small bits to be addressed it seems but it looks good overall.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Hi Mark,
Quoted 9 lines · On Tue, 17 Apr 2018 11:57:13 +0100 Mark Brown <[email protected]> wrote:
Quoted 4 lines · Boris Brezillon
In this v2, I think I addressed all the comments I had except the advanced direct memory mapping stuff mentioned by Cyrille, but I don't think any of the work done in this series prevents us from adding this feature later on.
I'm pretty much OK with this, there's a few small bits to be addressed it seems but it looks good overall.
Okay, cool. I'll send a v3 addressing the few issues pointed by reviewers.
Thanks,
Boris
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/