diff options
author | Mark Brown <broonie@kernel.org> | 2019-04-04 23:19:10 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2019-04-04 23:19:10 -0400 |
commit | e1a7d1673062a6a9160b1fc94e1540b747398e01 (patch) | |
tree | 77ed1ca15537d1ae04a6ab0ff6128567c0fa497e | |
parent | 9fda6693335cd51b0a74cffaac266c83439f7efe (diff) | |
parent | a026525d4e45e3d9690bffd0b05d018ff5638b5a (diff) |
Merge branch 'spi-5.1' into spi-5.2
-rw-r--r-- | drivers/spi/spi-fsl-lpspi.c | 4 | ||||
-rw-r--r-- | drivers/spi/spi-gpio.c | 1 | ||||
-rw-r--r-- | drivers/spi/spi-pic32.c | 2 | ||||
-rw-r--r-- | drivers/spi/spi-tegra114.c | 208 | ||||
-rw-r--r-- | drivers/spi/spi-tegra20-slink.c | 12 | ||||
-rw-r--r-- | drivers/spi/spi-topcliff-pch.c | 15 | ||||
-rw-r--r-- | drivers/spi/spi.c | 2 |
7 files changed, 173 insertions, 71 deletions
diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c index 2ad9d6262c2b..33b6a8affd55 100644 --- a/drivers/spi/spi-fsl-lpspi.c +++ b/drivers/spi/spi-fsl-lpspi.c | |||
@@ -77,7 +77,7 @@ | |||
77 | #define CFGR1_PCSPOL BIT(8) | 77 | #define CFGR1_PCSPOL BIT(8) |
78 | #define CFGR1_NOSTALL BIT(3) | 78 | #define CFGR1_NOSTALL BIT(3) |
79 | #define CFGR1_MASTER BIT(0) | 79 | #define CFGR1_MASTER BIT(0) |
80 | #define FSR_RXCOUNT (BIT(16)|BIT(17)|BIT(18)) | 80 | #define FSR_TXCOUNT (0xFF) |
81 | #define RSR_RXEMPTY BIT(1) | 81 | #define RSR_RXEMPTY BIT(1) |
82 | #define TCR_CPOL BIT(31) | 82 | #define TCR_CPOL BIT(31) |
83 | #define TCR_CPHA BIT(30) | 83 | #define TCR_CPHA BIT(30) |
@@ -771,7 +771,7 @@ static irqreturn_t fsl_lpspi_isr(int irq, void *dev_id) | |||
771 | } | 771 | } |
772 | 772 | ||
773 | if (temp_SR & SR_MBF || | 773 | if (temp_SR & SR_MBF || |
774 | readl(fsl_lpspi->base + IMX7ULP_FSR) & FSR_RXCOUNT) { | 774 | readl(fsl_lpspi->base + IMX7ULP_FSR) & FSR_TXCOUNT) { |
775 | writel(SR_FCF, fsl_lpspi->base + IMX7ULP_SR); | 775 | writel(SR_FCF, fsl_lpspi->base + IMX7ULP_SR); |
776 | fsl_lpspi_intctrl(fsl_lpspi, IER_FCIE); | 776 | fsl_lpspi_intctrl(fsl_lpspi, IER_FCIE); |
777 | return IRQ_HANDLED; | 777 | return IRQ_HANDLED; |
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 1cff30adc836..c8fe87ebf8c8 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c | |||
@@ -35,7 +35,6 @@ | |||
35 | * platform_device->driver_data ... points to spi_gpio | 35 | * platform_device->driver_data ... points to spi_gpio |
36 | * | 36 | * |
37 | * spi->controller_state ... reserved for bitbang framework code | 37 | * spi->controller_state ... reserved for bitbang framework code |
38 | * spi->controller_data ... holds chipselect GPIO | ||
39 | * | 38 | * |
40 | * spi->master->dev.driver_data ... points to spi_gpio->bitbang | 39 | * spi->master->dev.driver_data ... points to spi_gpio->bitbang |
41 | */ | 40 | */ |
diff --git a/drivers/spi/spi-pic32.c b/drivers/spi/spi-pic32.c index 131849adc570..d9f374c8b709 100644 --- a/drivers/spi/spi-pic32.c +++ b/drivers/spi/spi-pic32.c | |||
@@ -559,7 +559,7 @@ static int pic32_spi_one_transfer(struct spi_master *master, | |||
559 | dev_err(&spi->dev, "wait error/timedout\n"); | 559 | dev_err(&spi->dev, "wait error/timedout\n"); |
560 | if (dma_issued) { | 560 | if (dma_issued) { |
561 | dmaengine_terminate_all(master->dma_rx); | 561 | dmaengine_terminate_all(master->dma_rx); |
562 | dmaengine_terminate_all(master->dma_rx); | 562 | dmaengine_terminate_all(master->dma_tx); |
563 | } | 563 | } |
564 | ret = -ETIMEDOUT; | 564 | ret = -ETIMEDOUT; |
565 | } else { | 565 | } else { |
diff --git a/drivers/spi/spi-tegra114.c b/drivers/spi/spi-tegra114.c index 0c52aeeb1d4f..8c33bf056196 100644 --- a/drivers/spi/spi-tegra114.c +++ b/drivers/spi/spi-tegra114.c | |||
@@ -307,10 +307,16 @@ static unsigned tegra_spi_fill_tx_fifo_from_client_txbuf( | |||
307 | x |= (u32)(*tx_buf++) << (i * 8); | 307 | x |= (u32)(*tx_buf++) << (i * 8); |
308 | tegra_spi_writel(tspi, x, SPI_TX_FIFO); | 308 | tegra_spi_writel(tspi, x, SPI_TX_FIFO); |
309 | } | 309 | } |
310 | |||
311 | tspi->cur_tx_pos += written_words * tspi->bytes_per_word; | ||
310 | } else { | 312 | } else { |
313 | unsigned int write_bytes; | ||
311 | max_n_32bit = min(tspi->curr_dma_words, tx_empty_count); | 314 | max_n_32bit = min(tspi->curr_dma_words, tx_empty_count); |
312 | written_words = max_n_32bit; | 315 | written_words = max_n_32bit; |
313 | nbytes = written_words * tspi->bytes_per_word; | 316 | nbytes = written_words * tspi->bytes_per_word; |
317 | if (nbytes > t->len - tspi->cur_pos) | ||
318 | nbytes = t->len - tspi->cur_pos; | ||
319 | write_bytes = nbytes; | ||
314 | for (count = 0; count < max_n_32bit; count++) { | 320 | for (count = 0; count < max_n_32bit; count++) { |
315 | u32 x = 0; | 321 | u32 x = 0; |
316 | 322 | ||
@@ -319,8 +325,10 @@ static unsigned tegra_spi_fill_tx_fifo_from_client_txbuf( | |||
319 | x |= (u32)(*tx_buf++) << (i * 8); | 325 | x |= (u32)(*tx_buf++) << (i * 8); |
320 | tegra_spi_writel(tspi, x, SPI_TX_FIFO); | 326 | tegra_spi_writel(tspi, x, SPI_TX_FIFO); |
321 | } | 327 | } |
328 | |||
329 | tspi->cur_tx_pos += write_bytes; | ||
322 | } | 330 | } |
323 | tspi->cur_tx_pos += written_words * tspi->bytes_per_word; | 331 | |
324 | return written_words; | 332 | return written_words; |
325 | } | 333 | } |
326 | 334 | ||
@@ -344,20 +352,27 @@ static unsigned int tegra_spi_read_rx_fifo_to_client_rxbuf( | |||
344 | for (i = 0; len && (i < 4); i++, len--) | 352 | for (i = 0; len && (i < 4); i++, len--) |
345 | *rx_buf++ = (x >> i*8) & 0xFF; | 353 | *rx_buf++ = (x >> i*8) & 0xFF; |
346 | } | 354 | } |
347 | tspi->cur_rx_pos += tspi->curr_dma_words * tspi->bytes_per_word; | ||
348 | read_words += tspi->curr_dma_words; | 355 | read_words += tspi->curr_dma_words; |
356 | tspi->cur_rx_pos += tspi->curr_dma_words * tspi->bytes_per_word; | ||
349 | } else { | 357 | } else { |
350 | u32 rx_mask = ((u32)1 << t->bits_per_word) - 1; | 358 | u32 rx_mask = ((u32)1 << t->bits_per_word) - 1; |
359 | u8 bytes_per_word = tspi->bytes_per_word; | ||
360 | unsigned int read_bytes; | ||
351 | 361 | ||
362 | len = rx_full_count * bytes_per_word; | ||
363 | if (len > t->len - tspi->cur_pos) | ||
364 | len = t->len - tspi->cur_pos; | ||
365 | read_bytes = len; | ||
352 | for (count = 0; count < rx_full_count; count++) { | 366 | for (count = 0; count < rx_full_count; count++) { |
353 | u32 x = tegra_spi_readl(tspi, SPI_RX_FIFO) & rx_mask; | 367 | u32 x = tegra_spi_readl(tspi, SPI_RX_FIFO) & rx_mask; |
354 | 368 | ||
355 | for (i = 0; (i < tspi->bytes_per_word); i++) | 369 | for (i = 0; len && (i < bytes_per_word); i++, len--) |
356 | *rx_buf++ = (x >> (i*8)) & 0xFF; | 370 | *rx_buf++ = (x >> (i*8)) & 0xFF; |
357 | } | 371 | } |
358 | tspi->cur_rx_pos += rx_full_count * tspi->bytes_per_word; | ||
359 | read_words += rx_full_count; | 372 | read_words += rx_full_count; |
373 | tspi->cur_rx_pos += read_bytes; | ||
360 | } | 374 | } |
375 | |||
361 | return read_words; | 376 | return read_words; |
362 | } | 377 | } |
363 | 378 | ||
@@ -372,12 +387,17 @@ static void tegra_spi_copy_client_txbuf_to_spi_txbuf( | |||
372 | unsigned len = tspi->curr_dma_words * tspi->bytes_per_word; | 387 | unsigned len = tspi->curr_dma_words * tspi->bytes_per_word; |
373 | 388 | ||
374 | memcpy(tspi->tx_dma_buf, t->tx_buf + tspi->cur_pos, len); | 389 | memcpy(tspi->tx_dma_buf, t->tx_buf + tspi->cur_pos, len); |
390 | tspi->cur_tx_pos += tspi->curr_dma_words * tspi->bytes_per_word; | ||
375 | } else { | 391 | } else { |
376 | unsigned int i; | 392 | unsigned int i; |
377 | unsigned int count; | 393 | unsigned int count; |
378 | u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_tx_pos; | 394 | u8 *tx_buf = (u8 *)t->tx_buf + tspi->cur_tx_pos; |
379 | unsigned consume = tspi->curr_dma_words * tspi->bytes_per_word; | 395 | unsigned consume = tspi->curr_dma_words * tspi->bytes_per_word; |
396 | unsigned int write_bytes; | ||
380 | 397 | ||
398 | if (consume > t->len - tspi->cur_pos) | ||
399 | consume = t->len - tspi->cur_pos; | ||
400 | write_bytes = consume; | ||
381 | for (count = 0; count < tspi->curr_dma_words; count++) { | 401 | for (count = 0; count < tspi->curr_dma_words; count++) { |
382 | u32 x = 0; | 402 | u32 x = 0; |
383 | 403 | ||
@@ -386,8 +406,9 @@ static void tegra_spi_copy_client_txbuf_to_spi_txbuf( | |||
386 | x |= (u32)(*tx_buf++) << (i * 8); | 406 | x |= (u32)(*tx_buf++) << (i * 8); |
387 | tspi->tx_dma_buf[count] = x; | 407 | tspi->tx_dma_buf[count] = x; |
388 | } | 408 | } |
409 | |||
410 | tspi->cur_tx_pos += write_bytes; | ||
389 | } | 411 | } |
390 | tspi->cur_tx_pos += tspi->curr_dma_words * tspi->bytes_per_word; | ||
391 | 412 | ||
392 | /* Make the dma buffer to read by dma */ | 413 | /* Make the dma buffer to read by dma */ |
393 | dma_sync_single_for_device(tspi->dev, tspi->tx_dma_phys, | 414 | dma_sync_single_for_device(tspi->dev, tspi->tx_dma_phys, |
@@ -405,20 +426,28 @@ static void tegra_spi_copy_spi_rxbuf_to_client_rxbuf( | |||
405 | unsigned len = tspi->curr_dma_words * tspi->bytes_per_word; | 426 | unsigned len = tspi->curr_dma_words * tspi->bytes_per_word; |
406 | 427 | ||
407 | memcpy(t->rx_buf + tspi->cur_rx_pos, tspi->rx_dma_buf, len); | 428 | memcpy(t->rx_buf + tspi->cur_rx_pos, tspi->rx_dma_buf, len); |
429 | tspi->cur_rx_pos += tspi->curr_dma_words * tspi->bytes_per_word; | ||
408 | } else { | 430 | } else { |
409 | unsigned int i; | 431 | unsigned int i; |
410 | unsigned int count; | 432 | unsigned int count; |
411 | unsigned char *rx_buf = t->rx_buf + tspi->cur_rx_pos; | 433 | unsigned char *rx_buf = t->rx_buf + tspi->cur_rx_pos; |
412 | u32 rx_mask = ((u32)1 << t->bits_per_word) - 1; | 434 | u32 rx_mask = ((u32)1 << t->bits_per_word) - 1; |
435 | unsigned consume = tspi->curr_dma_words * tspi->bytes_per_word; | ||
436 | unsigned int read_bytes; | ||
413 | 437 | ||
438 | if (consume > t->len - tspi->cur_pos) | ||
439 | consume = t->len - tspi->cur_pos; | ||
440 | read_bytes = consume; | ||
414 | for (count = 0; count < tspi->curr_dma_words; count++) { | 441 | for (count = 0; count < tspi->curr_dma_words; count++) { |
415 | u32 x = tspi->rx_dma_buf[count] & rx_mask; | 442 | u32 x = tspi->rx_dma_buf[count] & rx_mask; |
416 | 443 | ||
417 | for (i = 0; (i < tspi->bytes_per_word); i++) | 444 | for (i = 0; consume && (i < tspi->bytes_per_word); |
445 | i++, consume--) | ||
418 | *rx_buf++ = (x >> (i*8)) & 0xFF; | 446 | *rx_buf++ = (x >> (i*8)) & 0xFF; |
419 | } | 447 | } |
448 | |||
449 | tspi->cur_rx_pos += read_bytes; | ||
420 | } | 450 | } |
421 | tspi->cur_rx_pos += tspi->curr_dma_words * tspi->bytes_per_word; | ||
422 | 451 | ||
423 | /* Make the dma buffer to read by dma */ | 452 | /* Make the dma buffer to read by dma */ |
424 | dma_sync_single_for_device(tspi->dev, tspi->rx_dma_phys, | 453 | dma_sync_single_for_device(tspi->dev, tspi->rx_dma_phys, |
@@ -470,22 +499,39 @@ static int tegra_spi_start_rx_dma(struct tegra_spi_data *tspi, int len) | |||
470 | return 0; | 499 | return 0; |
471 | } | 500 | } |
472 | 501 | ||
473 | static int tegra_spi_start_dma_based_transfer( | 502 | static int tegra_spi_flush_fifos(struct tegra_spi_data *tspi) |
474 | struct tegra_spi_data *tspi, struct spi_transfer *t) | ||
475 | { | 503 | { |
476 | u32 val; | 504 | unsigned long timeout = jiffies + HZ; |
477 | unsigned int len; | ||
478 | int ret = 0; | ||
479 | u32 status; | 505 | u32 status; |
480 | 506 | ||
481 | /* Make sure that Rx and Tx fifo are empty */ | ||
482 | status = tegra_spi_readl(tspi, SPI_FIFO_STATUS); | 507 | status = tegra_spi_readl(tspi, SPI_FIFO_STATUS); |
483 | if ((status & SPI_FIFO_EMPTY) != SPI_FIFO_EMPTY) { | 508 | if ((status & SPI_FIFO_EMPTY) != SPI_FIFO_EMPTY) { |
484 | dev_err(tspi->dev, "Rx/Tx fifo are not empty status 0x%08x\n", | 509 | status |= SPI_RX_FIFO_FLUSH | SPI_TX_FIFO_FLUSH; |
485 | (unsigned)status); | 510 | tegra_spi_writel(tspi, status, SPI_FIFO_STATUS); |
486 | return -EIO; | 511 | while ((status & SPI_FIFO_EMPTY) != SPI_FIFO_EMPTY) { |
512 | status = tegra_spi_readl(tspi, SPI_FIFO_STATUS); | ||
513 | if (time_after(jiffies, timeout)) { | ||
514 | dev_err(tspi->dev, | ||
515 | "timeout waiting for fifo flush\n"); | ||
516 | return -EIO; | ||
517 | } | ||
518 | |||
519 | udelay(1); | ||
520 | } | ||
487 | } | 521 | } |
488 | 522 | ||
523 | return 0; | ||
524 | } | ||
525 | |||
526 | static int tegra_spi_start_dma_based_transfer( | ||
527 | struct tegra_spi_data *tspi, struct spi_transfer *t) | ||
528 | { | ||
529 | u32 val; | ||
530 | unsigned int len; | ||
531 | int ret = 0; | ||
532 | u8 dma_burst; | ||
533 | struct dma_slave_config dma_sconfig = {0}; | ||
534 | |||
489 | val = SPI_DMA_BLK_SET(tspi->curr_dma_words - 1); | 535 | val = SPI_DMA_BLK_SET(tspi->curr_dma_words - 1); |
490 | tegra_spi_writel(tspi, val, SPI_DMA_BLK); | 536 | tegra_spi_writel(tspi, val, SPI_DMA_BLK); |
491 | 537 | ||
@@ -496,12 +542,16 @@ static int tegra_spi_start_dma_based_transfer( | |||
496 | len = tspi->curr_dma_words * 4; | 542 | len = tspi->curr_dma_words * 4; |
497 | 543 | ||
498 | /* Set attention level based on length of transfer */ | 544 | /* Set attention level based on length of transfer */ |
499 | if (len & 0xF) | 545 | if (len & 0xF) { |
500 | val |= SPI_TX_TRIG_1 | SPI_RX_TRIG_1; | 546 | val |= SPI_TX_TRIG_1 | SPI_RX_TRIG_1; |
501 | else if (((len) >> 4) & 0x1) | 547 | dma_burst = 1; |
548 | } else if (((len) >> 4) & 0x1) { | ||
502 | val |= SPI_TX_TRIG_4 | SPI_RX_TRIG_4; | 549 | val |= SPI_TX_TRIG_4 | SPI_RX_TRIG_4; |
503 | else | 550 | dma_burst = 4; |
551 | } else { | ||
504 | val |= SPI_TX_TRIG_8 | SPI_RX_TRIG_8; | 552 | val |= SPI_TX_TRIG_8 | SPI_RX_TRIG_8; |
553 | dma_burst = 8; | ||
554 | } | ||
505 | 555 | ||
506 | if (tspi->cur_direction & DATA_DIR_TX) | 556 | if (tspi->cur_direction & DATA_DIR_TX) |
507 | val |= SPI_IE_TX; | 557 | val |= SPI_IE_TX; |
@@ -512,7 +562,18 @@ static int tegra_spi_start_dma_based_transfer( | |||
512 | tegra_spi_writel(tspi, val, SPI_DMA_CTL); | 562 | tegra_spi_writel(tspi, val, SPI_DMA_CTL); |
513 | tspi->dma_control_reg = val; | 563 | tspi->dma_control_reg = val; |
514 | 564 | ||
565 | dma_sconfig.device_fc = true; | ||
515 | if (tspi->cur_direction & DATA_DIR_TX) { | 566 | if (tspi->cur_direction & DATA_DIR_TX) { |
567 | dma_sconfig.dst_addr = tspi->phys + SPI_TX_FIFO; | ||
568 | dma_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; | ||
569 | dma_sconfig.dst_maxburst = dma_burst; | ||
570 | ret = dmaengine_slave_config(tspi->tx_dma_chan, &dma_sconfig); | ||
571 | if (ret < 0) { | ||
572 | dev_err(tspi->dev, | ||
573 | "DMA slave config failed: %d\n", ret); | ||
574 | return ret; | ||
575 | } | ||
576 | |||
516 | tegra_spi_copy_client_txbuf_to_spi_txbuf(tspi, t); | 577 | tegra_spi_copy_client_txbuf_to_spi_txbuf(tspi, t); |
517 | ret = tegra_spi_start_tx_dma(tspi, len); | 578 | ret = tegra_spi_start_tx_dma(tspi, len); |
518 | if (ret < 0) { | 579 | if (ret < 0) { |
@@ -523,6 +584,16 @@ static int tegra_spi_start_dma_based_transfer( | |||
523 | } | 584 | } |
524 | 585 | ||
525 | if (tspi->cur_direction & DATA_DIR_RX) { | 586 | if (tspi->cur_direction & DATA_DIR_RX) { |
587 | dma_sconfig.src_addr = tspi->phys + SPI_RX_FIFO; | ||
588 | dma_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; | ||
589 | dma_sconfig.src_maxburst = dma_burst; | ||
590 | ret = dmaengine_slave_config(tspi->rx_dma_chan, &dma_sconfig); | ||
591 | if (ret < 0) { | ||
592 | dev_err(tspi->dev, | ||
593 | "DMA slave config failed: %d\n", ret); | ||
594 | return ret; | ||
595 | } | ||
596 | |||
526 | /* Make the dma buffer to read by dma */ | 597 | /* Make the dma buffer to read by dma */ |
527 | dma_sync_single_for_device(tspi->dev, tspi->rx_dma_phys, | 598 | dma_sync_single_for_device(tspi->dev, tspi->rx_dma_phys, |
528 | tspi->dma_buf_size, DMA_FROM_DEVICE); | 599 | tspi->dma_buf_size, DMA_FROM_DEVICE); |
@@ -582,7 +653,6 @@ static int tegra_spi_init_dma_param(struct tegra_spi_data *tspi, | |||
582 | u32 *dma_buf; | 653 | u32 *dma_buf; |
583 | dma_addr_t dma_phys; | 654 | dma_addr_t dma_phys; |
584 | int ret; | 655 | int ret; |
585 | struct dma_slave_config dma_sconfig; | ||
586 | 656 | ||
587 | dma_chan = dma_request_slave_channel_reason(tspi->dev, | 657 | dma_chan = dma_request_slave_channel_reason(tspi->dev, |
588 | dma_to_memory ? "rx" : "tx"); | 658 | dma_to_memory ? "rx" : "tx"); |
@@ -603,19 +673,6 @@ static int tegra_spi_init_dma_param(struct tegra_spi_data *tspi, | |||
603 | } | 673 | } |
604 | 674 | ||
605 | if (dma_to_memory) { | 675 | if (dma_to_memory) { |
606 | dma_sconfig.src_addr = tspi->phys + SPI_RX_FIFO; | ||
607 | dma_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; | ||
608 | dma_sconfig.src_maxburst = 0; | ||
609 | } else { | ||
610 | dma_sconfig.dst_addr = tspi->phys + SPI_TX_FIFO; | ||
611 | dma_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; | ||
612 | dma_sconfig.dst_maxburst = 0; | ||
613 | } | ||
614 | |||
615 | ret = dmaengine_slave_config(dma_chan, &dma_sconfig); | ||
616 | if (ret) | ||
617 | goto scrub; | ||
618 | if (dma_to_memory) { | ||
619 | tspi->rx_dma_chan = dma_chan; | 676 | tspi->rx_dma_chan = dma_chan; |
620 | tspi->rx_dma_buf = dma_buf; | 677 | tspi->rx_dma_buf = dma_buf; |
621 | tspi->rx_dma_phys = dma_phys; | 678 | tspi->rx_dma_phys = dma_phys; |
@@ -625,11 +682,6 @@ static int tegra_spi_init_dma_param(struct tegra_spi_data *tspi, | |||
625 | tspi->tx_dma_phys = dma_phys; | 682 | tspi->tx_dma_phys = dma_phys; |
626 | } | 683 | } |
627 | return 0; | 684 | return 0; |
628 | |||
629 | scrub: | ||
630 | dma_free_coherent(tspi->dev, tspi->dma_buf_size, dma_buf, dma_phys); | ||
631 | dma_release_channel(dma_chan); | ||
632 | return ret; | ||
633 | } | 685 | } |
634 | 686 | ||
635 | static void tegra_spi_deinit_dma_param(struct tegra_spi_data *tspi, | 687 | static void tegra_spi_deinit_dma_param(struct tegra_spi_data *tspi, |
@@ -735,6 +787,8 @@ static int tegra_spi_start_transfer_one(struct spi_device *spi, | |||
735 | 787 | ||
736 | if (tspi->is_packed) | 788 | if (tspi->is_packed) |
737 | command1 |= SPI_PACKED; | 789 | command1 |= SPI_PACKED; |
790 | else | ||
791 | command1 &= ~SPI_PACKED; | ||
738 | 792 | ||
739 | command1 &= ~(SPI_CS_SEL_MASK | SPI_TX_EN | SPI_RX_EN); | 793 | command1 &= ~(SPI_CS_SEL_MASK | SPI_TX_EN | SPI_RX_EN); |
740 | tspi->cur_direction = 0; | 794 | tspi->cur_direction = 0; |
@@ -753,6 +807,9 @@ static int tegra_spi_start_transfer_one(struct spi_device *spi, | |||
753 | dev_dbg(tspi->dev, "The def 0x%x and written 0x%x\n", | 807 | dev_dbg(tspi->dev, "The def 0x%x and written 0x%x\n", |
754 | tspi->def_command1_reg, (unsigned)command1); | 808 | tspi->def_command1_reg, (unsigned)command1); |
755 | 809 | ||
810 | ret = tegra_spi_flush_fifos(tspi); | ||
811 | if (ret < 0) | ||
812 | return ret; | ||
756 | if (total_fifo_words > SPI_FIFO_DEPTH) | 813 | if (total_fifo_words > SPI_FIFO_DEPTH) |
757 | ret = tegra_spi_start_dma_based_transfer(tspi, t); | 814 | ret = tegra_spi_start_dma_based_transfer(tspi, t); |
758 | else | 815 | else |
@@ -804,6 +861,19 @@ static void tegra_spi_transfer_delay(int delay) | |||
804 | udelay(delay % 1000); | 861 | udelay(delay % 1000); |
805 | } | 862 | } |
806 | 863 | ||
864 | static void tegra_spi_transfer_end(struct spi_device *spi) | ||
865 | { | ||
866 | struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master); | ||
867 | int cs_val = (spi->mode & SPI_CS_HIGH) ? 0 : 1; | ||
868 | |||
869 | if (cs_val) | ||
870 | tspi->command1_reg |= SPI_CS_SW_VAL; | ||
871 | else | ||
872 | tspi->command1_reg &= ~SPI_CS_SW_VAL; | ||
873 | tegra_spi_writel(tspi, tspi->command1_reg, SPI_COMMAND1); | ||
874 | tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1); | ||
875 | } | ||
876 | |||
807 | static int tegra_spi_transfer_one_message(struct spi_master *master, | 877 | static int tegra_spi_transfer_one_message(struct spi_master *master, |
808 | struct spi_message *msg) | 878 | struct spi_message *msg) |
809 | { | 879 | { |
@@ -843,7 +913,17 @@ static int tegra_spi_transfer_one_message(struct spi_master *master, | |||
843 | if (WARN_ON(ret == 0)) { | 913 | if (WARN_ON(ret == 0)) { |
844 | dev_err(tspi->dev, | 914 | dev_err(tspi->dev, |
845 | "spi transfer timeout, err %d\n", ret); | 915 | "spi transfer timeout, err %d\n", ret); |
916 | if (tspi->is_curr_dma_xfer && | ||
917 | (tspi->cur_direction & DATA_DIR_TX)) | ||
918 | dmaengine_terminate_all(tspi->tx_dma_chan); | ||
919 | if (tspi->is_curr_dma_xfer && | ||
920 | (tspi->cur_direction & DATA_DIR_RX)) | ||
921 | dmaengine_terminate_all(tspi->rx_dma_chan); | ||
846 | ret = -EIO; | 922 | ret = -EIO; |
923 | tegra_spi_flush_fifos(tspi); | ||
924 | reset_control_assert(tspi->rst); | ||
925 | udelay(2); | ||
926 | reset_control_deassert(tspi->rst); | ||
847 | goto complete_xfer; | 927 | goto complete_xfer; |
848 | } | 928 | } |
849 | 929 | ||
@@ -856,8 +936,7 @@ static int tegra_spi_transfer_one_message(struct spi_master *master, | |||
856 | 936 | ||
857 | complete_xfer: | 937 | complete_xfer: |
858 | if (ret < 0 || skip) { | 938 | if (ret < 0 || skip) { |
859 | tegra_spi_writel(tspi, tspi->def_command1_reg, | 939 | tegra_spi_transfer_end(spi); |
860 | SPI_COMMAND1); | ||
861 | tegra_spi_transfer_delay(xfer->delay_usecs); | 940 | tegra_spi_transfer_delay(xfer->delay_usecs); |
862 | goto exit; | 941 | goto exit; |
863 | } else if (list_is_last(&xfer->transfer_list, | 942 | } else if (list_is_last(&xfer->transfer_list, |
@@ -865,13 +944,11 @@ complete_xfer: | |||
865 | if (xfer->cs_change) | 944 | if (xfer->cs_change) |
866 | tspi->cs_control = spi; | 945 | tspi->cs_control = spi; |
867 | else { | 946 | else { |
868 | tegra_spi_writel(tspi, tspi->def_command1_reg, | 947 | tegra_spi_transfer_end(spi); |
869 | SPI_COMMAND1); | ||
870 | tegra_spi_transfer_delay(xfer->delay_usecs); | 948 | tegra_spi_transfer_delay(xfer->delay_usecs); |
871 | } | 949 | } |
872 | } else if (xfer->cs_change) { | 950 | } else if (xfer->cs_change) { |
873 | tegra_spi_writel(tspi, tspi->def_command1_reg, | 951 | tegra_spi_transfer_end(spi); |
874 | SPI_COMMAND1); | ||
875 | tegra_spi_transfer_delay(xfer->delay_usecs); | 952 | tegra_spi_transfer_delay(xfer->delay_usecs); |
876 | } | 953 | } |
877 | 954 | ||
@@ -894,11 +971,13 @@ static irqreturn_t handle_cpu_based_xfer(struct tegra_spi_data *tspi) | |||
894 | tspi->status_reg); | 971 | tspi->status_reg); |
895 | dev_err(tspi->dev, "CpuXfer 0x%08x:0x%08x\n", | 972 | dev_err(tspi->dev, "CpuXfer 0x%08x:0x%08x\n", |
896 | tspi->command1_reg, tspi->dma_control_reg); | 973 | tspi->command1_reg, tspi->dma_control_reg); |
974 | tegra_spi_flush_fifos(tspi); | ||
975 | complete(&tspi->xfer_completion); | ||
976 | spin_unlock_irqrestore(&tspi->lock, flags); | ||
897 | reset_control_assert(tspi->rst); | 977 | reset_control_assert(tspi->rst); |
898 | udelay(2); | 978 | udelay(2); |
899 | reset_control_deassert(tspi->rst); | 979 | reset_control_deassert(tspi->rst); |
900 | complete(&tspi->xfer_completion); | 980 | return IRQ_HANDLED; |
901 | goto exit; | ||
902 | } | 981 | } |
903 | 982 | ||
904 | if (tspi->cur_direction & DATA_DIR_RX) | 983 | if (tspi->cur_direction & DATA_DIR_RX) |
@@ -966,11 +1045,12 @@ static irqreturn_t handle_dma_based_xfer(struct tegra_spi_data *tspi) | |||
966 | tspi->status_reg); | 1045 | tspi->status_reg); |
967 | dev_err(tspi->dev, "DmaXfer 0x%08x:0x%08x\n", | 1046 | dev_err(tspi->dev, "DmaXfer 0x%08x:0x%08x\n", |
968 | tspi->command1_reg, tspi->dma_control_reg); | 1047 | tspi->command1_reg, tspi->dma_control_reg); |
1048 | tegra_spi_flush_fifos(tspi); | ||
1049 | complete(&tspi->xfer_completion); | ||
1050 | spin_unlock_irqrestore(&tspi->lock, flags); | ||
969 | reset_control_assert(tspi->rst); | 1051 | reset_control_assert(tspi->rst); |
970 | udelay(2); | 1052 | udelay(2); |
971 | reset_control_deassert(tspi->rst); | 1053 | reset_control_deassert(tspi->rst); |
972 | complete(&tspi->xfer_completion); | ||
973 | spin_unlock_irqrestore(&tspi->lock, flags); | ||
974 | return IRQ_HANDLED; | 1054 | return IRQ_HANDLED; |
975 | } | 1055 | } |
976 | 1056 | ||
@@ -1072,27 +1152,19 @@ static int tegra_spi_probe(struct platform_device *pdev) | |||
1072 | 1152 | ||
1073 | spi_irq = platform_get_irq(pdev, 0); | 1153 | spi_irq = platform_get_irq(pdev, 0); |
1074 | tspi->irq = spi_irq; | 1154 | tspi->irq = spi_irq; |
1075 | ret = request_threaded_irq(tspi->irq, tegra_spi_isr, | ||
1076 | tegra_spi_isr_thread, IRQF_ONESHOT, | ||
1077 | dev_name(&pdev->dev), tspi); | ||
1078 | if (ret < 0) { | ||
1079 | dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n", | ||
1080 | tspi->irq); | ||
1081 | goto exit_free_master; | ||
1082 | } | ||
1083 | 1155 | ||
1084 | tspi->clk = devm_clk_get(&pdev->dev, "spi"); | 1156 | tspi->clk = devm_clk_get(&pdev->dev, "spi"); |
1085 | if (IS_ERR(tspi->clk)) { | 1157 | if (IS_ERR(tspi->clk)) { |
1086 | dev_err(&pdev->dev, "can not get clock\n"); | 1158 | dev_err(&pdev->dev, "can not get clock\n"); |
1087 | ret = PTR_ERR(tspi->clk); | 1159 | ret = PTR_ERR(tspi->clk); |
1088 | goto exit_free_irq; | 1160 | goto exit_free_master; |
1089 | } | 1161 | } |
1090 | 1162 | ||
1091 | tspi->rst = devm_reset_control_get_exclusive(&pdev->dev, "spi"); | 1163 | tspi->rst = devm_reset_control_get_exclusive(&pdev->dev, "spi"); |
1092 | if (IS_ERR(tspi->rst)) { | 1164 | if (IS_ERR(tspi->rst)) { |
1093 | dev_err(&pdev->dev, "can not get reset\n"); | 1165 | dev_err(&pdev->dev, "can not get reset\n"); |
1094 | ret = PTR_ERR(tspi->rst); | 1166 | ret = PTR_ERR(tspi->rst); |
1095 | goto exit_free_irq; | 1167 | goto exit_free_master; |
1096 | } | 1168 | } |
1097 | 1169 | ||
1098 | tspi->max_buf_size = SPI_FIFO_DEPTH << 2; | 1170 | tspi->max_buf_size = SPI_FIFO_DEPTH << 2; |
@@ -1100,7 +1172,7 @@ static int tegra_spi_probe(struct platform_device *pdev) | |||
1100 | 1172 | ||
1101 | ret = tegra_spi_init_dma_param(tspi, true); | 1173 | ret = tegra_spi_init_dma_param(tspi, true); |
1102 | if (ret < 0) | 1174 | if (ret < 0) |
1103 | goto exit_free_irq; | 1175 | goto exit_free_master; |
1104 | ret = tegra_spi_init_dma_param(tspi, false); | 1176 | ret = tegra_spi_init_dma_param(tspi, false); |
1105 | if (ret < 0) | 1177 | if (ret < 0) |
1106 | goto exit_rx_dma_free; | 1178 | goto exit_rx_dma_free; |
@@ -1122,18 +1194,32 @@ static int tegra_spi_probe(struct platform_device *pdev) | |||
1122 | dev_err(&pdev->dev, "pm runtime get failed, e = %d\n", ret); | 1194 | dev_err(&pdev->dev, "pm runtime get failed, e = %d\n", ret); |
1123 | goto exit_pm_disable; | 1195 | goto exit_pm_disable; |
1124 | } | 1196 | } |
1197 | |||
1198 | reset_control_assert(tspi->rst); | ||
1199 | udelay(2); | ||
1200 | reset_control_deassert(tspi->rst); | ||
1125 | tspi->def_command1_reg = SPI_M_S; | 1201 | tspi->def_command1_reg = SPI_M_S; |
1126 | tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1); | 1202 | tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1); |
1127 | pm_runtime_put(&pdev->dev); | 1203 | pm_runtime_put(&pdev->dev); |
1204 | ret = request_threaded_irq(tspi->irq, tegra_spi_isr, | ||
1205 | tegra_spi_isr_thread, IRQF_ONESHOT, | ||
1206 | dev_name(&pdev->dev), tspi); | ||
1207 | if (ret < 0) { | ||
1208 | dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n", | ||
1209 | tspi->irq); | ||
1210 | goto exit_pm_disable; | ||
1211 | } | ||
1128 | 1212 | ||
1129 | master->dev.of_node = pdev->dev.of_node; | 1213 | master->dev.of_node = pdev->dev.of_node; |
1130 | ret = devm_spi_register_master(&pdev->dev, master); | 1214 | ret = devm_spi_register_master(&pdev->dev, master); |
1131 | if (ret < 0) { | 1215 | if (ret < 0) { |
1132 | dev_err(&pdev->dev, "can not register to master err %d\n", ret); | 1216 | dev_err(&pdev->dev, "can not register to master err %d\n", ret); |
1133 | goto exit_pm_disable; | 1217 | goto exit_free_irq; |
1134 | } | 1218 | } |
1135 | return ret; | 1219 | return ret; |
1136 | 1220 | ||
1221 | exit_free_irq: | ||
1222 | free_irq(spi_irq, tspi); | ||
1137 | exit_pm_disable: | 1223 | exit_pm_disable: |
1138 | pm_runtime_disable(&pdev->dev); | 1224 | pm_runtime_disable(&pdev->dev); |
1139 | if (!pm_runtime_status_suspended(&pdev->dev)) | 1225 | if (!pm_runtime_status_suspended(&pdev->dev)) |
@@ -1141,8 +1227,6 @@ exit_pm_disable: | |||
1141 | tegra_spi_deinit_dma_param(tspi, false); | 1227 | tegra_spi_deinit_dma_param(tspi, false); |
1142 | exit_rx_dma_free: | 1228 | exit_rx_dma_free: |
1143 | tegra_spi_deinit_dma_param(tspi, true); | 1229 | tegra_spi_deinit_dma_param(tspi, true); |
1144 | exit_free_irq: | ||
1145 | free_irq(spi_irq, tspi); | ||
1146 | exit_free_master: | 1230 | exit_free_master: |
1147 | spi_master_put(master); | 1231 | spi_master_put(master); |
1148 | return ret; | 1232 | return ret; |
diff --git a/drivers/spi/spi-tegra20-slink.c b/drivers/spi/spi-tegra20-slink.c index 1427f343b39a..6d4679126213 100644 --- a/drivers/spi/spi-tegra20-slink.c +++ b/drivers/spi/spi-tegra20-slink.c | |||
@@ -717,9 +717,6 @@ static int tegra_slink_start_transfer_one(struct spi_device *spi, | |||
717 | command2 = tspi->command2_reg; | 717 | command2 = tspi->command2_reg; |
718 | command2 &= ~(SLINK_RXEN | SLINK_TXEN); | 718 | command2 &= ~(SLINK_RXEN | SLINK_TXEN); |
719 | 719 | ||
720 | tegra_slink_writel(tspi, command, SLINK_COMMAND); | ||
721 | tspi->command_reg = command; | ||
722 | |||
723 | tspi->cur_direction = 0; | 720 | tspi->cur_direction = 0; |
724 | if (t->rx_buf) { | 721 | if (t->rx_buf) { |
725 | command2 |= SLINK_RXEN; | 722 | command2 |= SLINK_RXEN; |
@@ -729,9 +726,18 @@ static int tegra_slink_start_transfer_one(struct spi_device *spi, | |||
729 | command2 |= SLINK_TXEN; | 726 | command2 |= SLINK_TXEN; |
730 | tspi->cur_direction |= DATA_DIR_TX; | 727 | tspi->cur_direction |= DATA_DIR_TX; |
731 | } | 728 | } |
729 | |||
730 | /* | ||
731 | * Writing to the command2 register bevore the command register prevents | ||
732 | * a spike in chip_select line 0. This selects the chip_select line | ||
733 | * before changing the chip_select value. | ||
734 | */ | ||
732 | tegra_slink_writel(tspi, command2, SLINK_COMMAND2); | 735 | tegra_slink_writel(tspi, command2, SLINK_COMMAND2); |
733 | tspi->command2_reg = command2; | 736 | tspi->command2_reg = command2; |
734 | 737 | ||
738 | tegra_slink_writel(tspi, command, SLINK_COMMAND); | ||
739 | tspi->command_reg = command; | ||
740 | |||
735 | if (total_fifo_words > SLINK_FIFO_DEPTH) | 741 | if (total_fifo_words > SLINK_FIFO_DEPTH) |
736 | ret = tegra_slink_start_dma_based_transfer(tspi, t); | 742 | ret = tegra_slink_start_dma_based_transfer(tspi, t); |
737 | else | 743 | else |
diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c index fba3f180f233..8a5966963834 100644 --- a/drivers/spi/spi-topcliff-pch.c +++ b/drivers/spi/spi-topcliff-pch.c | |||
@@ -1299,18 +1299,27 @@ static void pch_free_dma_buf(struct pch_spi_board_data *board_dat, | |||
1299 | dma->rx_buf_virt, dma->rx_buf_dma); | 1299 | dma->rx_buf_virt, dma->rx_buf_dma); |
1300 | } | 1300 | } |
1301 | 1301 | ||
1302 | static void pch_alloc_dma_buf(struct pch_spi_board_data *board_dat, | 1302 | static int pch_alloc_dma_buf(struct pch_spi_board_data *board_dat, |
1303 | struct pch_spi_data *data) | 1303 | struct pch_spi_data *data) |
1304 | { | 1304 | { |
1305 | struct pch_spi_dma_ctrl *dma; | 1305 | struct pch_spi_dma_ctrl *dma; |
1306 | int ret; | ||
1306 | 1307 | ||
1307 | dma = &data->dma; | 1308 | dma = &data->dma; |
1309 | ret = 0; | ||
1308 | /* Get Consistent memory for Tx DMA */ | 1310 | /* Get Consistent memory for Tx DMA */ |
1309 | dma->tx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev, | 1311 | dma->tx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev, |
1310 | PCH_BUF_SIZE, &dma->tx_buf_dma, GFP_KERNEL); | 1312 | PCH_BUF_SIZE, &dma->tx_buf_dma, GFP_KERNEL); |
1313 | if (!dma->tx_buf_virt) | ||
1314 | ret = -ENOMEM; | ||
1315 | |||
1311 | /* Get Consistent memory for Rx DMA */ | 1316 | /* Get Consistent memory for Rx DMA */ |
1312 | dma->rx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev, | 1317 | dma->rx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev, |
1313 | PCH_BUF_SIZE, &dma->rx_buf_dma, GFP_KERNEL); | 1318 | PCH_BUF_SIZE, &dma->rx_buf_dma, GFP_KERNEL); |
1319 | if (!dma->rx_buf_virt) | ||
1320 | ret = -ENOMEM; | ||
1321 | |||
1322 | return ret; | ||
1314 | } | 1323 | } |
1315 | 1324 | ||
1316 | static int pch_spi_pd_probe(struct platform_device *plat_dev) | 1325 | static int pch_spi_pd_probe(struct platform_device *plat_dev) |
@@ -1387,7 +1396,9 @@ static int pch_spi_pd_probe(struct platform_device *plat_dev) | |||
1387 | 1396 | ||
1388 | if (use_dma) { | 1397 | if (use_dma) { |
1389 | dev_info(&plat_dev->dev, "Use DMA for data transfers\n"); | 1398 | dev_info(&plat_dev->dev, "Use DMA for data transfers\n"); |
1390 | pch_alloc_dma_buf(board_dat, data); | 1399 | ret = pch_alloc_dma_buf(board_dat, data); |
1400 | if (ret) | ||
1401 | goto err_spi_register_master; | ||
1391 | } | 1402 | } |
1392 | 1403 | ||
1393 | ret = spi_register_master(master); | 1404 | ret = spi_register_master(master); |
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index bd2a424672df..2ad20c735b61 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c | |||
@@ -2199,6 +2199,8 @@ static int spi_get_gpio_descs(struct spi_controller *ctlr) | |||
2199 | */ | 2199 | */ |
2200 | cs[i] = devm_gpiod_get_index_optional(dev, "cs", i, | 2200 | cs[i] = devm_gpiod_get_index_optional(dev, "cs", i, |
2201 | GPIOD_OUT_LOW); | 2201 | GPIOD_OUT_LOW); |
2202 | if (IS_ERR(cs[i])) | ||
2203 | return PTR_ERR(cs[i]); | ||
2202 | 2204 | ||
2203 | if (cs[i]) { | 2205 | if (cs[i]) { |
2204 | /* | 2206 | /* |