summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael van der Westhuizen <michael@smart-africa.com>2015-08-18 16:21:53 -0400
committerMark Brown <broonie@kernel.org>2015-08-21 13:25:28 -0400
commitc4fe57f76269dbb2af135071513f260ca40229a3 (patch)
tree60afe5453b7602b4cc2fae53ba75236bce2544e1
parent4b226fbde68b8bfb66452067523a677b8e6492fa (diff)
spi: dw: Allow interface drivers to limit data I/O to word sizes
The commit dd11444327ce ("spi: dw-spi: Convert 16bit accesses to 32bit accesses") changed all 16bit accesses in the DW_apb_ssi driver to 32bit. This, unfortunately, breaks data register access on picoXcell, where the DW IP needs data register accesses to be word accesses (all other accesses appear to be OK). This change introduces a new master variable to allow interface drivers to specify that 16bit data transfer I/O is required. This change also introduces the ability to set this variable via device tree bindings in the MMIO interface driver. Both the core and the MMIO interface driver default to the current 32bit behaviour. Before this change, on a picoXcell pc3x3: spi_master spi32766: interrupt_transfer: fifo overrun/underrun m25p80 spi32766.0: error -5 reading 9f m25p80: probe of spi32766.0 failed with error -5 After this change: m25p80 spi32766.0: m25p40 (512 Kbytes) Fixes: dd11444327ce ("spi: dw-spi: Convert 16bit accesses to 32bit accesses") Signed-off-by: Michael van der Westhuizen <michael@smart-africa.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/spi/spi-dw-mmio.c3
-rw-r--r--drivers/spi/spi-dw.c4
-rw-r--r--drivers/spi/spi-dw.h35
3 files changed, 40 insertions, 2 deletions
diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index eb03e1215195..7edede6e024b 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -74,6 +74,9 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
74 74
75 dws->max_freq = clk_get_rate(dwsmmio->clk); 75 dws->max_freq = clk_get_rate(dwsmmio->clk);
76 76
77 of_property_read_u32(pdev->dev.of_node, "reg-io-width",
78 &dws->reg_io_width);
79
77 num_cs = 4; 80 num_cs = 4;
78 81
79 if (pdev->dev.of_node) 82 if (pdev->dev.of_node)
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index 8d67d03c71eb..4fbfcdc5cb24 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -194,7 +194,7 @@ static void dw_writer(struct dw_spi *dws)
194 else 194 else
195 txw = *(u16 *)(dws->tx); 195 txw = *(u16 *)(dws->tx);
196 } 196 }
197 dw_writel(dws, DW_SPI_DR, txw); 197 dw_write_io_reg(dws, DW_SPI_DR, txw);
198 dws->tx += dws->n_bytes; 198 dws->tx += dws->n_bytes;
199 } 199 }
200} 200}
@@ -205,7 +205,7 @@ static void dw_reader(struct dw_spi *dws)
205 u16 rxw; 205 u16 rxw;
206 206
207 while (max--) { 207 while (max--) {
208 rxw = dw_readl(dws, DW_SPI_DR); 208 rxw = dw_read_io_reg(dws, DW_SPI_DR);
209 /* Care rx only if the transfer's original "rx" is not null */ 209 /* Care rx only if the transfer's original "rx" is not null */
210 if (dws->rx_end - dws->len) { 210 if (dws->rx_end - dws->len) {
211 if (dws->n_bytes == 1) 211 if (dws->n_bytes == 1)
diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h
index 6c91391c1a4f..b75ed327d5a2 100644
--- a/drivers/spi/spi-dw.h
+++ b/drivers/spi/spi-dw.h
@@ -109,6 +109,7 @@ struct dw_spi {
109 u32 fifo_len; /* depth of the FIFO buffer */ 109 u32 fifo_len; /* depth of the FIFO buffer */
110 u32 max_freq; /* max bus freq supported */ 110 u32 max_freq; /* max bus freq supported */
111 111
112 u32 reg_io_width; /* DR I/O width in bytes */
112 u16 bus_num; 113 u16 bus_num;
113 u16 num_cs; /* supported slave numbers */ 114 u16 num_cs; /* supported slave numbers */
114 115
@@ -145,11 +146,45 @@ static inline u32 dw_readl(struct dw_spi *dws, u32 offset)
145 return __raw_readl(dws->regs + offset); 146 return __raw_readl(dws->regs + offset);
146} 147}
147 148
149static inline u16 dw_readw(struct dw_spi *dws, u32 offset)
150{
151 return __raw_readw(dws->regs + offset);
152}
153
148static inline void dw_writel(struct dw_spi *dws, u32 offset, u32 val) 154static inline void dw_writel(struct dw_spi *dws, u32 offset, u32 val)
149{ 155{
150 __raw_writel(val, dws->regs + offset); 156 __raw_writel(val, dws->regs + offset);
151} 157}
152 158
159static inline void dw_writew(struct dw_spi *dws, u32 offset, u16 val)
160{
161 __raw_writew(val, dws->regs + offset);
162}
163
164static inline u32 dw_read_io_reg(struct dw_spi *dws, u32 offset)
165{
166 switch (dws->reg_io_width) {
167 case 2:
168 return dw_readw(dws, offset);
169 case 4:
170 default:
171 return dw_readl(dws, offset);
172 }
173}
174
175static inline void dw_write_io_reg(struct dw_spi *dws, u32 offset, u32 val)
176{
177 switch (dws->reg_io_width) {
178 case 2:
179 dw_writew(dws, offset, val);
180 break;
181 case 4:
182 default:
183 dw_writel(dws, offset, val);
184 break;
185 }
186}
187
153static inline void spi_enable_chip(struct dw_spi *dws, int enable) 188static inline void spi_enable_chip(struct dw_spi *dws, int enable)
154{ 189{
155 dw_writel(dws, DW_SPI_SSIENR, (enable ? 1 : 0)); 190 dw_writel(dws, DW_SPI_SSIENR, (enable ? 1 : 0));