diff options
Diffstat (limited to 'drivers/mmc')
32 files changed, 1078 insertions, 566 deletions
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index dd2d374dcc7a..f1c84decb192 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c | |||
| @@ -554,7 +554,6 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card) | |||
| 554 | struct mmc_request mrq = {NULL}; | 554 | struct mmc_request mrq = {NULL}; |
| 555 | struct mmc_command cmd = {0}; | 555 | struct mmc_command cmd = {0}; |
| 556 | struct mmc_data data = {0}; | 556 | struct mmc_data data = {0}; |
| 557 | unsigned int timeout_us; | ||
| 558 | 557 | ||
| 559 | struct scatterlist sg; | 558 | struct scatterlist sg; |
| 560 | 559 | ||
| @@ -574,23 +573,12 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card) | |||
| 574 | cmd.arg = 0; | 573 | cmd.arg = 0; |
| 575 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; | 574 | cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; |
| 576 | 575 | ||
| 577 | data.timeout_ns = card->csd.tacc_ns * 100; | ||
| 578 | data.timeout_clks = card->csd.tacc_clks * 100; | ||
| 579 | |||
| 580 | timeout_us = data.timeout_ns / 1000; | ||
| 581 | timeout_us += data.timeout_clks * 1000 / | ||
| 582 | (card->host->ios.clock / 1000); | ||
| 583 | |||
| 584 | if (timeout_us > 100000) { | ||
| 585 | data.timeout_ns = 100000000; | ||
| 586 | data.timeout_clks = 0; | ||
| 587 | } | ||
| 588 | |||
| 589 | data.blksz = 4; | 576 | data.blksz = 4; |
| 590 | data.blocks = 1; | 577 | data.blocks = 1; |
| 591 | data.flags = MMC_DATA_READ; | 578 | data.flags = MMC_DATA_READ; |
| 592 | data.sg = &sg; | 579 | data.sg = &sg; |
| 593 | data.sg_len = 1; | 580 | data.sg_len = 1; |
| 581 | mmc_set_data_timeout(&data, card); | ||
| 594 | 582 | ||
| 595 | mrq.cmd = &cmd; | 583 | mrq.cmd = &cmd; |
| 596 | mrq.data = &data; | 584 | mrq.data = &data; |
| @@ -862,9 +850,7 @@ out: | |||
| 862 | goto retry; | 850 | goto retry; |
| 863 | if (!err) | 851 | if (!err) |
| 864 | mmc_blk_reset_success(md, type); | 852 | mmc_blk_reset_success(md, type); |
| 865 | spin_lock_irq(&md->lock); | 853 | blk_end_request(req, err, blk_rq_bytes(req)); |
| 866 | __blk_end_request(req, err, blk_rq_bytes(req)); | ||
| 867 | spin_unlock_irq(&md->lock); | ||
| 868 | 854 | ||
| 869 | return err ? 0 : 1; | 855 | return err ? 0 : 1; |
| 870 | } | 856 | } |
| @@ -946,9 +932,7 @@ out_retry: | |||
| 946 | if (!err) | 932 | if (!err) |
| 947 | mmc_blk_reset_success(md, type); | 933 | mmc_blk_reset_success(md, type); |
| 948 | out: | 934 | out: |
| 949 | spin_lock_irq(&md->lock); | 935 | blk_end_request(req, err, blk_rq_bytes(req)); |
| 950 | __blk_end_request(req, err, blk_rq_bytes(req)); | ||
| 951 | spin_unlock_irq(&md->lock); | ||
| 952 | 936 | ||
| 953 | return err ? 0 : 1; | 937 | return err ? 0 : 1; |
| 954 | } | 938 | } |
| @@ -963,9 +947,7 @@ static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req) | |||
| 963 | if (ret) | 947 | if (ret) |
| 964 | ret = -EIO; | 948 | ret = -EIO; |
| 965 | 949 | ||
| 966 | spin_lock_irq(&md->lock); | 950 | blk_end_request_all(req, ret); |
| 967 | __blk_end_request_all(req, ret); | ||
| 968 | spin_unlock_irq(&md->lock); | ||
| 969 | 951 | ||
| 970 | return ret ? 0 : 1; | 952 | return ret ? 0 : 1; |
| 971 | } | 953 | } |
| @@ -1264,14 +1246,10 @@ static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card, | |||
| 1264 | 1246 | ||
| 1265 | blocks = mmc_sd_num_wr_blocks(card); | 1247 | blocks = mmc_sd_num_wr_blocks(card); |
| 1266 | if (blocks != (u32)-1) { | 1248 | if (blocks != (u32)-1) { |
| 1267 | spin_lock_irq(&md->lock); | 1249 | ret = blk_end_request(req, 0, blocks << 9); |
| 1268 | ret = __blk_end_request(req, 0, blocks << 9); | ||
| 1269 | spin_unlock_irq(&md->lock); | ||
| 1270 | } | 1250 | } |
| 1271 | } else { | 1251 | } else { |
| 1272 | spin_lock_irq(&md->lock); | 1252 | ret = blk_end_request(req, 0, brq->data.bytes_xfered); |
| 1273 | ret = __blk_end_request(req, 0, brq->data.bytes_xfered); | ||
| 1274 | spin_unlock_irq(&md->lock); | ||
| 1275 | } | 1253 | } |
| 1276 | return ret; | 1254 | return ret; |
| 1277 | } | 1255 | } |
| @@ -1323,10 +1301,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc) | |||
| 1323 | * A block was successfully transferred. | 1301 | * A block was successfully transferred. |
| 1324 | */ | 1302 | */ |
| 1325 | mmc_blk_reset_success(md, type); | 1303 | mmc_blk_reset_success(md, type); |
| 1326 | spin_lock_irq(&md->lock); | 1304 | ret = blk_end_request(req, 0, |
| 1327 | ret = __blk_end_request(req, 0, | ||
| 1328 | brq->data.bytes_xfered); | 1305 | brq->data.bytes_xfered); |
| 1329 | spin_unlock_irq(&md->lock); | ||
| 1330 | /* | 1306 | /* |
| 1331 | * If the blk_end_request function returns non-zero even | 1307 | * If the blk_end_request function returns non-zero even |
| 1332 | * though all data has been transferred and no errors | 1308 | * though all data has been transferred and no errors |
| @@ -1376,10 +1352,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc) | |||
| 1376 | * time, so we only reach here after trying to | 1352 | * time, so we only reach here after trying to |
| 1377 | * read a single sector. | 1353 | * read a single sector. |
| 1378 | */ | 1354 | */ |
| 1379 | spin_lock_irq(&md->lock); | 1355 | ret = blk_end_request(req, -EIO, |
| 1380 | ret = __blk_end_request(req, -EIO, | ||
| 1381 | brq->data.blksz); | 1356 | brq->data.blksz); |
| 1382 | spin_unlock_irq(&md->lock); | ||
| 1383 | if (!ret) | 1357 | if (!ret) |
| 1384 | goto start_new_req; | 1358 | goto start_new_req; |
| 1385 | break; | 1359 | break; |
| @@ -1400,12 +1374,10 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc) | |||
| 1400 | return 1; | 1374 | return 1; |
| 1401 | 1375 | ||
| 1402 | cmd_abort: | 1376 | cmd_abort: |
| 1403 | spin_lock_irq(&md->lock); | ||
| 1404 | if (mmc_card_removed(card)) | 1377 | if (mmc_card_removed(card)) |
| 1405 | req->cmd_flags |= REQ_QUIET; | 1378 | req->cmd_flags |= REQ_QUIET; |
| 1406 | while (ret) | 1379 | while (ret) |
| 1407 | ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req)); | 1380 | ret = blk_end_request(req, -EIO, blk_rq_cur_bytes(req)); |
| 1408 | spin_unlock_irq(&md->lock); | ||
| 1409 | 1381 | ||
| 1410 | start_new_req: | 1382 | start_new_req: |
| 1411 | if (rqc) { | 1383 | if (rqc) { |
| @@ -1429,9 +1401,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) | |||
| 1429 | ret = mmc_blk_part_switch(card, md); | 1401 | ret = mmc_blk_part_switch(card, md); |
| 1430 | if (ret) { | 1402 | if (ret) { |
| 1431 | if (req) { | 1403 | if (req) { |
| 1432 | spin_lock_irq(&md->lock); | 1404 | blk_end_request_all(req, -EIO); |
| 1433 | __blk_end_request_all(req, -EIO); | ||
| 1434 | spin_unlock_irq(&md->lock); | ||
| 1435 | } | 1405 | } |
| 1436 | ret = 0; | 1406 | ret = 0; |
| 1437 | goto out; | 1407 | goto out; |
diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile index dca4428380f1..38ed210ce2f3 100644 --- a/drivers/mmc/core/Makefile +++ b/drivers/mmc/core/Makefile | |||
| @@ -7,6 +7,6 @@ mmc_core-y := core.o bus.o host.o \ | |||
| 7 | mmc.o mmc_ops.o sd.o sd_ops.o \ | 7 | mmc.o mmc_ops.o sd.o sd_ops.o \ |
| 8 | sdio.o sdio_ops.o sdio_bus.o \ | 8 | sdio.o sdio_ops.o sdio_bus.o \ |
| 9 | sdio_cis.o sdio_io.o sdio_irq.o \ | 9 | sdio_cis.o sdio_io.o sdio_irq.o \ |
| 10 | quirks.o cd-gpio.o | 10 | quirks.o slot-gpio.o |
| 11 | 11 | ||
| 12 | mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o | 12 | mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o |
diff --git a/drivers/mmc/core/cd-gpio.c b/drivers/mmc/core/cd-gpio.c deleted file mode 100644 index f13e38deceac..000000000000 --- a/drivers/mmc/core/cd-gpio.c +++ /dev/null | |||
| @@ -1,83 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Generic GPIO card-detect helper | ||
| 3 | * | ||
| 4 | * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@gmx.de> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License version 2 as | ||
| 8 | * published by the Free Software Foundation. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/err.h> | ||
| 12 | #include <linux/gpio.h> | ||
| 13 | #include <linux/interrupt.h> | ||
| 14 | #include <linux/jiffies.h> | ||
| 15 | #include <linux/mmc/cd-gpio.h> | ||
| 16 | #include <linux/mmc/host.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/slab.h> | ||
| 19 | |||
| 20 | struct mmc_cd_gpio { | ||
| 21 | unsigned int gpio; | ||
| 22 | char label[0]; | ||
| 23 | }; | ||
| 24 | |||
| 25 | static irqreturn_t mmc_cd_gpio_irqt(int irq, void *dev_id) | ||
| 26 | { | ||
| 27 | /* Schedule a card detection after a debounce timeout */ | ||
| 28 | mmc_detect_change(dev_id, msecs_to_jiffies(100)); | ||
| 29 | return IRQ_HANDLED; | ||
| 30 | } | ||
| 31 | |||
| 32 | int mmc_cd_gpio_request(struct mmc_host *host, unsigned int gpio) | ||
| 33 | { | ||
| 34 | size_t len = strlen(dev_name(host->parent)) + 4; | ||
| 35 | struct mmc_cd_gpio *cd; | ||
| 36 | int irq = gpio_to_irq(gpio); | ||
| 37 | int ret; | ||
| 38 | |||
| 39 | if (irq < 0) | ||
| 40 | return irq; | ||
| 41 | |||
| 42 | cd = kmalloc(sizeof(*cd) + len, GFP_KERNEL); | ||
| 43 | if (!cd) | ||
| 44 | return -ENOMEM; | ||
| 45 | |||
| 46 | snprintf(cd->label, len, "%s cd", dev_name(host->parent)); | ||
| 47 | |||
| 48 | ret = gpio_request_one(gpio, GPIOF_DIR_IN, cd->label); | ||
| 49 | if (ret < 0) | ||
| 50 | goto egpioreq; | ||
| 51 | |||
| 52 | ret = request_threaded_irq(irq, NULL, mmc_cd_gpio_irqt, | ||
| 53 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, | ||
| 54 | cd->label, host); | ||
| 55 | if (ret < 0) | ||
| 56 | goto eirqreq; | ||
| 57 | |||
| 58 | cd->gpio = gpio; | ||
| 59 | host->hotplug.irq = irq; | ||
| 60 | host->hotplug.handler_priv = cd; | ||
| 61 | |||
| 62 | return 0; | ||
| 63 | |||
| 64 | eirqreq: | ||
| 65 | gpio_free(gpio); | ||
| 66 | egpioreq: | ||
| 67 | kfree(cd); | ||
| 68 | return ret; | ||
| 69 | } | ||
| 70 | EXPORT_SYMBOL(mmc_cd_gpio_request); | ||
| 71 | |||
| 72 | void mmc_cd_gpio_free(struct mmc_host *host) | ||
| 73 | { | ||
| 74 | struct mmc_cd_gpio *cd = host->hotplug.handler_priv; | ||
| 75 | |||
| 76 | if (!cd) | ||
| 77 | return; | ||
| 78 | |||
| 79 | free_irq(host->hotplug.irq, host); | ||
| 80 | gpio_free(cd->gpio); | ||
| 81 | kfree(cd); | ||
| 82 | } | ||
| 83 | EXPORT_SYMBOL(mmc_cd_gpio_free); | ||
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 0b6141d29dbd..8ac5246e2ab2 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c | |||
| @@ -404,6 +404,7 @@ int mmc_interrupt_hpi(struct mmc_card *card) | |||
| 404 | { | 404 | { |
| 405 | int err; | 405 | int err; |
| 406 | u32 status; | 406 | u32 status; |
| 407 | unsigned long prg_wait; | ||
| 407 | 408 | ||
| 408 | BUG_ON(!card); | 409 | BUG_ON(!card); |
| 409 | 410 | ||
| @@ -419,30 +420,38 @@ int mmc_interrupt_hpi(struct mmc_card *card) | |||
| 419 | goto out; | 420 | goto out; |
| 420 | } | 421 | } |
| 421 | 422 | ||
| 422 | /* | 423 | switch (R1_CURRENT_STATE(status)) { |
| 423 | * If the card status is in PRG-state, we can send the HPI command. | 424 | case R1_STATE_IDLE: |
| 424 | */ | 425 | case R1_STATE_READY: |
| 425 | if (R1_CURRENT_STATE(status) == R1_STATE_PRG) { | 426 | case R1_STATE_STBY: |
| 426 | do { | 427 | /* |
| 427 | /* | 428 | * In idle states, HPI is not needed and the caller |
| 428 | * We don't know when the HPI command will finish | 429 | * can issue the next intended command immediately |
| 429 | * processing, so we need to resend HPI until out | 430 | */ |
| 430 | * of prg-state, and keep checking the card status | 431 | goto out; |
| 431 | * with SEND_STATUS. If a timeout error occurs when | 432 | case R1_STATE_PRG: |
| 432 | * sending the HPI command, we are already out of | 433 | break; |
| 433 | * prg-state. | 434 | default: |
| 434 | */ | 435 | /* In all other states, it's illegal to issue HPI */ |
| 435 | err = mmc_send_hpi_cmd(card, &status); | 436 | pr_debug("%s: HPI cannot be sent. Card state=%d\n", |
| 436 | if (err) | 437 | mmc_hostname(card->host), R1_CURRENT_STATE(status)); |
| 437 | pr_debug("%s: abort HPI (%d error)\n", | 438 | err = -EINVAL; |
| 438 | mmc_hostname(card->host), err); | 439 | goto out; |
| 440 | } | ||
| 439 | 441 | ||
| 440 | err = mmc_send_status(card, &status); | 442 | err = mmc_send_hpi_cmd(card, &status); |
| 441 | if (err) | 443 | if (err) |
| 442 | break; | 444 | goto out; |
| 443 | } while (R1_CURRENT_STATE(status) == R1_STATE_PRG); | 445 | |
| 444 | } else | 446 | prg_wait = jiffies + msecs_to_jiffies(card->ext_csd.out_of_int_time); |
| 445 | pr_debug("%s: Left prg-state\n", mmc_hostname(card->host)); | 447 | do { |
| 448 | err = mmc_send_status(card, &status); | ||
| 449 | |||
| 450 | if (!err && R1_CURRENT_STATE(status) == R1_STATE_TRAN) | ||
| 451 | break; | ||
| 452 | if (time_after(jiffies, prg_wait)) | ||
| 453 | err = -ETIMEDOUT; | ||
| 454 | } while (!err); | ||
| 446 | 455 | ||
| 447 | out: | 456 | out: |
| 448 | mmc_release_host(card->host); | 457 | mmc_release_host(card->host); |
| @@ -941,7 +950,7 @@ int mmc_regulator_get_ocrmask(struct regulator *supply) | |||
| 941 | 950 | ||
| 942 | return result; | 951 | return result; |
| 943 | } | 952 | } |
| 944 | EXPORT_SYMBOL(mmc_regulator_get_ocrmask); | 953 | EXPORT_SYMBOL_GPL(mmc_regulator_get_ocrmask); |
| 945 | 954 | ||
| 946 | /** | 955 | /** |
| 947 | * mmc_regulator_set_ocr - set regulator to match host->ios voltage | 956 | * mmc_regulator_set_ocr - set regulator to match host->ios voltage |
| @@ -1011,7 +1020,30 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc, | |||
| 1011 | "could not set regulator OCR (%d)\n", result); | 1020 | "could not set regulator OCR (%d)\n", result); |
| 1012 | return result; | 1021 | return result; |
| 1013 | } | 1022 | } |
| 1014 | EXPORT_SYMBOL(mmc_regulator_set_ocr); | 1023 | EXPORT_SYMBOL_GPL(mmc_regulator_set_ocr); |
| 1024 | |||
| 1025 | int mmc_regulator_get_supply(struct mmc_host *mmc) | ||
| 1026 | { | ||
| 1027 | struct device *dev = mmc_dev(mmc); | ||
| 1028 | struct regulator *supply; | ||
| 1029 | int ret; | ||
| 1030 | |||
| 1031 | supply = devm_regulator_get(dev, "vmmc"); | ||
| 1032 | mmc->supply.vmmc = supply; | ||
| 1033 | mmc->supply.vqmmc = devm_regulator_get(dev, "vqmmc"); | ||
| 1034 | |||
| 1035 | if (IS_ERR(supply)) | ||
| 1036 | return PTR_ERR(supply); | ||
| 1037 | |||
| 1038 | ret = mmc_regulator_get_ocrmask(supply); | ||
| 1039 | if (ret > 0) | ||
| 1040 | mmc->ocr_avail = ret; | ||
| 1041 | else | ||
| 1042 | dev_warn(mmc_dev(mmc), "Failed getting OCR mask: %d\n", ret); | ||
| 1043 | |||
| 1044 | return 0; | ||
| 1045 | } | ||
| 1046 | EXPORT_SYMBOL_GPL(mmc_regulator_get_supply); | ||
| 1015 | 1047 | ||
| 1016 | #endif /* CONFIG_REGULATOR */ | 1048 | #endif /* CONFIG_REGULATOR */ |
| 1017 | 1049 | ||
| @@ -1180,6 +1212,9 @@ static void mmc_power_up(struct mmc_host *host) | |||
| 1180 | host->ios.timing = MMC_TIMING_LEGACY; | 1212 | host->ios.timing = MMC_TIMING_LEGACY; |
| 1181 | mmc_set_ios(host); | 1213 | mmc_set_ios(host); |
| 1182 | 1214 | ||
| 1215 | /* Set signal voltage to 3.3V */ | ||
| 1216 | mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, false); | ||
| 1217 | |||
| 1183 | /* | 1218 | /* |
| 1184 | * This delay should be sufficient to allow the power supply | 1219 | * This delay should be sufficient to allow the power supply |
| 1185 | * to reach the minimum voltage. | 1220 | * to reach the minimum voltage. |
| @@ -1931,9 +1966,6 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq) | |||
| 1931 | */ | 1966 | */ |
| 1932 | mmc_hw_reset_for_init(host); | 1967 | mmc_hw_reset_for_init(host); |
| 1933 | 1968 | ||
| 1934 | /* Initialization should be done at 3.3 V I/O voltage. */ | ||
| 1935 | mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0); | ||
| 1936 | |||
| 1937 | /* | 1969 | /* |
| 1938 | * sdio_reset sends CMD52 to reset card. Since we do not know | 1970 | * sdio_reset sends CMD52 to reset card. Since we do not know |
| 1939 | * if the card is being re-initialized, just send it. CMD52 | 1971 | * if the card is being re-initialized, just send it. CMD52 |
| @@ -2075,6 +2107,7 @@ void mmc_rescan(struct work_struct *work) | |||
| 2075 | void mmc_start_host(struct mmc_host *host) | 2107 | void mmc_start_host(struct mmc_host *host) |
| 2076 | { | 2108 | { |
| 2077 | host->f_init = max(freqs[0], host->f_min); | 2109 | host->f_init = max(freqs[0], host->f_min); |
| 2110 | host->rescan_disable = 0; | ||
| 2078 | mmc_power_up(host); | 2111 | mmc_power_up(host); |
| 2079 | mmc_detect_change(host, 0); | 2112 | mmc_detect_change(host, 0); |
| 2080 | } | 2113 | } |
| @@ -2088,6 +2121,7 @@ void mmc_stop_host(struct mmc_host *host) | |||
| 2088 | spin_unlock_irqrestore(&host->lock, flags); | 2121 | spin_unlock_irqrestore(&host->lock, flags); |
| 2089 | #endif | 2122 | #endif |
| 2090 | 2123 | ||
| 2124 | host->rescan_disable = 1; | ||
| 2091 | cancel_delayed_work_sync(&host->detect); | 2125 | cancel_delayed_work_sync(&host->detect); |
| 2092 | mmc_flush_scheduled_work(); | 2126 | mmc_flush_scheduled_work(); |
| 2093 | 2127 | ||
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index 91c84c7a1829..597f189b4427 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | static void mmc_host_classdev_release(struct device *dev) | 32 | static void mmc_host_classdev_release(struct device *dev) |
| 33 | { | 33 | { |
| 34 | struct mmc_host *host = cls_dev_to_mmc_host(dev); | 34 | struct mmc_host *host = cls_dev_to_mmc_host(dev); |
| 35 | mutex_destroy(&host->slot.lock); | ||
| 35 | kfree(host); | 36 | kfree(host); |
| 36 | } | 37 | } |
| 37 | 38 | ||
| @@ -312,6 +313,8 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) | |||
| 312 | if (!host) | 313 | if (!host) |
| 313 | return NULL; | 314 | return NULL; |
| 314 | 315 | ||
| 316 | /* scanning will be enabled when we're ready */ | ||
| 317 | host->rescan_disable = 1; | ||
| 315 | spin_lock(&mmc_host_lock); | 318 | spin_lock(&mmc_host_lock); |
| 316 | err = idr_get_new(&mmc_host_idr, host, &host->index); | 319 | err = idr_get_new(&mmc_host_idr, host, &host->index); |
| 317 | spin_unlock(&mmc_host_lock); | 320 | spin_unlock(&mmc_host_lock); |
| @@ -327,6 +330,9 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev) | |||
| 327 | 330 | ||
| 328 | mmc_host_clk_init(host); | 331 | mmc_host_clk_init(host); |
| 329 | 332 | ||
| 333 | mutex_init(&host->slot.lock); | ||
| 334 | host->slot.cd_irq = -EINVAL; | ||
| 335 | |||
| 330 | spin_lock_init(&host->lock); | 336 | spin_lock_init(&host->lock); |
| 331 | init_waitqueue_head(&host->wq); | 337 | init_waitqueue_head(&host->wq); |
| 332 | INIT_DELAYED_WORK(&host->detect, mmc_rescan); | 338 | INIT_DELAYED_WORK(&host->detect, mmc_rescan); |
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 2d4a4b746750..396b25891bb9 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c | |||
| @@ -717,10 +717,6 @@ static int mmc_select_powerclass(struct mmc_card *card, | |||
| 717 | card->ext_csd.generic_cmd6_time); | 717 | card->ext_csd.generic_cmd6_time); |
| 718 | } | 718 | } |
| 719 | 719 | ||
| 720 | if (err) | ||
| 721 | pr_err("%s: power class selection for ext_csd_bus_width %d" | ||
| 722 | " failed\n", mmc_hostname(card->host), bus_width); | ||
| 723 | |||
| 724 | return err; | 720 | return err; |
| 725 | } | 721 | } |
| 726 | 722 | ||
| @@ -822,9 +818,6 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
| 822 | if (!mmc_host_is_spi(host)) | 818 | if (!mmc_host_is_spi(host)) |
| 823 | mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); | 819 | mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); |
| 824 | 820 | ||
| 825 | /* Initialization should be done at 3.3 V I/O voltage. */ | ||
| 826 | mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0); | ||
| 827 | |||
| 828 | /* | 821 | /* |
| 829 | * Since we're changing the OCR value, we seem to | 822 | * Since we're changing the OCR value, we seem to |
| 830 | * need to tell some cards to go back to the idle | 823 | * need to tell some cards to go back to the idle |
| @@ -1104,7 +1097,9 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
| 1104 | EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; | 1097 | EXT_CSD_BUS_WIDTH_8 : EXT_CSD_BUS_WIDTH_4; |
| 1105 | err = mmc_select_powerclass(card, ext_csd_bits, ext_csd); | 1098 | err = mmc_select_powerclass(card, ext_csd_bits, ext_csd); |
| 1106 | if (err) | 1099 | if (err) |
| 1107 | goto err; | 1100 | pr_warning("%s: power class selection to bus width %d" |
| 1101 | " failed\n", mmc_hostname(card->host), | ||
| 1102 | 1 << bus_width); | ||
| 1108 | } | 1103 | } |
| 1109 | 1104 | ||
| 1110 | /* | 1105 | /* |
| @@ -1136,7 +1131,10 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
| 1136 | err = mmc_select_powerclass(card, ext_csd_bits[idx][0], | 1131 | err = mmc_select_powerclass(card, ext_csd_bits[idx][0], |
| 1137 | ext_csd); | 1132 | ext_csd); |
| 1138 | if (err) | 1133 | if (err) |
| 1139 | goto err; | 1134 | pr_warning("%s: power class selection to " |
| 1135 | "bus width %d failed\n", | ||
| 1136 | mmc_hostname(card->host), | ||
| 1137 | 1 << bus_width); | ||
| 1140 | 1138 | ||
| 1141 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1139 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
| 1142 | EXT_CSD_BUS_WIDTH, | 1140 | EXT_CSD_BUS_WIDTH, |
| @@ -1164,7 +1162,10 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
| 1164 | err = mmc_select_powerclass(card, ext_csd_bits[idx][1], | 1162 | err = mmc_select_powerclass(card, ext_csd_bits[idx][1], |
| 1165 | ext_csd); | 1163 | ext_csd); |
| 1166 | if (err) | 1164 | if (err) |
| 1167 | goto err; | 1165 | pr_warning("%s: power class selection to " |
| 1166 | "bus width %d ddr %d failed\n", | ||
| 1167 | mmc_hostname(card->host), | ||
| 1168 | 1 << bus_width, ddr); | ||
| 1168 | 1169 | ||
| 1169 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, | 1170 | err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, |
| 1170 | EXT_CSD_BUS_WIDTH, | 1171 | EXT_CSD_BUS_WIDTH, |
| @@ -1326,7 +1327,7 @@ static int mmc_suspend(struct mmc_host *host) | |||
| 1326 | if (!err) | 1327 | if (!err) |
| 1327 | mmc_card_set_sleep(host->card); | 1328 | mmc_card_set_sleep(host->card); |
| 1328 | } else if (!mmc_host_is_spi(host)) | 1329 | } else if (!mmc_host_is_spi(host)) |
| 1329 | mmc_deselect_cards(host); | 1330 | err = mmc_deselect_cards(host); |
| 1330 | host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); | 1331 | host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); |
| 1331 | mmc_release_host(host); | 1332 | mmc_release_host(host); |
| 1332 | 1333 | ||
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 69370f494e05..0ed2cc5f35b6 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c | |||
| @@ -569,7 +569,6 @@ int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status) | |||
| 569 | 569 | ||
| 570 | cmd.opcode = opcode; | 570 | cmd.opcode = opcode; |
| 571 | cmd.arg = card->rca << 16 | 1; | 571 | cmd.arg = card->rca << 16 | 1; |
| 572 | cmd.cmd_timeout_ms = card->ext_csd.out_of_int_time; | ||
| 573 | 572 | ||
| 574 | err = mmc_wait_for_cmd(card->host, &cmd, 0); | 573 | err = mmc_wait_for_cmd(card->host, &cmd, 0); |
| 575 | if (err) { | 574 | if (err) { |
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index c272c6868ecf..74972c241dff 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c | |||
| @@ -244,7 +244,7 @@ static int mmc_read_ssr(struct mmc_card *card) | |||
| 244 | * bitfield positions accordingly. | 244 | * bitfield positions accordingly. |
| 245 | */ | 245 | */ |
| 246 | au = UNSTUFF_BITS(ssr, 428 - 384, 4); | 246 | au = UNSTUFF_BITS(ssr, 428 - 384, 4); |
| 247 | if (au > 0 || au <= 9) { | 247 | if (au > 0 && au <= 9) { |
| 248 | card->ssr.au = 1 << (au + 4); | 248 | card->ssr.au = 1 << (au + 4); |
| 249 | es = UNSTUFF_BITS(ssr, 408 - 384, 16); | 249 | es = UNSTUFF_BITS(ssr, 408 - 384, 16); |
| 250 | et = UNSTUFF_BITS(ssr, 402 - 384, 6); | 250 | et = UNSTUFF_BITS(ssr, 402 - 384, 6); |
| @@ -290,8 +290,12 @@ static int mmc_read_switch(struct mmc_card *card) | |||
| 290 | return -ENOMEM; | 290 | return -ENOMEM; |
| 291 | } | 291 | } |
| 292 | 292 | ||
| 293 | /* Find out the supported Bus Speed Modes. */ | 293 | /* |
| 294 | err = mmc_sd_switch(card, 0, 0, 1, status); | 294 | * Find out the card's support bits with a mode 0 operation. |
| 295 | * The argument does not matter, as the support bits do not | ||
| 296 | * change with the arguments. | ||
| 297 | */ | ||
| 298 | err = mmc_sd_switch(card, 0, 0, 0, status); | ||
| 295 | if (err) { | 299 | if (err) { |
| 296 | /* | 300 | /* |
| 297 | * If the host or the card can't do the switch, | 301 | * If the host or the card can't do the switch, |
| @@ -312,46 +316,8 @@ static int mmc_read_switch(struct mmc_card *card) | |||
| 312 | 316 | ||
| 313 | if (card->scr.sda_spec3) { | 317 | if (card->scr.sda_spec3) { |
| 314 | card->sw_caps.sd3_bus_mode = status[13]; | 318 | card->sw_caps.sd3_bus_mode = status[13]; |
| 315 | 319 | /* Driver Strengths supported by the card */ | |
| 316 | /* Find out Driver Strengths supported by the card */ | ||
| 317 | err = mmc_sd_switch(card, 0, 2, 1, status); | ||
| 318 | if (err) { | ||
| 319 | /* | ||
| 320 | * If the host or the card can't do the switch, | ||
| 321 | * fail more gracefully. | ||
| 322 | */ | ||
| 323 | if (err != -EINVAL && err != -ENOSYS && err != -EFAULT) | ||
| 324 | goto out; | ||
| 325 | |||
| 326 | pr_warning("%s: problem reading " | ||
| 327 | "Driver Strength.\n", | ||
| 328 | mmc_hostname(card->host)); | ||
| 329 | err = 0; | ||
| 330 | |||
| 331 | goto out; | ||
| 332 | } | ||
| 333 | |||
| 334 | card->sw_caps.sd3_drv_type = status[9]; | 320 | card->sw_caps.sd3_drv_type = status[9]; |
| 335 | |||
| 336 | /* Find out Current Limits supported by the card */ | ||
| 337 | err = mmc_sd_switch(card, 0, 3, 1, status); | ||
| 338 | if (err) { | ||
| 339 | /* | ||
| 340 | * If the host or the card can't do the switch, | ||
| 341 | * fail more gracefully. | ||
| 342 | */ | ||
| 343 | if (err != -EINVAL && err != -ENOSYS && err != -EFAULT) | ||
| 344 | goto out; | ||
| 345 | |||
| 346 | pr_warning("%s: problem reading " | ||
| 347 | "Current Limit.\n", | ||
| 348 | mmc_hostname(card->host)); | ||
| 349 | err = 0; | ||
| 350 | |||
| 351 | goto out; | ||
| 352 | } | ||
| 353 | |||
| 354 | card->sw_caps.sd3_curr_limit = status[7]; | ||
| 355 | } | 321 | } |
| 356 | 322 | ||
| 357 | out: | 323 | out: |
| @@ -551,60 +517,80 @@ static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status) | |||
| 551 | return 0; | 517 | return 0; |
| 552 | } | 518 | } |
| 553 | 519 | ||
| 520 | /* Get host's max current setting at its current voltage */ | ||
| 521 | static u32 sd_get_host_max_current(struct mmc_host *host) | ||
| 522 | { | ||
| 523 | u32 voltage, max_current; | ||
| 524 | |||
| 525 | voltage = 1 << host->ios.vdd; | ||
| 526 | switch (voltage) { | ||
| 527 | case MMC_VDD_165_195: | ||
| 528 | max_current = host->max_current_180; | ||
| 529 | break; | ||
| 530 | case MMC_VDD_29_30: | ||
| 531 | case MMC_VDD_30_31: | ||
| 532 | max_current = host->max_current_300; | ||
| 533 | break; | ||
| 534 | case MMC_VDD_32_33: | ||
| 535 | case MMC_VDD_33_34: | ||
| 536 | max_current = host->max_current_330; | ||
| 537 | break; | ||
| 538 | default: | ||
| 539 | max_current = 0; | ||
| 540 | } | ||
| 541 | |||
| 542 | return max_current; | ||
| 543 | } | ||
| 544 | |||
| 554 | static int sd_set_current_limit(struct mmc_card *card, u8 *status) | 545 | static int sd_set_current_limit(struct mmc_card *card, u8 *status) |
| 555 | { | 546 | { |
| 556 | int current_limit = 0; | 547 | int current_limit = SD_SET_CURRENT_NO_CHANGE; |
| 557 | int err; | 548 | int err; |
| 549 | u32 max_current; | ||
| 558 | 550 | ||
| 559 | /* | 551 | /* |
| 560 | * Current limit switch is only defined for SDR50, SDR104, and DDR50 | 552 | * Current limit switch is only defined for SDR50, SDR104, and DDR50 |
| 561 | * bus speed modes. For other bus speed modes, we set the default | 553 | * bus speed modes. For other bus speed modes, we do not change the |
| 562 | * current limit of 200mA. | 554 | * current limit. |
| 563 | */ | 555 | */ |
| 564 | if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) || | 556 | if ((card->sd_bus_speed != UHS_SDR50_BUS_SPEED) && |
| 565 | (card->sd_bus_speed == UHS_SDR104_BUS_SPEED) || | 557 | (card->sd_bus_speed != UHS_SDR104_BUS_SPEED) && |
| 566 | (card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) { | 558 | (card->sd_bus_speed != UHS_DDR50_BUS_SPEED)) |
| 567 | if (card->host->caps & MMC_CAP_MAX_CURRENT_800) { | 559 | return 0; |
| 568 | if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_800) | 560 | |
| 569 | current_limit = SD_SET_CURRENT_LIMIT_800; | 561 | /* |
| 570 | else if (card->sw_caps.sd3_curr_limit & | 562 | * Host has different current capabilities when operating at |
| 571 | SD_MAX_CURRENT_600) | 563 | * different voltages, so find out its max current first. |
| 572 | current_limit = SD_SET_CURRENT_LIMIT_600; | 564 | */ |
| 573 | else if (card->sw_caps.sd3_curr_limit & | 565 | max_current = sd_get_host_max_current(card->host); |
| 574 | SD_MAX_CURRENT_400) | 566 | |
| 575 | current_limit = SD_SET_CURRENT_LIMIT_400; | 567 | /* |
| 576 | else if (card->sw_caps.sd3_curr_limit & | 568 | * We only check host's capability here, if we set a limit that is |
| 577 | SD_MAX_CURRENT_200) | 569 | * higher than the card's maximum current, the card will be using its |
| 578 | current_limit = SD_SET_CURRENT_LIMIT_200; | 570 | * maximum current, e.g. if the card's maximum current is 300ma, and |
| 579 | } else if (card->host->caps & MMC_CAP_MAX_CURRENT_600) { | 571 | * when we set current limit to 200ma, the card will draw 200ma, and |
| 580 | if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_600) | 572 | * when we set current limit to 400/600/800ma, the card will draw its |
| 581 | current_limit = SD_SET_CURRENT_LIMIT_600; | 573 | * maximum 300ma from the host. |
| 582 | else if (card->sw_caps.sd3_curr_limit & | 574 | */ |
| 583 | SD_MAX_CURRENT_400) | 575 | if (max_current >= 800) |
| 584 | current_limit = SD_SET_CURRENT_LIMIT_400; | 576 | current_limit = SD_SET_CURRENT_LIMIT_800; |
| 585 | else if (card->sw_caps.sd3_curr_limit & | 577 | else if (max_current >= 600) |
| 586 | SD_MAX_CURRENT_200) | 578 | current_limit = SD_SET_CURRENT_LIMIT_600; |
| 587 | current_limit = SD_SET_CURRENT_LIMIT_200; | 579 | else if (max_current >= 400) |
| 588 | } else if (card->host->caps & MMC_CAP_MAX_CURRENT_400) { | 580 | current_limit = SD_SET_CURRENT_LIMIT_400; |
| 589 | if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_400) | 581 | else if (max_current >= 200) |
| 590 | current_limit = SD_SET_CURRENT_LIMIT_400; | ||
| 591 | else if (card->sw_caps.sd3_curr_limit & | ||
| 592 | SD_MAX_CURRENT_200) | ||
| 593 | current_limit = SD_SET_CURRENT_LIMIT_200; | ||
| 594 | } else if (card->host->caps & MMC_CAP_MAX_CURRENT_200) { | ||
| 595 | if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_200) | ||
| 596 | current_limit = SD_SET_CURRENT_LIMIT_200; | ||
| 597 | } | ||
| 598 | } else | ||
| 599 | current_limit = SD_SET_CURRENT_LIMIT_200; | 582 | current_limit = SD_SET_CURRENT_LIMIT_200; |
| 600 | 583 | ||
| 601 | err = mmc_sd_switch(card, 1, 3, current_limit, status); | 584 | if (current_limit != SD_SET_CURRENT_NO_CHANGE) { |
| 602 | if (err) | 585 | err = mmc_sd_switch(card, 1, 3, current_limit, status); |
| 603 | return err; | 586 | if (err) |
| 587 | return err; | ||
| 604 | 588 | ||
| 605 | if (((status[15] >> 4) & 0x0F) != current_limit) | 589 | if (((status[15] >> 4) & 0x0F) != current_limit) |
| 606 | pr_warning("%s: Problem setting current limit!\n", | 590 | pr_warning("%s: Problem setting current limit!\n", |
| 607 | mmc_hostname(card->host)); | 591 | mmc_hostname(card->host)); |
| 592 | |||
| 593 | } | ||
| 608 | 594 | ||
| 609 | return 0; | 595 | return 0; |
| 610 | } | 596 | } |
| @@ -726,6 +712,7 @@ struct device_type sd_type = { | |||
| 726 | int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) | 712 | int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) |
| 727 | { | 713 | { |
| 728 | int err; | 714 | int err; |
| 715 | u32 max_current; | ||
| 729 | 716 | ||
| 730 | /* | 717 | /* |
| 731 | * Since we're changing the OCR value, we seem to | 718 | * Since we're changing the OCR value, we seem to |
| @@ -753,9 +740,12 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) | |||
| 753 | MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50)) | 740 | MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50)) |
| 754 | ocr |= SD_OCR_S18R; | 741 | ocr |= SD_OCR_S18R; |
| 755 | 742 | ||
| 756 | /* If the host can supply more than 150mA, XPC should be set to 1. */ | 743 | /* |
| 757 | if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 | | 744 | * If the host can supply more than 150mA at current voltage, |
| 758 | MMC_CAP_SET_XPC_180)) | 745 | * XPC should be set to 1. |
| 746 | */ | ||
| 747 | max_current = sd_get_host_max_current(host); | ||
| 748 | if (max_current > 150) | ||
| 759 | ocr |= SD_OCR_XPC; | 749 | ocr |= SD_OCR_XPC; |
| 760 | 750 | ||
| 761 | try_again: | 751 | try_again: |
| @@ -911,9 +901,6 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, | |||
| 911 | BUG_ON(!host); | 901 | BUG_ON(!host); |
| 912 | WARN_ON(!host->claimed); | 902 | WARN_ON(!host->claimed); |
| 913 | 903 | ||
| 914 | /* The initialization should be done at 3.3 V I/O voltage. */ | ||
| 915 | mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0); | ||
| 916 | |||
| 917 | err = mmc_sd_get_cid(host, ocr, cid, &rocr); | 904 | err = mmc_sd_get_cid(host, ocr, cid, &rocr); |
| 918 | if (err) | 905 | if (err) |
| 919 | return err; | 906 | return err; |
| @@ -1075,16 +1062,18 @@ static void mmc_sd_detect(struct mmc_host *host) | |||
| 1075 | */ | 1062 | */ |
| 1076 | static int mmc_sd_suspend(struct mmc_host *host) | 1063 | static int mmc_sd_suspend(struct mmc_host *host) |
| 1077 | { | 1064 | { |
| 1065 | int err = 0; | ||
| 1066 | |||
| 1078 | BUG_ON(!host); | 1067 | BUG_ON(!host); |
| 1079 | BUG_ON(!host->card); | 1068 | BUG_ON(!host->card); |
| 1080 | 1069 | ||
| 1081 | mmc_claim_host(host); | 1070 | mmc_claim_host(host); |
| 1082 | if (!mmc_host_is_spi(host)) | 1071 | if (!mmc_host_is_spi(host)) |
| 1083 | mmc_deselect_cards(host); | 1072 | err = mmc_deselect_cards(host); |
| 1084 | host->card->state &= ~MMC_STATE_HIGHSPEED; | 1073 | host->card->state &= ~MMC_STATE_HIGHSPEED; |
| 1085 | mmc_release_host(host); | 1074 | mmc_release_host(host); |
| 1086 | 1075 | ||
| 1087 | return 0; | 1076 | return err; |
| 1088 | } | 1077 | } |
| 1089 | 1078 | ||
| 1090 | /* | 1079 | /* |
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index 13d0e95380ab..d4619e2ec030 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c | |||
| @@ -218,6 +218,12 @@ static int sdio_enable_wide(struct mmc_card *card) | |||
| 218 | if (ret) | 218 | if (ret) |
| 219 | return ret; | 219 | return ret; |
| 220 | 220 | ||
| 221 | if ((ctrl & SDIO_BUS_WIDTH_MASK) == SDIO_BUS_WIDTH_RESERVED) | ||
| 222 | pr_warning("%s: SDIO_CCCR_IF is invalid: 0x%02x\n", | ||
| 223 | mmc_hostname(card->host), ctrl); | ||
| 224 | |||
| 225 | /* set as 4-bit bus width */ | ||
| 226 | ctrl &= ~SDIO_BUS_WIDTH_MASK; | ||
| 221 | ctrl |= SDIO_BUS_WIDTH_4BIT; | 227 | ctrl |= SDIO_BUS_WIDTH_4BIT; |
| 222 | 228 | ||
| 223 | ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL); | 229 | ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL); |
| @@ -585,9 +591,6 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, | |||
| 585 | * Inform the card of the voltage | 591 | * Inform the card of the voltage |
| 586 | */ | 592 | */ |
| 587 | if (!powered_resume) { | 593 | if (!powered_resume) { |
| 588 | /* The initialization should be done at 3.3 V I/O voltage. */ | ||
| 589 | mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0); | ||
| 590 | |||
| 591 | err = mmc_send_io_op_cond(host, host->ocr, &ocr); | 594 | err = mmc_send_io_op_cond(host, host->ocr, &ocr); |
| 592 | if (err) | 595 | if (err) |
| 593 | goto err; | 596 | goto err; |
| @@ -1000,10 +1003,6 @@ static int mmc_sdio_power_restore(struct mmc_host *host) | |||
| 1000 | * restore the correct voltage setting of the card. | 1003 | * restore the correct voltage setting of the card. |
| 1001 | */ | 1004 | */ |
| 1002 | 1005 | ||
| 1003 | /* The initialization should be done at 3.3 V I/O voltage. */ | ||
| 1004 | if (!mmc_card_keep_power(host)) | ||
| 1005 | mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0); | ||
| 1006 | |||
| 1007 | sdio_reset(host); | 1006 | sdio_reset(host); |
| 1008 | mmc_go_idle(host); | 1007 | mmc_go_idle(host); |
| 1009 | mmc_send_if_cond(host, host->ocr_avail); | 1008 | mmc_send_if_cond(host, host->ocr_avail); |
diff --git a/drivers/mmc/core/sdio_cis.c b/drivers/mmc/core/sdio_cis.c index f1c7ed8f4d85..8e94e555b788 100644 --- a/drivers/mmc/core/sdio_cis.c +++ b/drivers/mmc/core/sdio_cis.c | |||
| @@ -313,7 +313,7 @@ static int sdio_read_cis(struct mmc_card *card, struct sdio_func *func) | |||
| 313 | 313 | ||
| 314 | if (ret == -ENOENT) { | 314 | if (ret == -ENOENT) { |
| 315 | /* warn about unknown tuples */ | 315 | /* warn about unknown tuples */ |
| 316 | pr_warning("%s: queuing unknown" | 316 | pr_warn_ratelimited("%s: queuing unknown" |
| 317 | " CIS tuple 0x%02x (%u bytes)\n", | 317 | " CIS tuple 0x%02x (%u bytes)\n", |
| 318 | mmc_hostname(card->host), | 318 | mmc_hostname(card->host), |
| 319 | tpl_code, tpl_link); | 319 | tpl_code, tpl_link); |
diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c new file mode 100644 index 000000000000..058242916cef --- /dev/null +++ b/drivers/mmc/core/slot-gpio.c | |||
| @@ -0,0 +1,188 @@ | |||
| 1 | /* | ||
| 2 | * Generic GPIO card-detect helper | ||
| 3 | * | ||
| 4 | * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@gmx.de> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License version 2 as | ||
| 8 | * published by the Free Software Foundation. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/err.h> | ||
| 12 | #include <linux/gpio.h> | ||
| 13 | #include <linux/interrupt.h> | ||
| 14 | #include <linux/jiffies.h> | ||
| 15 | #include <linux/mmc/host.h> | ||
| 16 | #include <linux/mmc/slot-gpio.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/slab.h> | ||
| 19 | |||
| 20 | struct mmc_gpio { | ||
| 21 | int ro_gpio; | ||
| 22 | int cd_gpio; | ||
| 23 | char *ro_label; | ||
| 24 | char cd_label[0]; | ||
| 25 | }; | ||
| 26 | |||
| 27 | static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id) | ||
| 28 | { | ||
| 29 | /* Schedule a card detection after a debounce timeout */ | ||
| 30 | mmc_detect_change(dev_id, msecs_to_jiffies(100)); | ||
| 31 | return IRQ_HANDLED; | ||
| 32 | } | ||
| 33 | |||
| 34 | static int mmc_gpio_alloc(struct mmc_host *host) | ||
| 35 | { | ||
| 36 | size_t len = strlen(dev_name(host->parent)) + 4; | ||
| 37 | struct mmc_gpio *ctx; | ||
| 38 | |||
| 39 | mutex_lock(&host->slot.lock); | ||
| 40 | |||
| 41 | ctx = host->slot.handler_priv; | ||
| 42 | if (!ctx) { | ||
| 43 | /* | ||
| 44 | * devm_kzalloc() can be called after device_initialize(), even | ||
| 45 | * before device_add(), i.e., between mmc_alloc_host() and | ||
| 46 | * mmc_add_host() | ||
| 47 | */ | ||
| 48 | ctx = devm_kzalloc(&host->class_dev, sizeof(*ctx) + 2 * len, | ||
| 49 | GFP_KERNEL); | ||
| 50 | if (ctx) { | ||
| 51 | ctx->ro_label = ctx->cd_label + len; | ||
| 52 | snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent)); | ||
| 53 | snprintf(ctx->ro_label, len, "%s ro", dev_name(host->parent)); | ||
| 54 | ctx->cd_gpio = -EINVAL; | ||
| 55 | ctx->ro_gpio = -EINVAL; | ||
| 56 | host->slot.handler_priv = ctx; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | mutex_unlock(&host->slot.lock); | ||
| 61 | |||
| 62 | return ctx ? 0 : -ENOMEM; | ||
| 63 | } | ||
| 64 | |||
| 65 | int mmc_gpio_get_ro(struct mmc_host *host) | ||
| 66 | { | ||
| 67 | struct mmc_gpio *ctx = host->slot.handler_priv; | ||
| 68 | |||
| 69 | if (!ctx || !gpio_is_valid(ctx->ro_gpio)) | ||
| 70 | return -ENOSYS; | ||
| 71 | |||
| 72 | return !gpio_get_value_cansleep(ctx->ro_gpio) ^ | ||
| 73 | !!(host->caps2 & MMC_CAP2_RO_ACTIVE_HIGH); | ||
| 74 | } | ||
| 75 | EXPORT_SYMBOL(mmc_gpio_get_ro); | ||
| 76 | |||
| 77 | int mmc_gpio_get_cd(struct mmc_host *host) | ||
| 78 | { | ||
| 79 | struct mmc_gpio *ctx = host->slot.handler_priv; | ||
| 80 | |||
| 81 | if (!ctx || !gpio_is_valid(ctx->cd_gpio)) | ||
| 82 | return -ENOSYS; | ||
| 83 | |||
| 84 | return !gpio_get_value_cansleep(ctx->cd_gpio) ^ | ||
| 85 | !!(host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH); | ||
| 86 | } | ||
| 87 | EXPORT_SYMBOL(mmc_gpio_get_cd); | ||
| 88 | |||
| 89 | int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio) | ||
| 90 | { | ||
| 91 | struct mmc_gpio *ctx; | ||
| 92 | int ret; | ||
| 93 | |||
| 94 | if (!gpio_is_valid(gpio)) | ||
| 95 | return -EINVAL; | ||
| 96 | |||
| 97 | ret = mmc_gpio_alloc(host); | ||
| 98 | if (ret < 0) | ||
| 99 | return ret; | ||
| 100 | |||
| 101 | ctx = host->slot.handler_priv; | ||
| 102 | |||
| 103 | return gpio_request_one(gpio, GPIOF_DIR_IN, ctx->ro_label); | ||
| 104 | } | ||
| 105 | EXPORT_SYMBOL(mmc_gpio_request_ro); | ||
| 106 | |||
| 107 | int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio) | ||
| 108 | { | ||
| 109 | struct mmc_gpio *ctx; | ||
| 110 | int irq = gpio_to_irq(gpio); | ||
| 111 | int ret; | ||
| 112 | |||
| 113 | ret = mmc_gpio_alloc(host); | ||
| 114 | if (ret < 0) | ||
| 115 | return ret; | ||
| 116 | |||
| 117 | ctx = host->slot.handler_priv; | ||
| 118 | |||
| 119 | ret = gpio_request_one(gpio, GPIOF_DIR_IN, ctx->cd_label); | ||
| 120 | if (ret < 0) | ||
| 121 | /* | ||
| 122 | * don't bother freeing memory. It might still get used by other | ||
| 123 | * slot functions, in any case it will be freed, when the device | ||
| 124 | * is destroyed. | ||
| 125 | */ | ||
| 126 | return ret; | ||
| 127 | |||
| 128 | /* | ||
| 129 | * Even if gpio_to_irq() returns a valid IRQ number, the platform might | ||
| 130 | * still prefer to poll, e.g., because that IRQ number is already used | ||
| 131 | * by another unit and cannot be shared. | ||
| 132 | */ | ||
| 133 | if (irq >= 0 && host->caps & MMC_CAP_NEEDS_POLL) | ||
| 134 | irq = -EINVAL; | ||
| 135 | |||
| 136 | if (irq >= 0) { | ||
| 137 | ret = request_threaded_irq(irq, NULL, mmc_gpio_cd_irqt, | ||
| 138 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, | ||
| 139 | ctx->cd_label, host); | ||
| 140 | if (ret < 0) | ||
| 141 | irq = ret; | ||
| 142 | } | ||
| 143 | |||
| 144 | host->slot.cd_irq = irq; | ||
| 145 | |||
| 146 | if (irq < 0) | ||
| 147 | host->caps |= MMC_CAP_NEEDS_POLL; | ||
| 148 | |||
| 149 | ctx->cd_gpio = gpio; | ||
| 150 | |||
| 151 | return 0; | ||
| 152 | } | ||
| 153 | EXPORT_SYMBOL(mmc_gpio_request_cd); | ||
| 154 | |||
| 155 | void mmc_gpio_free_ro(struct mmc_host *host) | ||
| 156 | { | ||
| 157 | struct mmc_gpio *ctx = host->slot.handler_priv; | ||
| 158 | int gpio; | ||
| 159 | |||
| 160 | if (!ctx || !gpio_is_valid(ctx->ro_gpio)) | ||
| 161 | return; | ||
| 162 | |||
| 163 | gpio = ctx->ro_gpio; | ||
| 164 | ctx->ro_gpio = -EINVAL; | ||
| 165 | |||
| 166 | gpio_free(gpio); | ||
| 167 | } | ||
| 168 | EXPORT_SYMBOL(mmc_gpio_free_ro); | ||
| 169 | |||
| 170 | void mmc_gpio_free_cd(struct mmc_host *host) | ||
| 171 | { | ||
| 172 | struct mmc_gpio *ctx = host->slot.handler_priv; | ||
| 173 | int gpio; | ||
| 174 | |||
| 175 | if (!ctx || !gpio_is_valid(ctx->cd_gpio)) | ||
| 176 | return; | ||
| 177 | |||
| 178 | if (host->slot.cd_irq >= 0) { | ||
| 179 | free_irq(host->slot.cd_irq, host); | ||
| 180 | host->slot.cd_irq = -EINVAL; | ||
| 181 | } | ||
| 182 | |||
| 183 | gpio = ctx->cd_gpio; | ||
| 184 | ctx->cd_gpio = -EINVAL; | ||
| 185 | |||
| 186 | gpio_free(gpio); | ||
| 187 | } | ||
| 188 | EXPORT_SYMBOL(mmc_gpio_free_cd); | ||
diff --git a/drivers/mmc/host/atmel-mci-regs.h b/drivers/mmc/host/atmel-mci-regs.h index 787aba1682bb..ab56f7db5315 100644 --- a/drivers/mmc/host/atmel-mci-regs.h +++ b/drivers/mmc/host/atmel-mci-regs.h | |||
| @@ -140,4 +140,18 @@ | |||
| 140 | #define atmci_writel(port,reg,value) \ | 140 | #define atmci_writel(port,reg,value) \ |
| 141 | __raw_writel((value), (port)->regs + reg) | 141 | __raw_writel((value), (port)->regs + reg) |
| 142 | 142 | ||
| 143 | /* | ||
| 144 | * Fix sconfig's burst size according to atmel MCI. We need to convert them as: | ||
| 145 | * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3. | ||
| 146 | * | ||
| 147 | * This can be done by finding most significant bit set. | ||
| 148 | */ | ||
| 149 | static inline unsigned int atmci_convert_chksize(unsigned int maxburst) | ||
| 150 | { | ||
| 151 | if (maxburst > 1) | ||
| 152 | return fls(maxburst) - 2; | ||
| 153 | else | ||
| 154 | return 0; | ||
| 155 | } | ||
| 156 | |||
| 143 | #endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */ | 157 | #endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */ |
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c index 420aca642b14..322412cec4ee 100644 --- a/drivers/mmc/host/atmel-mci.c +++ b/drivers/mmc/host/atmel-mci.c | |||
| @@ -391,11 +391,17 @@ static int atmci_regs_show(struct seq_file *s, void *v) | |||
| 391 | clk_disable(host->mck); | 391 | clk_disable(host->mck); |
| 392 | spin_unlock_bh(&host->lock); | 392 | spin_unlock_bh(&host->lock); |
| 393 | 393 | ||
| 394 | seq_printf(s, "MR:\t0x%08x%s%s CLKDIV=%u\n", | 394 | seq_printf(s, "MR:\t0x%08x%s%s ", |
| 395 | buf[ATMCI_MR / 4], | 395 | buf[ATMCI_MR / 4], |
| 396 | buf[ATMCI_MR / 4] & ATMCI_MR_RDPROOF ? " RDPROOF" : "", | 396 | buf[ATMCI_MR / 4] & ATMCI_MR_RDPROOF ? " RDPROOF" : "", |
| 397 | buf[ATMCI_MR / 4] & ATMCI_MR_WRPROOF ? " WRPROOF" : "", | 397 | buf[ATMCI_MR / 4] & ATMCI_MR_WRPROOF ? " WRPROOF" : ""); |
| 398 | buf[ATMCI_MR / 4] & 0xff); | 398 | if (host->caps.has_odd_clk_div) |
| 399 | seq_printf(s, "{CLKDIV,CLKODD}=%u\n", | ||
| 400 | ((buf[ATMCI_MR / 4] & 0xff) << 1) | ||
| 401 | | ((buf[ATMCI_MR / 4] >> 16) & 1)); | ||
| 402 | else | ||
| 403 | seq_printf(s, "CLKDIV=%u\n", | ||
| 404 | (buf[ATMCI_MR / 4] & 0xff)); | ||
| 399 | seq_printf(s, "DTOR:\t0x%08x\n", buf[ATMCI_DTOR / 4]); | 405 | seq_printf(s, "DTOR:\t0x%08x\n", buf[ATMCI_DTOR / 4]); |
| 400 | seq_printf(s, "SDCR:\t0x%08x\n", buf[ATMCI_SDCR / 4]); | 406 | seq_printf(s, "SDCR:\t0x%08x\n", buf[ATMCI_SDCR / 4]); |
| 401 | seq_printf(s, "ARGR:\t0x%08x\n", buf[ATMCI_ARGR / 4]); | 407 | seq_printf(s, "ARGR:\t0x%08x\n", buf[ATMCI_ARGR / 4]); |
| @@ -910,6 +916,7 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data) | |||
| 910 | enum dma_data_direction direction; | 916 | enum dma_data_direction direction; |
| 911 | enum dma_transfer_direction slave_dirn; | 917 | enum dma_transfer_direction slave_dirn; |
| 912 | unsigned int sglen; | 918 | unsigned int sglen; |
| 919 | u32 maxburst; | ||
| 913 | u32 iflags; | 920 | u32 iflags; |
| 914 | 921 | ||
| 915 | data->error = -EINPROGRESS; | 922 | data->error = -EINPROGRESS; |
| @@ -943,17 +950,18 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data) | |||
| 943 | if (!chan) | 950 | if (!chan) |
| 944 | return -ENODEV; | 951 | return -ENODEV; |
| 945 | 952 | ||
| 946 | if (host->caps.has_dma) | ||
| 947 | atmci_writel(host, ATMCI_DMA, ATMCI_DMA_CHKSIZE(3) | ATMCI_DMAEN); | ||
| 948 | |||
| 949 | if (data->flags & MMC_DATA_READ) { | 953 | if (data->flags & MMC_DATA_READ) { |
| 950 | direction = DMA_FROM_DEVICE; | 954 | direction = DMA_FROM_DEVICE; |
| 951 | host->dma_conf.direction = slave_dirn = DMA_DEV_TO_MEM; | 955 | host->dma_conf.direction = slave_dirn = DMA_DEV_TO_MEM; |
| 956 | maxburst = atmci_convert_chksize(host->dma_conf.src_maxburst); | ||
| 952 | } else { | 957 | } else { |
| 953 | direction = DMA_TO_DEVICE; | 958 | direction = DMA_TO_DEVICE; |
| 954 | host->dma_conf.direction = slave_dirn = DMA_MEM_TO_DEV; | 959 | host->dma_conf.direction = slave_dirn = DMA_MEM_TO_DEV; |
| 960 | maxburst = atmci_convert_chksize(host->dma_conf.dst_maxburst); | ||
| 955 | } | 961 | } |
| 956 | 962 | ||
| 963 | atmci_writel(host, ATMCI_DMA, ATMCI_DMA_CHKSIZE(maxburst) | ATMCI_DMAEN); | ||
| 964 | |||
| 957 | sglen = dma_map_sg(chan->device->dev, data->sg, | 965 | sglen = dma_map_sg(chan->device->dev, data->sg, |
| 958 | data->sg_len, direction); | 966 | data->sg_len, direction); |
| 959 | 967 | ||
| @@ -1683,7 +1691,6 @@ static void atmci_tasklet_func(unsigned long priv) | |||
| 1683 | 1691 | ||
| 1684 | dev_dbg(&host->pdev->dev, "FSM: cmd ready\n"); | 1692 | dev_dbg(&host->pdev->dev, "FSM: cmd ready\n"); |
| 1685 | host->cmd = NULL; | 1693 | host->cmd = NULL; |
| 1686 | host->data = NULL; | ||
| 1687 | data->bytes_xfered = data->blocks * data->blksz; | 1694 | data->bytes_xfered = data->blocks * data->blksz; |
| 1688 | data->error = 0; | 1695 | data->error = 0; |
| 1689 | atmci_command_complete(host, mrq->stop); | 1696 | atmci_command_complete(host, mrq->stop); |
| @@ -1697,6 +1704,7 @@ static void atmci_tasklet_func(unsigned long priv) | |||
| 1697 | atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); | 1704 | atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); |
| 1698 | state = STATE_WAITING_NOTBUSY; | 1705 | state = STATE_WAITING_NOTBUSY; |
| 1699 | } | 1706 | } |
| 1707 | host->data = NULL; | ||
| 1700 | break; | 1708 | break; |
| 1701 | 1709 | ||
| 1702 | case STATE_END_REQUEST: | 1710 | case STATE_END_REQUEST: |
| @@ -2314,6 +2322,8 @@ static int __init atmci_probe(struct platform_device *pdev) | |||
| 2314 | 2322 | ||
| 2315 | platform_set_drvdata(pdev, host); | 2323 | platform_set_drvdata(pdev, host); |
| 2316 | 2324 | ||
| 2325 | setup_timer(&host->timer, atmci_timeout_timer, (unsigned long)host); | ||
| 2326 | |||
| 2317 | /* We need at least one slot to succeed */ | 2327 | /* We need at least one slot to succeed */ |
| 2318 | nr_slots = 0; | 2328 | nr_slots = 0; |
| 2319 | ret = -ENODEV; | 2329 | ret = -ENODEV; |
| @@ -2352,8 +2362,6 @@ static int __init atmci_probe(struct platform_device *pdev) | |||
| 2352 | } | 2362 | } |
| 2353 | } | 2363 | } |
| 2354 | 2364 | ||
| 2355 | setup_timer(&host->timer, atmci_timeout_timer, (unsigned long)host); | ||
| 2356 | |||
| 2357 | dev_info(&pdev->dev, | 2365 | dev_info(&pdev->dev, |
| 2358 | "Atmel MCI controller at 0x%08lx irq %d, %u slots\n", | 2366 | "Atmel MCI controller at 0x%08lx irq %d, %u slots\n", |
| 2359 | host->mapbase, irq, nr_slots); | 2367 | host->mapbase, irq, nr_slots); |
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 9bbf45f8c538..72dc3cde646d 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c | |||
| @@ -405,11 +405,23 @@ static void dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len) | |||
| 405 | static int dw_mci_idmac_init(struct dw_mci *host) | 405 | static int dw_mci_idmac_init(struct dw_mci *host) |
| 406 | { | 406 | { |
| 407 | struct idmac_desc *p; | 407 | struct idmac_desc *p; |
| 408 | int i; | 408 | int i, dma_support; |
| 409 | 409 | ||
| 410 | /* Number of descriptors in the ring buffer */ | 410 | /* Number of descriptors in the ring buffer */ |
| 411 | host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc); | 411 | host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc); |
| 412 | 412 | ||
| 413 | /* Check if Hardware Configuration Register has support for DMA */ | ||
| 414 | dma_support = (mci_readl(host, HCON) >> 16) & 0x3; | ||
| 415 | |||
| 416 | if (!dma_support || dma_support > 2) { | ||
| 417 | dev_err(&host->dev, | ||
| 418 | "Host Controller does not support IDMA Tx.\n"); | ||
| 419 | host->dma_ops = NULL; | ||
| 420 | return -ENODEV; | ||
| 421 | } | ||
| 422 | |||
| 423 | dev_info(&host->dev, "Using internal DMA controller.\n"); | ||
| 424 | |||
| 413 | /* Forward link the descriptor list */ | 425 | /* Forward link the descriptor list */ |
| 414 | for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++) | 426 | for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++) |
| 415 | p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * (i + 1)); | 427 | p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * (i + 1)); |
| @@ -418,6 +430,8 @@ static int dw_mci_idmac_init(struct dw_mci *host) | |||
| 418 | p->des3 = host->sg_dma; | 430 | p->des3 = host->sg_dma; |
| 419 | p->des0 = IDMAC_DES0_ER; | 431 | p->des0 = IDMAC_DES0_ER; |
| 420 | 432 | ||
| 433 | mci_writel(host, BMOD, SDMMC_IDMAC_SWRESET); | ||
| 434 | |||
| 421 | /* Mask out interrupts - get Tx & Rx complete only */ | 435 | /* Mask out interrupts - get Tx & Rx complete only */ |
| 422 | mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI | SDMMC_IDMAC_INT_RI | | 436 | mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI | SDMMC_IDMAC_INT_RI | |
| 423 | SDMMC_IDMAC_INT_TI); | 437 | SDMMC_IDMAC_INT_TI); |
| @@ -615,14 +629,15 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot) | |||
| 615 | u32 div; | 629 | u32 div; |
| 616 | 630 | ||
| 617 | if (slot->clock != host->current_speed) { | 631 | if (slot->clock != host->current_speed) { |
| 618 | if (host->bus_hz % slot->clock) | 632 | div = host->bus_hz / slot->clock; |
| 633 | if (host->bus_hz % slot->clock && host->bus_hz > slot->clock) | ||
| 619 | /* | 634 | /* |
| 620 | * move the + 1 after the divide to prevent | 635 | * move the + 1 after the divide to prevent |
| 621 | * over-clocking the card. | 636 | * over-clocking the card. |
| 622 | */ | 637 | */ |
| 623 | div = ((host->bus_hz / slot->clock) >> 1) + 1; | 638 | div += 1; |
| 624 | else | 639 | |
| 625 | div = (host->bus_hz / slot->clock) >> 1; | 640 | div = (host->bus_hz != slot->clock) ? DIV_ROUND_UP(div, 2) : 0; |
| 626 | 641 | ||
| 627 | dev_info(&slot->mmc->class_dev, | 642 | dev_info(&slot->mmc->class_dev, |
| 628 | "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ" | 643 | "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ" |
| @@ -939,8 +954,8 @@ static void dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd | |||
| 939 | mdelay(20); | 954 | mdelay(20); |
| 940 | 955 | ||
| 941 | if (cmd->data) { | 956 | if (cmd->data) { |
| 942 | host->data = NULL; | ||
| 943 | dw_mci_stop_dma(host); | 957 | dw_mci_stop_dma(host); |
| 958 | host->data = NULL; | ||
| 944 | } | 959 | } |
| 945 | } | 960 | } |
| 946 | } | 961 | } |
| @@ -1623,7 +1638,6 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id) | |||
| 1623 | if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) { | 1638 | if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) { |
| 1624 | mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI); | 1639 | mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI); |
| 1625 | mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI); | 1640 | mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI); |
| 1626 | set_bit(EVENT_DATA_COMPLETE, &host->pending_events); | ||
| 1627 | host->dma_ops->complete(host); | 1641 | host->dma_ops->complete(host); |
| 1628 | } | 1642 | } |
| 1629 | #endif | 1643 | #endif |
| @@ -1725,7 +1739,8 @@ static void dw_mci_work_routine_card(struct work_struct *work) | |||
| 1725 | 1739 | ||
| 1726 | #ifdef CONFIG_MMC_DW_IDMAC | 1740 | #ifdef CONFIG_MMC_DW_IDMAC |
| 1727 | ctrl = mci_readl(host, BMOD); | 1741 | ctrl = mci_readl(host, BMOD); |
| 1728 | ctrl |= 0x01; /* Software reset of DMA */ | 1742 | /* Software reset of DMA */ |
| 1743 | ctrl |= SDMMC_IDMAC_SWRESET; | ||
| 1729 | mci_writel(host, BMOD, ctrl); | 1744 | mci_writel(host, BMOD, ctrl); |
| 1730 | #endif | 1745 | #endif |
| 1731 | 1746 | ||
| @@ -1873,7 +1888,6 @@ static void dw_mci_init_dma(struct dw_mci *host) | |||
| 1873 | /* Determine which DMA interface to use */ | 1888 | /* Determine which DMA interface to use */ |
| 1874 | #ifdef CONFIG_MMC_DW_IDMAC | 1889 | #ifdef CONFIG_MMC_DW_IDMAC |
| 1875 | host->dma_ops = &dw_mci_idmac_ops; | 1890 | host->dma_ops = &dw_mci_idmac_ops; |
| 1876 | dev_info(&host->dev, "Using internal DMA controller.\n"); | ||
| 1877 | #endif | 1891 | #endif |
| 1878 | 1892 | ||
| 1879 | if (!host->dma_ops) | 1893 | if (!host->dma_ops) |
| @@ -1950,10 +1964,6 @@ int dw_mci_probe(struct dw_mci *host) | |||
| 1950 | spin_lock_init(&host->lock); | 1964 | spin_lock_init(&host->lock); |
| 1951 | INIT_LIST_HEAD(&host->queue); | 1965 | INIT_LIST_HEAD(&host->queue); |
| 1952 | 1966 | ||
| 1953 | |||
| 1954 | host->dma_ops = host->pdata->dma_ops; | ||
| 1955 | dw_mci_init_dma(host); | ||
| 1956 | |||
| 1957 | /* | 1967 | /* |
| 1958 | * Get the host data width - this assumes that HCON has been set with | 1968 | * Get the host data width - this assumes that HCON has been set with |
| 1959 | * the correct values. | 1969 | * the correct values. |
| @@ -1981,10 +1991,11 @@ int dw_mci_probe(struct dw_mci *host) | |||
| 1981 | } | 1991 | } |
| 1982 | 1992 | ||
| 1983 | /* Reset all blocks */ | 1993 | /* Reset all blocks */ |
| 1984 | if (!mci_wait_reset(&host->dev, host)) { | 1994 | if (!mci_wait_reset(&host->dev, host)) |
| 1985 | ret = -ENODEV; | 1995 | return -ENODEV; |
| 1986 | goto err_dmaunmap; | 1996 | |
| 1987 | } | 1997 | host->dma_ops = host->pdata->dma_ops; |
| 1998 | dw_mci_init_dma(host); | ||
| 1988 | 1999 | ||
| 1989 | /* Clear the interrupts for the host controller */ | 2000 | /* Clear the interrupts for the host controller */ |
| 1990 | mci_writel(host, RINTSTS, 0xFFFFFFFF); | 2001 | mci_writel(host, RINTSTS, 0xFFFFFFFF); |
| @@ -2170,14 +2181,14 @@ int dw_mci_resume(struct dw_mci *host) | |||
| 2170 | if (host->vmmc) | 2181 | if (host->vmmc) |
| 2171 | regulator_enable(host->vmmc); | 2182 | regulator_enable(host->vmmc); |
| 2172 | 2183 | ||
| 2173 | if (host->dma_ops->init) | ||
| 2174 | host->dma_ops->init(host); | ||
| 2175 | |||
| 2176 | if (!mci_wait_reset(&host->dev, host)) { | 2184 | if (!mci_wait_reset(&host->dev, host)) { |
| 2177 | ret = -ENODEV; | 2185 | ret = -ENODEV; |
| 2178 | return ret; | 2186 | return ret; |
| 2179 | } | 2187 | } |
| 2180 | 2188 | ||
| 2189 | if (host->use_dma && host->dma_ops->init) | ||
| 2190 | host->dma_ops->init(host); | ||
| 2191 | |||
| 2181 | /* Restore the old value at FIFOTH register */ | 2192 | /* Restore the old value at FIFOTH register */ |
| 2182 | mci_writel(host, FIFOTH, host->fifoth_val); | 2193 | mci_writel(host, FIFOTH, host->fifoth_val); |
| 2183 | 2194 | ||
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index f0fcce40cd8d..50ff19a62368 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c | |||
| @@ -1216,12 +1216,7 @@ static void mmci_dt_populate_generic_pdata(struct device_node *np, | |||
| 1216 | int bus_width = 0; | 1216 | int bus_width = 0; |
| 1217 | 1217 | ||
| 1218 | pdata->gpio_wp = of_get_named_gpio(np, "wp-gpios", 0); | 1218 | pdata->gpio_wp = of_get_named_gpio(np, "wp-gpios", 0); |
| 1219 | if (!pdata->gpio_wp) | ||
| 1220 | pdata->gpio_wp = -1; | ||
| 1221 | |||
| 1222 | pdata->gpio_cd = of_get_named_gpio(np, "cd-gpios", 0); | 1219 | pdata->gpio_cd = of_get_named_gpio(np, "cd-gpios", 0); |
| 1223 | if (!pdata->gpio_cd) | ||
| 1224 | pdata->gpio_cd = -1; | ||
| 1225 | 1220 | ||
| 1226 | if (of_get_property(np, "cd-inverted", NULL)) | 1221 | if (of_get_property(np, "cd-inverted", NULL)) |
| 1227 | pdata->cd_invert = true; | 1222 | pdata->cd_invert = true; |
| @@ -1276,6 +1271,12 @@ static int __devinit mmci_probe(struct amba_device *dev, | |||
| 1276 | return -EINVAL; | 1271 | return -EINVAL; |
| 1277 | } | 1272 | } |
| 1278 | 1273 | ||
| 1274 | if (!plat) { | ||
| 1275 | plat = devm_kzalloc(&dev->dev, sizeof(*plat), GFP_KERNEL); | ||
| 1276 | if (!plat) | ||
| 1277 | return -ENOMEM; | ||
| 1278 | } | ||
| 1279 | |||
| 1279 | if (np) | 1280 | if (np) |
| 1280 | mmci_dt_populate_generic_pdata(np, plat); | 1281 | mmci_dt_populate_generic_pdata(np, plat); |
| 1281 | 1282 | ||
| @@ -1424,6 +1425,10 @@ static int __devinit mmci_probe(struct amba_device *dev, | |||
| 1424 | writel(0, host->base + MMCIMASK1); | 1425 | writel(0, host->base + MMCIMASK1); |
| 1425 | writel(0xfff, host->base + MMCICLEAR); | 1426 | writel(0xfff, host->base + MMCICLEAR); |
| 1426 | 1427 | ||
| 1428 | if (plat->gpio_cd == -EPROBE_DEFER) { | ||
| 1429 | ret = -EPROBE_DEFER; | ||
| 1430 | goto err_gpio_cd; | ||
| 1431 | } | ||
| 1427 | if (gpio_is_valid(plat->gpio_cd)) { | 1432 | if (gpio_is_valid(plat->gpio_cd)) { |
| 1428 | ret = gpio_request(plat->gpio_cd, DRIVER_NAME " (cd)"); | 1433 | ret = gpio_request(plat->gpio_cd, DRIVER_NAME " (cd)"); |
| 1429 | if (ret == 0) | 1434 | if (ret == 0) |
| @@ -1447,6 +1452,10 @@ static int __devinit mmci_probe(struct amba_device *dev, | |||
| 1447 | if (ret >= 0) | 1452 | if (ret >= 0) |
| 1448 | host->gpio_cd_irq = gpio_to_irq(plat->gpio_cd); | 1453 | host->gpio_cd_irq = gpio_to_irq(plat->gpio_cd); |
| 1449 | } | 1454 | } |
| 1455 | if (plat->gpio_wp == -EPROBE_DEFER) { | ||
| 1456 | ret = -EPROBE_DEFER; | ||
| 1457 | goto err_gpio_wp; | ||
| 1458 | } | ||
| 1450 | if (gpio_is_valid(plat->gpio_wp)) { | 1459 | if (gpio_is_valid(plat->gpio_wp)) { |
| 1451 | ret = gpio_request(plat->gpio_wp, DRIVER_NAME " (wp)"); | 1460 | ret = gpio_request(plat->gpio_wp, DRIVER_NAME " (wp)"); |
| 1452 | if (ret == 0) | 1461 | if (ret == 0) |
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c index 34a90266ab11..a51f9309ffbb 100644 --- a/drivers/mmc/host/mxs-mmc.c +++ b/drivers/mmc/host/mxs-mmc.c | |||
| @@ -164,16 +164,23 @@ struct mxs_mmc_host { | |||
| 164 | spinlock_t lock; | 164 | spinlock_t lock; |
| 165 | int sdio_irq_en; | 165 | int sdio_irq_en; |
| 166 | int wp_gpio; | 166 | int wp_gpio; |
| 167 | bool wp_inverted; | ||
| 167 | }; | 168 | }; |
| 168 | 169 | ||
| 169 | static int mxs_mmc_get_ro(struct mmc_host *mmc) | 170 | static int mxs_mmc_get_ro(struct mmc_host *mmc) |
| 170 | { | 171 | { |
| 171 | struct mxs_mmc_host *host = mmc_priv(mmc); | 172 | struct mxs_mmc_host *host = mmc_priv(mmc); |
| 173 | int ret; | ||
| 172 | 174 | ||
| 173 | if (!gpio_is_valid(host->wp_gpio)) | 175 | if (!gpio_is_valid(host->wp_gpio)) |
| 174 | return -EINVAL; | 176 | return -EINVAL; |
| 175 | 177 | ||
| 176 | return gpio_get_value(host->wp_gpio); | 178 | ret = gpio_get_value(host->wp_gpio); |
| 179 | |||
| 180 | if (host->wp_inverted) | ||
| 181 | ret = !ret; | ||
| 182 | |||
| 183 | return ret; | ||
| 177 | } | 184 | } |
| 178 | 185 | ||
| 179 | static int mxs_mmc_get_cd(struct mmc_host *mmc) | 186 | static int mxs_mmc_get_cd(struct mmc_host *mmc) |
| @@ -707,6 +714,8 @@ static int mxs_mmc_probe(struct platform_device *pdev) | |||
| 707 | struct pinctrl *pinctrl; | 714 | struct pinctrl *pinctrl; |
| 708 | int ret = 0, irq_err, irq_dma; | 715 | int ret = 0, irq_err, irq_dma; |
| 709 | dma_cap_mask_t mask; | 716 | dma_cap_mask_t mask; |
| 717 | struct regulator *reg_vmmc; | ||
| 718 | enum of_gpio_flags flags; | ||
| 710 | 719 | ||
| 711 | iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 720 | iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 712 | dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); | 721 | dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
| @@ -747,6 +756,16 @@ static int mxs_mmc_probe(struct platform_device *pdev) | |||
| 747 | host->mmc = mmc; | 756 | host->mmc = mmc; |
| 748 | host->sdio_irq_en = 0; | 757 | host->sdio_irq_en = 0; |
| 749 | 758 | ||
| 759 | reg_vmmc = devm_regulator_get(&pdev->dev, "vmmc"); | ||
| 760 | if (!IS_ERR(reg_vmmc)) { | ||
| 761 | ret = regulator_enable(reg_vmmc); | ||
| 762 | if (ret) { | ||
| 763 | dev_err(&pdev->dev, | ||
| 764 | "Failed to enable vmmc regulator: %d\n", ret); | ||
| 765 | goto out_mmc_free; | ||
| 766 | } | ||
| 767 | } | ||
| 768 | |||
| 750 | pinctrl = devm_pinctrl_get_select_default(&pdev->dev); | 769 | pinctrl = devm_pinctrl_get_select_default(&pdev->dev); |
| 751 | if (IS_ERR(pinctrl)) { | 770 | if (IS_ERR(pinctrl)) { |
| 752 | ret = PTR_ERR(pinctrl); | 771 | ret = PTR_ERR(pinctrl); |
| @@ -785,7 +804,10 @@ static int mxs_mmc_probe(struct platform_device *pdev) | |||
| 785 | mmc->caps |= MMC_CAP_4_BIT_DATA; | 804 | mmc->caps |= MMC_CAP_4_BIT_DATA; |
| 786 | else if (bus_width == 8) | 805 | else if (bus_width == 8) |
| 787 | mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA; | 806 | mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA; |
| 788 | host->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0); | 807 | host->wp_gpio = of_get_named_gpio_flags(np, "wp-gpios", 0, |
| 808 | &flags); | ||
| 809 | if (flags & OF_GPIO_ACTIVE_LOW) | ||
| 810 | host->wp_inverted = 1; | ||
| 789 | } else { | 811 | } else { |
| 790 | if (pdata->flags & SLOTF_8_BIT_CAPABLE) | 812 | if (pdata->flags & SLOTF_8_BIT_CAPABLE) |
| 791 | mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA; | 813 | mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA; |
| @@ -894,8 +916,8 @@ static struct platform_driver mxs_mmc_driver = { | |||
| 894 | .owner = THIS_MODULE, | 916 | .owner = THIS_MODULE, |
| 895 | #ifdef CONFIG_PM | 917 | #ifdef CONFIG_PM |
| 896 | .pm = &mxs_mmc_pm_ops, | 918 | .pm = &mxs_mmc_pm_ops, |
| 897 | .of_match_table = mxs_mmc_dt_ids, | ||
| 898 | #endif | 919 | #endif |
| 920 | .of_match_table = mxs_mmc_dt_ids, | ||
| 899 | }, | 921 | }, |
| 900 | }; | 922 | }; |
| 901 | 923 | ||
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c index 552196c764d4..3e8dcf8d2e05 100644 --- a/drivers/mmc/host/omap.c +++ b/drivers/mmc/host/omap.c | |||
| @@ -1300,7 +1300,7 @@ static const struct mmc_host_ops mmc_omap_ops = { | |||
| 1300 | .set_ios = mmc_omap_set_ios, | 1300 | .set_ios = mmc_omap_set_ios, |
| 1301 | }; | 1301 | }; |
| 1302 | 1302 | ||
| 1303 | static int __init mmc_omap_new_slot(struct mmc_omap_host *host, int id) | 1303 | static int __devinit mmc_omap_new_slot(struct mmc_omap_host *host, int id) |
| 1304 | { | 1304 | { |
| 1305 | struct mmc_omap_slot *slot = NULL; | 1305 | struct mmc_omap_slot *slot = NULL; |
| 1306 | struct mmc_host *mmc; | 1306 | struct mmc_host *mmc; |
| @@ -1485,24 +1485,26 @@ static int __devinit mmc_omap_probe(struct platform_device *pdev) | |||
| 1485 | } | 1485 | } |
| 1486 | 1486 | ||
| 1487 | host->nr_slots = pdata->nr_slots; | 1487 | host->nr_slots = pdata->nr_slots; |
| 1488 | host->reg_shift = (cpu_is_omap7xx() ? 1 : 2); | ||
| 1489 | |||
| 1490 | host->mmc_omap_wq = alloc_workqueue("mmc_omap", 0, 0); | ||
| 1491 | if (!host->mmc_omap_wq) | ||
| 1492 | goto err_plat_cleanup; | ||
| 1493 | |||
| 1488 | for (i = 0; i < pdata->nr_slots; i++) { | 1494 | for (i = 0; i < pdata->nr_slots; i++) { |
| 1489 | ret = mmc_omap_new_slot(host, i); | 1495 | ret = mmc_omap_new_slot(host, i); |
| 1490 | if (ret < 0) { | 1496 | if (ret < 0) { |
| 1491 | while (--i >= 0) | 1497 | while (--i >= 0) |
| 1492 | mmc_omap_remove_slot(host->slots[i]); | 1498 | mmc_omap_remove_slot(host->slots[i]); |
| 1493 | 1499 | ||
| 1494 | goto err_plat_cleanup; | 1500 | goto err_destroy_wq; |
| 1495 | } | 1501 | } |
| 1496 | } | 1502 | } |
| 1497 | 1503 | ||
| 1498 | host->reg_shift = (cpu_is_omap7xx() ? 1 : 2); | ||
| 1499 | |||
| 1500 | host->mmc_omap_wq = alloc_workqueue("mmc_omap", 0, 0); | ||
| 1501 | if (!host->mmc_omap_wq) | ||
| 1502 | goto err_plat_cleanup; | ||
| 1503 | |||
| 1504 | return 0; | 1504 | return 0; |
| 1505 | 1505 | ||
| 1506 | err_destroy_wq: | ||
| 1507 | destroy_workqueue(host->mmc_omap_wq); | ||
| 1506 | err_plat_cleanup: | 1508 | err_plat_cleanup: |
| 1507 | if (pdata->cleanup) | 1509 | if (pdata->cleanup) |
| 1508 | pdata->cleanup(&pdev->dev); | 1510 | pdata->cleanup(&pdev->dev); |
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c index 9a7a60aeb19e..bc28627af66b 100644 --- a/drivers/mmc/host/omap_hsmmc.c +++ b/drivers/mmc/host/omap_hsmmc.c | |||
| @@ -85,7 +85,6 @@ | |||
| 85 | #define BRR_ENABLE (1 << 5) | 85 | #define BRR_ENABLE (1 << 5) |
| 86 | #define DTO_ENABLE (1 << 20) | 86 | #define DTO_ENABLE (1 << 20) |
| 87 | #define INIT_STREAM (1 << 1) | 87 | #define INIT_STREAM (1 << 1) |
| 88 | #define ACEN_ACMD12 (1 << 2) | ||
| 89 | #define DP_SELECT (1 << 21) | 88 | #define DP_SELECT (1 << 21) |
| 90 | #define DDIR (1 << 4) | 89 | #define DDIR (1 << 4) |
| 91 | #define DMA_EN 0x1 | 90 | #define DMA_EN 0x1 |
| @@ -117,7 +116,6 @@ | |||
| 117 | #define OMAP_MMC_MAX_CLOCK 52000000 | 116 | #define OMAP_MMC_MAX_CLOCK 52000000 |
| 118 | #define DRIVER_NAME "omap_hsmmc" | 117 | #define DRIVER_NAME "omap_hsmmc" |
| 119 | 118 | ||
| 120 | #define AUTO_CMD12 (1 << 0) /* Auto CMD12 support */ | ||
| 121 | /* | 119 | /* |
| 122 | * One controller can have multiple slots, like on some omap boards using | 120 | * One controller can have multiple slots, like on some omap boards using |
| 123 | * omap.c controller driver. Luckily this is not currently done on any known | 121 | * omap.c controller driver. Luckily this is not currently done on any known |
| @@ -177,7 +175,6 @@ struct omap_hsmmc_host { | |||
| 177 | int reqs_blocked; | 175 | int reqs_blocked; |
| 178 | int use_reg; | 176 | int use_reg; |
| 179 | int req_in_progress; | 177 | int req_in_progress; |
| 180 | unsigned int flags; | ||
| 181 | struct omap_hsmmc_next next_data; | 178 | struct omap_hsmmc_next next_data; |
| 182 | 179 | ||
| 183 | struct omap_mmc_platform_data *pdata; | 180 | struct omap_mmc_platform_data *pdata; |
| @@ -773,8 +770,6 @@ omap_hsmmc_start_command(struct omap_hsmmc_host *host, struct mmc_command *cmd, | |||
| 773 | cmdtype = 0x3; | 770 | cmdtype = 0x3; |
| 774 | 771 | ||
| 775 | cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22); | 772 | cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22); |
| 776 | if ((host->flags & AUTO_CMD12) && mmc_op_multi(cmd->opcode)) | ||
| 777 | cmdreg |= ACEN_ACMD12; | ||
| 778 | 773 | ||
| 779 | if (data) { | 774 | if (data) { |
| 780 | cmdreg |= DP_SELECT | MSBS | BCE; | 775 | cmdreg |= DP_SELECT | MSBS | BCE; |
| @@ -847,14 +842,11 @@ omap_hsmmc_xfer_done(struct omap_hsmmc_host *host, struct mmc_data *data) | |||
| 847 | else | 842 | else |
| 848 | data->bytes_xfered = 0; | 843 | data->bytes_xfered = 0; |
| 849 | 844 | ||
| 850 | if (data->stop && ((!(host->flags & AUTO_CMD12)) || data->error)) { | 845 | if (!data->stop) { |
| 851 | omap_hsmmc_start_command(host, data->stop, NULL); | ||
| 852 | } else { | ||
| 853 | if (data->stop) | ||
| 854 | data->stop->resp[0] = OMAP_HSMMC_READ(host->base, | ||
| 855 | RSP76); | ||
| 856 | omap_hsmmc_request_done(host, data->mrq); | 846 | omap_hsmmc_request_done(host, data->mrq); |
| 847 | return; | ||
| 857 | } | 848 | } |
| 849 | omap_hsmmc_start_command(host, data->stop, NULL); | ||
| 858 | } | 850 | } |
| 859 | 851 | ||
| 860 | /* | 852 | /* |
| @@ -1097,7 +1089,7 @@ static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd) | |||
| 1097 | /* Disable the clocks */ | 1089 | /* Disable the clocks */ |
| 1098 | pm_runtime_put_sync(host->dev); | 1090 | pm_runtime_put_sync(host->dev); |
| 1099 | if (host->dbclk) | 1091 | if (host->dbclk) |
| 1100 | clk_disable(host->dbclk); | 1092 | clk_disable_unprepare(host->dbclk); |
| 1101 | 1093 | ||
| 1102 | /* Turn the power off */ | 1094 | /* Turn the power off */ |
| 1103 | ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); | 1095 | ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); |
| @@ -1108,7 +1100,7 @@ static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd) | |||
| 1108 | vdd); | 1100 | vdd); |
| 1109 | pm_runtime_get_sync(host->dev); | 1101 | pm_runtime_get_sync(host->dev); |
| 1110 | if (host->dbclk) | 1102 | if (host->dbclk) |
| 1111 | clk_enable(host->dbclk); | 1103 | clk_prepare_enable(host->dbclk); |
| 1112 | 1104 | ||
| 1113 | if (ret != 0) | 1105 | if (ret != 0) |
| 1114 | goto err; | 1106 | goto err; |
| @@ -1859,7 +1851,6 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev) | |||
| 1859 | host->mapbase = res->start + pdata->reg_offset; | 1851 | host->mapbase = res->start + pdata->reg_offset; |
| 1860 | host->base = ioremap(host->mapbase, SZ_4K); | 1852 | host->base = ioremap(host->mapbase, SZ_4K); |
| 1861 | host->power_mode = MMC_POWER_OFF; | 1853 | host->power_mode = MMC_POWER_OFF; |
| 1862 | host->flags = AUTO_CMD12; | ||
| 1863 | host->next_data.cookie = 1; | 1854 | host->next_data.cookie = 1; |
| 1864 | 1855 | ||
| 1865 | platform_set_drvdata(pdev, host); | 1856 | platform_set_drvdata(pdev, host); |
| @@ -1908,7 +1899,7 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev) | |||
| 1908 | if (IS_ERR(host->dbclk)) { | 1899 | if (IS_ERR(host->dbclk)) { |
| 1909 | dev_warn(mmc_dev(host->mmc), "Failed to get debounce clk\n"); | 1900 | dev_warn(mmc_dev(host->mmc), "Failed to get debounce clk\n"); |
| 1910 | host->dbclk = NULL; | 1901 | host->dbclk = NULL; |
| 1911 | } else if (clk_enable(host->dbclk) != 0) { | 1902 | } else if (clk_prepare_enable(host->dbclk) != 0) { |
| 1912 | dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n"); | 1903 | dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n"); |
| 1913 | clk_put(host->dbclk); | 1904 | clk_put(host->dbclk); |
| 1914 | host->dbclk = NULL; | 1905 | host->dbclk = NULL; |
| @@ -1940,6 +1931,7 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev) | |||
| 1940 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); | 1931 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); |
| 1941 | if (!res) { | 1932 | if (!res) { |
| 1942 | dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n"); | 1933 | dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n"); |
| 1934 | ret = -ENXIO; | ||
| 1943 | goto err_irq; | 1935 | goto err_irq; |
| 1944 | } | 1936 | } |
| 1945 | host->dma_line_tx = res->start; | 1937 | host->dma_line_tx = res->start; |
| @@ -1947,6 +1939,7 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev) | |||
| 1947 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); | 1939 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); |
| 1948 | if (!res) { | 1940 | if (!res) { |
| 1949 | dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n"); | 1941 | dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n"); |
| 1942 | ret = -ENXIO; | ||
| 1950 | goto err_irq; | 1943 | goto err_irq; |
| 1951 | } | 1944 | } |
| 1952 | host->dma_line_rx = res->start; | 1945 | host->dma_line_rx = res->start; |
| @@ -2032,7 +2025,7 @@ err_irq: | |||
| 2032 | pm_runtime_disable(host->dev); | 2025 | pm_runtime_disable(host->dev); |
| 2033 | clk_put(host->fclk); | 2026 | clk_put(host->fclk); |
| 2034 | if (host->dbclk) { | 2027 | if (host->dbclk) { |
| 2035 | clk_disable(host->dbclk); | 2028 | clk_disable_unprepare(host->dbclk); |
| 2036 | clk_put(host->dbclk); | 2029 | clk_put(host->dbclk); |
| 2037 | } | 2030 | } |
| 2038 | err1: | 2031 | err1: |
| @@ -2067,7 +2060,7 @@ static int __devexit omap_hsmmc_remove(struct platform_device *pdev) | |||
| 2067 | pm_runtime_disable(host->dev); | 2060 | pm_runtime_disable(host->dev); |
| 2068 | clk_put(host->fclk); | 2061 | clk_put(host->fclk); |
| 2069 | if (host->dbclk) { | 2062 | if (host->dbclk) { |
| 2070 | clk_disable(host->dbclk); | 2063 | clk_disable_unprepare(host->dbclk); |
| 2071 | clk_put(host->dbclk); | 2064 | clk_put(host->dbclk); |
| 2072 | } | 2065 | } |
| 2073 | 2066 | ||
| @@ -2125,7 +2118,7 @@ static int omap_hsmmc_suspend(struct device *dev) | |||
| 2125 | } | 2118 | } |
| 2126 | 2119 | ||
| 2127 | if (host->dbclk) | 2120 | if (host->dbclk) |
| 2128 | clk_disable(host->dbclk); | 2121 | clk_disable_unprepare(host->dbclk); |
| 2129 | err: | 2122 | err: |
| 2130 | pm_runtime_put_sync(host->dev); | 2123 | pm_runtime_put_sync(host->dev); |
| 2131 | return ret; | 2124 | return ret; |
| @@ -2146,7 +2139,7 @@ static int omap_hsmmc_resume(struct device *dev) | |||
| 2146 | pm_runtime_get_sync(host->dev); | 2139 | pm_runtime_get_sync(host->dev); |
| 2147 | 2140 | ||
| 2148 | if (host->dbclk) | 2141 | if (host->dbclk) |
| 2149 | clk_enable(host->dbclk); | 2142 | clk_prepare_enable(host->dbclk); |
| 2150 | 2143 | ||
| 2151 | if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) | 2144 | if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) |
| 2152 | omap_hsmmc_conf_bus_power(host); | 2145 | omap_hsmmc_conf_bus_power(host); |
diff --git a/drivers/mmc/host/s3cmci.c b/drivers/mmc/host/s3cmci.c index c3622a69f432..bd5a5cce122c 100644 --- a/drivers/mmc/host/s3cmci.c +++ b/drivers/mmc/host/s3cmci.c | |||
| @@ -26,7 +26,6 @@ | |||
| 26 | #include <mach/dma.h> | 26 | #include <mach/dma.h> |
| 27 | 27 | ||
| 28 | #include <mach/regs-sdi.h> | 28 | #include <mach/regs-sdi.h> |
| 29 | #include <mach/regs-gpio.h> | ||
| 30 | 29 | ||
| 31 | #include <plat/mci.h> | 30 | #include <plat/mci.h> |
| 32 | 31 | ||
| @@ -1237,12 +1236,9 @@ static void s3cmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
| 1237 | switch (ios->power_mode) { | 1236 | switch (ios->power_mode) { |
| 1238 | case MMC_POWER_ON: | 1237 | case MMC_POWER_ON: |
| 1239 | case MMC_POWER_UP: | 1238 | case MMC_POWER_UP: |
| 1240 | s3c2410_gpio_cfgpin(S3C2410_GPE(5), S3C2410_GPE5_SDCLK); | 1239 | /* Configure GPE5...GPE10 pins in SD mode */ |
| 1241 | s3c2410_gpio_cfgpin(S3C2410_GPE(6), S3C2410_GPE6_SDCMD); | 1240 | s3c_gpio_cfgall_range(S3C2410_GPE(5), 6, S3C_GPIO_SFN(2), |
| 1242 | s3c2410_gpio_cfgpin(S3C2410_GPE(7), S3C2410_GPE7_SDDAT0); | 1241 | S3C_GPIO_PULL_NONE); |
| 1243 | s3c2410_gpio_cfgpin(S3C2410_GPE(8), S3C2410_GPE8_SDDAT1); | ||
| 1244 | s3c2410_gpio_cfgpin(S3C2410_GPE(9), S3C2410_GPE9_SDDAT2); | ||
| 1245 | s3c2410_gpio_cfgpin(S3C2410_GPE(10), S3C2410_GPE10_SDDAT3); | ||
| 1246 | 1242 | ||
| 1247 | if (host->pdata->set_power) | 1243 | if (host->pdata->set_power) |
| 1248 | host->pdata->set_power(ios->power_mode, ios->vdd); | 1244 | host->pdata->set_power(ios->power_mode, ios->vdd); |
diff --git a/drivers/mmc/host/sdhci-dove.c b/drivers/mmc/host/sdhci-dove.c index 177f697b5835..a6e53a1ebb08 100644 --- a/drivers/mmc/host/sdhci-dove.c +++ b/drivers/mmc/host/sdhci-dove.c | |||
| @@ -20,11 +20,17 @@ | |||
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
| 23 | #include <linux/clk.h> | ||
| 24 | #include <linux/err.h> | ||
| 23 | #include <linux/module.h> | 25 | #include <linux/module.h> |
| 24 | #include <linux/mmc/host.h> | 26 | #include <linux/mmc/host.h> |
| 25 | 27 | ||
| 26 | #include "sdhci-pltfm.h" | 28 | #include "sdhci-pltfm.h" |
| 27 | 29 | ||
| 30 | struct sdhci_dove_priv { | ||
| 31 | struct clk *clk; | ||
| 32 | }; | ||
| 33 | |||
| 28 | static u16 sdhci_dove_readw(struct sdhci_host *host, int reg) | 34 | static u16 sdhci_dove_readw(struct sdhci_host *host, int reg) |
| 29 | { | 35 | { |
| 30 | u16 ret; | 36 | u16 ret; |
| @@ -66,16 +72,57 @@ static struct sdhci_pltfm_data sdhci_dove_pdata = { | |||
| 66 | .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | | 72 | .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | |
| 67 | SDHCI_QUIRK_NO_BUSY_IRQ | | 73 | SDHCI_QUIRK_NO_BUSY_IRQ | |
| 68 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | | 74 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | |
| 69 | SDHCI_QUIRK_FORCE_DMA, | 75 | SDHCI_QUIRK_FORCE_DMA | |
| 76 | SDHCI_QUIRK_NO_HISPD_BIT, | ||
| 70 | }; | 77 | }; |
| 71 | 78 | ||
| 72 | static int __devinit sdhci_dove_probe(struct platform_device *pdev) | 79 | static int __devinit sdhci_dove_probe(struct platform_device *pdev) |
| 73 | { | 80 | { |
| 74 | return sdhci_pltfm_register(pdev, &sdhci_dove_pdata); | 81 | struct sdhci_host *host; |
| 82 | struct sdhci_pltfm_host *pltfm_host; | ||
| 83 | struct sdhci_dove_priv *priv; | ||
| 84 | int ret; | ||
| 85 | |||
| 86 | ret = sdhci_pltfm_register(pdev, &sdhci_dove_pdata); | ||
| 87 | if (ret) | ||
| 88 | goto sdhci_dove_register_fail; | ||
| 89 | |||
| 90 | priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_dove_priv), | ||
| 91 | GFP_KERNEL); | ||
| 92 | if (!priv) { | ||
| 93 | dev_err(&pdev->dev, "unable to allocate private data"); | ||
| 94 | ret = -ENOMEM; | ||
| 95 | goto sdhci_dove_allocate_fail; | ||
| 96 | } | ||
| 97 | |||
| 98 | host = platform_get_drvdata(pdev); | ||
| 99 | pltfm_host = sdhci_priv(host); | ||
| 100 | pltfm_host->priv = priv; | ||
| 101 | |||
| 102 | priv->clk = clk_get(&pdev->dev, NULL); | ||
| 103 | if (!IS_ERR(priv->clk)) | ||
| 104 | clk_prepare_enable(priv->clk); | ||
| 105 | return 0; | ||
| 106 | |||
| 107 | sdhci_dove_allocate_fail: | ||
| 108 | sdhci_pltfm_unregister(pdev); | ||
| 109 | sdhci_dove_register_fail: | ||
| 110 | return ret; | ||
| 75 | } | 111 | } |
| 76 | 112 | ||
| 77 | static int __devexit sdhci_dove_remove(struct platform_device *pdev) | 113 | static int __devexit sdhci_dove_remove(struct platform_device *pdev) |
| 78 | { | 114 | { |
| 115 | struct sdhci_host *host = platform_get_drvdata(pdev); | ||
| 116 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); | ||
| 117 | struct sdhci_dove_priv *priv = pltfm_host->priv; | ||
| 118 | |||
| 119 | if (priv->clk) { | ||
| 120 | if (!IS_ERR(priv->clk)) { | ||
| 121 | clk_disable_unprepare(priv->clk); | ||
| 122 | clk_put(priv->clk); | ||
| 123 | } | ||
| 124 | devm_kfree(&pdev->dev, priv->clk); | ||
| 125 | } | ||
| 79 | return sdhci_pltfm_unregister(pdev); | 126 | return sdhci_pltfm_unregister(pdev); |
| 80 | } | 127 | } |
| 81 | 128 | ||
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c index ebbe984e5d00..e23f8134591c 100644 --- a/drivers/mmc/host/sdhci-esdhc-imx.c +++ b/drivers/mmc/host/sdhci-esdhc-imx.c | |||
| @@ -299,6 +299,8 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg) | |||
| 299 | 299 | ||
| 300 | static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg) | 300 | static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg) |
| 301 | { | 301 | { |
| 302 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); | ||
| 303 | struct pltfm_imx_data *imx_data = pltfm_host->priv; | ||
| 302 | u32 new_val; | 304 | u32 new_val; |
| 303 | 305 | ||
| 304 | switch (reg) { | 306 | switch (reg) { |
| @@ -315,8 +317,11 @@ static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg) | |||
| 315 | SDHCI_CTRL_D3CD); | 317 | SDHCI_CTRL_D3CD); |
| 316 | /* ensure the endianess */ | 318 | /* ensure the endianess */ |
| 317 | new_val |= ESDHC_HOST_CONTROL_LE; | 319 | new_val |= ESDHC_HOST_CONTROL_LE; |
| 318 | /* DMA mode bits are shifted */ | 320 | /* bits 8&9 are reserved on mx25 */ |
| 319 | new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5; | 321 | if (!is_imx25_esdhc(imx_data)) { |
| 322 | /* DMA mode bits are shifted */ | ||
| 323 | new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5; | ||
| 324 | } | ||
| 320 | 325 | ||
| 321 | esdhc_clrset_le(host, 0xffff, new_val, reg); | 326 | esdhc_clrset_le(host, 0xffff, new_val, reg); |
| 322 | return; | 327 | return; |
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c index 69ef0beae104..504da715a41a 100644 --- a/drivers/mmc/host/sdhci-pci.c +++ b/drivers/mmc/host/sdhci-pci.c | |||
| @@ -157,6 +157,7 @@ static const struct sdhci_pci_fixes sdhci_ene_714 = { | |||
| 157 | static const struct sdhci_pci_fixes sdhci_cafe = { | 157 | static const struct sdhci_pci_fixes sdhci_cafe = { |
| 158 | .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | | 158 | .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | |
| 159 | SDHCI_QUIRK_NO_BUSY_IRQ | | 159 | SDHCI_QUIRK_NO_BUSY_IRQ | |
| 160 | SDHCI_QUIRK_BROKEN_CARD_DETECTION | | ||
| 160 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL, | 161 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL, |
| 161 | }; | 162 | }; |
| 162 | 163 | ||
diff --git a/drivers/mmc/host/sdhci-pxav2.c b/drivers/mmc/host/sdhci-pxav2.c index dbb75bfbcffb..b6ee8857e226 100644 --- a/drivers/mmc/host/sdhci-pxav2.c +++ b/drivers/mmc/host/sdhci-pxav2.c | |||
| @@ -28,6 +28,9 @@ | |||
| 28 | #include <linux/mmc/host.h> | 28 | #include <linux/mmc/host.h> |
| 29 | #include <linux/platform_data/pxa_sdhci.h> | 29 | #include <linux/platform_data/pxa_sdhci.h> |
| 30 | #include <linux/slab.h> | 30 | #include <linux/slab.h> |
| 31 | #include <linux/of.h> | ||
| 32 | #include <linux/of_device.h> | ||
| 33 | |||
| 31 | #include "sdhci.h" | 34 | #include "sdhci.h" |
| 32 | #include "sdhci-pltfm.h" | 35 | #include "sdhci-pltfm.h" |
| 33 | 36 | ||
| @@ -121,6 +124,48 @@ static struct sdhci_ops pxav2_sdhci_ops = { | |||
| 121 | .platform_8bit_width = pxav2_mmc_set_width, | 124 | .platform_8bit_width = pxav2_mmc_set_width, |
| 122 | }; | 125 | }; |
| 123 | 126 | ||
| 127 | #ifdef CONFIG_OF | ||
| 128 | static const struct of_device_id sdhci_pxav2_of_match[] = { | ||
| 129 | { | ||
| 130 | .compatible = "mrvl,pxav2-mmc", | ||
| 131 | }, | ||
| 132 | {}, | ||
| 133 | }; | ||
| 134 | MODULE_DEVICE_TABLE(of, sdhci_pxav2_of_match); | ||
| 135 | |||
| 136 | static struct sdhci_pxa_platdata *pxav2_get_mmc_pdata(struct device *dev) | ||
| 137 | { | ||
| 138 | struct sdhci_pxa_platdata *pdata; | ||
| 139 | struct device_node *np = dev->of_node; | ||
| 140 | u32 bus_width; | ||
| 141 | u32 clk_delay_cycles; | ||
| 142 | |||
| 143 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
| 144 | if (!pdata) | ||
| 145 | return NULL; | ||
| 146 | |||
| 147 | if (of_find_property(np, "non-removable", NULL)) | ||
| 148 | pdata->flags |= PXA_FLAG_CARD_PERMANENT; | ||
| 149 | |||
| 150 | of_property_read_u32(np, "bus-width", &bus_width); | ||
| 151 | if (bus_width == 8) | ||
| 152 | pdata->flags |= PXA_FLAG_SD_8_BIT_CAPABLE_SLOT; | ||
| 153 | |||
| 154 | of_property_read_u32(np, "mrvl,clk-delay-cycles", &clk_delay_cycles); | ||
| 155 | if (clk_delay_cycles > 0) { | ||
| 156 | pdata->clk_delay_sel = 1; | ||
| 157 | pdata->clk_delay_cycles = clk_delay_cycles; | ||
| 158 | } | ||
| 159 | |||
| 160 | return pdata; | ||
| 161 | } | ||
| 162 | #else | ||
| 163 | static inline struct sdhci_pxa_platdata *pxav2_get_mmc_pdata(struct device *dev) | ||
| 164 | { | ||
| 165 | return NULL; | ||
| 166 | } | ||
| 167 | #endif | ||
| 168 | |||
| 124 | static int __devinit sdhci_pxav2_probe(struct platform_device *pdev) | 169 | static int __devinit sdhci_pxav2_probe(struct platform_device *pdev) |
| 125 | { | 170 | { |
| 126 | struct sdhci_pltfm_host *pltfm_host; | 171 | struct sdhci_pltfm_host *pltfm_host; |
| @@ -128,6 +173,8 @@ static int __devinit sdhci_pxav2_probe(struct platform_device *pdev) | |||
| 128 | struct device *dev = &pdev->dev; | 173 | struct device *dev = &pdev->dev; |
| 129 | struct sdhci_host *host = NULL; | 174 | struct sdhci_host *host = NULL; |
| 130 | struct sdhci_pxa *pxa = NULL; | 175 | struct sdhci_pxa *pxa = NULL; |
| 176 | const struct of_device_id *match; | ||
| 177 | |||
| 131 | int ret; | 178 | int ret; |
| 132 | struct clk *clk; | 179 | struct clk *clk; |
| 133 | 180 | ||
| @@ -156,6 +203,10 @@ static int __devinit sdhci_pxav2_probe(struct platform_device *pdev) | |||
| 156 | | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | 203 | | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
| 157 | | SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN; | 204 | | SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN; |
| 158 | 205 | ||
| 206 | match = of_match_device(of_match_ptr(sdhci_pxav2_of_match), &pdev->dev); | ||
| 207 | if (match) { | ||
| 208 | pdata = pxav2_get_mmc_pdata(dev); | ||
| 209 | } | ||
| 159 | if (pdata) { | 210 | if (pdata) { |
| 160 | if (pdata->flags & PXA_FLAG_CARD_PERMANENT) { | 211 | if (pdata->flags & PXA_FLAG_CARD_PERMANENT) { |
| 161 | /* on-chip device */ | 212 | /* on-chip device */ |
| @@ -218,6 +269,9 @@ static struct platform_driver sdhci_pxav2_driver = { | |||
| 218 | .driver = { | 269 | .driver = { |
| 219 | .name = "sdhci-pxav2", | 270 | .name = "sdhci-pxav2", |
| 220 | .owner = THIS_MODULE, | 271 | .owner = THIS_MODULE, |
| 272 | #ifdef CONFIG_OF | ||
| 273 | .of_match_table = sdhci_pxav2_of_match, | ||
| 274 | #endif | ||
| 221 | .pm = SDHCI_PLTFM_PMOPS, | 275 | .pm = SDHCI_PLTFM_PMOPS, |
| 222 | }, | 276 | }, |
| 223 | .probe = sdhci_pxav2_probe, | 277 | .probe = sdhci_pxav2_probe, |
diff --git a/drivers/mmc/host/sdhci-pxav3.c b/drivers/mmc/host/sdhci-pxav3.c index f29695683556..07fe3834fe0b 100644 --- a/drivers/mmc/host/sdhci-pxav3.c +++ b/drivers/mmc/host/sdhci-pxav3.c | |||
| @@ -28,6 +28,9 @@ | |||
| 28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
| 29 | #include <linux/delay.h> | 29 | #include <linux/delay.h> |
| 30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
| 31 | #include <linux/of.h> | ||
| 32 | #include <linux/of_device.h> | ||
| 33 | |||
| 31 | #include "sdhci.h" | 34 | #include "sdhci.h" |
| 32 | #include "sdhci-pltfm.h" | 35 | #include "sdhci-pltfm.h" |
| 33 | 36 | ||
| @@ -164,6 +167,46 @@ static struct sdhci_ops pxav3_sdhci_ops = { | |||
| 164 | .platform_send_init_74_clocks = pxav3_gen_init_74_clocks, | 167 | .platform_send_init_74_clocks = pxav3_gen_init_74_clocks, |
| 165 | }; | 168 | }; |
| 166 | 169 | ||
| 170 | #ifdef CONFIG_OF | ||
| 171 | static const struct of_device_id sdhci_pxav3_of_match[] = { | ||
| 172 | { | ||
| 173 | .compatible = "mrvl,pxav3-mmc", | ||
| 174 | }, | ||
| 175 | {}, | ||
| 176 | }; | ||
| 177 | MODULE_DEVICE_TABLE(of, sdhci_pxav3_of_match); | ||
| 178 | |||
| 179 | static struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev) | ||
| 180 | { | ||
| 181 | struct sdhci_pxa_platdata *pdata; | ||
| 182 | struct device_node *np = dev->of_node; | ||
| 183 | u32 bus_width; | ||
| 184 | u32 clk_delay_cycles; | ||
| 185 | |||
| 186 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
| 187 | if (!pdata) | ||
| 188 | return NULL; | ||
| 189 | |||
| 190 | if (of_find_property(np, "non-removable", NULL)) | ||
| 191 | pdata->flags |= PXA_FLAG_CARD_PERMANENT; | ||
| 192 | |||
| 193 | of_property_read_u32(np, "bus-width", &bus_width); | ||
| 194 | if (bus_width == 8) | ||
| 195 | pdata->flags |= PXA_FLAG_SD_8_BIT_CAPABLE_SLOT; | ||
| 196 | |||
| 197 | of_property_read_u32(np, "mrvl,clk-delay-cycles", &clk_delay_cycles); | ||
| 198 | if (clk_delay_cycles > 0) | ||
| 199 | pdata->clk_delay_cycles = clk_delay_cycles; | ||
| 200 | |||
| 201 | return pdata; | ||
| 202 | } | ||
| 203 | #else | ||
| 204 | static inline struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev) | ||
| 205 | { | ||
| 206 | return NULL; | ||
| 207 | } | ||
| 208 | #endif | ||
| 209 | |||
| 167 | static int __devinit sdhci_pxav3_probe(struct platform_device *pdev) | 210 | static int __devinit sdhci_pxav3_probe(struct platform_device *pdev) |
| 168 | { | 211 | { |
| 169 | struct sdhci_pltfm_host *pltfm_host; | 212 | struct sdhci_pltfm_host *pltfm_host; |
| @@ -171,6 +214,8 @@ static int __devinit sdhci_pxav3_probe(struct platform_device *pdev) | |||
| 171 | struct device *dev = &pdev->dev; | 214 | struct device *dev = &pdev->dev; |
| 172 | struct sdhci_host *host = NULL; | 215 | struct sdhci_host *host = NULL; |
| 173 | struct sdhci_pxa *pxa = NULL; | 216 | struct sdhci_pxa *pxa = NULL; |
| 217 | const struct of_device_id *match; | ||
| 218 | |||
| 174 | int ret; | 219 | int ret; |
| 175 | struct clk *clk; | 220 | struct clk *clk; |
| 176 | 221 | ||
| @@ -202,6 +247,10 @@ static int __devinit sdhci_pxav3_probe(struct platform_device *pdev) | |||
| 202 | /* enable 1/8V DDR capable */ | 247 | /* enable 1/8V DDR capable */ |
| 203 | host->mmc->caps |= MMC_CAP_1_8V_DDR; | 248 | host->mmc->caps |= MMC_CAP_1_8V_DDR; |
| 204 | 249 | ||
| 250 | match = of_match_device(of_match_ptr(sdhci_pxav3_of_match), &pdev->dev); | ||
| 251 | if (match) | ||
| 252 | pdata = pxav3_get_mmc_pdata(dev); | ||
| 253 | |||
| 205 | if (pdata) { | 254 | if (pdata) { |
| 206 | if (pdata->flags & PXA_FLAG_CARD_PERMANENT) { | 255 | if (pdata->flags & PXA_FLAG_CARD_PERMANENT) { |
| 207 | /* on-chip device */ | 256 | /* on-chip device */ |
| @@ -263,6 +312,9 @@ static int __devexit sdhci_pxav3_remove(struct platform_device *pdev) | |||
| 263 | static struct platform_driver sdhci_pxav3_driver = { | 312 | static struct platform_driver sdhci_pxav3_driver = { |
| 264 | .driver = { | 313 | .driver = { |
| 265 | .name = "sdhci-pxav3", | 314 | .name = "sdhci-pxav3", |
| 315 | #ifdef CONFIG_OF | ||
| 316 | .of_match_table = sdhci_pxav3_of_match, | ||
| 317 | #endif | ||
| 266 | .owner = THIS_MODULE, | 318 | .owner = THIS_MODULE, |
| 267 | .pm = SDHCI_PLTFM_PMOPS, | 319 | .pm = SDHCI_PLTFM_PMOPS, |
| 268 | }, | 320 | }, |
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c index 55a164fcaa15..a50c205ea208 100644 --- a/drivers/mmc/host/sdhci-s3c.c +++ b/drivers/mmc/host/sdhci-s3c.c | |||
| @@ -404,7 +404,7 @@ static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc) | |||
| 404 | if (sc->ext_cd_irq && | 404 | if (sc->ext_cd_irq && |
| 405 | request_threaded_irq(sc->ext_cd_irq, NULL, | 405 | request_threaded_irq(sc->ext_cd_irq, NULL, |
| 406 | sdhci_s3c_gpio_card_detect_thread, | 406 | sdhci_s3c_gpio_card_detect_thread, |
| 407 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, | 407 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
| 408 | dev_name(dev), sc) == 0) { | 408 | dev_name(dev), sc) == 0) { |
| 409 | int status = gpio_get_value(sc->ext_cd_gpio); | 409 | int status = gpio_get_value(sc->ext_cd_gpio); |
| 410 | if (pdata->ext_cd_gpio_invert) | 410 | if (pdata->ext_cd_gpio_invert) |
diff --git a/drivers/mmc/host/sdhci-spear.c b/drivers/mmc/host/sdhci-spear.c index 1fe32dfa7cd4..423da8194cd8 100644 --- a/drivers/mmc/host/sdhci-spear.c +++ b/drivers/mmc/host/sdhci-spear.c | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | * Support of SDHCI platform devices for spear soc family | 4 | * Support of SDHCI platform devices for spear soc family |
| 5 | * | 5 | * |
| 6 | * Copyright (C) 2010 ST Microelectronics | 6 | * Copyright (C) 2010 ST Microelectronics |
| 7 | * Viresh Kumar<viresh.kumar@st.com> | 7 | * Viresh Kumar <viresh.linux@gmail.com> |
| 8 | * | 8 | * |
| 9 | * Inspired by sdhci-pltfm.c | 9 | * Inspired by sdhci-pltfm.c |
| 10 | * | 10 | * |
| @@ -289,5 +289,5 @@ static struct platform_driver sdhci_driver = { | |||
| 289 | module_platform_driver(sdhci_driver); | 289 | module_platform_driver(sdhci_driver); |
| 290 | 290 | ||
| 291 | MODULE_DESCRIPTION("SPEAr Secure Digital Host Controller Interface driver"); | 291 | MODULE_DESCRIPTION("SPEAr Secure Digital Host Controller Interface driver"); |
| 292 | MODULE_AUTHOR("Viresh Kumar <viresh.kumar@st.com>"); | 292 | MODULE_AUTHOR("Viresh Kumar <viresh.linux@gmail.com>"); |
| 293 | MODULE_LICENSE("GPL v2"); | 293 | MODULE_LICENSE("GPL v2"); |
diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c index b38d8a78f6a0..0810ccc23d7e 100644 --- a/drivers/mmc/host/sdhci-tegra.c +++ b/drivers/mmc/host/sdhci-tegra.c | |||
| @@ -223,6 +223,7 @@ static struct tegra_sdhci_platform_data * __devinit sdhci_tegra_dt_parse_pdata( | |||
| 223 | { | 223 | { |
| 224 | struct tegra_sdhci_platform_data *plat; | 224 | struct tegra_sdhci_platform_data *plat; |
| 225 | struct device_node *np = pdev->dev.of_node; | 225 | struct device_node *np = pdev->dev.of_node; |
| 226 | u32 bus_width; | ||
| 226 | 227 | ||
| 227 | if (!np) | 228 | if (!np) |
| 228 | return NULL; | 229 | return NULL; |
| @@ -236,7 +237,9 @@ static struct tegra_sdhci_platform_data * __devinit sdhci_tegra_dt_parse_pdata( | |||
| 236 | plat->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0); | 237 | plat->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0); |
| 237 | plat->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0); | 238 | plat->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0); |
| 238 | plat->power_gpio = of_get_named_gpio(np, "power-gpios", 0); | 239 | plat->power_gpio = of_get_named_gpio(np, "power-gpios", 0); |
| 239 | if (of_find_property(np, "support-8bit", NULL)) | 240 | |
| 241 | if (of_property_read_u32(np, "bus-width", &bus_width) == 0 && | ||
| 242 | bus_width == 8) | ||
| 240 | plat->is_8bit = 1; | 243 | plat->is_8bit = 1; |
| 241 | 244 | ||
| 242 | return plat; | 245 | return plat; |
| @@ -334,7 +337,7 @@ static int __devinit sdhci_tegra_probe(struct platform_device *pdev) | |||
| 334 | rc = PTR_ERR(clk); | 337 | rc = PTR_ERR(clk); |
| 335 | goto err_clk_get; | 338 | goto err_clk_get; |
| 336 | } | 339 | } |
| 337 | clk_enable(clk); | 340 | clk_prepare_enable(clk); |
| 338 | pltfm_host->clk = clk; | 341 | pltfm_host->clk = clk; |
| 339 | 342 | ||
| 340 | host->mmc->pm_caps = plat->pm_flags; | 343 | host->mmc->pm_caps = plat->pm_flags; |
| @@ -349,7 +352,7 @@ static int __devinit sdhci_tegra_probe(struct platform_device *pdev) | |||
| 349 | return 0; | 352 | return 0; |
| 350 | 353 | ||
| 351 | err_add_host: | 354 | err_add_host: |
| 352 | clk_disable(pltfm_host->clk); | 355 | clk_disable_unprepare(pltfm_host->clk); |
| 353 | clk_put(pltfm_host->clk); | 356 | clk_put(pltfm_host->clk); |
| 354 | err_clk_get: | 357 | err_clk_get: |
| 355 | if (gpio_is_valid(plat->wp_gpio)) | 358 | if (gpio_is_valid(plat->wp_gpio)) |
| @@ -390,7 +393,7 @@ static int __devexit sdhci_tegra_remove(struct platform_device *pdev) | |||
| 390 | if (gpio_is_valid(plat->power_gpio)) | 393 | if (gpio_is_valid(plat->power_gpio)) |
| 391 | gpio_free(plat->power_gpio); | 394 | gpio_free(plat->power_gpio); |
| 392 | 395 | ||
| 393 | clk_disable(pltfm_host->clk); | 396 | clk_disable_unprepare(pltfm_host->clk); |
| 394 | clk_put(pltfm_host->clk); | 397 | clk_put(pltfm_host->clk); |
| 395 | 398 | ||
| 396 | sdhci_pltfm_free(pdev); | 399 | sdhci_pltfm_free(pdev); |
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index e626732aff77..9a11dc39921c 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | 27 | ||
| 28 | #include <linux/mmc/mmc.h> | 28 | #include <linux/mmc/mmc.h> |
| 29 | #include <linux/mmc/host.h> | 29 | #include <linux/mmc/host.h> |
| 30 | #include <linux/mmc/card.h> | ||
| 30 | 31 | ||
| 31 | #include "sdhci.h" | 32 | #include "sdhci.h" |
| 32 | 33 | ||
| @@ -244,6 +245,19 @@ static void sdhci_init(struct sdhci_host *host, int soft) | |||
| 244 | static void sdhci_reinit(struct sdhci_host *host) | 245 | static void sdhci_reinit(struct sdhci_host *host) |
| 245 | { | 246 | { |
| 246 | sdhci_init(host, 0); | 247 | sdhci_init(host, 0); |
| 248 | /* | ||
| 249 | * Retuning stuffs are affected by different cards inserted and only | ||
| 250 | * applicable to UHS-I cards. So reset these fields to their initial | ||
| 251 | * value when card is removed. | ||
| 252 | */ | ||
| 253 | if (host->flags & SDHCI_USING_RETUNING_TIMER) { | ||
| 254 | host->flags &= ~SDHCI_USING_RETUNING_TIMER; | ||
| 255 | |||
| 256 | del_timer_sync(&host->tuning_timer); | ||
| 257 | host->flags &= ~SDHCI_NEEDS_RETUNING; | ||
| 258 | host->mmc->max_blk_count = | ||
| 259 | (host->quirks & SDHCI_QUIRK_NO_MULTIBLOCK) ? 1 : 65535; | ||
| 260 | } | ||
| 247 | sdhci_enable_card_detection(host); | 261 | sdhci_enable_card_detection(host); |
| 248 | } | 262 | } |
| 249 | 263 | ||
| @@ -680,8 +694,8 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd) | |||
| 680 | } | 694 | } |
| 681 | 695 | ||
| 682 | if (count >= 0xF) { | 696 | if (count >= 0xF) { |
| 683 | pr_warning("%s: Too large timeout 0x%x requested for CMD%d!\n", | 697 | DBG("%s: Too large timeout 0x%x requested for CMD%d!\n", |
| 684 | mmc_hostname(host->mmc), count, cmd->opcode); | 698 | mmc_hostname(host->mmc), count, cmd->opcode); |
| 685 | count = 0xE; | 699 | count = 0xE; |
| 686 | } | 700 | } |
| 687 | 701 | ||
| @@ -1245,6 +1259,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
| 1245 | struct sdhci_host *host; | 1259 | struct sdhci_host *host; |
| 1246 | bool present; | 1260 | bool present; |
| 1247 | unsigned long flags; | 1261 | unsigned long flags; |
| 1262 | u32 tuning_opcode; | ||
| 1248 | 1263 | ||
| 1249 | host = mmc_priv(mmc); | 1264 | host = mmc_priv(mmc); |
| 1250 | 1265 | ||
| @@ -1292,8 +1307,12 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
| 1292 | */ | 1307 | */ |
| 1293 | if ((host->flags & SDHCI_NEEDS_RETUNING) && | 1308 | if ((host->flags & SDHCI_NEEDS_RETUNING) && |
| 1294 | !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ))) { | 1309 | !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ))) { |
| 1310 | /* eMMC uses cmd21 while sd and sdio use cmd19 */ | ||
| 1311 | tuning_opcode = mmc->card->type == MMC_TYPE_MMC ? | ||
| 1312 | MMC_SEND_TUNING_BLOCK_HS200 : | ||
| 1313 | MMC_SEND_TUNING_BLOCK; | ||
| 1295 | spin_unlock_irqrestore(&host->lock, flags); | 1314 | spin_unlock_irqrestore(&host->lock, flags); |
| 1296 | sdhci_execute_tuning(mmc, mrq->cmd->opcode); | 1315 | sdhci_execute_tuning(mmc, tuning_opcode); |
| 1297 | spin_lock_irqsave(&host->lock, flags); | 1316 | spin_lock_irqsave(&host->lock, flags); |
| 1298 | 1317 | ||
| 1299 | /* Restore original mmc_request structure */ | 1318 | /* Restore original mmc_request structure */ |
| @@ -1663,11 +1682,15 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host, | |||
| 1663 | pwr = sdhci_readb(host, SDHCI_POWER_CONTROL); | 1682 | pwr = sdhci_readb(host, SDHCI_POWER_CONTROL); |
| 1664 | pwr &= ~SDHCI_POWER_ON; | 1683 | pwr &= ~SDHCI_POWER_ON; |
| 1665 | sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); | 1684 | sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); |
| 1685 | if (host->vmmc) | ||
| 1686 | regulator_disable(host->vmmc); | ||
| 1666 | 1687 | ||
| 1667 | /* Wait for 1ms as per the spec */ | 1688 | /* Wait for 1ms as per the spec */ |
| 1668 | usleep_range(1000, 1500); | 1689 | usleep_range(1000, 1500); |
| 1669 | pwr |= SDHCI_POWER_ON; | 1690 | pwr |= SDHCI_POWER_ON; |
| 1670 | sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); | 1691 | sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); |
| 1692 | if (host->vmmc) | ||
| 1693 | regulator_enable(host->vmmc); | ||
| 1671 | 1694 | ||
| 1672 | pr_info(DRIVER_NAME ": Switching to 1.8V signalling " | 1695 | pr_info(DRIVER_NAME ": Switching to 1.8V signalling " |
| 1673 | "voltage failed, retrying with S18R set to 0\n"); | 1696 | "voltage failed, retrying with S18R set to 0\n"); |
| @@ -1855,6 +1878,7 @@ out: | |||
| 1855 | */ | 1878 | */ |
| 1856 | if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count && | 1879 | if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count && |
| 1857 | (host->tuning_mode == SDHCI_TUNING_MODE_1)) { | 1880 | (host->tuning_mode == SDHCI_TUNING_MODE_1)) { |
| 1881 | host->flags |= SDHCI_USING_RETUNING_TIMER; | ||
| 1858 | mod_timer(&host->tuning_timer, jiffies + | 1882 | mod_timer(&host->tuning_timer, jiffies + |
| 1859 | host->tuning_count * HZ); | 1883 | host->tuning_count * HZ); |
| 1860 | /* Tuning mode 1 limits the maximum data length to 4MB */ | 1884 | /* Tuning mode 1 limits the maximum data length to 4MB */ |
| @@ -1872,10 +1896,10 @@ out: | |||
| 1872 | * try tuning again at a later time, when the re-tuning timer expires. | 1896 | * try tuning again at a later time, when the re-tuning timer expires. |
| 1873 | * So for these controllers, we return 0. Since there might be other | 1897 | * So for these controllers, we return 0. Since there might be other |
| 1874 | * controllers who do not have this capability, we return error for | 1898 | * controllers who do not have this capability, we return error for |
| 1875 | * them. | 1899 | * them. SDHCI_USING_RETUNING_TIMER means the host is currently using |
| 1900 | * a retuning timer to do the retuning for the card. | ||
| 1876 | */ | 1901 | */ |
| 1877 | if (err && host->tuning_count && | 1902 | if (err && (host->flags & SDHCI_USING_RETUNING_TIMER)) |
| 1878 | host->tuning_mode == SDHCI_TUNING_MODE_1) | ||
| 1879 | err = 0; | 1903 | err = 0; |
| 1880 | 1904 | ||
| 1881 | sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier); | 1905 | sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier); |
| @@ -2382,7 +2406,6 @@ out: | |||
| 2382 | int sdhci_suspend_host(struct sdhci_host *host) | 2406 | int sdhci_suspend_host(struct sdhci_host *host) |
| 2383 | { | 2407 | { |
| 2384 | int ret; | 2408 | int ret; |
| 2385 | bool has_tuning_timer; | ||
| 2386 | 2409 | ||
| 2387 | if (host->ops->platform_suspend) | 2410 | if (host->ops->platform_suspend) |
| 2388 | host->ops->platform_suspend(host); | 2411 | host->ops->platform_suspend(host); |
| @@ -2390,16 +2413,14 @@ int sdhci_suspend_host(struct sdhci_host *host) | |||
| 2390 | sdhci_disable_card_detection(host); | 2413 | sdhci_disable_card_detection(host); |
| 2391 | 2414 | ||
| 2392 | /* Disable tuning since we are suspending */ | 2415 | /* Disable tuning since we are suspending */ |
| 2393 | has_tuning_timer = host->version >= SDHCI_SPEC_300 && | 2416 | if (host->flags & SDHCI_USING_RETUNING_TIMER) { |
| 2394 | host->tuning_count && host->tuning_mode == SDHCI_TUNING_MODE_1; | ||
| 2395 | if (has_tuning_timer) { | ||
| 2396 | del_timer_sync(&host->tuning_timer); | 2417 | del_timer_sync(&host->tuning_timer); |
| 2397 | host->flags &= ~SDHCI_NEEDS_RETUNING; | 2418 | host->flags &= ~SDHCI_NEEDS_RETUNING; |
| 2398 | } | 2419 | } |
| 2399 | 2420 | ||
| 2400 | ret = mmc_suspend_host(host->mmc); | 2421 | ret = mmc_suspend_host(host->mmc); |
| 2401 | if (ret) { | 2422 | if (ret) { |
| 2402 | if (has_tuning_timer) { | 2423 | if (host->flags & SDHCI_USING_RETUNING_TIMER) { |
| 2403 | host->flags |= SDHCI_NEEDS_RETUNING; | 2424 | host->flags |= SDHCI_NEEDS_RETUNING; |
| 2404 | mod_timer(&host->tuning_timer, jiffies + | 2425 | mod_timer(&host->tuning_timer, jiffies + |
| 2405 | host->tuning_count * HZ); | 2426 | host->tuning_count * HZ); |
| @@ -2450,8 +2471,7 @@ int sdhci_resume_host(struct sdhci_host *host) | |||
| 2450 | host->ops->platform_resume(host); | 2471 | host->ops->platform_resume(host); |
| 2451 | 2472 | ||
| 2452 | /* Set the re-tuning expiration flag */ | 2473 | /* Set the re-tuning expiration flag */ |
| 2453 | if ((host->version >= SDHCI_SPEC_300) && host->tuning_count && | 2474 | if (host->flags & SDHCI_USING_RETUNING_TIMER) |
| 2454 | (host->tuning_mode == SDHCI_TUNING_MODE_1)) | ||
| 2455 | host->flags |= SDHCI_NEEDS_RETUNING; | 2475 | host->flags |= SDHCI_NEEDS_RETUNING; |
| 2456 | 2476 | ||
| 2457 | return ret; | 2477 | return ret; |
| @@ -2490,8 +2510,7 @@ int sdhci_runtime_suspend_host(struct sdhci_host *host) | |||
| 2490 | int ret = 0; | 2510 | int ret = 0; |
| 2491 | 2511 | ||
| 2492 | /* Disable tuning since we are suspending */ | 2512 | /* Disable tuning since we are suspending */ |
| 2493 | if (host->version >= SDHCI_SPEC_300 && | 2513 | if (host->flags & SDHCI_USING_RETUNING_TIMER) { |
| 2494 | host->tuning_mode == SDHCI_TUNING_MODE_1) { | ||
| 2495 | del_timer_sync(&host->tuning_timer); | 2514 | del_timer_sync(&host->tuning_timer); |
| 2496 | host->flags &= ~SDHCI_NEEDS_RETUNING; | 2515 | host->flags &= ~SDHCI_NEEDS_RETUNING; |
| 2497 | } | 2516 | } |
| @@ -2532,8 +2551,7 @@ int sdhci_runtime_resume_host(struct sdhci_host *host) | |||
| 2532 | sdhci_do_enable_preset_value(host, true); | 2551 | sdhci_do_enable_preset_value(host, true); |
| 2533 | 2552 | ||
| 2534 | /* Set the re-tuning expiration flag */ | 2553 | /* Set the re-tuning expiration flag */ |
| 2535 | if ((host->version >= SDHCI_SPEC_300) && host->tuning_count && | 2554 | if (host->flags & SDHCI_USING_RETUNING_TIMER) |
| 2536 | (host->tuning_mode == SDHCI_TUNING_MODE_1)) | ||
| 2537 | host->flags |= SDHCI_NEEDS_RETUNING; | 2555 | host->flags |= SDHCI_NEEDS_RETUNING; |
| 2538 | 2556 | ||
| 2539 | spin_lock_irqsave(&host->lock, flags); | 2557 | spin_lock_irqsave(&host->lock, flags); |
| @@ -2584,7 +2602,7 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host); | |||
| 2584 | int sdhci_add_host(struct sdhci_host *host) | 2602 | int sdhci_add_host(struct sdhci_host *host) |
| 2585 | { | 2603 | { |
| 2586 | struct mmc_host *mmc; | 2604 | struct mmc_host *mmc; |
| 2587 | u32 caps[2]; | 2605 | u32 caps[2] = {0, 0}; |
| 2588 | u32 max_current_caps; | 2606 | u32 max_current_caps; |
| 2589 | unsigned int ocr_avail; | 2607 | unsigned int ocr_avail; |
| 2590 | int ret; | 2608 | int ret; |
| @@ -2614,8 +2632,10 @@ int sdhci_add_host(struct sdhci_host *host) | |||
| 2614 | caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps : | 2632 | caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps : |
| 2615 | sdhci_readl(host, SDHCI_CAPABILITIES); | 2633 | sdhci_readl(host, SDHCI_CAPABILITIES); |
| 2616 | 2634 | ||
| 2617 | caps[1] = (host->version >= SDHCI_SPEC_300) ? | 2635 | if (host->version >= SDHCI_SPEC_300) |
| 2618 | sdhci_readl(host, SDHCI_CAPABILITIES_1) : 0; | 2636 | caps[1] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? |
| 2637 | host->caps1 : | ||
| 2638 | sdhci_readl(host, SDHCI_CAPABILITIES_1); | ||
| 2619 | 2639 | ||
| 2620 | if (host->quirks & SDHCI_QUIRK_FORCE_DMA) | 2640 | if (host->quirks & SDHCI_QUIRK_FORCE_DMA) |
| 2621 | host->flags |= SDHCI_USE_SDMA; | 2641 | host->flags |= SDHCI_USE_SDMA; |
| @@ -2779,7 +2799,7 @@ int sdhci_add_host(struct sdhci_host *host) | |||
| 2779 | mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; | 2799 | mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; |
| 2780 | 2800 | ||
| 2781 | if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && | 2801 | if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && |
| 2782 | mmc_card_is_removable(mmc)) | 2802 | !(host->mmc->caps & MMC_CAP_NONREMOVABLE)) |
| 2783 | mmc->caps |= MMC_CAP_NEEDS_POLL; | 2803 | mmc->caps |= MMC_CAP_NEEDS_POLL; |
| 2784 | 2804 | ||
| 2785 | /* Any UHS-I mode in caps implies SDR12 and SDR25 support. */ | 2805 | /* Any UHS-I mode in caps implies SDR12 and SDR25 support. */ |
| @@ -2837,6 +2857,30 @@ int sdhci_add_host(struct sdhci_host *host) | |||
| 2837 | SDHCI_RETUNING_MODE_SHIFT; | 2857 | SDHCI_RETUNING_MODE_SHIFT; |
| 2838 | 2858 | ||
| 2839 | ocr_avail = 0; | 2859 | ocr_avail = 0; |
| 2860 | |||
| 2861 | host->vmmc = regulator_get(mmc_dev(mmc), "vmmc"); | ||
| 2862 | if (IS_ERR(host->vmmc)) { | ||
| 2863 | pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc)); | ||
| 2864 | host->vmmc = NULL; | ||
| 2865 | } | ||
| 2866 | |||
| 2867 | #ifdef CONFIG_REGULATOR | ||
| 2868 | if (host->vmmc) { | ||
| 2869 | ret = regulator_is_supported_voltage(host->vmmc, 3300000, | ||
| 2870 | 3300000); | ||
| 2871 | if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_330))) | ||
| 2872 | caps[0] &= ~SDHCI_CAN_VDD_330; | ||
| 2873 | ret = regulator_is_supported_voltage(host->vmmc, 3000000, | ||
| 2874 | 3000000); | ||
| 2875 | if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_300))) | ||
| 2876 | caps[0] &= ~SDHCI_CAN_VDD_300; | ||
| 2877 | ret = regulator_is_supported_voltage(host->vmmc, 1800000, | ||
| 2878 | 1800000); | ||
| 2879 | if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_180))) | ||
| 2880 | caps[0] &= ~SDHCI_CAN_VDD_180; | ||
| 2881 | } | ||
| 2882 | #endif /* CONFIG_REGULATOR */ | ||
| 2883 | |||
| 2840 | /* | 2884 | /* |
| 2841 | * According to SD Host Controller spec v3.00, if the Host System | 2885 | * According to SD Host Controller spec v3.00, if the Host System |
| 2842 | * can afford more than 150mA, Host Driver should set XPC to 1. Also | 2886 | * can afford more than 150mA, Host Driver should set XPC to 1. Also |
| @@ -2845,55 +2889,45 @@ int sdhci_add_host(struct sdhci_host *host) | |||
| 2845 | * value. | 2889 | * value. |
| 2846 | */ | 2890 | */ |
| 2847 | max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT); | 2891 | max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT); |
| 2892 | if (!max_current_caps && host->vmmc) { | ||
| 2893 | u32 curr = regulator_get_current_limit(host->vmmc); | ||
| 2894 | if (curr > 0) { | ||
| 2895 | |||
| 2896 | /* convert to SDHCI_MAX_CURRENT format */ | ||
| 2897 | curr = curr/1000; /* convert to mA */ | ||
| 2898 | curr = curr/SDHCI_MAX_CURRENT_MULTIPLIER; | ||
| 2899 | |||
| 2900 | curr = min_t(u32, curr, SDHCI_MAX_CURRENT_LIMIT); | ||
| 2901 | max_current_caps = | ||
| 2902 | (curr << SDHCI_MAX_CURRENT_330_SHIFT) | | ||
| 2903 | (curr << SDHCI_MAX_CURRENT_300_SHIFT) | | ||
| 2904 | (curr << SDHCI_MAX_CURRENT_180_SHIFT); | ||
| 2905 | } | ||
| 2906 | } | ||
| 2848 | 2907 | ||
| 2849 | if (caps[0] & SDHCI_CAN_VDD_330) { | 2908 | if (caps[0] & SDHCI_CAN_VDD_330) { |
| 2850 | int max_current_330; | ||
| 2851 | |||
| 2852 | ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34; | 2909 | ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34; |
| 2853 | 2910 | ||
| 2854 | max_current_330 = ((max_current_caps & | 2911 | mmc->max_current_330 = ((max_current_caps & |
| 2855 | SDHCI_MAX_CURRENT_330_MASK) >> | 2912 | SDHCI_MAX_CURRENT_330_MASK) >> |
| 2856 | SDHCI_MAX_CURRENT_330_SHIFT) * | 2913 | SDHCI_MAX_CURRENT_330_SHIFT) * |
| 2857 | SDHCI_MAX_CURRENT_MULTIPLIER; | 2914 | SDHCI_MAX_CURRENT_MULTIPLIER; |
| 2858 | |||
| 2859 | if (max_current_330 > 150) | ||
| 2860 | mmc->caps |= MMC_CAP_SET_XPC_330; | ||
| 2861 | } | 2915 | } |
| 2862 | if (caps[0] & SDHCI_CAN_VDD_300) { | 2916 | if (caps[0] & SDHCI_CAN_VDD_300) { |
| 2863 | int max_current_300; | ||
| 2864 | |||
| 2865 | ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31; | 2917 | ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31; |
| 2866 | 2918 | ||
| 2867 | max_current_300 = ((max_current_caps & | 2919 | mmc->max_current_300 = ((max_current_caps & |
| 2868 | SDHCI_MAX_CURRENT_300_MASK) >> | 2920 | SDHCI_MAX_CURRENT_300_MASK) >> |
| 2869 | SDHCI_MAX_CURRENT_300_SHIFT) * | 2921 | SDHCI_MAX_CURRENT_300_SHIFT) * |
| 2870 | SDHCI_MAX_CURRENT_MULTIPLIER; | 2922 | SDHCI_MAX_CURRENT_MULTIPLIER; |
| 2871 | |||
| 2872 | if (max_current_300 > 150) | ||
| 2873 | mmc->caps |= MMC_CAP_SET_XPC_300; | ||
| 2874 | } | 2923 | } |
| 2875 | if (caps[0] & SDHCI_CAN_VDD_180) { | 2924 | if (caps[0] & SDHCI_CAN_VDD_180) { |
| 2876 | int max_current_180; | ||
| 2877 | |||
| 2878 | ocr_avail |= MMC_VDD_165_195; | 2925 | ocr_avail |= MMC_VDD_165_195; |
| 2879 | 2926 | ||
| 2880 | max_current_180 = ((max_current_caps & | 2927 | mmc->max_current_180 = ((max_current_caps & |
| 2881 | SDHCI_MAX_CURRENT_180_MASK) >> | 2928 | SDHCI_MAX_CURRENT_180_MASK) >> |
| 2882 | SDHCI_MAX_CURRENT_180_SHIFT) * | 2929 | SDHCI_MAX_CURRENT_180_SHIFT) * |
| 2883 | SDHCI_MAX_CURRENT_MULTIPLIER; | 2930 | SDHCI_MAX_CURRENT_MULTIPLIER; |
| 2884 | |||
| 2885 | if (max_current_180 > 150) | ||
| 2886 | mmc->caps |= MMC_CAP_SET_XPC_180; | ||
| 2887 | |||
| 2888 | /* Maximum current capabilities of the host at 1.8V */ | ||
| 2889 | if (max_current_180 >= 800) | ||
| 2890 | mmc->caps |= MMC_CAP_MAX_CURRENT_800; | ||
| 2891 | else if (max_current_180 >= 600) | ||
| 2892 | mmc->caps |= MMC_CAP_MAX_CURRENT_600; | ||
| 2893 | else if (max_current_180 >= 400) | ||
| 2894 | mmc->caps |= MMC_CAP_MAX_CURRENT_400; | ||
| 2895 | else | ||
| 2896 | mmc->caps |= MMC_CAP_MAX_CURRENT_200; | ||
| 2897 | } | 2931 | } |
| 2898 | 2932 | ||
| 2899 | mmc->ocr_avail = ocr_avail; | 2933 | mmc->ocr_avail = ocr_avail; |
| @@ -2992,13 +3026,10 @@ int sdhci_add_host(struct sdhci_host *host) | |||
| 2992 | 3026 | ||
| 2993 | ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED, | 3027 | ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED, |
| 2994 | mmc_hostname(mmc), host); | 3028 | mmc_hostname(mmc), host); |
| 2995 | if (ret) | 3029 | if (ret) { |
| 3030 | pr_err("%s: Failed to request IRQ %d: %d\n", | ||
| 3031 | mmc_hostname(mmc), host->irq, ret); | ||
| 2996 | goto untasklet; | 3032 | goto untasklet; |
| 2997 | |||
| 2998 | host->vmmc = regulator_get(mmc_dev(mmc), "vmmc"); | ||
| 2999 | if (IS_ERR(host->vmmc)) { | ||
| 3000 | pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc)); | ||
| 3001 | host->vmmc = NULL; | ||
| 3002 | } | 3033 | } |
| 3003 | 3034 | ||
| 3004 | sdhci_init(host, 0); | 3035 | sdhci_init(host, 0); |
| @@ -3016,8 +3047,11 @@ int sdhci_add_host(struct sdhci_host *host) | |||
| 3016 | host->led.brightness_set = sdhci_led_control; | 3047 | host->led.brightness_set = sdhci_led_control; |
| 3017 | 3048 | ||
| 3018 | ret = led_classdev_register(mmc_dev(mmc), &host->led); | 3049 | ret = led_classdev_register(mmc_dev(mmc), &host->led); |
| 3019 | if (ret) | 3050 | if (ret) { |
| 3051 | pr_err("%s: Failed to register LED device: %d\n", | ||
| 3052 | mmc_hostname(mmc), ret); | ||
| 3020 | goto reset; | 3053 | goto reset; |
| 3054 | } | ||
| 3021 | #endif | 3055 | #endif |
| 3022 | 3056 | ||
| 3023 | mmiowb(); | 3057 | mmiowb(); |
| @@ -3081,8 +3115,6 @@ void sdhci_remove_host(struct sdhci_host *host, int dead) | |||
| 3081 | free_irq(host->irq, host); | 3115 | free_irq(host->irq, host); |
| 3082 | 3116 | ||
| 3083 | del_timer_sync(&host->timer); | 3117 | del_timer_sync(&host->timer); |
| 3084 | if (host->version >= SDHCI_SPEC_300) | ||
| 3085 | del_timer_sync(&host->tuning_timer); | ||
| 3086 | 3118 | ||
| 3087 | tasklet_kill(&host->card_tasklet); | 3119 | tasklet_kill(&host->card_tasklet); |
| 3088 | tasklet_kill(&host->finish_tasklet); | 3120 | tasklet_kill(&host->finish_tasklet); |
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index f761f23d2a28..97653ea8942b 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h | |||
| @@ -205,6 +205,7 @@ | |||
| 205 | #define SDHCI_CAPABILITIES_1 0x44 | 205 | #define SDHCI_CAPABILITIES_1 0x44 |
| 206 | 206 | ||
| 207 | #define SDHCI_MAX_CURRENT 0x48 | 207 | #define SDHCI_MAX_CURRENT 0x48 |
| 208 | #define SDHCI_MAX_CURRENT_LIMIT 0xFF | ||
| 208 | #define SDHCI_MAX_CURRENT_330_MASK 0x0000FF | 209 | #define SDHCI_MAX_CURRENT_330_MASK 0x0000FF |
| 209 | #define SDHCI_MAX_CURRENT_330_SHIFT 0 | 210 | #define SDHCI_MAX_CURRENT_330_SHIFT 0 |
| 210 | #define SDHCI_MAX_CURRENT_300_MASK 0x00FF00 | 211 | #define SDHCI_MAX_CURRENT_300_MASK 0x00FF00 |
diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c index 724b35e85a26..5d8142773fac 100644 --- a/drivers/mmc/host/sh_mmcif.c +++ b/drivers/mmc/host/sh_mmcif.c | |||
| @@ -54,6 +54,8 @@ | |||
| 54 | #include <linux/mmc/mmc.h> | 54 | #include <linux/mmc/mmc.h> |
| 55 | #include <linux/mmc/sdio.h> | 55 | #include <linux/mmc/sdio.h> |
| 56 | #include <linux/mmc/sh_mmcif.h> | 56 | #include <linux/mmc/sh_mmcif.h> |
| 57 | #include <linux/mmc/slot-gpio.h> | ||
| 58 | #include <linux/mod_devicetable.h> | ||
| 57 | #include <linux/pagemap.h> | 59 | #include <linux/pagemap.h> |
| 58 | #include <linux/platform_device.h> | 60 | #include <linux/platform_device.h> |
| 59 | #include <linux/pm_qos.h> | 61 | #include <linux/pm_qos.h> |
| @@ -211,8 +213,6 @@ struct sh_mmcif_host { | |||
| 211 | struct mmc_host *mmc; | 213 | struct mmc_host *mmc; |
| 212 | struct mmc_request *mrq; | 214 | struct mmc_request *mrq; |
| 213 | struct platform_device *pd; | 215 | struct platform_device *pd; |
| 214 | struct sh_dmae_slave dma_slave_tx; | ||
| 215 | struct sh_dmae_slave dma_slave_rx; | ||
| 216 | struct clk *hclk; | 216 | struct clk *hclk; |
| 217 | unsigned int clk; | 217 | unsigned int clk; |
| 218 | int bus_width; | 218 | int bus_width; |
| @@ -371,56 +371,69 @@ static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host) | |||
| 371 | desc, cookie); | 371 | desc, cookie); |
| 372 | } | 372 | } |
| 373 | 373 | ||
| 374 | static bool sh_mmcif_filter(struct dma_chan *chan, void *arg) | ||
| 375 | { | ||
| 376 | dev_dbg(chan->device->dev, "%s: slave data %p\n", __func__, arg); | ||
| 377 | chan->private = arg; | ||
| 378 | return true; | ||
| 379 | } | ||
| 380 | |||
| 381 | static void sh_mmcif_request_dma(struct sh_mmcif_host *host, | 374 | static void sh_mmcif_request_dma(struct sh_mmcif_host *host, |
| 382 | struct sh_mmcif_plat_data *pdata) | 375 | struct sh_mmcif_plat_data *pdata) |
| 383 | { | 376 | { |
| 384 | struct sh_dmae_slave *tx, *rx; | 377 | struct resource *res = platform_get_resource(host->pd, IORESOURCE_MEM, 0); |
| 378 | struct dma_slave_config cfg; | ||
| 379 | dma_cap_mask_t mask; | ||
| 380 | int ret; | ||
| 381 | |||
| 385 | host->dma_active = false; | 382 | host->dma_active = false; |
| 386 | 383 | ||
| 384 | if (!pdata) | ||
| 385 | return; | ||
| 386 | |||
| 387 | if (pdata->slave_id_tx <= 0 || pdata->slave_id_rx <= 0) | ||
| 388 | return; | ||
| 389 | |||
| 387 | /* We can only either use DMA for both Tx and Rx or not use it at all */ | 390 | /* We can only either use DMA for both Tx and Rx or not use it at all */ |
| 388 | if (pdata->dma) { | 391 | dma_cap_zero(mask); |
| 389 | dev_warn(&host->pd->dev, | 392 | dma_cap_set(DMA_SLAVE, mask); |
| 390 | "Update your platform to use embedded DMA slave IDs\n"); | ||
| 391 | tx = &pdata->dma->chan_priv_tx; | ||
| 392 | rx = &pdata->dma->chan_priv_rx; | ||
| 393 | } else { | ||
| 394 | tx = &host->dma_slave_tx; | ||
| 395 | tx->slave_id = pdata->slave_id_tx; | ||
| 396 | rx = &host->dma_slave_rx; | ||
| 397 | rx->slave_id = pdata->slave_id_rx; | ||
| 398 | } | ||
| 399 | if (tx->slave_id > 0 && rx->slave_id > 0) { | ||
| 400 | dma_cap_mask_t mask; | ||
| 401 | 393 | ||
| 402 | dma_cap_zero(mask); | 394 | host->chan_tx = dma_request_channel(mask, shdma_chan_filter, |
| 403 | dma_cap_set(DMA_SLAVE, mask); | 395 | (void *)pdata->slave_id_tx); |
| 396 | dev_dbg(&host->pd->dev, "%s: TX: got channel %p\n", __func__, | ||
| 397 | host->chan_tx); | ||
| 404 | 398 | ||
| 405 | host->chan_tx = dma_request_channel(mask, sh_mmcif_filter, tx); | 399 | if (!host->chan_tx) |
| 406 | dev_dbg(&host->pd->dev, "%s: TX: got channel %p\n", __func__, | 400 | return; |
| 407 | host->chan_tx); | ||
| 408 | 401 | ||
| 409 | if (!host->chan_tx) | 402 | cfg.slave_id = pdata->slave_id_tx; |
| 410 | return; | 403 | cfg.direction = DMA_MEM_TO_DEV; |
| 404 | cfg.dst_addr = res->start + MMCIF_CE_DATA; | ||
| 405 | cfg.src_addr = 0; | ||
| 406 | ret = dmaengine_slave_config(host->chan_tx, &cfg); | ||
| 407 | if (ret < 0) | ||
| 408 | goto ecfgtx; | ||
| 411 | 409 | ||
| 412 | host->chan_rx = dma_request_channel(mask, sh_mmcif_filter, rx); | 410 | host->chan_rx = dma_request_channel(mask, shdma_chan_filter, |
| 413 | dev_dbg(&host->pd->dev, "%s: RX: got channel %p\n", __func__, | 411 | (void *)pdata->slave_id_rx); |
| 414 | host->chan_rx); | 412 | dev_dbg(&host->pd->dev, "%s: RX: got channel %p\n", __func__, |
| 413 | host->chan_rx); | ||
| 415 | 414 | ||
| 416 | if (!host->chan_rx) { | 415 | if (!host->chan_rx) |
| 417 | dma_release_channel(host->chan_tx); | 416 | goto erqrx; |
| 418 | host->chan_tx = NULL; | ||
| 419 | return; | ||
| 420 | } | ||
| 421 | 417 | ||
| 422 | init_completion(&host->dma_complete); | 418 | cfg.slave_id = pdata->slave_id_rx; |
| 423 | } | 419 | cfg.direction = DMA_DEV_TO_MEM; |
| 420 | cfg.dst_addr = 0; | ||
| 421 | cfg.src_addr = res->start + MMCIF_CE_DATA; | ||
| 422 | ret = dmaengine_slave_config(host->chan_rx, &cfg); | ||
| 423 | if (ret < 0) | ||
| 424 | goto ecfgrx; | ||
| 425 | |||
| 426 | init_completion(&host->dma_complete); | ||
| 427 | |||
| 428 | return; | ||
| 429 | |||
| 430 | ecfgrx: | ||
| 431 | dma_release_channel(host->chan_rx); | ||
| 432 | host->chan_rx = NULL; | ||
| 433 | erqrx: | ||
| 434 | ecfgtx: | ||
| 435 | dma_release_channel(host->chan_tx); | ||
| 436 | host->chan_tx = NULL; | ||
| 424 | } | 437 | } |
| 425 | 438 | ||
| 426 | static void sh_mmcif_release_dma(struct sh_mmcif_host *host) | 439 | static void sh_mmcif_release_dma(struct sh_mmcif_host *host) |
| @@ -444,13 +457,14 @@ static void sh_mmcif_release_dma(struct sh_mmcif_host *host) | |||
| 444 | static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk) | 457 | static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk) |
| 445 | { | 458 | { |
| 446 | struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; | 459 | struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; |
| 460 | bool sup_pclk = p ? p->sup_pclk : false; | ||
| 447 | 461 | ||
| 448 | sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE); | 462 | sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE); |
| 449 | sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR); | 463 | sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR); |
| 450 | 464 | ||
| 451 | if (!clk) | 465 | if (!clk) |
| 452 | return; | 466 | return; |
| 453 | if (p->sup_pclk && clk == host->clk) | 467 | if (sup_pclk && clk == host->clk) |
| 454 | sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK); | 468 | sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK); |
| 455 | else | 469 | else |
| 456 | sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR & | 470 | sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR & |
| @@ -892,21 +906,15 @@ static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
| 892 | 906 | ||
| 893 | switch (mrq->cmd->opcode) { | 907 | switch (mrq->cmd->opcode) { |
| 894 | /* MMCIF does not support SD/SDIO command */ | 908 | /* MMCIF does not support SD/SDIO command */ |
| 895 | case SD_IO_SEND_OP_COND: | 909 | case MMC_SLEEP_AWAKE: /* = SD_IO_SEND_OP_COND (5) */ |
| 910 | case MMC_SEND_EXT_CSD: /* = SD_SEND_IF_COND (8) */ | ||
| 911 | if ((mrq->cmd->flags & MMC_CMD_MASK) != MMC_CMD_BCR) | ||
| 912 | break; | ||
| 896 | case MMC_APP_CMD: | 913 | case MMC_APP_CMD: |
| 897 | host->state = STATE_IDLE; | 914 | host->state = STATE_IDLE; |
| 898 | mrq->cmd->error = -ETIMEDOUT; | 915 | mrq->cmd->error = -ETIMEDOUT; |
| 899 | mmc_request_done(mmc, mrq); | 916 | mmc_request_done(mmc, mrq); |
| 900 | return; | 917 | return; |
| 901 | case MMC_SEND_EXT_CSD: /* = SD_SEND_IF_COND (8) */ | ||
| 902 | if (!mrq->data) { | ||
| 903 | /* send_if_cond cmd (not support) */ | ||
| 904 | host->state = STATE_IDLE; | ||
| 905 | mrq->cmd->error = -ETIMEDOUT; | ||
| 906 | mmc_request_done(mmc, mrq); | ||
| 907 | return; | ||
| 908 | } | ||
| 909 | break; | ||
| 910 | default: | 918 | default: |
| 911 | break; | 919 | break; |
| 912 | } | 920 | } |
| @@ -916,10 +924,35 @@ static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
| 916 | sh_mmcif_start_cmd(host, mrq); | 924 | sh_mmcif_start_cmd(host, mrq); |
| 917 | } | 925 | } |
| 918 | 926 | ||
| 927 | static int sh_mmcif_clk_update(struct sh_mmcif_host *host) | ||
| 928 | { | ||
| 929 | int ret = clk_enable(host->hclk); | ||
| 930 | |||
| 931 | if (!ret) { | ||
| 932 | host->clk = clk_get_rate(host->hclk); | ||
| 933 | host->mmc->f_max = host->clk / 2; | ||
| 934 | host->mmc->f_min = host->clk / 512; | ||
| 935 | } | ||
| 936 | |||
| 937 | return ret; | ||
| 938 | } | ||
| 939 | |||
| 940 | static void sh_mmcif_set_power(struct sh_mmcif_host *host, struct mmc_ios *ios) | ||
| 941 | { | ||
| 942 | struct sh_mmcif_plat_data *pd = host->pd->dev.platform_data; | ||
| 943 | struct mmc_host *mmc = host->mmc; | ||
| 944 | |||
| 945 | if (pd && pd->set_pwr) | ||
| 946 | pd->set_pwr(host->pd, ios->power_mode != MMC_POWER_OFF); | ||
| 947 | if (!IS_ERR(mmc->supply.vmmc)) | ||
| 948 | /* Errors ignored... */ | ||
| 949 | mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, | ||
| 950 | ios->power_mode ? ios->vdd : 0); | ||
| 951 | } | ||
| 952 | |||
| 919 | static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | 953 | static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
| 920 | { | 954 | { |
| 921 | struct sh_mmcif_host *host = mmc_priv(mmc); | 955 | struct sh_mmcif_host *host = mmc_priv(mmc); |
| 922 | struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; | ||
| 923 | unsigned long flags; | 956 | unsigned long flags; |
| 924 | 957 | ||
| 925 | spin_lock_irqsave(&host->lock, flags); | 958 | spin_lock_irqsave(&host->lock, flags); |
| @@ -937,6 +970,7 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
| 937 | sh_mmcif_request_dma(host, host->pd->dev.platform_data); | 970 | sh_mmcif_request_dma(host, host->pd->dev.platform_data); |
| 938 | host->card_present = true; | 971 | host->card_present = true; |
| 939 | } | 972 | } |
| 973 | sh_mmcif_set_power(host, ios); | ||
| 940 | } else if (ios->power_mode == MMC_POWER_OFF || !ios->clock) { | 974 | } else if (ios->power_mode == MMC_POWER_OFF || !ios->clock) { |
| 941 | /* clock stop */ | 975 | /* clock stop */ |
| 942 | sh_mmcif_clock_control(host, 0); | 976 | sh_mmcif_clock_control(host, 0); |
| @@ -948,9 +982,10 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
| 948 | } | 982 | } |
| 949 | if (host->power) { | 983 | if (host->power) { |
| 950 | pm_runtime_put(&host->pd->dev); | 984 | pm_runtime_put(&host->pd->dev); |
| 985 | clk_disable(host->hclk); | ||
| 951 | host->power = false; | 986 | host->power = false; |
| 952 | if (p->down_pwr && ios->power_mode == MMC_POWER_OFF) | 987 | if (ios->power_mode == MMC_POWER_OFF) |
| 953 | p->down_pwr(host->pd); | 988 | sh_mmcif_set_power(host, ios); |
| 954 | } | 989 | } |
| 955 | host->state = STATE_IDLE; | 990 | host->state = STATE_IDLE; |
| 956 | return; | 991 | return; |
| @@ -958,8 +993,7 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
| 958 | 993 | ||
| 959 | if (ios->clock) { | 994 | if (ios->clock) { |
| 960 | if (!host->power) { | 995 | if (!host->power) { |
| 961 | if (p->set_pwr) | 996 | sh_mmcif_clk_update(host); |
| 962 | p->set_pwr(host->pd, ios->power_mode); | ||
| 963 | pm_runtime_get_sync(&host->pd->dev); | 997 | pm_runtime_get_sync(&host->pd->dev); |
| 964 | host->power = true; | 998 | host->power = true; |
| 965 | sh_mmcif_sync_reset(host); | 999 | sh_mmcif_sync_reset(host); |
| @@ -975,8 +1009,12 @@ static int sh_mmcif_get_cd(struct mmc_host *mmc) | |||
| 975 | { | 1009 | { |
| 976 | struct sh_mmcif_host *host = mmc_priv(mmc); | 1010 | struct sh_mmcif_host *host = mmc_priv(mmc); |
| 977 | struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; | 1011 | struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; |
| 1012 | int ret = mmc_gpio_get_cd(mmc); | ||
| 1013 | |||
| 1014 | if (ret >= 0) | ||
| 1015 | return ret; | ||
| 978 | 1016 | ||
| 979 | if (!p->get_cd) | 1017 | if (!p || !p->get_cd) |
| 980 | return -ENOSYS; | 1018 | return -ENOSYS; |
| 981 | else | 1019 | else |
| 982 | return p->get_cd(host->pd); | 1020 | return p->get_cd(host->pd); |
| @@ -1242,12 +1280,28 @@ static void mmcif_timeout_work(struct work_struct *work) | |||
| 1242 | mmc_request_done(host->mmc, mrq); | 1280 | mmc_request_done(host->mmc, mrq); |
| 1243 | } | 1281 | } |
| 1244 | 1282 | ||
| 1283 | static void sh_mmcif_init_ocr(struct sh_mmcif_host *host) | ||
| 1284 | { | ||
| 1285 | struct sh_mmcif_plat_data *pd = host->pd->dev.platform_data; | ||
| 1286 | struct mmc_host *mmc = host->mmc; | ||
| 1287 | |||
| 1288 | mmc_regulator_get_supply(mmc); | ||
| 1289 | |||
| 1290 | if (!pd) | ||
| 1291 | return; | ||
| 1292 | |||
| 1293 | if (!mmc->ocr_avail) | ||
| 1294 | mmc->ocr_avail = pd->ocr; | ||
| 1295 | else if (pd->ocr) | ||
| 1296 | dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n"); | ||
| 1297 | } | ||
| 1298 | |||
| 1245 | static int __devinit sh_mmcif_probe(struct platform_device *pdev) | 1299 | static int __devinit sh_mmcif_probe(struct platform_device *pdev) |
| 1246 | { | 1300 | { |
| 1247 | int ret = 0, irq[2]; | 1301 | int ret = 0, irq[2]; |
| 1248 | struct mmc_host *mmc; | 1302 | struct mmc_host *mmc; |
| 1249 | struct sh_mmcif_host *host; | 1303 | struct sh_mmcif_host *host; |
| 1250 | struct sh_mmcif_plat_data *pd; | 1304 | struct sh_mmcif_plat_data *pd = pdev->dev.platform_data; |
| 1251 | struct resource *res; | 1305 | struct resource *res; |
| 1252 | void __iomem *reg; | 1306 | void __iomem *reg; |
| 1253 | char clk_name[8]; | 1307 | char clk_name[8]; |
| @@ -1268,42 +1322,26 @@ static int __devinit sh_mmcif_probe(struct platform_device *pdev) | |||
| 1268 | dev_err(&pdev->dev, "ioremap error.\n"); | 1322 | dev_err(&pdev->dev, "ioremap error.\n"); |
| 1269 | return -ENOMEM; | 1323 | return -ENOMEM; |
| 1270 | } | 1324 | } |
| 1271 | pd = pdev->dev.platform_data; | 1325 | |
| 1272 | if (!pd) { | ||
| 1273 | dev_err(&pdev->dev, "sh_mmcif plat data error.\n"); | ||
| 1274 | ret = -ENXIO; | ||
| 1275 | goto clean_up; | ||
| 1276 | } | ||
| 1277 | mmc = mmc_alloc_host(sizeof(struct sh_mmcif_host), &pdev->dev); | 1326 | mmc = mmc_alloc_host(sizeof(struct sh_mmcif_host), &pdev->dev); |
| 1278 | if (!mmc) { | 1327 | if (!mmc) { |
| 1279 | ret = -ENOMEM; | 1328 | ret = -ENOMEM; |
| 1280 | goto clean_up; | 1329 | goto ealloch; |
| 1281 | } | 1330 | } |
| 1282 | host = mmc_priv(mmc); | 1331 | host = mmc_priv(mmc); |
| 1283 | host->mmc = mmc; | 1332 | host->mmc = mmc; |
| 1284 | host->addr = reg; | 1333 | host->addr = reg; |
| 1285 | host->timeout = 1000; | 1334 | host->timeout = 1000; |
| 1286 | 1335 | ||
| 1287 | snprintf(clk_name, sizeof(clk_name), "mmc%d", pdev->id); | ||
| 1288 | host->hclk = clk_get(&pdev->dev, clk_name); | ||
| 1289 | if (IS_ERR(host->hclk)) { | ||
| 1290 | dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name); | ||
| 1291 | ret = PTR_ERR(host->hclk); | ||
| 1292 | goto clean_up1; | ||
| 1293 | } | ||
| 1294 | clk_enable(host->hclk); | ||
| 1295 | host->clk = clk_get_rate(host->hclk); | ||
| 1296 | host->pd = pdev; | 1336 | host->pd = pdev; |
| 1297 | 1337 | ||
| 1298 | spin_lock_init(&host->lock); | 1338 | spin_lock_init(&host->lock); |
| 1299 | 1339 | ||
| 1300 | mmc->ops = &sh_mmcif_ops; | 1340 | mmc->ops = &sh_mmcif_ops; |
| 1301 | mmc->f_max = host->clk / 2; | 1341 | sh_mmcif_init_ocr(host); |
| 1302 | mmc->f_min = host->clk / 512; | 1342 | |
| 1303 | if (pd->ocr) | ||
| 1304 | mmc->ocr_avail = pd->ocr; | ||
| 1305 | mmc->caps = MMC_CAP_MMC_HIGHSPEED; | 1343 | mmc->caps = MMC_CAP_MMC_HIGHSPEED; |
| 1306 | if (pd->caps) | 1344 | if (pd && pd->caps) |
| 1307 | mmc->caps |= pd->caps; | 1345 | mmc->caps |= pd->caps; |
| 1308 | mmc->max_segs = 32; | 1346 | mmc->max_segs = 32; |
| 1309 | mmc->max_blk_size = 512; | 1347 | mmc->max_blk_size = 512; |
| @@ -1311,34 +1349,52 @@ static int __devinit sh_mmcif_probe(struct platform_device *pdev) | |||
| 1311 | mmc->max_blk_count = mmc->max_req_size / mmc->max_blk_size; | 1349 | mmc->max_blk_count = mmc->max_req_size / mmc->max_blk_size; |
| 1312 | mmc->max_seg_size = mmc->max_req_size; | 1350 | mmc->max_seg_size = mmc->max_req_size; |
| 1313 | 1351 | ||
| 1314 | sh_mmcif_sync_reset(host); | ||
| 1315 | platform_set_drvdata(pdev, host); | 1352 | platform_set_drvdata(pdev, host); |
| 1316 | 1353 | ||
| 1317 | pm_runtime_enable(&pdev->dev); | 1354 | pm_runtime_enable(&pdev->dev); |
| 1318 | host->power = false; | 1355 | host->power = false; |
| 1319 | 1356 | ||
| 1357 | snprintf(clk_name, sizeof(clk_name), "mmc%d", pdev->id); | ||
| 1358 | host->hclk = clk_get(&pdev->dev, clk_name); | ||
| 1359 | if (IS_ERR(host->hclk)) { | ||
| 1360 | ret = PTR_ERR(host->hclk); | ||
| 1361 | dev_err(&pdev->dev, "cannot get clock \"%s\": %d\n", clk_name, ret); | ||
| 1362 | goto eclkget; | ||
| 1363 | } | ||
| 1364 | ret = sh_mmcif_clk_update(host); | ||
| 1365 | if (ret < 0) | ||
| 1366 | goto eclkupdate; | ||
| 1367 | |||
| 1320 | ret = pm_runtime_resume(&pdev->dev); | 1368 | ret = pm_runtime_resume(&pdev->dev); |
| 1321 | if (ret < 0) | 1369 | if (ret < 0) |
| 1322 | goto clean_up2; | 1370 | goto eresume; |
| 1323 | 1371 | ||
| 1324 | INIT_DELAYED_WORK(&host->timeout_work, mmcif_timeout_work); | 1372 | INIT_DELAYED_WORK(&host->timeout_work, mmcif_timeout_work); |
| 1325 | 1373 | ||
| 1374 | sh_mmcif_sync_reset(host); | ||
| 1326 | sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); | 1375 | sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); |
| 1327 | 1376 | ||
| 1328 | ret = request_threaded_irq(irq[0], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:error", host); | 1377 | ret = request_threaded_irq(irq[0], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:error", host); |
| 1329 | if (ret) { | 1378 | if (ret) { |
| 1330 | dev_err(&pdev->dev, "request_irq error (sh_mmc:error)\n"); | 1379 | dev_err(&pdev->dev, "request_irq error (sh_mmc:error)\n"); |
| 1331 | goto clean_up3; | 1380 | goto ereqirq0; |
| 1332 | } | 1381 | } |
| 1333 | ret = request_threaded_irq(irq[1], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:int", host); | 1382 | ret = request_threaded_irq(irq[1], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:int", host); |
| 1334 | if (ret) { | 1383 | if (ret) { |
| 1335 | dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n"); | 1384 | dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n"); |
| 1336 | goto clean_up4; | 1385 | goto ereqirq1; |
| 1386 | } | ||
| 1387 | |||
| 1388 | if (pd && pd->use_cd_gpio) { | ||
| 1389 | ret = mmc_gpio_request_cd(mmc, pd->cd_gpio); | ||
| 1390 | if (ret < 0) | ||
| 1391 | goto erqcd; | ||
| 1337 | } | 1392 | } |
| 1338 | 1393 | ||
| 1394 | clk_disable(host->hclk); | ||
| 1339 | ret = mmc_add_host(mmc); | 1395 | ret = mmc_add_host(mmc); |
| 1340 | if (ret < 0) | 1396 | if (ret < 0) |
| 1341 | goto clean_up5; | 1397 | goto emmcaddh; |
| 1342 | 1398 | ||
| 1343 | dev_pm_qos_expose_latency_limit(&pdev->dev, 100); | 1399 | dev_pm_qos_expose_latency_limit(&pdev->dev, 100); |
| 1344 | 1400 | ||
| @@ -1347,33 +1403,42 @@ static int __devinit sh_mmcif_probe(struct platform_device *pdev) | |||
| 1347 | sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0x0000ffff); | 1403 | sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0x0000ffff); |
| 1348 | return ret; | 1404 | return ret; |
| 1349 | 1405 | ||
| 1350 | clean_up5: | 1406 | emmcaddh: |
| 1407 | if (pd && pd->use_cd_gpio) | ||
| 1408 | mmc_gpio_free_cd(mmc); | ||
| 1409 | erqcd: | ||
| 1351 | free_irq(irq[1], host); | 1410 | free_irq(irq[1], host); |
| 1352 | clean_up4: | 1411 | ereqirq1: |
| 1353 | free_irq(irq[0], host); | 1412 | free_irq(irq[0], host); |
| 1354 | clean_up3: | 1413 | ereqirq0: |
| 1355 | pm_runtime_suspend(&pdev->dev); | 1414 | pm_runtime_suspend(&pdev->dev); |
| 1356 | clean_up2: | 1415 | eresume: |
| 1357 | pm_runtime_disable(&pdev->dev); | ||
| 1358 | clk_disable(host->hclk); | 1416 | clk_disable(host->hclk); |
| 1359 | clean_up1: | 1417 | eclkupdate: |
| 1418 | clk_put(host->hclk); | ||
| 1419 | eclkget: | ||
| 1420 | pm_runtime_disable(&pdev->dev); | ||
| 1360 | mmc_free_host(mmc); | 1421 | mmc_free_host(mmc); |
| 1361 | clean_up: | 1422 | ealloch: |
| 1362 | if (reg) | 1423 | iounmap(reg); |
| 1363 | iounmap(reg); | ||
| 1364 | return ret; | 1424 | return ret; |
| 1365 | } | 1425 | } |
| 1366 | 1426 | ||
| 1367 | static int __devexit sh_mmcif_remove(struct platform_device *pdev) | 1427 | static int __devexit sh_mmcif_remove(struct platform_device *pdev) |
| 1368 | { | 1428 | { |
| 1369 | struct sh_mmcif_host *host = platform_get_drvdata(pdev); | 1429 | struct sh_mmcif_host *host = platform_get_drvdata(pdev); |
| 1430 | struct sh_mmcif_plat_data *pd = pdev->dev.platform_data; | ||
| 1370 | int irq[2]; | 1431 | int irq[2]; |
| 1371 | 1432 | ||
| 1372 | host->dying = true; | 1433 | host->dying = true; |
| 1434 | clk_enable(host->hclk); | ||
| 1373 | pm_runtime_get_sync(&pdev->dev); | 1435 | pm_runtime_get_sync(&pdev->dev); |
| 1374 | 1436 | ||
| 1375 | dev_pm_qos_hide_latency_limit(&pdev->dev); | 1437 | dev_pm_qos_hide_latency_limit(&pdev->dev); |
| 1376 | 1438 | ||
| 1439 | if (pd && pd->use_cd_gpio) | ||
| 1440 | mmc_gpio_free_cd(host->mmc); | ||
| 1441 | |||
| 1377 | mmc_remove_host(host->mmc); | 1442 | mmc_remove_host(host->mmc); |
| 1378 | sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); | 1443 | sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); |
| 1379 | 1444 | ||
| @@ -1395,9 +1460,9 @@ static int __devexit sh_mmcif_remove(struct platform_device *pdev) | |||
| 1395 | 1460 | ||
| 1396 | platform_set_drvdata(pdev, NULL); | 1461 | platform_set_drvdata(pdev, NULL); |
| 1397 | 1462 | ||
| 1398 | clk_disable(host->hclk); | ||
| 1399 | mmc_free_host(host->mmc); | 1463 | mmc_free_host(host->mmc); |
| 1400 | pm_runtime_put_sync(&pdev->dev); | 1464 | pm_runtime_put_sync(&pdev->dev); |
| 1465 | clk_disable(host->hclk); | ||
| 1401 | pm_runtime_disable(&pdev->dev); | 1466 | pm_runtime_disable(&pdev->dev); |
| 1402 | 1467 | ||
| 1403 | return 0; | 1468 | return 0; |
| @@ -1406,24 +1471,18 @@ static int __devexit sh_mmcif_remove(struct platform_device *pdev) | |||
| 1406 | #ifdef CONFIG_PM | 1471 | #ifdef CONFIG_PM |
| 1407 | static int sh_mmcif_suspend(struct device *dev) | 1472 | static int sh_mmcif_suspend(struct device *dev) |
| 1408 | { | 1473 | { |
| 1409 | struct platform_device *pdev = to_platform_device(dev); | 1474 | struct sh_mmcif_host *host = dev_get_drvdata(dev); |
| 1410 | struct sh_mmcif_host *host = platform_get_drvdata(pdev); | ||
| 1411 | int ret = mmc_suspend_host(host->mmc); | 1475 | int ret = mmc_suspend_host(host->mmc); |
| 1412 | 1476 | ||
| 1413 | if (!ret) { | 1477 | if (!ret) |
| 1414 | sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); | 1478 | sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); |
| 1415 | clk_disable(host->hclk); | ||
| 1416 | } | ||
| 1417 | 1479 | ||
| 1418 | return ret; | 1480 | return ret; |
| 1419 | } | 1481 | } |
| 1420 | 1482 | ||
| 1421 | static int sh_mmcif_resume(struct device *dev) | 1483 | static int sh_mmcif_resume(struct device *dev) |
| 1422 | { | 1484 | { |
| 1423 | struct platform_device *pdev = to_platform_device(dev); | 1485 | struct sh_mmcif_host *host = dev_get_drvdata(dev); |
| 1424 | struct sh_mmcif_host *host = platform_get_drvdata(pdev); | ||
| 1425 | |||
| 1426 | clk_enable(host->hclk); | ||
| 1427 | 1486 | ||
| 1428 | return mmc_resume_host(host->mmc); | 1487 | return mmc_resume_host(host->mmc); |
| 1429 | } | 1488 | } |
| @@ -1432,6 +1491,12 @@ static int sh_mmcif_resume(struct device *dev) | |||
| 1432 | #define sh_mmcif_resume NULL | 1491 | #define sh_mmcif_resume NULL |
| 1433 | #endif /* CONFIG_PM */ | 1492 | #endif /* CONFIG_PM */ |
| 1434 | 1493 | ||
| 1494 | static const struct of_device_id mmcif_of_match[] = { | ||
| 1495 | { .compatible = "renesas,sh-mmcif" }, | ||
| 1496 | { } | ||
| 1497 | }; | ||
| 1498 | MODULE_DEVICE_TABLE(of, mmcif_of_match); | ||
| 1499 | |||
| 1435 | static const struct dev_pm_ops sh_mmcif_dev_pm_ops = { | 1500 | static const struct dev_pm_ops sh_mmcif_dev_pm_ops = { |
| 1436 | .suspend = sh_mmcif_suspend, | 1501 | .suspend = sh_mmcif_suspend, |
| 1437 | .resume = sh_mmcif_resume, | 1502 | .resume = sh_mmcif_resume, |
| @@ -1443,6 +1508,8 @@ static struct platform_driver sh_mmcif_driver = { | |||
| 1443 | .driver = { | 1508 | .driver = { |
| 1444 | .name = DRIVER_NAME, | 1509 | .name = DRIVER_NAME, |
| 1445 | .pm = &sh_mmcif_dev_pm_ops, | 1510 | .pm = &sh_mmcif_dev_pm_ops, |
| 1511 | .owner = THIS_MODULE, | ||
| 1512 | .of_match_table = mmcif_of_match, | ||
| 1446 | }, | 1513 | }, |
| 1447 | }; | 1514 | }; |
| 1448 | 1515 | ||
diff --git a/drivers/mmc/host/sh_mobile_sdhi.c b/drivers/mmc/host/sh_mobile_sdhi.c index 934b68e9efc3..0bdc146178db 100644 --- a/drivers/mmc/host/sh_mobile_sdhi.c +++ b/drivers/mmc/host/sh_mobile_sdhi.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include <linux/kernel.h> | 21 | #include <linux/kernel.h> |
| 22 | #include <linux/clk.h> | 22 | #include <linux/clk.h> |
| 23 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
| 24 | #include <linux/mod_devicetable.h> | ||
| 24 | #include <linux/module.h> | 25 | #include <linux/module.h> |
| 25 | #include <linux/platform_device.h> | 26 | #include <linux/platform_device.h> |
| 26 | #include <linux/mmc/host.h> | 27 | #include <linux/mmc/host.h> |
| @@ -39,22 +40,39 @@ struct sh_mobile_sdhi { | |||
| 39 | struct tmio_mmc_dma dma_priv; | 40 | struct tmio_mmc_dma dma_priv; |
| 40 | }; | 41 | }; |
| 41 | 42 | ||
| 43 | static int sh_mobile_sdhi_clk_enable(struct platform_device *pdev, unsigned int *f) | ||
| 44 | { | ||
| 45 | struct mmc_host *mmc = dev_get_drvdata(&pdev->dev); | ||
| 46 | struct tmio_mmc_host *host = mmc_priv(mmc); | ||
| 47 | struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data); | ||
| 48 | int ret = clk_enable(priv->clk); | ||
| 49 | if (ret < 0) | ||
| 50 | return ret; | ||
| 51 | |||
| 52 | *f = clk_get_rate(priv->clk); | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | static void sh_mobile_sdhi_clk_disable(struct platform_device *pdev) | ||
| 57 | { | ||
| 58 | struct mmc_host *mmc = dev_get_drvdata(&pdev->dev); | ||
| 59 | struct tmio_mmc_host *host = mmc_priv(mmc); | ||
| 60 | struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data); | ||
| 61 | clk_disable(priv->clk); | ||
| 62 | } | ||
| 63 | |||
| 42 | static void sh_mobile_sdhi_set_pwr(struct platform_device *pdev, int state) | 64 | static void sh_mobile_sdhi_set_pwr(struct platform_device *pdev, int state) |
| 43 | { | 65 | { |
| 44 | struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; | 66 | struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; |
| 45 | 67 | ||
| 46 | if (p && p->set_pwr) | 68 | p->set_pwr(pdev, state); |
| 47 | p->set_pwr(pdev, state); | ||
| 48 | } | 69 | } |
| 49 | 70 | ||
| 50 | static int sh_mobile_sdhi_get_cd(struct platform_device *pdev) | 71 | static int sh_mobile_sdhi_get_cd(struct platform_device *pdev) |
| 51 | { | 72 | { |
| 52 | struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; | 73 | struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; |
| 53 | 74 | ||
| 54 | if (p && p->get_cd) | 75 | return p->get_cd(pdev); |
| 55 | return p->get_cd(pdev); | ||
| 56 | else | ||
| 57 | return -ENOSYS; | ||
| 58 | } | 76 | } |
| 59 | 77 | ||
| 60 | static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host) | 78 | static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host) |
| @@ -116,12 +134,14 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev) | |||
| 116 | } | 134 | } |
| 117 | 135 | ||
| 118 | mmc_data = &priv->mmc_data; | 136 | mmc_data = &priv->mmc_data; |
| 119 | p->pdata = mmc_data; | ||
| 120 | 137 | ||
| 121 | if (p->init) { | 138 | if (p) { |
| 122 | ret = p->init(pdev, &sdhi_ops); | 139 | p->pdata = mmc_data; |
| 123 | if (ret) | 140 | if (p->init) { |
| 124 | goto einit; | 141 | ret = p->init(pdev, &sdhi_ops); |
| 142 | if (ret) | ||
| 143 | goto einit; | ||
| 144 | } | ||
| 125 | } | 145 | } |
| 126 | 146 | ||
| 127 | snprintf(clk_name, sizeof(clk_name), "sdhi%d", pdev->id); | 147 | snprintf(clk_name, sizeof(clk_name), "sdhi%d", pdev->id); |
| @@ -132,9 +152,8 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev) | |||
| 132 | goto eclkget; | 152 | goto eclkget; |
| 133 | } | 153 | } |
| 134 | 154 | ||
| 135 | mmc_data->hclk = clk_get_rate(priv->clk); | 155 | mmc_data->clk_enable = sh_mobile_sdhi_clk_enable; |
| 136 | mmc_data->set_pwr = sh_mobile_sdhi_set_pwr; | 156 | mmc_data->clk_disable = sh_mobile_sdhi_clk_disable; |
| 137 | mmc_data->get_cd = sh_mobile_sdhi_get_cd; | ||
| 138 | mmc_data->capabilities = MMC_CAP_MMC_HIGHSPEED; | 157 | mmc_data->capabilities = MMC_CAP_MMC_HIGHSPEED; |
| 139 | if (p) { | 158 | if (p) { |
| 140 | mmc_data->flags = p->tmio_flags; | 159 | mmc_data->flags = p->tmio_flags; |
| @@ -142,13 +161,18 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev) | |||
| 142 | mmc_data->write16_hook = sh_mobile_sdhi_write16_hook; | 161 | mmc_data->write16_hook = sh_mobile_sdhi_write16_hook; |
| 143 | mmc_data->ocr_mask = p->tmio_ocr_mask; | 162 | mmc_data->ocr_mask = p->tmio_ocr_mask; |
| 144 | mmc_data->capabilities |= p->tmio_caps; | 163 | mmc_data->capabilities |= p->tmio_caps; |
| 164 | mmc_data->capabilities2 |= p->tmio_caps2; | ||
| 145 | mmc_data->cd_gpio = p->cd_gpio; | 165 | mmc_data->cd_gpio = p->cd_gpio; |
| 166 | if (p->set_pwr) | ||
| 167 | mmc_data->set_pwr = sh_mobile_sdhi_set_pwr; | ||
| 168 | if (p->get_cd) | ||
| 169 | mmc_data->get_cd = sh_mobile_sdhi_get_cd; | ||
| 146 | 170 | ||
| 147 | if (p->dma_slave_tx > 0 && p->dma_slave_rx > 0) { | 171 | if (p->dma_slave_tx > 0 && p->dma_slave_rx > 0) { |
| 148 | priv->param_tx.slave_id = p->dma_slave_tx; | 172 | priv->param_tx.shdma_slave.slave_id = p->dma_slave_tx; |
| 149 | priv->param_rx.slave_id = p->dma_slave_rx; | 173 | priv->param_rx.shdma_slave.slave_id = p->dma_slave_rx; |
| 150 | priv->dma_priv.chan_priv_tx = &priv->param_tx; | 174 | priv->dma_priv.chan_priv_tx = &priv->param_tx.shdma_slave; |
| 151 | priv->dma_priv.chan_priv_rx = &priv->param_rx; | 175 | priv->dma_priv.chan_priv_rx = &priv->param_rx.shdma_slave; |
| 152 | priv->dma_priv.alignment_shift = 1; /* 2-byte alignment */ | 176 | priv->dma_priv.alignment_shift = 1; /* 2-byte alignment */ |
| 153 | mmc_data->dma = &priv->dma_priv; | 177 | mmc_data->dma = &priv->dma_priv; |
| 154 | } | 178 | } |
| @@ -248,7 +272,7 @@ eirq_card_detect: | |||
| 248 | eprobe: | 272 | eprobe: |
| 249 | clk_put(priv->clk); | 273 | clk_put(priv->clk); |
| 250 | eclkget: | 274 | eclkget: |
| 251 | if (p->cleanup) | 275 | if (p && p->cleanup) |
| 252 | p->cleanup(pdev); | 276 | p->cleanup(pdev); |
| 253 | einit: | 277 | einit: |
| 254 | kfree(priv); | 278 | kfree(priv); |
| @@ -263,7 +287,8 @@ static int sh_mobile_sdhi_remove(struct platform_device *pdev) | |||
| 263 | struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; | 287 | struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; |
| 264 | int i = 0, irq; | 288 | int i = 0, irq; |
| 265 | 289 | ||
| 266 | p->pdata = NULL; | 290 | if (p) |
| 291 | p->pdata = NULL; | ||
| 267 | 292 | ||
| 268 | tmio_mmc_host_remove(host); | 293 | tmio_mmc_host_remove(host); |
| 269 | 294 | ||
| @@ -276,7 +301,7 @@ static int sh_mobile_sdhi_remove(struct platform_device *pdev) | |||
| 276 | 301 | ||
| 277 | clk_put(priv->clk); | 302 | clk_put(priv->clk); |
| 278 | 303 | ||
| 279 | if (p->cleanup) | 304 | if (p && p->cleanup) |
| 280 | p->cleanup(pdev); | 305 | p->cleanup(pdev); |
| 281 | 306 | ||
| 282 | kfree(priv); | 307 | kfree(priv); |
| @@ -291,11 +316,18 @@ static const struct dev_pm_ops tmio_mmc_dev_pm_ops = { | |||
| 291 | .runtime_resume = tmio_mmc_host_runtime_resume, | 316 | .runtime_resume = tmio_mmc_host_runtime_resume, |
| 292 | }; | 317 | }; |
| 293 | 318 | ||
| 319 | static const struct of_device_id sh_mobile_sdhi_of_match[] = { | ||
| 320 | { .compatible = "renesas,shmobile-sdhi" }, | ||
| 321 | { } | ||
| 322 | }; | ||
| 323 | MODULE_DEVICE_TABLE(of, sh_mobile_sdhi_of_match); | ||
| 324 | |||
| 294 | static struct platform_driver sh_mobile_sdhi_driver = { | 325 | static struct platform_driver sh_mobile_sdhi_driver = { |
| 295 | .driver = { | 326 | .driver = { |
| 296 | .name = "sh_mobile_sdhi", | 327 | .name = "sh_mobile_sdhi", |
| 297 | .owner = THIS_MODULE, | 328 | .owner = THIS_MODULE, |
| 298 | .pm = &tmio_mmc_dev_pm_ops, | 329 | .pm = &tmio_mmc_dev_pm_ops, |
| 330 | .of_match_table = sh_mobile_sdhi_of_match, | ||
| 299 | }, | 331 | }, |
| 300 | .probe = sh_mobile_sdhi_probe, | 332 | .probe = sh_mobile_sdhi_probe, |
| 301 | .remove = __devexit_p(sh_mobile_sdhi_remove), | 333 | .remove = __devexit_p(sh_mobile_sdhi_remove), |
diff --git a/drivers/mmc/host/tmio_mmc_pio.c b/drivers/mmc/host/tmio_mmc_pio.c index 9a7996ade58e..0d8a9bbe30be 100644 --- a/drivers/mmc/host/tmio_mmc_pio.c +++ b/drivers/mmc/host/tmio_mmc_pio.c | |||
| @@ -34,8 +34,9 @@ | |||
| 34 | #include <linux/io.h> | 34 | #include <linux/io.h> |
| 35 | #include <linux/irq.h> | 35 | #include <linux/irq.h> |
| 36 | #include <linux/mfd/tmio.h> | 36 | #include <linux/mfd/tmio.h> |
| 37 | #include <linux/mmc/cd-gpio.h> | ||
| 38 | #include <linux/mmc/host.h> | 37 | #include <linux/mmc/host.h> |
| 38 | #include <linux/mmc/mmc.h> | ||
| 39 | #include <linux/mmc/slot-gpio.h> | ||
| 39 | #include <linux/mmc/tmio.h> | 40 | #include <linux/mmc/tmio.h> |
| 40 | #include <linux/module.h> | 41 | #include <linux/module.h> |
| 41 | #include <linux/pagemap.h> | 42 | #include <linux/pagemap.h> |
| @@ -305,8 +306,8 @@ static int tmio_mmc_start_command(struct tmio_mmc_host *host, struct mmc_command | |||
| 305 | int c = cmd->opcode; | 306 | int c = cmd->opcode; |
| 306 | u32 irq_mask = TMIO_MASK_CMD; | 307 | u32 irq_mask = TMIO_MASK_CMD; |
| 307 | 308 | ||
| 308 | /* Command 12 is handled by hardware */ | 309 | /* CMD12 is handled by hardware */ |
| 309 | if (cmd->opcode == 12 && !cmd->arg) { | 310 | if (cmd->opcode == MMC_STOP_TRANSMISSION && !cmd->arg) { |
| 310 | sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x001); | 311 | sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x001); |
| 311 | return 0; | 312 | return 0; |
| 312 | } | 313 | } |
| @@ -449,7 +450,7 @@ void tmio_mmc_do_data_irq(struct tmio_mmc_host *host) | |||
| 449 | } | 450 | } |
| 450 | 451 | ||
| 451 | if (stop) { | 452 | if (stop) { |
| 452 | if (stop->opcode == 12 && !stop->arg) | 453 | if (stop->opcode == MMC_STOP_TRANSMISSION && !stop->arg) |
| 453 | sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x000); | 454 | sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x000); |
| 454 | else | 455 | else |
| 455 | BUG(); | 456 | BUG(); |
| @@ -751,6 +752,34 @@ fail: | |||
| 751 | mmc_request_done(mmc, mrq); | 752 | mmc_request_done(mmc, mrq); |
| 752 | } | 753 | } |
| 753 | 754 | ||
| 755 | static int tmio_mmc_clk_update(struct mmc_host *mmc) | ||
| 756 | { | ||
| 757 | struct tmio_mmc_host *host = mmc_priv(mmc); | ||
| 758 | struct tmio_mmc_data *pdata = host->pdata; | ||
| 759 | int ret; | ||
| 760 | |||
| 761 | if (!pdata->clk_enable) | ||
| 762 | return -ENOTSUPP; | ||
| 763 | |||
| 764 | ret = pdata->clk_enable(host->pdev, &mmc->f_max); | ||
| 765 | if (!ret) | ||
| 766 | mmc->f_min = mmc->f_max / 512; | ||
| 767 | |||
| 768 | return ret; | ||
| 769 | } | ||
| 770 | |||
| 771 | static void tmio_mmc_set_power(struct tmio_mmc_host *host, struct mmc_ios *ios) | ||
| 772 | { | ||
| 773 | struct mmc_host *mmc = host->mmc; | ||
| 774 | |||
| 775 | if (host->set_pwr) | ||
| 776 | host->set_pwr(host->pdev, ios->power_mode != MMC_POWER_OFF); | ||
| 777 | if (!IS_ERR(mmc->supply.vmmc)) | ||
| 778 | /* Errors ignored... */ | ||
| 779 | mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, | ||
| 780 | ios->power_mode ? ios->vdd : 0); | ||
| 781 | } | ||
| 782 | |||
| 754 | /* Set MMC clock / power. | 783 | /* Set MMC clock / power. |
| 755 | * Note: This controller uses a simple divider scheme therefore it cannot | 784 | * Note: This controller uses a simple divider scheme therefore it cannot |
| 756 | * run a MMC card at full speed (20MHz). The max clock is 24MHz on SD, but as | 785 | * run a MMC card at full speed (20MHz). The max clock is 24MHz on SD, but as |
| @@ -797,32 +826,37 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
| 797 | */ | 826 | */ |
| 798 | if (ios->power_mode == MMC_POWER_ON && ios->clock) { | 827 | if (ios->power_mode == MMC_POWER_ON && ios->clock) { |
| 799 | if (!host->power) { | 828 | if (!host->power) { |
| 829 | tmio_mmc_clk_update(mmc); | ||
| 800 | pm_runtime_get_sync(dev); | 830 | pm_runtime_get_sync(dev); |
| 801 | host->power = true; | 831 | host->power = true; |
| 802 | } | 832 | } |
| 803 | tmio_mmc_set_clock(host, ios->clock); | 833 | tmio_mmc_set_clock(host, ios->clock); |
| 804 | /* power up SD bus */ | 834 | /* power up SD bus */ |
| 805 | if (host->set_pwr) | 835 | tmio_mmc_set_power(host, ios); |
| 806 | host->set_pwr(host->pdev, 1); | ||
| 807 | /* start bus clock */ | 836 | /* start bus clock */ |
| 808 | tmio_mmc_clk_start(host); | 837 | tmio_mmc_clk_start(host); |
| 809 | } else if (ios->power_mode != MMC_POWER_UP) { | 838 | } else if (ios->power_mode != MMC_POWER_UP) { |
| 810 | if (host->set_pwr && ios->power_mode == MMC_POWER_OFF) | 839 | if (ios->power_mode == MMC_POWER_OFF) |
| 811 | host->set_pwr(host->pdev, 0); | 840 | tmio_mmc_set_power(host, ios); |
| 812 | if (host->power) { | 841 | if (host->power) { |
| 842 | struct tmio_mmc_data *pdata = host->pdata; | ||
| 843 | tmio_mmc_clk_stop(host); | ||
| 813 | host->power = false; | 844 | host->power = false; |
| 814 | pm_runtime_put(dev); | 845 | pm_runtime_put(dev); |
| 846 | if (pdata->clk_disable) | ||
| 847 | pdata->clk_disable(host->pdev); | ||
| 815 | } | 848 | } |
| 816 | tmio_mmc_clk_stop(host); | ||
| 817 | } | 849 | } |
| 818 | 850 | ||
| 819 | switch (ios->bus_width) { | 851 | if (host->power) { |
| 820 | case MMC_BUS_WIDTH_1: | 852 | switch (ios->bus_width) { |
| 821 | sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x80e0); | 853 | case MMC_BUS_WIDTH_1: |
| 822 | break; | 854 | sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x80e0); |
| 823 | case MMC_BUS_WIDTH_4: | 855 | break; |
| 824 | sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x00e0); | 856 | case MMC_BUS_WIDTH_4: |
| 825 | break; | 857 | sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x00e0); |
| 858 | break; | ||
| 859 | } | ||
| 826 | } | 860 | } |
| 827 | 861 | ||
| 828 | /* Let things settle. delay taken from winCE driver */ | 862 | /* Let things settle. delay taken from winCE driver */ |
| @@ -841,6 +875,9 @@ static int tmio_mmc_get_ro(struct mmc_host *mmc) | |||
| 841 | { | 875 | { |
| 842 | struct tmio_mmc_host *host = mmc_priv(mmc); | 876 | struct tmio_mmc_host *host = mmc_priv(mmc); |
| 843 | struct tmio_mmc_data *pdata = host->pdata; | 877 | struct tmio_mmc_data *pdata = host->pdata; |
| 878 | int ret = mmc_gpio_get_ro(mmc); | ||
| 879 | if (ret >= 0) | ||
| 880 | return ret; | ||
| 844 | 881 | ||
| 845 | return !((pdata->flags & TMIO_MMC_WRPROTECT_DISABLE) || | 882 | return !((pdata->flags & TMIO_MMC_WRPROTECT_DISABLE) || |
| 846 | (sd_ctrl_read32(host, CTL_STATUS) & TMIO_STAT_WRPROTECT)); | 883 | (sd_ctrl_read32(host, CTL_STATUS) & TMIO_STAT_WRPROTECT)); |
| @@ -850,6 +887,9 @@ static int tmio_mmc_get_cd(struct mmc_host *mmc) | |||
| 850 | { | 887 | { |
| 851 | struct tmio_mmc_host *host = mmc_priv(mmc); | 888 | struct tmio_mmc_host *host = mmc_priv(mmc); |
| 852 | struct tmio_mmc_data *pdata = host->pdata; | 889 | struct tmio_mmc_data *pdata = host->pdata; |
| 890 | int ret = mmc_gpio_get_cd(mmc); | ||
| 891 | if (ret >= 0) | ||
| 892 | return ret; | ||
| 853 | 893 | ||
| 854 | if (!pdata->get_cd) | 894 | if (!pdata->get_cd) |
| 855 | return -ENOSYS; | 895 | return -ENOSYS; |
| @@ -865,6 +905,19 @@ static const struct mmc_host_ops tmio_mmc_ops = { | |||
| 865 | .enable_sdio_irq = tmio_mmc_enable_sdio_irq, | 905 | .enable_sdio_irq = tmio_mmc_enable_sdio_irq, |
| 866 | }; | 906 | }; |
| 867 | 907 | ||
| 908 | static void tmio_mmc_init_ocr(struct tmio_mmc_host *host) | ||
| 909 | { | ||
| 910 | struct tmio_mmc_data *pdata = host->pdata; | ||
| 911 | struct mmc_host *mmc = host->mmc; | ||
| 912 | |||
| 913 | mmc_regulator_get_supply(mmc); | ||
| 914 | |||
| 915 | if (!mmc->ocr_avail) | ||
| 916 | mmc->ocr_avail = pdata->ocr_mask ? : MMC_VDD_32_33 | MMC_VDD_33_34; | ||
| 917 | else if (pdata->ocr_mask) | ||
| 918 | dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n"); | ||
| 919 | } | ||
| 920 | |||
| 868 | int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host, | 921 | int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host, |
| 869 | struct platform_device *pdev, | 922 | struct platform_device *pdev, |
| 870 | struct tmio_mmc_data *pdata) | 923 | struct tmio_mmc_data *pdata) |
| @@ -904,18 +957,14 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host, | |||
| 904 | 957 | ||
| 905 | mmc->ops = &tmio_mmc_ops; | 958 | mmc->ops = &tmio_mmc_ops; |
| 906 | mmc->caps = MMC_CAP_4_BIT_DATA | pdata->capabilities; | 959 | mmc->caps = MMC_CAP_4_BIT_DATA | pdata->capabilities; |
| 907 | mmc->f_max = pdata->hclk; | 960 | mmc->caps2 = pdata->capabilities2; |
| 908 | mmc->f_min = mmc->f_max / 512; | ||
| 909 | mmc->max_segs = 32; | 961 | mmc->max_segs = 32; |
| 910 | mmc->max_blk_size = 512; | 962 | mmc->max_blk_size = 512; |
| 911 | mmc->max_blk_count = (PAGE_CACHE_SIZE / mmc->max_blk_size) * | 963 | mmc->max_blk_count = (PAGE_CACHE_SIZE / mmc->max_blk_size) * |
| 912 | mmc->max_segs; | 964 | mmc->max_segs; |
| 913 | mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; | 965 | mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; |
| 914 | mmc->max_seg_size = mmc->max_req_size; | 966 | mmc->max_seg_size = mmc->max_req_size; |
| 915 | if (pdata->ocr_mask) | 967 | tmio_mmc_init_ocr(_host); |
| 916 | mmc->ocr_avail = pdata->ocr_mask; | ||
| 917 | else | ||
| 918 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; | ||
| 919 | 968 | ||
| 920 | _host->native_hotplug = !(pdata->flags & TMIO_MMC_USE_GPIO_CD || | 969 | _host->native_hotplug = !(pdata->flags & TMIO_MMC_USE_GPIO_CD || |
| 921 | mmc->caps & MMC_CAP_NEEDS_POLL || | 970 | mmc->caps & MMC_CAP_NEEDS_POLL || |
| @@ -927,6 +976,11 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host, | |||
| 927 | if (ret < 0) | 976 | if (ret < 0) |
| 928 | goto pm_disable; | 977 | goto pm_disable; |
| 929 | 978 | ||
| 979 | if (tmio_mmc_clk_update(mmc) < 0) { | ||
| 980 | mmc->f_max = pdata->hclk; | ||
| 981 | mmc->f_min = mmc->f_max / 512; | ||
| 982 | } | ||
| 983 | |||
| 930 | /* | 984 | /* |
| 931 | * There are 4 different scenarios for the card detection: | 985 | * There are 4 different scenarios for the card detection: |
| 932 | * 1) an external gpio irq handles the cd (best for power savings) | 986 | * 1) an external gpio irq handles the cd (best for power savings) |
| @@ -937,7 +991,6 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host, | |||
| 937 | * While we increment the runtime PM counter for all scenarios when | 991 | * While we increment the runtime PM counter for all scenarios when |
| 938 | * the mmc core activates us by calling an appropriate set_ios(), we | 992 | * the mmc core activates us by calling an appropriate set_ios(), we |
| 939 | * must additionally ensure that in case 2) the tmio mmc hardware stays | 993 | * must additionally ensure that in case 2) the tmio mmc hardware stays |
| 940 | * additionally ensure that in case 2) the tmio mmc hardware stays | ||
| 941 | * powered on during runtime for the card detection to work. | 994 | * powered on during runtime for the card detection to work. |
| 942 | */ | 995 | */ |
| 943 | if (_host->native_hotplug) | 996 | if (_host->native_hotplug) |
| @@ -948,6 +1001,17 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host, | |||
| 948 | 1001 | ||
| 949 | _host->sdcard_irq_mask = sd_ctrl_read32(_host, CTL_IRQ_MASK); | 1002 | _host->sdcard_irq_mask = sd_ctrl_read32(_host, CTL_IRQ_MASK); |
| 950 | tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL); | 1003 | tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL); |
| 1004 | |||
| 1005 | /* Unmask the IRQs we want to know about */ | ||
| 1006 | if (!_host->chan_rx) | ||
| 1007 | irq_mask |= TMIO_MASK_READOP; | ||
| 1008 | if (!_host->chan_tx) | ||
| 1009 | irq_mask |= TMIO_MASK_WRITEOP; | ||
| 1010 | if (!_host->native_hotplug) | ||
| 1011 | irq_mask &= ~(TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT); | ||
| 1012 | |||
| 1013 | _host->sdcard_irq_mask &= ~irq_mask; | ||
| 1014 | |||
| 951 | if (pdata->flags & TMIO_MMC_SDIO_IRQ) | 1015 | if (pdata->flags & TMIO_MMC_SDIO_IRQ) |
| 952 | tmio_mmc_enable_sdio_irq(mmc, 0); | 1016 | tmio_mmc_enable_sdio_irq(mmc, 0); |
| 953 | 1017 | ||
| @@ -961,22 +1025,18 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host, | |||
| 961 | /* See if we also get DMA */ | 1025 | /* See if we also get DMA */ |
| 962 | tmio_mmc_request_dma(_host, pdata); | 1026 | tmio_mmc_request_dma(_host, pdata); |
| 963 | 1027 | ||
| 964 | mmc_add_host(mmc); | 1028 | ret = mmc_add_host(mmc); |
| 1029 | if (pdata->clk_disable) | ||
| 1030 | pdata->clk_disable(pdev); | ||
| 1031 | if (ret < 0) { | ||
| 1032 | tmio_mmc_host_remove(_host); | ||
| 1033 | return ret; | ||
| 1034 | } | ||
| 965 | 1035 | ||
| 966 | dev_pm_qos_expose_latency_limit(&pdev->dev, 100); | 1036 | dev_pm_qos_expose_latency_limit(&pdev->dev, 100); |
| 967 | 1037 | ||
| 968 | /* Unmask the IRQs we want to know about */ | ||
| 969 | if (!_host->chan_rx) | ||
| 970 | irq_mask |= TMIO_MASK_READOP; | ||
| 971 | if (!_host->chan_tx) | ||
| 972 | irq_mask |= TMIO_MASK_WRITEOP; | ||
| 973 | if (!_host->native_hotplug) | ||
| 974 | irq_mask &= ~(TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT); | ||
| 975 | |||
| 976 | tmio_mmc_enable_mmc_irqs(_host, irq_mask); | ||
| 977 | |||
| 978 | if (pdata->flags & TMIO_MMC_USE_GPIO_CD) { | 1038 | if (pdata->flags & TMIO_MMC_USE_GPIO_CD) { |
| 979 | ret = mmc_cd_gpio_request(mmc, pdata->cd_gpio); | 1039 | ret = mmc_gpio_request_cd(mmc, pdata->cd_gpio); |
| 980 | if (ret < 0) { | 1040 | if (ret < 0) { |
| 981 | tmio_mmc_host_remove(_host); | 1041 | tmio_mmc_host_remove(_host); |
| 982 | return ret; | 1042 | return ret; |
| @@ -1008,7 +1068,7 @@ void tmio_mmc_host_remove(struct tmio_mmc_host *host) | |||
| 1008 | * This means we can miss a card-eject, but this is anyway | 1068 | * This means we can miss a card-eject, but this is anyway |
| 1009 | * possible, because of delayed processing of hotplug events. | 1069 | * possible, because of delayed processing of hotplug events. |
| 1010 | */ | 1070 | */ |
| 1011 | mmc_cd_gpio_free(mmc); | 1071 | mmc_gpio_free_cd(mmc); |
| 1012 | 1072 | ||
| 1013 | if (!host->native_hotplug) | 1073 | if (!host->native_hotplug) |
| 1014 | pm_runtime_get_sync(&pdev->dev); | 1074 | pm_runtime_get_sync(&pdev->dev); |
