* [PATCH 0/3] ARM: sun4i: SPI improvements
@ 2014-12-08 10:13 Alexandru Gagniuc
[not found] ` <1418033642-29731-1-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 9+ messages in thread
From: Alexandru Gagniuc @ 2014-12-08 10:13 UTC (permalink / raw)
To: linux-spi-u79uwXL29TY76Z2rM5mHXA
Cc: broonie-DgEjT+Ai2ygdnm+yROfE0A,
maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A, pawel.moll-5wv7dgnIgG8,
mark.rutland-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
galak-sgV2jX0FEOL9JmXXK+q4OQ, linux-lFZ/pmaqli7XmaaqVzeoHQ,
devicetree-u79uwXL29TY76Z2rM5mHXA, Alexandru Gagniuc
This is a series of patches that gets SPI working in a better state on the
Cubieboard. The main motivation was to use flashrom to to program SPI ROMs.
There is one patch missing, which adds an spidev node on the Cubieboard. Since
Maxime did not like the approach in that patch, I've left it out for now.
Alexandru Gagniuc (3):
ARM: sun4i: spi: Allow transfers larger than FIFO size
ARM: sun4i: dt: Add pin muxing options for SPI
ARM: sun4i: dt: cubieboard: Enable SPI0
arch/arm/boot/dts/sun4i-a10-cubieboard.dts | 6 +++
arch/arm/boot/dts/sun4i-a10.dtsi | 28 ++++++++++++
drivers/spi/spi-sun4i.c | 71 ++++++++++++++++++++++++++----
3 files changed, 96 insertions(+), 9 deletions(-)
--
1.9.3
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/3] ARM: sun4i: spi: Allow transfers larger than FIFO size
[not found] ` <1418033642-29731-1-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-12-08 10:14 ` Alexandru Gagniuc
[not found] ` <1418033642-29731-2-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-12-08 10:14 ` [PATCH 2/3] ARM: sun4i: dt: Add pin muxing options for SPI Alexandru Gagniuc
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Alexandru Gagniuc @ 2014-12-08 10:14 UTC (permalink / raw)
To: linux-spi-u79uwXL29TY76Z2rM5mHXA
Cc: broonie-DgEjT+Ai2ygdnm+yROfE0A,
maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A, pawel.moll-5wv7dgnIgG8,
mark.rutland-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
galak-sgV2jX0FEOL9JmXXK+q4OQ, linux-lFZ/pmaqli7XmaaqVzeoHQ,
devicetree-u79uwXL29TY76Z2rM5mHXA, Alexandru Gagniuc
SPI transfers were limited to one FIFO depth, which is 64 bytes.
This was an artificial limitation, however, as the hardware can handle
much larger bursts. To accommodate this, we enable the interrupt when
the Rx FIFO is 3/4 full, and drain the FIFO within the interrupt
handler. The 3/4 ratio was chosen arbitrarily, with the intention to
reduce the potential number of interrupts.
Since the SUN4I_CTL_TP bit is set, the hardware will pause
transmission whenever the FIFO is full, so there is no risk of losing
data if we can't service the interrupt in time.
For the Tx side, enable and use the Tx FIFO 3/4 empty interrupt to
replenish the FIFO on large SPI bursts. This requires more care in
when the interrupt is left enabled, as this interrupt will continually
trigger when the FIFO is less than 1/4 full, even though we
acknowledge it.
Signed-off-by: Alexandru Gagniuc <mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Acked-by: Maxime Ripard <maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
---
drivers/spi/spi-sun4i.c | 71 ++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 62 insertions(+), 9 deletions(-)
diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c
index 85204c9..e0e2a31 100644
--- a/drivers/spi/spi-sun4i.c
+++ b/drivers/spi/spi-sun4i.c
@@ -46,6 +46,8 @@
#define SUN4I_CTL_TP BIT(18)
#define SUN4I_INT_CTL_REG 0x0c
+#define SUN4I_INT_CTL_RF_F34 BIT(4)
+#define SUN4I_INT_CTL_TF_E34 BIT(12)
#define SUN4I_INT_CTL_TC BIT(16)
#define SUN4I_INT_STA_REG 0x10
@@ -61,11 +63,14 @@
#define SUN4I_CLK_CTL_CDR1(div) (((div) & SUN4I_CLK_CTL_CDR1_MASK) << 8)
#define SUN4I_CLK_CTL_DRS BIT(12)
+#define SUN4I_MAX_XFER_SIZE 0xffffff
+
#define SUN4I_BURST_CNT_REG 0x20
-#define SUN4I_BURST_CNT(cnt) ((cnt) & 0xffffff)
+#define SUN4I_BURST_CNT(cnt) ((cnt) & SUN4I_MAX_XFER_SIZE)
#define SUN4I_XMIT_CNT_REG 0x24
-#define SUN4I_XMIT_CNT(cnt) ((cnt) & 0xffffff)
+#define SUN4I_XMIT_CNT(cnt) ((cnt) & SUN4I_MAX_XFER_SIZE)
+
#define SUN4I_FIFO_STA_REG 0x28
#define SUN4I_FIFO_STA_RF_CNT_MASK 0x7f
@@ -96,6 +101,27 @@ static inline void sun4i_spi_write(struct sun4i_spi *sspi, u32 reg, u32 value)
writel(value, sspi->base_addr + reg);
}
+static inline u32 sun4i_spi_get_tx_fifo_count(struct sun4i_spi *sspi)
+{
+ u32 reg = sun4i_spi_read(sspi, SUN4I_FIFO_STA_REG);
+ reg >>= SUN4I_FIFO_STA_TF_CNT_BITS;
+ return reg & SUN4I_FIFO_STA_TF_CNT_MASK;
+}
+
+static inline void sun4i_spi_enable_interrupt(struct sun4i_spi *sspi, u32 mask)
+{
+ u32 reg = sun4i_spi_read(sspi, SUN4I_INT_CTL_REG);
+ reg |= mask;
+ sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, reg);
+}
+
+static inline void sun4i_spi_disable_interrupt(struct sun4i_spi *sspi, u32 mask)
+{
+ u32 reg = sun4i_spi_read(sspi, SUN4I_INT_CTL_REG);
+ reg &= ~mask;
+ sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, reg);
+}
+
static inline void sun4i_spi_drain_fifo(struct sun4i_spi *sspi, int len)
{
u32 reg, cnt;
@@ -118,10 +144,13 @@ static inline void sun4i_spi_drain_fifo(struct sun4i_spi *sspi, int len)
static inline void sun4i_spi_fill_fifo(struct sun4i_spi *sspi, int len)
{
+ u32 cnt;
u8 byte;
- if (len > sspi->len)
- len = sspi->len;
+ /* See how much data we can fit */
+ cnt = SUN4I_FIFO_DEPTH - sun4i_spi_get_tx_fifo_count(sspi);
+
+ len = min3(len, (int)cnt, sspi->len);
while (len--) {
byte = sspi->tx_buf ? *sspi->tx_buf++ : 0;
@@ -174,8 +203,8 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
int ret = 0;
u32 reg;
- /* We don't support transfer larger than the FIFO */
- if (tfr->len > SUN4I_FIFO_DEPTH)
+ /* This is the maximum SPI burst size supported by the hardware */
+ if (tfr->len > SUN4I_MAX_XFER_SIZE)
return -EINVAL;
reinit_completion(&sspi->done);
@@ -273,7 +302,10 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH);
/* Enable the interrupts */
- sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, SUN4I_INT_CTL_TC);
+ sun4i_spi_enable_interrupt(sspi, SUN4I_INT_CTL_TC | SUN4I_INT_CTL_RF_F34);
+ /* Only enable Tx FIFO interrupt if we really need it */
+ if (tx_len > SUN4I_FIFO_DEPTH)
+ sun4i_spi_enable_interrupt(sspi, SUN4I_INT_CTL_TF_E34);
/* Start the transfer */
reg = sun4i_spi_read(sspi, SUN4I_CTL_REG);
@@ -286,8 +318,6 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
goto out;
}
- sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH);
-
out:
sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, 0);
@@ -302,10 +332,33 @@ static irqreturn_t sun4i_spi_handler(int irq, void *dev_id)
/* Transfer complete */
if (status & SUN4I_INT_CTL_TC) {
sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_TC);
+ sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH);
complete(&sspi->done);
return IRQ_HANDLED;
}
+ /* Receive FIFO 3/4 full */
+ if (status & SUN4I_INT_CTL_RF_F34) {
+ sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH);
+ /* Only clear the interrupt _after_ draining the FIFO */
+ sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_RF_F34);
+ return IRQ_HANDLED;
+ }
+
+ /* Transmit FIFO 3/4 empty */
+ if (status & SUN4I_INT_CTL_TF_E34) {
+ sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH);
+
+ if (!sspi->len)
+ /* nothing left to transmit */
+ sun4i_spi_disable_interrupt(sspi, SUN4I_INT_CTL_TF_E34);
+
+ /* Only clear the interrupt _after_ re-seeding the FIFO */
+ sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_TF_E34);
+
+ return IRQ_HANDLED;
+ }
+
return IRQ_NONE;
}
--
1.9.3
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] ARM: sun4i: dt: Add pin muxing options for SPI
[not found] ` <1418033642-29731-1-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-12-08 10:14 ` [PATCH 1/3] ARM: sun4i: spi: Allow transfers larger than FIFO size Alexandru Gagniuc
@ 2014-12-08 10:14 ` Alexandru Gagniuc
[not found] ` <1418033642-29731-3-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-12-08 10:14 ` [PATCH 3/3] ARM: sun4i: dt: cubieboard: Enable SPI0 Alexandru Gagniuc
2014-12-11 16:56 ` [PATCH 0/3] ARM: sun4i: SPI improvements Maxime Ripard
3 siblings, 1 reply; 9+ messages in thread
From: Alexandru Gagniuc @ 2014-12-08 10:14 UTC (permalink / raw)
To: linux-spi-u79uwXL29TY76Z2rM5mHXA
Cc: broonie-DgEjT+Ai2ygdnm+yROfE0A,
maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A, pawel.moll-5wv7dgnIgG8,
mark.rutland-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
galak-sgV2jX0FEOL9JmXXK+q4OQ, linux-lFZ/pmaqli7XmaaqVzeoHQ,
devicetree-u79uwXL29TY76Z2rM5mHXA, Alexandru Gagniuc
These are based on the available SPI configurations of Cubieboard,
Olimex LIME, and PcDuino. There is no pin group for SPI3, as all the
boards seem to use those pins for EMAC.
Signed-off-by: Alexandru Gagniuc <mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
arch/arm/boot/dts/sun4i-a10.dtsi | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
index 5e2ec2d..38d9611 100644
--- a/arch/arm/boot/dts/sun4i-a10.dtsi
+++ b/arch/arm/boot/dts/sun4i-a10.dtsi
@@ -615,6 +615,34 @@
allwinner,drive = <0>;
allwinner,pull = <0>;
};
+
+ spi0_pins_a: spi0@0 {
+ allwinner,pins = "PI10", "PI11", "PI12", "PI13";
+ allwinner,function = "spi0";
+ allwinner,drive = <0>;
+ allwinner,pull = <0>;
+ };
+
+ spi1_pins_a: spi1@0 {
+ allwinner,pins = "PI16", "PI17", "PI18", "PI19";
+ allwinner,function = "spi1";
+ allwinner,drive = <0>;
+ allwinner,pull = <0>;
+ };
+
+ spi2_pins_a: spi2@0 {
+ allwinner,pins = "PB14", "PB15", "PB16", "PB17";
+ allwinner,function = "spi2";
+ allwinner,drive = <0>;
+ allwinner,pull = <0>;
+ };
+
+ spi2_pins_b: spi2@1 {
+ allwinner,pins = "PC19", "PC20", "PC21", "PC22";
+ allwinner,function = "spi2";
+ allwinner,drive = <0>;
+ allwinner,pull = <0>;
+ };
};
timer@01c20c00 {
--
1.9.3
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] ARM: sun4i: dt: cubieboard: Enable SPI0
[not found] ` <1418033642-29731-1-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-12-08 10:14 ` [PATCH 1/3] ARM: sun4i: spi: Allow transfers larger than FIFO size Alexandru Gagniuc
2014-12-08 10:14 ` [PATCH 2/3] ARM: sun4i: dt: Add pin muxing options for SPI Alexandru Gagniuc
@ 2014-12-08 10:14 ` Alexandru Gagniuc
[not found] ` <1418033642-29731-4-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-12-11 16:56 ` [PATCH 0/3] ARM: sun4i: SPI improvements Maxime Ripard
3 siblings, 1 reply; 9+ messages in thread
From: Alexandru Gagniuc @ 2014-12-08 10:14 UTC (permalink / raw)
To: linux-spi-u79uwXL29TY76Z2rM5mHXA
Cc: broonie-DgEjT+Ai2ygdnm+yROfE0A,
maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A, pawel.moll-5wv7dgnIgG8,
mark.rutland-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
galak-sgV2jX0FEOL9JmXXK+q4OQ, linux-lFZ/pmaqli7XmaaqVzeoHQ,
devicetree-u79uwXL29TY76Z2rM5mHXA, Alexandru Gagniuc
Only SPI0 is enabled, as the schematic denotes it as the only SPI bus,
while other pins are reserved for different peripherals.
Signed-off-by: Alexandru Gagniuc <mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
arch/arm/boot/dts/sun4i-a10-cubieboard.dts | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/arm/boot/dts/sun4i-a10-cubieboard.dts b/arch/arm/boot/dts/sun4i-a10-cubieboard.dts
index 6a310da..140e3ee 100644
--- a/arch/arm/boot/dts/sun4i-a10-cubieboard.dts
+++ b/arch/arm/boot/dts/sun4i-a10-cubieboard.dts
@@ -148,6 +148,12 @@
pinctrl-0 = <&i2c1_pins_a>;
status = "okay";
};
+
+ spi0: spi@01c05000 {
+ pinctrl-names = "default";
+ pinctrl-0 = <&spi0_pins_a>;
+ status = "okay";
+ };
};
leds {
--
1.9.3
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] ARM: sun4i: SPI improvements
[not found] ` <1418033642-29731-1-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
` (2 preceding siblings ...)
2014-12-08 10:14 ` [PATCH 3/3] ARM: sun4i: dt: cubieboard: Enable SPI0 Alexandru Gagniuc
@ 2014-12-11 16:56 ` Maxime Ripard
2014-12-15 16:59 ` Mark Brown
3 siblings, 1 reply; 9+ messages in thread
From: Maxime Ripard @ 2014-12-11 16:56 UTC (permalink / raw)
To: Alexandru Gagniuc
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA, broonie-DgEjT+Ai2ygdnm+yROfE0A,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A, pawel.moll-5wv7dgnIgG8,
mark.rutland-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
galak-sgV2jX0FEOL9JmXXK+q4OQ, linux-lFZ/pmaqli7XmaaqVzeoHQ,
devicetree-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 941 bytes --]
On Mon, Dec 08, 2014 at 04:13:59AM -0600, Alexandru Gagniuc wrote:
> This is a series of patches that gets SPI working in a better state on the
> Cubieboard. The main motivation was to use flashrom to to program SPI ROMs.
> There is one patch missing, which adds an spidev node on the Cubieboard. Since
> Maxime did not like the approach in that patch, I've left it out for now.
Just to make things straight, it's not me alone that didn't like the
approach.
It's both wrong on a theorical point of view to put that in the DT,
since it has no hardware meaning at all (ie it doesn't describe the
hardware, or the state the bootloader left the hardware in), and this
has been NAKed a number of times already by Mark Brown.
See http://permalink.gmane.org/gmane.linux.kernel.spi.devel/11747 for
example.
Maxime
--
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/3] ARM: sun4i: dt: Add pin muxing options for SPI
[not found] ` <1418033642-29731-3-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-12-11 16:57 ` Maxime Ripard
0 siblings, 0 replies; 9+ messages in thread
From: Maxime Ripard @ 2014-12-11 16:57 UTC (permalink / raw)
To: Alexandru Gagniuc
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA, broonie-DgEjT+Ai2ygdnm+yROfE0A,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A, pawel.moll-5wv7dgnIgG8,
mark.rutland-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
galak-sgV2jX0FEOL9JmXXK+q4OQ, linux-lFZ/pmaqli7XmaaqVzeoHQ,
devicetree-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 489 bytes --]
On Mon, Dec 08, 2014 at 04:14:01AM -0600, Alexandru Gagniuc wrote:
> These are based on the available SPI configurations of Cubieboard,
> Olimex LIME, and PcDuino. There is no pin group for SPI3, as all the
> boards seem to use those pins for EMAC.
>
> Signed-off-by: Alexandru Gagniuc <mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Applied, thanks.
Maxime
--
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] ARM: sun4i: dt: cubieboard: Enable SPI0
[not found] ` <1418033642-29731-4-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-12-11 16:57 ` Maxime Ripard
0 siblings, 0 replies; 9+ messages in thread
From: Maxime Ripard @ 2014-12-11 16:57 UTC (permalink / raw)
To: Alexandru Gagniuc
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA, broonie-DgEjT+Ai2ygdnm+yROfE0A,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A, pawel.moll-5wv7dgnIgG8,
mark.rutland-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
galak-sgV2jX0FEOL9JmXXK+q4OQ, linux-lFZ/pmaqli7XmaaqVzeoHQ,
devicetree-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 438 bytes --]
On Mon, Dec 08, 2014 at 04:14:02AM -0600, Alexandru Gagniuc wrote:
> Only SPI0 is enabled, as the schematic denotes it as the only SPI bus,
> while other pins are reserved for different peripherals.
>
> Signed-off-by: Alexandru Gagniuc <mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Applied, thanks!
Maxime
--
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] ARM: sun4i: SPI improvements
2014-12-11 16:56 ` [PATCH 0/3] ARM: sun4i: SPI improvements Maxime Ripard
@ 2014-12-15 16:59 ` Mark Brown
0 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2014-12-15 16:59 UTC (permalink / raw)
To: Maxime Ripard
Cc: Alexandru Gagniuc, linux-spi-u79uwXL29TY76Z2rM5mHXA,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A, pawel.moll-5wv7dgnIgG8,
mark.rutland-5wv7dgnIgG8, ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg,
galak-sgV2jX0FEOL9JmXXK+q4OQ, linux-lFZ/pmaqli7XmaaqVzeoHQ,
devicetree-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 1051 bytes --]
On Thu, Dec 11, 2014 at 05:56:02PM +0100, Maxime Ripard wrote:
> On Mon, Dec 08, 2014 at 04:13:59AM -0600, Alexandru Gagniuc wrote:
> > This is a series of patches that gets SPI working in a better state on the
> > Cubieboard. The main motivation was to use flashrom to to program SPI ROMs.
> > There is one patch missing, which adds an spidev node on the Cubieboard. Since
> > Maxime did not like the approach in that patch, I've left it out for now.
> Just to make things straight, it's not me alone that didn't like the
> approach.
> It's both wrong on a theorical point of view to put that in the DT,
> since it has no hardware meaning at all (ie it doesn't describe the
> hardware, or the state the bootloader left the hardware in), and this
> has been NAKed a number of times already by Mark Brown.
> See http://permalink.gmane.org/gmane.linux.kernel.spi.devel/11747 for
> example.
Right, I'm getting sufficiently many people making this mistake that I
think I'm going to add code to complain loudly if it's instantiated as
spidev from DT.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] ARM: sun4i: spi: Allow transfers larger than FIFO size
[not found] ` <1418033642-29731-2-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2015-01-11 20:06 ` mrnuke
0 siblings, 0 replies; 9+ messages in thread
From: mrnuke @ 2015-01-11 20:06 UTC (permalink / raw)
To: broonie-DgEjT+Ai2ygdnm+yROfE0A
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA,
maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8,
linux-lFZ/pmaqli7XmaaqVzeoHQ
ping
On Monday, December 08, 2014 04:14:00 AM Alexandru Gagniuc wrote:
> SPI transfers were limited to one FIFO depth, which is 64 bytes.
> This was an artificial limitation, however, as the hardware can handle
> much larger bursts. To accommodate this, we enable the interrupt when
> the Rx FIFO is 3/4 full, and drain the FIFO within the interrupt
> handler. The 3/4 ratio was chosen arbitrarily, with the intention to
> reduce the potential number of interrupts.
>
> Since the SUN4I_CTL_TP bit is set, the hardware will pause
> transmission whenever the FIFO is full, so there is no risk of losing
> data if we can't service the interrupt in time.
>
> For the Tx side, enable and use the Tx FIFO 3/4 empty interrupt to
> replenish the FIFO on large SPI bursts. This requires more care in
> when the interrupt is left enabled, as this interrupt will continually
> trigger when the FIFO is less than 1/4 full, even though we
> acknowledge it.
>
> Signed-off-by: Alexandru Gagniuc <mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Acked-by: Maxime Ripard <maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
> ---
> drivers/spi/spi-sun4i.c | 71
> ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62
> insertions(+), 9 deletions(-)
>
> diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c
> index 85204c9..e0e2a31 100644
> --- a/drivers/spi/spi-sun4i.c
> +++ b/drivers/spi/spi-sun4i.c
> @@ -46,6 +46,8 @@
> #define SUN4I_CTL_TP BIT(18)
>
> #define SUN4I_INT_CTL_REG 0x0c
> +#define SUN4I_INT_CTL_RF_F34 BIT(4)
> +#define SUN4I_INT_CTL_TF_E34 BIT(12)
> #define SUN4I_INT_CTL_TC BIT(16)
>
> #define SUN4I_INT_STA_REG 0x10
> @@ -61,11 +63,14 @@
> #define SUN4I_CLK_CTL_CDR1(div) (((div) &
SUN4I_CLK_CTL_CDR1_MASK) << 8)
> #define SUN4I_CLK_CTL_DRS BIT(12)
>
> +#define SUN4I_MAX_XFER_SIZE 0xffffff
> +
> #define SUN4I_BURST_CNT_REG 0x20
> -#define SUN4I_BURST_CNT(cnt) ((cnt) & 0xffffff)
> +#define SUN4I_BURST_CNT(cnt) ((cnt) & SUN4I_MAX_XFER_SIZE)
>
> #define SUN4I_XMIT_CNT_REG 0x24
> -#define SUN4I_XMIT_CNT(cnt) ((cnt) & 0xffffff)
> +#define SUN4I_XMIT_CNT(cnt) ((cnt) & SUN4I_MAX_XFER_SIZE)
> +
>
> #define SUN4I_FIFO_STA_REG 0x28
> #define SUN4I_FIFO_STA_RF_CNT_MASK 0x7f
> @@ -96,6 +101,27 @@ static inline void sun4i_spi_write(struct sun4i_spi
> *sspi, u32 reg, u32 value) writel(value, sspi->base_addr + reg);
> }
>
> +static inline u32 sun4i_spi_get_tx_fifo_count(struct sun4i_spi *sspi)
> +{
> + u32 reg = sun4i_spi_read(sspi, SUN4I_FIFO_STA_REG);
> + reg >>= SUN4I_FIFO_STA_TF_CNT_BITS;
> + return reg & SUN4I_FIFO_STA_TF_CNT_MASK;
> +}
> +
> +static inline void sun4i_spi_enable_interrupt(struct sun4i_spi *sspi, u32
> mask) +{
> + u32 reg = sun4i_spi_read(sspi, SUN4I_INT_CTL_REG);
> + reg |= mask;
> + sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, reg);
> +}
> +
> +static inline void sun4i_spi_disable_interrupt(struct sun4i_spi *sspi, u32
> mask) +{
> + u32 reg = sun4i_spi_read(sspi, SUN4I_INT_CTL_REG);
> + reg &= ~mask;
> + sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, reg);
> +}
> +
> static inline void sun4i_spi_drain_fifo(struct sun4i_spi *sspi, int len)
> {
> u32 reg, cnt;
> @@ -118,10 +144,13 @@ static inline void sun4i_spi_drain_fifo(struct
> sun4i_spi *sspi, int len)
>
> static inline void sun4i_spi_fill_fifo(struct sun4i_spi *sspi, int len)
> {
> + u32 cnt;
> u8 byte;
>
> - if (len > sspi->len)
> - len = sspi->len;
> + /* See how much data we can fit */
> + cnt = SUN4I_FIFO_DEPTH - sun4i_spi_get_tx_fifo_count(sspi);
> +
> + len = min3(len, (int)cnt, sspi->len);
>
> while (len--) {
> byte = sspi->tx_buf ? *sspi->tx_buf++ : 0;
> @@ -174,8 +203,8 @@ static int sun4i_spi_transfer_one(struct spi_master
> *master, int ret = 0;
> u32 reg;
>
> - /* We don't support transfer larger than the FIFO */
> - if (tfr->len > SUN4I_FIFO_DEPTH)
> + /* This is the maximum SPI burst size supported by the hardware */
> + if (tfr->len > SUN4I_MAX_XFER_SIZE)
> return -EINVAL;
>
> reinit_completion(&sspi->done);
> @@ -273,7 +302,10 @@ static int sun4i_spi_transfer_one(struct spi_master
> *master, sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH);
>
> /* Enable the interrupts */
> - sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, SUN4I_INT_CTL_TC);
> + sun4i_spi_enable_interrupt(sspi, SUN4I_INT_CTL_TC |
SUN4I_INT_CTL_RF_F34);
> + /* Only enable Tx FIFO interrupt if we really need it */
> + if (tx_len > SUN4I_FIFO_DEPTH)
> + sun4i_spi_enable_interrupt(sspi, SUN4I_INT_CTL_TF_E34);
>
> /* Start the transfer */
> reg = sun4i_spi_read(sspi, SUN4I_CTL_REG);
> @@ -286,8 +318,6 @@ static int sun4i_spi_transfer_one(struct spi_master
> *master, goto out;
> }
>
> - sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH);
> -
> out:
> sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, 0);
>
> @@ -302,10 +332,33 @@ static irqreturn_t sun4i_spi_handler(int irq, void
> *dev_id) /* Transfer complete */
> if (status & SUN4I_INT_CTL_TC) {
> sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_TC);
> + sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH);
> complete(&sspi->done);
> return IRQ_HANDLED;
> }
>
> + /* Receive FIFO 3/4 full */
> + if (status & SUN4I_INT_CTL_RF_F34) {
> + sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH);
> + /* Only clear the interrupt _after_ draining the FIFO */
> + sun4i_spi_write(sspi, SUN4I_INT_STA_REG,
SUN4I_INT_CTL_RF_F34);
> + return IRQ_HANDLED;
> + }
> +
> + /* Transmit FIFO 3/4 empty */
> + if (status & SUN4I_INT_CTL_TF_E34) {
> + sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH);
> +
> + if (!sspi->len)
> + /* nothing left to transmit */
> + sun4i_spi_disable_interrupt(sspi,
SUN4I_INT_CTL_TF_E34);
> +
> + /* Only clear the interrupt _after_ re-seeding the FIFO */
> + sun4i_spi_write(sspi, SUN4I_INT_STA_REG,
SUN4I_INT_CTL_TF_E34);
> +
> + return IRQ_HANDLED;
> + }
> +
> return IRQ_NONE;
> }
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-01-11 20:06 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-08 10:13 [PATCH 0/3] ARM: sun4i: SPI improvements Alexandru Gagniuc
[not found] ` <1418033642-29731-1-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-12-08 10:14 ` [PATCH 1/3] ARM: sun4i: spi: Allow transfers larger than FIFO size Alexandru Gagniuc
[not found] ` <1418033642-29731-2-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-01-11 20:06 ` mrnuke
2014-12-08 10:14 ` [PATCH 2/3] ARM: sun4i: dt: Add pin muxing options for SPI Alexandru Gagniuc
[not found] ` <1418033642-29731-3-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-12-11 16:57 ` Maxime Ripard
2014-12-08 10:14 ` [PATCH 3/3] ARM: sun4i: dt: cubieboard: Enable SPI0 Alexandru Gagniuc
[not found] ` <1418033642-29731-4-git-send-email-mr.nuke.me-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-12-11 16:57 ` Maxime Ripard
2014-12-11 16:56 ` [PATCH 0/3] ARM: sun4i: SPI improvements Maxime Ripard
2014-12-15 16:59 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).