diff options
Diffstat (limited to 'drivers/mmc')
-rw-r--r-- | drivers/mmc/host/mmc_spi.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c index 7503b81374e0..07faf5412a1f 100644 --- a/drivers/mmc/host/mmc_spi.c +++ b/drivers/mmc/host/mmc_spi.c | |||
@@ -95,8 +95,6 @@ | |||
95 | * reads which takes nowhere near that long. Older cards may be able to use | 95 | * reads which takes nowhere near that long. Older cards may be able to use |
96 | * shorter timeouts ... but why bother? | 96 | * shorter timeouts ... but why bother? |
97 | */ | 97 | */ |
98 | #define readblock_timeout ktime_set(0, 100 * 1000 * 1000) | ||
99 | #define writeblock_timeout ktime_set(0, 250 * 1000 * 1000) | ||
100 | #define r1b_timeout ktime_set(3, 0) | 98 | #define r1b_timeout ktime_set(3, 0) |
101 | 99 | ||
102 | 100 | ||
@@ -220,9 +218,9 @@ mmc_spi_wait_unbusy(struct mmc_spi_host *host, ktime_t timeout) | |||
220 | return mmc_spi_skip(host, timeout, sizeof(host->data->status), 0); | 218 | return mmc_spi_skip(host, timeout, sizeof(host->data->status), 0); |
221 | } | 219 | } |
222 | 220 | ||
223 | static int mmc_spi_readtoken(struct mmc_spi_host *host) | 221 | static int mmc_spi_readtoken(struct mmc_spi_host *host, ktime_t timeout) |
224 | { | 222 | { |
225 | return mmc_spi_skip(host, readblock_timeout, 1, 0xff); | 223 | return mmc_spi_skip(host, timeout, 1, 0xff); |
226 | } | 224 | } |
227 | 225 | ||
228 | 226 | ||
@@ -605,7 +603,8 @@ mmc_spi_setup_data_message( | |||
605 | * Return negative errno, else success. | 603 | * Return negative errno, else success. |
606 | */ | 604 | */ |
607 | static int | 605 | static int |
608 | mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t) | 606 | mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t, |
607 | ktime_t timeout) | ||
609 | { | 608 | { |
610 | struct spi_device *spi = host->spi; | 609 | struct spi_device *spi = host->spi; |
611 | int status, i; | 610 | int status, i; |
@@ -673,7 +672,7 @@ mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t) | |||
673 | if (scratch->status[i] != 0) | 672 | if (scratch->status[i] != 0) |
674 | return 0; | 673 | return 0; |
675 | } | 674 | } |
676 | return mmc_spi_wait_unbusy(host, writeblock_timeout); | 675 | return mmc_spi_wait_unbusy(host, timeout); |
677 | } | 676 | } |
678 | 677 | ||
679 | /* | 678 | /* |
@@ -693,7 +692,8 @@ mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t) | |||
693 | * STOP_TRANSMISSION command. | 692 | * STOP_TRANSMISSION command. |
694 | */ | 693 | */ |
695 | static int | 694 | static int |
696 | mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t) | 695 | mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t, |
696 | ktime_t timeout) | ||
697 | { | 697 | { |
698 | struct spi_device *spi = host->spi; | 698 | struct spi_device *spi = host->spi; |
699 | int status; | 699 | int status; |
@@ -707,7 +707,7 @@ mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t) | |||
707 | return status; | 707 | return status; |
708 | status = scratch->status[0]; | 708 | status = scratch->status[0]; |
709 | if (status == 0xff || status == 0) | 709 | if (status == 0xff || status == 0) |
710 | status = mmc_spi_readtoken(host); | 710 | status = mmc_spi_readtoken(host, timeout); |
711 | 711 | ||
712 | if (status == SPI_TOKEN_SINGLE) { | 712 | if (status == SPI_TOKEN_SINGLE) { |
713 | if (host->dma_dev) { | 713 | if (host->dma_dev) { |
@@ -778,6 +778,8 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd, | |||
778 | struct scatterlist *sg; | 778 | struct scatterlist *sg; |
779 | unsigned n_sg; | 779 | unsigned n_sg; |
780 | int multiple = (data->blocks > 1); | 780 | int multiple = (data->blocks > 1); |
781 | u32 clock_rate; | ||
782 | ktime_t timeout; | ||
781 | 783 | ||
782 | if (data->flags & MMC_DATA_READ) | 784 | if (data->flags & MMC_DATA_READ) |
783 | direction = DMA_FROM_DEVICE; | 785 | direction = DMA_FROM_DEVICE; |
@@ -786,6 +788,14 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd, | |||
786 | mmc_spi_setup_data_message(host, multiple, direction); | 788 | mmc_spi_setup_data_message(host, multiple, direction); |
787 | t = &host->t; | 789 | t = &host->t; |
788 | 790 | ||
791 | if (t->speed_hz) | ||
792 | clock_rate = t->speed_hz; | ||
793 | else | ||
794 | clock_rate = spi->max_speed_hz; | ||
795 | |||
796 | timeout = ktime_add_ns(ktime_set(0, 0), data->timeout_ns + | ||
797 | data->timeout_clks * 1000000 / clock_rate); | ||
798 | |||
789 | /* Handle scatterlist segments one at a time, with synch for | 799 | /* Handle scatterlist segments one at a time, with synch for |
790 | * each 512-byte block | 800 | * each 512-byte block |
791 | */ | 801 | */ |
@@ -832,9 +842,9 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd, | |||
832 | t->len); | 842 | t->len); |
833 | 843 | ||
834 | if (direction == DMA_TO_DEVICE) | 844 | if (direction == DMA_TO_DEVICE) |
835 | status = mmc_spi_writeblock(host, t); | 845 | status = mmc_spi_writeblock(host, t, timeout); |
836 | else | 846 | else |
837 | status = mmc_spi_readblock(host, t); | 847 | status = mmc_spi_readblock(host, t, timeout); |
838 | if (status < 0) | 848 | if (status < 0) |
839 | break; | 849 | break; |
840 | 850 | ||
@@ -917,7 +927,7 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd, | |||
917 | if (scratch->status[tmp] != 0) | 927 | if (scratch->status[tmp] != 0) |
918 | return; | 928 | return; |
919 | } | 929 | } |
920 | tmp = mmc_spi_wait_unbusy(host, writeblock_timeout); | 930 | tmp = mmc_spi_wait_unbusy(host, timeout); |
921 | if (tmp < 0 && !data->error) | 931 | if (tmp < 0 && !data->error) |
922 | data->error = tmp; | 932 | data->error = tmp; |
923 | } | 933 | } |