aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorBryan Wu <bryan.wu@analog.com>2007-12-05 02:45:18 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-12-05 12:21:19 -0500
commitbb90eb00b6c28c8be5a69c6b58d5a6924f6f2ad7 (patch)
tree946d2f6eb925a8d614e049a6e5157a543a4b0081 /drivers
parent3f479a65b3f49ee4f058a965e6e33d97ee467b68 (diff)
spi: spi_bfin: handle multiple spi_masters
Move global SPI regs_base and dma_ch to struct driver_data. Test on BF54x SPI Flash with 2 spi_master devices enabled. Signed-off-by: Bryan Wu <bryan.wu@analog.com> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/spi/spi_bfin5xx.c371
1 files changed, 189 insertions, 182 deletions
diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c
index c7cfd95fa8ec..c4c4905e0aa1 100644
--- a/drivers/spi/spi_bfin5xx.c
+++ b/drivers/spi/spi_bfin5xx.c
@@ -61,31 +61,14 @@ MODULE_AUTHOR(DRV_AUTHOR);
61MODULE_DESCRIPTION(DRV_DESC); 61MODULE_DESCRIPTION(DRV_DESC);
62MODULE_LICENSE("GPL"); 62MODULE_LICENSE("GPL");
63 63
64#define IS_DMA_ALIGNED(x) (((u32)(x)&0x07)==0) 64#define IS_DMA_ALIGNED(x) (((u32)(x)&0x07) == 0)
65 65
66static u32 spi_dma_ch; 66#define START_STATE ((void *)0)
67static u32 spi_regs_base; 67#define RUNNING_STATE ((void *)1)
68 68#define DONE_STATE ((void *)2)
69#define DEFINE_SPI_REG(reg, off) \ 69#define ERROR_STATE ((void *)-1)
70static inline u16 read_##reg(void) \ 70#define QUEUE_RUNNING 0
71 { return bfin_read16(spi_regs_base + off); } \ 71#define QUEUE_STOPPED 1
72static inline void write_##reg(u16 v) \
73 {bfin_write16(spi_regs_base + off, v); }
74
75DEFINE_SPI_REG(CTRL, 0x00)
76DEFINE_SPI_REG(FLAG, 0x04)
77DEFINE_SPI_REG(STAT, 0x08)
78DEFINE_SPI_REG(TDBR, 0x0C)
79DEFINE_SPI_REG(RDBR, 0x10)
80DEFINE_SPI_REG(BAUD, 0x14)
81DEFINE_SPI_REG(SHAW, 0x18)
82#define START_STATE ((void*)0)
83#define RUNNING_STATE ((void*)1)
84#define DONE_STATE ((void*)2)
85#define ERROR_STATE ((void*)-1)
86#define QUEUE_RUNNING 0
87#define QUEUE_STOPPED 1
88int dma_requested;
89 72
90struct driver_data { 73struct driver_data {
91 /* Driver model hookup */ 74 /* Driver model hookup */
@@ -94,6 +77,9 @@ struct driver_data {
94 /* SPI framework hookup */ 77 /* SPI framework hookup */
95 struct spi_master *master; 78 struct spi_master *master;
96 79
80 /* Regs base of SPI controller */
81 u32 regs_base;
82
97 /* BFIN hookup */ 83 /* BFIN hookup */
98 struct bfin5xx_spi_master *master_info; 84 struct bfin5xx_spi_master *master_info;
99 85
@@ -118,9 +104,14 @@ struct driver_data {
118 void *tx_end; 104 void *tx_end;
119 void *rx; 105 void *rx;
120 void *rx_end; 106 void *rx_end;
107
108 /* DMA stuffs */
109 int dma_channel;
121 int dma_mapped; 110 int dma_mapped;
111 int dma_requested;
122 dma_addr_t rx_dma; 112 dma_addr_t rx_dma;
123 dma_addr_t tx_dma; 113 dma_addr_t tx_dma;
114
124 size_t rx_map_len; 115 size_t rx_map_len;
125 size_t tx_map_len; 116 size_t tx_map_len;
126 u8 n_bytes; 117 u8 n_bytes;
@@ -147,20 +138,34 @@ struct chip_data {
147 void (*duplex) (struct driver_data *); 138 void (*duplex) (struct driver_data *);
148}; 139};
149 140
141#define DEFINE_SPI_REG(reg, off) \
142static inline u16 read_##reg(struct driver_data *drv_data) \
143 { return bfin_read16(drv_data->regs_base + off); } \
144static inline void write_##reg(struct driver_data *drv_data, u16 v) \
145 { bfin_write16(drv_data->regs_base + off, v); }
146
147DEFINE_SPI_REG(CTRL, 0x00)
148DEFINE_SPI_REG(FLAG, 0x04)
149DEFINE_SPI_REG(STAT, 0x08)
150DEFINE_SPI_REG(TDBR, 0x0C)
151DEFINE_SPI_REG(RDBR, 0x10)
152DEFINE_SPI_REG(BAUD, 0x14)
153DEFINE_SPI_REG(SHAW, 0x18)
154
150static void bfin_spi_enable(struct driver_data *drv_data) 155static void bfin_spi_enable(struct driver_data *drv_data)
151{ 156{
152 u16 cr; 157 u16 cr;
153 158
154 cr = read_CTRL(); 159 cr = read_CTRL(drv_data);
155 write_CTRL(cr | BIT_CTL_ENABLE); 160 write_CTRL(drv_data, (cr | BIT_CTL_ENABLE));
156} 161}
157 162
158static void bfin_spi_disable(struct driver_data *drv_data) 163static void bfin_spi_disable(struct driver_data *drv_data)
159{ 164{
160 u16 cr; 165 u16 cr;
161 166
162 cr = read_CTRL(); 167 cr = read_CTRL(drv_data);
163 write_CTRL(cr & (~BIT_CTL_ENABLE)); 168 write_CTRL(drv_data, (cr & (~BIT_CTL_ENABLE)));
164} 169}
165 170
166/* Caculate the SPI_BAUD register value based on input HZ */ 171/* Caculate the SPI_BAUD register value based on input HZ */
@@ -180,32 +185,32 @@ static int flush(struct driver_data *drv_data)
180 unsigned long limit = loops_per_jiffy << 1; 185 unsigned long limit = loops_per_jiffy << 1;
181 186
182 /* wait for stop and clear stat */ 187 /* wait for stop and clear stat */
183 while (!(read_STAT() & BIT_STAT_SPIF) && limit--) 188 while (!(read_STAT(drv_data) & BIT_STAT_SPIF) && limit--)
184 continue; 189 continue;
185 190
186 write_STAT(BIT_STAT_CLR); 191 write_STAT(drv_data, BIT_STAT_CLR);
187 192
188 return limit; 193 return limit;
189} 194}
190 195
191/* Chip select operation functions for cs_change flag */ 196/* Chip select operation functions for cs_change flag */
192static void cs_active(struct chip_data *chip) 197static void cs_active(struct driver_data *drv_data, struct chip_data *chip)
193{ 198{
194 u16 flag = read_FLAG(); 199 u16 flag = read_FLAG(drv_data);
195 200
196 flag |= chip->flag; 201 flag |= chip->flag;
197 flag &= ~(chip->flag << 8); 202 flag &= ~(chip->flag << 8);
198 203
199 write_FLAG(flag); 204 write_FLAG(drv_data, flag);
200} 205}
201 206
202static void cs_deactive(struct chip_data *chip) 207static void cs_deactive(struct driver_data *drv_data, struct chip_data *chip)
203{ 208{
204 u16 flag = read_FLAG(); 209 u16 flag = read_FLAG(drv_data);
205 210
206 flag |= (chip->flag << 8); 211 flag |= (chip->flag << 8);
207 212
208 write_FLAG(flag); 213 write_FLAG(drv_data, flag);
209} 214}
210 215
211#define MAX_SPI_SSEL 7 216#define MAX_SPI_SSEL 7
@@ -217,16 +222,16 @@ static int restore_state(struct driver_data *drv_data)
217 int ret = 0; 222 int ret = 0;
218 223
219 /* Clear status and disable clock */ 224 /* Clear status and disable clock */
220 write_STAT(BIT_STAT_CLR); 225 write_STAT(drv_data, BIT_STAT_CLR);
221 bfin_spi_disable(drv_data); 226 bfin_spi_disable(drv_data);
222 dev_dbg(&drv_data->pdev->dev, "restoring spi ctl state\n"); 227 dev_dbg(&drv_data->pdev->dev, "restoring spi ctl state\n");
223 228
224 /* Load the registers */ 229 /* Load the registers */
225 cs_deactive(chip); 230 cs_deactive(drv_data, chip);
226 write_BAUD(chip->baud); 231 write_BAUD(drv_data, chip->baud);
227 chip->ctl_reg &= (~BIT_CTL_TIMOD); 232 chip->ctl_reg &= (~BIT_CTL_TIMOD);
228 chip->ctl_reg |= (chip->width << 8); 233 chip->ctl_reg |= (chip->width << 8);
229 write_CTRL(chip->ctl_reg); 234 write_CTRL(drv_data, chip->ctl_reg);
230 235
231 bfin_spi_enable(drv_data); 236 bfin_spi_enable(drv_data);
232 237
@@ -239,10 +244,10 @@ static int restore_state(struct driver_data *drv_data)
239} 244}
240 245
241/* used to kick off transfer in rx mode */ 246/* used to kick off transfer in rx mode */
242static unsigned short dummy_read(void) 247static unsigned short dummy_read(struct driver_data *drv_data)
243{ 248{
244 unsigned short tmp; 249 unsigned short tmp;
245 tmp = read_RDBR(); 250 tmp = read_RDBR(drv_data);
246 return tmp; 251 return tmp;
247} 252}
248 253
@@ -251,8 +256,8 @@ static void null_writer(struct driver_data *drv_data)
251 u8 n_bytes = drv_data->n_bytes; 256 u8 n_bytes = drv_data->n_bytes;
252 257
253 while (drv_data->tx < drv_data->tx_end) { 258 while (drv_data->tx < drv_data->tx_end) {
254 write_TDBR(0); 259 write_TDBR(drv_data, 0);
255 while ((read_STAT() & BIT_STAT_TXS)) 260 while ((read_STAT(drv_data) & BIT_STAT_TXS))
256 continue; 261 continue;
257 drv_data->tx += n_bytes; 262 drv_data->tx += n_bytes;
258 } 263 }
@@ -261,12 +266,12 @@ static void null_writer(struct driver_data *drv_data)
261static void null_reader(struct driver_data *drv_data) 266static void null_reader(struct driver_data *drv_data)
262{ 267{
263 u8 n_bytes = drv_data->n_bytes; 268 u8 n_bytes = drv_data->n_bytes;
264 dummy_read(); 269 dummy_read(drv_data);
265 270
266 while (drv_data->rx < drv_data->rx_end) { 271 while (drv_data->rx < drv_data->rx_end) {
267 while (!(read_STAT() & BIT_STAT_RXS)) 272 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
268 continue; 273 continue;
269 dummy_read(); 274 dummy_read(drv_data);
270 drv_data->rx += n_bytes; 275 drv_data->rx += n_bytes;
271 } 276 }
272} 277}
@@ -274,15 +279,15 @@ static void null_reader(struct driver_data *drv_data)
274static void u8_writer(struct driver_data *drv_data) 279static void u8_writer(struct driver_data *drv_data)
275{ 280{
276 dev_dbg(&drv_data->pdev->dev, 281 dev_dbg(&drv_data->pdev->dev,
277 "cr8-s is 0x%x\n", read_STAT()); 282 "cr8-s is 0x%x\n", read_STAT(drv_data));
278 283
279 /* poll for SPI completion before start */ 284 /* poll for SPI completion before start */
280 while (!(read_STAT() & BIT_STAT_SPIF)) 285 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
281 continue; 286 continue;
282 287
283 while (drv_data->tx < drv_data->tx_end) { 288 while (drv_data->tx < drv_data->tx_end) {
284 write_TDBR(*(u8 *) (drv_data->tx)); 289 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
285 while (read_STAT() & BIT_STAT_TXS) 290 while (read_STAT(drv_data) & BIT_STAT_TXS)
286 continue; 291 continue;
287 ++drv_data->tx; 292 ++drv_data->tx;
288 } 293 }
@@ -293,16 +298,16 @@ static void u8_cs_chg_writer(struct driver_data *drv_data)
293 struct chip_data *chip = drv_data->cur_chip; 298 struct chip_data *chip = drv_data->cur_chip;
294 299
295 /* poll for SPI completion before start */ 300 /* poll for SPI completion before start */
296 while (!(read_STAT() & BIT_STAT_SPIF)) 301 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
297 continue; 302 continue;
298 303
299 while (drv_data->tx < drv_data->tx_end) { 304 while (drv_data->tx < drv_data->tx_end) {
300 cs_active(chip); 305 cs_active(drv_data, chip);
301 306
302 write_TDBR(*(u8 *) (drv_data->tx)); 307 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
303 while (read_STAT() & BIT_STAT_TXS) 308 while (read_STAT(drv_data) & BIT_STAT_TXS)
304 continue; 309 continue;
305 cs_deactive(chip); 310 cs_deactive(drv_data, chip);
306 311
307 if (chip->cs_chg_udelay) 312 if (chip->cs_chg_udelay)
308 udelay(chip->cs_chg_udelay); 313 udelay(chip->cs_chg_udelay);
@@ -313,27 +318,27 @@ static void u8_cs_chg_writer(struct driver_data *drv_data)
313static void u8_reader(struct driver_data *drv_data) 318static void u8_reader(struct driver_data *drv_data)
314{ 319{
315 dev_dbg(&drv_data->pdev->dev, 320 dev_dbg(&drv_data->pdev->dev,
316 "cr-8 is 0x%x\n", read_STAT()); 321 "cr-8 is 0x%x\n", read_STAT(drv_data));
317 322
318 /* poll for SPI completion before start */ 323 /* poll for SPI completion before start */
319 while (!(read_STAT() & BIT_STAT_SPIF)) 324 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
320 continue; 325 continue;
321 326
322 /* clear TDBR buffer before read(else it will be shifted out) */ 327 /* clear TDBR buffer before read(else it will be shifted out) */
323 write_TDBR(0xFFFF); 328 write_TDBR(drv_data, 0xFFFF);
324 329
325 dummy_read(); 330 dummy_read(drv_data);
326 331
327 while (drv_data->rx < drv_data->rx_end - 1) { 332 while (drv_data->rx < drv_data->rx_end - 1) {
328 while (!(read_STAT() & BIT_STAT_RXS)) 333 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
329 continue; 334 continue;
330 *(u8 *) (drv_data->rx) = read_RDBR(); 335 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
331 ++drv_data->rx; 336 ++drv_data->rx;
332 } 337 }
333 338
334 while (!(read_STAT() & BIT_STAT_RXS)) 339 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
335 continue; 340 continue;
336 *(u8 *) (drv_data->rx) = read_SHAW(); 341 *(u8 *) (drv_data->rx) = read_SHAW(drv_data);
337 ++drv_data->rx; 342 ++drv_data->rx;
338} 343}
339 344
@@ -342,49 +347,49 @@ static void u8_cs_chg_reader(struct driver_data *drv_data)
342 struct chip_data *chip = drv_data->cur_chip; 347 struct chip_data *chip = drv_data->cur_chip;
343 348
344 /* poll for SPI completion before start */ 349 /* poll for SPI completion before start */
345 while (!(read_STAT() & BIT_STAT_SPIF)) 350 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
346 continue; 351 continue;
347 352
348 /* clear TDBR buffer before read(else it will be shifted out) */ 353 /* clear TDBR buffer before read(else it will be shifted out) */
349 write_TDBR(0xFFFF); 354 write_TDBR(drv_data, 0xFFFF);
350 355
351 cs_active(chip); 356 cs_active(drv_data, chip);
352 dummy_read(); 357 dummy_read(drv_data);
353 358
354 while (drv_data->rx < drv_data->rx_end - 1) { 359 while (drv_data->rx < drv_data->rx_end - 1) {
355 cs_deactive(chip); 360 cs_deactive(drv_data, chip);
356 361
357 if (chip->cs_chg_udelay) 362 if (chip->cs_chg_udelay)
358 udelay(chip->cs_chg_udelay); 363 udelay(chip->cs_chg_udelay);
359 364
360 while (!(read_STAT() & BIT_STAT_RXS)) 365 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
361 continue; 366 continue;
362 cs_active(chip); 367 cs_active(drv_data, chip);
363 *(u8 *) (drv_data->rx) = read_RDBR(); 368 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
364 ++drv_data->rx; 369 ++drv_data->rx;
365 } 370 }
366 cs_deactive(chip); 371 cs_deactive(drv_data, chip);
367 372
368 while (!(read_STAT() & BIT_STAT_RXS)) 373 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
369 continue; 374 continue;
370 *(u8 *) (drv_data->rx) = read_SHAW(); 375 *(u8 *) (drv_data->rx) = read_SHAW(drv_data);
371 ++drv_data->rx; 376 ++drv_data->rx;
372} 377}
373 378
374static void u8_duplex(struct driver_data *drv_data) 379static void u8_duplex(struct driver_data *drv_data)
375{ 380{
376 /* poll for SPI completion before start */ 381 /* poll for SPI completion before start */
377 while (!(read_STAT() & BIT_STAT_SPIF)) 382 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
378 continue; 383 continue;
379 384
380 /* in duplex mode, clk is triggered by writing of TDBR */ 385 /* in duplex mode, clk is triggered by writing of TDBR */
381 while (drv_data->rx < drv_data->rx_end) { 386 while (drv_data->rx < drv_data->rx_end) {
382 write_TDBR(*(u8 *) (drv_data->tx)); 387 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
383 while (read_STAT() & BIT_STAT_TXS) 388 while (read_STAT(drv_data) & BIT_STAT_TXS)
384 continue; 389 continue;
385 while (!(read_STAT() & BIT_STAT_RXS)) 390 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
386 continue; 391 continue;
387 *(u8 *) (drv_data->rx) = read_RDBR(); 392 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
388 ++drv_data->rx; 393 ++drv_data->rx;
389 ++drv_data->tx; 394 ++drv_data->tx;
390 } 395 }
@@ -395,19 +400,19 @@ static void u8_cs_chg_duplex(struct driver_data *drv_data)
395 struct chip_data *chip = drv_data->cur_chip; 400 struct chip_data *chip = drv_data->cur_chip;
396 401
397 /* poll for SPI completion before start */ 402 /* poll for SPI completion before start */
398 while (!(read_STAT() & BIT_STAT_SPIF)) 403 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
399 continue; 404 continue;
400 405
401 while (drv_data->rx < drv_data->rx_end) { 406 while (drv_data->rx < drv_data->rx_end) {
402 cs_active(chip); 407 cs_active(drv_data, chip);
403 408
404 write_TDBR(*(u8 *) (drv_data->tx)); 409 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
405 while (read_STAT() & BIT_STAT_TXS) 410 while (read_STAT(drv_data) & BIT_STAT_TXS)
406 continue; 411 continue;
407 while (!(read_STAT() & BIT_STAT_RXS)) 412 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
408 continue; 413 continue;
409 *(u8 *) (drv_data->rx) = read_RDBR(); 414 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
410 cs_deactive(chip); 415 cs_deactive(drv_data, chip);
411 416
412 if (chip->cs_chg_udelay) 417 if (chip->cs_chg_udelay)
413 udelay(chip->cs_chg_udelay); 418 udelay(chip->cs_chg_udelay);
@@ -419,15 +424,15 @@ static void u8_cs_chg_duplex(struct driver_data *drv_data)
419static void u16_writer(struct driver_data *drv_data) 424static void u16_writer(struct driver_data *drv_data)
420{ 425{
421 dev_dbg(&drv_data->pdev->dev, 426 dev_dbg(&drv_data->pdev->dev,
422 "cr16 is 0x%x\n", read_STAT()); 427 "cr16 is 0x%x\n", read_STAT(drv_data));
423 428
424 /* poll for SPI completion before start */ 429 /* poll for SPI completion before start */
425 while (!(read_STAT() & BIT_STAT_SPIF)) 430 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
426 continue; 431 continue;
427 432
428 while (drv_data->tx < drv_data->tx_end) { 433 while (drv_data->tx < drv_data->tx_end) {
429 write_TDBR(*(u16 *) (drv_data->tx)); 434 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
430 while ((read_STAT() & BIT_STAT_TXS)) 435 while ((read_STAT(drv_data) & BIT_STAT_TXS))
431 continue; 436 continue;
432 drv_data->tx += 2; 437 drv_data->tx += 2;
433 } 438 }
@@ -438,16 +443,16 @@ static void u16_cs_chg_writer(struct driver_data *drv_data)
438 struct chip_data *chip = drv_data->cur_chip; 443 struct chip_data *chip = drv_data->cur_chip;
439 444
440 /* poll for SPI completion before start */ 445 /* poll for SPI completion before start */
441 while (!(read_STAT() & BIT_STAT_SPIF)) 446 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
442 continue; 447 continue;
443 448
444 while (drv_data->tx < drv_data->tx_end) { 449 while (drv_data->tx < drv_data->tx_end) {
445 cs_active(chip); 450 cs_active(drv_data, chip);
446 451
447 write_TDBR(*(u16 *) (drv_data->tx)); 452 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
448 while ((read_STAT() & BIT_STAT_TXS)) 453 while ((read_STAT(drv_data) & BIT_STAT_TXS))
449 continue; 454 continue;
450 cs_deactive(chip); 455 cs_deactive(drv_data, chip);
451 456
452 if (chip->cs_chg_udelay) 457 if (chip->cs_chg_udelay)
453 udelay(chip->cs_chg_udelay); 458 udelay(chip->cs_chg_udelay);
@@ -458,27 +463,27 @@ static void u16_cs_chg_writer(struct driver_data *drv_data)
458static void u16_reader(struct driver_data *drv_data) 463static void u16_reader(struct driver_data *drv_data)
459{ 464{
460 dev_dbg(&drv_data->pdev->dev, 465 dev_dbg(&drv_data->pdev->dev,
461 "cr-16 is 0x%x\n", read_STAT()); 466 "cr-16 is 0x%x\n", read_STAT(drv_data));
462 467
463 /* poll for SPI completion before start */ 468 /* poll for SPI completion before start */
464 while (!(read_STAT() & BIT_STAT_SPIF)) 469 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
465 continue; 470 continue;
466 471
467 /* clear TDBR buffer before read(else it will be shifted out) */ 472 /* clear TDBR buffer before read(else it will be shifted out) */
468 write_TDBR(0xFFFF); 473 write_TDBR(drv_data, 0xFFFF);
469 474
470 dummy_read(); 475 dummy_read(drv_data);
471 476
472 while (drv_data->rx < (drv_data->rx_end - 2)) { 477 while (drv_data->rx < (drv_data->rx_end - 2)) {
473 while (!(read_STAT() & BIT_STAT_RXS)) 478 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
474 continue; 479 continue;
475 *(u16 *) (drv_data->rx) = read_RDBR(); 480 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
476 drv_data->rx += 2; 481 drv_data->rx += 2;
477 } 482 }
478 483
479 while (!(read_STAT() & BIT_STAT_RXS)) 484 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
480 continue; 485 continue;
481 *(u16 *) (drv_data->rx) = read_SHAW(); 486 *(u16 *) (drv_data->rx) = read_SHAW(drv_data);
482 drv_data->rx += 2; 487 drv_data->rx += 2;
483} 488}
484 489
@@ -487,49 +492,49 @@ static void u16_cs_chg_reader(struct driver_data *drv_data)
487 struct chip_data *chip = drv_data->cur_chip; 492 struct chip_data *chip = drv_data->cur_chip;
488 493
489 /* poll for SPI completion before start */ 494 /* poll for SPI completion before start */
490 while (!(read_STAT() & BIT_STAT_SPIF)) 495 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
491 continue; 496 continue;
492 497
493 /* clear TDBR buffer before read(else it will be shifted out) */ 498 /* clear TDBR buffer before read(else it will be shifted out) */
494 write_TDBR(0xFFFF); 499 write_TDBR(drv_data, 0xFFFF);
495 500
496 cs_active(chip); 501 cs_active(drv_data, chip);
497 dummy_read(); 502 dummy_read(drv_data);
498 503
499 while (drv_data->rx < drv_data->rx_end) { 504 while (drv_data->rx < drv_data->rx_end) {
500 cs_deactive(chip); 505 cs_deactive(drv_data, chip);
501 506
502 if (chip->cs_chg_udelay) 507 if (chip->cs_chg_udelay)
503 udelay(chip->cs_chg_udelay); 508 udelay(chip->cs_chg_udelay);
504 509
505 while (!(read_STAT() & BIT_STAT_RXS)) 510 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
506 continue; 511 continue;
507 cs_active(chip); 512 cs_active(drv_data, chip);
508 *(u16 *) (drv_data->rx) = read_RDBR(); 513 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
509 drv_data->rx += 2; 514 drv_data->rx += 2;
510 } 515 }
511 cs_deactive(chip); 516 cs_deactive(drv_data, chip);
512 517
513 while (!(read_STAT() & BIT_STAT_RXS)) 518 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
514 continue; 519 continue;
515 *(u16 *) (drv_data->rx) = read_SHAW(); 520 *(u16 *) (drv_data->rx) = read_SHAW(drv_data);
516 drv_data->rx += 2; 521 drv_data->rx += 2;
517} 522}
518 523
519static void u16_duplex(struct driver_data *drv_data) 524static void u16_duplex(struct driver_data *drv_data)
520{ 525{
521 /* poll for SPI completion before start */ 526 /* poll for SPI completion before start */
522 while (!(read_STAT() & BIT_STAT_SPIF)) 527 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
523 continue; 528 continue;
524 529
525 /* in duplex mode, clk is triggered by writing of TDBR */ 530 /* in duplex mode, clk is triggered by writing of TDBR */
526 while (drv_data->tx < drv_data->tx_end) { 531 while (drv_data->tx < drv_data->tx_end) {
527 write_TDBR(*(u16 *) (drv_data->tx)); 532 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
528 while (read_STAT() & BIT_STAT_TXS) 533 while (read_STAT(drv_data) & BIT_STAT_TXS)
529 continue; 534 continue;
530 while (!(read_STAT() & BIT_STAT_RXS)) 535 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
531 continue; 536 continue;
532 *(u16 *) (drv_data->rx) = read_RDBR(); 537 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
533 drv_data->rx += 2; 538 drv_data->rx += 2;
534 drv_data->tx += 2; 539 drv_data->tx += 2;
535 } 540 }
@@ -540,19 +545,19 @@ static void u16_cs_chg_duplex(struct driver_data *drv_data)
540 struct chip_data *chip = drv_data->cur_chip; 545 struct chip_data *chip = drv_data->cur_chip;
541 546
542 /* poll for SPI completion before start */ 547 /* poll for SPI completion before start */
543 while (!(read_STAT() & BIT_STAT_SPIF)) 548 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
544 continue; 549 continue;
545 550
546 while (drv_data->tx < drv_data->tx_end) { 551 while (drv_data->tx < drv_data->tx_end) {
547 cs_active(chip); 552 cs_active(drv_data, chip);
548 553
549 write_TDBR(*(u16 *) (drv_data->tx)); 554 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
550 while (read_STAT() & BIT_STAT_TXS) 555 while (read_STAT(drv_data) & BIT_STAT_TXS)
551 continue; 556 continue;
552 while (!(read_STAT() & BIT_STAT_RXS)) 557 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
553 continue; 558 continue;
554 *(u16 *) (drv_data->rx) = read_RDBR(); 559 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
555 cs_deactive(chip); 560 cs_deactive(drv_data, chip);
556 561
557 if (chip->cs_chg_udelay) 562 if (chip->cs_chg_udelay)
558 udelay(chip->cs_chg_udelay); 563 udelay(chip->cs_chg_udelay);
@@ -603,12 +608,12 @@ static void giveback(struct driver_data *drv_data)
603 608
604 /* disable chip select signal. And not stop spi in autobuffer mode */ 609 /* disable chip select signal. And not stop spi in autobuffer mode */
605 if (drv_data->tx_dma != 0xFFFF) { 610 if (drv_data->tx_dma != 0xFFFF) {
606 cs_deactive(chip); 611 cs_deactive(drv_data, chip);
607 bfin_spi_disable(drv_data); 612 bfin_spi_disable(drv_data);
608 } 613 }
609 614
610 if (!drv_data->cs_change) 615 if (!drv_data->cs_change)
611 cs_deactive(chip); 616 cs_deactive(drv_data, chip);
612 617
613 if (msg->complete) 618 if (msg->complete)
614 msg->complete(msg->context); 619 msg->complete(msg->context);
@@ -617,14 +622,14 @@ static void giveback(struct driver_data *drv_data)
617static irqreturn_t dma_irq_handler(int irq, void *dev_id) 622static irqreturn_t dma_irq_handler(int irq, void *dev_id)
618{ 623{
619 struct driver_data *drv_data = (struct driver_data *)dev_id; 624 struct driver_data *drv_data = (struct driver_data *)dev_id;
620 struct spi_message *msg = drv_data->cur_msg;
621 struct chip_data *chip = drv_data->cur_chip; 625 struct chip_data *chip = drv_data->cur_chip;
626 struct spi_message *msg = drv_data->cur_msg;
622 627
623 dev_dbg(&drv_data->pdev->dev, "in dma_irq_handler\n"); 628 dev_dbg(&drv_data->pdev->dev, "in dma_irq_handler\n");
624 clear_dma_irqstat(spi_dma_ch); 629 clear_dma_irqstat(drv_data->dma_channel);
625 630
626 /* Wait for DMA to complete */ 631 /* Wait for DMA to complete */
627 while (get_dma_curr_irqstat(spi_dma_ch) & DMA_RUN) 632 while (get_dma_curr_irqstat(drv_data->dma_channel) & DMA_RUN)
628 continue; 633 continue;
629 634
630 /* 635 /*
@@ -634,18 +639,18 @@ static irqreturn_t dma_irq_handler(int irq, void *dev_id)
634 * register until it goes low for 2 successive reads 639 * register until it goes low for 2 successive reads
635 */ 640 */
636 if (drv_data->tx != NULL) { 641 if (drv_data->tx != NULL) {
637 while ((read_STAT() & TXS) || 642 while ((read_STAT(drv_data) & TXS) ||
638 (read_STAT() & TXS)) 643 (read_STAT(drv_data) & TXS))
639 continue; 644 continue;
640 } 645 }
641 646
642 while (!(read_STAT() & SPIF)) 647 while (!(read_STAT(drv_data) & SPIF))
643 continue; 648 continue;
644 649
645 msg->actual_length += drv_data->len_in_bytes; 650 msg->actual_length += drv_data->len_in_bytes;
646 651
647 if (drv_data->cs_change) 652 if (drv_data->cs_change)
648 cs_deactive(chip); 653 cs_deactive(drv_data, chip);
649 654
650 /* Move to next transfer */ 655 /* Move to next transfer */
651 msg->state = next_transfer(drv_data); 656 msg->state = next_transfer(drv_data);
@@ -656,8 +661,8 @@ static irqreturn_t dma_irq_handler(int irq, void *dev_id)
656 /* free the irq handler before next transfer */ 661 /* free the irq handler before next transfer */
657 dev_dbg(&drv_data->pdev->dev, 662 dev_dbg(&drv_data->pdev->dev,
658 "disable dma channel irq%d\n", 663 "disable dma channel irq%d\n",
659 spi_dma_ch); 664 drv_data->dma_channel);
660 dma_disable_irq(spi_dma_ch); 665 dma_disable_irq(drv_data->dma_channel);
661 666
662 return IRQ_HANDLED; 667 return IRQ_HANDLED;
663} 668}
@@ -751,9 +756,9 @@ static void pump_transfers(unsigned long data)
751 message->state = RUNNING_STATE; 756 message->state = RUNNING_STATE;
752 dma_config = 0; 757 dma_config = 0;
753 758
754 write_STAT(BIT_STAT_CLR); 759 write_STAT(drv_data, BIT_STAT_CLR);
755 cr = (read_CTRL() & (~BIT_CTL_TIMOD)); 760 cr = (read_CTRL(drv_data) & (~BIT_CTL_TIMOD));
756 cs_active(chip); 761 cs_active(drv_data, chip);
757 762
758 dev_dbg(&drv_data->pdev->dev, 763 dev_dbg(&drv_data->pdev->dev,
759 "now pumping a transfer: width is %d, len is %d\n", 764 "now pumping a transfer: width is %d, len is %d\n",
@@ -766,23 +771,23 @@ static void pump_transfers(unsigned long data)
766 */ 771 */
767 if (drv_data->cur_chip->enable_dma && drv_data->len > 6) { 772 if (drv_data->cur_chip->enable_dma && drv_data->len > 6) {
768 773
769 disable_dma(spi_dma_ch); 774 disable_dma(drv_data->dma_channel);
770 clear_dma_irqstat(spi_dma_ch); 775 clear_dma_irqstat(drv_data->dma_channel);
771 776
772 /* config dma channel */ 777 /* config dma channel */
773 dev_dbg(&drv_data->pdev->dev, "doing dma transfer\n"); 778 dev_dbg(&drv_data->pdev->dev, "doing dma transfer\n");
774 if (width == CFG_SPI_WORDSIZE16) { 779 if (width == CFG_SPI_WORDSIZE16) {
775 set_dma_x_count(spi_dma_ch, drv_data->len); 780 set_dma_x_count(drv_data->dma_channel, drv_data->len);
776 set_dma_x_modify(spi_dma_ch, 2); 781 set_dma_x_modify(drv_data->dma_channel, 2);
777 dma_width = WDSIZE_16; 782 dma_width = WDSIZE_16;
778 } else { 783 } else {
779 set_dma_x_count(spi_dma_ch, drv_data->len); 784 set_dma_x_count(drv_data->dma_channel, drv_data->len);
780 set_dma_x_modify(spi_dma_ch, 1); 785 set_dma_x_modify(drv_data->dma_channel, 1);
781 dma_width = WDSIZE_8; 786 dma_width = WDSIZE_8;
782 } 787 }
783 788
784 /* poll for SPI completion before start */ 789 /* poll for SPI completion before start */
785 while (!(read_STAT() & BIT_STAT_SPIF)) 790 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
786 continue; 791 continue;
787 792
788 /* dirty hack for autobuffer DMA mode */ 793 /* dirty hack for autobuffer DMA mode */
@@ -791,15 +796,15 @@ static void pump_transfers(unsigned long data)
791 "doing autobuffer DMA out.\n"); 796 "doing autobuffer DMA out.\n");
792 797
793 /* set SPI transfer mode */ 798 /* set SPI transfer mode */
794 write_CTRL(cr | CFG_SPI_DMAWRITE); 799 write_CTRL(drv_data, (cr | CFG_SPI_DMAWRITE));
795 800
796 /* no irq in autobuffer mode */ 801 /* no irq in autobuffer mode */
797 dma_config = 802 dma_config =
798 (DMAFLOW_AUTO | RESTART | dma_width | DI_EN); 803 (DMAFLOW_AUTO | RESTART | dma_width | DI_EN);
799 set_dma_config(spi_dma_ch, dma_config); 804 set_dma_config(drv_data->dma_channel, dma_config);
800 set_dma_start_addr(spi_dma_ch, 805 set_dma_start_addr(drv_data->dma_channel,
801 (unsigned long)drv_data->tx); 806 (unsigned long)drv_data->tx);
802 enable_dma(spi_dma_ch); 807 enable_dma(drv_data->dma_channel);
803 808
804 /* just return here, there can only be one transfer in this mode */ 809 /* just return here, there can only be one transfer in this mode */
805 message->status = 0; 810 message->status = 0;
@@ -813,34 +818,34 @@ static void pump_transfers(unsigned long data)
813 dev_dbg(&drv_data->pdev->dev, "doing DMA in.\n"); 818 dev_dbg(&drv_data->pdev->dev, "doing DMA in.\n");
814 819
815 /* set SPI transfer mode */ 820 /* set SPI transfer mode */
816 write_CTRL(cr | CFG_SPI_DMAREAD); 821 write_CTRL(drv_data, (cr | CFG_SPI_DMAREAD));
817 822
818 /* clear tx reg soformer data is not shifted out */ 823 /* clear tx reg soformer data is not shifted out */
819 write_TDBR(0xFFFF); 824 write_TDBR(drv_data, 0xFFFF);
820 825
821 set_dma_x_count(spi_dma_ch, drv_data->len); 826 set_dma_x_count(drv_data->dma_channel, drv_data->len);
822 827
823 /* start dma */ 828 /* start dma */
824 dma_enable_irq(spi_dma_ch); 829 dma_enable_irq(drv_data->dma_channel);
825 dma_config = (WNR | RESTART | dma_width | DI_EN); 830 dma_config = (WNR | RESTART | dma_width | DI_EN);
826 set_dma_config(spi_dma_ch, dma_config); 831 set_dma_config(drv_data->dma_channel, dma_config);
827 set_dma_start_addr(spi_dma_ch, 832 set_dma_start_addr(drv_data->dma_channel,
828 (unsigned long)drv_data->rx); 833 (unsigned long)drv_data->rx);
829 enable_dma(spi_dma_ch); 834 enable_dma(drv_data->dma_channel);
830 835
831 } else if (drv_data->tx != NULL) { 836 } else if (drv_data->tx != NULL) {
832 dev_dbg(&drv_data->pdev->dev, "doing DMA out.\n"); 837 dev_dbg(&drv_data->pdev->dev, "doing DMA out.\n");
833 838
834 /* set SPI transfer mode */ 839 /* set SPI transfer mode */
835 write_CTRL(cr | CFG_SPI_DMAWRITE); 840 write_CTRL(drv_data, (cr | CFG_SPI_DMAWRITE));
836 841
837 /* start dma */ 842 /* start dma */
838 dma_enable_irq(spi_dma_ch); 843 dma_enable_irq(drv_data->dma_channel);
839 dma_config = (RESTART | dma_width | DI_EN); 844 dma_config = (RESTART | dma_width | DI_EN);
840 set_dma_config(spi_dma_ch, dma_config); 845 set_dma_config(drv_data->dma_channel, dma_config);
841 set_dma_start_addr(spi_dma_ch, 846 set_dma_start_addr(drv_data->dma_channel,
842 (unsigned long)drv_data->tx); 847 (unsigned long)drv_data->tx);
843 enable_dma(spi_dma_ch); 848 enable_dma(drv_data->dma_channel);
844 } 849 }
845 } else { 850 } else {
846 /* IO mode write then read */ 851 /* IO mode write then read */
@@ -854,7 +859,7 @@ static void pump_transfers(unsigned long data)
854 "IO duplex: cr is 0x%x\n", cr); 859 "IO duplex: cr is 0x%x\n", cr);
855 860
856 /* set SPI transfer mode */ 861 /* set SPI transfer mode */
857 write_CTRL(cr | CFG_SPI_WRITE); 862 write_CTRL(drv_data, (cr | CFG_SPI_WRITE));
858 863
859 drv_data->duplex(drv_data); 864 drv_data->duplex(drv_data);
860 865
@@ -866,7 +871,7 @@ static void pump_transfers(unsigned long data)
866 "IO write: cr is 0x%x\n", cr); 871 "IO write: cr is 0x%x\n", cr);
867 872
868 /* set SPI transfer mode */ 873 /* set SPI transfer mode */
869 write_CTRL(cr | CFG_SPI_WRITE); 874 write_CTRL(drv_data, (cr | CFG_SPI_WRITE));
870 875
871 drv_data->write(drv_data); 876 drv_data->write(drv_data);
872 877
@@ -878,7 +883,7 @@ static void pump_transfers(unsigned long data)
878 "IO read: cr is 0x%x\n", cr); 883 "IO read: cr is 0x%x\n", cr);
879 884
880 /* set SPI transfer mode */ 885 /* set SPI transfer mode */
881 write_CTRL(cr | CFG_SPI_READ); 886 write_CTRL(drv_data, (cr | CFG_SPI_READ));
882 887
883 drv_data->read(drv_data); 888 drv_data->read(drv_data);
884 if (drv_data->rx != drv_data->rx_end) 889 if (drv_data->rx != drv_data->rx_end)
@@ -1075,20 +1080,20 @@ static int setup(struct spi_device *spi)
1075 * if any one SPI chip is registered and wants DMA, request the 1080 * if any one SPI chip is registered and wants DMA, request the
1076 * DMA channel for it 1081 * DMA channel for it
1077 */ 1082 */
1078 if (chip->enable_dma && !dma_requested) { 1083 if (chip->enable_dma && !drv_data->dma_requested) {
1079 /* register dma irq handler */ 1084 /* register dma irq handler */
1080 if (request_dma(spi_dma_ch, "BF53x_SPI_DMA") < 0) { 1085 if (request_dma(drv_data->dma_channel, "BF53x_SPI_DMA") < 0) {
1081 dev_dbg(&spi->dev, 1086 dev_dbg(&spi->dev,
1082 "Unable to request BlackFin SPI DMA channel\n"); 1087 "Unable to request BlackFin SPI DMA channel\n");
1083 return -ENODEV; 1088 return -ENODEV;
1084 } 1089 }
1085 if (set_dma_callback(spi_dma_ch, (void *)dma_irq_handler, 1090 if (set_dma_callback(drv_data->dma_channel,
1086 drv_data) < 0) { 1091 (void *)dma_irq_handler, drv_data) < 0) {
1087 dev_dbg(&spi->dev, "Unable to set dma callback\n"); 1092 dev_dbg(&spi->dev, "Unable to set dma callback\n");
1088 return -EPERM; 1093 return -EPERM;
1089 } 1094 }
1090 dma_disable_irq(spi_dma_ch); 1095 dma_disable_irq(drv_data->dma_channel);
1091 dma_requested = 1; 1096 drv_data->dma_requested = 1;
1092 } 1097 }
1093 1098
1094 /* 1099 /*
@@ -1304,15 +1309,16 @@ static int __init bfin5xx_spi_probe(struct platform_device *pdev)
1304 goto out_error_get_res; 1309 goto out_error_get_res;
1305 } 1310 }
1306 1311
1307 spi_regs_base = (u32) ioremap(res->start, (res->end - res->start)+1); 1312 drv_data->regs_base = (u32) ioremap(res->start,
1308 if (!spi_regs_base) { 1313 (res->end - res->start + 1));
1314 if (!drv_data->regs_base) {
1309 dev_err(dev, "Cannot map IO\n"); 1315 dev_err(dev, "Cannot map IO\n");
1310 status = -ENXIO; 1316 status = -ENXIO;
1311 goto out_error_ioremap; 1317 goto out_error_ioremap;
1312 } 1318 }
1313 1319
1314 spi_dma_ch = platform_get_irq(pdev, 0); 1320 drv_data->dma_channel = platform_get_irq(pdev, 0);
1315 if (spi_dma_ch < 0) { 1321 if (drv_data->dma_channel < 0) {
1316 dev_err(dev, "No DMA channel specified\n"); 1322 dev_err(dev, "No DMA channel specified\n");
1317 status = -ENOENT; 1323 status = -ENOENT;
1318 goto out_error_no_dma_ch; 1324 goto out_error_no_dma_ch;
@@ -1344,14 +1350,15 @@ static int __init bfin5xx_spi_probe(struct platform_device *pdev)
1344 goto out_error; 1350 goto out_error;
1345 } 1351 }
1346 1352
1347 dev_info(dev, "%s, Version %s, regs_base @ 0x%08x\n", 1353 dev_info(dev, "%s, Version %s, regs_base@0x%08x, dma channel@%d\n",
1348 DRV_DESC, DRV_VERSION, spi_regs_base); 1354 DRV_DESC, DRV_VERSION, drv_data->regs_base,
1355 drv_data->dma_channel);
1349 return status; 1356 return status;
1350 1357
1351out_error_queue_alloc: 1358out_error_queue_alloc:
1352 destroy_queue(drv_data); 1359 destroy_queue(drv_data);
1353out_error_no_dma_ch: 1360out_error_no_dma_ch:
1354 iounmap((void *) spi_regs_base); 1361 iounmap((void *) drv_data->regs_base);
1355out_error_ioremap: 1362out_error_ioremap:
1356out_error_get_res: 1363out_error_get_res:
1357out_error: 1364out_error:
@@ -1379,8 +1386,8 @@ static int __devexit bfin5xx_spi_remove(struct platform_device *pdev)
1379 1386
1380 /* Release DMA */ 1387 /* Release DMA */
1381 if (drv_data->master_info->enable_dma) { 1388 if (drv_data->master_info->enable_dma) {
1382 if (dma_channel_active(spi_dma_ch)) 1389 if (dma_channel_active(drv_data->dma_channel))
1383 free_dma(spi_dma_ch); 1390 free_dma(drv_data->dma_channel);
1384 } 1391 }
1385 1392
1386 /* Disconnect from the SPI framework */ 1393 /* Disconnect from the SPI framework */