spi: Add support for Amlogic Meson SPIFC
Subsystems (3)
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. It doesn't support DMA and has a 64-byte unified transmit/receive buffer.
The driver has been tested on a Meson8 based device to communicate with a Macronix mx25l1606e serial flash.
Beniamino Galvani (3):
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 | 411 +++++++++++++++++++++ 5 files changed, 450 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 1/3 spi: meson: Add device tree bindings documentation for SPIFC
This 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 2/3 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, basically 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 | 411 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 419 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 + bool "Amlogic Meson SPIFC controller" + depends on ARCH_MESON + 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 +411 -0
411 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 3/3 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 2/3] spi: meson: Add support for Amlogic Meson SPIFC
In reply to Beniamino Galvanidrivers/spi/spi-meson-spifc.c line 107
Quoted 11 lines · Beniamino Galvani
drivers/spi/spi-meson-spifc.c new file +11
-0+static int meson_spifc_wait_ready (struct meson_spifc *spifc) +{ +unsigned long deadline = jiffies +msecs_to_jiffies (1000 ); +u32 data; + +do { +regmap_read (spifc->regmap,REG_SLAVE , &data); +if (data &SLAVE_TRST_DONE ) +return 0 ; +cond_resched (); + }while (time_before (jiffies, deadline));
This will busy wait for up to a second, that seems like a long time to busy wait. We also appear to be using this for the entire duration of the transfer which could be a fairly long time even during normal operation if doing a large transfer such as a firmware download, or if the bus speed is low.
drivers/spi/spi-meson-spifc.c line 257
Quoted 3 lines
drivers/spi/spi-meson-spifc.c new file +3
-0+meson_spifc_setup_speed (spifc, xfer->speed_hz ? xfer->speed_hz : + spi->max_speed_hz); +
Please avoid the ternery operator, it does nothing for legibility and in this case it's not needed as the core will always ensure that there is a per-transfer speed set.
drivers/spi/spi-meson-spifc.c line 265
Quoted 6 lines
drivers/spi/spi-meson-spifc.c new file +6
-0+while (done < xfer->len && !ret) { + len =min_t (int, xfer->len - done,SPIFC_BUFFER_SIZE ); + ret =meson_spifc_txrx (spifc, xfer, done, len, + last_xfer, done + len >= xfer->len); + done += len; + }
I noticed that the handling of /CS was done in the spifc_txrx() function
- will this do the right thing if the transfer needs to be split for the buffer size?
drivers/spi/spi-meson-spifc.c line 271
Quoted 2 lines
drivers/spi/spi-meson-spifc.c new file +2
-0+if (!ret && xfer->delay_usecs) +udelay (xfer->delay_usecs);
The core will do this for you if you implement this as transfer_one().
drivers/spi/spi-meson-spifc.c line 283
Quoted 2 lines
drivers/spi/spi-meson-spifc.c new file +2
-0+static int meson_spifc_transfer_one_message (struct spi_master *master, +struct spi_message *msg)
This appears to do nothing that the core won't do - just implement transfer_one() and remove this.
drivers/spi/spi-meson-spifc.c line 319
Quoted 2 lines
drivers/spi/spi-meson-spifc.c new file +2
-0+ spifc =spi_master_get_devdata (master); +memset (spifc,0 ,sizeof (struct meson_spifc ));
There should be no need for this memset.
drivers/spi/spi-meson-spifc.c line 330
Quoted 2 lines
drivers/spi/spi-meson-spifc.c new file +2
-0+ spifc_regmap_config.max_register =resource_size (res) -4 ; + spifc_regmap_config.name ="amlogic,meson-spifc" ;
If you're dynamically initializing the structure you need to work with a copy of it rather than directly since there may be multiple instances. I'm not seeing a reason to override the regmap name here, this is only really intended for devices with multiple register maps.
drivers/spi/spi-meson-spifc.c line 349
Quoted 5 lines
drivers/spi/spi-meson-spifc.c new file +5
-0+ ret =clk_prepare_enable (spifc->clk); +if (ret) { +dev_err (spifc->dev,"can't prepare clock\n" ); + goto out_err; + }
You should really implement runtime PM operations to disable this when not in use and use auto_runtime_pm to make sure this happens.
drivers/spi/spi-meson-spifc.c line 353
Quoted 1 line
drivers/spi/spi-meson-spifc.c new file +1
-0+ master->bus_num = pdev->id;
Leave this blank for DT only devices (and for non-DT devices this won't
work if you get two different buses).
-------------- 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/20141109/68d347bd/attachment.sig>
Re: [PATCH 3/3] ARM: dts: meson: add node for SPIFC
In reply to Beniamino GalvaniQuoted 2 lines · Beniamino Galvani
This adds a node for the SPI Flash Controller to the Amlogic Meson DTS.
-------------- 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/20141109/6cc09c3a/attachment.sig>
Re: [PATCH 2/3] spi: meson: Add support for Amlogic Meson SPIFC
In reply to Mark BrownQuoted 11 lines · Mark Brown
Quoted 9 lines · Beniamino Galvani
drivers/spi/spi-meson-spifc.c new file +9
-0+static int meson_spifc_wait_ready (struct meson_spifc *spifc) +{ +unsigned long deadline = jiffies +msecs_to_jiffies (1000 ); +u32 data; + + do { + regmap_read(spifc->regmap, REG_SLAVE, &data); + if (data & SLAVE_TRST_DONE) + return 0;
Quoted 8 lines
drivers/spi/spi-meson-spifc.c line 107
Quoted 2 lines
drivers/spi/spi-meson-spifc.c new file +2
-0+cond_resched (); + }while (time_before (jiffies, deadline));This will busy wait for up to a second, that seems like a long time to busy wait. We also appear to be using this for the entire duration of the transfer which could be a fairly long time even during normal operation if doing a large transfer such as a firmware download, or if the bus speed is low.
Yes, probably the timeout value is too long since the maximum length of a basic transfer is 64 bytes. Can you suggest a reasonable value?
Quoted 8 lines
drivers/spi/spi-meson-spifc.c line 257
Quoted 4 lines
drivers/spi/spi-meson-spifc.c new file +3
-0+meson_spifc_setup_speed (spifc, xfer->speed_hz ? xfer->speed_hz : + spi->max_speed_hz); +Please avoid the ternery operator, it does nothing for legibility and in this case it's not needed as the core will always ensure that there is a per-transfer speed set.
Ok.
Quoted 10 lines
drivers/spi/spi-meson-spifc.c line 265
Quoted 6 lines
drivers/spi/spi-meson-spifc.c new file +6
-0+while (done < xfer->len && !ret) { + len =min_t (int, xfer->len - done,SPIFC_BUFFER_SIZE ); + ret =meson_spifc_txrx (spifc, xfer, done, len, + last_xfer, done + len >= xfer->len); + done += len; + }I noticed that the handling of /CS was done in the
spifc_txrx()function
- will this do the right thing if the transfer needs to be split for the buffer size?
It should. When the transfer gets split, CS is kept active for all the chunks and the value of CS after that depends on the value of cs_change.
Quoted 5 lines
drivers/spi/spi-meson-spifc.c line 271
Quoted 3 lines
drivers/spi/spi-meson-spifc.c new file +2
-0+if (!ret && xfer->delay_usecs) +udelay (xfer->delay_usecs);The core will do this for you if you implement this as
transfer_one().
Please correct me if I'm wrong, but I think that transfer_one() can't be used in this case. The hardware doesn't support direct manipulation of CS and allows only to specify if CS must be kept active after the current transfer. So I need to know for each transfer if it's the last and this can be achieved only implementing transfer_one_message().
Quoted 29 lines
drivers/spi/spi-meson-spifc.c line 283
Quoted 3 lines
drivers/spi/spi-meson-spifc.c new file +2
-0+static int meson_spifc_transfer_one_message (struct spi_master *master, +struct spi_message *msg)This appears to do nothing that the core won't do - just implement
transfer_one()and remove this.drivers/spi/spi-meson-spifc.c line 319
Quoted 2 lines
drivers/spi/spi-meson-spifc.c new file +2
-0+ spifc =spi_master_get_devdata (master); +memset (spifc,0 ,sizeof (struct meson_spifc ));There should be no need for this memset.
drivers/spi/spi-meson-spifc.c line 330
Quoted 2 lines
drivers/spi/spi-meson-spifc.c new file +2
-0+ spifc_regmap_config.max_register =resource_size (res) -4 ; + spifc_regmap_config.name ="amlogic,meson-spifc" ;If you're dynamically initializing the structure you need to work with a copy of it rather than directly since there may be multiple instances. I'm not seeing a reason to override the regmap name here, this is only really intended for devices with multiple register maps.
drivers/spi/spi-meson-spifc.c line 349
Quoted 5 lines
drivers/spi/spi-meson-spifc.c new file +5
-0+ ret =clk_prepare_enable (spifc->clk); +if (ret) { +dev_err (spifc->dev,"can't prepare clock\n" ); + goto out_err; + }You should really implement runtime PM operations to disable this when not in use and use
auto_runtime_pmto make sure this happens.
Quoted 4 lines
drivers/spi/spi-meson-spifc.c line 353
Quoted 1 line
drivers/spi/spi-meson-spifc.c new file +1
-0+ master->bus_num = pdev->id;Leave this blank for DT only devices (and for non-DT devices this won't work if you get two different buses).
Ok, will do. Thanks for the review.
Beniamino
Mark Brown
maintainerRe: [PATCH 2/3] spi: meson: Add support for Amlogic Meson SPIFC
Quoted 10 lines · Beniamino Galvani
Quoted 5 lines · Mark Brown
This will busy wait for up to a second, that seems like a long time to busy wait. We also appear to be using this for the entire duration of the transfer which could be a fairly long time even during normal operation if doing a large transfer such as a firmware download, or if the bus speed is low.
Yes, probably the timeout value is too long since the maximum length of a basic transfer is 64 bytes. Can you suggest a reasonable value?
10ms? It depends somewhat
Quoted 11 lines
Quoted 10 lines
drivers/spi/spi-meson-spifc.c line 265
Quoted 6 lines
drivers/spi/spi-meson-spifc.c new file +6
-0+while (done < xfer->len && !ret) { + len =min_t (int, xfer->len - done,SPIFC_BUFFER_SIZE ); + ret =meson_spifc_txrx (spifc, xfer, done, len, + last_xfer, done + len >= xfer->len); + done += len; + }I noticed that the handling of /CS was done in the
spifc_txrx()function
- will this do the right thing if the transfer needs to be split for the buffer size?
Quoted 3 lines
It should. When the transfer gets split, CS is kept active for all the chunks and the value of CS after that depends on the value of
cs_change.
Can you be more specific about how that works? I'm just not seeing the code that handles this.
Quoted 10 lines
Quoted 4 lines
drivers/spi/spi-meson-spifc.c line 271
Quoted 2 lines
drivers/spi/spi-meson-spifc.c new file +2
-0+if (!ret && xfer->delay_usecs) +udelay (xfer->delay_usecs);The core will do this for you if you implement this as
transfer_one().Please correct me if I'm wrong, but I think that
transfer_one()can't be used in this case. The hardware doesn't support direct manipulation of CS and allows only to specify if CS must be kept active after the current transfer. So I need to know for each transfer if it's the last and this can be achieved only implementingtransfer_one_message().
This is already in a function that's operating at the transfer_one()
level, the function is even called transfer_one() and besides it's
clearly not something specific to this hardware so should be factored
out into the core instead of open coded.
-------------- 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/20141110/08202a63/attachment.sig>
Re: [PATCH 2/3] spi: meson: Add support for Amlogic Meson SPIFC
Quoted 7 lines · Mark Brown
Quoted 5 lines · Beniamino Galvani
Quoted 3 lines · Mark Brown
I noticed that the handling of /CS was done in the
spifc_txrx()function
- will this do the right thing if the transfer needs to be split for the buffer size?
Quoted 6 lines
Quoted 3 lines
It should. When the transfer gets split, CS is kept active for all the chunks and the value of CS after that depends on the value of
cs_change.Can you be more specific about how that works? I'm just not seeing the code that handles this.
It's this:
static int meson_spifc_txrx(struct meson_spifc *spifc,
struct spi_transfer *xfer, int offset, int len, bool last_xfer, bool last_chunk)
{
bool keep_cs = true;
[...]
if (last_chunk) {
if (last_xfer)
keep_cs = xfer->cs_change;
else
keep_cs = !xfer->cs_change;
}
regmap_update_bits(spifc->regmap, REG_USER4, USER4_CS_ACT,
keep_cs ? USER4_CS_ACT : 0);
/* start transfer */
[...]
}The USER4_CS_ACT bit specifies if CS must be kept active after the transfer.
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
drivers/spi/spi-meson-spifc.c line 271
Quoted 2 lines
drivers/spi/spi-meson-spifc.c new file +2
-0+if (!ret && xfer->delay_usecs) +udelay (xfer->delay_usecs);The core will do this for you if you implement this as
transfer_one().Please correct me if I'm wrong, but I think that
transfer_one()can't be used in this case. The hardware doesn't support direct manipulation of CS and allows only to specify if CS must be kept active after the current transfer. So I need to know for each transfer if it's the last and this can be achieved only implementingtransfer_one_message().
Quoted 4 lines
This is already in a function that's operating at the
transfer_one()level, the function is even calledtransfer_one()and besides it's clearly not something specific to this hardware so should be factored out into the core instead of open coded.
A way to simplify this at core level could be to add a 'last' flag to the spi_transfer structure and populate it before calling transfer_one_message(); in this way, drivers that need to know the position of the transfer in the message in order to properly handle CS can use the generic version of transfer_one_message() instead of reimplementing it. It seems that other existing drivers probably can benefit from this.
Beniamino