diff options
author | Mark Brown <broonie@kernel.org> | 2019-09-15 05:32:06 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2019-09-15 05:32:06 -0400 |
commit | b769c5ba8aedc395ed04abe6db84a556d28beec1 (patch) | |
tree | dd00c955f899f65785d60c2b4673785c28054b30 /drivers/spi/spi-fsl-dspi.c | |
parent | 262a2f33454fcecdc2032ca84d6fecdb08233468 (diff) | |
parent | fdeae8f5a2e5eb3fcc9c295bfb28503c3abd4d6e (diff) |
Merge branch 'spi-5.4' into spi-next
Diffstat (limited to 'drivers/spi/spi-fsl-dspi.c')
-rw-r--r-- | drivers/spi/spi-fsl-dspi.c | 720 |
1 files changed, 366 insertions, 354 deletions
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 545fc8189fb0..bec758e978fb 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c | |||
@@ -9,26 +9,16 @@ | |||
9 | #include <linux/delay.h> | 9 | #include <linux/delay.h> |
10 | #include <linux/dmaengine.h> | 10 | #include <linux/dmaengine.h> |
11 | #include <linux/dma-mapping.h> | 11 | #include <linux/dma-mapping.h> |
12 | #include <linux/err.h> | ||
13 | #include <linux/errno.h> | ||
14 | #include <linux/interrupt.h> | 12 | #include <linux/interrupt.h> |
15 | #include <linux/io.h> | ||
16 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
17 | #include <linux/math64.h> | ||
18 | #include <linux/module.h> | 14 | #include <linux/module.h> |
19 | #include <linux/of.h> | ||
20 | #include <linux/of_device.h> | 15 | #include <linux/of_device.h> |
21 | #include <linux/pinctrl/consumer.h> | 16 | #include <linux/pinctrl/consumer.h> |
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/pm_runtime.h> | ||
24 | #include <linux/regmap.h> | 17 | #include <linux/regmap.h> |
25 | #include <linux/sched.h> | ||
26 | #include <linux/spi/spi.h> | 18 | #include <linux/spi/spi.h> |
27 | #include <linux/spi/spi-fsl-dspi.h> | 19 | #include <linux/spi/spi-fsl-dspi.h> |
28 | #include <linux/spi/spi_bitbang.h> | ||
29 | #include <linux/time.h> | ||
30 | 20 | ||
31 | #define DRIVER_NAME "fsl-dspi" | 21 | #define DRIVER_NAME "fsl-dspi" |
32 | 22 | ||
33 | #ifdef CONFIG_M5441x | 23 | #ifdef CONFIG_M5441x |
34 | #define DSPI_FIFO_SIZE 16 | 24 | #define DSPI_FIFO_SIZE 16 |
@@ -37,101 +27,97 @@ | |||
37 | #endif | 27 | #endif |
38 | #define DSPI_DMA_BUFSIZE (DSPI_FIFO_SIZE * 1024) | 28 | #define DSPI_DMA_BUFSIZE (DSPI_FIFO_SIZE * 1024) |
39 | 29 | ||
40 | #define SPI_MCR 0x00 | 30 | #define SPI_MCR 0x00 |
41 | #define SPI_MCR_MASTER (1 << 31) | 31 | #define SPI_MCR_MASTER BIT(31) |
42 | #define SPI_MCR_PCSIS (0x3F << 16) | 32 | #define SPI_MCR_PCSIS (0x3F << 16) |
43 | #define SPI_MCR_CLR_TXF (1 << 11) | 33 | #define SPI_MCR_CLR_TXF BIT(11) |
44 | #define SPI_MCR_CLR_RXF (1 << 10) | 34 | #define SPI_MCR_CLR_RXF BIT(10) |
45 | #define SPI_MCR_XSPI (1 << 3) | 35 | #define SPI_MCR_XSPI BIT(3) |
46 | 36 | ||
47 | #define SPI_TCR 0x08 | 37 | #define SPI_TCR 0x08 |
48 | #define SPI_TCR_GET_TCNT(x) (((x) & 0xffff0000) >> 16) | 38 | #define SPI_TCR_GET_TCNT(x) (((x) & GENMASK(31, 16)) >> 16) |
49 | 39 | ||
50 | #define SPI_CTAR(x) (0x0c + (((x) & 0x3) * 4)) | 40 | #define SPI_CTAR(x) (0x0c + (((x) & GENMASK(1, 0)) * 4)) |
51 | #define SPI_CTAR_FMSZ(x) (((x) & 0x0000000f) << 27) | 41 | #define SPI_CTAR_FMSZ(x) (((x) << 27) & GENMASK(30, 27)) |
52 | #define SPI_CTAR_CPOL(x) ((x) << 26) | 42 | #define SPI_CTAR_CPOL BIT(26) |
53 | #define SPI_CTAR_CPHA(x) ((x) << 25) | 43 | #define SPI_CTAR_CPHA BIT(25) |
54 | #define SPI_CTAR_LSBFE(x) ((x) << 24) | 44 | #define SPI_CTAR_LSBFE BIT(24) |
55 | #define SPI_CTAR_PCSSCK(x) (((x) & 0x00000003) << 22) | 45 | #define SPI_CTAR_PCSSCK(x) (((x) << 22) & GENMASK(23, 22)) |
56 | #define SPI_CTAR_PASC(x) (((x) & 0x00000003) << 20) | 46 | #define SPI_CTAR_PASC(x) (((x) << 20) & GENMASK(21, 20)) |
57 | #define SPI_CTAR_PDT(x) (((x) & 0x00000003) << 18) | 47 | #define SPI_CTAR_PDT(x) (((x) << 18) & GENMASK(19, 18)) |
58 | #define SPI_CTAR_PBR(x) (((x) & 0x00000003) << 16) | 48 | #define SPI_CTAR_PBR(x) (((x) << 16) & GENMASK(17, 16)) |
59 | #define SPI_CTAR_CSSCK(x) (((x) & 0x0000000f) << 12) | 49 | #define SPI_CTAR_CSSCK(x) (((x) << 12) & GENMASK(15, 12)) |
60 | #define SPI_CTAR_ASC(x) (((x) & 0x0000000f) << 8) | 50 | #define SPI_CTAR_ASC(x) (((x) << 8) & GENMASK(11, 8)) |
61 | #define SPI_CTAR_DT(x) (((x) & 0x0000000f) << 4) | 51 | #define SPI_CTAR_DT(x) (((x) << 4) & GENMASK(7, 4)) |
62 | #define SPI_CTAR_BR(x) ((x) & 0x0000000f) | 52 | #define SPI_CTAR_BR(x) ((x) & GENMASK(3, 0)) |
63 | #define SPI_CTAR_SCALE_BITS 0xf | 53 | #define SPI_CTAR_SCALE_BITS 0xf |
64 | 54 | ||
65 | #define SPI_CTAR0_SLAVE 0x0c | 55 | #define SPI_CTAR0_SLAVE 0x0c |
66 | 56 | ||
67 | #define SPI_SR 0x2c | 57 | #define SPI_SR 0x2c |
68 | #define SPI_SR_EOQF 0x10000000 | 58 | #define SPI_SR_TCFQF BIT(31) |
69 | #define SPI_SR_TCFQF 0x80000000 | 59 | #define SPI_SR_EOQF BIT(28) |
70 | #define SPI_SR_CLEAR 0x9aaf0000 | 60 | #define SPI_SR_TFUF BIT(27) |
71 | 61 | #define SPI_SR_TFFF BIT(25) | |
72 | #define SPI_RSER_TFFFE BIT(25) | 62 | #define SPI_SR_CMDTCF BIT(23) |
73 | #define SPI_RSER_TFFFD BIT(24) | 63 | #define SPI_SR_SPEF BIT(21) |
74 | #define SPI_RSER_RFDFE BIT(17) | 64 | #define SPI_SR_RFOF BIT(19) |
75 | #define SPI_RSER_RFDFD BIT(16) | 65 | #define SPI_SR_TFIWF BIT(18) |
76 | 66 | #define SPI_SR_RFDF BIT(17) | |
77 | #define SPI_RSER 0x30 | 67 | #define SPI_SR_CMDFFF BIT(16) |
78 | #define SPI_RSER_EOQFE 0x10000000 | 68 | #define SPI_SR_CLEAR (SPI_SR_TCFQF | SPI_SR_EOQF | \ |
79 | #define SPI_RSER_TCFQE 0x80000000 | 69 | SPI_SR_TFUF | SPI_SR_TFFF | \ |
80 | 70 | SPI_SR_CMDTCF | SPI_SR_SPEF | \ | |
81 | #define SPI_PUSHR 0x34 | 71 | SPI_SR_RFOF | SPI_SR_TFIWF | \ |
82 | #define SPI_PUSHR_CMD_CONT (1 << 15) | 72 | SPI_SR_RFDF | SPI_SR_CMDFFF) |
83 | #define SPI_PUSHR_CONT (SPI_PUSHR_CMD_CONT << 16) | 73 | |
84 | #define SPI_PUSHR_CMD_CTAS(x) (((x) & 0x0003) << 12) | 74 | #define SPI_RSER_TFFFE BIT(25) |
85 | #define SPI_PUSHR_CTAS(x) (SPI_PUSHR_CMD_CTAS(x) << 16) | 75 | #define SPI_RSER_TFFFD BIT(24) |
86 | #define SPI_PUSHR_CMD_EOQ (1 << 11) | 76 | #define SPI_RSER_RFDFE BIT(17) |
87 | #define SPI_PUSHR_EOQ (SPI_PUSHR_CMD_EOQ << 16) | 77 | #define SPI_RSER_RFDFD BIT(16) |
88 | #define SPI_PUSHR_CMD_CTCNT (1 << 10) | 78 | |
89 | #define SPI_PUSHR_CTCNT (SPI_PUSHR_CMD_CTCNT << 16) | 79 | #define SPI_RSER 0x30 |
90 | #define SPI_PUSHR_CMD_PCS(x) ((1 << x) & 0x003f) | 80 | #define SPI_RSER_TCFQE BIT(31) |
91 | #define SPI_PUSHR_PCS(x) (SPI_PUSHR_CMD_PCS(x) << 16) | 81 | #define SPI_RSER_EOQFE BIT(28) |
92 | #define SPI_PUSHR_TXDATA(x) ((x) & 0x0000ffff) | 82 | |
93 | 83 | #define SPI_PUSHR 0x34 | |
94 | #define SPI_PUSHR_SLAVE 0x34 | 84 | #define SPI_PUSHR_CMD_CONT BIT(15) |
95 | 85 | #define SPI_PUSHR_CMD_CTAS(x) (((x) << 12 & GENMASK(14, 12))) | |
96 | #define SPI_POPR 0x38 | 86 | #define SPI_PUSHR_CMD_EOQ BIT(11) |
97 | #define SPI_POPR_RXDATA(x) ((x) & 0x0000ffff) | 87 | #define SPI_PUSHR_CMD_CTCNT BIT(10) |
98 | 88 | #define SPI_PUSHR_CMD_PCS(x) (BIT(x) & GENMASK(5, 0)) | |
99 | #define SPI_TXFR0 0x3c | 89 | |
100 | #define SPI_TXFR1 0x40 | 90 | #define SPI_PUSHR_SLAVE 0x34 |
101 | #define SPI_TXFR2 0x44 | 91 | |
102 | #define SPI_TXFR3 0x48 | 92 | #define SPI_POPR 0x38 |
103 | #define SPI_RXFR0 0x7c | 93 | |
104 | #define SPI_RXFR1 0x80 | 94 | #define SPI_TXFR0 0x3c |
105 | #define SPI_RXFR2 0x84 | 95 | #define SPI_TXFR1 0x40 |
106 | #define SPI_RXFR3 0x88 | 96 | #define SPI_TXFR2 0x44 |
107 | 97 | #define SPI_TXFR3 0x48 | |
108 | #define SPI_CTARE(x) (0x11c + (((x) & 0x3) * 4)) | 98 | #define SPI_RXFR0 0x7c |
109 | #define SPI_CTARE_FMSZE(x) (((x) & 0x1) << 16) | 99 | #define SPI_RXFR1 0x80 |
110 | #define SPI_CTARE_DTCP(x) ((x) & 0x7ff) | 100 | #define SPI_RXFR2 0x84 |
111 | 101 | #define SPI_RXFR3 0x88 | |
112 | #define SPI_SREX 0x13c | 102 | |
113 | 103 | #define SPI_CTARE(x) (0x11c + (((x) & GENMASK(1, 0)) * 4)) | |
114 | #define SPI_FRAME_BITS(bits) SPI_CTAR_FMSZ((bits) - 1) | 104 | #define SPI_CTARE_FMSZE(x) (((x) & 0x1) << 16) |
115 | #define SPI_FRAME_BITS_MASK SPI_CTAR_FMSZ(0xf) | 105 | #define SPI_CTARE_DTCP(x) ((x) & 0x7ff) |
116 | #define SPI_FRAME_BITS_16 SPI_CTAR_FMSZ(0xf) | 106 | |
117 | #define SPI_FRAME_BITS_8 SPI_CTAR_FMSZ(0x7) | 107 | #define SPI_SREX 0x13c |
118 | 108 | ||
119 | #define SPI_FRAME_EBITS(bits) SPI_CTARE_FMSZE(((bits) - 1) >> 4) | 109 | #define SPI_FRAME_BITS(bits) SPI_CTAR_FMSZ((bits) - 1) |
120 | #define SPI_FRAME_EBITS_MASK SPI_CTARE_FMSZE(1) | 110 | #define SPI_FRAME_EBITS(bits) SPI_CTARE_FMSZE(((bits) - 1) >> 4) |
121 | 111 | ||
122 | /* Register offsets for regmap_pushr */ | 112 | /* Register offsets for regmap_pushr */ |
123 | #define PUSHR_CMD 0x0 | 113 | #define PUSHR_CMD 0x0 |
124 | #define PUSHR_TX 0x2 | 114 | #define PUSHR_TX 0x2 |
125 | 115 | ||
126 | #define SPI_CS_INIT 0x01 | 116 | #define DMA_COMPLETION_TIMEOUT msecs_to_jiffies(3000) |
127 | #define SPI_CS_ASSERT 0x02 | ||
128 | #define SPI_CS_DROP 0x04 | ||
129 | |||
130 | #define DMA_COMPLETION_TIMEOUT msecs_to_jiffies(3000) | ||
131 | 117 | ||
132 | struct chip_data { | 118 | struct chip_data { |
133 | u32 ctar_val; | 119 | u32 ctar_val; |
134 | u16 void_write_data; | 120 | u16 void_write_data; |
135 | }; | 121 | }; |
136 | 122 | ||
137 | enum dspi_trans_mode { | 123 | enum dspi_trans_mode { |
@@ -141,75 +127,75 @@ enum dspi_trans_mode { | |||
141 | }; | 127 | }; |
142 | 128 | ||
143 | struct fsl_dspi_devtype_data { | 129 | struct fsl_dspi_devtype_data { |
144 | enum dspi_trans_mode trans_mode; | 130 | enum dspi_trans_mode trans_mode; |
145 | u8 max_clock_factor; | 131 | u8 max_clock_factor; |
146 | bool xspi_mode; | 132 | bool xspi_mode; |
147 | }; | 133 | }; |
148 | 134 | ||
149 | static const struct fsl_dspi_devtype_data vf610_data = { | 135 | static const struct fsl_dspi_devtype_data vf610_data = { |
150 | .trans_mode = DSPI_DMA_MODE, | 136 | .trans_mode = DSPI_DMA_MODE, |
151 | .max_clock_factor = 2, | 137 | .max_clock_factor = 2, |
152 | }; | 138 | }; |
153 | 139 | ||
154 | static const struct fsl_dspi_devtype_data ls1021a_v1_data = { | 140 | static const struct fsl_dspi_devtype_data ls1021a_v1_data = { |
155 | .trans_mode = DSPI_TCFQ_MODE, | 141 | .trans_mode = DSPI_TCFQ_MODE, |
156 | .max_clock_factor = 8, | 142 | .max_clock_factor = 8, |
157 | .xspi_mode = true, | 143 | .xspi_mode = true, |
158 | }; | 144 | }; |
159 | 145 | ||
160 | static const struct fsl_dspi_devtype_data ls2085a_data = { | 146 | static const struct fsl_dspi_devtype_data ls2085a_data = { |
161 | .trans_mode = DSPI_TCFQ_MODE, | 147 | .trans_mode = DSPI_TCFQ_MODE, |
162 | .max_clock_factor = 8, | 148 | .max_clock_factor = 8, |
163 | }; | 149 | }; |
164 | 150 | ||
165 | static const struct fsl_dspi_devtype_data coldfire_data = { | 151 | static const struct fsl_dspi_devtype_data coldfire_data = { |
166 | .trans_mode = DSPI_EOQ_MODE, | 152 | .trans_mode = DSPI_EOQ_MODE, |
167 | .max_clock_factor = 8, | 153 | .max_clock_factor = 8, |
168 | }; | 154 | }; |
169 | 155 | ||
170 | struct fsl_dspi_dma { | 156 | struct fsl_dspi_dma { |
171 | /* Length of transfer in words of DSPI_FIFO_SIZE */ | 157 | /* Length of transfer in words of DSPI_FIFO_SIZE */ |
172 | u32 curr_xfer_len; | 158 | u32 curr_xfer_len; |
173 | 159 | ||
174 | u32 *tx_dma_buf; | 160 | u32 *tx_dma_buf; |
175 | struct dma_chan *chan_tx; | 161 | struct dma_chan *chan_tx; |
176 | dma_addr_t tx_dma_phys; | 162 | dma_addr_t tx_dma_phys; |
177 | struct completion cmd_tx_complete; | 163 | struct completion cmd_tx_complete; |
178 | struct dma_async_tx_descriptor *tx_desc; | 164 | struct dma_async_tx_descriptor *tx_desc; |
179 | 165 | ||
180 | u32 *rx_dma_buf; | 166 | u32 *rx_dma_buf; |
181 | struct dma_chan *chan_rx; | 167 | struct dma_chan *chan_rx; |
182 | dma_addr_t rx_dma_phys; | 168 | dma_addr_t rx_dma_phys; |
183 | struct completion cmd_rx_complete; | 169 | struct completion cmd_rx_complete; |
184 | struct dma_async_tx_descriptor *rx_desc; | 170 | struct dma_async_tx_descriptor *rx_desc; |
185 | }; | 171 | }; |
186 | 172 | ||
187 | struct fsl_dspi { | 173 | struct fsl_dspi { |
188 | struct spi_master *master; | 174 | struct spi_controller *ctlr; |
189 | struct platform_device *pdev; | 175 | struct platform_device *pdev; |
190 | 176 | ||
191 | struct regmap *regmap; | 177 | struct regmap *regmap; |
192 | struct regmap *regmap_pushr; | 178 | struct regmap *regmap_pushr; |
193 | int irq; | 179 | int irq; |
194 | struct clk *clk; | 180 | struct clk *clk; |
195 | 181 | ||
196 | struct spi_transfer *cur_transfer; | 182 | struct spi_transfer *cur_transfer; |
197 | struct spi_message *cur_msg; | 183 | struct spi_message *cur_msg; |
198 | struct chip_data *cur_chip; | 184 | struct chip_data *cur_chip; |
199 | size_t len; | 185 | size_t len; |
200 | const void *tx; | 186 | const void *tx; |
201 | void *rx; | 187 | void *rx; |
202 | void *rx_end; | 188 | void *rx_end; |
203 | u16 void_write_data; | 189 | u16 void_write_data; |
204 | u16 tx_cmd; | 190 | u16 tx_cmd; |
205 | u8 bits_per_word; | 191 | u8 bits_per_word; |
206 | u8 bytes_per_word; | 192 | u8 bytes_per_word; |
207 | const struct fsl_dspi_devtype_data *devtype_data; | 193 | const struct fsl_dspi_devtype_data *devtype_data; |
208 | 194 | ||
209 | wait_queue_head_t waitq; | 195 | wait_queue_head_t waitq; |
210 | u32 waitflags; | 196 | u32 waitflags; |
211 | 197 | ||
212 | struct fsl_dspi_dma *dma; | 198 | struct fsl_dspi_dma *dma; |
213 | }; | 199 | }; |
214 | 200 | ||
215 | static u32 dspi_pop_tx(struct fsl_dspi *dspi) | 201 | static u32 dspi_pop_tx(struct fsl_dspi *dspi) |
@@ -233,7 +219,7 @@ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi) | |||
233 | { | 219 | { |
234 | u16 cmd = dspi->tx_cmd, data = dspi_pop_tx(dspi); | 220 | u16 cmd = dspi->tx_cmd, data = dspi_pop_tx(dspi); |
235 | 221 | ||
236 | if (spi_controller_is_slave(dspi->master)) | 222 | if (spi_controller_is_slave(dspi->ctlr)) |
237 | return data; | 223 | return data; |
238 | 224 | ||
239 | if (dspi->len > 0) | 225 | if (dspi->len > 0) |
@@ -246,7 +232,7 @@ static void dspi_push_rx(struct fsl_dspi *dspi, u32 rxdata) | |||
246 | if (!dspi->rx) | 232 | if (!dspi->rx) |
247 | return; | 233 | return; |
248 | 234 | ||
249 | /* Mask of undefined bits */ | 235 | /* Mask off undefined bits */ |
250 | rxdata &= (1 << dspi->bits_per_word) - 1; | 236 | rxdata &= (1 << dspi->bits_per_word) - 1; |
251 | 237 | ||
252 | if (dspi->bytes_per_word == 1) | 238 | if (dspi->bytes_per_word == 1) |
@@ -282,8 +268,8 @@ static void dspi_rx_dma_callback(void *arg) | |||
282 | 268 | ||
283 | static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi) | 269 | static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi) |
284 | { | 270 | { |
285 | struct fsl_dspi_dma *dma = dspi->dma; | ||
286 | struct device *dev = &dspi->pdev->dev; | 271 | struct device *dev = &dspi->pdev->dev; |
272 | struct fsl_dspi_dma *dma = dspi->dma; | ||
287 | int time_left; | 273 | int time_left; |
288 | int i; | 274 | int i; |
289 | 275 | ||
@@ -332,13 +318,13 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi) | |||
332 | dma_async_issue_pending(dma->chan_rx); | 318 | dma_async_issue_pending(dma->chan_rx); |
333 | dma_async_issue_pending(dma->chan_tx); | 319 | dma_async_issue_pending(dma->chan_tx); |
334 | 320 | ||
335 | if (spi_controller_is_slave(dspi->master)) { | 321 | if (spi_controller_is_slave(dspi->ctlr)) { |
336 | wait_for_completion_interruptible(&dspi->dma->cmd_rx_complete); | 322 | wait_for_completion_interruptible(&dspi->dma->cmd_rx_complete); |
337 | return 0; | 323 | return 0; |
338 | } | 324 | } |
339 | 325 | ||
340 | time_left = wait_for_completion_timeout(&dspi->dma->cmd_tx_complete, | 326 | time_left = wait_for_completion_timeout(&dspi->dma->cmd_tx_complete, |
341 | DMA_COMPLETION_TIMEOUT); | 327 | DMA_COMPLETION_TIMEOUT); |
342 | if (time_left == 0) { | 328 | if (time_left == 0) { |
343 | dev_err(dev, "DMA tx timeout\n"); | 329 | dev_err(dev, "DMA tx timeout\n"); |
344 | dmaengine_terminate_all(dma->chan_tx); | 330 | dmaengine_terminate_all(dma->chan_tx); |
@@ -347,7 +333,7 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi) | |||
347 | } | 333 | } |
348 | 334 | ||
349 | time_left = wait_for_completion_timeout(&dspi->dma->cmd_rx_complete, | 335 | time_left = wait_for_completion_timeout(&dspi->dma->cmd_rx_complete, |
350 | DMA_COMPLETION_TIMEOUT); | 336 | DMA_COMPLETION_TIMEOUT); |
351 | if (time_left == 0) { | 337 | if (time_left == 0) { |
352 | dev_err(dev, "DMA rx timeout\n"); | 338 | dev_err(dev, "DMA rx timeout\n"); |
353 | dmaengine_terminate_all(dma->chan_tx); | 339 | dmaengine_terminate_all(dma->chan_tx); |
@@ -360,9 +346,9 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi) | |||
360 | 346 | ||
361 | static int dspi_dma_xfer(struct fsl_dspi *dspi) | 347 | static int dspi_dma_xfer(struct fsl_dspi *dspi) |
362 | { | 348 | { |
363 | struct fsl_dspi_dma *dma = dspi->dma; | ||
364 | struct device *dev = &dspi->pdev->dev; | ||
365 | struct spi_message *message = dspi->cur_msg; | 349 | struct spi_message *message = dspi->cur_msg; |
350 | struct device *dev = &dspi->pdev->dev; | ||
351 | struct fsl_dspi_dma *dma = dspi->dma; | ||
366 | int curr_remaining_bytes; | 352 | int curr_remaining_bytes; |
367 | int bytes_per_buffer; | 353 | int bytes_per_buffer; |
368 | int ret = 0; | 354 | int ret = 0; |
@@ -397,9 +383,9 @@ exit: | |||
397 | 383 | ||
398 | static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr) | 384 | static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr) |
399 | { | 385 | { |
400 | struct fsl_dspi_dma *dma; | ||
401 | struct dma_slave_config cfg; | ||
402 | struct device *dev = &dspi->pdev->dev; | 386 | struct device *dev = &dspi->pdev->dev; |
387 | struct dma_slave_config cfg; | ||
388 | struct fsl_dspi_dma *dma; | ||
403 | int ret; | 389 | int ret; |
404 | 390 | ||
405 | dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); | 391 | dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); |
@@ -421,14 +407,14 @@ static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr) | |||
421 | } | 407 | } |
422 | 408 | ||
423 | dma->tx_dma_buf = dma_alloc_coherent(dev, DSPI_DMA_BUFSIZE, | 409 | dma->tx_dma_buf = dma_alloc_coherent(dev, DSPI_DMA_BUFSIZE, |
424 | &dma->tx_dma_phys, GFP_KERNEL); | 410 | &dma->tx_dma_phys, GFP_KERNEL); |
425 | if (!dma->tx_dma_buf) { | 411 | if (!dma->tx_dma_buf) { |
426 | ret = -ENOMEM; | 412 | ret = -ENOMEM; |
427 | goto err_tx_dma_buf; | 413 | goto err_tx_dma_buf; |
428 | } | 414 | } |
429 | 415 | ||
430 | dma->rx_dma_buf = dma_alloc_coherent(dev, DSPI_DMA_BUFSIZE, | 416 | dma->rx_dma_buf = dma_alloc_coherent(dev, DSPI_DMA_BUFSIZE, |
431 | &dma->rx_dma_phys, GFP_KERNEL); | 417 | &dma->rx_dma_phys, GFP_KERNEL); |
432 | if (!dma->rx_dma_buf) { | 418 | if (!dma->rx_dma_buf) { |
433 | ret = -ENOMEM; | 419 | ret = -ENOMEM; |
434 | goto err_rx_dma_buf; | 420 | goto err_rx_dma_buf; |
@@ -485,30 +471,31 @@ static void dspi_release_dma(struct fsl_dspi *dspi) | |||
485 | struct fsl_dspi_dma *dma = dspi->dma; | 471 | struct fsl_dspi_dma *dma = dspi->dma; |
486 | struct device *dev = &dspi->pdev->dev; | 472 | struct device *dev = &dspi->pdev->dev; |
487 | 473 | ||
488 | if (dma) { | 474 | if (!dma) |
489 | if (dma->chan_tx) { | 475 | return; |
490 | dma_unmap_single(dev, dma->tx_dma_phys, | ||
491 | DSPI_DMA_BUFSIZE, DMA_TO_DEVICE); | ||
492 | dma_release_channel(dma->chan_tx); | ||
493 | } | ||
494 | 476 | ||
495 | if (dma->chan_rx) { | 477 | if (dma->chan_tx) { |
496 | dma_unmap_single(dev, dma->rx_dma_phys, | 478 | dma_unmap_single(dev, dma->tx_dma_phys, |
497 | DSPI_DMA_BUFSIZE, DMA_FROM_DEVICE); | 479 | DSPI_DMA_BUFSIZE, DMA_TO_DEVICE); |
498 | dma_release_channel(dma->chan_rx); | 480 | dma_release_channel(dma->chan_tx); |
499 | } | 481 | } |
482 | |||
483 | if (dma->chan_rx) { | ||
484 | dma_unmap_single(dev, dma->rx_dma_phys, | ||
485 | DSPI_DMA_BUFSIZE, DMA_FROM_DEVICE); | ||
486 | dma_release_channel(dma->chan_rx); | ||
500 | } | 487 | } |
501 | } | 488 | } |
502 | 489 | ||
503 | static void hz_to_spi_baud(char *pbr, char *br, int speed_hz, | 490 | static void hz_to_spi_baud(char *pbr, char *br, int speed_hz, |
504 | unsigned long clkrate) | 491 | unsigned long clkrate) |
505 | { | 492 | { |
506 | /* Valid baud rate pre-scaler values */ | 493 | /* Valid baud rate pre-scaler values */ |
507 | int pbr_tbl[4] = {2, 3, 5, 7}; | 494 | int pbr_tbl[4] = {2, 3, 5, 7}; |
508 | int brs[16] = { 2, 4, 6, 8, | 495 | int brs[16] = { 2, 4, 6, 8, |
509 | 16, 32, 64, 128, | 496 | 16, 32, 64, 128, |
510 | 256, 512, 1024, 2048, | 497 | 256, 512, 1024, 2048, |
511 | 4096, 8192, 16384, 32768 }; | 498 | 4096, 8192, 16384, 32768 }; |
512 | int scale_needed, scale, minscale = INT_MAX; | 499 | int scale_needed, scale, minscale = INT_MAX; |
513 | int i, j; | 500 | int i, j; |
514 | 501 | ||
@@ -538,15 +525,15 @@ static void hz_to_spi_baud(char *pbr, char *br, int speed_hz, | |||
538 | } | 525 | } |
539 | 526 | ||
540 | static void ns_delay_scale(char *psc, char *sc, int delay_ns, | 527 | static void ns_delay_scale(char *psc, char *sc, int delay_ns, |
541 | unsigned long clkrate) | 528 | unsigned long clkrate) |
542 | { | 529 | { |
543 | int pscale_tbl[4] = {1, 3, 5, 7}; | ||
544 | int scale_needed, scale, minscale = INT_MAX; | 530 | int scale_needed, scale, minscale = INT_MAX; |
545 | int i, j; | 531 | int pscale_tbl[4] = {1, 3, 5, 7}; |
546 | u32 remainder; | 532 | u32 remainder; |
533 | int i, j; | ||
547 | 534 | ||
548 | scale_needed = div_u64_rem((u64)delay_ns * clkrate, NSEC_PER_SEC, | 535 | scale_needed = div_u64_rem((u64)delay_ns * clkrate, NSEC_PER_SEC, |
549 | &remainder); | 536 | &remainder); |
550 | if (remainder) | 537 | if (remainder) |
551 | scale_needed++; | 538 | scale_needed++; |
552 | 539 | ||
@@ -601,7 +588,7 @@ static void dspi_tcfq_write(struct fsl_dspi *dspi) | |||
601 | */ | 588 | */ |
602 | u32 data = dspi_pop_tx(dspi); | 589 | u32 data = dspi_pop_tx(dspi); |
603 | 590 | ||
604 | if (dspi->cur_chip->ctar_val & SPI_CTAR_LSBFE(1)) { | 591 | if (dspi->cur_chip->ctar_val & SPI_CTAR_LSBFE) { |
605 | /* LSB */ | 592 | /* LSB */ |
606 | tx_fifo_write(dspi, data & 0xFFFF); | 593 | tx_fifo_write(dspi, data & 0xFFFF); |
607 | tx_fifo_write(dspi, data >> 16); | 594 | tx_fifo_write(dspi, data >> 16); |
@@ -655,19 +642,90 @@ static void dspi_eoq_read(struct fsl_dspi *dspi) | |||
655 | { | 642 | { |
656 | int fifo_size = DSPI_FIFO_SIZE; | 643 | int fifo_size = DSPI_FIFO_SIZE; |
657 | 644 | ||
658 | /* Read one FIFO entry at and push to rx buffer */ | 645 | /* Read one FIFO entry and push to rx buffer */ |
659 | while ((dspi->rx < dspi->rx_end) && fifo_size--) | 646 | while ((dspi->rx < dspi->rx_end) && fifo_size--) |
660 | dspi_push_rx(dspi, fifo_read(dspi)); | 647 | dspi_push_rx(dspi, fifo_read(dspi)); |
661 | } | 648 | } |
662 | 649 | ||
663 | static int dspi_transfer_one_message(struct spi_master *master, | 650 | static int dspi_rxtx(struct fsl_dspi *dspi) |
664 | struct spi_message *message) | 651 | { |
652 | struct spi_message *msg = dspi->cur_msg; | ||
653 | enum dspi_trans_mode trans_mode; | ||
654 | u16 spi_tcnt; | ||
655 | u32 spi_tcr; | ||
656 | |||
657 | /* Get transfer counter (in number of SPI transfers). It was | ||
658 | * reset to 0 when transfer(s) were started. | ||
659 | */ | ||
660 | regmap_read(dspi->regmap, SPI_TCR, &spi_tcr); | ||
661 | spi_tcnt = SPI_TCR_GET_TCNT(spi_tcr); | ||
662 | /* Update total number of bytes that were transferred */ | ||
663 | msg->actual_length += spi_tcnt * dspi->bytes_per_word; | ||
664 | |||
665 | trans_mode = dspi->devtype_data->trans_mode; | ||
666 | if (trans_mode == DSPI_EOQ_MODE) | ||
667 | dspi_eoq_read(dspi); | ||
668 | else if (trans_mode == DSPI_TCFQ_MODE) | ||
669 | dspi_tcfq_read(dspi); | ||
670 | |||
671 | if (!dspi->len) | ||
672 | /* Success! */ | ||
673 | return 0; | ||
674 | |||
675 | if (trans_mode == DSPI_EOQ_MODE) | ||
676 | dspi_eoq_write(dspi); | ||
677 | else if (trans_mode == DSPI_TCFQ_MODE) | ||
678 | dspi_tcfq_write(dspi); | ||
679 | |||
680 | return -EINPROGRESS; | ||
681 | } | ||
682 | |||
683 | static int dspi_poll(struct fsl_dspi *dspi) | ||
684 | { | ||
685 | int tries = 1000; | ||
686 | u32 spi_sr; | ||
687 | |||
688 | do { | ||
689 | regmap_read(dspi->regmap, SPI_SR, &spi_sr); | ||
690 | regmap_write(dspi->regmap, SPI_SR, spi_sr); | ||
691 | |||
692 | if (spi_sr & (SPI_SR_EOQF | SPI_SR_TCFQF)) | ||
693 | break; | ||
694 | } while (--tries); | ||
695 | |||
696 | if (!tries) | ||
697 | return -ETIMEDOUT; | ||
698 | |||
699 | return dspi_rxtx(dspi); | ||
700 | } | ||
701 | |||
702 | static irqreturn_t dspi_interrupt(int irq, void *dev_id) | ||
703 | { | ||
704 | struct fsl_dspi *dspi = (struct fsl_dspi *)dev_id; | ||
705 | u32 spi_sr; | ||
706 | |||
707 | regmap_read(dspi->regmap, SPI_SR, &spi_sr); | ||
708 | regmap_write(dspi->regmap, SPI_SR, spi_sr); | ||
709 | |||
710 | if (!(spi_sr & (SPI_SR_EOQF | SPI_SR_TCFQF))) | ||
711 | return IRQ_NONE; | ||
712 | |||
713 | if (dspi_rxtx(dspi) == 0) { | ||
714 | dspi->waitflags = 1; | ||
715 | wake_up_interruptible(&dspi->waitq); | ||
716 | } | ||
717 | |||
718 | return IRQ_HANDLED; | ||
719 | } | ||
720 | |||
721 | static int dspi_transfer_one_message(struct spi_controller *ctlr, | ||
722 | struct spi_message *message) | ||
665 | { | 723 | { |
666 | struct fsl_dspi *dspi = spi_master_get_devdata(master); | 724 | struct fsl_dspi *dspi = spi_controller_get_devdata(ctlr); |
667 | struct spi_device *spi = message->spi; | 725 | struct spi_device *spi = message->spi; |
726 | enum dspi_trans_mode trans_mode; | ||
668 | struct spi_transfer *transfer; | 727 | struct spi_transfer *transfer; |
669 | int status = 0; | 728 | int status = 0; |
670 | enum dspi_trans_mode trans_mode; | ||
671 | 729 | ||
672 | message->actual_length = 0; | 730 | message->actual_length = 0; |
673 | 731 | ||
@@ -677,7 +735,7 @@ static int dspi_transfer_one_message(struct spi_master *master, | |||
677 | dspi->cur_chip = spi_get_ctldata(spi); | 735 | dspi->cur_chip = spi_get_ctldata(spi); |
678 | /* Prepare command word for CMD FIFO */ | 736 | /* Prepare command word for CMD FIFO */ |
679 | dspi->tx_cmd = SPI_PUSHR_CMD_CTAS(0) | | 737 | dspi->tx_cmd = SPI_PUSHR_CMD_CTAS(0) | |
680 | SPI_PUSHR_CMD_PCS(spi->chip_select); | 738 | SPI_PUSHR_CMD_PCS(spi->chip_select); |
681 | if (list_is_last(&dspi->cur_transfer->transfer_list, | 739 | if (list_is_last(&dspi->cur_transfer->transfer_list, |
682 | &dspi->cur_msg->transfers)) { | 740 | &dspi->cur_msg->transfers)) { |
683 | /* Leave PCS activated after last transfer when | 741 | /* Leave PCS activated after last transfer when |
@@ -718,8 +776,8 @@ static int dspi_transfer_one_message(struct spi_master *master, | |||
718 | SPI_FRAME_BITS(transfer->bits_per_word)); | 776 | SPI_FRAME_BITS(transfer->bits_per_word)); |
719 | if (dspi->devtype_data->xspi_mode) | 777 | if (dspi->devtype_data->xspi_mode) |
720 | regmap_write(dspi->regmap, SPI_CTARE(0), | 778 | regmap_write(dspi->regmap, SPI_CTARE(0), |
721 | SPI_FRAME_EBITS(transfer->bits_per_word) | 779 | SPI_FRAME_EBITS(transfer->bits_per_word) | |
722 | | SPI_CTARE_DTCP(1)); | 780 | SPI_CTARE_DTCP(1)); |
723 | 781 | ||
724 | trans_mode = dspi->devtype_data->trans_mode; | 782 | trans_mode = dspi->devtype_data->trans_mode; |
725 | switch (trans_mode) { | 783 | switch (trans_mode) { |
@@ -733,8 +791,8 @@ static int dspi_transfer_one_message(struct spi_master *master, | |||
733 | break; | 791 | break; |
734 | case DSPI_DMA_MODE: | 792 | case DSPI_DMA_MODE: |
735 | regmap_write(dspi->regmap, SPI_RSER, | 793 | regmap_write(dspi->regmap, SPI_RSER, |
736 | SPI_RSER_TFFFE | SPI_RSER_TFFFD | | 794 | SPI_RSER_TFFFE | SPI_RSER_TFFFD | |
737 | SPI_RSER_RFDFE | SPI_RSER_RFDFD); | 795 | SPI_RSER_RFDFE | SPI_RSER_RFDFD); |
738 | status = dspi_dma_xfer(dspi); | 796 | status = dspi_dma_xfer(dspi); |
739 | break; | 797 | break; |
740 | default: | 798 | default: |
@@ -744,13 +802,18 @@ static int dspi_transfer_one_message(struct spi_master *master, | |||
744 | goto out; | 802 | goto out; |
745 | } | 803 | } |
746 | 804 | ||
747 | if (trans_mode != DSPI_DMA_MODE) { | 805 | if (!dspi->irq) { |
748 | if (wait_event_interruptible(dspi->waitq, | 806 | do { |
749 | dspi->waitflags)) | 807 | status = dspi_poll(dspi); |
750 | dev_err(&dspi->pdev->dev, | 808 | } while (status == -EINPROGRESS); |
751 | "wait transfer complete fail!\n"); | 809 | } else if (trans_mode != DSPI_DMA_MODE) { |
810 | status = wait_event_interruptible(dspi->waitq, | ||
811 | dspi->waitflags); | ||
752 | dspi->waitflags = 0; | 812 | dspi->waitflags = 0; |
753 | } | 813 | } |
814 | if (status) | ||
815 | dev_err(&dspi->pdev->dev, | ||
816 | "Waiting for transfer to complete failed!\n"); | ||
754 | 817 | ||
755 | if (transfer->delay_usecs) | 818 | if (transfer->delay_usecs) |
756 | udelay(transfer->delay_usecs); | 819 | udelay(transfer->delay_usecs); |
@@ -758,19 +821,19 @@ static int dspi_transfer_one_message(struct spi_master *master, | |||
758 | 821 | ||
759 | out: | 822 | out: |
760 | message->status = status; | 823 | message->status = status; |
761 | spi_finalize_current_message(master); | 824 | spi_finalize_current_message(ctlr); |
762 | 825 | ||
763 | return status; | 826 | return status; |
764 | } | 827 | } |
765 | 828 | ||
766 | static int dspi_setup(struct spi_device *spi) | 829 | static int dspi_setup(struct spi_device *spi) |
767 | { | 830 | { |
768 | struct chip_data *chip; | 831 | struct fsl_dspi *dspi = spi_controller_get_devdata(spi->controller); |
769 | struct fsl_dspi *dspi = spi_master_get_devdata(spi->master); | ||
770 | struct fsl_dspi_platform_data *pdata; | ||
771 | u32 cs_sck_delay = 0, sck_cs_delay = 0; | ||
772 | unsigned char br = 0, pbr = 0, pcssck = 0, cssck = 0; | 832 | unsigned char br = 0, pbr = 0, pcssck = 0, cssck = 0; |
833 | u32 cs_sck_delay = 0, sck_cs_delay = 0; | ||
834 | struct fsl_dspi_platform_data *pdata; | ||
773 | unsigned char pasc = 0, asc = 0; | 835 | unsigned char pasc = 0, asc = 0; |
836 | struct chip_data *chip; | ||
774 | unsigned long clkrate; | 837 | unsigned long clkrate; |
775 | 838 | ||
776 | /* Only alloc on first setup */ | 839 | /* Only alloc on first setup */ |
@@ -785,10 +848,10 @@ static int dspi_setup(struct spi_device *spi) | |||
785 | 848 | ||
786 | if (!pdata) { | 849 | if (!pdata) { |
787 | of_property_read_u32(spi->dev.of_node, "fsl,spi-cs-sck-delay", | 850 | of_property_read_u32(spi->dev.of_node, "fsl,spi-cs-sck-delay", |
788 | &cs_sck_delay); | 851 | &cs_sck_delay); |
789 | 852 | ||
790 | of_property_read_u32(spi->dev.of_node, "fsl,spi-sck-cs-delay", | 853 | of_property_read_u32(spi->dev.of_node, "fsl,spi-sck-cs-delay", |
791 | &sck_cs_delay); | 854 | &sck_cs_delay); |
792 | } else { | 855 | } else { |
793 | cs_sck_delay = pdata->cs_sck_delay; | 856 | cs_sck_delay = pdata->cs_sck_delay; |
794 | sck_cs_delay = pdata->sck_cs_delay; | 857 | sck_cs_delay = pdata->sck_cs_delay; |
@@ -805,18 +868,22 @@ static int dspi_setup(struct spi_device *spi) | |||
805 | /* Set After SCK delay scale values */ | 868 | /* Set After SCK delay scale values */ |
806 | ns_delay_scale(&pasc, &asc, sck_cs_delay, clkrate); | 869 | ns_delay_scale(&pasc, &asc, sck_cs_delay, clkrate); |
807 | 870 | ||
808 | chip->ctar_val = SPI_CTAR_CPOL(spi->mode & SPI_CPOL ? 1 : 0) | 871 | chip->ctar_val = 0; |
809 | | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0); | 872 | if (spi->mode & SPI_CPOL) |
810 | 873 | chip->ctar_val |= SPI_CTAR_CPOL; | |
811 | if (!spi_controller_is_slave(dspi->master)) { | 874 | if (spi->mode & SPI_CPHA) |
812 | chip->ctar_val |= SPI_CTAR_LSBFE(spi->mode & | 875 | chip->ctar_val |= SPI_CTAR_CPHA; |
813 | SPI_LSB_FIRST ? 1 : 0) | 876 | |
814 | | SPI_CTAR_PCSSCK(pcssck) | 877 | if (!spi_controller_is_slave(dspi->ctlr)) { |
815 | | SPI_CTAR_CSSCK(cssck) | 878 | chip->ctar_val |= SPI_CTAR_PCSSCK(pcssck) | |
816 | | SPI_CTAR_PASC(pasc) | 879 | SPI_CTAR_CSSCK(cssck) | |
817 | | SPI_CTAR_ASC(asc) | 880 | SPI_CTAR_PASC(pasc) | |
818 | | SPI_CTAR_PBR(pbr) | 881 | SPI_CTAR_ASC(asc) | |
819 | | SPI_CTAR_BR(br); | 882 | SPI_CTAR_PBR(pbr) | |
883 | SPI_CTAR_BR(br); | ||
884 | |||
885 | if (spi->mode & SPI_LSB_FIRST) | ||
886 | chip->ctar_val |= SPI_CTAR_LSBFE; | ||
820 | } | 887 | } |
821 | 888 | ||
822 | spi_set_ctldata(spi, chip); | 889 | spi_set_ctldata(spi, chip); |
@@ -829,70 +896,11 @@ static void dspi_cleanup(struct spi_device *spi) | |||
829 | struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi); | 896 | struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi); |
830 | 897 | ||
831 | dev_dbg(&spi->dev, "spi_device %u.%u cleanup\n", | 898 | dev_dbg(&spi->dev, "spi_device %u.%u cleanup\n", |
832 | spi->master->bus_num, spi->chip_select); | 899 | spi->controller->bus_num, spi->chip_select); |
833 | 900 | ||
834 | kfree(chip); | 901 | kfree(chip); |
835 | } | 902 | } |
836 | 903 | ||
837 | static irqreturn_t dspi_interrupt(int irq, void *dev_id) | ||
838 | { | ||
839 | struct fsl_dspi *dspi = (struct fsl_dspi *)dev_id; | ||
840 | struct spi_message *msg = dspi->cur_msg; | ||
841 | enum dspi_trans_mode trans_mode; | ||
842 | u32 spi_sr, spi_tcr; | ||
843 | u16 spi_tcnt; | ||
844 | |||
845 | regmap_read(dspi->regmap, SPI_SR, &spi_sr); | ||
846 | regmap_write(dspi->regmap, SPI_SR, spi_sr); | ||
847 | |||
848 | |||
849 | if (spi_sr & (SPI_SR_EOQF | SPI_SR_TCFQF)) { | ||
850 | /* Get transfer counter (in number of SPI transfers). It was | ||
851 | * reset to 0 when transfer(s) were started. | ||
852 | */ | ||
853 | regmap_read(dspi->regmap, SPI_TCR, &spi_tcr); | ||
854 | spi_tcnt = SPI_TCR_GET_TCNT(spi_tcr); | ||
855 | /* Update total number of bytes that were transferred */ | ||
856 | msg->actual_length += spi_tcnt * dspi->bytes_per_word; | ||
857 | |||
858 | trans_mode = dspi->devtype_data->trans_mode; | ||
859 | switch (trans_mode) { | ||
860 | case DSPI_EOQ_MODE: | ||
861 | dspi_eoq_read(dspi); | ||
862 | break; | ||
863 | case DSPI_TCFQ_MODE: | ||
864 | dspi_tcfq_read(dspi); | ||
865 | break; | ||
866 | default: | ||
867 | dev_err(&dspi->pdev->dev, "unsupported trans_mode %u\n", | ||
868 | trans_mode); | ||
869 | return IRQ_HANDLED; | ||
870 | } | ||
871 | |||
872 | if (!dspi->len) { | ||
873 | dspi->waitflags = 1; | ||
874 | wake_up_interruptible(&dspi->waitq); | ||
875 | } else { | ||
876 | switch (trans_mode) { | ||
877 | case DSPI_EOQ_MODE: | ||
878 | dspi_eoq_write(dspi); | ||
879 | break; | ||
880 | case DSPI_TCFQ_MODE: | ||
881 | dspi_tcfq_write(dspi); | ||
882 | break; | ||
883 | default: | ||
884 | dev_err(&dspi->pdev->dev, | ||
885 | "unsupported trans_mode %u\n", | ||
886 | trans_mode); | ||
887 | } | ||
888 | } | ||
889 | |||
890 | return IRQ_HANDLED; | ||
891 | } | ||
892 | |||
893 | return IRQ_NONE; | ||
894 | } | ||
895 | |||
896 | static const struct of_device_id fsl_dspi_dt_ids[] = { | 904 | static const struct of_device_id fsl_dspi_dt_ids[] = { |
897 | { .compatible = "fsl,vf610-dspi", .data = &vf610_data, }, | 905 | { .compatible = "fsl,vf610-dspi", .data = &vf610_data, }, |
898 | { .compatible = "fsl,ls1021a-v1.0-dspi", .data = &ls1021a_v1_data, }, | 906 | { .compatible = "fsl,ls1021a-v1.0-dspi", .data = &ls1021a_v1_data, }, |
@@ -904,10 +912,10 @@ MODULE_DEVICE_TABLE(of, fsl_dspi_dt_ids); | |||
904 | #ifdef CONFIG_PM_SLEEP | 912 | #ifdef CONFIG_PM_SLEEP |
905 | static int dspi_suspend(struct device *dev) | 913 | static int dspi_suspend(struct device *dev) |
906 | { | 914 | { |
907 | struct spi_master *master = dev_get_drvdata(dev); | 915 | struct spi_controller *ctlr = dev_get_drvdata(dev); |
908 | struct fsl_dspi *dspi = spi_master_get_devdata(master); | 916 | struct fsl_dspi *dspi = spi_controller_get_devdata(ctlr); |
909 | 917 | ||
910 | spi_master_suspend(master); | 918 | spi_controller_suspend(ctlr); |
911 | clk_disable_unprepare(dspi->clk); | 919 | clk_disable_unprepare(dspi->clk); |
912 | 920 | ||
913 | pinctrl_pm_select_sleep_state(dev); | 921 | pinctrl_pm_select_sleep_state(dev); |
@@ -917,8 +925,8 @@ static int dspi_suspend(struct device *dev) | |||
917 | 925 | ||
918 | static int dspi_resume(struct device *dev) | 926 | static int dspi_resume(struct device *dev) |
919 | { | 927 | { |
920 | struct spi_master *master = dev_get_drvdata(dev); | 928 | struct spi_controller *ctlr = dev_get_drvdata(dev); |
921 | struct fsl_dspi *dspi = spi_master_get_devdata(master); | 929 | struct fsl_dspi *dspi = spi_controller_get_devdata(ctlr); |
922 | int ret; | 930 | int ret; |
923 | 931 | ||
924 | pinctrl_pm_select_default_state(dev); | 932 | pinctrl_pm_select_default_state(dev); |
@@ -926,7 +934,7 @@ static int dspi_resume(struct device *dev) | |||
926 | ret = clk_prepare_enable(dspi->clk); | 934 | ret = clk_prepare_enable(dspi->clk); |
927 | if (ret) | 935 | if (ret) |
928 | return ret; | 936 | return ret; |
929 | spi_master_resume(master); | 937 | spi_controller_resume(ctlr); |
930 | 938 | ||
931 | return 0; | 939 | return 0; |
932 | } | 940 | } |
@@ -941,16 +949,16 @@ static const struct regmap_range dspi_volatile_ranges[] = { | |||
941 | }; | 949 | }; |
942 | 950 | ||
943 | static const struct regmap_access_table dspi_volatile_table = { | 951 | static const struct regmap_access_table dspi_volatile_table = { |
944 | .yes_ranges = dspi_volatile_ranges, | 952 | .yes_ranges = dspi_volatile_ranges, |
945 | .n_yes_ranges = ARRAY_SIZE(dspi_volatile_ranges), | 953 | .n_yes_ranges = ARRAY_SIZE(dspi_volatile_ranges), |
946 | }; | 954 | }; |
947 | 955 | ||
948 | static const struct regmap_config dspi_regmap_config = { | 956 | static const struct regmap_config dspi_regmap_config = { |
949 | .reg_bits = 32, | 957 | .reg_bits = 32, |
950 | .val_bits = 32, | 958 | .val_bits = 32, |
951 | .reg_stride = 4, | 959 | .reg_stride = 4, |
952 | .max_register = 0x88, | 960 | .max_register = 0x88, |
953 | .volatile_table = &dspi_volatile_table, | 961 | .volatile_table = &dspi_volatile_table, |
954 | }; | 962 | }; |
955 | 963 | ||
956 | static const struct regmap_range dspi_xspi_volatile_ranges[] = { | 964 | static const struct regmap_range dspi_xspi_volatile_ranges[] = { |
@@ -961,33 +969,34 @@ static const struct regmap_range dspi_xspi_volatile_ranges[] = { | |||
961 | }; | 969 | }; |
962 | 970 | ||
963 | static const struct regmap_access_table dspi_xspi_volatile_table = { | 971 | static const struct regmap_access_table dspi_xspi_volatile_table = { |
964 | .yes_ranges = dspi_xspi_volatile_ranges, | 972 | .yes_ranges = dspi_xspi_volatile_ranges, |
965 | .n_yes_ranges = ARRAY_SIZE(dspi_xspi_volatile_ranges), | 973 | .n_yes_ranges = ARRAY_SIZE(dspi_xspi_volatile_ranges), |
966 | }; | 974 | }; |
967 | 975 | ||
968 | static const struct regmap_config dspi_xspi_regmap_config[] = { | 976 | static const struct regmap_config dspi_xspi_regmap_config[] = { |
969 | { | 977 | { |
970 | .reg_bits = 32, | 978 | .reg_bits = 32, |
971 | .val_bits = 32, | 979 | .val_bits = 32, |
972 | .reg_stride = 4, | 980 | .reg_stride = 4, |
973 | .max_register = 0x13c, | 981 | .max_register = 0x13c, |
974 | .volatile_table = &dspi_xspi_volatile_table, | 982 | .volatile_table = &dspi_xspi_volatile_table, |
975 | }, | 983 | }, |
976 | { | 984 | { |
977 | .name = "pushr", | 985 | .name = "pushr", |
978 | .reg_bits = 16, | 986 | .reg_bits = 16, |
979 | .val_bits = 16, | 987 | .val_bits = 16, |
980 | .reg_stride = 2, | 988 | .reg_stride = 2, |
981 | .max_register = 0x2, | 989 | .max_register = 0x2, |
982 | }, | 990 | }, |
983 | }; | 991 | }; |
984 | 992 | ||
985 | static void dspi_init(struct fsl_dspi *dspi) | 993 | static void dspi_init(struct fsl_dspi *dspi) |
986 | { | 994 | { |
987 | unsigned int mcr = SPI_MCR_PCSIS | | 995 | unsigned int mcr = SPI_MCR_PCSIS; |
988 | (dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0); | ||
989 | 996 | ||
990 | if (!spi_controller_is_slave(dspi->master)) | 997 | if (dspi->devtype_data->xspi_mode) |
998 | mcr |= SPI_MCR_XSPI; | ||
999 | if (!spi_controller_is_slave(dspi->ctlr)) | ||
991 | mcr |= SPI_MCR_MASTER; | 1000 | mcr |= SPI_MCR_MASTER; |
992 | 1001 | ||
993 | regmap_write(dspi->regmap, SPI_MCR, mcr); | 1002 | regmap_write(dspi->regmap, SPI_MCR, mcr); |
@@ -1000,34 +1009,33 @@ static void dspi_init(struct fsl_dspi *dspi) | |||
1000 | static int dspi_probe(struct platform_device *pdev) | 1009 | static int dspi_probe(struct platform_device *pdev) |
1001 | { | 1010 | { |
1002 | struct device_node *np = pdev->dev.of_node; | 1011 | struct device_node *np = pdev->dev.of_node; |
1003 | struct spi_master *master; | 1012 | const struct regmap_config *regmap_config; |
1013 | struct fsl_dspi_platform_data *pdata; | ||
1014 | struct spi_controller *ctlr; | ||
1015 | int ret, cs_num, bus_num; | ||
1004 | struct fsl_dspi *dspi; | 1016 | struct fsl_dspi *dspi; |
1005 | struct resource *res; | 1017 | struct resource *res; |
1006 | const struct regmap_config *regmap_config; | ||
1007 | void __iomem *base; | 1018 | void __iomem *base; |
1008 | struct fsl_dspi_platform_data *pdata; | ||
1009 | int ret = 0, cs_num, bus_num; | ||
1010 | 1019 | ||
1011 | master = spi_alloc_master(&pdev->dev, sizeof(struct fsl_dspi)); | 1020 | ctlr = spi_alloc_master(&pdev->dev, sizeof(struct fsl_dspi)); |
1012 | if (!master) | 1021 | if (!ctlr) |
1013 | return -ENOMEM; | 1022 | return -ENOMEM; |
1014 | 1023 | ||
1015 | dspi = spi_master_get_devdata(master); | 1024 | dspi = spi_controller_get_devdata(ctlr); |
1016 | dspi->pdev = pdev; | 1025 | dspi->pdev = pdev; |
1017 | dspi->master = master; | 1026 | dspi->ctlr = ctlr; |
1018 | 1027 | ||
1019 | master->transfer = NULL; | 1028 | ctlr->setup = dspi_setup; |
1020 | master->setup = dspi_setup; | 1029 | ctlr->transfer_one_message = dspi_transfer_one_message; |
1021 | master->transfer_one_message = dspi_transfer_one_message; | 1030 | ctlr->dev.of_node = pdev->dev.of_node; |
1022 | master->dev.of_node = pdev->dev.of_node; | ||
1023 | 1031 | ||
1024 | master->cleanup = dspi_cleanup; | 1032 | ctlr->cleanup = dspi_cleanup; |
1025 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST; | 1033 | ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST; |
1026 | 1034 | ||
1027 | pdata = dev_get_platdata(&pdev->dev); | 1035 | pdata = dev_get_platdata(&pdev->dev); |
1028 | if (pdata) { | 1036 | if (pdata) { |
1029 | master->num_chipselect = pdata->cs_num; | 1037 | ctlr->num_chipselect = pdata->cs_num; |
1030 | master->bus_num = pdata->bus_num; | 1038 | ctlr->bus_num = pdata->bus_num; |
1031 | 1039 | ||
1032 | dspi->devtype_data = &coldfire_data; | 1040 | dspi->devtype_data = &coldfire_data; |
1033 | } else { | 1041 | } else { |
@@ -1035,38 +1043,38 @@ static int dspi_probe(struct platform_device *pdev) | |||
1035 | ret = of_property_read_u32(np, "spi-num-chipselects", &cs_num); | 1043 | ret = of_property_read_u32(np, "spi-num-chipselects", &cs_num); |
1036 | if (ret < 0) { | 1044 | if (ret < 0) { |
1037 | dev_err(&pdev->dev, "can't get spi-num-chipselects\n"); | 1045 | dev_err(&pdev->dev, "can't get spi-num-chipselects\n"); |
1038 | goto out_master_put; | 1046 | goto out_ctlr_put; |
1039 | } | 1047 | } |
1040 | master->num_chipselect = cs_num; | 1048 | ctlr->num_chipselect = cs_num; |
1041 | 1049 | ||
1042 | ret = of_property_read_u32(np, "bus-num", &bus_num); | 1050 | ret = of_property_read_u32(np, "bus-num", &bus_num); |
1043 | if (ret < 0) { | 1051 | if (ret < 0) { |
1044 | dev_err(&pdev->dev, "can't get bus-num\n"); | 1052 | dev_err(&pdev->dev, "can't get bus-num\n"); |
1045 | goto out_master_put; | 1053 | goto out_ctlr_put; |
1046 | } | 1054 | } |
1047 | master->bus_num = bus_num; | 1055 | ctlr->bus_num = bus_num; |
1048 | 1056 | ||
1049 | if (of_property_read_bool(np, "spi-slave")) | 1057 | if (of_property_read_bool(np, "spi-slave")) |
1050 | master->slave = true; | 1058 | ctlr->slave = true; |
1051 | 1059 | ||
1052 | dspi->devtype_data = of_device_get_match_data(&pdev->dev); | 1060 | dspi->devtype_data = of_device_get_match_data(&pdev->dev); |
1053 | if (!dspi->devtype_data) { | 1061 | if (!dspi->devtype_data) { |
1054 | dev_err(&pdev->dev, "can't get devtype_data\n"); | 1062 | dev_err(&pdev->dev, "can't get devtype_data\n"); |
1055 | ret = -EFAULT; | 1063 | ret = -EFAULT; |
1056 | goto out_master_put; | 1064 | goto out_ctlr_put; |
1057 | } | 1065 | } |
1058 | } | 1066 | } |
1059 | 1067 | ||
1060 | if (dspi->devtype_data->xspi_mode) | 1068 | if (dspi->devtype_data->xspi_mode) |
1061 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); | 1069 | ctlr->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); |
1062 | else | 1070 | else |
1063 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16); | 1071 | ctlr->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16); |
1064 | 1072 | ||
1065 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1073 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1066 | base = devm_ioremap_resource(&pdev->dev, res); | 1074 | base = devm_ioremap_resource(&pdev->dev, res); |
1067 | if (IS_ERR(base)) { | 1075 | if (IS_ERR(base)) { |
1068 | ret = PTR_ERR(base); | 1076 | ret = PTR_ERR(base); |
1069 | goto out_master_put; | 1077 | goto out_ctlr_put; |
1070 | } | 1078 | } |
1071 | 1079 | ||
1072 | if (dspi->devtype_data->xspi_mode) | 1080 | if (dspi->devtype_data->xspi_mode) |
@@ -1078,7 +1086,7 @@ static int dspi_probe(struct platform_device *pdev) | |||
1078 | dev_err(&pdev->dev, "failed to init regmap: %ld\n", | 1086 | dev_err(&pdev->dev, "failed to init regmap: %ld\n", |
1079 | PTR_ERR(dspi->regmap)); | 1087 | PTR_ERR(dspi->regmap)); |
1080 | ret = PTR_ERR(dspi->regmap); | 1088 | ret = PTR_ERR(dspi->regmap); |
1081 | goto out_master_put; | 1089 | goto out_ctlr_put; |
1082 | } | 1090 | } |
1083 | 1091 | ||
1084 | if (dspi->devtype_data->xspi_mode) { | 1092 | if (dspi->devtype_data->xspi_mode) { |
@@ -1090,7 +1098,7 @@ static int dspi_probe(struct platform_device *pdev) | |||
1090 | "failed to init pushr regmap: %ld\n", | 1098 | "failed to init pushr regmap: %ld\n", |
1091 | PTR_ERR(dspi->regmap_pushr)); | 1099 | PTR_ERR(dspi->regmap_pushr)); |
1092 | ret = PTR_ERR(dspi->regmap_pushr); | 1100 | ret = PTR_ERR(dspi->regmap_pushr); |
1093 | goto out_master_put; | 1101 | goto out_ctlr_put; |
1094 | } | 1102 | } |
1095 | } | 1103 | } |
1096 | 1104 | ||
@@ -1098,18 +1106,20 @@ static int dspi_probe(struct platform_device *pdev) | |||
1098 | if (IS_ERR(dspi->clk)) { | 1106 | if (IS_ERR(dspi->clk)) { |
1099 | ret = PTR_ERR(dspi->clk); | 1107 | ret = PTR_ERR(dspi->clk); |
1100 | dev_err(&pdev->dev, "unable to get clock\n"); | 1108 | dev_err(&pdev->dev, "unable to get clock\n"); |
1101 | goto out_master_put; | 1109 | goto out_ctlr_put; |
1102 | } | 1110 | } |
1103 | ret = clk_prepare_enable(dspi->clk); | 1111 | ret = clk_prepare_enable(dspi->clk); |
1104 | if (ret) | 1112 | if (ret) |
1105 | goto out_master_put; | 1113 | goto out_ctlr_put; |
1106 | 1114 | ||
1107 | dspi_init(dspi); | 1115 | dspi_init(dspi); |
1116 | |||
1108 | dspi->irq = platform_get_irq(pdev, 0); | 1117 | dspi->irq = platform_get_irq(pdev, 0); |
1109 | if (dspi->irq < 0) { | 1118 | if (dspi->irq <= 0) { |
1110 | dev_err(&pdev->dev, "can't get platform irq\n"); | 1119 | dev_info(&pdev->dev, |
1111 | ret = dspi->irq; | 1120 | "can't get platform irq, using poll mode\n"); |
1112 | goto out_clk_put; | 1121 | dspi->irq = 0; |
1122 | goto poll_mode; | ||
1113 | } | 1123 | } |
1114 | 1124 | ||
1115 | ret = devm_request_irq(&pdev->dev, dspi->irq, dspi_interrupt, | 1125 | ret = devm_request_irq(&pdev->dev, dspi->irq, dspi_interrupt, |
@@ -1119,6 +1129,9 @@ static int dspi_probe(struct platform_device *pdev) | |||
1119 | goto out_clk_put; | 1129 | goto out_clk_put; |
1120 | } | 1130 | } |
1121 | 1131 | ||
1132 | init_waitqueue_head(&dspi->waitq); | ||
1133 | |||
1134 | poll_mode: | ||
1122 | if (dspi->devtype_data->trans_mode == DSPI_DMA_MODE) { | 1135 | if (dspi->devtype_data->trans_mode == DSPI_DMA_MODE) { |
1123 | ret = dspi_request_dma(dspi, res->start); | 1136 | ret = dspi_request_dma(dspi, res->start); |
1124 | if (ret < 0) { | 1137 | if (ret < 0) { |
@@ -1127,15 +1140,14 @@ static int dspi_probe(struct platform_device *pdev) | |||
1127 | } | 1140 | } |
1128 | } | 1141 | } |
1129 | 1142 | ||
1130 | master->max_speed_hz = | 1143 | ctlr->max_speed_hz = |
1131 | clk_get_rate(dspi->clk) / dspi->devtype_data->max_clock_factor; | 1144 | clk_get_rate(dspi->clk) / dspi->devtype_data->max_clock_factor; |
1132 | 1145 | ||
1133 | init_waitqueue_head(&dspi->waitq); | 1146 | platform_set_drvdata(pdev, ctlr); |
1134 | platform_set_drvdata(pdev, master); | ||
1135 | 1147 | ||
1136 | ret = spi_register_master(master); | 1148 | ret = spi_register_controller(ctlr); |
1137 | if (ret != 0) { | 1149 | if (ret != 0) { |
1138 | dev_err(&pdev->dev, "Problem registering DSPI master\n"); | 1150 | dev_err(&pdev->dev, "Problem registering DSPI ctlr\n"); |
1139 | goto out_clk_put; | 1151 | goto out_clk_put; |
1140 | } | 1152 | } |
1141 | 1153 | ||
@@ -1143,32 +1155,32 @@ static int dspi_probe(struct platform_device *pdev) | |||
1143 | 1155 | ||
1144 | out_clk_put: | 1156 | out_clk_put: |
1145 | clk_disable_unprepare(dspi->clk); | 1157 | clk_disable_unprepare(dspi->clk); |
1146 | out_master_put: | 1158 | out_ctlr_put: |
1147 | spi_master_put(master); | 1159 | spi_controller_put(ctlr); |
1148 | 1160 | ||
1149 | return ret; | 1161 | return ret; |
1150 | } | 1162 | } |
1151 | 1163 | ||
1152 | static int dspi_remove(struct platform_device *pdev) | 1164 | static int dspi_remove(struct platform_device *pdev) |
1153 | { | 1165 | { |
1154 | struct spi_master *master = platform_get_drvdata(pdev); | 1166 | struct spi_controller *ctlr = platform_get_drvdata(pdev); |
1155 | struct fsl_dspi *dspi = spi_master_get_devdata(master); | 1167 | struct fsl_dspi *dspi = spi_controller_get_devdata(ctlr); |
1156 | 1168 | ||
1157 | /* Disconnect from the SPI framework */ | 1169 | /* Disconnect from the SPI framework */ |
1158 | dspi_release_dma(dspi); | 1170 | dspi_release_dma(dspi); |
1159 | clk_disable_unprepare(dspi->clk); | 1171 | clk_disable_unprepare(dspi->clk); |
1160 | spi_unregister_master(dspi->master); | 1172 | spi_unregister_controller(dspi->ctlr); |
1161 | 1173 | ||
1162 | return 0; | 1174 | return 0; |
1163 | } | 1175 | } |
1164 | 1176 | ||
1165 | static struct platform_driver fsl_dspi_driver = { | 1177 | static struct platform_driver fsl_dspi_driver = { |
1166 | .driver.name = DRIVER_NAME, | 1178 | .driver.name = DRIVER_NAME, |
1167 | .driver.of_match_table = fsl_dspi_dt_ids, | 1179 | .driver.of_match_table = fsl_dspi_dt_ids, |
1168 | .driver.owner = THIS_MODULE, | 1180 | .driver.owner = THIS_MODULE, |
1169 | .driver.pm = &dspi_pm, | 1181 | .driver.pm = &dspi_pm, |
1170 | .probe = dspi_probe, | 1182 | .probe = dspi_probe, |
1171 | .remove = dspi_remove, | 1183 | .remove = dspi_remove, |
1172 | }; | 1184 | }; |
1173 | module_platform_driver(fsl_dspi_driver); | 1185 | module_platform_driver(fsl_dspi_driver); |
1174 | 1186 | ||