~ubuntu-branches/ubuntu/gutsy/linux-source-2.6.22/gutsy-updates

« back to all changes in this revision

Viewing changes to debian/binary-custom.d/lpia/patchset/0013-pierre_sdio_stack.patch

  • Committer: Bazaar Package Importer
  • Author(s): Tim Gardner, Amit Kucheria, Kees Cook, Tim Gardner, Upstream Kernel Changes
  • Date: 2008-01-28 13:46:21 UTC
  • Revision ID: james.westby@ubuntu.com-20080128134621-2g3o1x6zrnf4gf81
Tags: 2.6.22-14.51
[Amit Kucheria]

* Poulsbo: Mass update of all patches from moblin repo
* Update config.lpia to reflect new patches
* [sata_sil][sata->ide-bridg] failed to set xfermode
  - LP: #153096
* Poulsbo: remove extra patch

[Kees Cook]

* fix NFSv4 client mount regression
  - LP: #164231

[Tim Gardner]

* Support of new AMD PowerNow! (family 0x11 and beyond)
  - LP: #185649

[Upstream Kernel Changes]

* minixfs: limit minixfs printks on corrupted dir i_size (CVE-2006-6058)
* [JFFS2] Fix ACL vs. mode handling. (CVE-2007-4849)
* [IEEE80211]: avoid integer underflow for runt rx frames (CVE-2007-4997)
* [TCP]: Make sure write_queue_from does not begin with NULL ptr
  (CVE-2007-5501)
* wait_task_stopped: Check p->exit_state instead of TASK_TRACED
  (CVE-2007-5500)
* fix DLM regression
* CVE-2008-0001: Use access mode instead of open flags to determine
  needed permissions
* hrtimers: avoid overflow for large relative timeouts (CVE-2007-5966)
* isdn: avoid copying overly-long strings (CVE-2007-6063)
* I4L: fix isdn_ioctl memory overrun vulnerability (CVE-2007-6151)
* vfs: coredumping fix (CVE-2007-6206)
* tmpfs: restore missing clear_highpage (CVE-2007-6417)
* [UBUNTU] fs/dlm: Fix regression introduced with last security fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
 
 
6
Signed-off-by: Amit Kucheria <amit.kucheria@ubuntu.com>
 
7
---
 
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
 
83
 
 
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.
 
91
 
 
92
+config MMC_BLOCK_BOUNCE
 
93
+       bool "Use bounce buffer for simple hosts"
 
94
+       depends on MMC_BLOCK
 
95
+       default y
 
96
+       help
 
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.
 
102
+
 
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
 
106
+         physical memory.
 
107
+
 
108
+         If unsure, say Y here.
 
109
+
 
110
+config SDIO_UART
 
111
+       tristate "SDIO UART/GPS class support"
 
112
+       depends on MMC
 
113
+       help
 
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
 
123
 
 
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)
 
130
 
 
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;
 
135
 
 
136
        err = mmc_wait_for_cmd(card->host, &cmd, 0);
 
137
-       if ((err != MMC_ERR_NONE) || !(cmd.resp[0] & R1_APP_CMD))
 
138
+       if (err)
 
139
+               return (u32)-1;
 
140
+       if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD))
 
141
                return (u32)-1;
 
142
 
 
143
        memset(&cmd, 0, sizeof(struct mmc_command));
 
144
 
 
145
        cmd.opcode = SD_APP_SEND_NUM_WR_BLKS;
 
146
        cmd.arg = 0;
 
147
-       cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
 
148
+       cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
 
149
 
 
150
        memset(&data, 0, sizeof(struct mmc_data));
 
151
 
 
152
@@ -192,7 +194,7 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
 
153
 
 
154
        mmc_wait_for_req(card->host, &mrq);
 
155
 
 
156
-       if (cmd.error != MMC_ERR_NONE || data.error != MMC_ERR_NONE)
 
157
+       if (cmd.error || data.error)
 
158
                return (u32)-1;
 
159
 
 
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))
 
164
                        brq.cmd.arg <<= 9;
 
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;
 
169
                brq.stop.arg = 0;
 
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;
 
175
 
 
176
-               mmc_set_data_timeout(&brq.data, card, rq_data_dir(req) != READ);
 
177
-
 
178
                /*
 
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)
 
182
                        brq.data.blocks = 1;
 
183
 
 
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.
 
188
+                        */
 
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;
 
196
                }
 
197
 
 
198
+               mmc_set_data_timeout(&brq.data, card);
 
199
+
 
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);
 
203
+
 
204
+               mmc_queue_bounce_pre(mq);
 
205
 
 
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)
 
209
                }
 
210
 
 
211
                mmc_wait_for_req(card->host, &brq.mrq);
 
212
+
 
213
+               mmc_queue_bounce_post(mq);
 
214
+
 
215
                if (brq.cmd.error) {
 
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)
 
219
                        goto cmd_err;
 
220
                }
 
221
 
 
222
-               if (rq_data_dir(req) != READ) {
 
223
+               if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
 
224
                        do {
 
225
                                int err;
 
226
 
 
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);
 
230
 
 
231
-       md = kmalloc(sizeof(struct mmc_blk_data), GFP_KERNEL);
 
232
+       md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL);
 
233
        if (!md) {
 
234
                ret = -ENOMEM;
 
235
                goto out;
 
236
        }
 
237
 
 
238
-       memset(md, 0, sizeof(struct mmc_blk_data));
 
239
 
 
240
        /*
 
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);
 
250
 
 
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
 
255
@@ -1,5 +1,5 @@
 
256
 /*
 
257
- *  linux/drivers/mmc/queue.c
 
258
+ *  linux/drivers/mmc/card/queue.c
 
259
  *
 
260
  *  Copyright (C) 2003 Russell King, All Rights Reserved.
 
261
  *  Copyright 2006-2007 Pierre Ossman
 
262
@@ -11,12 +11,16 @@
 
263
  */
 
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>
 
269
 
 
270
 #include <linux/mmc/card.h>
 
271
 #include <linux/mmc/host.h>
 
272
 #include "queue.h"
 
273
 
 
274
+#define MMC_QUEUE_BOUNCESZ     65536
 
275
+
 
276
 #define MMC_QUEUE_SUSPENDED    (1 << 0)
 
277
 
 
278
 /*
 
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;
 
282
 
 
283
-       /*
 
284
-        * Set iothread to ensure that we aren't put to sleep by
 
285
-        * the process freezing.  We handle suspension ourselves.
 
286
-        */
 
287
-       current->flags |= PF_MEMALLOC|PF_NOFREEZE;
 
288
+       current->flags |= PF_MEMALLOC|PF_NOFREEZE; /* will be changed in 24 */ 
 
289
 
 
290
        down(&mq->thread_sem);
 
291
        do {
 
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.
 
295
  */
 
296
-static void mmc_request(request_queue_t *q)
 
297
+static void mmc_request(struct request_queue *q)
 
298
 {
 
299
        struct mmc_queue *mq = q->queuedata;
 
300
        struct request *req;
 
301
@@ -127,21 +127,65 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
 
302
        if (!mq->queue)
 
303
                return -ENOMEM;
 
304
 
 
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);
 
311
-
 
312
        mq->queue->queuedata = mq;
 
313
        mq->req = NULL;
 
314
 
 
315
-       mq->sg = kmalloc(sizeof(struct scatterlist) * host->max_phys_segs,
 
316
-                        GFP_KERNEL);
 
317
-       if (!mq->sg) {
 
318
-               ret = -ENOMEM;
 
319
-               goto cleanup_queue;
 
320
+       blk_queue_prep_rq(mq->queue, mmc_prep_request);
 
321
+
 
322
+#ifdef CONFIG_MMC_BLOCK_BOUNCE
 
323
+       if (host->max_hw_segs == 1) {
 
324
+               unsigned int bouncesz;
 
325
+
 
326
+               bouncesz = MMC_QUEUE_BOUNCESZ;
 
327
+
 
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;
 
332
+
 
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));
 
337
+               } else {
 
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);
 
343
+
 
344
+                       mq->sg = kmalloc(sizeof(struct scatterlist),
 
345
+                               GFP_KERNEL);
 
346
+                       if (!mq->sg) {
 
347
+                               ret = -ENOMEM;
 
348
+                               goto cleanup_queue;
 
349
+                       }
 
350
+                       //sg_init_table(mq->sg, 1);
 
351
+
 
352
+                       mq->bounce_sg = kmalloc(sizeof(struct scatterlist) *
 
353
+                               bouncesz / 512, GFP_KERNEL);
 
354
+                       if (!mq->bounce_sg) {
 
355
+                               ret = -ENOMEM;
 
356
+                               goto cleanup_queue;
 
357
+                       }
 
358
+                       //sg_init_table(mq->bounce_sg, bouncesz / 512);
 
359
+               }
 
360
+       }
 
361
+#endif
 
362
+
 
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);
 
369
+
 
370
+               mq->sg = kzalloc(sizeof(struct scatterlist) *
 
371
+                       host->max_phys_segs, GFP_KERNEL);
 
372
+               if (!mq->sg) {
 
373
+                       ret = -ENOMEM;
 
374
+                       goto cleanup_queue;
 
375
+               }
 
376
        }
 
377
 
 
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);
 
383
-               goto free_sg;
 
384
+               goto free_bounce_sg;
 
385
        }
 
386
 
 
387
        return 0;
 
388
-
 
389
- free_sg:
 
390
-       kfree(mq->sg);
 
391
-       mq->sg = NULL;
 
392
+ free_bounce_sg:
 
393
+       if (mq->bounce_sg)
 
394
+               kfree(mq->bounce_sg);
 
395
+       mq->bounce_sg = NULL;
 
396
  cleanup_queue:
 
397
+       if (mq->sg)
 
398
+               kfree(mq->sg);
 
399
+       mq->sg = NULL;
 
400
+       if (mq->bounce_buf)
 
401
+               kfree(mq->bounce_buf);
 
402
+       mq->bounce_buf = NULL;
 
403
        blk_cleanup_queue(mq->queue);
 
404
        return ret;
 
405
 }
 
406
 
 
407
 void mmc_cleanup_queue(struct mmc_queue *mq)
 
408
 {
 
409
-       request_queue_t *q = mq->queue;
 
410
+       struct request_queue *q = mq->queue;
 
411
        unsigned long flags;
 
412
 
 
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);
 
417
 
 
418
+       if (mq->bounce_sg)
 
419
+               kfree(mq->bounce_sg);
 
420
+       mq->bounce_sg = NULL;
 
421
+
 
422
        kfree(mq->sg);
 
423
        mq->sg = NULL;
 
424
 
 
425
+       if (mq->bounce_buf)
 
426
+               kfree(mq->bounce_buf);
 
427
+       mq->bounce_buf = NULL;
 
428
+
 
429
        blk_cleanup_queue(mq->queue);
 
430
 
 
431
        mq->card = NULL;
 
432
@@ -197,7 +255,7 @@ EXPORT_SYMBOL(mmc_cleanup_queue);
 
433
  */
 
434
 void mmc_queue_suspend(struct mmc_queue *mq)
 
435
 {
 
436
-       request_queue_t *q = mq->queue;
 
437
+       struct request_queue *q = mq->queue;
 
438
        unsigned long flags;
 
439
 
 
440
        if (!(mq->flags & MMC_QUEUE_SUSPENDED)) {
 
441
@@ -217,7 +275,7 @@ void mmc_queue_suspend(struct mmc_queue *mq)
 
442
  */
 
443
 void mmc_queue_resume(struct mmc_queue *mq)
 
444
 {
 
445
-       request_queue_t *q = mq->queue;
 
446
+       struct request_queue *q = mq->queue;
 
447
        unsigned long flags;
 
448
 
 
449
        if (mq->flags & MMC_QUEUE_SUSPENDED) {
 
450
@@ -231,3 +289,106 @@ void mmc_queue_resume(struct mmc_queue *mq)
 
451
        }
 
452
 }
 
453
 
 
454
+static void copy_sg(struct scatterlist *dst, unsigned int dst_len,
 
455
+       struct scatterlist *src, unsigned int src_len)
 
456
+{
 
457
+       unsigned int chunk;
 
458
+       char *dst_buf, *src_buf;
 
459
+       unsigned int dst_size, src_size;
 
460
+
 
461
+       dst_buf = NULL;
 
462
+       src_buf = NULL;
 
463
+       dst_size = 0;
 
464
+       src_size = 0;
 
465
+
 
466
+       while (src_len) {
 
467
+               BUG_ON(dst_len == 0);
 
468
+
 
469
+               if (dst_size == 0) {
 
470
+                       dst_buf = page_address(dst->page) + dst->offset;
 
471
+                       dst_size = dst->length;
 
472
+               }
 
473
+
 
474
+               if (src_size == 0) {
 
475
+                       src_buf = page_address(src->page) + src->offset;
 
476
+                       src_size = src->length;
 
477
+               }
 
478
+
 
479
+               chunk = min(dst_size, src_size);
 
480
+
 
481
+               memcpy(dst_buf, src_buf, chunk);
 
482
+
 
483
+               dst_buf += chunk;
 
484
+               src_buf += chunk;
 
485
+               dst_size -= chunk;
 
486
+               src_size -= chunk;
 
487
+
 
488
+               if (dst_size == 0) {
 
489
+                       dst++;
 
490
+                       dst_len--;
 
491
+               }
 
492
+
 
493
+               if (src_size == 0) {
 
494
+                       src++;
 
495
+                       src_len--;
 
496
+               }
 
497
+       }
 
498
+}
 
499
+
 
500
+unsigned int mmc_queue_map_sg(struct mmc_queue *mq)
 
501
+{
 
502
+       unsigned int sg_len;
 
503
+
 
504
+       if (!mq->bounce_buf)
 
505
+               return blk_rq_map_sg(mq->queue, mq->req, mq->sg);
 
506
+
 
507
+       BUG_ON(!mq->bounce_sg);
 
508
+
 
509
+       sg_len = blk_rq_map_sg(mq->queue, mq->req, mq->bounce_sg);
 
510
+
 
511
+       mq->bounce_sg_len = sg_len;
 
512
+
 
513
+       /*
 
514
+        * Shortcut in the event we only get a single entry.
 
515
+        */
 
516
+       if (sg_len == 1) {
 
517
+               memcpy(mq->sg, mq->bounce_sg, sizeof(struct scatterlist));
 
518
+               return 1;
 
519
+       }
 
520
+
 
521
+       sg_init_one(mq->sg, mq->bounce_buf, 0);
 
522
+
 
523
+       while (sg_len) {
 
524
+               mq->sg[0].length += mq->bounce_sg[sg_len - 1].length;
 
525
+               sg_len--;
 
526
+       }
 
527
+
 
528
+       return 1;
 
529
+}
 
530
+
 
531
+void mmc_queue_bounce_pre(struct mmc_queue *mq)
 
532
+{
 
533
+       if (!mq->bounce_buf)
 
534
+               return;
 
535
+
 
536
+       if (mq->bounce_sg_len == 1)
 
537
+               return;
 
538
+       if (rq_data_dir(mq->req) != WRITE)
 
539
+               return;
 
540
+
 
541
+       copy_sg(mq->sg, 1, mq->bounce_sg, mq->bounce_sg_len);
 
542
+}
 
543
+
 
544
+void mmc_queue_bounce_post(struct mmc_queue *mq)
 
545
+{
 
546
+       if (!mq->bounce_buf)
 
547
+               return;
 
548
+
 
549
+       if (mq->bounce_sg_len == 1)
 
550
+               return;
 
551
+       if (rq_data_dir(mq->req) != READ)
 
552
+               return;
 
553
+
 
554
+       copy_sg(mq->bounce_sg, mq->bounce_sg_len, mq->sg, 1);
 
555
+}
 
556
+
 
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 {
 
562
        void                    *data;
 
563
        struct request_queue    *queue;
 
564
        struct scatterlist      *sg;
 
565
+       char                    *bounce_buf;
 
566
+       struct scatterlist      *bounce_sg;
 
567
+       unsigned int            bounce_sg_len;
 
568
 };
 
569
 
 
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 *);
 
574
 
 
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 *);
 
578
+
 
579
 #endif
 
580
diff --git a/drivers/mmc/card/sdio_uart.c b/drivers/mmc/card/sdio_uart.c
 
581
new file mode 100644
 
582
index 0000000..d552de6
 
583
--- /dev/null
 
584
+++ b/drivers/mmc/card/sdio_uart.c
 
585
@@ -0,0 +1,1158 @@
 
586
+/*
 
587
+ * linux/drivers/mmc/card/sdio_uart.c - SDIO UART/GPS driver
 
588
+ *
 
589
+ * Based on drivers/serial/8250.c and drivers/serial/serial_core.c
 
590
+ * by Russell King.
 
591
+ *
 
592
+ * Author:     Nicolas Pitre
 
593
+ * Created:    June 15, 2007
 
594
+ * Copyright:  MontaVista Software, Inc.
 
595
+ *
 
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.
 
600
+ */
 
601
+
 
602
+/*
 
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.
 
608
+ *
 
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.
 
612
+ */
 
613
+
 
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>
 
623
+
 
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>
 
628
+
 
629
+
 
630
+#define UART_NR                8       /* Number of UARTs this driver can handle */
 
631
+
 
632
+
 
633
+#define UART_XMIT_SIZE PAGE_SIZE
 
634
+#define WAKEUP_CHARS   256
 
635
+
 
636
+#define circ_empty(circ)       ((circ)->head == (circ)->tail)
 
637
+#define circ_clear(circ)       ((circ)->head = (circ)->tail = 0)
 
638
+
 
639
+#define circ_chars_pending(circ) \
 
640
+               (CIRC_CNT((circ)->head, (circ)->tail, UART_XMIT_SIZE))
 
641
+
 
642
+#define circ_chars_free(circ) \
 
643
+               (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE))
 
644
+
 
645
+
 
646
+struct uart_icount {
 
647
+       __u32   cts;
 
648
+       __u32   dsr;
 
649
+       __u32   rng;
 
650
+       __u32   dcd;
 
651
+       __u32   rx;
 
652
+       __u32   tx;
 
653
+       __u32   frame;
 
654
+       __u32   overrun;
 
655
+       __u32   parity;
 
656
+       __u32   brk;
 
657
+};
 
658
+
 
659
+struct sdio_uart_port {
 
660
+       struct kref             kref;
 
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;
 
677
+       unsigned char           ier;
 
678
+       unsigned char           lcr;
 
679
+};
 
680
+
 
681
+static struct sdio_uart_port *sdio_uart_table[UART_NR];
 
682
+static DEFINE_SPINLOCK(sdio_uart_table_lock);
 
683
+
 
684
+static int sdio_uart_add_port(struct sdio_uart_port *port)
 
685
+{
 
686
+       int index, ret = -EBUSY;
 
687
+
 
688
+       kref_init(&port->kref);
 
689
+       mutex_init(&port->open_lock);
 
690
+       mutex_init(&port->func_lock);
 
691
+       spin_lock_init(&port->write_lock);
 
692
+
 
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;
 
698
+                       ret = 0;
 
699
+                       break;
 
700
+               }
 
701
+       }
 
702
+       spin_unlock(&sdio_uart_table_lock);
 
703
+
 
704
+       return ret;
 
705
+}
 
706
+
 
707
+static struct sdio_uart_port *sdio_uart_port_get(unsigned index)
 
708
+{
 
709
+       struct sdio_uart_port *port;
 
710
+
 
711
+       if (index >= UART_NR)
 
712
+               return NULL;
 
713
+
 
714
+       spin_lock(&sdio_uart_table_lock);
 
715
+       port = sdio_uart_table[index];
 
716
+       if (port)
 
717
+               kref_get(&port->kref);
 
718
+       spin_unlock(&sdio_uart_table_lock);
 
719
+
 
720
+       return port;
 
721
+}
 
722
+
 
723
+static void sdio_uart_port_destroy(struct kref *kref)
 
724
+{
 
725
+       struct sdio_uart_port *port =
 
726
+               container_of(kref, struct sdio_uart_port, kref);
 
727
+       kfree(port);
 
728
+}
 
729
+
 
730
+static void sdio_uart_port_put(struct sdio_uart_port *port)
 
731
+{
 
732
+       kref_put(&port->kref, sdio_uart_port_destroy);
 
733
+}
 
734
+
 
735
+static void sdio_uart_port_remove(struct sdio_uart_port *port)
 
736
+{
 
737
+       struct sdio_func *func;
 
738
+
 
739
+       BUG_ON(sdio_uart_table[port->index] != port);
 
740
+
 
741
+       spin_lock(&sdio_uart_table_lock);
 
742
+       sdio_uart_table[port->index] = NULL;
 
743
+       spin_unlock(&sdio_uart_table_lock);
 
744
+
 
745
+       /*
 
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.
 
751
+        */
 
752
+       mutex_lock(&port->open_lock);
 
753
+       mutex_lock(&port->func_lock);
 
754
+       func = port->func;
 
755
+       sdio_claim_host(func);
 
756
+       port->func = NULL;
 
757
+       mutex_unlock(&port->func_lock);
 
758
+       if (port->opened)
 
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);
 
764
+
 
765
+       sdio_uart_port_put(port);
 
766
+}
 
767
+
 
768
+static int sdio_uart_claim_func(struct sdio_uart_port *port)
 
769
+{
 
770
+       mutex_lock(&port->func_lock);
 
771
+       if (unlikely(!port->func)) {
 
772
+               mutex_unlock(&port->func_lock);
 
773
+               return -ENODEV;
 
774
+       }
 
775
+       if (likely(port->in_sdio_uart_irq != current))
 
776
+               sdio_claim_host(port->func);
 
777
+       mutex_unlock(&port->func_lock);
 
778
+       return 0;
 
779
+}
 
780
+
 
781
+static inline void sdio_uart_release_func(struct sdio_uart_port *port)
 
782
+{
 
783
+       if (likely(port->in_sdio_uart_irq != current))
 
784
+               sdio_release_host(port->func);
 
785
+}
 
786
+
 
787
+static inline unsigned int sdio_in(struct sdio_uart_port *port, int offset)
 
788
+{
 
789
+       unsigned char c;
 
790
+       c = sdio_readb(port->func, port->regs_offset + offset, NULL);
 
791
+       return c;
 
792
+}
 
793
+
 
794
+static inline void sdio_out(struct sdio_uart_port *port, int offset, int value)
 
795
+{
 
796
+       sdio_writeb(port->func, value, port->regs_offset + offset, NULL);
 
797
+}
 
798
+
 
799
+static unsigned int sdio_uart_get_mctrl(struct sdio_uart_port *port)
 
800
+{
 
801
+       unsigned char status;
 
802
+       unsigned int ret;
 
803
+
 
804
+       status = sdio_in(port, UART_MSR);
 
805
+
 
806
+       ret = 0;
 
807
+       if (status & UART_MSR_DCD)
 
808
+               ret |= TIOCM_CAR;
 
809
+       if (status & UART_MSR_RI)
 
810
+               ret |= TIOCM_RNG;
 
811
+       if (status & UART_MSR_DSR)
 
812
+               ret |= TIOCM_DSR;
 
813
+       if (status & UART_MSR_CTS)
 
814
+               ret |= TIOCM_CTS;
 
815
+       return ret;
 
816
+}
 
817
+
 
818
+static void sdio_uart_write_mctrl(struct sdio_uart_port *port, unsigned int mctrl)
 
819
+{
 
820
+       unsigned char mcr = 0;
 
821
+
 
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;
 
832
+
 
833
+       sdio_out(port, UART_MCR, mcr);
 
834
+}
 
835
+
 
836
+static inline void sdio_uart_update_mctrl(struct sdio_uart_port *port,
 
837
+                                         unsigned int set, unsigned int clear)
 
838
+{
 
839
+       unsigned int old;
 
840
+
 
841
+       old = port->mctrl;
 
842
+       port->mctrl = (old & ~clear) | set;
 
843
+       if (old != port->mctrl)
 
844
+               sdio_uart_write_mctrl(port, port->mctrl);
 
845
+}
 
846
+
 
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)
 
849
+
 
850
+static void sdio_uart_change_speed(struct sdio_uart_port *port,
 
851
+                                  struct ktermios *termios,
 
852
+                                  struct ktermios *old)
 
853
+{
 
854
+       unsigned char cval, fcr = 0;
 
855
+       unsigned int baud, quot;
 
856
+
 
857
+       switch (termios->c_cflag & CSIZE) {
 
858
+       case CS5:
 
859
+               cval = UART_LCR_WLEN5;
 
860
+               break;
 
861
+       case CS6:
 
862
+               cval = UART_LCR_WLEN6;
 
863
+               break;
 
864
+       case CS7:
 
865
+               cval = UART_LCR_WLEN7;
 
866
+               break;
 
867
+       default:
 
868
+       case CS8:
 
869
+               cval = UART_LCR_WLEN8;
 
870
+               break;
 
871
+       }
 
872
+
 
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;
 
879
+
 
880
+       for (;;) {
 
881
+               baud = tty_termios_baud_rate(termios);
 
882
+               if (baud == 0)
 
883
+                       baud = 9600;  /* Special case: B0 rate. */
 
884
+               if (baud <= port->uartclk)
 
885
+                       break;
 
886
+               /*
 
887
+                * Oops, the quotient was zero.  Try again with the old
 
888
+                * baud rate if possible, otherwise default to 9600.
 
889
+                */
 
890
+               termios->c_cflag &= ~CBAUD;
 
891
+               if (old) {
 
892
+                       termios->c_cflag |= old->c_cflag & CBAUD;
 
893
+                       old = NULL;
 
894
+               } else
 
895
+                       termios->c_cflag |= B9600;
 
896
+       }
 
897
+       quot = (2 * port->uartclk + baud) / (2 * baud);
 
898
+
 
899
+       if (baud < 2400)
 
900
+               fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
 
901
+       else
 
902
+               fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10;
 
903
+
 
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;
 
909
+
 
910
+       /*
 
911
+        * Characters to ignore
 
912
+        */
 
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;
 
918
+               /*
 
919
+                * If we're ignoring parity and break indicators,
 
920
+                * ignore overruns too (for real raw support).
 
921
+                */
 
922
+               if (termios->c_iflag & IGNPAR)
 
923
+                       port->ignore_status_mask |= UART_LSR_OE;
 
924
+       }
 
925
+
 
926
+       /*
 
927
+        * ignore all characters if CREAD is not set
 
928
+        */
 
929
+       if ((termios->c_cflag & CREAD) == 0)
 
930
+               port->ignore_status_mask |= UART_LSR_DR;
 
931
+
 
932
+       /*
 
933
+        * CTS flow control flag and modem status interrupts
 
934
+        */
 
935
+       port->ier &= ~UART_IER_MSI;
 
936
+       if ((termios->c_cflag & CRTSCTS) || !(termios->c_cflag & CLOCAL))
 
937
+               port->ier |= UART_IER_MSI;
 
938
+
 
939
+       port->lcr = cval;
 
940
+
 
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);
 
947
+
 
948
+       sdio_uart_write_mctrl(port, port->mctrl);
 
949
+}
 
950
+
 
951
+static void sdio_uart_start_tx(struct sdio_uart_port *port)
 
952
+{
 
953
+       if (!(port->ier & UART_IER_THRI)) {
 
954
+               port->ier |= UART_IER_THRI;
 
955
+               sdio_out(port, UART_IER, port->ier);
 
956
+       }
 
957
+}
 
958
+
 
959
+static void sdio_uart_stop_tx(struct sdio_uart_port *port)
 
960
+{
 
961
+       if (port->ier & UART_IER_THRI) {
 
962
+               port->ier &= ~UART_IER_THRI;
 
963
+               sdio_out(port, UART_IER, port->ier);
 
964
+       }
 
965
+}
 
966
+
 
967
+static void sdio_uart_stop_rx(struct sdio_uart_port *port)
 
968
+{
 
969
+       port->ier &= ~UART_IER_RLSI;
 
970
+       port->read_status_mask &= ~UART_LSR_DR;
 
971
+       sdio_out(port, UART_IER, port->ier);
 
972
+}
 
973
+
 
974
+static void sdio_uart_receive_chars(struct sdio_uart_port *port, int *status)
 
975
+{
 
976
+       struct tty_struct *tty = port->tty;
 
977
+       unsigned int ch, flag;
 
978
+       int max_count = 256;
 
979
+
 
980
+       do {
 
981
+               ch = sdio_in(port, UART_RX);
 
982
+               flag = TTY_NORMAL;
 
983
+               port->icount.rx++;
 
984
+
 
985
+               if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
 
986
+                                       UART_LSR_FE | UART_LSR_OE))) {
 
987
+                       /*
 
988
+                        * For statistics only
 
989
+                        */
 
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++;
 
999
+
 
1000
+                       /*
 
1001
+                        * Mask off conditions which should be ignored.
 
1002
+                        */
 
1003
+                       *status &= port->read_status_mask;
 
1004
+                       if (*status & UART_LSR_BI) {
 
1005
+                               flag = TTY_BREAK;
 
1006
+                       } else if (*status & UART_LSR_PE)
 
1007
+                               flag = TTY_PARITY;
 
1008
+                       else if (*status & UART_LSR_FE)
 
1009
+                               flag = TTY_FRAME;
 
1010
+               }
 
1011
+
 
1012
+               if ((*status & port->ignore_status_mask & ~UART_LSR_OE) == 0)
 
1013
+                       tty_insert_flip_char(tty, ch, flag);
 
1014
+
 
1015
+               /*
 
1016
+                * Overrun is special.  Since it's reported immediately,
 
1017
+                * it doesn't affect the current character.
 
1018
+                */
 
1019
+               if (*status & ~port->ignore_status_mask & UART_LSR_OE)
 
1020
+                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 
1021
+
 
1022
+               *status = sdio_in(port, UART_LSR);
 
1023
+       } while ((*status & UART_LSR_DR) && (max_count-- > 0));
 
1024
+       tty_flip_buffer_push(tty);
 
1025
+}
 
1026
+
 
1027
+static void sdio_uart_transmit_chars(struct sdio_uart_port *port)
 
1028
+{
 
1029
+       struct circ_buf *xmit = &port->xmit;
 
1030
+       int count;
 
1031
+
 
1032
+       if (port->x_char) {
 
1033
+               sdio_out(port, UART_TX, port->x_char);
 
1034
+               port->icount.tx++;
 
1035
+               port->x_char = 0;
 
1036
+               return;
 
1037
+       }
 
1038
+       if (circ_empty(xmit) || port->tty->stopped || port->tty->hw_stopped) {
 
1039
+               sdio_uart_stop_tx(port);
 
1040
+               return;
 
1041
+       }
 
1042
+
 
1043
+       count = 16;
 
1044
+       do {
 
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))
 
1049
+                       break;
 
1050
+       } while (--count > 0);
 
1051
+
 
1052
+       if (circ_chars_pending(xmit) < WAKEUP_CHARS)
 
1053
+               tty_wakeup(port->tty);
 
1054
+
 
1055
+       if (circ_empty(xmit))
 
1056
+               sdio_uart_stop_tx(port);
 
1057
+}
 
1058
+
 
1059
+static void sdio_uart_check_modem_status(struct sdio_uart_port *port)
 
1060
+{
 
1061
+       int status;
 
1062
+
 
1063
+       status = sdio_in(port, UART_MSR);
 
1064
+
 
1065
+       if ((status & UART_MSR_ANY_DELTA) == 0)
 
1066
+               return;
 
1067
+
 
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) {
 
1079
+                               if (cts) {
 
1080
+                                       port->tty->hw_stopped = 0;
 
1081
+                                       sdio_uart_start_tx(port);
 
1082
+                                       tty_wakeup(port->tty);
 
1083
+                               }
 
1084
+                       } else {
 
1085
+                               if (!cts) {
 
1086
+                                       port->tty->hw_stopped = 1;
 
1087
+                                       sdio_uart_stop_tx(port);
 
1088
+                               }
 
1089
+                       }
 
1090
+               }
 
1091
+       }
 
1092
+}
 
1093
+
 
1094
+/*
 
1095
+ * This handles the interrupt from one port.
 
1096
+ */
 
1097
+static void sdio_uart_irq(struct sdio_func *func)
 
1098
+{
 
1099
+       struct sdio_uart_port *port = sdio_get_drvdata(func);
 
1100
+       unsigned int iir, lsr;
 
1101
+
 
1102
+       /*
 
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.
 
1109
+        */
 
1110
+       if (unlikely(port->in_sdio_uart_irq == current))
 
1111
+               return;
 
1112
+
 
1113
+       iir = sdio_in(port, UART_IIR);
 
1114
+       if (iir & UART_IIR_NO_INT)
 
1115
+               return;
 
1116
+
 
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;
 
1125
+}
 
1126
+
 
1127
+static int sdio_uart_startup(struct sdio_uart_port *port)
 
1128
+{
 
1129
+       unsigned long page;
 
1130
+       int ret;
 
1131
+
 
1132
+       /*
 
1133
+        * Set the TTY IO error marker - we will only clear this
 
1134
+        * once we have successfully opened the port.
 
1135
+        */
 
1136
+       set_bit(TTY_IO_ERROR, &port->tty->flags);
 
1137
+
 
1138
+       /* Initialise and allocate the transmit buffer. */
 
1139
+       page = __get_free_page(GFP_KERNEL);
 
1140
+       if (!page)
 
1141
+               return -ENOMEM;
 
1142
+       port->xmit.buf = (unsigned char *)page;
 
1143
+       circ_clear(&port->xmit);
 
1144
+
 
1145
+       ret = sdio_uart_claim_func(port);
 
1146
+       if (ret)
 
1147
+               goto err1;
 
1148
+       ret = sdio_enable_func(port->func);
 
1149
+       if (ret)
 
1150
+               goto err2;
 
1151
+       ret = sdio_claim_irq(port->func, sdio_uart_irq);
 
1152
+       if (ret)
 
1153
+               goto err3;
 
1154
+
 
1155
+       /*
 
1156
+        * Clear the FIFO buffers and disable them.
 
1157
+        * (they will be reenabled in sdio_change_speed())
 
1158
+        */
 
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);
 
1163
+
 
1164
+       /*
 
1165
+        * Clear the interrupt registers.
 
1166
+        */
 
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);
 
1171
+
 
1172
+       /*
 
1173
+        * Now, initialize the UART
 
1174
+        */
 
1175
+       sdio_out(port, UART_LCR, UART_LCR_WLEN8);
 
1176
+
 
1177
+       port->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE | UART_IER_UUE;
 
1178
+       port->mctrl = TIOCM_OUT2;
 
1179
+
 
1180
+       sdio_uart_change_speed(port, port->tty->termios, NULL);
 
1181
+
 
1182
+       if (port->tty->termios->c_cflag & CBAUD)
 
1183
+               sdio_uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR);
 
1184
+
 
1185
+       if (port->tty->termios->c_cflag & CRTSCTS)
 
1186
+               if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS))
 
1187
+                       port->tty->hw_stopped = 1;
 
1188
+
 
1189
+       clear_bit(TTY_IO_ERROR, &port->tty->flags);
 
1190
+
 
1191
+       /* Kick the IRQ handler once while we're still holding the host lock */
 
1192
+       sdio_uart_irq(port->func);
 
1193
+
 
1194
+       sdio_uart_release_func(port);
 
1195
+       return 0;
 
1196
+
 
1197
+err3:
 
1198
+       sdio_disable_func(port->func);
 
1199
+err2:
 
1200
+       sdio_uart_release_func(port);
 
1201
+err1:
 
1202
+       free_page((unsigned long)port->xmit.buf);
 
1203
+       return ret;
 
1204
+}
 
1205
+
 
1206
+static void sdio_uart_shutdown(struct sdio_uart_port *port)
 
1207
+{
 
1208
+       int ret;
 
1209
+
 
1210
+       ret = sdio_uart_claim_func(port);
 
1211
+       if (ret)
 
1212
+               goto skip;
 
1213
+
 
1214
+       sdio_uart_stop_rx(port);
 
1215
+
 
1216
+       /* TODO: wait here for TX FIFO to drain */
 
1217
+
 
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);
 
1221
+
 
1222
+        /* Disable interrupts from this port */
 
1223
+       sdio_release_irq(port->func);
 
1224
+       port->ier = 0;
 
1225
+       sdio_out(port, UART_IER, 0);
 
1226
+
 
1227
+       sdio_uart_clear_mctrl(port, TIOCM_OUT2);
 
1228
+
 
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);
 
1236
+
 
1237
+       sdio_disable_func(port->func);
 
1238
+
 
1239
+       sdio_uart_release_func(port);
 
1240
+
 
1241
+skip:
 
1242
+       /* Free the transmit buffer page. */
 
1243
+       free_page((unsigned long)port->xmit.buf);
 
1244
+}
 
1245
+
 
1246
+static int sdio_uart_open (struct tty_struct *tty, struct file * filp)
 
1247
+{
 
1248
+       struct sdio_uart_port *port;
 
1249
+       int ret;
 
1250
+
 
1251
+       port = sdio_uart_port_get(tty->index);
 
1252
+       if (!port)
 
1253
+               return -ENODEV;
 
1254
+
 
1255
+       mutex_lock(&port->open_lock);
 
1256
+
 
1257
+       /*
 
1258
+        * Make sure not to mess up with a dead port
 
1259
+        * which has not been closed yet.
 
1260
+        */
 
1261
+       if (tty->driver_data && tty->driver_data != port) {
 
1262
+               mutex_unlock(&port->open_lock);
 
1263
+               sdio_uart_port_put(port);
 
1264
+               return -EBUSY;
 
1265
+       }
 
1266
+
 
1267
+       if (!port->opened) {
 
1268
+               tty->driver_data = port;
 
1269
+               port->tty = tty;
 
1270
+               ret = sdio_uart_startup(port);
 
1271
+               if (ret) {
 
1272
+                       tty->driver_data = NULL;
 
1273
+                       port->tty = NULL;
 
1274
+                       mutex_unlock(&port->open_lock);
 
1275
+                       sdio_uart_port_put(port);
 
1276
+                       return ret;
 
1277
+               }
 
1278
+       }
 
1279
+       port->opened++;
 
1280
+       mutex_unlock(&port->open_lock);
 
1281
+       return 0;
 
1282
+}
 
1283
+
 
1284
+static void sdio_uart_close(struct tty_struct *tty, struct file * filp)
 
1285
+{
 
1286
+       struct sdio_uart_port *port = tty->driver_data;
 
1287
+
 
1288
+       if (!port)
 
1289
+               return;
 
1290
+
 
1291
+       mutex_lock(&port->open_lock);
 
1292
+       BUG_ON(!port->opened);
 
1293
+
 
1294
+       /*
 
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.
 
1298
+        */
 
1299
+       if (tty->count > port->opened) {
 
1300
+               mutex_unlock(&port->open_lock);
 
1301
+               return;
 
1302
+       }
 
1303
+
 
1304
+       if (--port->opened == 0) {
 
1305
+               tty->closing = 1;
 
1306
+               sdio_uart_shutdown(port);
 
1307
+               tty_ldisc_flush(tty);
 
1308
+               port->tty = NULL;
 
1309
+               tty->driver_data = NULL;
 
1310
+               tty->closing = 0;
 
1311
+       }
 
1312
+       mutex_unlock(&port->open_lock);
 
1313
+       sdio_uart_port_put(port);
 
1314
+}
 
1315
+
 
1316
+static int sdio_uart_write(struct tty_struct * tty, const unsigned char *buf,
 
1317
+                          int count)
 
1318
+{
 
1319
+       struct sdio_uart_port *port = tty->driver_data;
 
1320
+       struct circ_buf *circ = &port->xmit;
 
1321
+       int c, ret = 0;
 
1322
+
 
1323
+       if (!port->func)
 
1324
+               return -ENODEV;
 
1325
+
 
1326
+       spin_lock(&port->write_lock);
 
1327
+       while (1) {
 
1328
+               c = CIRC_SPACE_TO_END(circ->head, circ->tail, UART_XMIT_SIZE);
 
1329
+               if (count < c)
 
1330
+                       c = count;
 
1331
+               if (c <= 0)
 
1332
+                       break;
 
1333
+               memcpy(circ->buf + circ->head, buf, c);
 
1334
+               circ->head = (circ->head + c) & (UART_XMIT_SIZE - 1);
 
1335
+               buf += c;
 
1336
+               count -= c;
 
1337
+               ret += c;
 
1338
+       }
 
1339
+       spin_unlock(&port->write_lock);
 
1340
+
 
1341
+       if ( !(port->ier & UART_IER_THRI)) {
 
1342
+               int err = sdio_uart_claim_func(port);
 
1343
+               if (!err) {
 
1344
+                       sdio_uart_start_tx(port);
 
1345
+                       sdio_uart_irq(port->func);
 
1346
+                       sdio_uart_release_func(port);
 
1347
+               } else
 
1348
+                       ret = err;
 
1349
+       }
 
1350
+
 
1351
+       return ret;
 
1352
+}
 
1353
+
 
1354
+static int sdio_uart_write_room(struct tty_struct *tty)
 
1355
+{
 
1356
+       struct sdio_uart_port *port = tty->driver_data;
 
1357
+       return port ? circ_chars_free(&port->xmit) : 0;
 
1358
+}
 
1359
+
 
1360
+static int sdio_uart_chars_in_buffer(struct tty_struct *tty)
 
1361
+{
 
1362
+       struct sdio_uart_port *port = tty->driver_data;
 
1363
+       return port ? circ_chars_pending(&port->xmit) : 0;
 
1364
+}
 
1365
+
 
1366
+static void sdio_uart_send_xchar(struct tty_struct *tty, char ch)
 
1367
+{
 
1368
+       struct sdio_uart_port *port = tty->driver_data;
 
1369
+
 
1370
+       port->x_char = ch;
 
1371
+       if (ch && !(port->ier & UART_IER_THRI)) {
 
1372
+               if (sdio_uart_claim_func(port) != 0)
 
1373
+                       return;
 
1374
+               sdio_uart_start_tx(port);
 
1375
+               sdio_uart_irq(port->func);
 
1376
+               sdio_uart_release_func(port);
 
1377
+       }
 
1378
+}
 
1379
+
 
1380
+static void sdio_uart_throttle(struct tty_struct *tty)
 
1381
+{
 
1382
+       struct sdio_uart_port *port = tty->driver_data;
 
1383
+
 
1384
+       if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS))
 
1385
+               return;
 
1386
+
 
1387
+       if (sdio_uart_claim_func(port) != 0)
 
1388
+               return;
 
1389
+
 
1390
+       if (I_IXOFF(tty)) {
 
1391
+               port->x_char = STOP_CHAR(tty);
 
1392
+               sdio_uart_start_tx(port);
 
1393
+       }
 
1394
+
 
1395
+       if (tty->termios->c_cflag & CRTSCTS)
 
1396
+               sdio_uart_clear_mctrl(port, TIOCM_RTS);
 
1397
+
 
1398
+       sdio_uart_irq(port->func);
 
1399
+       sdio_uart_release_func(port);
 
1400
+}
 
1401
+
 
1402
+static void sdio_uart_unthrottle(struct tty_struct *tty)
 
1403
+{
 
1404
+       struct sdio_uart_port *port = tty->driver_data;
 
1405
+
 
1406
+       if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS))
 
1407
+               return;
 
1408
+
 
1409
+       if (sdio_uart_claim_func(port) != 0)
 
1410
+               return;
 
1411
+
 
1412
+       if (I_IXOFF(tty)) {
 
1413
+               if (port->x_char) {
 
1414
+                       port->x_char = 0;
 
1415
+               } else {
 
1416
+                       port->x_char = START_CHAR(tty);
 
1417
+                       sdio_uart_start_tx(port);
 
1418
+               }
 
1419
+       }
 
1420
+
 
1421
+       if (tty->termios->c_cflag & CRTSCTS)
 
1422
+               sdio_uart_set_mctrl(port, TIOCM_RTS);
 
1423
+
 
1424
+       sdio_uart_irq(port->func);
 
1425
+       sdio_uart_release_func(port);
 
1426
+}
 
1427
+
 
1428
+static void sdio_uart_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
 
1429
+{
 
1430
+       struct sdio_uart_port *port = tty->driver_data;
 
1431
+       unsigned int cflag = tty->termios->c_cflag;
 
1432
+
 
1433
+#define RELEVANT_IFLAG(iflag)   ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
 
1434
+
 
1435
+       if ((cflag ^ old_termios->c_cflag) == 0 &&
 
1436
+           RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0)
 
1437
+               return;
 
1438
+
 
1439
+       if (sdio_uart_claim_func(port) != 0)
 
1440
+               return;
 
1441
+
 
1442
+       sdio_uart_change_speed(port, tty->termios, old_termios);
 
1443
+
 
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);
 
1447
+
 
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);
 
1454
+       }
 
1455
+
 
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);
 
1460
+       }
 
1461
+
 
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);
 
1467
+               }
 
1468
+       }
 
1469
+
 
1470
+       sdio_uart_release_func(port);
 
1471
+}
 
1472
+
 
1473
+static void sdio_uart_break_ctl(struct tty_struct *tty, int break_state)
 
1474
+{
 
1475
+       struct sdio_uart_port *port = tty->driver_data;
 
1476
+
 
1477
+       if (sdio_uart_claim_func(port) != 0)
 
1478
+               return;
 
1479
+
 
1480
+       if (break_state == -1)
 
1481
+               port->lcr |= UART_LCR_SBC;
 
1482
+       else
 
1483
+               port->lcr &= ~UART_LCR_SBC;
 
1484
+       sdio_out(port, UART_LCR, port->lcr);
 
1485
+
 
1486
+       sdio_uart_release_func(port);
 
1487
+}
 
1488
+
 
1489
+static int sdio_uart_tiocmget(struct tty_struct *tty, struct file *file)
 
1490
+{
 
1491
+       struct sdio_uart_port *port = tty->driver_data;
 
1492
+       int result;
 
1493
+
 
1494
+       result = sdio_uart_claim_func(port);
 
1495
+       if (!result) {
 
1496
+               result = port->mctrl | sdio_uart_get_mctrl(port);
 
1497
+               sdio_uart_release_func(port);
 
1498
+       }
 
1499
+
 
1500
+       return result;
 
1501
+}
 
1502
+
 
1503
+static int sdio_uart_tiocmset(struct tty_struct *tty, struct file *file,
 
1504
+                             unsigned int set, unsigned int clear)
 
1505
+{
 
1506
+       struct sdio_uart_port *port = tty->driver_data;
 
1507
+       int result;
 
1508
+
 
1509
+       result =sdio_uart_claim_func(port);
 
1510
+       if(!result) {
 
1511
+               sdio_uart_update_mctrl(port, set, clear);
 
1512
+               sdio_uart_release_func(port);
 
1513
+       }
 
1514
+
 
1515
+       return result;
 
1516
+}
 
1517
+
 
1518
+static int sdio_uart_read_proc(char *page, char **start, off_t off,
 
1519
+                              int count, int *eof, void *data)
 
1520
+{
 
1521
+       int i, len = 0;
 
1522
+       off_t begin = 0;
 
1523
+
 
1524
+       len += sprintf(page, "serinfo:1.0 driver%s%s revision:%s\n",
 
1525
+                      "", "", "");
 
1526
+       for (i = 0; i < UART_NR && len < PAGE_SIZE - 96; i++) {
 
1527
+               struct sdio_uart_port *port = sdio_uart_port_get(i);
 
1528
+               if (port) {
 
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);
 
1557
+                       }
 
1558
+                       strcat(page, "\n");
 
1559
+                       len++;
 
1560
+                       sdio_uart_port_put(port);
 
1561
+               }
 
1562
+
 
1563
+               if (len + begin > off + count)
 
1564
+                       goto done;
 
1565
+               if (len + begin < off) {
 
1566
+                       begin += len;
 
1567
+                       len = 0;
 
1568
+               }
 
1569
+       }
 
1570
+       *eof = 1;
 
1571
+
 
1572
+done:
 
1573
+       if (off >= len + begin)
 
1574
+               return 0;
 
1575
+       *start = page + (off - begin);
 
1576
+       return (count < begin + len - off) ? count : (begin + len - off);
 
1577
+}
 
1578
+
 
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,
 
1593
+};
 
1594
+
 
1595
+static struct tty_driver *sdio_uart_tty_driver;
 
1596
+
 
1597
+static int sdio_uart_probe(struct sdio_func *func,
 
1598
+                          const struct sdio_device_id *id)
 
1599
+{
 
1600
+       struct sdio_uart_port *port;
 
1601
+       int ret;
 
1602
+
 
1603
+       port = kzalloc(sizeof(struct sdio_uart_port), GFP_KERNEL);
 
1604
+       if (!port)
 
1605
+               return -ENOMEM;
 
1606
+
 
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));
 
1610
+               kfree(port);
 
1611
+               return -ENOSYS;
 
1612
+       } else if (func->class == SDIO_CLASS_GPS) {
 
1613
+               /*
 
1614
+                * We need tuple 0x91.  It contains SUBTPL_SIOREG
 
1615
+                * and SUBTPL_RCVCAPS.
 
1616
+                */
 
1617
+               struct sdio_func_tuple *tpl;
 
1618
+               for (tpl = func->tuples; tpl; tpl = tpl->next) {
 
1619
+                       if (tpl->code != 0x91)
 
1620
+                               continue;
 
1621
+                       if (tpl->size < 10)
 
1622
+                               continue;
 
1623
+                       if (tpl->data[1] == 0)  /* SUBTPL_SIOREG */
 
1624
+                               break;
 
1625
+               }
 
1626
+               if (!tpl) {
 
1627
+                       printk(KERN_WARNING
 
1628
+                              "%s: can't find tuple 0x91 subtuple 0 (SUBTPL_SIOREG) for GPS class\n",
 
1629
+                              sdio_func_id(func));
 
1630
+                       kfree(port);
 
1631
+                       return -EINVAL;
 
1632
+               }
 
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));
 
1646
+       } else {
 
1647
+               kfree(port);
 
1648
+               return -EINVAL;
 
1649
+       }
 
1650
+
 
1651
+       port->func = func;
 
1652
+       sdio_set_drvdata(func, port);
 
1653
+
 
1654
+       ret = sdio_uart_add_port(port);
 
1655
+       if (ret) {
 
1656
+               kfree(port);
 
1657
+       } else {
 
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);
 
1663
+               }
 
1664
+       }
 
1665
+
 
1666
+       return ret;
 
1667
+}
 
1668
+
 
1669
+static void sdio_uart_remove(struct sdio_func *func)
 
1670
+{
 
1671
+       struct sdio_uart_port *port = sdio_get_drvdata(func);
 
1672
+
 
1673
+       tty_unregister_device(sdio_uart_tty_driver, port->index);
 
1674
+       sdio_uart_port_remove(port);
 
1675
+}
 
1676
+
 
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 */                         },
 
1681
+};
 
1682
+
 
1683
+MODULE_DEVICE_TABLE(sdio, sdio_uart_ids);
 
1684
+
 
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,
 
1690
+};
 
1691
+
 
1692
+static int __init sdio_uart_init(void)
 
1693
+{
 
1694
+       int ret;
 
1695
+       struct tty_driver *tty_drv;
 
1696
+
 
1697
+       sdio_uart_tty_driver = tty_drv = alloc_tty_driver(UART_NR);
 
1698
+       if (!tty_drv)
 
1699
+               return -ENOMEM;
 
1700
+
 
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);
 
1714
+
 
1715
+       ret = tty_register_driver(tty_drv);
 
1716
+       if (ret)
 
1717
+               goto err1;
 
1718
+
 
1719
+       ret = sdio_register_driver(&sdio_uart_driver);
 
1720
+       if (ret)
 
1721
+               goto err2;
 
1722
+
 
1723
+       return 0;
 
1724
+
 
1725
+err2:
 
1726
+       tty_unregister_driver(tty_drv);
 
1727
+err1:
 
1728
+       put_tty_driver(tty_drv);
 
1729
+       return ret;
 
1730
+}
 
1731
+
 
1732
+static void __exit sdio_uart_exit(void)
 
1733
+{
 
1734
+       sdio_unregister_driver(&sdio_uart_driver);
 
1735
+       tty_unregister_driver(sdio_uart_tty_driver);
 
1736
+       put_tty_driver(sdio_uart_tty_driver);
 
1737
+}
 
1738
+
 
1739
+module_init(sdio_uart_init);
 
1740
+module_exit(sdio_uart_exit);
 
1741
+
 
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)
 
1749
 endif
 
1750
 
 
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
 
1757
 
 
1758
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
 
1759
new file mode 100644
 
1760
index 0000000..f2e6ace
 
1761
--- /dev/null
 
1762
+++ b/drivers/mmc/core/bus.c
 
1763
@@ -0,0 +1,303 @@
 
1764
+/*
 
1765
+ *  linux/drivers/mmc/core/bus.c
 
1766
+ *
 
1767
+ *  Copyright (C) 2003 Russell King, All Rights Reserved.
 
1768
+ *  Copyright (C) 2007 Pierre Ossman
 
1769
+ *
 
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.
 
1773
+ *
 
1774
+ *  MMC card bus driver model
 
1775
+ */
 
1776
+
 
1777
+#include <linux/device.h>
 
1778
+#include <linux/err.h>
 
1779
+
 
1780
+#include <linux/mmc/card.h>
 
1781
+#include <linux/mmc/host.h>
 
1782
+
 
1783
+#include "sysfs.h"
 
1784
+#include "core.h"
 
1785
+#include "sdio_cis.h"
 
1786
+#include "bus.h"
 
1787
+
 
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)
 
1790
+
 
1791
+static ssize_t mmc_type_show(struct device *dev,
 
1792
+       struct device_attribute *attr, char *buf)
 
1793
+{
 
1794
+       struct mmc_card *card = dev_to_mmc_card(dev);
 
1795
+
 
1796
+       switch (card->type) {
 
1797
+       case MMC_TYPE_MMC:
 
1798
+               return sprintf(buf, "MMC\n");
 
1799
+       case MMC_TYPE_SD:
 
1800
+               return sprintf(buf, "SD\n");
 
1801
+       case MMC_TYPE_SDIO:
 
1802
+               return sprintf(buf, "SDIO\n");
 
1803
+       default:
 
1804
+               return -EFAULT;
 
1805
+       }
 
1806
+}
 
1807
+
 
1808
+static struct device_attribute mmc_dev_attrs[] = {
 
1809
+       MMC_ATTR_RO(type),
 
1810
+       __ATTR_NULL,
 
1811
+};
 
1812
+
 
1813
+/*
 
1814
+ * This currently matches any MMC driver to any MMC card - drivers
 
1815
+ * themselves make the decision whether to drive this card in their
 
1816
+ * probe method.
 
1817
+ */
 
1818
+static int mmc_bus_match(struct device *dev, struct device_driver *drv)
 
1819
+{
 
1820
+       return 1;
 
1821
+}
 
1822
+
 
1823
+static int
 
1824
+mmc_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
 
1825
+               int buf_size)
 
1826
+{
 
1827
+       struct mmc_card *card = dev_to_mmc_card(dev);
 
1828
+       const char *type;
 
1829
+       int i = 0, length = 0;
 
1830
+
 
1831
+       switch (card->type) {
 
1832
+       case MMC_TYPE_MMC:
 
1833
+               type = "MMC";
 
1834
+               break;
 
1835
+       case MMC_TYPE_SD:
 
1836
+               type = "SD";
 
1837
+               break;
 
1838
+       case MMC_TYPE_SDIO:
 
1839
+               type = "SDIO";
 
1840
+               break;
 
1841
+       default:
 
1842
+               type = NULL;
 
1843
+       }
 
1844
+
 
1845
+       if (type) {
 
1846
+               if (add_uevent_var(envp, num_envp, &i,
 
1847
+                               buf, buf_size, &length,
 
1848
+                               "MMC_TYPE=%s", type))
 
1849
+                       return -ENOMEM;
 
1850
+       }
 
1851
+
 
1852
+       if (add_uevent_var(envp, num_envp, &i,
 
1853
+                       buf, buf_size, &length,
 
1854
+                       "MMC_NAME=%s", mmc_card_name(card)))
 
1855
+               return -ENOMEM;
 
1856
+
 
1857
+       envp[i] = NULL;
 
1858
+
 
1859
+       return 0;
 
1860
+}
 
1861
+
 
1862
+static int mmc_bus_probe(struct device *dev)
 
1863
+{
 
1864
+       struct mmc_driver *drv = to_mmc_driver(dev->driver);
 
1865
+       struct mmc_card *card = dev_to_mmc_card(dev);
 
1866
+
 
1867
+       return drv->probe(card);
 
1868
+}
 
1869
+
 
1870
+static int mmc_bus_remove(struct device *dev)
 
1871
+{
 
1872
+       struct mmc_driver *drv = to_mmc_driver(dev->driver);
 
1873
+       struct mmc_card *card = dev_to_mmc_card(dev);
 
1874
+
 
1875
+       drv->remove(card);
 
1876
+
 
1877
+       return 0;
 
1878
+}
 
1879
+
 
1880
+static int mmc_bus_suspend(struct device *dev, pm_message_t state)
 
1881
+{
 
1882
+       struct mmc_driver *drv = to_mmc_driver(dev->driver);
 
1883
+       struct mmc_card *card = dev_to_mmc_card(dev);
 
1884
+       int ret = 0;
 
1885
+
 
1886
+       if (dev->driver && drv->suspend)
 
1887
+               ret = drv->suspend(card, state);
 
1888
+       return ret;
 
1889
+}
 
1890
+
 
1891
+static int mmc_bus_resume(struct device *dev)
 
1892
+{
 
1893
+       struct mmc_driver *drv = to_mmc_driver(dev->driver);
 
1894
+       struct mmc_card *card = dev_to_mmc_card(dev);
 
1895
+       int ret = 0;
 
1896
+
 
1897
+       if (dev->driver && drv->resume)
 
1898
+               ret = drv->resume(card);
 
1899
+       return ret;
 
1900
+}
 
1901
+
 
1902
+static struct bus_type mmc_bus_type = {
 
1903
+       .name           = "mmc",
 
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,
 
1911
+};
 
1912
+
 
1913
+int mmc_register_bus(void)
 
1914
+{
 
1915
+       return bus_register(&mmc_bus_type);
 
1916
+}
 
1917
+
 
1918
+void mmc_unregister_bus(void)
 
1919
+{
 
1920
+       bus_unregister(&mmc_bus_type);
 
1921
+}
 
1922
+
 
1923
+/**
 
1924
+ *     mmc_register_driver - register a media driver
 
1925
+ *     @drv: MMC media driver
 
1926
+ */
 
1927
+int mmc_register_driver(struct mmc_driver *drv)
 
1928
+{
 
1929
+       drv->drv.bus = &mmc_bus_type;
 
1930
+       return driver_register(&drv->drv);
 
1931
+}
 
1932
+
 
1933
+EXPORT_SYMBOL(mmc_register_driver);
 
1934
+
 
1935
+/**
 
1936
+ *     mmc_unregister_driver - unregister a media driver
 
1937
+ *     @drv: MMC media driver
 
1938
+ */
 
1939
+void mmc_unregister_driver(struct mmc_driver *drv)
 
1940
+{
 
1941
+       drv->drv.bus = &mmc_bus_type;
 
1942
+       driver_unregister(&drv->drv);
 
1943
+}
 
1944
+
 
1945
+EXPORT_SYMBOL(mmc_unregister_driver);
 
1946
+
 
1947
+static void mmc_release_card(struct device *dev)
 
1948
+{
 
1949
+       struct mmc_card *card = dev_to_mmc_card(dev);
 
1950
+
 
1951
+       sdio_free_common_cis(card);
 
1952
+
 
1953
+       if (card->info)
 
1954
+               kfree(card->info);
 
1955
+
 
1956
+       kfree(card);
 
1957
+}
 
1958
+
 
1959
+/*
 
1960
+ * Allocate and initialise a new MMC card structure.
 
1961
+ */
 
1962
+struct mmc_card *mmc_alloc_card(struct mmc_host *host)
 
1963
+{
 
1964
+       struct mmc_card *card;
 
1965
+
 
1966
+       card = kzalloc(sizeof(struct mmc_card), GFP_KERNEL);
 
1967
+       if (!card)
 
1968
+               return ERR_PTR(-ENOMEM);
 
1969
+
 
1970
+       card->host = host;
 
1971
+
 
1972
+       device_initialize(&card->dev);
 
1973
+
 
1974
+       card->dev.parent = mmc_classdev(host);
 
1975
+       card->dev.bus = &mmc_bus_type;
 
1976
+       card->dev.release = mmc_release_card;
 
1977
+
 
1978
+       return card;
 
1979
+}
 
1980
+
 
1981
+/*
 
1982
+ * Register a new MMC card with the driver model.
 
1983
+ */
 
1984
+int mmc_add_card(struct mmc_card *card)
 
1985
+{
 
1986
+       int ret;
 
1987
+       const char *type;
 
1988
+
 
1989
+       snprintf(card->dev.bus_id, sizeof(card->dev.bus_id),
 
1990
+                "%s:%04x", mmc_hostname(card->host), card->rca);
 
1991
+
 
1992
+       switch (card->type) {
 
1993
+       case MMC_TYPE_MMC:
 
1994
+               type = "MMC";
 
1995
+               break;
 
1996
+       case MMC_TYPE_SD:
 
1997
+               type = "SD";
 
1998
+               if (mmc_card_blockaddr(card))
 
1999
+                       type = "SDHC";
 
2000
+               break;
 
2001
+       case MMC_TYPE_SDIO:
 
2002
+               type = "SDIO";
 
2003
+               break;
 
2004
+       default:
 
2005
+               type = "?";
 
2006
+               break;
 
2007
+       }
 
2008
+
 
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 " : "",
 
2013
+                       type);
 
2014
+       } else {
 
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 " : "",
 
2018
+               type, card->rca);
 
2019
+       }
 
2020
+
 
2021
+       card->dev.uevent_suppress = 1;
 
2022
+
 
2023
+       ret = device_add(&card->dev);
 
2024
+       if (ret)
 
2025
+               return ret;
 
2026
+
 
2027
+       if (card->host->bus_ops->sysfs_add) {
 
2028
+               ret = card->host->bus_ops->sysfs_add(card->host, card);
 
2029
+               if (ret) {
 
2030
+                       device_del(&card->dev);
 
2031
+                       return ret;
 
2032
+                }
 
2033
+       }
 
2034
+
 
2035
+       card->dev.uevent_suppress = 0;
 
2036
+
 
2037
+       kobject_uevent(&card->dev.kobj, KOBJ_ADD);
 
2038
+
 
2039
+       mmc_card_set_present(card);
 
2040
+
 
2041
+       return 0;
 
2042
+}
 
2043
+
 
2044
+/*
 
2045
+ * Unregister a new MMC card with the driver model, and
 
2046
+ * (eventually) free it.
 
2047
+ */
 
2048
+void mmc_remove_card(struct mmc_card *card)
 
2049
+{
 
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));
 
2054
+               } else {
 
2055
+               printk(KERN_INFO "%s: card %04x removed\n",
 
2056
+                       mmc_hostname(card->host), card->rca);
 
2057
+               }
 
2058
+
 
2059
+               if (card->host->bus_ops->sysfs_remove)
 
2060
+                       card->host->bus_ops->sysfs_remove(card->host, card);
 
2061
+               device_del(&card->dev);
 
2062
+       }
 
2063
+
 
2064
+       put_device(&card->dev);
 
2065
+}
 
2066
+
 
2067
diff --git a/drivers/mmc/core/bus.h b/drivers/mmc/core/bus.h
 
2068
new file mode 100644
 
2069
index 0000000..4f35431
 
2070
--- /dev/null
 
2071
+++ b/drivers/mmc/core/bus.h
 
2072
@@ -0,0 +1,22 @@
 
2073
+/*
 
2074
+ *  linux/drivers/mmc/core/bus.h
 
2075
+ *
 
2076
+ *  Copyright (C) 2003 Russell King, All Rights Reserved.
 
2077
+ *  Copyright 2007 Pierre Ossman
 
2078
+ *
 
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.
 
2082
+ */
 
2083
+#ifndef _MMC_CORE_BUS_H
 
2084
+#define _MMC_CORE_BUS_H
 
2085
+
 
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);
 
2089
+
 
2090
+int mmc_register_bus(void);
 
2091
+void mmc_unregister_bus(void);
 
2092
+
 
2093
+#endif
 
2094
+
 
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
 
2099
@@ -18,6 +18,7 @@
 
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>
 
2106
 
 
2107
@@ -27,13 +28,44 @@
 
2108
 #include <linux/mmc/sd.h>
 
2109
 
 
2110
 #include "core.h"
 
2111
-#include "sysfs.h"
 
2112
+#include "bus.h"
 
2113
+#include "host.h"
 
2114
+#include "sdio_bus.h"
 
2115
 
 
2116
 #include "mmc_ops.h"
 
2117
 #include "sd_ops.h"
 
2118
+#include "sdio_ops.h"
 
2119
 
 
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);
 
2123
+
 
2124
+static struct workqueue_struct *workqueue;
 
2125
+
 
2126
+/*
 
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.
 
2130
+ */
 
2131
+int use_spi_crc = 1;
 
2132
+module_param(use_spi_crc, bool, 0);
 
2133
+
 
2134
+/*
 
2135
+ * Internal function. Schedule delayed work in the MMC work queue.
 
2136
+ */
 
2137
+static int mmc_schedule_delayed_work(struct delayed_work *work,
 
2138
+                                    unsigned long delay)
 
2139
+{
 
2140
+       return queue_delayed_work(workqueue, work, delay);
 
2141
+}
 
2142
+
 
2143
+/*
 
2144
+ * Internal function. Flush all scheduled work from the MMC work queue.
 
2145
+ */
 
2146
+static void mmc_flush_scheduled_work(void)
 
2147
+{
 
2148
+       flush_workqueue(workqueue);
 
2149
+}
 
2150
 
 
2151
 /**
 
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;
 
2156
 
 
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)
 
2164
+                       cmd->retries = 0;
 
2165
+       }
 
2166
 
 
2167
        if (err && cmd->retries) {
 
2168
+               pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
 
2169
+                       mmc_hostname(host), cmd->opcode, err);
 
2170
+
 
2171
                cmd->retries--;
 
2172
                cmd->error = 0;
 
2173
                host->ops->request(host, mrq);
 
2174
-       } else if (mrq->done) {
 
2175
-               mrq->done(mrq);
 
2176
+       } else {
 
2177
+               led_trigger_event(host->led, LED_OFF);
 
2178
+
 
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]);
 
2183
+
 
2184
+               if (mrq->data) {
 
2185
+                       pr_debug("%s:     %d bytes transferred: %d\n",
 
2186
+                               mmc_hostname(host),
 
2187
+                               mrq->data->bytes_xfered, mrq->data->error);
 
2188
+               }
 
2189
+
 
2190
+               if (mrq->stop) {
 
2191
+                       pr_debug("%s:     (CMD%u): %d: %08x %08x %08x %08x\n",
 
2192
+                               mmc_hostname(host), mrq->stop->opcode,
 
2193
+                               mrq->stop->error,
 
2194
+                               mrq->stop->resp[0], mrq->stop->resp[1],
 
2195
+                               mrq->stop->resp[2], mrq->stop->resp[3]);
 
2196
+               }
 
2197
+
 
2198
+               if (mrq->done)
 
2199
+                       mrq->done(mrq);
 
2200
        }
 
2201
 }
 
2202
 
 
2203
 EXPORT_SYMBOL(mmc_request_done);
 
2204
 
 
2205
-/**
 
2206
- *     mmc_start_request - start a command on a host
 
2207
- *     @host: MMC host to start command on
 
2208
- *     @mrq: MMC request to start
 
2209
- *
 
2210
- *     Queue a command on the specified host.  We expect the
 
2211
- *     caller to be holding the host lock with interrupts disabled.
 
2212
- */
 
2213
-void
 
2214
+static void
 
2215
 mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
 
2216
 {
 
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);
 
2221
 
 
2222
+       if (mrq->data) {
 
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);
 
2229
+       }
 
2230
+
 
2231
+       if (mrq->stop) {
 
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);
 
2235
+       }
 
2236
+
 
2237
        WARN_ON(!host->claimed);
 
2238
 
 
2239
+       led_trigger_event(host->led, LED_FULL);
 
2240
+
 
2241
        mrq->cmd->error = 0;
 
2242
        mrq->cmd->mrq = mrq;
 
2243
        if (mrq->data) {
 
2244
@@ -113,14 +178,21 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
 
2245
        host->ops->request(host, mrq);
 
2246
 }
 
2247
 
 
2248
-EXPORT_SYMBOL(mmc_start_request);
 
2249
-
 
2250
 static void mmc_wait_done(struct mmc_request *mrq)
 
2251
 {
 
2252
        complete(mrq->done_data);
 
2253
 }
 
2254
 
 
2255
-int mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
 
2256
+/**
 
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
 
2260
+ *
 
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
 
2263
+ *     response.
 
2264
+ */
 
2265
+void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
 
2266
 {
 
2267
        DECLARE_COMPLETION_ONSTACK(complete);
 
2268
 
 
2269
@@ -130,8 +202,6 @@ int mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
 
2270
        mmc_start_request(host, mrq);
 
2271
 
 
2272
        wait_for_completion(&complete);
 
2273
-
 
2274
-       return 0;
 
2275
 }
 
2276
 
 
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
 
2279
 {
 
2280
        struct mmc_request mrq;
 
2281
 
 
2282
-       BUG_ON(!host->claimed);
 
2283
+       WARN_ON(!host->claimed);
 
2284
 
 
2285
        memset(&mrq, 0, sizeof(struct mmc_request));
 
2286
 
 
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
 
2292
+ *
 
2293
+ *     Computes the data timeout parameters according to the
 
2294
+ *     correct algorithm given the card type.
 
2295
  */
 
2296
-void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card,
 
2297
-                         int write)
 
2298
+void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
 
2299
 {
 
2300
        unsigned int mult;
 
2301
 
 
2302
        /*
 
2303
+        * SDIO cards only define an upper 1 s limit on access.
 
2304
+        */
 
2305
+       if (mmc_card_sdio(card)) {
 
2306
+               data->timeout_ns = 1000000000;
 
2307
+               data->timeout_clks = 0;
 
2308
+               return;
 
2309
+       }
 
2310
+
 
2311
+       /*
 
2312
         * SD cards use a 100 multiplier rather than 10
 
2313
         */
 
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.
 
2318
         */
 
2319
-       if (write)
 
2320
+       if (data->flags & MMC_DATA_WRITE)
 
2321
                mult <<= card->csd.r2w_factor;
 
2322
 
 
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);
 
2327
 
 
2328
-               if (write)
 
2329
+               if (data->flags & MMC_DATA_WRITE)
 
2330
                        limit_us = 250000;
 
2331
                else
 
2332
                        limit_us = 100000;
 
2333
@@ -222,36 +302,43 @@ EXPORT_SYMBOL(mmc_set_data_timeout);
 
2334
 /**
 
2335
  *     __mmc_claim_host - exclusively claim a host
 
2336
  *     @host: mmc host to claim
 
2337
- *     @card: mmc card to claim host for
 
2338
- *
 
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
 
2343
  *
 
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.
 
2349
  */
 
2350
-void mmc_claim_host(struct mmc_host *host)
 
2351
+int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
 
2352
 {
 
2353
        DECLARE_WAITQUEUE(wait, current);
 
2354
        unsigned long flags;
 
2355
+       int stop;
 
2356
+
 
2357
+       might_sleep();
 
2358
 
 
2359
        add_wait_queue(&host->wq, &wait);
 
2360
        spin_lock_irqsave(&host->lock, flags);
 
2361
        while (1) {
 
2362
                set_current_state(TASK_UNINTERRUPTIBLE);
 
2363
-               if (!host->claimed)
 
2364
+               stop = abort ? atomic_read(abort) : 0;
 
2365
+               if (stop || !host->claimed)
 
2366
                        break;
 
2367
                spin_unlock_irqrestore(&host->lock, flags);
 
2368
                schedule();
 
2369
                spin_lock_irqsave(&host->lock, flags);
 
2370
        }
 
2371
        set_current_state(TASK_RUNNING);
 
2372
-       host->claimed = 1;
 
2373
+       if (!stop)
 
2374
+               host->claimed = 1;
 
2375
+       else
 
2376
+               wake_up(&host->wq);
 
2377
        spin_unlock_irqrestore(&host->lock, flags);
 
2378
        remove_wait_queue(&host->wq, &wait);
 
2379
+       return stop;
 
2380
 }
 
2381
 
 
2382
-EXPORT_SYMBOL(mmc_claim_host);
 
2383
+EXPORT_SYMBOL(__mmc_claim_host);
 
2384
 
 
2385
 /**
 
2386
  *     mmc_release_host - release a host
 
2387
@@ -264,7 +351,7 @@ void mmc_release_host(struct mmc_host *host)
 
2388
 {
 
2389
        unsigned long flags;
 
2390
 
 
2391
-       BUG_ON(!host->claimed);
 
2392
+       WARN_ON(!host->claimed);
 
2393
 
 
2394
        spin_lock_irqsave(&host->lock, flags);
 
2395
        host->claimed = 0;
 
2396
@@ -369,22 +456,6 @@ void mmc_set_timing(struct mmc_host *host, unsigned int timing)
 
2397
 }
 
2398
 
 
2399
 /*
 
2400
- * Allocate a new MMC card
 
2401
- */
 
2402
-struct mmc_card *mmc_alloc_card(struct mmc_host *host)
 
2403
-{
 
2404
-       struct mmc_card *card;
 
2405
-
 
2406
-       card = kmalloc(sizeof(struct mmc_card), GFP_KERNEL);
 
2407
-       if (!card)
 
2408
-               return ERR_PTR(-ENOMEM);
 
2409
-
 
2410
-       mmc_init_card(card, host);
 
2411
-
 
2412
-       return card;
 
2413
-}
 
2414
-
 
2415
-/*
 
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)
 
2420
 {
 
2421
        int bit = fls(host->ocr_avail) - 1;
 
2422
 
 
2423
+       umd_enter();
 
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;
 
2429
+       } else {
 
2430
        host->ios.chip_select = MMC_CS_DONTCARE;
 
2431
+               host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
 
2432
+       }
 
2433
        host->ios.power_mode = MMC_POWER_UP;
 
2434
        host->ios.bus_width = MMC_BUS_WIDTH_1;
 
2435
        host->ios.timing = MMC_TIMING_LEGACY;
 
2436
        mmc_set_ios(host);
 
2437
 
 
2438
-       mmc_delay(1);
 
2439
+       /*
 
2440
+        * This delay should be sufficient to allow the power supply
 
2441
+        * to reach the minimum voltage.
 
2442
+        */
 
2443
+       mmc_delay(2);
 
2444
 
 
2445
        host->ios.clock = host->f_min;
 
2446
        host->ios.power_mode = MMC_POWER_ON;
 
2447
        mmc_set_ios(host);
 
2448
 
 
2449
+       /*
 
2450
+        * This delay must be at least 74 clock sizes, or 1 ms, or the
 
2451
+        * time required to reach a stable voltage.
 
2452
+        */
 
2453
        mmc_delay(2);
 
2454
 }
 
2455
 
 
2456
 static void mmc_power_off(struct mmc_host *host)
 
2457
 {
 
2458
+       umd_enter();
 
2459
        host->ios.clock = 0;
 
2460
        host->ios.vdd = 0;
 
2461
+       if (!mmc_host_is_spi(host)) {
 
2462
        host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
 
2463
        host->ios.chip_select = MMC_CS_DONTCARE;
 
2464
+       }
 
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)
 
2469
 }
 
2470
 
 
2471
 /*
 
2472
+ * Cleanup when the last reference to the bus operator is dropped.
 
2473
+ */
 
2474
+void __mmc_release_bus(struct mmc_host *host)
 
2475
+{
 
2476
+       BUG_ON(!host);
 
2477
+       BUG_ON(host->bus_refs);
 
2478
+       BUG_ON(!host->bus_dead);
 
2479
+
 
2480
+       host->bus_ops = NULL;
 
2481
+}
 
2482
+
 
2483
+/*
 
2484
+ * Increase reference count of bus operator
 
2485
+ */
 
2486
+static inline void mmc_bus_get(struct mmc_host *host)
 
2487
+{
 
2488
+       unsigned long flags;
 
2489
+
 
2490
+       spin_lock_irqsave(&host->lock, flags);
 
2491
+       host->bus_refs++;
 
2492
+       spin_unlock_irqrestore(&host->lock, flags);
 
2493
+}
 
2494
+
 
2495
+/*
 
2496
+ * Decrease reference count of bus operator and free it if
 
2497
+ * it is the last reference.
 
2498
+ */
 
2499
+static inline void mmc_bus_put(struct mmc_host *host)
 
2500
+{
 
2501
+       unsigned long flags;
 
2502
+
 
2503
+       spin_lock_irqsave(&host->lock, flags);
 
2504
+       host->bus_refs--;
 
2505
+       if ((host->bus_refs == 0) && host->bus_ops)
 
2506
+               __mmc_release_bus(host);
 
2507
+       spin_unlock_irqrestore(&host->lock, flags);
 
2508
+}
 
2509
+
 
2510
+/*
 
2511
  * Assign a mmc bus handler to a host. Only one bus handler may control a
 
2512
  * host at any given time.
 
2513
  */
 
2514
@@ -436,10 +563,12 @@ void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
 
2515
 {
 
2516
        unsigned long flags;
 
2517
 
 
2518
+       umd_dbg("enter!!!!!!!!!!!!!!!!!\n\n");
 
2519
+
 
2520
        BUG_ON(!host);
 
2521
        BUG_ON(!ops);
 
2522
 
 
2523
-       BUG_ON(!host->claimed);
 
2524
+       WARN_ON(!host->claimed);
 
2525
 
 
2526
        spin_lock_irqsave(&host->lock, flags);
 
2527
 
 
2528
@@ -451,6 +580,8 @@ void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
 
2529
        host->bus_dead = 0;
 
2530
 
 
2531
        spin_unlock_irqrestore(&host->lock, flags);
 
2532
+
 
2533
+       umd_exit();
 
2534
 }
 
2535
 
 
2536
 /*
 
2537
@@ -463,8 +594,8 @@ void mmc_detach_bus(struct mmc_host *host)
 
2538
 
 
2539
        BUG_ON(!host);
 
2540
 
 
2541
-       BUG_ON(!host->claimed);
 
2542
-       BUG_ON(!host->bus_ops);
 
2543
+       WARN_ON(!host->claimed);
 
2544
+       WARN_ON(!host->bus_ops);
 
2545
 
 
2546
        spin_lock_irqsave(&host->lock, flags);
 
2547
 
 
2548
@@ -477,34 +608,25 @@ void mmc_detach_bus(struct mmc_host *host)
 
2549
        mmc_bus_put(host);
 
2550
 }
 
2551
 
 
2552
-/*
 
2553
- * Cleanup when the last reference to the bus operator is dropped.
 
2554
- */
 
2555
-void __mmc_release_bus(struct mmc_host *host)
 
2556
-{
 
2557
-       BUG_ON(!host);
 
2558
-       BUG_ON(host->bus_refs);
 
2559
-       BUG_ON(!host->bus_dead);
 
2560
-
 
2561
-       host->bus_ops = NULL;
 
2562
-}
 
2563
-
 
2564
 /**
 
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)
 
2568
  *
 
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
 
2574
+ *     inserted.
 
2575
  */
 
2576
 void mmc_detect_change(struct mmc_host *host, unsigned long delay)
 
2577
 {
 
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);
 
2584
 #endif
 
2585
+       umd_enter();
 
2586
 
 
2587
        mmc_schedule_delayed_work(&host->detect, delay);
 
2588
 }
 
2589
@@ -512,13 +634,14 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay)
 
2590
 EXPORT_SYMBOL(mmc_detect_change);
 
2591
 
 
2592
 
 
2593
-static void mmc_rescan(struct work_struct *work)
 
2594
+void mmc_rescan(struct work_struct *work)
 
2595
 {
 
2596
        struct mmc_host *host =
 
2597
                container_of(work, struct mmc_host, detect.work);
 
2598
        u32 ocr;
 
2599
        int err;
 
2600
 
 
2601
+       umd_dbg("Scan for  %s", host->class_dev.bus_id);
 
2602
        mmc_bus_get(host);
 
2603
 
 
2604
        if (host->bus_ops == NULL) {
 
2605
@@ -531,99 +654,64 @@ static void mmc_rescan(struct work_struct *work)
 
2606
                mmc_claim_host(host);
 
2607
 
 
2608
                mmc_power_up(host);
 
2609
+
 
2610
+               /* add by feng */
 
2611
+               //mmc_delay(100);
 
2612
+
 
2613
                mmc_go_idle(host);
 
2614
 
 
2615
                mmc_send_if_cond(host, host->ocr_avail);
 
2616
 
 
2617
+               /*
 
2618
+                * First we search for SDIO...
 
2619
+                */
 
2620
+               err = mmc_send_io_op_cond(host, 0, &ocr);
 
2621
+               if (!err) {
 
2622
+                       if (mmc_attach_sdio(host, ocr))
 
2623
+                               mmc_power_off(host);
 
2624
+                       return;
 
2625
+               }
 
2626
+
 
2627
+               /*
 
2628
+                * ...then normal SD...
 
2629
+                */
 
2630
                err = mmc_send_app_op_cond(host, 0, &ocr);
 
2631
-               if (err == MMC_ERR_NONE) {
 
2632
+               if (!err) {
 
2633
                        if (mmc_attach_sd(host, ocr))
 
2634
                                mmc_power_off(host);
 
2635
-               } else {
 
2636
-                       /*
 
2637
-                        * If we fail to detect any SD cards then try
 
2638
-                        * searching for MMC cards.
 
2639
-                        */
 
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);
 
2644
-                       } else {
 
2645
+                       return;
 
2646
+               }
 
2647
+
 
2648
+               /*
 
2649
+                * ...and finally MMC.
 
2650
+                */
 
2651
+               err = mmc_send_op_cond(host, 0, &ocr);
 
2652
+               if (!err) {
 
2653
+                       if (mmc_attach_mmc(host, ocr))
 
2654
                                mmc_power_off(host);
 
2655
-                               mmc_release_host(host);
 
2656
-                       }
 
2657
+                       return;
 
2658
                }
 
2659
+
 
2660
+               mmc_release_host(host);
 
2661
+               mmc_power_off(host);
 
2662
        } else {
 
2663
                if (host->bus_ops->detect && !host->bus_dead)
 
2664
                        host->bus_ops->detect(host);
 
2665
 
 
2666
                mmc_bus_put(host);
 
2667
        }
 
2668
-}
 
2669
-
 
2670
 
 
2671
-/**
 
2672
- *     mmc_alloc_host - initialise the per-host structure.
 
2673
- *     @extra: sizeof private data structure
 
2674
- *     @dev: pointer to host device model structure
 
2675
- *
 
2676
- *     Initialise the per-host structure.
 
2677
- */
 
2678
-struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
 
2679
-{
 
2680
-       struct mmc_host *host;
 
2681
-
 
2682
-       host = mmc_alloc_host_sysfs(extra, dev);
 
2683
-       if (host) {
 
2684
-               spin_lock_init(&host->lock);
 
2685
-               init_waitqueue_head(&host->wq);
 
2686
-               INIT_DELAYED_WORK(&host->detect, mmc_rescan);
 
2687
-
 
2688
-               /*
 
2689
-                * By default, hosts do not support SGIO or large requests.
 
2690
-                * They have to set these according to their abilities.
 
2691
-                */
 
2692
-               host->max_hw_segs = 1;
 
2693
-               host->max_phys_segs = 1;
 
2694
-               host->max_seg_size = PAGE_CACHE_SIZE;
 
2695
-
 
2696
-               host->max_req_size = PAGE_CACHE_SIZE;
 
2697
-               host->max_blk_size = 512;
 
2698
-               host->max_blk_count = PAGE_CACHE_SIZE / 512;
 
2699
-       }
 
2700
-
 
2701
-       return host;
 
2702
+       umd_exit();
 
2703
 }
 
2704
 
 
2705
-EXPORT_SYMBOL(mmc_alloc_host);
 
2706
-
 
2707
-/**
 
2708
- *     mmc_add_host - initialise host hardware
 
2709
- *     @host: mmc host
 
2710
- */
 
2711
-int mmc_add_host(struct mmc_host *host)
 
2712
+void mmc_start_host(struct mmc_host *host)
 
2713
 {
 
2714
-       int ret;
 
2715
-
 
2716
-       ret = mmc_add_host_sysfs(host);
 
2717
-       if (ret == 0) {
 
2718
-               mmc_power_off(host);
 
2719
-               mmc_detect_change(host, 0);
 
2720
-       }
 
2721
-
 
2722
-       return ret;
 
2723
+       umd_dbg("enter, for %s", host->class_dev.bus_id);
 
2724
+       mmc_power_off(host);
 
2725
+       mmc_detect_change(host, 0);
 
2726
 }
 
2727
 
 
2728
-EXPORT_SYMBOL(mmc_add_host);
 
2729
-
 
2730
-/**
 
2731
- *     mmc_remove_host - remove host hardware
 
2732
- *     @host: mmc host
 
2733
- *
 
2734
- *     Unregister and remove all cards associated with this host,
 
2735
- *     and power down the MMC bus.
 
2736
- */
 
2737
-void mmc_remove_host(struct mmc_host *host)
 
2738
+void mmc_stop_host(struct mmc_host *host)
 
2739
 {
 
2740
 #ifdef CONFIG_MMC_DEBUG
 
2741
        unsigned long flags;
 
2742
@@ -648,24 +736,8 @@ void mmc_remove_host(struct mmc_host *host)
 
2743
        BUG_ON(host->card);
 
2744
 
 
2745
        mmc_power_off(host);
 
2746
-       mmc_remove_host_sysfs(host);
 
2747
-}
 
2748
-
 
2749
-EXPORT_SYMBOL(mmc_remove_host);
 
2750
-
 
2751
-/**
 
2752
- *     mmc_free_host - free the host structure
 
2753
- *     @host: mmc host
 
2754
- *
 
2755
- *     Free the host once all references to it have been dropped.
 
2756
- */
 
2757
-void mmc_free_host(struct mmc_host *host)
 
2758
-{
 
2759
-       mmc_free_host_sysfs(host);
 
2760
 }
 
2761
 
 
2762
-EXPORT_SYMBOL(mmc_free_host);
 
2763
-
 
2764
 #ifdef CONFIG_PM
 
2765
 
 
2766
 /**
 
2767
@@ -675,6 +747,8 @@ EXPORT_SYMBOL(mmc_free_host);
 
2768
  */
 
2769
 int mmc_suspend_host(struct mmc_host *host, pm_message_t state)
 
2770
 {
 
2771
+
 
2772
+       umd_enter();
 
2773
        mmc_flush_scheduled_work();
 
2774
 
 
2775
        mmc_bus_get(host);
 
2776
@@ -705,6 +779,7 @@ EXPORT_SYMBOL(mmc_suspend_host);
 
2777
  */
 
2778
 int mmc_resume_host(struct mmc_host *host)
 
2779
 {
 
2780
+       umd_enter();
 
2781
        mmc_bus_get(host);
 
2782
        if (host->bus_ops && !host->bus_dead) {
 
2783
                mmc_power_up(host);
 
2784
@@ -726,4 +801,49 @@ EXPORT_SYMBOL(mmc_resume_host);
 
2785
 
 
2786
 #endif
 
2787
 
 
2788
+static int __init mmc_init(void)
 
2789
+{
 
2790
+       int ret;
 
2791
+
 
2792
+       umd_enter();
 
2793
+       workqueue = create_singlethread_workqueue("kmmcd");
 
2794
+       if (!workqueue)
 
2795
+               return -ENOMEM;
 
2796
+
 
2797
+       ret = mmc_register_bus();
 
2798
+       if (ret)
 
2799
+               goto destroy_workqueue;
 
2800
+
 
2801
+       ret = mmc_register_host_class();
 
2802
+       if (ret)
 
2803
+               goto unregister_bus;
 
2804
+
 
2805
+       ret = sdio_register_bus();
 
2806
+       if (ret)
 
2807
+               goto unregister_host_class;
 
2808
+
 
2809
+       umd_exit();
 
2810
+       return 0;
 
2811
+
 
2812
+unregister_host_class:
 
2813
+       mmc_unregister_host_class();
 
2814
+unregister_bus:
 
2815
+       mmc_unregister_bus();
 
2816
+destroy_workqueue:
 
2817
+       destroy_workqueue(workqueue);
 
2818
+
 
2819
+       return ret;
 
2820
+}
 
2821
+
 
2822
+static void __exit mmc_exit(void)
 
2823
+{
 
2824
+       sdio_unregister_bus();
 
2825
+       mmc_unregister_host_class();
 
2826
+       mmc_unregister_bus();
 
2827
+       destroy_workqueue(workqueue);
 
2828
+}
 
2829
+
 
2830
+subsys_initcall(mmc_init);
 
2831
+module_exit(mmc_exit);
 
2832
+
 
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
 
2838
@@ -18,6 +18,8 @@
 
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 *);
 
2846
 };
 
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);
 
2850
 
 
2851
-void __mmc_release_bus(struct mmc_host *host);
 
2852
-
 
2853
-static inline void mmc_bus_get(struct mmc_host *host)
 
2854
-{
 
2855
-       unsigned long flags;
 
2856
-
 
2857
-       spin_lock_irqsave(&host->lock, flags);
 
2858
-       host->bus_refs++;
 
2859
-       spin_unlock_irqrestore(&host->lock, flags);
 
2860
-}
 
2861
-
 
2862
-static inline void mmc_bus_put(struct mmc_host *host)
 
2863
-{
 
2864
-       unsigned long flags;
 
2865
-
 
2866
-       spin_lock_irqsave(&host->lock, flags);
 
2867
-       host->bus_refs--;
 
2868
-       if ((host->bus_refs == 0) && host->bus_ops)
 
2869
-               __mmc_release_bus(host);
 
2870
-       spin_unlock_irqrestore(&host->lock, flags);
 
2871
-}
 
2872
-
 
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);
 
2879
 
 
2880
-struct mmc_card *mmc_alloc_card(struct mmc_host *host);
 
2881
-
 
2882
 static inline void mmc_delay(unsigned int ms)
 
2883
 {
 
2884
        if (ms < 1000 / HZ) {
 
2885
@@ -66,5 +44,11 @@ static inline void mmc_delay(unsigned int ms)
 
2886
        }
 
2887
 }
 
2888
 
 
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);
 
2892
+
 
2893
+extern int use_spi_crc;
 
2894
+
 
2895
 #endif
 
2896
 
 
2897
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
 
2898
new file mode 100644
 
2899
index 0000000..c65d203
 
2900
--- /dev/null
 
2901
+++ b/drivers/mmc/core/host.c
 
2902
@@ -0,0 +1,167 @@
 
2903
+/*
 
2904
+ *  linux/drivers/mmc/core/host.c
 
2905
+ *
 
2906
+ *  Copyright (C) 2003 Russell King, All Rights Reserved.
 
2907
+ *  Copyright (C) 2007 Pierre Ossman
 
2908
+ *
 
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.
 
2912
+ *
 
2913
+ *  MMC host class device management
 
2914
+ */
 
2915
+
 
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>
 
2921
+
 
2922
+#include <linux/mmc/host.h>
 
2923
+
 
2924
+#include "core.h"
 
2925
+#include "host.h"
 
2926
+
 
2927
+#define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
 
2928
+
 
2929
+static void mmc_host_classdev_release(struct device *dev)
 
2930
+{
 
2931
+       struct mmc_host *host = cls_dev_to_mmc_host(dev);
 
2932
+       kfree(host);
 
2933
+}
 
2934
+
 
2935
+static struct class mmc_host_class = {
 
2936
+       .name           = "mmc_host",
 
2937
+       .dev_release    = mmc_host_classdev_release,
 
2938
+};
 
2939
+
 
2940
+int mmc_register_host_class(void)
 
2941
+{
 
2942
+       return class_register(&mmc_host_class);
 
2943
+}
 
2944
+
 
2945
+void mmc_unregister_host_class(void)
 
2946
+{
 
2947
+       class_unregister(&mmc_host_class);
 
2948
+}
 
2949
+
 
2950
+static DEFINE_IDR(mmc_host_idr);
 
2951
+static DEFINE_SPINLOCK(mmc_host_lock);
 
2952
+
 
2953
+/**
 
2954
+ *     mmc_alloc_host - initialise the per-host structure.
 
2955
+ *     @extra: sizeof private data structure
 
2956
+ *     @dev: pointer to host device model structure
 
2957
+ *
 
2958
+ *     Initialise the per-host structure.
 
2959
+ */
 
2960
+struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
 
2961
+{
 
2962
+       struct mmc_host *host;
 
2963
+
 
2964
+       host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
 
2965
+       if (!host)
 
2966
+               return NULL;
 
2967
+
 
2968
+       host->parent = dev;
 
2969
+       host->class_dev.parent = dev;
 
2970
+       host->class_dev.class = &mmc_host_class;
 
2971
+       device_initialize(&host->class_dev);
 
2972
+
 
2973
+       spin_lock_init(&host->lock);
 
2974
+       init_waitqueue_head(&host->wq);
 
2975
+       INIT_DELAYED_WORK(&host->detect, mmc_rescan);
 
2976
+
 
2977
+       /*
 
2978
+        * By default, hosts do not support SGIO or large requests.
 
2979
+        * They have to set these according to their abilities.
 
2980
+        */
 
2981
+       host->max_hw_segs = 1;
 
2982
+       host->max_phys_segs = 1;
 
2983
+       host->max_seg_size = PAGE_CACHE_SIZE;
 
2984
+
 
2985
+       host->max_req_size = PAGE_CACHE_SIZE;
 
2986
+       host->max_blk_size = 512;
 
2987
+       host->max_blk_count = PAGE_CACHE_SIZE / 512;
 
2988
+
 
2989
+       return host;
 
2990
+}
 
2991
+
 
2992
+EXPORT_SYMBOL(mmc_alloc_host);
 
2993
+
 
2994
+/**
 
2995
+ *     mmc_add_host - initialise host hardware
 
2996
+ *     @host: mmc host
 
2997
+ *
 
2998
+ *     Register the host with the driver model. The host must be
 
2999
+ *     prepared to start servicing requests before this function
 
3000
+ *     completes.
 
3001
+ */
 
3002
+int mmc_add_host(struct mmc_host *host)
 
3003
+{
 
3004
+       int err;
 
3005
+
 
3006
+       WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) &&
 
3007
+               !host->ops->enable_sdio_irq);
 
3008
+
 
3009
+       if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
 
3010
+               return -ENOMEM;
 
3011
+
 
3012
+       spin_lock(&mmc_host_lock);
 
3013
+       err = idr_get_new(&mmc_host_idr, host, &host->index);
 
3014
+       spin_unlock(&mmc_host_lock);
 
3015
+       if (err)
 
3016
+               return err;
 
3017
+
 
3018
+       snprintf(host->class_dev.bus_id, BUS_ID_SIZE,
 
3019
+                "mmc%d", host->index);
 
3020
+
 
3021
+       led_trigger_register_simple(host->class_dev.bus_id, &host->led);
 
3022
+
 
3023
+       err = device_add(&host->class_dev);
 
3024
+       if (err)
 
3025
+               return err;
 
3026
+
 
3027
+       mmc_start_host(host);
 
3028
+
 
3029
+       return 0;
 
3030
+}
 
3031
+
 
3032
+EXPORT_SYMBOL(mmc_add_host);
 
3033
+
 
3034
+/**
 
3035
+ *     mmc_remove_host - remove host hardware
 
3036
+ *     @host: mmc host
 
3037
+ *
 
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.
 
3041
+ */
 
3042
+void mmc_remove_host(struct mmc_host *host)
 
3043
+{
 
3044
+       mmc_stop_host(host);
 
3045
+
 
3046
+       device_del(&host->class_dev);
 
3047
+
 
3048
+       led_trigger_unregister_simple(host->led);
 
3049
+
 
3050
+       spin_lock(&mmc_host_lock);
 
3051
+       idr_remove(&mmc_host_idr, host->index);
 
3052
+       spin_unlock(&mmc_host_lock);
 
3053
+}
 
3054
+
 
3055
+EXPORT_SYMBOL(mmc_remove_host);
 
3056
+
 
3057
+/**
 
3058
+ *     mmc_free_host - free the host structure
 
3059
+ *     @host: mmc host
 
3060
+ *
 
3061
+ *     Free the host once all references to it have been dropped.
 
3062
+ */
 
3063
+void mmc_free_host(struct mmc_host *host)
 
3064
+{
 
3065
+       put_device(&host->class_dev);
 
3066
+}
 
3067
+
 
3068
+EXPORT_SYMBOL(mmc_free_host);
 
3069
+
 
3070
diff --git a/drivers/mmc/core/host.h b/drivers/mmc/core/host.h
 
3071
new file mode 100644
 
3072
index 0000000..c2dc3d2
 
3073
--- /dev/null
 
3074
+++ b/drivers/mmc/core/host.h
 
3075
@@ -0,0 +1,18 @@
 
3076
+/*
 
3077
+ *  linux/drivers/mmc/core/host.h
 
3078
+ *
 
3079
+ *  Copyright (C) 2003 Russell King, All Rights Reserved.
 
3080
+ *  Copyright 2007 Pierre Ossman
 
3081
+ *
 
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.
 
3085
+ */
 
3086
+#ifndef _MMC_CORE_HOST_H
 
3087
+#define _MMC_CORE_HOST_H
 
3088
+
 
3089
+int mmc_register_host_class(void);
 
3090
+void mmc_unregister_host_class(void);
 
3091
+
 
3092
+#endif
 
3093
+
 
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
 
3098
@@ -1,5 +1,5 @@
 
3099
 /*
 
3100
- *  linux/drivers/mmc/mmc.c
 
3101
+ *  linux/drivers/mmc/core/mmc.c
 
3102
  *
 
3103
  *  Copyright (C) 2003-2004 Russell King, All Rights Reserved.
 
3104
  *  Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
 
3105
@@ -18,6 +18,7 @@
 
3106
 
 
3107
 #include "core.h"
 
3108
 #include "sysfs.h"
 
3109
+#include "bus.h"
 
3110
 #include "mmc_ops.h"
 
3111
 
 
3112
 static const unsigned int tran_exp[] = {
 
3113
@@ -99,7 +100,7 @@ static int mmc_decode_cid(struct mmc_card *card)
 
3114
                break;
 
3115
 
 
3116
        default:
 
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);
 
3120
                return -EINVAL;
 
3121
        }
 
3122
@@ -122,7 +123,7 @@ static int mmc_decode_csd(struct mmc_card *card)
 
3123
         */
 
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);
 
3129
                return -EINVAL;
 
3130
        }
 
3131
@@ -160,13 +161,12 @@ static int mmc_read_ext_csd(struct mmc_card *card)
 
3132
 {
 
3133
        int err;
 
3134
        u8 *ext_csd;
 
3135
+       unsigned int ext_csd_struct;
 
3136
 
 
3137
        BUG_ON(!card);
 
3138
 
 
3139
-       err = MMC_ERR_FAILED;
 
3140
-
 
3141
        if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
 
3142
-               return MMC_ERR_NONE;
 
3143
+               return 0;
 
3144
 
 
3145
        /*
 
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);
 
3149
        if (!ext_csd) {
 
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));
 
3155
+               return -ENOMEM;
 
3156
        }
 
3157
 
 
3158
        err = mmc_send_ext_csd(card, ext_csd);
 
3159
-       if (err != MMC_ERR_NONE) {
 
3160
+       if (err) {
 
3161
+               /*
 
3162
+                * We all hosts that cannot perform the command
 
3163
+                * to fail more gracefully
 
3164
+                */
 
3165
+               if (err != -EINVAL)
 
3166
+                       goto out;
 
3167
+
 
3168
                /*
 
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 "
 
3173
                                "suffer.\n",
 
3174
                                mmc_hostname(card->host));
 
3175
-                       err = MMC_ERR_NONE;
 
3176
+                       err = 0;
 
3177
                }
 
3178
+
 
3179
+               goto out;
 
3180
+       }
 
3181
+
 
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),
 
3186
+                       ext_csd_struct);
 
3187
+               err = -EINVAL;
 
3188
                goto out;
 
3189
        }
 
3190
 
 
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);
 
3199
+       }
 
3200
 
 
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.
 
3206
  */
 
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)
 
3210
 {
 
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;
 
3214
 
 
3215
        BUG_ON(!host);
 
3216
-       BUG_ON(!host->claimed);
 
3217
+       WARN_ON(!host->claimed);
 
3218
 
 
3219
        /*
 
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,
 
3222
 
 
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)
 
3226
+       if (err)
 
3227
                goto err;
 
3228
 
 
3229
        /*
 
3230
+        * For SPI, enable CRC as appropriate.
 
3231
+        */
 
3232
+       if (mmc_host_is_spi(host)) {
 
3233
+               err = mmc_spi_set_crc(host, use_spi_crc);
 
3234
+               if (err)
 
3235
+                       goto err;
 
3236
+       }
 
3237
+
 
3238
+       /*
 
3239
         * Fetch CID from card.
 
3240
         */
 
3241
+       if (mmc_host_is_spi(host))
 
3242
+               err = mmc_send_cid(host, cid);
 
3243
+       else
 
3244
        err = mmc_all_send_cid(host, cid);
 
3245
-       if (err != MMC_ERR_NONE)
 
3246
+       if (err)
 
3247
                goto err;
 
3248
 
 
3249
        if (oldcard) {
 
3250
-               if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0)
 
3251
+               if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) {
 
3252
+                       err = -ENOENT;
 
3253
                        goto err;
 
3254
+               }
 
3255
 
 
3256
                card = oldcard;
 
3257
        } else {
 
3258
@@ -277,8 +309,10 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 
3259
                 * Allocate card structure.
 
3260
                 */
 
3261
                card = mmc_alloc_card(host);
 
3262
-               if (IS_ERR(card))
 
3263
+               if (IS_ERR(card)) {
 
3264
+                       err = PTR_ERR(card);
 
3265
                        goto err;
 
3266
+               }
 
3267
 
 
3268
                card->type = MMC_TYPE_MMC;
 
3269
                card->rca = 1;
 
3270
@@ -286,43 +320,47 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 
3271
        }
 
3272
 
 
3273
        /*
 
3274
-        * Set card RCA.
 
3275
+        * For native busses:  set card RCA and quit open drain mode.
 
3276
         */
 
3277
+       if (!mmc_host_is_spi(host)) {
 
3278
        err = mmc_set_relative_addr(card);
 
3279
-       if (err != MMC_ERR_NONE)
 
3280
+       if (err)
 
3281
                goto free_card;
 
3282
 
 
3283
        mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
 
3284
+       }
 
3285
 
 
3286
        if (!oldcard) {
 
3287
                /*
 
3288
                 * Fetch CSD from card.
 
3289
                 */
 
3290
                err = mmc_send_csd(card, card->raw_csd);
 
3291
-               if (err != MMC_ERR_NONE)
 
3292
+               if (err)
 
3293
                        goto free_card;
 
3294
 
 
3295
                err = mmc_decode_csd(card);
 
3296
-               if (err < 0)
 
3297
+               if (err)
 
3298
                        goto free_card;
 
3299
                err = mmc_decode_cid(card);
 
3300
-               if (err < 0)
 
3301
+               if (err)
 
3302
                        goto free_card;
 
3303
        }
 
3304
 
 
3305
        /*
 
3306
         * Select card, as all following commands rely on that.
 
3307
         */
 
3308
+       if (!mmc_host_is_spi(host)) {
 
3309
        err = mmc_select_card(card);
 
3310
-       if (err != MMC_ERR_NONE)
 
3311
+       if (err)
 
3312
                goto free_card;
 
3313
+       }
 
3314
 
 
3315
        if (!oldcard) {
 
3316
                /*
 
3317
-                * Fetch and process extened CSD.
 
3318
+                * Fetch and process extended CSD.
 
3319
                 */
 
3320
                err = mmc_read_ext_csd(card);
 
3321
-               if (err != MMC_ERR_NONE)
 
3322
+               if (err)
 
3323
                        goto free_card;
 
3324
        }
 
3325
 
 
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)
 
3331
+               if (err)
 
3332
                        goto free_card;
 
3333
 
 
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)
 
3340
+               if (err)
 
3341
                        goto free_card;
 
3342
 
 
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,
 
3345
        if (!oldcard)
 
3346
                host->card = card;
 
3347
 
 
3348
-       return MMC_ERR_NONE;
 
3349
+       return 0;
 
3350
 
 
3351
 free_card:
 
3352
        if (!oldcard)
 
3353
                mmc_remove_card(card);
 
3354
 err:
 
3355
 
 
3356
-       return MMC_ERR_FAILED;
 
3357
+       return err;
 
3358
 }
 
3359
 
 
3360
 /*
 
3361
@@ -412,9 +450,8 @@ static void mmc_detect(struct mmc_host *host)
 
3362
 
 
3363
        mmc_release_host(host);
 
3364
 
 
3365
-       if (err != MMC_ERR_NONE) {
 
3366
-               mmc_remove_card(host->card);
 
3367
-               host->card = NULL;
 
3368
+       if (err) {
 
3369
+               mmc_remove(host);
 
3370
 
 
3371
                mmc_claim_host(host);
 
3372
                mmc_detach_bus(host);
 
3373
@@ -422,6 +459,53 @@ static void mmc_detect(struct mmc_host *host)
 
3374
        }
 
3375
 }
 
3376
 
 
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);
 
3388
+
 
3389
+static struct device_attribute mmc_dev_attrs[] = {
 
3390
+       MMC_ATTR_RO(cid),
 
3391
+       MMC_ATTR_RO(csd),
 
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),
 
3399
+       __ATTR_NULL,
 
3400
+};
 
3401
+
 
3402
+/*
 
3403
+ * Adds sysfs entries as relevant.
 
3404
+ */
 
3405
+static int mmc_sysfs_add(struct mmc_host *host, struct mmc_card *card)
 
3406
+{
 
3407
+       int ret;
 
3408
+
 
3409
+       ret = mmc_add_attrs(card, mmc_dev_attrs);
 
3410
+       if (ret < 0)
 
3411
+               return ret;
 
3412
+
 
3413
+       return 0;
 
3414
+}
 
3415
+
 
3416
+/*
 
3417
+ * Removes the sysfs entries added by mmc_sysfs_add().
 
3418
+ */
 
3419
+static void mmc_sysfs_remove(struct mmc_host *host, struct mmc_card *card)
 
3420
+{
 
3421
+       mmc_remove_attrs(card, mmc_dev_attrs);
 
3422
+}
 
3423
+
 
3424
 #ifdef CONFIG_MMC_UNSAFE_RESUME
 
3425
 
 
3426
 /*
 
3427
@@ -433,6 +517,7 @@ static void mmc_suspend(struct mmc_host *host)
 
3428
        BUG_ON(!host->card);
 
3429
 
 
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);
 
3437
 
 
3438
        mmc_claim_host(host);
 
3439
+       err = mmc_init_card(host, host->ocr, host->card);
 
3440
+       mmc_release_host(host);
 
3441
 
 
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;
 
3446
+       if (err) {
 
3447
+               mmc_remove(host);
 
3448
 
 
3449
+               mmc_claim_host(host);
 
3450
                mmc_detach_bus(host);
 
3451
+               mmc_release_host(host);
 
3452
        }
 
3453
 
 
3454
-       mmc_release_host(host);
 
3455
 }
 
3456
 
 
3457
 #else
 
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,
 
3466
 };
 
3467
@@ -486,11 +574,20 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)
 
3468
        int err;
 
3469
 
 
3470
        BUG_ON(!host);
 
3471
-       BUG_ON(!host->claimed);
 
3472
+       WARN_ON(!host->claimed);
 
3473
 
 
3474
        mmc_attach_bus(host, &mmc_ops);
 
3475
 
 
3476
        /*
 
3477
+        * We need to get OCR a different way for SPI.
 
3478
+        */
 
3479
+       if (mmc_host_is_spi(host)) {
 
3480
+               err = mmc_spi_read_ocr(host, 1, &ocr);
 
3481
+               if (err)
 
3482
+                       goto err;
 
3483
+       }
 
3484
+
 
3485
+       /*
 
3486
         * Sanity check the voltages that the card claims to
 
3487
         * support.
 
3488
         */
 
3489
@@ -506,32 +603,37 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)
 
3490
        /*
 
3491
         * Can we support the voltage of the card?
 
3492
         */
 
3493
-       if (!host->ocr)
 
3494
+       if (!host->ocr) {
 
3495
+               err = -EINVAL;
 
3496
                goto err;
 
3497
+       }
 
3498
 
 
3499
        /*
 
3500
         * Detect and init the card.
 
3501
         */
 
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);
 
3505
+       if (err)
 
3506
                goto err;
 
3507
 
 
3508
        mmc_release_host(host);
 
3509
 
 
3510
-       err = mmc_register_card(host->card);
 
3511
+       err = mmc_add_card(host->card);
 
3512
        if (err)
 
3513
-               goto reclaim_host;
 
3514
+               goto remove_card;
 
3515
 
 
3516
        return 0;
 
3517
 
 
3518
-reclaim_host:
 
3519
-       mmc_claim_host(host);
 
3520
+remove_card:
 
3521
        mmc_remove_card(host->card);
 
3522
        host->card = NULL;
 
3523
+       mmc_claim_host(host);
 
3524
 err:
 
3525
        mmc_detach_bus(host);
 
3526
        mmc_release_host(host);
 
3527
 
 
3528
-       return 0;
 
3529
+       printk(KERN_ERR "%s: error %d whilst initialising MMC card\n",
 
3530
+               mmc_hostname(host), err);
 
3531
+
 
3532
+       return err;
 
3533
 }
 
3534
 
 
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
 
3539
@@ -1,5 +1,5 @@
 
3540
 /*
 
3541
- *  linux/drivers/mmc/mmc_ops.h
 
3542
+ *  linux/drivers/mmc/core/mmc_ops.h
 
3543
  *
 
3544
  *  Copyright 2006-2007 Pierre Ossman
 
3545
  *
 
3546
@@ -40,10 +40,10 @@ static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card)
 
3547
        }
 
3548
 
 
3549
        err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
 
3550
-       if (err != MMC_ERR_NONE)
 
3551
+       if (err)
 
3552
                return err;
 
3553
 
 
3554
-       return MMC_ERR_NONE;
 
3555
+       return 0;
 
3556
 }
 
3557
 
 
3558
 int mmc_select_card(struct mmc_card *card)
 
3559
@@ -63,23 +63,36 @@ int mmc_go_idle(struct mmc_host *host)
 
3560
        int err;
 
3561
        struct mmc_command cmd;
 
3562
 
 
3563
+       /*
 
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.
 
3567
+        *
 
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.
 
3571
+        */
 
3572
+       if (!mmc_host_is_spi(host)) {
 
3573
        mmc_set_chip_select(host, MMC_CS_HIGH);
 
3574
-
 
3575
        mmc_delay(1);
 
3576
+       }
 
3577
 
 
3578
        memset(&cmd, 0, sizeof(struct mmc_command));
 
3579
 
 
3580
        cmd.opcode = MMC_GO_IDLE_STATE;
 
3581
        cmd.arg = 0;
 
3582
-       cmd.flags = MMC_RSP_NONE | MMC_CMD_BC;
 
3583
+       cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_NONE | MMC_CMD_BC;
 
3584
 
 
3585
        err = mmc_wait_for_cmd(host, &cmd, 0);
 
3586
 
 
3587
        mmc_delay(1);
 
3588
 
 
3589
+       if (!mmc_host_is_spi(host)) {
 
3590
        mmc_set_chip_select(host, MMC_CS_DONTCARE);
 
3591
-
 
3592
        mmc_delay(1);
 
3593
+       }
 
3594
+
 
3595
+       host->use_spi_crc = 0;
 
3596
 
 
3597
        return err;
 
3598
 }
 
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));
 
3601
 
 
3602
        cmd.opcode = MMC_SEND_OP_COND;
 
3603
-       cmd.arg = ocr;
 
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;
 
3607
 
 
3608
        for (i = 100; i; i--) {
 
3609
                err = mmc_wait_for_cmd(host, &cmd, 0);
 
3610
-               if (err != MMC_ERR_NONE)
 
3611
+               if (err)
 
3612
                        break;
 
3613
 
 
3614
-               if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
 
3615
+               /* if we're just probing, do a single pass */
 
3616
+               if (ocr == 0)
 
3617
                        break;
 
3618
 
 
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))
 
3623
+                               break;
 
3624
+               } else {
 
3625
+                       if (cmd.resp[0] & MMC_CARD_BUSY)
 
3626
+                               break;
 
3627
+               }
 
3628
+
 
3629
+               err = -ETIMEDOUT;
 
3630
 
 
3631
                mmc_delay(10);
 
3632
        }
 
3633
 
 
3634
-       if (rocr)
 
3635
+       if (rocr && !mmc_host_is_spi(host))
 
3636
                *rocr = cmd.resp[0];
 
3637
 
 
3638
        return err;
 
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;
 
3641
 
 
3642
        err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
 
3643
-       if (err != MMC_ERR_NONE)
 
3644
+       if (err)
 
3645
                return err;
 
3646
 
 
3647
        memcpy(cid, cmd.resp, sizeof(u32) * 4);
 
3648
 
 
3649
-       return MMC_ERR_NONE;
 
3650
+       return 0;
 
3651
 }
 
3652
 
 
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;
 
3656
 
 
3657
        err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
 
3658
-       if (err != MMC_ERR_NONE)
 
3659
+       if (err)
 
3660
                return err;
 
3661
 
 
3662
-       return MMC_ERR_NONE;
 
3663
+       return 0;
 
3664
 }
 
3665
 
 
3666
-int mmc_send_csd(struct mmc_card *card, u32 *csd)
 
3667
+static int
 
3668
+mmc_send_cxd_native(struct mmc_host *host, u32 arg, u32 *cxd, int opcode)
 
3669
 {
 
3670
        int err;
 
3671
        struct mmc_command cmd;
 
3672
 
 
3673
-       BUG_ON(!card);
 
3674
-       BUG_ON(!card->host);
 
3675
-       BUG_ON(!csd);
 
3676
+       BUG_ON(!host);
 
3677
+       BUG_ON(!cxd);
 
3678
 
 
3679
        memset(&cmd, 0, sizeof(struct mmc_command));
 
3680
 
 
3681
-       cmd.opcode = MMC_SEND_CSD;
 
3682
-       cmd.arg = card->rca << 16;
 
3683
+       cmd.opcode = opcode;
 
3684
+       cmd.arg = arg;
 
3685
        cmd.flags = MMC_RSP_R2 | MMC_CMD_AC;
 
3686
 
 
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);
 
3690
+       if (err)
 
3691
                return err;
 
3692
 
 
3693
-       memcpy(csd, cmd.resp, sizeof(u32) * 4);
 
3694
+       memcpy(cxd, cmd.resp, sizeof(u32) * 4);
 
3695
 
 
3696
-       return MMC_ERR_NONE;
 
3697
+       return 0;
 
3698
 }
 
3699
 
 
3700
-int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
 
3701
+static int
 
3702
+mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
 
3703
+               u32 opcode, void *buf, unsigned len)
 
3704
 {
 
3705
        struct mmc_request mrq;
 
3706
        struct mmc_command cmd;
 
3707
        struct mmc_data data;
 
3708
        struct scatterlist sg;
 
3709
+       void *data_buf;
 
3710
 
 
3711
-       BUG_ON(!card);
 
3712
-       BUG_ON(!card->host);
 
3713
-       BUG_ON(!ext_csd);
 
3714
+       /* dma onto stack is unsafe/nonportable, but callers to this
 
3715
+        * routine normally provide temporary on-stack buffers ...
 
3716
+        */
 
3717
+       data_buf = kmalloc(len, GFP_KERNEL);
 
3718
+       if (data_buf == NULL)
 
3719
+               return -ENOMEM;
 
3720
 
 
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)
 
3724
        mrq.cmd = &cmd;
 
3725
        mrq.data = &data;
 
3726
 
 
3727
-       cmd.opcode = MMC_SEND_EXT_CSD;
 
3728
+       cmd.opcode = opcode;
 
3729
        cmd.arg = 0;
 
3730
-       cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
 
3731
 
 
3732
-       data.blksz = 512;
 
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.
 
3737
+        */
 
3738
+       cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
 
3739
+
 
3740
+       data.blksz = len;
 
3741
        data.blocks = 1;
 
3742
        data.flags = MMC_DATA_READ;
 
3743
        data.sg = &sg;
 
3744
        data.sg_len = 1;
 
3745
 
 
3746
-       sg_init_one(&sg, ext_csd, 512);
 
3747
+       sg_init_one(&sg, data_buf, len);
 
3748
+
 
3749
+       if (card)
 
3750
+               mmc_set_data_timeout(&data, card);
 
3751
 
 
3752
-       mmc_set_data_timeout(&data, card, 0);
 
3753
+       mmc_wait_for_req(host, &mrq);
 
3754
 
 
3755
-       mmc_wait_for_req(card->host, &mrq);
 
3756
+       memcpy(buf, data_buf, len);
 
3757
+       kfree(data_buf);
 
3758
 
 
3759
-       if (cmd.error != MMC_ERR_NONE)
 
3760
+       if (cmd.error)
 
3761
                return cmd.error;
 
3762
-       if (data.error != MMC_ERR_NONE)
 
3763
+       if (data.error)
 
3764
                return data.error;
 
3765
 
 
3766
-       return MMC_ERR_NONE;
 
3767
+       return 0;
 
3768
+}
 
3769
+
 
3770
+int mmc_send_csd(struct mmc_card *card, u32 *csd)
 
3771
+{
 
3772
+       int ret, i;
 
3773
+
 
3774
+       if (!mmc_host_is_spi(card->host))
 
3775
+               return mmc_send_cxd_native(card->host, card->rca << 16,
 
3776
+                               csd, MMC_SEND_CSD);
 
3777
+
 
3778
+       ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16);
 
3779
+       if (ret)
 
3780
+               return ret;
 
3781
+
 
3782
+       for (i = 0;i < 4;i++)
 
3783
+               csd[i] = be32_to_cpu(csd[i]);
 
3784
+
 
3785
+       return 0;
 
3786
+}
 
3787
+
 
3788
+int mmc_send_cid(struct mmc_host *host, u32 *cid)
 
3789
+{
 
3790
+       int ret, i;
 
3791
+
 
3792
+       if (!mmc_host_is_spi(host)) {
 
3793
+               if (!host->card)
 
3794
+                       return -EINVAL;
 
3795
+               return mmc_send_cxd_native(host, host->card->rca << 16,
 
3796
+                               cid, MMC_SEND_CID);
 
3797
+       }
 
3798
+
 
3799
+       ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16);
 
3800
+       if (ret)
 
3801
+               return ret;
 
3802
+
 
3803
+       for (i = 0;i < 4;i++)
 
3804
+               cid[i] = be32_to_cpu(cid[i]);
 
3805
+
 
3806
+       return 0;
 
3807
+}
 
3808
+
 
3809
+int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
 
3810
+{
 
3811
+       return mmc_send_cxd_data(card, card->host, MMC_SEND_EXT_CSD,
 
3812
+                       ext_csd, 512);
 
3813
+}
 
3814
+
 
3815
+int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp)
 
3816
+{
 
3817
+       struct mmc_command cmd;
 
3818
+       int err;
 
3819
+
 
3820
+       memset(&cmd, 0, sizeof(struct mmc_command));
 
3821
+
 
3822
+       cmd.opcode = MMC_SPI_READ_OCR;
 
3823
+       cmd.arg = highcap ? (1 << 30) : 0;
 
3824
+       cmd.flags = MMC_RSP_SPI_R3;
 
3825
+
 
3826
+       err = mmc_wait_for_cmd(host, &cmd, 0);
 
3827
+
 
3828
+       *ocrp = cmd.resp[1];
 
3829
+       return err;
 
3830
+}
 
3831
+
 
3832
+int mmc_spi_set_crc(struct mmc_host *host, int use_crc)
 
3833
+{
 
3834
+       struct mmc_command cmd;
 
3835
+       int err;
 
3836
+
 
3837
+       memset(&cmd, 0, sizeof(struct mmc_command));
 
3838
+
 
3839
+       cmd.opcode = MMC_SPI_CRC_ON_OFF;
 
3840
+       cmd.flags = MMC_RSP_SPI_R1;
 
3841
+       cmd.arg = use_crc;
 
3842
+
 
3843
+       err = mmc_wait_for_cmd(host, &cmd, 0);
 
3844
+       if (!err)
 
3845
+               host->use_spi_crc = use_crc;
 
3846
+       return err;
 
3847
 }
 
3848
 
 
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)
 
3851
                  (index << 16) |
 
3852
                  (value << 8) |
 
3853
                  set;
 
3854
-       cmd.flags = MMC_RSP_R1B | MMC_CMD_AC;
 
3855
+       cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
 
3856
 
 
3857
        err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
 
3858
-       if (err != MMC_ERR_NONE)
 
3859
+       if (err)
 
3860
                return err;
 
3861
 
 
3862
-       return MMC_ERR_NONE;
 
3863
+       return 0;
 
3864
 }
 
3865
 
 
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));
 
3869
 
 
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;
 
3875
 
 
3876
        err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
 
3877
-       if (err != MMC_ERR_NONE)
 
3878
+       if (err)
 
3879
                return err;
 
3880
 
 
3881
+       /* NOTE: callers are required to understand the difference
 
3882
+        * between "native" and SPI format status words!
 
3883
+        */
 
3884
        if (status)
 
3885
                *status = cmd.resp[0];
 
3886
 
 
3887
-       return MMC_ERR_NONE;
 
3888
+       return 0;
 
3889
 }
 
3890
 
 
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
 
3895
@@ -1,5 +1,5 @@
 
3896
 /*
 
3897
- *  linux/drivers/mmc/mmc_ops.h
 
3898
+ *  linux/drivers/mmc/core/mmc_ops.h
 
3899
  *
 
3900
  *  Copyright 2006-2007 Pierre Ossman
 
3901
  *
 
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);
 
3909
 
 
3910
 #endif
 
3911
 
 
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
 
3916
@@ -1,5 +1,5 @@
 
3917
 /*
 
3918
- *  linux/drivers/mmc/sd.c
 
3919
+ *  linux/drivers/mmc/core/sd.c
 
3920
  *
 
3921
  *  Copyright (C) 2003-2004 Russell King, All Rights Reserved.
 
3922
  *  SD support Copyright (C) 2004 Ian Molton, All Rights Reserved.
 
3923
@@ -19,11 +19,10 @@
 
3924
 
 
3925
 #include "core.h"
 
3926
 #include "sysfs.h"
 
3927
+#include "bus.h"
 
3928
 #include "mmc_ops.h"
 
3929
 #include "sd_ops.h"
 
3930
 
 
3931
-#include "core.h"
 
3932
-
 
3933
 static const unsigned int tran_exp[] = {
 
3934
        10000,          100000,         1000000,        10000000,
 
3935
        0,              0,              0,              0
 
3936
@@ -150,7 +149,7 @@ static int mmc_decode_csd(struct mmc_card *card)
 
3937
                csd->write_partial = 0;
 
3938
                break;
 
3939
        default:
 
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);
 
3943
                return -EINVAL;
 
3944
        }
 
3945
@@ -167,14 +166,12 @@ static int mmc_decode_scr(struct mmc_card *card)
 
3946
        unsigned int scr_struct;
 
3947
        u32 resp[4];
 
3948
 
 
3949
-       BUG_ON(!mmc_card_sd(card));
 
3950
-
 
3951
        resp[3] = card->raw_scr[1];
 
3952
        resp[2] = card->raw_scr[0];
 
3953
 
 
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);
 
3959
                return -EINVAL;
 
3960
        }
 
3961
@@ -194,31 +191,38 @@ static int mmc_read_switch(struct mmc_card *card)
 
3962
        u8 *status;
 
3963
 
 
3964
        if (card->scr.sda_vsn < SCR_SPEC_VER_1)
 
3965
-               return MMC_ERR_NONE;
 
3966
+               return 0;
 
3967
 
 
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;
 
3973
+               return 0;
 
3974
        }
 
3975
 
 
3976
-       err = MMC_ERR_FAILED;
 
3977
+       err = -EIO;
 
3978
 
 
3979
        status = kmalloc(64, GFP_KERNEL);
 
3980
        if (!status) {
 
3981
-               printk("%s: could not allocate a buffer for switch "
 
3982
-                      "capabilities.\n",
 
3983
-                       mmc_hostname(card->host));
 
3984
-               return err;
 
3985
+               printk(KERN_ERR "%s: could not allocate a buffer for "
 
3986
+                       "switch capabilities.\n", mmc_hostname(card->host));
 
3987
+               return -ENOMEM;
 
3988
        }
 
3989
 
 
3990
        err = mmc_sd_switch(card, 0, 0, 1, status);
 
3991
-       if (err != MMC_ERR_NONE) {
 
3992
+       if (err) {
 
3993
+               /*
 
3994
+                * We all hosts that cannot perform the command
 
3995
+                * to fail more gracefully
 
3996
+                */
 
3997
+               if (err != -EINVAL)
 
3998
+                       goto out;
 
3999
+
 
4000
                printk(KERN_WARNING "%s: problem reading switch "
 
4001
                        "capabilities, performance might suffer.\n",
 
4002
                        mmc_hostname(card->host));
 
4003
-               err = MMC_ERR_NONE;
 
4004
+               err = 0;
 
4005
+
 
4006
                goto out;
 
4007
        }
 
4008
 
 
4009
@@ -240,29 +244,28 @@ static int mmc_switch_hs(struct mmc_card *card)
 
4010
        u8 *status;
 
4011
 
 
4012
        if (card->scr.sda_vsn < SCR_SPEC_VER_1)
 
4013
-               return MMC_ERR_NONE;
 
4014
+               return 0;
 
4015
 
 
4016
        if (!(card->csd.cmdclass & CCC_SWITCH))
 
4017
-               return MMC_ERR_NONE;
 
4018
+               return 0;
 
4019
 
 
4020
        if (!(card->host->caps & MMC_CAP_SD_HIGHSPEED))
 
4021
-               return MMC_ERR_NONE;
 
4022
+               return 0;
 
4023
 
 
4024
        if (card->sw_caps.hs_max_dtr == 0)
 
4025
-               return MMC_ERR_NONE;
 
4026
+               return 0;
 
4027
 
 
4028
-       err = MMC_ERR_FAILED;
 
4029
+       err = -EIO;
 
4030
 
 
4031
        status = kmalloc(64, GFP_KERNEL);
 
4032
        if (!status) {
 
4033
-               printk("%s: could not allocate a buffer for switch "
 
4034
-                      "capabilities.\n",
 
4035
-                       mmc_hostname(card->host));
 
4036
-               return err;
 
4037
+               printk(KERN_ERR "%s: could not allocate a buffer for "
 
4038
+                       "switch capabilities.\n", mmc_hostname(card->host));
 
4039
+               return -ENOMEM;
 
4040
        }
 
4041
 
 
4042
        err = mmc_sd_switch(card, 1, 0, 1, status);
 
4043
-       if (err != MMC_ERR_NONE)
 
4044
+       if (err)
 
4045
                goto out;
 
4046
 
 
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;
 
4050
 
 
4051
        BUG_ON(!host);
 
4052
-       BUG_ON(!host->claimed);
 
4053
+       WARN_ON(!host->claimed);
 
4054
 
 
4055
        /*
 
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.
 
4059
         */
 
4060
        err = mmc_send_if_cond(host, ocr);
 
4061
-       if (err == MMC_ERR_NONE)
 
4062
+       if (!err)
 
4063
                ocr |= 1 << 30;
 
4064
 
 
4065
        err = mmc_send_app_op_cond(host, ocr, NULL);
 
4066
-       if (err != MMC_ERR_NONE)
 
4067
+       if (err)
 
4068
                goto err;
 
4069
 
 
4070
        /*
 
4071
+        * For SPI, enable CRC as appropriate.
 
4072
+        */
 
4073
+       if (mmc_host_is_spi(host)) {
 
4074
+               err = mmc_spi_set_crc(host, use_spi_crc);
 
4075
+               if (err)
 
4076
+                       goto err;
 
4077
+       }
 
4078
+
 
4079
+       /*
 
4080
         * Fetch CID from card.
 
4081
         */
 
4082
+       if (mmc_host_is_spi(host))
 
4083
+               err = mmc_send_cid(host, cid);
 
4084
+       else
 
4085
        err = mmc_all_send_cid(host, cid);
 
4086
-       if (err != MMC_ERR_NONE)
 
4087
+       if (err)
 
4088
                goto err;
 
4089
 
 
4090
        if (oldcard) {
 
4091
-               if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0)
 
4092
+               if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) {
 
4093
+                       err = -ENOENT;
 
4094
                        goto err;
 
4095
+               }
 
4096
 
 
4097
                card = oldcard;
 
4098
        } else {
 
4099
@@ -336,32 +353,36 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 
4100
                 * Allocate card structure.
 
4101
                 */
 
4102
                card = mmc_alloc_card(host);
 
4103
-               if (IS_ERR(card))
 
4104
+               if (IS_ERR(card)) {
 
4105
+                       err = PTR_ERR(card);
 
4106
                        goto err;
 
4107
+               }
 
4108
 
 
4109
                card->type = MMC_TYPE_SD;
 
4110
                memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
 
4111
        }
 
4112
 
 
4113
        /*
 
4114
-        * Set card RCA.
 
4115
+        * For native busses:  get card RCA and quit open drain mode.
 
4116
         */
 
4117
+       if (!mmc_host_is_spi(host)) {
 
4118
        err = mmc_send_relative_addr(host, &card->rca);
 
4119
-       if (err != MMC_ERR_NONE)
 
4120
+       if (err)
 
4121
                goto free_card;
 
4122
 
 
4123
        mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
 
4124
+       }
 
4125
 
 
4126
        if (!oldcard) {
 
4127
                /*
 
4128
                 * Fetch CSD from card.
 
4129
                 */
 
4130
                err = mmc_send_csd(card, card->raw_csd);
 
4131
-               if (err != MMC_ERR_NONE)
 
4132
+               if (err)
 
4133
                        goto free_card;
 
4134
 
 
4135
                err = mmc_decode_csd(card);
 
4136
-               if (err < 0)
 
4137
+               if (err)
 
4138
                        goto free_card;
 
4139
 
 
4140
                mmc_decode_cid(card);
 
4141
@@ -370,16 +391,18 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 
4142
        /*
 
4143
         * Select card, as all following commands rely on that.
 
4144
         */
 
4145
+       if (!mmc_host_is_spi(host)) {
 
4146
        err = mmc_select_card(card);
 
4147
-       if (err != MMC_ERR_NONE)
 
4148
+       if (err)
 
4149
                goto free_card;
 
4150
+       }
 
4151
 
 
4152
        if (!oldcard) {
 
4153
                /*
 
4154
                 * Fetch SCR from card.
 
4155
                 */
 
4156
                err = mmc_app_send_scr(card, card->raw_scr);
 
4157
-               if (err != MMC_ERR_NONE)
 
4158
+               if (err)
 
4159
                        goto free_card;
 
4160
 
 
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.
 
4164
                 */
 
4165
                err = mmc_read_switch(card);
 
4166
-               if (err != MMC_ERR_NONE)
 
4167
+               if (err)
 
4168
                        goto free_card;
 
4169
        }
 
4170
 
 
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)
 
4173
         */
 
4174
        err = mmc_switch_hs(card);
 
4175
-       if (err != MMC_ERR_NONE)
 
4176
+       if (err)
 
4177
                goto free_card;
 
4178
 
 
4179
        /*
 
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)
 
4185
+               if (err)
 
4186
                        goto free_card;
 
4187
 
 
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,
 
4190
        if (!oldcard)
 
4191
                host->card = card;
 
4192
 
 
4193
-       return MMC_ERR_NONE;
 
4194
+       return 0;
 
4195
 
 
4196
 free_card:
 
4197
        if (!oldcard)
 
4198
                mmc_remove_card(card);
 
4199
 err:
 
4200
 
 
4201
-       return MMC_ERR_FAILED;
 
4202
+       return err;
 
4203
 }
 
4204
 
 
4205
 /*
 
4206
@@ -486,9 +509,8 @@ static void mmc_sd_detect(struct mmc_host *host)
 
4207
 
 
4208
        mmc_release_host(host);
 
4209
 
 
4210
-       if (err != MMC_ERR_NONE) {
 
4211
-               mmc_remove_card(host->card);
 
4212
-               host->card = NULL;
 
4213
+       if (err) {
 
4214
+               mmc_sd_remove(host);
 
4215
 
 
4216
                mmc_claim_host(host);
 
4217
                mmc_detach_bus(host);
 
4218
@@ -496,6 +518,55 @@ static void mmc_sd_detect(struct mmc_host *host)
 
4219
        }
 
4220
 }
 
4221
 
 
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);
 
4234
+
 
4235
+static struct device_attribute mmc_sd_dev_attrs[] = {
 
4236
+       MMC_ATTR_RO(cid),
 
4237
+       MMC_ATTR_RO(csd),
 
4238
+       MMC_ATTR_RO(scr),
 
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),
 
4246
+       __ATTR_NULL,
 
4247
+};
 
4248
+
 
4249
+/*
 
4250
+ * Adds sysfs entries as relevant.
 
4251
+ */
 
4252
+static int mmc_sd_sysfs_add(struct mmc_host *host, struct mmc_card *card)
 
4253
+{
 
4254
+       int ret;
 
4255
+
 
4256
+       ret = mmc_add_attrs(card, mmc_sd_dev_attrs);
 
4257
+       if (ret < 0)
 
4258
+               return ret;
 
4259
+
 
4260
+       return 0;
 
4261
+}
 
4262
+
 
4263
+/*
 
4264
+ * Removes the sysfs entries added by mmc_sysfs_add().
 
4265
+ */
 
4266
+static void mmc_sd_sysfs_remove(struct mmc_host *host, struct mmc_card *card)
 
4267
+{
 
4268
+       mmc_remove_attrs(card, mmc_sd_dev_attrs);
 
4269
+}
 
4270
+
 
4271
 #ifdef CONFIG_MMC_UNSAFE_RESUME
 
4272
 
 
4273
 /*
 
4274
@@ -507,6 +578,7 @@ static void mmc_sd_suspend(struct mmc_host *host)
 
4275
        BUG_ON(!host->card);
 
4276
 
 
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);
 
4284
 
 
4285
        mmc_claim_host(host);
 
4286
-
 
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);
 
4292
+
 
4293
+       if (err) {
 
4294
+               mmc_sd_remove(host);
 
4295
 
 
4296
+               mmc_claim_host(host);
 
4297
                mmc_detach_bus(host);
 
4298
+               mmc_release_host(host);
 
4299
        }
 
4300
 
 
4301
-       mmc_release_host(host);
 
4302
 }
 
4303
 
 
4304
 #else
 
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,
 
4313
 };
 
4314
@@ -560,11 +635,22 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)
 
4315
        int err;
 
4316
 
 
4317
        BUG_ON(!host);
 
4318
-       BUG_ON(!host->claimed);
 
4319
+       WARN_ON(!host->claimed);
 
4320
 
 
4321
        mmc_attach_bus(host, &mmc_sd_ops);
 
4322
 
 
4323
        /*
 
4324
+        * We need to get OCR a different way for SPI.
 
4325
+        */
 
4326
+       if (mmc_host_is_spi(host)) {
 
4327
+               mmc_go_idle(host);
 
4328
+
 
4329
+               err = mmc_spi_read_ocr(host, 0, &ocr);
 
4330
+               if (err)
 
4331
+                       goto err;
 
4332
+       }
 
4333
+
 
4334
+       /*
 
4335
         * Sanity check the voltages that the card claims to
 
4336
         * support.
 
4337
         */
 
4338
@@ -587,32 +673,37 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)
 
4339
        /*
 
4340
         * Can we support the voltage(s) of the card(s)?
 
4341
         */
 
4342
-       if (!host->ocr)
 
4343
+       if (!host->ocr) {
 
4344
+               err = -EINVAL;
 
4345
                goto err;
 
4346
+       }
 
4347
 
 
4348
        /*
 
4349
         * Detect and init the card.
 
4350
         */
 
4351
        err = mmc_sd_init_card(host, host->ocr, NULL);
 
4352
-       if (err != MMC_ERR_NONE)
 
4353
+       if (err)
 
4354
                goto err;
 
4355
 
 
4356
        mmc_release_host(host);
 
4357
 
 
4358
-       err = mmc_register_card(host->card);
 
4359
+       err = mmc_add_card(host->card);
 
4360
        if (err)
 
4361
-               goto reclaim_host;
 
4362
+               goto remove_card;
 
4363
 
 
4364
        return 0;
 
4365
 
 
4366
-reclaim_host:
 
4367
-       mmc_claim_host(host);
 
4368
+remove_card:
 
4369
        mmc_remove_card(host->card);
 
4370
        host->card = NULL;
 
4371
+       mmc_claim_host(host);
 
4372
 err:
 
4373
        mmc_detach_bus(host);
 
4374
        mmc_release_host(host);
 
4375
 
 
4376
-       return 0;
 
4377
+       printk(KERN_ERR "%s: error %d whilst initialising SD card\n",
 
4378
+               mmc_hostname(host), err);
 
4379
+
 
4380
+       return err;
 
4381
 }
 
4382
 
 
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
 
4387
@@ -1,5 +1,5 @@
 
4388
 /*
 
4389
- *  linux/drivers/mmc/sd_ops.h
 
4390
+ *  linux/drivers/mmc/core/sd_ops.h
 
4391
  *
 
4392
  *  Copyright 2006-2007 Pierre Ossman
 
4393
  *
 
4394
@@ -21,11 +21,40 @@
 
4395
 #include "core.h"
 
4396
 #include "sd_ops.h"
 
4397
 
 
4398
+static int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
 
4399
+{
 
4400
+       int err;
 
4401
+       struct mmc_command cmd;
 
4402
+
 
4403
+       BUG_ON(!host);
 
4404
+       BUG_ON(card && (card->host != host));
 
4405
+
 
4406
+       cmd.opcode = MMC_APP_CMD;
 
4407
+
 
4408
+       if (card) {
 
4409
+               cmd.arg = card->rca << 16;
 
4410
+               cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
 
4411
+       } else {
 
4412
+               cmd.arg = 0;
 
4413
+               cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_BCR;
 
4414
+       }
 
4415
+
 
4416
+       err = mmc_wait_for_cmd(host, &cmd, 0);
 
4417
+       if (err)
 
4418
+               return err;
 
4419
+
 
4420
+       /* Check that card supported application commands */
 
4421
+       if (!mmc_host_is_spi(host) && !(cmd.resp[0] & R1_APP_CMD))
 
4422
+               return -EOPNOTSUPP;
 
4423
+
 
4424
+       return 0;
 
4425
+}
 
4426
+
 
4427
 /**
 
4428
  *     mmc_wait_for_app_cmd - start an application command and wait for
 
4429
                               completion
 
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
 
4435
  *
 
4436
@@ -44,7 +73,7 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
 
4437
        BUG_ON(!cmd);
 
4438
        BUG_ON(retries < 0);
 
4439
 
 
4440
-       err = MMC_ERR_INVALID;
 
4441
+       err = -EIO;
 
4442
 
 
4443
        /*
 
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));
 
4447
 
 
4448
                err = mmc_app_cmd(host, card);
 
4449
-               if (err != MMC_ERR_NONE)
 
4450
+               if (err) {
 
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)
 
4454
+                                       break;
 
4455
+                       }
 
4456
                        continue;
 
4457
+               }
 
4458
 
 
4459
                memset(&mrq, 0, sizeof(struct mmc_request));
 
4460
 
 
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);
 
4463
 
 
4464
                err = cmd->error;
 
4465
-               if (cmd->error == MMC_ERR_NONE)
 
4466
+               if (!cmd->error)
 
4467
                        break;
 
4468
+
 
4469
+               /* no point in retrying illegal APP commands */
 
4470
+               if (mmc_host_is_spi(host)) {
 
4471
+                       if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
 
4472
+                               break;
 
4473
+               }
 
4474
        }
 
4475
 
 
4476
        return err;
 
4477
@@ -77,35 +118,6 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
 
4478
 
 
4479
 EXPORT_SYMBOL(mmc_wait_for_app_cmd);
 
4480
 
 
4481
-int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
 
4482
-{
 
4483
-       int err;
 
4484
-       struct mmc_command cmd;
 
4485
-
 
4486
-       BUG_ON(!host);
 
4487
-       BUG_ON(card && (card->host != host));
 
4488
-
 
4489
-       cmd.opcode = MMC_APP_CMD;
 
4490
-
 
4491
-       if (card) {
 
4492
-               cmd.arg = card->rca << 16;
 
4493
-               cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
 
4494
-       } else {
 
4495
-               cmd.arg = 0;
 
4496
-               cmd.flags = MMC_RSP_R1 | MMC_CMD_BCR;
 
4497
-       }
 
4498
-
 
4499
-       err = mmc_wait_for_cmd(host, &cmd, 0);
 
4500
-       if (err != MMC_ERR_NONE)
 
4501
-               return err;
 
4502
-
 
4503
-       /* Check that card supported application commands */
 
4504
-       if (!(cmd.resp[0] & R1_APP_CMD))
 
4505
-               return MMC_ERR_FAILED;
 
4506
-
 
4507
-       return MMC_ERR_NONE;
 
4508
-}
 
4509
-
 
4510
 int mmc_app_set_bus_width(struct mmc_card *card, int width)
 
4511
 {
 
4512
        int err;
 
4513
@@ -127,14 +139,14 @@ int mmc_app_set_bus_width(struct mmc_card *card, int width)
 
4514
                cmd.arg = SD_BUS_WIDTH_4;
 
4515
                break;
 
4516
        default:
 
4517
-               return MMC_ERR_INVALID;
 
4518
+               return -EINVAL;
 
4519
        }
 
4520
 
 
4521
        err = mmc_wait_for_app_cmd(card->host, card, &cmd, MMC_CMD_RETRIES);
 
4522
-       if (err != MMC_ERR_NONE)
 
4523
+       if (err)
 
4524
                return err;
 
4525
 
 
4526
-       return MMC_ERR_NONE;
 
4527
+       return 0;
 
4528
 }
 
4529
 
 
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));
 
4533
 
 
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 */
 
4537
+       else
 
4538
        cmd.arg = ocr;
 
4539
-       cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR;
 
4540
+       cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR;
 
4541
 
 
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)
 
4545
+               if (err)
 
4546
                        break;
 
4547
 
 
4548
-               if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
 
4549
+               /* if we're just probing, do a single pass */
 
4550
+               if (ocr == 0)
 
4551
                        break;
 
4552
 
 
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))
 
4557
+                               break;
 
4558
+               } else {
 
4559
+                       if (cmd.resp[0] & MMC_CARD_BUSY)
 
4560
+                               break;
 
4561
+               }
 
4562
+
 
4563
+               err = -ETIMEDOUT;
 
4564
 
 
4565
                mmc_delay(10);
 
4566
        }
 
4567
 
 
4568
-       if (rocr)
 
4569
+       if (rocr && !mmc_host_is_spi(host))
 
4570
                *rocr = cmd.resp[0];
 
4571
 
 
4572
        return err;
 
4573
@@ -174,6 +199,7 @@ int mmc_send_if_cond(struct mmc_host *host, u32 ocr)
 
4574
        struct mmc_command cmd;
 
4575
        int err;
 
4576
        static const u8 test_pattern = 0xAA;
 
4577
+       u8 result_pattern;
 
4578
 
 
4579
        /*
 
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)
 
4582
         */
 
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;
 
4587
 
 
4588
        err = mmc_wait_for_cmd(host, &cmd, 0);
 
4589
-       if (err != MMC_ERR_NONE)
 
4590
+       if (err)
 
4591
                return err;
 
4592
 
 
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;
 
4597
+       else
 
4598
+               result_pattern = cmd.resp[0] & 0xFF;
 
4599
 
 
4600
-       return MMC_ERR_NONE;
 
4601
+       if (result_pattern != test_pattern)
 
4602
+               return -EIO;
 
4603
+
 
4604
+       return 0;
 
4605
 }
 
4606
 
 
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;
 
4610
 
 
4611
        err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
 
4612
-       if (err != MMC_ERR_NONE)
 
4613
+       if (err)
 
4614
                return err;
 
4615
 
 
4616
        *rca = cmd.resp[0] >> 16;
 
4617
 
 
4618
-       return MMC_ERR_NONE;
 
4619
+       return 0;
 
4620
 }
 
4621
 
 
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);
 
4625
        BUG_ON(!scr);
 
4626
 
 
4627
+       /* NOTE: caller guarantees scr is heap-allocated */
 
4628
+
 
4629
        err = mmc_app_cmd(card->host, card);
 
4630
-       if (err != MMC_ERR_NONE)
 
4631
+       if (err)
 
4632
                return err;
 
4633
 
 
4634
        memset(&mrq, 0, sizeof(struct mmc_request));
 
4635
@@ -242,7 +275,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
 
4636
 
 
4637
        cmd.opcode = SD_APP_SEND_SCR;
 
4638
        cmd.arg = 0;
 
4639
-       cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
 
4640
+       cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
 
4641
 
 
4642
        data.blksz = 8;
 
4643
        data.blocks = 1;
 
4644
@@ -252,19 +285,19 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
 
4645
 
 
4646
        sg_init_one(&sg, scr, 8);
 
4647
 
 
4648
-       mmc_set_data_timeout(&data, card, 0);
 
4649
+       mmc_set_data_timeout(&data, card);
 
4650
 
 
4651
        mmc_wait_for_req(card->host, &mrq);
 
4652
 
 
4653
-       if (cmd.error != MMC_ERR_NONE)
 
4654
+       if (cmd.error)
 
4655
                return cmd.error;
 
4656
-       if (data.error != MMC_ERR_NONE)
 
4657
+       if (data.error)
 
4658
                return data.error;
 
4659
 
 
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]);
 
4664
 
 
4665
-       return MMC_ERR_NONE;
 
4666
+       return 0;
 
4667
 }
 
4668
 
 
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,
 
4671
        BUG_ON(!card);
 
4672
        BUG_ON(!card->host);
 
4673
 
 
4674
+       /* NOTE: caller guarantees resp is heap-allocated */
 
4675
+
 
4676
        mode = !!mode;
 
4677
        value &= 0xF;
 
4678
 
 
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;
 
4685
 
 
4686
        data.blksz = 64;
 
4687
        data.blocks = 1;
 
4688
@@ -302,15 +337,15 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
 
4689
 
 
4690
        sg_init_one(&sg, resp, 64);
 
4691
 
 
4692
-       mmc_set_data_timeout(&data, card, 0);
 
4693
+       mmc_set_data_timeout(&data, card);
 
4694
 
 
4695
        mmc_wait_for_req(card->host, &mrq);
 
4696
 
 
4697
-       if (cmd.error != MMC_ERR_NONE)
 
4698
+       if (cmd.error)
 
4699
                return cmd.error;
 
4700
-       if (data.error != MMC_ERR_NONE)
 
4701
+       if (data.error)
 
4702
                return data.error;
 
4703
 
 
4704
-       return MMC_ERR_NONE;
 
4705
+       return 0;
 
4706
 }
 
4707
 
 
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
 
4712
@@ -1,5 +1,5 @@
 
4713
 /*
 
4714
- *  linux/drivers/mmc/sd_ops.h
 
4715
+ *  linux/drivers/mmc/core/sd_ops.h
 
4716
  *
 
4717
  *  Copyright 2006-2007 Pierre Ossman
 
4718
  *
 
4719
@@ -12,7 +12,6 @@
 
4720
 #ifndef _MMC_SD_OPS_H
 
4721
 #define _MMC_SD_OPS_H
 
4722
 
 
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
 
4730
--- /dev/null
 
4731
+++ b/drivers/mmc/core/sdio.c
 
4732
@@ -0,0 +1,402 @@
 
4733
+/*
 
4734
+ *  linux/drivers/mmc/sdio.c
 
4735
+ *
 
4736
+ *  Copyright 2006-2007 Pierre Ossman
 
4737
+ *
 
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.
 
4742
+ */
 
4743
+
 
4744
+#include <linux/err.h>
 
4745
+
 
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>
 
4750
+
 
4751
+#include "core.h"
 
4752
+#include "bus.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"
 
4758
+
 
4759
+static int sdio_read_fbr(struct sdio_func *func)
 
4760
+{
 
4761
+       int ret;
 
4762
+       unsigned char data;
 
4763
+
 
4764
+       ret = mmc_io_rw_direct(func->card, 0, 0,
 
4765
+               SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF, 0, &data);
 
4766
+       if (ret)
 
4767
+               goto out;
 
4768
+
 
4769
+       data &= 0x0f;
 
4770
+
 
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);
 
4774
+               if (ret)
 
4775
+                       goto out;
 
4776
+       }
 
4777
+
 
4778
+       func->class = data;
 
4779
+
 
4780
+out:
 
4781
+       return ret;
 
4782
+}
 
4783
+
 
4784
+static int sdio_init_func(struct mmc_card *card, unsigned int fn)
 
4785
+{
 
4786
+       int ret;
 
4787
+       struct sdio_func *func;
 
4788
+
 
4789
+       BUG_ON(fn > SDIO_MAX_FUNCS);
 
4790
+
 
4791
+       func = sdio_alloc_func(card);
 
4792
+       if (IS_ERR(func))
 
4793
+               return PTR_ERR(func);
 
4794
+
 
4795
+       func->num = fn;
 
4796
+
 
4797
+       ret = sdio_read_fbr(func);
 
4798
+       if (ret)
 
4799
+               goto fail;
 
4800
+
 
4801
+       ret = sdio_read_func_cis(func);
 
4802
+       if (ret)
 
4803
+               goto fail;
 
4804
+
 
4805
+       card->sdio_func[fn - 1] = func;
 
4806
+
 
4807
+       return 0;
 
4808
+
 
4809
+fail:
 
4810
+       /*
 
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.
 
4813
+        */
 
4814
+       sdio_remove_func(func);
 
4815
+       return ret;
 
4816
+}
 
4817
+
 
4818
+static int sdio_read_cccr(struct mmc_card *card)
 
4819
+{
 
4820
+       int ret;
 
4821
+       int cccr_vsn;
 
4822
+       unsigned char data;
 
4823
+
 
4824
+       memset(&card->cccr, 0, sizeof(struct sdio_cccr));
 
4825
+
 
4826
+       ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CCCR, 0, &data);
 
4827
+       if (ret)
 
4828
+               goto out;
 
4829
+
 
4830
+       cccr_vsn = data & 0x0f;
 
4831
+
 
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);
 
4835
+               return -EINVAL;
 
4836
+       }
 
4837
+
 
4838
+       card->cccr.sdio_vsn = (data & 0xf0) >> 4;
 
4839
+
 
4840
+       ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CAPS, 0, &data);
 
4841
+       if (ret)
 
4842
+               goto out;
 
4843
+
 
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;
 
4850
+
 
4851
+       if (cccr_vsn >= SDIO_CCCR_REV_1_10) {
 
4852
+               ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_POWER, 0, &data);
 
4853
+               if (ret)
 
4854
+                       goto out;
 
4855
+
 
4856
+               if (data & SDIO_POWER_SMPC)
 
4857
+                       card->cccr.high_power = 1;
 
4858
+       }
 
4859
+
 
4860
+       if (cccr_vsn >= SDIO_CCCR_REV_1_20) {
 
4861
+               ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &data);
 
4862
+               if (ret)
 
4863
+                       goto out;
 
4864
+
 
4865
+               if (data & SDIO_SPEED_SHS)
 
4866
+                       card->cccr.high_speed = 1;
 
4867
+       }
 
4868
+
 
4869
+out:
 
4870
+       return ret;
 
4871
+}
 
4872
+
 
4873
+static int sdio_enable_wide(struct mmc_card *card)
 
4874
+{
 
4875
+       int ret;
 
4876
+       u8 ctrl;
 
4877
+
 
4878
+       if (!(card->host->caps & MMC_CAP_4_BIT_DATA))
 
4879
+               return 0;
 
4880
+
 
4881
+       if (card->cccr.low_speed && !card->cccr.wide_bus)
 
4882
+               return 0;
 
4883
+
 
4884
+       ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &ctrl);
 
4885
+       if (ret)
 
4886
+               return ret;
 
4887
+
 
4888
+       ctrl |= SDIO_BUS_WIDTH_4BIT;
 
4889
+
 
4890
+       ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL);
 
4891
+       if (ret)
 
4892
+               return ret;
 
4893
+
 
4894
+       mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
 
4895
+
 
4896
+       return 0;
 
4897
+}
 
4898
+
 
4899
+/*
 
4900
+ * Host is being removed. Free up the current card.
 
4901
+ */
 
4902
+static void mmc_sdio_remove(struct mmc_host *host)
 
4903
+{
 
4904
+       int i;
 
4905
+
 
4906
+       BUG_ON(!host);
 
4907
+       BUG_ON(!host->card);
 
4908
+
 
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;
 
4913
+               }
 
4914
+       }
 
4915
+
 
4916
+       mmc_remove_card(host->card);
 
4917
+       host->card = NULL;
 
4918
+}
 
4919
+
 
4920
+/*
 
4921
+ * Card detection callback from host.
 
4922
+ */
 
4923
+static void mmc_sdio_detect(struct mmc_host *host)
 
4924
+{
 
4925
+       int err;
 
4926
+
 
4927
+       BUG_ON(!host);
 
4928
+       BUG_ON(!host->card);
 
4929
+
 
4930
+       mmc_claim_host(host);
 
4931
+
 
4932
+       /*
 
4933
+        * Just check if our card has been removed.
 
4934
+        */
 
4935
+       err = mmc_select_card(host->card);
 
4936
+
 
4937
+       mmc_release_host(host);
 
4938
+
 
4939
+       if (err) {
 
4940
+               mmc_sdio_remove(host);
 
4941
+
 
4942
+               mmc_claim_host(host);
 
4943
+               mmc_detach_bus(host);
 
4944
+               mmc_release_host(host);
 
4945
+       }
 
4946
+}
 
4947
+
 
4948
+
 
4949
+static const struct mmc_bus_ops mmc_sdio_ops = {
 
4950
+       .remove = mmc_sdio_remove,
 
4951
+       .detect = mmc_sdio_detect,
 
4952
+};
 
4953
+
 
4954
+
 
4955
+/*
 
4956
+ * Starting point for SDIO card init.
 
4957
+ */
 
4958
+int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
 
4959
+{
 
4960
+       int err;
 
4961
+       int i, funcs;
 
4962
+       struct mmc_card *card;
 
4963
+
 
4964
+       BUG_ON(!host);
 
4965
+       WARN_ON(!host->claimed);
 
4966
+
 
4967
+       mmc_attach_bus(host, &mmc_sdio_ops);
 
4968
+
 
4969
+       /*
 
4970
+        * Sanity check the voltages that the card claims to
 
4971
+        * support.
 
4972
+        */
 
4973
+       if (ocr & 0x7F) {
 
4974
+               printk(KERN_WARNING "%s: card claims to support voltages "
 
4975
+                      "below the defined range. These will be ignored.\n",
 
4976
+                      mmc_hostname(host));
 
4977
+               ocr &= ~0x7F;
 
4978
+       }
 
4979
+
 
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;
 
4985
+       }
 
4986
+
 
4987
+        /* force CB/Zi9 controller to work in 3.3V mode, due to HW bug */
 
4988
+        ocr &= 0xe00000;
 
4989
+
 
4990
+       host->ocr = mmc_select_voltage(host, ocr);
 
4991
+
 
4992
+       /*
 
4993
+        * Can we support the voltage(s) of the card(s)?
 
4994
+        */
 
4995
+       if (!host->ocr) {
 
4996
+               err = -EINVAL;
 
4997
+               goto err;
 
4998
+       }
 
4999
+
 
5000
+       umd_dbg("we will use voltage ocr: 0x%08x", host->ocr);
 
5001
+       /*
 
5002
+        * Inform the card of the voltage
 
5003
+        */
 
5004
+       err = mmc_send_io_op_cond(host, host->ocr, &ocr);
 
5005
+       if (err)
 
5006
+               goto err;
 
5007
+
 
5008
+       /*
 
5009
+        * For SPI, enable CRC as appropriate.
 
5010
+        */
 
5011
+       if (mmc_host_is_spi(host)) {
 
5012
+               err = mmc_spi_set_crc(host, use_spi_crc);
 
5013
+               if (err)
 
5014
+                       goto err;
 
5015
+       }
 
5016
+
 
5017
+       /*
 
5018
+        * The number of functions on the card is encoded inside
 
5019
+        * the ocr.
 
5020
+        */
 
5021
+       funcs = (ocr & 0x70000000) >> 28;
 
5022
+
 
5023
+       /*
 
5024
+        * Allocate card structure.
 
5025
+        */
 
5026
+       card = mmc_alloc_card(host);
 
5027
+       if (IS_ERR(card)) {
 
5028
+               err = PTR_ERR(card);
 
5029
+               goto err;
 
5030
+       }
 
5031
+
 
5032
+       card->type = MMC_TYPE_SDIO;
 
5033
+       card->sdio_funcs = funcs;
 
5034
+
 
5035
+       host->card = card;
 
5036
+
 
5037
+       /*
 
5038
+        * For native busses:  set card RCA and quit open drain mode.
 
5039
+        */
 
5040
+       if (!mmc_host_is_spi(host)) {
 
5041
+       err = mmc_send_relative_addr(host, &card->rca);
 
5042
+       if (err)
 
5043
+               goto remove;
 
5044
+
 
5045
+       mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
 
5046
+       }
 
5047
+
 
5048
+       /*
 
5049
+        * Select card, as all following commands rely on that.
 
5050
+        */
 
5051
+       if (!mmc_host_is_spi(host)) {
 
5052
+       err = mmc_select_card(card);
 
5053
+       if (err)
 
5054
+               goto remove;
 
5055
+       }
 
5056
+
 
5057
+       /*
 
5058
+        * Read the common registers.
 
5059
+        */
 
5060
+       err = sdio_read_cccr(card);
 
5061
+       if (err)
 
5062
+               goto remove;
 
5063
+
 
5064
+       /*
 
5065
+        * Read the common CIS tuples.
 
5066
+        */
 
5067
+       err = sdio_read_common_cis(card);
 
5068
+       if (err)
 
5069
+               goto remove;
 
5070
+
 
5071
+       /*
 
5072
+        * No support for high-speed yet, so just set
 
5073
+        * the card's maximum speed.
 
5074
+        */
 
5075
+       mmc_set_clock(host, card->cis.max_dtr);
 
5076
+
 
5077
+       /*
 
5078
+        * Switch to wider bus (if supported).
 
5079
+        */
 
5080
+       err = sdio_enable_wide(card);
 
5081
+       if (err)
 
5082
+               goto remove;
 
5083
+
 
5084
+       /*
 
5085
+        * Initialize (but don't add) all present functions.
 
5086
+        */
 
5087
+       for (i = 0;i < funcs;i++) {
 
5088
+               err = sdio_init_func(host->card, i + 1);
 
5089
+               if (err)
 
5090
+                       goto remove;
 
5091
+       }
 
5092
+
 
5093
+       mmc_release_host(host);
 
5094
+
 
5095
+       /*
 
5096
+        * First add the card to the driver model...
 
5097
+        */
 
5098
+       err = mmc_add_card(host->card);
 
5099
+       if (err)
 
5100
+               goto remove_added;
 
5101
+
 
5102
+       umd_dbg("success in add card");
 
5103
+
 
5104
+       /*
 
5105
+        * ...then the SDIO functions.
 
5106
+        */
 
5107
+       for (i = 0;i < funcs;i++) {
 
5108
+               err = sdio_add_func(host->card->sdio_func[i]);
 
5109
+               if (err)
 
5110
+                       goto remove_added;
 
5111
+       }
 
5112
+       
 
5113
+       umd_dbg("success in add %d functions", funcs);
 
5114
+
 
5115
+       return 0;
 
5116
+
 
5117
+
 
5118
+remove_added:
 
5119
+       /* Remove without lock if the device has been added. */
 
5120
+       mmc_sdio_remove(host);
 
5121
+       mmc_claim_host(host);
 
5122
+remove:
 
5123
+       /* And with lock if it hasn't been added. */
 
5124
+       if (host->card)
 
5125
+               mmc_sdio_remove(host);
 
5126
+err:
 
5127
+       mmc_detach_bus(host);
 
5128
+       mmc_release_host(host);
 
5129
+
 
5130
+       printk(KERN_ERR "%s: error %d whilst initialising SDIO card\n",
 
5131
+               mmc_hostname(host), err);
 
5132
+
 
5133
+       return err;
 
5134
+}
 
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
 
5138
--- /dev/null
 
5139
+++ b/drivers/mmc/core/sdio_bus.c
 
5140
@@ -0,0 +1,271 @@
 
5141
+/*
 
5142
+ *  linux/drivers/mmc/core/sdio_bus.c
 
5143
+ *
 
5144
+ *  Copyright 2007 Pierre Ossman
 
5145
+ *
 
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.
 
5150
+ *
 
5151
+ * SDIO function driver model
 
5152
+ */
 
5153
+
 
5154
+#include <linux/device.h>
 
5155
+#include <linux/err.h>
 
5156
+
 
5157
+#include <linux/mmc/card.h>
 
5158
+#include <linux/mmc/sdio_func.h>
 
5159
+
 
5160
+#include "sdio_cis.h"
 
5161
+#include "sdio_bus.h"
 
5162
+
 
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)
 
5165
+
 
5166
+/* show configuration fields */
 
5167
+#define sdio_config_attr(field, format_string)                         \
 
5168
+static ssize_t                                                         \
 
5169
+field##_show(struct device *dev, struct device_attribute *attr, char *buf)                             \
 
5170
+{                                                                      \
 
5171
+       struct sdio_func *func;                                         \
 
5172
+                                                                       \
 
5173
+       func = dev_to_sdio_func (dev);                                  \
 
5174
+       return sprintf (buf, format_string, func->field);               \
 
5175
+}
 
5176
+
 
5177
+sdio_config_attr(class, "0x%02x\n");
 
5178
+sdio_config_attr(vendor, "0x%04x\n");
 
5179
+sdio_config_attr(device, "0x%04x\n");
 
5180
+
 
5181
+static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
 
5182
+{
 
5183
+       struct sdio_func *func = dev_to_sdio_func (dev);
 
5184
+
 
5185
+       return sprintf(buf, "sdio:c%02Xv%04Xd%04X\n",
 
5186
+                       func->class, func->vendor, func->device);
 
5187
+}
 
5188
+
 
5189
+static struct device_attribute sdio_dev_attrs[] = {
 
5190
+       __ATTR_RO(class),
 
5191
+       __ATTR_RO(vendor),
 
5192
+       __ATTR_RO(device),
 
5193
+       __ATTR_RO(modalias),
 
5194
+       __ATTR_NULL,
 
5195
+};
 
5196
+
 
5197
+static const struct sdio_device_id *sdio_match_one(struct sdio_func *func,
 
5198
+       const struct sdio_device_id *id)
 
5199
+{
 
5200
+       if (id->class != (__u8)SDIO_ANY_ID && id->class != func->class)
 
5201
+               return NULL;
 
5202
+       if (id->vendor != (__u16)SDIO_ANY_ID && id->vendor != func->vendor)
 
5203
+               return NULL;
 
5204
+       if (id->device != (__u16)SDIO_ANY_ID && id->device != func->device)
 
5205
+               return NULL;
 
5206
+       return id;
 
5207
+}
 
5208
+
 
5209
+static const struct sdio_device_id *sdio_match_device(struct sdio_func *func,
 
5210
+       struct sdio_driver *sdrv)
 
5211
+{
 
5212
+       const struct sdio_device_id *ids;
 
5213
+
 
5214
+       ids = sdrv->id_table;
 
5215
+
 
5216
+       if (ids) {
 
5217
+               while (ids->class || ids->vendor || ids->device) {
 
5218
+                       if (sdio_match_one(func, ids))
 
5219
+                               return ids;
 
5220
+                       ids++;
 
5221
+               }
 
5222
+       }
 
5223
+
 
5224
+       return NULL;
 
5225
+}
 
5226
+
 
5227
+static int sdio_bus_match(struct device *dev, struct device_driver *drv)
 
5228
+{
 
5229
+       struct sdio_func *func = dev_to_sdio_func(dev);
 
5230
+       struct sdio_driver *sdrv = to_sdio_driver(drv);
 
5231
+
 
5232
+       if (sdio_match_device(func, sdrv))
 
5233
+               return 1;
 
5234
+
 
5235
+       return 0;
 
5236
+}
 
5237
+
 
5238
+static int
 
5239
+sdio_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
 
5240
+               int buf_size)
 
5241
+{
 
5242
+       struct sdio_func *func = dev_to_sdio_func(dev);
 
5243
+       int i = 0, length = 0;
 
5244
+
 
5245
+       if (add_uevent_var(envp, num_envp, &i,
 
5246
+                       buf, buf_size, &length,
 
5247
+                       "SDIO_CLASS=%02X", func->class))
 
5248
+               return -ENOMEM;
 
5249
+
 
5250
+       if (add_uevent_var(envp, num_envp, &i,
 
5251
+                       buf, buf_size, &length,
 
5252
+                       "SDIO_ID=%04X:%04X", func->vendor, func->device))
 
5253
+               return -ENOMEM;
 
5254
+
 
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))
 
5259
+               return -ENOMEM;
 
5260
+
 
5261
+       envp[i] = NULL;
 
5262
+
 
5263
+       return 0;
 
5264
+}
 
5265
+
 
5266
+static int sdio_bus_probe(struct device *dev)
 
5267
+{
 
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;
 
5271
+       int ret;
 
5272
+
 
5273
+       id = sdio_match_device(func, drv);
 
5274
+       if (!id)
 
5275
+               return -ENODEV;
 
5276
+
 
5277
+       /* Set the default block size so the driver is sure it's something
 
5278
+        * sensible. */
 
5279
+       sdio_claim_host(func);
 
5280
+       ret = sdio_set_block_size(func, 0);
 
5281
+       sdio_release_host(func);
 
5282
+       if (ret)
 
5283
+               return ret;
 
5284
+
 
5285
+       return drv->probe(func, id);
 
5286
+}
 
5287
+
 
5288
+static int sdio_bus_remove(struct device *dev)
 
5289
+{
 
5290
+       struct sdio_driver *drv = to_sdio_driver(dev->driver);
 
5291
+       struct sdio_func *func = dev_to_sdio_func(dev);
 
5292
+
 
5293
+       drv->remove(func);
 
5294
+
 
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);
 
5301
+       }
 
5302
+
 
5303
+       return 0;
 
5304
+}
 
5305
+
 
5306
+static struct bus_type sdio_bus_type = {
 
5307
+       .name           = "sdio",
 
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,
 
5313
+};
 
5314
+
 
5315
+int sdio_register_bus(void)
 
5316
+{
 
5317
+       return bus_register(&sdio_bus_type);
 
5318
+}
 
5319
+
 
5320
+void sdio_unregister_bus(void)
 
5321
+{
 
5322
+       bus_unregister(&sdio_bus_type);
 
5323
+}
 
5324
+
 
5325
+/**
 
5326
+ *     sdio_register_driver - register a function driver
 
5327
+ *     @drv: SDIO function driver
 
5328
+ */
 
5329
+int sdio_register_driver(struct sdio_driver *drv)
 
5330
+{
 
5331
+       drv->drv.name = drv->name;
 
5332
+       drv->drv.bus = &sdio_bus_type;
 
5333
+       return driver_register(&drv->drv);
 
5334
+}
 
5335
+
 
5336
+EXPORT_SYMBOL_GPL(sdio_register_driver);
 
5337
+
 
5338
+/**
 
5339
+ *     sdio_unregister_driver - unregister a function driver
 
5340
+ *     @drv: SDIO function driver
 
5341
+ */
 
5342
+void sdio_unregister_driver(struct sdio_driver *drv)
 
5343
+{
 
5344
+       drv->drv.bus = &sdio_bus_type;
 
5345
+       driver_unregister(&drv->drv);
 
5346
+}
 
5347
+
 
5348
+EXPORT_SYMBOL_GPL(sdio_unregister_driver);
 
5349
+
 
5350
+static void sdio_release_func(struct device *dev)
 
5351
+{
 
5352
+       struct sdio_func *func = dev_to_sdio_func(dev);
 
5353
+
 
5354
+       sdio_free_func_cis(func);
 
5355
+
 
5356
+       if (func->info)
 
5357
+               kfree(func->info);
 
5358
+
 
5359
+       kfree(func);
 
5360
+}
 
5361
+
 
5362
+/*
 
5363
+ * Allocate and initialise a new SDIO function structure.
 
5364
+ */
 
5365
+struct sdio_func *sdio_alloc_func(struct mmc_card *card)
 
5366
+{
 
5367
+       struct sdio_func *func;
 
5368
+
 
5369
+       func = kzalloc(sizeof(struct sdio_func), GFP_KERNEL);
 
5370
+       if (!func)
 
5371
+               return ERR_PTR(-ENOMEM);
 
5372
+
 
5373
+       func->card = card;
 
5374
+
 
5375
+       device_initialize(&func->dev);
 
5376
+
 
5377
+       func->dev.parent = &card->dev;
 
5378
+       func->dev.bus = &sdio_bus_type;
 
5379
+       func->dev.release = sdio_release_func;
 
5380
+
 
5381
+       return func;
 
5382
+}
 
5383
+
 
5384
+/*
 
5385
+ * Register a new SDIO function with the driver model.
 
5386
+ */
 
5387
+int sdio_add_func(struct sdio_func *func)
 
5388
+{
 
5389
+       int ret;
 
5390
+
 
5391
+       snprintf(func->dev.bus_id, sizeof(func->dev.bus_id),
 
5392
+                "%s:%d", mmc_card_id(func->card), func->num);
 
5393
+
 
5394
+       ret = device_add(&func->dev);
 
5395
+       if (ret == 0)
 
5396
+               sdio_func_set_present(func);
 
5397
+
 
5398
+       return ret;
 
5399
+}
 
5400
+
 
5401
+/*
 
5402
+ * Unregister a SDIO function with the driver model, and
 
5403
+ * (eventually) free it.
 
5404
+ */
 
5405
+void sdio_remove_func(struct sdio_func *func)
 
5406
+{
 
5407
+       if (sdio_func_present(func))
 
5408
+               device_del(&func->dev);
 
5409
+
 
5410
+       put_device(&func->dev);
 
5411
+}
 
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
 
5415
--- /dev/null
 
5416
+++ b/drivers/mmc/core/sdio_bus.h
 
5417
@@ -0,0 +1,21 @@
 
5418
+/*
 
5419
+ *  linux/drivers/mmc/core/sdio_bus.h
 
5420
+ *
 
5421
+ *  Copyright 2007 Pierre Ossman
 
5422
+ *
 
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.
 
5427
+ */
 
5428
+#ifndef _MMC_CORE_SDIO_BUS_H
 
5429
+#define _MMC_CORE_SDIO_BUS_H
 
5430
+
 
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);
 
5434
+
 
5435
+int sdio_register_bus(void);
 
5436
+void sdio_unregister_bus(void);
 
5437
+
 
5438
+#endif
 
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
 
5442
--- /dev/null
 
5443
+++ b/drivers/mmc/core/sdio_cis.c
 
5444
@@ -0,0 +1,348 @@
 
5445
+/*
 
5446
+ * linux/drivers/mmc/core/sdio_cis.c
 
5447
+ *
 
5448
+ * Author:     Nicolas Pitre
 
5449
+ * Created:    June 11, 2007
 
5450
+ * Copyright:  MontaVista Software Inc.
 
5451
+ *
 
5452
+ * Copyright 2007 Pierre Ossman
 
5453
+ *
 
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.
 
5458
+ */
 
5459
+
 
5460
+#include <linux/kernel.h>
 
5461
+
 
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>
 
5466
+
 
5467
+#include "sdio_cis.h"
 
5468
+#include "sdio_ops.h"
 
5469
+
 
5470
+static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func,
 
5471
+                        const unsigned char *buf, unsigned size)
 
5472
+{
 
5473
+       unsigned i, nr_strings;
 
5474
+       char **buffer, *string;
 
5475
+
 
5476
+       buf += 2;
 
5477
+       size -= 2;
 
5478
+
 
5479
+       nr_strings = 0;
 
5480
+       for (i = 0; i < size; i++) {
 
5481
+               if (buf[i] == 0xff)
 
5482
+                       break;
 
5483
+               if (buf[i] == 0)
 
5484
+                       nr_strings++;
 
5485
+       }
 
5486
+
 
5487
+       if (buf[i-1] != '\0') {
 
5488
+               printk(KERN_WARNING "SDIO: ignoring broken CISTPL_VERS_1\n");
 
5489
+               return 0;
 
5490
+       }
 
5491
+
 
5492
+       size = i;
 
5493
+
 
5494
+       buffer = kzalloc(sizeof(char*) * nr_strings + size, GFP_KERNEL);
 
5495
+       if (!buffer)
 
5496
+               return -ENOMEM;
 
5497
+
 
5498
+       string = (char*)(buffer + nr_strings);
 
5499
+
 
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;
 
5505
+       }
 
5506
+
 
5507
+       if (func) {
 
5508
+               func->num_info = nr_strings;
 
5509
+               func->info = (const char**)buffer;
 
5510
+       } else {
 
5511
+               card->num_info = nr_strings;
 
5512
+               card->info = (const char**)buffer;
 
5513
+       }
 
5514
+
 
5515
+       return 0;
 
5516
+}
 
5517
+
 
5518
+static int cistpl_manfid(struct mmc_card *card, struct sdio_func *func,
 
5519
+                        const unsigned char *buf, unsigned size)
 
5520
+{
 
5521
+       unsigned int vendor, device;
 
5522
+
 
5523
+       /* TPLMID_MANF */
 
5524
+       vendor = buf[0] | (buf[1] << 8);
 
5525
+
 
5526
+       /* TPLMID_CARD */
 
5527
+       device = buf[2] | (buf[3] << 8);
 
5528
+
 
5529
+       if (func) {
 
5530
+               func->vendor = vendor;
 
5531
+               func->device = device;
 
5532
+       } else {
 
5533
+               card->cis.vendor = vendor;
 
5534
+               card->cis.device = device;
 
5535
+       }
 
5536
+
 
5537
+       return 0;
 
5538
+}
 
5539
+
 
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 };
 
5544
+
 
5545
+static int cistpl_funce_common(struct mmc_card *card,
 
5546
+                              const unsigned char *buf, unsigned size)
 
5547
+{
 
5548
+       if (size < 0x04 || buf[0] != 0)
 
5549
+               return -EINVAL;
 
5550
+
 
5551
+       /* TPLFE_FN0_BLK_SIZE */
 
5552
+       card->cis.blksize = buf[1] | (buf[2] << 8);
 
5553
+
 
5554
+       /* TPLFE_MAX_TRAN_SPEED */
 
5555
+       card->cis.max_dtr = speed_val[(buf[3] >> 3) & 15] *
 
5556
+                           speed_unit[buf[3] & 7];
 
5557
+
 
5558
+       return 0;
 
5559
+}
 
5560
+
 
5561
+static int cistpl_funce_func(struct sdio_func *func,
 
5562
+                            const unsigned char *buf, unsigned size)
 
5563
+{
 
5564
+       unsigned vsn;
 
5565
+       unsigned min_size;
 
5566
+
 
5567
+       vsn = func->card->cccr.sdio_vsn;
 
5568
+       min_size = (vsn == SDIO_SDIO_REV_1_00) ? 28 : 42;
 
5569
+
 
5570
+       if (size < min_size || buf[0] != 1)
 
5571
+               return -EINVAL;
 
5572
+
 
5573
+       /* TPLFE_MAX_BLK_SIZE */
 
5574
+       func->max_blksize = buf[12] | (buf[13] << 8);
 
5575
+
 
5576
+       return 0;
 
5577
+}
 
5578
+
 
5579
+static int cistpl_funce(struct mmc_card *card, struct sdio_func *func,
 
5580
+                       const unsigned char *buf, unsigned size)
 
5581
+{
 
5582
+       int ret;
 
5583
+
 
5584
+       /*
 
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.
 
5589
+        */
 
5590
+       if (func)
 
5591
+               ret = cistpl_funce_func(func, buf, size);
 
5592
+       else
 
5593
+               ret = cistpl_funce_common(card, buf, size);
 
5594
+
 
5595
+       if (ret) {
 
5596
+               printk(KERN_ERR "%s: bad CISTPL_FUNCE size %u "
 
5597
+                      "type %u\n", mmc_hostname(card->host),
 
5598
+                      size, buf[0]);
 
5599
+               /* masked by feng for 8688 + CB debug . */
 
5600
+               /* return ret; */
 
5601
+       }
 
5602
+
 
5603
+       return 0;
 
5604
+}
 
5605
+
 
5606
+typedef int (tpl_parse_t)(struct mmc_card *, struct sdio_func *,
 
5607
+                          const unsigned char *, unsigned);
 
5608
+
 
5609
+struct cis_tpl {
 
5610
+       unsigned char code;
 
5611
+       unsigned char min_size;
 
5612
+       tpl_parse_t *parse;
 
5613
+};
 
5614
+
 
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    },
 
5620
+};
 
5621
+
 
5622
+static int sdio_read_cis(struct mmc_card *card, struct sdio_func *func)
 
5623
+{
 
5624
+       int ret;
 
5625
+       struct sdio_func_tuple *this, **prev;
 
5626
+       unsigned i, ptr = 0;
 
5627
+
 
5628
+       /*
 
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.
 
5632
+        */
 
5633
+       for (i = 0; i < 3; i++) {
 
5634
+               unsigned char x, fn;
 
5635
+
 
5636
+               if (func)
 
5637
+                       fn = func->num;
 
5638
+               else
 
5639
+                       fn = 0;
 
5640
+
 
5641
+               ret = mmc_io_rw_direct(card, 0, 0,
 
5642
+                       SDIO_FBR_BASE(fn) + SDIO_FBR_CIS + i, 0, &x);
 
5643
+               if (ret)
 
5644
+                       return ret;
 
5645
+               ptr |= x << (i * 8);
 
5646
+       }
 
5647
+
 
5648
+       if (func)
 
5649
+               prev = &func->tuples;
 
5650
+       else
 
5651
+               prev = &card->tuples;
 
5652
+
 
5653
+       BUG_ON(*prev);
 
5654
+
 
5655
+       do {
 
5656
+               unsigned char tpl_code, tpl_link;
 
5657
+
 
5658
+               ret = mmc_io_rw_direct(card, 0, 0, ptr++, 0, &tpl_code);
 
5659
+               if (ret)
 
5660
+                       break;
 
5661
+
 
5662
+               /* 0xff means we're done */
 
5663
+               if (tpl_code == 0xff)
 
5664
+                       break;
 
5665
+
 
5666
+               ret = mmc_io_rw_direct(card, 0, 0, ptr++, 0, &tpl_link);
 
5667
+               if (ret)
 
5668
+                       break;
 
5669
+
 
5670
+               this = kmalloc(sizeof(*this) + tpl_link, GFP_KERNEL);
 
5671
+               if (!this)
 
5672
+                       return -ENOMEM;
 
5673
+
 
5674
+               for (i = 0; i < tpl_link; i++) {
 
5675
+                       ret = mmc_io_rw_direct(card, 0, 0,
 
5676
+                                              ptr + i, 0, &this->data[i]);
 
5677
+                       if (ret)
 
5678
+                               break;
 
5679
+               }
 
5680
+               if (ret) {
 
5681
+                       kfree(this);
 
5682
+                       break;
 
5683
+               }
 
5684
+
 
5685
+               for (i = 0; i < ARRAY_SIZE(cis_tpl_list); i++)
 
5686
+                       if (cis_tpl_list[i].code == tpl_code)
 
5687
+                               break;
 
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;
 
5693
+                       *prev = this;
 
5694
+                       prev = &this->next;
 
5695
+                       printk(KERN_DEBUG
 
5696
+                              "%s: queuing CIS tuple 0x%02x length %u\n",
 
5697
+                              mmc_hostname(card->host), tpl_code, tpl_link);
 
5698
+               } else {
 
5699
+                       const struct cis_tpl *tpl = cis_tpl_list + i;
 
5700
+                       if (tpl_link < tpl->min_size) {
 
5701
+                               printk(KERN_ERR
 
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);
 
5705
+                               ret = -EINVAL;
 
5706
+                       } else if (tpl->parse) {
 
5707
+                               ret = tpl->parse(card, func,
 
5708
+                                                this->data, tpl_link);
 
5709
+                       }
 
5710
+                       kfree(this);
 
5711
+               }
 
5712
+
 
5713
+               ptr += tpl_link;
 
5714
+       } while (!ret);
 
5715
+
 
5716
+       /*
 
5717
+        * Link in all unknown tuples found in the common CIS so that
 
5718
+        * drivers don't have to go digging in two places.
 
5719
+        */
 
5720
+       if (func)
 
5721
+               *prev = card->tuples;
 
5722
+
 
5723
+       return ret;
 
5724
+}
 
5725
+
 
5726
+int sdio_read_common_cis(struct mmc_card *card)
 
5727
+{
 
5728
+       return sdio_read_cis(card, NULL);
 
5729
+}
 
5730
+
 
5731
+void sdio_free_common_cis(struct mmc_card *card)
 
5732
+{
 
5733
+       struct sdio_func_tuple *tuple, *victim;
 
5734
+
 
5735
+       tuple = card->tuples;
 
5736
+
 
5737
+       while (tuple) {
 
5738
+               victim = tuple;
 
5739
+               tuple = tuple->next;
 
5740
+               kfree(victim);
 
5741
+       }
 
5742
+
 
5743
+       card->tuples = NULL;
 
5744
+}
 
5745
+
 
5746
+int sdio_read_func_cis(struct sdio_func *func)
 
5747
+{
 
5748
+       int ret;
 
5749
+
 
5750
+       ret = sdio_read_cis(func->card, func);
 
5751
+       if (ret)
 
5752
+               return ret;
 
5753
+
 
5754
+       /*
 
5755
+        * Since we've linked to tuples in the card structure,
 
5756
+        * we must make sure we have a reference to it.
 
5757
+        */
 
5758
+       get_device(&func->card->dev);
 
5759
+
 
5760
+       /*
 
5761
+        * Vendor/device id is optional for function CIS, so
 
5762
+        * copy it from the card structure as needed.
 
5763
+        */
 
5764
+       if (func->vendor == 0) {
 
5765
+               func->vendor = func->card->cis.vendor;
 
5766
+               func->device = func->card->cis.device;
 
5767
+       }
 
5768
+
 
5769
+       return 0;
 
5770
+}
 
5771
+
 
5772
+void sdio_free_func_cis(struct sdio_func *func)
 
5773
+{
 
5774
+       struct sdio_func_tuple *tuple, *victim;
 
5775
+
 
5776
+       tuple = func->tuples;
 
5777
+
 
5778
+       while (tuple && tuple != func->card->tuples) {
 
5779
+               victim = tuple;
 
5780
+               tuple = tuple->next;
 
5781
+               kfree(victim);
 
5782
+       }
 
5783
+
 
5784
+       func->tuples = NULL;
 
5785
+
 
5786
+       /*
 
5787
+        * We have now removed the link to the tuples in the
 
5788
+        * card structure, so remove the reference.
 
5789
+        */
 
5790
+       put_device(&func->card->dev);
 
5791
+}
 
5792
+
 
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
 
5796
--- /dev/null
 
5797
+++ b/drivers/mmc/core/sdio_cis.h
 
5798
@@ -0,0 +1,23 @@
 
5799
+/*
 
5800
+ * linux/drivers/mmc/core/sdio_cis.h
 
5801
+ *
 
5802
+ * Author:     Nicolas Pitre
 
5803
+ * Created:    June 11, 2007
 
5804
+ * Copyright:  MontaVista Software Inc.
 
5805
+ *
 
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.
 
5810
+ */
 
5811
+
 
5812
+#ifndef _MMC_SDIO_CIS_H
 
5813
+#define _MMC_SDIO_CIS_H
 
5814
+
 
5815
+int sdio_read_common_cis(struct mmc_card *card);
 
5816
+void sdio_free_common_cis(struct mmc_card *card);
 
5817
+
 
5818
+int sdio_read_func_cis(struct sdio_func *func);
 
5819
+void sdio_free_func_cis(struct sdio_func *func);
 
5820
+
 
5821
+#endif
 
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
 
5825
--- /dev/null
 
5826
+++ b/drivers/mmc/core/sdio_io.c
 
5827
@@ -0,0 +1,617 @@
 
5828
+/*
 
5829
+ *  linux/drivers/mmc/core/sdio_io.c
 
5830
+ *
 
5831
+ *  Copyright 2007 Pierre Ossman
 
5832
+ *
 
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.
 
5837
+ */
 
5838
+
 
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>
 
5843
+
 
5844
+#include "sdio_ops.h"
 
5845
+
 
5846
+/**
 
5847
+ *     sdio_claim_host - exclusively claim a bus for a certain SDIO function
 
5848
+ *     @func: SDIO function that will be accessed
 
5849
+ *
 
5850
+ *     Claim a bus for a set of operations. The SDIO function given
 
5851
+ *     is used to figure out which bus is relevant.
 
5852
+ */
 
5853
+void sdio_claim_host(struct sdio_func *func)
 
5854
+{
 
5855
+       BUG_ON(!func);
 
5856
+       BUG_ON(!func->card);
 
5857
+
 
5858
+       mmc_claim_host(func->card->host);
 
5859
+}
 
5860
+EXPORT_SYMBOL_GPL(sdio_claim_host);
 
5861
+
 
5862
+/**
 
5863
+ *     sdio_release_host - release a bus for a certain SDIO function
 
5864
+ *     @func: SDIO function that was accessed
 
5865
+ *
 
5866
+ *     Release a bus, allowing others to claim the bus for their
 
5867
+ *     operations.
 
5868
+ */
 
5869
+void sdio_release_host(struct sdio_func *func)
 
5870
+{
 
5871
+       BUG_ON(!func);
 
5872
+       BUG_ON(!func->card);
 
5873
+
 
5874
+       mmc_release_host(func->card->host);
 
5875
+}
 
5876
+EXPORT_SYMBOL_GPL(sdio_release_host);
 
5877
+
 
5878
+/**
 
5879
+ *     sdio_enable_func - enables a SDIO function for usage
 
5880
+ *     @func: SDIO function to enable
 
5881
+ *
 
5882
+ *     Powers up and activates a SDIO function so that register
 
5883
+ *     access is possible.
 
5884
+ */
 
5885
+int sdio_enable_func(struct sdio_func *func)
 
5886
+{
 
5887
+       int ret;
 
5888
+       unsigned char reg;
 
5889
+       unsigned long timeout;
 
5890
+
 
5891
+       BUG_ON(!func);
 
5892
+       BUG_ON(!func->card);
 
5893
+
 
5894
+       pr_debug("SDIO: Enabling device %s...\n", sdio_func_id(func));
 
5895
+
 
5896
+       ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg);
 
5897
+       if (ret)
 
5898
+               goto err;
 
5899
+
 
5900
+       reg |= 1 << func->num;
 
5901
+
 
5902
+       ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
 
5903
+       if (ret)
 
5904
+               goto err;
 
5905
+
 
5906
+       /*
 
5907
+        * FIXME: This should timeout based on information in the CIS,
 
5908
+        * but we don't have card to parse that yet.
 
5909
+        */
 
5910
+       timeout = jiffies + HZ;
 
5911
+
 
5912
+       while (1) {
 
5913
+               ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, &reg);
 
5914
+               if (ret)
 
5915
+                       goto err;
 
5916
+               if (reg & (1 << func->num))
 
5917
+                       break;
 
5918
+               ret = -ETIME;
 
5919
+               if (time_after(jiffies, timeout))
 
5920
+                       goto err;
 
5921
+       }
 
5922
+
 
5923
+       pr_debug("SDIO: Enabled device %s\n", sdio_func_id(func));
 
5924
+
 
5925
+       return 0;
 
5926
+
 
5927
+err:
 
5928
+       pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func));
 
5929
+       return ret;
 
5930
+}
 
5931
+EXPORT_SYMBOL_GPL(sdio_enable_func);
 
5932
+
 
5933
+/**
 
5934
+ *     sdio_disable_func - disable a SDIO function
 
5935
+ *     @func: SDIO function to disable
 
5936
+ *
 
5937
+ *     Powers down and deactivates a SDIO function. Register access
 
5938
+ *     to this function will fail until the function is reenabled.
 
5939
+ */
 
5940
+int sdio_disable_func(struct sdio_func *func)
 
5941
+{
 
5942
+       int ret;
 
5943
+       unsigned char reg;
 
5944
+
 
5945
+       BUG_ON(!func);
 
5946
+       BUG_ON(!func->card);
 
5947
+
 
5948
+       pr_debug("SDIO: Disabling device %s...\n", sdio_func_id(func));
 
5949
+
 
5950
+       ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg);
 
5951
+       if (ret)
 
5952
+               goto err;
 
5953
+
 
5954
+       reg &= ~(1 << func->num);
 
5955
+
 
5956
+       ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
 
5957
+       if (ret)
 
5958
+               goto err;
 
5959
+
 
5960
+       pr_debug("SDIO: Disabled device %s\n", sdio_func_id(func));
 
5961
+
 
5962
+       return 0;
 
5963
+
 
5964
+err:
 
5965
+       pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func));
 
5966
+       return -EIO;
 
5967
+}
 
5968
+EXPORT_SYMBOL_GPL(sdio_disable_func);
 
5969
+
 
5970
+/**
 
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.
 
5974
+ *
 
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.
 
5978
+ *
 
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.
 
5983
+ *
 
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.
 
5987
+ *
 
5988
+ */
 
5989
+int sdio_set_block_size(struct sdio_func *func, unsigned blksz)
 
5990
+{
 
5991
+       int ret;
 
5992
+
 
5993
+       if (blksz > func->card->host->max_blk_size)
 
5994
+               return -EINVAL;
 
5995
+
 
5996
+       if (blksz == 0) {
 
5997
+               blksz = min(min(
 
5998
+                       func->max_blksize,
 
5999
+                       func->card->host->max_blk_size),
 
6000
+                       512u);
 
6001
+       }
 
6002
+
 
6003
+       ret = mmc_io_rw_direct(func->card, 1, 0,
 
6004
+               SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE,
 
6005
+               blksz & 0xff, NULL);
 
6006
+       if (ret)
 
6007
+               return ret;
 
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);
 
6011
+       if (ret)
 
6012
+               return ret;
 
6013
+       func->cur_blksize = blksz;
 
6014
+       return 0;
 
6015
+}
 
6016
+
 
6017
+EXPORT_SYMBOL_GPL(sdio_set_block_size);
 
6018
+
 
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)
 
6023
+{
 
6024
+       unsigned remainder = size;
 
6025
+       unsigned max_blocks;
 
6026
+       int ret;
 
6027
+
 
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),
 
6036
+                       511u);
 
6037
+
 
6038
+               while (remainder > func->cur_blksize) {
 
6039
+                       unsigned blocks;
 
6040
+
 
6041
+                       blocks = remainder / func->cur_blksize;
 
6042
+                       if (blocks > max_blocks)
 
6043
+                               blocks = max_blocks;
 
6044
+                       size = blocks * func->cur_blksize;
 
6045
+
 
6046
+                       ret = mmc_io_rw_extended(func->card, write,
 
6047
+                               func->num, addr, incr_addr, buf,
 
6048
+                               blocks, func->cur_blksize);
 
6049
+                       if (ret)
 
6050
+                               return ret;
 
6051
+
 
6052
+                       remainder -= size;
 
6053
+                       buf += size;
 
6054
+                       if (incr_addr)
 
6055
+                               addr += size;
 
6056
+               }
 
6057
+       }
 
6058
+
 
6059
+       /* Write the remainder using byte mode. */
 
6060
+       while (remainder > 0) {
 
6061
+               size = remainder;
 
6062
+               if (size > func->cur_blksize)
 
6063
+                       size = func->cur_blksize;
 
6064
+               if (size > 512)
 
6065
+                       size = 512; /* maximum size for byte mode */
 
6066
+
 
6067
+               ret = mmc_io_rw_extended(func->card, write, func->num, addr,
 
6068
+                        incr_addr, buf, 1, size);
 
6069
+               if (ret)
 
6070
+                       return ret;
 
6071
+
 
6072
+               remainder -= size;
 
6073
+               buf += size;
 
6074
+               if (incr_addr)
 
6075
+                       addr += size;
 
6076
+       }
 
6077
+       return 0;
 
6078
+}
 
6079
+
 
6080
+/**
 
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
 
6085
+ *
 
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.
 
6089
+ */
 
6090
+unsigned char sdio_readb(struct sdio_func *func, unsigned int addr,
 
6091
+       int *err_ret)
 
6092
+{
 
6093
+       int ret;
 
6094
+       unsigned char val;
 
6095
+
 
6096
+       BUG_ON(!func);
 
6097
+
 
6098
+       if (err_ret)
 
6099
+               *err_ret = 0;
 
6100
+
 
6101
+       ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val);
 
6102
+       if (ret) {
 
6103
+               if (err_ret)
 
6104
+                       *err_ret = ret;
 
6105
+               return 0xFF;
 
6106
+       }
 
6107
+
 
6108
+       return val;
 
6109
+}
 
6110
+EXPORT_SYMBOL_GPL(sdio_readb);
 
6111
+
 
6112
+/**
 
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
 
6118
+ *
 
6119
+ *     Writes a single byte to the address space of a given SDIO
 
6120
+ *     function. @err_ret will contain the status of the actual
 
6121
+ *     transfer.
 
6122
+ */
 
6123
+void sdio_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
 
6124
+       int *err_ret)
 
6125
+{
 
6126
+       int ret;
 
6127
+
 
6128
+       BUG_ON(!func);
 
6129
+
 
6130
+       ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL);
 
6131
+       if (err_ret)
 
6132
+               *err_ret = ret;
 
6133
+}
 
6134
+EXPORT_SYMBOL_GPL(sdio_writeb);
 
6135
+
 
6136
+/**
 
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
 
6142
+ *
 
6143
+ *     Reads from the address space of a given SDIO function. Return
 
6144
+ *     value indicates if the transfer succeeded or not.
 
6145
+ */
 
6146
+int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
 
6147
+       unsigned int addr, int count)
 
6148
+{
 
6149
+       return sdio_io_rw_ext_helper(func, 0, addr, 1, dst, count);
 
6150
+}
 
6151
+EXPORT_SYMBOL_GPL(sdio_memcpy_fromio);
 
6152
+
 
6153
+/**
 
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
 
6159
+ *
 
6160
+ *     Writes to the address space of a given SDIO function. Return
 
6161
+ *     value indicates if the transfer succeeded or not.
 
6162
+ */
 
6163
+int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
 
6164
+       void *src, int count)
 
6165
+{
 
6166
+       return sdio_io_rw_ext_helper(func, 1, addr, 1, src, count);
 
6167
+}
 
6168
+EXPORT_SYMBOL_GPL(sdio_memcpy_toio);
 
6169
+
 
6170
+/**
 
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
 
6176
+ *
 
6177
+ *     Reads from the specified FIFO of a given SDIO function. Return
 
6178
+ *     value indicates if the transfer succeeded or not.
 
6179
+ */
 
6180
+int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr,
 
6181
+       int count)
 
6182
+{
 
6183
+       return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count);
 
6184
+}
 
6185
+
 
6186
+EXPORT_SYMBOL_GPL(sdio_readsb);
 
6187
+
 
6188
+/**
 
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
 
6194
+ *
 
6195
+ *     Writes to the specified FIFO of a given SDIO function. Return
 
6196
+ *     value indicates if the transfer succeeded or not.
 
6197
+ */
 
6198
+int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src,
 
6199
+       int count)
 
6200
+{
 
6201
+       return sdio_io_rw_ext_helper(func, 1, addr, 0, src, count);
 
6202
+}
 
6203
+EXPORT_SYMBOL_GPL(sdio_writesb);
 
6204
+
 
6205
+/**
 
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
 
6210
+ *
 
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.
 
6214
+ */
 
6215
+unsigned short sdio_readw(struct sdio_func *func, unsigned int addr,
 
6216
+       int *err_ret)
 
6217
+{
 
6218
+       int ret;
 
6219
+
 
6220
+       if (err_ret)
 
6221
+               *err_ret = 0;
 
6222
+
 
6223
+       ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 2);
 
6224
+       if (ret) {
 
6225
+               if (err_ret)
 
6226
+                       *err_ret = ret;
 
6227
+               return 0xFFFF;
 
6228
+       }
 
6229
+
 
6230
+       return le16_to_cpu(*(u16*)func->tmpbuf);
 
6231
+}
 
6232
+EXPORT_SYMBOL_GPL(sdio_readw);
 
6233
+
 
6234
+/**
 
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
 
6240
+ *
 
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
 
6243
+ *     transfer.
 
6244
+ */
 
6245
+void sdio_writew(struct sdio_func *func, unsigned short b, unsigned int addr,
 
6246
+       int *err_ret)
 
6247
+{
 
6248
+       int ret;
 
6249
+
 
6250
+       *(u16*)func->tmpbuf = cpu_to_le16(b);
 
6251
+
 
6252
+       ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2);
 
6253
+       if (err_ret)
 
6254
+               *err_ret = ret;
 
6255
+}
 
6256
+EXPORT_SYMBOL_GPL(sdio_writew);
 
6257
+
 
6258
+/**
 
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
 
6263
+ *
 
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
 
6267
+ *     code.
 
6268
+ */
 
6269
+unsigned long sdio_readl(struct sdio_func *func, unsigned int addr,
 
6270
+       int *err_ret)
 
6271
+{
 
6272
+       int ret;
 
6273
+
 
6274
+       if (err_ret)
 
6275
+               *err_ret = 0;
 
6276
+
 
6277
+       ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 4);
 
6278
+       if (ret) {
 
6279
+               if (err_ret)
 
6280
+                       *err_ret = ret;
 
6281
+               return 0xFFFFFFFF;
 
6282
+       }
 
6283
+
 
6284
+       return le32_to_cpu(*(u32*)func->tmpbuf);
 
6285
+}
 
6286
+EXPORT_SYMBOL_GPL(sdio_readl);
 
6287
+
 
6288
+/**
 
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
 
6294
+ *
 
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
 
6297
+ *     transfer.
 
6298
+ */
 
6299
+void sdio_writel(struct sdio_func *func, unsigned long b, unsigned int addr,
 
6300
+       int *err_ret)
 
6301
+{
 
6302
+       int ret;
 
6303
+
 
6304
+       *(u32*)func->tmpbuf = cpu_to_le32(b);
 
6305
+
 
6306
+       ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4);
 
6307
+       if (err_ret)
 
6308
+               *err_ret = ret;
 
6309
+}
 
6310
+EXPORT_SYMBOL_GPL(sdio_writel);
 
6311
+
 
6312
+/**
 
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
 
6317
+ *
 
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.
 
6321
+ */
 
6322
+unsigned char sdio_f0_readb(struct sdio_func *func, unsigned int addr,
 
6323
+       int *err_ret)
 
6324
+{
 
6325
+       int ret;
 
6326
+       unsigned char val;
 
6327
+
 
6328
+       BUG_ON(!func);
 
6329
+
 
6330
+       if (err_ret)
 
6331
+               *err_ret = 0;
 
6332
+
 
6333
+       ret = mmc_io_rw_direct(func->card, 0, 0, addr, 0, &val);
 
6334
+       if (ret) {
 
6335
+               if (err_ret)
 
6336
+                       *err_ret = ret;
 
6337
+               return 0xFF;
 
6338
+       }
 
6339
+
 
6340
+       return val;
 
6341
+}
 
6342
+EXPORT_SYMBOL_GPL(sdio_f0_readb);
 
6343
+
 
6344
+/**
 
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
 
6350
+ *
 
6351
+ *     Writes a single byte to the address space of SDIO function 0.
 
6352
+ *     @err_ret will contain the status of the actual transfer.
 
6353
+ *
 
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.
 
6357
+ */
 
6358
+void sdio_f0_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
 
6359
+       int *err_ret)
 
6360
+{
 
6361
+       int ret;
 
6362
+
 
6363
+       BUG_ON(!func);
 
6364
+
 
6365
+       if (addr < 0xF0 || addr > 0xFF) {
 
6366
+               if (err_ret)
 
6367
+                       *err_ret = -EINVAL;
 
6368
+               return;
 
6369
+       }
 
6370
+
 
6371
+       ret = mmc_io_rw_direct(func->card, 1, 0, addr, b, NULL);
 
6372
+       if (err_ret)
 
6373
+               *err_ret = ret;
 
6374
+}
 
6375
+EXPORT_SYMBOL_GPL(sdio_f0_writeb);
 
6376
+
 
6377
+static char* sdio_version[4] = {
 
6378
+        "version 1.00",
 
6379
+        "version 1.10",
 
6380
+        "version 1.20",
 
6381
+        "version 2.00"
 
6382
+};
 
6383
+
 
6384
+static char* sd_phy_version[4] = {
 
6385
+        "version 1.01",
 
6386
+        "version 1.10",
 
6387
+        "version 2.00"
 
6388
+};
 
6389
+
 
6390
+void sdio_dump_cccr(struct sdio_func *func)
 
6391
+{
 
6392
+        struct mmc_card *card = func->card;
 
6393
+        u8       data, val;
 
6394
+        u8      *str;
 
6395
+        int      i;
 
6396
+
 
6397
+        printk(KERN_INFO "\nStart to dump SDIO CCCR registers:\n");
 
6398
+
 
6399
+        /* dump sdio version */
 
6400
+        mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CCCR, 0, &data);
 
6401
+        val = (data >> 4) & 0xf;
 
6402
+        if (val <= 3)
 
6403
+                printk(KERN_INFO "SDIO Spec: %s\n", sdio_version[val]);
 
6404
+        else
 
6405
+                printk(KERN_INFO "This card doesn't comply with any SDIO spec version!!\n");
 
6406
+                
 
6407
+        /* dump sd PHY version */
 
6408
+        mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SD, 0, &data);
 
6409
+        val = data & 0xf;
 
6410
+        if (val <= 2)
 
6411
+                printk(KERN_INFO "SD PHY spec: %s\n", sd_phy_version[val]);
 
6412
+        else
 
6413
+                printk(KERN_INFO "This card doesn't comply with any SD PHY spec version!!\n");
 
6414
+
 
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); 
 
6418
+
 
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); 
 
6422
+        
 
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); 
 
6426
+
 
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); 
 
6430
+
 
6431
+        /* dump Bus Interface reg */
 
6432
+        mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &data);
 
6433
+        val = data & 0x3;
 
6434
+        printk(KERN_INFO "Bus Width: %d bit\n", (val ? 4 : 1));
 
6435
+
 
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");
 
6442
+}
 
6443
+EXPORT_SYMBOL_GPL(sdio_dump_cccr);
 
6444
+
 
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
 
6448
--- /dev/null
 
6449
+++ b/drivers/mmc/core/sdio_irq.c
 
6450
@@ -0,0 +1,269 @@
 
6451
+/*
 
6452
+ * linux/drivers/mmc/core/sdio_irq.c
 
6453
+ *
 
6454
+ * Author:      Nicolas Pitre
 
6455
+ * Created:     June 18, 2007
 
6456
+ * Copyright:   MontaVista Software Inc.
 
6457
+ *
 
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.
 
6462
+ */
 
6463
+
 
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>
 
6469
+
 
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>
 
6475
+
 
6476
+#include "sdio_ops.h"
 
6477
+
 
6478
+static int process_sdio_pending_irqs(struct mmc_card *card)
 
6479
+{
 
6480
+       int i, ret, count;
 
6481
+       unsigned char pending;
 
6482
+
 
6483
+       ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_INTx, 0, &pending);
 
6484
+       if (ret) {
 
6485
+               printk(KERN_DEBUG "%s: error %d reading SDIO_CCCR_INTx\n",
 
6486
+                      mmc_card_id(card), ret);
 
6487
+               return ret;
 
6488
+       }
 
6489
+
 
6490
+       count = 0;
 
6491
+       for (i = 1; i <= 7; i++) {
 
6492
+               if (pending & (1 << i)) {
 
6493
+                       struct sdio_func *func = card->sdio_func[i - 1];
 
6494
+                       if (!func) {
 
6495
+                               printk(KERN_WARNING "%s: pending IRQ for "
 
6496
+                                       "non-existant function\n",
 
6497
+                                       mmc_card_id(card));
 
6498
+                               ret = -EINVAL;
 
6499
+                       } else if (func->irq_handler) {
 
6500
+                               func->irq_handler(func);
 
6501
+                               count++;
 
6502
+                       } else {
 
6503
+                               printk(KERN_WARNING "%s: pending IRQ with no handler\n",
 
6504
+                                      sdio_func_id(func));
 
6505
+                               ret = -EINVAL;
 
6506
+                       }
 
6507
+               }
 
6508
+       }
 
6509
+
 
6510
+       if (count)
 
6511
+               return count;
 
6512
+
 
6513
+       return ret;
 
6514
+}
 
6515
+
 
6516
+static int sdio_irq_thread(void *_host)
 
6517
+{
 
6518
+       struct mmc_host *host = _host;
 
6519
+       struct sched_param param = { .sched_priority = 1 };
 
6520
+       unsigned long period, idle_period;
 
6521
+       int ret;
 
6522
+
 
6523
+       sched_setscheduler(current, SCHED_FIFO, &param);
 
6524
+
 
6525
+       /*
 
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.
 
6530
+        */
 
6531
+       idle_period = msecs_to_jiffies(10);
 
6532
+       period = (host->caps & MMC_CAP_SDIO_IRQ) ?
 
6533
+               MAX_SCHEDULE_TIMEOUT : idle_period;
 
6534
+
 
6535
+       pr_debug("%s: IRQ thread started (poll period = %lu jiffies)\n",
 
6536
+                mmc_hostname(host), period);
 
6537
+
 
6538
+       current->flags |= PF_NOFREEZE;
 
6539
+
 
6540
+       do {
 
6541
+               /*
 
6542
+                * We claim the host here on drivers behalf for a couple
 
6543
+                * reasons:
 
6544
+                *
 
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.
 
6548
+                *
 
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.
 
6553
+                */
 
6554
+               ret = __mmc_claim_host(host, &host->sdio_irq_thread_abort);
 
6555
+               if (ret)
 
6556
+                       break;
 
6557
+               ret = process_sdio_pending_irqs(host->card);
 
6558
+               mmc_release_host(host);
 
6559
+
 
6560
+               /*
 
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.
 
6564
+                */
 
6565
+               if (ret < 0)
 
6566
+                       ssleep(1);
 
6567
+
 
6568
+               /*
 
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.
 
6572
+                */
 
6573
+               if (!(host->caps & MMC_CAP_SDIO_IRQ)) {
 
6574
+                       if (ret > 0)
 
6575
+                               period /= 2;
 
6576
+                       else {
 
6577
+                               period++;
 
6578
+                               if (period > idle_period)
 
6579
+                                       period = idle_period;
 
6580
+                       }
 
6581
+               }
 
6582
+
 
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());
 
6590
+
 
6591
+       if (host->caps & MMC_CAP_SDIO_IRQ)
 
6592
+               host->ops->enable_sdio_irq(host, 0);
 
6593
+
 
6594
+       pr_debug("%s: IRQ thread exiting with code %d\n",
 
6595
+                mmc_hostname(host), ret);
 
6596
+
 
6597
+       return ret;
 
6598
+}
 
6599
+
 
6600
+static int sdio_card_irq_get(struct mmc_card *card)
 
6601
+{
 
6602
+       struct mmc_host *host = card->host;
 
6603
+
 
6604
+       WARN_ON(!host->claimed);
 
6605
+
 
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--;
 
6613
+                       return err;
 
6614
+               }
 
6615
+       }
 
6616
+
 
6617
+       return 0;
 
6618
+}
 
6619
+
 
6620
+static int sdio_card_irq_put(struct mmc_card *card)
 
6621
+{
 
6622
+       struct mmc_host *host = card->host;
 
6623
+
 
6624
+       WARN_ON(!host->claimed);
 
6625
+       BUG_ON(host->sdio_irqs < 1);
 
6626
+
 
6627
+       if (!--host->sdio_irqs) {
 
6628
+               atomic_set(&host->sdio_irq_thread_abort, 1);
 
6629
+               kthread_stop(host->sdio_irq_thread);
 
6630
+       }
 
6631
+
 
6632
+       return 0;
 
6633
+}
 
6634
+
 
6635
+/**
 
6636
+ *     sdio_claim_irq - claim the IRQ for a SDIO function
 
6637
+ *     @func: SDIO function
 
6638
+ *     @handler: IRQ handler callback
 
6639
+ *
 
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().
 
6644
+ */
 
6645
+int sdio_claim_irq(struct sdio_func *func, sdio_irq_handler_t *handler)
 
6646
+{
 
6647
+       int ret;
 
6648
+       unsigned char reg;
 
6649
+
 
6650
+       BUG_ON(!func);
 
6651
+       BUG_ON(!func->card);
 
6652
+
 
6653
+       pr_debug("SDIO: Enabling IRQ for %s...\n", sdio_func_id(func));
 
6654
+
 
6655
+       if (func->irq_handler) {
 
6656
+               pr_debug("SDIO: IRQ for %s already in use.\n", sdio_func_id(func));
 
6657
+               return -EBUSY;
 
6658
+       }
 
6659
+
 
6660
+       ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IENx, 0, &reg);
 
6661
+       if (ret)
 
6662
+               return ret;
 
6663
+
 
6664
+       reg |= 1 << func->num;
 
6665
+
 
6666
+       reg |= 1; /* Master interrupt enable */
 
6667
+
 
6668
+       ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IENx, reg, NULL);
 
6669
+       if (ret)
 
6670
+               return ret;
 
6671
+
 
6672
+       func->irq_handler = handler;
 
6673
+       ret = sdio_card_irq_get(func->card);
 
6674
+       if (ret)
 
6675
+               func->irq_handler = NULL;
 
6676
+
 
6677
+       return ret;
 
6678
+}
 
6679
+EXPORT_SYMBOL_GPL(sdio_claim_irq);
 
6680
+
 
6681
+/**
 
6682
+ *     sdio_release_irq - release the IRQ for a SDIO function
 
6683
+ *     @func: SDIO function
 
6684
+ *
 
6685
+ *     Disable and release the IRQ for the given SDIO function.
 
6686
+ */
 
6687
+int sdio_release_irq(struct sdio_func *func)
 
6688
+{
 
6689
+       int ret;
 
6690
+       unsigned char reg;
 
6691
+
 
6692
+       BUG_ON(!func);
 
6693
+       BUG_ON(!func->card);
 
6694
+
 
6695
+       pr_debug("SDIO: Disabling IRQ for %s...\n", sdio_func_id(func));
 
6696
+
 
6697
+       if (func->irq_handler) {
 
6698
+               func->irq_handler = NULL;
 
6699
+               sdio_card_irq_put(func->card);
 
6700
+       }
 
6701
+
 
6702
+       ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IENx, 0, &reg);
 
6703
+       if (ret)
 
6704
+               return ret;
 
6705
+
 
6706
+       reg &= ~(1 << func->num);
 
6707
+
 
6708
+       /* Disable master interrupt with the last function interrupt */
 
6709
+       if (!(reg & 0xFE))
 
6710
+               reg = 0;
 
6711
+
 
6712
+       ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IENx, reg, NULL);
 
6713
+       if (ret)
 
6714
+               return ret;
 
6715
+
 
6716
+       return 0;
 
6717
+}
 
6718
+EXPORT_SYMBOL_GPL(sdio_release_irq);
 
6719
+
 
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
 
6723
--- /dev/null
 
6724
+++ b/drivers/mmc/core/sdio_ops.c
 
6725
@@ -0,0 +1,177 @@
 
6726
+/*
 
6727
+ *  linux/drivers/mmc/sdio_ops.c
 
6728
+ *
 
6729
+ *  Copyright 2006-2007 Pierre Ossman
 
6730
+ *
 
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.
 
6735
+ */
 
6736
+
 
6737
+#include <asm/scatterlist.h>
 
6738
+#include <linux/scatterlist.h>
 
6739
+
 
6740
+#include <linux/mmc/host.h>
 
6741
+#include <linux/mmc/card.h>
 
6742
+#include <linux/mmc/mmc.h>
 
6743
+#include <linux/mmc/sdio.h>
 
6744
+
 
6745
+#include "core.h"
 
6746
+
 
6747
+int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
 
6748
+{
 
6749
+       struct mmc_command cmd;
 
6750
+       int i, err = 0;
 
6751
+
 
6752
+       BUG_ON(!host);
 
6753
+
 
6754
+       memset(&cmd, 0, sizeof(struct mmc_command));
 
6755
+
 
6756
+       cmd.opcode = SD_IO_SEND_OP_COND;
 
6757
+       cmd.arg = ocr;
 
6758
+       cmd.flags = MMC_RSP_SPI_R4 | MMC_RSP_R4 | MMC_CMD_BCR;
 
6759
+
 
6760
+       for (i = 100; i; i--) {
 
6761
+               err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
 
6762
+               if (err)
 
6763
+                       break;
 
6764
+
 
6765
+               /* if we're just probing, do a single pass */
 
6766
+               if (ocr == 0)
 
6767
+                       break;
 
6768
+
 
6769
+               /* otherwise wait until reset completes */
 
6770
+               if (mmc_host_is_spi(host)) {
 
6771
+                       /*
 
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
 
6775
+                        * one.
 
6776
+                        */
 
6777
+                       if (cmd.resp[1] & MMC_CARD_BUSY)
 
6778
+                               break;
 
6779
+               } else {
 
6780
+                       if (cmd.resp[0] & MMC_CARD_BUSY)
 
6781
+                               break;
 
6782
+               }
 
6783
+
 
6784
+               err = -ETIMEDOUT;
 
6785
+
 
6786
+               mmc_delay(10);
 
6787
+       }
 
6788
+
 
6789
+       if (rocr)
 
6790
+               *rocr = cmd.resp[mmc_host_is_spi(host) ? 1 : 0];
 
6791
+
 
6792
+       return err;
 
6793
+}
 
6794
+
 
6795
+int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
 
6796
+       unsigned addr, u8 in, u8* out)
 
6797
+{
 
6798
+       struct mmc_command cmd;
 
6799
+       int err;
 
6800
+
 
6801
+       BUG_ON(!card);
 
6802
+       BUG_ON(fn > 7);
 
6803
+
 
6804
+       memset(&cmd, 0, sizeof(struct mmc_command));
 
6805
+
 
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;
 
6811
+       cmd.arg |= in;
 
6812
+       cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_AC;
 
6813
+
 
6814
+       err = mmc_wait_for_cmd(card->host, &cmd, 0);
 
6815
+       if (err)
 
6816
+               return err;
 
6817
+
 
6818
+       if (mmc_host_is_spi(card->host)) {
 
6819
+               /* host driver already reported errors */
 
6820
+       } else {
 
6821
+       if (cmd.resp[0] & R5_ERROR)
 
6822
+               return -EIO;
 
6823
+       if (cmd.resp[0] & R5_FUNCTION_NUMBER)
 
6824
+               return -EINVAL;
 
6825
+       if (cmd.resp[0] & R5_OUT_OF_RANGE)
 
6826
+               return -ERANGE;
 
6827
+       }
 
6828
+
 
6829
+       if (out) {
 
6830
+               if (mmc_host_is_spi(card->host))
 
6831
+                       *out = (cmd.resp[0] >> 8) & 0xFF;
 
6832
+               else
 
6833
+               *out = cmd.resp[0] & 0xFF;
 
6834
+       }
 
6835
+
 
6836
+       return 0;
 
6837
+}
 
6838
+
 
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)
 
6841
+{
 
6842
+       struct mmc_request mrq;
 
6843
+       struct mmc_command cmd;
 
6844
+       struct mmc_data data;
 
6845
+       struct scatterlist sg;
 
6846
+
 
6847
+       BUG_ON(!card);
 
6848
+       BUG_ON(fn > 7);
 
6849
+       BUG_ON(blocks == 1 && blksz > 512);
 
6850
+       WARN_ON(blocks == 0);
 
6851
+       WARN_ON(blksz == 0);
 
6852
+
 
6853
+       memset(&mrq, 0, sizeof(struct mmc_request));
 
6854
+       memset(&cmd, 0, sizeof(struct mmc_command));
 
6855
+       memset(&data, 0, sizeof(struct mmc_data));
 
6856
+
 
6857
+       mrq.cmd = &cmd;
 
6858
+       mrq.data = &data;
 
6859
+
 
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 */
 
6867
+       else
 
6868
+               cmd.arg |= 0x08000000 | blocks;         /* block mode */
 
6869
+       cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
 
6870
+
 
6871
+       data.blksz = blksz;
 
6872
+       data.blocks = blocks;
 
6873
+       data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
 
6874
+       data.sg = &sg;
 
6875
+       data.sg_len = 1;
 
6876
+
 
6877
+       sg_init_one(&sg, buf, blksz * blocks);
 
6878
+
 
6879
+       mmc_set_data_timeout(&data, card);
 
6880
+
 
6881
+       mmc_wait_for_req(card->host, &mrq);
 
6882
+
 
6883
+       if (cmd.error)
 
6884
+               return cmd.error;
 
6885
+       if (data.error)
 
6886
+               return data.error;
 
6887
+
 
6888
+       if (mmc_host_is_spi(card->host)) {
 
6889
+               /* host driver already reported errors */
 
6890
+       } else {
 
6891
+       if (cmd.resp[0] & R5_ERROR)
 
6892
+               return -EIO;
 
6893
+       if (cmd.resp[0] & R5_FUNCTION_NUMBER)
 
6894
+               return -EINVAL;
 
6895
+       if (cmd.resp[0] & R5_OUT_OF_RANGE)
 
6896
+               return -ERANGE;
 
6897
+       }
 
6898
+
 
6899
+       return 0;
 
6900
+}
 
6901
+EXPORT_SYMBOL_GPL(mmc_io_rw_extended);
 
6902
+
 
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
 
6906
--- /dev/null
 
6907
+++ b/drivers/mmc/core/sdio_ops.h
 
6908
@@ -0,0 +1,21 @@
 
6909
+/*
 
6910
+ *  linux/drivers/mmc/sdio_ops.c
 
6911
+ *
 
6912
+ *  Copyright 2006-2007 Pierre Ossman
 
6913
+ *
 
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.
 
6918
+ */
 
6919
+
 
6920
+#ifndef _MMC_SDIO_OPS_H
 
6921
+#define _MMC_SDIO_OPS_H
 
6922
+
 
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);
 
6928
+
 
6929
+#endif
 
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
 
6934
@@ -2,6 +2,7 @@
 
6935
  *  linux/drivers/mmc/core/sysfs.c
 
6936
  *
 
6937
  *  Copyright (C) 2003 Russell King, All Rights Reserved.
 
6938
+ *  Copyright 2007 Pierre Ossman
 
6939
  *
 
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
 
6942
@@ -9,352 +10,34 @@
 
6943
  *
 
6944
  *  MMC sysfs/driver model support.
 
6945
  */
 
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>
 
6951
 
 
6952
 #include <linux/mmc/card.h>
 
6953
-#include <linux/mmc/host.h>
 
6954
 
 
6955
 #include "sysfs.h"
 
6956
 
 
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)
 
6960
-
 
6961
-#define MMC_ATTR(name, fmt, args...)                                   \
 
6962
-static ssize_t mmc_##name##_show (struct device *dev, struct device_attribute *attr, char *buf)        \
 
6963
-{                                                                      \
 
6964
-       struct mmc_card *card = dev_to_mmc_card(dev);                   \
 
6965
-       return sprintf(buf, fmt, args);                                 \
 
6966
-}
 
6967
-
 
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);
 
6980
-
 
6981
-#define MMC_ATTR_RO(name) __ATTR(name, S_IRUGO, mmc_##name##_show, NULL)
 
6982
-
 
6983
-static struct device_attribute mmc_dev_attrs[] = {
 
6984
-       MMC_ATTR_RO(cid),
 
6985
-       MMC_ATTR_RO(csd),
 
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),
 
6993
-       __ATTR_NULL
 
6994
-};
 
6995
-
 
6996
-static struct device_attribute mmc_dev_attr_scr = MMC_ATTR_RO(scr);
 
6997
-
 
6998
-
 
6999
-static void mmc_release_card(struct device *dev)
 
7000
-{
 
7001
-       struct mmc_card *card = dev_to_mmc_card(dev);
 
7002
-
 
7003
-       kfree(card);
 
7004
-}
 
7005
-
 
7006
-/*
 
7007
- * This currently matches any MMC driver to any MMC card - drivers
 
7008
- * themselves make the decision whether to drive this card in their
 
7009
- * probe method.
 
7010
- */
 
7011
-static int mmc_bus_match(struct device *dev, struct device_driver *drv)
 
7012
-{
 
7013
-       return 1;
 
7014
-}
 
7015
-
 
7016
-static int
 
7017
-mmc_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
 
7018
-               int buf_size)
 
7019
-{
 
7020
-       struct mmc_card *card = dev_to_mmc_card(dev);
 
7021
-       char ccc[13];
 
7022
-       int retval = 0, i = 0, length = 0;
 
7023
-
 
7024
-#define add_env(fmt,val) do {                                  \
 
7025
-       retval = add_uevent_var(envp, num_envp, &i,             \
 
7026
-                               buf, buf_size, &length,         \
 
7027
-                               fmt, val);                      \
 
7028
-       if (retval)                                             \
 
7029
-               return retval;                                  \
 
7030
-} while (0);
 
7031
-
 
7032
-       for (i = 0; i < 12; i++)
 
7033
-               ccc[i] = card->csd.cmdclass & (1 << i) ? '1' : '0';
 
7034
-       ccc[12] = '\0';
 
7035
-
 
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);
 
7040
-#undef add_env
 
7041
-       envp[i] = NULL;
 
7042
-
 
7043
-       return 0;
 
7044
-}
 
7045
-
 
7046
-static int mmc_bus_suspend(struct device *dev, pm_message_t state)
 
7047
-{
 
7048
-       struct mmc_driver *drv = to_mmc_driver(dev->driver);
 
7049
-       struct mmc_card *card = dev_to_mmc_card(dev);
 
7050
-       int ret = 0;
 
7051
-
 
7052
-       if (dev->driver && drv->suspend)
 
7053
-               ret = drv->suspend(card, state);
 
7054
-       return ret;
 
7055
-}
 
7056
-
 
7057
-static int mmc_bus_resume(struct device *dev)
 
7058
-{
 
7059
-       struct mmc_driver *drv = to_mmc_driver(dev->driver);
 
7060
-       struct mmc_card *card = dev_to_mmc_card(dev);
 
7061
-       int ret = 0;
 
7062
-
 
7063
-       if (dev->driver && drv->resume)
 
7064
-               ret = drv->resume(card);
 
7065
-       return ret;
 
7066
-}
 
7067
-
 
7068
-static int mmc_bus_probe(struct device *dev)
 
7069
-{
 
7070
-       struct mmc_driver *drv = to_mmc_driver(dev->driver);
 
7071
-       struct mmc_card *card = dev_to_mmc_card(dev);
 
7072
-
 
7073
-       return drv->probe(card);
 
7074
-}
 
7075
-
 
7076
-static int mmc_bus_remove(struct device *dev)
 
7077
-{
 
7078
-       struct mmc_driver *drv = to_mmc_driver(dev->driver);
 
7079
-       struct mmc_card *card = dev_to_mmc_card(dev);
 
7080
-
 
7081
-       drv->remove(card);
 
7082
-
 
7083
-       return 0;
 
7084
-}
 
7085
-
 
7086
-static struct bus_type mmc_bus_type = {
 
7087
-       .name           = "mmc",
 
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,
 
7095
-};
 
7096
-
 
7097
-/**
 
7098
- *     mmc_register_driver - register a media driver
 
7099
- *     @drv: MMC media driver
 
7100
- */
 
7101
-int mmc_register_driver(struct mmc_driver *drv)
 
7102
-{
 
7103
-       drv->drv.bus = &mmc_bus_type;
 
7104
-       return driver_register(&drv->drv);
 
7105
-}
 
7106
-
 
7107
-EXPORT_SYMBOL(mmc_register_driver);
 
7108
-
 
7109
-/**
 
7110
- *     mmc_unregister_driver - unregister a media driver
 
7111
- *     @drv: MMC media driver
 
7112
- */
 
7113
-void mmc_unregister_driver(struct mmc_driver *drv)
 
7114
-{
 
7115
-       drv->drv.bus = &mmc_bus_type;
 
7116
-       driver_unregister(&drv->drv);
 
7117
-}
 
7118
-
 
7119
-EXPORT_SYMBOL(mmc_unregister_driver);
 
7120
-
 
7121
-
 
7122
-/*
 
7123
- * Internal function.  Initialise a MMC card structure.
 
7124
- */
 
7125
-void mmc_init_card(struct mmc_card *card, struct mmc_host *host)
 
7126
-{
 
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;
 
7133
-}
 
7134
-
 
7135
-/*
 
7136
- * Internal function.  Register a new MMC card with the driver model.
 
7137
- */
 
7138
-int mmc_register_card(struct mmc_card *card)
 
7139
+int mmc_add_attrs(struct mmc_card *card, struct device_attribute *attrs)
 
7140
 {
 
7141
-       int ret;
 
7142
+       int error = 0;
 
7143
+       int i;
 
7144
 
 
7145
-       snprintf(card->dev.bus_id, sizeof(card->dev.bus_id),
 
7146
-                "%s:%04x", mmc_hostname(card->host), card->rca);
 
7147
-
 
7148
-       ret = device_add(&card->dev);
 
7149
-       if (ret == 0) {
 
7150
-               if (mmc_card_sd(card)) {
 
7151
-                       ret = device_create_file(&card->dev, &mmc_dev_attr_scr);
 
7152
-                       if (ret)
 
7153
-                               device_del(&card->dev);
 
7154
+       for (i = 0; attr_name(attrs[i]); i++) {
 
7155
+               error = device_create_file(&card->dev, &attrs[i]);
 
7156
+               if (error) {
 
7157
+                       while (--i >= 0)
 
7158
+                               device_remove_file(&card->dev, &attrs[i]);
 
7159
+                       break;
 
7160
                }
 
7161
        }
 
7162
-       if (ret == 0)
 
7163
-               mmc_card_set_present(card);
 
7164
-       return ret;
 
7165
-}
 
7166
-
 
7167
-/*
 
7168
- * Internal function.  Unregister a new MMC card with the
 
7169
- * driver model, and (eventually) free it.
 
7170
- */
 
7171
-void mmc_remove_card(struct mmc_card *card)
 
7172
-{
 
7173
-       if (mmc_card_present(card)) {
 
7174
-               if (mmc_card_sd(card))
 
7175
-                       device_remove_file(&card->dev, &mmc_dev_attr_scr);
 
7176
-
 
7177
-               device_del(&card->dev);
 
7178
-       }
 
7179
-
 
7180
-       put_device(&card->dev);
 
7181
-}
 
7182
-
 
7183
-
 
7184
-static void mmc_host_classdev_release(struct device *dev)
 
7185
-{
 
7186
-       struct mmc_host *host = cls_dev_to_mmc_host(dev);
 
7187
-       kfree(host);
 
7188
-}
 
7189
-
 
7190
-static struct class mmc_host_class = {
 
7191
-       .name           = "mmc_host",
 
7192
-       .dev_release    = mmc_host_classdev_release,
 
7193
-};
 
7194
-
 
7195
-static DEFINE_IDR(mmc_host_idr);
 
7196
-static DEFINE_SPINLOCK(mmc_host_lock);
 
7197
-
 
7198
-/*
 
7199
- * Internal function. Allocate a new MMC host.
 
7200
- */
 
7201
-struct mmc_host *mmc_alloc_host_sysfs(int extra, struct device *dev)
 
7202
-{
 
7203
-       struct mmc_host *host;
 
7204
-
 
7205
-       host = kmalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
 
7206
-       if (host) {
 
7207
-               memset(host, 0, sizeof(struct mmc_host) + extra);
 
7208
-
 
7209
-               host->parent = dev;
 
7210
-               host->class_dev.parent = dev;
 
7211
-               host->class_dev.class = &mmc_host_class;
 
7212
-               device_initialize(&host->class_dev);
 
7213
-       }
 
7214
 
 
7215
-       return host;
 
7216
+       return error;
 
7217
 }
 
7218
 
 
7219
-/*
 
7220
- * Internal function. Register a new MMC host with the MMC class.
 
7221
- */
 
7222
-int mmc_add_host_sysfs(struct mmc_host *host)
 
7223
+void mmc_remove_attrs(struct mmc_card *card, struct device_attribute *attrs)
 
7224
 {
 
7225
-       int err;
 
7226
-
 
7227
-       if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
 
7228
-               return -ENOMEM;
 
7229
-
 
7230
-       spin_lock(&mmc_host_lock);
 
7231
-       err = idr_get_new(&mmc_host_idr, host, &host->index);
 
7232
-       spin_unlock(&mmc_host_lock);
 
7233
-       if (err)
 
7234
-               return err;
 
7235
-
 
7236
-       snprintf(host->class_dev.bus_id, BUS_ID_SIZE,
 
7237
-                "mmc%d", host->index);
 
7238
-
 
7239
-       return device_add(&host->class_dev);
 
7240
-}
 
7241
+       int i;
 
7242
 
 
7243
-/*
 
7244
- * Internal function. Unregister a MMC host with the MMC class.
 
7245
- */
 
7246
-void mmc_remove_host_sysfs(struct mmc_host *host)
 
7247
-{
 
7248
-       device_del(&host->class_dev);
 
7249
-
 
7250
-       spin_lock(&mmc_host_lock);
 
7251
-       idr_remove(&mmc_host_idr, host->index);
 
7252
-       spin_unlock(&mmc_host_lock);
 
7253
-}
 
7254
-
 
7255
-/*
 
7256
- * Internal function. Free a MMC host.
 
7257
- */
 
7258
-void mmc_free_host_sysfs(struct mmc_host *host)
 
7259
-{
 
7260
-       put_device(&host->class_dev);
 
7261
-}
 
7262
-
 
7263
-static struct workqueue_struct *workqueue;
 
7264
-
 
7265
-/*
 
7266
- * Internal function. Schedule delayed work in the MMC work queue.
 
7267
- */
 
7268
-int mmc_schedule_delayed_work(struct delayed_work *work, unsigned long delay)
 
7269
-{
 
7270
-       return queue_delayed_work(workqueue, work, delay);
 
7271
-}
 
7272
-
 
7273
-/*
 
7274
- * Internal function. Flush all scheduled work from the MMC work queue.
 
7275
- */
 
7276
-void mmc_flush_scheduled_work(void)
 
7277
-{
 
7278
-       flush_workqueue(workqueue);
 
7279
-}
 
7280
-
 
7281
-static int __init mmc_init(void)
 
7282
-{
 
7283
-       int ret;
 
7284
-
 
7285
-       workqueue = create_singlethread_workqueue("kmmcd");
 
7286
-       if (!workqueue)
 
7287
-               return -ENOMEM;
 
7288
-
 
7289
-       ret = bus_register(&mmc_bus_type);
 
7290
-       if (ret == 0) {
 
7291
-               ret = class_register(&mmc_host_class);
 
7292
-               if (ret)
 
7293
-                       bus_unregister(&mmc_bus_type);
 
7294
-       }
 
7295
-       return ret;
 
7296
-}
 
7297
-
 
7298
-static void __exit mmc_exit(void)
 
7299
-{
 
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]);
 
7305
 }
 
7306
 
 
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
 
7313
@@ -11,17 +11,16 @@
 
7314
 #ifndef _MMC_CORE_SYSFS_H
 
7315
 #define _MMC_CORE_SYSFS_H
 
7316
 
 
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)        \
 
7322
+{                                                                      \
 
7323
+       struct mmc_card *card = container_of(dev, struct mmc_card, dev);\
 
7324
+       return sprintf(buf, fmt, args);                                 \
 
7325
+}
 
7326
 
 
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)
 
7332
 
 
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);
 
7338
 
 
7339
 #endif
 
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
 
7345
 
 
7346
          If unsure, say N.
 
7347
 
 
7348
+config MMC_RICOH_MMC
 
7349
+       tristate "Ricoh MMC Controller Disabler  (EXPERIMENTAL)"
 
7350
+       depends on PCI && EXPERIMENTAL && MMC_SDHCI
 
7351
+       help
 
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.
 
7358
+
 
7359
+
 
7360
+         To compile this driver as a module, choose M here:
 
7361
+         the module will be called ricoh_mmc.
 
7362
+
 
7363
+         If unsure, say Y.
 
7364
+
 
7365
 config MMC_OMAP
 
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.
 
7371
 
 
7372
+config MMC_SPI
 
7373
+       tristate "MMC/SD over SPI (EXPERIMENTAL)"
 
7374
+       depends on MMC && SPI_MASTER && !HIGHMEM && EXPERIMENTAL
 
7375
+       select CRC7
 
7376
+       select CRC_ITU_T
 
7377
+       help
 
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.
 
7382
+
 
7383
+         If unsure, or if your system has no SPI master driver, say N.
 
7384
+
 
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
 
7400
 
 
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
 
7405
@@ -1,5 +1,5 @@
 
7406
 /*
 
7407
- *  linux/drivers/mmc/at91_mci.c - ATMEL AT91 MCI Driver
 
7408
+ *  linux/drivers/mmc/host/at91_mci.c - ATMEL AT91 MCI Driver
 
7409
  *
 
7410
  *  Copyright (C) 2005 Cougar Creek Computing Devices Ltd, All Rights Reserved
 
7411
  *
 
7412
@@ -78,14 +78,12 @@
 
7413
 
 
7414
 #define DRIVER_NAME "at91_mci"
 
7415
 
 
7416
-#undef SUPPORT_4WIRE
 
7417
-
 
7418
 #define FL_SENT_COMMAND        (1 << 0)
 
7419
 #define FL_SENT_STOP   (1 << 1)
 
7420
 
 
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)
 
7425
 
 
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
 
7429
 /*
 
7430
  * Copy from sg to a dma block - used for transfers
 
7431
  */
 
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)
 
7434
 {
 
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
 
7438
 
 
7439
                sg = &data->sg[i];
 
7440
 
 
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);
 
7444
                size -= amount;
 
7445
 
 
7446
@@ -180,7 +178,7 @@ static inline void at91mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
 
7447
 /*
 
7448
  * Prepare a dma read
 
7449
  */
 
7450
-static void at91mci_pre_dma_read(struct at91mci_host *host)
 
7451
+static void at91_mci_pre_dma_read(struct at91mci_host *host)
 
7452
 {
 
7453
        int i;
 
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);
 
7458
 
 
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);
 
7461
 
 
7462
                pr_debug("dma address = %08X, length = %d\n", sg->dma_address, sg->length);
 
7463
 
 
7464
@@ -248,7 +246,7 @@ static void at91mci_pre_dma_read(struct at91mci_host *host)
 
7465
 /*
 
7466
  * Handle after a dma read
 
7467
  */
 
7468
-static void at91mci_post_dma_read(struct at91mci_host *host)
 
7469
+static void at91_mci_post_dma_read(struct at91mci_host *host)
 
7470
 {
 
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)
 
7474
        }
 
7475
 
 
7476
        while (host->in_use_index < host->transfer_index) {
 
7477
-               unsigned int *buffer;
 
7478
-
 
7479
                struct scatterlist *sg;
 
7480
 
 
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)
 
7483
 
 
7484
                dma_unmap_page(NULL, sg->dma_address, sg->length, DMA_FROM_DEVICE);
 
7485
 
 
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);
 
7489
-
 
7490
                data->bytes_xfered += sg->length;
 
7491
 
 
7492
                if (cpu_is_at91rm9200()) {      /* AT91RM9200 errata */
 
7493
+                       unsigned int *buffer;
 
7494
                        int index;
 
7495
 
 
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);
 
7499
+
 
7500
                        for (index = 0; index < (sg->length / 4); index++)
 
7501
                                buffer[index] = swab32(buffer[index]);
 
7502
+
 
7503
+                       kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
 
7504
                }
 
7505
 
 
7506
-               kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
 
7507
-               flush_dcache_page(sg->page);
 
7508
+               flush_dcache_page(sg_page(sg));
 
7509
        }
 
7510
 
 
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);
 
7515
        else {
 
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);
 
7519
        }
 
7520
 
 
7521
        pr_debug("post dma read done\n");
 
7522
@@ -323,7 +321,6 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host)
 
7523
 
 
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);
 
7527
 
 
7528
        cmd = host->cmd;
 
7529
        if (!cmd) return;
 
7530
@@ -331,18 +328,53 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host)
 
7531
        data = cmd->data;
 
7532
        if (!data) return;
 
7533
 
 
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);
 
7537
+       } else
 
7538
+               at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY);
 
7539
+
 
7540
        data->bytes_xfered = host->total_length;
 
7541
 }
 
7542
 
 
7543
+/*Handle after command sent ready*/
 
7544
+static int at91_mci_handle_cmdrdy(struct at91mci_host *host)
 
7545
+{
 
7546
+       if (!host->cmd)
 
7547
+               return 1;
 
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);
 
7552
+               } else return 1;
 
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);
 
7558
+       }
 
7559
+
 
7560
+       /* command not completed, have to wait */
 
7561
+       return 0;
 
7562
+}
 
7563
+
 
7564
+
 
7565
 /*
 
7566
  * Enable the controller
 
7567
  */
 
7568
 static void at91_mci_enable(struct at91mci_host *host)
 
7569
 {
 
7570
+       unsigned int mr;
 
7571
+
 
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;
 
7577
+
 
7578
+       if (cpu_is_at91sam9260() || cpu_is_at91sam9263())
 
7579
+               mr |= AT91_MCI_RDPROOF | AT91_MCI_WRPROOF;
 
7580
+
 
7581
+       at91_mci_write(host, AT91_MCI_MR, mr);
 
7582
 
 
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)
 
7586
 
 
7587
 /*
 
7588
  * Send a command
 
7589
- * return the interrupts to enable
 
7590
  */
 
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)
 
7593
 {
 
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_
 
7597
 
 
7598
        host->cmd = cmd;
 
7599
 
 
7600
-       /* Not sure if this is needed */
 
7601
-#if 0
 
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));
 
7608
                }
 
7609
        }
 
7610
-#endif
 
7611
+
 
7612
        cmdr = cmd->opcode;
 
7613
 
 
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_
 
7616
        }
 
7617
 
 
7618
        if (data) {
 
7619
+
 
7620
+               if ( data->blksz & 0x3 ) {
 
7621
+                       pr_debug("Unsupported block size\n");
 
7622
+                       cmd->error = -EINVAL;
 
7623
+                       mmc_request_done(host->mmc, host->request);
 
7624
+                       return;
 
7625
+               }
 
7626
+
 
7627
                block_length = data->blksz;
 
7628
                blocks = data->blocks;
 
7629
 
 
7630
@@ -409,7 +447,7 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
 
7631
 
 
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;
 
7637
        }
 
7638
        else {
 
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;
 
7644
+       } else {
 
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);
 
7648
 
 
7649
-               at91_mci_write(host, AT91_MCI_ARGR, cmd->arg);
 
7650
-               at91_mci_write(host, AT91_MCI_CMDR, cmdr);
 
7651
-               return AT91_MCI_CMDRDY;
 
7652
-       }
 
7653
-
 
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);
 
7656
-
 
7657
-       /*
 
7658
-        * Disable the PDC controller
 
7659
-        */
 
7660
-       at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
 
7661
-
 
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) {
 
7667
-                       /*
 
7668
-                        * Handle a read
 
7669
-                        */
 
7670
-                       host->buffer = NULL;
 
7671
-                       host->total_length = 0;
 
7672
-
 
7673
-                       at91mci_pre_dma_read(host);
 
7674
-                       ier = AT91_MCI_ENDRX /* | AT91_MCI_RXBUFF */;
 
7675
-               }
 
7676
-               else {
 
7677
-                       /*
 
7678
-                        * Handle a write
 
7679
-                        */
 
7680
-                       host->total_length = block_length * blocks;
 
7681
-                       host->buffer = dma_alloc_coherent(NULL,
 
7682
-                                                 host->total_length,
 
7683
-                                                 &host->physical_address, GFP_KERNEL);
 
7684
-
 
7685
-                       at91mci_sg_to_dma(host, data);
 
7686
-
 
7687
-                       pr_debug("Transmitting %d bytes\n", host->total_length);
 
7688
+               /*
 
7689
+                * Disable the PDC controller
 
7690
+                */
 
7691
+               at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
 
7692
 
 
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) {
 
7701
+                               /*
 
7702
+                                * Handle a read
 
7703
+                                */
 
7704
+                               host->buffer = NULL;
 
7705
+                               host->total_length = 0;
 
7706
+
 
7707
+                               at91_mci_pre_dma_read(host);
 
7708
+                               ier = AT91_MCI_ENDRX /* | AT91_MCI_RXBUFF */;
 
7709
+                       }
 
7710
+                       else {
 
7711
+                               /*
 
7712
+                                * Handle a write
 
7713
+                                */
 
7714
+                               host->total_length = block_length * blocks;
 
7715
+                               host->buffer = dma_alloc_coherent(NULL,
 
7716
+                                               host->total_length,
 
7717
+                                               &host->physical_address, GFP_KERNEL);
 
7718
+
 
7719
+                               at91_mci_sg_to_dma(host, data);
 
7720
+
 
7721
+                               pr_debug("Transmitting %d bytes\n", host->total_length);
 
7722
+
 
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;
 
7726
+                       }
 
7727
                }
 
7728
        }
 
7729
 
 
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);
 
7734
-               else
 
7735
-                       at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN);
 
7736
        }
 
7737
-       return ier;
 
7738
-}
 
7739
-
 
7740
-/*
 
7741
- * Wait for a command to complete
 
7742
- */
 
7743
-static void at91mci_process_command(struct at91mci_host *host, struct mmc_command *cmd)
 
7744
-{
 
7745
-       unsigned int ier;
 
7746
 
 
7747
-       ier = at91_mci_send_command(host, cmd);
 
7748
-
 
7749
-       pr_debug("setting ier to %08X\n", ier);
 
7750
-
 
7751
-       /* Stop on errors or the required value */
 
7752
+       /* Enable selected interrupts */
 
7753
        at91_mci_write(host, AT91_MCI_IER, AT91_MCI_ERRORS | ier);
 
7754
 }
 
7755
 
 
7756
 /*
 
7757
  * Process the next step in the request
 
7758
  */
 
7759
-static void at91mci_process_next(struct at91mci_host *host)
 
7760
+static void at91_mci_process_next(struct at91mci_host *host)
 
7761
 {
 
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);
 
7766
        }
 
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);
 
7771
        }
 
7772
        else
 
7773
                mmc_request_done(host->mmc, host->request);
 
7774
@@ -538,7 +559,7 @@ static void at91mci_process_next(struct at91mci_host *host)
 
7775
 /*
 
7776
  * Handle a command that has been completed
 
7777
  */
 
7778
-static void at91mci_completed_command(struct at91mci_host *host)
 
7779
+static void at91_mci_completed_command(struct at91mci_host *host)
 
7780
 {
 
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]);
 
7786
 
 
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;
 
7793
+                       cmd->error = 0;
 
7794
                }
 
7795
                else {
 
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;
 
7804
                        else
 
7805
-                               cmd->error = MMC_ERR_FAILED;
 
7806
+                               cmd->error = -EIO;
 
7807
 
 
7808
                        pr_debug("Error detected and set to %d (cmd = %d, retries = %d)\n",
 
7809
                                 cmd->error, cmd->opcode, cmd->retries);
 
7810
                }
 
7811
        }
 
7812
        else
 
7813
-               cmd->error = MMC_ERR_NONE;
 
7814
+               cmd->error = 0;
 
7815
 
 
7816
-       at91mci_process_next(host);
 
7817
+       at91_mci_process_next(host);
 
7818
 }
 
7819
 
 
7820
 /*
 
7821
@@ -595,7 +612,7 @@ static void at91_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
7822
        host->request = mrq;
 
7823
        host->flags = 0;
 
7824
 
 
7825
-       at91mci_process_next(host);
 
7826
+       at91_mci_process_next(host);
 
7827
 }
 
7828
 
 
7829
 /*
 
7830
@@ -663,15 +680,15 @@ static irqreturn_t at91_mci_irq(int irq, void *devid)
 
7831
 
 
7832
        int_status = at91_mci_read(host, AT91_MCI_SR);
 
7833
        int_mask = at91_mci_read(host, AT91_MCI_IMR);
 
7834
-       
 
7835
+
 
7836
        pr_debug("MCI irq: status = %08X, %08X, %08X\n", int_status, int_mask,
 
7837
                int_status & int_mask);
 
7838
-       
 
7839
+
 
7840
        int_status = int_status & int_mask;
 
7841
 
 
7842
        if (int_status & AT91_MCI_ERRORS) {
 
7843
                completed = 1;
 
7844
-               
 
7845
+
 
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);
 
7851
                }
 
7852
 
 
7853
+               if (int_status & AT91_MCI_ENDRX) {
 
7854
+                       pr_debug("ENDRX\n");
 
7855
+                       at91_mci_post_dma_read(host);
 
7856
+               }
 
7857
+
 
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);
 
7863
+                       completed = 1;
 
7864
                }
 
7865
 
 
7866
                if (int_status & AT91_MCI_ENDTX)
 
7867
                        pr_debug("Transmit has ended\n");
 
7868
 
 
7869
-               if (int_status & AT91_MCI_ENDRX) {
 
7870
-                       pr_debug("Receive has ended\n");
 
7871
-                       at91mci_post_dma_read(host);
 
7872
-               }
 
7873
-
 
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);
 
7877
+                       completed = 1;
 
7878
                }
 
7879
 
 
7880
                if (int_status & AT91_MCI_DTIP)
 
7881
                        pr_debug("Data transfer in progress\n");
 
7882
 
 
7883
-               if (int_status & AT91_MCI_BLKE)
 
7884
+               if (int_status & AT91_MCI_BLKE) {
 
7885
                        pr_debug("Block transfer has ended\n");
 
7886
+                       completed = 1;
 
7887
+               }
 
7888
 
 
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)
 
7892
 
 
7893
                if (int_status & AT91_MCI_CMDRDY) {
 
7894
                        pr_debug("Command ready\n");
 
7895
-                       completed = 1;
 
7896
+                       completed = at91_mci_handle_cmdrdy(host);
 
7897
                }
 
7898
        }
 
7899
 
 
7900
        if (completed) {
 
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);
 
7905
        } else
 
7906
                at91_mci_write(host, AT91_MCI_IDR, int_status);
 
7907
 
 
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;
 
7913
 
 
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)
 
7917
        host->bus_mode = 0;
 
7918
        host->board = pdev->dev.platform_data;
 
7919
        if (host->board->wire4) {
 
7920
-#ifdef SUPPORT_4WIRE
 
7921
-               mmc->caps |= MMC_CAP_4_BIT_DATA;
 
7922
-#else
 
7923
-               printk("AT91 MMC: 4 wire bus mode not supported by this driver - using 1 wire\n");
 
7924
-#endif
 
7925
+               if (cpu_is_at91sam9260() || cpu_is_at91sam9263())
 
7926
+                       mmc->caps |= MMC_CAP_4_BIT_DATA;
 
7927
+               else
 
7928
+                       printk("AT91 MMC: 4 wire bus mode not supported"
 
7929
+                               " - using 1 wire\n");
 
7930
        }
 
7931
 
 
7932
        /*
 
7933
@@ -886,8 +906,10 @@ static int __init at91_mci_probe(struct platform_device *pdev)
 
7934
        /*
 
7935
         * Add host to MMC layer
 
7936
         */
 
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);
 
7941
+       }
 
7942
        else
 
7943
                host->present = -1;
 
7944
 
 
7945
@@ -922,7 +944,8 @@ static int __exit at91_mci_remove(struct platform_device *pdev)
 
7946
 
 
7947
        host = mmc_priv(mmc);
 
7948
 
 
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);
 
7954
        }
 
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)
 
7957
 {
 
7958
        struct mmc_host *mmc = platform_get_drvdata(pdev);
 
7959
+       struct at91mci_host *host = mmc_priv(mmc);
 
7960
        int ret = 0;
 
7961
 
 
7962
+       if (host->board->det_pin && device_may_wakeup(&pdev->dev))
 
7963
+               enable_irq_wake(host->board->det_pin);
 
7964
+
 
7965
        if (mmc)
 
7966
                ret = mmc_suspend_host(mmc, state);
 
7967
 
 
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)
 
7970
 {
 
7971
        struct mmc_host *mmc = platform_get_drvdata(pdev);
 
7972
+       struct at91mci_host *host = mmc_priv(mmc);
 
7973
        int ret = 0;
 
7974
 
 
7975
+       if (host->board->det_pin && device_may_wakeup(&pdev->dev))
 
7976
+               disable_irq_wake(host->board->det_pin);
 
7977
+
 
7978
        if (mmc)
 
7979
                ret = mmc_resume_host(mmc);
 
7980
 
 
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
 
7985
@@ -1,5 +1,5 @@
 
7986
 /*
 
7987
- * linux/drivers/mmc/au1xmmc.c - AU1XX0 MMC driver
 
7988
+ * linux/drivers/mmc/host/au1xmmc.c - AU1XX0 MMC driver
 
7989
  *
 
7990
  *  Copyright (c) 2005, Advanced Micro Devices, Inc.
 
7991
  *
 
7992
@@ -40,13 +40,13 @@
 
7993
 #include <linux/mm.h>
 
7994
 #include <linux/interrupt.h>
 
7995
 #include <linux/dma-mapping.h>
 
7996
+#include <linux/scatterlist.h>
 
7997
 
 
7998
 #include <linux/mmc/host.h>
 
7999
 #include <asm/io.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>
 
8004
 
 
8005
 #include <au1xxx.h>
 
8006
 #include "au1xmmc.h"
 
8007
@@ -186,7 +186,7 @@ static void au1xmmc_tasklet_finish(unsigned long param)
 
8008
 }
 
8009
 
 
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)
 
8013
 {
 
8014
        u32 mmccmd = (cmd->opcode << SD_CMD_CI_SHIFT);
 
8015
 
 
8016
@@ -208,19 +208,21 @@ static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
 
8017
        default:
 
8018
                printk(KERN_INFO "au1xmmc: unhandled response type %02x\n",
 
8019
                        mmc_resp_type(cmd));
 
8020
-               return MMC_ERR_INVALID;
 
8021
+               return -EINVAL;
 
8022
        }
 
8023
 
 
8024
-       if (flags & MMC_DATA_READ) {
 
8025
-               if (flags & MMC_DATA_MULTI)
 
8026
-                       mmccmd |= SD_CMD_CT_4;
 
8027
-               else
 
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;
 
8032
-               else
 
8033
-                       mmccmd |= SD_CMD_CT_1;
 
8034
+       if (data) {
 
8035
+               if (data->flags & MMC_DATA_READ) {
 
8036
+                       if (data->blocks > 1)
 
8037
+                               mmccmd |= SD_CMD_CT_4;
 
8038
+                       else
 
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;
 
8043
+                       else
 
8044
+                               mmccmd |= SD_CMD_CT_1;
 
8045
+               }
 
8046
        }
 
8047
 
 
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);
 
8051
        }
 
8052
 
 
8053
-       return MMC_ERR_NONE;
 
8054
+       return 0;
 
8055
 }
 
8056
 
 
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));
 
8061
 
 
8062
-       data->error = MMC_ERR_NONE;
 
8063
+       data->error = 0;
 
8064
        dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir);
 
8065
 
 
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;
 
8069
 
 
8070
        if (crc)
 
8071
-               data->error = MMC_ERR_BADCRC;
 
8072
+               data->error = -EILSEQ;
 
8073
 
 
8074
        /* Clear the CRC bits */
 
8075
        au_writel(SD_STATUS_WC | SD_STATUS_RC, HOST_STATUS(host));
 
8076
 
 
8077
        data->bytes_xfered = 0;
 
8078
 
 
8079
-       if (data->error == MMC_ERR_NONE) {
 
8080
+       if (!data->error) {
 
8081
                if (host->flags & HOST_F_DMA) {
 
8082
                        u32 chan = DMA_CHANNEL(host);
 
8083
 
 
8084
@@ -338,7 +340,7 @@ static void au1xmmc_send_pio(struct au1xmmc_host *host)
 
8085
 
 
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;
 
8090
 
 
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)
 
8094
 
 
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;
 
8099
 
 
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)
 
8103
                return;
 
8104
 
 
8105
        cmd = mrq->cmd;
 
8106
-       cmd->error = MMC_ERR_NONE;
 
8107
+       cmd->error = 0;
 
8108
 
 
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 */
 
8113
 
 
8114
        if (status & (SD_STATUS_SC | SD_STATUS_WC | SD_STATUS_RC))
 
8115
-               cmd->error = MMC_ERR_BADCRC;
 
8116
+               cmd->error = -EILSEQ;
 
8117
 
 
8118
        trans = host->flags & (HOST_F_XMIT | HOST_F_RECV);
 
8119
 
 
8120
-       if (!trans || cmd->error != MMC_ERR_NONE) {
 
8121
+       if (!trans || cmd->error) {
 
8122
 
 
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);
 
8127
 
 
8128
        if (host->dma.len == 0)
 
8129
-               return MMC_ERR_TIMEOUT;
 
8130
+               return -ETIMEDOUT;
 
8131
 
 
8132
        au_writel(data->blksz - 1, HOST_BLKSIZE(host));
 
8133
 
 
8134
@@ -611,14 +613,11 @@ au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data)
 
8135
 
 
8136
                        if (host->flags & HOST_F_XMIT){
 
8137
                                ret = au1xxx_dbdma_put_source_flags(channel,
 
8138
-                                       (void *) (page_address(sg->page) +
 
8139
-                                                 sg->offset),
 
8140
-                                       len, flags);
 
8141
+                                       (void *) sg_virt(sg), len, flags);
 
8142
                        }
 
8143
                        else {
 
8144
                                ret = au1xxx_dbdma_put_dest_flags(channel,
 
8145
-                                       (void *) (page_address(sg->page) +
 
8146
-                                                 sg->offset),
 
8147
+                                       (void *) sg_virt(sg),
 
8148
                                        len, flags);
 
8149
                        }
 
8150
 
 
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);
 
8153
        }
 
8154
 
 
8155
-       return MMC_ERR_NONE;
 
8156
+       return 0;
 
8157
 
 
8158
  dataerr:
 
8159
        dma_unmap_sg(mmc_dev(host->mmc),data->sg,data->sg_len,host->dma.dir);
 
8160
-       return MMC_ERR_TIMEOUT;
 
8161
+       return -ETIMEDOUT;
 
8162
 }
 
8163
 
 
8164
 /* static void au1xmmc_request
 
8165
@@ -656,7 +655,7 @@ static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq)
 
8166
 
 
8167
        struct au1xmmc_host *host = mmc_priv(mmc);
 
8168
        unsigned int flags = 0;
 
8169
-       int ret = MMC_ERR_NONE;
 
8170
+       int ret = 0;
 
8171
 
 
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);
 
8176
        }
 
8177
 
 
8178
-       if (ret == MMC_ERR_NONE)
 
8179
-               ret = au1xmmc_send_command(host, 0, mrq->cmd, flags);
 
8180
+       if (!ret)
 
8181
+               ret = au1xmmc_send_command(host, 0, mrq->cmd, mrq->data);
 
8182
 
 
8183
-       if (ret != MMC_ERR_NONE) {
 
8184
+       if (ret) {
 
8185
                mrq->cmd->error = ret;
 
8186
                au1xmmc_finish_request(host);
 
8187
        }
 
8188
@@ -764,10 +763,10 @@ static irqreturn_t au1xmmc_irq(int irq, void *dev_id)
 
8189
 
 
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;
 
8194
 
 
8195
                        else if (status & SD_STATUS_DT)
 
8196
-                               host->mrq->data->error = MMC_ERR_TIMEOUT;
 
8197
+                               host->mrq->data->error = -ETIMEDOUT;
 
8198
 
 
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
 
8205
@@ -1,5 +1,5 @@
 
8206
 /*
 
8207
- *  linux/drivers/mmc/imxmmc.c - Motorola i.MX MMCI driver
 
8208
+ *  linux/drivers/mmc/host/imxmmc.c - Motorola i.MX MMCI driver
 
8209
  *
 
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)
 
8213
                }
 
8214
 
 
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);
 
8218
                host->data_cnt = 0;
 
8219
 
 
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;
 
8230
                else
 
8231
-                       data->error = MMC_ERR_FAILED;
 
8232
+                       data->error = -EIO;
 
8233
        } else {
 
8234
                data->bytes_xfered = host->dma_size;
 
8235
        }
 
8236
@@ -458,10 +458,10 @@ static int imxmci_cmd_done(struct imxmci_host *host, unsigned int stat)
 
8237
 
 
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;
 
8246
        }
 
8247
 
 
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);
 
8252
 
 
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) {
 
8256
 
 
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);
 
8265
                                if(host->req)
 
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)
 
8268
        }
 
8269
 }
 
8270
 
 
8271
+static int imxmci_get_ro(struct mmc_host *mmc)
 
8272
+{
 
8273
+       struct imxmci_host *host = mmc_priv(mmc);
 
8274
+
 
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 */
 
8278
+       return 0;
 
8279
+}
 
8280
+
 
8281
+
 
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,
 
8286
 };
 
8287
 
 
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)
 
8290
 {
 
8291
        struct imxmci_host *host = (struct imxmci_host *)data;
 
8292
 
 
8293
-       if( host->pdata->card_present() != host->present ) {
 
8294
+       if( host->pdata->card_present(mmc_dev(host->mmc)) != host->present ) {
 
8295
                host->present ^= 1;
 
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;
 
8304
 
 
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)
 
8308
        if (ret)
 
8309
                goto out;
 
8310
 
 
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
 
8319
--- /dev/null
 
8320
+++ b/drivers/mmc/host/mmc_spi.c
 
8321
@@ -0,0 +1,1423 @@
 
8322
+/*
 
8323
+ * mmc_spi.c - Access SD/MMC cards through SPI master controllers
 
8324
+ *
 
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>
 
8332
+ *
 
8333
+ *
 
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.
 
8338
+ *
 
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.
 
8343
+ *
 
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.
 
8347
+ */
 
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>
 
8355
+
 
8356
+#include <linux/mmc/host.h>
 
8357
+#include <linux/mmc/mmc.h>             /* for R1_SPI_* bit values */
 
8358
+
 
8359
+#include <linux/spi/spi.h>
 
8360
+#include <linux/spi/mmc_spi.h>
 
8361
+
 
8362
+#include <asm/unaligned.h>
 
8363
+
 
8364
+
 
8365
+/* NOTES:
 
8366
+ *
 
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.
 
8371
+ *
 
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.
 
8375
+ *
 
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.
 
8380
+ *
 
8381
+ *   Pending updates to the programming interface, this driver expects
 
8382
+ *   that it not share the bus with other drivers (precluding conflicts).
 
8383
+ *
 
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!
 
8387
+ *
 
8388
+ *   However, many cards seem OK with chipselect flapping up/down
 
8389
+ *   during that time ... at least on unshared bus segments.
 
8390
+ */
 
8391
+
 
8392
+
 
8393
+/*
 
8394
+ * Local protocol constants, internal to data block protocols.
 
8395
+ */
 
8396
+
 
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)
 
8402
+
 
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.
 
8405
+ */
 
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 */
 
8409
+
 
8410
+#define MMC_SPI_BLOCKSIZE      512
 
8411
+
 
8412
+
 
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?
 
8418
+ */
 
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)
 
8422
+
 
8423
+
 
8424
+/****************************************************************************/
 
8425
+
 
8426
+/*
 
8427
+ * Local Data Structures
 
8428
+ */
 
8429
+
 
8430
+/* "scratch" is per-{command,block} data exchanged with the card */
 
8431
+struct scratch {
 
8432
+       u8                      status[29];
 
8433
+       u8                      data_token;
 
8434
+       __be16                  crc_val;
 
8435
+};
 
8436
+
 
8437
+struct mmc_spi_host {
 
8438
+       struct mmc_host         *mmc;
 
8439
+       struct spi_device       *spi;
 
8440
+
 
8441
+       unsigned char           power_mode;
 
8442
+       u16                     powerup_msecs;
 
8443
+
 
8444
+       struct mmc_spi_platform_data    *pdata;
 
8445
+
 
8446
+       /* for bulk data transfers */
 
8447
+       struct spi_transfer     token, t, crc, early_status;
 
8448
+       struct spi_message      m;
 
8449
+
 
8450
+       /* for status readback */
 
8451
+       struct spi_transfer     status;
 
8452
+       struct spi_message      readback;
 
8453
+
 
8454
+       /* underlying DMA-aware controller, or null */
 
8455
+       struct device           *dma_dev;
 
8456
+
 
8457
+       /* buffer used for commands and for message "overhead" */
 
8458
+       struct scratch          *data;
 
8459
+       dma_addr_t              data_dma;
 
8460
+
 
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.
 
8464
+        */
 
8465
+       void                    *ones;
 
8466
+       dma_addr_t              ones_dma;
 
8467
+};
 
8468
+
 
8469
+
 
8470
+/****************************************************************************/
 
8471
+
 
8472
+/*
 
8473
+ * MMC-over-SPI protocol glue, used by the MMC stack interface
 
8474
+ */
 
8475
+
 
8476
+static inline int mmc_cs_off(struct mmc_spi_host *host)
 
8477
+{
 
8478
+       /* chipselect will always be inactive after setup() */
 
8479
+       return spi_setup(host->spi);
 
8480
+}
 
8481
+
 
8482
+static int
 
8483
+mmc_spi_readbytes(struct mmc_spi_host *host, unsigned len)
 
8484
+{
 
8485
+       int status;
 
8486
+
 
8487
+       if (len > sizeof(*host->data)) {
 
8488
+               WARN_ON(1);
 
8489
+               return -EIO;
 
8490
+       }
 
8491
+
 
8492
+       host->status.len = len;
 
8493
+
 
8494
+       if (host->dma_dev)
 
8495
+               dma_sync_single_for_device(host->dma_dev,
 
8496
+                               host->data_dma, sizeof(*host->data),
 
8497
+                               DMA_FROM_DEVICE);
 
8498
+
 
8499
+       status = spi_sync(host->spi, &host->readback);
 
8500
+       if (status == 0)
 
8501
+               status = host->readback.status;
 
8502
+
 
8503
+       if (host->dma_dev)
 
8504
+               dma_sync_single_for_cpu(host->dma_dev,
 
8505
+                               host->data_dma, sizeof(*host->data),
 
8506
+                               DMA_FROM_DEVICE);
 
8507
+
 
8508
+       return status;
 
8509
+}
 
8510
+
 
8511
+static int
 
8512
+mmc_spi_skip(struct mmc_spi_host *host, ktime_t timeout, unsigned n, u8 byte)
 
8513
+{
 
8514
+       u8              *cp = host->data->status;
 
8515
+
 
8516
+       timeout = ktime_add(timeout, ktime_get());
 
8517
+
 
8518
+       while (1) {
 
8519
+               int             status;
 
8520
+               unsigned        i;
 
8521
+
 
8522
+               status = mmc_spi_readbytes(host, n);
 
8523
+               if (status < 0)
 
8524
+                       return status;
 
8525
+
 
8526
+               for (i = 0; i < n; i++) {
 
8527
+                       if (cp[i] != byte)
 
8528
+                               return cp[i];
 
8529
+               }
 
8530
+
 
8531
+               /* REVISIT investigate msleep() to avoid busy-wait I/O
 
8532
+                * in at least some cases.
 
8533
+                */
 
8534
+               if (ktime_to_ns(ktime_sub(ktime_get(), timeout)) > 0)
 
8535
+                       break;
 
8536
+       }
 
8537
+       return -ETIMEDOUT;
 
8538
+}
 
8539
+
 
8540
+static inline int
 
8541
+mmc_spi_wait_unbusy(struct mmc_spi_host *host, ktime_t timeout)
 
8542
+{
 
8543
+       return mmc_spi_skip(host, timeout, sizeof(host->data->status), 0);
 
8544
+}
 
8545
+
 
8546
+static int mmc_spi_readtoken(struct mmc_spi_host *host)
 
8547
+{
 
8548
+       return mmc_spi_skip(host, readblock_timeout, 1, 0xff);
 
8549
+}
 
8550
+
 
8551
+
 
8552
+/*
 
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.
 
8556
+ *
 
8557
+ * cmd->resp[1] holds any four-byte response, for R3 (READ_OCR) and on
 
8558
+ * newer cards R7 (IF_COND).
 
8559
+ */
 
8560
+
 
8561
+static char *maptype(struct mmc_command *cmd)
 
8562
+{
 
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 "?";
 
8569
+       }
 
8570
+}
 
8571
+
 
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)
 
8575
+{
 
8576
+       u8      *cp = host->data->status;
 
8577
+       u8      *end = cp + host->t.len;
 
8578
+       int     value = 0;
 
8579
+       char    tag[32];
 
8580
+
 
8581
+       snprintf(tag, sizeof(tag), "  ... CMD%d response SPI_%s",
 
8582
+               cmd->opcode, maptype(cmd));
 
8583
+
 
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.
 
8589
+        */
 
8590
+       cp += 8;
 
8591
+       while (cp < end && *cp == 0xff)
 
8592
+               cp++;
 
8593
+
 
8594
+       /* Data block reads (R1 response types) may need more data... */
 
8595
+       if (cp == end) {
 
8596
+               unsigned        i;
 
8597
+
 
8598
+               cp = host->data->status;
 
8599
+
 
8600
+               /* Card sends N(CR) (== 1..8) bytes of all-ones then one
 
8601
+                * status byte ... and we already scanned 2 bytes.
 
8602
+                *
 
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...
 
8607
+                */
 
8608
+               for (i = 2; i < 9; i++) {
 
8609
+                       value = mmc_spi_readbytes(host, 1);
 
8610
+                       if (value < 0)
 
8611
+                               goto done;
 
8612
+                       if (*cp != 0xff)
 
8613
+                               goto checkstatus;
 
8614
+               }
 
8615
+               value = -ETIMEDOUT;
 
8616
+               goto done;
 
8617
+       }
 
8618
+
 
8619
+checkstatus:
 
8620
+       if (*cp & 0x80) {
 
8621
+               dev_dbg(&host->spi->dev, "%s: INVALID RESPONSE, %02x\n",
 
8622
+                                       tag, *cp);
 
8623
+               value = -EBADR;
 
8624
+               goto done;
 
8625
+       }
 
8626
+
 
8627
+       cmd->resp[0] = *cp++;
 
8628
+       cmd->error = 0;
 
8629
+
 
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)
 
8634
+                               & cmd->resp[0])
 
8635
+                       value = -EINVAL;
 
8636
+               else if (R1_SPI_COM_CRC & cmd->resp[0])
 
8637
+                       value = -EILSEQ;
 
8638
+               else if ((R1_SPI_ERASE_SEQ | R1_SPI_ERASE_RESET)
 
8639
+                               & cmd->resp[0])
 
8640
+                       value = -EIO;
 
8641
+               /* else R1_SPI_IDLE, "it's resetting" */
 
8642
+       }
 
8643
+
 
8644
+       switch (mmc_spi_resp_type(cmd)) {
 
8645
+
 
8646
+       /* SPI R1B == R1 + busy; STOP_TRANSMISSION (for multiblock reads)
 
8647
+        * and less-common stuff like various erase operations.
 
8648
+        */
 
8649
+       case MMC_RSP_SPI_R1B:
 
8650
+               /* maybe we read all the busy tokens already */
 
8651
+               while (cp < end && *cp == 0)
 
8652
+                       cp++;
 
8653
+               if (cp == end)
 
8654
+                       mmc_spi_wait_unbusy(host, r1b_timeout);
 
8655
+               break;
 
8656
+
 
8657
+       /* SPI R2 == R1 + second status byte; SEND_STATUS
 
8658
+        * SPI R5 == R1 + data byte; IO_RW_DIRECT
 
8659
+        */
 
8660
+       case MMC_RSP_SPI_R2:
 
8661
+               cmd->resp[0] |= *cp << 8;
 
8662
+               break;
 
8663
+
 
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));
 
8667
+               break;
 
8668
+
 
8669
+       /* SPI R1 == just one status byte */
 
8670
+       case MMC_RSP_SPI_R1:
 
8671
+               break;
 
8672
+
 
8673
+       default:
 
8674
+               dev_dbg(&host->spi->dev, "bad response type %04x\n",
 
8675
+                               mmc_spi_resp_type(cmd));
 
8676
+               if (value >= 0)
 
8677
+                       value = -EINVAL;
 
8678
+               goto done;
 
8679
+       }
 
8680
+
 
8681
+       if (value < 0)
 
8682
+               dev_dbg(&host->spi->dev, "%s: resp %04x %08x\n",
 
8683
+                       tag, cmd->resp[0], cmd->resp[1]);
 
8684
+
 
8685
+       /* disable chipselect on errors and some success cases */
 
8686
+       if (value >= 0 && cs_on)
 
8687
+               return value;
 
8688
+done:
 
8689
+       if (value < 0)
 
8690
+               cmd->error = value;
 
8691
+       mmc_cs_off(host);
 
8692
+       return value;
 
8693
+}
 
8694
+
 
8695
+/* Issue command and read its response.
 
8696
+ * Returns zero on success, negative for error.
 
8697
+ *
 
8698
+ * On error, caller must cope with mmc core retry mechanism.  That
 
8699
+ * means immediate low-level resubmit, which affects the bus lock...
 
8700
+ */
 
8701
+static int
 
8702
+mmc_spi_command_send(struct mmc_spi_host *host,
 
8703
+               struct mmc_request *mrq,
 
8704
+               struct mmc_command *cmd, int cs_on)
 
8705
+{
 
8706
+       struct scratch          *data = host->data;
 
8707
+       u8                      *cp = data->status;
 
8708
+       u32                     arg = cmd->arg;
 
8709
+       int                     status;
 
8710
+       struct spi_transfer     *t;
 
8711
+
 
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.
 
8715
+        *
 
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
 
8721
+        *
 
8722
+        * We init the whole buffer to all-ones, which is what we need
 
8723
+        * to write while we're reading (later) response data.
 
8724
+        */
 
8725
+       memset(cp++, 0xff, sizeof(data->status));
 
8726
+
 
8727
+       *cp++ = 0x40 | cmd->opcode;
 
8728
+       *cp++ = (u8)(arg >> 24);
 
8729
+       *cp++ = (u8)(arg >> 16);
 
8730
+       *cp++ = (u8)(arg >> 8);
 
8731
+       *cp++ = (u8)arg;
 
8732
+       *cp++ = (crc7(0, &data->status[1], 5) << 1) | 0x01;
 
8733
+
 
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
 
8741
+        *
 
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
 
8747
+        *
 
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).
 
8752
+        *
 
8753
+        * There are two other cases, where it's not generally practical
 
8754
+        * to rely on a single I/O:
 
8755
+        *
 
8756
+        *  - R1B responses need at least N(EC) bytes of all-zeroes.
 
8757
+        *
 
8758
+        *    In this case we can *try* to fit it into one I/O, then
 
8759
+        *    maybe read more data later.
 
8760
+        *
 
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
 
8765
+        *
 
8766
+        *    In this case we currently only have minimal speedups here:
 
8767
+        *    when N(CR) == 1 we can avoid I/O in response_get().
 
8768
+        */
 
8769
+       if (cs_on && (mrq->data->flags & MMC_DATA_READ)) {
 
8770
+               cp += 2;        /* min(N(CR)) + status */
 
8771
+               /* R1 */
 
8772
+       } else {
 
8773
+               cp += 10;       /* max(N(CR)) + status + min(N(RC),N(WR)) */
 
8774
+               if (cmd->flags & MMC_RSP_SPI_S2)        /* R2/R5 */
 
8775
+                       cp++;
 
8776
+               else if (cmd->flags & MMC_RSP_SPI_B4)   /* R3/R4/R7 */
 
8777
+                       cp += 4;
 
8778
+               else if (cmd->flags & MMC_RSP_BUSY)     /* R1B */
 
8779
+                       cp = data->status + sizeof(data->status);
 
8780
+               /* else:  R1 (most commands) */
 
8781
+       }
 
8782
+
 
8783
+       dev_dbg(&host->spi->dev, "  mmc_spi: CMD%d, resp %s\n",
 
8784
+               cmd->opcode, maptype(cmd));
 
8785
+
 
8786
+       /* send command, leaving chipselect active */
 
8787
+       spi_message_init(&host->m);
 
8788
+
 
8789
+       t = &host->t;
 
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;
 
8794
+       t->cs_change = 1;
 
8795
+       spi_message_add_tail(t, &host->m);
 
8796
+
 
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);
 
8802
+       }
 
8803
+       status = spi_sync(host->spi, &host->m);
 
8804
+       if (status == 0)
 
8805
+               status = host->m.status;
 
8806
+
 
8807
+       if (host->dma_dev)
 
8808
+               dma_sync_single_for_cpu(host->dma_dev,
 
8809
+                               host->data_dma, sizeof(*host->data),
 
8810
+                               DMA_BIDIRECTIONAL);
 
8811
+       if (status < 0) {
 
8812
+               dev_dbg(&host->spi->dev, "  ... write returned %d\n", status);
 
8813
+               cmd->error = status;
 
8814
+               return status;
 
8815
+       }
 
8816
+
 
8817
+       /* after no-data commands and STOP_TRANSMISSION, chipselect off */
 
8818
+       return mmc_spi_response_get(host, cmd, cs_on);
 
8819
+}
 
8820
+
 
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.
 
8824
+ *
 
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.
 
8828
+ *
 
8829
+ * We also handle DMA mapping, so the underlying SPI controller does
 
8830
+ * not need to (re)do it for each message.
 
8831
+ */
 
8832
+static void
 
8833
+mmc_spi_setup_data_message(
 
8834
+       struct mmc_spi_host     *host,
 
8835
+       int                     multiple,
 
8836
+       enum dma_data_direction direction)
 
8837
+{
 
8838
+       struct spi_transfer     *t;
 
8839
+       struct scratch          *scratch = host->data;
 
8840
+       dma_addr_t              dma = host->data_dma;
 
8841
+
 
8842
+       spi_message_init(&host->m);
 
8843
+       if (dma)
 
8844
+               host->m.is_dma_mapped = 1;
 
8845
+
 
8846
+       /* for reads, readblock() skips 0xff bytes before finding
 
8847
+        * the token; for writes, this transfer issues that token.
 
8848
+        */
 
8849
+       if (direction == DMA_TO_DEVICE) {
 
8850
+               t = &host->token;
 
8851
+               memset(t, 0, sizeof(*t));
 
8852
+               t->len = 1;
 
8853
+               if (multiple)
 
8854
+                       scratch->data_token = SPI_TOKEN_MULTI_WRITE;
 
8855
+               else
 
8856
+                       scratch->data_token = SPI_TOKEN_SINGLE;
 
8857
+               t->tx_buf = &scratch->data_token;
 
8858
+               if (dma)
 
8859
+                       t->tx_dma = dma + offsetof(struct scratch, data_token);
 
8860
+               spi_message_add_tail(t, &host->m);
 
8861
+       }
 
8862
+
 
8863
+       /* Body of transfer is buffer, then CRC ...
 
8864
+        * either TX-only, or RX with TX-ones.
 
8865
+        */
 
8866
+       t = &host->t;
 
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);
 
8872
+
 
8873
+       t = &host->crc;
 
8874
+       memset(t, 0, sizeof(*t));
 
8875
+       t->len = 2;
 
8876
+       if (direction == DMA_TO_DEVICE) {
 
8877
+               /* the actual CRC may get written later */
 
8878
+               t->tx_buf = &scratch->crc_val;
 
8879
+               if (dma)
 
8880
+                       t->tx_dma = dma + offsetof(struct scratch, crc_val);
 
8881
+       } else {
 
8882
+               t->tx_buf = host->ones;
 
8883
+               t->tx_dma = host->ones_dma;
 
8884
+               t->rx_buf = &scratch->crc_val;
 
8885
+               if (dma)
 
8886
+                       t->rx_dma = dma + offsetof(struct scratch, crc_val);
 
8887
+       }
 
8888
+       spi_message_add_tail(t, &host->m);
 
8889
+
 
8890
+       /*
 
8891
+        * A single block read is followed by N(EC) [0+] all-ones bytes
 
8892
+        * before deselect ... don't bother.
 
8893
+        *
 
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.
 
8897
+        *
 
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.
 
8903
+        */
 
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)
 
8909
+                               : 1;
 
8910
+               t->tx_buf = host->ones;
 
8911
+               t->tx_dma = host->ones_dma;
 
8912
+               t->rx_buf = scratch->status;
 
8913
+               if (dma)
 
8914
+                       t->rx_dma = dma + offsetof(struct scratch, status);
 
8915
+               t->cs_change = 1;
 
8916
+               spi_message_add_tail(t, &host->m);
 
8917
+       }
 
8918
+}
 
8919
+
 
8920
+/*
 
8921
+ * Write one block:
 
8922
+ *  - caller handled preceding N(WR) [1+] all-ones bytes
 
8923
+ *  - data block
 
8924
+ *     + token
 
8925
+ *     + data bytes
 
8926
+ *     + crc16
 
8927
+ *  - an all-ones byte ... card writes a data-response byte
 
8928
+ *  - followed by N(EC) [0+] all-ones bytes, card writes zero/'busy'
 
8929
+ *
 
8930
+ * Return negative errno, else success.
 
8931
+ */
 
8932
+static int
 
8933
+mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t)
 
8934
+{
 
8935
+       struct spi_device       *spi = host->spi;
 
8936
+       int                     status, i;
 
8937
+       struct scratch          *scratch = host->data;
 
8938
+
 
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);
 
8946
+
 
8947
+       status = spi_sync(spi, &host->m);
 
8948
+       if (status == 0)
 
8949
+               status = host->m.status;
 
8950
+
 
8951
+       if (status != 0) {
 
8952
+               dev_dbg(&spi->dev, "write error (%d)\n", status);
 
8953
+               return status;
 
8954
+       }
 
8955
+
 
8956
+       if (host->dma_dev)
 
8957
+               dma_sync_single_for_cpu(host->dma_dev,
 
8958
+                               host->data_dma, sizeof(*scratch),
 
8959
+                               DMA_BIDIRECTIONAL);
 
8960
+
 
8961
+       /*
 
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.
 
8967
+        */
 
8968
+       switch (SPI_MMC_RESPONSE_CODE(scratch->status[0])) {
 
8969
+       case SPI_RESPONSE_ACCEPTED:
 
8970
+               status = 0;
 
8971
+               break;
 
8972
+       case SPI_RESPONSE_CRC_ERR:
 
8973
+               /* host shall then issue MMC_STOP_TRANSMISSION */
 
8974
+               status = -EILSEQ;
 
8975
+               break;
 
8976
+       case SPI_RESPONSE_WRITE_ERR:
 
8977
+               /* host shall then issue MMC_STOP_TRANSMISSION,
 
8978
+                * and should MMC_SEND_STATUS to sort it out
 
8979
+                */
 
8980
+               status = -EIO;
 
8981
+               break;
 
8982
+       default:
 
8983
+               status = -EPROTO;
 
8984
+               break;
 
8985
+       }
 
8986
+       if (status != 0) {
 
8987
+               dev_dbg(&spi->dev, "write error %02x (%d)\n",
 
8988
+                       scratch->status[0], status);
 
8989
+               return status;
 
8990
+       }
 
8991
+
 
8992
+       t->tx_buf += t->len;
 
8993
+       if (host->dma_dev)
 
8994
+               t->tx_dma += t->len;
 
8995
+
 
8996
+       /* Return when not busy.  If we didn't collect that status yet,
 
8997
+        * we'll need some more I/O.
 
8998
+        */
 
8999
+       for (i = 1; i < sizeof(scratch->status); i++) {
 
9000
+               if (scratch->status[i] != 0)
 
9001
+                       return 0;
 
9002
+       }
 
9003
+       return mmc_spi_wait_unbusy(host, writeblock_timeout);
 
9004
+}
 
9005
+
 
9006
+/*
 
9007
+ * Read one block:
 
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
 
9011
+ *  - data block
 
9012
+ *     + token ... if error token, no data or crc
 
9013
+ *     + data bytes
 
9014
+ *     + crc16
 
9015
+ *
 
9016
+ * After single block reads, we're done; N(EC) [0+] all-ones bytes follow
 
9017
+ * before dropping chipselect.
 
9018
+ *
 
9019
+ * For multiblock reads, caller either reads the next block or issues a
 
9020
+ * STOP_TRANSMISSION command.
 
9021
+ */
 
9022
+static int
 
9023
+mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t)
 
9024
+{
 
9025
+       struct spi_device       *spi = host->spi;
 
9026
+       int                     status;
 
9027
+       struct scratch          *scratch = host->data;
 
9028
+
 
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.
 
9031
+        */
 
9032
+       status = mmc_spi_readbytes(host, 1);
 
9033
+       if (status < 0)
 
9034
+               return status;
 
9035
+       status = scratch->status[0];
 
9036
+       if (status == 0xff || status == 0)
 
9037
+               status = mmc_spi_readtoken(host);
 
9038
+
 
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,
 
9046
+                                       DMA_FROM_DEVICE);
 
9047
+               }
 
9048
+
 
9049
+               status = spi_sync(spi, &host->m);
 
9050
+               if (status == 0)
 
9051
+                       status = host->m.status;
 
9052
+
 
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,
 
9059
+                                       DMA_FROM_DEVICE);
 
9060
+               }
 
9061
+
 
9062
+       } else {
 
9063
+               dev_dbg(&spi->dev, "read error %02x (%d)\n", status, status);
 
9064
+
 
9065
+               /* we've read extra garbage, timed out, etc */
 
9066
+               if (status < 0)
 
9067
+                       return status;
 
9068
+
 
9069
+               /* low four bits are an R2 subset, fifth seems to be
 
9070
+                * vendor specific ... map them all to generic error..
 
9071
+                */
 
9072
+               return -EIO;
 
9073
+       }
 
9074
+
 
9075
+       if (host->mmc->use_spi_crc) {
 
9076
+               u16 crc = crc_itu_t(0, t->rx_buf, t->len);
 
9077
+
 
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);
 
9083
+                       return -EILSEQ;
 
9084
+               }
 
9085
+       }
 
9086
+
 
9087
+       t->rx_buf += t->len;
 
9088
+       if (host->dma_dev)
 
9089
+               t->rx_dma += t->len;
 
9090
+
 
9091
+       return 0;
 
9092
+}
 
9093
+
 
9094
+/*
 
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.
 
9098
+ */
 
9099
+static void
 
9100
+mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
 
9101
+               struct mmc_data *data, u32 blk_size)
 
9102
+{
 
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;
 
9108
+       unsigned                n_sg;
 
9109
+       int                     multiple = (data->blocks > 1);
 
9110
+
 
9111
+       if (data->flags & MMC_DATA_READ)
 
9112
+               direction = DMA_FROM_DEVICE;
 
9113
+       else
 
9114
+               direction = DMA_TO_DEVICE;
 
9115
+       mmc_spi_setup_data_message(host, multiple, direction);
 
9116
+       t = &host->t;
 
9117
+
 
9118
+       /* Handle scatterlist segments one at a time, with synch for
 
9119
+        * each 512-byte block
 
9120
+        */
 
9121
+       for (sg = data->sg, n_sg = data->sg_len; n_sg; n_sg--, sg++) {
 
9122
+               int                     status = 0;
 
9123
+               dma_addr_t              dma_addr = 0;
 
9124
+               void                    *kmap_addr;
 
9125
+               unsigned                length = sg->length;
 
9126
+               enum dma_data_direction dir = direction;
 
9127
+
 
9128
+               /* set up dma mapping for controller drivers that might
 
9129
+                * use DMA ... though they may fall back to PIO
 
9130
+                */
 
9131
+               if (dma_dev) {
 
9132
+                       /* never invalidate whole *shared* pages ... */
 
9133
+                       if ((sg->offset != 0 || length != PAGE_SIZE)
 
9134
+                                       && dir == DMA_FROM_DEVICE)
 
9135
+                               dir = DMA_BIDIRECTIONAL;
 
9136
+
 
9137
+                       dma_addr = dma_map_page(dma_dev, sg_page(sg), 0,
 
9138
+                                               PAGE_SIZE, dir);
 
9139
+                       if (direction == DMA_TO_DEVICE)
 
9140
+                               t->tx_dma = dma_addr + sg->offset;
 
9141
+                       else
 
9142
+                               t->rx_dma = dma_addr + sg->offset;
 
9143
+               }
 
9144
+
 
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;
 
9149
+               else
 
9150
+                       t->rx_buf = kmap_addr + sg->offset;
 
9151
+
 
9152
+               /* transfer each block, and update request status */
 
9153
+               while (length) {
 
9154
+                       t->len = min(length, blk_size);
 
9155
+
 
9156
+                       dev_dbg(&host->spi->dev,
 
9157
+                               "    mmc_spi: %s block, %d bytes\n",
 
9158
+                               (direction == DMA_TO_DEVICE)
 
9159
+                               ? "write"
 
9160
+                               : "read",
 
9161
+                               t->len);
 
9162
+
 
9163
+                       if (direction == DMA_TO_DEVICE)
 
9164
+                               status = mmc_spi_writeblock(host, t);
 
9165
+                       else
 
9166
+                               status = mmc_spi_readblock(host, t);
 
9167
+                       if (status < 0)
 
9168
+                               break;
 
9169
+
 
9170
+                       data->bytes_xfered += t->len;
 
9171
+                       length -= t->len;
 
9172
+
 
9173
+                       if (!multiple)
 
9174
+                               break;
 
9175
+               }
 
9176
+
 
9177
+               /* discard mappings */
 
9178
+               if (direction == DMA_FROM_DEVICE)
 
9179
+                       flush_kernel_dcache_page(sg_page(sg));
 
9180
+               kunmap(sg_page(sg));
 
9181
+               if (dma_dev)
 
9182
+                       dma_unmap_page(dma_dev, dma_addr, PAGE_SIZE, dir);
 
9183
+
 
9184
+               if (status < 0) {
 
9185
+                       data->error = status;
 
9186
+                       dev_dbg(&spi->dev, "%s status %d\n",
 
9187
+                               (direction == DMA_TO_DEVICE)
 
9188
+                                       ? "write" : "read",
 
9189
+                               status);
 
9190
+                       break;
 
9191
+               }
 
9192
+       }
 
9193
+
 
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.
 
9199
+        */
 
9200
+       if (direction == DMA_TO_DEVICE && multiple) {
 
9201
+               struct scratch  *scratch = host->data;
 
9202
+               int             tmp;
 
9203
+               const unsigned  statlen = sizeof(scratch->status);
 
9204
+
 
9205
+               dev_dbg(&spi->dev, "    mmc_spi: STOP_TRAN\n");
 
9206
+
 
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.
 
9211
+                */
 
9212
+               INIT_LIST_HEAD(&host->m.transfers);
 
9213
+               list_add(&host->early_status.transfer_list,
 
9214
+                               &host->m.transfers);
 
9215
+
 
9216
+               memset(scratch->status, 0xff, statlen);
 
9217
+               scratch->status[0] = SPI_TOKEN_STOP_TRAN;
 
9218
+
 
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;
 
9222
+
 
9223
+               if (host->dma_dev)
 
9224
+                       dma_sync_single_for_device(host->dma_dev,
 
9225
+                                       host->data_dma, sizeof(*scratch),
 
9226
+                                       DMA_BIDIRECTIONAL);
 
9227
+
 
9228
+               tmp = spi_sync(spi, &host->m);
 
9229
+               if (tmp == 0)
 
9230
+                       tmp = host->m.status;
 
9231
+
 
9232
+               if (host->dma_dev)
 
9233
+                       dma_sync_single_for_cpu(host->dma_dev,
 
9234
+                                       host->data_dma, sizeof(*scratch),
 
9235
+                                       DMA_BIDIRECTIONAL);
 
9236
+
 
9237
+               if (tmp < 0) {
 
9238
+                       if (!data->error)
 
9239
+                               data->error = tmp;
 
9240
+                       return;
 
9241
+               }
 
9242
+
 
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.
 
9246
+                */
 
9247
+               for (tmp = 2; tmp < statlen; tmp++) {
 
9248
+                       if (scratch->status[tmp] != 0)
 
9249
+                               return;
 
9250
+               }
 
9251
+               tmp = mmc_spi_wait_unbusy(host, writeblock_timeout);
 
9252
+               if (tmp < 0 && !data->error)
 
9253
+                       data->error = tmp;
 
9254
+       }
 
9255
+}
 
9256
+
 
9257
+/****************************************************************************/
 
9258
+
 
9259
+/*
 
9260
+ * MMC driver implementation -- the interface to the MMC stack
 
9261
+ */
 
9262
+
 
9263
+static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
9264
+{
 
9265
+       struct mmc_spi_host     *host = mmc_priv(mmc);
 
9266
+       int                     status = -EINVAL;
 
9267
+
 
9268
+#ifdef DEBUG
 
9269
+       /* MMC core and layered drivers *MUST* issue SPI-aware commands */
 
9270
+       {
 
9271
+               struct mmc_command      *cmd;
 
9272
+               int                     invalid = 0;
 
9273
+
 
9274
+               cmd = mrq->cmd;
 
9275
+               if (!mmc_spi_resp_type(cmd)) {
 
9276
+                       dev_dbg(&host->spi->dev, "bogus command\n");
 
9277
+                       cmd->error = -EINVAL;
 
9278
+                       invalid = 1;
 
9279
+               }
 
9280
+
 
9281
+               cmd = mrq->stop;
 
9282
+               if (cmd && !mmc_spi_resp_type(cmd)) {
 
9283
+                       dev_dbg(&host->spi->dev, "bogus STOP command\n");
 
9284
+                       cmd->error = -EINVAL;
 
9285
+                       invalid = 1;
 
9286
+               }
 
9287
+
 
9288
+               if (invalid) {
 
9289
+                       dump_stack();
 
9290
+                       mmc_request_done(host->mmc, mrq);
 
9291
+                       return;
 
9292
+               }
 
9293
+       }
 
9294
+#endif
 
9295
+
 
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);
 
9300
+               if (mrq->stop)
 
9301
+                       status = mmc_spi_command_send(host, mrq, mrq->stop, 0);
 
9302
+               else
 
9303
+                       mmc_cs_off(host);
 
9304
+       }
 
9305
+
 
9306
+       mmc_request_done(host->mmc, mrq);
 
9307
+}
 
9308
+
 
9309
+/* See Section 6.4.1, in SD "Simplified Physical Layer Specification 2.0"
 
9310
+ *
 
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.
 
9313
+ *
 
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...
 
9316
+ */
 
9317
+static void mmc_spi_initsequence(struct mmc_spi_host *host)
 
9318
+{
 
9319
+       /* Try to be very sure any previous command has completed;
 
9320
+        * wait till not-busy, skip debris from any old commands.
 
9321
+        */
 
9322
+       mmc_spi_wait_unbusy(host, r1b_timeout);
 
9323
+       mmc_spi_readbytes(host, 10);
 
9324
+
 
9325
+       /*
 
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.
 
9330
+        *
 
9331
+        * Some cards are particularly needy of this (e.g. Viking "SD256")
 
9332
+        * while most others don't seem to care.
 
9333
+        *
 
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.
 
9338
+        */
 
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;
 
9345
+       } else {
 
9346
+               mmc_spi_readbytes(host, 18);
 
9347
+
 
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");
 
9353
+               }
 
9354
+       }
 
9355
+}
 
9356
+
 
9357
+static char *mmc_powerstring(u8 power_mode)
 
9358
+{
 
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";
 
9363
+       }
 
9364
+       return "?";
 
9365
+}
 
9366
+
 
9367
+static void mmc_spi_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 
9368
+{
 
9369
+       struct mmc_spi_host *host = mmc_priv(mmc);
 
9370
+
 
9371
+       if (host->power_mode != ios->power_mode) {
 
9372
+               int             canpower;
 
9373
+
 
9374
+               canpower = host->pdata && host->pdata->setpower;
 
9375
+
 
9376
+               dev_dbg(&host->spi->dev, "mmc_spi: power %s (%d)%s\n",
 
9377
+                               mmc_powerstring(ios->power_mode),
 
9378
+                               ios->vdd,
 
9379
+                               canpower ? ", can switch" : "");
 
9380
+
 
9381
+               /* switch power on/off if possible, accounting for
 
9382
+                * max 250msec powerup time if needed.
 
9383
+                */
 
9384
+               if (canpower) {
 
9385
+                       switch (ios->power_mode) {
 
9386
+                       case MMC_POWER_OFF:
 
9387
+                       case MMC_POWER_UP:
 
9388
+                               host->pdata->setpower(&host->spi->dev,
 
9389
+                                               ios->vdd);
 
9390
+                               if (ios->power_mode == MMC_POWER_UP)
 
9391
+                                       msleep(host->powerup_msecs);
 
9392
+                       }
 
9393
+               }
 
9394
+
 
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);
 
9398
+
 
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.
 
9403
+                *
 
9404
+                *   - Clock low means CPOL 0, e.g. mode 0
 
9405
+                *   - MOSI low comes from writing zero
 
9406
+                *   - Chipselect is usually active low...
 
9407
+                */
 
9408
+               if (canpower && ios->power_mode == MMC_POWER_OFF) {
 
9409
+                       int mres;
 
9410
+
 
9411
+                       host->spi->mode &= ~(SPI_CPOL|SPI_CPHA);
 
9412
+                       mres = spi_setup(host->spi);
 
9413
+                       if (mres < 0)
 
9414
+                               dev_dbg(&host->spi->dev,
 
9415
+                                       "switch to SPI mode 0 failed\n");
 
9416
+
 
9417
+                       if (spi_w8r8(host->spi, 0x00) < 0)
 
9418
+                               dev_dbg(&host->spi->dev,
 
9419
+                                       "put spi signals to low failed\n");
 
9420
+
 
9421
+                       /*
 
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!
 
9426
+                        *
 
9427
+                        * FIXME no, chipselect can be high since the
 
9428
+                        * device is inactive and SPI_CS_HIGH is clear...
 
9429
+                        */
 
9430
+                       msleep(10);
 
9431
+                       if (mres == 0) {
 
9432
+                               host->spi->mode |= (SPI_CPOL|SPI_CPHA);
 
9433
+                               mres = spi_setup(host->spi);
 
9434
+                               if (mres < 0)
 
9435
+                                       dev_dbg(&host->spi->dev,
 
9436
+                                               "switch back to SPI mode 3"
 
9437
+                                               " failed\n");
 
9438
+                       }
 
9439
+               }
 
9440
+
 
9441
+               host->power_mode = ios->power_mode;
 
9442
+       }
 
9443
+
 
9444
+       if (host->spi->max_speed_hz != ios->clock && ios->clock != 0) {
 
9445
+               int             status;
 
9446
+
 
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);
 
9452
+       }
 
9453
+}
 
9454
+
 
9455
+static int mmc_spi_get_ro(struct mmc_host *mmc)
 
9456
+{
 
9457
+       struct mmc_spi_host *host = mmc_priv(mmc);
 
9458
+
 
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 */
 
9462
+       return 0;
 
9463
+}
 
9464
+
 
9465
+
 
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,
 
9470
+};
 
9471
+
 
9472
+
 
9473
+/****************************************************************************/
 
9474
+
 
9475
+/*
 
9476
+ * SPI driver implementation
 
9477
+ */
 
9478
+
 
9479
+static irqreturn_t
 
9480
+mmc_spi_detect_irq(int irq, void *mmc)
 
9481
+{
 
9482
+       struct mmc_spi_host *host = mmc_priv(mmc);
 
9483
+       u16 delay_msec = max(host->pdata->detect_delay, (u16)100);
 
9484
+
 
9485
+       mmc_detect_change(mmc, msecs_to_jiffies(delay_msec));
 
9486
+       return IRQ_HANDLED;
 
9487
+}
 
9488
+
 
9489
+struct count_children {
 
9490
+       unsigned        n;
 
9491
+       struct bus_type *bus;
 
9492
+};
 
9493
+
 
9494
+static int maybe_count_child(struct device *dev, void *c)
 
9495
+{
 
9496
+       struct count_children *ccp = c;
 
9497
+
 
9498
+       if (dev->bus == ccp->bus) {
 
9499
+               if (ccp->n)
 
9500
+                       return -EBUSY;
 
9501
+               ccp->n++;
 
9502
+       }
 
9503
+       return 0;
 
9504
+}
 
9505
+
 
9506
+static int mmc_spi_probe(struct spi_device *spi)
 
9507
+{
 
9508
+       void                    *ones;
 
9509
+       struct mmc_host         *mmc;
 
9510
+       struct mmc_spi_host     *host;
 
9511
+       int                     status;
 
9512
+
 
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.
 
9517
+        */
 
9518
+       spi->mode = SPI_MODE_0;
 
9519
+       spi->bits_per_word = 8;
 
9520
+
 
9521
+       status = spi_setup(spi);
 
9522
+       if (status < 0) {
 
9523
+               dev_dbg(&spi->dev, "needs SPI mode %02x, %d KHz; %d\n",
 
9524
+                               spi->mode, spi->max_speed_hz / 1000,
 
9525
+                               status);
 
9526
+               return status;
 
9527
+       }
 
9528
+
 
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.
 
9534
+        *
 
9535
+        * Until we have software primitives which guarantee non-interference,
 
9536
+        * we'll aim for a hardware-level guarantee.
 
9537
+        *
 
9538
+        * REVISIT we can't guarantee another device won't be added later...
 
9539
+        */
 
9540
+       if (spi->master->num_chipselect > 1) {
 
9541
+               struct count_children cc;
 
9542
+
 
9543
+               cc.n = 0;
 
9544
+               cc.bus = spi->dev.bus;
 
9545
+               status = device_for_each_child(spi->dev.parent, &cc,
 
9546
+                               maybe_count_child);
 
9547
+               if (status < 0) {
 
9548
+                       dev_err(&spi->dev, "can't share SPI bus\n");
 
9549
+                       return status;
 
9550
+               }
 
9551
+
 
9552
+               dev_warn(&spi->dev, "ASSUMING SPI bus stays unshared!\n");
 
9553
+       }
 
9554
+
 
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.
 
9557
+        *
 
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.
 
9560
+        */
 
9561
+       status = -ENOMEM;
 
9562
+       ones = kmalloc(MMC_SPI_BLOCKSIZE, GFP_KERNEL);
 
9563
+       if (!ones)
 
9564
+               goto nomem;
 
9565
+       memset(ones, 0xff, MMC_SPI_BLOCKSIZE);
 
9566
+
 
9567
+       mmc = mmc_alloc_host(sizeof(*host), &spi->dev);
 
9568
+       if (!mmc)
 
9569
+               goto nomem;
 
9570
+
 
9571
+       mmc->ops = &mmc_spi_ops;
 
9572
+       mmc->max_blk_size = MMC_SPI_BLOCKSIZE;
 
9573
+
 
9574
+       /* As long as we keep track of the number of successfully
 
9575
+        * transmitted blocks, we're good for multiwrite.
 
9576
+        */
 
9577
+       mmc->caps = MMC_CAP_SPI | MMC_CAP_MULTIWRITE;
 
9578
+
 
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!
 
9582
+        *
 
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).
 
9586
+        */
 
9587
+       mmc->f_min = 400000;
 
9588
+       mmc->f_max = spi->max_speed_hz;
 
9589
+
 
9590
+       host = mmc_priv(mmc);
 
9591
+       host->mmc = mmc;
 
9592
+       host->spi = spi;
 
9593
+
 
9594
+       host->ones = ones;
 
9595
+
 
9596
+       /* Platform data is used to hook up things like card sensing
 
9597
+        * and power switching gpios.
 
9598
+        */
 
9599
+       host->pdata = spi->dev.platform_data;
 
9600
+       if (host->pdata)
 
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;
 
9605
+       }
 
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;
 
9610
+       }
 
9611
+
 
9612
+       dev_set_drvdata(&spi->dev, mmc);
 
9613
+
 
9614
+       /* preallocate dma buffers */
 
9615
+       host->data = kmalloc(sizeof(*host->data), GFP_KERNEL);
 
9616
+       if (!host->data)
 
9617
+               goto fail_nobuf1;
 
9618
+
 
9619
+       if (spi->master->dev.parent->dma_mask) {
 
9620
+               struct device   *dev = spi->master->dev.parent;
 
9621
+
 
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);
 
9627
+
 
9628
+               /* REVISIT in theory those map operations can fail... */
 
9629
+
 
9630
+               dma_sync_single_for_cpu(host->dma_dev,
 
9631
+                               host->data_dma, sizeof(*host->data),
 
9632
+                               DMA_BIDIRECTIONAL);
 
9633
+       }
 
9634
+
 
9635
+       /* setup message for status/busy readback */
 
9636
+       spi_message_init(&host->readback);
 
9637
+       host->readback.is_dma_mapped = (host->dma_dev != NULL);
 
9638
+
 
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;
 
9645
+
 
9646
+       /* register card detect irq */
 
9647
+       if (host->pdata && host->pdata->init) {
 
9648
+               status = host->pdata->init(&spi->dev, mmc_spi_detect_irq, mmc);
 
9649
+               if (status != 0)
 
9650
+                       goto fail_glue_init;
 
9651
+       }
 
9652
+
 
9653
+       status = mmc_add_host(mmc);
 
9654
+       if (status != 0)
 
9655
+               goto fail_add_host;
 
9656
+
 
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)
 
9661
+                               ? "" : ", no WP",
 
9662
+                       (host->pdata && host->pdata->setpower)
 
9663
+                               ? "" : ", no poweroff");
 
9664
+       return 0;
 
9665
+
 
9666
+fail_add_host:
 
9667
+       mmc_remove_host (mmc);
 
9668
+fail_glue_init:
 
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);
 
9673
+
 
9674
+fail_nobuf1:
 
9675
+       mmc_free_host(mmc);
 
9676
+       dev_set_drvdata(&spi->dev, NULL);
 
9677
+
 
9678
+nomem:
 
9679
+       kfree(ones);
 
9680
+       return status;
 
9681
+}
 
9682
+
 
9683
+
 
9684
+static int __devexit mmc_spi_remove(struct spi_device *spi)
 
9685
+{
 
9686
+       struct mmc_host         *mmc = dev_get_drvdata(&spi->dev);
 
9687
+       struct mmc_spi_host     *host;
 
9688
+
 
9689
+       if (mmc) {
 
9690
+               host = mmc_priv(mmc);
 
9691
+
 
9692
+               /* prevent new mmc_detect_change() calls */
 
9693
+               if (host->pdata && host->pdata->exit)
 
9694
+                       host->pdata->exit(&spi->dev, mmc);
 
9695
+
 
9696
+               mmc_remove_host(mmc);
 
9697
+
 
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);
 
9703
+               }
 
9704
+
 
9705
+               kfree(host->data);
 
9706
+               kfree(host->ones);
 
9707
+
 
9708
+               spi->max_speed_hz = mmc->f_max;
 
9709
+               mmc_free_host(mmc);
 
9710
+               dev_set_drvdata(&spi->dev, NULL);
 
9711
+       }
 
9712
+       return 0;
 
9713
+}
 
9714
+
 
9715
+
 
9716
+static struct spi_driver mmc_spi_driver = {
 
9717
+       .driver = {
 
9718
+               .name =         "mmc_spi",
 
9719
+               .bus =          &spi_bus_type,
 
9720
+               .owner =        THIS_MODULE,
 
9721
+       },
 
9722
+       .probe =        mmc_spi_probe,
 
9723
+       .remove =       __devexit_p(mmc_spi_remove),
 
9724
+};
 
9725
+
 
9726
+
 
9727
+static int __init mmc_spi_init(void)
 
9728
+{
 
9729
+       return spi_register_driver(&mmc_spi_driver);
 
9730
+}
 
9731
+module_init(mmc_spi_init);
 
9732
+
 
9733
+
 
9734
+static void __exit mmc_spi_exit(void)
 
9735
+{
 
9736
+       spi_unregister_driver(&mmc_spi_driver);
 
9737
+}
 
9738
+module_exit(mmc_spi_exit);
 
9739
+
 
9740
+
 
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
 
9749
@@ -1,5 +1,5 @@
 
9750
 /*
 
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
 
9753
  *
 
9754
  *  Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
 
9755
  *
 
9756
@@ -16,14 +16,15 @@
 
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>
 
9765
 
 
9766
 #include <asm/cacheflush.h>
 
9767
 #include <asm/div64.h>
 
9768
 #include <asm/io.h>
 
9769
-#include <asm/scatterlist.h>
 
9770
 #include <asm/sizes.h>
 
9771
 #include <asm/mach/mmc.h>
 
9772
 
 
9773
@@ -154,11 +155,11 @@ mmci_data_irq(struct mmci_host *host, struct mmc_data *data,
 
9774
        }
 
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;
 
9786
 
 
9787
                /*
 
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.
 
9790
                 */
 
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));
 
9794
        }
 
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);
 
9799
 
 
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;
 
9806
        }
 
9807
 
 
9808
-       if (!cmd->data || cmd->error != MMC_ERR_NONE) {
 
9809
+       if (!cmd->data || cmd->error) {
 
9810
                if (host->data)
 
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.
 
9815
                 */
 
9816
                if (status & MCI_RXACTIVE)
 
9817
-                       flush_dcache_page(host->sg_ptr->page);
 
9818
+                       flush_dcache_page(sg_page(host->sg_ptr));
 
9819
 
 
9820
                if (!mmci_next_sg(host))
 
9821
                        break;
 
9822
@@ -391,6 +392,14 @@ static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
9823
 
 
9824
        WARN_ON(host->mrq != NULL);
 
9825
 
 
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);
 
9831
+               return;
 
9832
+       }
 
9833
+
 
9834
        spin_lock_irq(&host->lock);
 
9835
 
 
9836
        host->mrq = mrq;
 
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
 
9841
@@ -1,5 +1,5 @@
 
9842
 /*
 
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
 
9845
  *
 
9846
  *  Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
 
9847
  *
 
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;
 
9850
 
 
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;
 
9854
 }
 
9855
 
 
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
 
9861
@@ -1,5 +1,5 @@
 
9862
 /*
 
9863
- *  linux/drivers/media/mmc/omap.c
 
9864
+ *  linux/drivers/mmc/host/omap.c
 
9865
  *
 
9866
  *  Copyright (C) 2004 Nokia Corporation
 
9867
  *  Written by Tuukka Tikkanen and Juha Yrj�l�<juha.yrjola@nokia.com>
 
9868
@@ -24,10 +24,10 @@
 
9869
 #include <linux/mmc/host.h>
 
9870
 #include <linux/mmc/card.h>
 
9871
 #include <linux/clk.h>
 
9872
+#include <linux/scatterlist.h>
 
9873
 
 
9874
 #include <asm/io.h>
 
9875
 #include <asm/irq.h>
 
9876
-#include <asm/scatterlist.h>
 
9877
 #include <asm/mach-types.h>
 
9878
 
 
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;
 
9882
 
 
9883
                BUG_ON(host->dma_ch < 0);
 
9884
-               if (data->error != MMC_ERR_NONE)
 
9885
+               if (data->error)
 
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)
 
9890
                }
 
9891
        }
 
9892
 
 
9893
-       if (host->data == NULL || cmd->error != MMC_ERR_NONE) {
 
9894
+       if (host->data == NULL || cmd->error) {
 
9895
                host->mrq = NULL;
 
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)
 
9899
 
 
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;
 
9906
 }
 
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");
 
9910
                        if (host->data) {
 
9911
-                               host->data->error |= MMC_ERR_TIMEOUT;
 
9912
+                               host->data->error = -ETIMEDOUT;
 
9913
                                transfer_error = 1;
 
9914
                        }
 
9915
                }
 
9916
 
 
9917
                if (status & OMAP_MMC_STAT_DATA_CRC) {
 
9918
                        if (host->data) {
 
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",
 
9927
                                                host->cmd->opcode);
 
9928
-                               host->cmd->error = MMC_ERR_TIMEOUT;
 
9929
+                               host->cmd->error = -ETIMEDOUT;
 
9930
                                end_command = 1;
 
9931
                        }
 
9932
                }
 
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;
 
9939
                                end_command = 1;
 
9940
                        } else
 
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
 
9946
@@ -1,5 +1,5 @@
 
9947
 /*
 
9948
- *  linux/drivers/mmc/pxa.c - PXA MMCI driver
 
9949
+ *  linux/drivers/mmc/host/pxa.c - PXA MMCI driver
 
9950
  *
 
9951
  *  Copyright (C) 2003 Russell King, All Rights Reserved.
 
9952
  *
 
9953
@@ -23,11 +23,12 @@
 
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>
 
9960
 
 
9961
 #include <asm/dma.h>
 
9962
 #include <asm/io.h>
 
9963
-#include <asm/scatterlist.h>
 
9964
 #include <asm/sizes.h>
 
9965
 
 
9966
 #include <asm/arch/pxa-regs.h>
 
9967
@@ -38,12 +39,15 @@
 
9968
 #define DRIVER_NAME    "pxa2xx-mci"
 
9969
 
 
9970
 #define NR_SG  1
 
9971
+#define CLKRT_OFF      (~0)
 
9972
 
 
9973
 struct pxamci_host {
 
9974
        struct mmc_host         *mmc;
 
9975
        spinlock_t              lock;
 
9976
        struct resource         *res;
 
9977
        void __iomem            *base;
 
9978
+       struct clk              *clk;
 
9979
+       unsigned long           clkrate;
 
9980
        int                     irq;
 
9981
        int                     dma;
 
9982
        unsigned int            clkrt;
 
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);
 
9986
 
 
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)
 
9993
                                   host->dma_dir);
 
9994
 
 
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;
 
10006
                }
 
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);
 
10010
        }
 
10011
@@ -226,7 +233,7 @@ static int pxamci_cmd_done(struct pxamci_host *host, unsigned int stat)
 
10012
        }
 
10013
 
 
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
 
10019
                /*
 
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);
 
10022
                } else
 
10023
 #endif
 
10024
-               cmd->error = MMC_ERR_BADCRC;
 
10025
+               cmd->error = -EILSEQ;
 
10026
        }
 
10027
 
 
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);
 
10032
        } else {
 
10033
                pxamci_finish_request(host, host->mrq);
 
10034
@@ -264,9 +271,9 @@ static int pxamci_data_done(struct pxamci_host *host, unsigned int stat)
 
10035
                     host->dma_dir);
 
10036
 
 
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;
 
10043
 
 
10044
        /*
 
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.
 
10049
         */
 
10050
-       if (data->error == MMC_ERR_NONE)
 
10051
+       if (!data->error)
 
10052
                data->bytes_xfered = data->blocks * data->blksz;
 
10053
        else
 
10054
                data->bytes_xfered = 0;
 
10055
@@ -284,7 +291,7 @@ static int pxamci_data_done(struct pxamci_host *host, unsigned int stat)
 
10056
        host->data = NULL;
 
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);
 
10061
        } else {
 
10062
                pxamci_finish_request(host, host->mrq);
 
10063
        }
 
10064
@@ -298,7 +305,7 @@ static irqreturn_t pxamci_irq(int irq, void *devid)
 
10065
        unsigned int ireg;
 
10066
        int handled = 0;
 
10067
 
 
10068
-       ireg = readl(host->base + MMC_I_REG);
 
10069
+       ireg = readl(host->base + MMC_I_REG) & ~readl(host->base + MMC_I_MASK);
 
10070
 
 
10071
        if (ireg) {
 
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);
 
10079
+                       handled = 1;
 
10080
+               }
 
10081
        }
 
10082
 
 
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);
 
10086
 
 
10087
        if (ios->clock) {
 
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;
 
10092
+
 
10093
+               if (host->clkrt == CLKRT_OFF)
 
10094
+                       clk_enable(host->clk);
 
10095
+
 
10096
+               /*
 
10097
+                * clk might result in a lower divisor than we
 
10098
+                * desire.  check for that condition and adjust
 
10099
+                * as appropriate.
 
10100
+                */
 
10101
+               if (rate / clk > ios->clock)
 
10102
                        clk <<= 1;
 
10103
                host->clkrt = fls(clk) - 1;
 
10104
-               pxa_set_cken(CKEN_MMC, 1);
 
10105
 
 
10106
                /*
 
10107
                 * we write clkrt on the next command
 
10108
                 */
 
10109
        } else {
 
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);
 
10115
+               }
 
10116
        }
 
10117
 
 
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;
 
10121
        }
 
10122
 
 
10123
+       if (ios->bus_width == MMC_BUS_WIDTH_4)
 
10124
+               host->cmdat |= CMDAT_SD_4DAT;
 
10125
+       else
 
10126
+               host->cmdat &= ~CMDAT_SD_4DAT;
 
10127
+
 
10128
        pr_debug("PXAMCI: clkrt = %x cmdat = %x\n",
 
10129
                 host->clkrt, host->cmdat);
 
10130
 }
 
10131
 
 
10132
+static void pxamci_enable_sdio_irq(struct mmc_host *host, int enable)
 
10133
+{
 
10134
+       struct pxamci_host *pxa_host = mmc_priv(host);
 
10135
+
 
10136
+       if (enable)
 
10137
+               pxamci_enable_irq(pxa_host, SDIO_INT);
 
10138
+       else
 
10139
+               pxamci_disable_irq(pxa_host, SDIO_INT);
 
10140
+}
 
10141
+
 
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,
 
10150
 };
 
10151
 
 
10152
 static void pxamci_dma_irq(int dma, void *devid)
 
10153
 {
 
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;
 
10159
+
 
10160
+       if (dcsr & DCSR_ENDINTR) {
 
10161
+               writel(BUF_PART_FULL, host->base + MMC_PRTBUF);
 
10162
+       } else {
 
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);
 
10167
+       }
 
10168
 }
 
10169
 
 
10170
 static irqreturn_t pxamci_detect_irq(int irq, void *devid)
 
10171
@@ -429,8 +478,6 @@ static int pxamci_probe(struct platform_device *pdev)
 
10172
        }
 
10173
 
 
10174
        mmc->ops = &pxamci_ops;
 
10175
-       mmc->f_min = CLOCKRATE_MIN;
 
10176
-       mmc->f_max = CLOCKRATE_MAX;
 
10177
 
 
10178
        /*
 
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;
 
10182
 
 
10183
        /*
 
10184
-        * Block length register is 10 bits.
 
10185
+        * Block length register is only 10 bits before PXA27x.
 
10186
         */
 
10187
-       mmc->max_blk_size = 1023;
 
10188
+       mmc->max_blk_size = (cpu_is_pxa21x() || cpu_is_pxa25x()) ? 1023 : 2048;
 
10189
 
 
10190
        /*
 
10191
         * Block count register is 16 bits.
 
10192
@@ -457,9 +504,32 @@ static int pxamci_probe(struct platform_device *pdev)
 
10193
        host->mmc = mmc;
 
10194
        host->dma = -1;
 
10195
        host->pdata = pdev->dev.platform_data;
 
10196
+       host->clkrt = CLKRT_OFF;
 
10197
+
 
10198
+       host->clk = clk_get(&pdev->dev, "MMCCLK");
 
10199
+       if (IS_ERR(host->clk)) {
 
10200
+               ret = PTR_ERR(host->clk);
 
10201
+               host->clk = NULL;
 
10202
+               goto out;
 
10203
+       }
 
10204
+
 
10205
+       host->clkrate = clk_get_rate(host->clk);
 
10206
+
 
10207
+       /*
 
10208
+        * Calculate minimum clock rate, rounding up.
 
10209
+        */
 
10210
+       mmc->f_min = (host->clkrate + 63) / 64;
 
10211
+       mmc->f_max = host->clkrate;
 
10212
+
 
10213
        mmc->ocr_avail = host->pdata ?
 
10214
                         host->pdata->ocr_mask :
 
10215
                         MMC_VDD_32_33|MMC_VDD_33_34;
 
10216
+       mmc->caps = 0;
 
10217
+       host->cmdat = 0;
 
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;
 
10221
+       }
 
10222
 
 
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);
 
10227
                if (host->sg_cpu)
 
10228
                        dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma);
 
10229
+               if (host->clk)
 
10230
+                       clk_put(host->clk);
 
10231
        }
 
10232
        if (mmc)
 
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);
 
10237
 
 
10238
+               clk_put(host->clk);
 
10239
+
 
10240
                release_resource(host->res);
 
10241
 
 
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
 
10247
@@ -1,25 +1,3 @@
 
10248
-#undef MMC_STRPCL
 
10249
-#undef MMC_STAT
 
10250
-#undef MMC_CLKRT
 
10251
-#undef MMC_SPI
 
10252
-#undef MMC_CMDAT
 
10253
-#undef MMC_RESTO
 
10254
-#undef MMC_RDTO
 
10255
-#undef MMC_BLKLEN
 
10256
-#undef MMC_NOB
 
10257
-#undef MMC_PRTBUF
 
10258
-#undef MMC_I_MASK
 
10259
-#undef END_CMD_RES
 
10260
-#undef PRG_DONE
 
10261
-#undef DATA_TRAN_DONE
 
10262
-#undef MMC_I_REG
 
10263
-#undef MMC_CMD
 
10264
-#undef MMC_ARGH
 
10265
-#undef MMC_ARGL
 
10266
-#undef MMC_RES
 
10267
-#undef MMC_RXFIFO
 
10268
-#undef MMC_TXFIFO
 
10269
-
 
10270
 #define MMC_STRPCL     0x0000
 
10271
 #define STOP_CLOCK             (1 << 0)
 
10272
 #define START_CLOCK            (2 << 0)
 
10273
@@ -47,6 +25,8 @@
 
10274
 #define SPI_EN                 (1 << 0)
 
10275
 
 
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 */
 
10284
 
 
10285
 #define MMC_TXFIFO     0x0044  /* 8 bit */
 
10286
-
 
10287
-/*
 
10288
- * The base MMC clock rate
 
10289
- */
 
10290
-#ifdef CONFIG_PXA27x
 
10291
-#define CLOCKRATE_MIN  304688
 
10292
-#define CLOCKRATE_MAX  19500000
 
10293
-#else
 
10294
-#define CLOCKRATE_MIN  312500
 
10295
-#define CLOCKRATE_MAX  20000000
 
10296
-#endif
 
10297
-
 
10298
-#define CLOCKRATE      CLOCKRATE_MAX
 
10299
-
 
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
 
10303
--- /dev/null
 
10304
+++ b/drivers/mmc/host/ricoh_mmc.c
 
10305
@@ -0,0 +1,151 @@
 
10306
+/*
 
10307
+ *  ricoh_mmc.c - Dummy driver to disable the Rioch MMC controller.
 
10308
+ *
 
10309
+ *  Copyright (C) 2007 Philip Langdale, All Rights Reserved.
 
10310
+ *
 
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.
 
10315
+ */
 
10316
+
 
10317
+/*
 
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
 
10327
+ * in the reader.
 
10328
+ *
 
10329
+ * The relevant registers live on the firewire function, so this is unavoidably
 
10330
+ * ugly. Such is life.
 
10331
+ */
 
10332
+
 
10333
+#include <linux/pci.h>
 
10334
+
 
10335
+#define DRIVER_NAME "ricoh-mmc"
 
10336
+
 
10337
+static const struct pci_device_id pci_ids[] __devinitdata = {
 
10338
+       {
 
10339
+               .vendor         = PCI_VENDOR_ID_RICOH,
 
10340
+               .device         = PCI_DEVICE_ID_RICOH_R5C843,
 
10341
+               .subvendor      = PCI_ANY_ID,
 
10342
+               .subdevice      = PCI_ANY_ID,
 
10343
+       },
 
10344
+       { /* end: all zeroes */ },
 
10345
+};
 
10346
+
 
10347
+MODULE_DEVICE_TABLE(pci, pci_ids);
 
10348
+
 
10349
+static int __devinit ricoh_mmc_probe(struct pci_dev *pdev,
 
10350
+                                    const struct pci_device_id *ent)
 
10351
+{
 
10352
+       u8 rev;
 
10353
+
 
10354
+       struct pci_dev *fw_dev = NULL;
 
10355
+
 
10356
+       BUG_ON(pdev == NULL);
 
10357
+       BUG_ON(ent == NULL);
 
10358
+
 
10359
+       pci_read_config_byte(pdev, PCI_CLASS_REVISION, &rev);
 
10360
+
 
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,
 
10364
+               (int)rev);
 
10365
+
 
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) {
 
10369
+                       u8 write_enable;
 
10370
+                       u8 disable;
 
10371
+
 
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");
 
10376
+                               return -ENODEV;
 
10377
+                       }
 
10378
+
 
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);
 
10383
+
 
10384
+                       pci_set_drvdata(pdev, fw_dev);
 
10385
+
 
10386
+                       printk(KERN_INFO DRIVER_NAME
 
10387
+                              ": Controller is now disabled.\n");
 
10388
+
 
10389
+                       break;
 
10390
+               }
 
10391
+       }
 
10392
+
 
10393
+       if (pci_get_drvdata(pdev) == NULL) {
 
10394
+               printk(KERN_WARNING DRIVER_NAME
 
10395
+                      ": Main firewire function not found. Cannot disable controller.\n");
 
10396
+               return -ENODEV;
 
10397
+       }
 
10398
+
 
10399
+       return 0;
 
10400
+}
 
10401
+
 
10402
+static void __devexit ricoh_mmc_remove(struct pci_dev *pdev)
 
10403
+{
 
10404
+       u8 write_enable;
 
10405
+       u8 disable;
 
10406
+       struct pci_dev *fw_dev = NULL;
 
10407
+
 
10408
+       fw_dev = pci_get_drvdata(pdev);
 
10409
+       BUG_ON(fw_dev == NULL);
 
10410
+
 
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);
 
10416
+
 
10417
+       printk(KERN_INFO DRIVER_NAME
 
10418
+              ": Controller is now re-enabled.\n");
 
10419
+
 
10420
+       pci_set_drvdata(pdev, NULL);
 
10421
+}
 
10422
+
 
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),
 
10428
+};
 
10429
+
 
10430
+/*****************************************************************************\
 
10431
+ *                                                                           *
 
10432
+ * Driver init/exit                                                          *
 
10433
+ *                                                                           *
 
10434
+\*****************************************************************************/
 
10435
+
 
10436
+static int __init ricoh_mmc_drv_init(void)
 
10437
+{
 
10438
+       printk(KERN_INFO DRIVER_NAME
 
10439
+               ": Ricoh MMC Controller disabling driver\n");
 
10440
+       printk(KERN_INFO DRIVER_NAME ": Copyright(c) Philip Langdale\n");
 
10441
+
 
10442
+       return pci_register_driver(&ricoh_mmc_driver);
 
10443
+}
 
10444
+
 
10445
+static void __exit ricoh_mmc_drv_exit(void)
 
10446
+{
 
10447
+       pci_unregister_driver(&ricoh_mmc_driver);
 
10448
+}
 
10449
+
 
10450
+module_init(ricoh_mmc_drv_init);
 
10451
+module_exit(ricoh_mmc_drv_exit);
 
10452
+
 
10453
+MODULE_AUTHOR("Philip Langdale <philipl@alumni.utexas.net>");
 
10454
+MODULE_DESCRIPTION("Ricoh MMC Controller disabling driver");
 
10455
+MODULE_LICENSE("GPL");
 
10456
+
 
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
 
10461
@@ -1,5 +1,5 @@
 
10462
 /*
 
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
 
10465
  *
 
10466
  *  Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
 
10467
  *
 
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>
 
10473
 
 
10474
 #include <linux/mmc/host.h>
 
10475
 
 
10476
-#include <asm/scatterlist.h>
 
10477
-
 
10478
 #include "sdhci.h"
 
10479
 
 
10480
+/* add by feng */
 
10481
+//#include <linux/mmc/core.h>
 
10482
+
 
10483
 #define DRIVER_NAME "sdhci"
 
10484
 
 
10485
 #define DBG(f, x...) \
 
10486
        pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
 
10487
 
 
10488
-static unsigned int debug_nodma = 0;
 
10489
-static unsigned int debug_forcedma = 0;
 
10490
 static unsigned int debug_quirks = 0;
 
10491
 
 
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)
 
10498
 
 
10499
 static const struct pci_device_id pci_ids[] __devinitdata = {
 
10500
        {
 
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,
 
10508
+       },
 
10509
+
 
10510
+       {
 
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,
 
10517
+       },
 
10518
+
 
10519
+       {
 
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,
 
10526
+       },
 
10527
+
 
10528
+       {
 
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,
 
10535
        },
 
10536
 
 
10537
        {
 
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)
 
10548
        if (data == NULL)
 
10549
                return;
 
10550
 
 
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);
 
10555
-
 
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);
 
10560
 
 
10561
+       host->data = data;
 
10562
+       host->data_early = 0;
 
10563
+
 
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,
 
10568
 {
 
10569
        u16 mode;
 
10570
 
 
10571
-       WARN_ON(host->data);
 
10572
-
 
10573
        if (data == NULL)
 
10574
                return;
 
10575
 
 
10576
+       WARN_ON(!host->data);
 
10577
+
 
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)
 
10582
        /*
 
10583
         * Controller doesn't count down when in single block mode.
 
10584
         */
 
10585
-       if ((data->blocks == 1) && (data->error == MMC_ERR_NONE))
 
10586
-               blocks = 0;
 
10587
+       if (data->blocks == 1)
 
10588
+               blocks = (data->error == 0) ? 0 : 1;
 
10589
        else
 
10590
                blocks = readw(host->ioaddr + SDHCI_BLOCK_COUNT);
 
10591
        data->bytes_xfered = data->blksz * (data->blocks - blocks);
 
10592
 
 
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;
 
10600
        }
 
10601
 
 
10602
-       DBG("Ending data transfer (%d bytes)\n", data->bytes_xfered);
 
10603
-
 
10604
        if (data->stop) {
 
10605
                /*
 
10606
                 * The controller needs a reset of internal state machines
 
10607
                 * upon error conditions.
 
10608
                 */
 
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);
 
10613
                }
 
10614
@@ -520,8 +545,6 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
 
10615
 
 
10616
        WARN_ON(host->cmd);
 
10617
 
 
10618
-       DBG("Sending cmd (%x)\n", cmd->opcode);
 
10619
-
 
10620
        /* Wait max 10 ms */
 
10621
        timeout = 10;
 
10622
 
 
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);
 
10630
                        return;
 
10631
                }
 
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);
 
10639
                return;
 
10640
        }
 
10641
@@ -607,13 +630,12 @@ static void sdhci_finish_command(struct sdhci_host *host)
 
10642
                }
 
10643
        }
 
10644
 
 
10645
-       host->cmd->error = MMC_ERR_NONE;
 
10646
+       host->cmd->error = 0;
 
10647
 
 
10648
-       DBG("Ending cmd (%x)\n", host->cmd->opcode);
 
10649
+       if (host->data && host->data_early)
 
10650
+               sdhci_finish_data(host);
 
10651
 
 
10652
-       if (host->cmd->data)
 
10653
-               host->data = host->cmd->data;
 
10654
-       else
 
10655
+       if (!host->cmd->data)
 
10656
                tasklet_schedule(&host->finish_tasklet);
 
10657
 
 
10658
        host->cmd = NULL;
 
10659
@@ -729,7 +751,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
10660
        host->mrq = mrq;
 
10661
 
 
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);
 
10666
        } else
 
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);
 
10671
 
 
10672
+       /*
 
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.
 
10676
+        */
 
10677
+       if(host->chip->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS)
 
10678
+               sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
 
10679
+
 
10680
        mmiowb();
 
10681
        spin_unlock_irqrestore(&host->lock, flags);
 
10682
 }
 
10683
@@ -807,10 +837,35 @@ static int sdhci_get_ro(struct mmc_host *mmc)
 
10684
        return !(present & SDHCI_WRITE_PROTECT);
 
10685
 }
 
10686
 
 
10687
+static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
 
10688
+{
 
10689
+       struct sdhci_host *host;
 
10690
+       unsigned long flags;
 
10691
+       u32 ier;
 
10692
+
 
10693
+       host = mmc_priv(mmc);
 
10694
+
 
10695
+       spin_lock_irqsave(&host->lock, flags);
 
10696
+
 
10697
+       ier = readl(host->ioaddr + SDHCI_INT_ENABLE);
 
10698
+
 
10699
+       ier &= ~SDHCI_INT_CARD_INT;
 
10700
+       if (enable)
 
10701
+               ier |= SDHCI_INT_CARD_INT;
 
10702
+
 
10703
+       writel(ier, host->ioaddr + SDHCI_INT_ENABLE);
 
10704
+       writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
 
10705
+
 
10706
+       mmiowb();
 
10707
+
 
10708
+       spin_unlock_irqrestore(&host->lock, flags);
 
10709
+}
 
10710
+
 
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,
 
10716
 };
 
10717
 
 
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);
 
10722
 
 
10723
-                       host->mrq->cmd->error = MMC_ERR_FAILED;
 
10724
+                       host->mrq->cmd->error = -ENOMEDIUM;
 
10725
                        tasklet_schedule(&host->finish_tasklet);
 
10726
                }
 
10727
        }
 
10728
@@ -862,15 +917,13 @@ static void sdhci_tasklet_finish(unsigned long param)
 
10729
 
 
10730
        mrq = host->mrq;
 
10731
 
 
10732
-       DBG("Ending request, cmd (%x)\n", mrq->cmd->opcode);
 
10733
-
 
10734
        /*
 
10735
         * The controller needs a reset of internal state machines
 
10736
         * upon error conditions.
 
10737
         */
 
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)))) {
 
10744
 
 
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);
 
10749
 
 
10750
                if (host->data) {
 
10751
-                       host->data->error = MMC_ERR_TIMEOUT;
 
10752
+                       host->data->error = -ETIMEDOUT;
 
10753
                        sdhci_finish_data(host);
 
10754
                } else {
 
10755
                        if (host->cmd)
 
10756
-                               host->cmd->error = MMC_ERR_TIMEOUT;
 
10757
+                               host->cmd->error = -ETIMEDOUT;
 
10758
                        else
 
10759
-                               host->mrq->cmd->error = MMC_ERR_TIMEOUT;
 
10760
+                               host->mrq->cmd->error = -ETIMEDOUT;
 
10761
 
 
10762
                        tasklet_schedule(&host->finish_tasklet);
 
10763
                }
 
10764
@@ -942,27 +995,23 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
 
10765
        BUG_ON(intmask == 0);
 
10766
 
 
10767
        if (!host->cmd) {
 
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);
 
10775
                return;
 
10776
        }
 
10777
 
 
10778
-       if (intmask & SDHCI_INT_RESPONSE)
 
10779
-               sdhci_finish_command(host);
 
10780
-       else {
 
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;
 
10787
-               else
 
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;
 
10794
 
 
10795
+       if (host->cmd->error)
 
10796
                tasklet_schedule(&host->finish_tasklet);
 
10797
-       }
 
10798
+       else if (intmask & SDHCI_INT_RESPONSE)
 
10799
+               sdhci_finish_command(host);
 
10800
 }
 
10801
 
 
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)
 
10805
                        return;
 
10806
 
 
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);
 
10814
 
 
10815
                return;
 
10816
        }
 
10817
 
 
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;
 
10827
 
 
10828
-       if (host->data->error != MMC_ERR_NONE)
 
10829
+       if (host->data->error)
 
10830
                sdhci_finish_data(host);
 
10831
        else {
 
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);
 
10836
 
 
10837
-               if (intmask & SDHCI_INT_DATA_END)
 
10838
-                       sdhci_finish_data(host);
 
10839
+               if (intmask & SDHCI_INT_DATA_END) {
 
10840
+                       if (host->cmd) {
 
10841
+                               /*
 
10842
+                                * Data managed to finish before the
 
10843
+                                * command completed. Make sure we do
 
10844
+                                * things in the proper order.
 
10845
+                                */
 
10846
+                               host->data_early = 1;
 
10847
+                       } else {
 
10848
+                               sdhci_finish_data(host);
 
10849
+                       }
 
10850
+               }
 
10851
        }
 
10852
 }
 
10853
 
 
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;
 
10857
        u32 intmask;
 
10858
+       int cardint = 0;
 
10859
 
 
10860
        spin_lock(&host->lock);
 
10861
 
 
10862
        intmask = readl(host->ioaddr + SDHCI_INT_STATUS);
 
10863
 
 
10864
        if (!intmask || intmask == 0xffffffff) {
 
10865
+
 
10866
                result = IRQ_NONE;
 
10867
                goto out;
 
10868
        }
 
10869
@@ -1051,13 +1110,20 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
 
10870
 
 
10871
        intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
 
10872
 
 
10873
+       intmask &= ~SDHCI_INT_ERROR;
 
10874
+
 
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);
 
10879
        }
 
10880
 
 
10881
-       intmask &= SDHCI_INT_BUS_POWER;
 
10882
+       intmask &= ~SDHCI_INT_BUS_POWER;
 
10883
+
 
10884
+       if (intmask & SDHCI_INT_CARD_INT)
 
10885
+               cardint = 1;
 
10886
+
 
10887
+       intmask &= ~SDHCI_INT_CARD_INT;
 
10888
 
 
10889
        if (intmask) {
 
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)
 
10892
 out:
 
10893
        spin_unlock(&host->lock);
 
10894
 
 
10895
+       /*
 
10896
+        * We have to delay this as it calls back into the driver.
 
10897
+        */
 
10898
+       if (cardint)
 
10899
+               mmc_signal_sdio_irq(host->mmc);
 
10900
+
 
10901
        return result;
 
10902
 }
 
10903
 
 
10904
@@ -1089,12 +1161,17 @@ static int sdhci_suspend (struct pci_dev *pdev, pm_message_t state)
 
10905
        struct sdhci_chip *chip;
 
10906
        int i, ret;
 
10907
 
 
10908
+       umd_enter();
 
10909
+
 
10910
        chip = pci_get_drvdata(pdev);
 
10911
        if (!chip)
 
10912
                return 0;
 
10913
 
 
10914
        DBG("Suspending...\n");
 
10915
 
 
10916
+       umd_dbg("This is for %s", chip->hosts[0]->mmc->class_dev.bus_id);
 
10917
+
 
10918
+
 
10919
        for (i = 0;i < chip->num_slots;i++) {
 
10920
                if (!chip->hosts[i])
 
10921
                        continue;
 
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));
 
10925
 
 
10926
+       /*
 
10927
+       if (!strcmp(chip->hosts[0]->mmc->class_dev.bus_id, "mmc0")) {
 
10928
+               umd_dbg("Return from here to test PM");
 
10929
+               return -1;
 
10930
+       }
 
10931
+       */
 
10932
+       umd_exit();
 
10933
+
 
10934
        return 0;
 
10935
 }
 
10936
 
 
10937
@@ -1126,6 +1211,8 @@ static int sdhci_resume (struct pci_dev *pdev)
 
10938
        struct sdhci_chip *chip;
 
10939
        int i, ret;
 
10940
 
 
10941
+       umd_enter();
 
10942
+
 
10943
        chip = pci_get_drvdata(pdev);
 
10944
        if (!chip)
 
10945
                return 0;
 
10946
@@ -1258,20 +1345,26 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
 
10947
 
 
10948
        caps = readl(host->ioaddr + SDHCI_CAPABILITIES);
 
10949
 
 
10950
-       if (debug_nodma)
 
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");
 
10962
        else
 
10963
                host->flags |= SDHCI_USE_DMA;
 
10964
 
 
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;
 
10969
+       }
 
10970
+
 
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);
 
10976
+       }
 
10977
+
 
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;
 
10987
 
 
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)
 
10991
         */
 
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",
 
10996
                        host->slot_descr);
 
10997
-               ret = -ENODEV;
 
10998
-               goto unmap;
 
10999
-       }
 
11000
-       mmc->max_blk_size = 512 << mmc->max_blk_size;
 
11001
+               mmc->max_blk_size = 512;
 
11002
+       } else
 
11003
+               mmc->max_blk_size = 512 << mmc->max_blk_size;
 
11004
 
 
11005
        /*
 
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);
 
11010
 
 
11011
-module_param(debug_nodma, uint, 0444);
 
11012
-module_param(debug_forcedma, uint, 0444);
 
11013
 module_param(debug_quirks, uint, 0444);
 
11014
 
 
11015
 MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>");
 
11016
 MODULE_DESCRIPTION("Secure Digital Host Controller Interface driver");
 
11017
 MODULE_LICENSE("GPL");
 
11018
 
 
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
 
11026
@@ -1,5 +1,5 @@
 
11027
 /*
 
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
 
11030
  *
 
11031
  *  Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
 
11032
  *
 
11033
@@ -81,7 +81,7 @@
 
11034
 
 
11035
 #define SDHCI_BLOCK_GAP_CONTROL        0x2A
 
11036
 
 
11037
-#define SDHCI_WALK_UP_CONTROL  0x2B
 
11038
+#define SDHCI_WAKE_UP_CONTROL  0x2B
 
11039
 
 
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 */
 
11055
 
 
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
 
11062
@@ -16,6 +16,7 @@
 
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>
 
11068
 
 
11069
 #define DRIVER_NAME "tifm_sd"
 
11070
@@ -191,7 +192,7 @@ static void tifm_sd_transfer_data(struct tifm_sd *host)
 
11071
                }
 
11072
                off = sg[host->sg_pos].offset + host->block_pos;
 
11073
 
 
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)
 
11080
                }
 
11081
                off = sg[host->sg_pos].offset + host->block_pos;
 
11082
 
 
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);
 
11089
 
 
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,
 
11094
                                          pg, p_off, p_cnt);
 
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);
 
11099
 
 
11100
                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;
 
11104
 
 
11105
-       if (cmd->error != MMC_ERR_NONE)
 
11106
+       if (cmd->error)
 
11107
                goto finish_request;
 
11108
 
 
11109
        if (!(host->cmd_flags & CMD_READY))
 
11110
                return;
 
11111
 
 
11112
        if (cmd->data) {
 
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))
 
11117
                                return;
 
11118
@@ -504,7 +505,7 @@ static void tifm_sd_card_event(struct tifm_dev *sock)
 
11119
 {
 
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;
 
11126
 
 
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;
 
11136
 
 
11137
                        if (cmd->data) {
 
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;
 
11144
                        }
 
11145
 
 
11146
                        writel(TIFM_FIFO_INT_SETALL,
 
11147
@@ -626,14 +627,21 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
11148
 
 
11149
        spin_lock_irqsave(&sock->lock, flags);
 
11150
        if (host->eject) {
 
11151
-               spin_unlock_irqrestore(&sock->lock, flags);
 
11152
+               mrq->cmd->error = -ENOMEDIUM;
 
11153
                goto err_out;
 
11154
        }
 
11155
 
 
11156
        if (host->req) {
 
11157
                printk(KERN_ERR "%s : unfinished request detected\n",
 
11158
                       sock->dev.bus_id);
 
11159
-               spin_unlock_irqrestore(&sock->lock, flags);
 
11160
+               mrq->cmd->error = -ETIMEDOUT;
 
11161
+               goto err_out;
 
11162
+       }
 
11163
+
 
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;
 
11168
                goto err_out;
 
11169
        }
 
11170
 
 
11171
@@ -722,7 +730,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
11172
        return;
 
11173
 
 
11174
 err_out:
 
11175
-       mrq->cmd->error = MMC_ERR_TIMEOUT;
 
11176
+       spin_unlock_irqrestore(&sock->lock, flags);
 
11177
        mmc_request_done(mmc, mrq);
 
11178
 }
 
11179
 
 
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);
 
11190
        }
 
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
 
11196
@@ -1,5 +1,5 @@
 
11197
 /*
 
11198
- *  linux/drivers/mmc/wbsd.c - Winbond W83L51xD SD/MMC driver
 
11199
+ *  linux/drivers/mmc/host/wbsd.c - Winbond W83L51xD SD/MMC driver
 
11200
  *
 
11201
  *  Copyright (C) 2004-2007 Pierre Ossman, All Rights Reserved.
 
11202
  *
 
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>
 
11208
 
 
11209
 #include <asm/io.h>
 
11210
 #include <asm/dma.h>
 
11211
-#include <asm/scatterlist.h>
 
11212
 
 
11213
 #include "wbsd.h"
 
11214
 
 
11215
@@ -207,8 +207,6 @@ static void wbsd_request_end(struct wbsd_host *host, struct mmc_request *mrq)
 
11216
 {
 
11217
        unsigned long dmaflags;
 
11218
 
 
11219
-       DBGF("Ending request, cmd (%x)\n", mrq->cmd->opcode);
 
11220
-
 
11221
        if (host->dma >= 0) {
 
11222
                /*
 
11223
                 * Release ISA DMA controller.
 
11224
@@ -271,7 +269,7 @@ static inline int wbsd_next_sg(struct wbsd_host *host)
 
11225
 
 
11226
 static inline char *wbsd_sg_to_buffer(struct wbsd_host *host)
 
11227
 {
 
11228
-       return page_address(host->cur_sg->page) + host->cur_sg->offset;
 
11229
+       return sg_virt(host->cur_sg);
 
11230
 }
 
11231
 
 
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;
 
11235
 
 
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;
 
11241
        }
 
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;
 
11244
 
 
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;
 
11250
        }
 
11251
@@ -319,7 +317,7 @@ static inline void wbsd_get_short_reply(struct wbsd_host *host,
 
11252
         * Correct response type?
 
11253
         */
 
11254
        if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_SHORT) {
 
11255
-               cmd->error = MMC_ERR_INVALID;
 
11256
+               cmd->error = -EILSEQ;
 
11257
                return;
 
11258
        }
 
11259
 
 
11260
@@ -339,7 +337,7 @@ static inline void wbsd_get_long_reply(struct wbsd_host *host,
 
11261
         * Correct response type?
 
11262
         */
 
11263
        if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_LONG) {
 
11264
-               cmd->error = MMC_ERR_INVALID;
 
11265
+               cmd->error = -EILSEQ;
 
11266
                return;
 
11267
        }
 
11268
 
 
11269
@@ -360,8 +358,6 @@ static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd)
 
11270
        int i;
 
11271
        u8 status, isr;
 
11272
 
 
11273
-       DBGF("Sending cmd (%x)\n", cmd->opcode);
 
11274
-
 
11275
        /*
 
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);
 
11281
 
 
11282
-       cmd->error = MMC_ERR_NONE;
 
11283
+       cmd->error = 0;
 
11284
 
 
11285
        /*
 
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)
 
11288
 
 
11289
                /* Card removed? */
 
11290
                if (isr & WBSD_INT_CARD)
 
11291
-                       cmd->error = MMC_ERR_TIMEOUT;
 
11292
+                       cmd->error = -ENOMEDIUM;
 
11293
                /* Timeout? */
 
11294
                else if (isr & WBSD_INT_TIMEOUT)
 
11295
-                       cmd->error = MMC_ERR_TIMEOUT;
 
11296
+                       cmd->error = -ETIMEDOUT;
 
11297
                /* CRC? */
 
11298
                else if ((cmd->flags & MMC_RSP_CRC) && (isr & WBSD_INT_CRC))
 
11299
-                       cmd->error = MMC_ERR_BADCRC;
 
11300
+                       cmd->error = -EILSEQ;
 
11301
                /* All ok */
 
11302
                else {
 
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);
 
11306
                }
 
11307
        }
 
11308
-
 
11309
-       DBGF("Sent cmd (%x), res %d\n", cmd->opcode, cmd->error);
 
11310
 }
 
11311
 
 
11312
 /*
 
11313
@@ -550,11 +544,6 @@ static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
 
11314
        unsigned long dmaflags;
 
11315
        unsigned int size;
 
11316
 
 
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);
 
11321
-
 
11322
        /*
 
11323
         * Calculate size.
 
11324
         */
 
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);
 
11328
        } else {
 
11329
-               data->error = MMC_ERR_INVALID;
 
11330
+               data->error = -EINVAL;
 
11331
                return;
 
11332
        }
 
11333
 
 
11334
@@ -618,7 +607,7 @@ static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
 
11335
                 */
 
11336
                BUG_ON(size > 0x10000);
 
11337
                if (size > 0x10000) {
 
11338
-                       data->error = MMC_ERR_INVALID;
 
11339
+                       data->error = -EINVAL;
 
11340
                        return;
 
11341
                }
 
11342
 
 
11343
@@ -680,7 +669,7 @@ static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
 
11344
                }
 
11345
        }
 
11346
 
 
11347
-       data->error = MMC_ERR_NONE;
 
11348
+       data->error = 0;
 
11349
 }
 
11350
 
 
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);
 
11355
 
 
11356
-                       if (data->error == MMC_ERR_NONE)
 
11357
-                               data->error = MMC_ERR_FAILED;
 
11358
+                       if (!data->error)
 
11359
+                               data->error = -EIO;
 
11360
                } else {
 
11361
                        /*
 
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);
 
11365
                }
 
11366
 
 
11367
-               if (data->error != MMC_ERR_NONE) {
 
11368
+               if (data->error) {
 
11369
                        if (data->bytes_xfered)
 
11370
                                data->bytes_xfered -= data->blksz;
 
11371
                }
 
11372
        }
 
11373
 
 
11374
-       DBGF("Ending data transfer (%d bytes)\n", data->bytes_xfered);
 
11375
-
 
11376
        wbsd_request_end(host, host->mrq);
 
11377
 }
 
11378
 
 
11379
@@ -780,11 +767,10 @@ static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
11380
        host->mrq = mrq;
 
11381
 
 
11382
        /*
 
11383
-        * If there is no card in the slot then
 
11384
-        * timeout immediatly.
 
11385
+        * Check that there is actually a card in the slot.
 
11386
         */
 
11387
        if (!(host->flags & WBSD_FCARD_PRESENT)) {
 
11388
-               cmd->error = MMC_ERR_TIMEOUT;
 
11389
+               cmd->error = -ENOMEDIUM;
 
11390
                goto done;
 
11391
        }
 
11392
 
 
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);
 
11396
 #endif
 
11397
-                       cmd->error = MMC_ERR_INVALID;
 
11398
+                       cmd->error = -EINVAL;
 
11399
 
 
11400
                        goto done;
 
11401
                };
 
11402
@@ -832,7 +818,7 @@ static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
 
11403
        if (cmd->data) {
 
11404
                wbsd_prepare_data(host, cmd->data);
 
11405
 
 
11406
-               if (cmd->data->error != MMC_ERR_NONE)
 
11407
+               if (cmd->data->error)
 
11408
                        goto done;
 
11409
        }
 
11410
 
 
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
 
11413
         * transfered.
 
11414
         */
 
11415
-       if (cmd->data && (cmd->error == MMC_ERR_NONE)) {
 
11416
+       if (cmd->data && !cmd->error) {
 
11417
                /*
 
11418
                 * Dirty fix for hardware bug.
 
11419
                 */
 
11420
@@ -1046,7 +1032,7 @@ static void wbsd_tasklet_card(unsigned long param)
 
11421
                                mmc_hostname(host->mmc));
 
11422
                        wbsd_reset(host);
 
11423
 
 
11424
-                       host->mrq->cmd->error = MMC_ERR_FAILED;
 
11425
+                       host->mrq->cmd->error = -ENOMEDIUM;
 
11426
                        tasklet_schedule(&host->finish_tasklet);
 
11427
                }
 
11428
 
 
11429
@@ -1110,7 +1096,7 @@ static void wbsd_tasklet_crc(unsigned long param)
 
11430
 
 
11431
        DBGF("CRC error\n");
 
11432
 
 
11433
-       data->error = MMC_ERR_BADCRC;
 
11434
+       data->error = -EILSEQ;
 
11435
 
 
11436
        tasklet_schedule(&host->finish_tasklet);
 
11437
 
 
11438
@@ -1134,7 +1120,7 @@ static void wbsd_tasklet_timeout(unsigned long param)
 
11439
 
 
11440
        DBGF("Timeout\n");
 
11441
 
 
11442
-       data->error = MMC_ERR_TIMEOUT;
 
11443
+       data->error = -ETIMEDOUT;
 
11444
 
 
11445
        tasklet_schedule(&host->finish_tasklet);
 
11446
 
 
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;
 
11453
 
 
11454
        spin_lock_init(&host->lock);
 
11455
 
 
11456
@@ -1279,7 +1265,7 @@ static int __devinit wbsd_alloc_mmc(struct device *dev)
 
11457
        return 0;
 
11458
 }
 
11459
 
 
11460
-static void __devexit wbsd_free_mmc(struct device *dev)
 
11461
+static void wbsd_free_mmc(struct device *dev)
 
11462
 {
 
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)
 
11466
        return 0;
 
11467
 }
 
11468
 
 
11469
-static void __devexit wbsd_release_regions(struct wbsd_host *host)
 
11470
+static void wbsd_release_regions(struct wbsd_host *host)
 
11471
 {
 
11472
        if (host->base)
 
11473
                release_region(host->base, 8);
 
11474
@@ -1447,7 +1433,7 @@ err:
 
11475
                "Falling back on FIFO.\n", dma);
 
11476
 }
 
11477
 
 
11478
-static void __devexit wbsd_release_dma(struct wbsd_host *host)
 
11479
+static void wbsd_release_dma(struct wbsd_host *host)
 
11480
 {
 
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)
 
11484
        return 0;
 
11485
 }
 
11486
 
 
11487
-static void __devexit wbsd_release_irq(struct wbsd_host *host)
 
11488
+static void  wbsd_release_irq(struct wbsd_host *host)
 
11489
 {
 
11490
        if (!host->irq)
 
11491
                return;
 
11492
@@ -1548,7 +1534,7 @@ static int __devinit wbsd_request_resources(struct wbsd_host *host,
 
11493
  * Release all resources for the host.
 
11494
  */
 
11495
 
 
11496
-static void __devexit wbsd_release_resources(struct wbsd_host *host)
 
11497
+static void wbsd_release_resources(struct wbsd_host *host)
 
11498
 {
 
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
 
11505
@@ -1,5 +1,5 @@
 
11506
 /*
 
11507
- *  linux/drivers/mmc/wbsd.h - Winbond W83L51xD SD/MMC driver
 
11508
+ *  linux/drivers/mmc/host/wbsd.h - Winbond W83L51xD SD/MMC driver
 
11509
  *
 
11510
  *  Copyright (C) 2004-2007 Pierre Ossman, All Rights Reserved.
 
11511
  *
 
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;
 
11518
 };
 
11519
 
 
11520
+struct sdio_cccr {
 
11521
+       unsigned int            sdio_vsn;
 
11522
+       unsigned int            sd_vsn;
 
11523
+       unsigned int            multi_block:1,
 
11524
+                               low_speed:1,
 
11525
+                               wide_bus:1,
 
11526
+                               high_power:1,
 
11527
+                               high_speed:1;
 
11528
+};
 
11529
+
 
11530
+struct sdio_cis {
 
11531
+       unsigned short          vendor;
 
11532
+       unsigned short          device;
 
11533
+       unsigned short          blksize;
 
11534
+       unsigned int            max_dtr;
 
11535
+};
 
11536
+
 
11537
 struct mmc_host;
 
11538
+struct sdio_func;
 
11539
+struct sdio_func_tuple;
 
11540
+
 
11541
+#define SDIO_MAX_FUNCS         7
 
11542
 
 
11543
 /*
 
11544
  * MMC device
 
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 */
 
11555
+
 
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 */
 
11563
+
 
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 */
 
11571
 };
 
11572
 
 
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)
 
11576
 
 
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 */
 
11588
+
 
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)
 
11594
 
 
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 */
 
11599
+
 
11600
 /*
 
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.
 
11605
  */
 
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)
 
11614
 
 
11615
 #define mmc_resp_type(cmd)     ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))
 
11616
 
 
11617
 /*
 
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.
 
11621
+ */
 
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)
 
11629
+
 
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))
 
11632
+
 
11633
+/*
 
11634
  * These are the command types.
 
11635
  */
 
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 */
 
11640
 
 
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
 
11647
+/*
 
11648
+ * Standard errno values are used for errors, but some have specific
 
11649
+ * meaning in the MMC layer:
 
11650
+ *
 
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
 
11659
+ */
 
11660
 
 
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)
 
11668
 
 
11669
        unsigned int            bytes_xfered;
 
11670
 
 
11671
@@ -99,14 +129,41 @@ struct mmc_request {
 
11672
 struct mmc_host;
 
11673
 struct mmc_card;
 
11674
 
 
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);
 
11680
 
 
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 *);
 
11683
 
 
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);
 
11687
 
 
11688
+/**
 
11689
+ *     mmc_claim_host - exclusively claim a host
 
11690
+ *     @host: mmc host to claim
 
11691
+ *
 
11692
+ *     Claim a host for a set of operations.
 
11693
+ */
 
11694
+static inline void mmc_claim_host(struct mmc_host *host)
 
11695
+{
 
11696
+       __mmc_claim_host(host, NULL);
 
11697
+}
 
11698
+
 
11699
+/* feng add for temply use */
 
11700
+#define DBG_2622 1
 
11701
+
 
11702
+#ifdef DBG_2622
 
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__)
 
11709
+#else
 
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 */
 
11714
+
 
11715
 #endif
 
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
 
11720
@@ -10,6 +10,8 @@
 
11721
 #ifndef LINUX_MMC_HOST_H
 
11722
 #define LINUX_MMC_HOST_H
 
11723
 
 
11724
+#include <linux/leds.h>
 
11725
+
 
11726
 #include <linux/mmc/core.h>
 
11727
 
 
11728
 struct mmc_ios {
 
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);
 
11734
 };
 
11735
 
 
11736
 struct mmc_card;
 
11737
@@ -87,9 +90,10 @@ struct mmc_host {
 
11738
 
 
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 */
 
11748
 
 
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 */
 
11754
 
 
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 */
 
11761
+#endif
 
11762
+
 
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 */
 
11768
 
 
11769
        wait_queue_head_t       wq;
 
11770
-       unsigned int            claimed:1;      /* host exclusively claimed */
 
11771
 
 
11772
        struct delayed_work     detect;
 
11773
-#ifdef CONFIG_MMC_DEBUG
 
11774
-       unsigned int            removed:1;      /* host is being removed */
 
11775
-#endif
 
11776
 
 
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 */
 
11780
+
 
11781
+       unsigned int            sdio_irqs;
 
11782
+       struct task_struct      *sdio_irq_thread;
 
11783
+       atomic_t                sdio_irq_thread_abort;
 
11784
+
 
11785
+#ifdef CONFIG_LEDS_TRIGGERS
 
11786
+       struct led_trigger      *led;           /* activity led */
 
11787
+#endif
 
11788
 
 
11789
        unsigned long           private[0] ____cacheline_aligned;
 
11790
 };
 
11791
@@ -137,6 +152,8 @@ static inline void *mmc_priv(struct mmc_host *host)
 
11792
        return (void *)host->private;
 
11793
 }
 
11794
 
 
11795
+#define mmc_host_is_spi(host)  ((host)->caps & MMC_CAP_SPI)
 
11796
+
 
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 *);
 
11803
 
 
11804
+static inline void mmc_signal_sdio_irq(struct mmc_host *host)
 
11805
+{
 
11806
+       host->ops->enable_sdio_irq(host, 0);
 
11807
+       wake_up_process(host->sdio_irq_thread);
 
11808
+}
 
11809
+
 
11810
 #endif
 
11811
 
 
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
 
11816
@@ -41,6 +41,8 @@
 
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 */
 
11822
 
 
11823
   /* class 2 */
 
11824
 #define MMC_SET_BLOCKLEN         16   /* ac   [31:0] block len   R1  */
 
11825
@@ -90,7 +92,7 @@
 
11826
  */
 
11827
 
 
11828
 /*
 
11829
-  MMC status in R1
 
11830
+  MMC status in R1, for native mode (SPI bits are different)
 
11831
   Type
 
11832
        e : error bit
 
11833
        s : status bit
 
11834
@@ -128,6 +130,29 @@
 
11835
 #define R1_READY_FOR_DATA      (1 << 8)        /* sx, a */
 
11836
 #define R1_APP_CMD             (1 << 5)        /* sr, c */
 
11837
 
 
11838
+/*
 
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.
 
11841
+ */
 
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
 
11860
+
 
11861
 /* These are unpacked versions of the actual responses */
 
11862
 
 
11863
 struct _mmc_csd {
 
11864
@@ -182,6 +207,7 @@ struct _mmc_csd {
 
11865
  */
 
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 */
 
11870
                                        /* (CMD11) */
 
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 */
 
11878
 
 
11879
 /*
 
11880
diff --git a/include/linux/mmc/sdio.h b/include/linux/mmc/sdio.h
 
11881
new file mode 100644
 
11882
index 0000000..96dc68d
 
11883
--- /dev/null
 
11884
+++ b/include/linux/mmc/sdio.h
 
11885
@@ -0,0 +1,158 @@
 
11886
+/*
 
11887
+ *  include/linux/mmc/sdio.h
 
11888
+ *
 
11889
+ *  Copyright 2006-2007 Pierre Ossman
 
11890
+ *
 
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.
 
11895
+ */
 
11896
+
 
11897
+#ifndef MMC_SDIO_H
 
11898
+#define MMC_SDIO_H
 
11899
+
 
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  */
 
11904
+
 
11905
+/*
 
11906
+ * SD_IO_RW_DIRECT argument format:
 
11907
+ *
 
11908
+ *      [31] R/W flag
 
11909
+ *      [30:28] Function number
 
11910
+ *      [27] RAW flag
 
11911
+ *      [25:9] Register address
 
11912
+ *      [7:0] Data
 
11913
+ */
 
11914
+
 
11915
+/*
 
11916
+ * SD_IO_RW_EXTENDED argument format:
 
11917
+ *
 
11918
+ *      [31] R/W flag
 
11919
+ *      [30:28] Function number
 
11920
+ *      [27] Block mode
 
11921
+ *      [26] Increment address
 
11922
+ *      [25:9] Register address
 
11923
+ *      [8:0] Byte/block count
 
11924
+ */
 
11925
+
 
11926
+/*
 
11927
+  SDIO status in R5
 
11928
+  Type
 
11929
+       e : error bit
 
11930
+       s : status bit
 
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.
 
11934
+  Clear condition
 
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
 
11939
+ */
 
11940
+
 
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 */
 
11948
+
 
11949
+/*
 
11950
+ * Card Common Control Registers (CCCR)
 
11951
+ */
 
11952
+
 
11953
+#define SDIO_CCCR_CCCR         0x00
 
11954
+
 
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 */
 
11958
+
 
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 */
 
11963
+
 
11964
+#define SDIO_CCCR_SD           0x01
 
11965
+
 
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 */
 
11969
+
 
11970
+#define SDIO_CCCR_IOEx         0x02
 
11971
+#define SDIO_CCCR_IORx         0x03
 
11972
+
 
11973
+#define SDIO_CCCR_IENx         0x04    /* Function/Master Interrupt Enable */
 
11974
+#define SDIO_CCCR_INTx         0x05    /* Function Interrupt Pending */
 
11975
+
 
11976
+#define SDIO_CCCR_ABORT                0x06    /* function abort/card reset */
 
11977
+
 
11978
+#define SDIO_CCCR_IF           0x07    /* bus interface controls */
 
11979
+
 
11980
+#define  SDIO_BUS_WIDTH_1BIT   0x00
 
11981
+#define  SDIO_BUS_WIDTH_4BIT   0x02
 
11982
+
 
11983
+#define  SDIO_BUS_CD_DISABLE     0x80  /* disable pull-up on DAT3 (pin 1) */
 
11984
+
 
11985
+#define SDIO_CCCR_CAPS         0x08
 
11986
+
 
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 */
 
11995
+
 
11996
+#define SDIO_CCCR_CIS          0x09    /* common CIS pointer (3 bytes) */
 
11997
+
 
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
 
12003
+
 
12004
+#define SDIO_CCCR_BLKSIZE      0x10
 
12005
+
 
12006
+#define SDIO_CCCR_POWER                0x12
 
12007
+
 
12008
+#define  SDIO_POWER_SMPC       0x01    /* Supports Master Power Control */
 
12009
+#define  SDIO_POWER_EMPC       0x02    /* Enable Master Power Control */
 
12010
+
 
12011
+#define SDIO_CCCR_SPEED                0x13
 
12012
+
 
12013
+#define  SDIO_SPEED_SHS                0x01    /* Supports High-Speed mode */
 
12014
+#define  SDIO_SPEED_EHS                0x02    /* Enable High-Speed mode */
 
12015
+
 
12016
+/*
 
12017
+ * Function Basic Registers (FBR)
 
12018
+ */
 
12019
+
 
12020
+#define SDIO_FBR_BASE(f)       ((f) * 0x100) /* base of function f's FBRs */
 
12021
+
 
12022
+#define SDIO_FBR_STD_IF                0x00
 
12023
+
 
12024
+#define  SDIO_FBR_SUPPORTS_CSA 0x40    /* supports Code Storage Area */
 
12025
+#define  SDIO_FBR_ENABLE_CSA   0x80    /* enable Code Storage Area */
 
12026
+
 
12027
+#define SDIO_FBR_STD_IF_EXT    0x01
 
12028
+
 
12029
+#define SDIO_FBR_POWER         0x02
 
12030
+
 
12031
+#define  SDIO_FBR_POWER_SPS    0x01    /* Supports Power Selection */
 
12032
+#define  SDIO_FBR_POWER_EPS    0x02    /* Enable (low) Power Selection */
 
12033
+
 
12034
+#define SDIO_FBR_CIS           0x09    /* CIS pointer (3 bytes) */
 
12035
+
 
12036
+
 
12037
+#define SDIO_FBR_CSA           0x0C    /* CSA pointer (3 bytes) */
 
12038
+
 
12039
+#define SDIO_FBR_CSA_DATA      0x0F
 
12040
+
 
12041
+#define SDIO_FBR_BLKSIZE       0x10    /* block size (2 bytes) */
 
12042
+
 
12043
+#endif
 
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
 
12047
--- /dev/null
 
12048
+++ b/include/linux/mmc/sdio_func.h
 
12049
@@ -0,0 +1,152 @@
 
12050
+/*
 
12051
+ *  include/linux/mmc/sdio_func.h
 
12052
+ *
 
12053
+ *  Copyright 2007 Pierre Ossman
 
12054
+ *
 
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.
 
12059
+ */
 
12060
+
 
12061
+#ifndef MMC_SDIO_FUNC_H
 
12062
+#define MMC_SDIO_FUNC_H
 
12063
+
 
12064
+#include <linux/device.h>
 
12065
+#include <linux/mod_devicetable.h>
 
12066
+
 
12067
+struct mmc_card;
 
12068
+struct sdio_func;
 
12069
+
 
12070
+typedef void (sdio_irq_handler_t)(struct sdio_func *);
 
12071
+
 
12072
+/*
 
12073
+ * SDIO function CIS tuple (unknown to the core)
 
12074
+ */
 
12075
+struct sdio_func_tuple {
 
12076
+       struct sdio_func_tuple *next;
 
12077
+       unsigned char code;
 
12078
+       unsigned char size;
 
12079
+       unsigned char data[0];
 
12080
+};
 
12081
+
 
12082
+/*
 
12083
+ * SDIO function devices
 
12084
+ */
 
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 */
 
12090
+
 
12091
+       unsigned char           class;          /* standard interface class */
 
12092
+       unsigned short          vendor;         /* vendor id */
 
12093
+       unsigned short          device;         /* device id */
 
12094
+
 
12095
+       unsigned                max_blksize;    /* maximum block size */
 
12096
+       unsigned                cur_blksize;    /* current block size */
 
12097
+
 
12098
+       unsigned int            state;          /* function state */
 
12099
+#define SDIO_STATE_PRESENT     (1<<0)          /* present in sysfs */
 
12100
+
 
12101
+       u8                      tmpbuf[4];      /* DMA:able scratch buffer */
 
12102
+
 
12103
+       unsigned                num_info;       /* number of info strings */
 
12104
+       const char              **info;         /* info strings */
 
12105
+
 
12106
+       struct sdio_func_tuple *tuples;
 
12107
+};
 
12108
+
 
12109
+#define sdio_func_present(f)   ((f)->state & SDIO_STATE_PRESENT)
 
12110
+
 
12111
+#define sdio_func_set_present(f) ((f)->state |= SDIO_STATE_PRESENT)
 
12112
+
 
12113
+#define sdio_func_id(f)                ((f)->dev.bus_id)
 
12114
+
 
12115
+#define sdio_get_drvdata(f)    dev_get_drvdata(&(f)->dev)
 
12116
+#define sdio_set_drvdata(f,d)  dev_set_drvdata(&(f)->dev, d)
 
12117
+
 
12118
+/*
 
12119
+ * SDIO function device driver
 
12120
+ */
 
12121
+struct sdio_driver {
 
12122
+       char *name;
 
12123
+       const struct sdio_device_id *id_table;
 
12124
+
 
12125
+       int (*probe)(struct sdio_func *, const struct sdio_device_id *);
 
12126
+       void (*remove)(struct sdio_func *);
 
12127
+
 
12128
+       struct device_driver drv;
 
12129
+};
 
12130
+
 
12131
+/**
 
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
 
12135
+ *
 
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.
 
12138
+ */
 
12139
+#define SDIO_DEVICE(vend,dev) \
 
12140
+       .class = SDIO_ANY_ID, \
 
12141
+       .vendor = (vend), .device = (dev)
 
12142
+
 
12143
+/**
 
12144
+ * SDIO_DEVICE_CLASS - macro used to describe a specific SDIO device class
 
12145
+ * @dev_class: the 8 bit standard interface code
 
12146
+ *
 
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.
 
12150
+ */
 
12151
+#define SDIO_DEVICE_CLASS(dev_class) \
 
12152
+       .class = (dev_class), \
 
12153
+       .vendor = SDIO_ANY_ID, .device = SDIO_ANY_ID
 
12154
+
 
12155
+extern int sdio_register_driver(struct sdio_driver *);
 
12156
+extern void sdio_unregister_driver(struct sdio_driver *);
 
12157
+
 
12158
+/*
 
12159
+ * SDIO I/O operations
 
12160
+ */
 
12161
+extern void sdio_claim_host(struct sdio_func *func);
 
12162
+extern void sdio_release_host(struct sdio_func *func);
 
12163
+
 
12164
+extern int sdio_enable_func(struct sdio_func *func);
 
12165
+extern int sdio_disable_func(struct sdio_func *func);
 
12166
+
 
12167
+extern int sdio_set_block_size(struct sdio_func *func, unsigned blksz);
 
12168
+
 
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);
 
12171
+
 
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);
 
12178
+
 
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);
 
12183
+
 
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);
 
12190
+
 
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);
 
12195
+
 
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);
 
12200
+
 
12201
+#endif
 
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
 
12205
--- /dev/null
 
12206
+++ b/include/linux/mmc/sdio_ids.h
 
12207
@@ -0,0 +1,29 @@
 
12208
+/*
 
12209
+ * SDIO Classes, Interface Types, Manufacturer IDs, etc.
 
12210
+ */
 
12211
+
 
12212
+#ifndef MMC_SDIO_IDS_H
 
12213
+#define MMC_SDIO_IDS_H
 
12214
+
 
12215
+/*
 
12216
+ * Standard SDIO Function Interfaces
 
12217
+ */
 
12218
+
 
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 */
 
12228
+
 
12229
+/*
 
12230
+ * Vendors and devices.  Sort key: vendor first, device next.
 
12231
+ */
 
12232
+
 
12233
+#define SDIO_VENDOR_ID_MARVELL                 0x02df
 
12234
+#define SDIO_DEVICE_ID_MARVELL_LIBERTAS                0x9103
 
12235
+
 
12236
+#endif
 
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
 
12244
 
 
12245
+/* SDIO */
 
12246
+
 
12247
+#define SDIO_ANY_ID (~0)
 
12248
+
 
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 */
 
12254
+};
 
12255
+
 
12256
 #endif /* LINUX_MOD_DEVICETABLE_H */
 
12257
-- 
 
12258
1.5.2.GIT
 
12259