diff options
Diffstat (limited to 'drivers/mmc/host/atmel-mci.c')
-rw-r--r-- | drivers/mmc/host/atmel-mci.c | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c index 9819dc09ce08..e94476beca18 100644 --- a/drivers/mmc/host/atmel-mci.c +++ b/drivers/mmc/host/atmel-mci.c | |||
@@ -77,6 +77,7 @@ struct atmel_mci_caps { | |||
77 | bool has_cstor_reg; | 77 | bool has_cstor_reg; |
78 | bool has_highspeed; | 78 | bool has_highspeed; |
79 | bool has_rwproof; | 79 | bool has_rwproof; |
80 | bool has_odd_clk_div; | ||
80 | }; | 81 | }; |
81 | 82 | ||
82 | struct atmel_mci_dma { | 83 | struct atmel_mci_dma { |
@@ -482,7 +483,14 @@ err: | |||
482 | static inline unsigned int atmci_ns_to_clocks(struct atmel_mci *host, | 483 | static inline unsigned int atmci_ns_to_clocks(struct atmel_mci *host, |
483 | unsigned int ns) | 484 | unsigned int ns) |
484 | { | 485 | { |
485 | return (ns * (host->bus_hz / 1000000) + 999) / 1000; | 486 | /* |
487 | * It is easier here to use us instead of ns for the timeout, | ||
488 | * it prevents from overflows during calculation. | ||
489 | */ | ||
490 | unsigned int us = DIV_ROUND_UP(ns, 1000); | ||
491 | |||
492 | /* Maximum clock frequency is host->bus_hz/2 */ | ||
493 | return us * (DIV_ROUND_UP(host->bus_hz, 2000000)); | ||
486 | } | 494 | } |
487 | 495 | ||
488 | static void atmci_set_timeout(struct atmel_mci *host, | 496 | static void atmci_set_timeout(struct atmel_mci *host, |
@@ -1127,16 +1135,27 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
1127 | } | 1135 | } |
1128 | 1136 | ||
1129 | /* Calculate clock divider */ | 1137 | /* Calculate clock divider */ |
1130 | clkdiv = DIV_ROUND_UP(host->bus_hz, 2 * clock_min) - 1; | 1138 | if (host->caps.has_odd_clk_div) { |
1131 | if (clkdiv > 255) { | 1139 | clkdiv = DIV_ROUND_UP(host->bus_hz, clock_min) - 2; |
1132 | dev_warn(&mmc->class_dev, | 1140 | if (clkdiv > 511) { |
1133 | "clock %u too slow; using %lu\n", | 1141 | dev_warn(&mmc->class_dev, |
1134 | clock_min, host->bus_hz / (2 * 256)); | 1142 | "clock %u too slow; using %lu\n", |
1135 | clkdiv = 255; | 1143 | clock_min, host->bus_hz / (511 + 2)); |
1144 | clkdiv = 511; | ||
1145 | } | ||
1146 | host->mode_reg = ATMCI_MR_CLKDIV(clkdiv >> 1) | ||
1147 | | ATMCI_MR_CLKODD(clkdiv & 1); | ||
1148 | } else { | ||
1149 | clkdiv = DIV_ROUND_UP(host->bus_hz, 2 * clock_min) - 1; | ||
1150 | if (clkdiv > 255) { | ||
1151 | dev_warn(&mmc->class_dev, | ||
1152 | "clock %u too slow; using %lu\n", | ||
1153 | clock_min, host->bus_hz / (2 * 256)); | ||
1154 | clkdiv = 255; | ||
1155 | } | ||
1156 | host->mode_reg = ATMCI_MR_CLKDIV(clkdiv); | ||
1136 | } | 1157 | } |
1137 | 1158 | ||
1138 | host->mode_reg = ATMCI_MR_CLKDIV(clkdiv); | ||
1139 | |||
1140 | /* | 1159 | /* |
1141 | * WRPROOF and RDPROOF prevent overruns/underruns by | 1160 | * WRPROOF and RDPROOF prevent overruns/underruns by |
1142 | * stopping the clock when the FIFO is full/empty. | 1161 | * stopping the clock when the FIFO is full/empty. |
@@ -2007,35 +2026,35 @@ static void __init atmci_get_cap(struct atmel_mci *host) | |||
2007 | "version: 0x%x\n", version); | 2026 | "version: 0x%x\n", version); |
2008 | 2027 | ||
2009 | host->caps.has_dma = 0; | 2028 | host->caps.has_dma = 0; |
2010 | host->caps.has_pdc = 0; | 2029 | host->caps.has_pdc = 1; |
2011 | host->caps.has_cfg_reg = 0; | 2030 | host->caps.has_cfg_reg = 0; |
2012 | host->caps.has_cstor_reg = 0; | 2031 | host->caps.has_cstor_reg = 0; |
2013 | host->caps.has_highspeed = 0; | 2032 | host->caps.has_highspeed = 0; |
2014 | host->caps.has_rwproof = 0; | 2033 | host->caps.has_rwproof = 0; |
2034 | host->caps.has_odd_clk_div = 0; | ||
2015 | 2035 | ||
2016 | /* keep only major version number */ | 2036 | /* keep only major version number */ |
2017 | switch (version & 0xf00) { | 2037 | switch (version & 0xf00) { |
2018 | case 0x100: | ||
2019 | case 0x200: | ||
2020 | host->caps.has_pdc = 1; | ||
2021 | host->caps.has_rwproof = 1; | ||
2022 | break; | ||
2023 | case 0x300: | ||
2024 | case 0x400: | ||
2025 | case 0x500: | 2038 | case 0x500: |
2039 | host->caps.has_odd_clk_div = 1; | ||
2040 | case 0x400: | ||
2041 | case 0x300: | ||
2026 | #ifdef CONFIG_AT_HDMAC | 2042 | #ifdef CONFIG_AT_HDMAC |
2027 | host->caps.has_dma = 1; | 2043 | host->caps.has_dma = 1; |
2028 | #else | 2044 | #else |
2029 | host->caps.has_dma = 0; | ||
2030 | dev_info(&host->pdev->dev, | 2045 | dev_info(&host->pdev->dev, |
2031 | "has dma capability but dma engine is not selected, then use pio\n"); | 2046 | "has dma capability but dma engine is not selected, then use pio\n"); |
2032 | #endif | 2047 | #endif |
2048 | host->caps.has_pdc = 0; | ||
2033 | host->caps.has_cfg_reg = 1; | 2049 | host->caps.has_cfg_reg = 1; |
2034 | host->caps.has_cstor_reg = 1; | 2050 | host->caps.has_cstor_reg = 1; |
2035 | host->caps.has_highspeed = 1; | 2051 | host->caps.has_highspeed = 1; |
2052 | case 0x200: | ||
2036 | host->caps.has_rwproof = 1; | 2053 | host->caps.has_rwproof = 1; |
2054 | case 0x100: | ||
2037 | break; | 2055 | break; |
2038 | default: | 2056 | default: |
2057 | host->caps.has_pdc = 0; | ||
2039 | dev_warn(&host->pdev->dev, | 2058 | dev_warn(&host->pdev->dev, |
2040 | "Unmanaged mci version, set minimum capabilities\n"); | 2059 | "Unmanaged mci version, set minimum capabilities\n"); |
2041 | break; | 2060 | break; |