1
From e6b1f81b5d62aa376abd7920d9920738eb7827b8 Mon Sep 17 00:00:00 2001
2
From: Amit Kucheria <amit.kucheria@ubuntu.com>
3
Date: Thu, 10 Jan 2008 13:40:10 +0200
4
Subject: [PATCH] poulsbo Pierr SDIO stack
6
Signed-off-by: Amit Kucheria <amit.kucheria@ubuntu.com>
8
drivers/mmc/card/Kconfig | 24 +
9
drivers/mmc/card/Makefile | 1 +
10
drivers/mmc/card/block.c | 38 +-
11
drivers/mmc/card/queue.c | 215 +++++-
12
drivers/mmc/card/queue.h | 7 +
13
drivers/mmc/card/sdio_uart.c | 1158 +++++++++++++++++++++++++++++++
14
drivers/mmc/core/Makefile | 5 +-
15
drivers/mmc/core/bus.c | 303 +++++++++
16
drivers/mmc/core/bus.h | 22 +
17
drivers/mmc/core/core.c | 448 ++++++++-----
18
drivers/mmc/core/core.h | 32 +-
19
drivers/mmc/core/host.c | 167 +++++
20
drivers/mmc/core/host.h | 18 +
21
drivers/mmc/core/mmc.c | 194 ++++--
22
drivers/mmc/core/mmc_ops.c | 212 +++++--
23
drivers/mmc/core/mmc_ops.h | 5 +-
24
drivers/mmc/core/sd.c | 209 ++++--
25
drivers/mmc/core/sd_ops.c | 159 +++--
26
drivers/mmc/core/sd_ops.h | 3 +-
27
drivers/mmc/core/sdio.c | 402 +++++++++++
28
drivers/mmc/core/sdio_bus.c | 271 ++++++++
29
drivers/mmc/core/sdio_bus.h | 21 +
30
drivers/mmc/core/sdio_cis.c | 348 ++++++++++
31
drivers/mmc/core/sdio_cis.h | 23 +
32
drivers/mmc/core/sdio_io.c | 617 +++++++++++++++++
33
drivers/mmc/core/sdio_irq.c | 269 ++++++++
34
drivers/mmc/core/sdio_ops.c | 177 +++++
35
drivers/mmc/core/sdio_ops.h | 21 +
36
drivers/mmc/core/sysfs.c | 347 +---------
37
drivers/mmc/core/sysfs.h | 19 +-
38
drivers/mmc/host/Kconfig | 30 +
39
drivers/mmc/host/Makefile | 2 +
40
drivers/mmc/host/at91_mci.c | 275 +++++----
41
drivers/mmc/host/au1xmmc.c | 73 +-
42
drivers/mmc/host/imxmmc.c | 36 +-
43
drivers/mmc/host/mmc_spi.c | 1423 +++++++++++++++++++++++++++++++++++++++
44
drivers/mmc/host/mmci.c | 29 +-
45
drivers/mmc/host/mmci.h | 4 +-
46
drivers/mmc/host/omap.c | 18 +-
47
drivers/mmc/host/pxamci.c | 124 +++-
48
drivers/mmc/host/pxamci.h | 38 +-
49
drivers/mmc/host/ricoh_mmc.c | 151 +++++
50
drivers/mmc/host/sdhci.c | 258 +++++---
51
drivers/mmc/host/sdhci.h | 6 +-
52
drivers/mmc/host/tifm_sd.c | 40 +-
53
drivers/mmc/host/wbsd.c | 76 +--
54
drivers/mmc/host/wbsd.h | 2 +-
55
include/linux/mmc/card.h | 32 +
56
include/linux/mmc/core.h | 81 ++-
57
include/linux/mmc/host.h | 39 +-
58
include/linux/mmc/mmc.h | 29 +-
59
include/linux/mmc/sdio.h | 158 +++++
60
include/linux/mmc/sdio_func.h | 152 +++++
61
include/linux/mmc/sdio_ids.h | 29 +
62
include/linux/mod_devicetable.h | 11 +
63
55 files changed, 7641 insertions(+), 1210 deletions(-)
64
create mode 100644 drivers/mmc/card/sdio_uart.c
65
create mode 100644 drivers/mmc/core/bus.c
66
create mode 100644 drivers/mmc/core/bus.h
67
create mode 100644 drivers/mmc/core/host.c
68
create mode 100644 drivers/mmc/core/host.h
69
create mode 100644 drivers/mmc/core/sdio.c
70
create mode 100644 drivers/mmc/core/sdio_bus.c
71
create mode 100644 drivers/mmc/core/sdio_bus.h
72
create mode 100644 drivers/mmc/core/sdio_cis.c
73
create mode 100644 drivers/mmc/core/sdio_cis.h
74
create mode 100644 drivers/mmc/core/sdio_io.c
75
create mode 100644 drivers/mmc/core/sdio_irq.c
76
create mode 100644 drivers/mmc/core/sdio_ops.c
77
create mode 100644 drivers/mmc/core/sdio_ops.h
78
create mode 100644 drivers/mmc/host/mmc_spi.c
79
create mode 100644 drivers/mmc/host/ricoh_mmc.c
80
create mode 100644 include/linux/mmc/sdio.h
81
create mode 100644 include/linux/mmc/sdio_func.h
82
create mode 100644 include/linux/mmc/sdio_ids.h
84
diff --git a/drivers/mmc/card/Kconfig b/drivers/mmc/card/Kconfig
85
index 9320a8c..e417994 100644
86
--- a/drivers/mmc/card/Kconfig
87
+++ b/drivers/mmc/card/Kconfig
88
@@ -14,3 +14,27 @@ config MMC_BLOCK
89
mount the filesystem. Almost everyone wishing MMC support
90
should say Y or M here.
92
+config MMC_BLOCK_BOUNCE
93
+ bool "Use bounce buffer for simple hosts"
94
+ depends on MMC_BLOCK
97
+ SD/MMC is a high latency protocol where it is crucial to
98
+ send large requests in order to get high performance. Many
99
+ controllers, however, are restricted to continuous memory
100
+ (i.e. they can't do scatter-gather), something the kernel
101
+ rarely can provide.
103
+ Say Y here to help these restricted hosts by bouncing
104
+ requests back and forth from a large buffer. You will get
105
+ a big performance gain at the cost of up to 64 KiB of
108
+ If unsure, say Y here.
111
+ tristate "SDIO UART/GPS class support"
114
+ SDIO function driver for SDIO cards that implements the UART
115
+ class, as well as the GPS class which appears like a UART.
116
diff --git a/drivers/mmc/card/Makefile b/drivers/mmc/card/Makefile
117
index cf8c939..59b29cc 100644
118
--- a/drivers/mmc/card/Makefile
119
+++ b/drivers/mmc/card/Makefile
120
@@ -9,3 +9,4 @@ endif
121
obj-$(CONFIG_MMC_BLOCK) += mmc_block.o
122
mmc_block-objs := block.o queue.o
124
+obj-$(CONFIG_SDIO_UART) += sdio_uart.o
125
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
126
index 540ff4b..bba87d5 100644
127
--- a/drivers/mmc/card/block.c
128
+++ b/drivers/mmc/card/block.c
129
@@ -151,17 +151,19 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
131
cmd.opcode = MMC_APP_CMD;
132
cmd.arg = card->rca << 16;
133
- cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
134
+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
136
err = mmc_wait_for_cmd(card->host, &cmd, 0);
137
- if ((err != MMC_ERR_NONE) || !(cmd.resp[0] & R1_APP_CMD))
140
+ if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD))
143
memset(&cmd, 0, sizeof(struct mmc_command));
145
cmd.opcode = SD_APP_SEND_NUM_WR_BLKS;
147
- cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
148
+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
150
memset(&data, 0, sizeof(struct mmc_data));
152
@@ -192,7 +194,7 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
154
mmc_wait_for_req(card->host, &mrq);
156
- if (cmd.error != MMC_ERR_NONE || data.error != MMC_ERR_NONE)
157
+ if (cmd.error || data.error)
160
blocks = ntohl(blocks);
161
@@ -220,17 +222,15 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
162
brq.cmd.arg = req->sector;
163
if (!mmc_card_blockaddr(card))
165
- brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
166
+ brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
167
brq.data.blksz = 1 << md->block_bits;
168
brq.stop.opcode = MMC_STOP_TRANSMISSION;
170
- brq.stop.flags = MMC_RSP_R1B | MMC_CMD_AC;
171
+ brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
172
brq.data.blocks = req->nr_sectors >> (md->block_bits - 9);
173
if (brq.data.blocks > card->host->max_blk_count)
174
brq.data.blocks = card->host->max_blk_count;
176
- mmc_set_data_timeout(&brq.data, card, rq_data_dir(req) != READ);
179
* If the host doesn't support multiple block writes, force
180
* block writes to single block. SD cards are excepted from
181
@@ -243,7 +243,11 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
184
if (brq.data.blocks > 1) {
185
- brq.data.flags |= MMC_DATA_MULTI;
186
+ /* SPI multiblock writes terminate using a special
187
+ * token, not a STOP_TRANSMISSION request.
189
+ if (!mmc_host_is_spi(card->host)
190
+ || rq_data_dir(req) == READ)
191
brq.mrq.stop = &brq.stop;
192
readcmd = MMC_READ_MULTIPLE_BLOCK;
193
writecmd = MMC_WRITE_MULTIPLE_BLOCK;
194
@@ -261,8 +265,12 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
195
brq.data.flags |= MMC_DATA_WRITE;
198
+ mmc_set_data_timeout(&brq.data, card);
200
brq.data.sg = mq->sg;
201
- brq.data.sg_len = blk_rq_map_sg(req->q, req, brq.data.sg);
202
+ brq.data.sg_len = mmc_queue_map_sg(mq);
204
+ mmc_queue_bounce_pre(mq);
206
if (brq.data.blocks !=
207
(req->nr_sectors >> (md->block_bits - 9))) {
208
@@ -279,6 +287,9 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
211
mmc_wait_for_req(card->host, &brq.mrq);
213
+ mmc_queue_bounce_post(mq);
216
printk(KERN_ERR "%s: error %d sending read/write command\n",
217
req->rq_disk->disk_name, brq.cmd.error);
218
@@ -297,7 +308,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
222
- if (rq_data_dir(req) != READ) {
223
+ if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
227
@@ -409,13 +420,12 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
228
return ERR_PTR(-ENOSPC);
229
__set_bit(devidx, dev_use);
231
- md = kmalloc(sizeof(struct mmc_blk_data), GFP_KERNEL);
232
+ md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL);
238
- memset(md, 0, sizeof(struct mmc_blk_data));
241
* Set the read-only status based on the supported commands
242
@@ -506,7 +516,7 @@ mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
243
mmc_claim_host(card->host);
244
cmd.opcode = MMC_SET_BLOCKLEN;
245
cmd.arg = 1 << md->block_bits;
246
- cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
247
+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
248
err = mmc_wait_for_cmd(card->host, &cmd, 5);
249
mmc_release_host(card->host);
251
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
252
index dd97bc7..53aecec 100644
253
--- a/drivers/mmc/card/queue.c
254
+++ b/drivers/mmc/card/queue.c
257
- * linux/drivers/mmc/queue.c
258
+ * linux/drivers/mmc/card/queue.c
260
* Copyright (C) 2003 Russell King, All Rights Reserved.
261
* Copyright 2006-2007 Pierre Ossman
264
#include <linux/module.h>
265
#include <linux/blkdev.h>
266
+#include <linux/freezer.h>
267
#include <linux/kthread.h>
268
+#include <linux/scatterlist.h>
270
#include <linux/mmc/card.h>
271
#include <linux/mmc/host.h>
274
+#define MMC_QUEUE_BOUNCESZ 65536
276
#define MMC_QUEUE_SUSPENDED (1 << 0)
279
@@ -42,11 +46,7 @@ static int mmc_queue_thread(void *d)
280
struct mmc_queue *mq = d;
281
struct request_queue *q = mq->queue;
284
- * Set iothread to ensure that we aren't put to sleep by
285
- * the process freezing. We handle suspension ourselves.
287
- current->flags |= PF_MEMALLOC|PF_NOFREEZE;
288
+ current->flags |= PF_MEMALLOC|PF_NOFREEZE; /* will be changed in 24 */
290
down(&mq->thread_sem);
292
@@ -84,7 +84,7 @@ static int mmc_queue_thread(void *d)
293
* on any queue on this host, and attempt to issue it. This may
294
* not be the queue we were asked to process.
296
-static void mmc_request(request_queue_t *q)
297
+static void mmc_request(struct request_queue *q)
299
struct mmc_queue *mq = q->queuedata;
301
@@ -127,21 +127,65 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
305
- blk_queue_prep_rq(mq->queue, mmc_prep_request);
306
- blk_queue_bounce_limit(mq->queue, limit);
307
- blk_queue_max_sectors(mq->queue, host->max_req_size / 512);
308
- blk_queue_max_phys_segments(mq->queue, host->max_phys_segs);
309
- blk_queue_max_hw_segments(mq->queue, host->max_hw_segs);
310
- blk_queue_max_segment_size(mq->queue, host->max_seg_size);
312
mq->queue->queuedata = mq;
315
- mq->sg = kmalloc(sizeof(struct scatterlist) * host->max_phys_segs,
319
- goto cleanup_queue;
320
+ blk_queue_prep_rq(mq->queue, mmc_prep_request);
322
+#ifdef CONFIG_MMC_BLOCK_BOUNCE
323
+ if (host->max_hw_segs == 1) {
324
+ unsigned int bouncesz;
326
+ bouncesz = MMC_QUEUE_BOUNCESZ;
328
+ if (bouncesz > host->max_req_size)
329
+ bouncesz = host->max_req_size;
330
+ if (bouncesz > host->max_seg_size)
331
+ bouncesz = host->max_seg_size;
333
+ mq->bounce_buf = kmalloc(bouncesz, GFP_KERNEL);
334
+ if (!mq->bounce_buf) {
335
+ printk(KERN_WARNING "%s: unable to allocate "
336
+ "bounce buffer\n", mmc_card_name(card));
338
+ blk_queue_bounce_limit(mq->queue, BLK_BOUNCE_HIGH);
339
+ blk_queue_max_sectors(mq->queue, bouncesz / 512);
340
+ blk_queue_max_phys_segments(mq->queue, bouncesz / 512);
341
+ blk_queue_max_hw_segments(mq->queue, bouncesz / 512);
342
+ blk_queue_max_segment_size(mq->queue, bouncesz);
344
+ mq->sg = kmalloc(sizeof(struct scatterlist),
348
+ goto cleanup_queue;
350
+ //sg_init_table(mq->sg, 1);
352
+ mq->bounce_sg = kmalloc(sizeof(struct scatterlist) *
353
+ bouncesz / 512, GFP_KERNEL);
354
+ if (!mq->bounce_sg) {
356
+ goto cleanup_queue;
358
+ //sg_init_table(mq->bounce_sg, bouncesz / 512);
363
+ if (!mq->bounce_buf) {
364
+ blk_queue_bounce_limit(mq->queue, limit);
365
+ blk_queue_max_sectors(mq->queue, host->max_req_size / 512);
366
+ blk_queue_max_phys_segments(mq->queue, host->max_phys_segs);
367
+ blk_queue_max_hw_segments(mq->queue, host->max_hw_segs);
368
+ blk_queue_max_segment_size(mq->queue, host->max_seg_size);
370
+ mq->sg = kzalloc(sizeof(struct scatterlist) *
371
+ host->max_phys_segs, GFP_KERNEL);
374
+ goto cleanup_queue;
378
init_MUTEX(&mq->thread_sem);
379
@@ -149,22 +193,28 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
380
mq->thread = kthread_run(mmc_queue_thread, mq, "mmcqd");
381
if (IS_ERR(mq->thread)) {
382
ret = PTR_ERR(mq->thread);
384
+ goto free_bounce_sg;
394
+ kfree(mq->bounce_sg);
395
+ mq->bounce_sg = NULL;
400
+ if (mq->bounce_buf)
401
+ kfree(mq->bounce_buf);
402
+ mq->bounce_buf = NULL;
403
blk_cleanup_queue(mq->queue);
407
void mmc_cleanup_queue(struct mmc_queue *mq)
409
- request_queue_t *q = mq->queue;
410
+ struct request_queue *q = mq->queue;
413
/* Mark that we should start throwing out stragglers */
414
@@ -178,9 +228,17 @@ void mmc_cleanup_queue(struct mmc_queue *mq)
415
/* Then terminate our worker thread */
416
kthread_stop(mq->thread);
419
+ kfree(mq->bounce_sg);
420
+ mq->bounce_sg = NULL;
425
+ if (mq->bounce_buf)
426
+ kfree(mq->bounce_buf);
427
+ mq->bounce_buf = NULL;
429
blk_cleanup_queue(mq->queue);
432
@@ -197,7 +255,7 @@ EXPORT_SYMBOL(mmc_cleanup_queue);
434
void mmc_queue_suspend(struct mmc_queue *mq)
436
- request_queue_t *q = mq->queue;
437
+ struct request_queue *q = mq->queue;
440
if (!(mq->flags & MMC_QUEUE_SUSPENDED)) {
441
@@ -217,7 +275,7 @@ void mmc_queue_suspend(struct mmc_queue *mq)
443
void mmc_queue_resume(struct mmc_queue *mq)
445
- request_queue_t *q = mq->queue;
446
+ struct request_queue *q = mq->queue;
449
if (mq->flags & MMC_QUEUE_SUSPENDED) {
450
@@ -231,3 +289,106 @@ void mmc_queue_resume(struct mmc_queue *mq)
454
+static void copy_sg(struct scatterlist *dst, unsigned int dst_len,
455
+ struct scatterlist *src, unsigned int src_len)
457
+ unsigned int chunk;
458
+ char *dst_buf, *src_buf;
459
+ unsigned int dst_size, src_size;
467
+ BUG_ON(dst_len == 0);
469
+ if (dst_size == 0) {
470
+ dst_buf = page_address(dst->page) + dst->offset;
471
+ dst_size = dst->length;
474
+ if (src_size == 0) {
475
+ src_buf = page_address(src->page) + src->offset;
476
+ src_size = src->length;
479
+ chunk = min(dst_size, src_size);
481
+ memcpy(dst_buf, src_buf, chunk);
488
+ if (dst_size == 0) {
493
+ if (src_size == 0) {
500
+unsigned int mmc_queue_map_sg(struct mmc_queue *mq)
502
+ unsigned int sg_len;
504
+ if (!mq->bounce_buf)
505
+ return blk_rq_map_sg(mq->queue, mq->req, mq->sg);
507
+ BUG_ON(!mq->bounce_sg);
509
+ sg_len = blk_rq_map_sg(mq->queue, mq->req, mq->bounce_sg);
511
+ mq->bounce_sg_len = sg_len;
514
+ * Shortcut in the event we only get a single entry.
517
+ memcpy(mq->sg, mq->bounce_sg, sizeof(struct scatterlist));
521
+ sg_init_one(mq->sg, mq->bounce_buf, 0);
524
+ mq->sg[0].length += mq->bounce_sg[sg_len - 1].length;
531
+void mmc_queue_bounce_pre(struct mmc_queue *mq)
533
+ if (!mq->bounce_buf)
536
+ if (mq->bounce_sg_len == 1)
538
+ if (rq_data_dir(mq->req) != WRITE)
541
+ copy_sg(mq->sg, 1, mq->bounce_sg, mq->bounce_sg_len);
544
+void mmc_queue_bounce_post(struct mmc_queue *mq)
546
+ if (!mq->bounce_buf)
549
+ if (mq->bounce_sg_len == 1)
551
+ if (rq_data_dir(mq->req) != READ)
554
+ copy_sg(mq->bounce_sg, mq->bounce_sg_len, mq->sg, 1);
557
diff --git a/drivers/mmc/card/queue.h b/drivers/mmc/card/queue.h
558
index 1590b3f..64e66e0 100644
559
--- a/drivers/mmc/card/queue.h
560
+++ b/drivers/mmc/card/queue.h
561
@@ -14,6 +14,9 @@ struct mmc_queue {
563
struct request_queue *queue;
564
struct scatterlist *sg;
566
+ struct scatterlist *bounce_sg;
567
+ unsigned int bounce_sg_len;
570
extern int mmc_init_queue(struct mmc_queue *, struct mmc_card *, spinlock_t *);
571
@@ -21,4 +24,8 @@ extern void mmc_cleanup_queue(struct mmc_queue *);
572
extern void mmc_queue_suspend(struct mmc_queue *);
573
extern void mmc_queue_resume(struct mmc_queue *);
575
+extern unsigned int mmc_queue_map_sg(struct mmc_queue *);
576
+extern void mmc_queue_bounce_pre(struct mmc_queue *);
577
+extern void mmc_queue_bounce_post(struct mmc_queue *);
580
diff --git a/drivers/mmc/card/sdio_uart.c b/drivers/mmc/card/sdio_uart.c
582
index 0000000..d552de6
584
+++ b/drivers/mmc/card/sdio_uart.c
587
+ * linux/drivers/mmc/card/sdio_uart.c - SDIO UART/GPS driver
589
+ * Based on drivers/serial/8250.c and drivers/serial/serial_core.c
592
+ * Author: Nicolas Pitre
593
+ * Created: June 15, 2007
594
+ * Copyright: MontaVista Software, Inc.
596
+ * This program is free software; you can redistribute it and/or modify
597
+ * it under the terms of the GNU General Public License as published by
598
+ * the Free Software Foundation; either version 2 of the License, or (at
599
+ * your option) any later version.
603
+ * Note: Although this driver assumes a 16550A-like UART implementation,
604
+ * it is not possible to leverage the common 8250/16550 driver, nor the
605
+ * core UART infrastructure, as they assumes direct access to the hardware
606
+ * registers, often under a spinlock. This is not possible in the SDIO
607
+ * context as SDIO access functions must be able to sleep.
609
+ * Because we need to lock the SDIO host to ensure an exclusive access to
610
+ * the card, we simply rely on that lock to also prevent and serialize
611
+ * concurrent access to the same port.
614
+#include <linux/module.h>
615
+#include <linux/init.h>
616
+#include <linux/kernel.h>
617
+#include <linux/mutex.h>
618
+#include <linux/serial_reg.h>
619
+#include <linux/circ_buf.h>
620
+#include <linux/gfp.h>
621
+#include <linux/tty.h>
622
+#include <linux/tty_flip.h>
624
+#include <linux/mmc/core.h>
625
+#include <linux/mmc/card.h>
626
+#include <linux/mmc/sdio_func.h>
627
+#include <linux/mmc/sdio_ids.h>
630
+#define UART_NR 8 /* Number of UARTs this driver can handle */
633
+#define UART_XMIT_SIZE PAGE_SIZE
634
+#define WAKEUP_CHARS 256
636
+#define circ_empty(circ) ((circ)->head == (circ)->tail)
637
+#define circ_clear(circ) ((circ)->head = (circ)->tail = 0)
639
+#define circ_chars_pending(circ) \
640
+ (CIRC_CNT((circ)->head, (circ)->tail, UART_XMIT_SIZE))
642
+#define circ_chars_free(circ) \
643
+ (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE))
646
+struct uart_icount {
659
+struct sdio_uart_port {
661
+ struct tty_struct *tty;
662
+ unsigned int index;
663
+ unsigned int opened;
664
+ struct mutex open_lock;
665
+ struct sdio_func *func;
666
+ struct mutex func_lock;
667
+ struct task_struct *in_sdio_uart_irq;
668
+ unsigned int regs_offset;
669
+ struct circ_buf xmit;
670
+ spinlock_t write_lock;
671
+ struct uart_icount icount;
672
+ unsigned int uartclk;
673
+ unsigned int mctrl;
674
+ unsigned int read_status_mask;
675
+ unsigned int ignore_status_mask;
676
+ unsigned char x_char;
681
+static struct sdio_uart_port *sdio_uart_table[UART_NR];
682
+static DEFINE_SPINLOCK(sdio_uart_table_lock);
684
+static int sdio_uart_add_port(struct sdio_uart_port *port)
686
+ int index, ret = -EBUSY;
688
+ kref_init(&port->kref);
689
+ mutex_init(&port->open_lock);
690
+ mutex_init(&port->func_lock);
691
+ spin_lock_init(&port->write_lock);
693
+ spin_lock(&sdio_uart_table_lock);
694
+ for (index = 0; index < UART_NR; index++) {
695
+ if (!sdio_uart_table[index]) {
696
+ port->index = index;
697
+ sdio_uart_table[index] = port;
702
+ spin_unlock(&sdio_uart_table_lock);
707
+static struct sdio_uart_port *sdio_uart_port_get(unsigned index)
709
+ struct sdio_uart_port *port;
711
+ if (index >= UART_NR)
714
+ spin_lock(&sdio_uart_table_lock);
715
+ port = sdio_uart_table[index];
717
+ kref_get(&port->kref);
718
+ spin_unlock(&sdio_uart_table_lock);
723
+static void sdio_uart_port_destroy(struct kref *kref)
725
+ struct sdio_uart_port *port =
726
+ container_of(kref, struct sdio_uart_port, kref);
730
+static void sdio_uart_port_put(struct sdio_uart_port *port)
732
+ kref_put(&port->kref, sdio_uart_port_destroy);
735
+static void sdio_uart_port_remove(struct sdio_uart_port *port)
737
+ struct sdio_func *func;
739
+ BUG_ON(sdio_uart_table[port->index] != port);
741
+ spin_lock(&sdio_uart_table_lock);
742
+ sdio_uart_table[port->index] = NULL;
743
+ spin_unlock(&sdio_uart_table_lock);
746
+ * We're killing a port that potentially still is in use by
747
+ * the tty layer. Be careful to prevent any further access
748
+ * to the SDIO function and arrange for the tty layer to
749
+ * give up on that port ASAP.
750
+ * Beware: the lock ordering is critical.
752
+ mutex_lock(&port->open_lock);
753
+ mutex_lock(&port->func_lock);
755
+ sdio_claim_host(func);
757
+ mutex_unlock(&port->func_lock);
759
+ tty_hangup(port->tty);
760
+ mutex_unlock(&port->open_lock);
761
+ sdio_release_irq(func);
762
+ sdio_disable_func(func);
763
+ sdio_release_host(func);
765
+ sdio_uart_port_put(port);
768
+static int sdio_uart_claim_func(struct sdio_uart_port *port)
770
+ mutex_lock(&port->func_lock);
771
+ if (unlikely(!port->func)) {
772
+ mutex_unlock(&port->func_lock);
775
+ if (likely(port->in_sdio_uart_irq != current))
776
+ sdio_claim_host(port->func);
777
+ mutex_unlock(&port->func_lock);
781
+static inline void sdio_uart_release_func(struct sdio_uart_port *port)
783
+ if (likely(port->in_sdio_uart_irq != current))
784
+ sdio_release_host(port->func);
787
+static inline unsigned int sdio_in(struct sdio_uart_port *port, int offset)
790
+ c = sdio_readb(port->func, port->regs_offset + offset, NULL);
794
+static inline void sdio_out(struct sdio_uart_port *port, int offset, int value)
796
+ sdio_writeb(port->func, value, port->regs_offset + offset, NULL);
799
+static unsigned int sdio_uart_get_mctrl(struct sdio_uart_port *port)
801
+ unsigned char status;
804
+ status = sdio_in(port, UART_MSR);
807
+ if (status & UART_MSR_DCD)
809
+ if (status & UART_MSR_RI)
811
+ if (status & UART_MSR_DSR)
813
+ if (status & UART_MSR_CTS)
818
+static void sdio_uart_write_mctrl(struct sdio_uart_port *port, unsigned int mctrl)
820
+ unsigned char mcr = 0;
822
+ if (mctrl & TIOCM_RTS)
823
+ mcr |= UART_MCR_RTS;
824
+ if (mctrl & TIOCM_DTR)
825
+ mcr |= UART_MCR_DTR;
826
+ if (mctrl & TIOCM_OUT1)
827
+ mcr |= UART_MCR_OUT1;
828
+ if (mctrl & TIOCM_OUT2)
829
+ mcr |= UART_MCR_OUT2;
830
+ if (mctrl & TIOCM_LOOP)
831
+ mcr |= UART_MCR_LOOP;
833
+ sdio_out(port, UART_MCR, mcr);
836
+static inline void sdio_uart_update_mctrl(struct sdio_uart_port *port,
837
+ unsigned int set, unsigned int clear)
842
+ port->mctrl = (old & ~clear) | set;
843
+ if (old != port->mctrl)
844
+ sdio_uart_write_mctrl(port, port->mctrl);
847
+#define sdio_uart_set_mctrl(port, x) sdio_uart_update_mctrl(port, x, 0)
848
+#define sdio_uart_clear_mctrl(port, x) sdio_uart_update_mctrl(port, 0, x)
850
+static void sdio_uart_change_speed(struct sdio_uart_port *port,
851
+ struct ktermios *termios,
852
+ struct ktermios *old)
854
+ unsigned char cval, fcr = 0;
855
+ unsigned int baud, quot;
857
+ switch (termios->c_cflag & CSIZE) {
859
+ cval = UART_LCR_WLEN5;
862
+ cval = UART_LCR_WLEN6;
865
+ cval = UART_LCR_WLEN7;
869
+ cval = UART_LCR_WLEN8;
873
+ if (termios->c_cflag & CSTOPB)
874
+ cval |= UART_LCR_STOP;
875
+ if (termios->c_cflag & PARENB)
876
+ cval |= UART_LCR_PARITY;
877
+ if (!(termios->c_cflag & PARODD))
878
+ cval |= UART_LCR_EPAR;
881
+ baud = tty_termios_baud_rate(termios);
883
+ baud = 9600; /* Special case: B0 rate. */
884
+ if (baud <= port->uartclk)
887
+ * Oops, the quotient was zero. Try again with the old
888
+ * baud rate if possible, otherwise default to 9600.
890
+ termios->c_cflag &= ~CBAUD;
892
+ termios->c_cflag |= old->c_cflag & CBAUD;
895
+ termios->c_cflag |= B9600;
897
+ quot = (2 * port->uartclk + baud) / (2 * baud);
900
+ fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
902
+ fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10;
904
+ port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
905
+ if (termios->c_iflag & INPCK)
906
+ port->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
907
+ if (termios->c_iflag & (BRKINT | PARMRK))
908
+ port->read_status_mask |= UART_LSR_BI;
911
+ * Characters to ignore
913
+ port->ignore_status_mask = 0;
914
+ if (termios->c_iflag & IGNPAR)
915
+ port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
916
+ if (termios->c_iflag & IGNBRK) {
917
+ port->ignore_status_mask |= UART_LSR_BI;
919
+ * If we're ignoring parity and break indicators,
920
+ * ignore overruns too (for real raw support).
922
+ if (termios->c_iflag & IGNPAR)
923
+ port->ignore_status_mask |= UART_LSR_OE;
927
+ * ignore all characters if CREAD is not set
929
+ if ((termios->c_cflag & CREAD) == 0)
930
+ port->ignore_status_mask |= UART_LSR_DR;
933
+ * CTS flow control flag and modem status interrupts
935
+ port->ier &= ~UART_IER_MSI;
936
+ if ((termios->c_cflag & CRTSCTS) || !(termios->c_cflag & CLOCAL))
937
+ port->ier |= UART_IER_MSI;
941
+ sdio_out(port, UART_IER, port->ier);
942
+ sdio_out(port, UART_LCR, cval | UART_LCR_DLAB);
943
+ sdio_out(port, UART_DLL, quot & 0xff);
944
+ sdio_out(port, UART_DLM, quot >> 8);
945
+ sdio_out(port, UART_LCR, cval);
946
+ sdio_out(port, UART_FCR, fcr);
948
+ sdio_uart_write_mctrl(port, port->mctrl);
951
+static void sdio_uart_start_tx(struct sdio_uart_port *port)
953
+ if (!(port->ier & UART_IER_THRI)) {
954
+ port->ier |= UART_IER_THRI;
955
+ sdio_out(port, UART_IER, port->ier);
959
+static void sdio_uart_stop_tx(struct sdio_uart_port *port)
961
+ if (port->ier & UART_IER_THRI) {
962
+ port->ier &= ~UART_IER_THRI;
963
+ sdio_out(port, UART_IER, port->ier);
967
+static void sdio_uart_stop_rx(struct sdio_uart_port *port)
969
+ port->ier &= ~UART_IER_RLSI;
970
+ port->read_status_mask &= ~UART_LSR_DR;
971
+ sdio_out(port, UART_IER, port->ier);
974
+static void sdio_uart_receive_chars(struct sdio_uart_port *port, int *status)
976
+ struct tty_struct *tty = port->tty;
977
+ unsigned int ch, flag;
978
+ int max_count = 256;
981
+ ch = sdio_in(port, UART_RX);
985
+ if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
986
+ UART_LSR_FE | UART_LSR_OE))) {
988
+ * For statistics only
990
+ if (*status & UART_LSR_BI) {
991
+ *status &= ~(UART_LSR_FE | UART_LSR_PE);
992
+ port->icount.brk++;
993
+ } else if (*status & UART_LSR_PE)
994
+ port->icount.parity++;
995
+ else if (*status & UART_LSR_FE)
996
+ port->icount.frame++;
997
+ if (*status & UART_LSR_OE)
998
+ port->icount.overrun++;
1001
+ * Mask off conditions which should be ignored.
1003
+ *status &= port->read_status_mask;
1004
+ if (*status & UART_LSR_BI) {
1006
+ } else if (*status & UART_LSR_PE)
1007
+ flag = TTY_PARITY;
1008
+ else if (*status & UART_LSR_FE)
1012
+ if ((*status & port->ignore_status_mask & ~UART_LSR_OE) == 0)
1013
+ tty_insert_flip_char(tty, ch, flag);
1016
+ * Overrun is special. Since it's reported immediately,
1017
+ * it doesn't affect the current character.
1019
+ if (*status & ~port->ignore_status_mask & UART_LSR_OE)
1020
+ tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1022
+ *status = sdio_in(port, UART_LSR);
1023
+ } while ((*status & UART_LSR_DR) && (max_count-- > 0));
1024
+ tty_flip_buffer_push(tty);
1027
+static void sdio_uart_transmit_chars(struct sdio_uart_port *port)
1029
+ struct circ_buf *xmit = &port->xmit;
1032
+ if (port->x_char) {
1033
+ sdio_out(port, UART_TX, port->x_char);
1034
+ port->icount.tx++;
1038
+ if (circ_empty(xmit) || port->tty->stopped || port->tty->hw_stopped) {
1039
+ sdio_uart_stop_tx(port);
1045
+ sdio_out(port, UART_TX, xmit->buf[xmit->tail]);
1046
+ xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
1047
+ port->icount.tx++;
1048
+ if (circ_empty(xmit))
1050
+ } while (--count > 0);
1052
+ if (circ_chars_pending(xmit) < WAKEUP_CHARS)
1053
+ tty_wakeup(port->tty);
1055
+ if (circ_empty(xmit))
1056
+ sdio_uart_stop_tx(port);
1059
+static void sdio_uart_check_modem_status(struct sdio_uart_port *port)
1063
+ status = sdio_in(port, UART_MSR);
1065
+ if ((status & UART_MSR_ANY_DELTA) == 0)
1068
+ if (status & UART_MSR_TERI)
1069
+ port->icount.rng++;
1070
+ if (status & UART_MSR_DDSR)
1071
+ port->icount.dsr++;
1072
+ if (status & UART_MSR_DDCD)
1073
+ port->icount.dcd++;
1074
+ if (status & UART_MSR_DCTS) {
1075
+ port->icount.cts++;
1076
+ if (port->tty->termios->c_cflag & CRTSCTS) {
1077
+ int cts = (status & UART_MSR_CTS);
1078
+ if (port->tty->hw_stopped) {
1080
+ port->tty->hw_stopped = 0;
1081
+ sdio_uart_start_tx(port);
1082
+ tty_wakeup(port->tty);
1086
+ port->tty->hw_stopped = 1;
1087
+ sdio_uart_stop_tx(port);
1095
+ * This handles the interrupt from one port.
1097
+static void sdio_uart_irq(struct sdio_func *func)
1099
+ struct sdio_uart_port *port = sdio_get_drvdata(func);
1100
+ unsigned int iir, lsr;
1103
+ * In a few places sdio_uart_irq() is called directly instead of
1104
+ * waiting for the actual interrupt to be raised and the SDIO IRQ
1105
+ * thread scheduled in order to reduce latency. However, some
1106
+ * interaction with the tty core may end up calling us back
1107
+ * (serial echo, flow control, etc.) through those same places
1108
+ * causing undesirable effects. Let's stop the recursion here.
1110
+ if (unlikely(port->in_sdio_uart_irq == current))
1113
+ iir = sdio_in(port, UART_IIR);
1114
+ if (iir & UART_IIR_NO_INT)
1117
+ port->in_sdio_uart_irq = current;
1118
+ lsr = sdio_in(port, UART_LSR);
1119
+ if (lsr & UART_LSR_DR)
1120
+ sdio_uart_receive_chars(port, &lsr);
1121
+ sdio_uart_check_modem_status(port);
1122
+ if (lsr & UART_LSR_THRE)
1123
+ sdio_uart_transmit_chars(port);
1124
+ port->in_sdio_uart_irq = NULL;
1127
+static int sdio_uart_startup(struct sdio_uart_port *port)
1129
+ unsigned long page;
1133
+ * Set the TTY IO error marker - we will only clear this
1134
+ * once we have successfully opened the port.
1136
+ set_bit(TTY_IO_ERROR, &port->tty->flags);
1138
+ /* Initialise and allocate the transmit buffer. */
1139
+ page = __get_free_page(GFP_KERNEL);
1142
+ port->xmit.buf = (unsigned char *)page;
1143
+ circ_clear(&port->xmit);
1145
+ ret = sdio_uart_claim_func(port);
1148
+ ret = sdio_enable_func(port->func);
1151
+ ret = sdio_claim_irq(port->func, sdio_uart_irq);
1156
+ * Clear the FIFO buffers and disable them.
1157
+ * (they will be reenabled in sdio_change_speed())
1159
+ sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO);
1160
+ sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO |
1161
+ UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
1162
+ sdio_out(port, UART_FCR, 0);
1165
+ * Clear the interrupt registers.
1167
+ (void) sdio_in(port, UART_LSR);
1168
+ (void) sdio_in(port, UART_RX);
1169
+ (void) sdio_in(port, UART_IIR);
1170
+ (void) sdio_in(port, UART_MSR);
1173
+ * Now, initialize the UART
1175
+ sdio_out(port, UART_LCR, UART_LCR_WLEN8);
1177
+ port->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE | UART_IER_UUE;
1178
+ port->mctrl = TIOCM_OUT2;
1180
+ sdio_uart_change_speed(port, port->tty->termios, NULL);
1182
+ if (port->tty->termios->c_cflag & CBAUD)
1183
+ sdio_uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR);
1185
+ if (port->tty->termios->c_cflag & CRTSCTS)
1186
+ if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS))
1187
+ port->tty->hw_stopped = 1;
1189
+ clear_bit(TTY_IO_ERROR, &port->tty->flags);
1191
+ /* Kick the IRQ handler once while we're still holding the host lock */
1192
+ sdio_uart_irq(port->func);
1194
+ sdio_uart_release_func(port);
1198
+ sdio_disable_func(port->func);
1200
+ sdio_uart_release_func(port);
1202
+ free_page((unsigned long)port->xmit.buf);
1206
+static void sdio_uart_shutdown(struct sdio_uart_port *port)
1210
+ ret = sdio_uart_claim_func(port);
1214
+ sdio_uart_stop_rx(port);
1216
+ /* TODO: wait here for TX FIFO to drain */
1218
+ /* Turn off DTR and RTS early. */
1219
+ if (port->tty->termios->c_cflag & HUPCL)
1220
+ sdio_uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1222
+ /* Disable interrupts from this port */
1223
+ sdio_release_irq(port->func);
1225
+ sdio_out(port, UART_IER, 0);
1227
+ sdio_uart_clear_mctrl(port, TIOCM_OUT2);
1229
+ /* Disable break condition and FIFOs. */
1230
+ port->lcr &= ~UART_LCR_SBC;
1231
+ sdio_out(port, UART_LCR, port->lcr);
1232
+ sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO |
1233
+ UART_FCR_CLEAR_RCVR |
1234
+ UART_FCR_CLEAR_XMIT);
1235
+ sdio_out(port, UART_FCR, 0);
1237
+ sdio_disable_func(port->func);
1239
+ sdio_uart_release_func(port);
1242
+ /* Free the transmit buffer page. */
1243
+ free_page((unsigned long)port->xmit.buf);
1246
+static int sdio_uart_open (struct tty_struct *tty, struct file * filp)
1248
+ struct sdio_uart_port *port;
1251
+ port = sdio_uart_port_get(tty->index);
1255
+ mutex_lock(&port->open_lock);
1258
+ * Make sure not to mess up with a dead port
1259
+ * which has not been closed yet.
1261
+ if (tty->driver_data && tty->driver_data != port) {
1262
+ mutex_unlock(&port->open_lock);
1263
+ sdio_uart_port_put(port);
1267
+ if (!port->opened) {
1268
+ tty->driver_data = port;
1270
+ ret = sdio_uart_startup(port);
1272
+ tty->driver_data = NULL;
1274
+ mutex_unlock(&port->open_lock);
1275
+ sdio_uart_port_put(port);
1280
+ mutex_unlock(&port->open_lock);
1284
+static void sdio_uart_close(struct tty_struct *tty, struct file * filp)
1286
+ struct sdio_uart_port *port = tty->driver_data;
1291
+ mutex_lock(&port->open_lock);
1292
+ BUG_ON(!port->opened);
1295
+ * This is messy. The tty layer calls us even when open()
1296
+ * returned an error. Ignore this close request if tty->count
1297
+ * is larger than port->count.
1299
+ if (tty->count > port->opened) {
1300
+ mutex_unlock(&port->open_lock);
1304
+ if (--port->opened == 0) {
1306
+ sdio_uart_shutdown(port);
1307
+ tty_ldisc_flush(tty);
1309
+ tty->driver_data = NULL;
1312
+ mutex_unlock(&port->open_lock);
1313
+ sdio_uart_port_put(port);
1316
+static int sdio_uart_write(struct tty_struct * tty, const unsigned char *buf,
1319
+ struct sdio_uart_port *port = tty->driver_data;
1320
+ struct circ_buf *circ = &port->xmit;
1326
+ spin_lock(&port->write_lock);
1328
+ c = CIRC_SPACE_TO_END(circ->head, circ->tail, UART_XMIT_SIZE);
1333
+ memcpy(circ->buf + circ->head, buf, c);
1334
+ circ->head = (circ->head + c) & (UART_XMIT_SIZE - 1);
1339
+ spin_unlock(&port->write_lock);
1341
+ if ( !(port->ier & UART_IER_THRI)) {
1342
+ int err = sdio_uart_claim_func(port);
1344
+ sdio_uart_start_tx(port);
1345
+ sdio_uart_irq(port->func);
1346
+ sdio_uart_release_func(port);
1354
+static int sdio_uart_write_room(struct tty_struct *tty)
1356
+ struct sdio_uart_port *port = tty->driver_data;
1357
+ return port ? circ_chars_free(&port->xmit) : 0;
1360
+static int sdio_uart_chars_in_buffer(struct tty_struct *tty)
1362
+ struct sdio_uart_port *port = tty->driver_data;
1363
+ return port ? circ_chars_pending(&port->xmit) : 0;
1366
+static void sdio_uart_send_xchar(struct tty_struct *tty, char ch)
1368
+ struct sdio_uart_port *port = tty->driver_data;
1370
+ port->x_char = ch;
1371
+ if (ch && !(port->ier & UART_IER_THRI)) {
1372
+ if (sdio_uart_claim_func(port) != 0)
1374
+ sdio_uart_start_tx(port);
1375
+ sdio_uart_irq(port->func);
1376
+ sdio_uart_release_func(port);
1380
+static void sdio_uart_throttle(struct tty_struct *tty)
1382
+ struct sdio_uart_port *port = tty->driver_data;
1384
+ if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS))
1387
+ if (sdio_uart_claim_func(port) != 0)
1390
+ if (I_IXOFF(tty)) {
1391
+ port->x_char = STOP_CHAR(tty);
1392
+ sdio_uart_start_tx(port);
1395
+ if (tty->termios->c_cflag & CRTSCTS)
1396
+ sdio_uart_clear_mctrl(port, TIOCM_RTS);
1398
+ sdio_uart_irq(port->func);
1399
+ sdio_uart_release_func(port);
1402
+static void sdio_uart_unthrottle(struct tty_struct *tty)
1404
+ struct sdio_uart_port *port = tty->driver_data;
1406
+ if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS))
1409
+ if (sdio_uart_claim_func(port) != 0)
1412
+ if (I_IXOFF(tty)) {
1413
+ if (port->x_char) {
1416
+ port->x_char = START_CHAR(tty);
1417
+ sdio_uart_start_tx(port);
1421
+ if (tty->termios->c_cflag & CRTSCTS)
1422
+ sdio_uart_set_mctrl(port, TIOCM_RTS);
1424
+ sdio_uart_irq(port->func);
1425
+ sdio_uart_release_func(port);
1428
+static void sdio_uart_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1430
+ struct sdio_uart_port *port = tty->driver_data;
1431
+ unsigned int cflag = tty->termios->c_cflag;
1433
+#define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1435
+ if ((cflag ^ old_termios->c_cflag) == 0 &&
1436
+ RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0)
1439
+ if (sdio_uart_claim_func(port) != 0)
1442
+ sdio_uart_change_speed(port, tty->termios, old_termios);
1444
+ /* Handle transition to B0 status */
1445
+ if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD))
1446
+ sdio_uart_clear_mctrl(port, TIOCM_RTS | TIOCM_DTR);
1448
+ /* Handle transition away from B0 status */
1449
+ if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
1450
+ unsigned int mask = TIOCM_DTR;
1451
+ if (!(cflag & CRTSCTS) || !test_bit(TTY_THROTTLED, &tty->flags))
1452
+ mask |= TIOCM_RTS;
1453
+ sdio_uart_set_mctrl(port, mask);
1456
+ /* Handle turning off CRTSCTS */
1457
+ if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) {
1458
+ tty->hw_stopped = 0;
1459
+ sdio_uart_start_tx(port);
1462
+ /* Handle turning on CRTSCTS */
1463
+ if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) {
1464
+ if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS)) {
1465
+ tty->hw_stopped = 1;
1466
+ sdio_uart_stop_tx(port);
1470
+ sdio_uart_release_func(port);
1473
+static void sdio_uart_break_ctl(struct tty_struct *tty, int break_state)
1475
+ struct sdio_uart_port *port = tty->driver_data;
1477
+ if (sdio_uart_claim_func(port) != 0)
1480
+ if (break_state == -1)
1481
+ port->lcr |= UART_LCR_SBC;
1483
+ port->lcr &= ~UART_LCR_SBC;
1484
+ sdio_out(port, UART_LCR, port->lcr);
1486
+ sdio_uart_release_func(port);
1489
+static int sdio_uart_tiocmget(struct tty_struct *tty, struct file *file)
1491
+ struct sdio_uart_port *port = tty->driver_data;
1494
+ result = sdio_uart_claim_func(port);
1496
+ result = port->mctrl | sdio_uart_get_mctrl(port);
1497
+ sdio_uart_release_func(port);
1503
+static int sdio_uart_tiocmset(struct tty_struct *tty, struct file *file,
1504
+ unsigned int set, unsigned int clear)
1506
+ struct sdio_uart_port *port = tty->driver_data;
1509
+ result =sdio_uart_claim_func(port);
1511
+ sdio_uart_update_mctrl(port, set, clear);
1512
+ sdio_uart_release_func(port);
1518
+static int sdio_uart_read_proc(char *page, char **start, off_t off,
1519
+ int count, int *eof, void *data)
1524
+ len += sprintf(page, "serinfo:1.0 driver%s%s revision:%s\n",
1526
+ for (i = 0; i < UART_NR && len < PAGE_SIZE - 96; i++) {
1527
+ struct sdio_uart_port *port = sdio_uart_port_get(i);
1529
+ len += sprintf(page+len, "%d: uart:SDIO", i);
1530
+ if(capable(CAP_SYS_ADMIN)) {
1531
+ len += sprintf(page + len, " tx:%d rx:%d",
1532
+ port->icount.tx, port->icount.rx);
1533
+ if (port->icount.frame)
1534
+ len += sprintf(page + len, " fe:%d",
1535
+ port->icount.frame);
1536
+ if (port->icount.parity)
1537
+ len += sprintf(page + len, " pe:%d",
1538
+ port->icount.parity);
1539
+ if (port->icount.brk)
1540
+ len += sprintf(page + len, " brk:%d",
1541
+ port->icount.brk);
1542
+ if (port->icount.overrun)
1543
+ len += sprintf(page + len, " oe:%d",
1544
+ port->icount.overrun);
1545
+ if (port->icount.cts)
1546
+ len += sprintf(page + len, " cts:%d",
1547
+ port->icount.cts);
1548
+ if (port->icount.dsr)
1549
+ len += sprintf(page + len, " dsr:%d",
1550
+ port->icount.dsr);
1551
+ if (port->icount.rng)
1552
+ len += sprintf(page + len, " rng:%d",
1553
+ port->icount.rng);
1554
+ if (port->icount.dcd)
1555
+ len += sprintf(page + len, " dcd:%d",
1556
+ port->icount.dcd);
1558
+ strcat(page, "\n");
1560
+ sdio_uart_port_put(port);
1563
+ if (len + begin > off + count)
1565
+ if (len + begin < off) {
1573
+ if (off >= len + begin)
1575
+ *start = page + (off - begin);
1576
+ return (count < begin + len - off) ? count : (begin + len - off);
1579
+static const struct tty_operations sdio_uart_ops = {
1580
+ .open = sdio_uart_open,
1581
+ .close = sdio_uart_close,
1582
+ .write = sdio_uart_write,
1583
+ .write_room = sdio_uart_write_room,
1584
+ .chars_in_buffer = sdio_uart_chars_in_buffer,
1585
+ .send_xchar = sdio_uart_send_xchar,
1586
+ .throttle = sdio_uart_throttle,
1587
+ .unthrottle = sdio_uart_unthrottle,
1588
+ .set_termios = sdio_uart_set_termios,
1589
+ .break_ctl = sdio_uart_break_ctl,
1590
+ .tiocmget = sdio_uart_tiocmget,
1591
+ .tiocmset = sdio_uart_tiocmset,
1592
+ .read_proc = sdio_uart_read_proc,
1595
+static struct tty_driver *sdio_uart_tty_driver;
1597
+static int sdio_uart_probe(struct sdio_func *func,
1598
+ const struct sdio_device_id *id)
1600
+ struct sdio_uart_port *port;
1603
+ port = kzalloc(sizeof(struct sdio_uart_port), GFP_KERNEL);
1607
+ if (func->class == SDIO_CLASS_UART) {
1608
+ printk(KERN_WARNING "%s: need info on UART class basic setup\n",
1609
+ sdio_func_id(func));
1612
+ } else if (func->class == SDIO_CLASS_GPS) {
1614
+ * We need tuple 0x91. It contains SUBTPL_SIOREG
1615
+ * and SUBTPL_RCVCAPS.
1617
+ struct sdio_func_tuple *tpl;
1618
+ for (tpl = func->tuples; tpl; tpl = tpl->next) {
1619
+ if (tpl->code != 0x91)
1621
+ if (tpl->size < 10)
1623
+ if (tpl->data[1] == 0) /* SUBTPL_SIOREG */
1627
+ printk(KERN_WARNING
1628
+ "%s: can't find tuple 0x91 subtuple 0 (SUBTPL_SIOREG) for GPS class\n",
1629
+ sdio_func_id(func));
1633
+ printk(KERN_DEBUG "%s: Register ID = 0x%02x, Exp ID = 0x%02x\n",
1634
+ sdio_func_id(func), tpl->data[2], tpl->data[3]);
1635
+ port->regs_offset = (tpl->data[4] << 0) |
1636
+ (tpl->data[5] << 8) |
1637
+ (tpl->data[6] << 16);
1638
+ printk(KERN_DEBUG "%s: regs offset = 0x%x\n",
1639
+ sdio_func_id(func), port->regs_offset);
1640
+ port->uartclk = tpl->data[7] * 115200;
1641
+ if (port->uartclk == 0)
1642
+ port->uartclk = 115200;
1643
+ printk(KERN_DEBUG "%s: clk %d baudcode %u 4800-div %u\n",
1644
+ sdio_func_id(func), port->uartclk,
1645
+ tpl->data[7], tpl->data[8] | (tpl->data[9] << 8));
1651
+ port->func = func;
1652
+ sdio_set_drvdata(func, port);
1654
+ ret = sdio_uart_add_port(port);
1658
+ struct device *dev;
1659
+ dev = tty_register_device(sdio_uart_tty_driver, port->index, &func->dev);
1660
+ if (IS_ERR(dev)) {
1661
+ sdio_uart_port_remove(port);
1662
+ ret = PTR_ERR(dev);
1669
+static void sdio_uart_remove(struct sdio_func *func)
1671
+ struct sdio_uart_port *port = sdio_get_drvdata(func);
1673
+ tty_unregister_device(sdio_uart_tty_driver, port->index);
1674
+ sdio_uart_port_remove(port);
1677
+static const struct sdio_device_id sdio_uart_ids[] = {
1678
+ { SDIO_DEVICE_CLASS(SDIO_CLASS_UART) },
1679
+ { SDIO_DEVICE_CLASS(SDIO_CLASS_GPS) },
1680
+ { /* end: all zeroes */ },
1683
+MODULE_DEVICE_TABLE(sdio, sdio_uart_ids);
1685
+static struct sdio_driver sdio_uart_driver = {
1686
+ .probe = sdio_uart_probe,
1687
+ .remove = sdio_uart_remove,
1688
+ .name = "sdio_uart",
1689
+ .id_table = sdio_uart_ids,
1692
+static int __init sdio_uart_init(void)
1695
+ struct tty_driver *tty_drv;
1697
+ sdio_uart_tty_driver = tty_drv = alloc_tty_driver(UART_NR);
1701
+ tty_drv->owner = THIS_MODULE;
1702
+ tty_drv->driver_name = "sdio_uart";
1703
+ tty_drv->name = "ttySDIO";
1704
+ tty_drv->major = 0; /* dynamically allocated */
1705
+ tty_drv->minor_start = 0;
1706
+ tty_drv->type = TTY_DRIVER_TYPE_SERIAL;
1707
+ tty_drv->subtype = SERIAL_TYPE_NORMAL;
1708
+ tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
1709
+ tty_drv->init_termios = tty_std_termios;
1710
+ tty_drv->init_termios.c_cflag = B4800 | CS8 | CREAD | HUPCL | CLOCAL;
1711
+ tty_drv->init_termios.c_ispeed = 4800;
1712
+ tty_drv->init_termios.c_ospeed = 4800;
1713
+ tty_set_operations(tty_drv, &sdio_uart_ops);
1715
+ ret = tty_register_driver(tty_drv);
1719
+ ret = sdio_register_driver(&sdio_uart_driver);
1726
+ tty_unregister_driver(tty_drv);
1728
+ put_tty_driver(tty_drv);
1732
+static void __exit sdio_uart_exit(void)
1734
+ sdio_unregister_driver(&sdio_uart_driver);
1735
+ tty_unregister_driver(sdio_uart_tty_driver);
1736
+ put_tty_driver(sdio_uart_tty_driver);
1739
+module_init(sdio_uart_init);
1740
+module_exit(sdio_uart_exit);
1742
+MODULE_AUTHOR("Nicolas Pitre");
1743
+MODULE_LICENSE("GPL");
1744
diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile
1745
index 1075b02..4985807 100644
1746
--- a/drivers/mmc/core/Makefile
1747
+++ b/drivers/mmc/core/Makefile
1748
@@ -7,5 +7,8 @@ ifeq ($(CONFIG_MMC_DEBUG),y)
1751
obj-$(CONFIG_MMC) += mmc_core.o
1752
-mmc_core-y := core.o sysfs.o mmc.o mmc_ops.o sd.o sd_ops.o
1753
+mmc_core-y := core.o sysfs.o bus.o host.o \
1754
+ mmc.o mmc_ops.o sd.o sd_ops.o \
1755
+ sdio.o sdio_ops.o sdio_bus.o \
1756
+ sdio_cis.o sdio_io.o sdio_irq.o
1758
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
1759
new file mode 100644
1760
index 0000000..f2e6ace
1762
+++ b/drivers/mmc/core/bus.c
1765
+ * linux/drivers/mmc/core/bus.c
1767
+ * Copyright (C) 2003 Russell King, All Rights Reserved.
1768
+ * Copyright (C) 2007 Pierre Ossman
1770
+ * This program is free software; you can redistribute it and/or modify
1771
+ * it under the terms of the GNU General Public License version 2 as
1772
+ * published by the Free Software Foundation.
1774
+ * MMC card bus driver model
1777
+#include <linux/device.h>
1778
+#include <linux/err.h>
1780
+#include <linux/mmc/card.h>
1781
+#include <linux/mmc/host.h>
1785
+#include "sdio_cis.h"
1788
+#define dev_to_mmc_card(d) container_of(d, struct mmc_card, dev)
1789
+#define to_mmc_driver(d) container_of(d, struct mmc_driver, drv)
1791
+static ssize_t mmc_type_show(struct device *dev,
1792
+ struct device_attribute *attr, char *buf)
1794
+ struct mmc_card *card = dev_to_mmc_card(dev);
1796
+ switch (card->type) {
1797
+ case MMC_TYPE_MMC:
1798
+ return sprintf(buf, "MMC\n");
1800
+ return sprintf(buf, "SD\n");
1801
+ case MMC_TYPE_SDIO:
1802
+ return sprintf(buf, "SDIO\n");
1808
+static struct device_attribute mmc_dev_attrs[] = {
1809
+ MMC_ATTR_RO(type),
1814
+ * This currently matches any MMC driver to any MMC card - drivers
1815
+ * themselves make the decision whether to drive this card in their
1818
+static int mmc_bus_match(struct device *dev, struct device_driver *drv)
1824
+mmc_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
1827
+ struct mmc_card *card = dev_to_mmc_card(dev);
1829
+ int i = 0, length = 0;
1831
+ switch (card->type) {
1832
+ case MMC_TYPE_MMC:
1838
+ case MMC_TYPE_SDIO:
1846
+ if (add_uevent_var(envp, num_envp, &i,
1847
+ buf, buf_size, &length,
1848
+ "MMC_TYPE=%s", type))
1852
+ if (add_uevent_var(envp, num_envp, &i,
1853
+ buf, buf_size, &length,
1854
+ "MMC_NAME=%s", mmc_card_name(card)))
1862
+static int mmc_bus_probe(struct device *dev)
1864
+ struct mmc_driver *drv = to_mmc_driver(dev->driver);
1865
+ struct mmc_card *card = dev_to_mmc_card(dev);
1867
+ return drv->probe(card);
1870
+static int mmc_bus_remove(struct device *dev)
1872
+ struct mmc_driver *drv = to_mmc_driver(dev->driver);
1873
+ struct mmc_card *card = dev_to_mmc_card(dev);
1875
+ drv->remove(card);
1880
+static int mmc_bus_suspend(struct device *dev, pm_message_t state)
1882
+ struct mmc_driver *drv = to_mmc_driver(dev->driver);
1883
+ struct mmc_card *card = dev_to_mmc_card(dev);
1886
+ if (dev->driver && drv->suspend)
1887
+ ret = drv->suspend(card, state);
1891
+static int mmc_bus_resume(struct device *dev)
1893
+ struct mmc_driver *drv = to_mmc_driver(dev->driver);
1894
+ struct mmc_card *card = dev_to_mmc_card(dev);
1897
+ if (dev->driver && drv->resume)
1898
+ ret = drv->resume(card);
1902
+static struct bus_type mmc_bus_type = {
1904
+ .dev_attrs = mmc_dev_attrs,
1905
+ .match = mmc_bus_match,
1906
+ .uevent = mmc_bus_uevent,
1907
+ .probe = mmc_bus_probe,
1908
+ .remove = mmc_bus_remove,
1909
+ .suspend = mmc_bus_suspend,
1910
+ .resume = mmc_bus_resume,
1913
+int mmc_register_bus(void)
1915
+ return bus_register(&mmc_bus_type);
1918
+void mmc_unregister_bus(void)
1920
+ bus_unregister(&mmc_bus_type);
1924
+ * mmc_register_driver - register a media driver
1925
+ * @drv: MMC media driver
1927
+int mmc_register_driver(struct mmc_driver *drv)
1929
+ drv->drv.bus = &mmc_bus_type;
1930
+ return driver_register(&drv->drv);
1933
+EXPORT_SYMBOL(mmc_register_driver);
1936
+ * mmc_unregister_driver - unregister a media driver
1937
+ * @drv: MMC media driver
1939
+void mmc_unregister_driver(struct mmc_driver *drv)
1941
+ drv->drv.bus = &mmc_bus_type;
1942
+ driver_unregister(&drv->drv);
1945
+EXPORT_SYMBOL(mmc_unregister_driver);
1947
+static void mmc_release_card(struct device *dev)
1949
+ struct mmc_card *card = dev_to_mmc_card(dev);
1951
+ sdio_free_common_cis(card);
1954
+ kfree(card->info);
1960
+ * Allocate and initialise a new MMC card structure.
1962
+struct mmc_card *mmc_alloc_card(struct mmc_host *host)
1964
+ struct mmc_card *card;
1966
+ card = kzalloc(sizeof(struct mmc_card), GFP_KERNEL);
1968
+ return ERR_PTR(-ENOMEM);
1970
+ card->host = host;
1972
+ device_initialize(&card->dev);
1974
+ card->dev.parent = mmc_classdev(host);
1975
+ card->dev.bus = &mmc_bus_type;
1976
+ card->dev.release = mmc_release_card;
1982
+ * Register a new MMC card with the driver model.
1984
+int mmc_add_card(struct mmc_card *card)
1989
+ snprintf(card->dev.bus_id, sizeof(card->dev.bus_id),
1990
+ "%s:%04x", mmc_hostname(card->host), card->rca);
1992
+ switch (card->type) {
1993
+ case MMC_TYPE_MMC:
1998
+ if (mmc_card_blockaddr(card))
2001
+ case MMC_TYPE_SDIO:
2009
+ if (mmc_host_is_spi(card->host)) {
2010
+ printk(KERN_INFO "%s: new %s%s card on SPI\n",
2011
+ mmc_hostname(card->host),
2012
+ mmc_card_highspeed(card) ? "high speed " : "",
2015
+ printk(KERN_INFO "%s: new %s%s card at address %04x\n",
2016
+ mmc_hostname(card->host),
2017
+ mmc_card_highspeed(card) ? "high speed " : "",
2021
+ card->dev.uevent_suppress = 1;
2023
+ ret = device_add(&card->dev);
2027
+ if (card->host->bus_ops->sysfs_add) {
2028
+ ret = card->host->bus_ops->sysfs_add(card->host, card);
2030
+ device_del(&card->dev);
2035
+ card->dev.uevent_suppress = 0;
2037
+ kobject_uevent(&card->dev.kobj, KOBJ_ADD);
2039
+ mmc_card_set_present(card);
2045
+ * Unregister a new MMC card with the driver model, and
2046
+ * (eventually) free it.
2048
+void mmc_remove_card(struct mmc_card *card)
2050
+ if (mmc_card_present(card)) {
2051
+ if (mmc_host_is_spi(card->host)) {
2052
+ printk(KERN_INFO "%s: SPI card removed\n",
2053
+ mmc_hostname(card->host));
2055
+ printk(KERN_INFO "%s: card %04x removed\n",
2056
+ mmc_hostname(card->host), card->rca);
2059
+ if (card->host->bus_ops->sysfs_remove)
2060
+ card->host->bus_ops->sysfs_remove(card->host, card);
2061
+ device_del(&card->dev);
2064
+ put_device(&card->dev);
2067
diff --git a/drivers/mmc/core/bus.h b/drivers/mmc/core/bus.h
2068
new file mode 100644
2069
index 0000000..4f35431
2071
+++ b/drivers/mmc/core/bus.h
2074
+ * linux/drivers/mmc/core/bus.h
2076
+ * Copyright (C) 2003 Russell King, All Rights Reserved.
2077
+ * Copyright 2007 Pierre Ossman
2079
+ * This program is free software; you can redistribute it and/or modify
2080
+ * it under the terms of the GNU General Public License version 2 as
2081
+ * published by the Free Software Foundation.
2083
+#ifndef _MMC_CORE_BUS_H
2084
+#define _MMC_CORE_BUS_H
2086
+struct mmc_card *mmc_alloc_card(struct mmc_host *host);
2087
+int mmc_add_card(struct mmc_card *card);
2088
+void mmc_remove_card(struct mmc_card *card);
2090
+int mmc_register_bus(void);
2091
+void mmc_unregister_bus(void);
2095
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
2096
index 7385acf..95a9fc4 100644
2097
--- a/drivers/mmc/core/core.c
2098
+++ b/drivers/mmc/core/core.c
2100
#include <linux/delay.h>
2101
#include <linux/pagemap.h>
2102
#include <linux/err.h>
2103
+#include <linux/leds.h>
2104
#include <asm/scatterlist.h>
2105
#include <linux/scatterlist.h>
2108
#include <linux/mmc/sd.h>
2114
+#include "sdio_bus.h"
2116
#include "mmc_ops.h"
2118
+#include "sdio_ops.h"
2120
extern int mmc_attach_mmc(struct mmc_host *host, u32 ocr);
2121
extern int mmc_attach_sd(struct mmc_host *host, u32 ocr);
2122
+extern int mmc_attach_sdio(struct mmc_host *host, u32 ocr);
2124
+static struct workqueue_struct *workqueue;
2127
+ * Enabling software CRCs on the data blocks can be a significant (30%)
2128
+ * performance cost, and for other reasons may not always be desired.
2129
+ * So we allow it it to be disabled.
2131
+int use_spi_crc = 1;
2132
+module_param(use_spi_crc, bool, 0);
2135
+ * Internal function. Schedule delayed work in the MMC work queue.
2137
+static int mmc_schedule_delayed_work(struct delayed_work *work,
2138
+ unsigned long delay)
2140
+ return queue_delayed_work(workqueue, work, delay);
2144
+ * Internal function. Flush all scheduled work from the MMC work queue.
2146
+static void mmc_flush_scheduled_work(void)
2148
+ flush_workqueue(workqueue);
2152
* mmc_request_done - finish processing an MMC request
2153
@@ -48,32 +80,48 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
2154
struct mmc_command *cmd = mrq->cmd;
2155
int err = cmd->error;
2157
- pr_debug("%s: req done (CMD%u): %d/%d/%d: %08x %08x %08x %08x\n",
2158
- mmc_hostname(host), cmd->opcode, err,
2159
- mrq->data ? mrq->data->error : 0,
2160
- mrq->stop ? mrq->stop->error : 0,
2161
- cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]);
2162
+ if (err && cmd->retries && mmc_host_is_spi(host)) {
2163
+ if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
2167
if (err && cmd->retries) {
2168
+ pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
2169
+ mmc_hostname(host), cmd->opcode, err);
2173
host->ops->request(host, mrq);
2174
- } else if (mrq->done) {
2177
+ led_trigger_event(host->led, LED_OFF);
2179
+ pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n",
2180
+ mmc_hostname(host), cmd->opcode, err,
2181
+ cmd->resp[0], cmd->resp[1],
2182
+ cmd->resp[2], cmd->resp[3]);
2185
+ pr_debug("%s: %d bytes transferred: %d\n",
2186
+ mmc_hostname(host),
2187
+ mrq->data->bytes_xfered, mrq->data->error);
2191
+ pr_debug("%s: (CMD%u): %d: %08x %08x %08x %08x\n",
2192
+ mmc_hostname(host), mrq->stop->opcode,
2194
+ mrq->stop->resp[0], mrq->stop->resp[1],
2195
+ mrq->stop->resp[2], mrq->stop->resp[3]);
2203
EXPORT_SYMBOL(mmc_request_done);
2206
- * mmc_start_request - start a command on a host
2207
- * @host: MMC host to start command on
2208
- * @mrq: MMC request to start
2210
- * Queue a command on the specified host. We expect the
2211
- * caller to be holding the host lock with interrupts disabled.
2215
mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
2217
#ifdef CONFIG_MMC_DEBUG
2218
@@ -84,8 +132,25 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
2219
mmc_hostname(host), mrq->cmd->opcode,
2220
mrq->cmd->arg, mrq->cmd->flags);
2223
+ pr_debug("%s: blksz %d blocks %d flags %08x "
2224
+ "tsac %d ms nsac %d\n",
2225
+ mmc_hostname(host), mrq->data->blksz,
2226
+ mrq->data->blocks, mrq->data->flags,
2227
+ mrq->data->timeout_ns / 1000000,
2228
+ mrq->data->timeout_clks);
2232
+ pr_debug("%s: CMD%u arg %08x flags %08x\n",
2233
+ mmc_hostname(host), mrq->stop->opcode,
2234
+ mrq->stop->arg, mrq->stop->flags);
2237
WARN_ON(!host->claimed);
2239
+ led_trigger_event(host->led, LED_FULL);
2241
mrq->cmd->error = 0;
2242
mrq->cmd->mrq = mrq;
2244
@@ -113,14 +178,21 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
2245
host->ops->request(host, mrq);
2248
-EXPORT_SYMBOL(mmc_start_request);
2250
static void mmc_wait_done(struct mmc_request *mrq)
2252
complete(mrq->done_data);
2255
-int mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
2257
+ * mmc_wait_for_req - start a request and wait for completion
2258
+ * @host: MMC host to start command
2259
+ * @mrq: MMC request to start
2261
+ * Start a new MMC custom command request for a host, and wait
2262
+ * for the command to complete. Does not attempt to parse the
2265
+void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
2267
DECLARE_COMPLETION_ONSTACK(complete);
2269
@@ -130,8 +202,6 @@ int mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
2270
mmc_start_request(host, mrq);
2272
wait_for_completion(&complete);
2277
EXPORT_SYMBOL(mmc_wait_for_req);
2278
@@ -150,7 +220,7 @@ int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries
2280
struct mmc_request mrq;
2282
- BUG_ON(!host->claimed);
2283
+ WARN_ON(!host->claimed);
2285
memset(&mrq, 0, sizeof(struct mmc_request));
2287
@@ -171,14 +241,24 @@ EXPORT_SYMBOL(mmc_wait_for_cmd);
2288
* mmc_set_data_timeout - set the timeout for a data command
2289
* @data: data phase for command
2290
* @card: the MMC card associated with the data transfer
2291
- * @write: flag to differentiate reads from writes
2293
+ * Computes the data timeout parameters according to the
2294
+ * correct algorithm given the card type.
2296
-void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card,
2298
+void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
2303
+ * SDIO cards only define an upper 1 s limit on access.
2305
+ if (mmc_card_sdio(card)) {
2306
+ data->timeout_ns = 1000000000;
2307
+ data->timeout_clks = 0;
2312
* SD cards use a 100 multiplier rather than 10
2314
mult = mmc_card_sd(card) ? 100 : 10;
2315
@@ -187,7 +267,7 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card,
2316
* Scale up the multiplier (and therefore the timeout) by
2317
* the r2w factor for writes.
2320
+ if (data->flags & MMC_DATA_WRITE)
2321
mult <<= card->csd.r2w_factor;
2323
data->timeout_ns = card->csd.tacc_ns * mult;
2324
@@ -203,7 +283,7 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card,
2325
timeout_us += data->timeout_clks * 1000 /
2326
(card->host->ios.clock / 1000);
2329
+ if (data->flags & MMC_DATA_WRITE)
2333
@@ -222,36 +302,43 @@ EXPORT_SYMBOL(mmc_set_data_timeout);
2335
* __mmc_claim_host - exclusively claim a host
2336
* @host: mmc host to claim
2337
- * @card: mmc card to claim host for
2339
- * Claim a host for a set of operations. If a valid card
2340
- * is passed and this wasn't the last card selected, select
2341
- * the card before returning.
2342
+ * @abort: whether or not the operation should be aborted
2344
- * Note: you should use mmc_card_claim_host or mmc_claim_host.
2345
+ * Claim a host for a set of operations. If @abort is non null and
2346
+ * dereference a non-zero value then this will return prematurely with
2347
+ * that non-zero value without acquiring the lock. Returns zero
2348
+ * with the lock held otherwise.
2350
-void mmc_claim_host(struct mmc_host *host)
2351
+int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
2353
DECLARE_WAITQUEUE(wait, current);
2354
unsigned long flags;
2359
add_wait_queue(&host->wq, &wait);
2360
spin_lock_irqsave(&host->lock, flags);
2362
set_current_state(TASK_UNINTERRUPTIBLE);
2363
- if (!host->claimed)
2364
+ stop = abort ? atomic_read(abort) : 0;
2365
+ if (stop || !host->claimed)
2367
spin_unlock_irqrestore(&host->lock, flags);
2369
spin_lock_irqsave(&host->lock, flags);
2371
set_current_state(TASK_RUNNING);
2372
- host->claimed = 1;
2374
+ host->claimed = 1;
2376
+ wake_up(&host->wq);
2377
spin_unlock_irqrestore(&host->lock, flags);
2378
remove_wait_queue(&host->wq, &wait);
2382
-EXPORT_SYMBOL(mmc_claim_host);
2383
+EXPORT_SYMBOL(__mmc_claim_host);
2386
* mmc_release_host - release a host
2387
@@ -264,7 +351,7 @@ void mmc_release_host(struct mmc_host *host)
2389
unsigned long flags;
2391
- BUG_ON(!host->claimed);
2392
+ WARN_ON(!host->claimed);
2394
spin_lock_irqsave(&host->lock, flags);
2396
@@ -369,22 +456,6 @@ void mmc_set_timing(struct mmc_host *host, unsigned int timing)
2400
- * Allocate a new MMC card
2402
-struct mmc_card *mmc_alloc_card(struct mmc_host *host)
2404
- struct mmc_card *card;
2406
- card = kmalloc(sizeof(struct mmc_card), GFP_KERNEL);
2408
- return ERR_PTR(-ENOMEM);
2410
- mmc_init_card(card, host);
2416
* Apply power to the MMC stack. This is a two-stage process.
2417
* First, we enable power to the card without the clock running.
2418
* We then wait a bit for the power to stabilise. Finally,
2419
@@ -399,29 +470,46 @@ static void mmc_power_up(struct mmc_host *host)
2421
int bit = fls(host->ocr_avail) - 1;
2424
host->ios.vdd = bit;
2425
- host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
2426
+ if (mmc_host_is_spi(host)) {
2427
+ host->ios.chip_select = MMC_CS_HIGH;
2428
+ host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
2430
host->ios.chip_select = MMC_CS_DONTCARE;
2431
+ host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
2433
host->ios.power_mode = MMC_POWER_UP;
2434
host->ios.bus_width = MMC_BUS_WIDTH_1;
2435
host->ios.timing = MMC_TIMING_LEGACY;
2440
+ * This delay should be sufficient to allow the power supply
2441
+ * to reach the minimum voltage.
2445
host->ios.clock = host->f_min;
2446
host->ios.power_mode = MMC_POWER_ON;
2450
+ * This delay must be at least 74 clock sizes, or 1 ms, or the
2451
+ * time required to reach a stable voltage.
2456
static void mmc_power_off(struct mmc_host *host)
2459
host->ios.clock = 0;
2461
+ if (!mmc_host_is_spi(host)) {
2462
host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
2463
host->ios.chip_select = MMC_CS_DONTCARE;
2465
host->ios.power_mode = MMC_POWER_OFF;
2466
host->ios.bus_width = MMC_BUS_WIDTH_1;
2467
host->ios.timing = MMC_TIMING_LEGACY;
2468
@@ -429,6 +517,45 @@ static void mmc_power_off(struct mmc_host *host)
2472
+ * Cleanup when the last reference to the bus operator is dropped.
2474
+void __mmc_release_bus(struct mmc_host *host)
2477
+ BUG_ON(host->bus_refs);
2478
+ BUG_ON(!host->bus_dead);
2480
+ host->bus_ops = NULL;
2484
+ * Increase reference count of bus operator
2486
+static inline void mmc_bus_get(struct mmc_host *host)
2488
+ unsigned long flags;
2490
+ spin_lock_irqsave(&host->lock, flags);
2492
+ spin_unlock_irqrestore(&host->lock, flags);
2496
+ * Decrease reference count of bus operator and free it if
2497
+ * it is the last reference.
2499
+static inline void mmc_bus_put(struct mmc_host *host)
2501
+ unsigned long flags;
2503
+ spin_lock_irqsave(&host->lock, flags);
2505
+ if ((host->bus_refs == 0) && host->bus_ops)
2506
+ __mmc_release_bus(host);
2507
+ spin_unlock_irqrestore(&host->lock, flags);
2511
* Assign a mmc bus handler to a host. Only one bus handler may control a
2512
* host at any given time.
2514
@@ -436,10 +563,12 @@ void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
2516
unsigned long flags;
2518
+ umd_dbg("enter!!!!!!!!!!!!!!!!!\n\n");
2523
- BUG_ON(!host->claimed);
2524
+ WARN_ON(!host->claimed);
2526
spin_lock_irqsave(&host->lock, flags);
2528
@@ -451,6 +580,8 @@ void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
2531
spin_unlock_irqrestore(&host->lock, flags);
2537
@@ -463,8 +594,8 @@ void mmc_detach_bus(struct mmc_host *host)
2541
- BUG_ON(!host->claimed);
2542
- BUG_ON(!host->bus_ops);
2543
+ WARN_ON(!host->claimed);
2544
+ WARN_ON(!host->bus_ops);
2546
spin_lock_irqsave(&host->lock, flags);
2548
@@ -477,34 +608,25 @@ void mmc_detach_bus(struct mmc_host *host)
2553
- * Cleanup when the last reference to the bus operator is dropped.
2555
-void __mmc_release_bus(struct mmc_host *host)
2558
- BUG_ON(host->bus_refs);
2559
- BUG_ON(!host->bus_dead);
2561
- host->bus_ops = NULL;
2565
* mmc_detect_change - process change of state on a MMC socket
2566
* @host: host which changed state.
2567
* @delay: optional delay to wait before detection (jiffies)
2569
- * All we know is that card(s) have been inserted or removed
2570
- * from the socket(s). We don't know which socket or cards.
2571
+ * MMC drivers should call this when they detect a card has been
2572
+ * inserted or removed. The MMC layer will confirm that any
2573
+ * present card is still functional, and initialize any newly
2576
void mmc_detect_change(struct mmc_host *host, unsigned long delay)
2578
#ifdef CONFIG_MMC_DEBUG
2579
unsigned long flags;
2580
spin_lock_irqsave(&host->lock, flags);
2581
- BUG_ON(host->removed);
2582
+ WARN_ON(host->removed);
2583
spin_unlock_irqrestore(&host->lock, flags);
2587
mmc_schedule_delayed_work(&host->detect, delay);
2589
@@ -512,13 +634,14 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay)
2590
EXPORT_SYMBOL(mmc_detect_change);
2593
-static void mmc_rescan(struct work_struct *work)
2594
+void mmc_rescan(struct work_struct *work)
2596
struct mmc_host *host =
2597
container_of(work, struct mmc_host, detect.work);
2601
+ umd_dbg("Scan for %s", host->class_dev.bus_id);
2604
if (host->bus_ops == NULL) {
2605
@@ -531,99 +654,64 @@ static void mmc_rescan(struct work_struct *work)
2606
mmc_claim_host(host);
2615
mmc_send_if_cond(host, host->ocr_avail);
2618
+ * First we search for SDIO...
2620
+ err = mmc_send_io_op_cond(host, 0, &ocr);
2622
+ if (mmc_attach_sdio(host, ocr))
2623
+ mmc_power_off(host);
2628
+ * ...then normal SD...
2630
err = mmc_send_app_op_cond(host, 0, &ocr);
2631
- if (err == MMC_ERR_NONE) {
2633
if (mmc_attach_sd(host, ocr))
2634
mmc_power_off(host);
2637
- * If we fail to detect any SD cards then try
2638
- * searching for MMC cards.
2640
- err = mmc_send_op_cond(host, 0, &ocr);
2641
- if (err == MMC_ERR_NONE) {
2642
- if (mmc_attach_mmc(host, ocr))
2643
- mmc_power_off(host);
2649
+ * ...and finally MMC.
2651
+ err = mmc_send_op_cond(host, 0, &ocr);
2653
+ if (mmc_attach_mmc(host, ocr))
2654
mmc_power_off(host);
2655
- mmc_release_host(host);
2660
+ mmc_release_host(host);
2661
+ mmc_power_off(host);
2663
if (host->bus_ops->detect && !host->bus_dead)
2664
host->bus_ops->detect(host);
2672
- * mmc_alloc_host - initialise the per-host structure.
2673
- * @extra: sizeof private data structure
2674
- * @dev: pointer to host device model structure
2676
- * Initialise the per-host structure.
2678
-struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
2680
- struct mmc_host *host;
2682
- host = mmc_alloc_host_sysfs(extra, dev);
2684
- spin_lock_init(&host->lock);
2685
- init_waitqueue_head(&host->wq);
2686
- INIT_DELAYED_WORK(&host->detect, mmc_rescan);
2689
- * By default, hosts do not support SGIO or large requests.
2690
- * They have to set these according to their abilities.
2692
- host->max_hw_segs = 1;
2693
- host->max_phys_segs = 1;
2694
- host->max_seg_size = PAGE_CACHE_SIZE;
2696
- host->max_req_size = PAGE_CACHE_SIZE;
2697
- host->max_blk_size = 512;
2698
- host->max_blk_count = PAGE_CACHE_SIZE / 512;
2705
-EXPORT_SYMBOL(mmc_alloc_host);
2708
- * mmc_add_host - initialise host hardware
2711
-int mmc_add_host(struct mmc_host *host)
2712
+void mmc_start_host(struct mmc_host *host)
2716
- ret = mmc_add_host_sysfs(host);
2718
- mmc_power_off(host);
2719
- mmc_detect_change(host, 0);
2723
+ umd_dbg("enter, for %s", host->class_dev.bus_id);
2724
+ mmc_power_off(host);
2725
+ mmc_detect_change(host, 0);
2728
-EXPORT_SYMBOL(mmc_add_host);
2731
- * mmc_remove_host - remove host hardware
2734
- * Unregister and remove all cards associated with this host,
2735
- * and power down the MMC bus.
2737
-void mmc_remove_host(struct mmc_host *host)
2738
+void mmc_stop_host(struct mmc_host *host)
2740
#ifdef CONFIG_MMC_DEBUG
2741
unsigned long flags;
2742
@@ -648,24 +736,8 @@ void mmc_remove_host(struct mmc_host *host)
2745
mmc_power_off(host);
2746
- mmc_remove_host_sysfs(host);
2749
-EXPORT_SYMBOL(mmc_remove_host);
2752
- * mmc_free_host - free the host structure
2755
- * Free the host once all references to it have been dropped.
2757
-void mmc_free_host(struct mmc_host *host)
2759
- mmc_free_host_sysfs(host);
2762
-EXPORT_SYMBOL(mmc_free_host);
2767
@@ -675,6 +747,8 @@ EXPORT_SYMBOL(mmc_free_host);
2769
int mmc_suspend_host(struct mmc_host *host, pm_message_t state)
2773
mmc_flush_scheduled_work();
2776
@@ -705,6 +779,7 @@ EXPORT_SYMBOL(mmc_suspend_host);
2778
int mmc_resume_host(struct mmc_host *host)
2782
if (host->bus_ops && !host->bus_dead) {
2784
@@ -726,4 +801,49 @@ EXPORT_SYMBOL(mmc_resume_host);
2788
+static int __init mmc_init(void)
2793
+ workqueue = create_singlethread_workqueue("kmmcd");
2797
+ ret = mmc_register_bus();
2799
+ goto destroy_workqueue;
2801
+ ret = mmc_register_host_class();
2803
+ goto unregister_bus;
2805
+ ret = sdio_register_bus();
2807
+ goto unregister_host_class;
2812
+unregister_host_class:
2813
+ mmc_unregister_host_class();
2815
+ mmc_unregister_bus();
2817
+ destroy_workqueue(workqueue);
2822
+static void __exit mmc_exit(void)
2824
+ sdio_unregister_bus();
2825
+ mmc_unregister_host_class();
2826
+ mmc_unregister_bus();
2827
+ destroy_workqueue(workqueue);
2830
+subsys_initcall(mmc_init);
2831
+module_exit(mmc_exit);
2833
MODULE_LICENSE("GPL");
2834
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
2835
index 177264d..39daf2f 100644
2836
--- a/drivers/mmc/core/core.h
2837
+++ b/drivers/mmc/core/core.h
2839
struct mmc_bus_ops {
2840
void (*remove)(struct mmc_host *);
2841
void (*detect)(struct mmc_host *);
2842
+ int (*sysfs_add)(struct mmc_host *, struct mmc_card *card);
2843
+ void (*sysfs_remove)(struct mmc_host *, struct mmc_card *card);
2844
void (*suspend)(struct mmc_host *);
2845
void (*resume)(struct mmc_host *);
2847
@@ -25,28 +27,6 @@ struct mmc_bus_ops {
2848
void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
2849
void mmc_detach_bus(struct mmc_host *host);
2851
-void __mmc_release_bus(struct mmc_host *host);
2853
-static inline void mmc_bus_get(struct mmc_host *host)
2855
- unsigned long flags;
2857
- spin_lock_irqsave(&host->lock, flags);
2859
- spin_unlock_irqrestore(&host->lock, flags);
2862
-static inline void mmc_bus_put(struct mmc_host *host)
2864
- unsigned long flags;
2866
- spin_lock_irqsave(&host->lock, flags);
2868
- if ((host->bus_refs == 0) && host->bus_ops)
2869
- __mmc_release_bus(host);
2870
- spin_unlock_irqrestore(&host->lock, flags);
2873
void mmc_set_chip_select(struct mmc_host *host, int mode);
2874
void mmc_set_clock(struct mmc_host *host, unsigned int hz);
2875
void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
2876
@@ -54,8 +34,6 @@ void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
2877
u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
2878
void mmc_set_timing(struct mmc_host *host, unsigned int timing);
2880
-struct mmc_card *mmc_alloc_card(struct mmc_host *host);
2882
static inline void mmc_delay(unsigned int ms)
2884
if (ms < 1000 / HZ) {
2885
@@ -66,5 +44,11 @@ static inline void mmc_delay(unsigned int ms)
2889
+void mmc_rescan(struct work_struct *work);
2890
+void mmc_start_host(struct mmc_host *host);
2891
+void mmc_stop_host(struct mmc_host *host);
2893
+extern int use_spi_crc;
2897
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
2898
new file mode 100644
2899
index 0000000..c65d203
2901
+++ b/drivers/mmc/core/host.c
2904
+ * linux/drivers/mmc/core/host.c
2906
+ * Copyright (C) 2003 Russell King, All Rights Reserved.
2907
+ * Copyright (C) 2007 Pierre Ossman
2909
+ * This program is free software; you can redistribute it and/or modify
2910
+ * it under the terms of the GNU General Public License version 2 as
2911
+ * published by the Free Software Foundation.
2913
+ * MMC host class device management
2916
+#include <linux/device.h>
2917
+#include <linux/err.h>
2918
+#include <linux/idr.h>
2919
+#include <linux/pagemap.h>
2920
+#include <linux/leds.h>
2922
+#include <linux/mmc/host.h>
2927
+#define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
2929
+static void mmc_host_classdev_release(struct device *dev)
2931
+ struct mmc_host *host = cls_dev_to_mmc_host(dev);
2935
+static struct class mmc_host_class = {
2936
+ .name = "mmc_host",
2937
+ .dev_release = mmc_host_classdev_release,
2940
+int mmc_register_host_class(void)
2942
+ return class_register(&mmc_host_class);
2945
+void mmc_unregister_host_class(void)
2947
+ class_unregister(&mmc_host_class);
2950
+static DEFINE_IDR(mmc_host_idr);
2951
+static DEFINE_SPINLOCK(mmc_host_lock);
2954
+ * mmc_alloc_host - initialise the per-host structure.
2955
+ * @extra: sizeof private data structure
2956
+ * @dev: pointer to host device model structure
2958
+ * Initialise the per-host structure.
2960
+struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
2962
+ struct mmc_host *host;
2964
+ host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
2968
+ host->parent = dev;
2969
+ host->class_dev.parent = dev;
2970
+ host->class_dev.class = &mmc_host_class;
2971
+ device_initialize(&host->class_dev);
2973
+ spin_lock_init(&host->lock);
2974
+ init_waitqueue_head(&host->wq);
2975
+ INIT_DELAYED_WORK(&host->detect, mmc_rescan);
2978
+ * By default, hosts do not support SGIO or large requests.
2979
+ * They have to set these according to their abilities.
2981
+ host->max_hw_segs = 1;
2982
+ host->max_phys_segs = 1;
2983
+ host->max_seg_size = PAGE_CACHE_SIZE;
2985
+ host->max_req_size = PAGE_CACHE_SIZE;
2986
+ host->max_blk_size = 512;
2987
+ host->max_blk_count = PAGE_CACHE_SIZE / 512;
2992
+EXPORT_SYMBOL(mmc_alloc_host);
2995
+ * mmc_add_host - initialise host hardware
2998
+ * Register the host with the driver model. The host must be
2999
+ * prepared to start servicing requests before this function
3002
+int mmc_add_host(struct mmc_host *host)
3006
+ WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) &&
3007
+ !host->ops->enable_sdio_irq);
3009
+ if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
3012
+ spin_lock(&mmc_host_lock);
3013
+ err = idr_get_new(&mmc_host_idr, host, &host->index);
3014
+ spin_unlock(&mmc_host_lock);
3018
+ snprintf(host->class_dev.bus_id, BUS_ID_SIZE,
3019
+ "mmc%d", host->index);
3021
+ led_trigger_register_simple(host->class_dev.bus_id, &host->led);
3023
+ err = device_add(&host->class_dev);
3027
+ mmc_start_host(host);
3032
+EXPORT_SYMBOL(mmc_add_host);
3035
+ * mmc_remove_host - remove host hardware
3038
+ * Unregister and remove all cards associated with this host,
3039
+ * and power down the MMC bus. No new requests will be issued
3040
+ * after this function has returned.
3042
+void mmc_remove_host(struct mmc_host *host)
3044
+ mmc_stop_host(host);
3046
+ device_del(&host->class_dev);
3048
+ led_trigger_unregister_simple(host->led);
3050
+ spin_lock(&mmc_host_lock);
3051
+ idr_remove(&mmc_host_idr, host->index);
3052
+ spin_unlock(&mmc_host_lock);
3055
+EXPORT_SYMBOL(mmc_remove_host);
3058
+ * mmc_free_host - free the host structure
3061
+ * Free the host once all references to it have been dropped.
3063
+void mmc_free_host(struct mmc_host *host)
3065
+ put_device(&host->class_dev);
3068
+EXPORT_SYMBOL(mmc_free_host);
3070
diff --git a/drivers/mmc/core/host.h b/drivers/mmc/core/host.h
3071
new file mode 100644
3072
index 0000000..c2dc3d2
3074
+++ b/drivers/mmc/core/host.h
3077
+ * linux/drivers/mmc/core/host.h
3079
+ * Copyright (C) 2003 Russell King, All Rights Reserved.
3080
+ * Copyright 2007 Pierre Ossman
3082
+ * This program is free software; you can redistribute it and/or modify
3083
+ * it under the terms of the GNU General Public License version 2 as
3084
+ * published by the Free Software Foundation.
3086
+#ifndef _MMC_CORE_HOST_H
3087
+#define _MMC_CORE_HOST_H
3089
+int mmc_register_host_class(void);
3090
+void mmc_unregister_host_class(void);
3094
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
3095
index 42cc286..78d6ae0 100644
3096
--- a/drivers/mmc/core/mmc.c
3097
+++ b/drivers/mmc/core/mmc.c
3100
- * linux/drivers/mmc/mmc.c
3101
+ * linux/drivers/mmc/core/mmc.c
3103
* Copyright (C) 2003-2004 Russell King, All Rights Reserved.
3104
* Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
3110
#include "mmc_ops.h"
3112
static const unsigned int tran_exp[] = {
3113
@@ -99,7 +100,7 @@ static int mmc_decode_cid(struct mmc_card *card)
3117
- printk("%s: card has unknown MMCA version %d\n",
3118
+ printk(KERN_ERR "%s: card has unknown MMCA version %d\n",
3119
mmc_hostname(card->host), card->csd.mmca_vsn);
3122
@@ -122,7 +123,7 @@ static int mmc_decode_csd(struct mmc_card *card)
3124
csd_struct = UNSTUFF_BITS(resp, 126, 2);
3125
if (csd_struct != 1 && csd_struct != 2) {
3126
- printk("%s: unrecognised CSD structure version %d\n",
3127
+ printk(KERN_ERR "%s: unrecognised CSD structure version %d\n",
3128
mmc_hostname(card->host), csd_struct);
3131
@@ -160,13 +161,12 @@ static int mmc_read_ext_csd(struct mmc_card *card)
3135
+ unsigned int ext_csd_struct;
3139
- err = MMC_ERR_FAILED;
3141
if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
3142
- return MMC_ERR_NONE;
3146
* As the ext_csd is so large and mostly unused, we don't store the
3147
@@ -175,13 +175,19 @@ static int mmc_read_ext_csd(struct mmc_card *card)
3148
ext_csd = kmalloc(512, GFP_KERNEL);
3150
printk(KERN_ERR "%s: could not allocate a buffer to "
3151
- "receive the ext_csd. mmc v4 cards will be "
3152
- "treated as v3.\n", mmc_hostname(card->host));
3153
- return MMC_ERR_FAILED;
3154
+ "receive the ext_csd.\n", mmc_hostname(card->host));
3158
err = mmc_send_ext_csd(card, ext_csd);
3159
- if (err != MMC_ERR_NONE) {
3162
+ * We all hosts that cannot perform the command
3163
+ * to fail more gracefully
3165
+ if (err != -EINVAL)
3169
* High capacity cards should have this "magic" size
3170
* stored in their CSD.
3171
@@ -196,11 +202,22 @@ static int mmc_read_ext_csd(struct mmc_card *card)
3172
"EXT_CSD, performance might "
3174
mmc_hostname(card->host));
3175
- err = MMC_ERR_NONE;
3182
+ ext_csd_struct = ext_csd[EXT_CSD_REV];
3183
+ if (ext_csd_struct > 2) {
3184
+ printk(KERN_ERR "%s: unrecognised EXT_CSD structure "
3185
+ "version %d\n", mmc_hostname(card->host),
3191
+ if (ext_csd_struct >= 2) {
3192
card->ext_csd.sectors =
3193
ext_csd[EXT_CSD_SEC_CNT + 0] << 0 |
3194
ext_csd[EXT_CSD_SEC_CNT + 1] << 8 |
3195
@@ -208,6 +225,7 @@ static int mmc_read_ext_csd(struct mmc_card *card)
3196
ext_csd[EXT_CSD_SEC_CNT + 3] << 24;
3197
if (card->ext_csd.sectors)
3198
mmc_card_set_blockaddr(card);
3201
switch (ext_csd[EXT_CSD_CARD_TYPE]) {
3202
case EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26:
3203
@@ -236,7 +254,7 @@ out:
3204
* In the case of a resume, "curcard" will contain the card
3205
* we're trying to reinitialise.
3207
-static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
3208
+static int mmc_init_card(struct mmc_host *host, u32 ocr,
3209
struct mmc_card *oldcard)
3211
struct mmc_card *card;
3212
@@ -245,7 +263,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
3213
unsigned int max_dtr;
3216
- BUG_ON(!host->claimed);
3217
+ WARN_ON(!host->claimed);
3220
* Since we're changing the OCR value, we seem to
3221
@@ -257,19 +275,33 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
3223
/* The extra bit indicates that we support high capacity */
3224
err = mmc_send_op_cond(host, ocr | (1 << 30), NULL);
3225
- if (err != MMC_ERR_NONE)
3230
+ * For SPI, enable CRC as appropriate.
3232
+ if (mmc_host_is_spi(host)) {
3233
+ err = mmc_spi_set_crc(host, use_spi_crc);
3239
* Fetch CID from card.
3241
+ if (mmc_host_is_spi(host))
3242
+ err = mmc_send_cid(host, cid);
3244
err = mmc_all_send_cid(host, cid);
3245
- if (err != MMC_ERR_NONE)
3250
- if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0)
3251
+ if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) {
3258
@@ -277,8 +309,10 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
3259
* Allocate card structure.
3261
card = mmc_alloc_card(host);
3263
+ if (IS_ERR(card)) {
3264
+ err = PTR_ERR(card);
3268
card->type = MMC_TYPE_MMC;
3270
@@ -286,43 +320,47 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
3275
+ * For native busses: set card RCA and quit open drain mode.
3277
+ if (!mmc_host_is_spi(host)) {
3278
err = mmc_set_relative_addr(card);
3279
- if (err != MMC_ERR_NONE)
3283
mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
3288
* Fetch CSD from card.
3290
err = mmc_send_csd(card, card->raw_csd);
3291
- if (err != MMC_ERR_NONE)
3295
err = mmc_decode_csd(card);
3299
err = mmc_decode_cid(card);
3306
* Select card, as all following commands rely on that.
3308
+ if (!mmc_host_is_spi(host)) {
3309
err = mmc_select_card(card);
3310
- if (err != MMC_ERR_NONE)
3317
- * Fetch and process extened CSD.
3318
+ * Fetch and process extended CSD.
3320
err = mmc_read_ext_csd(card);
3321
- if (err != MMC_ERR_NONE)
3326
@@ -333,7 +371,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
3327
(host->caps & MMC_CAP_MMC_HIGHSPEED)) {
3328
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
3329
EXT_CSD_HS_TIMING, 1);
3330
- if (err != MMC_ERR_NONE)
3334
mmc_card_set_highspeed(card);
3335
@@ -362,7 +400,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
3336
(host->caps & MMC_CAP_4_BIT_DATA)) {
3337
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
3338
EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_4);
3339
- if (err != MMC_ERR_NONE)
3343
mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
3344
@@ -371,14 +409,14 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
3348
- return MMC_ERR_NONE;
3353
mmc_remove_card(card);
3356
- return MMC_ERR_FAILED;
3361
@@ -412,9 +450,8 @@ static void mmc_detect(struct mmc_host *host)
3363
mmc_release_host(host);
3365
- if (err != MMC_ERR_NONE) {
3366
- mmc_remove_card(host->card);
3367
- host->card = NULL;
3371
mmc_claim_host(host);
3372
mmc_detach_bus(host);
3373
@@ -422,6 +459,53 @@ static void mmc_detect(struct mmc_host *host)
3377
+MMC_ATTR_FN(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
3378
+ card->raw_cid[2], card->raw_cid[3]);
3379
+MMC_ATTR_FN(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
3380
+ card->raw_csd[2], card->raw_csd[3]);
3381
+MMC_ATTR_FN(date, "%02d/%04d\n", card->cid.month, card->cid.year);
3382
+MMC_ATTR_FN(fwrev, "0x%x\n", card->cid.fwrev);
3383
+MMC_ATTR_FN(hwrev, "0x%x\n", card->cid.hwrev);
3384
+MMC_ATTR_FN(manfid, "0x%06x\n", card->cid.manfid);
3385
+MMC_ATTR_FN(name, "%s\n", card->cid.prod_name);
3386
+MMC_ATTR_FN(oemid, "0x%04x\n", card->cid.oemid);
3387
+MMC_ATTR_FN(serial, "0x%08x\n", card->cid.serial);
3389
+static struct device_attribute mmc_dev_attrs[] = {
3392
+ MMC_ATTR_RO(date),
3393
+ MMC_ATTR_RO(fwrev),
3394
+ MMC_ATTR_RO(hwrev),
3395
+ MMC_ATTR_RO(manfid),
3396
+ MMC_ATTR_RO(name),
3397
+ MMC_ATTR_RO(oemid),
3398
+ MMC_ATTR_RO(serial),
3403
+ * Adds sysfs entries as relevant.
3405
+static int mmc_sysfs_add(struct mmc_host *host, struct mmc_card *card)
3409
+ ret = mmc_add_attrs(card, mmc_dev_attrs);
3417
+ * Removes the sysfs entries added by mmc_sysfs_add().
3419
+static void mmc_sysfs_remove(struct mmc_host *host, struct mmc_card *card)
3421
+ mmc_remove_attrs(card, mmc_dev_attrs);
3424
#ifdef CONFIG_MMC_UNSAFE_RESUME
3427
@@ -433,6 +517,7 @@ static void mmc_suspend(struct mmc_host *host)
3428
BUG_ON(!host->card);
3430
mmc_claim_host(host);
3431
+ if (!mmc_host_is_spi(host))
3432
mmc_deselect_cards(host);
3433
host->card->state &= ~MMC_STATE_HIGHSPEED;
3434
mmc_release_host(host);
3435
@@ -452,16 +537,17 @@ static void mmc_resume(struct mmc_host *host)
3436
BUG_ON(!host->card);
3438
mmc_claim_host(host);
3439
+ err = mmc_init_card(host, host->ocr, host->card);
3440
+ mmc_release_host(host);
3442
- err = mmc_sd_init_card(host, host->ocr, host->card);
3443
- if (err != MMC_ERR_NONE) {
3444
- mmc_remove_card(host->card);
3445
- host->card = NULL;
3449
+ mmc_claim_host(host);
3450
mmc_detach_bus(host);
3451
+ mmc_release_host(host);
3454
- mmc_release_host(host);
3458
@@ -474,6 +560,8 @@ static void mmc_resume(struct mmc_host *host)
3459
static const struct mmc_bus_ops mmc_ops = {
3460
.remove = mmc_remove,
3461
.detect = mmc_detect,
3462
+ .sysfs_add = mmc_sysfs_add,
3463
+ .sysfs_remove = mmc_sysfs_remove,
3464
.suspend = mmc_suspend,
3465
.resume = mmc_resume,
3467
@@ -486,11 +574,20 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)
3471
- BUG_ON(!host->claimed);
3472
+ WARN_ON(!host->claimed);
3474
mmc_attach_bus(host, &mmc_ops);
3477
+ * We need to get OCR a different way for SPI.
3479
+ if (mmc_host_is_spi(host)) {
3480
+ err = mmc_spi_read_ocr(host, 1, &ocr);
3486
* Sanity check the voltages that the card claims to
3489
@@ -506,32 +603,37 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)
3491
* Can we support the voltage of the card?
3500
* Detect and init the card.
3502
- err = mmc_sd_init_card(host, host->ocr, NULL);
3503
- if (err != MMC_ERR_NONE)
3504
+ err = mmc_init_card(host, host->ocr, NULL);
3508
mmc_release_host(host);
3510
- err = mmc_register_card(host->card);
3511
+ err = mmc_add_card(host->card);
3513
- goto reclaim_host;
3519
- mmc_claim_host(host);
3521
mmc_remove_card(host->card);
3523
+ mmc_claim_host(host);
3525
mmc_detach_bus(host);
3526
mmc_release_host(host);
3529
+ printk(KERN_ERR "%s: error %d whilst initialising MMC card\n",
3530
+ mmc_hostname(host), err);
3535
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
3536
index 7dd720f..8a34df8 100644
3537
--- a/drivers/mmc/core/mmc_ops.c
3538
+++ b/drivers/mmc/core/mmc_ops.c
3541
- * linux/drivers/mmc/mmc_ops.h
3542
+ * linux/drivers/mmc/core/mmc_ops.h
3544
* Copyright 2006-2007 Pierre Ossman
3546
@@ -40,10 +40,10 @@ static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card)
3549
err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
3550
- if (err != MMC_ERR_NONE)
3554
- return MMC_ERR_NONE;
3558
int mmc_select_card(struct mmc_card *card)
3559
@@ -63,23 +63,36 @@ int mmc_go_idle(struct mmc_host *host)
3561
struct mmc_command cmd;
3564
+ * Non-SPI hosts need to prevent chipselect going active during
3565
+ * GO_IDLE; that would put chips into SPI mode. Remind them of
3566
+ * that in case of hardware that won't pull up DAT3/nCS otherwise.
3568
+ * SPI hosts ignore ios.chip_select; it's managed according to
3569
+ * rules that must accomodate non-MMC slaves which this layer
3570
+ * won't even know about.
3572
+ if (!mmc_host_is_spi(host)) {
3573
mmc_set_chip_select(host, MMC_CS_HIGH);
3578
memset(&cmd, 0, sizeof(struct mmc_command));
3580
cmd.opcode = MMC_GO_IDLE_STATE;
3582
- cmd.flags = MMC_RSP_NONE | MMC_CMD_BC;
3583
+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_NONE | MMC_CMD_BC;
3585
err = mmc_wait_for_cmd(host, &cmd, 0);
3589
+ if (!mmc_host_is_spi(host)) {
3590
mmc_set_chip_select(host, MMC_CS_DONTCARE);
3595
+ host->use_spi_crc = 0;
3599
@@ -94,23 +107,33 @@ int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
3600
memset(&cmd, 0, sizeof(struct mmc_command));
3602
cmd.opcode = MMC_SEND_OP_COND;
3604
- cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR;
3605
+ cmd.arg = mmc_host_is_spi(host) ? 0 : ocr;
3606
+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR;
3608
for (i = 100; i; i--) {
3609
err = mmc_wait_for_cmd(host, &cmd, 0);
3610
- if (err != MMC_ERR_NONE)
3614
- if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
3615
+ /* if we're just probing, do a single pass */
3619
- err = MMC_ERR_TIMEOUT;
3620
+ /* otherwise wait until reset completes */
3621
+ if (mmc_host_is_spi(host)) {
3622
+ if (!(cmd.resp[0] & R1_SPI_IDLE))
3625
+ if (cmd.resp[0] & MMC_CARD_BUSY)
3635
+ if (rocr && !mmc_host_is_spi(host))
3636
*rocr = cmd.resp[0];
3639
@@ -131,12 +154,12 @@ int mmc_all_send_cid(struct mmc_host *host, u32 *cid)
3640
cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR;
3642
err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
3643
- if (err != MMC_ERR_NONE)
3647
memcpy(cid, cmd.resp, sizeof(u32) * 4);
3649
- return MMC_ERR_NONE;
3653
int mmc_set_relative_addr(struct mmc_card *card)
3654
@@ -154,46 +177,52 @@ int mmc_set_relative_addr(struct mmc_card *card)
3655
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
3657
err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
3658
- if (err != MMC_ERR_NONE)
3662
- return MMC_ERR_NONE;
3666
-int mmc_send_csd(struct mmc_card *card, u32 *csd)
3668
+mmc_send_cxd_native(struct mmc_host *host, u32 arg, u32 *cxd, int opcode)
3671
struct mmc_command cmd;
3674
- BUG_ON(!card->host);
3679
memset(&cmd, 0, sizeof(struct mmc_command));
3681
- cmd.opcode = MMC_SEND_CSD;
3682
- cmd.arg = card->rca << 16;
3683
+ cmd.opcode = opcode;
3685
cmd.flags = MMC_RSP_R2 | MMC_CMD_AC;
3687
- err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
3688
- if (err != MMC_ERR_NONE)
3689
+ err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
3693
- memcpy(csd, cmd.resp, sizeof(u32) * 4);
3694
+ memcpy(cxd, cmd.resp, sizeof(u32) * 4);
3696
- return MMC_ERR_NONE;
3700
-int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
3702
+mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
3703
+ u32 opcode, void *buf, unsigned len)
3705
struct mmc_request mrq;
3706
struct mmc_command cmd;
3707
struct mmc_data data;
3708
struct scatterlist sg;
3712
- BUG_ON(!card->host);
3714
+ /* dma onto stack is unsafe/nonportable, but callers to this
3715
+ * routine normally provide temporary on-stack buffers ...
3717
+ data_buf = kmalloc(len, GFP_KERNEL);
3718
+ if (data_buf == NULL)
3721
memset(&mrq, 0, sizeof(struct mmc_request));
3722
memset(&cmd, 0, sizeof(struct mmc_command));
3723
@@ -202,28 +231,117 @@ int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
3727
- cmd.opcode = MMC_SEND_EXT_CSD;
3728
+ cmd.opcode = opcode;
3730
- cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
3733
+ /* NOTE HACK: the MMC_RSP_SPI_R1 is always correct here, but we
3734
+ * rely on callers to never use this with "native" calls for reading
3735
+ * CSD or CID. Native versions of those commands use the R2 type,
3736
+ * not R1 plus a data block.
3738
+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
3742
data.flags = MMC_DATA_READ;
3746
- sg_init_one(&sg, ext_csd, 512);
3747
+ sg_init_one(&sg, data_buf, len);
3750
+ mmc_set_data_timeout(&data, card);
3752
- mmc_set_data_timeout(&data, card, 0);
3753
+ mmc_wait_for_req(host, &mrq);
3755
- mmc_wait_for_req(card->host, &mrq);
3756
+ memcpy(buf, data_buf, len);
3759
- if (cmd.error != MMC_ERR_NONE)
3762
- if (data.error != MMC_ERR_NONE)
3766
- return MMC_ERR_NONE;
3770
+int mmc_send_csd(struct mmc_card *card, u32 *csd)
3774
+ if (!mmc_host_is_spi(card->host))
3775
+ return mmc_send_cxd_native(card->host, card->rca << 16,
3776
+ csd, MMC_SEND_CSD);
3778
+ ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16);
3782
+ for (i = 0;i < 4;i++)
3783
+ csd[i] = be32_to_cpu(csd[i]);
3788
+int mmc_send_cid(struct mmc_host *host, u32 *cid)
3792
+ if (!mmc_host_is_spi(host)) {
3795
+ return mmc_send_cxd_native(host, host->card->rca << 16,
3796
+ cid, MMC_SEND_CID);
3799
+ ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16);
3803
+ for (i = 0;i < 4;i++)
3804
+ cid[i] = be32_to_cpu(cid[i]);
3809
+int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
3811
+ return mmc_send_cxd_data(card, card->host, MMC_SEND_EXT_CSD,
3815
+int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp)
3817
+ struct mmc_command cmd;
3820
+ memset(&cmd, 0, sizeof(struct mmc_command));
3822
+ cmd.opcode = MMC_SPI_READ_OCR;
3823
+ cmd.arg = highcap ? (1 << 30) : 0;
3824
+ cmd.flags = MMC_RSP_SPI_R3;
3826
+ err = mmc_wait_for_cmd(host, &cmd, 0);
3828
+ *ocrp = cmd.resp[1];
3832
+int mmc_spi_set_crc(struct mmc_host *host, int use_crc)
3834
+ struct mmc_command cmd;
3837
+ memset(&cmd, 0, sizeof(struct mmc_command));
3839
+ cmd.opcode = MMC_SPI_CRC_ON_OFF;
3840
+ cmd.flags = MMC_RSP_SPI_R1;
3841
+ cmd.arg = use_crc;
3843
+ err = mmc_wait_for_cmd(host, &cmd, 0);
3845
+ host->use_spi_crc = use_crc;
3849
int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value)
3850
@@ -241,13 +359,13 @@ int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value)
3854
- cmd.flags = MMC_RSP_R1B | MMC_CMD_AC;
3855
+ cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
3857
err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
3858
- if (err != MMC_ERR_NONE)
3862
- return MMC_ERR_NONE;
3866
int mmc_send_status(struct mmc_card *card, u32 *status)
3867
@@ -261,16 +379,20 @@ int mmc_send_status(struct mmc_card *card, u32 *status)
3868
memset(&cmd, 0, sizeof(struct mmc_command));
3870
cmd.opcode = MMC_SEND_STATUS;
3871
+ if (!mmc_host_is_spi(card->host))
3872
cmd.arg = card->rca << 16;
3873
- cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
3874
+ cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
3876
err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
3877
- if (err != MMC_ERR_NONE)
3881
+ /* NOTE: callers are required to understand the difference
3882
+ * between "native" and SPI format status words!
3885
*status = cmd.resp[0];
3887
- return MMC_ERR_NONE;
3891
diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h
3892
index 7a481e8..17854bf 100644
3893
--- a/drivers/mmc/core/mmc_ops.h
3894
+++ b/drivers/mmc/core/mmc_ops.h
3897
- * linux/drivers/mmc/mmc_ops.h
3898
+ * linux/drivers/mmc/core/mmc_ops.h
3900
* Copyright 2006-2007 Pierre Ossman
3902
@@ -22,6 +22,9 @@ int mmc_send_csd(struct mmc_card *card, u32 *csd);
3903
int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd);
3904
int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value);
3905
int mmc_send_status(struct mmc_card *card, u32 *status);
3906
+int mmc_send_cid(struct mmc_host *host, u32 *cid);
3907
+int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp);
3908
+int mmc_spi_set_crc(struct mmc_host *host, int use_crc);
3912
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
3913
index 918477c..def941d 100644
3914
--- a/drivers/mmc/core/sd.c
3915
+++ b/drivers/mmc/core/sd.c
3918
- * linux/drivers/mmc/sd.c
3919
+ * linux/drivers/mmc/core/sd.c
3921
* Copyright (C) 2003-2004 Russell King, All Rights Reserved.
3922
* SD support Copyright (C) 2004 Ian Molton, All Rights Reserved.
3928
#include "mmc_ops.h"
3933
static const unsigned int tran_exp[] = {
3934
10000, 100000, 1000000, 10000000,
3936
@@ -150,7 +149,7 @@ static int mmc_decode_csd(struct mmc_card *card)
3937
csd->write_partial = 0;
3940
- printk("%s: unrecognised CSD structure version %d\n",
3941
+ printk(KERN_ERR "%s: unrecognised CSD structure version %d\n",
3942
mmc_hostname(card->host), csd_struct);
3945
@@ -167,14 +166,12 @@ static int mmc_decode_scr(struct mmc_card *card)
3946
unsigned int scr_struct;
3949
- BUG_ON(!mmc_card_sd(card));
3951
resp[3] = card->raw_scr[1];
3952
resp[2] = card->raw_scr[0];
3954
scr_struct = UNSTUFF_BITS(resp, 60, 4);
3955
if (scr_struct != 0) {
3956
- printk("%s: unrecognised SCR structure version %d\n",
3957
+ printk(KERN_ERR "%s: unrecognised SCR structure version %d\n",
3958
mmc_hostname(card->host), scr_struct);
3961
@@ -194,31 +191,38 @@ static int mmc_read_switch(struct mmc_card *card)
3964
if (card->scr.sda_vsn < SCR_SPEC_VER_1)
3965
- return MMC_ERR_NONE;
3968
if (!(card->csd.cmdclass & CCC_SWITCH)) {
3969
printk(KERN_WARNING "%s: card lacks mandatory switch "
3970
"function, performance might suffer.\n",
3971
mmc_hostname(card->host));
3972
- return MMC_ERR_NONE;
3976
- err = MMC_ERR_FAILED;
3979
status = kmalloc(64, GFP_KERNEL);
3981
- printk("%s: could not allocate a buffer for switch "
3982
- "capabilities.\n",
3983
- mmc_hostname(card->host));
3985
+ printk(KERN_ERR "%s: could not allocate a buffer for "
3986
+ "switch capabilities.\n", mmc_hostname(card->host));
3990
err = mmc_sd_switch(card, 0, 0, 1, status);
3991
- if (err != MMC_ERR_NONE) {
3994
+ * We all hosts that cannot perform the command
3995
+ * to fail more gracefully
3997
+ if (err != -EINVAL)
4000
printk(KERN_WARNING "%s: problem reading switch "
4001
"capabilities, performance might suffer.\n",
4002
mmc_hostname(card->host));
4003
- err = MMC_ERR_NONE;
4009
@@ -240,29 +244,28 @@ static int mmc_switch_hs(struct mmc_card *card)
4012
if (card->scr.sda_vsn < SCR_SPEC_VER_1)
4013
- return MMC_ERR_NONE;
4016
if (!(card->csd.cmdclass & CCC_SWITCH))
4017
- return MMC_ERR_NONE;
4020
if (!(card->host->caps & MMC_CAP_SD_HIGHSPEED))
4021
- return MMC_ERR_NONE;
4024
if (card->sw_caps.hs_max_dtr == 0)
4025
- return MMC_ERR_NONE;
4028
- err = MMC_ERR_FAILED;
4031
status = kmalloc(64, GFP_KERNEL);
4033
- printk("%s: could not allocate a buffer for switch "
4034
- "capabilities.\n",
4035
- mmc_hostname(card->host));
4037
+ printk(KERN_ERR "%s: could not allocate a buffer for "
4038
+ "switch capabilities.\n", mmc_hostname(card->host));
4042
err = mmc_sd_switch(card, 1, 0, 1, status);
4043
- if (err != MMC_ERR_NONE)
4047
if ((status[16] & 0xF) != 1) {
4048
@@ -295,7 +298,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
4049
unsigned int max_dtr;
4052
- BUG_ON(!host->claimed);
4053
+ WARN_ON(!host->claimed);
4056
* Since we're changing the OCR value, we seem to
4057
@@ -312,23 +315,37 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
4058
* block-addressed SDHC cards.
4060
err = mmc_send_if_cond(host, ocr);
4061
- if (err == MMC_ERR_NONE)
4065
err = mmc_send_app_op_cond(host, ocr, NULL);
4066
- if (err != MMC_ERR_NONE)
4071
+ * For SPI, enable CRC as appropriate.
4073
+ if (mmc_host_is_spi(host)) {
4074
+ err = mmc_spi_set_crc(host, use_spi_crc);
4080
* Fetch CID from card.
4082
+ if (mmc_host_is_spi(host))
4083
+ err = mmc_send_cid(host, cid);
4085
err = mmc_all_send_cid(host, cid);
4086
- if (err != MMC_ERR_NONE)
4091
- if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0)
4092
+ if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) {
4099
@@ -336,32 +353,36 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
4100
* Allocate card structure.
4102
card = mmc_alloc_card(host);
4104
+ if (IS_ERR(card)) {
4105
+ err = PTR_ERR(card);
4109
card->type = MMC_TYPE_SD;
4110
memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
4115
+ * For native busses: get card RCA and quit open drain mode.
4117
+ if (!mmc_host_is_spi(host)) {
4118
err = mmc_send_relative_addr(host, &card->rca);
4119
- if (err != MMC_ERR_NONE)
4123
mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
4128
* Fetch CSD from card.
4130
err = mmc_send_csd(card, card->raw_csd);
4131
- if (err != MMC_ERR_NONE)
4135
err = mmc_decode_csd(card);
4140
mmc_decode_cid(card);
4141
@@ -370,16 +391,18 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
4143
* Select card, as all following commands rely on that.
4145
+ if (!mmc_host_is_spi(host)) {
4146
err = mmc_select_card(card);
4147
- if (err != MMC_ERR_NONE)
4154
* Fetch SCR from card.
4156
err = mmc_app_send_scr(card, card->raw_scr);
4157
- if (err != MMC_ERR_NONE)
4161
err = mmc_decode_scr(card);
4162
@@ -390,7 +413,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
4163
* Fetch switch information from card.
4165
err = mmc_read_switch(card);
4166
- if (err != MMC_ERR_NONE)
4171
@@ -398,7 +421,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
4172
* Attempt to change to high-speed (if supported)
4174
err = mmc_switch_hs(card);
4175
- if (err != MMC_ERR_NONE)
4180
@@ -421,7 +444,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
4181
if ((host->caps & MMC_CAP_4_BIT_DATA) &&
4182
(card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
4183
err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4);
4184
- if (err != MMC_ERR_NONE)
4188
mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
4189
@@ -445,14 +468,14 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
4193
- return MMC_ERR_NONE;
4198
mmc_remove_card(card);
4201
- return MMC_ERR_FAILED;
4206
@@ -486,9 +509,8 @@ static void mmc_sd_detect(struct mmc_host *host)
4208
mmc_release_host(host);
4210
- if (err != MMC_ERR_NONE) {
4211
- mmc_remove_card(host->card);
4212
- host->card = NULL;
4214
+ mmc_sd_remove(host);
4216
mmc_claim_host(host);
4217
mmc_detach_bus(host);
4218
@@ -496,6 +518,55 @@ static void mmc_sd_detect(struct mmc_host *host)
4222
+MMC_ATTR_FN(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
4223
+ card->raw_cid[2], card->raw_cid[3]);
4224
+MMC_ATTR_FN(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
4225
+ card->raw_csd[2], card->raw_csd[3]);
4226
+MMC_ATTR_FN(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]);
4227
+MMC_ATTR_FN(date, "%02d/%04d\n", card->cid.month, card->cid.year);
4228
+MMC_ATTR_FN(fwrev, "0x%x\n", card->cid.fwrev);
4229
+MMC_ATTR_FN(hwrev, "0x%x\n", card->cid.hwrev);
4230
+MMC_ATTR_FN(manfid, "0x%06x\n", card->cid.manfid);
4231
+MMC_ATTR_FN(name, "%s\n", card->cid.prod_name);
4232
+MMC_ATTR_FN(oemid, "0x%04x\n", card->cid.oemid);
4233
+MMC_ATTR_FN(serial, "0x%08x\n", card->cid.serial);
4235
+static struct device_attribute mmc_sd_dev_attrs[] = {
4239
+ MMC_ATTR_RO(date),
4240
+ MMC_ATTR_RO(fwrev),
4241
+ MMC_ATTR_RO(hwrev),
4242
+ MMC_ATTR_RO(manfid),
4243
+ MMC_ATTR_RO(name),
4244
+ MMC_ATTR_RO(oemid),
4245
+ MMC_ATTR_RO(serial),
4250
+ * Adds sysfs entries as relevant.
4252
+static int mmc_sd_sysfs_add(struct mmc_host *host, struct mmc_card *card)
4256
+ ret = mmc_add_attrs(card, mmc_sd_dev_attrs);
4264
+ * Removes the sysfs entries added by mmc_sysfs_add().
4266
+static void mmc_sd_sysfs_remove(struct mmc_host *host, struct mmc_card *card)
4268
+ mmc_remove_attrs(card, mmc_sd_dev_attrs);
4271
#ifdef CONFIG_MMC_UNSAFE_RESUME
4274
@@ -507,6 +578,7 @@ static void mmc_sd_suspend(struct mmc_host *host)
4275
BUG_ON(!host->card);
4277
mmc_claim_host(host);
4278
+ if (!mmc_host_is_spi(host))
4279
mmc_deselect_cards(host);
4280
host->card->state &= ~MMC_STATE_HIGHSPEED;
4281
mmc_release_host(host);
4282
@@ -526,16 +598,17 @@ static void mmc_sd_resume(struct mmc_host *host)
4283
BUG_ON(!host->card);
4285
mmc_claim_host(host);
4287
err = mmc_sd_init_card(host, host->ocr, host->card);
4288
- if (err != MMC_ERR_NONE) {
4289
- mmc_remove_card(host->card);
4290
- host->card = NULL;
4291
+ mmc_release_host(host);
4294
+ mmc_sd_remove(host);
4296
+ mmc_claim_host(host);
4297
mmc_detach_bus(host);
4298
+ mmc_release_host(host);
4301
- mmc_release_host(host);
4305
@@ -548,6 +621,8 @@ static void mmc_sd_resume(struct mmc_host *host)
4306
static const struct mmc_bus_ops mmc_sd_ops = {
4307
.remove = mmc_sd_remove,
4308
.detect = mmc_sd_detect,
4309
+ .sysfs_add = mmc_sd_sysfs_add,
4310
+ .sysfs_remove = mmc_sd_sysfs_remove,
4311
.suspend = mmc_sd_suspend,
4312
.resume = mmc_sd_resume,
4314
@@ -560,11 +635,22 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)
4318
- BUG_ON(!host->claimed);
4319
+ WARN_ON(!host->claimed);
4321
mmc_attach_bus(host, &mmc_sd_ops);
4324
+ * We need to get OCR a different way for SPI.
4326
+ if (mmc_host_is_spi(host)) {
4327
+ mmc_go_idle(host);
4329
+ err = mmc_spi_read_ocr(host, 0, &ocr);
4335
* Sanity check the voltages that the card claims to
4338
@@ -587,32 +673,37 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)
4340
* Can we support the voltage(s) of the card(s)?
4349
* Detect and init the card.
4351
err = mmc_sd_init_card(host, host->ocr, NULL);
4352
- if (err != MMC_ERR_NONE)
4356
mmc_release_host(host);
4358
- err = mmc_register_card(host->card);
4359
+ err = mmc_add_card(host->card);
4361
- goto reclaim_host;
4367
- mmc_claim_host(host);
4369
mmc_remove_card(host->card);
4371
+ mmc_claim_host(host);
4373
mmc_detach_bus(host);
4374
mmc_release_host(host);
4377
+ printk(KERN_ERR "%s: error %d whilst initialising SD card\n",
4378
+ mmc_hostname(host), err);
4383
diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
4384
index 9697ce5..dc99361 100644
4385
--- a/drivers/mmc/core/sd_ops.c
4386
+++ b/drivers/mmc/core/sd_ops.c
4389
- * linux/drivers/mmc/sd_ops.h
4390
+ * linux/drivers/mmc/core/sd_ops.h
4392
* Copyright 2006-2007 Pierre Ossman
4398
+static int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
4401
+ struct mmc_command cmd;
4404
+ BUG_ON(card && (card->host != host));
4406
+ cmd.opcode = MMC_APP_CMD;
4409
+ cmd.arg = card->rca << 16;
4410
+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
4413
+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_BCR;
4416
+ err = mmc_wait_for_cmd(host, &cmd, 0);
4420
+ /* Check that card supported application commands */
4421
+ if (!mmc_host_is_spi(host) && !(cmd.resp[0] & R1_APP_CMD))
4422
+ return -EOPNOTSUPP;
4428
* mmc_wait_for_app_cmd - start an application command and wait for
4430
* @host: MMC host to start command
4431
- * @rca: RCA to send MMC_APP_CMD to
4432
+ * @card: Card to send MMC_APP_CMD to
4433
* @cmd: MMC command to start
4434
* @retries: maximum number of retries
4436
@@ -44,7 +73,7 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
4438
BUG_ON(retries < 0);
4440
- err = MMC_ERR_INVALID;
4444
* We have to resend MMC_APP_CMD for each attempt so
4445
@@ -54,8 +83,14 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
4446
memset(&mrq, 0, sizeof(struct mmc_request));
4448
err = mmc_app_cmd(host, card);
4449
- if (err != MMC_ERR_NONE)
4451
+ /* no point in retrying; no APP commands allowed */
4452
+ if (mmc_host_is_spi(host)) {
4453
+ if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
4459
memset(&mrq, 0, sizeof(struct mmc_request));
4461
@@ -68,8 +103,14 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
4462
mmc_wait_for_req(host, &mrq);
4465
- if (cmd->error == MMC_ERR_NONE)
4469
+ /* no point in retrying illegal APP commands */
4470
+ if (mmc_host_is_spi(host)) {
4471
+ if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
4477
@@ -77,35 +118,6 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
4479
EXPORT_SYMBOL(mmc_wait_for_app_cmd);
4481
-int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
4484
- struct mmc_command cmd;
4487
- BUG_ON(card && (card->host != host));
4489
- cmd.opcode = MMC_APP_CMD;
4492
- cmd.arg = card->rca << 16;
4493
- cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
4496
- cmd.flags = MMC_RSP_R1 | MMC_CMD_BCR;
4499
- err = mmc_wait_for_cmd(host, &cmd, 0);
4500
- if (err != MMC_ERR_NONE)
4503
- /* Check that card supported application commands */
4504
- if (!(cmd.resp[0] & R1_APP_CMD))
4505
- return MMC_ERR_FAILED;
4507
- return MMC_ERR_NONE;
4510
int mmc_app_set_bus_width(struct mmc_card *card, int width)
4513
@@ -127,14 +139,14 @@ int mmc_app_set_bus_width(struct mmc_card *card, int width)
4514
cmd.arg = SD_BUS_WIDTH_4;
4517
- return MMC_ERR_INVALID;
4521
err = mmc_wait_for_app_cmd(card->host, card, &cmd, MMC_CMD_RETRIES);
4522
- if (err != MMC_ERR_NONE)
4526
- return MMC_ERR_NONE;
4530
int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
4531
@@ -147,23 +159,36 @@ int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
4532
memset(&cmd, 0, sizeof(struct mmc_command));
4534
cmd.opcode = SD_APP_OP_COND;
4535
+ if (mmc_host_is_spi(host))
4536
+ cmd.arg = ocr & (1 << 30); /* SPI only defines one bit */
4539
- cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR;
4540
+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR;
4542
for (i = 100; i; i--) {
4543
err = mmc_wait_for_app_cmd(host, NULL, &cmd, MMC_CMD_RETRIES);
4544
- if (err != MMC_ERR_NONE)
4548
- if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
4549
+ /* if we're just probing, do a single pass */
4553
- err = MMC_ERR_TIMEOUT;
4554
+ /* otherwise wait until reset completes */
4555
+ if (mmc_host_is_spi(host)) {
4556
+ if (!(cmd.resp[0] & R1_SPI_IDLE))
4559
+ if (cmd.resp[0] & MMC_CARD_BUSY)
4569
+ if (rocr && !mmc_host_is_spi(host))
4570
*rocr = cmd.resp[0];
4573
@@ -174,6 +199,7 @@ int mmc_send_if_cond(struct mmc_host *host, u32 ocr)
4574
struct mmc_command cmd;
4576
static const u8 test_pattern = 0xAA;
4577
+ u8 result_pattern;
4580
* To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND
4581
@@ -182,16 +208,21 @@ int mmc_send_if_cond(struct mmc_host *host, u32 ocr)
4583
cmd.opcode = SD_SEND_IF_COND;
4584
cmd.arg = ((ocr & 0xFF8000) != 0) << 8 | test_pattern;
4585
- cmd.flags = MMC_RSP_R7 | MMC_CMD_BCR;
4586
+ cmd.flags = MMC_RSP_SPI_R7 | MMC_RSP_R7 | MMC_CMD_BCR;
4588
err = mmc_wait_for_cmd(host, &cmd, 0);
4589
- if (err != MMC_ERR_NONE)
4593
- if ((cmd.resp[0] & 0xFF) != test_pattern)
4594
- return MMC_ERR_FAILED;
4595
+ if (mmc_host_is_spi(host))
4596
+ result_pattern = cmd.resp[1] & 0xFF;
4598
+ result_pattern = cmd.resp[0] & 0xFF;
4600
- return MMC_ERR_NONE;
4601
+ if (result_pattern != test_pattern)
4607
int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca)
4608
@@ -209,12 +240,12 @@ int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca)
4609
cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR;
4611
err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
4612
- if (err != MMC_ERR_NONE)
4616
*rca = cmd.resp[0] >> 16;
4618
- return MMC_ERR_NONE;
4622
int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
4623
@@ -229,8 +260,10 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
4624
BUG_ON(!card->host);
4627
+ /* NOTE: caller guarantees scr is heap-allocated */
4629
err = mmc_app_cmd(card->host, card);
4630
- if (err != MMC_ERR_NONE)
4634
memset(&mrq, 0, sizeof(struct mmc_request));
4635
@@ -242,7 +275,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
4637
cmd.opcode = SD_APP_SEND_SCR;
4639
- cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
4640
+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
4644
@@ -252,19 +285,19 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
4646
sg_init_one(&sg, scr, 8);
4648
- mmc_set_data_timeout(&data, card, 0);
4649
+ mmc_set_data_timeout(&data, card);
4651
mmc_wait_for_req(card->host, &mrq);
4653
- if (cmd.error != MMC_ERR_NONE)
4656
- if (data.error != MMC_ERR_NONE)
4660
- scr[0] = ntohl(scr[0]);
4661
- scr[1] = ntohl(scr[1]);
4662
+ scr[0] = be32_to_cpu(scr[0]);
4663
+ scr[1] = be32_to_cpu(scr[1]);
4665
- return MMC_ERR_NONE;
4669
int mmc_sd_switch(struct mmc_card *card, int mode, int group,
4670
@@ -278,6 +311,8 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
4672
BUG_ON(!card->host);
4674
+ /* NOTE: caller guarantees resp is heap-allocated */
4679
@@ -292,7 +327,7 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
4680
cmd.arg = mode << 31 | 0x00FFFFFF;
4681
cmd.arg &= ~(0xF << (group * 4));
4682
cmd.arg |= value << (group * 4);
4683
- cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
4684
+ cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
4688
@@ -302,15 +337,15 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
4690
sg_init_one(&sg, resp, 64);
4692
- mmc_set_data_timeout(&data, card, 0);
4693
+ mmc_set_data_timeout(&data, card);
4695
mmc_wait_for_req(card->host, &mrq);
4697
- if (cmd.error != MMC_ERR_NONE)
4700
- if (data.error != MMC_ERR_NONE)
4704
- return MMC_ERR_NONE;
4708
diff --git a/drivers/mmc/core/sd_ops.h b/drivers/mmc/core/sd_ops.h
4709
index 1240fdd..9742d8a 100644
4710
--- a/drivers/mmc/core/sd_ops.h
4711
+++ b/drivers/mmc/core/sd_ops.h
4714
- * linux/drivers/mmc/sd_ops.h
4715
+ * linux/drivers/mmc/core/sd_ops.h
4717
* Copyright 2006-2007 Pierre Ossman
4720
#ifndef _MMC_SD_OPS_H
4721
#define _MMC_SD_OPS_H
4723
-int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card);
4724
int mmc_app_set_bus_width(struct mmc_card *card, int width);
4725
int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr);
4726
int mmc_send_if_cond(struct mmc_host *host, u32 ocr);
4727
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
4728
new file mode 100644
4729
index 0000000..93d4ecf
4731
+++ b/drivers/mmc/core/sdio.c
4734
+ * linux/drivers/mmc/sdio.c
4736
+ * Copyright 2006-2007 Pierre Ossman
4738
+ * This program is free software; you can redistribute it and/or modify
4739
+ * it under the terms of the GNU General Public License as published by
4740
+ * the Free Software Foundation; either version 2 of the License, or (at
4741
+ * your option) any later version.
4744
+#include <linux/err.h>
4746
+#include <linux/mmc/host.h>
4747
+#include <linux/mmc/card.h>
4748
+#include <linux/mmc/sdio.h>
4749
+#include <linux/mmc/sdio_func.h>
4753
+#include "sdio_bus.h"
4754
+#include "mmc_ops.h"
4755
+#include "sd_ops.h"
4756
+#include "sdio_ops.h"
4757
+#include "sdio_cis.h"
4759
+static int sdio_read_fbr(struct sdio_func *func)
4762
+ unsigned char data;
4764
+ ret = mmc_io_rw_direct(func->card, 0, 0,
4765
+ SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF, 0, &data);
4771
+ if (data == 0x0f) {
4772
+ ret = mmc_io_rw_direct(func->card, 0, 0,
4773
+ SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF_EXT, 0, &data);
4778
+ func->class = data;
4784
+static int sdio_init_func(struct mmc_card *card, unsigned int fn)
4787
+ struct sdio_func *func;
4789
+ BUG_ON(fn > SDIO_MAX_FUNCS);
4791
+ func = sdio_alloc_func(card);
4793
+ return PTR_ERR(func);
4797
+ ret = sdio_read_fbr(func);
4801
+ ret = sdio_read_func_cis(func);
4805
+ card->sdio_func[fn - 1] = func;
4811
+ * It is okay to remove the function here even though we hold
4812
+ * the host lock as we haven't registered the device yet.
4814
+ sdio_remove_func(func);
4818
+static int sdio_read_cccr(struct mmc_card *card)
4822
+ unsigned char data;
4824
+ memset(&card->cccr, 0, sizeof(struct sdio_cccr));
4826
+ ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CCCR, 0, &data);
4830
+ cccr_vsn = data & 0x0f;
4832
+ if (cccr_vsn > SDIO_CCCR_REV_1_20) {
4833
+ printk(KERN_ERR "%s: unrecognised CCCR structure version %d\n",
4834
+ mmc_hostname(card->host), cccr_vsn);
4838
+ card->cccr.sdio_vsn = (data & 0xf0) >> 4;
4840
+ ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CAPS, 0, &data);
4844
+ if (data & SDIO_CCCR_CAP_SMB)
4845
+ card->cccr.multi_block = 1;
4846
+ if (data & SDIO_CCCR_CAP_LSC)
4847
+ card->cccr.low_speed = 1;
4848
+ if (data & SDIO_CCCR_CAP_4BLS)
4849
+ card->cccr.wide_bus = 1;
4851
+ if (cccr_vsn >= SDIO_CCCR_REV_1_10) {
4852
+ ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_POWER, 0, &data);
4856
+ if (data & SDIO_POWER_SMPC)
4857
+ card->cccr.high_power = 1;
4860
+ if (cccr_vsn >= SDIO_CCCR_REV_1_20) {
4861
+ ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &data);
4865
+ if (data & SDIO_SPEED_SHS)
4866
+ card->cccr.high_speed = 1;
4873
+static int sdio_enable_wide(struct mmc_card *card)
4878
+ if (!(card->host->caps & MMC_CAP_4_BIT_DATA))
4881
+ if (card->cccr.low_speed && !card->cccr.wide_bus)
4884
+ ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &ctrl);
4888
+ ctrl |= SDIO_BUS_WIDTH_4BIT;
4890
+ ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL);
4894
+ mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
4900
+ * Host is being removed. Free up the current card.
4902
+static void mmc_sdio_remove(struct mmc_host *host)
4907
+ BUG_ON(!host->card);
4909
+ for (i = 0;i < host->card->sdio_funcs;i++) {
4910
+ if (host->card->sdio_func[i]) {
4911
+ sdio_remove_func(host->card->sdio_func[i]);
4912
+ host->card->sdio_func[i] = NULL;
4916
+ mmc_remove_card(host->card);
4917
+ host->card = NULL;
4921
+ * Card detection callback from host.
4923
+static void mmc_sdio_detect(struct mmc_host *host)
4928
+ BUG_ON(!host->card);
4930
+ mmc_claim_host(host);
4933
+ * Just check if our card has been removed.
4935
+ err = mmc_select_card(host->card);
4937
+ mmc_release_host(host);
4940
+ mmc_sdio_remove(host);
4942
+ mmc_claim_host(host);
4943
+ mmc_detach_bus(host);
4944
+ mmc_release_host(host);
4949
+static const struct mmc_bus_ops mmc_sdio_ops = {
4950
+ .remove = mmc_sdio_remove,
4951
+ .detect = mmc_sdio_detect,
4956
+ * Starting point for SDIO card init.
4958
+int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
4962
+ struct mmc_card *card;
4965
+ WARN_ON(!host->claimed);
4967
+ mmc_attach_bus(host, &mmc_sdio_ops);
4970
+ * Sanity check the voltages that the card claims to
4974
+ printk(KERN_WARNING "%s: card claims to support voltages "
4975
+ "below the defined range. These will be ignored.\n",
4976
+ mmc_hostname(host));
4980
+ if (ocr & MMC_VDD_165_195) {
4981
+ printk(KERN_WARNING "%s: SDIO card claims to support the "
4982
+ "incompletely defined 'low voltage range'. This "
4983
+ "will be ignored.\n", mmc_hostname(host));
4984
+ ocr &= ~MMC_VDD_165_195;
4987
+ /* force CB/Zi9 controller to work in 3.3V mode, due to HW bug */
4990
+ host->ocr = mmc_select_voltage(host, ocr);
4993
+ * Can we support the voltage(s) of the card(s)?
5000
+ umd_dbg("we will use voltage ocr: 0x%08x", host->ocr);
5002
+ * Inform the card of the voltage
5004
+ err = mmc_send_io_op_cond(host, host->ocr, &ocr);
5009
+ * For SPI, enable CRC as appropriate.
5011
+ if (mmc_host_is_spi(host)) {
5012
+ err = mmc_spi_set_crc(host, use_spi_crc);
5018
+ * The number of functions on the card is encoded inside
5021
+ funcs = (ocr & 0x70000000) >> 28;
5024
+ * Allocate card structure.
5026
+ card = mmc_alloc_card(host);
5027
+ if (IS_ERR(card)) {
5028
+ err = PTR_ERR(card);
5032
+ card->type = MMC_TYPE_SDIO;
5033
+ card->sdio_funcs = funcs;
5035
+ host->card = card;
5038
+ * For native busses: set card RCA and quit open drain mode.
5040
+ if (!mmc_host_is_spi(host)) {
5041
+ err = mmc_send_relative_addr(host, &card->rca);
5045
+ mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
5049
+ * Select card, as all following commands rely on that.
5051
+ if (!mmc_host_is_spi(host)) {
5052
+ err = mmc_select_card(card);
5058
+ * Read the common registers.
5060
+ err = sdio_read_cccr(card);
5065
+ * Read the common CIS tuples.
5067
+ err = sdio_read_common_cis(card);
5072
+ * No support for high-speed yet, so just set
5073
+ * the card's maximum speed.
5075
+ mmc_set_clock(host, card->cis.max_dtr);
5078
+ * Switch to wider bus (if supported).
5080
+ err = sdio_enable_wide(card);
5085
+ * Initialize (but don't add) all present functions.
5087
+ for (i = 0;i < funcs;i++) {
5088
+ err = sdio_init_func(host->card, i + 1);
5093
+ mmc_release_host(host);
5096
+ * First add the card to the driver model...
5098
+ err = mmc_add_card(host->card);
5100
+ goto remove_added;
5102
+ umd_dbg("success in add card");
5105
+ * ...then the SDIO functions.
5107
+ for (i = 0;i < funcs;i++) {
5108
+ err = sdio_add_func(host->card->sdio_func[i]);
5110
+ goto remove_added;
5113
+ umd_dbg("success in add %d functions", funcs);
5119
+ /* Remove without lock if the device has been added. */
5120
+ mmc_sdio_remove(host);
5121
+ mmc_claim_host(host);
5123
+ /* And with lock if it hasn't been added. */
5125
+ mmc_sdio_remove(host);
5127
+ mmc_detach_bus(host);
5128
+ mmc_release_host(host);
5130
+ printk(KERN_ERR "%s: error %d whilst initialising SDIO card\n",
5131
+ mmc_hostname(host), err);
5135
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
5136
new file mode 100644
5137
index 0000000..abf0e36
5139
+++ b/drivers/mmc/core/sdio_bus.c
5142
+ * linux/drivers/mmc/core/sdio_bus.c
5144
+ * Copyright 2007 Pierre Ossman
5146
+ * This program is free software; you can redistribute it and/or modify
5147
+ * it under the terms of the GNU General Public License as published by
5148
+ * the Free Software Foundation; either version 2 of the License, or (at
5149
+ * your option) any later version.
5151
+ * SDIO function driver model
5154
+#include <linux/device.h>
5155
+#include <linux/err.h>
5157
+#include <linux/mmc/card.h>
5158
+#include <linux/mmc/sdio_func.h>
5160
+#include "sdio_cis.h"
5161
+#include "sdio_bus.h"
5163
+#define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev)
5164
+#define to_sdio_driver(d) container_of(d, struct sdio_driver, drv)
5166
+/* show configuration fields */
5167
+#define sdio_config_attr(field, format_string) \
5169
+field##_show(struct device *dev, struct device_attribute *attr, char *buf) \
5171
+ struct sdio_func *func; \
5173
+ func = dev_to_sdio_func (dev); \
5174
+ return sprintf (buf, format_string, func->field); \
5177
+sdio_config_attr(class, "0x%02x\n");
5178
+sdio_config_attr(vendor, "0x%04x\n");
5179
+sdio_config_attr(device, "0x%04x\n");
5181
+static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
5183
+ struct sdio_func *func = dev_to_sdio_func (dev);
5185
+ return sprintf(buf, "sdio:c%02Xv%04Xd%04X\n",
5186
+ func->class, func->vendor, func->device);
5189
+static struct device_attribute sdio_dev_attrs[] = {
5191
+ __ATTR_RO(vendor),
5192
+ __ATTR_RO(device),
5193
+ __ATTR_RO(modalias),
5197
+static const struct sdio_device_id *sdio_match_one(struct sdio_func *func,
5198
+ const struct sdio_device_id *id)
5200
+ if (id->class != (__u8)SDIO_ANY_ID && id->class != func->class)
5202
+ if (id->vendor != (__u16)SDIO_ANY_ID && id->vendor != func->vendor)
5204
+ if (id->device != (__u16)SDIO_ANY_ID && id->device != func->device)
5209
+static const struct sdio_device_id *sdio_match_device(struct sdio_func *func,
5210
+ struct sdio_driver *sdrv)
5212
+ const struct sdio_device_id *ids;
5214
+ ids = sdrv->id_table;
5217
+ while (ids->class || ids->vendor || ids->device) {
5218
+ if (sdio_match_one(func, ids))
5227
+static int sdio_bus_match(struct device *dev, struct device_driver *drv)
5229
+ struct sdio_func *func = dev_to_sdio_func(dev);
5230
+ struct sdio_driver *sdrv = to_sdio_driver(drv);
5232
+ if (sdio_match_device(func, sdrv))
5239
+sdio_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
5242
+ struct sdio_func *func = dev_to_sdio_func(dev);
5243
+ int i = 0, length = 0;
5245
+ if (add_uevent_var(envp, num_envp, &i,
5246
+ buf, buf_size, &length,
5247
+ "SDIO_CLASS=%02X", func->class))
5250
+ if (add_uevent_var(envp, num_envp, &i,
5251
+ buf, buf_size, &length,
5252
+ "SDIO_ID=%04X:%04X", func->vendor, func->device))
5255
+ if (add_uevent_var(envp, num_envp, &i,
5256
+ buf, buf_size, &length,
5257
+ "MODALIAS=sdio:c%02Xv%04Xd%04X",
5258
+ func->class, func->vendor, func->device))
5266
+static int sdio_bus_probe(struct device *dev)
5268
+ struct sdio_driver *drv = to_sdio_driver(dev->driver);
5269
+ struct sdio_func *func = dev_to_sdio_func(dev);
5270
+ const struct sdio_device_id *id;
5273
+ id = sdio_match_device(func, drv);
5277
+ /* Set the default block size so the driver is sure it's something
5279
+ sdio_claim_host(func);
5280
+ ret = sdio_set_block_size(func, 0);
5281
+ sdio_release_host(func);
5285
+ return drv->probe(func, id);
5288
+static int sdio_bus_remove(struct device *dev)
5290
+ struct sdio_driver *drv = to_sdio_driver(dev->driver);
5291
+ struct sdio_func *func = dev_to_sdio_func(dev);
5293
+ drv->remove(func);
5295
+ if (func->irq_handler) {
5296
+ printk(KERN_WARNING "WARNING: driver %s did not remove "
5297
+ "its interrupt handler!\n", drv->name);
5298
+ sdio_claim_host(func);
5299
+ sdio_release_irq(func);
5300
+ sdio_release_host(func);
5306
+static struct bus_type sdio_bus_type = {
5308
+ .dev_attrs = sdio_dev_attrs,
5309
+ .match = sdio_bus_match,
5310
+ .uevent = sdio_bus_uevent,
5311
+ .probe = sdio_bus_probe,
5312
+ .remove = sdio_bus_remove,
5315
+int sdio_register_bus(void)
5317
+ return bus_register(&sdio_bus_type);
5320
+void sdio_unregister_bus(void)
5322
+ bus_unregister(&sdio_bus_type);
5326
+ * sdio_register_driver - register a function driver
5327
+ * @drv: SDIO function driver
5329
+int sdio_register_driver(struct sdio_driver *drv)
5331
+ drv->drv.name = drv->name;
5332
+ drv->drv.bus = &sdio_bus_type;
5333
+ return driver_register(&drv->drv);
5336
+EXPORT_SYMBOL_GPL(sdio_register_driver);
5339
+ * sdio_unregister_driver - unregister a function driver
5340
+ * @drv: SDIO function driver
5342
+void sdio_unregister_driver(struct sdio_driver *drv)
5344
+ drv->drv.bus = &sdio_bus_type;
5345
+ driver_unregister(&drv->drv);
5348
+EXPORT_SYMBOL_GPL(sdio_unregister_driver);
5350
+static void sdio_release_func(struct device *dev)
5352
+ struct sdio_func *func = dev_to_sdio_func(dev);
5354
+ sdio_free_func_cis(func);
5357
+ kfree(func->info);
5363
+ * Allocate and initialise a new SDIO function structure.
5365
+struct sdio_func *sdio_alloc_func(struct mmc_card *card)
5367
+ struct sdio_func *func;
5369
+ func = kzalloc(sizeof(struct sdio_func), GFP_KERNEL);
5371
+ return ERR_PTR(-ENOMEM);
5373
+ func->card = card;
5375
+ device_initialize(&func->dev);
5377
+ func->dev.parent = &card->dev;
5378
+ func->dev.bus = &sdio_bus_type;
5379
+ func->dev.release = sdio_release_func;
5385
+ * Register a new SDIO function with the driver model.
5387
+int sdio_add_func(struct sdio_func *func)
5391
+ snprintf(func->dev.bus_id, sizeof(func->dev.bus_id),
5392
+ "%s:%d", mmc_card_id(func->card), func->num);
5394
+ ret = device_add(&func->dev);
5396
+ sdio_func_set_present(func);
5402
+ * Unregister a SDIO function with the driver model, and
5403
+ * (eventually) free it.
5405
+void sdio_remove_func(struct sdio_func *func)
5407
+ if (sdio_func_present(func))
5408
+ device_del(&func->dev);
5410
+ put_device(&func->dev);
5412
diff --git a/drivers/mmc/core/sdio_bus.h b/drivers/mmc/core/sdio_bus.h
5413
new file mode 100644
5414
index 0000000..6fb2cbc
5416
+++ b/drivers/mmc/core/sdio_bus.h
5419
+ * linux/drivers/mmc/core/sdio_bus.h
5421
+ * Copyright 2007 Pierre Ossman
5423
+ * This program is free software; you can redistribute it and/or modify
5424
+ * it under the terms of the GNU General Public License as published by
5425
+ * the Free Software Foundation; either version 2 of the License, or (at
5426
+ * your option) any later version.
5428
+#ifndef _MMC_CORE_SDIO_BUS_H
5429
+#define _MMC_CORE_SDIO_BUS_H
5431
+struct sdio_func *sdio_alloc_func(struct mmc_card *card);
5432
+int sdio_add_func(struct sdio_func *func);
5433
+void sdio_remove_func(struct sdio_func *func);
5435
+int sdio_register_bus(void);
5436
+void sdio_unregister_bus(void);
5439
diff --git a/drivers/mmc/core/sdio_cis.c b/drivers/mmc/core/sdio_cis.c
5440
new file mode 100644
5441
index 0000000..88d403a
5443
+++ b/drivers/mmc/core/sdio_cis.c
5446
+ * linux/drivers/mmc/core/sdio_cis.c
5448
+ * Author: Nicolas Pitre
5449
+ * Created: June 11, 2007
5450
+ * Copyright: MontaVista Software Inc.
5452
+ * Copyright 2007 Pierre Ossman
5454
+ * This program is free software; you can redistribute it and/or modify
5455
+ * it under the terms of the GNU General Public License as published by
5456
+ * the Free Software Foundation; either version 2 of the License, or (at
5457
+ * your option) any later version.
5460
+#include <linux/kernel.h>
5462
+#include <linux/mmc/host.h>
5463
+#include <linux/mmc/card.h>
5464
+#include <linux/mmc/sdio.h>
5465
+#include <linux/mmc/sdio_func.h>
5467
+#include "sdio_cis.h"
5468
+#include "sdio_ops.h"
5470
+static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func,
5471
+ const unsigned char *buf, unsigned size)
5473
+ unsigned i, nr_strings;
5474
+ char **buffer, *string;
5480
+ for (i = 0; i < size; i++) {
5481
+ if (buf[i] == 0xff)
5487
+ if (buf[i-1] != '\0') {
5488
+ printk(KERN_WARNING "SDIO: ignoring broken CISTPL_VERS_1\n");
5494
+ buffer = kzalloc(sizeof(char*) * nr_strings + size, GFP_KERNEL);
5498
+ string = (char*)(buffer + nr_strings);
5500
+ for (i = 0; i < nr_strings; i++) {
5501
+ buffer[i] = string;
5502
+ strcpy(string, buf);
5503
+ string += strlen(string) + 1;
5504
+ buf += strlen(buf) + 1;
5508
+ func->num_info = nr_strings;
5509
+ func->info = (const char**)buffer;
5511
+ card->num_info = nr_strings;
5512
+ card->info = (const char**)buffer;
5518
+static int cistpl_manfid(struct mmc_card *card, struct sdio_func *func,
5519
+ const unsigned char *buf, unsigned size)
5521
+ unsigned int vendor, device;
5524
+ vendor = buf[0] | (buf[1] << 8);
5527
+ device = buf[2] | (buf[3] << 8);
5530
+ func->vendor = vendor;
5531
+ func->device = device;
5533
+ card->cis.vendor = vendor;
5534
+ card->cis.device = device;
5540
+static const unsigned char speed_val[16] =
5541
+ { 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 };
5542
+static const unsigned int speed_unit[8] =
5543
+ { 10000, 100000, 1000000, 10000000, 0, 0, 0, 0 };
5545
+static int cistpl_funce_common(struct mmc_card *card,
5546
+ const unsigned char *buf, unsigned size)
5548
+ if (size < 0x04 || buf[0] != 0)
5551
+ /* TPLFE_FN0_BLK_SIZE */
5552
+ card->cis.blksize = buf[1] | (buf[2] << 8);
5554
+ /* TPLFE_MAX_TRAN_SPEED */
5555
+ card->cis.max_dtr = speed_val[(buf[3] >> 3) & 15] *
5556
+ speed_unit[buf[3] & 7];
5561
+static int cistpl_funce_func(struct sdio_func *func,
5562
+ const unsigned char *buf, unsigned size)
5565
+ unsigned min_size;
5567
+ vsn = func->card->cccr.sdio_vsn;
5568
+ min_size = (vsn == SDIO_SDIO_REV_1_00) ? 28 : 42;
5570
+ if (size < min_size || buf[0] != 1)
5573
+ /* TPLFE_MAX_BLK_SIZE */
5574
+ func->max_blksize = buf[12] | (buf[13] << 8);
5579
+static int cistpl_funce(struct mmc_card *card, struct sdio_func *func,
5580
+ const unsigned char *buf, unsigned size)
5585
+ * There should be two versions of the CISTPL_FUNCE tuple,
5586
+ * one for the common CIS (function 0) and a version used by
5587
+ * the individual function's CIS (1-7). Yet, the later has a
5588
+ * different length depending on the SDIO spec version.
5591
+ ret = cistpl_funce_func(func, buf, size);
5593
+ ret = cistpl_funce_common(card, buf, size);
5596
+ printk(KERN_ERR "%s: bad CISTPL_FUNCE size %u "
5597
+ "type %u\n", mmc_hostname(card->host),
5599
+ /* masked by feng for 8688 + CB debug . */
5606
+typedef int (tpl_parse_t)(struct mmc_card *, struct sdio_func *,
5607
+ const unsigned char *, unsigned);
5610
+ unsigned char code;
5611
+ unsigned char min_size;
5612
+ tpl_parse_t *parse;
5615
+static const struct cis_tpl cis_tpl_list[] = {
5616
+ { 0x15, 3, cistpl_vers_1 },
5617
+ { 0x20, 4, cistpl_manfid },
5618
+ { 0x21, 2, /* cistpl_funcid */ },
5619
+ { 0x22, 0, cistpl_funce },
5622
+static int sdio_read_cis(struct mmc_card *card, struct sdio_func *func)
5625
+ struct sdio_func_tuple *this, **prev;
5626
+ unsigned i, ptr = 0;
5629
+ * Note that this works for the common CIS (function number 0) as
5630
+ * well as a function's CIS * since SDIO_CCCR_CIS and SDIO_FBR_CIS
5631
+ * have the same offset.
5633
+ for (i = 0; i < 3; i++) {
5634
+ unsigned char x, fn;
5641
+ ret = mmc_io_rw_direct(card, 0, 0,
5642
+ SDIO_FBR_BASE(fn) + SDIO_FBR_CIS + i, 0, &x);
5645
+ ptr |= x << (i * 8);
5649
+ prev = &func->tuples;
5651
+ prev = &card->tuples;
5656
+ unsigned char tpl_code, tpl_link;
5658
+ ret = mmc_io_rw_direct(card, 0, 0, ptr++, 0, &tpl_code);
5662
+ /* 0xff means we're done */
5663
+ if (tpl_code == 0xff)
5666
+ ret = mmc_io_rw_direct(card, 0, 0, ptr++, 0, &tpl_link);
5670
+ this = kmalloc(sizeof(*this) + tpl_link, GFP_KERNEL);
5674
+ for (i = 0; i < tpl_link; i++) {
5675
+ ret = mmc_io_rw_direct(card, 0, 0,
5676
+ ptr + i, 0, &this->data[i]);
5685
+ for (i = 0; i < ARRAY_SIZE(cis_tpl_list); i++)
5686
+ if (cis_tpl_list[i].code == tpl_code)
5688
+ if (i >= ARRAY_SIZE(cis_tpl_list)) {
5689
+ /* this tuple is unknown to the core */
5690
+ this->next = NULL;
5691
+ this->code = tpl_code;
5692
+ this->size = tpl_link;
5694
+ prev = &this->next;
5696
+ "%s: queuing CIS tuple 0x%02x length %u\n",
5697
+ mmc_hostname(card->host), tpl_code, tpl_link);
5699
+ const struct cis_tpl *tpl = cis_tpl_list + i;
5700
+ if (tpl_link < tpl->min_size) {
5702
+ "%s: bad CIS tuple 0x%02x (length = %u, expected >= %u)\n",
5703
+ mmc_hostname(card->host),
5704
+ tpl_code, tpl_link, tpl->min_size);
5706
+ } else if (tpl->parse) {
5707
+ ret = tpl->parse(card, func,
5708
+ this->data, tpl_link);
5717
+ * Link in all unknown tuples found in the common CIS so that
5718
+ * drivers don't have to go digging in two places.
5721
+ *prev = card->tuples;
5726
+int sdio_read_common_cis(struct mmc_card *card)
5728
+ return sdio_read_cis(card, NULL);
5731
+void sdio_free_common_cis(struct mmc_card *card)
5733
+ struct sdio_func_tuple *tuple, *victim;
5735
+ tuple = card->tuples;
5739
+ tuple = tuple->next;
5743
+ card->tuples = NULL;
5746
+int sdio_read_func_cis(struct sdio_func *func)
5750
+ ret = sdio_read_cis(func->card, func);
5755
+ * Since we've linked to tuples in the card structure,
5756
+ * we must make sure we have a reference to it.
5758
+ get_device(&func->card->dev);
5761
+ * Vendor/device id is optional for function CIS, so
5762
+ * copy it from the card structure as needed.
5764
+ if (func->vendor == 0) {
5765
+ func->vendor = func->card->cis.vendor;
5766
+ func->device = func->card->cis.device;
5772
+void sdio_free_func_cis(struct sdio_func *func)
5774
+ struct sdio_func_tuple *tuple, *victim;
5776
+ tuple = func->tuples;
5778
+ while (tuple && tuple != func->card->tuples) {
5780
+ tuple = tuple->next;
5784
+ func->tuples = NULL;
5787
+ * We have now removed the link to the tuples in the
5788
+ * card structure, so remove the reference.
5790
+ put_device(&func->card->dev);
5793
diff --git a/drivers/mmc/core/sdio_cis.h b/drivers/mmc/core/sdio_cis.h
5794
new file mode 100644
5795
index 0000000..4d903c2
5797
+++ b/drivers/mmc/core/sdio_cis.h
5800
+ * linux/drivers/mmc/core/sdio_cis.h
5802
+ * Author: Nicolas Pitre
5803
+ * Created: June 11, 2007
5804
+ * Copyright: MontaVista Software Inc.
5806
+ * This program is free software; you can redistribute it and/or modify
5807
+ * it under the terms of the GNU General Public License as published by
5808
+ * the Free Software Foundation; either version 2 of the License, or (at
5809
+ * your option) any later version.
5812
+#ifndef _MMC_SDIO_CIS_H
5813
+#define _MMC_SDIO_CIS_H
5815
+int sdio_read_common_cis(struct mmc_card *card);
5816
+void sdio_free_common_cis(struct mmc_card *card);
5818
+int sdio_read_func_cis(struct sdio_func *func);
5819
+void sdio_free_func_cis(struct sdio_func *func);
5822
diff --git a/drivers/mmc/core/sdio_io.c b/drivers/mmc/core/sdio_io.c
5823
new file mode 100644
5824
index 0000000..edfb547
5826
+++ b/drivers/mmc/core/sdio_io.c
5829
+ * linux/drivers/mmc/core/sdio_io.c
5831
+ * Copyright 2007 Pierre Ossman
5833
+ * This program is free software; you can redistribute it and/or modify
5834
+ * it under the terms of the GNU General Public License as published by
5835
+ * the Free Software Foundation; either version 2 of the License, or (at
5836
+ * your option) any later version.
5839
+#include <linux/mmc/host.h>
5840
+#include <linux/mmc/card.h>
5841
+#include <linux/mmc/sdio.h>
5842
+#include <linux/mmc/sdio_func.h>
5844
+#include "sdio_ops.h"
5847
+ * sdio_claim_host - exclusively claim a bus for a certain SDIO function
5848
+ * @func: SDIO function that will be accessed
5850
+ * Claim a bus for a set of operations. The SDIO function given
5851
+ * is used to figure out which bus is relevant.
5853
+void sdio_claim_host(struct sdio_func *func)
5856
+ BUG_ON(!func->card);
5858
+ mmc_claim_host(func->card->host);
5860
+EXPORT_SYMBOL_GPL(sdio_claim_host);
5863
+ * sdio_release_host - release a bus for a certain SDIO function
5864
+ * @func: SDIO function that was accessed
5866
+ * Release a bus, allowing others to claim the bus for their
5869
+void sdio_release_host(struct sdio_func *func)
5872
+ BUG_ON(!func->card);
5874
+ mmc_release_host(func->card->host);
5876
+EXPORT_SYMBOL_GPL(sdio_release_host);
5879
+ * sdio_enable_func - enables a SDIO function for usage
5880
+ * @func: SDIO function to enable
5882
+ * Powers up and activates a SDIO function so that register
5883
+ * access is possible.
5885
+int sdio_enable_func(struct sdio_func *func)
5888
+ unsigned char reg;
5889
+ unsigned long timeout;
5892
+ BUG_ON(!func->card);
5894
+ pr_debug("SDIO: Enabling device %s...\n", sdio_func_id(func));
5896
+ ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, ®);
5900
+ reg |= 1 << func->num;
5902
+ ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
5907
+ * FIXME: This should timeout based on information in the CIS,
5908
+ * but we don't have card to parse that yet.
5910
+ timeout = jiffies + HZ;
5913
+ ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, ®);
5916
+ if (reg & (1 << func->num))
5919
+ if (time_after(jiffies, timeout))
5923
+ pr_debug("SDIO: Enabled device %s\n", sdio_func_id(func));
5928
+ pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func));
5931
+EXPORT_SYMBOL_GPL(sdio_enable_func);
5934
+ * sdio_disable_func - disable a SDIO function
5935
+ * @func: SDIO function to disable
5937
+ * Powers down and deactivates a SDIO function. Register access
5938
+ * to this function will fail until the function is reenabled.
5940
+int sdio_disable_func(struct sdio_func *func)
5943
+ unsigned char reg;
5946
+ BUG_ON(!func->card);
5948
+ pr_debug("SDIO: Disabling device %s...\n", sdio_func_id(func));
5950
+ ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, ®);
5954
+ reg &= ~(1 << func->num);
5956
+ ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
5960
+ pr_debug("SDIO: Disabled device %s\n", sdio_func_id(func));
5965
+ pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func));
5968
+EXPORT_SYMBOL_GPL(sdio_disable_func);
5971
+ * sdio_set_block_size - set the block size of an SDIO function
5972
+ * @func: SDIO function to change
5973
+ * @blksz: new block size or 0 to use the default.
5975
+ * The default block size is the largest supported by both the function
5976
+ * and the host, with a maximum of 512 to ensure that arbitrarily sized
5977
+ * data transfer use the optimal (least) number of commands.
5979
+ * A driver may call this to override the default block size set by the
5980
+ * core. This can be used to set a block size greater than the maximum
5981
+ * that reported by the card; it is the driver's responsibility to ensure
5982
+ * it uses a value that the card supports.
5984
+ * Returns 0 on success, -EINVAL if the host does not support the
5985
+ * requested block size, or -EIO (etc.) if one of the resultant FBR block
5986
+ * size register writes failed.
5989
+int sdio_set_block_size(struct sdio_func *func, unsigned blksz)
5993
+ if (blksz > func->card->host->max_blk_size)
5998
+ func->max_blksize,
5999
+ func->card->host->max_blk_size),
6003
+ ret = mmc_io_rw_direct(func->card, 1, 0,
6004
+ SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE,
6005
+ blksz & 0xff, NULL);
6008
+ ret = mmc_io_rw_direct(func->card, 1, 0,
6009
+ SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE + 1,
6010
+ (blksz >> 8) & 0xff, NULL);
6013
+ func->cur_blksize = blksz;
6017
+EXPORT_SYMBOL_GPL(sdio_set_block_size);
6019
+/* Split an arbitrarily sized data transfer into several
6020
+ * IO_RW_EXTENDED commands. */
6021
+static int sdio_io_rw_ext_helper(struct sdio_func *func, int write,
6022
+ unsigned addr, int incr_addr, u8 *buf, unsigned size)
6024
+ unsigned remainder = size;
6025
+ unsigned max_blocks;
6028
+ /* Do the bulk of the transfer using block mode (if supported). */
6029
+ if (func->card->cccr.multi_block) {
6030
+ /* Blocks per command is limited by host count, host transfer
6031
+ * size (we only use a single sg entry) and the maximum for
6032
+ * IO_RW_EXTENDED of 511 blocks. */
6033
+ max_blocks = min(min(
6034
+ func->card->host->max_blk_count,
6035
+ func->card->host->max_seg_size / func->cur_blksize),
6038
+ while (remainder > func->cur_blksize) {
6041
+ blocks = remainder / func->cur_blksize;
6042
+ if (blocks > max_blocks)
6043
+ blocks = max_blocks;
6044
+ size = blocks * func->cur_blksize;
6046
+ ret = mmc_io_rw_extended(func->card, write,
6047
+ func->num, addr, incr_addr, buf,
6048
+ blocks, func->cur_blksize);
6052
+ remainder -= size;
6059
+ /* Write the remainder using byte mode. */
6060
+ while (remainder > 0) {
6062
+ if (size > func->cur_blksize)
6063
+ size = func->cur_blksize;
6065
+ size = 512; /* maximum size for byte mode */
6067
+ ret = mmc_io_rw_extended(func->card, write, func->num, addr,
6068
+ incr_addr, buf, 1, size);
6072
+ remainder -= size;
6081
+ * sdio_readb - read a single byte from a SDIO function
6082
+ * @func: SDIO function to access
6083
+ * @addr: address to read
6084
+ * @err_ret: optional status value from transfer
6086
+ * Reads a single byte from the address space of a given SDIO
6087
+ * function. If there is a problem reading the address, 0xff
6088
+ * is returned and @err_ret will contain the error code.
6090
+unsigned char sdio_readb(struct sdio_func *func, unsigned int addr,
6094
+ unsigned char val;
6101
+ ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val);
6110
+EXPORT_SYMBOL_GPL(sdio_readb);
6113
+ * sdio_writeb - write a single byte to a SDIO function
6114
+ * @func: SDIO function to access
6115
+ * @b: byte to write
6116
+ * @addr: address to write to
6117
+ * @err_ret: optional status value from transfer
6119
+ * Writes a single byte to the address space of a given SDIO
6120
+ * function. @err_ret will contain the status of the actual
6123
+void sdio_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
6130
+ ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL);
6134
+EXPORT_SYMBOL_GPL(sdio_writeb);
6137
+ * sdio_memcpy_fromio - read a chunk of memory from a SDIO function
6138
+ * @func: SDIO function to access
6139
+ * @dst: buffer to store the data
6140
+ * @addr: address to begin reading from
6141
+ * @count: number of bytes to read
6143
+ * Reads from the address space of a given SDIO function. Return
6144
+ * value indicates if the transfer succeeded or not.
6146
+int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
6147
+ unsigned int addr, int count)
6149
+ return sdio_io_rw_ext_helper(func, 0, addr, 1, dst, count);
6151
+EXPORT_SYMBOL_GPL(sdio_memcpy_fromio);
6154
+ * sdio_memcpy_toio - write a chunk of memory to a SDIO function
6155
+ * @func: SDIO function to access
6156
+ * @addr: address to start writing to
6157
+ * @src: buffer that contains the data to write
6158
+ * @count: number of bytes to write
6160
+ * Writes to the address space of a given SDIO function. Return
6161
+ * value indicates if the transfer succeeded or not.
6163
+int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
6164
+ void *src, int count)
6166
+ return sdio_io_rw_ext_helper(func, 1, addr, 1, src, count);
6168
+EXPORT_SYMBOL_GPL(sdio_memcpy_toio);
6171
+ * sdio_readsb - read from a FIFO on a SDIO function
6172
+ * @func: SDIO function to access
6173
+ * @dst: buffer to store the data
6174
+ * @addr: address of (single byte) FIFO
6175
+ * @count: number of bytes to read
6177
+ * Reads from the specified FIFO of a given SDIO function. Return
6178
+ * value indicates if the transfer succeeded or not.
6180
+int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr,
6183
+ return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count);
6186
+EXPORT_SYMBOL_GPL(sdio_readsb);
6189
+ * sdio_writesb - write to a FIFO of a SDIO function
6190
+ * @func: SDIO function to access
6191
+ * @addr: address of (single byte) FIFO
6192
+ * @src: buffer that contains the data to write
6193
+ * @count: number of bytes to write
6195
+ * Writes to the specified FIFO of a given SDIO function. Return
6196
+ * value indicates if the transfer succeeded or not.
6198
+int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src,
6201
+ return sdio_io_rw_ext_helper(func, 1, addr, 0, src, count);
6203
+EXPORT_SYMBOL_GPL(sdio_writesb);
6206
+ * sdio_readw - read a 16 bit integer from a SDIO function
6207
+ * @func: SDIO function to access
6208
+ * @addr: address to read
6209
+ * @err_ret: optional status value from transfer
6211
+ * Reads a 16 bit integer from the address space of a given SDIO
6212
+ * function. If there is a problem reading the address, 0xffff
6213
+ * is returned and @err_ret will contain the error code.
6215
+unsigned short sdio_readw(struct sdio_func *func, unsigned int addr,
6223
+ ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 2);
6230
+ return le16_to_cpu(*(u16*)func->tmpbuf);
6232
+EXPORT_SYMBOL_GPL(sdio_readw);
6235
+ * sdio_writew - write a 16 bit integer to a SDIO function
6236
+ * @func: SDIO function to access
6237
+ * @b: integer to write
6238
+ * @addr: address to write to
6239
+ * @err_ret: optional status value from transfer
6241
+ * Writes a 16 bit integer to the address space of a given SDIO
6242
+ * function. @err_ret will contain the status of the actual
6245
+void sdio_writew(struct sdio_func *func, unsigned short b, unsigned int addr,
6250
+ *(u16*)func->tmpbuf = cpu_to_le16(b);
6252
+ ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2);
6256
+EXPORT_SYMBOL_GPL(sdio_writew);
6259
+ * sdio_readl - read a 32 bit integer from a SDIO function
6260
+ * @func: SDIO function to access
6261
+ * @addr: address to read
6262
+ * @err_ret: optional status value from transfer
6264
+ * Reads a 32 bit integer from the address space of a given SDIO
6265
+ * function. If there is a problem reading the address,
6266
+ * 0xffffffff is returned and @err_ret will contain the error
6269
+unsigned long sdio_readl(struct sdio_func *func, unsigned int addr,
6277
+ ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 4);
6281
+ return 0xFFFFFFFF;
6284
+ return le32_to_cpu(*(u32*)func->tmpbuf);
6286
+EXPORT_SYMBOL_GPL(sdio_readl);
6289
+ * sdio_writel - write a 32 bit integer to a SDIO function
6290
+ * @func: SDIO function to access
6291
+ * @b: integer to write
6292
+ * @addr: address to write to
6293
+ * @err_ret: optional status value from transfer
6295
+ * Writes a 32 bit integer to the address space of a given SDIO
6296
+ * function. @err_ret will contain the status of the actual
6299
+void sdio_writel(struct sdio_func *func, unsigned long b, unsigned int addr,
6304
+ *(u32*)func->tmpbuf = cpu_to_le32(b);
6306
+ ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4);
6310
+EXPORT_SYMBOL_GPL(sdio_writel);
6313
+ * sdio_f0_readb - read a single byte from SDIO function 0
6314
+ * @func: an SDIO function of the card
6315
+ * @addr: address to read
6316
+ * @err_ret: optional status value from transfer
6318
+ * Reads a single byte from the address space of SDIO function 0.
6319
+ * If there is a problem reading the address, 0xff is returned
6320
+ * and @err_ret will contain the error code.
6322
+unsigned char sdio_f0_readb(struct sdio_func *func, unsigned int addr,
6326
+ unsigned char val;
6333
+ ret = mmc_io_rw_direct(func->card, 0, 0, addr, 0, &val);
6342
+EXPORT_SYMBOL_GPL(sdio_f0_readb);
6345
+ * sdio_f0_writeb - write a single byte to SDIO function 0
6346
+ * @func: an SDIO function of the card
6347
+ * @b: byte to write
6348
+ * @addr: address to write to
6349
+ * @err_ret: optional status value from transfer
6351
+ * Writes a single byte to the address space of SDIO function 0.
6352
+ * @err_ret will contain the status of the actual transfer.
6354
+ * Only writes to the vendor specific CCCR registers (0xF0 -
6355
+ * 0xFF) are permiited; @err_ret will be set to -EINVAL for *
6356
+ * writes outside this range.
6358
+void sdio_f0_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
6365
+ if (addr < 0xF0 || addr > 0xFF) {
6367
+ *err_ret = -EINVAL;
6371
+ ret = mmc_io_rw_direct(func->card, 1, 0, addr, b, NULL);
6375
+EXPORT_SYMBOL_GPL(sdio_f0_writeb);
6377
+static char* sdio_version[4] = {
6384
+static char* sd_phy_version[4] = {
6390
+void sdio_dump_cccr(struct sdio_func *func)
6392
+ struct mmc_card *card = func->card;
6397
+ printk(KERN_INFO "\nStart to dump SDIO CCCR registers:\n");
6399
+ /* dump sdio version */
6400
+ mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CCCR, 0, &data);
6401
+ val = (data >> 4) & 0xf;
6403
+ printk(KERN_INFO "SDIO Spec: %s\n", sdio_version[val]);
6405
+ printk(KERN_INFO "This card doesn't comply with any SDIO spec version!!\n");
6407
+ /* dump sd PHY version */
6408
+ mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SD, 0, &data);
6411
+ printk(KERN_INFO "SD PHY spec: %s\n", sd_phy_version[val]);
6413
+ printk(KERN_INFO "This card doesn't comply with any SD PHY spec version!!\n");
6415
+ /* dump IO Enalbe reg */
6416
+ mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IOEx, 0, &data);
6417
+ printk(KERN_INFO "IO Enable Reg: 0x%02x\n", data);
6419
+ /* dump IO Ready reg */
6420
+ mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IORx, 0, &data);
6421
+ printk(KERN_INFO "IO Ready Reg: 0x%02x\n", data);
6423
+ /* dump INT Enable reg */
6424
+ mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IENx, 0, &data);
6425
+ printk(KERN_INFO "INT Enable Reg: 0x%02x\n", data);
6427
+ /* dump INT Pending reg */
6428
+ mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_INTx, 0, &data);
6429
+ printk(KERN_INFO "INT Pending Reg: 0x%02x\n", data);
6431
+ /* dump Bus Interface reg */
6432
+ mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &data);
6434
+ printk(KERN_INFO "Bus Width: %d bit\n", (val ? 4 : 1));
6436
+ /* dump capability reg */
6437
+ mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CAPS, 0, &data);
6438
+ printk(KERN_INFO "Multi-Block support: %s\n", (data & SDIO_CCCR_CAP_SMB) ? "YES" : "NO");
6439
+ printk(KERN_INFO "Suspend/Resume support: %s\n", (data & SDIO_CCCR_CAP_SBS) ? "YES" : "NO");
6440
+ printk(KERN_INFO "Low Speed Card: %s\n", (data & SDIO_CCCR_CAP_LSC) ? "YES" : "NO");
6441
+ printk(KERN_INFO "4 bits Low Speed Card: %s\n", (data & SDIO_CCCR_CAP_4BLS) ? "YES" : "NO");
6443
+EXPORT_SYMBOL_GPL(sdio_dump_cccr);
6445
diff --git a/drivers/mmc/core/sdio_irq.c b/drivers/mmc/core/sdio_irq.c
6446
new file mode 100644
6447
index 0000000..9d34f81
6449
+++ b/drivers/mmc/core/sdio_irq.c
6452
+ * linux/drivers/mmc/core/sdio_irq.c
6454
+ * Author: Nicolas Pitre
6455
+ * Created: June 18, 2007
6456
+ * Copyright: MontaVista Software Inc.
6458
+ * This program is free software; you can redistribute it and/or modify
6459
+ * it under the terms of the GNU General Public License as published by
6460
+ * the Free Software Foundation; either version 2 of the License, or (at
6461
+ * your option) any later version.
6464
+#include <linux/kernel.h>
6465
+#include <linux/sched.h>
6466
+#include <linux/kthread.h>
6467
+#include <linux/wait.h>
6468
+#include <linux/delay.h>
6470
+#include <linux/mmc/core.h>
6471
+#include <linux/mmc/host.h>
6472
+#include <linux/mmc/card.h>
6473
+#include <linux/mmc/sdio.h>
6474
+#include <linux/mmc/sdio_func.h>
6476
+#include "sdio_ops.h"
6478
+static int process_sdio_pending_irqs(struct mmc_card *card)
6480
+ int i, ret, count;
6481
+ unsigned char pending;
6483
+ ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_INTx, 0, &pending);
6485
+ printk(KERN_DEBUG "%s: error %d reading SDIO_CCCR_INTx\n",
6486
+ mmc_card_id(card), ret);
6491
+ for (i = 1; i <= 7; i++) {
6492
+ if (pending & (1 << i)) {
6493
+ struct sdio_func *func = card->sdio_func[i - 1];
6495
+ printk(KERN_WARNING "%s: pending IRQ for "
6496
+ "non-existant function\n",
6497
+ mmc_card_id(card));
6499
+ } else if (func->irq_handler) {
6500
+ func->irq_handler(func);
6503
+ printk(KERN_WARNING "%s: pending IRQ with no handler\n",
6504
+ sdio_func_id(func));
6516
+static int sdio_irq_thread(void *_host)
6518
+ struct mmc_host *host = _host;
6519
+ struct sched_param param = { .sched_priority = 1 };
6520
+ unsigned long period, idle_period;
6523
+ sched_setscheduler(current, SCHED_FIFO, ¶m);
6526
+ * We want to allow for SDIO cards to work even on non SDIO
6527
+ * aware hosts. One thing that non SDIO host cannot do is
6528
+ * asynchronous notification of pending SDIO card interrupts
6529
+ * hence we poll for them in that case.
6531
+ idle_period = msecs_to_jiffies(10);
6532
+ period = (host->caps & MMC_CAP_SDIO_IRQ) ?
6533
+ MAX_SCHEDULE_TIMEOUT : idle_period;
6535
+ pr_debug("%s: IRQ thread started (poll period = %lu jiffies)\n",
6536
+ mmc_hostname(host), period);
6538
+ current->flags |= PF_NOFREEZE;
6542
+ * We claim the host here on drivers behalf for a couple
6545
+ * 1) it is already needed to retrieve the CCCR_INTx;
6546
+ * 2) we want the driver(s) to clear the IRQ condition ASAP;
6547
+ * 3) we need to control the abort condition locally.
6549
+ * Just like traditional hard IRQ handlers, we expect SDIO
6550
+ * IRQ handlers to be quick and to the point, so that the
6551
+ * holding of the host lock does not cover too much work
6552
+ * that doesn't require that lock to be held.
6554
+ ret = __mmc_claim_host(host, &host->sdio_irq_thread_abort);
6557
+ ret = process_sdio_pending_irqs(host->card);
6558
+ mmc_release_host(host);
6561
+ * Give other threads a chance to run in the presence of
6562
+ * errors. FIXME: determine if due to card removal and
6563
+ * possibly exit this thread if so.
6569
+ * Adaptive polling frequency based on the assumption
6570
+ * that an interrupt will be closely followed by more.
6571
+ * This has a substantial benefit for network devices.
6573
+ if (!(host->caps & MMC_CAP_SDIO_IRQ)) {
6578
+ if (period > idle_period)
6579
+ period = idle_period;
6583
+ set_task_state(current, TASK_INTERRUPTIBLE);
6584
+ if (host->caps & MMC_CAP_SDIO_IRQ)
6585
+ host->ops->enable_sdio_irq(host, 1);
6586
+ if (!kthread_should_stop())
6587
+ schedule_timeout(period);
6588
+ set_task_state(current, TASK_RUNNING);
6589
+ } while (!kthread_should_stop());
6591
+ if (host->caps & MMC_CAP_SDIO_IRQ)
6592
+ host->ops->enable_sdio_irq(host, 0);
6594
+ pr_debug("%s: IRQ thread exiting with code %d\n",
6595
+ mmc_hostname(host), ret);
6600
+static int sdio_card_irq_get(struct mmc_card *card)
6602
+ struct mmc_host *host = card->host;
6604
+ WARN_ON(!host->claimed);
6606
+ if (!host->sdio_irqs++) {
6607
+ atomic_set(&host->sdio_irq_thread_abort, 0);
6608
+ host->sdio_irq_thread =
6609
+ kthread_run(sdio_irq_thread, host, "ksdiorqd");
6610
+ if (IS_ERR(host->sdio_irq_thread)) {
6611
+ int err = PTR_ERR(host->sdio_irq_thread);
6612
+ host->sdio_irqs--;
6620
+static int sdio_card_irq_put(struct mmc_card *card)
6622
+ struct mmc_host *host = card->host;
6624
+ WARN_ON(!host->claimed);
6625
+ BUG_ON(host->sdio_irqs < 1);
6627
+ if (!--host->sdio_irqs) {
6628
+ atomic_set(&host->sdio_irq_thread_abort, 1);
6629
+ kthread_stop(host->sdio_irq_thread);
6636
+ * sdio_claim_irq - claim the IRQ for a SDIO function
6637
+ * @func: SDIO function
6638
+ * @handler: IRQ handler callback
6640
+ * Claim and activate the IRQ for the given SDIO function. The provided
6641
+ * handler will be called when that IRQ is asserted. The host is always
6642
+ * claimed already when the handler is called so the handler must not
6643
+ * call sdio_claim_host() nor sdio_release_host().
6645
+int sdio_claim_irq(struct sdio_func *func, sdio_irq_handler_t *handler)
6648
+ unsigned char reg;
6651
+ BUG_ON(!func->card);
6653
+ pr_debug("SDIO: Enabling IRQ for %s...\n", sdio_func_id(func));
6655
+ if (func->irq_handler) {
6656
+ pr_debug("SDIO: IRQ for %s already in use.\n", sdio_func_id(func));
6660
+ ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IENx, 0, ®);
6664
+ reg |= 1 << func->num;
6666
+ reg |= 1; /* Master interrupt enable */
6668
+ ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IENx, reg, NULL);
6672
+ func->irq_handler = handler;
6673
+ ret = sdio_card_irq_get(func->card);
6675
+ func->irq_handler = NULL;
6679
+EXPORT_SYMBOL_GPL(sdio_claim_irq);
6682
+ * sdio_release_irq - release the IRQ for a SDIO function
6683
+ * @func: SDIO function
6685
+ * Disable and release the IRQ for the given SDIO function.
6687
+int sdio_release_irq(struct sdio_func *func)
6690
+ unsigned char reg;
6693
+ BUG_ON(!func->card);
6695
+ pr_debug("SDIO: Disabling IRQ for %s...\n", sdio_func_id(func));
6697
+ if (func->irq_handler) {
6698
+ func->irq_handler = NULL;
6699
+ sdio_card_irq_put(func->card);
6702
+ ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IENx, 0, ®);
6706
+ reg &= ~(1 << func->num);
6708
+ /* Disable master interrupt with the last function interrupt */
6709
+ if (!(reg & 0xFE))
6712
+ ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IENx, reg, NULL);
6718
+EXPORT_SYMBOL_GPL(sdio_release_irq);
6720
diff --git a/drivers/mmc/core/sdio_ops.c b/drivers/mmc/core/sdio_ops.c
6721
new file mode 100644
6722
index 0000000..34e8f02
6724
+++ b/drivers/mmc/core/sdio_ops.c
6727
+ * linux/drivers/mmc/sdio_ops.c
6729
+ * Copyright 2006-2007 Pierre Ossman
6731
+ * This program is free software; you can redistribute it and/or modify
6732
+ * it under the terms of the GNU General Public License as published by
6733
+ * the Free Software Foundation; either version 2 of the License, or (at
6734
+ * your option) any later version.
6737
+#include <asm/scatterlist.h>
6738
+#include <linux/scatterlist.h>
6740
+#include <linux/mmc/host.h>
6741
+#include <linux/mmc/card.h>
6742
+#include <linux/mmc/mmc.h>
6743
+#include <linux/mmc/sdio.h>
6747
+int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
6749
+ struct mmc_command cmd;
6754
+ memset(&cmd, 0, sizeof(struct mmc_command));
6756
+ cmd.opcode = SD_IO_SEND_OP_COND;
6758
+ cmd.flags = MMC_RSP_SPI_R4 | MMC_RSP_R4 | MMC_CMD_BCR;
6760
+ for (i = 100; i; i--) {
6761
+ err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
6765
+ /* if we're just probing, do a single pass */
6769
+ /* otherwise wait until reset completes */
6770
+ if (mmc_host_is_spi(host)) {
6772
+ * Both R1_SPI_IDLE and MMC_CARD_BUSY indicate
6773
+ * an initialized card under SPI, but some cards
6774
+ * (Marvell's) only behave when looking at this
6777
+ if (cmd.resp[1] & MMC_CARD_BUSY)
6780
+ if (cmd.resp[0] & MMC_CARD_BUSY)
6790
+ *rocr = cmd.resp[mmc_host_is_spi(host) ? 1 : 0];
6795
+int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
6796
+ unsigned addr, u8 in, u8* out)
6798
+ struct mmc_command cmd;
6804
+ memset(&cmd, 0, sizeof(struct mmc_command));
6806
+ cmd.opcode = SD_IO_RW_DIRECT;
6807
+ cmd.arg = write ? 0x80000000 : 0x00000000;
6808
+ cmd.arg |= fn << 28;
6809
+ cmd.arg |= (write && out) ? 0x08000000 : 0x00000000;
6810
+ cmd.arg |= addr << 9;
6812
+ cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_AC;
6814
+ err = mmc_wait_for_cmd(card->host, &cmd, 0);
6818
+ if (mmc_host_is_spi(card->host)) {
6819
+ /* host driver already reported errors */
6821
+ if (cmd.resp[0] & R5_ERROR)
6823
+ if (cmd.resp[0] & R5_FUNCTION_NUMBER)
6825
+ if (cmd.resp[0] & R5_OUT_OF_RANGE)
6830
+ if (mmc_host_is_spi(card->host))
6831
+ *out = (cmd.resp[0] >> 8) & 0xFF;
6833
+ *out = cmd.resp[0] & 0xFF;
6839
+int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
6840
+ unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz)
6842
+ struct mmc_request mrq;
6843
+ struct mmc_command cmd;
6844
+ struct mmc_data data;
6845
+ struct scatterlist sg;
6849
+ BUG_ON(blocks == 1 && blksz > 512);
6850
+ WARN_ON(blocks == 0);
6851
+ WARN_ON(blksz == 0);
6853
+ memset(&mrq, 0, sizeof(struct mmc_request));
6854
+ memset(&cmd, 0, sizeof(struct mmc_command));
6855
+ memset(&data, 0, sizeof(struct mmc_data));
6860
+ cmd.opcode = SD_IO_RW_EXTENDED;
6861
+ cmd.arg = write ? 0x80000000 : 0x00000000;
6862
+ cmd.arg |= fn << 28;
6863
+ cmd.arg |= incr_addr ? 0x04000000 : 0x00000000;
6864
+ cmd.arg |= addr << 9;
6865
+ if (blocks == 1 && blksz <= 512)
6866
+ cmd.arg |= (blksz == 512) ? 0 : blksz; /* byte mode */
6868
+ cmd.arg |= 0x08000000 | blocks; /* block mode */
6869
+ cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
6871
+ data.blksz = blksz;
6872
+ data.blocks = blocks;
6873
+ data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
6877
+ sg_init_one(&sg, buf, blksz * blocks);
6879
+ mmc_set_data_timeout(&data, card);
6881
+ mmc_wait_for_req(card->host, &mrq);
6886
+ return data.error;
6888
+ if (mmc_host_is_spi(card->host)) {
6889
+ /* host driver already reported errors */
6891
+ if (cmd.resp[0] & R5_ERROR)
6893
+ if (cmd.resp[0] & R5_FUNCTION_NUMBER)
6895
+ if (cmd.resp[0] & R5_OUT_OF_RANGE)
6901
+EXPORT_SYMBOL_GPL(mmc_io_rw_extended);
6903
diff --git a/drivers/mmc/core/sdio_ops.h b/drivers/mmc/core/sdio_ops.h
6904
new file mode 100644
6905
index 0000000..24ed1fd
6907
+++ b/drivers/mmc/core/sdio_ops.h
6910
+ * linux/drivers/mmc/sdio_ops.c
6912
+ * Copyright 2006-2007 Pierre Ossman
6914
+ * This program is free software; you can redistribute it and/or modify
6915
+ * it under the terms of the GNU General Public License as published by
6916
+ * the Free Software Foundation; either version 2 of the License, or (at
6917
+ * your option) any later version.
6920
+#ifndef _MMC_SDIO_OPS_H
6921
+#define _MMC_SDIO_OPS_H
6923
+int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr);
6924
+int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
6925
+ unsigned addr, u8 in, u8* out);
6926
+int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
6927
+ unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz);
6930
diff --git a/drivers/mmc/core/sysfs.c b/drivers/mmc/core/sysfs.c
6931
index 843b1fb..00a97e7 100644
6932
--- a/drivers/mmc/core/sysfs.c
6933
+++ b/drivers/mmc/core/sysfs.c
6935
* linux/drivers/mmc/core/sysfs.c
6937
* Copyright (C) 2003 Russell King, All Rights Reserved.
6938
+ * Copyright 2007 Pierre Ossman
6940
* This program is free software; you can redistribute it and/or modify
6941
* it under the terms of the GNU General Public License version 2 as
6944
* MMC sysfs/driver model support.
6946
-#include <linux/module.h>
6947
-#include <linux/init.h>
6948
#include <linux/device.h>
6949
-#include <linux/idr.h>
6950
-#include <linux/workqueue.h>
6952
#include <linux/mmc/card.h>
6953
-#include <linux/mmc/host.h>
6957
-#define dev_to_mmc_card(d) container_of(d, struct mmc_card, dev)
6958
-#define to_mmc_driver(d) container_of(d, struct mmc_driver, drv)
6959
-#define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
6961
-#define MMC_ATTR(name, fmt, args...) \
6962
-static ssize_t mmc_##name##_show (struct device *dev, struct device_attribute *attr, char *buf) \
6964
- struct mmc_card *card = dev_to_mmc_card(dev); \
6965
- return sprintf(buf, fmt, args); \
6968
-MMC_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
6969
- card->raw_cid[2], card->raw_cid[3]);
6970
-MMC_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
6971
- card->raw_csd[2], card->raw_csd[3]);
6972
-MMC_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]);
6973
-MMC_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
6974
-MMC_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
6975
-MMC_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
6976
-MMC_ATTR(manfid, "0x%06x\n", card->cid.manfid);
6977
-MMC_ATTR(name, "%s\n", card->cid.prod_name);
6978
-MMC_ATTR(oemid, "0x%04x\n", card->cid.oemid);
6979
-MMC_ATTR(serial, "0x%08x\n", card->cid.serial);
6981
-#define MMC_ATTR_RO(name) __ATTR(name, S_IRUGO, mmc_##name##_show, NULL)
6983
-static struct device_attribute mmc_dev_attrs[] = {
6986
- MMC_ATTR_RO(date),
6987
- MMC_ATTR_RO(fwrev),
6988
- MMC_ATTR_RO(hwrev),
6989
- MMC_ATTR_RO(manfid),
6990
- MMC_ATTR_RO(name),
6991
- MMC_ATTR_RO(oemid),
6992
- MMC_ATTR_RO(serial),
6996
-static struct device_attribute mmc_dev_attr_scr = MMC_ATTR_RO(scr);
6999
-static void mmc_release_card(struct device *dev)
7001
- struct mmc_card *card = dev_to_mmc_card(dev);
7007
- * This currently matches any MMC driver to any MMC card - drivers
7008
- * themselves make the decision whether to drive this card in their
7011
-static int mmc_bus_match(struct device *dev, struct device_driver *drv)
7017
-mmc_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
7020
- struct mmc_card *card = dev_to_mmc_card(dev);
7022
- int retval = 0, i = 0, length = 0;
7024
-#define add_env(fmt,val) do { \
7025
- retval = add_uevent_var(envp, num_envp, &i, \
7026
- buf, buf_size, &length, \
7032
- for (i = 0; i < 12; i++)
7033
- ccc[i] = card->csd.cmdclass & (1 << i) ? '1' : '0';
7036
- add_env("MMC_CCC=%s", ccc);
7037
- add_env("MMC_MANFID=%06x", card->cid.manfid);
7038
- add_env("MMC_NAME=%s", mmc_card_name(card));
7039
- add_env("MMC_OEMID=%04x", card->cid.oemid);
7046
-static int mmc_bus_suspend(struct device *dev, pm_message_t state)
7048
- struct mmc_driver *drv = to_mmc_driver(dev->driver);
7049
- struct mmc_card *card = dev_to_mmc_card(dev);
7052
- if (dev->driver && drv->suspend)
7053
- ret = drv->suspend(card, state);
7057
-static int mmc_bus_resume(struct device *dev)
7059
- struct mmc_driver *drv = to_mmc_driver(dev->driver);
7060
- struct mmc_card *card = dev_to_mmc_card(dev);
7063
- if (dev->driver && drv->resume)
7064
- ret = drv->resume(card);
7068
-static int mmc_bus_probe(struct device *dev)
7070
- struct mmc_driver *drv = to_mmc_driver(dev->driver);
7071
- struct mmc_card *card = dev_to_mmc_card(dev);
7073
- return drv->probe(card);
7076
-static int mmc_bus_remove(struct device *dev)
7078
- struct mmc_driver *drv = to_mmc_driver(dev->driver);
7079
- struct mmc_card *card = dev_to_mmc_card(dev);
7081
- drv->remove(card);
7086
-static struct bus_type mmc_bus_type = {
7088
- .dev_attrs = mmc_dev_attrs,
7089
- .match = mmc_bus_match,
7090
- .uevent = mmc_bus_uevent,
7091
- .probe = mmc_bus_probe,
7092
- .remove = mmc_bus_remove,
7093
- .suspend = mmc_bus_suspend,
7094
- .resume = mmc_bus_resume,
7098
- * mmc_register_driver - register a media driver
7099
- * @drv: MMC media driver
7101
-int mmc_register_driver(struct mmc_driver *drv)
7103
- drv->drv.bus = &mmc_bus_type;
7104
- return driver_register(&drv->drv);
7107
-EXPORT_SYMBOL(mmc_register_driver);
7110
- * mmc_unregister_driver - unregister a media driver
7111
- * @drv: MMC media driver
7113
-void mmc_unregister_driver(struct mmc_driver *drv)
7115
- drv->drv.bus = &mmc_bus_type;
7116
- driver_unregister(&drv->drv);
7119
-EXPORT_SYMBOL(mmc_unregister_driver);
7123
- * Internal function. Initialise a MMC card structure.
7125
-void mmc_init_card(struct mmc_card *card, struct mmc_host *host)
7127
- memset(card, 0, sizeof(struct mmc_card));
7128
- card->host = host;
7129
- device_initialize(&card->dev);
7130
- card->dev.parent = mmc_classdev(host);
7131
- card->dev.bus = &mmc_bus_type;
7132
- card->dev.release = mmc_release_card;
7136
- * Internal function. Register a new MMC card with the driver model.
7138
-int mmc_register_card(struct mmc_card *card)
7139
+int mmc_add_attrs(struct mmc_card *card, struct device_attribute *attrs)
7145
- snprintf(card->dev.bus_id, sizeof(card->dev.bus_id),
7146
- "%s:%04x", mmc_hostname(card->host), card->rca);
7148
- ret = device_add(&card->dev);
7150
- if (mmc_card_sd(card)) {
7151
- ret = device_create_file(&card->dev, &mmc_dev_attr_scr);
7153
- device_del(&card->dev);
7154
+ for (i = 0; attr_name(attrs[i]); i++) {
7155
+ error = device_create_file(&card->dev, &attrs[i]);
7158
+ device_remove_file(&card->dev, &attrs[i]);
7163
- mmc_card_set_present(card);
7168
- * Internal function. Unregister a new MMC card with the
7169
- * driver model, and (eventually) free it.
7171
-void mmc_remove_card(struct mmc_card *card)
7173
- if (mmc_card_present(card)) {
7174
- if (mmc_card_sd(card))
7175
- device_remove_file(&card->dev, &mmc_dev_attr_scr);
7177
- device_del(&card->dev);
7180
- put_device(&card->dev);
7184
-static void mmc_host_classdev_release(struct device *dev)
7186
- struct mmc_host *host = cls_dev_to_mmc_host(dev);
7190
-static struct class mmc_host_class = {
7191
- .name = "mmc_host",
7192
- .dev_release = mmc_host_classdev_release,
7195
-static DEFINE_IDR(mmc_host_idr);
7196
-static DEFINE_SPINLOCK(mmc_host_lock);
7199
- * Internal function. Allocate a new MMC host.
7201
-struct mmc_host *mmc_alloc_host_sysfs(int extra, struct device *dev)
7203
- struct mmc_host *host;
7205
- host = kmalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
7207
- memset(host, 0, sizeof(struct mmc_host) + extra);
7209
- host->parent = dev;
7210
- host->class_dev.parent = dev;
7211
- host->class_dev.class = &mmc_host_class;
7212
- device_initialize(&host->class_dev);
7220
- * Internal function. Register a new MMC host with the MMC class.
7222
-int mmc_add_host_sysfs(struct mmc_host *host)
7223
+void mmc_remove_attrs(struct mmc_card *card, struct device_attribute *attrs)
7227
- if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
7230
- spin_lock(&mmc_host_lock);
7231
- err = idr_get_new(&mmc_host_idr, host, &host->index);
7232
- spin_unlock(&mmc_host_lock);
7236
- snprintf(host->class_dev.bus_id, BUS_ID_SIZE,
7237
- "mmc%d", host->index);
7239
- return device_add(&host->class_dev);
7244
- * Internal function. Unregister a MMC host with the MMC class.
7246
-void mmc_remove_host_sysfs(struct mmc_host *host)
7248
- device_del(&host->class_dev);
7250
- spin_lock(&mmc_host_lock);
7251
- idr_remove(&mmc_host_idr, host->index);
7252
- spin_unlock(&mmc_host_lock);
7256
- * Internal function. Free a MMC host.
7258
-void mmc_free_host_sysfs(struct mmc_host *host)
7260
- put_device(&host->class_dev);
7263
-static struct workqueue_struct *workqueue;
7266
- * Internal function. Schedule delayed work in the MMC work queue.
7268
-int mmc_schedule_delayed_work(struct delayed_work *work, unsigned long delay)
7270
- return queue_delayed_work(workqueue, work, delay);
7274
- * Internal function. Flush all scheduled work from the MMC work queue.
7276
-void mmc_flush_scheduled_work(void)
7278
- flush_workqueue(workqueue);
7281
-static int __init mmc_init(void)
7285
- workqueue = create_singlethread_workqueue("kmmcd");
7289
- ret = bus_register(&mmc_bus_type);
7291
- ret = class_register(&mmc_host_class);
7293
- bus_unregister(&mmc_bus_type);
7298
-static void __exit mmc_exit(void)
7300
- class_unregister(&mmc_host_class);
7301
- bus_unregister(&mmc_bus_type);
7302
- destroy_workqueue(workqueue);
7303
+ for (i = 0; attr_name(attrs[i]); i++)
7304
+ device_remove_file(&card->dev, &attrs[i]);
7307
-module_init(mmc_init);
7308
-module_exit(mmc_exit);
7309
diff --git a/drivers/mmc/core/sysfs.h b/drivers/mmc/core/sysfs.h
7310
index 80e29b3..4b8f670 100644
7311
--- a/drivers/mmc/core/sysfs.h
7312
+++ b/drivers/mmc/core/sysfs.h
7314
#ifndef _MMC_CORE_SYSFS_H
7315
#define _MMC_CORE_SYSFS_H
7317
-void mmc_init_card(struct mmc_card *card, struct mmc_host *host);
7318
-int mmc_register_card(struct mmc_card *card);
7319
-void mmc_remove_card(struct mmc_card *card);
7320
+#define MMC_ATTR_FN(name, fmt, args...) \
7321
+static ssize_t mmc_##name##_show (struct device *dev, struct device_attribute *attr, char *buf) \
7323
+ struct mmc_card *card = container_of(dev, struct mmc_card, dev);\
7324
+ return sprintf(buf, fmt, args); \
7327
-struct mmc_host *mmc_alloc_host_sysfs(int extra, struct device *dev);
7328
-int mmc_add_host_sysfs(struct mmc_host *host);
7329
-void mmc_remove_host_sysfs(struct mmc_host *host);
7330
-void mmc_free_host_sysfs(struct mmc_host *host);
7331
+#define MMC_ATTR_RO(name) __ATTR(name, S_IRUGO, mmc_##name##_show, NULL)
7333
-int mmc_schedule_work(struct work_struct *work);
7334
-int mmc_schedule_delayed_work(struct delayed_work *work, unsigned long delay);
7335
-void mmc_flush_scheduled_work(void);
7336
+int mmc_add_attrs(struct mmc_card *card, struct device_attribute *attrs);
7337
+void mmc_remove_attrs(struct mmc_card *card, struct device_attribute *attrs);
7340
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
7341
index e23082f..5fef678 100644
7342
--- a/drivers/mmc/host/Kconfig
7343
+++ b/drivers/mmc/host/Kconfig
7344
@@ -35,6 +35,23 @@ config MMC_SDHCI
7348
+config MMC_RICOH_MMC
7349
+ tristate "Ricoh MMC Controller Disabler (EXPERIMENTAL)"
7350
+ depends on PCI && EXPERIMENTAL && MMC_SDHCI
7352
+ This selects the disabler for the Ricoh MMC Controller. This
7353
+ proprietary controller is unnecessary because the SDHCI driver
7354
+ supports MMC cards on the SD controller, but if it is not
7355
+ disabled, it will steal the MMC cards away - rendering them
7356
+ useless. It is safe to select this driver even if you don't
7357
+ have a Ricoh based card reader.
7360
+ To compile this driver as a module, choose M here:
7361
+ the module will be called ricoh_mmc.
7366
tristate "TI OMAP Multimedia Card Interface support"
7367
depends on ARCH_OMAP
7368
@@ -100,3 +117,16 @@ config MMC_TIFM_SD
7369
To compile this driver as a module, choose M here: the
7370
module will be called tifm_sd.
7373
+ tristate "MMC/SD over SPI (EXPERIMENTAL)"
7374
+ depends on MMC && SPI_MASTER && !HIGHMEM && EXPERIMENTAL
7378
+ Some systems accss MMC/SD cards using a SPI controller instead of
7379
+ using a "native" MMC/SD controller. This has a disadvantage of
7380
+ being relatively high overhead, but a compensating advantage of
7381
+ working on many systems without dedicated MMC/SD controllers.
7383
+ If unsure, or if your system has no SPI master driver, say N.
7385
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
7386
index 6685f64..3877c87 100644
7387
--- a/drivers/mmc/host/Makefile
7388
+++ b/drivers/mmc/host/Makefile
7389
@@ -10,9 +10,11 @@ obj-$(CONFIG_MMC_ARMMMCI) += mmci.o
7390
obj-$(CONFIG_MMC_PXA) += pxamci.o
7391
obj-$(CONFIG_MMC_IMX) += imxmmc.o
7392
obj-$(CONFIG_MMC_SDHCI) += sdhci.o
7393
+obj-$(CONFIG_MMC_RICOH_MMC) += ricoh_mmc.o
7394
obj-$(CONFIG_MMC_WBSD) += wbsd.o
7395
obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
7396
obj-$(CONFIG_MMC_OMAP) += omap.o
7397
obj-$(CONFIG_MMC_AT91) += at91_mci.o
7398
obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
7399
+obj-$(CONFIG_MMC_SPI) += mmc_spi.o
7401
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c
7402
index 5b00c19..b1edcef 100644
7403
--- a/drivers/mmc/host/at91_mci.c
7404
+++ b/drivers/mmc/host/at91_mci.c
7407
- * linux/drivers/mmc/at91_mci.c - ATMEL AT91 MCI Driver
7408
+ * linux/drivers/mmc/host/at91_mci.c - ATMEL AT91 MCI Driver
7410
* Copyright (C) 2005 Cougar Creek Computing Devices Ltd, All Rights Reserved
7414
#define DRIVER_NAME "at91_mci"
7416
-#undef SUPPORT_4WIRE
7418
#define FL_SENT_COMMAND (1 << 0)
7419
#define FL_SENT_STOP (1 << 1)
7421
#define AT91_MCI_ERRORS (AT91_MCI_RINDE | AT91_MCI_RDIRE | AT91_MCI_RCRCE \
7422
| AT91_MCI_RENDE | AT91_MCI_RTOE | AT91_MCI_DCRCE \
7423
- | AT91_MCI_DTOE | AT91_MCI_OVRE | AT91_MCI_UNRE)
7424
+ | AT91_MCI_DTOE | AT91_MCI_OVRE | AT91_MCI_UNRE)
7426
#define at91_mci_read(host, reg) __raw_readl((host)->baseaddr + (reg))
7427
#define at91_mci_write(host, reg, val) __raw_writel((val), (host)->baseaddr + (reg))
7428
@@ -131,7 +129,7 @@ struct at91mci_host
7430
* Copy from sg to a dma block - used for transfers
7432
-static inline void at91mci_sg_to_dma(struct at91mci_host *host, struct mmc_data *data)
7433
+static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data *data)
7435
unsigned int len, i, size;
7436
unsigned *dmabuf = host->buffer;
7437
@@ -151,7 +149,7 @@ static inline void at91mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
7441
- sgbuffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset;
7442
+ sgbuffer = kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
7443
amount = min(size, sg->length);
7446
@@ -180,7 +178,7 @@ static inline void at91mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
7448
* Prepare a dma read
7450
-static void at91mci_pre_dma_read(struct at91mci_host *host)
7451
+static void at91_mci_pre_dma_read(struct at91mci_host *host)
7454
struct scatterlist *sg;
7455
@@ -228,7 +226,7 @@ static void at91mci_pre_dma_read(struct at91mci_host *host)
7456
sg = &data->sg[host->transfer_index++];
7457
pr_debug("sg = %p\n", sg);
7459
- sg->dma_address = dma_map_page(NULL, sg->page, sg->offset, sg->length, DMA_FROM_DEVICE);
7460
+ sg->dma_address = dma_map_page(NULL, sg_page(sg), sg->offset, sg->length, DMA_FROM_DEVICE);
7462
pr_debug("dma address = %08X, length = %d\n", sg->dma_address, sg->length);
7464
@@ -248,7 +246,7 @@ static void at91mci_pre_dma_read(struct at91mci_host *host)
7466
* Handle after a dma read
7468
-static void at91mci_post_dma_read(struct at91mci_host *host)
7469
+static void at91_mci_post_dma_read(struct at91mci_host *host)
7471
struct mmc_command *cmd;
7472
struct mmc_data *data;
7473
@@ -268,8 +266,6 @@ static void at91mci_post_dma_read(struct at91mci_host *host)
7476
while (host->in_use_index < host->transfer_index) {
7477
- unsigned int *buffer;
7479
struct scatterlist *sg;
7481
pr_debug("finishing index %d\n", host->in_use_index);
7482
@@ -280,29 +276,31 @@ static void at91mci_post_dma_read(struct at91mci_host *host)
7484
dma_unmap_page(NULL, sg->dma_address, sg->length, DMA_FROM_DEVICE);
7486
- /* Swap the contents of the buffer */
7487
- buffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset;
7488
- pr_debug("buffer = %p, length = %d\n", buffer, sg->length);
7490
data->bytes_xfered += sg->length;
7492
if (cpu_is_at91rm9200()) { /* AT91RM9200 errata */
7493
+ unsigned int *buffer;
7496
+ /* Swap the contents of the buffer */
7497
+ buffer = kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
7498
+ pr_debug("buffer = %p, length = %d\n", buffer, sg->length);
7500
for (index = 0; index < (sg->length / 4); index++)
7501
buffer[index] = swab32(buffer[index]);
7503
+ kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
7506
- kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
7507
- flush_dcache_page(sg->page);
7508
+ flush_dcache_page(sg_page(sg));
7511
/* Is there another transfer to trigger? */
7512
if (host->transfer_index < data->sg_len)
7513
- at91mci_pre_dma_read(host);
7514
+ at91_mci_pre_dma_read(host);
7516
+ at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_ENDRX);
7517
at91_mci_write(host, AT91_MCI_IER, AT91_MCI_RXBUFF);
7518
- at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
7521
pr_debug("post dma read done\n");
7522
@@ -323,7 +321,6 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host)
7524
/* Now wait for cmd ready */
7525
at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_TXBUFE);
7526
- at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY);
7530
@@ -331,18 +328,53 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host)
7534
+ if (cmd->data->blocks > 1) {
7535
+ pr_debug("multiple write : wait for BLKE...\n");
7536
+ at91_mci_write(host, AT91_MCI_IER, AT91_MCI_BLKE);
7538
+ at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY);
7540
data->bytes_xfered = host->total_length;
7543
+/*Handle after command sent ready*/
7544
+static int at91_mci_handle_cmdrdy(struct at91mci_host *host)
7548
+ else if (!host->cmd->data) {
7549
+ if (host->flags & FL_SENT_STOP) {
7550
+ /*After multi block write, we must wait for NOTBUSY*/
7551
+ at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY);
7553
+ } else if (host->cmd->data->flags & MMC_DATA_WRITE) {
7554
+ /*After sendding multi-block-write command, start DMA transfer*/
7555
+ at91_mci_write(host, AT91_MCI_IER, AT91_MCI_TXBUFE);
7556
+ at91_mci_write(host, AT91_MCI_IER, AT91_MCI_BLKE);
7557
+ at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN);
7560
+ /* command not completed, have to wait */
7566
* Enable the controller
7568
static void at91_mci_enable(struct at91mci_host *host)
7572
at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN);
7573
at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
7574
at91_mci_write(host, AT91_MCI_DTOR, AT91_MCI_DTOMUL_1M | AT91_MCI_DTOCYC);
7575
- at91_mci_write(host, AT91_MCI_MR, AT91_MCI_PDCMODE | 0x34a);
7576
+ mr = AT91_MCI_PDCMODE | 0x34a;
7578
+ if (cpu_is_at91sam9260() || cpu_is_at91sam9263())
7579
+ mr |= AT91_MCI_RDPROOF | AT91_MCI_WRPROOF;
7581
+ at91_mci_write(host, AT91_MCI_MR, mr);
7583
/* use Slot A or B (only one at same time) */
7584
at91_mci_write(host, AT91_MCI_SDCR, host->board->slot_b);
7585
@@ -358,9 +390,8 @@ static void at91_mci_disable(struct at91mci_host *host)
7589
- * return the interrupts to enable
7591
-static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_command *cmd)
7592
+static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command *cmd)
7594
unsigned int cmdr, mr;
7595
unsigned int block_length;
7596
@@ -371,8 +402,7 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
7600
- /* Not sure if this is needed */
7602
+ /* Needed for leaving busy state before CMD1 */
7603
if ((at91_mci_read(host, AT91_MCI_SR) & AT91_MCI_RTOE) && (cmd->opcode == 1)) {
7604
pr_debug("Clearing timeout\n");
7605
at91_mci_write(host, AT91_MCI_ARGR, 0);
7606
@@ -382,7 +412,7 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
7607
pr_debug("Clearing: SR = %08X\n", at91_mci_read(host, AT91_MCI_SR));
7614
if (mmc_resp_type(cmd) == MMC_RSP_NONE)
7615
@@ -398,6 +428,14 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
7620
+ if ( data->blksz & 0x3 ) {
7621
+ pr_debug("Unsupported block size\n");
7622
+ cmd->error = -EINVAL;
7623
+ mmc_request_done(host->mmc, host->request);
7627
block_length = data->blksz;
7628
blocks = data->blocks;
7630
@@ -409,7 +447,7 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
7632
if (data->flags & MMC_DATA_STREAM)
7633
cmdr |= AT91_MCI_TRTYP_STREAM;
7634
- if (data->flags & MMC_DATA_MULTI)
7635
+ if (data->blocks > 1)
7636
cmdr |= AT91_MCI_TRTYP_MULTIPLE;
7639
@@ -439,50 +477,48 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
7640
at91_mci_write(host, ATMEL_PDC_TCR, 0);
7641
at91_mci_write(host, ATMEL_PDC_TNPR, 0);
7642
at91_mci_write(host, ATMEL_PDC_TNCR, 0);
7643
+ ier = AT91_MCI_CMDRDY;
7645
+ /* zero block length and PDC mode */
7646
+ mr = at91_mci_read(host, AT91_MCI_MR) & 0x7fff;
7647
+ at91_mci_write(host, AT91_MCI_MR, mr | (block_length << 16) | AT91_MCI_PDCMODE);
7649
- at91_mci_write(host, AT91_MCI_ARGR, cmd->arg);
7650
- at91_mci_write(host, AT91_MCI_CMDR, cmdr);
7651
- return AT91_MCI_CMDRDY;
7654
- mr = at91_mci_read(host, AT91_MCI_MR) & 0x7fff; /* zero block length and PDC mode */
7655
- at91_mci_write(host, AT91_MCI_MR, mr | (block_length << 16) | AT91_MCI_PDCMODE);
7658
- * Disable the PDC controller
7660
- at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
7662
- if (cmdr & AT91_MCI_TRCMD_START) {
7663
- data->bytes_xfered = 0;
7664
- host->transfer_index = 0;
7665
- host->in_use_index = 0;
7666
- if (cmdr & AT91_MCI_TRDIR) {
7670
- host->buffer = NULL;
7671
- host->total_length = 0;
7673
- at91mci_pre_dma_read(host);
7674
- ier = AT91_MCI_ENDRX /* | AT91_MCI_RXBUFF */;
7680
- host->total_length = block_length * blocks;
7681
- host->buffer = dma_alloc_coherent(NULL,
7682
- host->total_length,
7683
- &host->physical_address, GFP_KERNEL);
7685
- at91mci_sg_to_dma(host, data);
7687
- pr_debug("Transmitting %d bytes\n", host->total_length);
7689
+ * Disable the PDC controller
7691
+ at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
7693
- at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address);
7694
- at91_mci_write(host, ATMEL_PDC_TCR, host->total_length / 4);
7695
- ier = AT91_MCI_TXBUFE;
7696
+ if (cmdr & AT91_MCI_TRCMD_START) {
7697
+ data->bytes_xfered = 0;
7698
+ host->transfer_index = 0;
7699
+ host->in_use_index = 0;
7700
+ if (cmdr & AT91_MCI_TRDIR) {
7704
+ host->buffer = NULL;
7705
+ host->total_length = 0;
7707
+ at91_mci_pre_dma_read(host);
7708
+ ier = AT91_MCI_ENDRX /* | AT91_MCI_RXBUFF */;
7714
+ host->total_length = block_length * blocks;
7715
+ host->buffer = dma_alloc_coherent(NULL,
7716
+ host->total_length,
7717
+ &host->physical_address, GFP_KERNEL);
7719
+ at91_mci_sg_to_dma(host, data);
7721
+ pr_debug("Transmitting %d bytes\n", host->total_length);
7723
+ at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address);
7724
+ at91_mci_write(host, ATMEL_PDC_TCR, host->total_length / 4);
7725
+ ier = AT91_MCI_CMDRDY;
7730
@@ -497,39 +533,24 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
7731
if (cmdr & AT91_MCI_TRCMD_START) {
7732
if (cmdr & AT91_MCI_TRDIR)
7733
at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTEN);
7735
- at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN);
7741
- * Wait for a command to complete
7743
-static void at91mci_process_command(struct at91mci_host *host, struct mmc_command *cmd)
7747
- ier = at91_mci_send_command(host, cmd);
7749
- pr_debug("setting ier to %08X\n", ier);
7751
- /* Stop on errors or the required value */
7752
+ /* Enable selected interrupts */
7753
at91_mci_write(host, AT91_MCI_IER, AT91_MCI_ERRORS | ier);
7757
* Process the next step in the request
7759
-static void at91mci_process_next(struct at91mci_host *host)
7760
+static void at91_mci_process_next(struct at91mci_host *host)
7762
if (!(host->flags & FL_SENT_COMMAND)) {
7763
host->flags |= FL_SENT_COMMAND;
7764
- at91mci_process_command(host, host->request->cmd);
7765
+ at91_mci_send_command(host, host->request->cmd);
7767
else if ((!(host->flags & FL_SENT_STOP)) && host->request->stop) {
7768
host->flags |= FL_SENT_STOP;
7769
- at91mci_process_command(host, host->request->stop);
7770
+ at91_mci_send_command(host, host->request->stop);
7773
mmc_request_done(host->mmc, host->request);
7774
@@ -538,7 +559,7 @@ static void at91mci_process_next(struct at91mci_host *host)
7776
* Handle a command that has been completed
7778
-static void at91mci_completed_command(struct at91mci_host *host)
7779
+static void at91_mci_completed_command(struct at91mci_host *host)
7781
struct mmc_command *cmd = host->cmd;
7782
unsigned int status;
7783
@@ -560,30 +581,26 @@ static void at91mci_completed_command(struct at91mci_host *host)
7784
pr_debug("Status = %08X [%08X %08X %08X %08X]\n",
7785
status, cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]);
7787
- if (status & (AT91_MCI_RINDE | AT91_MCI_RDIRE | AT91_MCI_RCRCE |
7788
- AT91_MCI_RENDE | AT91_MCI_RTOE | AT91_MCI_DCRCE |
7789
- AT91_MCI_DTOE | AT91_MCI_OVRE | AT91_MCI_UNRE)) {
7790
+ if (status & AT91_MCI_ERRORS) {
7791
if ((status & AT91_MCI_RCRCE) && !(mmc_resp_type(cmd) & MMC_RSP_CRC)) {
7792
- cmd->error = MMC_ERR_NONE;
7796
if (status & (AT91_MCI_RTOE | AT91_MCI_DTOE))
7797
- cmd->error = MMC_ERR_TIMEOUT;
7798
+ cmd->error = -ETIMEDOUT;
7799
else if (status & (AT91_MCI_RCRCE | AT91_MCI_DCRCE))
7800
- cmd->error = MMC_ERR_BADCRC;
7801
- else if (status & (AT91_MCI_OVRE | AT91_MCI_UNRE))
7802
- cmd->error = MMC_ERR_FIFO;
7803
+ cmd->error = -EILSEQ;
7805
- cmd->error = MMC_ERR_FAILED;
7806
+ cmd->error = -EIO;
7808
pr_debug("Error detected and set to %d (cmd = %d, retries = %d)\n",
7809
cmd->error, cmd->opcode, cmd->retries);
7813
- cmd->error = MMC_ERR_NONE;
7816
- at91mci_process_next(host);
7817
+ at91_mci_process_next(host);
7821
@@ -595,7 +612,7 @@ static void at91_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
7822
host->request = mrq;
7825
- at91mci_process_next(host);
7826
+ at91_mci_process_next(host);
7830
@@ -663,15 +680,15 @@ static irqreturn_t at91_mci_irq(int irq, void *devid)
7832
int_status = at91_mci_read(host, AT91_MCI_SR);
7833
int_mask = at91_mci_read(host, AT91_MCI_IMR);
7836
pr_debug("MCI irq: status = %08X, %08X, %08X\n", int_status, int_mask,
7837
int_status & int_mask);
7840
int_status = int_status & int_mask;
7842
if (int_status & AT91_MCI_ERRORS) {
7846
if (int_status & AT91_MCI_UNRE)
7847
pr_debug("MMC: Underrun error\n");
7848
if (int_status & AT91_MCI_OVRE)
7849
@@ -698,29 +715,33 @@ static irqreturn_t at91_mci_irq(int irq, void *devid)
7850
at91_mci_handle_transmitted(host);
7853
+ if (int_status & AT91_MCI_ENDRX) {
7854
+ pr_debug("ENDRX\n");
7855
+ at91_mci_post_dma_read(host);
7858
if (int_status & AT91_MCI_RXBUFF) {
7859
pr_debug("RX buffer full\n");
7860
- at91_mci_write(host, AT91_MCI_IER, AT91_MCI_CMDRDY);
7861
+ at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
7862
+ at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_RXBUFF | AT91_MCI_ENDRX);
7866
if (int_status & AT91_MCI_ENDTX)
7867
pr_debug("Transmit has ended\n");
7869
- if (int_status & AT91_MCI_ENDRX) {
7870
- pr_debug("Receive has ended\n");
7871
- at91mci_post_dma_read(host);
7874
if (int_status & AT91_MCI_NOTBUSY) {
7875
pr_debug("Card is ready\n");
7876
- at91_mci_write(host, AT91_MCI_IER, AT91_MCI_CMDRDY);
7880
if (int_status & AT91_MCI_DTIP)
7881
pr_debug("Data transfer in progress\n");
7883
- if (int_status & AT91_MCI_BLKE)
7884
+ if (int_status & AT91_MCI_BLKE) {
7885
pr_debug("Block transfer has ended\n");
7889
if (int_status & AT91_MCI_TXRDY)
7890
pr_debug("Ready to transmit\n");
7891
@@ -730,14 +751,14 @@ static irqreturn_t at91_mci_irq(int irq, void *devid)
7893
if (int_status & AT91_MCI_CMDRDY) {
7894
pr_debug("Command ready\n");
7896
+ completed = at91_mci_handle_cmdrdy(host);
7901
pr_debug("Completed command\n");
7902
at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
7903
- at91mci_completed_command(host);
7904
+ at91_mci_completed_command(host);
7906
at91_mci_write(host, AT91_MCI_IDR, int_status);
7908
@@ -819,7 +840,6 @@ static int __init at91_mci_probe(struct platform_device *pdev)
7909
mmc->f_min = 375000;
7910
mmc->f_max = 25000000;
7911
mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
7912
- mmc->caps = MMC_CAP_BYTEBLOCK;
7914
mmc->max_blk_size = 4095;
7915
mmc->max_blk_count = mmc->max_req_size;
7916
@@ -830,11 +850,11 @@ static int __init at91_mci_probe(struct platform_device *pdev)
7918
host->board = pdev->dev.platform_data;
7919
if (host->board->wire4) {
7920
-#ifdef SUPPORT_4WIRE
7921
- mmc->caps |= MMC_CAP_4_BIT_DATA;
7923
- printk("AT91 MMC: 4 wire bus mode not supported by this driver - using 1 wire\n");
7925
+ if (cpu_is_at91sam9260() || cpu_is_at91sam9263())
7926
+ mmc->caps |= MMC_CAP_4_BIT_DATA;
7928
+ printk("AT91 MMC: 4 wire bus mode not supported"
7929
+ " - using 1 wire\n");
7933
@@ -886,8 +906,10 @@ static int __init at91_mci_probe(struct platform_device *pdev)
7935
* Add host to MMC layer
7937
- if (host->board->det_pin)
7938
+ if (host->board->det_pin) {
7939
host->present = !at91_get_gpio_value(host->board->det_pin);
7940
+ device_init_wakeup(&pdev->dev, 1);
7945
@@ -922,7 +944,8 @@ static int __exit at91_mci_remove(struct platform_device *pdev)
7947
host = mmc_priv(mmc);
7949
- if (host->present != -1) {
7950
+ if (host->board->det_pin) {
7951
+ device_init_wakeup(&pdev->dev, 0);
7952
free_irq(host->board->det_pin, host);
7953
cancel_delayed_work(&host->mmc->detect);
7955
@@ -949,8 +972,12 @@ static int __exit at91_mci_remove(struct platform_device *pdev)
7956
static int at91_mci_suspend(struct platform_device *pdev, pm_message_t state)
7958
struct mmc_host *mmc = platform_get_drvdata(pdev);
7959
+ struct at91mci_host *host = mmc_priv(mmc);
7962
+ if (host->board->det_pin && device_may_wakeup(&pdev->dev))
7963
+ enable_irq_wake(host->board->det_pin);
7966
ret = mmc_suspend_host(mmc, state);
7968
@@ -960,8 +987,12 @@ static int at91_mci_suspend(struct platform_device *pdev, pm_message_t state)
7969
static int at91_mci_resume(struct platform_device *pdev)
7971
struct mmc_host *mmc = platform_get_drvdata(pdev);
7972
+ struct at91mci_host *host = mmc_priv(mmc);
7975
+ if (host->board->det_pin && device_may_wakeup(&pdev->dev))
7976
+ disable_irq_wake(host->board->det_pin);
7979
ret = mmc_resume_host(mmc);
7981
diff --git a/drivers/mmc/host/au1xmmc.c b/drivers/mmc/host/au1xmmc.c
7982
index 52b63f1..c3926eb 100644
7983
--- a/drivers/mmc/host/au1xmmc.c
7984
+++ b/drivers/mmc/host/au1xmmc.c
7987
- * linux/drivers/mmc/au1xmmc.c - AU1XX0 MMC driver
7988
+ * linux/drivers/mmc/host/au1xmmc.c - AU1XX0 MMC driver
7990
* Copyright (c) 2005, Advanced Micro Devices, Inc.
7993
#include <linux/mm.h>
7994
#include <linux/interrupt.h>
7995
#include <linux/dma-mapping.h>
7996
+#include <linux/scatterlist.h>
7998
#include <linux/mmc/host.h>
8000
#include <asm/mach-au1x00/au1000.h>
8001
#include <asm/mach-au1x00/au1xxx_dbdma.h>
8002
#include <asm/mach-au1x00/au1100_mmc.h>
8003
-#include <asm/scatterlist.h>
8006
#include "au1xmmc.h"
8007
@@ -186,7 +186,7 @@ static void au1xmmc_tasklet_finish(unsigned long param)
8010
static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
8011
- struct mmc_command *cmd, unsigned int flags)
8012
+ struct mmc_command *cmd, struct mmc_data *data)
8014
u32 mmccmd = (cmd->opcode << SD_CMD_CI_SHIFT);
8016
@@ -208,19 +208,21 @@ static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
8018
printk(KERN_INFO "au1xmmc: unhandled response type %02x\n",
8019
mmc_resp_type(cmd));
8020
- return MMC_ERR_INVALID;
8024
- if (flags & MMC_DATA_READ) {
8025
- if (flags & MMC_DATA_MULTI)
8026
- mmccmd |= SD_CMD_CT_4;
8028
- mmccmd |= SD_CMD_CT_2;
8029
- } else if (flags & MMC_DATA_WRITE) {
8030
- if (flags & MMC_DATA_MULTI)
8031
- mmccmd |= SD_CMD_CT_3;
8033
- mmccmd |= SD_CMD_CT_1;
8035
+ if (data->flags & MMC_DATA_READ) {
8036
+ if (data->blocks > 1)
8037
+ mmccmd |= SD_CMD_CT_4;
8039
+ mmccmd |= SD_CMD_CT_2;
8040
+ } else if (data->flags & MMC_DATA_WRITE) {
8041
+ if (data->blocks > 1)
8042
+ mmccmd |= SD_CMD_CT_3;
8044
+ mmccmd |= SD_CMD_CT_1;
8048
au_writel(cmd->arg, HOST_CMDARG(host));
8049
@@ -253,7 +255,7 @@ static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
8050
IRQ_ON(host, SD_CONFIG_CR);
8053
- return MMC_ERR_NONE;
8057
static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status)
8058
@@ -278,7 +280,7 @@ static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status)
8059
while((host->flags & HOST_F_XMIT) && (status & SD_STATUS_DB))
8060
status = au_readl(HOST_STATUS(host));
8062
- data->error = MMC_ERR_NONE;
8064
dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir);
8066
/* Process any errors */
8067
@@ -288,14 +290,14 @@ static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status)
8068
crc |= ((status & 0x07) == 0x02) ? 0 : 1;
8071
- data->error = MMC_ERR_BADCRC;
8072
+ data->error = -EILSEQ;
8074
/* Clear the CRC bits */
8075
au_writel(SD_STATUS_WC | SD_STATUS_RC, HOST_STATUS(host));
8077
data->bytes_xfered = 0;
8079
- if (data->error == MMC_ERR_NONE) {
8080
+ if (!data->error) {
8081
if (host->flags & HOST_F_DMA) {
8082
u32 chan = DMA_CHANNEL(host);
8084
@@ -338,7 +340,7 @@ static void au1xmmc_send_pio(struct au1xmmc_host *host)
8086
/* This is the pointer to the data buffer */
8087
sg = &data->sg[host->pio.index];
8088
- sg_ptr = page_address(sg->page) + sg->offset + host->pio.offset;
8089
+ sg_ptr = sg_virt(sg) + host->pio.offset;
8091
/* This is the space left inside the buffer */
8092
sg_len = data->sg[host->pio.index].length - host->pio.offset;
8093
@@ -398,7 +400,7 @@ static void au1xmmc_receive_pio(struct au1xmmc_host *host)
8095
if (host->pio.index < host->dma.len) {
8096
sg = &data->sg[host->pio.index];
8097
- sg_ptr = page_address(sg->page) + sg->offset + host->pio.offset;
8098
+ sg_ptr = sg_virt(sg) + host->pio.offset;
8100
/* This is the space left inside the buffer */
8101
sg_len = sg_dma_len(&data->sg[host->pio.index]) - host->pio.offset;
8102
@@ -475,7 +477,7 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status)
8106
- cmd->error = MMC_ERR_NONE;
8109
if (cmd->flags & MMC_RSP_PRESENT) {
8110
if (cmd->flags & MMC_RSP_136) {
8111
@@ -512,11 +514,11 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status)
8112
/* Figure out errors */
8114
if (status & (SD_STATUS_SC | SD_STATUS_WC | SD_STATUS_RC))
8115
- cmd->error = MMC_ERR_BADCRC;
8116
+ cmd->error = -EILSEQ;
8118
trans = host->flags & (HOST_F_XMIT | HOST_F_RECV);
8120
- if (!trans || cmd->error != MMC_ERR_NONE) {
8121
+ if (!trans || cmd->error) {
8123
IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA|SD_CONFIG_RF);
8124
tasklet_schedule(&host->finish_task);
8125
@@ -589,7 +591,7 @@ au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data)
8126
data->sg_len, host->dma.dir);
8128
if (host->dma.len == 0)
8129
- return MMC_ERR_TIMEOUT;
8130
+ return -ETIMEDOUT;
8132
au_writel(data->blksz - 1, HOST_BLKSIZE(host));
8134
@@ -611,14 +613,11 @@ au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data)
8136
if (host->flags & HOST_F_XMIT){
8137
ret = au1xxx_dbdma_put_source_flags(channel,
8138
- (void *) (page_address(sg->page) +
8141
+ (void *) sg_virt(sg), len, flags);
8144
ret = au1xxx_dbdma_put_dest_flags(channel,
8145
- (void *) (page_address(sg->page) +
8147
+ (void *) sg_virt(sg),
8151
@@ -640,11 +639,11 @@ au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data)
8152
//IRQ_ON(host, SD_CONFIG_RA|SD_CONFIG_RF);
8155
- return MMC_ERR_NONE;
8159
dma_unmap_sg(mmc_dev(host->mmc),data->sg,data->sg_len,host->dma.dir);
8160
- return MMC_ERR_TIMEOUT;
8161
+ return -ETIMEDOUT;
8164
/* static void au1xmmc_request
8165
@@ -656,7 +655,7 @@ static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq)
8167
struct au1xmmc_host *host = mmc_priv(mmc);
8168
unsigned int flags = 0;
8169
- int ret = MMC_ERR_NONE;
8172
WARN_ON(irqs_disabled());
8173
WARN_ON(host->status != HOST_S_IDLE);
8174
@@ -672,10 +671,10 @@ static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq)
8175
ret = au1xmmc_prepare_data(host, mrq->data);
8178
- if (ret == MMC_ERR_NONE)
8179
- ret = au1xmmc_send_command(host, 0, mrq->cmd, flags);
8181
+ ret = au1xmmc_send_command(host, 0, mrq->cmd, mrq->data);
8183
- if (ret != MMC_ERR_NONE) {
8185
mrq->cmd->error = ret;
8186
au1xmmc_finish_request(host);
8188
@@ -764,10 +763,10 @@ static irqreturn_t au1xmmc_irq(int irq, void *dev_id)
8190
if (host->mrq && (status & STATUS_TIMEOUT)) {
8191
if (status & SD_STATUS_RAT)
8192
- host->mrq->cmd->error = MMC_ERR_TIMEOUT;
8193
+ host->mrq->cmd->error = -ETIMEDOUT;
8195
else if (status & SD_STATUS_DT)
8196
- host->mrq->data->error = MMC_ERR_TIMEOUT;
8197
+ host->mrq->data->error = -ETIMEDOUT;
8199
/* In PIO mode, interrupts might still be enabled */
8200
IRQ_OFF(host, SD_CONFIG_NE | SD_CONFIG_TH);
8201
diff --git a/drivers/mmc/host/imxmmc.c b/drivers/mmc/host/imxmmc.c
8202
index 7ee2045..f2070a1 100644
8203
--- a/drivers/mmc/host/imxmmc.c
8204
+++ b/drivers/mmc/host/imxmmc.c
8207
- * linux/drivers/mmc/imxmmc.c - Motorola i.MX MMCI driver
8208
+ * linux/drivers/mmc/host/imxmmc.c - Motorola i.MX MMCI driver
8210
* Copyright (C) 2004 Sascha Hauer, Pengutronix <sascha@saschahauer.de>
8211
* Copyright (C) 2006 Pavel Pisa, PiKRON <ppisa@pikron.com>
8212
@@ -262,7 +262,7 @@ static void imxmci_setup_data(struct imxmci_host *host, struct mmc_data *data)
8215
/* Convert back to virtual address */
8216
- host->data_ptr = (u16*)(page_address(data->sg->page) + data->sg->offset);
8217
+ host->data_ptr = (u16*)sg_virt(data->sg);
8220
clear_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events);
8221
@@ -428,11 +428,11 @@ static int imxmci_finish_data(struct imxmci_host *host, unsigned int stat)
8222
if ( stat & STATUS_ERR_MASK ) {
8223
dev_dbg(mmc_dev(host->mmc), "request failed. status: 0x%08x\n",stat);
8224
if(stat & (STATUS_CRC_READ_ERR | STATUS_CRC_WRITE_ERR))
8225
- data->error = MMC_ERR_BADCRC;
8226
+ data->error = -EILSEQ;
8227
else if(stat & STATUS_TIME_OUT_READ)
8228
- data->error = MMC_ERR_TIMEOUT;
8229
+ data->error = -ETIMEDOUT;
8231
- data->error = MMC_ERR_FAILED;
8232
+ data->error = -EIO;
8234
data->bytes_xfered = host->dma_size;
8236
@@ -458,10 +458,10 @@ static int imxmci_cmd_done(struct imxmci_host *host, unsigned int stat)
8238
if (stat & STATUS_TIME_OUT_RESP) {
8239
dev_dbg(mmc_dev(host->mmc), "CMD TIMEOUT\n");
8240
- cmd->error = MMC_ERR_TIMEOUT;
8241
+ cmd->error = -ETIMEDOUT;
8242
} else if (stat & STATUS_RESP_CRC_ERR && cmd->flags & MMC_RSP_CRC) {
8243
dev_dbg(mmc_dev(host->mmc), "cmd crc error\n");
8244
- cmd->error = MMC_ERR_BADCRC;
8245
+ cmd->error = -EILSEQ;
8248
if(cmd->flags & MMC_RSP_PRESENT) {
8249
@@ -482,7 +482,7 @@ static int imxmci_cmd_done(struct imxmci_host *host, unsigned int stat)
8250
dev_dbg(mmc_dev(host->mmc), "RESP 0x%08x, 0x%08x, 0x%08x, 0x%08x, error %d\n",
8251
cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3], cmd->error);
8253
- if (data && (cmd->error == MMC_ERR_NONE) && !(stat & STATUS_ERR_MASK)) {
8254
+ if (data && !cmd->error && !(stat & STATUS_ERR_MASK)) {
8255
if (host->req->data->flags & MMC_DATA_WRITE) {
8257
/* Wait for FIFO to be empty before starting DMA write */
8258
@@ -491,7 +491,7 @@ static int imxmci_cmd_done(struct imxmci_host *host, unsigned int stat)
8259
if(imxmci_busy_wait_for_status(host, &stat,
8260
STATUS_APPL_BUFF_FE,
8261
40, "imxmci_cmd_done DMA WR") < 0) {
8262
- cmd->error = MMC_ERR_FIFO;
8263
+ cmd->error = -EIO;
8264
imxmci_finish_data(host, stat);
8266
imxmci_finish_request(host, host->req);
8267
@@ -884,9 +884,21 @@ static void imxmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
8271
+static int imxmci_get_ro(struct mmc_host *mmc)
8273
+ struct imxmci_host *host = mmc_priv(mmc);
8275
+ if (host->pdata && host->pdata->get_ro)
8276
+ return host->pdata->get_ro(mmc_dev(mmc));
8277
+ /* Host doesn't support read only detection so assume writeable */
8282
static const struct mmc_host_ops imxmci_ops = {
8283
.request = imxmci_request,
8284
.set_ios = imxmci_set_ios,
8285
+ .get_ro = imxmci_get_ro,
8288
static struct resource *platform_device_resource(struct platform_device *dev, unsigned int mask, int nr)
8289
@@ -913,7 +925,7 @@ static void imxmci_check_status(unsigned long data)
8291
struct imxmci_host *host = (struct imxmci_host *)data;
8293
- if( host->pdata->card_present() != host->present ) {
8294
+ if( host->pdata->card_present(mmc_dev(host->mmc)) != host->present ) {
8296
dev_info(mmc_dev(host->mmc), "card %s\n",
8297
host->present ? "inserted" : "removed");
8298
@@ -963,7 +975,7 @@ static int imxmci_probe(struct platform_device *pdev)
8299
mmc->f_min = 150000;
8300
mmc->f_max = CLK_RATE/2;
8301
mmc->ocr_avail = MMC_VDD_32_33;
8302
- mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_BYTEBLOCK;
8303
+ mmc->caps = MMC_CAP_4_BIT_DATA;
8305
/* MMC core transfer sizes tunable parameters */
8306
mmc->max_hw_segs = 64;
8307
@@ -1022,7 +1034,7 @@ static int imxmci_probe(struct platform_device *pdev)
8311
- host->present = host->pdata->card_present();
8312
+ host->present = host->pdata->card_present(mmc_dev(mmc));
8313
init_timer(&host->timer);
8314
host->timer.data = (unsigned long)host;
8315
host->timer.function = imxmci_check_status;
8316
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
8317
new file mode 100644
8318
index 0000000..a646921
8320
+++ b/drivers/mmc/host/mmc_spi.c
8323
+ * mmc_spi.c - Access SD/MMC cards through SPI master controllers
8325
+ * (C) Copyright 2005, Intec Automation,
8326
+ * Mike Lavender (mike@steroidmicros)
8327
+ * (C) Copyright 2006-2007, David Brownell
8328
+ * (C) Copyright 2007, Axis Communications,
8329
+ * Hans-Peter Nilsson (hp@axis.com)
8330
+ * (C) Copyright 2007, ATRON electronic GmbH,
8331
+ * Jan Nikitenko <jan.nikitenko@gmail.com>
8334
+ * This program is free software; you can redistribute it and/or modify
8335
+ * it under the terms of the GNU General Public License as published by
8336
+ * the Free Software Foundation; either version 2 of the License, or
8337
+ * (at your option) any later version.
8339
+ * This program is distributed in the hope that it will be useful,
8340
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
8341
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8342
+ * GNU General Public License for more details.
8344
+ * You should have received a copy of the GNU General Public License
8345
+ * along with this program; if not, write to the Free Software
8346
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
8348
+#include <linux/hrtimer.h>
8349
+#include <linux/delay.h>
8350
+#include <linux/bio.h>
8351
+#include <linux/dma-mapping.h>
8352
+#include <linux/crc7.h>
8353
+#include <linux/crc-itu-t.h>
8354
+#include <linux/scatterlist.h>
8356
+#include <linux/mmc/host.h>
8357
+#include <linux/mmc/mmc.h> /* for R1_SPI_* bit values */
8359
+#include <linux/spi/spi.h>
8360
+#include <linux/spi/mmc_spi.h>
8362
+#include <asm/unaligned.h>
8367
+ * - For now, we won't try to interoperate with a real mmc/sd/sdio
8368
+ * controller, although some of them do have hardware support for
8369
+ * SPI protocol. The main reason for such configs would be mmc-ish
8370
+ * cards like DataFlash, which don't support that "native" protocol.
8372
+ * We don't have a "DataFlash/MMC/SD/SDIO card slot" abstraction to
8373
+ * switch between driver stacks, and in any case if "native" mode
8374
+ * is available, it will be faster and hence preferable.
8376
+ * - MMC depends on a different chipselect management policy than the
8377
+ * SPI interface currently supports for shared bus segments: it needs
8378
+ * to issue multiple spi_message requests with the chipselect active,
8379
+ * using the results of one message to decide the next one to issue.
8381
+ * Pending updates to the programming interface, this driver expects
8382
+ * that it not share the bus with other drivers (precluding conflicts).
8384
+ * - We tell the controller to keep the chipselect active from the
8385
+ * beginning of an mmc_host_ops.request until the end. So beware
8386
+ * of SPI controller drivers that mis-handle the cs_change flag!
8388
+ * However, many cards seem OK with chipselect flapping up/down
8389
+ * during that time ... at least on unshared bus segments.
8394
+ * Local protocol constants, internal to data block protocols.
8397
+/* Response tokens used to ack each block written: */
8398
+#define SPI_MMC_RESPONSE_CODE(x) ((x) & 0x1f)
8399
+#define SPI_RESPONSE_ACCEPTED ((2 << 1)|1)
8400
+#define SPI_RESPONSE_CRC_ERR ((5 << 1)|1)
8401
+#define SPI_RESPONSE_WRITE_ERR ((6 << 1)|1)
8403
+/* Read and write blocks start with these tokens and end with crc;
8404
+ * on error, read tokens act like a subset of R2_SPI_* values.
8406
+#define SPI_TOKEN_SINGLE 0xfe /* single block r/w, multiblock read */
8407
+#define SPI_TOKEN_MULTI_WRITE 0xfc /* multiblock write */
8408
+#define SPI_TOKEN_STOP_TRAN 0xfd /* terminate multiblock write */
8410
+#define MMC_SPI_BLOCKSIZE 512
8413
+/* These fixed timeouts come from the latest SD specs, which say to ignore
8414
+ * the CSD values. The R1B value is for card erase (e.g. the "I forgot the
8415
+ * card's password" scenario); it's mostly applied to STOP_TRANSMISSION after
8416
+ * reads which takes nowhere near that long. Older cards may be able to use
8417
+ * shorter timeouts ... but why bother?
8419
+#define readblock_timeout ktime_set(0, 100 * 1000 * 1000)
8420
+#define writeblock_timeout ktime_set(0, 250 * 1000 * 1000)
8421
+#define r1b_timeout ktime_set(3, 0)
8424
+/****************************************************************************/
8427
+ * Local Data Structures
8430
+/* "scratch" is per-{command,block} data exchanged with the card */
8437
+struct mmc_spi_host {
8438
+ struct mmc_host *mmc;
8439
+ struct spi_device *spi;
8441
+ unsigned char power_mode;
8442
+ u16 powerup_msecs;
8444
+ struct mmc_spi_platform_data *pdata;
8446
+ /* for bulk data transfers */
8447
+ struct spi_transfer token, t, crc, early_status;
8448
+ struct spi_message m;
8450
+ /* for status readback */
8451
+ struct spi_transfer status;
8452
+ struct spi_message readback;
8454
+ /* underlying DMA-aware controller, or null */
8455
+ struct device *dma_dev;
8457
+ /* buffer used for commands and for message "overhead" */
8458
+ struct scratch *data;
8459
+ dma_addr_t data_dma;
8461
+ /* Specs say to write ones most of the time, even when the card
8462
+ * has no need to read its input data; and many cards won't care.
8463
+ * This is our source of those ones.
8466
+ dma_addr_t ones_dma;
8470
+/****************************************************************************/
8473
+ * MMC-over-SPI protocol glue, used by the MMC stack interface
8476
+static inline int mmc_cs_off(struct mmc_spi_host *host)
8478
+ /* chipselect will always be inactive after setup() */
8479
+ return spi_setup(host->spi);
8483
+mmc_spi_readbytes(struct mmc_spi_host *host, unsigned len)
8487
+ if (len > sizeof(*host->data)) {
8492
+ host->status.len = len;
8494
+ if (host->dma_dev)
8495
+ dma_sync_single_for_device(host->dma_dev,
8496
+ host->data_dma, sizeof(*host->data),
8499
+ status = spi_sync(host->spi, &host->readback);
8501
+ status = host->readback.status;
8503
+ if (host->dma_dev)
8504
+ dma_sync_single_for_cpu(host->dma_dev,
8505
+ host->data_dma, sizeof(*host->data),
8512
+mmc_spi_skip(struct mmc_spi_host *host, ktime_t timeout, unsigned n, u8 byte)
8514
+ u8 *cp = host->data->status;
8516
+ timeout = ktime_add(timeout, ktime_get());
8522
+ status = mmc_spi_readbytes(host, n);
8526
+ for (i = 0; i < n; i++) {
8527
+ if (cp[i] != byte)
8531
+ /* REVISIT investigate msleep() to avoid busy-wait I/O
8532
+ * in at least some cases.
8534
+ if (ktime_to_ns(ktime_sub(ktime_get(), timeout)) > 0)
8537
+ return -ETIMEDOUT;
8541
+mmc_spi_wait_unbusy(struct mmc_spi_host *host, ktime_t timeout)
8543
+ return mmc_spi_skip(host, timeout, sizeof(host->data->status), 0);
8546
+static int mmc_spi_readtoken(struct mmc_spi_host *host)
8548
+ return mmc_spi_skip(host, readblock_timeout, 1, 0xff);
8553
+ * Note that for SPI, cmd->resp[0] is not the same data as "native" protocol
8554
+ * hosts return! The low byte holds R1_SPI bits. The next byte may hold
8555
+ * R2_SPI bits ... for SEND_STATUS, or after data read errors.
8557
+ * cmd->resp[1] holds any four-byte response, for R3 (READ_OCR) and on
8558
+ * newer cards R7 (IF_COND).
8561
+static char *maptype(struct mmc_command *cmd)
8563
+ switch (mmc_spi_resp_type(cmd)) {
8564
+ case MMC_RSP_SPI_R1: return "R1";
8565
+ case MMC_RSP_SPI_R1B: return "R1B";
8566
+ case MMC_RSP_SPI_R2: return "R2/R5";
8567
+ case MMC_RSP_SPI_R3: return "R3/R4/R7";
8568
+ default: return "?";
8572
+/* return zero, else negative errno after setting cmd->error */
8573
+static int mmc_spi_response_get(struct mmc_spi_host *host,
8574
+ struct mmc_command *cmd, int cs_on)
8576
+ u8 *cp = host->data->status;
8577
+ u8 *end = cp + host->t.len;
8581
+ snprintf(tag, sizeof(tag), " ... CMD%d response SPI_%s",
8582
+ cmd->opcode, maptype(cmd));
8584
+ /* Except for data block reads, the whole response will already
8585
+ * be stored in the scratch buffer. It's somewhere after the
8586
+ * command and the first byte we read after it. We ignore that
8587
+ * first byte. After STOP_TRANSMISSION command it may include
8588
+ * two data bits, but otherwise it's all ones.
8591
+ while (cp < end && *cp == 0xff)
8594
+ /* Data block reads (R1 response types) may need more data... */
8598
+ cp = host->data->status;
8600
+ /* Card sends N(CR) (== 1..8) bytes of all-ones then one
8601
+ * status byte ... and we already scanned 2 bytes.
8603
+ * REVISIT block read paths use nasty byte-at-a-time I/O
8604
+ * so it can always DMA directly into the target buffer.
8605
+ * It'd probably be better to memcpy() the first chunk and
8606
+ * avoid extra i/o calls...
8608
+ for (i = 2; i < 9; i++) {
8609
+ value = mmc_spi_readbytes(host, 1);
8615
+ value = -ETIMEDOUT;
8621
+ dev_dbg(&host->spi->dev, "%s: INVALID RESPONSE, %02x\n",
8627
+ cmd->resp[0] = *cp++;
8630
+ /* Status byte: the entire seven-bit R1 response. */
8631
+ if (cmd->resp[0] != 0) {
8632
+ if ((R1_SPI_PARAMETER | R1_SPI_ADDRESS
8633
+ | R1_SPI_ILLEGAL_COMMAND)
8636
+ else if (R1_SPI_COM_CRC & cmd->resp[0])
8638
+ else if ((R1_SPI_ERASE_SEQ | R1_SPI_ERASE_RESET)
8641
+ /* else R1_SPI_IDLE, "it's resetting" */
8644
+ switch (mmc_spi_resp_type(cmd)) {
8646
+ /* SPI R1B == R1 + busy; STOP_TRANSMISSION (for multiblock reads)
8647
+ * and less-common stuff like various erase operations.
8649
+ case MMC_RSP_SPI_R1B:
8650
+ /* maybe we read all the busy tokens already */
8651
+ while (cp < end && *cp == 0)
8654
+ mmc_spi_wait_unbusy(host, r1b_timeout);
8657
+ /* SPI R2 == R1 + second status byte; SEND_STATUS
8658
+ * SPI R5 == R1 + data byte; IO_RW_DIRECT
8660
+ case MMC_RSP_SPI_R2:
8661
+ cmd->resp[0] |= *cp << 8;
8664
+ /* SPI R3, R4, or R7 == R1 + 4 bytes */
8665
+ case MMC_RSP_SPI_R3:
8666
+ cmd->resp[1] = be32_to_cpu(get_unaligned((u32 *)cp));
8669
+ /* SPI R1 == just one status byte */
8670
+ case MMC_RSP_SPI_R1:
8674
+ dev_dbg(&host->spi->dev, "bad response type %04x\n",
8675
+ mmc_spi_resp_type(cmd));
8682
+ dev_dbg(&host->spi->dev, "%s: resp %04x %08x\n",
8683
+ tag, cmd->resp[0], cmd->resp[1]);
8685
+ /* disable chipselect on errors and some success cases */
8686
+ if (value >= 0 && cs_on)
8690
+ cmd->error = value;
8695
+/* Issue command and read its response.
8696
+ * Returns zero on success, negative for error.
8698
+ * On error, caller must cope with mmc core retry mechanism. That
8699
+ * means immediate low-level resubmit, which affects the bus lock...
8702
+mmc_spi_command_send(struct mmc_spi_host *host,
8703
+ struct mmc_request *mrq,
8704
+ struct mmc_command *cmd, int cs_on)
8706
+ struct scratch *data = host->data;
8707
+ u8 *cp = data->status;
8708
+ u32 arg = cmd->arg;
8710
+ struct spi_transfer *t;
8712
+ /* We can handle most commands (except block reads) in one full
8713
+ * duplex I/O operation before either starting the next transfer
8714
+ * (data block or command) or else deselecting the card.
8716
+ * First, write 7 bytes:
8717
+ * - an all-ones byte to ensure the card is ready
8718
+ * - opcode byte (plus start and transmission bits)
8719
+ * - four bytes of big-endian argument
8720
+ * - crc7 (plus end bit) ... always computed, it's cheap
8722
+ * We init the whole buffer to all-ones, which is what we need
8723
+ * to write while we're reading (later) response data.
8725
+ memset(cp++, 0xff, sizeof(data->status));
8727
+ *cp++ = 0x40 | cmd->opcode;
8728
+ *cp++ = (u8)(arg >> 24);
8729
+ *cp++ = (u8)(arg >> 16);
8730
+ *cp++ = (u8)(arg >> 8);
8732
+ *cp++ = (crc7(0, &data->status[1], 5) << 1) | 0x01;
8734
+ /* Then, read up to 13 bytes (while writing all-ones):
8735
+ * - N(CR) (== 1..8) bytes of all-ones
8736
+ * - status byte (for all response types)
8737
+ * - the rest of the response, either:
8738
+ * + nothing, for R1 or R1B responses
8739
+ * + second status byte, for R2 responses
8740
+ * + four data bytes, for R3 and R7 responses
8742
+ * Finally, read some more bytes ... in the nice cases we know in
8743
+ * advance how many, and reading 1 more is always OK:
8744
+ * - N(EC) (== 0..N) bytes of all-ones, before deselect/finish
8745
+ * - N(RC) (== 1..N) bytes of all-ones, before next command
8746
+ * - N(WR) (== 1..N) bytes of all-ones, before data write
8748
+ * So in those cases one full duplex I/O of at most 21 bytes will
8749
+ * handle the whole command, leaving the card ready to receive a
8750
+ * data block or new command. We do that whenever we can, shaving
8751
+ * CPU and IRQ costs (especially when using DMA or FIFOs).
8753
+ * There are two other cases, where it's not generally practical
8754
+ * to rely on a single I/O:
8756
+ * - R1B responses need at least N(EC) bytes of all-zeroes.
8758
+ * In this case we can *try* to fit it into one I/O, then
8759
+ * maybe read more data later.
8761
+ * - Data block reads are more troublesome, since a variable
8762
+ * number of padding bytes precede the token and data.
8763
+ * + N(CX) (== 0..8) bytes of all-ones, before CSD or CID
8764
+ * + N(AC) (== 1..many) bytes of all-ones
8766
+ * In this case we currently only have minimal speedups here:
8767
+ * when N(CR) == 1 we can avoid I/O in response_get().
8769
+ if (cs_on && (mrq->data->flags & MMC_DATA_READ)) {
8770
+ cp += 2; /* min(N(CR)) + status */
8773
+ cp += 10; /* max(N(CR)) + status + min(N(RC),N(WR)) */
8774
+ if (cmd->flags & MMC_RSP_SPI_S2) /* R2/R5 */
8776
+ else if (cmd->flags & MMC_RSP_SPI_B4) /* R3/R4/R7 */
8778
+ else if (cmd->flags & MMC_RSP_BUSY) /* R1B */
8779
+ cp = data->status + sizeof(data->status);
8780
+ /* else: R1 (most commands) */
8783
+ dev_dbg(&host->spi->dev, " mmc_spi: CMD%d, resp %s\n",
8784
+ cmd->opcode, maptype(cmd));
8786
+ /* send command, leaving chipselect active */
8787
+ spi_message_init(&host->m);
8790
+ memset(t, 0, sizeof(*t));
8791
+ t->tx_buf = t->rx_buf = data->status;
8792
+ t->tx_dma = t->rx_dma = host->data_dma;
8793
+ t->len = cp - data->status;
8795
+ spi_message_add_tail(t, &host->m);
8797
+ if (host->dma_dev) {
8798
+ host->m.is_dma_mapped = 1;
8799
+ dma_sync_single_for_device(host->dma_dev,
8800
+ host->data_dma, sizeof(*host->data),
8801
+ DMA_BIDIRECTIONAL);
8803
+ status = spi_sync(host->spi, &host->m);
8805
+ status = host->m.status;
8807
+ if (host->dma_dev)
8808
+ dma_sync_single_for_cpu(host->dma_dev,
8809
+ host->data_dma, sizeof(*host->data),
8810
+ DMA_BIDIRECTIONAL);
8812
+ dev_dbg(&host->spi->dev, " ... write returned %d\n", status);
8813
+ cmd->error = status;
8817
+ /* after no-data commands and STOP_TRANSMISSION, chipselect off */
8818
+ return mmc_spi_response_get(host, cmd, cs_on);
8821
+/* Build data message with up to four separate transfers. For TX, we
8822
+ * start by writing the data token. And in most cases, we finish with
8823
+ * a status transfer.
8825
+ * We always provide TX data for data and CRC. The MMC/SD protocol
8826
+ * requires us to write ones; but Linux defaults to writing zeroes;
8827
+ * so we explicitly initialize it to all ones on RX paths.
8829
+ * We also handle DMA mapping, so the underlying SPI controller does
8830
+ * not need to (re)do it for each message.
8833
+mmc_spi_setup_data_message(
8834
+ struct mmc_spi_host *host,
8836
+ enum dma_data_direction direction)
8838
+ struct spi_transfer *t;
8839
+ struct scratch *scratch = host->data;
8840
+ dma_addr_t dma = host->data_dma;
8842
+ spi_message_init(&host->m);
8844
+ host->m.is_dma_mapped = 1;
8846
+ /* for reads, readblock() skips 0xff bytes before finding
8847
+ * the token; for writes, this transfer issues that token.
8849
+ if (direction == DMA_TO_DEVICE) {
8851
+ memset(t, 0, sizeof(*t));
8854
+ scratch->data_token = SPI_TOKEN_MULTI_WRITE;
8856
+ scratch->data_token = SPI_TOKEN_SINGLE;
8857
+ t->tx_buf = &scratch->data_token;
8859
+ t->tx_dma = dma + offsetof(struct scratch, data_token);
8860
+ spi_message_add_tail(t, &host->m);
8863
+ /* Body of transfer is buffer, then CRC ...
8864
+ * either TX-only, or RX with TX-ones.
8867
+ memset(t, 0, sizeof(*t));
8868
+ t->tx_buf = host->ones;
8869
+ t->tx_dma = host->ones_dma;
8870
+ /* length and actual buffer info are written later */
8871
+ spi_message_add_tail(t, &host->m);
8874
+ memset(t, 0, sizeof(*t));
8876
+ if (direction == DMA_TO_DEVICE) {
8877
+ /* the actual CRC may get written later */
8878
+ t->tx_buf = &scratch->crc_val;
8880
+ t->tx_dma = dma + offsetof(struct scratch, crc_val);
8882
+ t->tx_buf = host->ones;
8883
+ t->tx_dma = host->ones_dma;
8884
+ t->rx_buf = &scratch->crc_val;
8886
+ t->rx_dma = dma + offsetof(struct scratch, crc_val);
8888
+ spi_message_add_tail(t, &host->m);
8891
+ * A single block read is followed by N(EC) [0+] all-ones bytes
8892
+ * before deselect ... don't bother.
8894
+ * Multiblock reads are followed by N(AC) [1+] all-ones bytes before
8895
+ * the next block is read, or a STOP_TRANSMISSION is issued. We'll
8896
+ * collect that single byte, so readblock() doesn't need to.
8898
+ * For a write, the one-byte data response follows immediately, then
8899
+ * come zero or more busy bytes, then N(WR) [1+] all-ones bytes.
8900
+ * Then single block reads may deselect, and multiblock ones issue
8901
+ * the next token (next data block, or STOP_TRAN). We can try to
8902
+ * minimize I/O ops by using a single read to collect end-of-busy.
8904
+ if (multiple || direction == DMA_TO_DEVICE) {
8905
+ t = &host->early_status;
8906
+ memset(t, 0, sizeof(*t));
8907
+ t->len = (direction == DMA_TO_DEVICE)
8908
+ ? sizeof(scratch->status)
8910
+ t->tx_buf = host->ones;
8911
+ t->tx_dma = host->ones_dma;
8912
+ t->rx_buf = scratch->status;
8914
+ t->rx_dma = dma + offsetof(struct scratch, status);
8916
+ spi_message_add_tail(t, &host->m);
8921
+ * Write one block:
8922
+ * - caller handled preceding N(WR) [1+] all-ones bytes
8927
+ * - an all-ones byte ... card writes a data-response byte
8928
+ * - followed by N(EC) [0+] all-ones bytes, card writes zero/'busy'
8930
+ * Return negative errno, else success.
8933
+mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t)
8935
+ struct spi_device *spi = host->spi;
8937
+ struct scratch *scratch = host->data;
8939
+ if (host->mmc->use_spi_crc)
8940
+ scratch->crc_val = cpu_to_be16(
8941
+ crc_itu_t(0, t->tx_buf, t->len));
8942
+ if (host->dma_dev)
8943
+ dma_sync_single_for_device(host->dma_dev,
8944
+ host->data_dma, sizeof(*scratch),
8945
+ DMA_BIDIRECTIONAL);
8947
+ status = spi_sync(spi, &host->m);
8949
+ status = host->m.status;
8951
+ if (status != 0) {
8952
+ dev_dbg(&spi->dev, "write error (%d)\n", status);
8956
+ if (host->dma_dev)
8957
+ dma_sync_single_for_cpu(host->dma_dev,
8958
+ host->data_dma, sizeof(*scratch),
8959
+ DMA_BIDIRECTIONAL);
8962
+ * Get the transmission data-response reply. It must follow
8963
+ * immediately after the data block we transferred. This reply
8964
+ * doesn't necessarily tell whether the write operation succeeded;
8965
+ * it just says if the transmission was ok and whether *earlier*
8966
+ * writes succeeded; see the standard.
8968
+ switch (SPI_MMC_RESPONSE_CODE(scratch->status[0])) {
8969
+ case SPI_RESPONSE_ACCEPTED:
8972
+ case SPI_RESPONSE_CRC_ERR:
8973
+ /* host shall then issue MMC_STOP_TRANSMISSION */
8976
+ case SPI_RESPONSE_WRITE_ERR:
8977
+ /* host shall then issue MMC_STOP_TRANSMISSION,
8978
+ * and should MMC_SEND_STATUS to sort it out
8986
+ if (status != 0) {
8987
+ dev_dbg(&spi->dev, "write error %02x (%d)\n",
8988
+ scratch->status[0], status);
8992
+ t->tx_buf += t->len;
8993
+ if (host->dma_dev)
8994
+ t->tx_dma += t->len;
8996
+ /* Return when not busy. If we didn't collect that status yet,
8997
+ * we'll need some more I/O.
8999
+ for (i = 1; i < sizeof(scratch->status); i++) {
9000
+ if (scratch->status[i] != 0)
9003
+ return mmc_spi_wait_unbusy(host, writeblock_timeout);
9008
+ * - skip leading all-ones bytes ... either
9009
+ * + N(AC) [1..f(clock,CSD)] usually, else
9010
+ * + N(CX) [0..8] when reading CSD or CID
9012
+ * + token ... if error token, no data or crc
9016
+ * After single block reads, we're done; N(EC) [0+] all-ones bytes follow
9017
+ * before dropping chipselect.
9019
+ * For multiblock reads, caller either reads the next block or issues a
9020
+ * STOP_TRANSMISSION command.
9023
+mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t)
9025
+ struct spi_device *spi = host->spi;
9027
+ struct scratch *scratch = host->data;
9029
+ /* At least one SD card sends an all-zeroes byte when N(CX)
9030
+ * applies, before the all-ones bytes ... just cope with that.
9032
+ status = mmc_spi_readbytes(host, 1);
9035
+ status = scratch->status[0];
9036
+ if (status == 0xff || status == 0)
9037
+ status = mmc_spi_readtoken(host);
9039
+ if (status == SPI_TOKEN_SINGLE) {
9040
+ if (host->dma_dev) {
9041
+ dma_sync_single_for_device(host->dma_dev,
9042
+ host->data_dma, sizeof(*scratch),
9043
+ DMA_BIDIRECTIONAL);
9044
+ dma_sync_single_for_device(host->dma_dev,
9045
+ t->rx_dma, t->len,
9049
+ status = spi_sync(spi, &host->m);
9051
+ status = host->m.status;
9053
+ if (host->dma_dev) {
9054
+ dma_sync_single_for_cpu(host->dma_dev,
9055
+ host->data_dma, sizeof(*scratch),
9056
+ DMA_BIDIRECTIONAL);
9057
+ dma_sync_single_for_cpu(host->dma_dev,
9058
+ t->rx_dma, t->len,
9063
+ dev_dbg(&spi->dev, "read error %02x (%d)\n", status, status);
9065
+ /* we've read extra garbage, timed out, etc */
9069
+ /* low four bits are an R2 subset, fifth seems to be
9070
+ * vendor specific ... map them all to generic error..
9075
+ if (host->mmc->use_spi_crc) {
9076
+ u16 crc = crc_itu_t(0, t->rx_buf, t->len);
9078
+ be16_to_cpus(&scratch->crc_val);
9079
+ if (scratch->crc_val != crc) {
9080
+ dev_dbg(&spi->dev, "read - crc error: crc_val=0x%04x, "
9081
+ "computed=0x%04x len=%d\n",
9082
+ scratch->crc_val, crc, t->len);
9087
+ t->rx_buf += t->len;
9088
+ if (host->dma_dev)
9089
+ t->rx_dma += t->len;
9095
+ * An MMC/SD data stage includes one or more blocks, optional CRCs,
9096
+ * and inline handshaking. That handhaking makes it unlike most
9097
+ * other SPI protocol stacks.
9100
+mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
9101
+ struct mmc_data *data, u32 blk_size)
9103
+ struct spi_device *spi = host->spi;
9104
+ struct device *dma_dev = host->dma_dev;
9105
+ struct spi_transfer *t;
9106
+ enum dma_data_direction direction;
9107
+ struct scatterlist *sg;
9109
+ int multiple = (data->blocks > 1);
9111
+ if (data->flags & MMC_DATA_READ)
9112
+ direction = DMA_FROM_DEVICE;
9114
+ direction = DMA_TO_DEVICE;
9115
+ mmc_spi_setup_data_message(host, multiple, direction);
9118
+ /* Handle scatterlist segments one at a time, with synch for
9119
+ * each 512-byte block
9121
+ for (sg = data->sg, n_sg = data->sg_len; n_sg; n_sg--, sg++) {
9123
+ dma_addr_t dma_addr = 0;
9125
+ unsigned length = sg->length;
9126
+ enum dma_data_direction dir = direction;
9128
+ /* set up dma mapping for controller drivers that might
9129
+ * use DMA ... though they may fall back to PIO
9132
+ /* never invalidate whole *shared* pages ... */
9133
+ if ((sg->offset != 0 || length != PAGE_SIZE)
9134
+ && dir == DMA_FROM_DEVICE)
9135
+ dir = DMA_BIDIRECTIONAL;
9137
+ dma_addr = dma_map_page(dma_dev, sg_page(sg), 0,
9139
+ if (direction == DMA_TO_DEVICE)
9140
+ t->tx_dma = dma_addr + sg->offset;
9142
+ t->rx_dma = dma_addr + sg->offset;
9145
+ /* allow pio too; we don't allow highmem */
9146
+ kmap_addr = kmap(sg_page(sg));
9147
+ if (direction == DMA_TO_DEVICE)
9148
+ t->tx_buf = kmap_addr + sg->offset;
9150
+ t->rx_buf = kmap_addr + sg->offset;
9152
+ /* transfer each block, and update request status */
9154
+ t->len = min(length, blk_size);
9156
+ dev_dbg(&host->spi->dev,
9157
+ " mmc_spi: %s block, %d bytes\n",
9158
+ (direction == DMA_TO_DEVICE)
9163
+ if (direction == DMA_TO_DEVICE)
9164
+ status = mmc_spi_writeblock(host, t);
9166
+ status = mmc_spi_readblock(host, t);
9170
+ data->bytes_xfered += t->len;
9177
+ /* discard mappings */
9178
+ if (direction == DMA_FROM_DEVICE)
9179
+ flush_kernel_dcache_page(sg_page(sg));
9180
+ kunmap(sg_page(sg));
9182
+ dma_unmap_page(dma_dev, dma_addr, PAGE_SIZE, dir);
9185
+ data->error = status;
9186
+ dev_dbg(&spi->dev, "%s status %d\n",
9187
+ (direction == DMA_TO_DEVICE)
9188
+ ? "write" : "read",
9194
+ /* NOTE some docs describe an MMC-only SET_BLOCK_COUNT (CMD23) that
9195
+ * can be issued before multiblock writes. Unlike its more widely
9196
+ * documented analogue for SD cards (SET_WR_BLK_ERASE_COUNT, ACMD23),
9197
+ * that can affect the STOP_TRAN logic. Complete (and current)
9198
+ * MMC specs should sort that out before Linux starts using CMD23.
9200
+ if (direction == DMA_TO_DEVICE && multiple) {
9201
+ struct scratch *scratch = host->data;
9203
+ const unsigned statlen = sizeof(scratch->status);
9205
+ dev_dbg(&spi->dev, " mmc_spi: STOP_TRAN\n");
9207
+ /* Tweak the per-block message we set up earlier by morphing
9208
+ * it to hold single buffer with the token followed by some
9209
+ * all-ones bytes ... skip N(BR) (0..1), scan the rest for
9210
+ * "not busy any longer" status, and leave chip selected.
9212
+ INIT_LIST_HEAD(&host->m.transfers);
9213
+ list_add(&host->early_status.transfer_list,
9214
+ &host->m.transfers);
9216
+ memset(scratch->status, 0xff, statlen);
9217
+ scratch->status[0] = SPI_TOKEN_STOP_TRAN;
9219
+ host->early_status.tx_buf = host->early_status.rx_buf;
9220
+ host->early_status.tx_dma = host->early_status.rx_dma;
9221
+ host->early_status.len = statlen;
9223
+ if (host->dma_dev)
9224
+ dma_sync_single_for_device(host->dma_dev,
9225
+ host->data_dma, sizeof(*scratch),
9226
+ DMA_BIDIRECTIONAL);
9228
+ tmp = spi_sync(spi, &host->m);
9230
+ tmp = host->m.status;
9232
+ if (host->dma_dev)
9233
+ dma_sync_single_for_cpu(host->dma_dev,
9234
+ host->data_dma, sizeof(*scratch),
9235
+ DMA_BIDIRECTIONAL);
9239
+ data->error = tmp;
9243
+ /* Ideally we collected "not busy" status with one I/O,
9244
+ * avoiding wasteful byte-at-a-time scanning... but more
9245
+ * I/O is often needed.
9247
+ for (tmp = 2; tmp < statlen; tmp++) {
9248
+ if (scratch->status[tmp] != 0)
9251
+ tmp = mmc_spi_wait_unbusy(host, writeblock_timeout);
9252
+ if (tmp < 0 && !data->error)
9253
+ data->error = tmp;
9257
+/****************************************************************************/
9260
+ * MMC driver implementation -- the interface to the MMC stack
9263
+static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
9265
+ struct mmc_spi_host *host = mmc_priv(mmc);
9266
+ int status = -EINVAL;
9269
+ /* MMC core and layered drivers *MUST* issue SPI-aware commands */
9271
+ struct mmc_command *cmd;
9275
+ if (!mmc_spi_resp_type(cmd)) {
9276
+ dev_dbg(&host->spi->dev, "bogus command\n");
9277
+ cmd->error = -EINVAL;
9282
+ if (cmd && !mmc_spi_resp_type(cmd)) {
9283
+ dev_dbg(&host->spi->dev, "bogus STOP command\n");
9284
+ cmd->error = -EINVAL;
9290
+ mmc_request_done(host->mmc, mrq);
9296
+ /* issue command; then optionally data and stop */
9297
+ status = mmc_spi_command_send(host, mrq, mrq->cmd, mrq->data != NULL);
9298
+ if (status == 0 && mrq->data) {
9299
+ mmc_spi_data_do(host, mrq->cmd, mrq->data, mrq->data->blksz);
9301
+ status = mmc_spi_command_send(host, mrq, mrq->stop, 0);
9306
+ mmc_request_done(host->mmc, mrq);
9309
+/* See Section 6.4.1, in SD "Simplified Physical Layer Specification 2.0"
9311
+ * NOTE that here we can't know that the card has just been powered up;
9312
+ * not all MMC/SD sockets support power switching.
9314
+ * FIXME when the card is still in SPI mode, e.g. from a previous kernel,
9315
+ * this doesn't seem to do the right thing at all...
9317
+static void mmc_spi_initsequence(struct mmc_spi_host *host)
9319
+ /* Try to be very sure any previous command has completed;
9320
+ * wait till not-busy, skip debris from any old commands.
9322
+ mmc_spi_wait_unbusy(host, r1b_timeout);
9323
+ mmc_spi_readbytes(host, 10);
9326
+ * Do a burst with chipselect active-high. We need to do this to
9327
+ * meet the requirement of 74 clock cycles with both chipselect
9328
+ * and CMD (MOSI) high before CMD0 ... after the card has been
9329
+ * powered up to Vdd(min), and so is ready to take commands.
9331
+ * Some cards are particularly needy of this (e.g. Viking "SD256")
9332
+ * while most others don't seem to care.
9334
+ * Note that this is one of the places MMC/SD plays games with the
9335
+ * SPI protocol. Another is that when chipselect is released while
9336
+ * the card returns BUSY status, the clock must issue several cycles
9337
+ * with chipselect high before the card will stop driving its output.
9339
+ host->spi->mode |= SPI_CS_HIGH;
9340
+ if (spi_setup(host->spi) != 0) {
9341
+ /* Just warn; most cards work without it. */
9342
+ dev_warn(&host->spi->dev,
9343
+ "can't change chip-select polarity\n");
9344
+ host->spi->mode &= ~SPI_CS_HIGH;
9346
+ mmc_spi_readbytes(host, 18);
9348
+ host->spi->mode &= ~SPI_CS_HIGH;
9349
+ if (spi_setup(host->spi) != 0) {
9350
+ /* Wot, we can't get the same setup we had before? */
9351
+ dev_err(&host->spi->dev,
9352
+ "can't restore chip-select polarity\n");
9357
+static char *mmc_powerstring(u8 power_mode)
9359
+ switch (power_mode) {
9360
+ case MMC_POWER_OFF: return "off";
9361
+ case MMC_POWER_UP: return "up";
9362
+ case MMC_POWER_ON: return "on";
9367
+static void mmc_spi_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
9369
+ struct mmc_spi_host *host = mmc_priv(mmc);
9371
+ if (host->power_mode != ios->power_mode) {
9374
+ canpower = host->pdata && host->pdata->setpower;
9376
+ dev_dbg(&host->spi->dev, "mmc_spi: power %s (%d)%s\n",
9377
+ mmc_powerstring(ios->power_mode),
9379
+ canpower ? ", can switch" : "");
9381
+ /* switch power on/off if possible, accounting for
9382
+ * max 250msec powerup time if needed.
9385
+ switch (ios->power_mode) {
9386
+ case MMC_POWER_OFF:
9387
+ case MMC_POWER_UP:
9388
+ host->pdata->setpower(&host->spi->dev,
9390
+ if (ios->power_mode == MMC_POWER_UP)
9391
+ msleep(host->powerup_msecs);
9395
+ /* See 6.4.1 in the simplified SD card physical spec 2.0 */
9396
+ if (ios->power_mode == MMC_POWER_ON)
9397
+ mmc_spi_initsequence(host);
9399
+ /* If powering down, ground all card inputs to avoid power
9400
+ * delivery from data lines! On a shared SPI bus, this
9401
+ * will probably be temporary; 6.4.2 of the simplified SD
9402
+ * spec says this must last at least 1msec.
9404
+ * - Clock low means CPOL 0, e.g. mode 0
9405
+ * - MOSI low comes from writing zero
9406
+ * - Chipselect is usually active low...
9408
+ if (canpower && ios->power_mode == MMC_POWER_OFF) {
9411
+ host->spi->mode &= ~(SPI_CPOL|SPI_CPHA);
9412
+ mres = spi_setup(host->spi);
9414
+ dev_dbg(&host->spi->dev,
9415
+ "switch to SPI mode 0 failed\n");
9417
+ if (spi_w8r8(host->spi, 0x00) < 0)
9418
+ dev_dbg(&host->spi->dev,
9419
+ "put spi signals to low failed\n");
9422
+ * Now clock should be low due to spi mode 0;
9423
+ * MOSI should be low because of written 0x00;
9424
+ * chipselect should be low (it is active low)
9425
+ * power supply is off, so now MMC is off too!
9427
+ * FIXME no, chipselect can be high since the
9428
+ * device is inactive and SPI_CS_HIGH is clear...
9432
+ host->spi->mode |= (SPI_CPOL|SPI_CPHA);
9433
+ mres = spi_setup(host->spi);
9435
+ dev_dbg(&host->spi->dev,
9436
+ "switch back to SPI mode 3"
9441
+ host->power_mode = ios->power_mode;
9444
+ if (host->spi->max_speed_hz != ios->clock && ios->clock != 0) {
9447
+ host->spi->max_speed_hz = ios->clock;
9448
+ status = spi_setup(host->spi);
9449
+ dev_dbg(&host->spi->dev,
9450
+ "mmc_spi: clock to %d Hz, %d\n",
9451
+ host->spi->max_speed_hz, status);
9455
+static int mmc_spi_get_ro(struct mmc_host *mmc)
9457
+ struct mmc_spi_host *host = mmc_priv(mmc);
9459
+ if (host->pdata && host->pdata->get_ro)
9460
+ return host->pdata->get_ro(mmc->parent);
9461
+ /* board doesn't support read only detection; assume writeable */
9466
+static const struct mmc_host_ops mmc_spi_ops = {
9467
+ .request = mmc_spi_request,
9468
+ .set_ios = mmc_spi_set_ios,
9469
+ .get_ro = mmc_spi_get_ro,
9473
+/****************************************************************************/
9476
+ * SPI driver implementation
9480
+mmc_spi_detect_irq(int irq, void *mmc)
9482
+ struct mmc_spi_host *host = mmc_priv(mmc);
9483
+ u16 delay_msec = max(host->pdata->detect_delay, (u16)100);
9485
+ mmc_detect_change(mmc, msecs_to_jiffies(delay_msec));
9486
+ return IRQ_HANDLED;
9489
+struct count_children {
9491
+ struct bus_type *bus;
9494
+static int maybe_count_child(struct device *dev, void *c)
9496
+ struct count_children *ccp = c;
9498
+ if (dev->bus == ccp->bus) {
9506
+static int mmc_spi_probe(struct spi_device *spi)
9509
+ struct mmc_host *mmc;
9510
+ struct mmc_spi_host *host;
9513
+ /* MMC and SD specs only seem to care that sampling is on the
9514
+ * rising edge ... meaning SPI modes 0 or 3. So either SPI mode
9515
+ * should be legit. We'll use mode 0 since it seems to be a
9516
+ * bit less troublesome on some hardware ... unclear why.
9518
+ spi->mode = SPI_MODE_0;
9519
+ spi->bits_per_word = 8;
9521
+ status = spi_setup(spi);
9523
+ dev_dbg(&spi->dev, "needs SPI mode %02x, %d KHz; %d\n",
9524
+ spi->mode, spi->max_speed_hz / 1000,
9529
+ /* We can use the bus safely iff nobody else will interfere with us.
9530
+ * Most commands consist of one SPI message to issue a command, then
9531
+ * several more to collect its response, then possibly more for data
9532
+ * transfer. Clocking access to other devices during that period will
9533
+ * corrupt the command execution.
9535
+ * Until we have software primitives which guarantee non-interference,
9536
+ * we'll aim for a hardware-level guarantee.
9538
+ * REVISIT we can't guarantee another device won't be added later...
9540
+ if (spi->master->num_chipselect > 1) {
9541
+ struct count_children cc;
9544
+ cc.bus = spi->dev.bus;
9545
+ status = device_for_each_child(spi->dev.parent, &cc,
9546
+ maybe_count_child);
9548
+ dev_err(&spi->dev, "can't share SPI bus\n");
9552
+ dev_warn(&spi->dev, "ASSUMING SPI bus stays unshared!\n");
9555
+ /* We need a supply of ones to transmit. This is the only time
9556
+ * the CPU touches these, so cache coherency isn't a concern.
9558
+ * NOTE if many systems use more than one MMC-over-SPI connector
9559
+ * it'd save some memory to share this. That's evidently rare.
9562
+ ones = kmalloc(MMC_SPI_BLOCKSIZE, GFP_KERNEL);
9565
+ memset(ones, 0xff, MMC_SPI_BLOCKSIZE);
9567
+ mmc = mmc_alloc_host(sizeof(*host), &spi->dev);
9571
+ mmc->ops = &mmc_spi_ops;
9572
+ mmc->max_blk_size = MMC_SPI_BLOCKSIZE;
9574
+ /* As long as we keep track of the number of successfully
9575
+ * transmitted blocks, we're good for multiwrite.
9577
+ mmc->caps = MMC_CAP_SPI | MMC_CAP_MULTIWRITE;
9579
+ /* SPI doesn't need the lowspeed device identification thing for
9580
+ * MMC or SD cards, since it never comes up in open drain mode.
9581
+ * That's good; some SPI masters can't handle very low speeds!
9583
+ * However, low speed SDIO cards need not handle over 400 KHz;
9584
+ * that's the only reason not to use a few MHz for f_min (until
9585
+ * the upper layer reads the target frequency from the CSD).
9587
+ mmc->f_min = 400000;
9588
+ mmc->f_max = spi->max_speed_hz;
9590
+ host = mmc_priv(mmc);
9594
+ host->ones = ones;
9596
+ /* Platform data is used to hook up things like card sensing
9597
+ * and power switching gpios.
9599
+ host->pdata = spi->dev.platform_data;
9601
+ mmc->ocr_avail = host->pdata->ocr_mask;
9602
+ if (!mmc->ocr_avail) {
9603
+ dev_warn(&spi->dev, "ASSUMING 3.2-3.4 V slot power\n");
9604
+ mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34;
9606
+ if (host->pdata && host->pdata->setpower) {
9607
+ host->powerup_msecs = host->pdata->powerup_msecs;
9608
+ if (!host->powerup_msecs || host->powerup_msecs > 250)
9609
+ host->powerup_msecs = 250;
9612
+ dev_set_drvdata(&spi->dev, mmc);
9614
+ /* preallocate dma buffers */
9615
+ host->data = kmalloc(sizeof(*host->data), GFP_KERNEL);
9619
+ if (spi->master->dev.parent->dma_mask) {
9620
+ struct device *dev = spi->master->dev.parent;
9622
+ host->dma_dev = dev;
9623
+ host->ones_dma = dma_map_single(dev, ones,
9624
+ MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
9625
+ host->data_dma = dma_map_single(dev, host->data,
9626
+ sizeof(*host->data), DMA_BIDIRECTIONAL);
9628
+ /* REVISIT in theory those map operations can fail... */
9630
+ dma_sync_single_for_cpu(host->dma_dev,
9631
+ host->data_dma, sizeof(*host->data),
9632
+ DMA_BIDIRECTIONAL);
9635
+ /* setup message for status/busy readback */
9636
+ spi_message_init(&host->readback);
9637
+ host->readback.is_dma_mapped = (host->dma_dev != NULL);
9639
+ spi_message_add_tail(&host->status, &host->readback);
9640
+ host->status.tx_buf = host->ones;
9641
+ host->status.tx_dma = host->ones_dma;
9642
+ host->status.rx_buf = &host->data->status;
9643
+ host->status.rx_dma = host->data_dma + offsetof(struct scratch, status);
9644
+ host->status.cs_change = 1;
9646
+ /* register card detect irq */
9647
+ if (host->pdata && host->pdata->init) {
9648
+ status = host->pdata->init(&spi->dev, mmc_spi_detect_irq, mmc);
9650
+ goto fail_glue_init;
9653
+ status = mmc_add_host(mmc);
9655
+ goto fail_add_host;
9657
+ dev_info(&spi->dev, "SD/MMC host %s%s%s%s\n",
9658
+ mmc->class_dev.bus_id,
9659
+ host->dma_dev ? "" : ", no DMA",
9660
+ (host->pdata && host->pdata->get_ro)
9662
+ (host->pdata && host->pdata->setpower)
9663
+ ? "" : ", no poweroff");
9667
+ mmc_remove_host (mmc);
9669
+ if (host->dma_dev)
9670
+ dma_unmap_single(host->dma_dev, host->data_dma,
9671
+ sizeof(*host->data), DMA_BIDIRECTIONAL);
9672
+ kfree(host->data);
9675
+ mmc_free_host(mmc);
9676
+ dev_set_drvdata(&spi->dev, NULL);
9684
+static int __devexit mmc_spi_remove(struct spi_device *spi)
9686
+ struct mmc_host *mmc = dev_get_drvdata(&spi->dev);
9687
+ struct mmc_spi_host *host;
9690
+ host = mmc_priv(mmc);
9692
+ /* prevent new mmc_detect_change() calls */
9693
+ if (host->pdata && host->pdata->exit)
9694
+ host->pdata->exit(&spi->dev, mmc);
9696
+ mmc_remove_host(mmc);
9698
+ if (host->dma_dev) {
9699
+ dma_unmap_single(host->dma_dev, host->ones_dma,
9700
+ MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
9701
+ dma_unmap_single(host->dma_dev, host->data_dma,
9702
+ sizeof(*host->data), DMA_BIDIRECTIONAL);
9705
+ kfree(host->data);
9706
+ kfree(host->ones);
9708
+ spi->max_speed_hz = mmc->f_max;
9709
+ mmc_free_host(mmc);
9710
+ dev_set_drvdata(&spi->dev, NULL);
9716
+static struct spi_driver mmc_spi_driver = {
9718
+ .name = "mmc_spi",
9719
+ .bus = &spi_bus_type,
9720
+ .owner = THIS_MODULE,
9722
+ .probe = mmc_spi_probe,
9723
+ .remove = __devexit_p(mmc_spi_remove),
9727
+static int __init mmc_spi_init(void)
9729
+ return spi_register_driver(&mmc_spi_driver);
9731
+module_init(mmc_spi_init);
9734
+static void __exit mmc_spi_exit(void)
9736
+ spi_unregister_driver(&mmc_spi_driver);
9738
+module_exit(mmc_spi_exit);
9741
+MODULE_AUTHOR("Mike Lavender, David Brownell, "
9742
+ "Hans-Peter Nilsson, Jan Nikitenko");
9743
+MODULE_DESCRIPTION("SPI SD/MMC host driver");
9744
+MODULE_LICENSE("GPL");
9745
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
9746
index d11c2d2..95244a7 100644
9747
--- a/drivers/mmc/host/mmci.c
9748
+++ b/drivers/mmc/host/mmci.c
9751
- * linux/drivers/mmc/mmci.c - ARM PrimeCell MMCI PL180/1 driver
9752
+ * linux/drivers/mmc/host/mmci.c - ARM PrimeCell MMCI PL180/1 driver
9754
* Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
9757
#include <linux/delay.h>
9758
#include <linux/err.h>
9759
#include <linux/highmem.h>
9760
+#include <linux/log2.h>
9761
#include <linux/mmc/host.h>
9762
#include <linux/amba/bus.h>
9763
#include <linux/clk.h>
9764
+#include <linux/scatterlist.h>
9766
#include <asm/cacheflush.h>
9767
#include <asm/div64.h>
9769
-#include <asm/scatterlist.h>
9770
#include <asm/sizes.h>
9771
#include <asm/mach/mmc.h>
9773
@@ -154,11 +155,11 @@ mmci_data_irq(struct mmci_host *host, struct mmc_data *data,
9775
if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_TXUNDERRUN|MCI_RXOVERRUN)) {
9776
if (status & MCI_DATACRCFAIL)
9777
- data->error = MMC_ERR_BADCRC;
9778
+ data->error = -EILSEQ;
9779
else if (status & MCI_DATATIMEOUT)
9780
- data->error = MMC_ERR_TIMEOUT;
9781
+ data->error = -ETIMEDOUT;
9782
else if (status & (MCI_TXUNDERRUN|MCI_RXOVERRUN))
9783
- data->error = MMC_ERR_FIFO;
9784
+ data->error = -EIO;
9785
status |= MCI_DATAEND;
9788
@@ -166,7 +167,7 @@ mmci_data_irq(struct mmci_host *host, struct mmc_data *data,
9789
* partially written to a page is properly coherent.
9791
if (host->sg_len && data->flags & MMC_DATA_READ)
9792
- flush_dcache_page(host->sg_ptr->page);
9793
+ flush_dcache_page(sg_page(host->sg_ptr));
9795
if (status & MCI_DATAEND) {
9796
mmci_stop_data(host);
9797
@@ -193,12 +194,12 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd,
9798
cmd->resp[3] = readl(base + MMCIRESPONSE3);
9800
if (status & MCI_CMDTIMEOUT) {
9801
- cmd->error = MMC_ERR_TIMEOUT;
9802
+ cmd->error = -ETIMEDOUT;
9803
} else if (status & MCI_CMDCRCFAIL && cmd->flags & MMC_RSP_CRC) {
9804
- cmd->error = MMC_ERR_BADCRC;
9805
+ cmd->error = -EILSEQ;
9808
- if (!cmd->data || cmd->error != MMC_ERR_NONE) {
9809
+ if (!cmd->data || cmd->error) {
9811
mmci_stop_data(host);
9812
mmci_request_end(host, cmd->mrq);
9813
@@ -318,7 +319,7 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
9814
* page, ensure that the data cache is coherent.
9816
if (status & MCI_RXACTIVE)
9817
- flush_dcache_page(host->sg_ptr->page);
9818
+ flush_dcache_page(sg_page(host->sg_ptr));
9820
if (!mmci_next_sg(host))
9822
@@ -391,6 +392,14 @@ static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
9824
WARN_ON(host->mrq != NULL);
9826
+ if (mrq->data && !is_power_of_2(mrq->data->blksz)) {
9827
+ printk(KERN_ERR "%s: Unsupported block size (%d bytes)\n",
9828
+ mmc_hostname(mmc), mrq->data->blksz);
9829
+ mrq->cmd->error = -EINVAL;
9830
+ mmc_request_done(mmc, mrq);
9834
spin_lock_irq(&host->lock);
9837
diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h
9838
index 6d7eadc..0f39c49 100644
9839
--- a/drivers/mmc/host/mmci.h
9840
+++ b/drivers/mmc/host/mmci.h
9843
- * linux/drivers/mmc/mmci.h - ARM PrimeCell MMCI PL180/1 driver
9844
+ * linux/drivers/mmc/host/mmci.h - ARM PrimeCell MMCI PL180/1 driver
9846
* Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
9848
@@ -169,7 +169,7 @@ static inline char *mmci_kmap_atomic(struct mmci_host *host, unsigned long *flag
9849
struct scatterlist *sg = host->sg_ptr;
9851
local_irq_save(*flags);
9852
- return kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset;
9853
+ return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
9856
static inline void mmci_kunmap_atomic(struct mmci_host *host, void *buffer, unsigned long *flags)
9857
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
9858
index b0824a3..971e18b 100644
9859
--- a/drivers/mmc/host/omap.c
9860
+++ b/drivers/mmc/host/omap.c
9863
- * linux/drivers/media/mmc/omap.c
9864
+ * linux/drivers/mmc/host/omap.c
9866
* Copyright (C) 2004 Nokia Corporation
9867
* Written by Tuukka Tikkanen and Juha Yrj�l�<juha.yrjola@nokia.com>
9869
#include <linux/mmc/host.h>
9870
#include <linux/mmc/card.h>
9871
#include <linux/clk.h>
9872
+#include <linux/scatterlist.h>
9875
#include <asm/irq.h>
9876
-#include <asm/scatterlist.h>
9877
#include <asm/mach-types.h>
9879
#include <asm/arch/board.h>
9880
@@ -263,7 +263,7 @@ mmc_omap_xfer_done(struct mmc_omap_host *host, struct mmc_data *data)
9881
enum dma_data_direction dma_data_dir;
9883
BUG_ON(host->dma_ch < 0);
9884
- if (data->error != MMC_ERR_NONE)
9886
omap_stop_dma(host->dma_ch);
9887
/* Release DMA channel lazily */
9888
mod_timer(&host->dma_timer, jiffies + HZ);
9889
@@ -368,7 +368,7 @@ mmc_omap_cmd_done(struct mmc_omap_host *host, struct mmc_command *cmd)
9893
- if (host->data == NULL || cmd->error != MMC_ERR_NONE) {
9894
+ if (host->data == NULL || cmd->error) {
9896
clk_disable(host->fclk);
9897
mmc_request_done(host->mmc, cmd->mrq);
9898
@@ -383,7 +383,7 @@ mmc_omap_sg_to_buf(struct mmc_omap_host *host)
9900
sg = host->data->sg + host->sg_idx;
9901
host->buffer_bytes_left = sg->length;
9902
- host->buffer = page_address(sg->page) + sg->offset;
9903
+ host->buffer = sg_virt(sg);
9904
if (host->buffer_bytes_left > host->total_bytes_left)
9905
host->buffer_bytes_left = host->total_bytes_left;
9907
@@ -475,14 +475,14 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
9908
if (status & OMAP_MMC_STAT_DATA_TOUT) {
9909
dev_dbg(mmc_dev(host->mmc), "data timeout\n");
9911
- host->data->error |= MMC_ERR_TIMEOUT;
9912
+ host->data->error = -ETIMEDOUT;
9917
if (status & OMAP_MMC_STAT_DATA_CRC) {
9919
- host->data->error |= MMC_ERR_BADCRC;
9920
+ host->data->error = -EILSEQ;
9921
dev_dbg(mmc_dev(host->mmc),
9922
"data CRC error, bytes left %d\n",
9923
host->total_bytes_left);
9924
@@ -504,7 +504,7 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
9925
dev_err(mmc_dev(host->mmc),
9926
"command timeout, CMD %d\n",
9928
- host->cmd->error = MMC_ERR_TIMEOUT;
9929
+ host->cmd->error = -ETIMEDOUT;
9933
@@ -514,7 +514,7 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
9934
dev_err(mmc_dev(host->mmc),
9935
"command CRC error (CMD%d, arg 0x%08x)\n",
9936
host->cmd->opcode, host->cmd->arg);
9937
- host->cmd->error = MMC_ERR_BADCRC;
9938
+ host->cmd->error = -EILSEQ;
9941
dev_err(mmc_dev(host->mmc),
9942
diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
9943
index f8985c5..1654a33 100644
9944
--- a/drivers/mmc/host/pxamci.c
9945
+++ b/drivers/mmc/host/pxamci.c
9948
- * linux/drivers/mmc/pxa.c - PXA MMCI driver
9949
+ * linux/drivers/mmc/host/pxa.c - PXA MMCI driver
9951
* Copyright (C) 2003 Russell King, All Rights Reserved.
9954
#include <linux/delay.h>
9955
#include <linux/interrupt.h>
9956
#include <linux/dma-mapping.h>
9957
+#include <linux/clk.h>
9958
+#include <linux/err.h>
9959
#include <linux/mmc/host.h>
9961
#include <asm/dma.h>
9963
-#include <asm/scatterlist.h>
9964
#include <asm/sizes.h>
9966
#include <asm/arch/pxa-regs.h>
9968
#define DRIVER_NAME "pxa2xx-mci"
9971
+#define CLKRT_OFF (~0)
9973
struct pxamci_host {
9974
struct mmc_host *mmc;
9976
struct resource *res;
9979
+ unsigned long clkrate;
9983
@@ -119,7 +123,7 @@ static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
9984
writel(nob, host->base + MMC_NOB);
9985
writel(data->blksz, host->base + MMC_BLKLEN);
9987
- clks = (unsigned long long)data->timeout_ns * CLOCKRATE;
9988
+ clks = (unsigned long long)data->timeout_ns * host->clkrate;
9989
do_div(clks, 1000000000UL);
9990
timeout = (unsigned int)clks + (data->timeout_clks << host->clkrt);
9991
writel((timeout + 255) / 256, host->base + MMC_RDTO);
9992
@@ -142,6 +146,10 @@ static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
9995
for (i = 0; i < host->dma_len; i++) {
9996
+ unsigned int length = sg_dma_len(&data->sg[i]);
9997
+ host->sg_cpu[i].dcmd = dcmd | length;
9998
+ if (length & 31 && !(data->flags & MMC_DATA_READ))
9999
+ host->sg_cpu[i].dcmd |= DCMD_ENDIRQEN;
10000
if (data->flags & MMC_DATA_READ) {
10001
host->sg_cpu[i].dsadr = host->res->start + MMC_RXFIFO;
10002
host->sg_cpu[i].dtadr = sg_dma_address(&data->sg[i]);
10003
@@ -149,7 +157,6 @@ static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
10004
host->sg_cpu[i].dsadr = sg_dma_address(&data->sg[i]);
10005
host->sg_cpu[i].dtadr = host->res->start + MMC_TXFIFO;
10007
- host->sg_cpu[i].dcmd = dcmd | sg_dma_len(&data->sg[i]);
10008
host->sg_cpu[i].ddadr = host->sg_dma + (i + 1) *
10009
sizeof(struct pxa_dma_desc);
10011
@@ -226,7 +233,7 @@ static int pxamci_cmd_done(struct pxamci_host *host, unsigned int stat)
10014
if (stat & STAT_TIME_OUT_RESPONSE) {
10015
- cmd->error = MMC_ERR_TIMEOUT;
10016
+ cmd->error = -ETIMEDOUT;
10017
} else if (stat & STAT_RES_CRC_ERR && cmd->flags & MMC_RSP_CRC) {
10018
#ifdef CONFIG_PXA27x
10020
@@ -239,11 +246,11 @@ static int pxamci_cmd_done(struct pxamci_host *host, unsigned int stat)
10021
pr_debug("ignoring CRC from command %d - *risky*\n", cmd->opcode);
10024
- cmd->error = MMC_ERR_BADCRC;
10025
+ cmd->error = -EILSEQ;
10028
pxamci_disable_irq(host, END_CMD_RES);
10029
- if (host->data && cmd->error == MMC_ERR_NONE) {
10030
+ if (host->data && !cmd->error) {
10031
pxamci_enable_irq(host, DATA_TRAN_DONE);
10033
pxamci_finish_request(host, host->mrq);
10034
@@ -264,9 +271,9 @@ static int pxamci_data_done(struct pxamci_host *host, unsigned int stat)
10037
if (stat & STAT_READ_TIME_OUT)
10038
- data->error = MMC_ERR_TIMEOUT;
10039
+ data->error = -ETIMEDOUT;
10040
else if (stat & (STAT_CRC_READ_ERROR|STAT_CRC_WRITE_ERROR))
10041
- data->error = MMC_ERR_BADCRC;
10042
+ data->error = -EILSEQ;
10045
* There appears to be a hardware design bug here. There seems to
10046
@@ -274,7 +281,7 @@ static int pxamci_data_done(struct pxamci_host *host, unsigned int stat)
10047
* This means that if there was an error on any block, we mark all
10048
* data blocks as being in error.
10050
- if (data->error == MMC_ERR_NONE)
10051
+ if (!data->error)
10052
data->bytes_xfered = data->blocks * data->blksz;
10054
data->bytes_xfered = 0;
10055
@@ -284,7 +291,7 @@ static int pxamci_data_done(struct pxamci_host *host, unsigned int stat)
10057
if (host->mrq->stop) {
10058
pxamci_stop_clock(host);
10059
- pxamci_start_cmd(host, host->mrq->stop, 0);
10060
+ pxamci_start_cmd(host, host->mrq->stop, host->cmdat);
10062
pxamci_finish_request(host, host->mrq);
10064
@@ -298,7 +305,7 @@ static irqreturn_t pxamci_irq(int irq, void *devid)
10068
- ireg = readl(host->base + MMC_I_REG);
10069
+ ireg = readl(host->base + MMC_I_REG) & ~readl(host->base + MMC_I_MASK);
10072
unsigned stat = readl(host->base + MMC_STAT);
10073
@@ -309,6 +316,10 @@ static irqreturn_t pxamci_irq(int irq, void *devid)
10074
handled |= pxamci_cmd_done(host, stat);
10075
if (ireg & DATA_TRAN_DONE)
10076
handled |= pxamci_data_done(host, stat);
10077
+ if (ireg & SDIO_INT) {
10078
+ mmc_signal_sdio_irq(host->mmc);
10083
return IRQ_RETVAL(handled);
10084
@@ -358,18 +369,30 @@ static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
10085
struct pxamci_host *host = mmc_priv(mmc);
10088
- unsigned int clk = CLOCKRATE / ios->clock;
10089
- if (CLOCKRATE / clk > ios->clock)
10090
+ unsigned long rate = host->clkrate;
10091
+ unsigned int clk = rate / ios->clock;
10093
+ if (host->clkrt == CLKRT_OFF)
10094
+ clk_enable(host->clk);
10097
+ * clk might result in a lower divisor than we
10098
+ * desire. check for that condition and adjust
10099
+ * as appropriate.
10101
+ if (rate / clk > ios->clock)
10103
host->clkrt = fls(clk) - 1;
10104
- pxa_set_cken(CKEN_MMC, 1);
10107
* we write clkrt on the next command
10110
pxamci_stop_clock(host);
10111
- pxa_set_cken(CKEN_MMC, 0);
10112
+ if (host->clkrt != CLKRT_OFF) {
10113
+ host->clkrt = CLKRT_OFF;
10114
+ clk_disable(host->clk);
10118
if (host->power_mode != ios->power_mode) {
10119
@@ -382,20 +405,46 @@ static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
10120
host->cmdat |= CMDAT_INIT;
10123
+ if (ios->bus_width == MMC_BUS_WIDTH_4)
10124
+ host->cmdat |= CMDAT_SD_4DAT;
10126
+ host->cmdat &= ~CMDAT_SD_4DAT;
10128
pr_debug("PXAMCI: clkrt = %x cmdat = %x\n",
10129
host->clkrt, host->cmdat);
10132
+static void pxamci_enable_sdio_irq(struct mmc_host *host, int enable)
10134
+ struct pxamci_host *pxa_host = mmc_priv(host);
10137
+ pxamci_enable_irq(pxa_host, SDIO_INT);
10139
+ pxamci_disable_irq(pxa_host, SDIO_INT);
10142
static const struct mmc_host_ops pxamci_ops = {
10143
- .request = pxamci_request,
10144
- .get_ro = pxamci_get_ro,
10145
- .set_ios = pxamci_set_ios,
10146
+ .request = pxamci_request,
10147
+ .get_ro = pxamci_get_ro,
10148
+ .set_ios = pxamci_set_ios,
10149
+ .enable_sdio_irq = pxamci_enable_sdio_irq,
10152
static void pxamci_dma_irq(int dma, void *devid)
10154
- printk(KERN_ERR "DMA%d: IRQ???\n", dma);
10155
- DCSR(dma) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
10156
+ struct pxamci_host *host = devid;
10157
+ int dcsr = DCSR(dma);
10158
+ DCSR(dma) = dcsr & ~DCSR_STOPIRQEN;
10160
+ if (dcsr & DCSR_ENDINTR) {
10161
+ writel(BUF_PART_FULL, host->base + MMC_PRTBUF);
10163
+ printk(KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n",
10164
+ mmc_hostname(host->mmc), dma, dcsr);
10165
+ host->data->error = -EIO;
10166
+ pxamci_data_done(host, 0);
10170
static irqreturn_t pxamci_detect_irq(int irq, void *devid)
10171
@@ -429,8 +478,6 @@ static int pxamci_probe(struct platform_device *pdev)
10174
mmc->ops = &pxamci_ops;
10175
- mmc->f_min = CLOCKRATE_MIN;
10176
- mmc->f_max = CLOCKRATE_MAX;
10179
* We can do SG-DMA, but we don't because we never know how much
10180
@@ -444,9 +491,9 @@ static int pxamci_probe(struct platform_device *pdev)
10181
mmc->max_seg_size = PAGE_SIZE;
10184
- * Block length register is 10 bits.
10185
+ * Block length register is only 10 bits before PXA27x.
10187
- mmc->max_blk_size = 1023;
10188
+ mmc->max_blk_size = (cpu_is_pxa21x() || cpu_is_pxa25x()) ? 1023 : 2048;
10191
* Block count register is 16 bits.
10192
@@ -457,9 +504,32 @@ static int pxamci_probe(struct platform_device *pdev)
10195
host->pdata = pdev->dev.platform_data;
10196
+ host->clkrt = CLKRT_OFF;
10198
+ host->clk = clk_get(&pdev->dev, "MMCCLK");
10199
+ if (IS_ERR(host->clk)) {
10200
+ ret = PTR_ERR(host->clk);
10201
+ host->clk = NULL;
10205
+ host->clkrate = clk_get_rate(host->clk);
10208
+ * Calculate minimum clock rate, rounding up.
10210
+ mmc->f_min = (host->clkrate + 63) / 64;
10211
+ mmc->f_max = host->clkrate;
10213
mmc->ocr_avail = host->pdata ?
10214
host->pdata->ocr_mask :
10215
MMC_VDD_32_33|MMC_VDD_33_34;
10218
+ if (!cpu_is_pxa21x() && !cpu_is_pxa25x()) {
10219
+ mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
10220
+ host->cmdat |= CMDAT_SDIO_INT_EN;
10223
host->sg_cpu = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, &host->sg_dma, GFP_KERNEL);
10224
if (!host->sg_cpu) {
10225
@@ -515,6 +585,8 @@ static int pxamci_probe(struct platform_device *pdev)
10226
iounmap(host->base);
10228
dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma);
10230
+ clk_put(host->clk);
10233
mmc_free_host(mmc);
10234
@@ -549,6 +621,8 @@ static int pxamci_remove(struct platform_device *pdev)
10235
iounmap(host->base);
10236
dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma);
10238
+ clk_put(host->clk);
10240
release_resource(host->res);
10242
mmc_free_host(mmc);
10243
diff --git a/drivers/mmc/host/pxamci.h b/drivers/mmc/host/pxamci.h
10244
index 1b16322..748c770 100644
10245
--- a/drivers/mmc/host/pxamci.h
10246
+++ b/drivers/mmc/host/pxamci.h
10259
-#undef END_CMD_RES
10261
-#undef DATA_TRAN_DONE
10270
#define MMC_STRPCL 0x0000
10271
#define STOP_CLOCK (1 << 0)
10272
#define START_CLOCK (2 << 0)
10274
#define SPI_EN (1 << 0)
10276
#define MMC_CMDAT 0x0010
10277
+#define CMDAT_SDIO_INT_EN (1 << 11)
10278
+#define CMDAT_SD_4DAT (1 << 8)
10279
#define CMDAT_DMAEN (1 << 7)
10280
#define CMDAT_INIT (1 << 6)
10281
#define CMDAT_BUSY (1 << 5)
10282
@@ -108,17 +88,3 @@
10283
#define MMC_RXFIFO 0x0040 /* 8 bit */
10285
#define MMC_TXFIFO 0x0044 /* 8 bit */
10288
- * The base MMC clock rate
10290
-#ifdef CONFIG_PXA27x
10291
-#define CLOCKRATE_MIN 304688
10292
-#define CLOCKRATE_MAX 19500000
10294
-#define CLOCKRATE_MIN 312500
10295
-#define CLOCKRATE_MAX 20000000
10298
-#define CLOCKRATE CLOCKRATE_MAX
10300
diff --git a/drivers/mmc/host/ricoh_mmc.c b/drivers/mmc/host/ricoh_mmc.c
10301
new file mode 100644
10302
index 0000000..1e87045
10304
+++ b/drivers/mmc/host/ricoh_mmc.c
10307
+ * ricoh_mmc.c - Dummy driver to disable the Rioch MMC controller.
10309
+ * Copyright (C) 2007 Philip Langdale, All Rights Reserved.
10311
+ * This program is free software; you can redistribute it and/or modify
10312
+ * it under the terms of the GNU General Public License as published by
10313
+ * the Free Software Foundation; either version 2 of the License, or (at
10314
+ * your option) any later version.
10318
+ * This is a conceptually ridiculous driver, but it is required by the way
10319
+ * the Ricoh multi-function R5C832 works. This chip implements firewire
10320
+ * and four different memory card controllers. Two of those controllers are
10321
+ * an SDHCI controller and a proprietary MMC controller. The linux SDHCI
10322
+ * driver supports MMC cards but the chip detects MMC cards in hardware
10323
+ * and directs them to the MMC controller - so the SDHCI driver never sees
10324
+ * them. To get around this, we must disable the useless MMC controller.
10325
+ * At that point, the SDHCI controller will start seeing them. As a bonus,
10326
+ * a detection event occurs immediately, even if the MMC card is already
10329
+ * The relevant registers live on the firewire function, so this is unavoidably
10330
+ * ugly. Such is life.
10333
+#include <linux/pci.h>
10335
+#define DRIVER_NAME "ricoh-mmc"
10337
+static const struct pci_device_id pci_ids[] __devinitdata = {
10339
+ .vendor = PCI_VENDOR_ID_RICOH,
10340
+ .device = PCI_DEVICE_ID_RICOH_R5C843,
10341
+ .subvendor = PCI_ANY_ID,
10342
+ .subdevice = PCI_ANY_ID,
10344
+ { /* end: all zeroes */ },
10347
+MODULE_DEVICE_TABLE(pci, pci_ids);
10349
+static int __devinit ricoh_mmc_probe(struct pci_dev *pdev,
10350
+ const struct pci_device_id *ent)
10354
+ struct pci_dev *fw_dev = NULL;
10356
+ BUG_ON(pdev == NULL);
10357
+ BUG_ON(ent == NULL);
10359
+ pci_read_config_byte(pdev, PCI_CLASS_REVISION, &rev);
10361
+ printk(KERN_INFO DRIVER_NAME
10362
+ ": Ricoh MMC controller found at %s [%04x:%04x] (rev %x)\n",
10363
+ pci_name(pdev), (int)pdev->vendor, (int)pdev->device,
10366
+ while ((fw_dev = pci_get_device(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, fw_dev))) {
10367
+ if (PCI_SLOT(pdev->devfn) == PCI_SLOT(fw_dev->devfn) &&
10368
+ pdev->bus == fw_dev->bus) {
10372
+ pci_read_config_byte(fw_dev, 0xCB, &disable);
10373
+ if (disable & 0x02) {
10374
+ printk(KERN_INFO DRIVER_NAME
10375
+ ": Controller already disabled. Nothing to do.\n");
10379
+ pci_read_config_byte(fw_dev, 0xCA, &write_enable);
10380
+ pci_write_config_byte(fw_dev, 0xCA, 0x57);
10381
+ pci_write_config_byte(fw_dev, 0xCB, disable | 0x02);
10382
+ pci_write_config_byte(fw_dev, 0xCA, write_enable);
10384
+ pci_set_drvdata(pdev, fw_dev);
10386
+ printk(KERN_INFO DRIVER_NAME
10387
+ ": Controller is now disabled.\n");
10393
+ if (pci_get_drvdata(pdev) == NULL) {
10394
+ printk(KERN_WARNING DRIVER_NAME
10395
+ ": Main firewire function not found. Cannot disable controller.\n");
10402
+static void __devexit ricoh_mmc_remove(struct pci_dev *pdev)
10406
+ struct pci_dev *fw_dev = NULL;
10408
+ fw_dev = pci_get_drvdata(pdev);
10409
+ BUG_ON(fw_dev == NULL);
10411
+ pci_read_config_byte(fw_dev, 0xCA, &write_enable);
10412
+ pci_read_config_byte(fw_dev, 0xCB, &disable);
10413
+ pci_write_config_byte(fw_dev, 0xCA, 0x57);
10414
+ pci_write_config_byte(fw_dev, 0xCB, disable & ~0x02);
10415
+ pci_write_config_byte(fw_dev, 0xCA, write_enable);
10417
+ printk(KERN_INFO DRIVER_NAME
10418
+ ": Controller is now re-enabled.\n");
10420
+ pci_set_drvdata(pdev, NULL);
10423
+static struct pci_driver ricoh_mmc_driver = {
10424
+ .name = DRIVER_NAME,
10425
+ .id_table = pci_ids,
10426
+ .probe = ricoh_mmc_probe,
10427
+ .remove = __devexit_p(ricoh_mmc_remove),
10430
+/*****************************************************************************\
10432
+ * Driver init/exit *
10434
+\*****************************************************************************/
10436
+static int __init ricoh_mmc_drv_init(void)
10438
+ printk(KERN_INFO DRIVER_NAME
10439
+ ": Ricoh MMC Controller disabling driver\n");
10440
+ printk(KERN_INFO DRIVER_NAME ": Copyright(c) Philip Langdale\n");
10442
+ return pci_register_driver(&ricoh_mmc_driver);
10445
+static void __exit ricoh_mmc_drv_exit(void)
10447
+ pci_unregister_driver(&ricoh_mmc_driver);
10450
+module_init(ricoh_mmc_drv_init);
10451
+module_exit(ricoh_mmc_drv_exit);
10453
+MODULE_AUTHOR("Philip Langdale <philipl@alumni.utexas.net>");
10454
+MODULE_DESCRIPTION("Ricoh MMC Controller disabling driver");
10455
+MODULE_LICENSE("GPL");
10457
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
10458
index df5da96..8135a49 100644
10459
--- a/drivers/mmc/host/sdhci.c
10460
+++ b/drivers/mmc/host/sdhci.c
10463
- * linux/drivers/mmc/sdhci.c - Secure Digital Host Controller Interface driver
10464
+ * linux/drivers/mmc/host/sdhci.c - Secure Digital Host Controller Interface driver
10466
* Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
10468
@@ -13,20 +13,20 @@
10469
#include <linux/highmem.h>
10470
#include <linux/pci.h>
10471
#include <linux/dma-mapping.h>
10472
+#include <linux/scatterlist.h>
10474
#include <linux/mmc/host.h>
10476
-#include <asm/scatterlist.h>
10481
+//#include <linux/mmc/core.h>
10483
#define DRIVER_NAME "sdhci"
10485
#define DBG(f, x...) \
10486
pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
10488
-static unsigned int debug_nodma = 0;
10489
-static unsigned int debug_forcedma = 0;
10490
static unsigned int debug_quirks = 0;
10492
#define SDHCI_QUIRK_CLOCK_BEFORE_RESET (1<<0)
10493
@@ -35,6 +35,7 @@ static unsigned int debug_quirks = 0;
10494
#define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2)
10495
#define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3)
10496
#define SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS (1<<4)
10497
+#define SDHCI_QUIRK_BROKEN_DMA (1<<5)
10499
static const struct pci_device_id pci_ids[] __devinitdata = {
10501
@@ -68,7 +69,35 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
10502
.device = PCI_DEVICE_ID_ENE_CB712_SD,
10503
.subvendor = PCI_ANY_ID,
10504
.subdevice = PCI_ANY_ID,
10505
- .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE,
10506
+ .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE |
10507
+ SDHCI_QUIRK_BROKEN_DMA,
10511
+ .vendor = PCI_VENDOR_ID_ENE,
10512
+ .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
10513
+ .subvendor = PCI_ANY_ID,
10514
+ .subdevice = PCI_ANY_ID,
10515
+ .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE |
10516
+ SDHCI_QUIRK_BROKEN_DMA,
10520
+ .vendor = PCI_VENDOR_ID_ENE,
10521
+ .device = PCI_DEVICE_ID_ENE_CB714_SD,
10522
+ .subvendor = PCI_ANY_ID,
10523
+ .subdevice = PCI_ANY_ID,
10524
+ .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE |
10525
+ SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS,
10529
+ .vendor = PCI_VENDOR_ID_ENE,
10530
+ .device = PCI_DEVICE_ID_ENE_CB714_SD_2,
10531
+ .subvendor = PCI_ANY_ID,
10532
+ .subdevice = PCI_ANY_ID,
10533
+ .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE |
10534
+ SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS,
10538
@@ -132,7 +161,7 @@ static void sdhci_dumpregs(struct sdhci_host *host)
10539
readb(host->ioaddr + SDHCI_POWER_CONTROL),
10540
readb(host->ioaddr + SDHCI_BLOCK_GAP_CONTROL));
10541
printk(KERN_DEBUG DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n",
10542
- readb(host->ioaddr + SDHCI_WALK_UP_CONTROL),
10543
+ readb(host->ioaddr + SDHCI_WAKE_UP_CONTROL),
10544
readw(host->ioaddr + SDHCI_CLOCK_CONTROL));
10545
printk(KERN_DEBUG DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n",
10546
readb(host->ioaddr + SDHCI_TIMEOUT_CONTROL),
10547
@@ -380,16 +409,14 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data)
10551
- DBG("blksz %04x blks %04x flags %08x\n",
10552
- data->blksz, data->blocks, data->flags);
10553
- DBG("tsac %d ms nsac %d clk\n",
10554
- data->timeout_ns / 1000000, data->timeout_clks);
10556
/* Sanity checks */
10557
BUG_ON(data->blksz * data->blocks > 524288);
10558
BUG_ON(data->blksz > host->mmc->max_blk_size);
10559
BUG_ON(data->blocks > 65535);
10561
+ host->data = data;
10562
+ host->data_early = 0;
10564
/* timeout in us */
10565
target_timeout = data->timeout_ns / 1000 +
10566
data->timeout_clks / host->clock;
10567
@@ -448,11 +475,11 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,
10571
- WARN_ON(host->data);
10576
+ WARN_ON(!host->data);
10578
mode = SDHCI_TRNS_BLK_CNT_EN;
10579
if (data->blocks > 1)
10580
mode |= SDHCI_TRNS_MULTI;
10581
@@ -482,27 +509,25 @@ static void sdhci_finish_data(struct sdhci_host *host)
10583
* Controller doesn't count down when in single block mode.
10585
- if ((data->blocks == 1) && (data->error == MMC_ERR_NONE))
10587
+ if (data->blocks == 1)
10588
+ blocks = (data->error == 0) ? 0 : 1;
10590
blocks = readw(host->ioaddr + SDHCI_BLOCK_COUNT);
10591
data->bytes_xfered = data->blksz * (data->blocks - blocks);
10593
- if ((data->error == MMC_ERR_NONE) && blocks) {
10594
+ if (!data->error && blocks) {
10595
printk(KERN_ERR "%s: Controller signalled completion even "
10596
"though there were blocks left.\n",
10597
mmc_hostname(host->mmc));
10598
- data->error = MMC_ERR_FAILED;
10599
+ data->error = -EIO;
10602
- DBG("Ending data transfer (%d bytes)\n", data->bytes_xfered);
10606
* The controller needs a reset of internal state machines
10607
* upon error conditions.
10609
- if (data->error != MMC_ERR_NONE) {
10610
+ if (data->error) {
10611
sdhci_reset(host, SDHCI_RESET_CMD);
10612
sdhci_reset(host, SDHCI_RESET_DATA);
10614
@@ -520,8 +545,6 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
10616
WARN_ON(host->cmd);
10618
- DBG("Sending cmd (%x)\n", cmd->opcode);
10620
/* Wait max 10 ms */
10623
@@ -539,7 +562,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
10624
printk(KERN_ERR "%s: Controller never released "
10625
"inhibit bit(s).\n", mmc_hostname(host->mmc));
10626
sdhci_dumpregs(host);
10627
- cmd->error = MMC_ERR_FAILED;
10628
+ cmd->error = -EIO;
10629
tasklet_schedule(&host->finish_tasklet);
10632
@@ -560,7 +583,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
10633
if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
10634
printk(KERN_ERR "%s: Unsupported response type!\n",
10635
mmc_hostname(host->mmc));
10636
- cmd->error = MMC_ERR_INVALID;
10637
+ cmd->error = -EINVAL;
10638
tasklet_schedule(&host->finish_tasklet);
10641
@@ -607,13 +630,12 @@ static void sdhci_finish_command(struct sdhci_host *host)
10645
- host->cmd->error = MMC_ERR_NONE;
10646
+ host->cmd->error = 0;
10648
- DBG("Ending cmd (%x)\n", host->cmd->opcode);
10649
+ if (host->data && host->data_early)
10650
+ sdhci_finish_data(host);
10652
- if (host->cmd->data)
10653
- host->data = host->cmd->data;
10655
+ if (!host->cmd->data)
10656
tasklet_schedule(&host->finish_tasklet);
10659
@@ -729,7 +751,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
10662
if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
10663
- host->mrq->cmd->error = MMC_ERR_TIMEOUT;
10664
+ host->mrq->cmd->error = -ENOMEDIUM;
10665
tasklet_schedule(&host->finish_tasklet);
10667
sdhci_send_command(host, mrq->cmd);
10668
@@ -786,6 +808,14 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
10669
if(host->chip->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS)
10670
sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
10673
+ * Some (ENE) controllers go apeshit on some ios operation,
10674
+ * signalling timeout and CRC errors even on CMD0. Resetting
10675
+ * it on each ios seems to solve the problem.
10677
+ if(host->chip->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS)
10678
+ sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
10681
spin_unlock_irqrestore(&host->lock, flags);
10683
@@ -807,10 +837,35 @@ static int sdhci_get_ro(struct mmc_host *mmc)
10684
return !(present & SDHCI_WRITE_PROTECT);
10687
+static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
10689
+ struct sdhci_host *host;
10690
+ unsigned long flags;
10693
+ host = mmc_priv(mmc);
10695
+ spin_lock_irqsave(&host->lock, flags);
10697
+ ier = readl(host->ioaddr + SDHCI_INT_ENABLE);
10699
+ ier &= ~SDHCI_INT_CARD_INT;
10701
+ ier |= SDHCI_INT_CARD_INT;
10703
+ writel(ier, host->ioaddr + SDHCI_INT_ENABLE);
10704
+ writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
10708
+ spin_unlock_irqrestore(&host->lock, flags);
10711
static const struct mmc_host_ops sdhci_ops = {
10712
.request = sdhci_request,
10713
.set_ios = sdhci_set_ios,
10714
.get_ro = sdhci_get_ro,
10715
+ .enable_sdio_irq = sdhci_enable_sdio_irq,
10718
/*****************************************************************************\
10719
@@ -838,7 +893,7 @@ static void sdhci_tasklet_card(unsigned long param)
10720
sdhci_reset(host, SDHCI_RESET_CMD);
10721
sdhci_reset(host, SDHCI_RESET_DATA);
10723
- host->mrq->cmd->error = MMC_ERR_FAILED;
10724
+ host->mrq->cmd->error = -ENOMEDIUM;
10725
tasklet_schedule(&host->finish_tasklet);
10728
@@ -862,15 +917,13 @@ static void sdhci_tasklet_finish(unsigned long param)
10732
- DBG("Ending request, cmd (%x)\n", mrq->cmd->opcode);
10735
* The controller needs a reset of internal state machines
10736
* upon error conditions.
10738
- if ((mrq->cmd->error != MMC_ERR_NONE) ||
10739
- (mrq->data && ((mrq->data->error != MMC_ERR_NONE) ||
10740
- (mrq->data->stop && (mrq->data->stop->error != MMC_ERR_NONE))))) {
10741
+ if (mrq->cmd->error ||
10742
+ (mrq->data && (mrq->data->error ||
10743
+ (mrq->data->stop && mrq->data->stop->error)))) {
10745
/* Some controllers need this kick or reset won't work here */
10746
if (host->chip->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) {
10747
@@ -915,13 +968,13 @@ static void sdhci_timeout_timer(unsigned long data)
10748
sdhci_dumpregs(host);
10751
- host->data->error = MMC_ERR_TIMEOUT;
10752
+ host->data->error = -ETIMEDOUT;
10753
sdhci_finish_data(host);
10756
- host->cmd->error = MMC_ERR_TIMEOUT;
10757
+ host->cmd->error = -ETIMEDOUT;
10759
- host->mrq->cmd->error = MMC_ERR_TIMEOUT;
10760
+ host->mrq->cmd->error = -ETIMEDOUT;
10762
tasklet_schedule(&host->finish_tasklet);
10764
@@ -942,27 +995,23 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
10765
BUG_ON(intmask == 0);
10768
- printk(KERN_ERR "%s: Got command interrupt even though no "
10769
- "command operation was in progress.\n",
10770
- mmc_hostname(host->mmc));
10771
+ printk(KERN_ERR "%s: Got command interrupt 0x%08x even "
10772
+ "though no command operation was in progress.\n",
10773
+ mmc_hostname(host->mmc), (unsigned)intmask);
10774
sdhci_dumpregs(host);
10778
- if (intmask & SDHCI_INT_RESPONSE)
10779
- sdhci_finish_command(host);
10781
- if (intmask & SDHCI_INT_TIMEOUT)
10782
- host->cmd->error = MMC_ERR_TIMEOUT;
10783
- else if (intmask & SDHCI_INT_CRC)
10784
- host->cmd->error = MMC_ERR_BADCRC;
10785
- else if (intmask & (SDHCI_INT_END_BIT | SDHCI_INT_INDEX))
10786
- host->cmd->error = MMC_ERR_FAILED;
10788
- host->cmd->error = MMC_ERR_INVALID;
10789
+ if (intmask & SDHCI_INT_TIMEOUT)
10790
+ host->cmd->error = -ETIMEDOUT;
10791
+ else if (intmask & (SDHCI_INT_CRC | SDHCI_INT_END_BIT |
10792
+ SDHCI_INT_INDEX))
10793
+ host->cmd->error = -EILSEQ;
10795
+ if (host->cmd->error)
10796
tasklet_schedule(&host->finish_tasklet);
10798
+ else if (intmask & SDHCI_INT_RESPONSE)
10799
+ sdhci_finish_command(host);
10802
static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
10803
@@ -977,22 +1026,20 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
10804
if (intmask & SDHCI_INT_DATA_END)
10807
- printk(KERN_ERR "%s: Got data interrupt even though no "
10808
- "data operation was in progress.\n",
10809
- mmc_hostname(host->mmc));
10810
+ printk(KERN_ERR "%s: Got data interrupt 0x%08x even "
10811
+ "though no data operation was in progress.\n",
10812
+ mmc_hostname(host->mmc), (unsigned)intmask);
10813
sdhci_dumpregs(host);
10818
if (intmask & SDHCI_INT_DATA_TIMEOUT)
10819
- host->data->error = MMC_ERR_TIMEOUT;
10820
- else if (intmask & SDHCI_INT_DATA_CRC)
10821
- host->data->error = MMC_ERR_BADCRC;
10822
- else if (intmask & SDHCI_INT_DATA_END_BIT)
10823
- host->data->error = MMC_ERR_FAILED;
10824
+ host->data->error = -ETIMEDOUT;
10825
+ else if (intmask & (SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_END_BIT))
10826
+ host->data->error = -EILSEQ;
10828
- if (host->data->error != MMC_ERR_NONE)
10829
+ if (host->data->error)
10830
sdhci_finish_data(host);
10832
if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
10833
@@ -1007,8 +1054,18 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
10834
writel(readl(host->ioaddr + SDHCI_DMA_ADDRESS),
10835
host->ioaddr + SDHCI_DMA_ADDRESS);
10837
- if (intmask & SDHCI_INT_DATA_END)
10838
- sdhci_finish_data(host);
10839
+ if (intmask & SDHCI_INT_DATA_END) {
10842
+ * Data managed to finish before the
10843
+ * command completed. Make sure we do
10844
+ * things in the proper order.
10846
+ host->data_early = 1;
10848
+ sdhci_finish_data(host);
10854
@@ -1017,12 +1074,14 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
10855
irqreturn_t result;
10856
struct sdhci_host* host = dev_id;
10860
spin_lock(&host->lock);
10862
intmask = readl(host->ioaddr + SDHCI_INT_STATUS);
10864
if (!intmask || intmask == 0xffffffff) {
10869
@@ -1051,13 +1110,20 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
10871
intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
10873
+ intmask &= ~SDHCI_INT_ERROR;
10875
if (intmask & SDHCI_INT_BUS_POWER) {
10876
printk(KERN_ERR "%s: Card is consuming too much power!\n",
10877
mmc_hostname(host->mmc));
10878
writel(SDHCI_INT_BUS_POWER, host->ioaddr + SDHCI_INT_STATUS);
10881
- intmask &= SDHCI_INT_BUS_POWER;
10882
+ intmask &= ~SDHCI_INT_BUS_POWER;
10884
+ if (intmask & SDHCI_INT_CARD_INT)
10887
+ intmask &= ~SDHCI_INT_CARD_INT;
10890
printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n",
10891
@@ -1073,6 +1139,12 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
10893
spin_unlock(&host->lock);
10896
+ * We have to delay this as it calls back into the driver.
10899
+ mmc_signal_sdio_irq(host->mmc);
10904
@@ -1089,12 +1161,17 @@ static int sdhci_suspend (struct pci_dev *pdev, pm_message_t state)
10905
struct sdhci_chip *chip;
10910
chip = pci_get_drvdata(pdev);
10914
DBG("Suspending...\n");
10916
+ umd_dbg("This is for %s", chip->hosts[0]->mmc->class_dev.bus_id);
10919
for (i = 0;i < chip->num_slots;i++) {
10920
if (!chip->hosts[i])
10922
@@ -1118,6 +1195,14 @@ static int sdhci_suspend (struct pci_dev *pdev, pm_message_t state)
10923
pci_disable_device(pdev);
10924
pci_set_power_state(pdev, pci_choose_state(pdev, state));
10927
+ if (!strcmp(chip->hosts[0]->mmc->class_dev.bus_id, "mmc0")) {
10928
+ umd_dbg("Return from here to test PM");
10937
@@ -1126,6 +1211,8 @@ static int sdhci_resume (struct pci_dev *pdev)
10938
struct sdhci_chip *chip;
10943
chip = pci_get_drvdata(pdev);
10946
@@ -1258,20 +1345,26 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
10948
caps = readl(host->ioaddr + SDHCI_CAPABILITIES);
10951
- DBG("DMA forced off\n");
10952
- else if (debug_forcedma) {
10953
- DBG("DMA forced on\n");
10954
+ if (chip->quirks & SDHCI_QUIRK_FORCE_DMA)
10955
host->flags |= SDHCI_USE_DMA;
10956
- } else if (chip->quirks & SDHCI_QUIRK_FORCE_DMA)
10957
- host->flags |= SDHCI_USE_DMA;
10958
- else if ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA)
10959
- DBG("Controller doesn't have DMA interface\n");
10960
else if (!(caps & SDHCI_CAN_DO_DMA))
10961
DBG("Controller doesn't have DMA capability\n");
10963
host->flags |= SDHCI_USE_DMA;
10965
+ if ((chip->quirks & SDHCI_QUIRK_BROKEN_DMA) &&
10966
+ (host->flags & SDHCI_USE_DMA)) {
10967
+ DBG("Disabling DMA as it is marked broken\n");
10968
+ host->flags &= ~SDHCI_USE_DMA;
10971
+ if (((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
10972
+ (host->flags & SDHCI_USE_DMA)) {
10973
+ printk(KERN_WARNING "%s: Will use DMA "
10974
+ "mode even though HW doesn't fully "
10975
+ "claim to support it.\n", host->slot_descr);
10978
if (host->flags & SDHCI_USE_DMA) {
10979
if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
10980
printk(KERN_WARNING "%s: No suitable DMA available. "
10981
@@ -1312,7 +1405,7 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
10982
mmc->ops = &sdhci_ops;
10983
mmc->f_min = host->max_clk / 256;
10984
mmc->f_max = host->max_clk;
10985
- mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_BYTEBLOCK;
10986
+ mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_SDIO_IRQ;
10988
if (caps & SDHCI_CAN_DO_HISPD)
10989
mmc->caps |= MMC_CAP_SD_HIGHSPEED;
10990
@@ -1361,12 +1454,11 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
10992
mmc->max_blk_size = (caps & SDHCI_MAX_BLOCK_MASK) >> SDHCI_MAX_BLOCK_SHIFT;
10993
if (mmc->max_blk_size >= 3) {
10994
- printk(KERN_ERR "%s: Invalid maximum block size.\n",
10995
+ printk(KERN_WARNING "%s: Invalid maximum block size, assuming 512\n",
11000
- mmc->max_blk_size = 512 << mmc->max_blk_size;
11001
+ mmc->max_blk_size = 512;
11003
+ mmc->max_blk_size = 512 << mmc->max_blk_size;
11006
* Maximum block count.
11007
@@ -1566,14 +1658,10 @@ static void __exit sdhci_drv_exit(void)
11008
module_init(sdhci_drv_init);
11009
module_exit(sdhci_drv_exit);
11011
-module_param(debug_nodma, uint, 0444);
11012
-module_param(debug_forcedma, uint, 0444);
11013
module_param(debug_quirks, uint, 0444);
11015
MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>");
11016
MODULE_DESCRIPTION("Secure Digital Host Controller Interface driver");
11017
MODULE_LICENSE("GPL");
11019
-MODULE_PARM_DESC(debug_nodma, "Forcefully disable DMA transfers. (default 0)");
11020
-MODULE_PARM_DESC(debug_forcedma, "Forcefully enable DMA transfers. (default 0)");
11021
MODULE_PARM_DESC(debug_quirks, "Force certain quirks.");
11022
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
11023
index 7400f4b..05195ea 100644
11024
--- a/drivers/mmc/host/sdhci.h
11025
+++ b/drivers/mmc/host/sdhci.h
11028
- * linux/drivers/mmc/sdhci.h - Secure Digital Host Controller Interface driver
11029
+ * linux/drivers/mmc/host/sdhci.h - Secure Digital Host Controller Interface driver
11031
* Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
11035
#define SDHCI_BLOCK_GAP_CONTROL 0x2A
11037
-#define SDHCI_WALK_UP_CONTROL 0x2B
11038
+#define SDHCI_WAKE_UP_CONTROL 0x2B
11040
#define SDHCI_CLOCK_CONTROL 0x2C
11041
#define SDHCI_DIVIDER_SHIFT 8
11042
@@ -107,6 +107,7 @@
11043
#define SDHCI_INT_CARD_INSERT 0x00000040
11044
#define SDHCI_INT_CARD_REMOVE 0x00000080
11045
#define SDHCI_INT_CARD_INT 0x00000100
11046
+#define SDHCI_INT_ERROR 0x00008000
11047
#define SDHCI_INT_TIMEOUT 0x00010000
11048
#define SDHCI_INT_CRC 0x00020000
11049
#define SDHCI_INT_END_BIT 0x00040000
11050
@@ -181,6 +182,7 @@ struct sdhci_host {
11051
struct mmc_request *mrq; /* Current request */
11052
struct mmc_command *cmd; /* Current command */
11053
struct mmc_data *data; /* Current data request */
11054
+ int data_early:1; /* Data finished before cmd */
11056
struct scatterlist *cur_sg; /* We're working on this */
11057
int num_sg; /* Entries left */
11058
diff --git a/drivers/mmc/host/tifm_sd.c b/drivers/mmc/host/tifm_sd.c
11059
index 8b736e9..c11a3d2 100644
11060
--- a/drivers/mmc/host/tifm_sd.c
11061
+++ b/drivers/mmc/host/tifm_sd.c
11063
#include <linux/mmc/host.h>
11064
#include <linux/highmem.h>
11065
#include <linux/scatterlist.h>
11066
+#include <linux/log2.h>
11067
#include <asm/io.h>
11069
#define DRIVER_NAME "tifm_sd"
11070
@@ -191,7 +192,7 @@ static void tifm_sd_transfer_data(struct tifm_sd *host)
11072
off = sg[host->sg_pos].offset + host->block_pos;
11074
- pg = nth_page(sg[host->sg_pos].page, off >> PAGE_SHIFT);
11075
+ pg = nth_page(sg_page(&sg[host->sg_pos]), off >> PAGE_SHIFT);
11076
p_off = offset_in_page(off);
11077
p_cnt = PAGE_SIZE - p_off;
11078
p_cnt = min(p_cnt, cnt);
11079
@@ -240,18 +241,18 @@ static void tifm_sd_bounce_block(struct tifm_sd *host, struct mmc_data *r_data)
11081
off = sg[host->sg_pos].offset + host->block_pos;
11083
- pg = nth_page(sg[host->sg_pos].page, off >> PAGE_SHIFT);
11084
+ pg = nth_page(sg_page(&sg[host->sg_pos]), off >> PAGE_SHIFT);
11085
p_off = offset_in_page(off);
11086
p_cnt = PAGE_SIZE - p_off;
11087
p_cnt = min(p_cnt, cnt);
11088
p_cnt = min(p_cnt, t_size);
11090
if (r_data->flags & MMC_DATA_WRITE)
11091
- tifm_sd_copy_page(host->bounce_buf.page,
11092
+ tifm_sd_copy_page(sg_page(&host->bounce_buf),
11093
r_data->blksz - t_size,
11095
else if (r_data->flags & MMC_DATA_READ)
11096
- tifm_sd_copy_page(pg, p_off, host->bounce_buf.page,
11097
+ tifm_sd_copy_page(pg, p_off, sg_page(&host->bounce_buf),
11098
r_data->blksz - t_size, p_cnt);
11101
@@ -404,14 +405,14 @@ static void tifm_sd_check_status(struct tifm_sd *host)
11102
struct tifm_dev *sock = host->dev;
11103
struct mmc_command *cmd = host->req->cmd;
11105
- if (cmd->error != MMC_ERR_NONE)
11107
goto finish_request;
11109
if (!(host->cmd_flags & CMD_READY))
11113
- if (cmd->data->error != MMC_ERR_NONE) {
11114
+ if (cmd->data->error) {
11115
if ((host->cmd_flags & SCMD_ACTIVE)
11116
&& !(host->cmd_flags & SCMD_READY))
11118
@@ -504,7 +505,7 @@ static void tifm_sd_card_event(struct tifm_dev *sock)
11120
struct tifm_sd *host;
11121
unsigned int host_status = 0;
11122
- int cmd_error = MMC_ERR_NONE;
11123
+ int cmd_error = 0;
11124
struct mmc_command *cmd = NULL;
11125
unsigned long flags;
11127
@@ -521,15 +522,15 @@ static void tifm_sd_card_event(struct tifm_dev *sock)
11128
writel(host_status & TIFM_MMCSD_ERRMASK,
11129
sock->addr + SOCK_MMCSD_STATUS);
11130
if (host_status & TIFM_MMCSD_CTO)
11131
- cmd_error = MMC_ERR_TIMEOUT;
11132
+ cmd_error = -ETIMEDOUT;
11133
else if (host_status & TIFM_MMCSD_CCRC)
11134
- cmd_error = MMC_ERR_BADCRC;
11135
+ cmd_error = -EILSEQ;
11138
if (host_status & TIFM_MMCSD_DTO)
11139
- cmd->data->error = MMC_ERR_TIMEOUT;
11140
+ cmd->data->error = -ETIMEDOUT;
11141
else if (host_status & TIFM_MMCSD_DCRC)
11142
- cmd->data->error = MMC_ERR_BADCRC;
11143
+ cmd->data->error = -EILSEQ;
11146
writel(TIFM_FIFO_INT_SETALL,
11147
@@ -626,14 +627,21 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
11149
spin_lock_irqsave(&sock->lock, flags);
11151
- spin_unlock_irqrestore(&sock->lock, flags);
11152
+ mrq->cmd->error = -ENOMEDIUM;
11157
printk(KERN_ERR "%s : unfinished request detected\n",
11159
- spin_unlock_irqrestore(&sock->lock, flags);
11160
+ mrq->cmd->error = -ETIMEDOUT;
11164
+ if (mrq->data && !is_power_of_2(mrq->data->blksz)) {
11165
+ printk(KERN_ERR "%s: Unsupported block size (%d bytes)\n",
11166
+ sock->dev.bus_id, mrq->data->blksz);
11167
+ mrq->cmd->error = -EINVAL;
11171
@@ -722,7 +730,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
11175
- mrq->cmd->error = MMC_ERR_TIMEOUT;
11176
+ spin_unlock_irqrestore(&sock->lock, flags);
11177
mmc_request_done(mmc, mrq);
11180
@@ -1012,9 +1020,9 @@ static void tifm_sd_remove(struct tifm_dev *sock)
11181
writel(TIFM_FIFO_INT_SETALL,
11182
sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR);
11183
writel(0, sock->addr + SOCK_DMA_FIFO_INT_ENABLE_SET);
11184
- host->req->cmd->error = MMC_ERR_TIMEOUT;
11185
+ host->req->cmd->error = -ENOMEDIUM;
11186
if (host->req->stop)
11187
- host->req->stop->error = MMC_ERR_TIMEOUT;
11188
+ host->req->stop->error = -ENOMEDIUM;
11189
tasklet_schedule(&host->finish_tasklet);
11191
spin_unlock_irqrestore(&sock->lock, flags);
11192
diff --git a/drivers/mmc/host/wbsd.c b/drivers/mmc/host/wbsd.c
11193
index 867ca6a..4d5f374 100644
11194
--- a/drivers/mmc/host/wbsd.c
11195
+++ b/drivers/mmc/host/wbsd.c
11198
- * linux/drivers/mmc/wbsd.c - Winbond W83L51xD SD/MMC driver
11199
+ * linux/drivers/mmc/host/wbsd.c - Winbond W83L51xD SD/MMC driver
11201
* Copyright (C) 2004-2007 Pierre Ossman, All Rights Reserved.
11203
@@ -33,10 +33,10 @@
11204
#include <linux/pnp.h>
11205
#include <linux/highmem.h>
11206
#include <linux/mmc/host.h>
11207
+#include <linux/scatterlist.h>
11209
#include <asm/io.h>
11210
#include <asm/dma.h>
11211
-#include <asm/scatterlist.h>
11215
@@ -207,8 +207,6 @@ static void wbsd_request_end(struct wbsd_host *host, struct mmc_request *mrq)
11217
unsigned long dmaflags;
11219
- DBGF("Ending request, cmd (%x)\n", mrq->cmd->opcode);
11221
if (host->dma >= 0) {
11223
* Release ISA DMA controller.
11224
@@ -271,7 +269,7 @@ static inline int wbsd_next_sg(struct wbsd_host *host)
11226
static inline char *wbsd_sg_to_buffer(struct wbsd_host *host)
11228
- return page_address(host->cur_sg->page) + host->cur_sg->offset;
11229
+ return sg_virt(host->cur_sg);
11232
static inline void wbsd_sg_to_dma(struct wbsd_host *host, struct mmc_data *data)
11233
@@ -285,7 +283,7 @@ static inline void wbsd_sg_to_dma(struct wbsd_host *host, struct mmc_data *data)
11234
len = data->sg_len;
11236
for (i = 0; i < len; i++) {
11237
- sgbuf = page_address(sg[i].page) + sg[i].offset;
11238
+ sgbuf = sg_virt(&sg[i]);
11239
memcpy(dmabuf, sgbuf, sg[i].length);
11240
dmabuf += sg[i].length;
11242
@@ -302,7 +300,7 @@ static inline void wbsd_dma_to_sg(struct wbsd_host *host, struct mmc_data *data)
11243
len = data->sg_len;
11245
for (i = 0; i < len; i++) {
11246
- sgbuf = page_address(sg[i].page) + sg[i].offset;
11247
+ sgbuf = sg_virt(&sg[i]);
11248
memcpy(sgbuf, dmabuf, sg[i].length);
11249
dmabuf += sg[i].length;
11251
@@ -319,7 +317,7 @@ static inline void wbsd_get_short_reply(struct wbsd_host *host,
11252
* Correct response type?
11254
if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_SHORT) {
11255
- cmd->error = MMC_ERR_INVALID;
11256
+ cmd->error = -EILSEQ;
11260
@@ -339,7 +337,7 @@ static inline void wbsd_get_long_reply(struct wbsd_host *host,
11261
* Correct response type?
11263
if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_LONG) {
11264
- cmd->error = MMC_ERR_INVALID;
11265
+ cmd->error = -EILSEQ;
11269
@@ -360,8 +358,6 @@ static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd)
11273
- DBGF("Sending cmd (%x)\n", cmd->opcode);
11276
* Clear accumulated ISR. The interrupt routine
11277
* will fill this one with events that occur during
11278
@@ -376,7 +372,7 @@ static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd)
11279
for (i = 3; i >= 0; i--)
11280
outb((cmd->arg >> (i * 8)) & 0xff, host->base + WBSD_CMDR);
11282
- cmd->error = MMC_ERR_NONE;
11286
* Wait for the request to complete.
11287
@@ -396,13 +392,13 @@ static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd)
11289
/* Card removed? */
11290
if (isr & WBSD_INT_CARD)
11291
- cmd->error = MMC_ERR_TIMEOUT;
11292
+ cmd->error = -ENOMEDIUM;
11294
else if (isr & WBSD_INT_TIMEOUT)
11295
- cmd->error = MMC_ERR_TIMEOUT;
11296
+ cmd->error = -ETIMEDOUT;
11298
else if ((cmd->flags & MMC_RSP_CRC) && (isr & WBSD_INT_CRC))
11299
- cmd->error = MMC_ERR_BADCRC;
11300
+ cmd->error = -EILSEQ;
11303
if (cmd->flags & MMC_RSP_136)
11304
@@ -411,8 +407,6 @@ static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd)
11305
wbsd_get_short_reply(host, cmd);
11309
- DBGF("Sent cmd (%x), res %d\n", cmd->opcode, cmd->error);
11313
@@ -550,11 +544,6 @@ static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
11314
unsigned long dmaflags;
11317
- DBGF("blksz %04x blks %04x flags %08x\n",
11318
- data->blksz, data->blocks, data->flags);
11319
- DBGF("tsac %d ms nsac %d clk\n",
11320
- data->timeout_ns / 1000000, data->timeout_clks);
11325
@@ -596,7 +585,7 @@ static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
11326
((blksize >> 4) & 0xF0) | WBSD_DATA_WIDTH);
11327
wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF);
11329
- data->error = MMC_ERR_INVALID;
11330
+ data->error = -EINVAL;
11334
@@ -618,7 +607,7 @@ static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
11336
BUG_ON(size > 0x10000);
11337
if (size > 0x10000) {
11338
- data->error = MMC_ERR_INVALID;
11339
+ data->error = -EINVAL;
11343
@@ -680,7 +669,7 @@ static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
11347
- data->error = MMC_ERR_NONE;
11351
static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data)
11352
@@ -735,8 +724,8 @@ static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data)
11353
"%d bytes left.\n",
11354
mmc_hostname(host->mmc), count);
11356
- if (data->error == MMC_ERR_NONE)
11357
- data->error = MMC_ERR_FAILED;
11358
+ if (!data->error)
11359
+ data->error = -EIO;
11362
* Transfer data from DMA buffer to
11363
@@ -746,14 +735,12 @@ static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data)
11364
wbsd_dma_to_sg(host, data);
11367
- if (data->error != MMC_ERR_NONE) {
11368
+ if (data->error) {
11369
if (data->bytes_xfered)
11370
data->bytes_xfered -= data->blksz;
11374
- DBGF("Ending data transfer (%d bytes)\n", data->bytes_xfered);
11376
wbsd_request_end(host, host->mrq);
11379
@@ -780,11 +767,10 @@ static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
11383
- * If there is no card in the slot then
11384
- * timeout immediatly.
11385
+ * Check that there is actually a card in the slot.
11387
if (!(host->flags & WBSD_FCARD_PRESENT)) {
11388
- cmd->error = MMC_ERR_TIMEOUT;
11389
+ cmd->error = -ENOMEDIUM;
11393
@@ -820,7 +806,7 @@ static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
11394
"supported by this controller.\n",
11395
mmc_hostname(host->mmc), cmd->opcode);
11397
- cmd->error = MMC_ERR_INVALID;
11398
+ cmd->error = -EINVAL;
11402
@@ -832,7 +818,7 @@ static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
11404
wbsd_prepare_data(host, cmd->data);
11406
- if (cmd->data->error != MMC_ERR_NONE)
11407
+ if (cmd->data->error)
11411
@@ -843,7 +829,7 @@ static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
11412
* will be finished after the data has
11415
- if (cmd->data && (cmd->error == MMC_ERR_NONE)) {
11416
+ if (cmd->data && !cmd->error) {
11418
* Dirty fix for hardware bug.
11420
@@ -1046,7 +1032,7 @@ static void wbsd_tasklet_card(unsigned long param)
11421
mmc_hostname(host->mmc));
11424
- host->mrq->cmd->error = MMC_ERR_FAILED;
11425
+ host->mrq->cmd->error = -ENOMEDIUM;
11426
tasklet_schedule(&host->finish_tasklet);
11429
@@ -1110,7 +1096,7 @@ static void wbsd_tasklet_crc(unsigned long param)
11431
DBGF("CRC error\n");
11433
- data->error = MMC_ERR_BADCRC;
11434
+ data->error = -EILSEQ;
11436
tasklet_schedule(&host->finish_tasklet);
11438
@@ -1134,7 +1120,7 @@ static void wbsd_tasklet_timeout(unsigned long param)
11442
- data->error = MMC_ERR_TIMEOUT;
11443
+ data->error = -ETIMEDOUT;
11445
tasklet_schedule(&host->finish_tasklet);
11447
@@ -1233,7 +1219,7 @@ static int __devinit wbsd_alloc_mmc(struct device *dev)
11448
mmc->f_min = 375000;
11449
mmc->f_max = 24000000;
11450
mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
11451
- mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_BYTEBLOCK;
11452
+ mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE;
11454
spin_lock_init(&host->lock);
11456
@@ -1279,7 +1265,7 @@ static int __devinit wbsd_alloc_mmc(struct device *dev)
11460
-static void __devexit wbsd_free_mmc(struct device *dev)
11461
+static void wbsd_free_mmc(struct device *dev)
11463
struct mmc_host *mmc;
11464
struct wbsd_host *host;
11465
@@ -1371,7 +1357,7 @@ static int __devinit wbsd_request_region(struct wbsd_host *host, int base)
11469
-static void __devexit wbsd_release_regions(struct wbsd_host *host)
11470
+static void wbsd_release_regions(struct wbsd_host *host)
11473
release_region(host->base, 8);
11474
@@ -1447,7 +1433,7 @@ err:
11475
"Falling back on FIFO.\n", dma);
11478
-static void __devexit wbsd_release_dma(struct wbsd_host *host)
11479
+static void wbsd_release_dma(struct wbsd_host *host)
11481
if (host->dma_addr) {
11482
dma_unmap_single(mmc_dev(host->mmc), host->dma_addr,
11483
@@ -1497,7 +1483,7 @@ static int __devinit wbsd_request_irq(struct wbsd_host *host, int irq)
11487
-static void __devexit wbsd_release_irq(struct wbsd_host *host)
11488
+static void wbsd_release_irq(struct wbsd_host *host)
11492
@@ -1548,7 +1534,7 @@ static int __devinit wbsd_request_resources(struct wbsd_host *host,
11493
* Release all resources for the host.
11496
-static void __devexit wbsd_release_resources(struct wbsd_host *host)
11497
+static void wbsd_release_resources(struct wbsd_host *host)
11499
wbsd_release_dma(host);
11500
wbsd_release_irq(host);
11501
diff --git a/drivers/mmc/host/wbsd.h b/drivers/mmc/host/wbsd.h
11502
index 873bda1..0877866 100644
11503
--- a/drivers/mmc/host/wbsd.h
11504
+++ b/drivers/mmc/host/wbsd.h
11507
- * linux/drivers/mmc/wbsd.h - Winbond W83L51xD SD/MMC driver
11508
+ * linux/drivers/mmc/host/wbsd.h - Winbond W83L51xD SD/MMC driver
11510
* Copyright (C) 2004-2007 Pierre Ossman, All Rights Reserved.
11512
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
11513
index badf702..0d508ac 100644
11514
--- a/include/linux/mmc/card.h
11515
+++ b/include/linux/mmc/card.h
11516
@@ -55,7 +55,28 @@ struct sd_switch_caps {
11517
unsigned int hs_max_dtr;
11520
+struct sdio_cccr {
11521
+ unsigned int sdio_vsn;
11522
+ unsigned int sd_vsn;
11523
+ unsigned int multi_block:1,
11531
+ unsigned short vendor;
11532
+ unsigned short device;
11533
+ unsigned short blksize;
11534
+ unsigned int max_dtr;
11539
+struct sdio_func_tuple;
11541
+#define SDIO_MAX_FUNCS 7
11545
@@ -67,11 +88,13 @@ struct mmc_card {
11546
unsigned int type; /* card type */
11547
#define MMC_TYPE_MMC 0 /* MMC card */
11548
#define MMC_TYPE_SD 1 /* SD card */
11549
+#define MMC_TYPE_SDIO 2 /* SDIO card */
11550
unsigned int state; /* (our) card state */
11551
#define MMC_STATE_PRESENT (1<<0) /* present in sysfs */
11552
#define MMC_STATE_READONLY (1<<1) /* card is read-only */
11553
#define MMC_STATE_HIGHSPEED (1<<2) /* card is in high speed mode */
11554
#define MMC_STATE_BLOCKADDR (1<<3) /* card uses block-addressing */
11556
u32 raw_cid[4]; /* raw card CID */
11557
u32 raw_csd[4]; /* raw card CSD */
11558
u32 raw_scr[2]; /* raw card SCR */
11559
@@ -80,10 +103,19 @@ struct mmc_card {
11560
struct mmc_ext_csd ext_csd; /* mmc v4 extended card specific */
11561
struct sd_scr scr; /* extra SD information */
11562
struct sd_switch_caps sw_caps; /* switch (CMD6) caps */
11564
+ unsigned int sdio_funcs; /* number of SDIO functions */
11565
+ struct sdio_cccr cccr; /* common card info */
11566
+ struct sdio_cis cis; /* common tuple info */
11567
+ struct sdio_func *sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */
11568
+ unsigned num_info; /* number of info strings */
11569
+ const char **info; /* info strings */
11570
+ struct sdio_func_tuple *tuples; /* unknown common tuples */
11573
#define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC)
11574
#define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD)
11575
+#define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO)
11577
#define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT)
11578
#define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
11579
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
11580
index 04bbe12..a5f4bd3 100644
11581
--- a/include/linux/mmc/core.h
11582
+++ b/include/linux/mmc/core.h
11583
@@ -25,14 +25,20 @@ struct mmc_command {
11584
#define MMC_RSP_CRC (1 << 2) /* expect valid crc */
11585
#define MMC_RSP_BUSY (1 << 3) /* card may send busy */
11586
#define MMC_RSP_OPCODE (1 << 4) /* response contains opcode */
11587
-#define MMC_CMD_MASK (3 << 5) /* command type */
11589
+#define MMC_CMD_MASK (3 << 5) /* non-SPI command type */
11590
#define MMC_CMD_AC (0 << 5)
11591
#define MMC_CMD_ADTC (1 << 5)
11592
#define MMC_CMD_BC (2 << 5)
11593
#define MMC_CMD_BCR (3 << 5)
11595
+#define MMC_RSP_SPI_S1 (1 << 7) /* one status byte */
11596
+#define MMC_RSP_SPI_S2 (1 << 8) /* second byte */
11597
+#define MMC_RSP_SPI_B4 (1 << 9) /* four data bytes */
11598
+#define MMC_RSP_SPI_BUSY (1 << 10) /* card may send busy */
11601
- * These are the response types, and correspond to valid bit
11602
+ * These are the native response types, and correspond to valid bit
11603
* patterns of the above flags. One additional valid pattern
11604
* is all zeros, which means we don't expect a response.
11606
@@ -41,12 +47,30 @@ struct mmc_command {
11607
#define MMC_RSP_R1B (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY)
11608
#define MMC_RSP_R2 (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
11609
#define MMC_RSP_R3 (MMC_RSP_PRESENT)
11610
+#define MMC_RSP_R4 (MMC_RSP_PRESENT)
11611
+#define MMC_RSP_R5 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
11612
#define MMC_RSP_R6 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
11613
#define MMC_RSP_R7 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
11615
#define mmc_resp_type(cmd) ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))
11618
+ * These are the SPI response types for MMC, SD, and SDIO cards.
11619
+ * Commands return R1, with maybe more info. Zero is an error type;
11620
+ * callers must always provide the appropriate MMC_RSP_SPI_Rx flags.
11622
+#define MMC_RSP_SPI_R1 (MMC_RSP_SPI_S1)
11623
+#define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY)
11624
+#define MMC_RSP_SPI_R2 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
11625
+#define MMC_RSP_SPI_R3 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
11626
+#define MMC_RSP_SPI_R4 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
11627
+#define MMC_RSP_SPI_R5 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
11628
+#define MMC_RSP_SPI_R7 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
11630
+#define mmc_spi_resp_type(cmd) ((cmd)->flags & \
11631
+ (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_B4))
11634
* These are the command types.
11636
#define mmc_cmd_type(cmd) ((cmd)->flags & MMC_CMD_MASK)
11637
@@ -54,12 +78,19 @@ struct mmc_command {
11638
unsigned int retries; /* max number of retries */
11639
unsigned int error; /* command error */
11641
-#define MMC_ERR_NONE 0
11642
-#define MMC_ERR_TIMEOUT 1
11643
-#define MMC_ERR_BADCRC 2
11644
-#define MMC_ERR_FIFO 3
11645
-#define MMC_ERR_FAILED 4
11646
-#define MMC_ERR_INVALID 5
11648
+ * Standard errno values are used for errors, but some have specific
11649
+ * meaning in the MMC layer:
11651
+ * ETIMEDOUT Card took too long to respond
11652
+ * EILSEQ Basic format problem with the received or sent data
11653
+ * (e.g. CRC check failed, incorrect opcode in response
11654
+ * or bad end bit)
11655
+ * EINVAL Request cannot be performed because of restrictions
11656
+ * in hardware and/or the driver
11657
+ * ENOMEDIUM Host can determine that the slot is empty and is
11658
+ * actively failing requests
11661
struct mmc_data *data; /* data segment associated with cmd */
11662
struct mmc_request *mrq; /* associated request */
11663
@@ -76,7 +107,6 @@ struct mmc_data {
11664
#define MMC_DATA_WRITE (1 << 8)
11665
#define MMC_DATA_READ (1 << 9)
11666
#define MMC_DATA_STREAM (1 << 10)
11667
-#define MMC_DATA_MULTI (1 << 11)
11669
unsigned int bytes_xfered;
11671
@@ -99,14 +129,41 @@ struct mmc_request {
11675
-extern int mmc_wait_for_req(struct mmc_host *, struct mmc_request *);
11676
+extern void mmc_wait_for_req(struct mmc_host *, struct mmc_request *);
11677
extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int);
11678
extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
11679
struct mmc_command *, int);
11681
-extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *, int);
11682
+extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
11684
-extern void mmc_claim_host(struct mmc_host *host);
11685
+extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort);
11686
extern void mmc_release_host(struct mmc_host *host);
11689
+ * mmc_claim_host - exclusively claim a host
11690
+ * @host: mmc host to claim
11692
+ * Claim a host for a set of operations.
11694
+static inline void mmc_claim_host(struct mmc_host *host)
11696
+ __mmc_claim_host(host, NULL);
11699
+/* feng add for temply use */
11700
+#define DBG_2622 1
11703
+#define umd_dbg(f, x...) \
11704
+ printk(KERN_ERR "[%s()]: " f "\n", __func__,##x)
11705
+#define umd_enter() \
11706
+ printk(KERN_ERR "[%s()]: enter\n", __func__)
11707
+#define umd_exit() \
11708
+ printk(KERN_ERR "[%s()]: exit\n", __func__)
11710
+#define umd_dbg(f, x...) do{} while(0)
11711
+#define umd_enter() do{} while(0)
11712
+#define umd_exit() do{} while(0)
11713
+#endif /* end of DBG_2622 */
11716
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
11717
index b1350df..125eee1 100644
11718
--- a/include/linux/mmc/host.h
11719
+++ b/include/linux/mmc/host.h
11721
#ifndef LINUX_MMC_HOST_H
11722
#define LINUX_MMC_HOST_H
11724
+#include <linux/leds.h>
11726
#include <linux/mmc/core.h>
11729
@@ -51,6 +53,7 @@ struct mmc_host_ops {
11730
void (*request)(struct mmc_host *host, struct mmc_request *req);
11731
void (*set_ios)(struct mmc_host *host, struct mmc_ios *ios);
11732
int (*get_ro)(struct mmc_host *host);
11733
+ void (*enable_sdio_irq)(struct mmc_host *host, int enable);
11737
@@ -87,9 +90,10 @@ struct mmc_host {
11739
#define MMC_CAP_4_BIT_DATA (1 << 0) /* Can the host do 4 bit transfers */
11740
#define MMC_CAP_MULTIWRITE (1 << 1) /* Can accurately report bytes sent to card on error */
11741
-#define MMC_CAP_BYTEBLOCK (1 << 2) /* Can do non-log2 block sizes */
11742
-#define MMC_CAP_MMC_HIGHSPEED (1 << 3) /* Can do MMC high-speed timing */
11743
-#define MMC_CAP_SD_HIGHSPEED (1 << 4) /* Can do SD high-speed timing */
11744
+#define MMC_CAP_MMC_HIGHSPEED (1 << 2) /* Can do MMC high-speed timing */
11745
+#define MMC_CAP_SD_HIGHSPEED (1 << 3) /* Can do SD high-speed timing */
11746
+#define MMC_CAP_SDIO_IRQ (1 << 4) /* Can signal pending SDIO IRQs */
11747
+#define MMC_CAP_SPI (1 << 5) /* Talks only SPI protocols */
11749
/* host specific block data */
11750
unsigned int max_seg_size; /* see blk_queue_max_segment_size */
11751
@@ -106,6 +110,14 @@ struct mmc_host {
11752
struct mmc_ios ios; /* current io bus settings */
11753
u32 ocr; /* the current OCR setting */
11755
+ /* group bitfields together to minimize padding */
11756
+ unsigned int use_spi_crc:1;
11757
+ unsigned int claimed:1; /* host exclusively claimed */
11758
+ unsigned int bus_dead:1; /* bus has been released */
11759
+#ifdef CONFIG_MMC_DEBUG
11760
+ unsigned int removed:1; /* host is being removed */
11763
unsigned int mode; /* current card mode of host */
11764
#define MMC_MODE_MMC 0
11765
#define MMC_MODE_SD 1
11766
@@ -113,16 +125,19 @@ struct mmc_host {
11767
struct mmc_card *card; /* device attached to this host */
11769
wait_queue_head_t wq;
11770
- unsigned int claimed:1; /* host exclusively claimed */
11772
struct delayed_work detect;
11773
-#ifdef CONFIG_MMC_DEBUG
11774
- unsigned int removed:1; /* host is being removed */
11777
const struct mmc_bus_ops *bus_ops; /* current bus driver */
11778
unsigned int bus_refs; /* reference counter */
11779
- unsigned int bus_dead:1; /* bus has been released */
11781
+ unsigned int sdio_irqs;
11782
+ struct task_struct *sdio_irq_thread;
11783
+ atomic_t sdio_irq_thread_abort;
11785
+#ifdef CONFIG_LEDS_TRIGGERS
11786
+ struct led_trigger *led; /* activity led */
11789
unsigned long private[0] ____cacheline_aligned;
11791
@@ -137,6 +152,8 @@ static inline void *mmc_priv(struct mmc_host *host)
11792
return (void *)host->private;
11795
+#define mmc_host_is_spi(host) ((host)->caps & MMC_CAP_SPI)
11797
#define mmc_dev(x) ((x)->parent)
11798
#define mmc_classdev(x) (&(x)->class_dev)
11799
#define mmc_hostname(x) ((x)->class_dev.bus_id)
11800
@@ -147,5 +164,11 @@ extern int mmc_resume_host(struct mmc_host *);
11801
extern void mmc_detect_change(struct mmc_host *, unsigned long delay);
11802
extern void mmc_request_done(struct mmc_host *, struct mmc_request *);
11804
+static inline void mmc_signal_sdio_irq(struct mmc_host *host)
11806
+ host->ops->enable_sdio_irq(host, 0);
11807
+ wake_up_process(host->sdio_irq_thread);
11812
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
11813
index e3ed9b9..cdcc2da 100644
11814
--- a/include/linux/mmc/mmc.h
11815
+++ b/include/linux/mmc/mmc.h
11817
#define MMC_STOP_TRANSMISSION 12 /* ac R1b */
11818
#define MMC_SEND_STATUS 13 /* ac [31:16] RCA R1 */
11819
#define MMC_GO_INACTIVE_STATE 15 /* ac [31:16] RCA */
11820
+#define MMC_SPI_READ_OCR 58 /* spi spi_R3 */
11821
+#define MMC_SPI_CRC_ON_OFF 59 /* spi [0:0] flag spi_R1 */
11824
#define MMC_SET_BLOCKLEN 16 /* ac [31:0] block len R1 */
11830
+ MMC status in R1, for native mode (SPI bits are different)
11834
@@ -128,6 +130,29 @@
11835
#define R1_READY_FOR_DATA (1 << 8) /* sx, a */
11836
#define R1_APP_CMD (1 << 5) /* sr, c */
11839
+ * MMC/SD in SPI mode reports R1 status always, and R2 for SEND_STATUS
11840
+ * R1 is the low order byte; R2 is the next highest byte, when present.
11842
+#define R1_SPI_IDLE (1 << 0)
11843
+#define R1_SPI_ERASE_RESET (1 << 1)
11844
+#define R1_SPI_ILLEGAL_COMMAND (1 << 2)
11845
+#define R1_SPI_COM_CRC (1 << 3)
11846
+#define R1_SPI_ERASE_SEQ (1 << 4)
11847
+#define R1_SPI_ADDRESS (1 << 5)
11848
+#define R1_SPI_PARAMETER (1 << 6)
11849
+/* R1 bit 7 is always zero */
11850
+#define R2_SPI_CARD_LOCKED (1 << 8)
11851
+#define R2_SPI_WP_ERASE_SKIP (1 << 9) /* or lock/unlock fail */
11852
+#define R2_SPI_LOCK_UNLOCK_FAIL R2_SPI_WP_ERASE_SKIP
11853
+#define R2_SPI_ERROR (1 << 10)
11854
+#define R2_SPI_CC_ERROR (1 << 11)
11855
+#define R2_SPI_CARD_ECC_ERROR (1 << 12)
11856
+#define R2_SPI_WP_VIOLATION (1 << 13)
11857
+#define R2_SPI_ERASE_PARAM (1 << 14)
11858
+#define R2_SPI_OUT_OF_RANGE (1 << 15) /* or CSD overwrite */
11859
+#define R2_SPI_CSD_OVERWRITE R2_SPI_OUT_OF_RANGE
11861
/* These are unpacked versions of the actual responses */
11864
@@ -182,6 +207,7 @@ struct _mmc_csd {
11866
#define CCC_BASIC (1<<0) /* (0) Basic protocol functions */
11867
/* (CMD0,1,2,3,4,7,9,10,12,13,15) */
11868
+ /* (and for SPI, CMD58,59) */
11869
#define CCC_STREAM_READ (1<<1) /* (1) Stream read commands */
11871
#define CCC_BLOCK_READ (1<<2) /* (2) Block read commands */
11872
@@ -227,6 +253,7 @@ struct _mmc_csd {
11873
#define EXT_CSD_BUS_WIDTH 183 /* R/W */
11874
#define EXT_CSD_HS_TIMING 185 /* R/W */
11875
#define EXT_CSD_CARD_TYPE 196 /* RO */
11876
+#define EXT_CSD_REV 192 /* RO */
11877
#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
11880
diff --git a/include/linux/mmc/sdio.h b/include/linux/mmc/sdio.h
11881
new file mode 100644
11882
index 0000000..96dc68d
11884
+++ b/include/linux/mmc/sdio.h
11887
+ * include/linux/mmc/sdio.h
11889
+ * Copyright 2006-2007 Pierre Ossman
11891
+ * This program is free software; you can redistribute it and/or modify
11892
+ * it under the terms of the GNU General Public License as published by
11893
+ * the Free Software Foundation; either version 2 of the License, or (at
11894
+ * your option) any later version.
11897
+#ifndef MMC_SDIO_H
11898
+#define MMC_SDIO_H
11900
+/* SDIO commands type argument response */
11901
+#define SD_IO_SEND_OP_COND 5 /* bcr [23:0] OCR R4 */
11902
+#define SD_IO_RW_DIRECT 52 /* ac [31:0] See below R5 */
11903
+#define SD_IO_RW_EXTENDED 53 /* adtc [31:0] See below R5 */
11906
+ * SD_IO_RW_DIRECT argument format:
11909
+ * [30:28] Function number
11911
+ * [25:9] Register address
11916
+ * SD_IO_RW_EXTENDED argument format:
11919
+ * [30:28] Function number
11920
+ * [27] Block mode
11921
+ * [26] Increment address
11922
+ * [25:9] Register address
11923
+ * [8:0] Byte/block count
11927
+ SDIO status in R5
11931
+ r : detected and set for the actual command response
11932
+ x : detected and set during command execution. the host must poll
11933
+ the card by sending status command in order to read these bits.
11935
+ a : according to the card state
11936
+ b : always related to the previous command. Reception of
11937
+ a valid command will clear it (with a delay of one command)
11938
+ c : clear by read
11941
+#define R5_COM_CRC_ERROR (1 << 15) /* er, b */
11942
+#define R5_ILLEGAL_COMMAND (1 << 14) /* er, b */
11943
+#define R5_ERROR (1 << 11) /* erx, c */
11944
+#define R5_FUNCTION_NUMBER (1 << 9) /* er, c */
11945
+#define R5_OUT_OF_RANGE (1 << 8) /* er, c */
11946
+#define R5_STATUS(x) (x & 0xCB00)
11947
+#define R5_IO_CURRENT_STATE(x) ((x & 0x3000) >> 12) /* s, b */
11950
+ * Card Common Control Registers (CCCR)
11953
+#define SDIO_CCCR_CCCR 0x00
11955
+#define SDIO_CCCR_REV_1_00 0 /* CCCR/FBR Version 1.00 */
11956
+#define SDIO_CCCR_REV_1_10 1 /* CCCR/FBR Version 1.10 */
11957
+#define SDIO_CCCR_REV_1_20 2 /* CCCR/FBR Version 1.20 */
11959
+#define SDIO_SDIO_REV_1_00 0 /* SDIO Spec Version 1.00 */
11960
+#define SDIO_SDIO_REV_1_10 1 /* SDIO Spec Version 1.10 */
11961
+#define SDIO_SDIO_REV_1_20 2 /* SDIO Spec Version 1.20 */
11962
+#define SDIO_SDIO_REV_2_00 3 /* SDIO Spec Version 2.00 */
11964
+#define SDIO_CCCR_SD 0x01
11966
+#define SDIO_SD_REV_1_01 0 /* SD Physical Spec Version 1.01 */
11967
+#define SDIO_SD_REV_1_10 1 /* SD Physical Spec Version 1.10 */
11968
+#define SDIO_SD_REV_2_00 2 /* SD Physical Spec Version 2.00 */
11970
+#define SDIO_CCCR_IOEx 0x02
11971
+#define SDIO_CCCR_IORx 0x03
11973
+#define SDIO_CCCR_IENx 0x04 /* Function/Master Interrupt Enable */
11974
+#define SDIO_CCCR_INTx 0x05 /* Function Interrupt Pending */
11976
+#define SDIO_CCCR_ABORT 0x06 /* function abort/card reset */
11978
+#define SDIO_CCCR_IF 0x07 /* bus interface controls */
11980
+#define SDIO_BUS_WIDTH_1BIT 0x00
11981
+#define SDIO_BUS_WIDTH_4BIT 0x02
11983
+#define SDIO_BUS_CD_DISABLE 0x80 /* disable pull-up on DAT3 (pin 1) */
11985
+#define SDIO_CCCR_CAPS 0x08
11987
+#define SDIO_CCCR_CAP_SDC 0x01 /* can do CMD52 while data transfer */
11988
+#define SDIO_CCCR_CAP_SMB 0x02 /* can do multi-block xfers (CMD53) */
11989
+#define SDIO_CCCR_CAP_SRW 0x04 /* supports read-wait protocol */
11990
+#define SDIO_CCCR_CAP_SBS 0x08 /* supports suspend/resume */
11991
+#define SDIO_CCCR_CAP_S4MI 0x10 /* interrupt during 4-bit CMD53 */
11992
+#define SDIO_CCCR_CAP_E4MI 0x20 /* enable ints during 4-bit CMD53 */
11993
+#define SDIO_CCCR_CAP_LSC 0x40 /* low speed card */
11994
+#define SDIO_CCCR_CAP_4BLS 0x80 /* 4 bit low speed card */
11996
+#define SDIO_CCCR_CIS 0x09 /* common CIS pointer (3 bytes) */
11998
+/* Following 4 regs are valid only if SBS is set */
11999
+#define SDIO_CCCR_SUSPEND 0x0c
12000
+#define SDIO_CCCR_SELx 0x0d
12001
+#define SDIO_CCCR_EXECx 0x0e
12002
+#define SDIO_CCCR_READYx 0x0f
12004
+#define SDIO_CCCR_BLKSIZE 0x10
12006
+#define SDIO_CCCR_POWER 0x12
12008
+#define SDIO_POWER_SMPC 0x01 /* Supports Master Power Control */
12009
+#define SDIO_POWER_EMPC 0x02 /* Enable Master Power Control */
12011
+#define SDIO_CCCR_SPEED 0x13
12013
+#define SDIO_SPEED_SHS 0x01 /* Supports High-Speed mode */
12014
+#define SDIO_SPEED_EHS 0x02 /* Enable High-Speed mode */
12017
+ * Function Basic Registers (FBR)
12020
+#define SDIO_FBR_BASE(f) ((f) * 0x100) /* base of function f's FBRs */
12022
+#define SDIO_FBR_STD_IF 0x00
12024
+#define SDIO_FBR_SUPPORTS_CSA 0x40 /* supports Code Storage Area */
12025
+#define SDIO_FBR_ENABLE_CSA 0x80 /* enable Code Storage Area */
12027
+#define SDIO_FBR_STD_IF_EXT 0x01
12029
+#define SDIO_FBR_POWER 0x02
12031
+#define SDIO_FBR_POWER_SPS 0x01 /* Supports Power Selection */
12032
+#define SDIO_FBR_POWER_EPS 0x02 /* Enable (low) Power Selection */
12034
+#define SDIO_FBR_CIS 0x09 /* CIS pointer (3 bytes) */
12037
+#define SDIO_FBR_CSA 0x0C /* CSA pointer (3 bytes) */
12039
+#define SDIO_FBR_CSA_DATA 0x0F
12041
+#define SDIO_FBR_BLKSIZE 0x10 /* block size (2 bytes) */
12044
diff --git a/include/linux/mmc/sdio_func.h b/include/linux/mmc/sdio_func.h
12045
new file mode 100644
12046
index 0000000..8284be9
12048
+++ b/include/linux/mmc/sdio_func.h
12051
+ * include/linux/mmc/sdio_func.h
12053
+ * Copyright 2007 Pierre Ossman
12055
+ * This program is free software; you can redistribute it and/or modify
12056
+ * it under the terms of the GNU General Public License as published by
12057
+ * the Free Software Foundation; either version 2 of the License, or (at
12058
+ * your option) any later version.
12061
+#ifndef MMC_SDIO_FUNC_H
12062
+#define MMC_SDIO_FUNC_H
12064
+#include <linux/device.h>
12065
+#include <linux/mod_devicetable.h>
12070
+typedef void (sdio_irq_handler_t)(struct sdio_func *);
12073
+ * SDIO function CIS tuple (unknown to the core)
12075
+struct sdio_func_tuple {
12076
+ struct sdio_func_tuple *next;
12077
+ unsigned char code;
12078
+ unsigned char size;
12079
+ unsigned char data[0];
12083
+ * SDIO function devices
12085
+struct sdio_func {
12086
+ struct mmc_card *card; /* the card this device belongs to */
12087
+ struct device dev; /* the device */
12088
+ sdio_irq_handler_t *irq_handler; /* IRQ callback */
12089
+ unsigned int num; /* function number */
12091
+ unsigned char class; /* standard interface class */
12092
+ unsigned short vendor; /* vendor id */
12093
+ unsigned short device; /* device id */
12095
+ unsigned max_blksize; /* maximum block size */
12096
+ unsigned cur_blksize; /* current block size */
12098
+ unsigned int state; /* function state */
12099
+#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */
12101
+ u8 tmpbuf[4]; /* DMA:able scratch buffer */
12103
+ unsigned num_info; /* number of info strings */
12104
+ const char **info; /* info strings */
12106
+ struct sdio_func_tuple *tuples;
12109
+#define sdio_func_present(f) ((f)->state & SDIO_STATE_PRESENT)
12111
+#define sdio_func_set_present(f) ((f)->state |= SDIO_STATE_PRESENT)
12113
+#define sdio_func_id(f) ((f)->dev.bus_id)
12115
+#define sdio_get_drvdata(f) dev_get_drvdata(&(f)->dev)
12116
+#define sdio_set_drvdata(f,d) dev_set_drvdata(&(f)->dev, d)
12119
+ * SDIO function device driver
12121
+struct sdio_driver {
12123
+ const struct sdio_device_id *id_table;
12125
+ int (*probe)(struct sdio_func *, const struct sdio_device_id *);
12126
+ void (*remove)(struct sdio_func *);
12128
+ struct device_driver drv;
12132
+ * SDIO_DEVICE - macro used to describe a specific SDIO device
12133
+ * @vend: the 16 bit manufacturer code
12134
+ * @dev: the 16 bit function id
12136
+ * This macro is used to create a struct sdio_device_id that matches a
12137
+ * specific device. The class field will be set to SDIO_ANY_ID.
12139
+#define SDIO_DEVICE(vend,dev) \
12140
+ .class = SDIO_ANY_ID, \
12141
+ .vendor = (vend), .device = (dev)
12144
+ * SDIO_DEVICE_CLASS - macro used to describe a specific SDIO device class
12145
+ * @dev_class: the 8 bit standard interface code
12147
+ * This macro is used to create a struct sdio_device_id that matches a
12148
+ * specific standard SDIO function type. The vendor and device fields will
12149
+ * be set to SDIO_ANY_ID.
12151
+#define SDIO_DEVICE_CLASS(dev_class) \
12152
+ .class = (dev_class), \
12153
+ .vendor = SDIO_ANY_ID, .device = SDIO_ANY_ID
12155
+extern int sdio_register_driver(struct sdio_driver *);
12156
+extern void sdio_unregister_driver(struct sdio_driver *);
12159
+ * SDIO I/O operations
12161
+extern void sdio_claim_host(struct sdio_func *func);
12162
+extern void sdio_release_host(struct sdio_func *func);
12164
+extern int sdio_enable_func(struct sdio_func *func);
12165
+extern int sdio_disable_func(struct sdio_func *func);
12167
+extern int sdio_set_block_size(struct sdio_func *func, unsigned blksz);
12169
+extern int sdio_claim_irq(struct sdio_func *func, sdio_irq_handler_t *handler);
12170
+extern int sdio_release_irq(struct sdio_func *func);
12172
+extern unsigned char sdio_readb(struct sdio_func *func,
12173
+ unsigned int addr, int *err_ret);
12174
+extern unsigned short sdio_readw(struct sdio_func *func,
12175
+ unsigned int addr, int *err_ret);
12176
+extern unsigned long sdio_readl(struct sdio_func *func,
12177
+ unsigned int addr, int *err_ret);
12179
+extern int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
12180
+ unsigned int addr, int count);
12181
+extern int sdio_readsb(struct sdio_func *func, void *dst,
12182
+ unsigned int addr, int count);
12184
+extern void sdio_writeb(struct sdio_func *func, unsigned char b,
12185
+ unsigned int addr, int *err_ret);
12186
+extern void sdio_writew(struct sdio_func *func, unsigned short b,
12187
+ unsigned int addr, int *err_ret);
12188
+extern void sdio_writel(struct sdio_func *func, unsigned long b,
12189
+ unsigned int addr, int *err_ret);
12191
+extern int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
12192
+ void *src, int count);
12193
+extern int sdio_writesb(struct sdio_func *func, unsigned int addr,
12194
+ void *src, int count);
12196
+extern unsigned char sdio_f0_readb(struct sdio_func *func,
12197
+ unsigned int addr, int *err_ret);
12198
+extern void sdio_f0_writeb(struct sdio_func *func, unsigned char b,
12199
+ unsigned int addr, int *err_ret);
12202
diff --git a/include/linux/mmc/sdio_ids.h b/include/linux/mmc/sdio_ids.h
12203
new file mode 100644
12204
index 0000000..ea1bf5b
12206
+++ b/include/linux/mmc/sdio_ids.h
12209
+ * SDIO Classes, Interface Types, Manufacturer IDs, etc.
12212
+#ifndef MMC_SDIO_IDS_H
12213
+#define MMC_SDIO_IDS_H
12216
+ * Standard SDIO Function Interfaces
12219
+#define SDIO_CLASS_NONE 0x00 /* Not a SDIO standard interface */
12220
+#define SDIO_CLASS_UART 0x01 /* standard UART interface */
12221
+#define SDIO_CLASS_BT_A 0x02 /* Type-A BlueTooth std interface */
12222
+#define SDIO_CLASS_BT_B 0x03 /* Type-B BlueTooth std interface */
12223
+#define SDIO_CLASS_GPS 0x04 /* GPS standard interface */
12224
+#define SDIO_CLASS_CAMERA 0x05 /* Camera standard interface */
12225
+#define SDIO_CLASS_PHS 0x06 /* PHS standard interface */
12226
+#define SDIO_CLASS_WLAN 0x07 /* WLAN interface */
12227
+#define SDIO_CLASS_ATA 0x08 /* Embedded SDIO-ATA std interface */
12230
+ * Vendors and devices. Sort key: vendor first, device next.
12233
+#define SDIO_VENDOR_ID_MARVELL 0x02df
12234
+#define SDIO_DEVICE_ID_MARVELL_LIBERTAS 0x9103
12237
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
12238
index af04a55..8eff133 100644
12239
--- a/include/linux/mod_devicetable.h
12240
+++ b/include/linux/mod_devicetable.h
12241
@@ -333,4 +333,15 @@ struct parisc_device_id {
12242
#define PA_HVERSION_ANY_ID 0xffff
12243
#define PA_SVERSION_ANY_ID 0xffffffff
12247
+#define SDIO_ANY_ID (~0)
12249
+struct sdio_device_id {
12250
+ __u8 class; /* Standard interface or SDIO_ANY_ID */
12251
+ __u16 vendor; /* Vendor or SDIO_ANY_ID */
12252
+ __u16 device; /* Device ID or SDIO_ANY_ID */
12253
+ kernel_ulong_t driver_data; /* Data private to the driver */
12256
#endif /* LINUX_MOD_DEVICETABLE_H */