Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'spi/next' of git://git.secretlab.ca/git/linux-2.6

* 'spi/next' of git://git.secretlab.ca/git/linux-2.6:
spi/amba-pl022: work in polling or interrupt mode if pl022_dma_probe fails
spi/spi_s3c24xx: Use spi_bitbang_stop instead of spi_unregister_master in s3c24xx_spi_remove
spi/spi_nuc900: Use spi_bitbang_stop instead of spi_unregister_master in nuc900_spi_remove
spi/spi_tegra: use spi_unregister_master() instead of spi_master_put()
spi/spi_sh: use spi_unregister_master instead of spi_master_put in remove path
spi: Use void pointers for data in simple SPI I/O operations
spi/pl022: use cpu_relax in the busy loop
spi/pl022: mark driver non-experimental
spi/pl022: timeout on polled transfer v2
spi/dw_spi: improve the interrupt mode with the batch ops
spi/dw_spi: change poll mode transfer from byte ops to batch ops
spi/dw_spi: remove the un-necessary flush()
spi/dw_spi: unify the low level read/write routines

+111 -174
+2 -2
drivers/spi/Kconfig
··· 271 271 This enables using the SPI master controller on the Orion chips. 272 272 273 273 config SPI_PL022 274 - tristate "ARM AMBA PL022 SSP controller (EXPERIMENTAL)" 275 - depends on ARM_AMBA && EXPERIMENTAL 274 + tristate "ARM AMBA PL022 SSP controller" 275 + depends on ARM_AMBA 276 276 default y if MACH_U300 277 277 default y if ARCH_REALVIEW 278 278 default y if INTEGRATOR_IMPD1
+22 -13
drivers/spi/amba-pl022.c
··· 24 24 * GNU General Public License for more details. 25 25 */ 26 26 27 - /* 28 - * TODO: 29 - * - add timeout on polled transfers 30 - */ 31 - 32 27 #include <linux/init.h> 33 28 #include <linux/module.h> 34 29 #include <linux/device.h> ··· 281 286 #define ENABLE_ALL_INTERRUPTS (~DEFAULT_SSP_REG_IMSC) 282 287 283 288 #define CLEAR_ALL_INTERRUPTS 0x3 289 + 290 + #define SPI_POLLING_TIMEOUT 1000 284 291 285 292 286 293 /* ··· 1060 1063 pl022->master_info->dma_filter, 1061 1064 pl022->master_info->dma_rx_param); 1062 1065 if (!pl022->dma_rx_channel) { 1063 - dev_err(&pl022->adev->dev, "no RX DMA channel!\n"); 1066 + dev_dbg(&pl022->adev->dev, "no RX DMA channel!\n"); 1064 1067 goto err_no_rxchan; 1065 1068 } 1066 1069 ··· 1068 1071 pl022->master_info->dma_filter, 1069 1072 pl022->master_info->dma_tx_param); 1070 1073 if (!pl022->dma_tx_channel) { 1071 - dev_err(&pl022->adev->dev, "no TX DMA channel!\n"); 1074 + dev_dbg(&pl022->adev->dev, "no TX DMA channel!\n"); 1072 1075 goto err_no_txchan; 1073 1076 } 1074 1077 1075 1078 pl022->dummypage = kmalloc(PAGE_SIZE, GFP_KERNEL); 1076 1079 if (!pl022->dummypage) { 1077 - dev_err(&pl022->adev->dev, "no DMA dummypage!\n"); 1080 + dev_dbg(&pl022->adev->dev, "no DMA dummypage!\n"); 1078 1081 goto err_no_dummypage; 1079 1082 } 1080 1083 ··· 1090 1093 dma_release_channel(pl022->dma_rx_channel); 1091 1094 pl022->dma_rx_channel = NULL; 1092 1095 err_no_rxchan: 1096 + dev_err(&pl022->adev->dev, 1097 + "Failed to work in dma mode, work without dma!\n"); 1093 1098 return -ENODEV; 1094 1099 } 1095 1100 ··· 1377 1378 struct spi_transfer *transfer = NULL; 1378 1379 struct spi_transfer *previous = NULL; 1379 1380 struct chip_data *chip; 1381 + unsigned long time, timeout; 1380 1382 1381 1383 chip = pl022->cur_chip; 1382 1384 message = pl022->cur_msg; ··· 1415 1415 SSP_CR1(pl022->virtbase)); 1416 1416 1417 1417 dev_dbg(&pl022->adev->dev, "polling transfer ongoing ...\n"); 1418 - /* FIXME: insert a timeout so we don't hang here indefinitely */ 1419 - while (pl022->tx < pl022->tx_end || pl022->rx < pl022->rx_end) 1418 + 1419 + timeout = jiffies + msecs_to_jiffies(SPI_POLLING_TIMEOUT); 1420 + while (pl022->tx < pl022->tx_end || pl022->rx < pl022->rx_end) { 1421 + time = jiffies; 1420 1422 readwriter(pl022); 1423 + if (time_after(time, timeout)) { 1424 + dev_warn(&pl022->adev->dev, 1425 + "%s: timeout!\n", __func__); 1426 + message->state = STATE_ERROR; 1427 + goto out; 1428 + } 1429 + cpu_relax(); 1430 + } 1421 1431 1422 1432 /* Update total byte transferred */ 1423 1433 message->actual_length += pl022->cur_transfer->len; ··· 1436 1426 /* Move to next transfer */ 1437 1427 message->state = next_transfer(pl022); 1438 1428 } 1439 - 1429 + out: 1440 1430 /* Handle end of message */ 1441 1431 if (message->state == STATE_DONE) 1442 1432 message->status = 0; ··· 2117 2107 if (platform_info->enable_dma) { 2118 2108 status = pl022_dma_probe(pl022); 2119 2109 if (status != 0) 2120 - goto err_no_dma; 2110 + platform_info->enable_dma = 0; 2121 2111 } 2122 2112 2123 2113 /* Initialize and start queue */ ··· 2153 2143 err_init_queue: 2154 2144 destroy_queue(pl022); 2155 2145 pl022_dma_remove(pl022); 2156 - err_no_dma: 2157 2146 free_irq(adev->irq[0], pl022); 2158 2147 err_no_irq: 2159 2148 clk_put(pl022->clk);
+77 -147
drivers/spi/dw_spi.c
··· 58 58 u8 bits_per_word; 59 59 u16 clk_div; /* baud rate divider */ 60 60 u32 speed_hz; /* baud rate */ 61 - int (*write)(struct dw_spi *dws); 62 - int (*read)(struct dw_spi *dws); 63 61 void (*cs_control)(u32 command); 64 62 }; 65 63 ··· 160 162 } 161 163 #endif /* CONFIG_DEBUG_FS */ 162 164 163 - static void wait_till_not_busy(struct dw_spi *dws) 165 + /* Return the max entries we can fill into tx fifo */ 166 + static inline u32 tx_max(struct dw_spi *dws) 164 167 { 165 - unsigned long end = jiffies + 1 + usecs_to_jiffies(5000); 168 + u32 tx_left, tx_room, rxtx_gap; 166 169 167 - while (time_before(jiffies, end)) { 168 - if (!(dw_readw(dws, sr) & SR_BUSY)) 169 - return; 170 - cpu_relax(); 170 + tx_left = (dws->tx_end - dws->tx) / dws->n_bytes; 171 + tx_room = dws->fifo_len - dw_readw(dws, txflr); 172 + 173 + /* 174 + * Another concern is about the tx/rx mismatch, we 175 + * though to use (dws->fifo_len - rxflr - txflr) as 176 + * one maximum value for tx, but it doesn't cover the 177 + * data which is out of tx/rx fifo and inside the 178 + * shift registers. So a control from sw point of 179 + * view is taken. 180 + */ 181 + rxtx_gap = ((dws->rx_end - dws->rx) - (dws->tx_end - dws->tx)) 182 + / dws->n_bytes; 183 + 184 + return min3(tx_left, tx_room, (u32) (dws->fifo_len - rxtx_gap)); 185 + } 186 + 187 + /* Return the max entries we should read out of rx fifo */ 188 + static inline u32 rx_max(struct dw_spi *dws) 189 + { 190 + u32 rx_left = (dws->rx_end - dws->rx) / dws->n_bytes; 191 + 192 + return min(rx_left, (u32)dw_readw(dws, rxflr)); 193 + } 194 + 195 + static void dw_writer(struct dw_spi *dws) 196 + { 197 + u32 max = tx_max(dws); 198 + u16 txw = 0; 199 + 200 + while (max--) { 201 + /* Set the tx word if the transfer's original "tx" is not null */ 202 + if (dws->tx_end - dws->len) { 203 + if (dws->n_bytes == 1) 204 + txw = *(u8 *)(dws->tx); 205 + else 206 + txw = *(u16 *)(dws->tx); 207 + } 208 + dw_writew(dws, dr, txw); 209 + dws->tx += dws->n_bytes; 171 210 } 172 - dev_err(&dws->master->dev, 173 - "DW SPI: Status keeps busy for 5000us after a read/write!\n"); 174 211 } 175 212 176 - static void flush(struct dw_spi *dws) 213 + static void dw_reader(struct dw_spi *dws) 177 214 { 178 - while (dw_readw(dws, sr) & SR_RF_NOT_EMPT) { 179 - dw_readw(dws, dr); 180 - cpu_relax(); 215 + u32 max = rx_max(dws); 216 + u16 rxw; 217 + 218 + while (max--) { 219 + rxw = dw_readw(dws, dr); 220 + /* Care rx only if the transfer's original "rx" is not null */ 221 + if (dws->rx_end - dws->len) { 222 + if (dws->n_bytes == 1) 223 + *(u8 *)(dws->rx) = rxw; 224 + else 225 + *(u16 *)(dws->rx) = rxw; 226 + } 227 + dws->rx += dws->n_bytes; 181 228 } 182 - 183 - wait_till_not_busy(dws); 184 - } 185 - 186 - static int null_writer(struct dw_spi *dws) 187 - { 188 - u8 n_bytes = dws->n_bytes; 189 - 190 - if (!(dw_readw(dws, sr) & SR_TF_NOT_FULL) 191 - || (dws->tx == dws->tx_end)) 192 - return 0; 193 - dw_writew(dws, dr, 0); 194 - dws->tx += n_bytes; 195 - 196 - wait_till_not_busy(dws); 197 - return 1; 198 - } 199 - 200 - static int null_reader(struct dw_spi *dws) 201 - { 202 - u8 n_bytes = dws->n_bytes; 203 - 204 - while ((dw_readw(dws, sr) & SR_RF_NOT_EMPT) 205 - && (dws->rx < dws->rx_end)) { 206 - dw_readw(dws, dr); 207 - dws->rx += n_bytes; 208 - } 209 - wait_till_not_busy(dws); 210 - return dws->rx == dws->rx_end; 211 - } 212 - 213 - static int u8_writer(struct dw_spi *dws) 214 - { 215 - if (!(dw_readw(dws, sr) & SR_TF_NOT_FULL) 216 - || (dws->tx == dws->tx_end)) 217 - return 0; 218 - 219 - dw_writew(dws, dr, *(u8 *)(dws->tx)); 220 - ++dws->tx; 221 - 222 - wait_till_not_busy(dws); 223 - return 1; 224 - } 225 - 226 - static int u8_reader(struct dw_spi *dws) 227 - { 228 - while ((dw_readw(dws, sr) & SR_RF_NOT_EMPT) 229 - && (dws->rx < dws->rx_end)) { 230 - *(u8 *)(dws->rx) = dw_readw(dws, dr); 231 - ++dws->rx; 232 - } 233 - 234 - wait_till_not_busy(dws); 235 - return dws->rx == dws->rx_end; 236 - } 237 - 238 - static int u16_writer(struct dw_spi *dws) 239 - { 240 - if (!(dw_readw(dws, sr) & SR_TF_NOT_FULL) 241 - || (dws->tx == dws->tx_end)) 242 - return 0; 243 - 244 - dw_writew(dws, dr, *(u16 *)(dws->tx)); 245 - dws->tx += 2; 246 - 247 - wait_till_not_busy(dws); 248 - return 1; 249 - } 250 - 251 - static int u16_reader(struct dw_spi *dws) 252 - { 253 - u16 temp; 254 - 255 - while ((dw_readw(dws, sr) & SR_RF_NOT_EMPT) 256 - && (dws->rx < dws->rx_end)) { 257 - temp = dw_readw(dws, dr); 258 - *(u16 *)(dws->rx) = temp; 259 - dws->rx += 2; 260 - } 261 - 262 - wait_till_not_busy(dws); 263 - return dws->rx == dws->rx_end; 264 229 } 265 230 266 231 static void *next_transfer(struct dw_spi *dws) ··· 295 334 296 335 static void int_error_stop(struct dw_spi *dws, const char *msg) 297 336 { 298 - /* Stop and reset hw */ 299 - flush(dws); 337 + /* Stop the hw */ 300 338 spi_enable_chip(dws, 0); 301 339 302 340 dev_err(&dws->master->dev, "%s\n", msg); ··· 322 362 323 363 static irqreturn_t interrupt_transfer(struct dw_spi *dws) 324 364 { 325 - u16 irq_status, irq_mask = 0x3f; 326 - u32 int_level = dws->fifo_len / 2; 327 - u32 left; 365 + u16 irq_status = dw_readw(dws, isr); 328 366 329 - irq_status = dw_readw(dws, isr) & irq_mask; 330 367 /* Error handling */ 331 368 if (irq_status & (SPI_INT_TXOI | SPI_INT_RXOI | SPI_INT_RXUI)) { 332 369 dw_readw(dws, txoicr); 333 370 dw_readw(dws, rxoicr); 334 371 dw_readw(dws, rxuicr); 335 - int_error_stop(dws, "interrupt_transfer: fifo overrun"); 372 + int_error_stop(dws, "interrupt_transfer: fifo overrun/underrun"); 336 373 return IRQ_HANDLED; 337 374 } 338 375 376 + dw_reader(dws); 377 + if (dws->rx_end == dws->rx) { 378 + spi_mask_intr(dws, SPI_INT_TXEI); 379 + dw_spi_xfer_done(dws); 380 + return IRQ_HANDLED; 381 + } 339 382 if (irq_status & SPI_INT_TXEI) { 340 383 spi_mask_intr(dws, SPI_INT_TXEI); 341 - 342 - left = (dws->tx_end - dws->tx) / dws->n_bytes; 343 - left = (left > int_level) ? int_level : left; 344 - 345 - while (left--) 346 - dws->write(dws); 347 - dws->read(dws); 348 - 349 - /* Re-enable the IRQ if there is still data left to tx */ 350 - if (dws->tx_end > dws->tx) 351 - spi_umask_intr(dws, SPI_INT_TXEI); 352 - else 353 - dw_spi_xfer_done(dws); 384 + dw_writer(dws); 385 + /* Enable TX irq always, it will be disabled when RX finished */ 386 + spi_umask_intr(dws, SPI_INT_TXEI); 354 387 } 355 388 356 389 return IRQ_HANDLED; ··· 352 399 static irqreturn_t dw_spi_irq(int irq, void *dev_id) 353 400 { 354 401 struct dw_spi *dws = dev_id; 355 - u16 irq_status, irq_mask = 0x3f; 402 + u16 irq_status = dw_readw(dws, isr) & 0x3f; 356 403 357 - irq_status = dw_readw(dws, isr) & irq_mask; 358 404 if (!irq_status) 359 405 return IRQ_NONE; 360 406 361 407 if (!dws->cur_msg) { 362 408 spi_mask_intr(dws, SPI_INT_TXEI); 363 - /* Never fail */ 364 409 return IRQ_HANDLED; 365 410 } 366 411 ··· 368 417 /* Must be called inside pump_transfers() */ 369 418 static void poll_transfer(struct dw_spi *dws) 370 419 { 371 - while (dws->write(dws)) 372 - dws->read(dws); 373 - /* 374 - * There is a possibility that the last word of a transaction 375 - * will be lost if data is not ready. Re-read to solve this issue. 376 - */ 377 - dws->read(dws); 420 + do { 421 + dw_writer(dws); 422 + dw_reader(dws); 423 + cpu_relax(); 424 + } while (dws->rx_end > dws->rx); 378 425 379 426 dw_spi_xfer_done(dws); 380 427 } ··· 432 483 dws->tx_end = dws->tx + transfer->len; 433 484 dws->rx = transfer->rx_buf; 434 485 dws->rx_end = dws->rx + transfer->len; 435 - dws->write = dws->tx ? chip->write : null_writer; 436 - dws->read = dws->rx ? chip->read : null_reader; 437 486 dws->cs_change = transfer->cs_change; 438 487 dws->len = dws->cur_transfer->len; 439 488 if (chip != dws->prev_chip) ··· 465 518 466 519 switch (bits) { 467 520 case 8: 468 - dws->n_bytes = 1; 469 - dws->dma_width = 1; 470 - dws->read = (dws->read != null_reader) ? 471 - u8_reader : null_reader; 472 - dws->write = (dws->write != null_writer) ? 473 - u8_writer : null_writer; 474 - break; 475 521 case 16: 476 - dws->n_bytes = 2; 477 - dws->dma_width = 2; 478 - dws->read = (dws->read != null_reader) ? 479 - u16_reader : null_reader; 480 - dws->write = (dws->write != null_writer) ? 481 - u16_writer : null_writer; 522 + dws->n_bytes = dws->dma_width = bits >> 3; 482 523 break; 483 524 default: 484 525 printk(KERN_ERR "MRST SPI0: unsupported bits:" ··· 510 575 txint_level = dws->fifo_len / 2; 511 576 txint_level = (templen > txint_level) ? txint_level : templen; 512 577 513 - imask |= SPI_INT_TXEI; 578 + imask |= SPI_INT_TXEI | SPI_INT_TXOI | SPI_INT_RXUI | SPI_INT_RXOI; 514 579 dws->transfer_handler = interrupt_transfer; 515 580 } 516 581 ··· 668 733 if (spi->bits_per_word <= 8) { 669 734 chip->n_bytes = 1; 670 735 chip->dma_width = 1; 671 - chip->read = u8_reader; 672 - chip->write = u8_writer; 673 736 } else if (spi->bits_per_word <= 16) { 674 737 chip->n_bytes = 2; 675 738 chip->dma_width = 2; 676 - chip->read = u16_reader; 677 - chip->write = u16_writer; 678 739 } else { 679 740 /* Never take >16b case for MRST SPIC */ 680 741 dev_err(&spi->dev, "invalid wordsize\n"); ··· 782 851 spi_enable_chip(dws, 0); 783 852 spi_mask_intr(dws, 0xff); 784 853 spi_enable_chip(dws, 1); 785 - flush(dws); 786 854 787 855 /* 788 856 * Try to detect the FIFO depth if not set by interface driver,
-2
drivers/spi/dw_spi.h
··· 137 137 u8 max_bits_per_word; /* maxim is 16b */ 138 138 u32 dma_width; 139 139 int cs_change; 140 - int (*write)(struct dw_spi *dws); 141 - int (*read)(struct dw_spi *dws); 142 140 irqreturn_t (*transfer_handler)(struct dw_spi *dws); 143 141 void (*cs_control)(u32 command); 144 142
+2 -2
drivers/spi/spi.c
··· 1047 1047 * spi_{async,sync}() calls with dma-safe buffers. 1048 1048 */ 1049 1049 int spi_write_then_read(struct spi_device *spi, 1050 - const u8 *txbuf, unsigned n_tx, 1051 - u8 *rxbuf, unsigned n_rx) 1050 + const void *txbuf, unsigned n_tx, 1051 + void *rxbuf, unsigned n_rx) 1052 1052 { 1053 1053 static DEFINE_MUTEX(lock); 1054 1054
+1 -1
drivers/spi/spi_nuc900.c
··· 463 463 464 464 platform_set_drvdata(dev, NULL); 465 465 466 - spi_unregister_master(hw->master); 466 + spi_bitbang_stop(&hw->bitbang); 467 467 468 468 clk_disable(hw->clk); 469 469 clk_put(hw->clk);
+1 -1
drivers/spi/spi_s3c24xx.c
··· 668 668 669 669 platform_set_drvdata(dev, NULL); 670 670 671 - spi_unregister_master(hw->master); 671 + spi_bitbang_stop(&hw->bitbang); 672 672 673 673 clk_disable(hw->clk); 674 674 clk_put(hw->clk);
+1 -1
drivers/spi/spi_sh.c
··· 427 427 { 428 428 struct spi_sh_data *ss = dev_get_drvdata(&pdev->dev); 429 429 430 + spi_unregister_master(ss->master); 430 431 destroy_workqueue(ss->workqueue); 431 432 free_irq(ss->irq, ss); 432 433 iounmap(ss->addr); 433 - spi_master_put(ss->master); 434 434 435 435 return 0; 436 436 }
+1 -1
drivers/spi/spi_tegra.c
··· 578 578 master = dev_get_drvdata(&pdev->dev); 579 579 tspi = spi_master_get_devdata(master); 580 580 581 + spi_unregister_master(master); 581 582 tegra_dma_free_channel(tspi->rx_dma); 582 583 583 584 dma_free_coherent(&pdev->dev, sizeof(u32) * BB_LEN, ··· 587 586 clk_put(tspi->clk); 588 587 iounmap(tspi->base); 589 588 590 - spi_master_put(master); 591 589 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 592 590 release_mem_region(r->start, (r->end - r->start) + 1); 593 591
+4 -4
include/linux/spi/spi.h
··· 581 581 * Callable only from contexts that can sleep. 582 582 */ 583 583 static inline int 584 - spi_write(struct spi_device *spi, const u8 *buf, size_t len) 584 + spi_write(struct spi_device *spi, const void *buf, size_t len) 585 585 { 586 586 struct spi_transfer t = { 587 587 .tx_buf = buf, ··· 605 605 * Callable only from contexts that can sleep. 606 606 */ 607 607 static inline int 608 - spi_read(struct spi_device *spi, u8 *buf, size_t len) 608 + spi_read(struct spi_device *spi, void *buf, size_t len) 609 609 { 610 610 struct spi_transfer t = { 611 611 .rx_buf = buf, ··· 620 620 621 621 /* this copies txbuf and rxbuf data; for small transfers only! */ 622 622 extern int spi_write_then_read(struct spi_device *spi, 623 - const u8 *txbuf, unsigned n_tx, 624 - u8 *rxbuf, unsigned n_rx); 623 + const void *txbuf, unsigned n_tx, 624 + void *rxbuf, unsigned n_rx); 625 625 626 626 /** 627 627 * spi_w8r8 - SPI synchronous 8 bit write followed by 8 bit read