diff options
Diffstat (limited to 'drivers/mmc/core')
-rw-r--r-- | drivers/mmc/core/block.c | 11 | ||||
-rw-r--r-- | drivers/mmc/core/card.h | 6 | ||||
-rw-r--r-- | drivers/mmc/core/core.c | 67 | ||||
-rw-r--r-- | drivers/mmc/core/core.h | 4 | ||||
-rw-r--r-- | drivers/mmc/core/host.c | 16 | ||||
-rw-r--r-- | drivers/mmc/core/mmc.c | 16 | ||||
-rw-r--r-- | drivers/mmc/core/pwrseq_simple.c | 14 | ||||
-rw-r--r-- | drivers/mmc/core/quirks.h | 3 | ||||
-rw-r--r-- | drivers/mmc/core/sd.c | 12 | ||||
-rw-r--r-- | drivers/mmc/core/sdio.c | 70 | ||||
-rw-r--r-- | drivers/mmc/core/slot-gpio.c | 22 |
11 files changed, 176 insertions, 65 deletions
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index d89e17829527..a0b9102c4c6e 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c | |||
@@ -2351,7 +2351,8 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, | |||
2351 | set_disk_ro(md->disk, md->read_only || default_ro); | 2351 | set_disk_ro(md->disk, md->read_only || default_ro); |
2352 | md->disk->flags = GENHD_FL_EXT_DEVT; | 2352 | md->disk->flags = GENHD_FL_EXT_DEVT; |
2353 | if (area_type & (MMC_BLK_DATA_AREA_RPMB | MMC_BLK_DATA_AREA_BOOT)) | 2353 | if (area_type & (MMC_BLK_DATA_AREA_RPMB | MMC_BLK_DATA_AREA_BOOT)) |
2354 | md->disk->flags |= GENHD_FL_NO_PART_SCAN; | 2354 | md->disk->flags |= GENHD_FL_NO_PART_SCAN |
2355 | | GENHD_FL_SUPPRESS_PARTITION_INFO; | ||
2355 | 2356 | ||
2356 | /* | 2357 | /* |
2357 | * As discussed on lkml, GENHD_FL_REMOVABLE should: | 2358 | * As discussed on lkml, GENHD_FL_REMOVABLE should: |
@@ -2965,9 +2966,11 @@ static void mmc_blk_remove(struct mmc_card *card) | |||
2965 | mmc_blk_remove_debugfs(card, md); | 2966 | mmc_blk_remove_debugfs(card, md); |
2966 | mmc_blk_remove_parts(card, md); | 2967 | mmc_blk_remove_parts(card, md); |
2967 | pm_runtime_get_sync(&card->dev); | 2968 | pm_runtime_get_sync(&card->dev); |
2968 | mmc_claim_host(card->host); | 2969 | if (md->part_curr != md->part_type) { |
2969 | mmc_blk_part_switch(card, md->part_type); | 2970 | mmc_claim_host(card->host); |
2970 | mmc_release_host(card->host); | 2971 | mmc_blk_part_switch(card, md->part_type); |
2972 | mmc_release_host(card->host); | ||
2973 | } | ||
2971 | if (card->type != MMC_TYPE_SD_COMBO) | 2974 | if (card->type != MMC_TYPE_SD_COMBO) |
2972 | pm_runtime_disable(&card->dev); | 2975 | pm_runtime_disable(&card->dev); |
2973 | pm_runtime_put_noidle(&card->dev); | 2976 | pm_runtime_put_noidle(&card->dev); |
diff --git a/drivers/mmc/core/card.h b/drivers/mmc/core/card.h index 9c821eedd156..1170feb8f969 100644 --- a/drivers/mmc/core/card.h +++ b/drivers/mmc/core/card.h | |||
@@ -149,6 +149,12 @@ static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data) | |||
149 | card->quirks &= ~data; | 149 | card->quirks &= ~data; |
150 | } | 150 | } |
151 | 151 | ||
152 | static inline void __maybe_unused add_limit_rate_quirk(struct mmc_card *card, | ||
153 | int data) | ||
154 | { | ||
155 | card->quirk_max_rate = data; | ||
156 | } | ||
157 | |||
152 | /* | 158 | /* |
153 | * Quirk add/remove for MMC products. | 159 | * Quirk add/remove for MMC products. |
154 | */ | 160 | */ |
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 121ce50b6d5e..281826d1fcca 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c | |||
@@ -50,9 +50,6 @@ | |||
50 | #include "sd_ops.h" | 50 | #include "sd_ops.h" |
51 | #include "sdio_ops.h" | 51 | #include "sdio_ops.h" |
52 | 52 | ||
53 | /* If the device is not responding */ | ||
54 | #define MMC_CORE_TIMEOUT_MS (10 * 60 * 1000) /* 10 minute timeout */ | ||
55 | |||
56 | /* The max erase timeout, used when host->max_busy_timeout isn't specified */ | 53 | /* The max erase timeout, used when host->max_busy_timeout isn't specified */ |
57 | #define MMC_ERASE_TIMEOUT_MS (60 * 1000) /* 60 s */ | 54 | #define MMC_ERASE_TIMEOUT_MS (60 * 1000) /* 60 s */ |
58 | 55 | ||
@@ -1484,6 +1481,17 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage) | |||
1484 | 1481 | ||
1485 | } | 1482 | } |
1486 | 1483 | ||
1484 | void mmc_set_initial_signal_voltage(struct mmc_host *host) | ||
1485 | { | ||
1486 | /* Try to set signal voltage to 3.3V but fall back to 1.8v or 1.2v */ | ||
1487 | if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330)) | ||
1488 | dev_dbg(mmc_dev(host), "Initial signal voltage of 3.3v\n"); | ||
1489 | else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) | ||
1490 | dev_dbg(mmc_dev(host), "Initial signal voltage of 1.8v\n"); | ||
1491 | else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120)) | ||
1492 | dev_dbg(mmc_dev(host), "Initial signal voltage of 1.2v\n"); | ||
1493 | } | ||
1494 | |||
1487 | int mmc_host_set_uhs_voltage(struct mmc_host *host) | 1495 | int mmc_host_set_uhs_voltage(struct mmc_host *host) |
1488 | { | 1496 | { |
1489 | u32 clock; | 1497 | u32 clock; |
@@ -1646,19 +1654,13 @@ void mmc_power_up(struct mmc_host *host, u32 ocr) | |||
1646 | /* Set initial state and call mmc_set_ios */ | 1654 | /* Set initial state and call mmc_set_ios */ |
1647 | mmc_set_initial_state(host); | 1655 | mmc_set_initial_state(host); |
1648 | 1656 | ||
1649 | /* Try to set signal voltage to 3.3V but fall back to 1.8v or 1.2v */ | 1657 | mmc_set_initial_signal_voltage(host); |
1650 | if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330)) | ||
1651 | dev_dbg(mmc_dev(host), "Initial signal voltage of 3.3v\n"); | ||
1652 | else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) | ||
1653 | dev_dbg(mmc_dev(host), "Initial signal voltage of 1.8v\n"); | ||
1654 | else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120)) | ||
1655 | dev_dbg(mmc_dev(host), "Initial signal voltage of 1.2v\n"); | ||
1656 | 1658 | ||
1657 | /* | 1659 | /* |
1658 | * This delay should be sufficient to allow the power supply | 1660 | * This delay should be sufficient to allow the power supply |
1659 | * to reach the minimum voltage. | 1661 | * to reach the minimum voltage. |
1660 | */ | 1662 | */ |
1661 | mmc_delay(10); | 1663 | mmc_delay(host->ios.power_delay_ms); |
1662 | 1664 | ||
1663 | mmc_pwrseq_post_power_on(host); | 1665 | mmc_pwrseq_post_power_on(host); |
1664 | 1666 | ||
@@ -1671,7 +1673,7 @@ void mmc_power_up(struct mmc_host *host, u32 ocr) | |||
1671 | * This delay must be at least 74 clock sizes, or 1 ms, or the | 1673 | * This delay must be at least 74 clock sizes, or 1 ms, or the |
1672 | * time required to reach a stable voltage. | 1674 | * time required to reach a stable voltage. |
1673 | */ | 1675 | */ |
1674 | mmc_delay(10); | 1676 | mmc_delay(host->ios.power_delay_ms); |
1675 | } | 1677 | } |
1676 | 1678 | ||
1677 | void mmc_power_off(struct mmc_host *host) | 1679 | void mmc_power_off(struct mmc_host *host) |
@@ -1967,6 +1969,7 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from, | |||
1967 | unsigned int qty = 0, busy_timeout = 0; | 1969 | unsigned int qty = 0, busy_timeout = 0; |
1968 | bool use_r1b_resp = false; | 1970 | bool use_r1b_resp = false; |
1969 | unsigned long timeout; | 1971 | unsigned long timeout; |
1972 | int loop_udelay=64, udelay_max=32768; | ||
1970 | int err; | 1973 | int err; |
1971 | 1974 | ||
1972 | mmc_retune_hold(card->host); | 1975 | mmc_retune_hold(card->host); |
@@ -2091,9 +2094,15 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from, | |||
2091 | err = -EIO; | 2094 | err = -EIO; |
2092 | goto out; | 2095 | goto out; |
2093 | } | 2096 | } |
2097 | if ((cmd.resp[0] & R1_READY_FOR_DATA) && | ||
2098 | R1_CURRENT_STATE(cmd.resp[0]) != R1_STATE_PRG) | ||
2099 | break; | ||
2100 | |||
2101 | usleep_range(loop_udelay, loop_udelay*2); | ||
2102 | if (loop_udelay < udelay_max) | ||
2103 | loop_udelay *= 2; | ||
2104 | } while (1); | ||
2094 | 2105 | ||
2095 | } while (!(cmd.resp[0] & R1_READY_FOR_DATA) || | ||
2096 | (R1_CURRENT_STATE(cmd.resp[0]) == R1_STATE_PRG)); | ||
2097 | out: | 2106 | out: |
2098 | mmc_retune_release(card->host); | 2107 | mmc_retune_release(card->host); |
2099 | return err; | 2108 | return err; |
@@ -2435,22 +2444,46 @@ int mmc_hw_reset(struct mmc_host *host) | |||
2435 | return -EINVAL; | 2444 | return -EINVAL; |
2436 | 2445 | ||
2437 | mmc_bus_get(host); | 2446 | mmc_bus_get(host); |
2438 | if (!host->bus_ops || host->bus_dead || !host->bus_ops->reset) { | 2447 | if (!host->bus_ops || host->bus_dead || !host->bus_ops->hw_reset) { |
2439 | mmc_bus_put(host); | 2448 | mmc_bus_put(host); |
2440 | return -EOPNOTSUPP; | 2449 | return -EOPNOTSUPP; |
2441 | } | 2450 | } |
2442 | 2451 | ||
2443 | ret = host->bus_ops->reset(host); | 2452 | ret = host->bus_ops->hw_reset(host); |
2444 | mmc_bus_put(host); | 2453 | mmc_bus_put(host); |
2445 | 2454 | ||
2446 | if (ret) | 2455 | if (ret) |
2447 | pr_warn("%s: tried to reset card, got error %d\n", | 2456 | pr_warn("%s: tried to HW reset card, got error %d\n", |
2448 | mmc_hostname(host), ret); | 2457 | mmc_hostname(host), ret); |
2449 | 2458 | ||
2450 | return ret; | 2459 | return ret; |
2451 | } | 2460 | } |
2452 | EXPORT_SYMBOL(mmc_hw_reset); | 2461 | EXPORT_SYMBOL(mmc_hw_reset); |
2453 | 2462 | ||
2463 | int mmc_sw_reset(struct mmc_host *host) | ||
2464 | { | ||
2465 | int ret; | ||
2466 | |||
2467 | if (!host->card) | ||
2468 | return -EINVAL; | ||
2469 | |||
2470 | mmc_bus_get(host); | ||
2471 | if (!host->bus_ops || host->bus_dead || !host->bus_ops->sw_reset) { | ||
2472 | mmc_bus_put(host); | ||
2473 | return -EOPNOTSUPP; | ||
2474 | } | ||
2475 | |||
2476 | ret = host->bus_ops->sw_reset(host); | ||
2477 | mmc_bus_put(host); | ||
2478 | |||
2479 | if (ret) | ||
2480 | pr_warn("%s: tried to SW reset card, got error %d\n", | ||
2481 | mmc_hostname(host), ret); | ||
2482 | |||
2483 | return ret; | ||
2484 | } | ||
2485 | EXPORT_SYMBOL(mmc_sw_reset); | ||
2486 | |||
2454 | static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq) | 2487 | static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq) |
2455 | { | 2488 | { |
2456 | host->f_init = freq; | 2489 | host->f_init = freq; |
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index d6303d69071b..9d8f09ac0821 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h | |||
@@ -32,7 +32,8 @@ struct mmc_bus_ops { | |||
32 | int (*power_restore)(struct mmc_host *); | 32 | int (*power_restore)(struct mmc_host *); |
33 | int (*alive)(struct mmc_host *); | 33 | int (*alive)(struct mmc_host *); |
34 | int (*shutdown)(struct mmc_host *); | 34 | int (*shutdown)(struct mmc_host *); |
35 | int (*reset)(struct mmc_host *); | 35 | int (*hw_reset)(struct mmc_host *); |
36 | int (*sw_reset)(struct mmc_host *); | ||
36 | }; | 37 | }; |
37 | 38 | ||
38 | void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops); | 39 | void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops); |
@@ -51,6 +52,7 @@ u32 mmc_select_voltage(struct mmc_host *host, u32 ocr); | |||
51 | int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr); | 52 | int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr); |
52 | int mmc_host_set_uhs_voltage(struct mmc_host *host); | 53 | int mmc_host_set_uhs_voltage(struct mmc_host *host); |
53 | int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage); | 54 | int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage); |
55 | void mmc_set_initial_signal_voltage(struct mmc_host *host); | ||
54 | void mmc_set_timing(struct mmc_host *host, unsigned int timing); | 56 | void mmc_set_timing(struct mmc_host *host, unsigned int timing); |
55 | void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type); | 57 | void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type); |
56 | int mmc_select_drive_strength(struct mmc_card *card, unsigned int max_dtr, | 58 | int mmc_select_drive_strength(struct mmc_card *card, unsigned int max_dtr, |
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index 64b03d6eaf18..abf9e884386c 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c | |||
@@ -143,9 +143,6 @@ int mmc_retune(struct mmc_host *host) | |||
143 | goto out; | 143 | goto out; |
144 | 144 | ||
145 | return_to_hs400 = true; | 145 | return_to_hs400 = true; |
146 | |||
147 | if (host->ops->prepare_hs400_tuning) | ||
148 | host->ops->prepare_hs400_tuning(host, &host->ios); | ||
149 | } | 146 | } |
150 | 147 | ||
151 | err = mmc_execute_tuning(host->card); | 148 | err = mmc_execute_tuning(host->card); |
@@ -179,7 +176,7 @@ static void mmc_retune_timer(struct timer_list *t) | |||
179 | int mmc_of_parse(struct mmc_host *host) | 176 | int mmc_of_parse(struct mmc_host *host) |
180 | { | 177 | { |
181 | struct device *dev = host->parent; | 178 | struct device *dev = host->parent; |
182 | u32 bus_width, drv_type; | 179 | u32 bus_width, drv_type, cd_debounce_delay_ms; |
183 | int ret; | 180 | int ret; |
184 | bool cd_cap_invert, cd_gpio_invert = false; | 181 | bool cd_cap_invert, cd_gpio_invert = false; |
185 | bool ro_cap_invert, ro_gpio_invert = false; | 182 | bool ro_cap_invert, ro_gpio_invert = false; |
@@ -230,11 +227,16 @@ int mmc_of_parse(struct mmc_host *host) | |||
230 | } else { | 227 | } else { |
231 | cd_cap_invert = device_property_read_bool(dev, "cd-inverted"); | 228 | cd_cap_invert = device_property_read_bool(dev, "cd-inverted"); |
232 | 229 | ||
230 | if (device_property_read_u32(dev, "cd-debounce-delay-ms", | ||
231 | &cd_debounce_delay_ms)) | ||
232 | cd_debounce_delay_ms = 200; | ||
233 | |||
233 | if (device_property_read_bool(dev, "broken-cd")) | 234 | if (device_property_read_bool(dev, "broken-cd")) |
234 | host->caps |= MMC_CAP_NEEDS_POLL; | 235 | host->caps |= MMC_CAP_NEEDS_POLL; |
235 | 236 | ||
236 | ret = mmc_gpiod_request_cd(host, "cd", 0, true, | 237 | ret = mmc_gpiod_request_cd(host, "cd", 0, true, |
237 | 0, &cd_gpio_invert); | 238 | cd_debounce_delay_ms, |
239 | &cd_gpio_invert); | ||
238 | if (!ret) | 240 | if (!ret) |
239 | dev_info(host->parent, "Got CD GPIO\n"); | 241 | dev_info(host->parent, "Got CD GPIO\n"); |
240 | else if (ret != -ENOENT && ret != -ENOSYS) | 242 | else if (ret != -ENOENT && ret != -ENOSYS) |
@@ -338,6 +340,9 @@ int mmc_of_parse(struct mmc_host *host) | |||
338 | host->dsr_req = 0; | 340 | host->dsr_req = 0; |
339 | } | 341 | } |
340 | 342 | ||
343 | device_property_read_u32(dev, "post-power-on-delay-ms", | ||
344 | &host->ios.power_delay_ms); | ||
345 | |||
341 | return mmc_pwrseq_alloc(host); | 346 | return mmc_pwrseq_alloc(host); |
342 | } | 347 | } |
343 | 348 | ||
@@ -403,6 +408,7 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) | |||
403 | host->max_blk_count = PAGE_SIZE / 512; | 408 | host->max_blk_count = PAGE_SIZE / 512; |
404 | 409 | ||
405 | host->fixed_drv_type = -EINVAL; | 410 | host->fixed_drv_type = -EINVAL; |
411 | host->ios.power_delay_ms = 10; | ||
406 | 412 | ||
407 | return host; | 413 | return host; |
408 | } | 414 | } |
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 6f8ebd6caa4c..4466f5de54d4 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c | |||
@@ -1282,6 +1282,10 @@ int mmc_hs400_to_hs200(struct mmc_card *card) | |||
1282 | 1282 | ||
1283 | mmc_set_bus_speed(card); | 1283 | mmc_set_bus_speed(card); |
1284 | 1284 | ||
1285 | /* Prepare tuning for HS400 mode. */ | ||
1286 | if (host->ops->prepare_hs400_tuning) | ||
1287 | host->ops->prepare_hs400_tuning(host, &host->ios); | ||
1288 | |||
1285 | return 0; | 1289 | return 0; |
1286 | 1290 | ||
1287 | out_err: | 1291 | out_err: |
@@ -1830,6 +1834,14 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
1830 | } | 1834 | } |
1831 | } | 1835 | } |
1832 | 1836 | ||
1837 | if (host->caps2 & MMC_CAP2_AVOID_3_3V && | ||
1838 | host->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_330) { | ||
1839 | pr_err("%s: Host failed to negotiate down from 3.3V\n", | ||
1840 | mmc_hostname(host)); | ||
1841 | err = -EINVAL; | ||
1842 | goto free_card; | ||
1843 | } | ||
1844 | |||
1833 | if (!oldcard) | 1845 | if (!oldcard) |
1834 | host->card = card; | 1846 | host->card = card; |
1835 | 1847 | ||
@@ -2117,7 +2129,7 @@ static int mmc_can_reset(struct mmc_card *card) | |||
2117 | return 1; | 2129 | return 1; |
2118 | } | 2130 | } |
2119 | 2131 | ||
2120 | static int mmc_reset(struct mmc_host *host) | 2132 | static int _mmc_hw_reset(struct mmc_host *host) |
2121 | { | 2133 | { |
2122 | struct mmc_card *card = host->card; | 2134 | struct mmc_card *card = host->card; |
2123 | 2135 | ||
@@ -2151,7 +2163,7 @@ static const struct mmc_bus_ops mmc_ops = { | |||
2151 | .runtime_resume = mmc_runtime_resume, | 2163 | .runtime_resume = mmc_runtime_resume, |
2152 | .alive = mmc_alive, | 2164 | .alive = mmc_alive, |
2153 | .shutdown = mmc_shutdown, | 2165 | .shutdown = mmc_shutdown, |
2154 | .reset = mmc_reset, | 2166 | .hw_reset = _mmc_hw_reset, |
2155 | }; | 2167 | }; |
2156 | 2168 | ||
2157 | /* | 2169 | /* |
diff --git a/drivers/mmc/core/pwrseq_simple.c b/drivers/mmc/core/pwrseq_simple.c index 13ef162cf066..a8b9fee4d62a 100644 --- a/drivers/mmc/core/pwrseq_simple.c +++ b/drivers/mmc/core/pwrseq_simple.c | |||
@@ -40,14 +40,18 @@ static void mmc_pwrseq_simple_set_gpios_value(struct mmc_pwrseq_simple *pwrseq, | |||
40 | struct gpio_descs *reset_gpios = pwrseq->reset_gpios; | 40 | struct gpio_descs *reset_gpios = pwrseq->reset_gpios; |
41 | 41 | ||
42 | if (!IS_ERR(reset_gpios)) { | 42 | if (!IS_ERR(reset_gpios)) { |
43 | int i; | 43 | int i, *values; |
44 | int values[reset_gpios->ndescs]; | 44 | int nvalues = reset_gpios->ndescs; |
45 | 45 | ||
46 | for (i = 0; i < reset_gpios->ndescs; i++) | 46 | values = kmalloc_array(nvalues, sizeof(int), GFP_KERNEL); |
47 | if (!values) | ||
48 | return; | ||
49 | |||
50 | for (i = 0; i < nvalues; i++) | ||
47 | values[i] = value; | 51 | values[i] = value; |
48 | 52 | ||
49 | gpiod_set_array_value_cansleep( | 53 | gpiod_set_array_value_cansleep(nvalues, reset_gpios->desc, values); |
50 | reset_gpios->ndescs, reset_gpios->desc, values); | 54 | kfree(values); |
51 | } | 55 | } |
52 | } | 56 | } |
53 | 57 | ||
diff --git a/drivers/mmc/core/quirks.h b/drivers/mmc/core/quirks.h index 5153577754f0..dd2f73af8f2c 100644 --- a/drivers/mmc/core/quirks.h +++ b/drivers/mmc/core/quirks.h | |||
@@ -132,6 +132,9 @@ static const struct mmc_fixup sdio_fixup_methods[] = { | |||
132 | SDIO_FIXUP(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797_F0, | 132 | SDIO_FIXUP(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797_F0, |
133 | add_quirk, MMC_QUIRK_BROKEN_IRQ_POLLING), | 133 | add_quirk, MMC_QUIRK_BROKEN_IRQ_POLLING), |
134 | 134 | ||
135 | SDIO_FIXUP(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8887WLAN, | ||
136 | add_limit_rate_quirk, 150000000), | ||
137 | |||
135 | END_FIXUP | 138 | END_FIXUP |
136 | }; | 139 | }; |
137 | 140 | ||
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index baf3d5da4ccb..d0d9f90e7cdf 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c | |||
@@ -1058,6 +1058,14 @@ retry: | |||
1058 | mmc_set_bus_width(host, MMC_BUS_WIDTH_4); | 1058 | mmc_set_bus_width(host, MMC_BUS_WIDTH_4); |
1059 | } | 1059 | } |
1060 | } | 1060 | } |
1061 | |||
1062 | if (host->caps2 & MMC_CAP2_AVOID_3_3V && | ||
1063 | host->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_330) { | ||
1064 | pr_err("%s: Host failed to negotiate down from 3.3V\n", | ||
1065 | mmc_hostname(host)); | ||
1066 | err = -EINVAL; | ||
1067 | goto free_card; | ||
1068 | } | ||
1061 | done: | 1069 | done: |
1062 | host->card = card; | 1070 | host->card = card; |
1063 | return 0; | 1071 | return 0; |
@@ -1214,7 +1222,7 @@ static int mmc_sd_runtime_resume(struct mmc_host *host) | |||
1214 | return 0; | 1222 | return 0; |
1215 | } | 1223 | } |
1216 | 1224 | ||
1217 | static int mmc_sd_reset(struct mmc_host *host) | 1225 | static int mmc_sd_hw_reset(struct mmc_host *host) |
1218 | { | 1226 | { |
1219 | mmc_power_cycle(host, host->card->ocr); | 1227 | mmc_power_cycle(host, host->card->ocr); |
1220 | return mmc_sd_init_card(host, host->card->ocr, host->card); | 1228 | return mmc_sd_init_card(host, host->card->ocr, host->card); |
@@ -1229,7 +1237,7 @@ static const struct mmc_bus_ops mmc_sd_ops = { | |||
1229 | .resume = mmc_sd_resume, | 1237 | .resume = mmc_sd_resume, |
1230 | .alive = mmc_sd_alive, | 1238 | .alive = mmc_sd_alive, |
1231 | .shutdown = mmc_sd_suspend, | 1239 | .shutdown = mmc_sd_suspend, |
1232 | .reset = mmc_sd_reset, | 1240 | .hw_reset = mmc_sd_hw_reset, |
1233 | }; | 1241 | }; |
1234 | 1242 | ||
1235 | /* | 1243 | /* |
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index c599a628a387..a86490dbca70 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c | |||
@@ -444,6 +444,7 @@ static int sdio_set_bus_speed_mode(struct mmc_card *card) | |||
444 | unsigned int bus_speed, timing; | 444 | unsigned int bus_speed, timing; |
445 | int err; | 445 | int err; |
446 | unsigned char speed; | 446 | unsigned char speed; |
447 | unsigned int max_rate; | ||
447 | 448 | ||
448 | /* | 449 | /* |
449 | * If the host doesn't support any of the UHS-I modes, fallback on | 450 | * If the host doesn't support any of the UHS-I modes, fallback on |
@@ -500,9 +501,12 @@ static int sdio_set_bus_speed_mode(struct mmc_card *card) | |||
500 | if (err) | 501 | if (err) |
501 | return err; | 502 | return err; |
502 | 503 | ||
504 | max_rate = min_not_zero(card->quirk_max_rate, | ||
505 | card->sw_caps.uhs_max_dtr); | ||
506 | |||
503 | if (bus_speed) { | 507 | if (bus_speed) { |
504 | mmc_set_timing(card->host, timing); | 508 | mmc_set_timing(card->host, timing); |
505 | mmc_set_clock(card->host, card->sw_caps.uhs_max_dtr); | 509 | mmc_set_clock(card->host, max_rate); |
506 | } | 510 | } |
507 | 511 | ||
508 | return 0; | 512 | return 0; |
@@ -788,6 +792,14 @@ try_again: | |||
788 | if (err) | 792 | if (err) |
789 | goto remove; | 793 | goto remove; |
790 | } | 794 | } |
795 | |||
796 | if (host->caps2 & MMC_CAP2_AVOID_3_3V && | ||
797 | host->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_330) { | ||
798 | pr_err("%s: Host failed to negotiate down from 3.3V\n", | ||
799 | mmc_hostname(host)); | ||
800 | err = -EINVAL; | ||
801 | goto remove; | ||
802 | } | ||
791 | finish: | 803 | finish: |
792 | if (!oldcard) | 804 | if (!oldcard) |
793 | host->card = card; | 805 | host->card = card; |
@@ -801,6 +813,22 @@ err: | |||
801 | return err; | 813 | return err; |
802 | } | 814 | } |
803 | 815 | ||
816 | static int mmc_sdio_reinit_card(struct mmc_host *host, bool powered_resume) | ||
817 | { | ||
818 | int ret; | ||
819 | |||
820 | sdio_reset(host); | ||
821 | mmc_go_idle(host); | ||
822 | mmc_send_if_cond(host, host->card->ocr); | ||
823 | |||
824 | ret = mmc_send_io_op_cond(host, 0, NULL); | ||
825 | if (ret) | ||
826 | return ret; | ||
827 | |||
828 | return mmc_sdio_init_card(host, host->card->ocr, host->card, | ||
829 | powered_resume); | ||
830 | } | ||
831 | |||
804 | /* | 832 | /* |
805 | * Host is being removed. Free up the current card. | 833 | * Host is being removed. Free up the current card. |
806 | */ | 834 | */ |
@@ -948,14 +976,7 @@ static int mmc_sdio_resume(struct mmc_host *host) | |||
948 | 976 | ||
949 | /* No need to reinitialize powered-resumed nonremovable cards */ | 977 | /* No need to reinitialize powered-resumed nonremovable cards */ |
950 | if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) { | 978 | if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) { |
951 | sdio_reset(host); | 979 | err = mmc_sdio_reinit_card(host, mmc_card_keep_power(host)); |
952 | mmc_go_idle(host); | ||
953 | mmc_send_if_cond(host, host->card->ocr); | ||
954 | err = mmc_send_io_op_cond(host, 0, NULL); | ||
955 | if (!err) | ||
956 | err = mmc_sdio_init_card(host, host->card->ocr, | ||
957 | host->card, | ||
958 | mmc_card_keep_power(host)); | ||
959 | } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) { | 980 | } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) { |
960 | /* We may have switched to 1-bit mode during suspend */ | 981 | /* We may have switched to 1-bit mode during suspend */ |
961 | err = sdio_enable_4bit_bus(host->card); | 982 | err = sdio_enable_4bit_bus(host->card); |
@@ -978,8 +999,6 @@ static int mmc_sdio_power_restore(struct mmc_host *host) | |||
978 | { | 999 | { |
979 | int ret; | 1000 | int ret; |
980 | 1001 | ||
981 | mmc_claim_host(host); | ||
982 | |||
983 | /* | 1002 | /* |
984 | * Reset the card by performing the same steps that are taken by | 1003 | * Reset the card by performing the same steps that are taken by |
985 | * mmc_rescan_try_freq() and mmc_attach_sdio() during a "normal" probe. | 1004 | * mmc_rescan_try_freq() and mmc_attach_sdio() during a "normal" probe. |
@@ -997,20 +1016,12 @@ static int mmc_sdio_power_restore(struct mmc_host *host) | |||
997 | * | 1016 | * |
998 | */ | 1017 | */ |
999 | 1018 | ||
1000 | sdio_reset(host); | 1019 | mmc_claim_host(host); |
1001 | mmc_go_idle(host); | ||
1002 | mmc_send_if_cond(host, host->card->ocr); | ||
1003 | |||
1004 | ret = mmc_send_io_op_cond(host, 0, NULL); | ||
1005 | if (ret) | ||
1006 | goto out; | ||
1007 | 1020 | ||
1008 | ret = mmc_sdio_init_card(host, host->card->ocr, host->card, | 1021 | ret = mmc_sdio_reinit_card(host, mmc_card_keep_power(host)); |
1009 | mmc_card_keep_power(host)); | ||
1010 | if (!ret && host->sdio_irqs) | 1022 | if (!ret && host->sdio_irqs) |
1011 | mmc_signal_sdio_irq(host); | 1023 | mmc_signal_sdio_irq(host); |
1012 | 1024 | ||
1013 | out: | ||
1014 | mmc_release_host(host); | 1025 | mmc_release_host(host); |
1015 | 1026 | ||
1016 | return ret; | 1027 | return ret; |
@@ -1039,12 +1050,24 @@ static int mmc_sdio_runtime_resume(struct mmc_host *host) | |||
1039 | return ret; | 1050 | return ret; |
1040 | } | 1051 | } |
1041 | 1052 | ||
1042 | static int mmc_sdio_reset(struct mmc_host *host) | 1053 | static int mmc_sdio_hw_reset(struct mmc_host *host) |
1043 | { | 1054 | { |
1044 | mmc_power_cycle(host, host->card->ocr); | 1055 | mmc_power_cycle(host, host->card->ocr); |
1045 | return mmc_sdio_power_restore(host); | 1056 | return mmc_sdio_power_restore(host); |
1046 | } | 1057 | } |
1047 | 1058 | ||
1059 | static int mmc_sdio_sw_reset(struct mmc_host *host) | ||
1060 | { | ||
1061 | mmc_set_clock(host, host->f_init); | ||
1062 | sdio_reset(host); | ||
1063 | mmc_go_idle(host); | ||
1064 | |||
1065 | mmc_set_initial_state(host); | ||
1066 | mmc_set_initial_signal_voltage(host); | ||
1067 | |||
1068 | return mmc_sdio_reinit_card(host, 0); | ||
1069 | } | ||
1070 | |||
1048 | static const struct mmc_bus_ops mmc_sdio_ops = { | 1071 | static const struct mmc_bus_ops mmc_sdio_ops = { |
1049 | .remove = mmc_sdio_remove, | 1072 | .remove = mmc_sdio_remove, |
1050 | .detect = mmc_sdio_detect, | 1073 | .detect = mmc_sdio_detect, |
@@ -1055,7 +1078,8 @@ static const struct mmc_bus_ops mmc_sdio_ops = { | |||
1055 | .runtime_resume = mmc_sdio_runtime_resume, | 1078 | .runtime_resume = mmc_sdio_runtime_resume, |
1056 | .power_restore = mmc_sdio_power_restore, | 1079 | .power_restore = mmc_sdio_power_restore, |
1057 | .alive = mmc_sdio_alive, | 1080 | .alive = mmc_sdio_alive, |
1058 | .reset = mmc_sdio_reset, | 1081 | .hw_reset = mmc_sdio_hw_reset, |
1082 | .sw_reset = mmc_sdio_sw_reset, | ||
1059 | }; | 1083 | }; |
1060 | 1084 | ||
1061 | 1085 | ||
diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c index 31f7dbb15668..ef05e0039378 100644 --- a/drivers/mmc/core/slot-gpio.c +++ b/drivers/mmc/core/slot-gpio.c | |||
@@ -28,15 +28,17 @@ struct mmc_gpio { | |||
28 | irqreturn_t (*cd_gpio_isr)(int irq, void *dev_id); | 28 | irqreturn_t (*cd_gpio_isr)(int irq, void *dev_id); |
29 | char *ro_label; | 29 | char *ro_label; |
30 | char cd_label[0]; | 30 | char cd_label[0]; |
31 | u32 cd_debounce_delay_ms; | ||
31 | }; | 32 | }; |
32 | 33 | ||
33 | static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id) | 34 | static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id) |
34 | { | 35 | { |
35 | /* Schedule a card detection after a debounce timeout */ | 36 | /* Schedule a card detection after a debounce timeout */ |
36 | struct mmc_host *host = dev_id; | 37 | struct mmc_host *host = dev_id; |
38 | struct mmc_gpio *ctx = host->slot.handler_priv; | ||
37 | 39 | ||
38 | host->trigger_card_event = true; | 40 | host->trigger_card_event = true; |
39 | mmc_detect_change(host, msecs_to_jiffies(200)); | 41 | mmc_detect_change(host, msecs_to_jiffies(ctx->cd_debounce_delay_ms)); |
40 | 42 | ||
41 | return IRQ_HANDLED; | 43 | return IRQ_HANDLED; |
42 | } | 44 | } |
@@ -49,6 +51,7 @@ int mmc_gpio_alloc(struct mmc_host *host) | |||
49 | 51 | ||
50 | if (ctx) { | 52 | if (ctx) { |
51 | ctx->ro_label = ctx->cd_label + len; | 53 | ctx->ro_label = ctx->cd_label + len; |
54 | ctx->cd_debounce_delay_ms = 200; | ||
52 | snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent)); | 55 | snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent)); |
53 | snprintf(ctx->ro_label, len, "%s ro", dev_name(host->parent)); | 56 | snprintf(ctx->ro_label, len, "%s ro", dev_name(host->parent)); |
54 | host->slot.handler_priv = ctx; | 57 | host->slot.handler_priv = ctx; |
@@ -76,15 +79,22 @@ EXPORT_SYMBOL(mmc_gpio_get_ro); | |||
76 | int mmc_gpio_get_cd(struct mmc_host *host) | 79 | int mmc_gpio_get_cd(struct mmc_host *host) |
77 | { | 80 | { |
78 | struct mmc_gpio *ctx = host->slot.handler_priv; | 81 | struct mmc_gpio *ctx = host->slot.handler_priv; |
82 | int cansleep; | ||
79 | 83 | ||
80 | if (!ctx || !ctx->cd_gpio) | 84 | if (!ctx || !ctx->cd_gpio) |
81 | return -ENOSYS; | 85 | return -ENOSYS; |
82 | 86 | ||
83 | if (ctx->override_cd_active_level) | 87 | cansleep = gpiod_cansleep(ctx->cd_gpio); |
84 | return !gpiod_get_raw_value_cansleep(ctx->cd_gpio) ^ | 88 | if (ctx->override_cd_active_level) { |
85 | !!(host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH); | 89 | int value = cansleep ? |
90 | gpiod_get_raw_value_cansleep(ctx->cd_gpio) : | ||
91 | gpiod_get_raw_value(ctx->cd_gpio); | ||
92 | return !value ^ !!(host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH); | ||
93 | } | ||
86 | 94 | ||
87 | return gpiod_get_value_cansleep(ctx->cd_gpio); | 95 | return cansleep ? |
96 | gpiod_get_value_cansleep(ctx->cd_gpio) : | ||
97 | gpiod_get_value(ctx->cd_gpio); | ||
88 | } | 98 | } |
89 | EXPORT_SYMBOL(mmc_gpio_get_cd); | 99 | EXPORT_SYMBOL(mmc_gpio_get_cd); |
90 | 100 | ||
@@ -261,7 +271,7 @@ int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id, | |||
261 | if (debounce) { | 271 | if (debounce) { |
262 | ret = gpiod_set_debounce(desc, debounce); | 272 | ret = gpiod_set_debounce(desc, debounce); |
263 | if (ret < 0) | 273 | if (ret < 0) |
264 | return ret; | 274 | ctx->cd_debounce_delay_ms = debounce; |
265 | } | 275 | } |
266 | 276 | ||
267 | if (gpio_invert) | 277 | if (gpio_invert) |