spi:fsl-dspi:add support of DSPI IP in big endian
Subsystems (3)
PATCH v2 1/2 spi:fsl-dspi:add support of DSPI IP in big endian
From: Chao Fu <[email protected]>
Freescale DSPI module will have two endianess in diffrente platform, but ARM is little endian. So when DSPI in big endian, core in little endian, readl and writel can not adjust R/W register in this condition. This patch will provide a new io R/W method for the device in two endianess.
Add big/little endian judgement macros:
"#define DSPI_BITWISE16(d, v) (d->big_endian ? cpu_to_be16(v) : cpu_to_le16(v)) "#define DSPI_BITWISE32(d, v) (d->big_endian ? cpu_to_be32(v) : cpu_to_le32(v))
Add functions:
dspi_readb dspi_readw dspi_readl
dspi_writeb dspi_writew dspi_writel
And remove some coding style not in standard.
---
Change in v2:
Make dspi_readx dspi_writex as inline functions. Modify the issue of indentation in function is_double_byte_mode. Add description about big endian in bindings document.
.../devicetree/bindings/spi/spi-fsl-dspi.txt | 2 + drivers/spi/spi-fsl-dspi.c | 87 +++++++++++++++++----- 2 files changed, 71 insertions(+), 18 deletions(-)
Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt +2 -0
@@ -10,6 +10,7 @@ Required properties: - pinctrl-names: must contain a "default" entry. - spi-num-chipselects : the number of the chipselect signals. - bus-num : the slave chip chipselect signal number. +- big-endian : if DSPI modudle is big endian, the bool will be set in node. Example: dspi0 at 4002c000 {
@@ -24,6 +25,7 @@ dspi0 at 4002c000 { bus-num = <0>; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_dspi0_1>; + big-endian; status = "okay"; sflash: at26df081a at 0 {
drivers/spi/spi-fsl-dspi.c +69 -18
174 lines not on this page · raw message
Signature · 1 line
1.8.4
PATCH v2 2/2 spi:dspi:Remove some coding sytle not in standard
From: Chao Fu <[email protected]>
Remove some coding sytle not in standard in former code.
---
Change in v2:
New.
drivers/spi/spi-fsl-dspi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/spi/spi-fsl-dspi.c +4 -4
@@ -113,10 +113,10 @@ struct fsl_dspi {void __iomem *base;int irq; -struct clk *clk; +struct clk *clk;bool big_endian; -struct spi_transfer *cur_transfer; +struct spi_transfer *cur_transfer;struct chip_data *cur_chip;size_t len;void *tx;
@@ -127,8 +127,8 @@ struct fsl_dspi {u8 cs;u16 void_write_data; -wait_queue_head_t waitq; -u32 waitflags; +wait_queue_head_t waitq; +u32 waitflags; };static inline u8 dspi_readb (void __iomem *addr)
Signature · 1 line
1.8.4
Mark Brown
maintainerPATCH v2 2/2 spi:dspi:Remove some coding sytle not in standard
Quoted 3 lines · Chao Fu
From: Chao Fu <[email protected]>
Remove some coding sytle not in standard in former code.
This is OK but depends on your previous patch so can't be applied just
yet.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140109/da0d504a/attachment-0001.sig>
Mark Brown
maintainerPATCH v2 1/2 spi:fsl-dspi:add support of DSPI IP in big endian
In reply to Chao FuOn Wed, Jan 08, 2014 at 02:14:14PM +0800, Chao Fu wrote:
This looks a lot nicer - a few things below though.
drivers/spi/spi-fsl-dspi.c line 35
Quoted 2 lines
drivers/spi/spi-fsl-dspi.c +2
-0+#define DSPI_BITWISE16 (d, v) (d->big_endian ? cpu_to_be16(v) : cpu_to_le16(v)) +#define DSPI_BITWISE32 (d, v) (d->big_endian ? cpu_to_be32(v) : cpu_to_le32(v))
These should probably be inline for the same reason as the I/O functions, perhaps even being done as part of the I/O functions.
drivers/spi/spi-fsl-dspi.c struct fsl_dspi { · line 145
Quoted 7 lines
drivers/spi/spi-fsl-dspi.c +7
-0+static inline u16 dspi_readw (void __iomem *addr) +{ +u16 __v = (__force u16 )__raw_readw (addr); +__iormb (); + +return __v; +}
Why does this need a barrier and why does it not take care of the endianness translation? A quick glance through shows most if not all of the callers doing the translation.
drivers/spi/spi-fsl-dspi.c struct fsl_dspi { · line 164
Quoted 5 lines
drivers/spi/spi-fsl-dspi.c +5
-0+static inline void dspi_writew (u16 val,void __iomem *addr) +{ +__iowmb (); +__raw_writew ((__force u16 ) val, addr); +}
Again the memory barrier seems odd, especially the barrier *before*
doing the write.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140109/4e66f9b4/attachment.sig>
PATCH v2 1/2 spi:fsl-dspi:add support of DSPI IP in big endian
Quoted 10 lines
This looks a lot nicer - a few things below though.
Quoted 1 line
+#define
DSPI_BITWISE16(d, v)(d->big_endian?cpu_to_be16(v):
cpu_to_le16(v))Quoted 1 line
+#define
DSPI_BITWISE32(d, v)(d->big_endian?cpu_to_be32(v):
cpu_to_le32(v))These should probably be inline for the same reason as the I/O functions, perhaps even being done as part of the I/O functions.
[Chao Fu] Thank you, Mark! I wiil put them into inline functions.
Quoted 11 lines
drivers/spi/spi-fsl-dspi.c struct fsl_dspi { · line 145
Quoted 6 lines
drivers/spi/spi-fsl-dspi.c +6
-0+static inline u16 dspi_readw (void __iomem *addr) { +u16 __v = (__force u16 )__raw_readw (addr); +__iormb (); + +return __v; +}Why does this need a barrier and why does it not take care of the endianness translation? A quick glance through shows most if not all of the callers doing the translation.
[Chao Fu] Our CPUs are working on only ARM architecture. But DSPI have two endianness In different series CPU, so we use __raw_read that do not take of endianness. We need observe ARM io methods make sure avoid instructions executing reorder . ARM IO methods :
#define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })
#define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
#define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; })#define writeb(v,c) ({ __iowmb(); writeb_relaxed(v,c); })
#define writew(v,c) ({ __iowmb(); writew_relaxed(v,c); })
#define writel(v,c) ({ __iowmb(); writel_relaxed(v,c); })So add barrier here. Could you give some suggestions? Many thanks!
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+static inline void dspi_writew(u16 val, void __iomem *addr) { + __iowmb(); + __raw_writew((__force u16) val, addr); }Again the memory barrier seems odd, especially the barrier *before* doing the write.
Mark Brown
maintainerPATCH v2 1/2 spi:fsl-dspi:add support of DSPI IP in big endian
Quoted 8 lines · Chao Fu
[Chao Fu] Our CPUs are working on only ARM architecture. But DSPI have two endianness In different series CPU, so we use
__raw_readthat do not take of endianness. We need observe ARM io methods make sure avoid instructions executing reorder . ARM IO methods :#define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; }) #define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; }) #define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; })
Quoted 5 lines
#define writeb(v,c) ({ __iowmb(); writeb_relaxed(v,c); }) #define writew(v,c) ({ __iowmb(); writew_relaxed(v,c); }) #define writel(v,c) ({ __iowmb(); writel_relaxed(v,c); })So add barrier here. Could you give some suggestions? Many thanks!
OK that makes sense, please add comments explaining that this is due to
the endinaness translation. Given that people are starting to use big
endian more it might be sensible to have these factored out into generic
code but that can wait.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140110/7d8b491e/attachment.sig>
PATCH v2 1/2 spi:fsl-dspi:add support of DSPI IP in big endian
Quoted 14 lines · Mark Brown
Quoted 12 lines · Chao Fu
[Chao Fu] Our CPUs are working on only ARM architecture. But DSPI have two endianness In different series CPU, so we use
__raw_readthat do not take of endianness. We need observe ARM io methods make sure avoid instructions executing reorder . ARM IO methods :#define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; }) #define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; }) #define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; })#define writeb(v,c) ({ __iowmb(); writeb_relaxed(v,c); }) #define writew(v,c) ({ __iowmb(); writew_relaxed(v,c); }) #define writel(v,c) ({ __iowmb(); writel_relaxed(v,c); })
Quoted 6 lines
Quoted 1 line
So add barrier here. Could you give some suggestions? Many thanks!
OK that makes sense, please add comments explaining that this is due to the endinaness translation. Given that people are starting to use big endian more it might be sensible to have these factored out into generic code but that can wait.
Accesses to device memory are guaranteed by the architecture to be in program order when they're within the same 1K block of memory. Larger blocks are permissible, and depends on the SoC. (The ARM ARM is a little unclear on this statement, and I believe the statement is/has been fixed.)
The barriers above are not about ensuring correct program order (we have that anyway), they're about ensuring the visibility externally given the ARM ARM mess-up, and _primerily_ ensuring proper order between DMA coherent memory and a DMA agent being enabled, or the DMA agent status being read vs DMA coherent memory.
Signature · 3 lines
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up. Estimation in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad. Estimate before purchase was "up to 13.2Mbit".