aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/core
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mmc/core')
-rw-r--r--drivers/mmc/core/Makefile3
-rw-r--r--drivers/mmc/core/core.c26
-rw-r--r--drivers/mmc/core/core.h2
-rw-r--r--drivers/mmc/core/host.c5
-rw-r--r--drivers/mmc/core/mmc.c86
-rw-r--r--drivers/mmc/core/mmc_ops.c2
-rw-r--r--drivers/mmc/core/quirks.c84
-rw-r--r--drivers/mmc/core/sd.c1
-rw-r--r--drivers/mmc/core/sd_ops.c14
-rw-r--r--drivers/mmc/core/sdio.c9
-rw-r--r--drivers/mmc/core/sdio_irq.c2
11 files changed, 222 insertions, 12 deletions
diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile
index 86b479119332..639501970b41 100644
--- a/drivers/mmc/core/Makefile
+++ b/drivers/mmc/core/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_MMC) += mmc_core.o
6mmc_core-y := core.o bus.o host.o \ 6mmc_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
10 11
11mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o 12mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 150b5f3cd401..1f453acc8682 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -167,8 +167,6 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
167 167
168 WARN_ON(!host->claimed); 168 WARN_ON(!host->claimed);
169 169
170 led_trigger_event(host->led, LED_FULL);
171
172 mrq->cmd->error = 0; 170 mrq->cmd->error = 0;
173 mrq->cmd->mrq = mrq; 171 mrq->cmd->mrq = mrq;
174 if (mrq->data) { 172 if (mrq->data) {
@@ -194,6 +192,7 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
194 } 192 }
195 } 193 }
196 mmc_host_clk_ungate(host); 194 mmc_host_clk_ungate(host);
195 led_trigger_event(host->led, LED_FULL);
197 host->ops->request(host, mrq); 196 host->ops->request(host, mrq);
198} 197}
199 198
@@ -528,7 +527,14 @@ int mmc_try_claim_host(struct mmc_host *host)
528} 527}
529EXPORT_SYMBOL(mmc_try_claim_host); 528EXPORT_SYMBOL(mmc_try_claim_host);
530 529
531static void mmc_do_release_host(struct mmc_host *host) 530/**
531 * mmc_do_release_host - release a claimed host
532 * @host: mmc host to release
533 *
534 * If you successfully claimed a host, this function will
535 * release it again.
536 */
537void mmc_do_release_host(struct mmc_host *host)
532{ 538{
533 unsigned long flags; 539 unsigned long flags;
534 540
@@ -543,6 +549,7 @@ static void mmc_do_release_host(struct mmc_host *host)
543 wake_up(&host->wq); 549 wake_up(&host->wq);
544 } 550 }
545} 551}
552EXPORT_SYMBOL(mmc_do_release_host);
546 553
547void mmc_host_deeper_disable(struct work_struct *work) 554void mmc_host_deeper_disable(struct work_struct *work)
548{ 555{
@@ -1002,6 +1009,13 @@ static void mmc_power_off(struct mmc_host *host)
1002{ 1009{
1003 host->ios.clock = 0; 1010 host->ios.clock = 0;
1004 host->ios.vdd = 0; 1011 host->ios.vdd = 0;
1012
1013 /*
1014 * Reset ocr mask to be the highest possible voltage supported for
1015 * this mmc host. This value will be used at next power up.
1016 */
1017 host->ocr = 1 << (fls(host->ocr_avail) - 1);
1018
1005 if (!mmc_host_is_spi(host)) { 1019 if (!mmc_host_is_spi(host)) {
1006 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; 1020 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
1007 host->ios.chip_select = MMC_CS_DONTCARE; 1021 host->ios.chip_select = MMC_CS_DONTCARE;
@@ -1495,6 +1509,12 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
1495 mmc_hostname(host), __func__, host->f_init); 1509 mmc_hostname(host), __func__, host->f_init);
1496#endif 1510#endif
1497 mmc_power_up(host); 1511 mmc_power_up(host);
1512
1513 /*
1514 * sdio_reset sends CMD52 to reset card. Since we do not know
1515 * if the card is being re-initialized, just send it. CMD52
1516 * should be ignored by SD/eMMC cards.
1517 */
1498 sdio_reset(host); 1518 sdio_reset(host);
1499 mmc_go_idle(host); 1519 mmc_go_idle(host);
1500 1520
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index ca1fdde29df6..20b1c0831eac 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -61,6 +61,8 @@ int mmc_attach_mmc(struct mmc_host *host);
61int mmc_attach_sd(struct mmc_host *host); 61int mmc_attach_sd(struct mmc_host *host);
62int mmc_attach_sdio(struct mmc_host *host); 62int mmc_attach_sdio(struct mmc_host *host);
63 63
64void mmc_fixup_device(struct mmc_card *card);
65
64/* Module parameters */ 66/* Module parameters */
65extern int use_spi_crc; 67extern int use_spi_crc;
66 68
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index b3ac6c5bc5c6..461e6a17fb90 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -160,10 +160,7 @@ static bool mmc_host_may_gate_card(struct mmc_card *card)
160 * gate the clock, because there is somebody out there that may still 160 * gate the clock, because there is somebody out there that may still
161 * be using it. 161 * be using it.
162 */ 162 */
163 if (mmc_card_sdio(card)) 163 return !(card->quirks & MMC_QUIRK_BROKEN_CLK_GATING);
164 return false;
165
166 return true;
167} 164}
168 165
169/** 166/**
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 16006ef153fe..772d0d0a541b 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -302,6 +302,44 @@ static int mmc_read_ext_csd(struct mmc_card *card)
302 } 302 }
303 303
304 if (card->ext_csd.rev >= 4) { 304 if (card->ext_csd.rev >= 4) {
305 /*
306 * Enhanced area feature support -- check whether the eMMC
307 * card has the Enhanced area enabled. If so, export enhanced
308 * area offset and size to user by adding sysfs interface.
309 */
310 if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) &&
311 (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) {
312 u8 hc_erase_grp_sz =
313 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
314 u8 hc_wp_grp_sz =
315 ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
316
317 card->ext_csd.enhanced_area_en = 1;
318 /*
319 * calculate the enhanced data area offset, in bytes
320 */
321 card->ext_csd.enhanced_area_offset =
322 (ext_csd[139] << 24) + (ext_csd[138] << 16) +
323 (ext_csd[137] << 8) + ext_csd[136];
324 if (mmc_card_blockaddr(card))
325 card->ext_csd.enhanced_area_offset <<= 9;
326 /*
327 * calculate the enhanced data area size, in kilobytes
328 */
329 card->ext_csd.enhanced_area_size =
330 (ext_csd[142] << 16) + (ext_csd[141] << 8) +
331 ext_csd[140];
332 card->ext_csd.enhanced_area_size *=
333 (size_t)(hc_erase_grp_sz * hc_wp_grp_sz);
334 card->ext_csd.enhanced_area_size <<= 9;
335 } else {
336 /*
337 * If the enhanced area is not enabled, disable these
338 * device attributes.
339 */
340 card->ext_csd.enhanced_area_offset = -EINVAL;
341 card->ext_csd.enhanced_area_size = -EINVAL;
342 }
305 card->ext_csd.sec_trim_mult = 343 card->ext_csd.sec_trim_mult =
306 ext_csd[EXT_CSD_SEC_TRIM_MULT]; 344 ext_csd[EXT_CSD_SEC_TRIM_MULT];
307 card->ext_csd.sec_erase_mult = 345 card->ext_csd.sec_erase_mult =
@@ -336,6 +374,9 @@ MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
336MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name); 374MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
337MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid); 375MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
338MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial); 376MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
377MMC_DEV_ATTR(enhanced_area_offset, "%llu\n",
378 card->ext_csd.enhanced_area_offset);
379MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size);
339 380
340static struct attribute *mmc_std_attrs[] = { 381static struct attribute *mmc_std_attrs[] = {
341 &dev_attr_cid.attr, 382 &dev_attr_cid.attr,
@@ -349,6 +390,8 @@ static struct attribute *mmc_std_attrs[] = {
349 &dev_attr_name.attr, 390 &dev_attr_name.attr,
350 &dev_attr_oemid.attr, 391 &dev_attr_oemid.attr,
351 &dev_attr_serial.attr, 392 &dev_attr_serial.attr,
393 &dev_attr_enhanced_area_offset.attr,
394 &dev_attr_enhanced_area_size.attr,
352 NULL, 395 NULL,
353}; 396};
354 397
@@ -378,6 +421,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
378 int err, ddr = 0; 421 int err, ddr = 0;
379 u32 cid[4]; 422 u32 cid[4];
380 unsigned int max_dtr; 423 unsigned int max_dtr;
424 u32 rocr;
381 425
382 BUG_ON(!host); 426 BUG_ON(!host);
383 WARN_ON(!host->claimed); 427 WARN_ON(!host->claimed);
@@ -391,7 +435,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
391 mmc_go_idle(host); 435 mmc_go_idle(host);
392 436
393 /* The extra bit indicates that we support high capacity */ 437 /* The extra bit indicates that we support high capacity */
394 err = mmc_send_op_cond(host, ocr | (1 << 30), NULL); 438 err = mmc_send_op_cond(host, ocr | (1 << 30), &rocr);
395 if (err) 439 if (err)
396 goto err; 440 goto err;
397 441
@@ -479,11 +523,51 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
479 err = mmc_read_ext_csd(card); 523 err = mmc_read_ext_csd(card);
480 if (err) 524 if (err)
481 goto free_card; 525 goto free_card;
526
527 /* If doing byte addressing, check if required to do sector
528 * addressing. Handle the case of <2GB cards needing sector
529 * addressing. See section 8.1 JEDEC Standard JED84-A441;
530 * ocr register has bit 30 set for sector addressing.
531 */
532 if (!(mmc_card_blockaddr(card)) && (rocr & (1<<30)))
533 mmc_card_set_blockaddr(card);
534
482 /* Erase size depends on CSD and Extended CSD */ 535 /* Erase size depends on CSD and Extended CSD */
483 mmc_set_erase_size(card); 536 mmc_set_erase_size(card);
484 } 537 }
485 538
486 /* 539 /*
540 * If enhanced_area_en is TRUE, host needs to enable ERASE_GRP_DEF
541 * bit. This bit will be lost every time after a reset or power off.
542 */
543 if (card->ext_csd.enhanced_area_en) {
544 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
545 EXT_CSD_ERASE_GROUP_DEF, 1);
546
547 if (err && err != -EBADMSG)
548 goto free_card;
549
550 if (err) {
551 err = 0;
552 /*
553 * Just disable enhanced area off & sz
554 * will try to enable ERASE_GROUP_DEF
555 * during next time reinit
556 */
557 card->ext_csd.enhanced_area_offset = -EINVAL;
558 card->ext_csd.enhanced_area_size = -EINVAL;
559 } else {
560 card->ext_csd.erase_group_def = 1;
561 /*
562 * enable ERASE_GRP_DEF successfully.
563 * This will affect the erase size, so
564 * here need to reset erase size
565 */
566 mmc_set_erase_size(card);
567 }
568 }
569
570 /*
487 * Activate high speed (if supported) 571 * Activate high speed (if supported)
488 */ 572 */
489 if ((card->ext_csd.hs_max_dtr != 0) && 573 if ((card->ext_csd.hs_max_dtr != 0) &&
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 60842f878ded..f3b22bf89cc9 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -105,7 +105,7 @@ int mmc_go_idle(struct mmc_host *host)
105 * that in case of hardware that won't pull up DAT3/nCS otherwise. 105 * that in case of hardware that won't pull up DAT3/nCS otherwise.
106 * 106 *
107 * SPI hosts ignore ios.chip_select; it's managed according to 107 * SPI hosts ignore ios.chip_select; it's managed according to
108 * rules that must accomodate non-MMC slaves which this layer 108 * rules that must accommodate non-MMC slaves which this layer
109 * won't even know about. 109 * won't even know about.
110 */ 110 */
111 if (!mmc_host_is_spi(host)) { 111 if (!mmc_host_is_spi(host)) {
diff --git a/drivers/mmc/core/quirks.c b/drivers/mmc/core/quirks.c
new file mode 100644
index 000000000000..11118b74eb20
--- /dev/null
+++ b/drivers/mmc/core/quirks.c
@@ -0,0 +1,84 @@
1/*
2 * This file contains work-arounds for many known sdio hardware
3 * bugs.
4 *
5 * Copyright (c) 2011 Pierre Tardy <tardyp@gmail.com>
6 * Inspired from pci fixup code:
7 * Copyright (c) 1999 Martin Mares <mj@ucw.cz>
8 *
9 */
10
11#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/mmc/card.h>
14#include <linux/mod_devicetable.h>
15
16/*
17 * The world is not perfect and supplies us with broken mmc/sdio devices.
18 * For at least a part of these bugs we need a work-around
19 */
20
21struct mmc_fixup {
22 u16 vendor, device; /* You can use SDIO_ANY_ID here of course */
23 void (*vendor_fixup)(struct mmc_card *card, int data);
24 int data;
25};
26
27/*
28 * This hook just adds a quirk unconditionnally
29 */
30static void __maybe_unused add_quirk(struct mmc_card *card, int data)
31{
32 card->quirks |= data;
33}
34
35/*
36 * This hook just removes a quirk unconditionnally
37 */
38static void __maybe_unused remove_quirk(struct mmc_card *card, int data)
39{
40 card->quirks &= ~data;
41}
42
43/*
44 * This hook just adds a quirk for all sdio devices
45 */
46static void add_quirk_for_sdio_devices(struct mmc_card *card, int data)
47{
48 if (mmc_card_sdio(card))
49 card->quirks |= data;
50}
51
52#ifndef SDIO_VENDOR_ID_TI
53#define SDIO_VENDOR_ID_TI 0x0097
54#endif
55
56#ifndef SDIO_DEVICE_ID_TI_WL1271
57#define SDIO_DEVICE_ID_TI_WL1271 0x4076
58#endif
59
60static const struct mmc_fixup mmc_fixup_methods[] = {
61 /* by default sdio devices are considered CLK_GATING broken */
62 /* good cards will be whitelisted as they are tested */
63 { SDIO_ANY_ID, SDIO_ANY_ID,
64 add_quirk_for_sdio_devices, MMC_QUIRK_BROKEN_CLK_GATING },
65 { SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
66 remove_quirk, MMC_QUIRK_BROKEN_CLK_GATING },
67 { 0 }
68};
69
70void mmc_fixup_device(struct mmc_card *card)
71{
72 const struct mmc_fixup *f;
73
74 for (f = mmc_fixup_methods; f->vendor_fixup; f++) {
75 if ((f->vendor == card->cis.vendor
76 || f->vendor == (u16) SDIO_ANY_ID) &&
77 (f->device == card->cis.device
78 || f->device == (u16) SDIO_ANY_ID)) {
79 dev_dbg(&card->dev, "calling %pF\n", f->vendor_fixup);
80 f->vendor_fixup(card, f->data);
81 }
82 }
83}
84EXPORT_SYMBOL(mmc_fixup_device);
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index d18c32bca99b..6dac89fe0535 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -21,6 +21,7 @@
21#include "core.h" 21#include "core.h"
22#include "bus.h" 22#include "bus.h"
23#include "mmc_ops.h" 23#include "mmc_ops.h"
24#include "sd.h"
24#include "sd_ops.h" 25#include "sd_ops.h"
25 26
26static const unsigned int tran_exp[] = { 27static const unsigned int tran_exp[] = {
diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
index 797cdb5887fd..76af349c14b4 100644
--- a/drivers/mmc/core/sd_ops.c
+++ b/drivers/mmc/core/sd_ops.c
@@ -9,6 +9,7 @@
9 * your option) any later version. 9 * your option) any later version.
10 */ 10 */
11 11
12#include <linux/slab.h>
12#include <linux/types.h> 13#include <linux/types.h>
13#include <linux/scatterlist.h> 14#include <linux/scatterlist.h>
14 15
@@ -252,6 +253,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
252 struct mmc_command cmd; 253 struct mmc_command cmd;
253 struct mmc_data data; 254 struct mmc_data data;
254 struct scatterlist sg; 255 struct scatterlist sg;
256 void *data_buf;
255 257
256 BUG_ON(!card); 258 BUG_ON(!card);
257 BUG_ON(!card->host); 259 BUG_ON(!card->host);
@@ -263,6 +265,13 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
263 if (err) 265 if (err)
264 return err; 266 return err;
265 267
268 /* dma onto stack is unsafe/nonportable, but callers to this
269 * routine normally provide temporary on-stack buffers ...
270 */
271 data_buf = kmalloc(sizeof(card->raw_scr), GFP_KERNEL);
272 if (data_buf == NULL)
273 return -ENOMEM;
274
266 memset(&mrq, 0, sizeof(struct mmc_request)); 275 memset(&mrq, 0, sizeof(struct mmc_request));
267 memset(&cmd, 0, sizeof(struct mmc_command)); 276 memset(&cmd, 0, sizeof(struct mmc_command));
268 memset(&data, 0, sizeof(struct mmc_data)); 277 memset(&data, 0, sizeof(struct mmc_data));
@@ -280,12 +289,15 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
280 data.sg = &sg; 289 data.sg = &sg;
281 data.sg_len = 1; 290 data.sg_len = 1;
282 291
283 sg_init_one(&sg, scr, 8); 292 sg_init_one(&sg, data_buf, 8);
284 293
285 mmc_set_data_timeout(&data, card); 294 mmc_set_data_timeout(&data, card);
286 295
287 mmc_wait_for_req(card->host, &mrq); 296 mmc_wait_for_req(card->host, &mrq);
288 297
298 memcpy(scr, data_buf, sizeof(card->raw_scr));
299 kfree(data_buf);
300
289 if (cmd.error) 301 if (cmd.error)
290 return cmd.error; 302 return cmd.error;
291 if (data.error) 303 if (data.error)
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index ebc62ad4cc56..db0f0b44d684 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -395,6 +395,14 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
395 if (err) 395 if (err)
396 goto remove; 396 goto remove;
397 397
398 /*
399 * Update oldcard with the new RCA received from the SDIO
400 * device -- we're doing this so that it's updated in the
401 * "card" struct when oldcard overwrites that later.
402 */
403 if (oldcard)
404 oldcard->rca = card->rca;
405
398 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); 406 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
399 } 407 }
400 408
@@ -458,6 +466,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
458 466
459 card = oldcard; 467 card = oldcard;
460 } 468 }
469 mmc_fixup_device(card);
461 470
462 if (card->type == MMC_TYPE_SD_COMBO) { 471 if (card->type == MMC_TYPE_SD_COMBO) {
463 err = mmc_sd_setup_card(host, card, oldcard != NULL); 472 err = mmc_sd_setup_card(host, card, oldcard != NULL);
diff --git a/drivers/mmc/core/sdio_irq.c b/drivers/mmc/core/sdio_irq.c
index bb192f90e8e9..b3001617e67d 100644
--- a/drivers/mmc/core/sdio_irq.c
+++ b/drivers/mmc/core/sdio_irq.c
@@ -45,7 +45,7 @@ static int process_sdio_pending_irqs(struct mmc_card *card)
45 struct sdio_func *func = card->sdio_func[i - 1]; 45 struct sdio_func *func = card->sdio_func[i - 1];
46 if (!func) { 46 if (!func) {
47 printk(KERN_WARNING "%s: pending IRQ for " 47 printk(KERN_WARNING "%s: pending IRQ for "
48 "non-existant function\n", 48 "non-existent function\n",
49 mmc_card_id(card)); 49 mmc_card_id(card));
50 ret = -EINVAL; 50 ret = -EINVAL;
51 } else if (func->irq_handler) { 51 } else if (func->irq_handler) {