diff options
| -rw-r--r-- | drivers/spi/Kconfig | 2 | ||||
| -rw-r--r-- | drivers/spi/spi-sh-msiof.c | 529 | ||||
| -rw-r--r-- | drivers/spi/spi-sh.c | 15 | ||||
| -rw-r--r-- | drivers/spi/spi-topcliff-pch.c | 12 | ||||
| -rw-r--r-- | include/linux/spi/sh_msiof.h | 2 |
5 files changed, 495 insertions, 65 deletions
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 20bd055ea2d1..62e2242ad7e0 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig | |||
| @@ -446,7 +446,7 @@ config SPI_SC18IS602 | |||
| 446 | 446 | ||
| 447 | config SPI_SH_MSIOF | 447 | config SPI_SH_MSIOF |
| 448 | tristate "SuperH MSIOF SPI controller" | 448 | tristate "SuperH MSIOF SPI controller" |
| 449 | depends on HAVE_CLK | 449 | depends on HAVE_CLK && HAS_DMA |
| 450 | depends on SUPERH || ARCH_SHMOBILE || COMPILE_TEST | 450 | depends on SUPERH || ARCH_SHMOBILE || COMPILE_TEST |
| 451 | help | 451 | help |
| 452 | SPI driver for SuperH and SH Mobile MSIOF blocks. | 452 | SPI driver for SuperH and SH Mobile MSIOF blocks. |
diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c index 83c43707f093..2a4354dcd661 100644 --- a/drivers/spi/spi-sh-msiof.c +++ b/drivers/spi/spi-sh-msiof.c | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | * SuperH MSIOF SPI Master Interface | 2 | * SuperH MSIOF SPI Master Interface |
| 3 | * | 3 | * |
| 4 | * Copyright (c) 2009 Magnus Damm | 4 | * Copyright (c) 2009 Magnus Damm |
| 5 | * Copyright (C) 2014 Glider bvba | ||
| 5 | * | 6 | * |
| 6 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as | 8 | * it under the terms of the GNU General Public License version 2 as |
| @@ -13,6 +14,8 @@ | |||
| 13 | #include <linux/clk.h> | 14 | #include <linux/clk.h> |
| 14 | #include <linux/completion.h> | 15 | #include <linux/completion.h> |
| 15 | #include <linux/delay.h> | 16 | #include <linux/delay.h> |
| 17 | #include <linux/dma-mapping.h> | ||
| 18 | #include <linux/dmaengine.h> | ||
| 16 | #include <linux/err.h> | 19 | #include <linux/err.h> |
| 17 | #include <linux/gpio.h> | 20 | #include <linux/gpio.h> |
| 18 | #include <linux/interrupt.h> | 21 | #include <linux/interrupt.h> |
| @@ -23,6 +26,7 @@ | |||
| 23 | #include <linux/of_device.h> | 26 | #include <linux/of_device.h> |
| 24 | #include <linux/platform_device.h> | 27 | #include <linux/platform_device.h> |
| 25 | #include <linux/pm_runtime.h> | 28 | #include <linux/pm_runtime.h> |
| 29 | #include <linux/sh_dma.h> | ||
| 26 | 30 | ||
| 27 | #include <linux/spi/sh_msiof.h> | 31 | #include <linux/spi/sh_msiof.h> |
| 28 | #include <linux/spi/spi.h> | 32 | #include <linux/spi/spi.h> |
| @@ -37,6 +41,7 @@ struct sh_msiof_chipdata { | |||
| 37 | }; | 41 | }; |
| 38 | 42 | ||
| 39 | struct sh_msiof_spi_priv { | 43 | struct sh_msiof_spi_priv { |
| 44 | struct spi_master *master; | ||
| 40 | void __iomem *mapbase; | 45 | void __iomem *mapbase; |
| 41 | struct clk *clk; | 46 | struct clk *clk; |
| 42 | struct platform_device *pdev; | 47 | struct platform_device *pdev; |
| @@ -45,6 +50,10 @@ struct sh_msiof_spi_priv { | |||
| 45 | struct completion done; | 50 | struct completion done; |
| 46 | int tx_fifo_size; | 51 | int tx_fifo_size; |
| 47 | int rx_fifo_size; | 52 | int rx_fifo_size; |
| 53 | void *tx_dma_page; | ||
| 54 | void *rx_dma_page; | ||
| 55 | dma_addr_t tx_dma_addr; | ||
| 56 | dma_addr_t rx_dma_addr; | ||
| 48 | }; | 57 | }; |
| 49 | 58 | ||
| 50 | #define TMDR1 0x00 /* Transmit Mode Register 1 */ | 59 | #define TMDR1 0x00 /* Transmit Mode Register 1 */ |
| @@ -84,6 +93,8 @@ struct sh_msiof_spi_priv { | |||
| 84 | #define MDR2_WDLEN1(i) (((i) - 1) << 16) /* Word Count (1-64/256 (SH, A1))) */ | 93 | #define MDR2_WDLEN1(i) (((i) - 1) << 16) /* Word Count (1-64/256 (SH, A1))) */ |
| 85 | #define MDR2_GRPMASK1 0x00000001 /* Group Output Mask 1 (SH, A1) */ | 94 | #define MDR2_GRPMASK1 0x00000001 /* Group Output Mask 1 (SH, A1) */ |
| 86 | 95 | ||
| 96 | #define MAX_WDLEN 256U | ||
| 97 | |||
| 87 | /* TSCR and RSCR */ | 98 | /* TSCR and RSCR */ |
| 88 | #define SCR_BRPS_MASK 0x1f00 /* Prescaler Setting (1-32) */ | 99 | #define SCR_BRPS_MASK 0x1f00 /* Prescaler Setting (1-32) */ |
| 89 | #define SCR_BRPS(i) (((i) - 1) << 8) | 100 | #define SCR_BRPS(i) (((i) - 1) << 8) |
| @@ -113,9 +124,61 @@ struct sh_msiof_spi_priv { | |||
| 113 | #define CTR_TXE 0x00000200 /* Transmit Enable */ | 124 | #define CTR_TXE 0x00000200 /* Transmit Enable */ |
| 114 | #define CTR_RXE 0x00000100 /* Receive Enable */ | 125 | #define CTR_RXE 0x00000100 /* Receive Enable */ |
| 115 | 126 | ||
| 116 | /* STR and IER */ | 127 | /* FCTR */ |
| 128 | #define FCTR_TFWM_MASK 0xe0000000 /* Transmit FIFO Watermark */ | ||
| 129 | #define FCTR_TFWM_64 0x00000000 /* Transfer Request when 64 empty stages */ | ||
| 130 | #define FCTR_TFWM_32 0x20000000 /* Transfer Request when 32 empty stages */ | ||
| 131 | #define FCTR_TFWM_24 0x40000000 /* Transfer Request when 24 empty stages */ | ||
| 132 | #define FCTR_TFWM_16 0x60000000 /* Transfer Request when 16 empty stages */ | ||
| 133 | #define FCTR_TFWM_12 0x80000000 /* Transfer Request when 12 empty stages */ | ||
| 134 | #define FCTR_TFWM_8 0xa0000000 /* Transfer Request when 8 empty stages */ | ||
| 135 | #define FCTR_TFWM_4 0xc0000000 /* Transfer Request when 4 empty stages */ | ||
| 136 | #define FCTR_TFWM_1 0xe0000000 /* Transfer Request when 1 empty stage */ | ||
| 137 | #define FCTR_TFUA_MASK 0x07f00000 /* Transmit FIFO Usable Area */ | ||
| 138 | #define FCTR_TFUA_SHIFT 20 | ||
| 139 | #define FCTR_TFUA(i) ((i) << FCTR_TFUA_SHIFT) | ||
| 140 | #define FCTR_RFWM_MASK 0x0000e000 /* Receive FIFO Watermark */ | ||
| 141 | #define FCTR_RFWM_1 0x00000000 /* Transfer Request when 1 valid stages */ | ||
| 142 | #define FCTR_RFWM_4 0x00002000 /* Transfer Request when 4 valid stages */ | ||
| 143 | #define FCTR_RFWM_8 0x00004000 /* Transfer Request when 8 valid stages */ | ||
| 144 | #define FCTR_RFWM_16 0x00006000 /* Transfer Request when 16 valid stages */ | ||
| 145 | #define FCTR_RFWM_32 0x00008000 /* Transfer Request when 32 valid stages */ | ||
| 146 | #define FCTR_RFWM_64 0x0000a000 /* Transfer Request when 64 valid stages */ | ||
| 147 | #define FCTR_RFWM_128 0x0000c000 /* Transfer Request when 128 valid stages */ | ||
| 148 | #define FCTR_RFWM_256 0x0000e000 /* Transfer Request when 256 valid stages */ | ||
| 149 | #define FCTR_RFUA_MASK 0x00001ff0 /* Receive FIFO Usable Area (0x40 = full) */ | ||
| 150 | #define FCTR_RFUA_SHIFT 4 | ||
| 151 | #define FCTR_RFUA(i) ((i) << FCTR_RFUA_SHIFT) | ||
| 152 | |||
| 153 | /* STR */ | ||
| 154 | #define STR_TFEMP 0x20000000 /* Transmit FIFO Empty */ | ||
| 155 | #define STR_TDREQ 0x10000000 /* Transmit Data Transfer Request */ | ||
| 117 | #define STR_TEOF 0x00800000 /* Frame Transmission End */ | 156 | #define STR_TEOF 0x00800000 /* Frame Transmission End */ |
| 157 | #define STR_TFSERR 0x00200000 /* Transmit Frame Synchronization Error */ | ||
| 158 | #define STR_TFOVF 0x00100000 /* Transmit FIFO Overflow */ | ||
| 159 | #define STR_TFUDF 0x00080000 /* Transmit FIFO Underflow */ | ||
| 160 | #define STR_RFFUL 0x00002000 /* Receive FIFO Full */ | ||
| 161 | #define STR_RDREQ 0x00001000 /* Receive Data Transfer Request */ | ||
| 118 | #define STR_REOF 0x00000080 /* Frame Reception End */ | 162 | #define STR_REOF 0x00000080 /* Frame Reception End */ |
| 163 | #define STR_RFSERR 0x00000020 /* Receive Frame Synchronization Error */ | ||
| 164 | #define STR_RFUDF 0x00000010 /* Receive FIFO Underflow */ | ||
| 165 | #define STR_RFOVF 0x00000008 /* Receive FIFO Overflow */ | ||
| 166 | |||
| 167 | /* IER */ | ||
| 168 | #define IER_TDMAE 0x80000000 /* Transmit Data DMA Transfer Req. Enable */ | ||
| 169 | #define IER_TFEMPE 0x20000000 /* Transmit FIFO Empty Enable */ | ||
| 170 | #define IER_TDREQE 0x10000000 /* Transmit Data Transfer Request Enable */ | ||
| 171 | #define IER_TEOFE 0x00800000 /* Frame Transmission End Enable */ | ||
| 172 | #define IER_TFSERRE 0x00200000 /* Transmit Frame Sync Error Enable */ | ||
| 173 | #define IER_TFOVFE 0x00100000 /* Transmit FIFO Overflow Enable */ | ||
| 174 | #define IER_TFUDFE 0x00080000 /* Transmit FIFO Underflow Enable */ | ||
| 175 | #define IER_RDMAE 0x00008000 /* Receive Data DMA Transfer Req. Enable */ | ||
| 176 | #define IER_RFFULE 0x00002000 /* Receive FIFO Full Enable */ | ||
| 177 | #define IER_RDREQE 0x00001000 /* Receive Data Transfer Request Enable */ | ||
| 178 | #define IER_REOFE 0x00000080 /* Frame Reception End Enable */ | ||
| 179 | #define IER_RFSERRE 0x00000020 /* Receive Frame Sync Error Enable */ | ||
| 180 | #define IER_RFUDFE 0x00000010 /* Receive FIFO Underflow Enable */ | ||
| 181 | #define IER_RFOVFE 0x00000008 /* Receive FIFO Overflow Enable */ | ||
| 119 | 182 | ||
| 120 | 183 | ||
| 121 | static u32 sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs) | 184 | static u32 sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs) |
| @@ -230,8 +293,6 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, | |||
| 230 | * 1 0 11 11 0 0 | 293 | * 1 0 11 11 0 0 |
| 231 | * 1 1 11 11 1 1 | 294 | * 1 1 11 11 1 1 |
| 232 | */ | 295 | */ |
| 233 | sh_msiof_write(p, FCTR, 0); | ||
| 234 | |||
| 235 | tmp = MDR1_SYNCMD_SPI | 1 << MDR1_FLD_SHIFT | MDR1_XXSTP; | 296 | tmp = MDR1_SYNCMD_SPI | 1 << MDR1_FLD_SHIFT | MDR1_XXSTP; |
| 236 | tmp |= !cs_high << MDR1_SYNCAC_SHIFT; | 297 | tmp |= !cs_high << MDR1_SYNCAC_SHIFT; |
| 237 | tmp |= lsb_first << MDR1_BITLSB_SHIFT; | 298 | tmp |= lsb_first << MDR1_BITLSB_SHIFT; |
| @@ -267,8 +328,6 @@ static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p, | |||
| 267 | 328 | ||
| 268 | if (rx_buf) | 329 | if (rx_buf) |
| 269 | sh_msiof_write(p, RMDR2, dr2); | 330 | sh_msiof_write(p, RMDR2, dr2); |
| 270 | |||
| 271 | sh_msiof_write(p, IER, STR_TEOF | STR_REOF); | ||
| 272 | } | 331 | } |
| 273 | 332 | ||
| 274 | static void sh_msiof_reset_str(struct sh_msiof_spi_priv *p) | 333 | static void sh_msiof_reset_str(struct sh_msiof_spi_priv *p) |
| @@ -457,6 +516,40 @@ static int sh_msiof_prepare_message(struct spi_master *master, | |||
| 457 | return 0; | 516 | return 0; |
| 458 | } | 517 | } |
| 459 | 518 | ||
| 519 | static int sh_msiof_spi_start(struct sh_msiof_spi_priv *p, void *rx_buf) | ||
| 520 | { | ||
| 521 | int ret; | ||
| 522 | |||
| 523 | /* setup clock and rx/tx signals */ | ||
| 524 | ret = sh_msiof_modify_ctr_wait(p, 0, CTR_TSCKE); | ||
| 525 | if (rx_buf && !ret) | ||
| 526 | ret = sh_msiof_modify_ctr_wait(p, 0, CTR_RXE); | ||
| 527 | if (!ret) | ||
| 528 | ret = sh_msiof_modify_ctr_wait(p, 0, CTR_TXE); | ||
| 529 | |||
| 530 | /* start by setting frame bit */ | ||
| 531 | if (!ret) | ||
| 532 | ret = sh_msiof_modify_ctr_wait(p, 0, CTR_TFSE); | ||
| 533 | |||
| 534 | return ret; | ||
| 535 | } | ||
| 536 | |||
| 537 | static int sh_msiof_spi_stop(struct sh_msiof_spi_priv *p, void *rx_buf) | ||
| 538 | { | ||
| 539 | int ret; | ||
| 540 | |||
| 541 | /* shut down frame, rx/tx and clock signals */ | ||
| 542 | ret = sh_msiof_modify_ctr_wait(p, CTR_TFSE, 0); | ||
| 543 | if (!ret) | ||
| 544 | ret = sh_msiof_modify_ctr_wait(p, CTR_TXE, 0); | ||
| 545 | if (rx_buf && !ret) | ||
| 546 | ret = sh_msiof_modify_ctr_wait(p, CTR_RXE, 0); | ||
| 547 | if (!ret) | ||
| 548 | ret = sh_msiof_modify_ctr_wait(p, CTR_TSCKE, 0); | ||
| 549 | |||
| 550 | return ret; | ||
| 551 | } | ||
| 552 | |||
| 460 | static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, | 553 | static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, |
| 461 | void (*tx_fifo)(struct sh_msiof_spi_priv *, | 554 | void (*tx_fifo)(struct sh_msiof_spi_priv *, |
| 462 | const void *, int, int), | 555 | const void *, int, int), |
| @@ -477,29 +570,32 @@ static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, | |||
| 477 | /* the fifo contents need shifting */ | 570 | /* the fifo contents need shifting */ |
| 478 | fifo_shift = 32 - bits; | 571 | fifo_shift = 32 - bits; |
| 479 | 572 | ||
| 573 | /* default FIFO watermarks for PIO */ | ||
| 574 | sh_msiof_write(p, FCTR, 0); | ||
| 575 | |||
| 480 | /* setup msiof transfer mode registers */ | 576 | /* setup msiof transfer mode registers */ |
| 481 | sh_msiof_spi_set_mode_regs(p, tx_buf, rx_buf, bits, words); | 577 | sh_msiof_spi_set_mode_regs(p, tx_buf, rx_buf, bits, words); |
| 578 | sh_msiof_write(p, IER, IER_TEOFE | IER_REOFE); | ||
| 482 | 579 | ||
| 483 | /* write tx fifo */ | 580 | /* write tx fifo */ |
| 484 | if (tx_buf) | 581 | if (tx_buf) |
| 485 | tx_fifo(p, tx_buf, words, fifo_shift); | 582 | tx_fifo(p, tx_buf, words, fifo_shift); |
| 486 | 583 | ||
| 487 | /* setup clock and rx/tx signals */ | ||
| 488 | ret = sh_msiof_modify_ctr_wait(p, 0, CTR_TSCKE); | ||
| 489 | if (rx_buf) | ||
| 490 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_RXE); | ||
| 491 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_TXE); | ||
| 492 | |||
| 493 | /* start by setting frame bit */ | ||
| 494 | reinit_completion(&p->done); | 584 | reinit_completion(&p->done); |
| 495 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, 0, CTR_TFSE); | 585 | |
| 586 | ret = sh_msiof_spi_start(p, rx_buf); | ||
| 496 | if (ret) { | 587 | if (ret) { |
| 497 | dev_err(&p->pdev->dev, "failed to start hardware\n"); | 588 | dev_err(&p->pdev->dev, "failed to start hardware\n"); |
| 498 | goto err; | 589 | goto stop_ier; |
| 499 | } | 590 | } |
| 500 | 591 | ||
| 501 | /* wait for tx fifo to be emptied / rx fifo to be filled */ | 592 | /* wait for tx fifo to be emptied / rx fifo to be filled */ |
| 502 | wait_for_completion(&p->done); | 593 | ret = wait_for_completion_timeout(&p->done, HZ); |
| 594 | if (!ret) { | ||
| 595 | dev_err(&p->pdev->dev, "PIO timeout\n"); | ||
| 596 | ret = -ETIMEDOUT; | ||
| 597 | goto stop_reset; | ||
| 598 | } | ||
| 503 | 599 | ||
| 504 | /* read rx fifo */ | 600 | /* read rx fifo */ |
| 505 | if (rx_buf) | 601 | if (rx_buf) |
| @@ -508,41 +604,248 @@ static int sh_msiof_spi_txrx_once(struct sh_msiof_spi_priv *p, | |||
| 508 | /* clear status bits */ | 604 | /* clear status bits */ |
| 509 | sh_msiof_reset_str(p); | 605 | sh_msiof_reset_str(p); |
| 510 | 606 | ||
| 511 | /* shut down frame, rx/tx and clock signals */ | 607 | ret = sh_msiof_spi_stop(p, rx_buf); |
| 512 | ret = sh_msiof_modify_ctr_wait(p, CTR_TFSE, 0); | ||
| 513 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, CTR_TXE, 0); | ||
| 514 | if (rx_buf) | ||
| 515 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, CTR_RXE, 0); | ||
| 516 | ret = ret ? ret : sh_msiof_modify_ctr_wait(p, CTR_TSCKE, 0); | ||
| 517 | if (ret) { | 608 | if (ret) { |
| 518 | dev_err(&p->pdev->dev, "failed to shut down hardware\n"); | 609 | dev_err(&p->pdev->dev, "failed to shut down hardware\n"); |
| 519 | goto err; | 610 | return ret; |
| 520 | } | 611 | } |
| 521 | 612 | ||
| 522 | return words; | 613 | return words; |
| 523 | 614 | ||
| 524 | err: | 615 | stop_reset: |
| 616 | sh_msiof_reset_str(p); | ||
| 617 | sh_msiof_spi_stop(p, rx_buf); | ||
| 618 | stop_ier: | ||
| 525 | sh_msiof_write(p, IER, 0); | 619 | sh_msiof_write(p, IER, 0); |
| 526 | return ret; | 620 | return ret; |
| 527 | } | 621 | } |
| 528 | 622 | ||
| 623 | static void sh_msiof_dma_complete(void *arg) | ||
| 624 | { | ||
| 625 | struct sh_msiof_spi_priv *p = arg; | ||
| 626 | |||
| 627 | sh_msiof_write(p, IER, 0); | ||
| 628 | complete(&p->done); | ||
| 629 | } | ||
| 630 | |||
| 631 | static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx, | ||
| 632 | void *rx, unsigned int len) | ||
| 633 | { | ||
| 634 | u32 ier_bits = 0; | ||
| 635 | struct dma_async_tx_descriptor *desc_tx = NULL, *desc_rx = NULL; | ||
| 636 | dma_cookie_t cookie; | ||
| 637 | int ret; | ||
| 638 | |||
| 639 | if (tx) { | ||
| 640 | ier_bits |= IER_TDREQE | IER_TDMAE; | ||
| 641 | dma_sync_single_for_device(p->master->dma_tx->device->dev, | ||
| 642 | p->tx_dma_addr, len, DMA_TO_DEVICE); | ||
| 643 | desc_tx = dmaengine_prep_slave_single(p->master->dma_tx, | ||
| 644 | p->tx_dma_addr, len, DMA_TO_DEVICE, | ||
| 645 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | ||
| 646 | if (!desc_tx) | ||
| 647 | return -EAGAIN; | ||
| 648 | } | ||
| 649 | |||
| 650 | if (rx) { | ||
| 651 | ier_bits |= IER_RDREQE | IER_RDMAE; | ||
| 652 | desc_rx = dmaengine_prep_slave_single(p->master->dma_rx, | ||
| 653 | p->rx_dma_addr, len, DMA_FROM_DEVICE, | ||
| 654 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | ||
| 655 | if (!desc_rx) | ||
| 656 | return -EAGAIN; | ||
| 657 | } | ||
| 658 | |||
| 659 | /* 1 stage FIFO watermarks for DMA */ | ||
| 660 | sh_msiof_write(p, FCTR, FCTR_TFWM_1 | FCTR_RFWM_1); | ||
| 661 | |||
| 662 | /* setup msiof transfer mode registers (32-bit words) */ | ||
| 663 | sh_msiof_spi_set_mode_regs(p, tx, rx, 32, len / 4); | ||
| 664 | |||
| 665 | sh_msiof_write(p, IER, ier_bits); | ||
| 666 | |||
| 667 | reinit_completion(&p->done); | ||
| 668 | |||
| 669 | if (rx) { | ||
| 670 | desc_rx->callback = sh_msiof_dma_complete; | ||
| 671 | desc_rx->callback_param = p; | ||
| 672 | cookie = dmaengine_submit(desc_rx); | ||
| 673 | if (dma_submit_error(cookie)) { | ||
| 674 | ret = cookie; | ||
| 675 | goto stop_ier; | ||
| 676 | } | ||
| 677 | dma_async_issue_pending(p->master->dma_rx); | ||
| 678 | } | ||
| 679 | |||
| 680 | if (tx) { | ||
| 681 | if (rx) { | ||
| 682 | /* No callback */ | ||
| 683 | desc_tx->callback = NULL; | ||
| 684 | } else { | ||
| 685 | desc_tx->callback = sh_msiof_dma_complete; | ||
| 686 | desc_tx->callback_param = p; | ||
| 687 | } | ||
| 688 | cookie = dmaengine_submit(desc_tx); | ||
| 689 | if (dma_submit_error(cookie)) { | ||
| 690 | ret = cookie; | ||
| 691 | goto stop_rx; | ||
| 692 | } | ||
| 693 | dma_async_issue_pending(p->master->dma_tx); | ||
| 694 | } | ||
| 695 | |||
| 696 | ret = sh_msiof_spi_start(p, rx); | ||
| 697 | if (ret) { | ||
| 698 | dev_err(&p->pdev->dev, "failed to start hardware\n"); | ||
| 699 | goto stop_tx; | ||
| 700 | } | ||
| 701 | |||
| 702 | /* wait for tx fifo to be emptied / rx fifo to be filled */ | ||
| 703 | ret = wait_for_completion_timeout(&p->done, HZ); | ||
| 704 | if (!ret) { | ||
| 705 | dev_err(&p->pdev->dev, "DMA timeout\n"); | ||
| 706 | ret = -ETIMEDOUT; | ||
| 707 | goto stop_reset; | ||
| 708 | } | ||
| 709 | |||
| 710 | /* clear status bits */ | ||
| 711 | sh_msiof_reset_str(p); | ||
| 712 | |||
| 713 | ret = sh_msiof_spi_stop(p, rx); | ||
| 714 | if (ret) { | ||
| 715 | dev_err(&p->pdev->dev, "failed to shut down hardware\n"); | ||
| 716 | return ret; | ||
| 717 | } | ||
| 718 | |||
| 719 | if (rx) | ||
| 720 | dma_sync_single_for_cpu(p->master->dma_rx->device->dev, | ||
| 721 | p->rx_dma_addr, len, | ||
| 722 | DMA_FROM_DEVICE); | ||
| 723 | |||
| 724 | return 0; | ||
| 725 | |||
| 726 | stop_reset: | ||
| 727 | sh_msiof_reset_str(p); | ||
| 728 | sh_msiof_spi_stop(p, rx); | ||
| 729 | stop_tx: | ||
| 730 | if (tx) | ||
| 731 | dmaengine_terminate_all(p->master->dma_tx); | ||
| 732 | stop_rx: | ||
| 733 | if (rx) | ||
| 734 | dmaengine_terminate_all(p->master->dma_rx); | ||
| 735 | stop_ier: | ||
| 736 | sh_msiof_write(p, IER, 0); | ||
| 737 | return ret; | ||
| 738 | } | ||
| 739 | |||
| 740 | static void copy_bswap32(u32 *dst, const u32 *src, unsigned int words) | ||
| 741 | { | ||
| 742 | /* src or dst can be unaligned, but not both */ | ||
| 743 | if ((unsigned long)src & 3) { | ||
| 744 | while (words--) { | ||
| 745 | *dst++ = swab32(get_unaligned(src)); | ||
| 746 | src++; | ||
| 747 | } | ||
| 748 | } else if ((unsigned long)dst & 3) { | ||
| 749 | while (words--) { | ||
| 750 | put_unaligned(swab32(*src++), dst); | ||
| 751 | dst++; | ||
| 752 | } | ||
| 753 | } else { | ||
| 754 | while (words--) | ||
| 755 | *dst++ = swab32(*src++); | ||
| 756 | } | ||
| 757 | } | ||
| 758 | |||
| 759 | static void copy_wswap32(u32 *dst, const u32 *src, unsigned int words) | ||
| 760 | { | ||
| 761 | /* src or dst can be unaligned, but not both */ | ||
| 762 | if ((unsigned long)src & 3) { | ||
| 763 | while (words--) { | ||
| 764 | *dst++ = swahw32(get_unaligned(src)); | ||
| 765 | src++; | ||
| 766 | } | ||
| 767 | } else if ((unsigned long)dst & 3) { | ||
| 768 | while (words--) { | ||
| 769 | put_unaligned(swahw32(*src++), dst); | ||
| 770 | dst++; | ||
| 771 | } | ||
| 772 | } else { | ||
| 773 | while (words--) | ||
| 774 | *dst++ = swahw32(*src++); | ||
| 775 | } | ||
| 776 | } | ||
| 777 | |||
| 778 | static void copy_plain32(u32 *dst, const u32 *src, unsigned int words) | ||
| 779 | { | ||
| 780 | memcpy(dst, src, words * 4); | ||
| 781 | } | ||
| 782 | |||
| 529 | static int sh_msiof_transfer_one(struct spi_master *master, | 783 | static int sh_msiof_transfer_one(struct spi_master *master, |
| 530 | struct spi_device *spi, | 784 | struct spi_device *spi, |
| 531 | struct spi_transfer *t) | 785 | struct spi_transfer *t) |
| 532 | { | 786 | { |
| 533 | struct sh_msiof_spi_priv *p = spi_master_get_devdata(master); | 787 | struct sh_msiof_spi_priv *p = spi_master_get_devdata(master); |
| 788 | void (*copy32)(u32 *, const u32 *, unsigned int); | ||
| 534 | void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int); | 789 | void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int); |
| 535 | void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int); | 790 | void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int); |
| 536 | int bits; | 791 | const void *tx_buf = t->tx_buf; |
| 537 | int bytes_per_word; | 792 | void *rx_buf = t->rx_buf; |
| 538 | int bytes_done; | 793 | unsigned int len = t->len; |
| 539 | int words; | 794 | unsigned int bits = t->bits_per_word; |
| 795 | unsigned int bytes_per_word; | ||
| 796 | unsigned int words; | ||
| 540 | int n; | 797 | int n; |
| 541 | bool swab; | 798 | bool swab; |
| 799 | int ret; | ||
| 542 | 800 | ||
| 543 | bits = t->bits_per_word; | 801 | /* setup clocks (clock already enabled in chipselect()) */ |
| 802 | sh_msiof_spi_set_clk_regs(p, clk_get_rate(p->clk), t->speed_hz); | ||
| 544 | 803 | ||
| 545 | if (bits <= 8 && t->len > 15 && !(t->len & 3)) { | 804 | while (master->dma_tx && len > 15) { |
| 805 | /* | ||
| 806 | * DMA supports 32-bit words only, hence pack 8-bit and 16-bit | ||
| 807 | * words, with byte resp. word swapping. | ||
| 808 | */ | ||
| 809 | unsigned int l = min(len, MAX_WDLEN * 4); | ||
| 810 | |||
| 811 | if (bits <= 8) { | ||
| 812 | if (l & 3) | ||
| 813 | break; | ||
| 814 | copy32 = copy_bswap32; | ||
| 815 | } else if (bits <= 16) { | ||
| 816 | if (l & 1) | ||
| 817 | break; | ||
| 818 | copy32 = copy_wswap32; | ||
| 819 | } else { | ||
| 820 | copy32 = copy_plain32; | ||
| 821 | } | ||
| 822 | |||
| 823 | if (tx_buf) | ||
| 824 | copy32(p->tx_dma_page, tx_buf, l / 4); | ||
| 825 | |||
| 826 | ret = sh_msiof_dma_once(p, tx_buf, rx_buf, l); | ||
| 827 | if (ret == -EAGAIN) { | ||
| 828 | pr_warn_once("%s %s: DMA not available, falling back to PIO\n", | ||
| 829 | dev_driver_string(&p->pdev->dev), | ||
| 830 | dev_name(&p->pdev->dev)); | ||
| 831 | break; | ||
| 832 | } | ||
| 833 | if (ret) | ||
| 834 | return ret; | ||
| 835 | |||
| 836 | if (rx_buf) { | ||
| 837 | copy32(rx_buf, p->rx_dma_page, l / 4); | ||
| 838 | rx_buf += l; | ||
| 839 | } | ||
| 840 | if (tx_buf) | ||
| 841 | tx_buf += l; | ||
| 842 | |||
| 843 | len -= l; | ||
| 844 | if (!len) | ||
| 845 | return 0; | ||
| 846 | } | ||
| 847 | |||
| 848 | if (bits <= 8 && len > 15 && !(len & 3)) { | ||
| 546 | bits = 32; | 849 | bits = 32; |
| 547 | swab = true; | 850 | swab = true; |
| 548 | } else { | 851 | } else { |
| @@ -556,57 +859,52 @@ static int sh_msiof_transfer_one(struct spi_master *master, | |||
| 556 | rx_fifo = sh_msiof_spi_read_fifo_8; | 859 | rx_fifo = sh_msiof_spi_read_fifo_8; |
| 557 | } else if (bits <= 16) { | 860 | } else if (bits <= 16) { |
| 558 | bytes_per_word = 2; | 861 | bytes_per_word = 2; |
| 559 | if ((unsigned long)t->tx_buf & 0x01) | 862 | if ((unsigned long)tx_buf & 0x01) |
| 560 | tx_fifo = sh_msiof_spi_write_fifo_16u; | 863 | tx_fifo = sh_msiof_spi_write_fifo_16u; |
| 561 | else | 864 | else |
| 562 | tx_fifo = sh_msiof_spi_write_fifo_16; | 865 | tx_fifo = sh_msiof_spi_write_fifo_16; |
| 563 | 866 | ||
| 564 | if ((unsigned long)t->rx_buf & 0x01) | 867 | if ((unsigned long)rx_buf & 0x01) |
| 565 | rx_fifo = sh_msiof_spi_read_fifo_16u; | 868 | rx_fifo = sh_msiof_spi_read_fifo_16u; |
| 566 | else | 869 | else |
| 567 | rx_fifo = sh_msiof_spi_read_fifo_16; | 870 | rx_fifo = sh_msiof_spi_read_fifo_16; |
| 568 | } else if (swab) { | 871 | } else if (swab) { |
| 569 | bytes_per_word = 4; | 872 | bytes_per_word = 4; |
| 570 | if ((unsigned long)t->tx_buf & 0x03) | 873 | if ((unsigned long)tx_buf & 0x03) |
| 571 | tx_fifo = sh_msiof_spi_write_fifo_s32u; | 874 | tx_fifo = sh_msiof_spi_write_fifo_s32u; |
| 572 | else | 875 | else |
| 573 | tx_fifo = sh_msiof_spi_write_fifo_s32; | 876 | tx_fifo = sh_msiof_spi_write_fifo_s32; |
| 574 | 877 | ||
| 575 | if ((unsigned long)t->rx_buf & 0x03) | 878 | if ((unsigned long)rx_buf & 0x03) |
| 576 | rx_fifo = sh_msiof_spi_read_fifo_s32u; | 879 | rx_fifo = sh_msiof_spi_read_fifo_s32u; |
| 577 | else | 880 | else |
| 578 | rx_fifo = sh_msiof_spi_read_fifo_s32; | 881 | rx_fifo = sh_msiof_spi_read_fifo_s32; |
| 579 | } else { | 882 | } else { |
| 580 | bytes_per_word = 4; | 883 | bytes_per_word = 4; |
| 581 | if ((unsigned long)t->tx_buf & 0x03) | 884 | if ((unsigned long)tx_buf & 0x03) |
| 582 | tx_fifo = sh_msiof_spi_write_fifo_32u; | 885 | tx_fifo = sh_msiof_spi_write_fifo_32u; |
| 583 | else | 886 | else |
| 584 | tx_fifo = sh_msiof_spi_write_fifo_32; | 887 | tx_fifo = sh_msiof_spi_write_fifo_32; |
| 585 | 888 | ||
| 586 | if ((unsigned long)t->rx_buf & 0x03) | 889 | if ((unsigned long)rx_buf & 0x03) |
| 587 | rx_fifo = sh_msiof_spi_read_fifo_32u; | 890 | rx_fifo = sh_msiof_spi_read_fifo_32u; |
| 588 | else | 891 | else |
| 589 | rx_fifo = sh_msiof_spi_read_fifo_32; | 892 | rx_fifo = sh_msiof_spi_read_fifo_32; |
| 590 | } | 893 | } |
| 591 | 894 | ||
| 592 | /* setup clocks (clock already enabled in chipselect()) */ | ||
| 593 | sh_msiof_spi_set_clk_regs(p, clk_get_rate(p->clk), t->speed_hz); | ||
| 594 | |||
| 595 | /* transfer in fifo sized chunks */ | 895 | /* transfer in fifo sized chunks */ |
| 596 | words = t->len / bytes_per_word; | 896 | words = len / bytes_per_word; |
| 597 | bytes_done = 0; | 897 | |
| 598 | 898 | while (words > 0) { | |
| 599 | while (bytes_done < t->len) { | 899 | n = sh_msiof_spi_txrx_once(p, tx_fifo, rx_fifo, tx_buf, rx_buf, |
| 600 | void *rx_buf = t->rx_buf ? t->rx_buf + bytes_done : NULL; | ||
| 601 | const void *tx_buf = t->tx_buf ? t->tx_buf + bytes_done : NULL; | ||
| 602 | n = sh_msiof_spi_txrx_once(p, tx_fifo, rx_fifo, | ||
| 603 | tx_buf, | ||
| 604 | rx_buf, | ||
| 605 | words, bits); | 900 | words, bits); |
| 606 | if (n < 0) | 901 | if (n < 0) |
| 607 | break; | 902 | return n; |
| 608 | 903 | ||
| 609 | bytes_done += n * bytes_per_word; | 904 | if (tx_buf) |
| 905 | tx_buf += n * bytes_per_word; | ||
| 906 | if (rx_buf) | ||
| 907 | rx_buf += n * bytes_per_word; | ||
| 610 | words -= n; | 908 | words -= n; |
| 611 | } | 909 | } |
| 612 | 910 | ||
| @@ -663,6 +961,128 @@ static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev) | |||
| 663 | } | 961 | } |
| 664 | #endif | 962 | #endif |
| 665 | 963 | ||
| 964 | static struct dma_chan *sh_msiof_request_dma_chan(struct device *dev, | ||
| 965 | enum dma_transfer_direction dir, unsigned int id, dma_addr_t port_addr) | ||
| 966 | { | ||
| 967 | dma_cap_mask_t mask; | ||
| 968 | struct dma_chan *chan; | ||
| 969 | struct dma_slave_config cfg; | ||
| 970 | int ret; | ||
| 971 | |||
| 972 | dma_cap_zero(mask); | ||
| 973 | dma_cap_set(DMA_SLAVE, mask); | ||
| 974 | |||
| 975 | chan = dma_request_channel(mask, shdma_chan_filter, | ||
| 976 | (void *)(unsigned long)id); | ||
| 977 | if (!chan) { | ||
| 978 | dev_warn(dev, "dma_request_channel failed\n"); | ||
| 979 | return NULL; | ||
| 980 | } | ||
| 981 | |||
| 982 | memset(&cfg, 0, sizeof(cfg)); | ||
| 983 | cfg.slave_id = id; | ||
| 984 | cfg.direction = dir; | ||
| 985 | if (dir == DMA_MEM_TO_DEV) | ||
| 986 | cfg.dst_addr = port_addr; | ||
| 987 | else | ||
| 988 | cfg.src_addr = port_addr; | ||
| 989 | |||
| 990 | ret = dmaengine_slave_config(chan, &cfg); | ||
| 991 | if (ret) { | ||
| 992 | dev_warn(dev, "dmaengine_slave_config failed %d\n", ret); | ||
| 993 | dma_release_channel(chan); | ||
| 994 | return NULL; | ||
| 995 | } | ||
| 996 | |||
| 997 | return chan; | ||
| 998 | } | ||
| 999 | |||
| 1000 | static int sh_msiof_request_dma(struct sh_msiof_spi_priv *p) | ||
| 1001 | { | ||
| 1002 | struct platform_device *pdev = p->pdev; | ||
| 1003 | struct device *dev = &pdev->dev; | ||
| 1004 | const struct sh_msiof_spi_info *info = dev_get_platdata(dev); | ||
| 1005 | const struct resource *res; | ||
| 1006 | struct spi_master *master; | ||
| 1007 | struct device *tx_dev, *rx_dev; | ||
| 1008 | |||
| 1009 | if (!info || !info->dma_tx_id || !info->dma_rx_id) | ||
| 1010 | return 0; /* The driver assumes no error */ | ||
| 1011 | |||
| 1012 | /* The DMA engine uses the second register set, if present */ | ||
| 1013 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | ||
| 1014 | if (!res) | ||
| 1015 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
| 1016 | |||
| 1017 | master = p->master; | ||
| 1018 | master->dma_tx = sh_msiof_request_dma_chan(dev, DMA_MEM_TO_DEV, | ||
| 1019 | info->dma_tx_id, | ||
| 1020 | res->start + TFDR); | ||
| 1021 | if (!master->dma_tx) | ||
| 1022 | return -ENODEV; | ||
| 1023 | |||
| 1024 | master->dma_rx = sh_msiof_request_dma_chan(dev, DMA_DEV_TO_MEM, | ||
| 1025 | info->dma_rx_id, | ||
| 1026 | res->start + RFDR); | ||
| 1027 | if (!master->dma_rx) | ||
| 1028 | goto free_tx_chan; | ||
| 1029 | |||
| 1030 | p->tx_dma_page = (void *)__get_free_page(GFP_KERNEL | GFP_DMA); | ||
| 1031 | if (!p->tx_dma_page) | ||
| 1032 | goto free_rx_chan; | ||
| 1033 | |||
| 1034 | p->rx_dma_page = (void *)__get_free_page(GFP_KERNEL | GFP_DMA); | ||
| 1035 | if (!p->rx_dma_page) | ||
| 1036 | goto free_tx_page; | ||
| 1037 | |||
| 1038 | tx_dev = master->dma_tx->device->dev; | ||
| 1039 | p->tx_dma_addr = dma_map_single(tx_dev, p->tx_dma_page, PAGE_SIZE, | ||
| 1040 | DMA_TO_DEVICE); | ||
| 1041 | if (dma_mapping_error(tx_dev, p->tx_dma_addr)) | ||
| 1042 | goto free_rx_page; | ||
| 1043 | |||
| 1044 | rx_dev = master->dma_rx->device->dev; | ||
| 1045 | p->rx_dma_addr = dma_map_single(rx_dev, p->rx_dma_page, PAGE_SIZE, | ||
| 1046 | DMA_FROM_DEVICE); | ||
| 1047 | if (dma_mapping_error(rx_dev, p->rx_dma_addr)) | ||
| 1048 | goto unmap_tx_page; | ||
| 1049 | |||
| 1050 | dev_info(dev, "DMA available"); | ||
| 1051 | return 0; | ||
| 1052 | |||
| 1053 | unmap_tx_page: | ||
| 1054 | dma_unmap_single(tx_dev, p->tx_dma_addr, PAGE_SIZE, DMA_TO_DEVICE); | ||
| 1055 | free_rx_page: | ||
| 1056 | free_page((unsigned long)p->rx_dma_page); | ||
| 1057 | free_tx_page: | ||
| 1058 | free_page((unsigned long)p->tx_dma_page); | ||
| 1059 | free_rx_chan: | ||
| 1060 | dma_release_channel(master->dma_rx); | ||
| 1061 | free_tx_chan: | ||
| 1062 | dma_release_channel(master->dma_tx); | ||
| 1063 | master->dma_tx = NULL; | ||
| 1064 | return -ENODEV; | ||
| 1065 | } | ||
| 1066 | |||
| 1067 | static void sh_msiof_release_dma(struct sh_msiof_spi_priv *p) | ||
| 1068 | { | ||
| 1069 | struct spi_master *master = p->master; | ||
| 1070 | struct device *dev; | ||
| 1071 | |||
| 1072 | if (!master->dma_tx) | ||
| 1073 | return; | ||
| 1074 | |||
| 1075 | dev = &p->pdev->dev; | ||
| 1076 | dma_unmap_single(master->dma_rx->device->dev, p->rx_dma_addr, | ||
| 1077 | PAGE_SIZE, DMA_FROM_DEVICE); | ||
| 1078 | dma_unmap_single(master->dma_tx->device->dev, p->tx_dma_addr, | ||
| 1079 | PAGE_SIZE, DMA_TO_DEVICE); | ||
| 1080 | free_page((unsigned long)p->rx_dma_page); | ||
| 1081 | free_page((unsigned long)p->tx_dma_page); | ||
| 1082 | dma_release_channel(master->dma_rx); | ||
| 1083 | dma_release_channel(master->dma_tx); | ||
| 1084 | } | ||
| 1085 | |||
| 666 | static int sh_msiof_spi_probe(struct platform_device *pdev) | 1086 | static int sh_msiof_spi_probe(struct platform_device *pdev) |
| 667 | { | 1087 | { |
| 668 | struct resource *r; | 1088 | struct resource *r; |
| @@ -680,6 +1100,9 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) | |||
| 680 | 1100 | ||
| 681 | p = spi_master_get_devdata(master); | 1101 | p = spi_master_get_devdata(master); |
| 682 | 1102 | ||
| 1103 | platform_set_drvdata(pdev, p); | ||
| 1104 | p->master = master; | ||
| 1105 | |||
| 683 | of_id = of_match_device(sh_msiof_match, &pdev->dev); | 1106 | of_id = of_match_device(sh_msiof_match, &pdev->dev); |
| 684 | if (of_id) { | 1107 | if (of_id) { |
| 685 | p->chipdata = of_id->data; | 1108 | p->chipdata = of_id->data; |
| @@ -749,6 +1172,10 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) | |||
| 749 | master->auto_runtime_pm = true; | 1172 | master->auto_runtime_pm = true; |
| 750 | master->transfer_one = sh_msiof_transfer_one; | 1173 | master->transfer_one = sh_msiof_transfer_one; |
| 751 | 1174 | ||
| 1175 | ret = sh_msiof_request_dma(p); | ||
| 1176 | if (ret < 0) | ||
| 1177 | dev_warn(&pdev->dev, "DMA not available, using PIO\n"); | ||
| 1178 | |||
| 752 | ret = devm_spi_register_master(&pdev->dev, master); | 1179 | ret = devm_spi_register_master(&pdev->dev, master); |
| 753 | if (ret < 0) { | 1180 | if (ret < 0) { |
| 754 | dev_err(&pdev->dev, "spi_register_master error.\n"); | 1181 | dev_err(&pdev->dev, "spi_register_master error.\n"); |
| @@ -758,6 +1185,7 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) | |||
| 758 | return 0; | 1185 | return 0; |
| 759 | 1186 | ||
| 760 | err2: | 1187 | err2: |
| 1188 | sh_msiof_release_dma(p); | ||
| 761 | pm_runtime_disable(&pdev->dev); | 1189 | pm_runtime_disable(&pdev->dev); |
| 762 | err1: | 1190 | err1: |
| 763 | spi_master_put(master); | 1191 | spi_master_put(master); |
| @@ -766,6 +1194,9 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) | |||
| 766 | 1194 | ||
| 767 | static int sh_msiof_spi_remove(struct platform_device *pdev) | 1195 | static int sh_msiof_spi_remove(struct platform_device *pdev) |
| 768 | { | 1196 | { |
| 1197 | struct sh_msiof_spi_priv *p = platform_get_drvdata(pdev); | ||
| 1198 | |||
| 1199 | sh_msiof_release_dma(p); | ||
| 769 | pm_runtime_disable(&pdev->dev); | 1200 | pm_runtime_disable(&pdev->dev); |
| 770 | return 0; | 1201 | return 0; |
| 771 | } | 1202 | } |
diff --git a/drivers/spi/spi-sh.c b/drivers/spi/spi-sh.c index 03edf5ed0e9f..8e171a76049f 100644 --- a/drivers/spi/spi-sh.c +++ b/drivers/spi/spi-sh.c | |||
| @@ -432,7 +432,6 @@ static int spi_sh_remove(struct platform_device *pdev) | |||
| 432 | spi_unregister_master(ss->master); | 432 | spi_unregister_master(ss->master); |
| 433 | destroy_workqueue(ss->workqueue); | 433 | destroy_workqueue(ss->workqueue); |
| 434 | free_irq(ss->irq, ss); | 434 | free_irq(ss->irq, ss); |
| 435 | iounmap(ss->addr); | ||
| 436 | 435 | ||
| 437 | return 0; | 436 | return 0; |
| 438 | } | 437 | } |
| @@ -480,7 +479,7 @@ static int spi_sh_probe(struct platform_device *pdev) | |||
| 480 | } | 479 | } |
| 481 | ss->irq = irq; | 480 | ss->irq = irq; |
| 482 | ss->master = master; | 481 | ss->master = master; |
| 483 | ss->addr = ioremap(res->start, resource_size(res)); | 482 | ss->addr = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
| 484 | if (ss->addr == NULL) { | 483 | if (ss->addr == NULL) { |
| 485 | dev_err(&pdev->dev, "ioremap error.\n"); | 484 | dev_err(&pdev->dev, "ioremap error.\n"); |
| 486 | ret = -ENOMEM; | 485 | ret = -ENOMEM; |
| @@ -495,13 +494,13 @@ static int spi_sh_probe(struct platform_device *pdev) | |||
| 495 | if (ss->workqueue == NULL) { | 494 | if (ss->workqueue == NULL) { |
| 496 | dev_err(&pdev->dev, "create workqueue error\n"); | 495 | dev_err(&pdev->dev, "create workqueue error\n"); |
| 497 | ret = -EBUSY; | 496 | ret = -EBUSY; |
| 498 | goto error2; | 497 | goto error1; |
| 499 | } | 498 | } |
| 500 | 499 | ||
| 501 | ret = request_irq(irq, spi_sh_irq, 0, "spi_sh", ss); | 500 | ret = request_irq(irq, spi_sh_irq, 0, "spi_sh", ss); |
| 502 | if (ret < 0) { | 501 | if (ret < 0) { |
| 503 | dev_err(&pdev->dev, "request_irq error\n"); | 502 | dev_err(&pdev->dev, "request_irq error\n"); |
| 504 | goto error3; | 503 | goto error2; |
| 505 | } | 504 | } |
| 506 | 505 | ||
| 507 | master->num_chipselect = 2; | 506 | master->num_chipselect = 2; |
| @@ -513,17 +512,15 @@ static int spi_sh_probe(struct platform_device *pdev) | |||
| 513 | ret = spi_register_master(master); | 512 | ret = spi_register_master(master); |
| 514 | if (ret < 0) { | 513 | if (ret < 0) { |
| 515 | printk(KERN_ERR "spi_register_master error.\n"); | 514 | printk(KERN_ERR "spi_register_master error.\n"); |
| 516 | goto error4; | 515 | goto error3; |
| 517 | } | 516 | } |
| 518 | 517 | ||
| 519 | return 0; | 518 | return 0; |
| 520 | 519 | ||
| 521 | error4: | ||
| 522 | free_irq(irq, ss); | ||
| 523 | error3: | 520 | error3: |
| 524 | destroy_workqueue(ss->workqueue); | 521 | free_irq(irq, ss); |
| 525 | error2: | 522 | error2: |
| 526 | iounmap(ss->addr); | 523 | destroy_workqueue(ss->workqueue); |
| 527 | error1: | 524 | error1: |
| 528 | spi_master_put(master); | 525 | spi_master_put(master); |
| 529 | 526 | ||
diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c index f05abf89c067..0a87ec39f619 100644 --- a/drivers/spi/spi-topcliff-pch.c +++ b/drivers/spi/spi-topcliff-pch.c | |||
| @@ -874,8 +874,8 @@ static void pch_spi_request_dma(struct pch_spi_data *data, int bpw) | |||
| 874 | dma_cap_set(DMA_SLAVE, mask); | 874 | dma_cap_set(DMA_SLAVE, mask); |
| 875 | 875 | ||
| 876 | /* Get DMA's dev information */ | 876 | /* Get DMA's dev information */ |
| 877 | dma_dev = pci_get_bus_and_slot(data->board_dat->pdev->bus->number, | 877 | dma_dev = pci_get_slot(data->board_dat->pdev->bus, |
| 878 | PCI_DEVFN(12, 0)); | 878 | PCI_DEVFN(PCI_SLOT(data->board_dat->pdev->devfn), 0)); |
| 879 | 879 | ||
| 880 | /* Set Tx DMA */ | 880 | /* Set Tx DMA */ |
| 881 | param = &dma->param_tx; | 881 | param = &dma->param_tx; |
| @@ -1047,8 +1047,8 @@ static void pch_spi_handle_dma(struct pch_spi_data *data, int *bpw) | |||
| 1047 | num, DMA_DEV_TO_MEM, | 1047 | num, DMA_DEV_TO_MEM, |
| 1048 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | 1048 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 1049 | if (!desc_rx) { | 1049 | if (!desc_rx) { |
| 1050 | dev_err(&data->master->dev, "%s:device_prep_slave_sg Failed\n", | 1050 | dev_err(&data->master->dev, |
| 1051 | __func__); | 1051 | "%s:dmaengine_prep_slave_sg Failed\n", __func__); |
| 1052 | return; | 1052 | return; |
| 1053 | } | 1053 | } |
| 1054 | dma_sync_sg_for_device(&data->master->dev, sg, num, DMA_FROM_DEVICE); | 1054 | dma_sync_sg_for_device(&data->master->dev, sg, num, DMA_FROM_DEVICE); |
| @@ -1106,8 +1106,8 @@ static void pch_spi_handle_dma(struct pch_spi_data *data, int *bpw) | |||
| 1106 | sg, num, DMA_MEM_TO_DEV, | 1106 | sg, num, DMA_MEM_TO_DEV, |
| 1107 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | 1107 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 1108 | if (!desc_tx) { | 1108 | if (!desc_tx) { |
| 1109 | dev_err(&data->master->dev, "%s:device_prep_slave_sg Failed\n", | 1109 | dev_err(&data->master->dev, |
| 1110 | __func__); | 1110 | "%s:dmaengine_prep_slave_sg Failed\n", __func__); |
| 1111 | return; | 1111 | return; |
| 1112 | } | 1112 | } |
| 1113 | dma_sync_sg_for_device(&data->master->dev, sg, num, DMA_TO_DEVICE); | 1113 | dma_sync_sg_for_device(&data->master->dev, sg, num, DMA_TO_DEVICE); |
diff --git a/include/linux/spi/sh_msiof.h b/include/linux/spi/sh_msiof.h index 2e8db3d2d2e5..88a14d81c49e 100644 --- a/include/linux/spi/sh_msiof.h +++ b/include/linux/spi/sh_msiof.h | |||
| @@ -5,6 +5,8 @@ struct sh_msiof_spi_info { | |||
| 5 | int tx_fifo_override; | 5 | int tx_fifo_override; |
| 6 | int rx_fifo_override; | 6 | int rx_fifo_override; |
| 7 | u16 num_chipselect; | 7 | u16 num_chipselect; |
| 8 | unsigned int dma_tx_id; | ||
| 9 | unsigned int dma_rx_id; | ||
| 8 | }; | 10 | }; |
| 9 | 11 | ||
| 10 | #endif /* __SPI_SH_MSIOF_H__ */ | 12 | #endif /* __SPI_SH_MSIOF_H__ */ |
