aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
authorH Hartley Sweeten <hartleys@visionengravers.com>2011-09-20 14:06:17 -0400
committerGrant Likely <grant.likely@secretlab.ca>2011-09-21 11:41:48 -0400
commit7eb187b3cd3f6f285d91a196dbefac9b6adbb07c (patch)
tree2086865907f57e441d15ad16bd8bbdd07c29091a /drivers/spi
parent3e3ea716270dc64810f624ad6a3672440b45d3d4 (diff)
spi: spi-dw: fix all sparse warnings
The dw_{read,write}[lw] macros produce sparse warnings everytime they are used. The "read" ones cause: warning: cast removes address space of expression warning: incorrect type in argument 1 (different address spaces) expected void const volatile [noderef] <asn:2>*addr got unsigned int *<noident> And the "write" ones: warning: cast removes address space of expression warning: incorrect type in argument 2 (different address spaces) expected void volatile [noderef] <asn:2>*addr got unsigned int *<noident> Fix this by removing struct dw_spi_reg and converting all the register offsets to #defines. Then convert the macros into inlined functions so that proper type checking can occur. While here, also fix the three sparse warnings in spi-dw-mid.c due to the return value of ioremap_nocache being stored in a u32 * not a void __iomem *. With these changes the spi-dw* files all build with no sparse warnings. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Acked-by: Feng Tang <feng.tang@intel.com> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/spi-dw-mid.c9
-rw-r--r--drivers/spi/spi-dw.c62
-rw-r--r--drivers/spi/spi-dw.h97
3 files changed, 89 insertions, 79 deletions
diff --git a/drivers/spi/spi-dw-mid.c b/drivers/spi/spi-dw-mid.c
index 130e55537db6..e743a45ee92c 100644
--- a/drivers/spi/spi-dw-mid.c
+++ b/drivers/spi/spi-dw-mid.c
@@ -116,13 +116,13 @@ static int mid_spi_dma_transfer(struct dw_spi *dws, int cs_change)
116 /* 1. setup DMA related registers */ 116 /* 1. setup DMA related registers */
117 if (cs_change) { 117 if (cs_change) {
118 spi_enable_chip(dws, 0); 118 spi_enable_chip(dws, 0);
119 dw_writew(dws, dmardlr, 0xf); 119 dw_writew(dws, DW_SPI_DMARDLR, 0xf);
120 dw_writew(dws, dmatdlr, 0x10); 120 dw_writew(dws, DW_SPI_DMATDLR, 0x10);
121 if (dws->tx_dma) 121 if (dws->tx_dma)
122 dma_ctrl |= 0x2; 122 dma_ctrl |= 0x2;
123 if (dws->rx_dma) 123 if (dws->rx_dma)
124 dma_ctrl |= 0x1; 124 dma_ctrl |= 0x1;
125 dw_writew(dws, dmacr, dma_ctrl); 125 dw_writew(dws, DW_SPI_DMACR, dma_ctrl);
126 spi_enable_chip(dws, 1); 126 spi_enable_chip(dws, 1);
127 } 127 }
128 128
@@ -200,7 +200,8 @@ static struct dw_spi_dma_ops mid_dma_ops = {
200 200
201int dw_spi_mid_init(struct dw_spi *dws) 201int dw_spi_mid_init(struct dw_spi *dws)
202{ 202{
203 u32 *clk_reg, clk_cdiv; 203 void __iomem *clk_reg;
204 u32 clk_cdiv;
204 205
205 clk_reg = ioremap_nocache(MRST_CLK_SPI0_REG, 16); 206 clk_reg = ioremap_nocache(MRST_CLK_SPI0_REG, 16);
206 if (!clk_reg) 207 if (!clk_reg)
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index 857cd30b44bb..296d94f4cf72 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -88,35 +88,35 @@ static ssize_t spi_show_regs(struct file *file, char __user *user_buf,
88 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 88 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
89 "=================================\n"); 89 "=================================\n");
90 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 90 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
91 "CTRL0: \t\t0x%08x\n", dw_readl(dws, ctrl0)); 91 "CTRL0: \t\t0x%08x\n", dw_readl(dws, DW_SPI_CTRL0));
92 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 92 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
93 "CTRL1: \t\t0x%08x\n", dw_readl(dws, ctrl1)); 93 "CTRL1: \t\t0x%08x\n", dw_readl(dws, DW_SPI_CTRL1));
94 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 94 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
95 "SSIENR: \t0x%08x\n", dw_readl(dws, ssienr)); 95 "SSIENR: \t0x%08x\n", dw_readl(dws, DW_SPI_SSIENR));
96 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 96 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
97 "SER: \t\t0x%08x\n", dw_readl(dws, ser)); 97 "SER: \t\t0x%08x\n", dw_readl(dws, DW_SPI_SER));
98 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 98 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
99 "BAUDR: \t\t0x%08x\n", dw_readl(dws, baudr)); 99 "BAUDR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_BAUDR));
100 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 100 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
101 "TXFTLR: \t0x%08x\n", dw_readl(dws, txfltr)); 101 "TXFTLR: \t0x%08x\n", dw_readl(dws, DW_SPI_TXFLTR));
102 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 102 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
103 "RXFTLR: \t0x%08x\n", dw_readl(dws, rxfltr)); 103 "RXFTLR: \t0x%08x\n", dw_readl(dws, DW_SPI_RXFLTR));
104 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 104 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
105 "TXFLR: \t\t0x%08x\n", dw_readl(dws, txflr)); 105 "TXFLR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_TXFLR));
106 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 106 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
107 "RXFLR: \t\t0x%08x\n", dw_readl(dws, rxflr)); 107 "RXFLR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_RXFLR));
108 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 108 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
109 "SR: \t\t0x%08x\n", dw_readl(dws, sr)); 109 "SR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_SR));
110 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 110 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
111 "IMR: \t\t0x%08x\n", dw_readl(dws, imr)); 111 "IMR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_IMR));
112 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 112 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
113 "ISR: \t\t0x%08x\n", dw_readl(dws, isr)); 113 "ISR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_ISR));
114 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 114 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
115 "DMACR: \t\t0x%08x\n", dw_readl(dws, dmacr)); 115 "DMACR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_DMACR));
116 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 116 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
117 "DMATDLR: \t0x%08x\n", dw_readl(dws, dmatdlr)); 117 "DMATDLR: \t0x%08x\n", dw_readl(dws, DW_SPI_DMATDLR));
118 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 118 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
119 "DMARDLR: \t0x%08x\n", dw_readl(dws, dmardlr)); 119 "DMARDLR: \t0x%08x\n", dw_readl(dws, DW_SPI_DMARDLR));
120 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, 120 len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
121 "=================================\n"); 121 "=================================\n");
122 122
@@ -166,7 +166,7 @@ static inline u32 tx_max(struct dw_spi *dws)
166 u32 tx_left, tx_room, rxtx_gap; 166 u32 tx_left, tx_room, rxtx_gap;
167 167
168 tx_left = (dws->tx_end - dws->tx) / dws->n_bytes; 168 tx_left = (dws->tx_end - dws->tx) / dws->n_bytes;
169 tx_room = dws->fifo_len - dw_readw(dws, txflr); 169 tx_room = dws->fifo_len - dw_readw(dws, DW_SPI_TXFLR);
170 170
171 /* 171 /*
172 * Another concern is about the tx/rx mismatch, we 172 * Another concern is about the tx/rx mismatch, we
@@ -187,7 +187,7 @@ static inline u32 rx_max(struct dw_spi *dws)
187{ 187{
188 u32 rx_left = (dws->rx_end - dws->rx) / dws->n_bytes; 188 u32 rx_left = (dws->rx_end - dws->rx) / dws->n_bytes;
189 189
190 return min(rx_left, (u32)dw_readw(dws, rxflr)); 190 return min(rx_left, (u32)dw_readw(dws, DW_SPI_RXFLR));
191} 191}
192 192
193static void dw_writer(struct dw_spi *dws) 193static void dw_writer(struct dw_spi *dws)
@@ -203,7 +203,7 @@ static void dw_writer(struct dw_spi *dws)
203 else 203 else
204 txw = *(u16 *)(dws->tx); 204 txw = *(u16 *)(dws->tx);
205 } 205 }
206 dw_writew(dws, dr, txw); 206 dw_writew(dws, DW_SPI_DR, txw);
207 dws->tx += dws->n_bytes; 207 dws->tx += dws->n_bytes;
208 } 208 }
209} 209}
@@ -214,7 +214,7 @@ static void dw_reader(struct dw_spi *dws)
214 u16 rxw; 214 u16 rxw;
215 215
216 while (max--) { 216 while (max--) {
217 rxw = dw_readw(dws, dr); 217 rxw = dw_readw(dws, DW_SPI_DR);
218 /* Care rx only if the transfer's original "rx" is not null */ 218 /* Care rx only if the transfer's original "rx" is not null */
219 if (dws->rx_end - dws->len) { 219 if (dws->rx_end - dws->len) {
220 if (dws->n_bytes == 1) 220 if (dws->n_bytes == 1)
@@ -322,13 +322,13 @@ EXPORT_SYMBOL_GPL(dw_spi_xfer_done);
322 322
323static irqreturn_t interrupt_transfer(struct dw_spi *dws) 323static irqreturn_t interrupt_transfer(struct dw_spi *dws)
324{ 324{
325 u16 irq_status = dw_readw(dws, isr); 325 u16 irq_status = dw_readw(dws, DW_SPI_ISR);
326 326
327 /* Error handling */ 327 /* Error handling */
328 if (irq_status & (SPI_INT_TXOI | SPI_INT_RXOI | SPI_INT_RXUI)) { 328 if (irq_status & (SPI_INT_TXOI | SPI_INT_RXOI | SPI_INT_RXUI)) {
329 dw_readw(dws, txoicr); 329 dw_readw(dws, DW_SPI_TXOICR);
330 dw_readw(dws, rxoicr); 330 dw_readw(dws, DW_SPI_RXOICR);
331 dw_readw(dws, rxuicr); 331 dw_readw(dws, DW_SPI_RXUICR);
332 int_error_stop(dws, "interrupt_transfer: fifo overrun/underrun"); 332 int_error_stop(dws, "interrupt_transfer: fifo overrun/underrun");
333 return IRQ_HANDLED; 333 return IRQ_HANDLED;
334 } 334 }
@@ -352,7 +352,7 @@ static irqreturn_t interrupt_transfer(struct dw_spi *dws)
352static irqreturn_t dw_spi_irq(int irq, void *dev_id) 352static irqreturn_t dw_spi_irq(int irq, void *dev_id)
353{ 353{
354 struct dw_spi *dws = dev_id; 354 struct dw_spi *dws = dev_id;
355 u16 irq_status = dw_readw(dws, isr) & 0x3f; 355 u16 irq_status = dw_readw(dws, DW_SPI_ISR) & 0x3f;
356 356
357 if (!irq_status) 357 if (!irq_status)
358 return IRQ_NONE; 358 return IRQ_NONE;
@@ -520,11 +520,11 @@ static void pump_transfers(unsigned long data)
520 * 2. clk_div is changed 520 * 2. clk_div is changed
521 * 3. control value changes 521 * 3. control value changes
522 */ 522 */
523 if (dw_readw(dws, ctrl0) != cr0 || cs_change || clk_div || imask) { 523 if (dw_readw(dws, DW_SPI_CTRL0) != cr0 || cs_change || clk_div || imask) {
524 spi_enable_chip(dws, 0); 524 spi_enable_chip(dws, 0);
525 525
526 if (dw_readw(dws, ctrl0) != cr0) 526 if (dw_readw(dws, DW_SPI_CTRL0) != cr0)
527 dw_writew(dws, ctrl0, cr0); 527 dw_writew(dws, DW_SPI_CTRL0, cr0);
528 528
529 spi_set_clk(dws, clk_div ? clk_div : chip->clk_div); 529 spi_set_clk(dws, clk_div ? clk_div : chip->clk_div);
530 spi_chip_sel(dws, spi->chip_select); 530 spi_chip_sel(dws, spi->chip_select);
@@ -534,7 +534,7 @@ static void pump_transfers(unsigned long data)
534 if (imask) 534 if (imask)
535 spi_umask_intr(dws, imask); 535 spi_umask_intr(dws, imask);
536 if (txint_level) 536 if (txint_level)
537 dw_writew(dws, txfltr, txint_level); 537 dw_writew(dws, DW_SPI_TXFLTR, txint_level);
538 538
539 spi_enable_chip(dws, 1); 539 spi_enable_chip(dws, 1);
540 if (cs_change) 540 if (cs_change)
@@ -790,13 +790,13 @@ static void spi_hw_init(struct dw_spi *dws)
790 if (!dws->fifo_len) { 790 if (!dws->fifo_len) {
791 u32 fifo; 791 u32 fifo;
792 for (fifo = 2; fifo <= 257; fifo++) { 792 for (fifo = 2; fifo <= 257; fifo++) {
793 dw_writew(dws, txfltr, fifo); 793 dw_writew(dws, DW_SPI_TXFLTR, fifo);
794 if (fifo != dw_readw(dws, txfltr)) 794 if (fifo != dw_readw(dws, DW_SPI_TXFLTR))
795 break; 795 break;
796 } 796 }
797 797
798 dws->fifo_len = (fifo == 257) ? 0 : fifo; 798 dws->fifo_len = (fifo == 257) ? 0 : fifo;
799 dw_writew(dws, txfltr, 0); 799 dw_writew(dws, DW_SPI_TXFLTR, 0);
800 } 800 }
801} 801}
802 802
diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h
index 8b7b07bf6c3f..9c57c078031e 100644
--- a/drivers/spi/spi-dw.h
+++ b/drivers/spi/spi-dw.h
@@ -4,6 +4,33 @@
4#include <linux/io.h> 4#include <linux/io.h>
5#include <linux/scatterlist.h> 5#include <linux/scatterlist.h>
6 6
7/* Register offsets */
8#define DW_SPI_CTRL0 0x00
9#define DW_SPI_CTRL1 0x04
10#define DW_SPI_SSIENR 0x08
11#define DW_SPI_MWCR 0x0c
12#define DW_SPI_SER 0x10
13#define DW_SPI_BAUDR 0x14
14#define DW_SPI_TXFLTR 0x18
15#define DW_SPI_RXFLTR 0x1c
16#define DW_SPI_TXFLR 0x20
17#define DW_SPI_RXFLR 0x24
18#define DW_SPI_SR 0x28
19#define DW_SPI_IMR 0x2c
20#define DW_SPI_ISR 0x30
21#define DW_SPI_RISR 0x34
22#define DW_SPI_TXOICR 0x38
23#define DW_SPI_RXOICR 0x3c
24#define DW_SPI_RXUICR 0x40
25#define DW_SPI_MSTICR 0x44
26#define DW_SPI_ICR 0x48
27#define DW_SPI_DMACR 0x4c
28#define DW_SPI_DMATDLR 0x50
29#define DW_SPI_DMARDLR 0x54
30#define DW_SPI_IDR 0x58
31#define DW_SPI_VERSION 0x5c
32#define DW_SPI_DR 0x60
33
7/* Bit fields in CTRLR0 */ 34/* Bit fields in CTRLR0 */
8#define SPI_DFS_OFFSET 0 35#define SPI_DFS_OFFSET 0
9 36
@@ -55,35 +82,6 @@ enum dw_ssi_type {
55 SSI_NS_MICROWIRE, 82 SSI_NS_MICROWIRE,
56}; 83};
57 84
58struct dw_spi_reg {
59 u32 ctrl0;
60 u32 ctrl1;
61 u32 ssienr;
62 u32 mwcr;
63 u32 ser;
64 u32 baudr;
65 u32 txfltr;
66 u32 rxfltr;
67 u32 txflr;
68 u32 rxflr;
69 u32 sr;
70 u32 imr;
71 u32 isr;
72 u32 risr;
73 u32 txoicr;
74 u32 rxoicr;
75 u32 rxuicr;
76 u32 msticr;
77 u32 icr;
78 u32 dmacr;
79 u32 dmatdlr;
80 u32 dmardlr;
81 u32 idr;
82 u32 version;
83 u32 dr; /* Currently oper as 32 bits,
84 though only low 16 bits matters */
85} __packed;
86
87struct dw_spi; 85struct dw_spi;
88struct dw_spi_dma_ops { 86struct dw_spi_dma_ops {
89 int (*dma_init)(struct dw_spi *dws); 87 int (*dma_init)(struct dw_spi *dws);
@@ -161,23 +159,34 @@ struct dw_spi {
161#endif 159#endif
162}; 160};
163 161
164#define dw_readl(dw, name) \ 162static inline u32 dw_readl(struct dw_spi *dws, u32 offset)
165 __raw_readl(&(((struct dw_spi_reg *)dw->regs)->name)) 163{
166#define dw_writel(dw, name, val) \ 164 return __raw_readl(dws->regs + offset);
167 __raw_writel((val), &(((struct dw_spi_reg *)dw->regs)->name)) 165}
168#define dw_readw(dw, name) \ 166
169 __raw_readw(&(((struct dw_spi_reg *)dw->regs)->name)) 167static inline void dw_writel(struct dw_spi *dws, u32 offset, u32 val)
170#define dw_writew(dw, name, val) \ 168{
171 __raw_writew((val), &(((struct dw_spi_reg *)dw->regs)->name)) 169 __raw_writel(val, dws->regs + offset);
170}
171
172static inline u16 dw_readw(struct dw_spi *dws, u32 offset)
173{
174 return __raw_readw(dws->regs + offset);
175}
176
177static inline void dw_writew(struct dw_spi *dws, u32 offset, u16 val)
178{
179 __raw_writew(val, dws->regs + offset);
180}
172 181
173static inline void spi_enable_chip(struct dw_spi *dws, int enable) 182static inline void spi_enable_chip(struct dw_spi *dws, int enable)
174{ 183{
175 dw_writel(dws, ssienr, (enable ? 1 : 0)); 184 dw_writel(dws, DW_SPI_SSIENR, (enable ? 1 : 0));
176} 185}
177 186
178static inline void spi_set_clk(struct dw_spi *dws, u16 div) 187static inline void spi_set_clk(struct dw_spi *dws, u16 div)
179{ 188{
180 dw_writel(dws, baudr, div); 189 dw_writel(dws, DW_SPI_BAUDR, div);
181} 190}
182 191
183static inline void spi_chip_sel(struct dw_spi *dws, u16 cs) 192static inline void spi_chip_sel(struct dw_spi *dws, u16 cs)
@@ -188,7 +197,7 @@ static inline void spi_chip_sel(struct dw_spi *dws, u16 cs)
188 if (dws->cs_control) 197 if (dws->cs_control)
189 dws->cs_control(1); 198 dws->cs_control(1);
190 199
191 dw_writel(dws, ser, 1 << cs); 200 dw_writel(dws, DW_SPI_SER, 1 << cs);
192} 201}
193 202
194/* Disable IRQ bits */ 203/* Disable IRQ bits */
@@ -196,8 +205,8 @@ static inline void spi_mask_intr(struct dw_spi *dws, u32 mask)
196{ 205{
197 u32 new_mask; 206 u32 new_mask;
198 207
199 new_mask = dw_readl(dws, imr) & ~mask; 208 new_mask = dw_readl(dws, DW_SPI_IMR) & ~mask;
200 dw_writel(dws, imr, new_mask); 209 dw_writel(dws, DW_SPI_IMR, new_mask);
201} 210}
202 211
203/* Enable IRQ bits */ 212/* Enable IRQ bits */
@@ -205,8 +214,8 @@ static inline void spi_umask_intr(struct dw_spi *dws, u32 mask)
205{ 214{
206 u32 new_mask; 215 u32 new_mask;
207 216
208 new_mask = dw_readl(dws, imr) | mask; 217 new_mask = dw_readl(dws, DW_SPI_IMR) | mask;
209 dw_writel(dws, imr, new_mask); 218 dw_writel(dws, DW_SPI_IMR, new_mask);
210} 219}
211 220
212/* 221/*