diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-06 12:48:31 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-06 12:48:31 -0400 |
commit | c87985a3ce723995fc7b25e598238d67154108a1 (patch) | |
tree | e60def1b77c25c1d74180f62e8a5603f9826f209 /drivers/mmc | |
parent | d155255a344c417acad74156654295a2964e6b81 (diff) | |
parent | 0d7614f09c1ebdbaa1599a5aba7593f147bf96ee (diff) |
Merge tty-next into 3.6-rc1
This handles the merge issue in:
arch/um/drivers/line.c
arch/um/drivers/line.h
And resolves the duplicate patches that were in both trees do to the
tty-next branch not getting merged into 3.6-rc1.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/mmc')
29 files changed, 1253 insertions, 797 deletions
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index 276d21ce6bc1..f1c84decb192 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c | |||
@@ -850,9 +850,7 @@ out: | |||
850 | goto retry; | 850 | goto retry; |
851 | if (!err) | 851 | if (!err) |
852 | mmc_blk_reset_success(md, type); | 852 | mmc_blk_reset_success(md, type); |
853 | spin_lock_irq(&md->lock); | 853 | blk_end_request(req, err, blk_rq_bytes(req)); |
854 | __blk_end_request(req, err, blk_rq_bytes(req)); | ||
855 | spin_unlock_irq(&md->lock); | ||
856 | 854 | ||
857 | return err ? 0 : 1; | 855 | return err ? 0 : 1; |
858 | } | 856 | } |
@@ -934,9 +932,7 @@ out_retry: | |||
934 | if (!err) | 932 | if (!err) |
935 | mmc_blk_reset_success(md, type); | 933 | mmc_blk_reset_success(md, type); |
936 | out: | 934 | out: |
937 | spin_lock_irq(&md->lock); | 935 | blk_end_request(req, err, blk_rq_bytes(req)); |
938 | __blk_end_request(req, err, blk_rq_bytes(req)); | ||
939 | spin_unlock_irq(&md->lock); | ||
940 | 936 | ||
941 | return err ? 0 : 1; | 937 | return err ? 0 : 1; |
942 | } | 938 | } |
@@ -951,9 +947,7 @@ static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req) | |||
951 | if (ret) | 947 | if (ret) |
952 | ret = -EIO; | 948 | ret = -EIO; |
953 | 949 | ||
954 | spin_lock_irq(&md->lock); | 950 | blk_end_request_all(req, ret); |
955 | __blk_end_request_all(req, ret); | ||
956 | spin_unlock_irq(&md->lock); | ||
957 | 951 | ||
958 | return ret ? 0 : 1; | 952 | return ret ? 0 : 1; |
959 | } | 953 | } |
@@ -1252,14 +1246,10 @@ static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card, | |||
1252 | 1246 | ||
1253 | blocks = mmc_sd_num_wr_blocks(card); | 1247 | blocks = mmc_sd_num_wr_blocks(card); |
1254 | if (blocks != (u32)-1) { | 1248 | if (blocks != (u32)-1) { |
1255 | spin_lock_irq(&md->lock); | 1249 | ret = blk_end_request(req, 0, blocks << 9); |
1256 | ret = __blk_end_request(req, 0, blocks << 9); | ||
1257 | spin_unlock_irq(&md->lock); | ||
1258 | } | 1250 | } |
1259 | } else { | 1251 | } else { |
1260 | spin_lock_irq(&md->lock); | 1252 | ret = blk_end_request(req, 0, brq->data.bytes_xfered); |
1261 | ret = __blk_end_request(req, 0, brq->data.bytes_xfered); | ||
1262 | spin_unlock_irq(&md->lock); | ||
1263 | } | 1253 | } |
1264 | return ret; | 1254 | return ret; |
1265 | } | 1255 | } |
@@ -1311,10 +1301,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc) | |||
1311 | * A block was successfully transferred. | 1301 | * A block was successfully transferred. |
1312 | */ | 1302 | */ |
1313 | mmc_blk_reset_success(md, type); | 1303 | mmc_blk_reset_success(md, type); |
1314 | spin_lock_irq(&md->lock); | 1304 | ret = blk_end_request(req, 0, |
1315 | ret = __blk_end_request(req, 0, | ||
1316 | brq->data.bytes_xfered); | 1305 | brq->data.bytes_xfered); |
1317 | spin_unlock_irq(&md->lock); | ||
1318 | /* | 1306 | /* |
1319 | * If the blk_end_request function returns non-zero even | 1307 | * If the blk_end_request function returns non-zero even |
1320 | * though all data has been transferred and no errors | 1308 | * though all data has been transferred and no errors |
@@ -1364,10 +1352,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc) | |||
1364 | * time, so we only reach here after trying to | 1352 | * time, so we only reach here after trying to |
1365 | * read a single sector. | 1353 | * read a single sector. |
1366 | */ | 1354 | */ |
1367 | spin_lock_irq(&md->lock); | 1355 | ret = blk_end_request(req, -EIO, |
1368 | ret = __blk_end_request(req, -EIO, | ||
1369 | brq->data.blksz); | 1356 | brq->data.blksz); |
1370 | spin_unlock_irq(&md->lock); | ||
1371 | if (!ret) | 1357 | if (!ret) |
1372 | goto start_new_req; | 1358 | goto start_new_req; |
1373 | break; | 1359 | break; |
@@ -1388,12 +1374,10 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc) | |||
1388 | return 1; | 1374 | return 1; |
1389 | 1375 | ||
1390 | cmd_abort: | 1376 | cmd_abort: |
1391 | spin_lock_irq(&md->lock); | ||
1392 | if (mmc_card_removed(card)) | 1377 | if (mmc_card_removed(card)) |
1393 | req->cmd_flags |= REQ_QUIET; | 1378 | req->cmd_flags |= REQ_QUIET; |
1394 | while (ret) | 1379 | while (ret) |
1395 | ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req)); | 1380 | ret = blk_end_request(req, -EIO, blk_rq_cur_bytes(req)); |
1396 | spin_unlock_irq(&md->lock); | ||
1397 | 1381 | ||
1398 | start_new_req: | 1382 | start_new_req: |
1399 | if (rqc) { | 1383 | if (rqc) { |
@@ -1417,9 +1401,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) | |||
1417 | ret = mmc_blk_part_switch(card, md); | 1401 | ret = mmc_blk_part_switch(card, md); |
1418 | if (ret) { | 1402 | if (ret) { |
1419 | if (req) { | 1403 | if (req) { |
1420 | spin_lock_irq(&md->lock); | 1404 | blk_end_request_all(req, -EIO); |
1421 | __blk_end_request_all(req, -EIO); | ||
1422 | spin_unlock_irq(&md->lock); | ||
1423 | } | 1405 | } |
1424 | ret = 0; | 1406 | ret = 0; |
1425 | 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 8f5dc08d6598..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 | IRQF_ONESHOT, 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 4f4489aa6bae..396b25891bb9 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c | |||
@@ -818,9 +818,6 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, | |||
818 | if (!mmc_host_is_spi(host)) | 818 | if (!mmc_host_is_spi(host)) |
819 | mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); | 819 | mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); |
820 | 820 | ||
821 | /* Initialization should be done at 3.3 V I/O voltage. */ | ||
822 | mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0); | ||
823 | |||
824 | /* | 821 | /* |
825 | * Since we're changing the OCR value, we seem to | 822 | * Since we're changing the OCR value, we seem to |
826 | * need to tell some cards to go back to the idle | 823 | * need to tell some cards to go back to the idle |
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 b2b43f624b9e..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; |
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index 41c5fd8848f4..d4619e2ec030 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c | |||
@@ -591,9 +591,6 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, | |||
591 | * Inform the card of the voltage | 591 | * Inform the card of the voltage |
592 | */ | 592 | */ |
593 | if (!powered_resume) { | 593 | if (!powered_resume) { |
594 | /* The initialization should be done at 3.3 V I/O voltage. */ | ||
595 | mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0); | ||
596 | |||
597 | err = mmc_send_io_op_cond(host, host->ocr, &ocr); | 594 | err = mmc_send_io_op_cond(host, host->ocr, &ocr); |
598 | if (err) | 595 | if (err) |
599 | goto err; | 596 | goto err; |
@@ -1006,10 +1003,6 @@ static int mmc_sdio_power_restore(struct mmc_host *host) | |||
1006 | * restore the correct voltage setting of the card. | 1003 | * restore the correct voltage setting of the card. |
1007 | */ | 1004 | */ |
1008 | 1005 | ||
1009 | /* The initialization should be done at 3.3 V I/O voltage. */ | ||
1010 | if (!mmc_card_keep_power(host)) | ||
1011 | mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0); | ||
1012 | |||
1013 | sdio_reset(host); | 1006 | sdio_reset(host); |
1014 | mmc_go_idle(host); | 1007 | mmc_go_idle(host); |
1015 | 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.c b/drivers/mmc/host/atmel-mci.c index f2c115e06438..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]); |
@@ -1685,7 +1691,6 @@ static void atmci_tasklet_func(unsigned long priv) | |||
1685 | 1691 | ||
1686 | dev_dbg(&host->pdev->dev, "FSM: cmd ready\n"); | 1692 | dev_dbg(&host->pdev->dev, "FSM: cmd ready\n"); |
1687 | host->cmd = NULL; | 1693 | host->cmd = NULL; |
1688 | host->data = NULL; | ||
1689 | data->bytes_xfered = data->blocks * data->blksz; | 1694 | data->bytes_xfered = data->blocks * data->blksz; |
1690 | data->error = 0; | 1695 | data->error = 0; |
1691 | atmci_command_complete(host, mrq->stop); | 1696 | atmci_command_complete(host, mrq->stop); |
@@ -1699,6 +1704,7 @@ static void atmci_tasklet_func(unsigned long priv) | |||
1699 | atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); | 1704 | atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); |
1700 | state = STATE_WAITING_NOTBUSY; | 1705 | state = STATE_WAITING_NOTBUSY; |
1701 | } | 1706 | } |
1707 | host->data = NULL; | ||
1702 | break; | 1708 | break; |
1703 | 1709 | ||
1704 | case STATE_END_REQUEST: | 1710 | case STATE_END_REQUEST: |
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 1ca5e72ceb65..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)); |
@@ -1876,7 +1888,6 @@ static void dw_mci_init_dma(struct dw_mci *host) | |||
1876 | /* Determine which DMA interface to use */ | 1888 | /* Determine which DMA interface to use */ |
1877 | #ifdef CONFIG_MMC_DW_IDMAC | 1889 | #ifdef CONFIG_MMC_DW_IDMAC |
1878 | host->dma_ops = &dw_mci_idmac_ops; | 1890 | host->dma_ops = &dw_mci_idmac_ops; |
1879 | dev_info(&host->dev, "Using internal DMA controller.\n"); | ||
1880 | #endif | 1891 | #endif |
1881 | 1892 | ||
1882 | if (!host->dma_ops) | 1893 | if (!host->dma_ops) |
@@ -2175,7 +2186,7 @@ int dw_mci_resume(struct dw_mci *host) | |||
2175 | return ret; | 2186 | return ret; |
2176 | } | 2187 | } |
2177 | 2188 | ||
2178 | if (host->dma_ops->init) | 2189 | if (host->use_dma && host->dma_ops->init) |
2179 | host->dma_ops->init(host); | 2190 | host->dma_ops->init(host); |
2180 | 2191 | ||
2181 | /* Restore the old value at FIFOTH register */ | 2192 | /* Restore the old value at FIFOTH register */ |
diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c index 3b9136c1a475..a61cb5fca22d 100644 --- a/drivers/mmc/host/mvsdio.c +++ b/drivers/mmc/host/mvsdio.c | |||
@@ -839,6 +839,10 @@ out: | |||
839 | if (r) | 839 | if (r) |
840 | release_resource(r); | 840 | release_resource(r); |
841 | if (mmc) | 841 | if (mmc) |
842 | if (!IS_ERR_OR_NULL(host->clk)) { | ||
843 | clk_disable_unprepare(host->clk); | ||
844 | clk_put(host->clk); | ||
845 | } | ||
842 | mmc_free_host(mmc); | 846 | mmc_free_host(mmc); |
843 | 847 | ||
844 | return ret; | 848 | return ret; |
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c index 277161d279b8..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; |
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c index 3e8dcf8d2e05..50e08f03aa65 100644 --- a/drivers/mmc/host/omap.c +++ b/drivers/mmc/host/omap.c | |||
@@ -17,10 +17,12 @@ | |||
17 | #include <linux/ioport.h> | 17 | #include <linux/ioport.h> |
18 | #include <linux/platform_device.h> | 18 | #include <linux/platform_device.h> |
19 | #include <linux/interrupt.h> | 19 | #include <linux/interrupt.h> |
20 | #include <linux/dmaengine.h> | ||
20 | #include <linux/dma-mapping.h> | 21 | #include <linux/dma-mapping.h> |
21 | #include <linux/delay.h> | 22 | #include <linux/delay.h> |
22 | #include <linux/spinlock.h> | 23 | #include <linux/spinlock.h> |
23 | #include <linux/timer.h> | 24 | #include <linux/timer.h> |
25 | #include <linux/omap-dma.h> | ||
24 | #include <linux/mmc/host.h> | 26 | #include <linux/mmc/host.h> |
25 | #include <linux/mmc/card.h> | 27 | #include <linux/mmc/card.h> |
26 | #include <linux/clk.h> | 28 | #include <linux/clk.h> |
@@ -128,6 +130,10 @@ struct mmc_omap_host { | |||
128 | unsigned char id; /* 16xx chips have 2 MMC blocks */ | 130 | unsigned char id; /* 16xx chips have 2 MMC blocks */ |
129 | struct clk * iclk; | 131 | struct clk * iclk; |
130 | struct clk * fclk; | 132 | struct clk * fclk; |
133 | struct dma_chan *dma_rx; | ||
134 | u32 dma_rx_burst; | ||
135 | struct dma_chan *dma_tx; | ||
136 | u32 dma_tx_burst; | ||
131 | struct resource *mem_res; | 137 | struct resource *mem_res; |
132 | void __iomem *virt_base; | 138 | void __iomem *virt_base; |
133 | unsigned int phys_base; | 139 | unsigned int phys_base; |
@@ -153,12 +159,8 @@ struct mmc_omap_host { | |||
153 | 159 | ||
154 | unsigned use_dma:1; | 160 | unsigned use_dma:1; |
155 | unsigned brs_received:1, dma_done:1; | 161 | unsigned brs_received:1, dma_done:1; |
156 | unsigned dma_is_read:1; | ||
157 | unsigned dma_in_use:1; | 162 | unsigned dma_in_use:1; |
158 | int dma_ch; | ||
159 | spinlock_t dma_lock; | 163 | spinlock_t dma_lock; |
160 | struct timer_list dma_timer; | ||
161 | unsigned dma_len; | ||
162 | 164 | ||
163 | struct mmc_omap_slot *slots[OMAP_MMC_MAX_SLOTS]; | 165 | struct mmc_omap_slot *slots[OMAP_MMC_MAX_SLOTS]; |
164 | struct mmc_omap_slot *current_slot; | 166 | struct mmc_omap_slot *current_slot; |
@@ -406,18 +408,25 @@ mmc_omap_release_dma(struct mmc_omap_host *host, struct mmc_data *data, | |||
406 | int abort) | 408 | int abort) |
407 | { | 409 | { |
408 | enum dma_data_direction dma_data_dir; | 410 | enum dma_data_direction dma_data_dir; |
411 | struct device *dev = mmc_dev(host->mmc); | ||
412 | struct dma_chan *c; | ||
409 | 413 | ||
410 | BUG_ON(host->dma_ch < 0); | 414 | if (data->flags & MMC_DATA_WRITE) { |
411 | if (data->error) | ||
412 | omap_stop_dma(host->dma_ch); | ||
413 | /* Release DMA channel lazily */ | ||
414 | mod_timer(&host->dma_timer, jiffies + HZ); | ||
415 | if (data->flags & MMC_DATA_WRITE) | ||
416 | dma_data_dir = DMA_TO_DEVICE; | 415 | dma_data_dir = DMA_TO_DEVICE; |
417 | else | 416 | c = host->dma_tx; |
417 | } else { | ||
418 | dma_data_dir = DMA_FROM_DEVICE; | 418 | dma_data_dir = DMA_FROM_DEVICE; |
419 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, host->sg_len, | 419 | c = host->dma_rx; |
420 | dma_data_dir); | 420 | } |
421 | if (c) { | ||
422 | if (data->error) { | ||
423 | dmaengine_terminate_all(c); | ||
424 | /* Claim nothing transferred on error... */ | ||
425 | data->bytes_xfered = 0; | ||
426 | } | ||
427 | dev = c->device->dev; | ||
428 | } | ||
429 | dma_unmap_sg(dev, data->sg, host->sg_len, dma_data_dir); | ||
421 | } | 430 | } |
422 | 431 | ||
423 | static void mmc_omap_send_stop_work(struct work_struct *work) | 432 | static void mmc_omap_send_stop_work(struct work_struct *work) |
@@ -525,16 +534,6 @@ mmc_omap_end_of_data(struct mmc_omap_host *host, struct mmc_data *data) | |||
525 | } | 534 | } |
526 | 535 | ||
527 | static void | 536 | static void |
528 | mmc_omap_dma_timer(unsigned long data) | ||
529 | { | ||
530 | struct mmc_omap_host *host = (struct mmc_omap_host *) data; | ||
531 | |||
532 | BUG_ON(host->dma_ch < 0); | ||
533 | omap_free_dma(host->dma_ch); | ||
534 | host->dma_ch = -1; | ||
535 | } | ||
536 | |||
537 | static void | ||
538 | mmc_omap_dma_done(struct mmc_omap_host *host, struct mmc_data *data) | 537 | mmc_omap_dma_done(struct mmc_omap_host *host, struct mmc_data *data) |
539 | { | 538 | { |
540 | unsigned long flags; | 539 | unsigned long flags; |
@@ -891,159 +890,15 @@ static void mmc_omap_cover_handler(unsigned long param) | |||
891 | jiffies + msecs_to_jiffies(OMAP_MMC_COVER_POLL_DELAY)); | 890 | jiffies + msecs_to_jiffies(OMAP_MMC_COVER_POLL_DELAY)); |
892 | } | 891 | } |
893 | 892 | ||
894 | /* Prepare to transfer the next segment of a scatterlist */ | 893 | static void mmc_omap_dma_callback(void *priv) |
895 | static void | ||
896 | mmc_omap_prepare_dma(struct mmc_omap_host *host, struct mmc_data *data) | ||
897 | { | 894 | { |
898 | int dma_ch = host->dma_ch; | 895 | struct mmc_omap_host *host = priv; |
899 | unsigned long data_addr; | 896 | struct mmc_data *data = host->data; |
900 | u16 buf, frame; | ||
901 | u32 count; | ||
902 | struct scatterlist *sg = &data->sg[host->sg_idx]; | ||
903 | int src_port = 0; | ||
904 | int dst_port = 0; | ||
905 | int sync_dev = 0; | ||
906 | |||
907 | data_addr = host->phys_base + OMAP_MMC_REG(host, DATA); | ||
908 | frame = data->blksz; | ||
909 | count = sg_dma_len(sg); | ||
910 | |||
911 | if ((data->blocks == 1) && (count > data->blksz)) | ||
912 | count = frame; | ||
913 | |||
914 | host->dma_len = count; | ||
915 | |||
916 | /* FIFO is 16x2 bytes on 15xx, and 32x2 bytes on 16xx and 24xx. | ||
917 | * Use 16 or 32 word frames when the blocksize is at least that large. | ||
918 | * Blocksize is usually 512 bytes; but not for some SD reads. | ||
919 | */ | ||
920 | if (cpu_is_omap15xx() && frame > 32) | ||
921 | frame = 32; | ||
922 | else if (frame > 64) | ||
923 | frame = 64; | ||
924 | count /= frame; | ||
925 | frame >>= 1; | ||
926 | |||
927 | if (!(data->flags & MMC_DATA_WRITE)) { | ||
928 | buf = 0x800f | ((frame - 1) << 8); | ||
929 | |||
930 | if (cpu_class_is_omap1()) { | ||
931 | src_port = OMAP_DMA_PORT_TIPB; | ||
932 | dst_port = OMAP_DMA_PORT_EMIFF; | ||
933 | } | ||
934 | if (cpu_is_omap24xx()) | ||
935 | sync_dev = OMAP24XX_DMA_MMC1_RX; | ||
936 | |||
937 | omap_set_dma_src_params(dma_ch, src_port, | ||
938 | OMAP_DMA_AMODE_CONSTANT, | ||
939 | data_addr, 0, 0); | ||
940 | omap_set_dma_dest_params(dma_ch, dst_port, | ||
941 | OMAP_DMA_AMODE_POST_INC, | ||
942 | sg_dma_address(sg), 0, 0); | ||
943 | omap_set_dma_dest_data_pack(dma_ch, 1); | ||
944 | omap_set_dma_dest_burst_mode(dma_ch, OMAP_DMA_DATA_BURST_4); | ||
945 | } else { | ||
946 | buf = 0x0f80 | ((frame - 1) << 0); | ||
947 | |||
948 | if (cpu_class_is_omap1()) { | ||
949 | src_port = OMAP_DMA_PORT_EMIFF; | ||
950 | dst_port = OMAP_DMA_PORT_TIPB; | ||
951 | } | ||
952 | if (cpu_is_omap24xx()) | ||
953 | sync_dev = OMAP24XX_DMA_MMC1_TX; | ||
954 | |||
955 | omap_set_dma_dest_params(dma_ch, dst_port, | ||
956 | OMAP_DMA_AMODE_CONSTANT, | ||
957 | data_addr, 0, 0); | ||
958 | omap_set_dma_src_params(dma_ch, src_port, | ||
959 | OMAP_DMA_AMODE_POST_INC, | ||
960 | sg_dma_address(sg), 0, 0); | ||
961 | omap_set_dma_src_data_pack(dma_ch, 1); | ||
962 | omap_set_dma_src_burst_mode(dma_ch, OMAP_DMA_DATA_BURST_4); | ||
963 | } | ||
964 | 897 | ||
965 | /* Max limit for DMA frame count is 0xffff */ | 898 | /* If we got to the end of DMA, assume everything went well */ |
966 | BUG_ON(count > 0xffff); | 899 | data->bytes_xfered += data->blocks * data->blksz; |
967 | 900 | ||
968 | OMAP_MMC_WRITE(host, BUF, buf); | 901 | mmc_omap_dma_done(host, data); |
969 | omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S16, | ||
970 | frame, count, OMAP_DMA_SYNC_FRAME, | ||
971 | sync_dev, 0); | ||
972 | } | ||
973 | |||
974 | /* A scatterlist segment completed */ | ||
975 | static void mmc_omap_dma_cb(int lch, u16 ch_status, void *data) | ||
976 | { | ||
977 | struct mmc_omap_host *host = (struct mmc_omap_host *) data; | ||
978 | struct mmc_data *mmcdat = host->data; | ||
979 | |||
980 | if (unlikely(host->dma_ch < 0)) { | ||
981 | dev_err(mmc_dev(host->mmc), | ||
982 | "DMA callback while DMA not enabled\n"); | ||
983 | return; | ||
984 | } | ||
985 | /* FIXME: We really should do something to _handle_ the errors */ | ||
986 | if (ch_status & OMAP1_DMA_TOUT_IRQ) { | ||
987 | dev_err(mmc_dev(host->mmc),"DMA timeout\n"); | ||
988 | return; | ||
989 | } | ||
990 | if (ch_status & OMAP_DMA_DROP_IRQ) { | ||
991 | dev_err(mmc_dev(host->mmc), "DMA sync error\n"); | ||
992 | return; | ||
993 | } | ||
994 | if (!(ch_status & OMAP_DMA_BLOCK_IRQ)) { | ||
995 | return; | ||
996 | } | ||
997 | mmcdat->bytes_xfered += host->dma_len; | ||
998 | host->sg_idx++; | ||
999 | if (host->sg_idx < host->sg_len) { | ||
1000 | mmc_omap_prepare_dma(host, host->data); | ||
1001 | omap_start_dma(host->dma_ch); | ||
1002 | } else | ||
1003 | mmc_omap_dma_done(host, host->data); | ||
1004 | } | ||
1005 | |||
1006 | static int mmc_omap_get_dma_channel(struct mmc_omap_host *host, struct mmc_data *data) | ||
1007 | { | ||
1008 | const char *dma_dev_name; | ||
1009 | int sync_dev, dma_ch, is_read, r; | ||
1010 | |||
1011 | is_read = !(data->flags & MMC_DATA_WRITE); | ||
1012 | del_timer_sync(&host->dma_timer); | ||
1013 | if (host->dma_ch >= 0) { | ||
1014 | if (is_read == host->dma_is_read) | ||
1015 | return 0; | ||
1016 | omap_free_dma(host->dma_ch); | ||
1017 | host->dma_ch = -1; | ||
1018 | } | ||
1019 | |||
1020 | if (is_read) { | ||
1021 | if (host->id == 0) { | ||
1022 | sync_dev = OMAP_DMA_MMC_RX; | ||
1023 | dma_dev_name = "MMC1 read"; | ||
1024 | } else { | ||
1025 | sync_dev = OMAP_DMA_MMC2_RX; | ||
1026 | dma_dev_name = "MMC2 read"; | ||
1027 | } | ||
1028 | } else { | ||
1029 | if (host->id == 0) { | ||
1030 | sync_dev = OMAP_DMA_MMC_TX; | ||
1031 | dma_dev_name = "MMC1 write"; | ||
1032 | } else { | ||
1033 | sync_dev = OMAP_DMA_MMC2_TX; | ||
1034 | dma_dev_name = "MMC2 write"; | ||
1035 | } | ||
1036 | } | ||
1037 | r = omap_request_dma(sync_dev, dma_dev_name, mmc_omap_dma_cb, | ||
1038 | host, &dma_ch); | ||
1039 | if (r != 0) { | ||
1040 | dev_dbg(mmc_dev(host->mmc), "omap_request_dma() failed with %d\n", r); | ||
1041 | return r; | ||
1042 | } | ||
1043 | host->dma_ch = dma_ch; | ||
1044 | host->dma_is_read = is_read; | ||
1045 | |||
1046 | return 0; | ||
1047 | } | 902 | } |
1048 | 903 | ||
1049 | static inline void set_cmd_timeout(struct mmc_omap_host *host, struct mmc_request *req) | 904 | static inline void set_cmd_timeout(struct mmc_omap_host *host, struct mmc_request *req) |
@@ -1118,33 +973,85 @@ mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req) | |||
1118 | 973 | ||
1119 | host->sg_idx = 0; | 974 | host->sg_idx = 0; |
1120 | if (use_dma) { | 975 | if (use_dma) { |
1121 | if (mmc_omap_get_dma_channel(host, data) == 0) { | 976 | enum dma_data_direction dma_data_dir; |
1122 | enum dma_data_direction dma_data_dir; | 977 | struct dma_async_tx_descriptor *tx; |
1123 | 978 | struct dma_chan *c; | |
1124 | if (data->flags & MMC_DATA_WRITE) | 979 | u32 burst, *bp; |
1125 | dma_data_dir = DMA_TO_DEVICE; | 980 | u16 buf; |
1126 | else | 981 | |
1127 | dma_data_dir = DMA_FROM_DEVICE; | 982 | /* |
1128 | 983 | * FIFO is 16x2 bytes on 15xx, and 32x2 bytes on 16xx | |
1129 | host->sg_len = dma_map_sg(mmc_dev(host->mmc), data->sg, | 984 | * and 24xx. Use 16 or 32 word frames when the |
1130 | sg_len, dma_data_dir); | 985 | * blocksize is at least that large. Blocksize is |
1131 | host->total_bytes_left = 0; | 986 | * usually 512 bytes; but not for some SD reads. |
1132 | mmc_omap_prepare_dma(host, req->data); | 987 | */ |
1133 | host->brs_received = 0; | 988 | burst = cpu_is_omap15xx() ? 32 : 64; |
1134 | host->dma_done = 0; | 989 | if (burst > data->blksz) |
1135 | host->dma_in_use = 1; | 990 | burst = data->blksz; |
1136 | } else | 991 | |
1137 | use_dma = 0; | 992 | burst >>= 1; |
993 | |||
994 | if (data->flags & MMC_DATA_WRITE) { | ||
995 | c = host->dma_tx; | ||
996 | bp = &host->dma_tx_burst; | ||
997 | buf = 0x0f80 | (burst - 1) << 0; | ||
998 | dma_data_dir = DMA_TO_DEVICE; | ||
999 | } else { | ||
1000 | c = host->dma_rx; | ||
1001 | bp = &host->dma_rx_burst; | ||
1002 | buf = 0x800f | (burst - 1) << 8; | ||
1003 | dma_data_dir = DMA_FROM_DEVICE; | ||
1004 | } | ||
1005 | |||
1006 | if (!c) | ||
1007 | goto use_pio; | ||
1008 | |||
1009 | /* Only reconfigure if we have a different burst size */ | ||
1010 | if (*bp != burst) { | ||
1011 | struct dma_slave_config cfg; | ||
1012 | |||
1013 | cfg.src_addr = host->phys_base + OMAP_MMC_REG(host, DATA); | ||
1014 | cfg.dst_addr = host->phys_base + OMAP_MMC_REG(host, DATA); | ||
1015 | cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; | ||
1016 | cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; | ||
1017 | cfg.src_maxburst = burst; | ||
1018 | cfg.dst_maxburst = burst; | ||
1019 | |||
1020 | if (dmaengine_slave_config(c, &cfg)) | ||
1021 | goto use_pio; | ||
1022 | |||
1023 | *bp = burst; | ||
1024 | } | ||
1025 | |||
1026 | host->sg_len = dma_map_sg(c->device->dev, data->sg, sg_len, | ||
1027 | dma_data_dir); | ||
1028 | if (host->sg_len == 0) | ||
1029 | goto use_pio; | ||
1030 | |||
1031 | tx = dmaengine_prep_slave_sg(c, data->sg, host->sg_len, | ||
1032 | data->flags & MMC_DATA_WRITE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, | ||
1033 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | ||
1034 | if (!tx) | ||
1035 | goto use_pio; | ||
1036 | |||
1037 | OMAP_MMC_WRITE(host, BUF, buf); | ||
1038 | |||
1039 | tx->callback = mmc_omap_dma_callback; | ||
1040 | tx->callback_param = host; | ||
1041 | dmaengine_submit(tx); | ||
1042 | host->brs_received = 0; | ||
1043 | host->dma_done = 0; | ||
1044 | host->dma_in_use = 1; | ||
1045 | return; | ||
1138 | } | 1046 | } |
1047 | use_pio: | ||
1139 | 1048 | ||
1140 | /* Revert to PIO? */ | 1049 | /* Revert to PIO? */ |
1141 | if (!use_dma) { | 1050 | OMAP_MMC_WRITE(host, BUF, 0x1f1f); |
1142 | OMAP_MMC_WRITE(host, BUF, 0x1f1f); | 1051 | host->total_bytes_left = data->blocks * block_size; |
1143 | host->total_bytes_left = data->blocks * block_size; | 1052 | host->sg_len = sg_len; |
1144 | host->sg_len = sg_len; | 1053 | mmc_omap_sg_to_buf(host); |
1145 | mmc_omap_sg_to_buf(host); | 1054 | host->dma_in_use = 0; |
1146 | host->dma_in_use = 0; | ||
1147 | } | ||
1148 | } | 1055 | } |
1149 | 1056 | ||
1150 | static void mmc_omap_start_request(struct mmc_omap_host *host, | 1057 | static void mmc_omap_start_request(struct mmc_omap_host *host, |
@@ -1157,8 +1064,12 @@ static void mmc_omap_start_request(struct mmc_omap_host *host, | |||
1157 | /* only touch fifo AFTER the controller readies it */ | 1064 | /* only touch fifo AFTER the controller readies it */ |
1158 | mmc_omap_prepare_data(host, req); | 1065 | mmc_omap_prepare_data(host, req); |
1159 | mmc_omap_start_command(host, req->cmd); | 1066 | mmc_omap_start_command(host, req->cmd); |
1160 | if (host->dma_in_use) | 1067 | if (host->dma_in_use) { |
1161 | omap_start_dma(host->dma_ch); | 1068 | struct dma_chan *c = host->data->flags & MMC_DATA_WRITE ? |
1069 | host->dma_tx : host->dma_rx; | ||
1070 | |||
1071 | dma_async_issue_pending(c); | ||
1072 | } | ||
1162 | } | 1073 | } |
1163 | 1074 | ||
1164 | static void mmc_omap_request(struct mmc_host *mmc, struct mmc_request *req) | 1075 | static void mmc_omap_request(struct mmc_host *mmc, struct mmc_request *req) |
@@ -1400,6 +1311,8 @@ static int __devinit mmc_omap_probe(struct platform_device *pdev) | |||
1400 | struct omap_mmc_platform_data *pdata = pdev->dev.platform_data; | 1311 | struct omap_mmc_platform_data *pdata = pdev->dev.platform_data; |
1401 | struct mmc_omap_host *host = NULL; | 1312 | struct mmc_omap_host *host = NULL; |
1402 | struct resource *res; | 1313 | struct resource *res; |
1314 | dma_cap_mask_t mask; | ||
1315 | unsigned sig; | ||
1403 | int i, ret = 0; | 1316 | int i, ret = 0; |
1404 | int irq; | 1317 | int irq; |
1405 | 1318 | ||
@@ -1439,7 +1352,6 @@ static int __devinit mmc_omap_probe(struct platform_device *pdev) | |||
1439 | setup_timer(&host->clk_timer, mmc_omap_clk_timer, (unsigned long) host); | 1352 | setup_timer(&host->clk_timer, mmc_omap_clk_timer, (unsigned long) host); |
1440 | 1353 | ||
1441 | spin_lock_init(&host->dma_lock); | 1354 | spin_lock_init(&host->dma_lock); |
1442 | setup_timer(&host->dma_timer, mmc_omap_dma_timer, (unsigned long) host); | ||
1443 | spin_lock_init(&host->slot_lock); | 1355 | spin_lock_init(&host->slot_lock); |
1444 | init_waitqueue_head(&host->slot_wq); | 1356 | init_waitqueue_head(&host->slot_wq); |
1445 | 1357 | ||
@@ -1450,11 +1362,7 @@ static int __devinit mmc_omap_probe(struct platform_device *pdev) | |||
1450 | host->id = pdev->id; | 1362 | host->id = pdev->id; |
1451 | host->mem_res = res; | 1363 | host->mem_res = res; |
1452 | host->irq = irq; | 1364 | host->irq = irq; |
1453 | |||
1454 | host->use_dma = 1; | 1365 | host->use_dma = 1; |
1455 | host->dev->dma_mask = &pdata->dma_mask; | ||
1456 | host->dma_ch = -1; | ||
1457 | |||
1458 | host->irq = irq; | 1366 | host->irq = irq; |
1459 | host->phys_base = host->mem_res->start; | 1367 | host->phys_base = host->mem_res->start; |
1460 | host->virt_base = ioremap(res->start, resource_size(res)); | 1368 | host->virt_base = ioremap(res->start, resource_size(res)); |
@@ -1474,9 +1382,48 @@ static int __devinit mmc_omap_probe(struct platform_device *pdev) | |||
1474 | goto err_free_iclk; | 1382 | goto err_free_iclk; |
1475 | } | 1383 | } |
1476 | 1384 | ||
1385 | dma_cap_zero(mask); | ||
1386 | dma_cap_set(DMA_SLAVE, mask); | ||
1387 | |||
1388 | host->dma_tx_burst = -1; | ||
1389 | host->dma_rx_burst = -1; | ||
1390 | |||
1391 | if (cpu_is_omap24xx()) | ||
1392 | sig = host->id == 0 ? OMAP24XX_DMA_MMC1_TX : OMAP24XX_DMA_MMC2_TX; | ||
1393 | else | ||
1394 | sig = host->id == 0 ? OMAP_DMA_MMC_TX : OMAP_DMA_MMC2_TX; | ||
1395 | host->dma_tx = dma_request_channel(mask, omap_dma_filter_fn, &sig); | ||
1396 | #if 0 | ||
1397 | if (!host->dma_tx) { | ||
1398 | dev_err(host->dev, "unable to obtain TX DMA engine channel %u\n", | ||
1399 | sig); | ||
1400 | goto err_dma; | ||
1401 | } | ||
1402 | #else | ||
1403 | if (!host->dma_tx) | ||
1404 | dev_warn(host->dev, "unable to obtain TX DMA engine channel %u\n", | ||
1405 | sig); | ||
1406 | #endif | ||
1407 | if (cpu_is_omap24xx()) | ||
1408 | sig = host->id == 0 ? OMAP24XX_DMA_MMC1_RX : OMAP24XX_DMA_MMC2_RX; | ||
1409 | else | ||
1410 | sig = host->id == 0 ? OMAP_DMA_MMC_RX : OMAP_DMA_MMC2_RX; | ||
1411 | host->dma_rx = dma_request_channel(mask, omap_dma_filter_fn, &sig); | ||
1412 | #if 0 | ||
1413 | if (!host->dma_rx) { | ||
1414 | dev_err(host->dev, "unable to obtain RX DMA engine channel %u\n", | ||
1415 | sig); | ||
1416 | goto err_dma; | ||
1417 | } | ||
1418 | #else | ||
1419 | if (!host->dma_rx) | ||
1420 | dev_warn(host->dev, "unable to obtain RX DMA engine channel %u\n", | ||
1421 | sig); | ||
1422 | #endif | ||
1423 | |||
1477 | ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host); | 1424 | ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host); |
1478 | if (ret) | 1425 | if (ret) |
1479 | goto err_free_fclk; | 1426 | goto err_free_dma; |
1480 | 1427 | ||
1481 | if (pdata->init != NULL) { | 1428 | if (pdata->init != NULL) { |
1482 | ret = pdata->init(&pdev->dev); | 1429 | ret = pdata->init(&pdev->dev); |
@@ -1510,7 +1457,11 @@ err_plat_cleanup: | |||
1510 | pdata->cleanup(&pdev->dev); | 1457 | pdata->cleanup(&pdev->dev); |
1511 | err_free_irq: | 1458 | err_free_irq: |
1512 | free_irq(host->irq, host); | 1459 | free_irq(host->irq, host); |
1513 | err_free_fclk: | 1460 | err_free_dma: |
1461 | if (host->dma_tx) | ||
1462 | dma_release_channel(host->dma_tx); | ||
1463 | if (host->dma_rx) | ||
1464 | dma_release_channel(host->dma_rx); | ||
1514 | clk_put(host->fclk); | 1465 | clk_put(host->fclk); |
1515 | err_free_iclk: | 1466 | err_free_iclk: |
1516 | clk_disable(host->iclk); | 1467 | clk_disable(host->iclk); |
@@ -1545,6 +1496,11 @@ static int __devexit mmc_omap_remove(struct platform_device *pdev) | |||
1545 | clk_disable(host->iclk); | 1496 | clk_disable(host->iclk); |
1546 | clk_put(host->iclk); | 1497 | clk_put(host->iclk); |
1547 | 1498 | ||
1499 | if (host->dma_tx) | ||
1500 | dma_release_channel(host->dma_tx); | ||
1501 | if (host->dma_rx) | ||
1502 | dma_release_channel(host->dma_rx); | ||
1503 | |||
1548 | iounmap(host->virt_base); | 1504 | iounmap(host->virt_base); |
1549 | release_mem_region(pdev->resource[0].start, | 1505 | release_mem_region(pdev->resource[0].start, |
1550 | pdev->resource[0].end - pdev->resource[0].start + 1); | 1506 | pdev->resource[0].end - pdev->resource[0].start + 1); |
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c index 389a3eedfc24..3a09f93cc3b6 100644 --- a/drivers/mmc/host/omap_hsmmc.c +++ b/drivers/mmc/host/omap_hsmmc.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/init.h> | 19 | #include <linux/init.h> |
20 | #include <linux/kernel.h> | 20 | #include <linux/kernel.h> |
21 | #include <linux/debugfs.h> | 21 | #include <linux/debugfs.h> |
22 | #include <linux/dmaengine.h> | ||
22 | #include <linux/seq_file.h> | 23 | #include <linux/seq_file.h> |
23 | #include <linux/interrupt.h> | 24 | #include <linux/interrupt.h> |
24 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
@@ -29,6 +30,7 @@ | |||
29 | #include <linux/of.h> | 30 | #include <linux/of.h> |
30 | #include <linux/of_gpio.h> | 31 | #include <linux/of_gpio.h> |
31 | #include <linux/of_device.h> | 32 | #include <linux/of_device.h> |
33 | #include <linux/omap-dma.h> | ||
32 | #include <linux/mmc/host.h> | 34 | #include <linux/mmc/host.h> |
33 | #include <linux/mmc/core.h> | 35 | #include <linux/mmc/core.h> |
34 | #include <linux/mmc/mmc.h> | 36 | #include <linux/mmc/mmc.h> |
@@ -37,7 +39,6 @@ | |||
37 | #include <linux/gpio.h> | 39 | #include <linux/gpio.h> |
38 | #include <linux/regulator/consumer.h> | 40 | #include <linux/regulator/consumer.h> |
39 | #include <linux/pm_runtime.h> | 41 | #include <linux/pm_runtime.h> |
40 | #include <plat/dma.h> | ||
41 | #include <mach/hardware.h> | 42 | #include <mach/hardware.h> |
42 | #include <plat/board.h> | 43 | #include <plat/board.h> |
43 | #include <plat/mmc.h> | 44 | #include <plat/mmc.h> |
@@ -166,7 +167,8 @@ struct omap_hsmmc_host { | |||
166 | int suspended; | 167 | int suspended; |
167 | int irq; | 168 | int irq; |
168 | int use_dma, dma_ch; | 169 | int use_dma, dma_ch; |
169 | int dma_line_tx, dma_line_rx; | 170 | struct dma_chan *tx_chan; |
171 | struct dma_chan *rx_chan; | ||
170 | int slot_id; | 172 | int slot_id; |
171 | int response_busy; | 173 | int response_busy; |
172 | int context_loss; | 174 | int context_loss; |
@@ -797,6 +799,12 @@ omap_hsmmc_get_dma_dir(struct omap_hsmmc_host *host, struct mmc_data *data) | |||
797 | return DMA_FROM_DEVICE; | 799 | return DMA_FROM_DEVICE; |
798 | } | 800 | } |
799 | 801 | ||
802 | static struct dma_chan *omap_hsmmc_get_dma_chan(struct omap_hsmmc_host *host, | ||
803 | struct mmc_data *data) | ||
804 | { | ||
805 | return data->flags & MMC_DATA_WRITE ? host->tx_chan : host->rx_chan; | ||
806 | } | ||
807 | |||
800 | static void omap_hsmmc_request_done(struct omap_hsmmc_host *host, struct mmc_request *mrq) | 808 | static void omap_hsmmc_request_done(struct omap_hsmmc_host *host, struct mmc_request *mrq) |
801 | { | 809 | { |
802 | int dma_ch; | 810 | int dma_ch; |
@@ -889,10 +897,13 @@ static void omap_hsmmc_dma_cleanup(struct omap_hsmmc_host *host, int errno) | |||
889 | spin_unlock_irqrestore(&host->irq_lock, flags); | 897 | spin_unlock_irqrestore(&host->irq_lock, flags); |
890 | 898 | ||
891 | if (host->use_dma && dma_ch != -1) { | 899 | if (host->use_dma && dma_ch != -1) { |
892 | dma_unmap_sg(mmc_dev(host->mmc), host->data->sg, | 900 | struct dma_chan *chan = omap_hsmmc_get_dma_chan(host, host->data); |
893 | host->data->sg_len, | 901 | |
902 | dmaengine_terminate_all(chan); | ||
903 | dma_unmap_sg(chan->device->dev, | ||
904 | host->data->sg, host->data->sg_len, | ||
894 | omap_hsmmc_get_dma_dir(host, host->data)); | 905 | omap_hsmmc_get_dma_dir(host, host->data)); |
895 | omap_free_dma(dma_ch); | 906 | |
896 | host->data->host_cookie = 0; | 907 | host->data->host_cookie = 0; |
897 | } | 908 | } |
898 | host->data = NULL; | 909 | host->data = NULL; |
@@ -1089,7 +1100,7 @@ static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd) | |||
1089 | /* Disable the clocks */ | 1100 | /* Disable the clocks */ |
1090 | pm_runtime_put_sync(host->dev); | 1101 | pm_runtime_put_sync(host->dev); |
1091 | if (host->dbclk) | 1102 | if (host->dbclk) |
1092 | clk_disable(host->dbclk); | 1103 | clk_disable_unprepare(host->dbclk); |
1093 | 1104 | ||
1094 | /* Turn the power off */ | 1105 | /* Turn the power off */ |
1095 | ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); | 1106 | ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); |
@@ -1100,7 +1111,7 @@ static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd) | |||
1100 | vdd); | 1111 | vdd); |
1101 | pm_runtime_get_sync(host->dev); | 1112 | pm_runtime_get_sync(host->dev); |
1102 | if (host->dbclk) | 1113 | if (host->dbclk) |
1103 | clk_enable(host->dbclk); | 1114 | clk_prepare_enable(host->dbclk); |
1104 | 1115 | ||
1105 | if (ret != 0) | 1116 | if (ret != 0) |
1106 | goto err; | 1117 | goto err; |
@@ -1190,90 +1201,29 @@ static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id) | |||
1190 | return IRQ_HANDLED; | 1201 | return IRQ_HANDLED; |
1191 | } | 1202 | } |
1192 | 1203 | ||
1193 | static int omap_hsmmc_get_dma_sync_dev(struct omap_hsmmc_host *host, | 1204 | static void omap_hsmmc_dma_callback(void *param) |
1194 | struct mmc_data *data) | ||
1195 | { | ||
1196 | int sync_dev; | ||
1197 | |||
1198 | if (data->flags & MMC_DATA_WRITE) | ||
1199 | sync_dev = host->dma_line_tx; | ||
1200 | else | ||
1201 | sync_dev = host->dma_line_rx; | ||
1202 | return sync_dev; | ||
1203 | } | ||
1204 | |||
1205 | static void omap_hsmmc_config_dma_params(struct omap_hsmmc_host *host, | ||
1206 | struct mmc_data *data, | ||
1207 | struct scatterlist *sgl) | ||
1208 | { | 1205 | { |
1209 | int blksz, nblk, dma_ch; | 1206 | struct omap_hsmmc_host *host = param; |
1210 | 1207 | struct dma_chan *chan; | |
1211 | dma_ch = host->dma_ch; | ||
1212 | if (data->flags & MMC_DATA_WRITE) { | ||
1213 | omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT, | ||
1214 | (host->mapbase + OMAP_HSMMC_DATA), 0, 0); | ||
1215 | omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC, | ||
1216 | sg_dma_address(sgl), 0, 0); | ||
1217 | } else { | ||
1218 | omap_set_dma_src_params(dma_ch, 0, OMAP_DMA_AMODE_CONSTANT, | ||
1219 | (host->mapbase + OMAP_HSMMC_DATA), 0, 0); | ||
1220 | omap_set_dma_dest_params(dma_ch, 0, OMAP_DMA_AMODE_POST_INC, | ||
1221 | sg_dma_address(sgl), 0, 0); | ||
1222 | } | ||
1223 | |||
1224 | blksz = host->data->blksz; | ||
1225 | nblk = sg_dma_len(sgl) / blksz; | ||
1226 | |||
1227 | omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S32, | ||
1228 | blksz / 4, nblk, OMAP_DMA_SYNC_FRAME, | ||
1229 | omap_hsmmc_get_dma_sync_dev(host, data), | ||
1230 | !(data->flags & MMC_DATA_WRITE)); | ||
1231 | |||
1232 | omap_start_dma(dma_ch); | ||
1233 | } | ||
1234 | |||
1235 | /* | ||
1236 | * DMA call back function | ||
1237 | */ | ||
1238 | static void omap_hsmmc_dma_cb(int lch, u16 ch_status, void *cb_data) | ||
1239 | { | ||
1240 | struct omap_hsmmc_host *host = cb_data; | ||
1241 | struct mmc_data *data; | 1208 | struct mmc_data *data; |
1242 | int dma_ch, req_in_progress; | 1209 | int req_in_progress; |
1243 | unsigned long flags; | ||
1244 | 1210 | ||
1245 | if (!(ch_status & OMAP_DMA_BLOCK_IRQ)) { | 1211 | spin_lock_irq(&host->irq_lock); |
1246 | dev_warn(mmc_dev(host->mmc), "unexpected dma status %x\n", | ||
1247 | ch_status); | ||
1248 | return; | ||
1249 | } | ||
1250 | |||
1251 | spin_lock_irqsave(&host->irq_lock, flags); | ||
1252 | if (host->dma_ch < 0) { | 1212 | if (host->dma_ch < 0) { |
1253 | spin_unlock_irqrestore(&host->irq_lock, flags); | 1213 | spin_unlock_irq(&host->irq_lock); |
1254 | return; | 1214 | return; |
1255 | } | 1215 | } |
1256 | 1216 | ||
1257 | data = host->mrq->data; | 1217 | data = host->mrq->data; |
1258 | host->dma_sg_idx++; | 1218 | chan = omap_hsmmc_get_dma_chan(host, data); |
1259 | if (host->dma_sg_idx < host->dma_len) { | ||
1260 | /* Fire up the next transfer. */ | ||
1261 | omap_hsmmc_config_dma_params(host, data, | ||
1262 | data->sg + host->dma_sg_idx); | ||
1263 | spin_unlock_irqrestore(&host->irq_lock, flags); | ||
1264 | return; | ||
1265 | } | ||
1266 | |||
1267 | if (!data->host_cookie) | 1219 | if (!data->host_cookie) |
1268 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, | 1220 | dma_unmap_sg(chan->device->dev, |
1221 | data->sg, data->sg_len, | ||
1269 | omap_hsmmc_get_dma_dir(host, data)); | 1222 | omap_hsmmc_get_dma_dir(host, data)); |
1270 | 1223 | ||
1271 | req_in_progress = host->req_in_progress; | 1224 | req_in_progress = host->req_in_progress; |
1272 | dma_ch = host->dma_ch; | ||
1273 | host->dma_ch = -1; | 1225 | host->dma_ch = -1; |
1274 | spin_unlock_irqrestore(&host->irq_lock, flags); | 1226 | spin_unlock_irq(&host->irq_lock); |
1275 | |||
1276 | omap_free_dma(dma_ch); | ||
1277 | 1227 | ||
1278 | /* If DMA has finished after TC, complete the request */ | 1228 | /* If DMA has finished after TC, complete the request */ |
1279 | if (!req_in_progress) { | 1229 | if (!req_in_progress) { |
@@ -1286,7 +1236,8 @@ static void omap_hsmmc_dma_cb(int lch, u16 ch_status, void *cb_data) | |||
1286 | 1236 | ||
1287 | static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host *host, | 1237 | static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host *host, |
1288 | struct mmc_data *data, | 1238 | struct mmc_data *data, |
1289 | struct omap_hsmmc_next *next) | 1239 | struct omap_hsmmc_next *next, |
1240 | struct dma_chan *chan) | ||
1290 | { | 1241 | { |
1291 | int dma_len; | 1242 | int dma_len; |
1292 | 1243 | ||
@@ -1301,8 +1252,7 @@ static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host *host, | |||
1301 | /* Check if next job is already prepared */ | 1252 | /* Check if next job is already prepared */ |
1302 | if (next || | 1253 | if (next || |
1303 | (!next && data->host_cookie != host->next_data.cookie)) { | 1254 | (!next && data->host_cookie != host->next_data.cookie)) { |
1304 | dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg, | 1255 | dma_len = dma_map_sg(chan->device->dev, data->sg, data->sg_len, |
1305 | data->sg_len, | ||
1306 | omap_hsmmc_get_dma_dir(host, data)); | 1256 | omap_hsmmc_get_dma_dir(host, data)); |
1307 | 1257 | ||
1308 | } else { | 1258 | } else { |
@@ -1329,8 +1279,11 @@ static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host *host, | |||
1329 | static int omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host, | 1279 | static int omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host, |
1330 | struct mmc_request *req) | 1280 | struct mmc_request *req) |
1331 | { | 1281 | { |
1332 | int dma_ch = 0, ret = 0, i; | 1282 | struct dma_slave_config cfg; |
1283 | struct dma_async_tx_descriptor *tx; | ||
1284 | int ret = 0, i; | ||
1333 | struct mmc_data *data = req->data; | 1285 | struct mmc_data *data = req->data; |
1286 | struct dma_chan *chan; | ||
1334 | 1287 | ||
1335 | /* Sanity check: all the SG entries must be aligned by block size. */ | 1288 | /* Sanity check: all the SG entries must be aligned by block size. */ |
1336 | for (i = 0; i < data->sg_len; i++) { | 1289 | for (i = 0; i < data->sg_len; i++) { |
@@ -1348,22 +1301,41 @@ static int omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host, | |||
1348 | 1301 | ||
1349 | BUG_ON(host->dma_ch != -1); | 1302 | BUG_ON(host->dma_ch != -1); |
1350 | 1303 | ||
1351 | ret = omap_request_dma(omap_hsmmc_get_dma_sync_dev(host, data), | 1304 | chan = omap_hsmmc_get_dma_chan(host, data); |
1352 | "MMC/SD", omap_hsmmc_dma_cb, host, &dma_ch); | 1305 | |
1353 | if (ret != 0) { | 1306 | cfg.src_addr = host->mapbase + OMAP_HSMMC_DATA; |
1354 | dev_err(mmc_dev(host->mmc), | 1307 | cfg.dst_addr = host->mapbase + OMAP_HSMMC_DATA; |
1355 | "%s: omap_request_dma() failed with %d\n", | 1308 | cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; |
1356 | mmc_hostname(host->mmc), ret); | 1309 | cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; |
1310 | cfg.src_maxburst = data->blksz / 4; | ||
1311 | cfg.dst_maxburst = data->blksz / 4; | ||
1312 | |||
1313 | ret = dmaengine_slave_config(chan, &cfg); | ||
1314 | if (ret) | ||
1357 | return ret; | 1315 | return ret; |
1358 | } | 1316 | |
1359 | ret = omap_hsmmc_pre_dma_transfer(host, data, NULL); | 1317 | ret = omap_hsmmc_pre_dma_transfer(host, data, NULL, chan); |
1360 | if (ret) | 1318 | if (ret) |
1361 | return ret; | 1319 | return ret; |
1362 | 1320 | ||
1363 | host->dma_ch = dma_ch; | 1321 | tx = dmaengine_prep_slave_sg(chan, data->sg, data->sg_len, |
1364 | host->dma_sg_idx = 0; | 1322 | data->flags & MMC_DATA_WRITE ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM, |
1323 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); | ||
1324 | if (!tx) { | ||
1325 | dev_err(mmc_dev(host->mmc), "prep_slave_sg() failed\n"); | ||
1326 | /* FIXME: cleanup */ | ||
1327 | return -1; | ||
1328 | } | ||
1329 | |||
1330 | tx->callback = omap_hsmmc_dma_callback; | ||
1331 | tx->callback_param = host; | ||
1332 | |||
1333 | /* Does not fail */ | ||
1334 | dmaengine_submit(tx); | ||
1365 | 1335 | ||
1366 | omap_hsmmc_config_dma_params(host, data, data->sg); | 1336 | host->dma_ch = 1; |
1337 | |||
1338 | dma_async_issue_pending(chan); | ||
1367 | 1339 | ||
1368 | return 0; | 1340 | return 0; |
1369 | } | 1341 | } |
@@ -1445,11 +1417,11 @@ static void omap_hsmmc_post_req(struct mmc_host *mmc, struct mmc_request *mrq, | |||
1445 | struct omap_hsmmc_host *host = mmc_priv(mmc); | 1417 | struct omap_hsmmc_host *host = mmc_priv(mmc); |
1446 | struct mmc_data *data = mrq->data; | 1418 | struct mmc_data *data = mrq->data; |
1447 | 1419 | ||
1448 | if (host->use_dma) { | 1420 | if (host->use_dma && data->host_cookie) { |
1449 | if (data->host_cookie) | 1421 | struct dma_chan *c = omap_hsmmc_get_dma_chan(host, data); |
1450 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, | 1422 | |
1451 | data->sg_len, | 1423 | dma_unmap_sg(c->device->dev, data->sg, data->sg_len, |
1452 | omap_hsmmc_get_dma_dir(host, data)); | 1424 | omap_hsmmc_get_dma_dir(host, data)); |
1453 | data->host_cookie = 0; | 1425 | data->host_cookie = 0; |
1454 | } | 1426 | } |
1455 | } | 1427 | } |
@@ -1464,10 +1436,13 @@ static void omap_hsmmc_pre_req(struct mmc_host *mmc, struct mmc_request *mrq, | |||
1464 | return ; | 1436 | return ; |
1465 | } | 1437 | } |
1466 | 1438 | ||
1467 | if (host->use_dma) | 1439 | if (host->use_dma) { |
1440 | struct dma_chan *c = omap_hsmmc_get_dma_chan(host, mrq->data); | ||
1441 | |||
1468 | if (omap_hsmmc_pre_dma_transfer(host, mrq->data, | 1442 | if (omap_hsmmc_pre_dma_transfer(host, mrq->data, |
1469 | &host->next_data)) | 1443 | &host->next_data, c)) |
1470 | mrq->data->host_cookie = 0; | 1444 | mrq->data->host_cookie = 0; |
1445 | } | ||
1471 | } | 1446 | } |
1472 | 1447 | ||
1473 | /* | 1448 | /* |
@@ -1800,6 +1775,8 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev) | |||
1800 | struct resource *res; | 1775 | struct resource *res; |
1801 | int ret, irq; | 1776 | int ret, irq; |
1802 | const struct of_device_id *match; | 1777 | const struct of_device_id *match; |
1778 | dma_cap_mask_t mask; | ||
1779 | unsigned tx_req, rx_req; | ||
1803 | 1780 | ||
1804 | match = of_match_device(of_match_ptr(omap_mmc_of_match), &pdev->dev); | 1781 | match = of_match_device(of_match_ptr(omap_mmc_of_match), &pdev->dev); |
1805 | if (match) { | 1782 | if (match) { |
@@ -1844,7 +1821,6 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev) | |||
1844 | host->pdata = pdata; | 1821 | host->pdata = pdata; |
1845 | host->dev = &pdev->dev; | 1822 | host->dev = &pdev->dev; |
1846 | host->use_dma = 1; | 1823 | host->use_dma = 1; |
1847 | host->dev->dma_mask = &pdata->dma_mask; | ||
1848 | host->dma_ch = -1; | 1824 | host->dma_ch = -1; |
1849 | host->irq = irq; | 1825 | host->irq = irq; |
1850 | host->slot_id = 0; | 1826 | host->slot_id = 0; |
@@ -1899,7 +1875,7 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev) | |||
1899 | if (IS_ERR(host->dbclk)) { | 1875 | if (IS_ERR(host->dbclk)) { |
1900 | dev_warn(mmc_dev(host->mmc), "Failed to get debounce clk\n"); | 1876 | dev_warn(mmc_dev(host->mmc), "Failed to get debounce clk\n"); |
1901 | host->dbclk = NULL; | 1877 | host->dbclk = NULL; |
1902 | } else if (clk_enable(host->dbclk) != 0) { | 1878 | } else if (clk_prepare_enable(host->dbclk) != 0) { |
1903 | dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n"); | 1879 | dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n"); |
1904 | clk_put(host->dbclk); | 1880 | clk_put(host->dbclk); |
1905 | host->dbclk = NULL; | 1881 | host->dbclk = NULL; |
@@ -1931,16 +1907,35 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev) | |||
1931 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); | 1907 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); |
1932 | if (!res) { | 1908 | if (!res) { |
1933 | dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n"); | 1909 | dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n"); |
1910 | ret = -ENXIO; | ||
1934 | goto err_irq; | 1911 | goto err_irq; |
1935 | } | 1912 | } |
1936 | host->dma_line_tx = res->start; | 1913 | tx_req = res->start; |
1937 | 1914 | ||
1938 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); | 1915 | res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); |
1939 | if (!res) { | 1916 | if (!res) { |
1940 | dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n"); | 1917 | dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n"); |
1918 | ret = -ENXIO; | ||
1919 | goto err_irq; | ||
1920 | } | ||
1921 | rx_req = res->start; | ||
1922 | |||
1923 | dma_cap_zero(mask); | ||
1924 | dma_cap_set(DMA_SLAVE, mask); | ||
1925 | |||
1926 | host->rx_chan = dma_request_channel(mask, omap_dma_filter_fn, &rx_req); | ||
1927 | if (!host->rx_chan) { | ||
1928 | dev_err(mmc_dev(host->mmc), "unable to obtain RX DMA engine channel %u\n", rx_req); | ||
1929 | ret = -ENXIO; | ||
1930 | goto err_irq; | ||
1931 | } | ||
1932 | |||
1933 | host->tx_chan = dma_request_channel(mask, omap_dma_filter_fn, &tx_req); | ||
1934 | if (!host->tx_chan) { | ||
1935 | dev_err(mmc_dev(host->mmc), "unable to obtain TX DMA engine channel %u\n", tx_req); | ||
1936 | ret = -ENXIO; | ||
1941 | goto err_irq; | 1937 | goto err_irq; |
1942 | } | 1938 | } |
1943 | host->dma_line_rx = res->start; | ||
1944 | 1939 | ||
1945 | /* Request IRQ for MMC operations */ | 1940 | /* Request IRQ for MMC operations */ |
1946 | ret = request_irq(host->irq, omap_hsmmc_irq, 0, | 1941 | ret = request_irq(host->irq, omap_hsmmc_irq, 0, |
@@ -2019,11 +2014,15 @@ err_reg: | |||
2019 | err_irq_cd_init: | 2014 | err_irq_cd_init: |
2020 | free_irq(host->irq, host); | 2015 | free_irq(host->irq, host); |
2021 | err_irq: | 2016 | err_irq: |
2017 | if (host->tx_chan) | ||
2018 | dma_release_channel(host->tx_chan); | ||
2019 | if (host->rx_chan) | ||
2020 | dma_release_channel(host->rx_chan); | ||
2022 | pm_runtime_put_sync(host->dev); | 2021 | pm_runtime_put_sync(host->dev); |
2023 | pm_runtime_disable(host->dev); | 2022 | pm_runtime_disable(host->dev); |
2024 | clk_put(host->fclk); | 2023 | clk_put(host->fclk); |
2025 | if (host->dbclk) { | 2024 | if (host->dbclk) { |
2026 | clk_disable(host->dbclk); | 2025 | clk_disable_unprepare(host->dbclk); |
2027 | clk_put(host->dbclk); | 2026 | clk_put(host->dbclk); |
2028 | } | 2027 | } |
2029 | err1: | 2028 | err1: |
@@ -2054,11 +2053,16 @@ static int __devexit omap_hsmmc_remove(struct platform_device *pdev) | |||
2054 | if (mmc_slot(host).card_detect_irq) | 2053 | if (mmc_slot(host).card_detect_irq) |
2055 | free_irq(mmc_slot(host).card_detect_irq, host); | 2054 | free_irq(mmc_slot(host).card_detect_irq, host); |
2056 | 2055 | ||
2056 | if (host->tx_chan) | ||
2057 | dma_release_channel(host->tx_chan); | ||
2058 | if (host->rx_chan) | ||
2059 | dma_release_channel(host->rx_chan); | ||
2060 | |||
2057 | pm_runtime_put_sync(host->dev); | 2061 | pm_runtime_put_sync(host->dev); |
2058 | pm_runtime_disable(host->dev); | 2062 | pm_runtime_disable(host->dev); |
2059 | clk_put(host->fclk); | 2063 | clk_put(host->fclk); |
2060 | if (host->dbclk) { | 2064 | if (host->dbclk) { |
2061 | clk_disable(host->dbclk); | 2065 | clk_disable_unprepare(host->dbclk); |
2062 | clk_put(host->dbclk); | 2066 | clk_put(host->dbclk); |
2063 | } | 2067 | } |
2064 | 2068 | ||
@@ -2116,7 +2120,7 @@ static int omap_hsmmc_suspend(struct device *dev) | |||
2116 | } | 2120 | } |
2117 | 2121 | ||
2118 | if (host->dbclk) | 2122 | if (host->dbclk) |
2119 | clk_disable(host->dbclk); | 2123 | clk_disable_unprepare(host->dbclk); |
2120 | err: | 2124 | err: |
2121 | pm_runtime_put_sync(host->dev); | 2125 | pm_runtime_put_sync(host->dev); |
2122 | return ret; | 2126 | return ret; |
@@ -2137,7 +2141,7 @@ static int omap_hsmmc_resume(struct device *dev) | |||
2137 | pm_runtime_get_sync(host->dev); | 2141 | pm_runtime_get_sync(host->dev); |
2138 | 2142 | ||
2139 | if (host->dbclk) | 2143 | if (host->dbclk) |
2140 | clk_enable(host->dbclk); | 2144 | clk_prepare_enable(host->dbclk); |
2141 | 2145 | ||
2142 | if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) | 2146 | if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) |
2143 | omap_hsmmc_conf_bus_power(host); | 2147 | 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-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 f4b8b4db3a9a..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 | ||
@@ -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); |