spi: Add support for Amlogic Meson SPIFC
Subsystems (3)
v2 cover spi: Add support for Amlogic Meson SPIFC
Hi,
this patchset adds a driver for the SPIFC (SPI flash controller) available in Amlogic Meson6 and Meson8 SoCs. The driver has been tested on a Meson8 based device to communicate with a Macronix mx25l1606e serial flash.
The first patch adds a field to the spi_transfer structure that allows the driver to know in transfer_one() whether the transfer is the last one and change CS accordingly, without the need to reimplement transfer_one_message().
Changes since v1 [ https://lkml.org/lkml/2014/11/9/35 ]:
- decrease busy wait timeout
- remove check on xfer->speed_hz value in meson_spifc_transfer_one()
- implement transfer_one() instead of transfer_one_message()
- remove useless memset of devdata
- use fixed regmap config
- implement PM operations
- don't set master->bus_num
- allow modular build of the driver
Beniamino Galvani (4):
spi: Add 'last' flag to spi_transfer structure
spi: meson: Add device tree bindings documentation for SPIFC
spi: meson: Add support for Amlogic Meson SPIFC
ARM: dts: meson: add node for SPIFC
.../devicetree/bindings/spi/spi-meson.txt | 22 + arch/arm/boot/dts/meson.dtsi | 9 + drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/spi-meson-spifc.c | 461 +++++++++++++++++++++ drivers/spi/spi.c | 6 + include/linux/spi/spi.h | 2 + 7 files changed, 508 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-meson.txt create mode 100644 drivers/spi/spi-meson-spifc.c
Signature · 1 line
1.9.1
PATCH v2 1/4 spi: Add 'last' flag to spi_transfer structure
Some drivers need to know whether the current transfer is the last in the message in order to properly handle CS. A common way to achieve this is to reimplement transfer_one_message() but this leads to undesirable code duplication.
This patch adds a 'last' field to the spi_transfer structure and populates it before passing the structure to the driver.
--- drivers/spi/spi.c | 6 ++++++ include/linux/spi/spi.h | 2 ++ 2 files changed, 8 insertions(+)
drivers/spi/spi.c +6 -0
@@ -887,6 +887,7 @@ static void spi_pump_messages(struct kthread_work *work) {struct spi_master *master = container_of(work, struct spi_master, pump_messages); +struct spi_transfer *xfer;unsigned long flags;bool was_busy = false;int ret;
@@ -941,6 +942,11 @@ static void spi_pump_messages(struct kthread_work *work) } } +list_for_each_entry (xfer, &master->cur_msg->transfers, transfer_list) { + xfer->last =list_is_last (&xfer->transfer_list, + &master->cur_msg->transfers); + } +if (!was_busy)trace_spi_master_busy (master);
include/linux/spi/spi.h +2 -0
@@ -535,6 +535,7 @@ extern struct spi_master *spi_busnum_to_master(u16 busnum);* (SPI_NBITS_SINGLE) is used. * @rx_nbits: number of bits used for reading. If 0 the default * (SPI_NBITS_SINGLE) is used. +* @last: whether the transfer is the last in the message. * @len: size of rx and tx buffers (in bytes) * @speed_hz: Select a speed other than the device default for this * transfer. If 0 the default (from @spi_device) is used.
@@ -620,6 +621,7 @@ struct spi_transfer { unsigned cs_change:1; unsigned tx_nbits:3; unsigned rx_nbits:3; + unsigned last:1;#define SPI_NBITS_SINGLE 0x01/* 1bit transfer */ #define SPI_NBITS_DUAL 0x02/* 2bits transfer */ #define SPI_NBITS_QUAD 0x04/* 4bits transfer */
Signature · 1 line
1.9.1
PATCH v2 2/4 spi: meson: Add device tree bindings documentation for SPIFC
In reply to Beniamino GalvaniThis adds documentation of device tree bindings for the Amlogic Meson SPIFC (SPI Flash Controller).
--- .../devicetree/bindings/spi/spi-meson.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-meson.txt
Documentation/devicetree/bindings/spi/spi-meson.txt new file +22 -0
@@ -0,0 +1,22 @@ +Amlogic Meson SPI controllers + +* SPIFC (SPI Flash Controller) + +The Meson SPIFC is a controller optimized for communication with SPI +NOR memories, without DMA support and a 64-byte unified transmit / +receive buffer. + +Required properties: + - compatible: should be "amlogic,meson6-spifc" + - reg: physical base address and length of the controller registers + - clocks: phandle of the input clock for the baud rate generator + - #address-cells: should be 1 + - #size-cells: should be 0 + + spi at c1108c80 { + compatible = "amlogic,meson6-spifc"; + reg = <0xc1108c80 0x80>; + clocks = <&clk81>; + #address-cells = <1>; + #size-cells = <0>; + };
Signature · 1 line
1.9.1
PATCH v2 3/4 spi: meson: Add support for Amlogic Meson SPIFC
In reply to Beniamino GalvaniThis is a driver for the Amlogic Meson SPIFC (SPI flash controller), which is one of the two SPI controllers available on the SoC. It doesn't support DMA and has a 64-byte unified transmit/receive buffer.
The device is optimized for interfacing with SPI NOR memories and allows the execution of standard operations such as read, page program, sector erase, etc. in a simplified way, toggling a bit in a dedicated register. The driver doesn't use those predefined commands and relies only on custom transfers.
--- drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/spi-meson-spifc.c | 461 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 469 insertions(+) create mode 100644 drivers/spi/spi-meson-spifc.c
drivers/spi/Kconfig +7 -0
@@ -301,6 +301,13 @@ config SPI_FSL_ESPI From MPC8536, 85xx platform uses the controller, and all P10xx, P20xx, P30xx,P40xx, P50xx uses this controller. +config SPI_MESON_SPIFC + tristate "Amlogic Meson SPIFC controller" + depends on ARCH_MESON || COMPILE_TEST + help + This enables master mode support for the SPIFC (SPI flash + controller) available in Amlogic Meson SoCs. + config SPI_OC_TINY tristate "OpenCores tiny SPI" depends on GPIOLIB
drivers/spi/Makefile +1 -0
@@ -42,6 +42,7 @@ obj-$(CONFIG_SPI_FSL_SPI) += spi-fsl-spi.o obj-$(CONFIG_SPI_GPIO) += spi-gpio.o obj-$(CONFIG_SPI_IMX) += spi-imx.o obj-$(CONFIG_SPI_LM70_LLP) += spi-lm70llp.o +obj-$(CONFIG_SPI_MESON_SPIFC) += spi-meson-spifc.o obj-$(CONFIG_SPI_MPC512x_PSC) += spi-mpc512x-psc.o obj-$(CONFIG_SPI_MPC52xx_PSC) += spi-mpc52xx-psc.o obj-$(CONFIG_SPI_MPC52xx) += spi-mpc52xx.o
drivers/spi/spi-meson-spifc.c new file +461 -0
461 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 4/4 ARM: dts: meson: add node for SPIFC
In reply to Beniamino GalvaniThis adds a node for the SPI Flash Controller to the Amlogic Meson DTS.
--- arch/arm/boot/dts/meson.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm/boot/dts/meson.dtsi +9 -0
@@ -106,5 +106,14 @@ clocks = <&clk81>; status = "disabled"; }; + + spifc: spi at c1108c80 { + compatible = "amlogic,meson6-spifc"; + reg = <0xc1108c80 0x80>; + #address-cells = <1>; + #size-cells = <0>; + clocks = <&clk81>; + status = "disabled"; + }; }; }; /* end of / */
Signature · 1 line
1.9.1
Mark Brown
maintainerRe: [PATCH v2 1/4] spi: Add 'last' flag to spi_transfer structure
In reply to Beniamino Galvanidrivers/spi/spi.c static void spi_pump_messages(struct kthread_work *work) · line 948
Quoted 4 lines · Beniamino Galvani
drivers/spi/spi.c +4
-0+list_for_each_entry (xfer, &master->cur_msg->transfers, transfer_list) { + xfer->last =list_is_last (&xfer->transfer_list, + &master->cur_msg->transfers); + }
It's incredibly sad to iterate through the entire list in order to find the last entry, especially given that it's a doubly linked list and this is a bit of a hot path. We should look at the previous entry for the list head instead, or perhaps better yet by doing this as part of spi_validate() which already itereates over the entire list and is where we do other similar fixups.
Though looking at this I'm not sure that a flag is the best approach at
all - why not just have the driver call list_is_last() in the transfer
function or ideally provide an inline function that does that so that we
can change the implementation later?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141118/e87d57a0/attachment.sig>
Mark Brown
maintainerRe: [PATCH v2 3/4] spi: meson: Add support for Amlogic Meson SPIFC
In reply to Beniamino GalvaniQuoted 3 lines · Beniamino Galvani
This is a driver for the Amlogic Meson SPIFC (SPI flash controller), which is one of the two SPI controllers available on the SoC. It doesn't support DMA and has a 64-byte unified transmit/receive buffer.
This is all good.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141118/8ff574f9/attachment.sig>
Re: [PATCH v2 1/4] spi: Add 'last' flag to spi_transfer structure
In reply to Mark BrownQuoted 11 lines · Mark Brown
It's incredibly sad to iterate through the entire list in order to find the last entry, especially given that it's a doubly linked list and this is a bit of a hot path. We should look at the previous entry for the list head instead, or perhaps better yet by doing this as part of
spi_validate()which already itereates over the entire list and is where we do other similar fixups.Though looking at this I'm not sure that a flag is the best approach at all - why not just have the driver call
list_is_last()in the transfer function or ideally provide an inline function that does that so that we can change the implementation later?
I didn't realize that the master structure passed to transfer_one() has a reference to the current message and thus to the transfer list. Then yes, the additional flag in the transfer structure probably doesn't make much sense.
Would it be better to introduce something like:
static inline boolspi_transfer_is_last(struct spi_master *master, struct spi_transfer *xfer)
{
return list_is_last(&xfer->transfer_list, &master->cur_msg->transfers);
}or open code it in the driver?
Beniamino
Mark Brown
maintainerRe: [PATCH v2 1/4] spi: Add 'last' flag to spi_transfer structure
Quoted 9 lines · Beniamino Galvani
Would it be better to introduce something like:
static inline bool
spi_transfer_is_last(struct spi_master *master, struct spi_transfer *xfer){ return list_is_last(&xfer->transfer_list, &master->cur_msg->transfers); }or open code it in the driver?
Adding the helper function seems better, it means we can change the
implementation later.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20141119/c10e4109/attachment-0001.sig>