Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'mmc-updates-for-3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc

Pull MMC updates from Chris Ball:
"MMC highlights for 3.11:

Core:
- Add support for eMMC 5.1 devices
- Add MMC_CAP_AGGRESSIVE_PM capability for aggressive power
management of eMMC/SD between requests, using runtime PM
- Add an ioctl to perform the eMMC 4.5 Sanitize command. Sample code
at:

git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc-utils.git

Drivers:
- dw_mmc: Add support for Rockchip's Cortex-A9 SoCs
- dw_mmc: Add support for Altera SoCFPGAs
- sdhci-esdhc-imx: Add support for 8-bit bus width, non-removable
cards
- sdhci-bcm-kona: New driver for Broadcom Kona (281xx) SoCs
- sdhi/tmio: Add DT DMA support"

* tag 'mmc-updates-for-3.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc: (87 commits)
mmc: bcm281xx SDHCI driver
mmc: sdhci: add card_event callback to sdhci
mmc: core: Fixup Oops for SDIO shutdown
mmc: sdhci-pci: add another device id
mmc: esdhc: Fix bug when writing to SDHCI_HOST_CONTROL register
mmc: esdhc: Add support for 8-bit bus width and non-removable card
mmc: core: production year for eMMC 4.41 and later
mmc: omap: remove unnecessary #if 0's
mmc: sdhci: fix ctrl_2 on super-speed selection
mmc: dw_mmc-pltfm: add Rockchip variant
mmc: dw_mmc-pltfm: move probe and remove below dt match table
mmc: dw_mmc-pltfm: remove static from dw_mci_pltfm_remove
mmc: sdhci-acpi: add support for eMMC hardware reset for HID 80860F14
mmc: sdhci-pci: add support for eMMC hardware reset for BYT eMMC.
mmc: dw_mmc: Add support DW SD/MMC driver on SOCFPGA
mmc: sdhci: fix caps2 for HS200
sdhci-pxav3: Fix runtime PM initialization
mmc: core: Add DT-bindings for MMC_CAP2_FULL_PWR_CYCLE
mmc: core: Invent MMC_CAP2_FULL_PWR_CYCLE
mmc: core: Enable power_off_notify for eMMC shutdown sequence
...

+1811 -794
+1
Documentation/devicetree/bindings/mmc/mmc.txt
··· 28 28 - cap-mmc-highspeed: MMC high-speed timing is supported 29 29 - cap-power-off-card: powering off the card is safe 30 30 - cap-sdio-irq: enable SDIO IRQ signalling on this interface 31 + - full-pwr-cycle: full power cycle of the card is supported 31 32 32 33 *NOTE* on CD and WP polarity. To use common for all SD/MMC host controllers line 33 34 polarity properties, we have to fix the meaning of the "normal" and "inverted"
+23
Documentation/devicetree/bindings/mmc/rockchip-dw-mshc.txt
··· 1 + * Rockchip specific extensions to the Synopsis Designware Mobile 2 + Storage Host Controller 3 + 4 + The Synopsis designware mobile storage host controller is used to interface 5 + a SoC with storage medium such as eMMC or SD/MMC cards. This file documents 6 + differences between the core Synopsis dw mshc controller properties described 7 + by synopsis-dw-mshc.txt and the properties used by the Rockchip specific 8 + extensions to the Synopsis Designware Mobile Storage Host Controller. 9 + 10 + Required Properties: 11 + 12 + * compatible: should be 13 + - "rockchip,rk2928-dw-mshc": for Rockchip RK2928 and following 14 + 15 + Example: 16 + 17 + rkdwmmc0@12200000 { 18 + compatible = "rockchip,rk2928-dw-mshc"; 19 + reg = <0x12200000 0x1000>; 20 + interrupts = <0 75 0>; 21 + #address-cells = <1>; 22 + #size-cells = <0>; 23 + };
+20
Documentation/devicetree/bindings/mmc/synopsis-dw-mshc.txt
··· 39 39 40 40 Optional properties: 41 41 42 + * clocks: from common clock binding: handle to biu and ciu clocks for the 43 + bus interface unit clock and the card interface unit clock. 44 + 45 + * clock-names: from common clock binding: Shall be "biu" and "ciu". 46 + If the biu clock is missing we'll simply skip enabling it. If the 47 + ciu clock is missing we'll just assume that the clock is running at 48 + clock-frequency. It is an error to omit both the ciu clock and the 49 + clock-frequency. 50 + 51 + * clock-frequency: should be the frequency (in Hz) of the ciu clock. If this 52 + is specified and the ciu clock is specified then we'll try to set the ciu 53 + clock to this at probe time. 54 + 42 55 * num-slots: specifies the number of slots supported by the controller. 43 56 The number of physical slots actually used could be equal or less than the 44 57 value specified by num-slots. If this property is not specified, the value ··· 68 55 69 56 * broken-cd: as documented in mmc core bindings. 70 57 58 + * vmmc-supply: The phandle to the regulator to use for vmmc. If this is 59 + specified we'll defer probe until we can find this regulator. 60 + 71 61 Aliases: 72 62 73 63 - All the MSHC controller nodes should be represented in the aliases node using ··· 83 67 84 68 dwmmc0@12200000 { 85 69 compatible = "snps,dw-mshc"; 70 + clocks = <&clock 351>, <&clock 132>; 71 + clock-names = "biu", "ciu"; 86 72 reg = <0x12200000 0x1000>; 87 73 interrupts = <0 75 0>; 88 74 #address-cells = <1>; ··· 92 74 }; 93 75 94 76 dwmmc0@12200000 { 77 + clock-frequency = <400000000>; 95 78 num-slots = <1>; 96 79 supports-highspeed; 97 80 broken-cd; 98 81 fifo-depth = <0x80>; 99 82 card-detect-delay = <200>; 83 + vmmc-supply = <&buck8>; 100 84 101 85 slot@0 { 102 86 reg = <0>;
+7
arch/arm/configs/bcm_defconfig
··· 78 78 CONFIG_LCD_CLASS_DEVICE=y 79 79 CONFIG_BACKLIGHT_CLASS_DEVICE=y 80 80 # CONFIG_USB_SUPPORT is not set 81 + CONFIG_MMC=y 82 + CONFIG_MMC_UNSAFE_RESUME=y 83 + CONFIG_MMC_BLOCK_MINORS=32 84 + CONFIG_MMC_TEST=y 85 + CONFIG_MMC_SDHCI=y 86 + CONFIG_MMC_SDHCI_PLTFM=y 87 + CONFIG_MMC_SDHCI_BCM_KONA=y 81 88 CONFIG_NEW_LEDS=y 82 89 CONFIG_LEDS_CLASS=y 83 90 CONFIG_LEDS_TRIGGERS=y
+95 -35
drivers/mmc/card/block.c
··· 34 34 #include <linux/delay.h> 35 35 #include <linux/capability.h> 36 36 #include <linux/compat.h> 37 + #include <linux/pm_runtime.h> 37 38 38 39 #include <linux/mmc/ioctl.h> 39 40 #include <linux/mmc/card.h> ··· 59 58 #define INAND_CMD38_ARG_SECTRIM1 0x81 60 59 #define INAND_CMD38_ARG_SECTRIM2 0x88 61 60 #define MMC_BLK_TIMEOUT_MS (10 * 60 * 1000) /* 10 minute timeout */ 61 + #define MMC_SANITIZE_REQ_TIMEOUT 240000 62 + #define MMC_EXTRACT_INDEX_FROM_ARG(x) ((x & 0x00FF0000) >> 16) 62 63 63 64 #define mmc_req_rel_wr(req) (((req->cmd_flags & REQ_FUA) || \ 64 65 (req->cmd_flags & REQ_META)) && \ ··· 225 222 md = mmc_blk_get(dev_to_disk(dev)); 226 223 card = md->queue.card; 227 224 228 - mmc_claim_host(card->host); 225 + mmc_get_card(card); 229 226 230 227 ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP, 231 228 card->ext_csd.boot_ro_lock | ··· 236 233 else 237 234 card->ext_csd.boot_ro_lock |= EXT_CSD_BOOT_WP_B_PWR_WP_EN; 238 235 239 - mmc_release_host(card->host); 236 + mmc_put_card(card); 240 237 241 238 if (!ret) { 242 239 pr_info("%s: Locking boot partition ro until next power on\n", ··· 411 408 return err; 412 409 } 413 410 411 + static int ioctl_do_sanitize(struct mmc_card *card) 412 + { 413 + int err; 414 + 415 + if (!(mmc_can_sanitize(card) && 416 + (card->host->caps2 & MMC_CAP2_SANITIZE))) { 417 + pr_warn("%s: %s - SANITIZE is not supported\n", 418 + mmc_hostname(card->host), __func__); 419 + err = -EOPNOTSUPP; 420 + goto out; 421 + } 422 + 423 + pr_debug("%s: %s - SANITIZE IN PROGRESS...\n", 424 + mmc_hostname(card->host), __func__); 425 + 426 + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 427 + EXT_CSD_SANITIZE_START, 1, 428 + MMC_SANITIZE_REQ_TIMEOUT); 429 + 430 + if (err) 431 + pr_err("%s: %s - EXT_CSD_SANITIZE_START failed. err=%d\n", 432 + mmc_hostname(card->host), __func__, err); 433 + 434 + pr_debug("%s: %s - SANITIZE COMPLETED\n", mmc_hostname(card->host), 435 + __func__); 436 + out: 437 + return err; 438 + } 439 + 414 440 static int mmc_blk_ioctl_cmd(struct block_device *bdev, 415 441 struct mmc_ioc_cmd __user *ic_ptr) 416 442 { ··· 523 491 524 492 mrq.cmd = &cmd; 525 493 526 - mmc_claim_host(card->host); 494 + mmc_get_card(card); 527 495 528 496 err = mmc_blk_part_switch(card, md); 529 497 if (err) ··· 540 508 idata->ic.write_flag & (1 << 31)); 541 509 if (err) 542 510 goto cmd_rel_host; 511 + } 512 + 513 + if ((MMC_EXTRACT_INDEX_FROM_ARG(cmd.arg) == EXT_CSD_SANITIZE_START) && 514 + (cmd.opcode == MMC_SWITCH)) { 515 + err = ioctl_do_sanitize(card); 516 + 517 + if (err) 518 + pr_err("%s: ioctl_do_sanitize() failed. err = %d", 519 + __func__, err); 520 + 521 + goto cmd_rel_host; 543 522 } 544 523 545 524 mmc_wait_for_req(card->host, &mrq); ··· 601 558 } 602 559 603 560 cmd_rel_host: 604 - mmc_release_host(card->host); 561 + mmc_put_card(card); 605 562 606 563 cmd_done: 607 564 mmc_blk_put(md); ··· 982 939 { 983 940 struct mmc_blk_data *md = mq->data; 984 941 struct mmc_card *card = md->queue.card; 985 - unsigned int from, nr, arg, trim_arg, erase_arg; 942 + unsigned int from, nr, arg; 986 943 int err = 0, type = MMC_BLK_SECDISCARD; 987 944 988 - if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) { 945 + if (!(mmc_can_secure_erase_trim(card))) { 989 946 err = -EOPNOTSUPP; 990 947 goto out; 991 948 } ··· 993 950 from = blk_rq_pos(req); 994 951 nr = blk_rq_sectors(req); 995 952 996 - /* The sanitize operation is supported at v4.5 only */ 997 - if (mmc_can_sanitize(card)) { 998 - erase_arg = MMC_ERASE_ARG; 999 - trim_arg = MMC_TRIM_ARG; 1000 - } else { 1001 - erase_arg = MMC_SECURE_ERASE_ARG; 1002 - trim_arg = MMC_SECURE_TRIM1_ARG; 1003 - } 953 + if (mmc_can_trim(card) && !mmc_erase_group_aligned(card, from, nr)) 954 + arg = MMC_SECURE_TRIM1_ARG; 955 + else 956 + arg = MMC_SECURE_ERASE_ARG; 1004 957 1005 - if (mmc_erase_group_aligned(card, from, nr)) 1006 - arg = erase_arg; 1007 - else if (mmc_can_trim(card)) 1008 - arg = trim_arg; 1009 - else { 1010 - err = -EINVAL; 1011 - goto out; 1012 - } 1013 958 retry: 1014 959 if (card->quirks & MMC_QUIRK_INAND_CMD38) { 1015 960 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, ··· 1033 1002 goto out; 1034 1003 } 1035 1004 1036 - if (mmc_can_sanitize(card)) 1037 - err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1038 - EXT_CSD_SANITIZE_START, 1, 0); 1039 1005 out_retry: 1040 1006 if (err && !mmc_blk_reset(md, card->host, type)) 1041 1007 goto retry; ··· 1923 1895 1924 1896 if (req && !mq->mqrq_prev->req) 1925 1897 /* claim host only for the first request */ 1926 - mmc_claim_host(card->host); 1898 + mmc_get_card(card); 1927 1899 1928 1900 ret = mmc_blk_part_switch(card, md); 1929 1901 if (ret) { ··· 1967 1939 * In case sepecial request, there is no reentry to 1968 1940 * the 'mmc_blk_issue_rq' with 'mqrq_prev->req'. 1969 1941 */ 1970 - mmc_release_host(card->host); 1942 + mmc_put_card(card); 1971 1943 return ret; 1972 1944 } 1973 1945 ··· 2186 2158 struct mmc_card *card; 2187 2159 2188 2160 if (md) { 2161 + /* 2162 + * Flush remaining requests and free queues. It 2163 + * is freeing the queue that stops new requests 2164 + * from being accepted. 2165 + */ 2166 + mmc_cleanup_queue(&md->queue); 2167 + if (md->flags & MMC_BLK_PACKED_CMD) 2168 + mmc_packed_clean(&md->queue); 2189 2169 card = md->queue.card; 2190 2170 if (md->disk->flags & GENHD_FL_UP) { 2191 2171 device_remove_file(disk_to_dev(md->disk), &md->force_ro); ··· 2202 2166 device_remove_file(disk_to_dev(md->disk), 2203 2167 &md->power_ro_lock); 2204 2168 2205 - /* Stop new requests from getting into the queue */ 2206 2169 del_gendisk(md->disk); 2207 2170 } 2208 - 2209 - /* Then flush out any already in there */ 2210 - mmc_cleanup_queue(&md->queue); 2211 - if (md->flags & MMC_BLK_PACKED_CMD) 2212 - mmc_packed_clean(&md->queue); 2213 2171 mmc_blk_put(md); 2214 2172 } 2215 2173 } ··· 2366 2336 if (mmc_add_disk(part_md)) 2367 2337 goto out; 2368 2338 } 2339 + 2340 + pm_runtime_set_autosuspend_delay(&card->dev, 3000); 2341 + pm_runtime_use_autosuspend(&card->dev); 2342 + 2343 + /* 2344 + * Don't enable runtime PM for SD-combo cards here. Leave that 2345 + * decision to be taken during the SDIO init sequence instead. 2346 + */ 2347 + if (card->type != MMC_TYPE_SD_COMBO) { 2348 + pm_runtime_set_active(&card->dev); 2349 + pm_runtime_enable(&card->dev); 2350 + } 2351 + 2369 2352 return 0; 2370 2353 2371 2354 out: ··· 2392 2349 struct mmc_blk_data *md = mmc_get_drvdata(card); 2393 2350 2394 2351 mmc_blk_remove_parts(card, md); 2352 + pm_runtime_get_sync(&card->dev); 2395 2353 mmc_claim_host(card->host); 2396 2354 mmc_blk_part_switch(card, md); 2397 2355 mmc_release_host(card->host); 2356 + if (card->type != MMC_TYPE_SD_COMBO) 2357 + pm_runtime_disable(&card->dev); 2358 + pm_runtime_put_noidle(&card->dev); 2398 2359 mmc_blk_remove_req(md); 2399 2360 mmc_set_drvdata(card, NULL); 2400 2361 } 2401 2362 2402 - #ifdef CONFIG_PM 2403 - static int mmc_blk_suspend(struct mmc_card *card) 2363 + static int _mmc_blk_suspend(struct mmc_card *card) 2404 2364 { 2405 2365 struct mmc_blk_data *part_md; 2406 2366 struct mmc_blk_data *md = mmc_get_drvdata(card); 2407 2367 2408 2368 if (md) { 2369 + pm_runtime_get_sync(&card->dev); 2409 2370 mmc_queue_suspend(&md->queue); 2410 2371 list_for_each_entry(part_md, &md->part, part) { 2411 2372 mmc_queue_suspend(&part_md->queue); 2412 2373 } 2413 2374 } 2414 2375 return 0; 2376 + } 2377 + 2378 + static void mmc_blk_shutdown(struct mmc_card *card) 2379 + { 2380 + _mmc_blk_suspend(card); 2381 + } 2382 + 2383 + #ifdef CONFIG_PM 2384 + static int mmc_blk_suspend(struct mmc_card *card) 2385 + { 2386 + return _mmc_blk_suspend(card); 2415 2387 } 2416 2388 2417 2389 static int mmc_blk_resume(struct mmc_card *card) ··· 2444 2386 list_for_each_entry(part_md, &md->part, part) { 2445 2387 mmc_queue_resume(&part_md->queue); 2446 2388 } 2389 + pm_runtime_put(&card->dev); 2447 2390 } 2448 2391 return 0; 2449 2392 } ··· 2461 2402 .remove = mmc_blk_remove, 2462 2403 .suspend = mmc_blk_suspend, 2463 2404 .resume = mmc_blk_resume, 2405 + .shutdown = mmc_blk_shutdown, 2464 2406 }; 2465 2407 2466 2408 static int __init mmc_blk_init(void)
+5
drivers/mmc/card/mmc_test.c
··· 3025 3025 mmc_test_free_dbgfs_file(card); 3026 3026 } 3027 3027 3028 + static void mmc_test_shutdown(struct mmc_card *card) 3029 + { 3030 + } 3031 + 3028 3032 static struct mmc_driver mmc_driver = { 3029 3033 .drv = { 3030 3034 .name = "mmc_test", 3031 3035 }, 3032 3036 .probe = mmc_test_probe, 3033 3037 .remove = mmc_test_remove, 3038 + .shutdown = mmc_test_shutdown, 3034 3039 }; 3035 3040 3036 3041 static int __init mmc_test_init(void)
+1 -1
drivers/mmc/card/queue.c
··· 173 173 /* granularity must not be greater than max. discard */ 174 174 if (card->pref_erase > max_discard) 175 175 q->limits.discard_granularity = 0; 176 - if (mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card)) 176 + if (mmc_can_secure_erase_trim(card)) 177 177 queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD, q); 178 178 } 179 179
+47 -5
drivers/mmc/core/bus.c
··· 122 122 return 0; 123 123 } 124 124 125 + static void mmc_bus_shutdown(struct device *dev) 126 + { 127 + struct mmc_driver *drv = to_mmc_driver(dev->driver); 128 + struct mmc_card *card = mmc_dev_to_card(dev); 129 + struct mmc_host *host = card->host; 130 + int ret; 131 + 132 + if (dev->driver && drv->shutdown) 133 + drv->shutdown(card); 134 + 135 + if (host->bus_ops->shutdown) { 136 + ret = host->bus_ops->shutdown(host); 137 + if (ret) 138 + pr_warn("%s: error %d during shutdown\n", 139 + mmc_hostname(host), ret); 140 + } 141 + } 142 + 125 143 #ifdef CONFIG_PM_SLEEP 126 144 static int mmc_bus_suspend(struct device *dev) 127 145 { 128 146 struct mmc_driver *drv = to_mmc_driver(dev->driver); 129 147 struct mmc_card *card = mmc_dev_to_card(dev); 130 - int ret = 0; 148 + struct mmc_host *host = card->host; 149 + int ret; 131 150 132 - if (dev->driver && drv->suspend) 151 + if (dev->driver && drv->suspend) { 133 152 ret = drv->suspend(card); 153 + if (ret) 154 + return ret; 155 + } 156 + 157 + ret = host->bus_ops->suspend(host); 134 158 return ret; 135 159 } 136 160 ··· 162 138 { 163 139 struct mmc_driver *drv = to_mmc_driver(dev->driver); 164 140 struct mmc_card *card = mmc_dev_to_card(dev); 165 - int ret = 0; 141 + struct mmc_host *host = card->host; 142 + int ret; 143 + 144 + ret = host->bus_ops->resume(host); 145 + if (ret) 146 + pr_warn("%s: error %d during resume (card was removed?)\n", 147 + mmc_hostname(host), ret); 166 148 167 149 if (dev->driver && drv->resume) 168 150 ret = drv->resume(card); 151 + 169 152 return ret; 170 153 } 171 154 #endif ··· 182 151 static int mmc_runtime_suspend(struct device *dev) 183 152 { 184 153 struct mmc_card *card = mmc_dev_to_card(dev); 154 + struct mmc_host *host = card->host; 155 + int ret = 0; 185 156 186 - return mmc_power_save_host(card->host); 157 + if (host->bus_ops->runtime_suspend) 158 + ret = host->bus_ops->runtime_suspend(host); 159 + 160 + return ret; 187 161 } 188 162 189 163 static int mmc_runtime_resume(struct device *dev) 190 164 { 191 165 struct mmc_card *card = mmc_dev_to_card(dev); 166 + struct mmc_host *host = card->host; 167 + int ret = 0; 192 168 193 - return mmc_power_restore_host(card->host); 169 + if (host->bus_ops->runtime_resume) 170 + ret = host->bus_ops->runtime_resume(host); 171 + 172 + return ret; 194 173 } 195 174 196 175 static int mmc_runtime_idle(struct device *dev) ··· 223 182 .uevent = mmc_bus_uevent, 224 183 .probe = mmc_bus_probe, 225 184 .remove = mmc_bus_remove, 185 + .shutdown = mmc_bus_shutdown, 226 186 .pm = &mmc_bus_pm_ops, 227 187 }; 228 188
+58 -142
drivers/mmc/core/core.c
··· 402 402 context_info->is_done_rcv = false; 403 403 context_info->is_new_req = false; 404 404 cmd = mrq->cmd; 405 + 405 406 if (!cmd->error || !cmd->retries || 406 407 mmc_card_removed(host->card)) { 407 408 err = host->areq->err_check(host->card, ··· 437 436 wait_for_completion(&mrq->completion); 438 437 439 438 cmd = mrq->cmd; 439 + 440 + /* 441 + * If host has timed out waiting for the sanitize 442 + * to complete, card might be still in programming state 443 + * so let's try to bring the card out of programming 444 + * state. 445 + */ 446 + if (cmd->sanitize_busy && cmd->error == -ETIMEDOUT) { 447 + if (!mmc_interrupt_hpi(host->card)) { 448 + pr_warning("%s: %s: Interrupted sanitize\n", 449 + mmc_hostname(host), __func__); 450 + cmd->error = 0; 451 + break; 452 + } else { 453 + pr_err("%s: %s: Failed to interrupt sanitize\n", 454 + mmc_hostname(host), __func__); 455 + } 456 + } 440 457 if (!cmd->error || !cmd->retries || 441 458 mmc_card_removed(host->card)) 442 459 break; ··· 971 952 EXPORT_SYMBOL(mmc_release_host); 972 953 973 954 /* 955 + * This is a helper function, which fetches a runtime pm reference for the 956 + * card device and also claims the host. 957 + */ 958 + void mmc_get_card(struct mmc_card *card) 959 + { 960 + pm_runtime_get_sync(&card->dev); 961 + mmc_claim_host(card->host); 962 + } 963 + EXPORT_SYMBOL(mmc_get_card); 964 + 965 + /* 966 + * This is a helper function, which releases the host and drops the runtime 967 + * pm reference for the card device. 968 + */ 969 + void mmc_put_card(struct mmc_card *card) 970 + { 971 + mmc_release_host(card->host); 972 + pm_runtime_mark_last_busy(&card->dev); 973 + pm_runtime_put_autosuspend(&card->dev); 974 + } 975 + EXPORT_SYMBOL(mmc_put_card); 976 + 977 + /* 974 978 * Internal function that does the actual ios call to the host driver, 975 979 * optionally printing some debug output. 976 980 */ ··· 1501 1459 * If a host does all the power sequencing itself, ignore the 1502 1460 * initial MMC_POWER_UP stage. 1503 1461 */ 1504 - static void mmc_power_up(struct mmc_host *host) 1462 + void mmc_power_up(struct mmc_host *host) 1505 1463 { 1506 1464 int bit; 1507 1465 ··· 2367 2325 * The card will be considered unchanged unless we have been asked to 2368 2326 * detect a change or host requires polling to provide card detection. 2369 2327 */ 2370 - if (!host->detect_change && !(host->caps & MMC_CAP_NEEDS_POLL) && 2371 - !(host->caps2 & MMC_CAP2_DETECT_ON_ERR)) 2328 + if (!host->detect_change && !(host->caps & MMC_CAP_NEEDS_POLL)) 2372 2329 return ret; 2373 2330 2374 2331 host->detect_change = 0; 2375 2332 if (!ret) { 2376 2333 ret = _mmc_detect_card_removed(host); 2377 - if (ret && (host->caps2 & MMC_CAP2_DETECT_ON_ERR)) { 2334 + if (ret && (host->caps & MMC_CAP_NEEDS_POLL)) { 2378 2335 /* 2379 2336 * Schedule a detect work as soon as possible to let a 2380 2337 * rescan handle the card removal. ··· 2483 2442 mmc_bus_get(host); 2484 2443 if (host->bus_ops && !host->bus_dead) { 2485 2444 /* Calling bus_ops->remove() with a claimed host can deadlock */ 2486 - if (host->bus_ops->remove) 2487 - host->bus_ops->remove(host); 2488 - 2445 + host->bus_ops->remove(host); 2489 2446 mmc_claim_host(host); 2490 2447 mmc_detach_bus(host); 2491 2448 mmc_power_off(host); ··· 2547 2508 return ret; 2548 2509 } 2549 2510 EXPORT_SYMBOL(mmc_power_restore_host); 2550 - 2551 - int mmc_card_awake(struct mmc_host *host) 2552 - { 2553 - int err = -ENOSYS; 2554 - 2555 - if (host->caps2 & MMC_CAP2_NO_SLEEP_CMD) 2556 - return 0; 2557 - 2558 - mmc_bus_get(host); 2559 - 2560 - if (host->bus_ops && !host->bus_dead && host->bus_ops->awake) 2561 - err = host->bus_ops->awake(host); 2562 - 2563 - mmc_bus_put(host); 2564 - 2565 - return err; 2566 - } 2567 - EXPORT_SYMBOL(mmc_card_awake); 2568 - 2569 - int mmc_card_sleep(struct mmc_host *host) 2570 - { 2571 - int err = -ENOSYS; 2572 - 2573 - if (host->caps2 & MMC_CAP2_NO_SLEEP_CMD) 2574 - return 0; 2575 - 2576 - mmc_bus_get(host); 2577 - 2578 - if (host->bus_ops && !host->bus_dead && host->bus_ops->sleep) 2579 - err = host->bus_ops->sleep(host); 2580 - 2581 - mmc_bus_put(host); 2582 - 2583 - return err; 2584 - } 2585 - EXPORT_SYMBOL(mmc_card_sleep); 2586 - 2587 - int mmc_card_can_sleep(struct mmc_host *host) 2588 - { 2589 - struct mmc_card *card = host->card; 2590 - 2591 - if (card && mmc_card_mmc(card) && card->ext_csd.rev >= 3) 2592 - return 1; 2593 - return 0; 2594 - } 2595 - EXPORT_SYMBOL(mmc_card_can_sleep); 2596 2511 2597 2512 /* 2598 2513 * Flush the cache to the non-volatile storage. ··· 2619 2626 */ 2620 2627 int mmc_suspend_host(struct mmc_host *host) 2621 2628 { 2622 - int err = 0; 2623 - 2624 - cancel_delayed_work(&host->detect); 2625 - mmc_flush_scheduled_work(); 2626 - 2627 - mmc_bus_get(host); 2628 - if (host->bus_ops && !host->bus_dead) { 2629 - if (host->bus_ops->suspend) { 2630 - if (mmc_card_doing_bkops(host->card)) { 2631 - err = mmc_stop_bkops(host->card); 2632 - if (err) 2633 - goto out; 2634 - } 2635 - err = host->bus_ops->suspend(host); 2636 - } 2637 - 2638 - if (err == -ENOSYS || !host->bus_ops->resume) { 2639 - /* 2640 - * We simply "remove" the card in this case. 2641 - * It will be redetected on resume. (Calling 2642 - * bus_ops->remove() with a claimed host can 2643 - * deadlock.) 2644 - */ 2645 - if (host->bus_ops->remove) 2646 - host->bus_ops->remove(host); 2647 - mmc_claim_host(host); 2648 - mmc_detach_bus(host); 2649 - mmc_power_off(host); 2650 - mmc_release_host(host); 2651 - host->pm_flags = 0; 2652 - err = 0; 2653 - } 2654 - } 2655 - mmc_bus_put(host); 2656 - 2657 - if (!err && !mmc_card_keep_power(host)) 2658 - mmc_power_off(host); 2659 - 2660 - out: 2661 - return err; 2629 + /* This function is deprecated */ 2630 + return 0; 2662 2631 } 2663 - 2664 2632 EXPORT_SYMBOL(mmc_suspend_host); 2665 2633 2666 2634 /** ··· 2630 2676 */ 2631 2677 int mmc_resume_host(struct mmc_host *host) 2632 2678 { 2633 - int err = 0; 2634 - 2635 - mmc_bus_get(host); 2636 - if (host->bus_ops && !host->bus_dead) { 2637 - if (!mmc_card_keep_power(host)) { 2638 - mmc_power_up(host); 2639 - mmc_select_voltage(host, host->ocr); 2640 - /* 2641 - * Tell runtime PM core we just powered up the card, 2642 - * since it still believes the card is powered off. 2643 - * Note that currently runtime PM is only enabled 2644 - * for SDIO cards that are MMC_CAP_POWER_OFF_CARD 2645 - */ 2646 - if (mmc_card_sdio(host->card) && 2647 - (host->caps & MMC_CAP_POWER_OFF_CARD)) { 2648 - pm_runtime_disable(&host->card->dev); 2649 - pm_runtime_set_active(&host->card->dev); 2650 - pm_runtime_enable(&host->card->dev); 2651 - } 2652 - } 2653 - BUG_ON(!host->bus_ops->resume); 2654 - err = host->bus_ops->resume(host); 2655 - if (err) { 2656 - pr_warning("%s: error %d during resume " 2657 - "(card was removed?)\n", 2658 - mmc_hostname(host), err); 2659 - err = 0; 2660 - } 2661 - } 2662 - host->pm_flags &= ~MMC_PM_KEEP_POWER; 2663 - mmc_bus_put(host); 2664 - 2665 - return err; 2679 + /* This function is deprecated */ 2680 + return 0; 2666 2681 } 2667 2682 EXPORT_SYMBOL(mmc_resume_host); 2668 2683 ··· 2650 2727 switch (mode) { 2651 2728 case PM_HIBERNATION_PREPARE: 2652 2729 case PM_SUSPEND_PREPARE: 2653 - if (host->card && mmc_card_mmc(host->card) && 2654 - mmc_card_doing_bkops(host->card)) { 2655 - err = mmc_stop_bkops(host->card); 2656 - if (err) { 2657 - pr_err("%s: didn't stop bkops\n", 2658 - mmc_hostname(host)); 2659 - return err; 2660 - } 2661 - mmc_card_clr_doing_bkops(host->card); 2662 - } 2663 - 2664 2730 spin_lock_irqsave(&host->lock, flags); 2665 2731 host->rescan_disable = 1; 2666 2732 spin_unlock_irqrestore(&host->lock, flags); 2667 2733 cancel_delayed_work_sync(&host->detect); 2668 2734 2669 - if (!host->bus_ops || host->bus_ops->suspend) 2735 + if (!host->bus_ops) 2736 + break; 2737 + 2738 + /* Validate prerequisites for suspend */ 2739 + if (host->bus_ops->pre_suspend) 2740 + err = host->bus_ops->pre_suspend(host); 2741 + if (!err && host->bus_ops->suspend) 2670 2742 break; 2671 2743 2672 2744 /* Calling bus_ops->remove() with a claimed host can deadlock */ 2673 - if (host->bus_ops->remove) 2674 - host->bus_ops->remove(host); 2675 - 2745 + host->bus_ops->remove(host); 2676 2746 mmc_claim_host(host); 2677 2747 mmc_detach_bus(host); 2678 2748 mmc_power_off(host);
+5 -2
drivers/mmc/core/core.h
··· 16 16 #define MMC_CMD_RETRIES 3 17 17 18 18 struct mmc_bus_ops { 19 - int (*awake)(struct mmc_host *); 20 - int (*sleep)(struct mmc_host *); 21 19 void (*remove)(struct mmc_host *); 22 20 void (*detect)(struct mmc_host *); 21 + int (*pre_suspend)(struct mmc_host *); 23 22 int (*suspend)(struct mmc_host *); 24 23 int (*resume)(struct mmc_host *); 24 + int (*runtime_suspend)(struct mmc_host *); 25 + int (*runtime_resume)(struct mmc_host *); 25 26 int (*power_save)(struct mmc_host *); 26 27 int (*power_restore)(struct mmc_host *); 27 28 int (*alive)(struct mmc_host *); 29 + int (*shutdown)(struct mmc_host *); 28 30 }; 29 31 30 32 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops); ··· 46 44 int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage); 47 45 void mmc_set_timing(struct mmc_host *host, unsigned int timing); 48 46 void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type); 47 + void mmc_power_up(struct mmc_host *host); 49 48 void mmc_power_off(struct mmc_host *host); 50 49 void mmc_power_cycle(struct mmc_host *host); 51 50
+4 -4
drivers/mmc/core/debugfs.c
··· 258 258 u32 status; 259 259 int ret; 260 260 261 - mmc_claim_host(card->host); 261 + mmc_get_card(card); 262 262 263 263 ret = mmc_send_status(data, &status); 264 264 if (!ret) 265 265 *val = status; 266 266 267 - mmc_release_host(card->host); 267 + mmc_put_card(card); 268 268 269 269 return ret; 270 270 } ··· 291 291 goto out_free; 292 292 } 293 293 294 - mmc_claim_host(card->host); 294 + mmc_get_card(card); 295 295 err = mmc_send_ext_csd(card, ext_csd); 296 - mmc_release_host(card->host); 296 + mmc_put_card(card); 297 297 if (err) 298 298 goto out_free; 299 299
+27 -5
drivers/mmc/core/host.c
··· 306 306 * parse the properties and set respective generic mmc-host flags and 307 307 * parameters. 308 308 */ 309 - void mmc_of_parse(struct mmc_host *host) 309 + int mmc_of_parse(struct mmc_host *host) 310 310 { 311 311 struct device_node *np; 312 312 u32 bus_width; ··· 315 315 int len, ret, gpio; 316 316 317 317 if (!host->parent || !host->parent->of_node) 318 - return; 318 + return 0; 319 319 320 320 np = host->parent->of_node; 321 321 ··· 338 338 default: 339 339 dev_err(host->parent, 340 340 "Invalid \"bus-width\" value %ud!\n", bus_width); 341 + return -EINVAL; 341 342 } 342 343 343 344 /* f_max is obtained from the optional "max-frequency" property */ ··· 368 367 host->caps |= MMC_CAP_NEEDS_POLL; 369 368 370 369 gpio = of_get_named_gpio_flags(np, "cd-gpios", 0, &flags); 370 + if (gpio == -EPROBE_DEFER) 371 + return gpio; 371 372 if (gpio_is_valid(gpio)) { 372 373 if (!(flags & OF_GPIO_ACTIVE_LOW)) 373 374 gpio_inv_cd = true; 374 375 375 376 ret = mmc_gpio_request_cd(host, gpio); 376 - if (ret < 0) 377 + if (ret < 0) { 377 378 dev_err(host->parent, 378 379 "Failed to request CD GPIO #%d: %d!\n", 379 380 gpio, ret); 380 - else 381 + return ret; 382 + } else { 381 383 dev_info(host->parent, "Got CD GPIO #%d.\n", 382 384 gpio); 385 + } 383 386 } 384 387 385 388 if (explicit_inv_cd ^ gpio_inv_cd) ··· 394 389 explicit_inv_wp = of_property_read_bool(np, "wp-inverted"); 395 390 396 391 gpio = of_get_named_gpio_flags(np, "wp-gpios", 0, &flags); 392 + if (gpio == -EPROBE_DEFER) { 393 + ret = -EPROBE_DEFER; 394 + goto out; 395 + } 397 396 if (gpio_is_valid(gpio)) { 398 397 if (!(flags & OF_GPIO_ACTIVE_LOW)) 399 398 gpio_inv_wp = true; 400 399 401 400 ret = mmc_gpio_request_ro(host, gpio); 402 - if (ret < 0) 401 + if (ret < 0) { 403 402 dev_err(host->parent, 404 403 "Failed to request WP GPIO: %d!\n", ret); 404 + goto out; 405 + } else { 406 + dev_info(host->parent, "Got WP GPIO #%d.\n", 407 + gpio); 408 + } 405 409 } 406 410 if (explicit_inv_wp ^ gpio_inv_wp) 407 411 host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; ··· 423 409 host->caps |= MMC_CAP_POWER_OFF_CARD; 424 410 if (of_find_property(np, "cap-sdio-irq", &len)) 425 411 host->caps |= MMC_CAP_SDIO_IRQ; 412 + if (of_find_property(np, "full-pwr-cycle", &len)) 413 + host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE; 426 414 if (of_find_property(np, "keep-power-in-suspend", &len)) 427 415 host->pm_caps |= MMC_PM_KEEP_POWER; 428 416 if (of_find_property(np, "enable-sdio-wakeup", &len)) 429 417 host->pm_caps |= MMC_PM_WAKE_SDIO_IRQ; 418 + 419 + return 0; 420 + 421 + out: 422 + mmc_gpio_free_cd(host); 423 + return ret; 430 424 } 431 425 432 426 EXPORT_SYMBOL(mmc_of_parse);
+184 -73
drivers/mmc/core/mmc.c
··· 293 293 } 294 294 295 295 card->ext_csd.rev = ext_csd[EXT_CSD_REV]; 296 - if (card->ext_csd.rev > 6) { 296 + if (card->ext_csd.rev > 7) { 297 297 pr_err("%s: unrecognised EXT_CSD revision %d\n", 298 298 mmc_hostname(card->host), card->ext_csd.rev); 299 299 err = -EINVAL; ··· 461 461 */ 462 462 card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; 463 463 card->ext_csd.boot_ro_lockable = true; 464 + 465 + /* Save power class values */ 466 + card->ext_csd.raw_pwr_cl_52_195 = 467 + ext_csd[EXT_CSD_PWR_CL_52_195]; 468 + card->ext_csd.raw_pwr_cl_26_195 = 469 + ext_csd[EXT_CSD_PWR_CL_26_195]; 470 + card->ext_csd.raw_pwr_cl_52_360 = 471 + ext_csd[EXT_CSD_PWR_CL_52_360]; 472 + card->ext_csd.raw_pwr_cl_26_360 = 473 + ext_csd[EXT_CSD_PWR_CL_26_360]; 474 + card->ext_csd.raw_pwr_cl_200_195 = 475 + ext_csd[EXT_CSD_PWR_CL_200_195]; 476 + card->ext_csd.raw_pwr_cl_200_360 = 477 + ext_csd[EXT_CSD_PWR_CL_200_360]; 478 + card->ext_csd.raw_pwr_cl_ddr_52_195 = 479 + ext_csd[EXT_CSD_PWR_CL_DDR_52_195]; 480 + card->ext_csd.raw_pwr_cl_ddr_52_360 = 481 + ext_csd[EXT_CSD_PWR_CL_DDR_52_360]; 464 482 } 465 483 466 484 if (card->ext_csd.rev >= 5) { 485 + /* Adjust production date as per JEDEC JESD84-B451 */ 486 + if (card->cid.year < 2010) 487 + card->cid.year += 16; 488 + 467 489 /* check whether the eMMC card supports BKOPS */ 468 490 if (ext_csd[EXT_CSD_BKOPS_SUPPORT] & 0x1) { 469 491 card->ext_csd.bkops = 1; ··· 629 607 (card->ext_csd.raw_sectors[2] == 630 608 bw_ext_csd[EXT_CSD_SEC_CNT + 2]) && 631 609 (card->ext_csd.raw_sectors[3] == 632 - bw_ext_csd[EXT_CSD_SEC_CNT + 3])); 610 + bw_ext_csd[EXT_CSD_SEC_CNT + 3]) && 611 + (card->ext_csd.raw_pwr_cl_52_195 == 612 + bw_ext_csd[EXT_CSD_PWR_CL_52_195]) && 613 + (card->ext_csd.raw_pwr_cl_26_195 == 614 + bw_ext_csd[EXT_CSD_PWR_CL_26_195]) && 615 + (card->ext_csd.raw_pwr_cl_52_360 == 616 + bw_ext_csd[EXT_CSD_PWR_CL_52_360]) && 617 + (card->ext_csd.raw_pwr_cl_26_360 == 618 + bw_ext_csd[EXT_CSD_PWR_CL_26_360]) && 619 + (card->ext_csd.raw_pwr_cl_200_195 == 620 + bw_ext_csd[EXT_CSD_PWR_CL_200_195]) && 621 + (card->ext_csd.raw_pwr_cl_200_360 == 622 + bw_ext_csd[EXT_CSD_PWR_CL_200_360]) && 623 + (card->ext_csd.raw_pwr_cl_ddr_52_195 == 624 + bw_ext_csd[EXT_CSD_PWR_CL_DDR_52_195]) && 625 + (card->ext_csd.raw_pwr_cl_ddr_52_360 == 626 + bw_ext_csd[EXT_CSD_PWR_CL_DDR_52_360])); 633 627 if (err) 634 628 err = -EINVAL; 635 629 ··· 714 676 * mmc_switch command. 715 677 */ 716 678 static int mmc_select_powerclass(struct mmc_card *card, 717 - unsigned int bus_width, u8 *ext_csd) 679 + unsigned int bus_width) 718 680 { 719 681 int err = 0; 720 - unsigned int pwrclass_val; 721 - unsigned int index = 0; 682 + unsigned int pwrclass_val = 0; 722 683 struct mmc_host *host; 723 684 724 685 BUG_ON(!card); 725 686 726 687 host = card->host; 727 688 BUG_ON(!host); 728 - 729 - if (ext_csd == NULL) 730 - return 0; 731 689 732 690 /* Power class selection is supported for versions >= 4.0 */ 733 691 if (card->csd.mmca_vsn < CSD_SPEC_VER_4) ··· 736 702 switch (1 << host->ios.vdd) { 737 703 case MMC_VDD_165_195: 738 704 if (host->ios.clock <= 26000000) 739 - index = EXT_CSD_PWR_CL_26_195; 705 + pwrclass_val = card->ext_csd.raw_pwr_cl_26_195; 740 706 else if (host->ios.clock <= 52000000) 741 - index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? 742 - EXT_CSD_PWR_CL_52_195 : 743 - EXT_CSD_PWR_CL_DDR_52_195; 707 + pwrclass_val = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? 708 + card->ext_csd.raw_pwr_cl_52_195 : 709 + card->ext_csd.raw_pwr_cl_ddr_52_195; 744 710 else if (host->ios.clock <= 200000000) 745 - index = EXT_CSD_PWR_CL_200_195; 711 + pwrclass_val = card->ext_csd.raw_pwr_cl_200_195; 746 712 break; 747 713 case MMC_VDD_27_28: 748 714 case MMC_VDD_28_29: ··· 754 720 case MMC_VDD_34_35: 755 721 case MMC_VDD_35_36: 756 722 if (host->ios.clock <= 26000000) 757 - index = EXT_CSD_PWR_CL_26_360; 723 + pwrclass_val = card->ext_csd.raw_pwr_cl_26_360; 758 724 else if (host->ios.clock <= 52000000) 759 - index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? 760 - EXT_CSD_PWR_CL_52_360 : 761 - EXT_CSD_PWR_CL_DDR_52_360; 725 + pwrclass_val = (bus_width <= EXT_CSD_BUS_WIDTH_8) ? 726 + card->ext_csd.raw_pwr_cl_52_360 : 727 + card->ext_csd.raw_pwr_cl_ddr_52_360; 762 728 else if (host->ios.clock <= 200000000) 763 - index = EXT_CSD_PWR_CL_200_360; 729 + pwrclass_val = card->ext_csd.raw_pwr_cl_200_360; 764 730 break; 765 731 default: 766 732 pr_warning("%s: Voltage range not supported " 767 733 "for power class.\n", mmc_hostname(host)); 768 734 return -EINVAL; 769 735 } 770 - 771 - pwrclass_val = ext_csd[index]; 772 736 773 737 if (bus_width & (EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_BUS_WIDTH_8)) 774 738 pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_8BIT_MASK) >> ··· 1045 1013 } 1046 1014 1047 1015 /* 1048 - * If the host supports the power_off_notify capability then 1049 - * set the notification byte in the ext_csd register of device 1016 + * Enable power_off_notification byte in the ext_csd register 1050 1017 */ 1051 - if ((host->caps2 & MMC_CAP2_POWEROFF_NOTIFY) && 1052 - (card->ext_csd.rev >= 6)) { 1018 + if (card->ext_csd.rev >= 6) { 1053 1019 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1054 1020 EXT_CSD_POWER_OFF_NOTIFICATION, 1055 1021 EXT_CSD_POWER_ON, ··· 1161 1131 1162 1132 ext_csd_bits = (bus_width == MMC_BUS_WIDTH_8) ? 1163 1133 EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; 1164 - err = mmc_select_powerclass(card, ext_csd_bits, ext_csd); 1134 + err = mmc_select_powerclass(card, ext_csd_bits); 1165 1135 if (err) 1166 1136 pr_warning("%s: power class selection to bus width %d" 1167 1137 " failed\n", mmc_hostname(card->host), ··· 1194 1164 bus_width = bus_widths[idx]; 1195 1165 if (bus_width == MMC_BUS_WIDTH_1) 1196 1166 ddr = 0; /* no DDR for 1-bit width */ 1197 - err = mmc_select_powerclass(card, ext_csd_bits[idx][0], 1198 - ext_csd); 1167 + err = mmc_select_powerclass(card, ext_csd_bits[idx][0]); 1199 1168 if (err) 1200 1169 pr_warning("%s: power class selection to " 1201 1170 "bus width %d failed\n", ··· 1224 1195 } 1225 1196 1226 1197 if (!err && ddr) { 1227 - err = mmc_select_powerclass(card, ext_csd_bits[idx][1], 1228 - ext_csd); 1198 + err = mmc_select_powerclass(card, ext_csd_bits[idx][1]); 1229 1199 if (err) 1230 1200 pr_warning("%s: power class selection to " 1231 1201 "bus width %d ddr %d failed\n", ··· 1349 1321 return err; 1350 1322 } 1351 1323 1324 + static int mmc_can_sleep(struct mmc_card *card) 1325 + { 1326 + return (card && card->ext_csd.rev >= 3); 1327 + } 1328 + 1329 + static int mmc_sleep(struct mmc_host *host) 1330 + { 1331 + struct mmc_command cmd = {0}; 1332 + struct mmc_card *card = host->card; 1333 + int err; 1334 + 1335 + if (host->caps2 & MMC_CAP2_NO_SLEEP_CMD) 1336 + return 0; 1337 + 1338 + err = mmc_deselect_cards(host); 1339 + if (err) 1340 + return err; 1341 + 1342 + cmd.opcode = MMC_SLEEP_AWAKE; 1343 + cmd.arg = card->rca << 16; 1344 + cmd.arg |= 1 << 15; 1345 + 1346 + cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; 1347 + err = mmc_wait_for_cmd(host, &cmd, 0); 1348 + if (err) 1349 + return err; 1350 + 1351 + /* 1352 + * If the host does not wait while the card signals busy, then we will 1353 + * will have to wait the sleep/awake timeout. Note, we cannot use the 1354 + * SEND_STATUS command to poll the status because that command (and most 1355 + * others) is invalid while the card sleeps. 1356 + */ 1357 + if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) 1358 + mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000)); 1359 + 1360 + return err; 1361 + } 1362 + 1352 1363 static int mmc_can_poweroff_notify(const struct mmc_card *card) 1353 1364 { 1354 1365 return card && ··· 1447 1380 BUG_ON(!host); 1448 1381 BUG_ON(!host->card); 1449 1382 1450 - mmc_claim_host(host); 1383 + mmc_get_card(host->card); 1451 1384 1452 1385 /* 1453 1386 * Just check if our card has been removed. 1454 1387 */ 1455 1388 err = _mmc_detect_card_removed(host); 1456 1389 1457 - mmc_release_host(host); 1390 + mmc_put_card(host->card); 1458 1391 1459 1392 if (err) { 1460 1393 mmc_remove(host); ··· 1466 1399 } 1467 1400 } 1468 1401 1469 - /* 1470 - * Suspend callback from host. 1471 - */ 1472 - static int mmc_suspend(struct mmc_host *host) 1402 + static int _mmc_suspend(struct mmc_host *host, bool is_suspend) 1473 1403 { 1474 1404 int err = 0; 1405 + unsigned int notify_type = is_suspend ? EXT_CSD_POWER_OFF_SHORT : 1406 + EXT_CSD_POWER_OFF_LONG; 1475 1407 1476 1408 BUG_ON(!host); 1477 1409 BUG_ON(!host->card); 1478 1410 1479 1411 mmc_claim_host(host); 1480 1412 1413 + if (mmc_card_doing_bkops(host->card)) { 1414 + err = mmc_stop_bkops(host->card); 1415 + if (err) 1416 + goto out; 1417 + } 1418 + 1481 1419 err = mmc_cache_ctrl(host, 0); 1482 1420 if (err) 1483 1421 goto out; 1484 1422 1485 - if (mmc_can_poweroff_notify(host->card)) 1486 - err = mmc_poweroff_notify(host->card, EXT_CSD_POWER_OFF_SHORT); 1487 - else if (mmc_card_can_sleep(host)) 1488 - err = mmc_card_sleep(host); 1423 + if (mmc_can_poweroff_notify(host->card) && 1424 + ((host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) || !is_suspend)) 1425 + err = mmc_poweroff_notify(host->card, notify_type); 1426 + else if (mmc_can_sleep(host->card)) 1427 + err = mmc_sleep(host); 1489 1428 else if (!mmc_host_is_spi(host)) 1490 1429 err = mmc_deselect_cards(host); 1491 1430 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); 1492 1431 1432 + if (!err) 1433 + mmc_power_off(host); 1493 1434 out: 1494 1435 mmc_release_host(host); 1495 1436 return err; 1437 + } 1438 + 1439 + /* 1440 + * Suspend callback from host. 1441 + */ 1442 + static int mmc_suspend(struct mmc_host *host) 1443 + { 1444 + return _mmc_suspend(host, true); 1445 + } 1446 + 1447 + /* 1448 + * Shutdown callback 1449 + */ 1450 + static int mmc_shutdown(struct mmc_host *host) 1451 + { 1452 + return _mmc_suspend(host, false); 1496 1453 } 1497 1454 1498 1455 /* ··· 1533 1442 BUG_ON(!host->card); 1534 1443 1535 1444 mmc_claim_host(host); 1445 + mmc_power_up(host); 1446 + mmc_select_voltage(host, host->ocr); 1536 1447 err = mmc_init_card(host, host->ocr, host->card); 1537 1448 mmc_release_host(host); 1538 1449 1539 1450 return err; 1451 + } 1452 + 1453 + 1454 + /* 1455 + * Callback for runtime_suspend. 1456 + */ 1457 + static int mmc_runtime_suspend(struct mmc_host *host) 1458 + { 1459 + int err; 1460 + 1461 + if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) 1462 + return 0; 1463 + 1464 + mmc_claim_host(host); 1465 + 1466 + err = mmc_suspend(host); 1467 + if (err) { 1468 + pr_err("%s: error %d doing aggessive suspend\n", 1469 + mmc_hostname(host), err); 1470 + goto out; 1471 + } 1472 + mmc_power_off(host); 1473 + 1474 + out: 1475 + mmc_release_host(host); 1476 + return err; 1477 + } 1478 + 1479 + /* 1480 + * Callback for runtime_resume. 1481 + */ 1482 + static int mmc_runtime_resume(struct mmc_host *host) 1483 + { 1484 + int err; 1485 + 1486 + if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) 1487 + return 0; 1488 + 1489 + mmc_claim_host(host); 1490 + 1491 + mmc_power_up(host); 1492 + err = mmc_resume(host); 1493 + if (err) 1494 + pr_err("%s: error %d doing aggessive resume\n", 1495 + mmc_hostname(host), err); 1496 + 1497 + mmc_release_host(host); 1498 + return 0; 1540 1499 } 1541 1500 1542 1501 static int mmc_power_restore(struct mmc_host *host) ··· 1601 1460 return ret; 1602 1461 } 1603 1462 1604 - static int mmc_sleep(struct mmc_host *host) 1605 - { 1606 - struct mmc_card *card = host->card; 1607 - int err = -ENOSYS; 1608 - 1609 - if (card && card->ext_csd.rev >= 3) { 1610 - err = mmc_card_sleepawake(host, 1); 1611 - if (err < 0) 1612 - pr_debug("%s: Error %d while putting card into sleep", 1613 - mmc_hostname(host), err); 1614 - } 1615 - 1616 - return err; 1617 - } 1618 - 1619 - static int mmc_awake(struct mmc_host *host) 1620 - { 1621 - struct mmc_card *card = host->card; 1622 - int err = -ENOSYS; 1623 - 1624 - if (card && card->ext_csd.rev >= 3) { 1625 - err = mmc_card_sleepawake(host, 0); 1626 - if (err < 0) 1627 - pr_debug("%s: Error %d while awaking sleeping card", 1628 - mmc_hostname(host), err); 1629 - } 1630 - 1631 - return err; 1632 - } 1633 - 1634 1463 static const struct mmc_bus_ops mmc_ops = { 1635 - .awake = mmc_awake, 1636 - .sleep = mmc_sleep, 1637 1464 .remove = mmc_remove, 1638 1465 .detect = mmc_detect, 1639 1466 .suspend = NULL, 1640 1467 .resume = NULL, 1641 1468 .power_restore = mmc_power_restore, 1642 1469 .alive = mmc_alive, 1470 + .shutdown = mmc_shutdown, 1643 1471 }; 1644 1472 1645 1473 static const struct mmc_bus_ops mmc_ops_unsafe = { 1646 - .awake = mmc_awake, 1647 - .sleep = mmc_sleep, 1648 1474 .remove = mmc_remove, 1649 1475 .detect = mmc_detect, 1650 1476 .suspend = mmc_suspend, 1651 1477 .resume = mmc_resume, 1478 + .runtime_suspend = mmc_runtime_suspend, 1479 + .runtime_resume = mmc_runtime_resume, 1652 1480 .power_restore = mmc_power_restore, 1653 1481 .alive = mmc_alive, 1482 + .shutdown = mmc_shutdown, 1654 1483 }; 1655 1484 1656 1485 static void mmc_attach_bus_ops(struct mmc_host *host)
+2 -34
drivers/mmc/core/mmc_ops.c
··· 59 59 return _mmc_select_card(host, NULL); 60 60 } 61 61 62 - int mmc_card_sleepawake(struct mmc_host *host, int sleep) 63 - { 64 - struct mmc_command cmd = {0}; 65 - struct mmc_card *card = host->card; 66 - int err; 67 - 68 - if (sleep) 69 - mmc_deselect_cards(host); 70 - 71 - cmd.opcode = MMC_SLEEP_AWAKE; 72 - cmd.arg = card->rca << 16; 73 - if (sleep) 74 - cmd.arg |= 1 << 15; 75 - 76 - cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; 77 - err = mmc_wait_for_cmd(host, &cmd, 0); 78 - if (err) 79 - return err; 80 - 81 - /* 82 - * If the host does not wait while the card signals busy, then we will 83 - * will have to wait the sleep/awake timeout. Note, we cannot use the 84 - * SEND_STATUS command to poll the status because that command (and most 85 - * others) is invalid while the card sleeps. 86 - */ 87 - if (!(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) 88 - mmc_delay(DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000)); 89 - 90 - if (!sleep) 91 - err = mmc_select_card(card); 92 - 93 - return err; 94 - } 95 - 96 62 int mmc_go_idle(struct mmc_host *host) 97 63 { 98 64 int err; ··· 397 431 398 432 399 433 cmd.cmd_timeout_ms = timeout_ms; 434 + if (index == EXT_CSD_SANITIZE_START) 435 + cmd.sanitize_busy = true; 400 436 401 437 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); 402 438 if (err)
-1
drivers/mmc/core/mmc_ops.h
··· 24 24 int mmc_send_cid(struct mmc_host *host, u32 *cid); 25 25 int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp); 26 26 int mmc_spi_set_crc(struct mmc_host *host, int use_crc); 27 - int mmc_card_sleepawake(struct mmc_host *host, int sleep); 28 27 int mmc_bus_test(struct mmc_card *card, u8 bus_width); 29 28 int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status); 30 29
+64 -4
drivers/mmc/core/sd.c
··· 646 646 if (err) 647 647 goto out; 648 648 649 - /* SPI mode doesn't define CMD19 */ 650 - if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning) { 649 + /* 650 + * SPI mode doesn't define CMD19 and tuning is only valid for SDR50 and 651 + * SDR104 mode SD-cards. Note that tuning is mandatory for SDR104. 652 + */ 653 + if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning && 654 + (card->sd_bus_speed == UHS_SDR50_BUS_SPEED || 655 + card->sd_bus_speed == UHS_SDR104_BUS_SPEED)) { 651 656 mmc_host_clk_hold(card->host); 652 657 err = card->host->ops->execute_tuning(card->host, 653 658 MMC_SEND_TUNING_BLOCK); ··· 1042 1037 BUG_ON(!host); 1043 1038 BUG_ON(!host->card); 1044 1039 1045 - mmc_claim_host(host); 1040 + mmc_get_card(host->card); 1046 1041 1047 1042 /* 1048 1043 * Just check if our card has been removed. 1049 1044 */ 1050 1045 err = _mmc_detect_card_removed(host); 1051 1046 1052 - mmc_release_host(host); 1047 + mmc_put_card(host->card); 1053 1048 1054 1049 if (err) { 1055 1050 mmc_sd_remove(host); ··· 1075 1070 if (!mmc_host_is_spi(host)) 1076 1071 err = mmc_deselect_cards(host); 1077 1072 host->card->state &= ~MMC_STATE_HIGHSPEED; 1073 + if (!err) 1074 + mmc_power_off(host); 1078 1075 mmc_release_host(host); 1079 1076 1080 1077 return err; ··· 1096 1089 BUG_ON(!host->card); 1097 1090 1098 1091 mmc_claim_host(host); 1092 + mmc_power_up(host); 1093 + mmc_select_voltage(host, host->ocr); 1099 1094 err = mmc_sd_init_card(host, host->ocr, host->card); 1100 1095 mmc_release_host(host); 1101 1096 1102 1097 return err; 1098 + } 1099 + 1100 + /* 1101 + * Callback for runtime_suspend. 1102 + */ 1103 + static int mmc_sd_runtime_suspend(struct mmc_host *host) 1104 + { 1105 + int err; 1106 + 1107 + if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) 1108 + return 0; 1109 + 1110 + mmc_claim_host(host); 1111 + 1112 + err = mmc_sd_suspend(host); 1113 + if (err) { 1114 + pr_err("%s: error %d doing aggessive suspend\n", 1115 + mmc_hostname(host), err); 1116 + goto out; 1117 + } 1118 + mmc_power_off(host); 1119 + 1120 + out: 1121 + mmc_release_host(host); 1122 + return err; 1123 + } 1124 + 1125 + /* 1126 + * Callback for runtime_resume. 1127 + */ 1128 + static int mmc_sd_runtime_resume(struct mmc_host *host) 1129 + { 1130 + int err; 1131 + 1132 + if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) 1133 + return 0; 1134 + 1135 + mmc_claim_host(host); 1136 + 1137 + mmc_power_up(host); 1138 + err = mmc_sd_resume(host); 1139 + if (err) 1140 + pr_err("%s: error %d doing aggessive resume\n", 1141 + mmc_hostname(host), err); 1142 + 1143 + mmc_release_host(host); 1144 + return 0; 1103 1145 } 1104 1146 1105 1147 static int mmc_sd_power_restore(struct mmc_host *host) ··· 1170 1114 .resume = NULL, 1171 1115 .power_restore = mmc_sd_power_restore, 1172 1116 .alive = mmc_sd_alive, 1117 + .shutdown = mmc_sd_suspend, 1173 1118 }; 1174 1119 1175 1120 static const struct mmc_bus_ops mmc_sd_ops_unsafe = { 1176 1121 .remove = mmc_sd_remove, 1177 1122 .detect = mmc_sd_detect, 1123 + .runtime_suspend = mmc_sd_runtime_suspend, 1124 + .runtime_resume = mmc_sd_runtime_resume, 1178 1125 .suspend = mmc_sd_suspend, 1179 1126 .resume = mmc_sd_resume, 1180 1127 .power_restore = mmc_sd_power_restore, 1181 1128 .alive = mmc_sd_alive, 1129 + .shutdown = mmc_sd_suspend, 1182 1130 }; 1183 1131 1184 1132 static void mmc_sd_attach_bus_ops(struct mmc_host *host)
+70 -6
drivers/mmc/core/sdio.c
··· 563 563 if (err) 564 564 goto out; 565 565 566 - /* Initialize and start re-tuning timer */ 567 - if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning) 566 + /* 567 + * SPI mode doesn't define CMD19 and tuning is only valid for SDR50 and 568 + * SDR104 mode SD-cards. Note that tuning is mandatory for SDR104. 569 + */ 570 + if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning && 571 + ((card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR50) || 572 + (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104))) { 573 + mmc_host_clk_hold(card->host); 568 574 err = card->host->ops->execute_tuning(card->host, 569 575 MMC_SEND_TUNING_BLOCK); 576 + mmc_host_clk_release(card->host); 577 + } 570 578 571 579 out: 572 580 ··· 910 902 } 911 903 912 904 /* 913 - * SDIO suspend. We need to suspend all functions separately. 905 + * SDIO pre_suspend. We need to suspend all functions separately. 914 906 * Therefore all registered functions must have drivers with suspend 915 907 * and resume methods. Failing that we simply remove the whole card. 916 908 */ 917 - static int mmc_sdio_suspend(struct mmc_host *host) 909 + static int mmc_sdio_pre_suspend(struct mmc_host *host) 918 910 { 919 911 int i, err = 0; 920 912 ··· 925 917 if (!pmops || !pmops->suspend || !pmops->resume) { 926 918 /* force removal of entire card in that case */ 927 919 err = -ENOSYS; 928 - } else 929 - err = pmops->suspend(&func->dev); 920 + break; 921 + } 922 + } 923 + } 924 + 925 + return err; 926 + } 927 + 928 + /* 929 + * SDIO suspend. Suspend all functions separately. 930 + */ 931 + static int mmc_sdio_suspend(struct mmc_host *host) 932 + { 933 + int i, err = 0; 934 + 935 + for (i = 0; i < host->card->sdio_funcs; i++) { 936 + struct sdio_func *func = host->card->sdio_func[i]; 937 + if (func && sdio_func_present(func) && func->dev.driver) { 938 + const struct dev_pm_ops *pmops = func->dev.driver->pm; 939 + err = pmops->suspend(&func->dev); 930 940 if (err) 931 941 break; 932 942 } ··· 963 937 mmc_release_host(host); 964 938 } 965 939 940 + if (!err && !mmc_card_keep_power(host)) 941 + mmc_power_off(host); 942 + 966 943 return err; 967 944 } 968 945 ··· 978 949 979 950 /* Basic card reinitialization. */ 980 951 mmc_claim_host(host); 952 + 953 + /* Restore power if needed */ 954 + if (!mmc_card_keep_power(host)) { 955 + mmc_power_up(host); 956 + mmc_select_voltage(host, host->ocr); 957 + /* 958 + * Tell runtime PM core we just powered up the card, 959 + * since it still believes the card is powered off. 960 + * Note that currently runtime PM is only enabled 961 + * for SDIO cards that are MMC_CAP_POWER_OFF_CARD 962 + */ 963 + if (host->caps & MMC_CAP_POWER_OFF_CARD) { 964 + pm_runtime_disable(&host->card->dev); 965 + pm_runtime_set_active(&host->card->dev); 966 + pm_runtime_enable(&host->card->dev); 967 + } 968 + } 981 969 982 970 /* No need to reinitialize powered-resumed nonremovable cards */ 983 971 if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) { ··· 1033 987 } 1034 988 } 1035 989 990 + host->pm_flags &= ~MMC_PM_KEEP_POWER; 1036 991 return err; 1037 992 } 1038 993 ··· 1098 1051 return ret; 1099 1052 } 1100 1053 1054 + static int mmc_sdio_runtime_suspend(struct mmc_host *host) 1055 + { 1056 + /* No references to the card, cut the power to it. */ 1057 + mmc_power_off(host); 1058 + return 0; 1059 + } 1060 + 1061 + static int mmc_sdio_runtime_resume(struct mmc_host *host) 1062 + { 1063 + /* Restore power and re-initialize. */ 1064 + mmc_power_up(host); 1065 + return mmc_sdio_power_restore(host); 1066 + } 1067 + 1101 1068 static const struct mmc_bus_ops mmc_sdio_ops = { 1102 1069 .remove = mmc_sdio_remove, 1103 1070 .detect = mmc_sdio_detect, 1071 + .pre_suspend = mmc_sdio_pre_suspend, 1104 1072 .suspend = mmc_sdio_suspend, 1105 1073 .resume = mmc_sdio_resume, 1074 + .runtime_suspend = mmc_sdio_runtime_suspend, 1075 + .runtime_resume = mmc_sdio_runtime_resume, 1106 1076 .power_restore = mmc_sdio_power_restore, 1107 1077 .alive = mmc_sdio_alive, 1108 1078 };
+19
drivers/mmc/host/Kconfig
··· 249 249 250 250 YMMV. 251 251 252 + config MMC_SDHCI_BCM_KONA 253 + tristate "SDHCI support on Broadcom KONA platform" 254 + depends on ARCH_BCM 255 + select MMC_SDHCI_PLTFM 256 + help 257 + This selects the Broadcom Kona Secure Digital Host Controller 258 + Interface(SDHCI) support. 259 + This is used in Broadcom mobile SoCs. 260 + 261 + If you have a controller with this interface, say Y or M here. 262 + 252 263 config MMC_SDHCI_BCM2835 253 264 tristate "SDHCI platform support for the BCM2835 SD/MMC Controller" 254 265 depends on ARCH_BCM2835 ··· 566 555 This selects support for Samsung Exynos SoC specific extensions to the 567 556 Synopsys DesignWare Memory Card Interface driver. Select this option 568 557 for platforms based on Exynos4 and Exynos5 SoC's. 558 + 559 + config MMC_DW_SOCFPGA 560 + tristate "SOCFPGA specific extensions for Synopsys DW Memory Card Interface" 561 + depends on MMC_DW 562 + select MMC_DW_PLTFM 563 + help 564 + This selects support for Altera SoCFPGA specific extensions to the 565 + Synopsys DesignWare Memory Card Interface driver. 569 566 570 567 config MMC_DW_PCI 571 568 tristate "Synopsys Designware MCI support on PCI bus"
+2
drivers/mmc/host/Makefile
··· 42 42 obj-$(CONFIG_MMC_DW) += dw_mmc.o 43 43 obj-$(CONFIG_MMC_DW_PLTFM) += dw_mmc-pltfm.o 44 44 obj-$(CONFIG_MMC_DW_EXYNOS) += dw_mmc-exynos.o 45 + obj-$(CONFIG_MMC_DW_SOCFPGA) += dw_mmc-socfpga.o 45 46 obj-$(CONFIG_MMC_DW_PCI) += dw_mmc-pci.o 46 47 obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o 47 48 obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o ··· 61 60 obj-$(CONFIG_MMC_SDHCI_TEGRA) += sdhci-tegra.o 62 61 obj-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o 63 62 obj-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o 63 + obj-$(CONFIG_MMC_SDHCI_BCM_KONA) += sdhci-bcm-kona.o 64 64 obj-$(CONFIG_MMC_SDHCI_BCM2835) += sdhci-bcm2835.o 65 65 66 66 ifeq ($(CONFIG_CB710_DEBUG),y)
-2
drivers/mmc/host/android-goldfish.c
··· 546 546 { 547 547 struct goldfish_mmc_host *host = platform_get_drvdata(pdev); 548 548 549 - platform_set_drvdata(pdev, NULL); 550 - 551 549 BUG_ON(host == NULL); 552 550 553 551 mmc_remove_host(host->mmc);
+4 -10
drivers/mmc/host/atmel-mci.c
··· 40 40 #include <asm/io.h> 41 41 #include <asm/unaligned.h> 42 42 43 - #include <mach/cpu.h> 44 - 45 43 #include "atmel-mci-regs.h" 46 44 47 45 #define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE | ATMCI_OVRE | ATMCI_UNRE) ··· 2473 2475 struct atmel_mci *host = platform_get_drvdata(pdev); 2474 2476 unsigned int i; 2475 2477 2476 - platform_set_drvdata(pdev, NULL); 2477 - 2478 2478 if (host->buffer) 2479 2479 dma_free_coherent(&pdev->dev, host->buf_size, 2480 2480 host->buffer, host->buf_phys_addr); ··· 2500 2504 return 0; 2501 2505 } 2502 2506 2503 - #ifdef CONFIG_PM 2507 + #ifdef CONFIG_PM_SLEEP 2504 2508 static int atmci_suspend(struct device *dev) 2505 2509 { 2506 2510 struct atmel_mci *host = dev_get_drvdata(dev); ··· 2555 2559 2556 2560 return ret; 2557 2561 } 2558 - static SIMPLE_DEV_PM_OPS(atmci_pm, atmci_suspend, atmci_resume); 2559 - #define ATMCI_PM_OPS (&atmci_pm) 2560 - #else 2561 - #define ATMCI_PM_OPS NULL 2562 2562 #endif 2563 + 2564 + static SIMPLE_DEV_PM_OPS(atmci_pm, atmci_suspend, atmci_resume); 2563 2565 2564 2566 static struct platform_driver atmci_driver = { 2565 2567 .remove = __exit_p(atmci_remove), 2566 2568 .driver = { 2567 2569 .name = "atmel_mci", 2568 - .pm = ATMCI_PM_OPS, 2570 + .pm = &atmci_pm, 2569 2571 .of_match_table = of_match_ptr(atmci_dt_ids), 2570 2572 }, 2571 2573 };
-1
drivers/mmc/host/au1xmmc.c
··· 1149 1149 kfree(host->ioarea); 1150 1150 1151 1151 mmc_free_host(host->mmc); 1152 - platform_set_drvdata(pdev, NULL); 1153 1152 } 1154 1153 return 0; 1155 1154 }
-2
drivers/mmc/host/bfin_sdh.c
··· 621 621 { 622 622 struct mmc_host *mmc = platform_get_drvdata(pdev); 623 623 624 - platform_set_drvdata(pdev, NULL); 625 - 626 624 if (mmc) { 627 625 struct sdh_host *host = mmc_priv(mmc); 628 626
+1 -1
drivers/mmc/host/cb710-mmc.c
··· 703 703 if (!mmc) 704 704 return -ENOMEM; 705 705 706 - dev_set_drvdata(&pdev->dev, mmc); 706 + platform_set_drvdata(pdev, mmc); 707 707 708 708 /* harmless (maybe) magic */ 709 709 pci_read_config_dword(chip->pdev, 0x48, &val);
+1 -1
drivers/mmc/host/cb710-mmc.h
··· 24 24 25 25 static inline struct mmc_host *cb710_slot_to_mmc(struct cb710_slot *slot) 26 26 { 27 - return dev_get_drvdata(&slot->pdev.dev); 27 + return platform_get_drvdata(&slot->pdev); 28 28 } 29 29 30 30 static inline struct cb710_slot *cb710_mmc_to_slot(struct mmc_host *mmc)
-1
drivers/mmc/host/davinci_mmc.c
··· 1407 1407 { 1408 1408 struct mmc_davinci_host *host = platform_get_drvdata(pdev); 1409 1409 1410 - platform_set_drvdata(pdev, NULL); 1411 1410 if (host) { 1412 1411 mmc_davinci_cpufreq_deregister(host); 1413 1412
-2
drivers/mmc/host/dw_mmc-exynos.c
··· 31 31 SDMMC_CLKSEL_CCLK_DRIVE(y) | \ 32 32 SDMMC_CLKSEL_CCLK_DIVIDER(z)) 33 33 34 - #define SDMMC_CMD_USE_HOLD_REG BIT(29) 35 - 36 34 #define EXYNOS4210_FIXED_CIU_CLK_DIV 2 37 35 #define EXYNOS4412_FIXED_CIU_CLK_DIV 4 38 36
+16 -40
drivers/mmc/host/dw_mmc-pci.c
··· 21 21 #include "dw_mmc.h" 22 22 23 23 #define PCI_BAR_NO 2 24 - #define COMPLETE_BAR 0 25 24 #define SYNOPSYS_DW_MCI_VENDOR_ID 0x700 26 25 #define SYNOPSYS_DW_MCI_DEVICE_ID 0x1107 27 26 /* Defining the Capabilities */ ··· 37 38 }; 38 39 39 40 static int dw_mci_pci_probe(struct pci_dev *pdev, 40 - const struct pci_device_id *entries) 41 + const struct pci_device_id *entries) 41 42 { 42 43 struct dw_mci *host; 43 44 int ret; 44 45 45 - ret = pci_enable_device(pdev); 46 + ret = pcim_enable_device(pdev); 46 47 if (ret) 47 48 return ret; 48 - if (pci_request_regions(pdev, "dw_mmc_pci")) { 49 - ret = -ENODEV; 50 - goto err_disable_dev; 51 - } 52 49 53 - host = kzalloc(sizeof(struct dw_mci), GFP_KERNEL); 54 - if (!host) { 55 - ret = -ENOMEM; 56 - goto err_release; 57 - } 50 + host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL); 51 + if (!host) 52 + return -ENOMEM; 58 53 59 54 host->irq = pdev->irq; 60 55 host->irq_flags = IRQF_SHARED; 61 56 host->dev = &pdev->dev; 62 57 host->pdata = &pci_board_data; 63 58 64 - host->regs = pci_iomap(pdev, PCI_BAR_NO, COMPLETE_BAR); 65 - if (!host->regs) { 66 - ret = -EIO; 67 - goto err_unmap; 68 - } 59 + ret = pcim_iomap_regions(pdev, 1 << PCI_BAR_NO, pci_name(pdev)); 60 + if (ret) 61 + return ret; 69 62 70 - pci_set_drvdata(pdev, host); 63 + host->regs = pcim_iomap_table(pdev)[0]; 64 + 71 65 ret = dw_mci_probe(host); 72 66 if (ret) 73 - goto err_probe_failed; 74 - return ret; 67 + return ret; 75 68 76 - err_probe_failed: 77 - pci_iounmap(pdev, host->regs); 78 - err_unmap: 79 - kfree(host); 80 - err_release: 81 - pci_release_regions(pdev); 82 - err_disable_dev: 83 - pci_disable_device(pdev); 84 - return ret; 69 + pci_set_drvdata(pdev, host); 70 + 71 + return 0; 85 72 } 86 73 87 74 static void dw_mci_pci_remove(struct pci_dev *pdev) ··· 75 90 struct dw_mci *host = pci_get_drvdata(pdev); 76 91 77 92 dw_mci_remove(host); 78 - pci_set_drvdata(pdev, NULL); 79 - pci_release_regions(pdev); 80 - pci_iounmap(pdev, host->regs); 81 - kfree(host); 82 - pci_disable_device(pdev); 83 93 } 84 94 85 95 #ifdef CONFIG_PM_SLEEP 86 96 static int dw_mci_pci_suspend(struct device *dev) 87 97 { 88 - int ret; 89 98 struct pci_dev *pdev = to_pci_dev(dev); 90 99 struct dw_mci *host = pci_get_drvdata(pdev); 91 100 92 - ret = dw_mci_suspend(host); 93 - return ret; 101 + return dw_mci_suspend(host); 94 102 } 95 103 96 104 static int dw_mci_pci_resume(struct device *dev) 97 105 { 98 - int ret; 99 106 struct pci_dev *pdev = to_pci_dev(dev); 100 107 struct dw_mci *host = pci_get_drvdata(pdev); 101 108 102 - ret = dw_mci_resume(host); 103 - return ret; 109 + return dw_mci_resume(host); 104 110 } 105 111 #else 106 112 #define dw_mci_pci_suspend NULL
+39 -34
drivers/mmc/host/dw_mmc-pltfm.c
··· 24 24 25 25 #include "dw_mmc.h" 26 26 27 + static void dw_mci_rockchip_prepare_command(struct dw_mci *host, u32 *cmdr) 28 + { 29 + *cmdr |= SDMMC_CMD_USE_HOLD_REG; 30 + } 31 + 32 + static const struct dw_mci_drv_data rockchip_drv_data = { 33 + .prepare_command = dw_mci_rockchip_prepare_command, 34 + }; 35 + 27 36 int dw_mci_pltfm_register(struct platform_device *pdev, 28 - const struct dw_mci_drv_data *drv_data) 37 + const struct dw_mci_drv_data *drv_data) 29 38 { 30 39 struct dw_mci *host; 31 40 struct resource *regs; ··· 44 35 if (!host) 45 36 return -ENOMEM; 46 37 47 - regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 48 - if (!regs) 49 - return -ENXIO; 50 - 51 38 host->irq = platform_get_irq(pdev, 0); 52 39 if (host->irq < 0) 53 40 return host->irq; ··· 52 47 host->dev = &pdev->dev; 53 48 host->irq_flags = 0; 54 49 host->pdata = pdev->dev.platform_data; 50 + 51 + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 55 52 host->regs = devm_ioremap_resource(&pdev->dev, regs); 56 53 if (IS_ERR(host->regs)) 57 54 return PTR_ERR(host->regs); ··· 65 58 } 66 59 67 60 platform_set_drvdata(pdev, host); 68 - ret = dw_mci_probe(host); 69 - return ret; 61 + return dw_mci_probe(host); 70 62 } 71 63 EXPORT_SYMBOL_GPL(dw_mci_pltfm_register); 72 - 73 - static int dw_mci_pltfm_probe(struct platform_device *pdev) 74 - { 75 - return dw_mci_pltfm_register(pdev, NULL); 76 - } 77 - 78 - static int dw_mci_pltfm_remove(struct platform_device *pdev) 79 - { 80 - struct dw_mci *host = platform_get_drvdata(pdev); 81 - 82 - platform_set_drvdata(pdev, NULL); 83 - dw_mci_remove(host); 84 - return 0; 85 - } 86 - EXPORT_SYMBOL_GPL(dw_mci_pltfm_remove); 87 64 88 65 #ifdef CONFIG_PM_SLEEP 89 66 /* ··· 75 84 */ 76 85 static int dw_mci_pltfm_suspend(struct device *dev) 77 86 { 78 - int ret; 79 87 struct dw_mci *host = dev_get_drvdata(dev); 80 88 81 - ret = dw_mci_suspend(host); 82 - if (ret) 83 - return ret; 84 - 85 - return 0; 89 + return dw_mci_suspend(host); 86 90 } 87 91 88 92 static int dw_mci_pltfm_resume(struct device *dev) 89 93 { 90 - int ret; 91 94 struct dw_mci *host = dev_get_drvdata(dev); 92 95 93 - ret = dw_mci_resume(host); 94 - if (ret) 95 - return ret; 96 - 97 - return 0; 96 + return dw_mci_resume(host); 98 97 } 99 98 #else 100 99 #define dw_mci_pltfm_suspend NULL ··· 96 115 97 116 static const struct of_device_id dw_mci_pltfm_match[] = { 98 117 { .compatible = "snps,dw-mshc", }, 118 + { .compatible = "rockchip,rk2928-dw-mshc", 119 + .data = &rockchip_drv_data }, 99 120 {}, 100 121 }; 101 122 MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match); 123 + 124 + static int dw_mci_pltfm_probe(struct platform_device *pdev) 125 + { 126 + const struct dw_mci_drv_data *drv_data = NULL; 127 + const struct of_device_id *match; 128 + 129 + if (pdev->dev.of_node) { 130 + match = of_match_node(dw_mci_pltfm_match, pdev->dev.of_node); 131 + drv_data = match->data; 132 + } 133 + 134 + return dw_mci_pltfm_register(pdev, drv_data); 135 + } 136 + 137 + int dw_mci_pltfm_remove(struct platform_device *pdev) 138 + { 139 + struct dw_mci *host = platform_get_drvdata(pdev); 140 + 141 + dw_mci_remove(host); 142 + return 0; 143 + } 144 + EXPORT_SYMBOL_GPL(dw_mci_pltfm_remove); 102 145 103 146 static struct platform_driver dw_mci_pltfm_driver = { 104 147 .probe = dw_mci_pltfm_probe,
+140
drivers/mmc/host/dw_mmc-socfpga.c
··· 1 + /* 2 + * Altera SoCFPGA Specific Extensions for Synopsys DW Multimedia Card Interface 3 + * driver 4 + * 5 + * Copyright (C) 2012, Samsung Electronics Co., Ltd. 6 + * Copyright (C) 2013 Altera Corporation 7 + * 8 + * This program is free software; you can redistribute it and/or modify 9 + * it under the terms of the GNU General Public License as published by 10 + * the Free Software Foundation; either version 2 of the License, or 11 + * (at your option) any later version. 12 + * 13 + * Taken from dw_mmc-exynos.c 14 + */ 15 + #include <linux/clk.h> 16 + #include <linux/mfd/syscon.h> 17 + #include <linux/mmc/host.h> 18 + #include <linux/mmc/dw_mmc.h> 19 + #include <linux/module.h> 20 + #include <linux/of.h> 21 + #include <linux/platform_device.h> 22 + #include <linux/regmap.h> 23 + 24 + #include "dw_mmc.h" 25 + #include "dw_mmc-pltfm.h" 26 + 27 + #define SYSMGR_SDMMCGRP_CTRL_OFFSET 0x108 28 + #define DRV_CLK_PHASE_SHIFT_SEL_MASK 0x7 29 + #define SYSMGR_SDMMC_CTRL_SET(smplsel, drvsel) \ 30 + ((((smplsel) & 0x7) << 3) | (((drvsel) & 0x7) << 0)) 31 + 32 + /* SOCFPGA implementation specific driver private data */ 33 + struct dw_mci_socfpga_priv_data { 34 + u8 ciu_div; /* card interface unit divisor */ 35 + u32 hs_timing; /* bitmask for CIU clock phase shift */ 36 + struct regmap *sysreg; /* regmap for system manager register */ 37 + }; 38 + 39 + static int dw_mci_socfpga_priv_init(struct dw_mci *host) 40 + { 41 + struct dw_mci_socfpga_priv_data *priv; 42 + 43 + priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); 44 + if (!priv) { 45 + dev_err(host->dev, "mem alloc failed for private data\n"); 46 + return -ENOMEM; 47 + } 48 + 49 + priv->sysreg = syscon_regmap_lookup_by_compatible("altr,sys-mgr"); 50 + if (IS_ERR(priv->sysreg)) { 51 + dev_err(host->dev, "regmap for altr,sys-mgr lookup failed.\n"); 52 + return PTR_ERR(priv->sysreg); 53 + } 54 + host->priv = priv; 55 + 56 + return 0; 57 + } 58 + 59 + static int dw_mci_socfpga_setup_clock(struct dw_mci *host) 60 + { 61 + struct dw_mci_socfpga_priv_data *priv = host->priv; 62 + 63 + clk_disable_unprepare(host->ciu_clk); 64 + regmap_write(priv->sysreg, SYSMGR_SDMMCGRP_CTRL_OFFSET, 65 + priv->hs_timing); 66 + clk_prepare_enable(host->ciu_clk); 67 + 68 + host->bus_hz /= (priv->ciu_div + 1); 69 + return 0; 70 + } 71 + 72 + static void dw_mci_socfpga_prepare_command(struct dw_mci *host, u32 *cmdr) 73 + { 74 + struct dw_mci_socfpga_priv_data *priv = host->priv; 75 + 76 + if (priv->hs_timing & DRV_CLK_PHASE_SHIFT_SEL_MASK) 77 + *cmdr |= SDMMC_CMD_USE_HOLD_REG; 78 + } 79 + 80 + static int dw_mci_socfpga_parse_dt(struct dw_mci *host) 81 + { 82 + struct dw_mci_socfpga_priv_data *priv = host->priv; 83 + struct device_node *np = host->dev->of_node; 84 + u32 timing[2]; 85 + u32 div = 0; 86 + int ret; 87 + 88 + ret = of_property_read_u32(np, "altr,dw-mshc-ciu-div", &div); 89 + if (ret) 90 + dev_info(host->dev, "No dw-mshc-ciu-div specified, assuming 1"); 91 + priv->ciu_div = div; 92 + 93 + ret = of_property_read_u32_array(np, 94 + "altr,dw-mshc-sdr-timing", timing, 2); 95 + if (ret) 96 + return ret; 97 + 98 + priv->hs_timing = SYSMGR_SDMMC_CTRL_SET(timing[0], timing[1]); 99 + return 0; 100 + } 101 + 102 + static const struct dw_mci_drv_data socfpga_drv_data = { 103 + .init = dw_mci_socfpga_priv_init, 104 + .setup_clock = dw_mci_socfpga_setup_clock, 105 + .prepare_command = dw_mci_socfpga_prepare_command, 106 + .parse_dt = dw_mci_socfpga_parse_dt, 107 + }; 108 + 109 + static const struct of_device_id dw_mci_socfpga_match[] = { 110 + { .compatible = "altr,socfpga-dw-mshc", 111 + .data = &socfpga_drv_data, }, 112 + {}, 113 + }; 114 + MODULE_DEVICE_TABLE(of, dw_mci_socfpga_match); 115 + 116 + int dw_mci_socfpga_probe(struct platform_device *pdev) 117 + { 118 + const struct dw_mci_drv_data *drv_data; 119 + const struct of_device_id *match; 120 + 121 + match = of_match_node(dw_mci_socfpga_match, pdev->dev.of_node); 122 + drv_data = match->data; 123 + return dw_mci_pltfm_register(pdev, drv_data); 124 + } 125 + 126 + static struct platform_driver dw_mci_socfpga_pltfm_driver = { 127 + .probe = dw_mci_socfpga_probe, 128 + .remove = __exit_p(dw_mci_pltfm_remove), 129 + .driver = { 130 + .name = "dwmmc_socfpga", 131 + .of_match_table = of_match_ptr(dw_mci_socfpga_match), 132 + .pm = &dw_mci_pltfm_pmops, 133 + }, 134 + }; 135 + 136 + module_platform_driver(dw_mci_socfpga_pltfm_driver); 137 + 138 + MODULE_DESCRIPTION("Altera SOCFPGA Specific DW-MSHC Driver Extension"); 139 + MODULE_LICENSE("GPL v2"); 140 + MODULE_ALIAS("platform:dwmmc-socfpga");
+44 -21
drivers/mmc/host/dw_mmc.c
··· 39 39 #include "dw_mmc.h" 40 40 41 41 /* Common flag combinations */ 42 - #define DW_MCI_DATA_ERROR_FLAGS (SDMMC_INT_DTO | SDMMC_INT_DCRC | \ 42 + #define DW_MCI_DATA_ERROR_FLAGS (SDMMC_INT_DRTO | SDMMC_INT_DCRC | \ 43 43 SDMMC_INT_HTO | SDMMC_INT_SBE | \ 44 44 SDMMC_INT_EBE) 45 45 #define DW_MCI_CMD_ERROR_FLAGS (SDMMC_INT_RTO | SDMMC_INT_RCRC | \ ··· 51 51 #define DW_MCI_DMA_THRESHOLD 16 52 52 53 53 #ifdef CONFIG_MMC_DW_IDMAC 54 + #define IDMAC_INT_CLR (SDMMC_IDMAC_INT_AI | SDMMC_IDMAC_INT_NI | \ 55 + SDMMC_IDMAC_INT_CES | SDMMC_IDMAC_INT_DU | \ 56 + SDMMC_IDMAC_INT_FBE | SDMMC_IDMAC_INT_RI | \ 57 + SDMMC_IDMAC_INT_TI) 58 + 54 59 struct idmac_desc { 55 60 u32 des0; /* Control Descriptor */ 56 61 #define IDMAC_DES0_DIC BIT(1) ··· 438 433 mci_writel(host, BMOD, SDMMC_IDMAC_SWRESET); 439 434 440 435 /* Mask out interrupts - get Tx & Rx complete only */ 436 + mci_writel(host, IDSTS, IDMAC_INT_CLR); 441 437 mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI | SDMMC_IDMAC_INT_RI | 442 438 SDMMC_IDMAC_INT_TI); 443 439 ··· 1093 1087 status = host->data_status; 1094 1088 1095 1089 if (status & DW_MCI_DATA_ERROR_FLAGS) { 1096 - if (status & SDMMC_INT_DTO) { 1090 + if (status & SDMMC_INT_DRTO) { 1097 1091 data->error = -ETIMEDOUT; 1098 1092 } else if (status & SDMMC_INT_DCRC) { 1099 1093 data->error = -EILSEQ; ··· 1991 1985 #endif /* CONFIG_MMC_DW_IDMAC */ 1992 1986 } 1993 1987 1994 - host->vmmc = devm_regulator_get(mmc_dev(mmc), "vmmc"); 1995 - if (IS_ERR(host->vmmc)) { 1996 - pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc)); 1997 - host->vmmc = NULL; 1998 - } else { 1999 - ret = regulator_enable(host->vmmc); 2000 - if (ret) { 2001 - dev_err(host->dev, 2002 - "failed to enable regulator: %d\n", ret); 2003 - goto err_setup_bus; 2004 - } 2005 - } 2006 - 2007 1988 if (dw_mci_get_cd(mmc)) 2008 1989 set_bit(DW_MMC_CARD_PRESENT, &slot->flags); 2009 1990 else ··· 2117 2124 struct device_node *np = dev->of_node; 2118 2125 const struct dw_mci_drv_data *drv_data = host->drv_data; 2119 2126 int idx, ret; 2127 + u32 clock_frequency; 2120 2128 2121 2129 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 2122 2130 if (!pdata) { ··· 2143 2149 "value of FIFOTH register as default\n"); 2144 2150 2145 2151 of_property_read_u32(np, "card-detect-delay", &pdata->detect_delay_ms); 2152 + 2153 + if (!of_property_read_u32(np, "clock-frequency", &clock_frequency)) 2154 + pdata->bus_hz = clock_frequency; 2146 2155 2147 2156 if (drv_data && drv_data->parse_dt) { 2148 2157 ret = drv_data->parse_dt(host); ··· 2204 2207 host->ciu_clk = devm_clk_get(host->dev, "ciu"); 2205 2208 if (IS_ERR(host->ciu_clk)) { 2206 2209 dev_dbg(host->dev, "ciu clock not available\n"); 2210 + host->bus_hz = host->pdata->bus_hz; 2207 2211 } else { 2208 2212 ret = clk_prepare_enable(host->ciu_clk); 2209 2213 if (ret) { 2210 2214 dev_err(host->dev, "failed to enable ciu clock\n"); 2211 2215 goto err_clk_biu; 2212 2216 } 2213 - } 2214 2217 2215 - if (IS_ERR(host->ciu_clk)) 2216 - host->bus_hz = host->pdata->bus_hz; 2217 - else 2218 + if (host->pdata->bus_hz) { 2219 + ret = clk_set_rate(host->ciu_clk, host->pdata->bus_hz); 2220 + if (ret) 2221 + dev_warn(host->dev, 2222 + "Unable to set bus rate to %ul\n", 2223 + host->pdata->bus_hz); 2224 + } 2218 2225 host->bus_hz = clk_get_rate(host->ciu_clk); 2226 + } 2219 2227 2220 2228 if (drv_data && drv_data->setup_clock) { 2221 2229 ret = drv_data->setup_clock(host); ··· 2231 2229 } 2232 2230 } 2233 2231 2232 + host->vmmc = devm_regulator_get(host->dev, "vmmc"); 2233 + if (IS_ERR(host->vmmc)) { 2234 + ret = PTR_ERR(host->vmmc); 2235 + if (ret == -EPROBE_DEFER) 2236 + goto err_clk_ciu; 2237 + 2238 + dev_info(host->dev, "no vmmc regulator found: %d\n", ret); 2239 + host->vmmc = NULL; 2240 + } else { 2241 + ret = regulator_enable(host->vmmc); 2242 + if (ret) { 2243 + if (ret != -EPROBE_DEFER) 2244 + dev_err(host->dev, 2245 + "regulator_enable fail: %d\n", ret); 2246 + goto err_clk_ciu; 2247 + } 2248 + } 2249 + 2234 2250 if (!host->bus_hz) { 2235 2251 dev_err(host->dev, 2236 2252 "Platform data must supply bus speed\n"); 2237 2253 ret = -ENODEV; 2238 - goto err_clk_ciu; 2254 + goto err_regulator; 2239 2255 } 2240 2256 2241 2257 host->quirks = host->pdata->quirks; ··· 2341 2321 tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host); 2342 2322 host->card_workqueue = alloc_workqueue("dw-mci-card", 2343 2323 WQ_MEM_RECLAIM | WQ_NON_REENTRANT, 1); 2344 - if (!host->card_workqueue) 2324 + if (!host->card_workqueue) { 2325 + ret = -ENOMEM; 2345 2326 goto err_dmaunmap; 2327 + } 2346 2328 INIT_WORK(&host->card_work, dw_mci_work_routine_card); 2347 2329 ret = devm_request_irq(host->dev, host->irq, dw_mci_interrupt, 2348 2330 host->irq_flags, "dw-mci", host); ··· 2400 2378 if (host->use_dma && host->dma_ops->exit) 2401 2379 host->dma_ops->exit(host); 2402 2380 2381 + err_regulator: 2403 2382 if (host->vmmc) 2404 2383 regulator_disable(host->vmmc); 2405 2384
+2 -1
drivers/mmc/host/dw_mmc.h
··· 98 98 #define SDMMC_INT_HLE BIT(12) 99 99 #define SDMMC_INT_FRUN BIT(11) 100 100 #define SDMMC_INT_HTO BIT(10) 101 - #define SDMMC_INT_DTO BIT(9) 101 + #define SDMMC_INT_DRTO BIT(9) 102 102 #define SDMMC_INT_RTO BIT(8) 103 103 #define SDMMC_INT_DCRC BIT(7) 104 104 #define SDMMC_INT_RCRC BIT(6) ··· 111 111 #define SDMMC_INT_ERROR 0xbfc2 112 112 /* Command register defines */ 113 113 #define SDMMC_CMD_START BIT(31) 114 + #define SDMMC_CMD_USE_HOLD_REG BIT(29) 114 115 #define SDMMC_CMD_CCS_EXP BIT(23) 115 116 #define SDMMC_CMD_CEATA_RD BIT(22) 116 117 #define SDMMC_CMD_UPD_CLK BIT(21)
+43 -139
drivers/mmc/host/jz4740_mmc.c
··· 14 14 */ 15 15 16 16 #include <linux/mmc/host.h> 17 + #include <linux/mmc/slot-gpio.h> 17 18 #include <linux/err.h> 18 19 #include <linux/io.h> 19 20 #include <linux/irq.h> ··· 121 120 int irq; 122 121 int card_detect_irq; 123 122 124 - struct resource *mem; 125 123 void __iomem *base; 126 124 struct mmc_request *req; 127 125 struct mmc_command *cmd; ··· 225 225 status = readl(host->base + JZ_REG_MMC_STATUS); 226 226 if (status & JZ_MMC_STATUS_WRITE_ERROR_MASK) { 227 227 if (status & (JZ_MMC_STATUS_TIMEOUT_WRITE)) { 228 + host->req->cmd->error = -ETIMEDOUT; 229 + data->error = -ETIMEDOUT; 230 + } else { 231 + host->req->cmd->error = -EIO; 232 + data->error = -EIO; 233 + } 234 + } else if (status & JZ_MMC_STATUS_READ_ERROR_MASK) { 235 + if (status & (JZ_MMC_STATUS_TIMEOUT_READ)) { 228 236 host->req->cmd->error = -ETIMEDOUT; 229 237 data->error = -ETIMEDOUT; 230 238 } else { ··· 568 560 if (cmd->data) 569 561 cmd->data->error = -EIO; 570 562 cmd->error = -EIO; 571 - } else if (status & (JZ_MMC_STATUS_CRC_READ_ERROR | 572 - JZ_MMC_STATUS_CRC_WRITE_ERROR)) { 573 - if (cmd->data) 574 - cmd->data->error = -EIO; 575 - cmd->error = -EIO; 576 563 } 577 564 578 565 jz4740_mmc_set_irq_enabled(host, irq_reg, false); ··· 629 626 gpio_set_value(host->pdata->gpio_power, 630 627 !host->pdata->power_active_low); 631 628 host->cmdat |= JZ_MMC_CMDAT_INIT; 632 - clk_enable(host->clk); 629 + clk_prepare_enable(host->clk); 633 630 break; 634 631 case MMC_POWER_ON: 635 632 break; ··· 637 634 if (gpio_is_valid(host->pdata->gpio_power)) 638 635 gpio_set_value(host->pdata->gpio_power, 639 636 host->pdata->power_active_low); 640 - clk_disable(host->clk); 637 + clk_disable_unprepare(host->clk); 641 638 break; 642 639 } 643 640 ··· 653 650 } 654 651 } 655 652 656 - static int jz4740_mmc_get_ro(struct mmc_host *mmc) 657 - { 658 - struct jz4740_mmc_host *host = mmc_priv(mmc); 659 - if (!gpio_is_valid(host->pdata->gpio_read_only)) 660 - return -ENOSYS; 661 - 662 - return gpio_get_value(host->pdata->gpio_read_only) ^ 663 - host->pdata->read_only_active_low; 664 - } 665 - 666 - static int jz4740_mmc_get_cd(struct mmc_host *mmc) 667 - { 668 - struct jz4740_mmc_host *host = mmc_priv(mmc); 669 - if (!gpio_is_valid(host->pdata->gpio_card_detect)) 670 - return -ENOSYS; 671 - 672 - return gpio_get_value(host->pdata->gpio_card_detect) ^ 673 - host->pdata->card_detect_active_low; 674 - } 675 - 676 - static irqreturn_t jz4740_mmc_card_detect_irq(int irq, void *devid) 677 - { 678 - struct jz4740_mmc_host *host = devid; 679 - 680 - mmc_detect_change(host->mmc, HZ / 2); 681 - 682 - return IRQ_HANDLED; 683 - } 684 - 685 653 static void jz4740_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable) 686 654 { 687 655 struct jz4740_mmc_host *host = mmc_priv(mmc); ··· 662 688 static const struct mmc_host_ops jz4740_mmc_ops = { 663 689 .request = jz4740_mmc_request, 664 690 .set_ios = jz4740_mmc_set_ios, 665 - .get_ro = jz4740_mmc_get_ro, 666 - .get_cd = jz4740_mmc_get_cd, 691 + .get_ro = mmc_gpio_get_ro, 692 + .get_cd = mmc_gpio_get_cd, 667 693 .enable_sdio_irq = jz4740_mmc_enable_sdio_irq, 668 694 }; 669 695 ··· 698 724 return 0; 699 725 } 700 726 701 - static int jz4740_mmc_request_gpios(struct platform_device *pdev) 727 + static int jz4740_mmc_request_gpios(struct mmc_host *mmc, 728 + struct platform_device *pdev) 702 729 { 703 - int ret; 704 730 struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data; 731 + int ret = 0; 705 732 706 733 if (!pdata) 707 734 return 0; 708 735 709 - ret = jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_card_detect, 710 - "MMC detect change", false, 0); 711 - if (ret) 712 - goto err; 736 + if (!pdata->card_detect_active_low) 737 + mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; 738 + if (!pdata->read_only_active_low) 739 + mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; 713 740 714 - ret = jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_read_only, 715 - "MMC read only", false, 0); 716 - if (ret) 717 - goto err_free_gpio_card_detect; 718 - 719 - ret = jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_power, 720 - "MMC read only", true, pdata->power_active_low); 721 - if (ret) 722 - goto err_free_gpio_read_only; 723 - 724 - return 0; 725 - 726 - err_free_gpio_read_only: 727 - if (gpio_is_valid(pdata->gpio_read_only)) 728 - gpio_free(pdata->gpio_read_only); 729 - err_free_gpio_card_detect: 730 - if (gpio_is_valid(pdata->gpio_card_detect)) 731 - gpio_free(pdata->gpio_card_detect); 732 - err: 733 - return ret; 734 - } 735 - 736 - static int jz4740_mmc_request_cd_irq(struct platform_device *pdev, 737 - struct jz4740_mmc_host *host) 738 - { 739 - struct jz4740_mmc_platform_data *pdata = pdev->dev.platform_data; 740 - 741 - if (!gpio_is_valid(pdata->gpio_card_detect)) 742 - return 0; 743 - 744 - host->card_detect_irq = gpio_to_irq(pdata->gpio_card_detect); 745 - if (host->card_detect_irq < 0) { 746 - dev_warn(&pdev->dev, "Failed to get card detect irq\n"); 747 - return 0; 741 + if (gpio_is_valid(pdata->gpio_card_detect)) { 742 + ret = mmc_gpio_request_cd(mmc, pdata->gpio_card_detect); 743 + if (ret) 744 + return ret; 748 745 } 749 746 750 - return request_irq(host->card_detect_irq, jz4740_mmc_card_detect_irq, 751 - IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 752 - "MMC card detect", host); 747 + if (gpio_is_valid(pdata->gpio_read_only)) { 748 + ret = mmc_gpio_request_ro(mmc, pdata->gpio_read_only); 749 + if (ret) 750 + return ret; 751 + } 752 + 753 + return jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_power, 754 + "MMC read only", true, pdata->power_active_low); 753 755 } 754 756 755 757 static void jz4740_mmc_free_gpios(struct platform_device *pdev) ··· 737 787 738 788 if (gpio_is_valid(pdata->gpio_power)) 739 789 gpio_free(pdata->gpio_power); 740 - if (gpio_is_valid(pdata->gpio_read_only)) 741 - gpio_free(pdata->gpio_read_only); 742 - if (gpio_is_valid(pdata->gpio_card_detect)) 743 - gpio_free(pdata->gpio_card_detect); 744 790 } 745 791 746 792 static inline size_t jz4740_mmc_num_pins(struct jz4740_mmc_host *host) ··· 754 808 struct mmc_host *mmc; 755 809 struct jz4740_mmc_host *host; 756 810 struct jz4740_mmc_platform_data *pdata; 811 + struct resource *res; 757 812 758 813 pdata = pdev->dev.platform_data; 759 814 ··· 774 827 goto err_free_host; 775 828 } 776 829 777 - host->clk = clk_get(&pdev->dev, "mmc"); 830 + host->clk = devm_clk_get(&pdev->dev, "mmc"); 778 831 if (IS_ERR(host->clk)) { 779 832 ret = PTR_ERR(host->clk); 780 833 dev_err(&pdev->dev, "Failed to get mmc clock\n"); 781 834 goto err_free_host; 782 835 } 783 836 784 - host->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 785 - if (!host->mem) { 786 - ret = -ENOENT; 787 - dev_err(&pdev->dev, "Failed to get base platform memory\n"); 788 - goto err_clk_put; 789 - } 790 - 791 - host->mem = request_mem_region(host->mem->start, 792 - resource_size(host->mem), pdev->name); 793 - if (!host->mem) { 794 - ret = -EBUSY; 795 - dev_err(&pdev->dev, "Failed to request base memory region\n"); 796 - goto err_clk_put; 797 - } 798 - 799 - host->base = ioremap_nocache(host->mem->start, resource_size(host->mem)); 837 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 838 + host->base = devm_ioremap_resource(&pdev->dev, res); 800 839 if (!host->base) { 801 840 ret = -EBUSY; 802 841 dev_err(&pdev->dev, "Failed to ioremap base memory\n"); 803 - goto err_release_mem_region; 842 + goto err_free_host; 804 843 } 805 844 806 845 ret = jz_gpio_bulk_request(jz4740_mmc_pins, jz4740_mmc_num_pins(host)); 807 846 if (ret) { 808 847 dev_err(&pdev->dev, "Failed to request mmc pins: %d\n", ret); 809 - goto err_iounmap; 848 + goto err_free_host; 810 849 } 811 850 812 - ret = jz4740_mmc_request_gpios(pdev); 851 + ret = jz4740_mmc_request_gpios(mmc, pdev); 813 852 if (ret) 814 853 goto err_gpio_bulk_free; 815 854 ··· 818 885 spin_lock_init(&host->lock); 819 886 host->irq_mask = 0xffff; 820 887 821 - ret = jz4740_mmc_request_cd_irq(pdev, host); 822 - if (ret) { 823 - dev_err(&pdev->dev, "Failed to request card detect irq\n"); 824 - goto err_free_gpios; 825 - } 826 - 827 888 ret = request_threaded_irq(host->irq, jz_mmc_irq, jz_mmc_irq_worker, 0, 828 889 dev_name(&pdev->dev), host); 829 890 if (ret) { 830 891 dev_err(&pdev->dev, "Failed to request irq: %d\n", ret); 831 - goto err_free_card_detect_irq; 892 + goto err_free_gpios; 832 893 } 833 894 834 895 jz4740_mmc_reset(host); ··· 845 918 846 919 err_free_irq: 847 920 free_irq(host->irq, host); 848 - err_free_card_detect_irq: 849 - if (host->card_detect_irq >= 0) 850 - free_irq(host->card_detect_irq, host); 851 921 err_free_gpios: 852 922 jz4740_mmc_free_gpios(pdev); 853 923 err_gpio_bulk_free: 854 924 jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(host)); 855 - err_iounmap: 856 - iounmap(host->base); 857 - err_release_mem_region: 858 - release_mem_region(host->mem->start, resource_size(host->mem)); 859 - err_clk_put: 860 - clk_put(host->clk); 861 925 err_free_host: 862 - platform_set_drvdata(pdev, NULL); 863 926 mmc_free_host(mmc); 864 927 865 928 return ret; ··· 866 949 mmc_remove_host(host->mmc); 867 950 868 951 free_irq(host->irq, host); 869 - if (host->card_detect_irq >= 0) 870 - free_irq(host->card_detect_irq, host); 871 952 872 953 jz4740_mmc_free_gpios(pdev); 873 954 jz_gpio_bulk_free(jz4740_mmc_pins, jz4740_mmc_num_pins(host)); 874 955 875 - iounmap(host->base); 876 - release_mem_region(host->mem->start, resource_size(host->mem)); 877 - 878 - clk_put(host->clk); 879 - 880 - platform_set_drvdata(pdev, NULL); 881 956 mmc_free_host(host->mmc); 882 957 883 958 return 0; 884 959 } 885 960 886 - #ifdef CONFIG_PM 961 + #ifdef CONFIG_PM_SLEEP 887 962 888 963 static int jz4740_mmc_suspend(struct device *dev) 889 964 { ··· 899 990 return 0; 900 991 } 901 992 902 - const struct dev_pm_ops jz4740_mmc_pm_ops = { 903 - .suspend = jz4740_mmc_suspend, 904 - .resume = jz4740_mmc_resume, 905 - .poweroff = jz4740_mmc_suspend, 906 - .restore = jz4740_mmc_resume, 907 - }; 908 - 993 + static SIMPLE_DEV_PM_OPS(jz4740_mmc_pm_ops, jz4740_mmc_suspend, 994 + jz4740_mmc_resume); 909 995 #define JZ4740_MMC_PM_OPS (&jz4740_mmc_pm_ops) 910 996 #else 911 997 #define JZ4740_MMC_PM_OPS NULL
+40 -34
drivers/mmc/host/mvsdio.c
··· 35 35 36 36 #define DRIVER_NAME "mvsdio" 37 37 38 - static int maxfreq = MVSD_CLOCKRATE_MAX; 38 + static int maxfreq; 39 39 static int nodma; 40 40 41 41 struct mvsd_host { ··· 685 685 const struct mbus_dram_target_info *dram; 686 686 struct resource *r; 687 687 int ret, irq; 688 - int gpio_card_detect, gpio_write_protect; 689 688 struct pinctrl *pinctrl; 690 689 691 690 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); ··· 717 718 if (!IS_ERR(host->clk)) 718 719 clk_prepare_enable(host->clk); 719 720 721 + mmc->ops = &mvsd_ops; 722 + 723 + mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 724 + 725 + mmc->f_min = DIV_ROUND_UP(host->base_clock, MVSD_BASE_DIV_MAX); 726 + mmc->f_max = MVSD_CLOCKRATE_MAX; 727 + 728 + mmc->max_blk_size = 2048; 729 + mmc->max_blk_count = 65535; 730 + 731 + mmc->max_segs = 1; 732 + mmc->max_seg_size = mmc->max_blk_size * mmc->max_blk_count; 733 + mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; 734 + 720 735 if (np) { 721 736 if (IS_ERR(host->clk)) { 722 737 dev_err(&pdev->dev, "DT platforms must have a clock associated\n"); ··· 739 726 } 740 727 741 728 host->base_clock = clk_get_rate(host->clk) / 2; 742 - gpio_card_detect = of_get_named_gpio(np, "cd-gpios", 0); 743 - gpio_write_protect = of_get_named_gpio(np, "wp-gpios", 0); 729 + ret = mmc_of_parse(mmc); 730 + if (ret < 0) 731 + goto out; 744 732 } else { 745 733 const struct mvsdio_platform_data *mvsd_data; 734 + 746 735 mvsd_data = pdev->dev.platform_data; 747 736 if (!mvsd_data) { 748 737 ret = -ENXIO; 749 738 goto out; 750 739 } 740 + mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ | 741 + MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; 751 742 host->base_clock = mvsd_data->clock / 2; 752 - gpio_card_detect = mvsd_data->gpio_card_detect ? : -EINVAL; 753 - gpio_write_protect = mvsd_data->gpio_write_protect ? : -EINVAL; 743 + /* GPIO 0 regarded as invalid for backward compatibility */ 744 + if (mvsd_data->gpio_card_detect && 745 + gpio_is_valid(mvsd_data->gpio_card_detect)) { 746 + ret = mmc_gpio_request_cd(mmc, 747 + mvsd_data->gpio_card_detect); 748 + if (ret) 749 + goto out; 750 + } else { 751 + mmc->caps |= MMC_CAP_NEEDS_POLL; 752 + } 753 + 754 + if (mvsd_data->gpio_write_protect && 755 + gpio_is_valid(mvsd_data->gpio_write_protect)) 756 + mmc_gpio_request_ro(mmc, mvsd_data->gpio_write_protect); 754 757 } 755 758 756 - mmc->ops = &mvsd_ops; 757 - 758 - mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 759 - mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ | 760 - MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; 761 - 762 - mmc->f_min = DIV_ROUND_UP(host->base_clock, MVSD_BASE_DIV_MAX); 763 - mmc->f_max = maxfreq; 764 - 765 - mmc->max_blk_size = 2048; 766 - mmc->max_blk_count = 65535; 767 - 768 - mmc->max_segs = 1; 769 - mmc->max_seg_size = mmc->max_blk_size * mmc->max_blk_count; 770 - mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; 759 + if (maxfreq) 760 + mmc->f_max = maxfreq; 771 761 772 762 spin_lock_init(&host->lock); 773 763 ··· 793 777 goto out; 794 778 } 795 779 796 - if (gpio_is_valid(gpio_card_detect)) { 797 - ret = mmc_gpio_request_cd(mmc, gpio_card_detect); 798 - if (ret) 799 - goto out; 800 - } else 801 - mmc->caps |= MMC_CAP_NEEDS_POLL; 802 - 803 - mmc_gpio_request_ro(mmc, gpio_write_protect); 804 - 805 780 setup_timer(&host->timer, mvsd_timeout_timer, (unsigned long)host); 806 781 platform_set_drvdata(pdev, mmc); 807 782 ret = mmc_add_host(mmc); ··· 800 793 goto out; 801 794 802 795 if (!(mmc->caps & MMC_CAP_NEEDS_POLL)) 803 - dev_notice(&pdev->dev, "using GPIO %d for card detection\n", 804 - gpio_card_detect); 796 + dev_notice(&pdev->dev, "using GPIO for card detection\n"); 805 797 else 806 - dev_notice(&pdev->dev, "lacking card detect (fall back to polling)\n"); 798 + dev_notice(&pdev->dev, 799 + "lacking card detect (fall back to polling)\n"); 807 800 return 0; 808 801 809 802 out: ··· 834 827 clk_disable_unprepare(host->clk); 835 828 mmc_free_host(mmc); 836 829 837 - platform_set_drvdata(pdev, NULL); 838 830 return 0; 839 831 } 840 832
+3 -3
drivers/mmc/host/mxcmmc.c
··· 1067 1067 goto out_release_mem; 1068 1068 } 1069 1069 1070 - mmc_of_parse(mmc); 1070 + ret = mmc_of_parse(mmc); 1071 + if (ret) 1072 + goto out_free; 1071 1073 mmc->ops = &mxcmci_ops; 1072 1074 1073 1075 /* For devicetree parsing, the bus width is read from devicetree */ ··· 1220 1218 { 1221 1219 struct mmc_host *mmc = platform_get_drvdata(pdev); 1222 1220 struct mxcmci_host *host = mmc_priv(mmc); 1223 - 1224 - platform_set_drvdata(pdev, NULL); 1225 1221 1226 1222 mmc_remove_host(mmc); 1227 1223
+1 -10
drivers/mmc/host/mxs-mmc.c
··· 41 41 #include <linux/gpio.h> 42 42 #include <linux/regulator/consumer.h> 43 43 #include <linux/module.h> 44 - #include <linux/pinctrl/consumer.h> 45 44 #include <linux/stmp_device.h> 46 45 #include <linux/spi/mxs-spi.h> 47 46 ··· 579 580 struct mxs_mmc_host *host; 580 581 struct mmc_host *mmc; 581 582 struct resource *iores; 582 - struct pinctrl *pinctrl; 583 583 int ret = 0, irq_err; 584 584 struct regulator *reg_vmmc; 585 585 enum of_gpio_flags flags; ··· 618 620 } 619 621 } 620 622 621 - pinctrl = devm_pinctrl_get_select_default(&pdev->dev); 622 - if (IS_ERR(pinctrl)) { 623 - ret = PTR_ERR(pinctrl); 624 - goto out_mmc_free; 625 - } 626 - 627 623 ssp->clk = clk_get(&pdev->dev, NULL); 628 624 if (IS_ERR(ssp->clk)) { 629 625 ret = PTR_ERR(ssp->clk); ··· 631 639 if (!ssp->dmach) { 632 640 dev_err(mmc_dev(host->mmc), 633 641 "%s: failed to request dma\n", __func__); 642 + ret = -ENODEV; 634 643 goto out_clk_put; 635 644 } 636 645 ··· 700 707 struct mxs_ssp *ssp = &host->ssp; 701 708 702 709 mmc_remove_host(mmc); 703 - 704 - platform_set_drvdata(pdev, NULL); 705 710 706 711 if (ssp->dmach) 707 712 dma_release_channel(ssp->dmach);
-18
drivers/mmc/host/omap.c
··· 1413 1413 else 1414 1414 sig = host->id == 0 ? OMAP_DMA_MMC_TX : OMAP_DMA_MMC2_TX; 1415 1415 host->dma_tx = dma_request_channel(mask, omap_dma_filter_fn, &sig); 1416 - #if 0 1417 - if (!host->dma_tx) { 1418 - dev_err(host->dev, "unable to obtain TX DMA engine channel %u\n", 1419 - sig); 1420 - goto err_dma; 1421 - } 1422 - #else 1423 1416 if (!host->dma_tx) 1424 1417 dev_warn(host->dev, "unable to obtain TX DMA engine channel %u\n", 1425 1418 sig); 1426 - #endif 1427 1419 if (mmc_omap2()) 1428 1420 sig = host->id == 0 ? OMAP24XX_DMA_MMC1_RX : OMAP24XX_DMA_MMC2_RX; 1429 1421 else 1430 1422 sig = host->id == 0 ? OMAP_DMA_MMC_RX : OMAP_DMA_MMC2_RX; 1431 1423 host->dma_rx = dma_request_channel(mask, omap_dma_filter_fn, &sig); 1432 - #if 0 1433 - if (!host->dma_rx) { 1434 - dev_err(host->dev, "unable to obtain RX DMA engine channel %u\n", 1435 - sig); 1436 - goto err_dma; 1437 - } 1438 - #else 1439 1424 if (!host->dma_rx) 1440 1425 dev_warn(host->dev, "unable to obtain RX DMA engine channel %u\n", 1441 1426 sig); 1442 - #endif 1443 1427 1444 1428 ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host); 1445 1429 if (ret) ··· 1483 1499 { 1484 1500 struct mmc_omap_host *host = platform_get_drvdata(pdev); 1485 1501 int i; 1486 - 1487 - platform_set_drvdata(pdev, NULL); 1488 1502 1489 1503 BUG_ON(host == NULL); 1490 1504
-2
drivers/mmc/host/omap_hsmmc.c
··· 2047 2047 } 2048 2048 err1: 2049 2049 iounmap(host->base); 2050 - platform_set_drvdata(pdev, NULL); 2051 2050 mmc_free_host(mmc); 2052 2051 err_alloc: 2053 2052 omap_hsmmc_gpio_free(pdata); ··· 2092 2093 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2093 2094 if (res) 2094 2095 release_mem_region(res->start, resource_size(res)); 2095 - platform_set_drvdata(pdev, NULL); 2096 2096 2097 2097 return 0; 2098 2098 }
-2
drivers/mmc/host/pxamci.c
··· 834 834 struct mmc_host *mmc = platform_get_drvdata(pdev); 835 835 int gpio_cd = -1, gpio_ro = -1, gpio_power = -1; 836 836 837 - platform_set_drvdata(pdev, NULL); 838 - 839 837 if (mmc) { 840 838 struct pxamci_host *host = mmc_priv(mmc); 841 839
-2
drivers/mmc/host/rtsx_pci_sdmmc.c
··· 1316 1316 mmc_remove_host(mmc); 1317 1317 mmc_free_host(mmc); 1318 1318 1319 - platform_set_drvdata(pdev, NULL); 1320 - 1321 1319 dev_dbg(&(pdev->dev), 1322 1320 ": Realtek PCI-E SDMMC controller has been removed\n"); 1323 1321
+92 -4
drivers/mmc/host/sdhci-acpi.c
··· 31 31 #include <linux/bitops.h> 32 32 #include <linux/types.h> 33 33 #include <linux/err.h> 34 + #include <linux/gpio.h> 34 35 #include <linux/interrupt.h> 35 36 #include <linux/acpi.h> 37 + #include <linux/acpi_gpio.h> 36 38 #include <linux/pm.h> 37 39 #include <linux/pm_runtime.h> 40 + #include <linux/delay.h> 38 41 39 42 #include <linux/mmc/host.h> 40 43 #include <linux/mmc/pm.h> ··· 86 83 return 0; 87 84 } 88 85 86 + static void sdhci_acpi_int_hw_reset(struct sdhci_host *host) 87 + { 88 + u8 reg; 89 + 90 + reg = sdhci_readb(host, SDHCI_POWER_CONTROL); 91 + reg |= 0x10; 92 + sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 93 + /* For eMMC, minimum is 1us but give it 9us for good measure */ 94 + udelay(9); 95 + reg &= ~0x10; 96 + sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 97 + /* For eMMC, minimum is 200us but give it 300us for good measure */ 98 + usleep_range(300, 1000); 99 + } 100 + 89 101 static const struct sdhci_ops sdhci_acpi_ops_dflt = { 90 102 .enable_dma = sdhci_acpi_enable_dma, 91 103 }; 92 104 105 + static const struct sdhci_ops sdhci_acpi_ops_int = { 106 + .enable_dma = sdhci_acpi_enable_dma, 107 + .hw_reset = sdhci_acpi_int_hw_reset, 108 + }; 109 + 110 + static const struct sdhci_acpi_chip sdhci_acpi_chip_int = { 111 + .ops = &sdhci_acpi_ops_int, 112 + }; 113 + 93 114 static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc = { 94 - .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE, 115 + .chip = &sdhci_acpi_chip_int, 116 + .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | MMC_CAP_HW_RESET, 95 117 .caps2 = MMC_CAP2_HC_ERASE_SZ, 96 118 .flags = SDHCI_ACPI_RUNTIME_PM, 97 119 }; ··· 129 101 }; 130 102 131 103 static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = { 104 + .flags = SDHCI_ACPI_SD_CD | SDHCI_ACPI_RUNTIME_PM, 105 + .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON, 132 106 }; 133 107 134 108 struct sdhci_acpi_uid_slot { ··· 191 161 return slot; 192 162 } 193 163 164 + #ifdef CONFIG_PM_RUNTIME 165 + 166 + static irqreturn_t sdhci_acpi_sd_cd(int irq, void *dev_id) 167 + { 168 + mmc_detect_change(dev_id, msecs_to_jiffies(200)); 169 + return IRQ_HANDLED; 170 + } 171 + 172 + static int sdhci_acpi_add_own_cd(struct device *dev, int gpio, 173 + struct mmc_host *mmc) 174 + { 175 + unsigned long flags; 176 + int err, irq; 177 + 178 + if (gpio < 0) { 179 + err = gpio; 180 + goto out; 181 + } 182 + 183 + err = devm_gpio_request_one(dev, gpio, GPIOF_DIR_IN, "sd_cd"); 184 + if (err) 185 + goto out; 186 + 187 + irq = gpio_to_irq(gpio); 188 + if (irq < 0) { 189 + err = irq; 190 + goto out_free; 191 + } 192 + 193 + flags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; 194 + err = devm_request_irq(dev, irq, sdhci_acpi_sd_cd, flags, "sd_cd", mmc); 195 + if (err) 196 + goto out_free; 197 + 198 + return 0; 199 + 200 + out_free: 201 + devm_gpio_free(dev, gpio); 202 + out: 203 + dev_warn(dev, "failed to setup card detect wake up\n"); 204 + return err; 205 + } 206 + 207 + #else 208 + 209 + static int sdhci_acpi_add_own_cd(struct device *dev, int gpio, 210 + struct mmc_host *mmc) 211 + { 212 + return 0; 213 + } 214 + 215 + #endif 216 + 194 217 static int sdhci_acpi_probe(struct platform_device *pdev) 195 218 { 196 219 struct device *dev = &pdev->dev; ··· 254 171 struct resource *iomem; 255 172 resource_size_t len; 256 173 const char *hid; 257 - int err; 174 + int err, gpio; 258 175 259 176 if (acpi_bus_get_device(handle, &device)) 260 177 return -ENODEV; ··· 278 195 host = sdhci_alloc_host(dev, sizeof(struct sdhci_acpi_host)); 279 196 if (IS_ERR(host)) 280 197 return PTR_ERR(host); 198 + 199 + gpio = acpi_get_gpio_by_index(dev, 0, NULL); 281 200 282 201 c = sdhci_priv(host); 283 202 c->host = host; ··· 336 251 if (err) 337 252 goto err_free; 338 253 254 + if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) { 255 + if (sdhci_acpi_add_own_cd(dev, gpio, host->mmc)) 256 + c->use_runtime_pm = false; 257 + } 258 + 339 259 if (c->use_runtime_pm) { 340 260 pm_runtime_set_active(dev); 341 261 pm_suspend_ignore_children(dev, 1); ··· 352 262 return 0; 353 263 354 264 err_free: 355 - platform_set_drvdata(pdev, NULL); 356 265 sdhci_free_host(c->host); 357 266 return err; 358 267 } ··· 370 281 371 282 dead = (sdhci_readl(c->host, SDHCI_INT_STATUS) == ~0); 372 283 sdhci_remove_host(c->host, dead); 373 - platform_set_drvdata(pdev, NULL); 374 284 sdhci_free_host(c->host); 375 285 376 286 return 0;
+348
drivers/mmc/host/sdhci-bcm-kona.c
··· 1 + /* 2 + * Copyright (C) 2013 Broadcom Corporation 3 + * 4 + * This program is free software; you can redistribute it and/or 5 + * modify it under the terms of the GNU General Public License as 6 + * published by the Free Software Foundation version 2. 7 + * 8 + * This program is distributed "as is" WITHOUT ANY WARRANTY of any 9 + * kind, whether express or implied; without even the implied warranty 10 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + 14 + #include <linux/kernel.h> 15 + #include <linux/module.h> 16 + #include <linux/delay.h> 17 + #include <linux/highmem.h> 18 + #include <linux/platform_device.h> 19 + #include <linux/mmc/host.h> 20 + #include <linux/io.h> 21 + #include <linux/gpio.h> 22 + #include <linux/clk.h> 23 + #include <linux/regulator/consumer.h> 24 + #include <linux/of.h> 25 + #include <linux/of_device.h> 26 + #include <linux/of_gpio.h> 27 + #include <linux/version.h> 28 + #include <linux/mmc/slot-gpio.h> 29 + 30 + #include "sdhci-pltfm.h" 31 + #include "sdhci.h" 32 + 33 + #define SDHCI_SOFT_RESET 0x01000000 34 + #define KONA_SDHOST_CORECTRL 0x8000 35 + #define KONA_SDHOST_CD_PINCTRL 0x00000008 36 + #define KONA_SDHOST_STOP_HCLK 0x00000004 37 + #define KONA_SDHOST_RESET 0x00000002 38 + #define KONA_SDHOST_EN 0x00000001 39 + 40 + #define KONA_SDHOST_CORESTAT 0x8004 41 + #define KONA_SDHOST_WP 0x00000002 42 + #define KONA_SDHOST_CD_SW 0x00000001 43 + 44 + #define KONA_SDHOST_COREIMR 0x8008 45 + #define KONA_SDHOST_IP 0x00000001 46 + 47 + #define KONA_SDHOST_COREISR 0x800C 48 + #define KONA_SDHOST_COREIMSR 0x8010 49 + #define KONA_SDHOST_COREDBG1 0x8014 50 + #define KONA_SDHOST_COREGPO_MASK 0x8018 51 + 52 + #define SD_DETECT_GPIO_DEBOUNCE_128MS 128 53 + 54 + #define KONA_MMC_AUTOSUSPEND_DELAY (50) 55 + 56 + struct sdhci_bcm_kona_dev { 57 + struct mutex write_lock; /* protect back to back writes */ 58 + }; 59 + 60 + 61 + static int sdhci_bcm_kona_sd_reset(struct sdhci_host *host) 62 + { 63 + unsigned int val; 64 + unsigned long timeout; 65 + 66 + /* This timeout should be sufficent for core to reset */ 67 + timeout = jiffies + msecs_to_jiffies(100); 68 + 69 + /* reset the host using the top level reset */ 70 + val = sdhci_readl(host, KONA_SDHOST_CORECTRL); 71 + val |= KONA_SDHOST_RESET; 72 + sdhci_writel(host, val, KONA_SDHOST_CORECTRL); 73 + 74 + while (!(sdhci_readl(host, KONA_SDHOST_CORECTRL) & KONA_SDHOST_RESET)) { 75 + if (time_is_before_jiffies(timeout)) { 76 + pr_err("Error: sd host is stuck in reset!!!\n"); 77 + return -EFAULT; 78 + } 79 + } 80 + 81 + /* bring the host out of reset */ 82 + val = sdhci_readl(host, KONA_SDHOST_CORECTRL); 83 + val &= ~KONA_SDHOST_RESET; 84 + 85 + /* 86 + * Back-to-Back register write needs a delay of 1ms at bootup (min 10uS) 87 + * Back-to-Back writes to same register needs delay when SD bus clock 88 + * is very low w.r.t AHB clock, mainly during boot-time and during card 89 + * insert-removal. 90 + */ 91 + usleep_range(1000, 5000); 92 + sdhci_writel(host, val, KONA_SDHOST_CORECTRL); 93 + 94 + return 0; 95 + } 96 + 97 + static void sdhci_bcm_kona_sd_init(struct sdhci_host *host) 98 + { 99 + unsigned int val; 100 + 101 + /* enable the interrupt from the IP core */ 102 + val = sdhci_readl(host, KONA_SDHOST_COREIMR); 103 + val |= KONA_SDHOST_IP; 104 + sdhci_writel(host, val, KONA_SDHOST_COREIMR); 105 + 106 + /* Enable the AHB clock gating module to the host */ 107 + val = sdhci_readl(host, KONA_SDHOST_CORECTRL); 108 + val |= KONA_SDHOST_EN; 109 + 110 + /* 111 + * Back-to-Back register write needs a delay of 1ms at bootup (min 10uS) 112 + * Back-to-Back writes to same register needs delay when SD bus clock 113 + * is very low w.r.t AHB clock, mainly during boot-time and during card 114 + * insert-removal. 115 + */ 116 + usleep_range(1000, 5000); 117 + sdhci_writel(host, val, KONA_SDHOST_CORECTRL); 118 + } 119 + 120 + /* 121 + * Software emulation of the SD card insertion/removal. Set insert=1 for insert 122 + * and insert=0 for removal. The card detection is done by GPIO. For Broadcom 123 + * IP to function properly the bit 0 of CORESTAT register needs to be set/reset 124 + * to generate the CD IRQ handled in sdhci.c which schedules card_tasklet. 125 + */ 126 + static int sdhci_bcm_kona_sd_card_emulate(struct sdhci_host *host, int insert) 127 + { 128 + struct sdhci_pltfm_host *pltfm_priv = sdhci_priv(host); 129 + struct sdhci_bcm_kona_dev *kona_dev = sdhci_pltfm_priv(pltfm_priv); 130 + u32 val; 131 + 132 + /* 133 + * Back-to-Back register write needs a delay of min 10uS. 134 + * Back-to-Back writes to same register needs delay when SD bus clock 135 + * is very low w.r.t AHB clock, mainly during boot-time and during card 136 + * insert-removal. 137 + * We keep 20uS 138 + */ 139 + mutex_lock(&kona_dev->write_lock); 140 + udelay(20); 141 + val = sdhci_readl(host, KONA_SDHOST_CORESTAT); 142 + 143 + if (insert) { 144 + int ret; 145 + 146 + ret = mmc_gpio_get_ro(host->mmc); 147 + if (ret >= 0) 148 + val = (val & ~KONA_SDHOST_WP) | 149 + ((ret) ? KONA_SDHOST_WP : 0); 150 + 151 + val |= KONA_SDHOST_CD_SW; 152 + sdhci_writel(host, val, KONA_SDHOST_CORESTAT); 153 + } else { 154 + val &= ~KONA_SDHOST_CD_SW; 155 + sdhci_writel(host, val, KONA_SDHOST_CORESTAT); 156 + } 157 + mutex_unlock(&kona_dev->write_lock); 158 + 159 + return 0; 160 + } 161 + 162 + /* 163 + * SD card interrupt event callback 164 + */ 165 + void sdhci_bcm_kona_card_event(struct sdhci_host *host) 166 + { 167 + if (mmc_gpio_get_cd(host->mmc) > 0) { 168 + dev_dbg(mmc_dev(host->mmc), 169 + "card inserted\n"); 170 + sdhci_bcm_kona_sd_card_emulate(host, 1); 171 + } else { 172 + dev_dbg(mmc_dev(host->mmc), 173 + "card removed\n"); 174 + sdhci_bcm_kona_sd_card_emulate(host, 0); 175 + } 176 + } 177 + 178 + /* 179 + * Get the base clock. Use central clock source for now. Not sure if different 180 + * clock speed to each dev is allowed 181 + */ 182 + static unsigned int sdhci_bcm_kona_get_max_clk(struct sdhci_host *host) 183 + { 184 + struct sdhci_bcm_kona_dev *kona_dev; 185 + struct sdhci_pltfm_host *pltfm_priv = sdhci_priv(host); 186 + kona_dev = sdhci_pltfm_priv(pltfm_priv); 187 + 188 + return host->mmc->f_max; 189 + } 190 + 191 + static unsigned int sdhci_bcm_kona_get_timeout_clock(struct sdhci_host *host) 192 + { 193 + return sdhci_bcm_kona_get_max_clk(host); 194 + } 195 + 196 + static void sdhci_bcm_kona_init_74_clocks(struct sdhci_host *host, 197 + u8 power_mode) 198 + { 199 + /* 200 + * JEDEC and SD spec specify supplying 74 continuous clocks to 201 + * device after power up. With minimum bus (100KHz) that 202 + * that translates to 740us 203 + */ 204 + if (power_mode != MMC_POWER_OFF) 205 + udelay(740); 206 + } 207 + 208 + static struct sdhci_ops sdhci_bcm_kona_ops = { 209 + .get_max_clock = sdhci_bcm_kona_get_max_clk, 210 + .get_timeout_clock = sdhci_bcm_kona_get_timeout_clock, 211 + .platform_send_init_74_clocks = sdhci_bcm_kona_init_74_clocks, 212 + .card_event = sdhci_bcm_kona_card_event, 213 + }; 214 + 215 + static struct sdhci_pltfm_data sdhci_pltfm_data_kona = { 216 + .ops = &sdhci_bcm_kona_ops, 217 + .quirks = SDHCI_QUIRK_NO_CARD_NO_RESET | 218 + SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | SDHCI_QUIRK_32BIT_DMA_ADDR | 219 + SDHCI_QUIRK_32BIT_DMA_SIZE | SDHCI_QUIRK_32BIT_ADMA_SIZE | 220 + SDHCI_QUIRK_FORCE_BLK_SZ_2048 | 221 + SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN, 222 + }; 223 + 224 + static const struct of_device_id sdhci_bcm_kona_of_match[] __initdata = { 225 + { .compatible = "bcm,kona-sdhci"}, 226 + {} 227 + }; 228 + MODULE_DEVICE_TABLE(of, sdhci_bcm_kona_of_match); 229 + 230 + static int __init sdhci_bcm_kona_probe(struct platform_device *pdev) 231 + { 232 + struct sdhci_bcm_kona_dev *kona_dev = NULL; 233 + struct sdhci_pltfm_host *pltfm_priv; 234 + struct device *dev = &pdev->dev; 235 + struct sdhci_host *host; 236 + int ret; 237 + 238 + ret = 0; 239 + 240 + host = sdhci_pltfm_init(pdev, &sdhci_pltfm_data_kona, 241 + sizeof(*kona_dev)); 242 + if (IS_ERR(host)) 243 + return PTR_ERR(host); 244 + 245 + dev_dbg(dev, "%s: inited. IOADDR=%p\n", __func__, host->ioaddr); 246 + 247 + pltfm_priv = sdhci_priv(host); 248 + 249 + kona_dev = sdhci_pltfm_priv(pltfm_priv); 250 + mutex_init(&kona_dev->write_lock); 251 + 252 + mmc_of_parse(host->mmc); 253 + 254 + if (!host->mmc->f_max) { 255 + dev_err(&pdev->dev, "Missing max-freq for SDHCI cfg\n"); 256 + ret = -ENXIO; 257 + goto err_pltfm_free; 258 + } 259 + 260 + dev_dbg(dev, "non-removable=%c\n", 261 + (host->mmc->caps & MMC_CAP_NONREMOVABLE) ? 'Y' : 'N'); 262 + dev_dbg(dev, "cd_gpio %c, wp_gpio %c\n", 263 + (mmc_gpio_get_cd(host->mmc) != -ENOSYS) ? 'Y' : 'N', 264 + (mmc_gpio_get_ro(host->mmc) != -ENOSYS) ? 'Y' : 'N'); 265 + 266 + if (host->mmc->caps | MMC_CAP_NONREMOVABLE) 267 + host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; 268 + 269 + dev_dbg(dev, "is_8bit=%c\n", 270 + (host->mmc->caps | MMC_CAP_8_BIT_DATA) ? 'Y' : 'N'); 271 + 272 + ret = sdhci_bcm_kona_sd_reset(host); 273 + if (ret) 274 + goto err_pltfm_free; 275 + 276 + sdhci_bcm_kona_sd_init(host); 277 + 278 + ret = sdhci_add_host(host); 279 + if (ret) { 280 + dev_err(dev, "Failed sdhci_add_host\n"); 281 + goto err_reset; 282 + } 283 + 284 + /* if device is eMMC, emulate card insert right here */ 285 + if (host->mmc->caps | MMC_CAP_NONREMOVABLE) { 286 + ret = sdhci_bcm_kona_sd_card_emulate(host, 1); 287 + if (ret) { 288 + dev_err(dev, 289 + "unable to emulate card insertion\n"); 290 + goto err_remove_host; 291 + } 292 + } 293 + /* 294 + * Since the card detection GPIO interrupt is configured to be 295 + * edge sensitive, check the initial GPIO value here, emulate 296 + * only if the card is present 297 + */ 298 + if (mmc_gpio_get_cd(host->mmc) > 0) 299 + sdhci_bcm_kona_sd_card_emulate(host, 1); 300 + 301 + dev_dbg(dev, "initialized properly\n"); 302 + return 0; 303 + 304 + err_remove_host: 305 + sdhci_remove_host(host, 0); 306 + 307 + err_reset: 308 + sdhci_bcm_kona_sd_reset(host); 309 + 310 + err_pltfm_free: 311 + sdhci_pltfm_free(pdev); 312 + 313 + dev_err(dev, "Probing of sdhci-pltfm failed: %d\n", ret); 314 + return ret; 315 + } 316 + 317 + static int __exit sdhci_bcm_kona_remove(struct platform_device *pdev) 318 + { 319 + struct sdhci_host *host = platform_get_drvdata(pdev); 320 + int dead; 321 + u32 scratch; 322 + 323 + dead = 0; 324 + scratch = readl(host->ioaddr + SDHCI_INT_STATUS); 325 + if (scratch == (u32)-1) 326 + dead = 1; 327 + sdhci_remove_host(host, dead); 328 + 329 + sdhci_free_host(host); 330 + 331 + return 0; 332 + } 333 + 334 + static struct platform_driver sdhci_bcm_kona_driver = { 335 + .driver = { 336 + .name = "sdhci-kona", 337 + .owner = THIS_MODULE, 338 + .pm = SDHCI_PLTFM_PMOPS, 339 + .of_match_table = of_match_ptr(sdhci_bcm_kona_of_match), 340 + }, 341 + .probe = sdhci_bcm_kona_probe, 342 + .remove = __exit_p(sdhci_bcm_kona_remove), 343 + }; 344 + module_platform_driver(sdhci_bcm_kona_driver); 345 + 346 + MODULE_DESCRIPTION("SDHCI driver for Broadcom Kona platform"); 347 + MODULE_AUTHOR("Broadcom"); 348 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/mmc/host/sdhci-bcm2835.c
··· 148 148 struct sdhci_pltfm_host *pltfm_host; 149 149 int ret; 150 150 151 - host = sdhci_pltfm_init(pdev, &bcm2835_sdhci_pdata); 151 + host = sdhci_pltfm_init(pdev, &bcm2835_sdhci_pdata, 0); 152 152 if (IS_ERR(host)) 153 153 return PTR_ERR(host); 154 154
+1 -1
drivers/mmc/host/sdhci-cns3xxx.c
··· 96 96 97 97 static int sdhci_cns3xxx_probe(struct platform_device *pdev) 98 98 { 99 - return sdhci_pltfm_register(pdev, &sdhci_cns3xxx_pdata); 99 + return sdhci_pltfm_register(pdev, &sdhci_cns3xxx_pdata, 0); 100 100 } 101 101 102 102 static int sdhci_cns3xxx_remove(struct platform_device *pdev)
+1 -1
drivers/mmc/host/sdhci-dove.c
··· 130 130 gpio_direction_input(priv->gpio_cd); 131 131 } 132 132 133 - host = sdhci_pltfm_init(pdev, &sdhci_dove_pdata); 133 + host = sdhci_pltfm_init(pdev, &sdhci_dove_pdata, 0); 134 134 if (IS_ERR(host)) { 135 135 ret = PTR_ERR(host); 136 136 goto err_sdhci_pltfm_init;
+27 -3
drivers/mmc/host/sdhci-esdhc-imx.c
··· 384 384 } 385 385 } 386 386 387 + static unsigned int esdhc_pltfm_get_max_clock(struct sdhci_host *host) 388 + { 389 + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 390 + struct pltfm_imx_data *imx_data = pltfm_host->priv; 391 + struct esdhc_platform_data *boarddata = &imx_data->boarddata; 392 + 393 + u32 f_host = clk_get_rate(pltfm_host->clk); 394 + 395 + if (boarddata->f_max && (boarddata->f_max < f_host)) 396 + return boarddata->f_max; 397 + else 398 + return f_host; 399 + } 400 + 387 401 static unsigned int esdhc_pltfm_get_min_clock(struct sdhci_host *host) 388 402 { 389 403 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 390 404 391 405 return clk_get_rate(pltfm_host->clk) / 256 / 16; 406 + } 407 + 408 + static inline void esdhc_pltfm_set_clock(struct sdhci_host *host, 409 + unsigned int clock) 410 + { 411 + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 412 + 413 + esdhc_set_clock(host, clock, clk_get_rate(pltfm_host->clk)); 392 414 } 393 415 394 416 static unsigned int esdhc_pltfm_get_ro(struct sdhci_host *host) ··· 460 438 .write_l = esdhc_writel_le, 461 439 .write_w = esdhc_writew_le, 462 440 .write_b = esdhc_writeb_le, 463 - .set_clock = esdhc_set_clock, 464 - .get_max_clock = sdhci_pltfm_clk_get_max_clock, 441 + .set_clock = esdhc_pltfm_set_clock, 442 + .get_max_clock = esdhc_pltfm_get_max_clock, 465 443 .get_min_clock = esdhc_pltfm_get_min_clock, 466 444 .get_ro = esdhc_pltfm_get_ro, 467 445 .platform_bus_width = esdhc_pltfm_bus_width, ··· 504 482 505 483 of_property_read_u32(np, "bus-width", &boarddata->max_bus_width); 506 484 485 + of_property_read_u32(np, "max-frequency", &boarddata->f_max); 486 + 507 487 return 0; 508 488 } 509 489 #else ··· 527 503 int err; 528 504 struct pltfm_imx_data *imx_data; 529 505 530 - host = sdhci_pltfm_init(pdev, &sdhci_esdhc_imx_pdata); 506 + host = sdhci_pltfm_init(pdev, &sdhci_esdhc_imx_pdata, 0); 531 507 if (IS_ERR(host)) 532 508 return PTR_ERR(host); 533 509
+12 -4
drivers/mmc/host/sdhci-esdhc.h
··· 36 36 /* pltfm-specific */ 37 37 #define ESDHC_HOST_CONTROL_LE 0x20 38 38 39 + /* 40 + * P2020 interpretation of the SDHCI_HOST_CONTROL register 41 + */ 42 + #define ESDHC_CTRL_4BITBUS (0x1 << 1) 43 + #define ESDHC_CTRL_8BITBUS (0x2 << 1) 44 + #define ESDHC_CTRL_BUSWIDTH_MASK (0x3 << 1) 45 + 39 46 /* OF-specific */ 40 47 #define ESDHC_DMA_SYSCTL 0x40c 41 48 #define ESDHC_DMA_SNOOP 0x00000040 42 49 43 50 #define ESDHC_HOST_CONTROL_RES 0x05 44 51 45 - static inline void esdhc_set_clock(struct sdhci_host *host, unsigned int clock) 52 + static inline void esdhc_set_clock(struct sdhci_host *host, unsigned int clock, 53 + unsigned int host_clock) 46 54 { 47 55 int pre_div = 2; 48 56 int div = 1; ··· 64 56 | ESDHC_CLOCK_MASK); 65 57 sdhci_writel(host, temp, ESDHC_SYSTEM_CONTROL); 66 58 67 - while (host->max_clk / pre_div / 16 > clock && pre_div < 256) 59 + while (host_clock / pre_div / 16 > clock && pre_div < 256) 68 60 pre_div *= 2; 69 61 70 - while (host->max_clk / pre_div / div > clock && div < 16) 62 + while (host_clock / pre_div / div > clock && div < 16) 71 63 div++; 72 64 73 65 dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n", 74 - clock, host->max_clk / pre_div / div); 66 + clock, host_clock / pre_div / div); 75 67 76 68 pre_div >>= 1; 77 69 div--;
+61 -2
drivers/mmc/host/sdhci-of-esdhc.c
··· 13 13 * your option) any later version. 14 14 */ 15 15 16 + #include <linux/err.h> 16 17 #include <linux/io.h> 17 18 #include <linux/of.h> 18 19 #include <linux/delay.h> ··· 121 120 if (reg == SDHCI_HOST_CONTROL) { 122 121 u32 dma_bits; 123 122 123 + /* 124 + * If host control register is not standard, exit 125 + * this function 126 + */ 127 + if (host->quirks2 & SDHCI_QUIRK2_BROKEN_HOST_CONTROL) 128 + return; 129 + 124 130 /* DMA select is 22,23 bits in Protocol Control Register */ 125 131 dma_bits = (val & SDHCI_CTRL_DMA_MASK) << 5; 126 132 clrsetbits_be32(host->ioaddr + reg , SDHCI_CTRL_DMA_MASK << 5, ··· 208 200 } 209 201 210 202 /* Set the clock */ 211 - esdhc_set_clock(host, clock); 203 + esdhc_set_clock(host, clock, host->max_clk); 212 204 } 213 205 214 206 #ifdef CONFIG_PM ··· 238 230 host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ; 239 231 } 240 232 233 + static int esdhc_pltfm_bus_width(struct sdhci_host *host, int width) 234 + { 235 + u32 ctrl; 236 + 237 + switch (width) { 238 + case MMC_BUS_WIDTH_8: 239 + ctrl = ESDHC_CTRL_8BITBUS; 240 + break; 241 + 242 + case MMC_BUS_WIDTH_4: 243 + ctrl = ESDHC_CTRL_4BITBUS; 244 + break; 245 + 246 + default: 247 + ctrl = 0; 248 + break; 249 + } 250 + 251 + clrsetbits_be32(host->ioaddr + SDHCI_HOST_CONTROL, 252 + ESDHC_CTRL_BUSWIDTH_MASK, ctrl); 253 + 254 + return 0; 255 + } 256 + 241 257 static const struct sdhci_ops sdhci_esdhc_ops = { 242 258 .read_l = esdhc_readl, 243 259 .read_w = esdhc_readw, ··· 279 247 .platform_resume = esdhc_of_resume, 280 248 #endif 281 249 .adma_workaround = esdhci_of_adma_workaround, 250 + .platform_bus_width = esdhc_pltfm_bus_width, 282 251 }; 283 252 284 253 static const struct sdhci_pltfm_data sdhci_esdhc_pdata = { ··· 295 262 296 263 static int sdhci_esdhc_probe(struct platform_device *pdev) 297 264 { 298 - return sdhci_pltfm_register(pdev, &sdhci_esdhc_pdata); 265 + struct sdhci_host *host; 266 + struct device_node *np; 267 + int ret; 268 + 269 + host = sdhci_pltfm_init(pdev, &sdhci_esdhc_pdata, 0); 270 + if (IS_ERR(host)) 271 + return PTR_ERR(host); 272 + 273 + sdhci_get_of_property(pdev); 274 + 275 + np = pdev->dev.of_node; 276 + if (of_device_is_compatible(np, "fsl,p2020-esdhc")) { 277 + /* 278 + * Freescale messed up with P2020 as it has a non-standard 279 + * host control register 280 + */ 281 + host->quirks2 |= SDHCI_QUIRK2_BROKEN_HOST_CONTROL; 282 + } 283 + 284 + /* call to generic mmc_of_parse to support additional capabilities */ 285 + mmc_of_parse(host->mmc); 286 + 287 + ret = sdhci_add_host(host); 288 + if (ret) 289 + sdhci_pltfm_free(pdev); 290 + 291 + return ret; 299 292 } 300 293 301 294 static int sdhci_esdhc_remove(struct platform_device *pdev)
+1 -1
drivers/mmc/host/sdhci-of-hlwd.c
··· 68 68 69 69 static int sdhci_hlwd_probe(struct platform_device *pdev) 70 70 { 71 - return sdhci_pltfm_register(pdev, &sdhci_hlwd_pdata); 71 + return sdhci_pltfm_register(pdev, &sdhci_hlwd_pdata, 0); 72 72 } 73 73 74 74 static int sdhci_hlwd_remove(struct platform_device *pdev)
+41 -2
drivers/mmc/host/sdhci-pci.c
··· 36 36 #define PCI_DEVICE_ID_INTEL_BYT_EMMC 0x0f14 37 37 #define PCI_DEVICE_ID_INTEL_BYT_SDIO 0x0f15 38 38 #define PCI_DEVICE_ID_INTEL_BYT_SD 0x0f16 39 + #define PCI_DEVICE_ID_INTEL_BYT_EMMC2 0x0f50 39 40 40 41 /* 41 42 * PCI registers ··· 78 77 int rst_n_gpio; 79 78 int cd_gpio; 80 79 int cd_irq; 80 + 81 + void (*hw_reset)(struct sdhci_host *host); 81 82 }; 82 83 83 84 struct sdhci_pci_chip { ··· 310 307 .probe_slot = pch_hc_probe_slot, 311 308 }; 312 309 310 + static void sdhci_pci_int_hw_reset(struct sdhci_host *host) 311 + { 312 + u8 reg; 313 + 314 + reg = sdhci_readb(host, SDHCI_POWER_CONTROL); 315 + reg |= 0x10; 316 + sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 317 + /* For eMMC, minimum is 1us but give it 9us for good measure */ 318 + udelay(9); 319 + reg &= ~0x10; 320 + sdhci_writeb(host, reg, SDHCI_POWER_CONTROL); 321 + /* For eMMC, minimum is 200us but give it 300us for good measure */ 322 + usleep_range(300, 1000); 323 + } 324 + 313 325 static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot) 314 326 { 315 - slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE; 327 + slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | 328 + MMC_CAP_HW_RESET; 316 329 slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ; 330 + slot->hw_reset = sdhci_pci_int_hw_reset; 317 331 return 0; 318 332 } 319 333 ··· 352 332 }; 353 333 354 334 static const struct sdhci_pci_fixes sdhci_intel_byt_sd = { 335 + .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON, 336 + .allow_runtime_pm = true, 355 337 }; 356 338 357 339 /* O2Micro extra registers */ ··· 932 910 }, 933 911 934 912 { 913 + .vendor = PCI_VENDOR_ID_INTEL, 914 + .device = PCI_DEVICE_ID_INTEL_BYT_EMMC2, 915 + .subvendor = PCI_ANY_ID, 916 + .subdevice = PCI_ANY_ID, 917 + .driver_data = (kernel_ulong_t)&sdhci_intel_byt_emmc, 918 + }, 919 + 920 + { 935 921 .vendor = PCI_VENDOR_ID_O2, 936 922 .device = PCI_DEVICE_ID_O2_8120, 937 923 .subvendor = PCI_ANY_ID, ··· 1044 1014 return 0; 1045 1015 } 1046 1016 1047 - static void sdhci_pci_hw_reset(struct sdhci_host *host) 1017 + static void sdhci_pci_gpio_hw_reset(struct sdhci_host *host) 1048 1018 { 1049 1019 struct sdhci_pci_slot *slot = sdhci_priv(host); 1050 1020 int rst_n_gpio = slot->rst_n_gpio; ··· 1057 1027 gpio_set_value_cansleep(rst_n_gpio, 1); 1058 1028 /* For eMMC, minimum is 200us but give it 300us for good measure */ 1059 1029 usleep_range(300, 1000); 1030 + } 1031 + 1032 + static void sdhci_pci_hw_reset(struct sdhci_host *host) 1033 + { 1034 + struct sdhci_pci_slot *slot = sdhci_priv(host); 1035 + 1036 + if (slot->hw_reset) 1037 + slot->hw_reset(host); 1060 1038 } 1061 1039 1062 1040 static const struct sdhci_ops sdhci_pci_ops = { ··· 1364 1326 if (!gpio_request(slot->rst_n_gpio, "eMMC_reset")) { 1365 1327 gpio_direction_output(slot->rst_n_gpio, 1); 1366 1328 slot->host->mmc->caps |= MMC_CAP_HW_RESET; 1329 + slot->hw_reset = sdhci_pci_gpio_hw_reset; 1367 1330 } else { 1368 1331 dev_warn(&pdev->dev, "failed to request rst_n_gpio\n"); 1369 1332 slot->rst_n_gpio = -EINVAL;
+13 -10
drivers/mmc/host/sdhci-pltfm.c
··· 115 115 EXPORT_SYMBOL_GPL(sdhci_get_of_property); 116 116 117 117 struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev, 118 - const struct sdhci_pltfm_data *pdata) 118 + const struct sdhci_pltfm_data *pdata, 119 + size_t priv_size) 119 120 { 120 121 struct sdhci_host *host; 121 - struct sdhci_pltfm_host *pltfm_host; 122 122 struct device_node *np = pdev->dev.of_node; 123 123 struct resource *iomem; 124 124 int ret; ··· 134 134 135 135 /* Some PCI-based MFD need the parent here */ 136 136 if (pdev->dev.parent != &platform_bus && !np) 137 - host = sdhci_alloc_host(pdev->dev.parent, sizeof(*pltfm_host)); 137 + host = sdhci_alloc_host(pdev->dev.parent, 138 + sizeof(struct sdhci_pltfm_host) + priv_size); 138 139 else 139 - host = sdhci_alloc_host(&pdev->dev, sizeof(*pltfm_host)); 140 + host = sdhci_alloc_host(&pdev->dev, 141 + sizeof(struct sdhci_pltfm_host) + priv_size); 140 142 141 143 if (IS_ERR(host)) { 142 144 ret = PTR_ERR(host); 143 145 goto err; 144 146 } 145 147 146 - pltfm_host = sdhci_priv(host); 147 - 148 148 host->hw_name = dev_name(&pdev->dev); 149 149 if (pdata && pdata->ops) 150 150 host->ops = pdata->ops; 151 151 else 152 152 host->ops = &sdhci_pltfm_ops; 153 - if (pdata) 153 + if (pdata) { 154 154 host->quirks = pdata->quirks; 155 + host->quirks2 = pdata->quirks2; 156 + } 157 + 155 158 host->irq = platform_get_irq(pdev, 0); 156 159 157 160 if (!request_mem_region(iomem->start, resource_size(iomem), ··· 200 197 iounmap(host->ioaddr); 201 198 release_mem_region(iomem->start, resource_size(iomem)); 202 199 sdhci_free_host(host); 203 - platform_set_drvdata(pdev, NULL); 204 200 } 205 201 EXPORT_SYMBOL_GPL(sdhci_pltfm_free); 206 202 207 203 int sdhci_pltfm_register(struct platform_device *pdev, 208 - const struct sdhci_pltfm_data *pdata) 204 + const struct sdhci_pltfm_data *pdata, 205 + size_t priv_size) 209 206 { 210 207 struct sdhci_host *host; 211 208 int ret = 0; 212 209 213 - host = sdhci_pltfm_init(pdev, pdata); 210 + host = sdhci_pltfm_init(pdev, pdata, priv_size); 214 211 if (IS_ERR(host)) 215 212 return PTR_ERR(host); 216 213
+12 -2
drivers/mmc/host/sdhci-pltfm.h
··· 18 18 struct sdhci_pltfm_data { 19 19 const struct sdhci_ops *ops; 20 20 unsigned int quirks; 21 + unsigned int quirks2; 21 22 }; 22 23 23 24 struct sdhci_pltfm_host { ··· 28 27 /* migrate from sdhci_of_host */ 29 28 unsigned int clock; 30 29 u16 xfer_mode_shadow; 30 + 31 + unsigned long private[0] ____cacheline_aligned; 31 32 }; 32 33 33 34 #ifdef CONFIG_MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER ··· 94 91 extern void sdhci_get_of_property(struct platform_device *pdev); 95 92 96 93 extern struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev, 97 - const struct sdhci_pltfm_data *pdata); 94 + const struct sdhci_pltfm_data *pdata, 95 + size_t priv_size); 98 96 extern void sdhci_pltfm_free(struct platform_device *pdev); 99 97 100 98 extern int sdhci_pltfm_register(struct platform_device *pdev, 101 - const struct sdhci_pltfm_data *pdata); 99 + const struct sdhci_pltfm_data *pdata, 100 + size_t priv_size); 102 101 extern int sdhci_pltfm_unregister(struct platform_device *pdev); 103 102 104 103 extern unsigned int sdhci_pltfm_clk_get_max_clock(struct sdhci_host *host); 104 + 105 + static inline void *sdhci_pltfm_priv(struct sdhci_pltfm_host *host) 106 + { 107 + return (void *)host->private; 108 + } 105 109 106 110 #ifdef CONFIG_PM 107 111 extern const struct dev_pm_ops sdhci_pltfm_pmops;
+1 -3
drivers/mmc/host/sdhci-pxav2.c
··· 175 175 if (!pxa) 176 176 return -ENOMEM; 177 177 178 - host = sdhci_pltfm_init(pdev, NULL); 178 + host = sdhci_pltfm_init(pdev, NULL, 0); 179 179 if (IS_ERR(host)) { 180 180 kfree(pxa); 181 181 return PTR_ERR(host); ··· 252 252 clk_put(pltfm_host->clk); 253 253 sdhci_pltfm_free(pdev); 254 254 kfree(pxa); 255 - 256 - platform_set_drvdata(pdev, NULL); 257 255 258 256 return 0; 259 257 }
+9 -9
drivers/mmc/host/sdhci-pxav3.c
··· 230 230 if (!pxa) 231 231 return -ENOMEM; 232 232 233 - host = sdhci_pltfm_init(pdev, &sdhci_pxav3_pdata); 233 + host = sdhci_pltfm_init(pdev, &sdhci_pxav3_pdata, 0); 234 234 if (IS_ERR(host)) { 235 235 kfree(pxa); 236 236 return PTR_ERR(host); ··· 252 252 253 253 match = of_match_device(of_match_ptr(sdhci_pxav3_of_match), &pdev->dev); 254 254 if (match) { 255 - mmc_of_parse(host->mmc); 255 + ret = mmc_of_parse(host->mmc); 256 + if (ret) 257 + goto err_of_parse; 256 258 sdhci_get_of_property(pdev); 257 259 pdata = pxav3_get_mmc_pdata(dev); 258 260 } else if (pdata) { ··· 287 285 } 288 286 } 289 287 290 - pm_runtime_set_active(&pdev->dev); 291 288 pm_runtime_enable(&pdev->dev); 289 + pm_runtime_get_sync(&pdev->dev); 292 290 pm_runtime_set_autosuspend_delay(&pdev->dev, PXAV3_RPM_DELAY_MS); 293 291 pm_runtime_use_autosuspend(&pdev->dev); 294 292 pm_suspend_ignore_children(&pdev->dev, 1); 295 - pm_runtime_get_noresume(&pdev->dev); 296 293 297 294 ret = sdhci_add_host(host); 298 295 if (ret) { 299 296 dev_err(&pdev->dev, "failed to add host\n"); 300 - pm_runtime_forbid(&pdev->dev); 301 - pm_runtime_disable(&pdev->dev); 302 297 goto err_add_host; 303 298 } 304 299 ··· 312 313 313 314 return 0; 314 315 316 + err_of_parse: 317 + err_cd_req: 315 318 err_add_host: 319 + pm_runtime_put_sync(&pdev->dev); 320 + pm_runtime_disable(&pdev->dev); 316 321 clk_disable_unprepare(clk); 317 322 clk_put(clk); 318 - err_cd_req: 319 323 err_clk_get: 320 324 sdhci_pltfm_free(pdev); 321 325 kfree(pxa); ··· 340 338 341 339 sdhci_pltfm_free(pdev); 342 340 kfree(pxa); 343 - 344 - platform_set_drvdata(pdev, NULL); 345 341 346 342 return 0; 347 343 }
-1
drivers/mmc/host/sdhci-s3c.c
··· 745 745 clk_disable_unprepare(sc->clk_io); 746 746 747 747 sdhci_free_host(host); 748 - platform_set_drvdata(pdev, NULL); 749 748 750 749 return 0; 751 750 }
+23 -36
drivers/mmc/host/sdhci-sirf.c
··· 13 13 #include <linux/of.h> 14 14 #include <linux/of_gpio.h> 15 15 #include <linux/mmc/slot-gpio.h> 16 - #include <linux/pinctrl/consumer.h> 17 16 #include "sdhci-pltfm.h" 18 17 19 18 struct sdhci_sirf_priv { ··· 23 24 static unsigned int sdhci_sirf_get_max_clk(struct sdhci_host *host) 24 25 { 25 26 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 26 - struct sdhci_sirf_priv *priv = pltfm_host->priv; 27 + struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host); 27 28 return clk_get_rate(priv->clk); 28 29 } 29 30 ··· 45 46 struct sdhci_host *host; 46 47 struct sdhci_pltfm_host *pltfm_host; 47 48 struct sdhci_sirf_priv *priv; 48 - struct pinctrl *pinctrl; 49 + struct clk *clk; 50 + int gpio_cd; 49 51 int ret; 50 52 51 - pinctrl = devm_pinctrl_get_select_default(&pdev->dev); 52 - if (IS_ERR(pinctrl)) { 53 - dev_err(&pdev->dev, "unable to get pinmux"); 54 - return PTR_ERR(pinctrl); 55 - } 56 - 57 - priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_sirf_priv), 58 - GFP_KERNEL); 59 - if (!priv) { 60 - dev_err(&pdev->dev, "unable to allocate private data"); 61 - return -ENOMEM; 62 - } 63 - 64 - priv->clk = devm_clk_get(&pdev->dev, NULL); 65 - if (IS_ERR(priv->clk)) { 53 + clk = devm_clk_get(&pdev->dev, NULL); 54 + if (IS_ERR(clk)) { 66 55 dev_err(&pdev->dev, "unable to get clock"); 67 - return PTR_ERR(priv->clk); 56 + return PTR_ERR(clk); 68 57 } 69 58 70 - if (pdev->dev.of_node) { 71 - priv->gpio_cd = of_get_named_gpio(pdev->dev.of_node, 72 - "cd-gpios", 0); 73 - } else { 74 - priv->gpio_cd = -EINVAL; 75 - } 59 + if (pdev->dev.of_node) 60 + gpio_cd = of_get_named_gpio(pdev->dev.of_node, "cd-gpios", 0); 61 + else 62 + gpio_cd = -EINVAL; 76 63 77 - host = sdhci_pltfm_init(pdev, &sdhci_sirf_pdata); 78 - if (IS_ERR(host)) { 79 - ret = PTR_ERR(host); 80 - goto err_sdhci_pltfm_init; 81 - } 64 + host = sdhci_pltfm_init(pdev, &sdhci_sirf_pdata, sizeof(struct sdhci_sirf_priv)); 65 + if (IS_ERR(host)) 66 + return PTR_ERR(host); 82 67 83 68 pltfm_host = sdhci_priv(host); 84 - pltfm_host->priv = priv; 69 + priv = sdhci_pltfm_priv(pltfm_host); 70 + priv->clk = clk; 71 + priv->gpio_cd = gpio_cd; 85 72 86 73 sdhci_get_of_property(pdev); 87 74 88 - clk_prepare_enable(priv->clk); 75 + ret = clk_prepare_enable(priv->clk); 76 + if (ret) 77 + goto err_clk_prepare; 89 78 90 79 ret = sdhci_add_host(host); 91 80 if (ret) ··· 98 111 sdhci_remove_host(host, 0); 99 112 err_sdhci_add: 100 113 clk_disable_unprepare(priv->clk); 114 + err_clk_prepare: 101 115 sdhci_pltfm_free(pdev); 102 - err_sdhci_pltfm_init: 103 116 return ret; 104 117 } 105 118 ··· 107 120 { 108 121 struct sdhci_host *host = platform_get_drvdata(pdev); 109 122 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 110 - struct sdhci_sirf_priv *priv = pltfm_host->priv; 123 + struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host); 111 124 112 125 sdhci_pltfm_unregister(pdev); 113 126 ··· 123 136 { 124 137 struct sdhci_host *host = dev_get_drvdata(dev); 125 138 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 126 - struct sdhci_sirf_priv *priv = pltfm_host->priv; 139 + struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host); 127 140 int ret; 128 141 129 142 ret = sdhci_suspend_host(host); ··· 139 152 { 140 153 struct sdhci_host *host = dev_get_drvdata(dev); 141 154 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 142 - struct sdhci_sirf_priv *priv = pltfm_host->priv; 155 + struct sdhci_sirf_priv *priv = sdhci_pltfm_priv(pltfm_host); 143 156 int ret; 144 157 145 158 ret = clk_enable(priv->clk);
-2
drivers/mmc/host/sdhci-spear.c
··· 258 258 return 0; 259 259 260 260 set_drvdata: 261 - platform_set_drvdata(pdev, NULL); 262 261 sdhci_remove_host(host, 1); 263 262 free_host: 264 263 sdhci_free_host(host); ··· 277 278 int dead = 0; 278 279 u32 scratch; 279 280 280 - platform_set_drvdata(pdev, NULL); 281 281 scratch = readl(host->ioaddr + SDHCI_INT_STATUS); 282 282 if (scratch == (u32)-1) 283 283 dead = 1;
+7 -4
drivers/mmc/host/sdhci-tegra.c
··· 205 205 }; 206 206 MODULE_DEVICE_TABLE(of, sdhci_tegra_dt_match); 207 207 208 - static void sdhci_tegra_parse_dt(struct device *dev) 208 + static int sdhci_tegra_parse_dt(struct device *dev) 209 209 { 210 210 struct device_node *np = dev->of_node; 211 211 struct sdhci_host *host = dev_get_drvdata(dev); ··· 213 213 struct sdhci_tegra *tegra_host = pltfm_host->priv; 214 214 215 215 tegra_host->power_gpio = of_get_named_gpio(np, "power-gpios", 0); 216 - mmc_of_parse(host->mmc); 216 + return mmc_of_parse(host->mmc); 217 217 } 218 218 219 219 static int sdhci_tegra_probe(struct platform_device *pdev) ··· 231 231 return -EINVAL; 232 232 soc_data = match->data; 233 233 234 - host = sdhci_pltfm_init(pdev, soc_data->pdata); 234 + host = sdhci_pltfm_init(pdev, soc_data->pdata, 0); 235 235 if (IS_ERR(host)) 236 236 return PTR_ERR(host); 237 237 pltfm_host = sdhci_priv(host); ··· 245 245 tegra_host->soc_data = soc_data; 246 246 pltfm_host->priv = tegra_host; 247 247 248 - sdhci_tegra_parse_dt(&pdev->dev); 248 + rc = sdhci_tegra_parse_dt(&pdev->dev); 249 + if (rc) 250 + goto err_parse_dt; 249 251 250 252 if (gpio_is_valid(tegra_host->power_gpio)) { 251 253 rc = gpio_request(tegra_host->power_gpio, "sdhci_power"); ··· 281 279 if (gpio_is_valid(tegra_host->power_gpio)) 282 280 gpio_free(tegra_host->power_gpio); 283 281 err_power_req: 282 + err_parse_dt: 284 283 err_alloc_tegra_host: 285 284 sdhci_pltfm_free(pdev); 286 285 return rc;
+51 -12
drivers/mmc/host/sdhci.c
··· 58 58 #ifdef CONFIG_PM_RUNTIME 59 59 static int sdhci_runtime_pm_get(struct sdhci_host *host); 60 60 static int sdhci_runtime_pm_put(struct sdhci_host *host); 61 + static void sdhci_runtime_pm_bus_on(struct sdhci_host *host); 62 + static void sdhci_runtime_pm_bus_off(struct sdhci_host *host); 61 63 #else 62 64 static inline int sdhci_runtime_pm_get(struct sdhci_host *host) 63 65 { ··· 68 66 static inline int sdhci_runtime_pm_put(struct sdhci_host *host) 69 67 { 70 68 return 0; 69 + } 70 + static void sdhci_runtime_pm_bus_on(struct sdhci_host *host) 71 + { 72 + } 73 + static void sdhci_runtime_pm_bus_off(struct sdhci_host *host) 74 + { 71 75 } 72 76 #endif 73 77 ··· 200 192 201 193 sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET); 202 194 203 - if (mask & SDHCI_RESET_ALL) 195 + if (mask & SDHCI_RESET_ALL) { 204 196 host->clock = 0; 197 + /* Reset-all turns off SD Bus Power */ 198 + if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) 199 + sdhci_runtime_pm_bus_off(host); 200 + } 205 201 206 202 /* Wait max 100 ms */ 207 203 timeout = 100; ··· 1280 1268 1281 1269 if (pwr == 0) { 1282 1270 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); 1271 + if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) 1272 + sdhci_runtime_pm_bus_off(host); 1283 1273 return 0; 1284 1274 } 1285 1275 ··· 1302 1288 pwr |= SDHCI_POWER_ON; 1303 1289 1304 1290 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); 1291 + 1292 + if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) 1293 + sdhci_runtime_pm_bus_on(host); 1305 1294 1306 1295 /* 1307 1296 * Some controllers need an extra 10ms delay of 10ms before they ··· 1543 1526 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); 1544 1527 /* Select Bus Speed Mode for host */ 1545 1528 ctrl_2 &= ~SDHCI_CTRL_UHS_MASK; 1546 - if (ios->timing == MMC_TIMING_MMC_HS200) 1547 - ctrl_2 |= SDHCI_CTRL_HS_SDR200; 1529 + if ((ios->timing == MMC_TIMING_MMC_HS200) || 1530 + (ios->timing == MMC_TIMING_UHS_SDR104)) 1531 + ctrl_2 |= SDHCI_CTRL_UHS_SDR104; 1548 1532 else if (ios->timing == MMC_TIMING_UHS_SDR12) 1549 1533 ctrl_2 |= SDHCI_CTRL_UHS_SDR12; 1550 1534 else if (ios->timing == MMC_TIMING_UHS_SDR25) 1551 1535 ctrl_2 |= SDHCI_CTRL_UHS_SDR25; 1552 1536 else if (ios->timing == MMC_TIMING_UHS_SDR50) 1553 1537 ctrl_2 |= SDHCI_CTRL_UHS_SDR50; 1554 - else if (ios->timing == MMC_TIMING_UHS_SDR104) 1555 - ctrl_2 |= SDHCI_CTRL_UHS_SDR104; 1556 1538 else if (ios->timing == MMC_TIMING_UHS_DDR50) 1557 1539 ctrl_2 |= SDHCI_CTRL_UHS_DDR50; 1558 1540 sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); ··· 1862 1846 */ 1863 1847 if (((ctrl & SDHCI_CTRL_UHS_MASK) == SDHCI_CTRL_UHS_SDR50) && 1864 1848 (host->flags & SDHCI_SDR50_NEEDS_TUNING || 1865 - host->flags & SDHCI_HS200_NEEDS_TUNING)) 1849 + host->flags & SDHCI_SDR104_NEEDS_TUNING)) 1866 1850 requires_tuning_nonuhs = true; 1867 1851 1868 1852 if (((ctrl & SDHCI_CTRL_UHS_MASK) == SDHCI_CTRL_UHS_SDR104) || ··· 2062 2046 struct sdhci_host *host = mmc_priv(mmc); 2063 2047 unsigned long flags; 2064 2048 2049 + /* First check if client has provided their own card event */ 2050 + if (host->ops->card_event) 2051 + host->ops->card_event(host); 2052 + 2065 2053 spin_lock_irqsave(&host->lock, flags); 2066 2054 2067 2055 /* Check host->mrq first in case we are runtime suspended */ 2068 - if (host->mrq && 2069 - !(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) { 2056 + if (host->mrq && !sdhci_do_get_cd(host)) { 2070 2057 pr_err("%s: Card removed during transfer!\n", 2071 2058 mmc_hostname(host->mmc)); 2072 2059 pr_err("%s: Resetting controller.\n", ··· 2644 2625 return pm_runtime_put_autosuspend(host->mmc->parent); 2645 2626 } 2646 2627 2628 + static void sdhci_runtime_pm_bus_on(struct sdhci_host *host) 2629 + { 2630 + if (host->runtime_suspended || host->bus_on) 2631 + return; 2632 + host->bus_on = true; 2633 + pm_runtime_get_noresume(host->mmc->parent); 2634 + } 2635 + 2636 + static void sdhci_runtime_pm_bus_off(struct sdhci_host *host) 2637 + { 2638 + if (host->runtime_suspended || !host->bus_on) 2639 + return; 2640 + host->bus_on = false; 2641 + pm_runtime_put_noidle(host->mmc->parent); 2642 + } 2643 + 2647 2644 int sdhci_runtime_suspend_host(struct sdhci_host *host) 2648 2645 { 2649 2646 unsigned long flags; ··· 2997 2962 mmc->caps |= MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25; 2998 2963 2999 2964 /* SDR104 supports also implies SDR50 support */ 3000 - if (caps[1] & SDHCI_SUPPORT_SDR104) 2965 + if (caps[1] & SDHCI_SUPPORT_SDR104) { 3001 2966 mmc->caps |= MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_SDR50; 3002 - else if (caps[1] & SDHCI_SUPPORT_SDR50) 2967 + /* SD3.0: SDR104 is supported so (for eMMC) the caps2 2968 + * field can be promoted to support HS200. 2969 + */ 2970 + mmc->caps2 |= MMC_CAP2_HS200; 2971 + } else if (caps[1] & SDHCI_SUPPORT_SDR50) 3003 2972 mmc->caps |= MMC_CAP_UHS_SDR50; 3004 2973 3005 2974 if (caps[1] & SDHCI_SUPPORT_DDR50) ··· 3013 2974 if (caps[1] & SDHCI_USE_SDR50_TUNING) 3014 2975 host->flags |= SDHCI_SDR50_NEEDS_TUNING; 3015 2976 3016 - /* Does the host need tuning for HS200? */ 2977 + /* Does the host need tuning for SDR104 / HS200? */ 3017 2978 if (mmc->caps2 & MMC_CAP2_HS200) 3018 - host->flags |= SDHCI_HS200_NEEDS_TUNING; 2979 + host->flags |= SDHCI_SDR104_NEEDS_TUNING; 3019 2980 3020 2981 /* Driver Type(s) (A, C, D) supported by the host */ 3021 2982 if (caps[1] & SDHCI_DRIVER_TYPE_A)
+1
drivers/mmc/host/sdhci.h
··· 294 294 void (*platform_resume)(struct sdhci_host *host); 295 295 void (*adma_workaround)(struct sdhci_host *host, u32 intmask); 296 296 void (*platform_init)(struct sdhci_host *host); 297 + void (*card_event)(struct sdhci_host *host); 297 298 }; 298 299 299 300 #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
+8 -4
drivers/mmc/host/sh_mmcif.c
··· 1244 1244 u32 state; 1245 1245 1246 1246 state = sh_mmcif_readl(host->addr, MMCIF_CE_INT); 1247 - sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~state); 1247 + sh_mmcif_writel(host->addr, MMCIF_CE_INT, 1248 + ~(state & sh_mmcif_readl(host->addr, MMCIF_CE_INT_MASK))); 1248 1249 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, state & MASK_CLEAN); 1249 1250 1250 1251 if (state & ~MASK_CLEAN) ··· 1370 1369 ret = -ENOMEM; 1371 1370 goto ealloch; 1372 1371 } 1373 - mmc_of_parse(mmc); 1372 + 1373 + ret = mmc_of_parse(mmc); 1374 + if (ret < 0) 1375 + goto eofparse; 1376 + 1374 1377 host = mmc_priv(mmc); 1375 1378 host->mmc = mmc; 1376 1379 host->addr = reg; ··· 1469 1464 clk_put(host->hclk); 1470 1465 eclkget: 1471 1466 pm_runtime_disable(&pdev->dev); 1467 + eofparse: 1472 1468 mmc_free_host(mmc); 1473 1469 ealloch: 1474 1470 iounmap(reg); ··· 1506 1500 free_irq(irq[0], host); 1507 1501 if (irq[1] >= 0) 1508 1502 free_irq(irq[1], host); 1509 - 1510 - platform_set_drvdata(pdev, NULL); 1511 1503 1512 1504 clk_disable(host->hclk); 1513 1505 mmc_free_host(host->mmc);
+22 -12
drivers/mmc/host/sh_mobile_sdhi.c
··· 46 46 struct sh_mobile_sdhi { 47 47 struct clk *clk; 48 48 struct tmio_mmc_data mmc_data; 49 - struct sh_dmae_slave param_tx; 50 - struct sh_dmae_slave param_rx; 51 49 struct tmio_mmc_dma dma_priv; 52 50 }; 53 51 54 52 static int sh_mobile_sdhi_clk_enable(struct platform_device *pdev, unsigned int *f) 55 53 { 56 - struct mmc_host *mmc = dev_get_drvdata(&pdev->dev); 54 + struct mmc_host *mmc = platform_get_drvdata(pdev); 57 55 struct tmio_mmc_host *host = mmc_priv(mmc); 58 56 struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data); 59 57 int ret = clk_enable(priv->clk); ··· 64 66 65 67 static void sh_mobile_sdhi_clk_disable(struct platform_device *pdev) 66 68 { 67 - struct mmc_host *mmc = dev_get_drvdata(&pdev->dev); 69 + struct mmc_host *mmc = platform_get_drvdata(pdev); 68 70 struct tmio_mmc_host *host = mmc_priv(mmc); 69 71 struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data); 70 72 clk_disable(priv->clk); ··· 119 121 120 122 static void sh_mobile_sdhi_cd_wakeup(const struct platform_device *pdev) 121 123 { 122 - mmc_detect_change(dev_get_drvdata(&pdev->dev), msecs_to_jiffies(100)); 124 + mmc_detect_change(platform_get_drvdata(pdev), msecs_to_jiffies(100)); 123 125 } 124 126 125 127 static const struct sh_mobile_sdhi_ops sdhi_ops = { ··· 144 146 struct tmio_mmc_host *host; 145 147 int irq, ret, i = 0; 146 148 bool multiplexed_isr = true; 149 + struct tmio_mmc_dma *dma_priv; 147 150 148 151 priv = devm_kzalloc(&pdev->dev, sizeof(struct sh_mobile_sdhi), GFP_KERNEL); 149 152 if (priv == NULL) { ··· 153 154 } 154 155 155 156 mmc_data = &priv->mmc_data; 157 + dma_priv = &priv->dma_priv; 156 158 157 159 if (p) { 158 160 if (p->init) { ··· 186 186 mmc_data->get_cd = sh_mobile_sdhi_get_cd; 187 187 188 188 if (p->dma_slave_tx > 0 && p->dma_slave_rx > 0) { 189 - priv->param_tx.shdma_slave.slave_id = p->dma_slave_tx; 190 - priv->param_rx.shdma_slave.slave_id = p->dma_slave_rx; 191 - priv->dma_priv.chan_priv_tx = &priv->param_tx.shdma_slave; 192 - priv->dma_priv.chan_priv_rx = &priv->param_rx.shdma_slave; 193 - priv->dma_priv.alignment_shift = 1; /* 2-byte alignment */ 194 - mmc_data->dma = &priv->dma_priv; 189 + /* 190 + * Yes, we have to provide slave IDs twice to TMIO: 191 + * once as a filter parameter and once for channel 192 + * configuration as an explicit slave ID 193 + */ 194 + dma_priv->chan_priv_tx = (void *)p->dma_slave_tx; 195 + dma_priv->chan_priv_rx = (void *)p->dma_slave_rx; 196 + dma_priv->slave_id_tx = p->dma_slave_tx; 197 + dma_priv->slave_id_rx = p->dma_slave_rx; 195 198 } 196 199 } 200 + 201 + dma_priv->alignment_shift = 1; /* 2-byte alignment */ 202 + dma_priv->filter = shdma_chan_filter; 203 + 204 + mmc_data->dma = dma_priv; 197 205 198 206 /* 199 207 * All SDHI blocks support 2-byte and larger block sizes in 4-bit ··· 273 265 } 274 266 275 267 /* There must be at least one IRQ source */ 276 - if (!i) 268 + if (!i) { 269 + ret = irq; 277 270 goto eirq; 271 + } 278 272 } 279 273 280 274 dev_info(&pdev->dev, "%s base at 0x%08lx clock rate %u MHz\n",
-2
drivers/mmc/host/tmio_mmc.c
··· 112 112 const struct mfd_cell *cell = mfd_get_cell(pdev); 113 113 struct mmc_host *mmc = platform_get_drvdata(pdev); 114 114 115 - platform_set_drvdata(pdev, NULL); 116 - 117 115 if (mmc) { 118 116 struct tmio_mmc_host *host = mmc_priv(mmc); 119 117 free_irq(platform_get_irq(pdev, 0), host);
+19 -2
drivers/mmc/host/tmio_mmc.h
··· 40 40 41 41 struct tmio_mmc_data; 42 42 43 + /* 44 + * We differentiate between the following 3 power states: 45 + * 1. card slot powered off, controller stopped. This is used, when either there 46 + * is no card in the slot, or the card really has to be powered down. 47 + * 2. card slot powered on, controller stopped. This is used, when a card is in 48 + * the slot, but no activity is currently taking place. This is a power- 49 + * saving mode with card-state preserved. This state can be entered, e.g. 50 + * when MMC clock-gating is used. 51 + * 3. card slot powered on, controller running. This is the actual active state. 52 + */ 53 + enum tmio_mmc_power { 54 + TMIO_MMC_OFF_STOP, /* card power off, controller stopped */ 55 + TMIO_MMC_ON_STOP, /* card power on, controller stopped */ 56 + TMIO_MMC_ON_RUN, /* card power on, controller running */ 57 + }; 58 + 43 59 struct tmio_mmc_host { 44 60 void __iomem *ctl; 45 61 unsigned long bus_shift; ··· 64 48 struct mmc_data *data; 65 49 struct mmc_host *mmc; 66 50 67 - /* Controller power state */ 68 - bool power; 51 + /* Controller and card power state */ 52 + enum tmio_mmc_power power; 69 53 70 54 /* Callbacks for clock / power control */ 71 55 void (*set_pwr)(struct platform_device *host, int state); ··· 101 85 unsigned long last_req_ts; 102 86 struct mutex ios_lock; /* protect set_ios() context */ 103 87 bool native_hotplug; 88 + bool resuming; 104 89 }; 105 90 106 91 int tmio_mmc_host_probe(struct tmio_mmc_host **host,
+35 -13
drivers/mmc/host/tmio_mmc_dma.c
··· 261 261 spin_unlock_irq(&host->lock); 262 262 } 263 263 264 - /* It might be necessary to make filter MFD specific */ 265 - static bool tmio_mmc_filter(struct dma_chan *chan, void *arg) 266 - { 267 - dev_dbg(chan->device->dev, "%s: slave data %p\n", __func__, arg); 268 - chan->private = arg; 269 - return true; 270 - } 271 - 272 264 void tmio_mmc_request_dma(struct tmio_mmc_host *host, struct tmio_mmc_data *pdata) 273 265 { 274 266 /* We can only either use DMA for both Tx and Rx or not use it at all */ 275 - if (!pdata->dma) 267 + if (!pdata->dma || (!host->pdev->dev.of_node && 268 + (!pdata->dma->chan_priv_tx || !pdata->dma->chan_priv_rx))) 276 269 return; 277 270 278 271 if (!host->chan_tx && !host->chan_rx) { 272 + struct resource *res = platform_get_resource(host->pdev, 273 + IORESOURCE_MEM, 0); 274 + struct dma_slave_config cfg = {}; 279 275 dma_cap_mask_t mask; 276 + int ret; 277 + 278 + if (!res) 279 + return; 280 280 281 281 dma_cap_zero(mask); 282 282 dma_cap_set(DMA_SLAVE, mask); 283 283 284 - host->chan_tx = dma_request_channel(mask, tmio_mmc_filter, 285 - pdata->dma->chan_priv_tx); 284 + host->chan_tx = dma_request_slave_channel_compat(mask, 285 + pdata->dma->filter, pdata->dma->chan_priv_tx, 286 + &host->pdev->dev, "tx"); 286 287 dev_dbg(&host->pdev->dev, "%s: TX: got channel %p\n", __func__, 287 288 host->chan_tx); 288 289 289 290 if (!host->chan_tx) 290 291 return; 291 292 292 - host->chan_rx = dma_request_channel(mask, tmio_mmc_filter, 293 - pdata->dma->chan_priv_rx); 293 + if (pdata->dma->chan_priv_tx) 294 + cfg.slave_id = pdata->dma->slave_id_tx; 295 + cfg.direction = DMA_MEM_TO_DEV; 296 + cfg.dst_addr = res->start + (CTL_SD_DATA_PORT << host->bus_shift); 297 + cfg.src_addr = 0; 298 + ret = dmaengine_slave_config(host->chan_tx, &cfg); 299 + if (ret < 0) 300 + goto ecfgtx; 301 + 302 + host->chan_rx = dma_request_slave_channel_compat(mask, 303 + pdata->dma->filter, pdata->dma->chan_priv_rx, 304 + &host->pdev->dev, "rx"); 294 305 dev_dbg(&host->pdev->dev, "%s: RX: got channel %p\n", __func__, 295 306 host->chan_rx); 296 307 297 308 if (!host->chan_rx) 298 309 goto ereqrx; 310 + 311 + if (pdata->dma->chan_priv_rx) 312 + cfg.slave_id = pdata->dma->slave_id_rx; 313 + cfg.direction = DMA_DEV_TO_MEM; 314 + cfg.src_addr = cfg.dst_addr; 315 + cfg.dst_addr = 0; 316 + ret = dmaengine_slave_config(host->chan_rx, &cfg); 317 + if (ret < 0) 318 + goto ecfgrx; 299 319 300 320 host->bounce_buf = (u8 *)__get_free_page(GFP_KERNEL | GFP_DMA); 301 321 if (!host->bounce_buf) ··· 330 310 return; 331 311 332 312 ebouncebuf: 313 + ecfgrx: 333 314 dma_release_channel(host->chan_rx); 334 315 host->chan_rx = NULL; 335 316 ereqrx: 317 + ecfgtx: 336 318 dma_release_channel(host->chan_tx); 337 319 host->chan_tx = NULL; 338 320 }
+27 -13
drivers/mmc/host/tmio_mmc_pio.c
··· 859 859 * is kept positive, so no suspending actually takes place. 860 860 */ 861 861 if (ios->power_mode == MMC_POWER_ON && ios->clock) { 862 - if (!host->power) { 862 + if (host->power != TMIO_MMC_ON_RUN) { 863 863 tmio_mmc_clk_update(mmc); 864 864 pm_runtime_get_sync(dev); 865 + if (host->resuming) { 866 + tmio_mmc_reset(host); 867 + host->resuming = false; 868 + } 865 869 } 870 + if (host->power == TMIO_MMC_OFF_STOP) 871 + tmio_mmc_reset(host); 866 872 tmio_mmc_set_clock(host, ios->clock); 867 - if (!host->power) { 873 + if (host->power == TMIO_MMC_OFF_STOP) 868 874 /* power up SD card and the bus */ 869 875 tmio_mmc_power_on(host, ios->vdd); 870 - host->power = true; 871 - } 876 + host->power = TMIO_MMC_ON_RUN; 872 877 /* start bus clock */ 873 878 tmio_mmc_clk_start(host); 874 879 } else if (ios->power_mode != MMC_POWER_UP) { 875 - if (host->power) { 876 - struct tmio_mmc_data *pdata = host->pdata; 877 - if (ios->power_mode == MMC_POWER_OFF) 880 + struct tmio_mmc_data *pdata = host->pdata; 881 + unsigned int old_power = host->power; 882 + 883 + if (old_power != TMIO_MMC_OFF_STOP) { 884 + if (ios->power_mode == MMC_POWER_OFF) { 878 885 tmio_mmc_power_off(host); 886 + host->power = TMIO_MMC_OFF_STOP; 887 + } else { 888 + host->power = TMIO_MMC_ON_STOP; 889 + } 890 + } 891 + 892 + if (old_power == TMIO_MMC_ON_RUN) { 879 893 tmio_mmc_clk_stop(host); 880 - host->power = false; 881 894 pm_runtime_put(dev); 882 895 if (pdata->clk_disable) 883 896 pdata->clk_disable(host->pdev); 884 897 } 885 898 } 886 899 887 - if (host->power) { 900 + if (host->power != TMIO_MMC_OFF_STOP) { 888 901 switch (ios->bus_width) { 889 902 case MMC_BUS_WIDTH_1: 890 903 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x80e0); ··· 1001 988 if (!mmc) 1002 989 return -ENOMEM; 1003 990 1004 - mmc_of_parse(mmc); 991 + ret = mmc_of_parse(mmc); 992 + if (ret < 0) 993 + goto host_free; 1005 994 1006 995 pdata->dev = &pdev->dev; 1007 996 _host = mmc_priv(mmc); ··· 1040 1025 mmc->caps & MMC_CAP_NONREMOVABLE || 1041 1026 mmc->slot.cd_irq >= 0); 1042 1027 1043 - _host->power = false; 1028 + _host->power = TMIO_MMC_OFF_STOP; 1044 1029 pm_runtime_enable(&pdev->dev); 1045 1030 ret = pm_runtime_resume(&pdev->dev); 1046 1031 if (ret < 0) ··· 1169 1154 struct mmc_host *mmc = dev_get_drvdata(dev); 1170 1155 struct tmio_mmc_host *host = mmc_priv(mmc); 1171 1156 1172 - tmio_mmc_reset(host); 1173 1157 tmio_mmc_enable_dma(host, true); 1174 1158 1175 1159 /* The MMC core will perform the complete set up */ 1160 + host->resuming = true; 1176 1161 return mmc_resume_host(mmc); 1177 1162 } 1178 1163 EXPORT_SYMBOL(tmio_mmc_host_resume); ··· 1190 1175 struct mmc_host *mmc = dev_get_drvdata(dev); 1191 1176 struct tmio_mmc_host *host = mmc_priv(mmc); 1192 1177 1193 - tmio_mmc_reset(host); 1194 1178 tmio_mmc_enable_dma(host, true); 1195 1179 1196 1180 return 0;
-2
drivers/mmc/host/wmt-sdmmc.c
··· 927 927 928 928 mmc_free_host(mmc); 929 929 930 - platform_set_drvdata(pdev, NULL); 931 - 932 930 dev_info(&pdev->dev, "WMT MCI device removed\n"); 933 931 934 932 return 0;
+5
include/linux/mfd/tmio.h
··· 81 81 void tmio_core_mmc_pwr(void __iomem *cnf, int shift, int state); 82 82 void tmio_core_mmc_clk_div(void __iomem *cnf, int shift, int state); 83 83 84 + struct dma_chan; 85 + 84 86 struct tmio_mmc_dma { 85 87 void *chan_priv_tx; 86 88 void *chan_priv_rx; 89 + int slave_id_tx; 90 + int slave_id_rx; 87 91 int alignment_shift; 92 + bool (*filter)(struct dma_chan *chan, void *arg); 88 93 }; 89 94 90 95 struct tmio_mmc_host;
+10 -1
include/linux/mmc/card.h
··· 94 94 u8 raw_ext_csd_structure; /* 194 */ 95 95 u8 raw_card_type; /* 196 */ 96 96 u8 out_of_int_time; /* 198 */ 97 - u8 raw_s_a_timeout; /* 217 */ 97 + u8 raw_pwr_cl_52_195; /* 200 */ 98 + u8 raw_pwr_cl_26_195; /* 201 */ 99 + u8 raw_pwr_cl_52_360; /* 202 */ 100 + u8 raw_pwr_cl_26_360; /* 203 */ 101 + u8 raw_s_a_timeout; /* 217 */ 98 102 u8 raw_hc_erase_gap_size; /* 221 */ 99 103 u8 raw_erase_timeout_mult; /* 223 */ 100 104 u8 raw_hc_erase_grp_size; /* 224 */ ··· 106 102 u8 raw_sec_erase_mult; /* 230 */ 107 103 u8 raw_sec_feature_support;/* 231 */ 108 104 u8 raw_trim_mult; /* 232 */ 105 + u8 raw_pwr_cl_200_195; /* 236 */ 106 + u8 raw_pwr_cl_200_360; /* 237 */ 107 + u8 raw_pwr_cl_ddr_52_195; /* 238 */ 108 + u8 raw_pwr_cl_ddr_52_360; /* 239 */ 109 109 u8 raw_bkops_status; /* 246 */ 110 110 u8 raw_sectors[4]; /* 212 - 4 bytes */ 111 111 ··· 520 512 void (*remove)(struct mmc_card *); 521 513 int (*suspend)(struct mmc_card *); 522 514 int (*resume)(struct mmc_card *); 515 + void (*shutdown)(struct mmc_card *); 523 516 }; 524 517 525 518 extern int mmc_register_driver(struct mmc_driver *);
+5
include/linux/mmc/core.h
··· 96 96 */ 97 97 98 98 unsigned int cmd_timeout_ms; /* in milliseconds */ 99 + /* Set this flag only for blocking sanitize request */ 100 + bool sanitize_busy; 99 101 100 102 struct mmc_data *data; /* data segment associated with cmd */ 101 103 struct mmc_request *mrq; /* associated request */ ··· 189 187 extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort); 190 188 extern void mmc_release_host(struct mmc_host *host); 191 189 extern int mmc_try_claim_host(struct mmc_host *host); 190 + 191 + extern void mmc_get_card(struct mmc_card *card); 192 + extern void mmc_put_card(struct mmc_card *card); 192 193 193 194 extern int mmc_flush_cache(struct mmc_card *); 194 195
+4 -8
include/linux/mmc/host.h
··· 239 239 #define MMC_CAP_SPI (1 << 4) /* Talks only SPI protocols */ 240 240 #define MMC_CAP_NEEDS_POLL (1 << 5) /* Needs polling for card-detection */ 241 241 #define MMC_CAP_8_BIT_DATA (1 << 6) /* Can the host do 8 bit transfers */ 242 - 242 + #define MMC_CAP_AGGRESSIVE_PM (1 << 7) /* Suspend (e)MMC/SD at idle */ 243 243 #define MMC_CAP_NONREMOVABLE (1 << 8) /* Nonremovable e.g. eMMC */ 244 244 #define MMC_CAP_WAIT_WHILE_BUSY (1 << 9) /* Waits while card is busy */ 245 245 #define MMC_CAP_ERASE (1 << 10) /* Allow erase/trim commands */ ··· 264 264 265 265 #define MMC_CAP2_BOOTPART_NOACC (1 << 0) /* Boot partition no access */ 266 266 #define MMC_CAP2_CACHE_CTRL (1 << 1) /* Allow cache control */ 267 - #define MMC_CAP2_POWEROFF_NOTIFY (1 << 2) /* Notify poweroff supported */ 267 + #define MMC_CAP2_FULL_PWR_CYCLE (1 << 2) /* Can do full power cycle */ 268 268 #define MMC_CAP2_NO_MULTI_READ (1 << 3) /* Multiblock reads don't work */ 269 269 #define MMC_CAP2_NO_SLEEP_CMD (1 << 4) /* Don't allow sleep command */ 270 270 #define MMC_CAP2_HS200_1_8V_SDR (1 << 5) /* can support */ ··· 272 272 #define MMC_CAP2_HS200 (MMC_CAP2_HS200_1_8V_SDR | \ 273 273 MMC_CAP2_HS200_1_2V_SDR) 274 274 #define MMC_CAP2_BROKEN_VOLTAGE (1 << 7) /* Use the broken voltage */ 275 - #define MMC_CAP2_DETECT_ON_ERR (1 << 8) /* On I/O err check card removal */ 276 275 #define MMC_CAP2_HC_ERASE_SZ (1 << 9) /* High-capacity erase size */ 277 276 #define MMC_CAP2_CD_ACTIVE_HIGH (1 << 10) /* Card-detect signal active high */ 278 277 #define MMC_CAP2_RO_ACTIVE_HIGH (1 << 11) /* Write-protect signal active high */ ··· 280 281 #define MMC_CAP2_PACKED_CMD (MMC_CAP2_PACKED_RD | \ 281 282 MMC_CAP2_PACKED_WR) 282 283 #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */ 284 + #define MMC_CAP2_SANITIZE (1 << 15) /* Support Sanitize */ 283 285 284 286 mmc_pm_flag_t pm_caps; /* supported pm features */ 285 287 ··· 369 369 int mmc_add_host(struct mmc_host *); 370 370 void mmc_remove_host(struct mmc_host *); 371 371 void mmc_free_host(struct mmc_host *); 372 - void mmc_of_parse(struct mmc_host *host); 372 + int mmc_of_parse(struct mmc_host *host); 373 373 374 374 static inline void *mmc_priv(struct mmc_host *host) 375 375 { ··· 424 424 return 0; 425 425 } 426 426 #endif 427 - 428 - int mmc_card_awake(struct mmc_host *host); 429 - int mmc_card_sleep(struct mmc_host *host); 430 - int mmc_card_can_sleep(struct mmc_host *host); 431 427 432 428 int mmc_pm_notify(struct notifier_block *notify_block, unsigned long, void *); 433 429
+5 -1
include/linux/mmc/sdhci.h
··· 95 95 /* The system physically doesn't support 1.8v, even if the host does */ 96 96 #define SDHCI_QUIRK2_NO_1_8_V (1<<2) 97 97 #define SDHCI_QUIRK2_PRESET_VALUE_BROKEN (1<<3) 98 + #define SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON (1<<4) 99 + /* Controller has a non-standard host control register */ 100 + #define SDHCI_QUIRK2_BROKEN_HOST_CONTROL (1<<5) 98 101 99 102 int irq; /* Device IRQ */ 100 103 void __iomem *ioaddr; /* Mapped address */ ··· 129 126 #define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */ 130 127 #define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */ 131 128 #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */ 132 - #define SDHCI_HS200_NEEDS_TUNING (1<<10) /* HS200 needs tuning */ 129 + #define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */ 133 130 #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */ 134 131 135 132 unsigned int version; /* SDHCI spec. version */ ··· 142 139 u8 pwr; /* Current voltage */ 143 140 144 141 bool runtime_suspended; /* Host is runtime suspended */ 142 + bool bus_on; /* Bus power prevents runtime suspend */ 145 143 146 144 struct mmc_request *mrq; /* Current request */ 147 145 struct mmc_command *cmd; /* Current command */
+1
include/linux/platform_data/mmc-esdhc-imx.h
··· 40 40 enum wp_types wp_type; 41 41 enum cd_types cd_type; 42 42 int max_bus_width; 43 + unsigned int f_max; 43 44 }; 44 45 #endif /* __ASM_ARCH_IMX_ESDHC_H */