Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]

Diff markup

Differences between /linux/drivers/mmc/core/core.c (Version 2.6.31.13) and /linux/drivers/mmc/core/core.c (Version 2.6.25.8)


  1 /*                                                  1 /*
  2  *  linux/drivers/mmc/core/core.c                   2  *  linux/drivers/mmc/core/core.c
  3  *                                                  3  *
  4  *  Copyright (C) 2003-2004 Russell King, All       4  *  Copyright (C) 2003-2004 Russell King, All Rights Reserved.
  5  *  SD support Copyright (C) 2004 Ian Molton,       5  *  SD support Copyright (C) 2004 Ian Molton, All Rights Reserved.
  6  *  Copyright (C) 2005-2008 Pierre Ossman, All !!   6  *  Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
  7  *  MMCv4 support Copyright (C) 2006 Philip La      7  *  MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved.
  8  *                                                  8  *
  9  * This program is free software; you can redi      9  * This program is free software; you can redistribute it and/or modify
 10  * it under the terms of the GNU General Publi     10  * it under the terms of the GNU General Public License version 2 as
 11  * published by the Free Software Foundation.      11  * published by the Free Software Foundation.
 12  */                                                12  */
 13 #include <linux/module.h>                          13 #include <linux/module.h>
 14 #include <linux/init.h>                            14 #include <linux/init.h>
 15 #include <linux/interrupt.h>                       15 #include <linux/interrupt.h>
 16 #include <linux/completion.h>                      16 #include <linux/completion.h>
 17 #include <linux/device.h>                          17 #include <linux/device.h>
 18 #include <linux/delay.h>                           18 #include <linux/delay.h>
 19 #include <linux/pagemap.h>                         19 #include <linux/pagemap.h>
 20 #include <linux/err.h>                             20 #include <linux/err.h>
 21 #include <linux/leds.h>                            21 #include <linux/leds.h>
 22 #include <linux/scatterlist.h>                     22 #include <linux/scatterlist.h>
 23 #include <linux/log2.h>                        << 
 24 #include <linux/regulator/consumer.h>          << 
 25                                                    23 
 26 #include <linux/mmc/card.h>                        24 #include <linux/mmc/card.h>
 27 #include <linux/mmc/host.h>                        25 #include <linux/mmc/host.h>
 28 #include <linux/mmc/mmc.h>                         26 #include <linux/mmc/mmc.h>
 29 #include <linux/mmc/sd.h>                          27 #include <linux/mmc/sd.h>
 30                                                    28 
 31 #include "core.h"                                  29 #include "core.h"
 32 #include "bus.h"                                   30 #include "bus.h"
 33 #include "host.h"                                  31 #include "host.h"
 34 #include "sdio_bus.h"                              32 #include "sdio_bus.h"
 35                                                    33 
 36 #include "mmc_ops.h"                               34 #include "mmc_ops.h"
 37 #include "sd_ops.h"                                35 #include "sd_ops.h"
 38 #include "sdio_ops.h"                              36 #include "sdio_ops.h"
 39                                                    37 
                                                   >>  38 extern int mmc_attach_mmc(struct mmc_host *host, u32 ocr);
                                                   >>  39 extern int mmc_attach_sd(struct mmc_host *host, u32 ocr);
                                                   >>  40 extern int mmc_attach_sdio(struct mmc_host *host, u32 ocr);
                                                   >>  41 
 40 static struct workqueue_struct *workqueue;         42 static struct workqueue_struct *workqueue;
 41                                                    43 
 42 /*                                                 44 /*
 43  * Enabling software CRCs on the data blocks c     45  * Enabling software CRCs on the data blocks can be a significant (30%)
 44  * performance cost, and for other reasons may     46  * performance cost, and for other reasons may not always be desired.
 45  * So we allow it it to be disabled.               47  * So we allow it it to be disabled.
 46  */                                                48  */
 47 int use_spi_crc = 1;                               49 int use_spi_crc = 1;
 48 module_param(use_spi_crc, bool, 0);                50 module_param(use_spi_crc, bool, 0);
 49                                                    51 
 50 /*                                                 52 /*
 51  * Internal function. Schedule delayed work in     53  * Internal function. Schedule delayed work in the MMC work queue.
 52  */                                                54  */
 53 static int mmc_schedule_delayed_work(struct de     55 static int mmc_schedule_delayed_work(struct delayed_work *work,
 54                                      unsigned      56                                      unsigned long delay)
 55 {                                                  57 {
 56         return queue_delayed_work(workqueue, w     58         return queue_delayed_work(workqueue, work, delay);
 57 }                                                  59 }
 58                                                    60 
 59 /*                                                 61 /*
 60  * Internal function. Flush all scheduled work     62  * Internal function. Flush all scheduled work from the MMC work queue.
 61  */                                                63  */
 62 static void mmc_flush_scheduled_work(void)         64 static void mmc_flush_scheduled_work(void)
 63 {                                                  65 {
 64         flush_workqueue(workqueue);                66         flush_workqueue(workqueue);
 65 }                                                  67 }
 66                                                    68 
 67 /**                                                69 /**
 68  *      mmc_request_done - finish processing a     70  *      mmc_request_done - finish processing an MMC request
 69  *      @host: MMC host which completed reques     71  *      @host: MMC host which completed request
 70  *      @mrq: MMC request which request            72  *      @mrq: MMC request which request
 71  *                                                 73  *
 72  *      MMC drivers should call this function      74  *      MMC drivers should call this function when they have completed
 73  *      their processing of a request.             75  *      their processing of a request.
 74  */                                                76  */
 75 void mmc_request_done(struct mmc_host *host, s     77 void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
 76 {                                                  78 {
 77         struct mmc_command *cmd = mrq->cmd;        79         struct mmc_command *cmd = mrq->cmd;
 78         int err = cmd->error;                      80         int err = cmd->error;
 79                                                    81 
 80         if (err && cmd->retries && mmc_host_is     82         if (err && cmd->retries && mmc_host_is_spi(host)) {
 81                 if (cmd->resp[0] & R1_SPI_ILLE     83                 if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
 82                         cmd->retries = 0;          84                         cmd->retries = 0;
 83         }                                          85         }
 84                                                    86 
 85         if (err && cmd->retries) {                 87         if (err && cmd->retries) {
 86                 pr_debug("%s: req failed (CMD%     88                 pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
 87                         mmc_hostname(host), cm     89                         mmc_hostname(host), cmd->opcode, err);
 88                                                    90 
 89                 cmd->retries--;                    91                 cmd->retries--;
 90                 cmd->error = 0;                    92                 cmd->error = 0;
 91                 host->ops->request(host, mrq);     93                 host->ops->request(host, mrq);
 92         } else {                                   94         } else {
 93                 led_trigger_event(host->led, L     95                 led_trigger_event(host->led, LED_OFF);
 94                                                    96 
 95                 pr_debug("%s: req done (CMD%u)     97                 pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n",
 96                         mmc_hostname(host), cm     98                         mmc_hostname(host), cmd->opcode, err,
 97                         cmd->resp[0], cmd->res     99                         cmd->resp[0], cmd->resp[1],
 98                         cmd->resp[2], cmd->res    100                         cmd->resp[2], cmd->resp[3]);
 99                                                   101 
100                 if (mrq->data) {                  102                 if (mrq->data) {
101                         pr_debug("%s:     %d b    103                         pr_debug("%s:     %d bytes transferred: %d\n",
102                                 mmc_hostname(h    104                                 mmc_hostname(host),
103                                 mrq->data->byt    105                                 mrq->data->bytes_xfered, mrq->data->error);
104                 }                                 106                 }
105                                                   107 
106                 if (mrq->stop) {                  108                 if (mrq->stop) {
107                         pr_debug("%s:     (CMD    109                         pr_debug("%s:     (CMD%u): %d: %08x %08x %08x %08x\n",
108                                 mmc_hostname(h    110                                 mmc_hostname(host), mrq->stop->opcode,
109                                 mrq->stop->err    111                                 mrq->stop->error,
110                                 mrq->stop->res    112                                 mrq->stop->resp[0], mrq->stop->resp[1],
111                                 mrq->stop->res    113                                 mrq->stop->resp[2], mrq->stop->resp[3]);
112                 }                                 114                 }
113                                                   115 
114                 if (mrq->done)                    116                 if (mrq->done)
115                         mrq->done(mrq);           117                         mrq->done(mrq);
116         }                                         118         }
117 }                                                 119 }
118                                                   120 
119 EXPORT_SYMBOL(mmc_request_done);                  121 EXPORT_SYMBOL(mmc_request_done);
120                                                   122 
121 static void                                       123 static void
122 mmc_start_request(struct mmc_host *host, struc    124 mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
123 {                                                 125 {
124 #ifdef CONFIG_MMC_DEBUG                           126 #ifdef CONFIG_MMC_DEBUG
125         unsigned int i, sz;                       127         unsigned int i, sz;
126         struct scatterlist *sg;                << 
127 #endif                                            128 #endif
128                                                   129 
129         pr_debug("%s: starting CMD%u arg %08x     130         pr_debug("%s: starting CMD%u arg %08x flags %08x\n",
130                  mmc_hostname(host), mrq->cmd-    131                  mmc_hostname(host), mrq->cmd->opcode,
131                  mrq->cmd->arg, mrq->cmd->flag    132                  mrq->cmd->arg, mrq->cmd->flags);
132                                                   133 
133         if (mrq->data) {                          134         if (mrq->data) {
134                 pr_debug("%s:     blksz %d blo    135                 pr_debug("%s:     blksz %d blocks %d flags %08x "
135                         "tsac %d ms nsac %d\n"    136                         "tsac %d ms nsac %d\n",
136                         mmc_hostname(host), mr    137                         mmc_hostname(host), mrq->data->blksz,
137                         mrq->data->blocks, mrq    138                         mrq->data->blocks, mrq->data->flags,
138                         mrq->data->timeout_ns     139                         mrq->data->timeout_ns / 1000000,
139                         mrq->data->timeout_clk    140                         mrq->data->timeout_clks);
140         }                                         141         }
141                                                   142 
142         if (mrq->stop) {                          143         if (mrq->stop) {
143                 pr_debug("%s:     CMD%u arg %0    144                 pr_debug("%s:     CMD%u arg %08x flags %08x\n",
144                          mmc_hostname(host), m    145                          mmc_hostname(host), mrq->stop->opcode,
145                          mrq->stop->arg, mrq->    146                          mrq->stop->arg, mrq->stop->flags);
146         }                                         147         }
147                                                   148 
148         WARN_ON(!host->claimed);                  149         WARN_ON(!host->claimed);
149                                                   150 
150         led_trigger_event(host->led, LED_FULL)    151         led_trigger_event(host->led, LED_FULL);
151                                                   152 
152         mrq->cmd->error = 0;                      153         mrq->cmd->error = 0;
153         mrq->cmd->mrq = mrq;                      154         mrq->cmd->mrq = mrq;
154         if (mrq->data) {                          155         if (mrq->data) {
155                 BUG_ON(mrq->data->blksz > host    156                 BUG_ON(mrq->data->blksz > host->max_blk_size);
156                 BUG_ON(mrq->data->blocks > hos    157                 BUG_ON(mrq->data->blocks > host->max_blk_count);
157                 BUG_ON(mrq->data->blocks * mrq    158                 BUG_ON(mrq->data->blocks * mrq->data->blksz >
158                         host->max_req_size);      159                         host->max_req_size);
159                                                   160 
160 #ifdef CONFIG_MMC_DEBUG                           161 #ifdef CONFIG_MMC_DEBUG
161                 sz = 0;                           162                 sz = 0;
162                 for_each_sg(mrq->data->sg, sg, !! 163                 for (i = 0;i < mrq->data->sg_len;i++)
163                         sz += sg->length;      !! 164                         sz += mrq->data->sg[i].length;
164                 BUG_ON(sz != mrq->data->blocks    165                 BUG_ON(sz != mrq->data->blocks * mrq->data->blksz);
165 #endif                                            166 #endif
166                                                   167 
167                 mrq->cmd->data = mrq->data;       168                 mrq->cmd->data = mrq->data;
168                 mrq->data->error = 0;             169                 mrq->data->error = 0;
169                 mrq->data->mrq = mrq;             170                 mrq->data->mrq = mrq;
170                 if (mrq->stop) {                  171                 if (mrq->stop) {
171                         mrq->data->stop = mrq-    172                         mrq->data->stop = mrq->stop;
172                         mrq->stop->error = 0;     173                         mrq->stop->error = 0;
173                         mrq->stop->mrq = mrq;     174                         mrq->stop->mrq = mrq;
174                 }                                 175                 }
175         }                                         176         }
176         host->ops->request(host, mrq);            177         host->ops->request(host, mrq);
177 }                                                 178 }
178                                                   179 
179 static void mmc_wait_done(struct mmc_request *    180 static void mmc_wait_done(struct mmc_request *mrq)
180 {                                                 181 {
181         complete(mrq->done_data);                 182         complete(mrq->done_data);
182 }                                                 183 }
183                                                   184 
184 /**                                               185 /**
185  *      mmc_wait_for_req - start a request and    186  *      mmc_wait_for_req - start a request and wait for completion
186  *      @host: MMC host to start command          187  *      @host: MMC host to start command
187  *      @mrq: MMC request to start                188  *      @mrq: MMC request to start
188  *                                                189  *
189  *      Start a new MMC custom command request    190  *      Start a new MMC custom command request for a host, and wait
190  *      for the command to complete. Does not     191  *      for the command to complete. Does not attempt to parse the
191  *      response.                                 192  *      response.
192  */                                               193  */
193 void mmc_wait_for_req(struct mmc_host *host, s    194 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
194 {                                                 195 {
195         DECLARE_COMPLETION_ONSTACK(complete);     196         DECLARE_COMPLETION_ONSTACK(complete);
196                                                   197 
197         mrq->done_data = &complete;               198         mrq->done_data = &complete;
198         mrq->done = mmc_wait_done;                199         mrq->done = mmc_wait_done;
199                                                   200 
200         mmc_start_request(host, mrq);             201         mmc_start_request(host, mrq);
201                                                   202 
202         wait_for_completion(&complete);           203         wait_for_completion(&complete);
203 }                                                 204 }
204                                                   205 
205 EXPORT_SYMBOL(mmc_wait_for_req);                  206 EXPORT_SYMBOL(mmc_wait_for_req);
206                                                   207 
207 /**                                               208 /**
208  *      mmc_wait_for_cmd - start a command and    209  *      mmc_wait_for_cmd - start a command and wait for completion
209  *      @host: MMC host to start command          210  *      @host: MMC host to start command
210  *      @cmd: MMC command to start                211  *      @cmd: MMC command to start
211  *      @retries: maximum number of retries       212  *      @retries: maximum number of retries
212  *                                                213  *
213  *      Start a new MMC command for a host, an    214  *      Start a new MMC command for a host, and wait for the command
214  *      to complete.  Return any error that oc    215  *      to complete.  Return any error that occurred while the command
215  *      was executing.  Do not attempt to pars    216  *      was executing.  Do not attempt to parse the response.
216  */                                               217  */
217 int mmc_wait_for_cmd(struct mmc_host *host, st    218 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries)
218 {                                                 219 {
219         struct mmc_request mrq;                   220         struct mmc_request mrq;
220                                                   221 
221         WARN_ON(!host->claimed);                  222         WARN_ON(!host->claimed);
222                                                   223 
223         memset(&mrq, 0, sizeof(struct mmc_requ    224         memset(&mrq, 0, sizeof(struct mmc_request));
224                                                   225 
225         memset(cmd->resp, 0, sizeof(cmd->resp)    226         memset(cmd->resp, 0, sizeof(cmd->resp));
226         cmd->retries = retries;                   227         cmd->retries = retries;
227                                                   228 
228         mrq.cmd = cmd;                            229         mrq.cmd = cmd;
229         cmd->data = NULL;                         230         cmd->data = NULL;
230                                                   231 
231         mmc_wait_for_req(host, &mrq);             232         mmc_wait_for_req(host, &mrq);
232                                                   233 
233         return cmd->error;                        234         return cmd->error;
234 }                                                 235 }
235                                                   236 
236 EXPORT_SYMBOL(mmc_wait_for_cmd);                  237 EXPORT_SYMBOL(mmc_wait_for_cmd);
237                                                   238 
238 /**                                               239 /**
239  *      mmc_set_data_timeout - set the timeout    240  *      mmc_set_data_timeout - set the timeout for a data command
240  *      @data: data phase for command             241  *      @data: data phase for command
241  *      @card: the MMC card associated with th    242  *      @card: the MMC card associated with the data transfer
242  *                                                243  *
243  *      Computes the data timeout parameters a    244  *      Computes the data timeout parameters according to the
244  *      correct algorithm given the card type.    245  *      correct algorithm given the card type.
245  */                                               246  */
246 void mmc_set_data_timeout(struct mmc_data *dat    247 void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
247 {                                                 248 {
248         unsigned int mult;                        249         unsigned int mult;
249                                                   250 
250         /*                                        251         /*
251          * SDIO cards only define an upper 1 s    252          * SDIO cards only define an upper 1 s limit on access.
252          */                                       253          */
253         if (mmc_card_sdio(card)) {                254         if (mmc_card_sdio(card)) {
254                 data->timeout_ns = 1000000000;    255                 data->timeout_ns = 1000000000;
255                 data->timeout_clks = 0;           256                 data->timeout_clks = 0;
256                 return;                           257                 return;
257         }                                         258         }
258                                                   259 
259         /*                                        260         /*
260          * SD cards use a 100 multiplier rathe    261          * SD cards use a 100 multiplier rather than 10
261          */                                       262          */
262         mult = mmc_card_sd(card) ? 100 : 10;      263         mult = mmc_card_sd(card) ? 100 : 10;
263                                                   264 
264         /*                                        265         /*
265          * Scale up the multiplier (and theref    266          * Scale up the multiplier (and therefore the timeout) by
266          * the r2w factor for writes.             267          * the r2w factor for writes.
267          */                                       268          */
268         if (data->flags & MMC_DATA_WRITE)         269         if (data->flags & MMC_DATA_WRITE)
269                 mult <<= card->csd.r2w_factor;    270                 mult <<= card->csd.r2w_factor;
270                                                   271 
271         data->timeout_ns = card->csd.tacc_ns *    272         data->timeout_ns = card->csd.tacc_ns * mult;
272         data->timeout_clks = card->csd.tacc_cl    273         data->timeout_clks = card->csd.tacc_clks * mult;
273                                                   274 
274         /*                                        275         /*
275          * SD cards also have an upper limit o    276          * SD cards also have an upper limit on the timeout.
276          */                                       277          */
277         if (mmc_card_sd(card)) {                  278         if (mmc_card_sd(card)) {
278                 unsigned int timeout_us, limit    279                 unsigned int timeout_us, limit_us;
279                                                   280 
280                 timeout_us = data->timeout_ns     281                 timeout_us = data->timeout_ns / 1000;
281                 timeout_us += data->timeout_cl    282                 timeout_us += data->timeout_clks * 1000 /
282                         (card->host->ios.clock    283                         (card->host->ios.clock / 1000);
283                                                   284 
284                 if (data->flags & MMC_DATA_WRI    285                 if (data->flags & MMC_DATA_WRITE)
285                         /*                     !! 286                         limit_us = 250000;
286                          * The limit is really << 
287                          * insufficient for so << 
288                          */                    << 
289                         limit_us = 300000;     << 
290                 else                              287                 else
291                         limit_us = 100000;        288                         limit_us = 100000;
292                                                   289 
293                 /*                                290                 /*
294                  * SDHC cards always use these    291                  * SDHC cards always use these fixed values.
295                  */                               292                  */
296                 if (timeout_us > limit_us || m    293                 if (timeout_us > limit_us || mmc_card_blockaddr(card)) {
297                         data->timeout_ns = lim    294                         data->timeout_ns = limit_us * 1000;
298                         data->timeout_clks = 0    295                         data->timeout_clks = 0;
299                 }                                 296                 }
300         }                                         297         }
301         /*                                     << 
302          * Some cards need very high timeouts  << 
303          * The worst observed timeout was 900m << 
304          * continuous stream of data until the << 
305          * overflowed.                         << 
306          */                                    << 
307         if (mmc_host_is_spi(card->host)) {     << 
308                 if (data->flags & MMC_DATA_WRI << 
309                         if (data->timeout_ns < << 
310                                 data->timeout_ << 
311                 } else {                       << 
312                         if (data->timeout_ns < << 
313                                 data->timeout_ << 
314                 }                              << 
315         }                                      << 
316 }                                                 298 }
317 EXPORT_SYMBOL(mmc_set_data_timeout);              299 EXPORT_SYMBOL(mmc_set_data_timeout);
318                                                   300 
319 /**                                               301 /**
320  *      mmc_align_data_size - pads a transfer  << 
321  *      @card: the MMC card associated with th << 
322  *      @sz: original transfer size            << 
323  *                                             << 
324  *      Pads the original data size with a num << 
325  *      order to avoid controller bugs and/or  << 
326  *      (e.g. some controllers revert to PIO f << 
327  *                                             << 
328  *      Returns the improved size, which might << 
329  *                                             << 
330  *      Note that this function is only releva << 
331  *      single scatter gather entry.           << 
332  */                                            << 
333 unsigned int mmc_align_data_size(struct mmc_ca << 
334 {                                              << 
335         /*                                     << 
336          * FIXME: We don't have a system for t << 
337          * the core about its problems yet, so << 
338          * align the size.                     << 
339          */                                    << 
340         sz = ((sz + 3) / 4) * 4;               << 
341                                                << 
342         return sz;                             << 
343 }                                              << 
344 EXPORT_SYMBOL(mmc_align_data_size);            << 
345                                                << 
346 /**                                            << 
347  *      __mmc_claim_host - exclusively claim a    302  *      __mmc_claim_host - exclusively claim a host
348  *      @host: mmc host to claim                  303  *      @host: mmc host to claim
349  *      @abort: whether or not the operation s    304  *      @abort: whether or not the operation should be aborted
350  *                                                305  *
351  *      Claim a host for a set of operations.     306  *      Claim a host for a set of operations.  If @abort is non null and
352  *      dereference a non-zero value then this    307  *      dereference a non-zero value then this will return prematurely with
353  *      that non-zero value without acquiring     308  *      that non-zero value without acquiring the lock.  Returns zero
354  *      with the lock held otherwise.             309  *      with the lock held otherwise.
355  */                                               310  */
356 int __mmc_claim_host(struct mmc_host *host, at    311 int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
357 {                                                 312 {
358         DECLARE_WAITQUEUE(wait, current);         313         DECLARE_WAITQUEUE(wait, current);
359         unsigned long flags;                      314         unsigned long flags;
360         int stop;                                 315         int stop;
361                                                   316 
362         might_sleep();                            317         might_sleep();
363                                                   318 
364         add_wait_queue(&host->wq, &wait);         319         add_wait_queue(&host->wq, &wait);
365         spin_lock_irqsave(&host->lock, flags);    320         spin_lock_irqsave(&host->lock, flags);
366         while (1) {                               321         while (1) {
367                 set_current_state(TASK_UNINTER    322                 set_current_state(TASK_UNINTERRUPTIBLE);
368                 stop = abort ? atomic_read(abo    323                 stop = abort ? atomic_read(abort) : 0;
369                 if (stop || !host->claimed)       324                 if (stop || !host->claimed)
370                         break;                    325                         break;
371                 spin_unlock_irqrestore(&host->    326                 spin_unlock_irqrestore(&host->lock, flags);
372                 schedule();                       327                 schedule();
373                 spin_lock_irqsave(&host->lock,    328                 spin_lock_irqsave(&host->lock, flags);
374         }                                         329         }
375         set_current_state(TASK_RUNNING);          330         set_current_state(TASK_RUNNING);
376         if (!stop)                                331         if (!stop)
377                 host->claimed = 1;                332                 host->claimed = 1;
378         else                                      333         else
379                 wake_up(&host->wq);               334                 wake_up(&host->wq);
380         spin_unlock_irqrestore(&host->lock, fl    335         spin_unlock_irqrestore(&host->lock, flags);
381         remove_wait_queue(&host->wq, &wait);      336         remove_wait_queue(&host->wq, &wait);
382         return stop;                              337         return stop;
383 }                                                 338 }
384                                                   339 
385 EXPORT_SYMBOL(__mmc_claim_host);                  340 EXPORT_SYMBOL(__mmc_claim_host);
386                                                   341 
387 /**                                               342 /**
388  *      mmc_release_host - release a host         343  *      mmc_release_host - release a host
389  *      @host: mmc host to release                344  *      @host: mmc host to release
390  *                                                345  *
391  *      Release a MMC host, allowing others to    346  *      Release a MMC host, allowing others to claim the host
392  *      for their operations.                     347  *      for their operations.
393  */                                               348  */
394 void mmc_release_host(struct mmc_host *host)      349 void mmc_release_host(struct mmc_host *host)
395 {                                                 350 {
396         unsigned long flags;                      351         unsigned long flags;
397                                                   352 
398         WARN_ON(!host->claimed);                  353         WARN_ON(!host->claimed);
399                                                   354 
400         spin_lock_irqsave(&host->lock, flags);    355         spin_lock_irqsave(&host->lock, flags);
401         host->claimed = 0;                        356         host->claimed = 0;
402         spin_unlock_irqrestore(&host->lock, fl    357         spin_unlock_irqrestore(&host->lock, flags);
403                                                   358 
404         wake_up(&host->wq);                       359         wake_up(&host->wq);
405 }                                                 360 }
406                                                   361 
407 EXPORT_SYMBOL(mmc_release_host);                  362 EXPORT_SYMBOL(mmc_release_host);
408                                                   363 
409 /*                                                364 /*
410  * Internal function that does the actual ios     365  * Internal function that does the actual ios call to the host driver,
411  * optionally printing some debug output.         366  * optionally printing some debug output.
412  */                                               367  */
413 static inline void mmc_set_ios(struct mmc_host    368 static inline void mmc_set_ios(struct mmc_host *host)
414 {                                                 369 {
415         struct mmc_ios *ios = &host->ios;         370         struct mmc_ios *ios = &host->ios;
416                                                   371 
417         pr_debug("%s: clock %uHz busmode %u po    372         pr_debug("%s: clock %uHz busmode %u powermode %u cs %u Vdd %u "
418                 "width %u timing %u\n",           373                 "width %u timing %u\n",
419                  mmc_hostname(host), ios->cloc    374                  mmc_hostname(host), ios->clock, ios->bus_mode,
420                  ios->power_mode, ios->chip_se    375                  ios->power_mode, ios->chip_select, ios->vdd,
421                  ios->bus_width, ios->timing);    376                  ios->bus_width, ios->timing);
422                                                   377 
423         host->ops->set_ios(host, ios);            378         host->ops->set_ios(host, ios);
424 }                                                 379 }
425                                                   380 
426 /*                                                381 /*
427  * Control chip select pin on a host.             382  * Control chip select pin on a host.
428  */                                               383  */
429 void mmc_set_chip_select(struct mmc_host *host    384 void mmc_set_chip_select(struct mmc_host *host, int mode)
430 {                                                 385 {
431         host->ios.chip_select = mode;             386         host->ios.chip_select = mode;
432         mmc_set_ios(host);                        387         mmc_set_ios(host);
433 }                                                 388 }
434                                                   389 
435 /*                                                390 /*
436  * Sets the host clock to the highest possible    391  * Sets the host clock to the highest possible frequency that
437  * is below "hz".                                 392  * is below "hz".
438  */                                               393  */
439 void mmc_set_clock(struct mmc_host *host, unsi    394 void mmc_set_clock(struct mmc_host *host, unsigned int hz)
440 {                                                 395 {
441         WARN_ON(hz < host->f_min);                396         WARN_ON(hz < host->f_min);
442                                                   397 
443         if (hz > host->f_max)                     398         if (hz > host->f_max)
444                 hz = host->f_max;                 399                 hz = host->f_max;
445                                                   400 
446         host->ios.clock = hz;                     401         host->ios.clock = hz;
447         mmc_set_ios(host);                        402         mmc_set_ios(host);
448 }                                                 403 }
449                                                   404 
450 /*                                                405 /*
451  * Change the bus mode (open drain/push-pull)     406  * Change the bus mode (open drain/push-pull) of a host.
452  */                                               407  */
453 void mmc_set_bus_mode(struct mmc_host *host, u    408 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode)
454 {                                                 409 {
455         host->ios.bus_mode = mode;                410         host->ios.bus_mode = mode;
456         mmc_set_ios(host);                        411         mmc_set_ios(host);
457 }                                                 412 }
458                                                   413 
459 /*                                                414 /*
460  * Change data bus width of a host.               415  * Change data bus width of a host.
461  */                                               416  */
462 void mmc_set_bus_width(struct mmc_host *host,     417 void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
463 {                                                 418 {
464         host->ios.bus_width = width;              419         host->ios.bus_width = width;
465         mmc_set_ios(host);                        420         mmc_set_ios(host);
466 }                                                 421 }
467                                                   422 
468 /**                                            << 
469  * mmc_vdd_to_ocrbitnum - Convert a voltage to << 
470  * @vdd:        voltage (mV)                   << 
471  * @low_bits:   prefer low bits in boundary ca << 
472  *                                             << 
473  * This function returns the OCR bit number ac << 
474  * value. If conversion is not possible a nega << 
475  *                                             << 
476  * Depending on the @low_bits flag the functio << 
477  * on boundary voltages. For example,          << 
478  * with @low_bits = true, 3300 mV translates t << 
479  * with @low_bits = false, 3300 mV translates  << 
480  *                                             << 
481  * Any value in the [1951:1999] range translat << 
482  */                                            << 
483 static int mmc_vdd_to_ocrbitnum(int vdd, bool  << 
484 {                                              << 
485         const int max_bit = ilog2(MMC_VDD_35_3 << 
486         int bit;                               << 
487                                                << 
488         if (vdd < 1650 || vdd > 3600)          << 
489                 return -EINVAL;                << 
490                                                << 
491         if (vdd >= 1650 && vdd <= 1950)        << 
492                 return ilog2(MMC_VDD_165_195); << 
493                                                << 
494         if (low_bits)                          << 
495                 vdd -= 1;                      << 
496                                                << 
497         /* Base 2000 mV, step 100 mV, bit's ba << 
498         bit = (vdd - 2000) / 100 + 8;          << 
499         if (bit > max_bit)                     << 
500                 return max_bit;                << 
501         return bit;                            << 
502 }                                              << 
503                                                << 
504 /**                                            << 
505  * mmc_vddrange_to_ocrmask - Convert a voltage << 
506  * @vdd_min:    minimum voltage value (mV)     << 
507  * @vdd_max:    maximum voltage value (mV)     << 
508  *                                             << 
509  * This function returns the OCR mask bits acc << 
510  * and @vdd_max values. If conversion is not p << 
511  *                                             << 
512  * Notes wrt boundary cases:                   << 
513  * This function sets the OCR bits for all bou << 
514  * [3300:3400] range is translated to MMC_VDD_ << 
515  * MMC_VDD_34_35 mask.                         << 
516  */                                            << 
517 u32 mmc_vddrange_to_ocrmask(int vdd_min, int v << 
518 {                                              << 
519         u32 mask = 0;                          << 
520                                                << 
521         if (vdd_max < vdd_min)                 << 
522                 return 0;                      << 
523                                                << 
524         /* Prefer high bits for the boundary v << 
525         vdd_max = mmc_vdd_to_ocrbitnum(vdd_max << 
526         if (vdd_max < 0)                       << 
527                 return 0;                      << 
528                                                << 
529         /* Prefer low bits for the boundary vd << 
530         vdd_min = mmc_vdd_to_ocrbitnum(vdd_min << 
531         if (vdd_min < 0)                       << 
532                 return 0;                      << 
533                                                << 
534         /* Fill the mask, from max bit to min  << 
535         while (vdd_max >= vdd_min)             << 
536                 mask |= 1 << vdd_max--;        << 
537                                                << 
538         return mask;                           << 
539 }                                              << 
540 EXPORT_SYMBOL(mmc_vddrange_to_ocrmask);        << 
541                                                << 
542 #ifdef CONFIG_REGULATOR                        << 
543                                                << 
544 /**                                            << 
545  * mmc_regulator_get_ocrmask - return mask of  << 
546  * @supply: regulator to use                   << 
547  *                                             << 
548  * This returns either a negative errno, or a  << 
549  * can be provided to MMC/SD/SDIO devices usin << 
550  * regulator.  This would normally be called b << 
551  * MMC host adapter.                           << 
552  */                                            << 
553 int mmc_regulator_get_ocrmask(struct regulator << 
554 {                                              << 
555         int                     result = 0;    << 
556         int                     count;         << 
557         int                     i;             << 
558                                                << 
559         count = regulator_count_voltages(suppl << 
560         if (count < 0)                         << 
561                 return count;                  << 
562                                                << 
563         for (i = 0; i < count; i++) {          << 
564                 int             vdd_uV;        << 
565                 int             vdd_mV;        << 
566                                                << 
567                 vdd_uV = regulator_list_voltag << 
568                 if (vdd_uV <= 0)               << 
569                         continue;              << 
570                                                << 
571                 vdd_mV = vdd_uV / 1000;        << 
572                 result |= mmc_vddrange_to_ocrm << 
573         }                                      << 
574                                                << 
575         return result;                         << 
576 }                                              << 
577 EXPORT_SYMBOL(mmc_regulator_get_ocrmask);      << 
578                                                << 
579 /**                                            << 
580  * mmc_regulator_set_ocr - set regulator to ma << 
581  * @vdd_bit: zero for power off, else a bit nu << 
582  * @supply: regulator to use                   << 
583  *                                             << 
584  * Returns zero on success, else negative errn << 
585  *                                             << 
586  * MMC host drivers may use this to enable or  << 
587  * a particular supply voltage.  This would no << 
588  * set_ios() method.                           << 
589  */                                            << 
590 int mmc_regulator_set_ocr(struct regulator *su << 
591 {                                              << 
592         int                     result = 0;    << 
593         int                     min_uV, max_uV << 
594         int                     enabled;       << 
595                                                << 
596         enabled = regulator_is_enabled(supply) << 
597         if (enabled < 0)                       << 
598                 return enabled;                << 
599                                                << 
600         if (vdd_bit) {                         << 
601                 int             tmp;           << 
602                 int             voltage;       << 
603                                                << 
604                 /* REVISIT mmc_vddrange_to_ocr << 
605                  * bits this regulator doesn't << 
606                  * be too picky, most cards an << 
607                  * a 0.1V range goof (it's a s << 
608                  */                            << 
609                 tmp = vdd_bit - ilog2(MMC_VDD_ << 
610                 if (tmp == 0) {                << 
611                         min_uV = 1650 * 1000;  << 
612                         max_uV = 1950 * 1000;  << 
613                 } else {                       << 
614                         min_uV = 1900 * 1000 + << 
615                         max_uV = min_uV + 100  << 
616                 }                              << 
617                                                << 
618                 /* avoid needless changes to t << 
619                  * might not allow this operat << 
620                  */                            << 
621                 voltage = regulator_get_voltag << 
622                 if (voltage < 0)               << 
623                         result = voltage;      << 
624                 else if (voltage < min_uV || v << 
625                         result = regulator_set << 
626                 else                           << 
627                         result = 0;            << 
628                                                << 
629                 if (result == 0 && !enabled)   << 
630                         result = regulator_ena << 
631         } else if (enabled) {                  << 
632                 result = regulator_disable(sup << 
633         }                                      << 
634                                                << 
635         return result;                         << 
636 }                                              << 
637 EXPORT_SYMBOL(mmc_regulator_set_ocr);          << 
638                                                << 
639 #endif                                         << 
640                                                << 
641 /*                                                423 /*
642  * Mask off any voltages we don't support and     424  * Mask off any voltages we don't support and select
643  * the lowest voltage                             425  * the lowest voltage
644  */                                               426  */
645 u32 mmc_select_voltage(struct mmc_host *host,     427 u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
646 {                                                 428 {
647         int bit;                                  429         int bit;
648                                                   430 
649         ocr &= host->ocr_avail;                   431         ocr &= host->ocr_avail;
650                                                   432 
651         bit = ffs(ocr);                           433         bit = ffs(ocr);
652         if (bit) {                                434         if (bit) {
653                 bit -= 1;                         435                 bit -= 1;
654                                                   436 
655                 ocr &= 3 << bit;                  437                 ocr &= 3 << bit;
656                                                   438 
657                 host->ios.vdd = bit;              439                 host->ios.vdd = bit;
658                 mmc_set_ios(host);                440                 mmc_set_ios(host);
659         } else {                                  441         } else {
660                 pr_warning("%s: host doesn't s << 
661                                 mmc_hostname(h << 
662                 ocr = 0;                          442                 ocr = 0;
663         }                                         443         }
664                                                   444 
665         return ocr;                               445         return ocr;
666 }                                                 446 }
667                                                   447 
668 /*                                                448 /*
669  * Select timing parameters for host.             449  * Select timing parameters for host.
670  */                                               450  */
671 void mmc_set_timing(struct mmc_host *host, uns    451 void mmc_set_timing(struct mmc_host *host, unsigned int timing)
672 {                                                 452 {
673         host->ios.timing = timing;                453         host->ios.timing = timing;
674         mmc_set_ios(host);                        454         mmc_set_ios(host);
675 }                                                 455 }
676                                                   456 
677 /*                                                457 /*
678  * Apply power to the MMC stack.  This is a tw    458  * Apply power to the MMC stack.  This is a two-stage process.
679  * First, we enable power to the card without     459  * First, we enable power to the card without the clock running.
680  * We then wait a bit for the power to stabili    460  * We then wait a bit for the power to stabilise.  Finally,
681  * enable the bus drivers and clock to the car    461  * enable the bus drivers and clock to the card.
682  *                                                462  *
683  * We must _NOT_ enable the clock prior to pow    463  * We must _NOT_ enable the clock prior to power stablising.
684  *                                                464  *
685  * If a host does all the power sequencing its    465  * If a host does all the power sequencing itself, ignore the
686  * initial MMC_POWER_UP stage.                    466  * initial MMC_POWER_UP stage.
687  */                                               467  */
688 static void mmc_power_up(struct mmc_host *host    468 static void mmc_power_up(struct mmc_host *host)
689 {                                                 469 {
690         int bit = fls(host->ocr_avail) - 1;       470         int bit = fls(host->ocr_avail) - 1;
691                                                   471 
692         host->ios.vdd = bit;                      472         host->ios.vdd = bit;
693         if (mmc_host_is_spi(host)) {              473         if (mmc_host_is_spi(host)) {
694                 host->ios.chip_select = MMC_CS    474                 host->ios.chip_select = MMC_CS_HIGH;
695                 host->ios.bus_mode = MMC_BUSMO    475                 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
696         } else {                                  476         } else {
697                 host->ios.chip_select = MMC_CS    477                 host->ios.chip_select = MMC_CS_DONTCARE;
698                 host->ios.bus_mode = MMC_BUSMO    478                 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
699         }                                         479         }
700         host->ios.power_mode = MMC_POWER_UP;      480         host->ios.power_mode = MMC_POWER_UP;
701         host->ios.bus_width = MMC_BUS_WIDTH_1;    481         host->ios.bus_width = MMC_BUS_WIDTH_1;
702         host->ios.timing = MMC_TIMING_LEGACY;     482         host->ios.timing = MMC_TIMING_LEGACY;
703         mmc_set_ios(host);                        483         mmc_set_ios(host);
704                                                   484 
705         /*                                        485         /*
706          * This delay should be sufficient to     486          * This delay should be sufficient to allow the power supply
707          * to reach the minimum voltage.          487          * to reach the minimum voltage.
708          */                                       488          */
709         mmc_delay(10);                         !! 489         mmc_delay(2);
710                                                << 
711         if (host->f_min > 400000) {            << 
712                 pr_warning("%s: Minimum clock  << 
713                                 "identificatio << 
714                 host->ios.clock = host->f_min; << 
715         } else                                 << 
716                 host->ios.clock = 400000;      << 
717                                                   490 
                                                   >> 491         host->ios.clock = host->f_min;
718         host->ios.power_mode = MMC_POWER_ON;      492         host->ios.power_mode = MMC_POWER_ON;
719         mmc_set_ios(host);                        493         mmc_set_ios(host);
720                                                   494 
721         /*                                        495         /*
722          * This delay must be at least 74 cloc    496          * This delay must be at least 74 clock sizes, or 1 ms, or the
723          * time required to reach a stable vol    497          * time required to reach a stable voltage.
724          */                                       498          */
725         mmc_delay(10);                         !! 499         mmc_delay(2);
726 }                                                 500 }
727                                                   501 
728 static void mmc_power_off(struct mmc_host *hos    502 static void mmc_power_off(struct mmc_host *host)
729 {                                                 503 {
730         host->ios.clock = 0;                      504         host->ios.clock = 0;
731         host->ios.vdd = 0;                        505         host->ios.vdd = 0;
732         if (!mmc_host_is_spi(host)) {             506         if (!mmc_host_is_spi(host)) {
733                 host->ios.bus_mode = MMC_BUSMO    507                 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
734                 host->ios.chip_select = MMC_CS    508                 host->ios.chip_select = MMC_CS_DONTCARE;
735         }                                         509         }
736         host->ios.power_mode = MMC_POWER_OFF;     510         host->ios.power_mode = MMC_POWER_OFF;
737         host->ios.bus_width = MMC_BUS_WIDTH_1;    511         host->ios.bus_width = MMC_BUS_WIDTH_1;
738         host->ios.timing = MMC_TIMING_LEGACY;     512         host->ios.timing = MMC_TIMING_LEGACY;
739         mmc_set_ios(host);                        513         mmc_set_ios(host);
740 }                                                 514 }
741                                                   515 
742 /*                                                516 /*
743  * Cleanup when the last reference to the bus     517  * Cleanup when the last reference to the bus operator is dropped.
744  */                                               518  */
745 static void __mmc_release_bus(struct mmc_host  !! 519 void __mmc_release_bus(struct mmc_host *host)
746 {                                                 520 {
747         BUG_ON(!host);                            521         BUG_ON(!host);
748         BUG_ON(host->bus_refs);                   522         BUG_ON(host->bus_refs);
749         BUG_ON(!host->bus_dead);                  523         BUG_ON(!host->bus_dead);
750                                                   524 
751         host->bus_ops = NULL;                     525         host->bus_ops = NULL;
752 }                                                 526 }
753                                                   527 
754 /*                                                528 /*
755  * Increase reference count of bus operator       529  * Increase reference count of bus operator
756  */                                               530  */
757 static inline void mmc_bus_get(struct mmc_host    531 static inline void mmc_bus_get(struct mmc_host *host)
758 {                                                 532 {
759         unsigned long flags;                      533         unsigned long flags;
760                                                   534 
761         spin_lock_irqsave(&host->lock, flags);    535         spin_lock_irqsave(&host->lock, flags);
762         host->bus_refs++;                         536         host->bus_refs++;
763         spin_unlock_irqrestore(&host->lock, fl    537         spin_unlock_irqrestore(&host->lock, flags);
764 }                                                 538 }
765                                                   539 
766 /*                                                540 /*
767  * Decrease reference count of bus operator an    541  * Decrease reference count of bus operator and free it if
768  * it is the last reference.                      542  * it is the last reference.
769  */                                               543  */
770 static inline void mmc_bus_put(struct mmc_host    544 static inline void mmc_bus_put(struct mmc_host *host)
771 {                                                 545 {
772         unsigned long flags;                      546         unsigned long flags;
773                                                   547 
774         spin_lock_irqsave(&host->lock, flags);    548         spin_lock_irqsave(&host->lock, flags);
775         host->bus_refs--;                         549         host->bus_refs--;
776         if ((host->bus_refs == 0) && host->bus    550         if ((host->bus_refs == 0) && host->bus_ops)
777                 __mmc_release_bus(host);          551                 __mmc_release_bus(host);
778         spin_unlock_irqrestore(&host->lock, fl    552         spin_unlock_irqrestore(&host->lock, flags);
779 }                                                 553 }
780                                                   554 
781 /*                                                555 /*
782  * Assign a mmc bus handler to a host. Only on    556  * Assign a mmc bus handler to a host. Only one bus handler may control a
783  * host at any given time.                        557  * host at any given time.
784  */                                               558  */
785 void mmc_attach_bus(struct mmc_host *host, con    559 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
786 {                                                 560 {
787         unsigned long flags;                      561         unsigned long flags;
788                                                   562 
789         BUG_ON(!host);                            563         BUG_ON(!host);
790         BUG_ON(!ops);                             564         BUG_ON(!ops);
791                                                   565 
792         WARN_ON(!host->claimed);                  566         WARN_ON(!host->claimed);
793                                                   567 
794         spin_lock_irqsave(&host->lock, flags);    568         spin_lock_irqsave(&host->lock, flags);
795                                                   569 
796         BUG_ON(host->bus_ops);                    570         BUG_ON(host->bus_ops);
797         BUG_ON(host->bus_refs);                   571         BUG_ON(host->bus_refs);
798                                                   572 
799         host->bus_ops = ops;                      573         host->bus_ops = ops;
800         host->bus_refs = 1;                       574         host->bus_refs = 1;
801         host->bus_dead = 0;                       575         host->bus_dead = 0;
802                                                   576 
803         spin_unlock_irqrestore(&host->lock, fl    577         spin_unlock_irqrestore(&host->lock, flags);
804 }                                                 578 }
805                                                   579 
806 /*                                                580 /*
807  * Remove the current bus handler from a host.    581  * Remove the current bus handler from a host. Assumes that there are
808  * no interesting cards left, so the bus is po    582  * no interesting cards left, so the bus is powered down.
809  */                                               583  */
810 void mmc_detach_bus(struct mmc_host *host)        584 void mmc_detach_bus(struct mmc_host *host)
811 {                                                 585 {
812         unsigned long flags;                      586         unsigned long flags;
813                                                   587 
814         BUG_ON(!host);                            588         BUG_ON(!host);
815                                                   589 
816         WARN_ON(!host->claimed);                  590         WARN_ON(!host->claimed);
817         WARN_ON(!host->bus_ops);                  591         WARN_ON(!host->bus_ops);
818                                                   592 
819         spin_lock_irqsave(&host->lock, flags);    593         spin_lock_irqsave(&host->lock, flags);
820                                                   594 
821         host->bus_dead = 1;                       595         host->bus_dead = 1;
822                                                   596 
823         spin_unlock_irqrestore(&host->lock, fl    597         spin_unlock_irqrestore(&host->lock, flags);
824                                                   598 
825         mmc_power_off(host);                      599         mmc_power_off(host);
826                                                   600 
827         mmc_bus_put(host);                        601         mmc_bus_put(host);
828 }                                                 602 }
829                                                   603 
830 /**                                               604 /**
831  *      mmc_detect_change - process change of     605  *      mmc_detect_change - process change of state on a MMC socket
832  *      @host: host which changed state.          606  *      @host: host which changed state.
833  *      @delay: optional delay to wait before     607  *      @delay: optional delay to wait before detection (jiffies)
834  *                                                608  *
835  *      MMC drivers should call this when they    609  *      MMC drivers should call this when they detect a card has been
836  *      inserted or removed. The MMC layer wil    610  *      inserted or removed. The MMC layer will confirm that any
837  *      present card is still functional, and     611  *      present card is still functional, and initialize any newly
838  *      inserted.                                 612  *      inserted.
839  */                                               613  */
840 void mmc_detect_change(struct mmc_host *host,     614 void mmc_detect_change(struct mmc_host *host, unsigned long delay)
841 {                                                 615 {
842 #ifdef CONFIG_MMC_DEBUG                           616 #ifdef CONFIG_MMC_DEBUG
843         unsigned long flags;                      617         unsigned long flags;
844         spin_lock_irqsave(&host->lock, flags);    618         spin_lock_irqsave(&host->lock, flags);
845         WARN_ON(host->removed);                   619         WARN_ON(host->removed);
846         spin_unlock_irqrestore(&host->lock, fl    620         spin_unlock_irqrestore(&host->lock, flags);
847 #endif                                            621 #endif
848                                                   622 
849         mmc_schedule_delayed_work(&host->detec    623         mmc_schedule_delayed_work(&host->detect, delay);
850 }                                                 624 }
851                                                   625 
852 EXPORT_SYMBOL(mmc_detect_change);                 626 EXPORT_SYMBOL(mmc_detect_change);
853                                                   627 
854                                                   628 
855 void mmc_rescan(struct work_struct *work)         629 void mmc_rescan(struct work_struct *work)
856 {                                                 630 {
857         struct mmc_host *host =                   631         struct mmc_host *host =
858                 container_of(work, struct mmc_    632                 container_of(work, struct mmc_host, detect.work);
859         u32 ocr;                                  633         u32 ocr;
860         int err;                                  634         int err;
861                                                   635 
862         mmc_bus_get(host);                        636         mmc_bus_get(host);
863                                                   637 
864         /* if there is a card registered, chec !! 638         if (host->bus_ops == NULL) {
865         if ((host->bus_ops != NULL) && host->b !! 639                 /*
866                 host->bus_ops->detect(host);   !! 640                  * Only we can add a new handler, so it's safe to
867                                                !! 641                  * release the lock here.
868         mmc_bus_put(host);                     !! 642                  */
869                                                << 
870                                                << 
871         mmc_bus_get(host);                     << 
872                                                << 
873         /* if there still is a card present, s << 
874         if (host->bus_ops != NULL) {           << 
875                 mmc_bus_put(host);                643                 mmc_bus_put(host);
876                 goto out;                      << 
877         }                                      << 
878                                                   644 
879         /* detect a newly inserted card */     !! 645                 mmc_claim_host(host);
880                                                << 
881         /*                                     << 
882          * Only we can add a new handler, so i << 
883          * release the lock here.              << 
884          */                                    << 
885         mmc_bus_put(host);                     << 
886                                                   646 
887         if (host->ops->get_cd && host->ops->ge !! 647                 mmc_power_up(host);
888                 goto out;                      !! 648                 mmc_go_idle(host);
889                                                   649 
890         mmc_claim_host(host);                  !! 650                 mmc_send_if_cond(host, host->ocr_avail);
891                                                   651 
892         mmc_power_up(host);                    !! 652                 /*
893         mmc_go_idle(host);                     !! 653                  * First we search for SDIO...
                                                   >> 654                  */
                                                   >> 655                 err = mmc_send_io_op_cond(host, 0, &ocr);
                                                   >> 656                 if (!err) {
                                                   >> 657                         if (mmc_attach_sdio(host, ocr))
                                                   >> 658                                 mmc_power_off(host);
                                                   >> 659                         return;
                                                   >> 660                 }
894                                                   661 
895         mmc_send_if_cond(host, host->ocr_avail !! 662                 /*
                                                   >> 663                  * ...then normal SD...
                                                   >> 664                  */
                                                   >> 665                 err = mmc_send_app_op_cond(host, 0, &ocr);
                                                   >> 666                 if (!err) {
                                                   >> 667                         if (mmc_attach_sd(host, ocr))
                                                   >> 668                                 mmc_power_off(host);
                                                   >> 669                         return;
                                                   >> 670                 }
896                                                   671 
897         /*                                     !! 672                 /*
898          * First we search for SDIO...         !! 673                  * ...and finally MMC.
899          */                                    !! 674                  */
900         err = mmc_send_io_op_cond(host, 0, &oc !! 675                 err = mmc_send_op_cond(host, 0, &ocr);
901         if (!err) {                            !! 676                 if (!err) {
902                 if (mmc_attach_sdio(host, ocr) !! 677                         if (mmc_attach_mmc(host, ocr))
903                         mmc_power_off(host);   !! 678                                 mmc_power_off(host);
904                 goto out;                      !! 679                         return;
905         }                                      !! 680                 }
906                                                   681 
907         /*                                     !! 682                 mmc_release_host(host);
908          * ...then normal SD...                !! 683                 mmc_power_off(host);
909          */                                    !! 684         } else {
910         err = mmc_send_app_op_cond(host, 0, &o !! 685                 if (host->bus_ops->detect && !host->bus_dead)
911         if (!err) {                            !! 686                         host->bus_ops->detect(host);
912                 if (mmc_attach_sd(host, ocr))  << 
913                         mmc_power_off(host);   << 
914                 goto out;                      << 
915         }                                      << 
916                                                   687 
917         /*                                     !! 688                 mmc_bus_put(host);
918          * ...and finally MMC.                 << 
919          */                                    << 
920         err = mmc_send_op_cond(host, 0, &ocr); << 
921         if (!err) {                            << 
922                 if (mmc_attach_mmc(host, ocr)) << 
923                         mmc_power_off(host);   << 
924                 goto out;                      << 
925         }                                         689         }
926                                                << 
927         mmc_release_host(host);                << 
928         mmc_power_off(host);                   << 
929                                                << 
930 out:                                           << 
931         if (host->caps & MMC_CAP_NEEDS_POLL)   << 
932                 mmc_schedule_delayed_work(&hos << 
933 }                                                 690 }
934                                                   691 
935 void mmc_start_host(struct mmc_host *host)        692 void mmc_start_host(struct mmc_host *host)
936 {                                                 693 {
937         mmc_power_off(host);                      694         mmc_power_off(host);
938         mmc_detect_change(host, 0);               695         mmc_detect_change(host, 0);
939 }                                                 696 }
940                                                   697 
941 void mmc_stop_host(struct mmc_host *host)         698 void mmc_stop_host(struct mmc_host *host)
942 {                                                 699 {
943 #ifdef CONFIG_MMC_DEBUG                           700 #ifdef CONFIG_MMC_DEBUG
944         unsigned long flags;                      701         unsigned long flags;
945         spin_lock_irqsave(&host->lock, flags);    702         spin_lock_irqsave(&host->lock, flags);
946         host->removed = 1;                        703         host->removed = 1;
947         spin_unlock_irqrestore(&host->lock, fl    704         spin_unlock_irqrestore(&host->lock, flags);
948 #endif                                            705 #endif
949                                                   706 
950         cancel_delayed_work(&host->detect);    << 
951         mmc_flush_scheduled_work();               707         mmc_flush_scheduled_work();
952                                                   708 
953         mmc_bus_get(host);                        709         mmc_bus_get(host);
954         if (host->bus_ops && !host->bus_dead)     710         if (host->bus_ops && !host->bus_dead) {
955                 if (host->bus_ops->remove)        711                 if (host->bus_ops->remove)
956                         host->bus_ops->remove(    712                         host->bus_ops->remove(host);
957                                                   713 
958                 mmc_claim_host(host);             714                 mmc_claim_host(host);
959                 mmc_detach_bus(host);             715                 mmc_detach_bus(host);
960                 mmc_release_host(host);           716                 mmc_release_host(host);
961         }                                         717         }
962         mmc_bus_put(host);                        718         mmc_bus_put(host);
963                                                   719 
964         BUG_ON(host->card);                       720         BUG_ON(host->card);
965                                                   721 
966         mmc_power_off(host);                      722         mmc_power_off(host);
967 }                                                 723 }
968                                                   724 
969 #ifdef CONFIG_PM                                  725 #ifdef CONFIG_PM
970                                                   726 
971 /**                                               727 /**
972  *      mmc_suspend_host - suspend a host         728  *      mmc_suspend_host - suspend a host
973  *      @host: mmc host                           729  *      @host: mmc host
974  *      @state: suspend mode (PM_SUSPEND_xxx)     730  *      @state: suspend mode (PM_SUSPEND_xxx)
975  */                                               731  */
976 int mmc_suspend_host(struct mmc_host *host, pm    732 int mmc_suspend_host(struct mmc_host *host, pm_message_t state)
977 {                                                 733 {
978         cancel_delayed_work(&host->detect);    << 
979         mmc_flush_scheduled_work();               734         mmc_flush_scheduled_work();
980                                                   735 
981         mmc_bus_get(host);                        736         mmc_bus_get(host);
982         if (host->bus_ops && !host->bus_dead)     737         if (host->bus_ops && !host->bus_dead) {
983                 if (host->bus_ops->suspend)       738                 if (host->bus_ops->suspend)
984                         host->bus_ops->suspend    739                         host->bus_ops->suspend(host);
985                 if (!host->bus_ops->resume) {     740                 if (!host->bus_ops->resume) {
986                         if (host->bus_ops->rem    741                         if (host->bus_ops->remove)
987                                 host->bus_ops-    742                                 host->bus_ops->remove(host);
988                                                   743 
989                         mmc_claim_host(host);     744                         mmc_claim_host(host);
990                         mmc_detach_bus(host);     745                         mmc_detach_bus(host);
991                         mmc_release_host(host)    746                         mmc_release_host(host);
992                 }                                 747                 }
993         }                                         748         }
994         mmc_bus_put(host);                        749         mmc_bus_put(host);
995                                                   750 
996         mmc_power_off(host);                      751         mmc_power_off(host);
997                                                   752 
998         return 0;                                 753         return 0;
999 }                                                 754 }
1000                                                  755 
1001 EXPORT_SYMBOL(mmc_suspend_host);                 756 EXPORT_SYMBOL(mmc_suspend_host);
1002                                                  757 
1003 /**                                              758 /**
1004  *      mmc_resume_host - resume a previously    759  *      mmc_resume_host - resume a previously suspended host
1005  *      @host: mmc host                          760  *      @host: mmc host
1006  */                                              761  */
1007 int mmc_resume_host(struct mmc_host *host)       762 int mmc_resume_host(struct mmc_host *host)
1008 {                                                763 {
1009         mmc_bus_get(host);                       764         mmc_bus_get(host);
1010         if (host->bus_ops && !host->bus_dead)    765         if (host->bus_ops && !host->bus_dead) {
1011                 mmc_power_up(host);              766                 mmc_power_up(host);
1012                 mmc_select_voltage(host, host << 
1013                 BUG_ON(!host->bus_ops->resume    767                 BUG_ON(!host->bus_ops->resume);
1014                 host->bus_ops->resume(host);     768                 host->bus_ops->resume(host);
1015         }                                        769         }
1016         mmc_bus_put(host);                       770         mmc_bus_put(host);
1017                                                  771 
1018         /*                                       772         /*
1019          * We add a slight delay here so that    773          * We add a slight delay here so that resume can progress
1020          * in parallel.                          774          * in parallel.
1021          */                                      775          */
1022         mmc_detect_change(host, 1);              776         mmc_detect_change(host, 1);
1023                                                  777 
1024         return 0;                                778         return 0;
1025 }                                                779 }
1026                                                  780 
1027 EXPORT_SYMBOL(mmc_resume_host);                  781 EXPORT_SYMBOL(mmc_resume_host);
1028                                                  782 
1029 #endif                                           783 #endif
1030                                                  784 
1031 static int __init mmc_init(void)                 785 static int __init mmc_init(void)
1032 {                                                786 {
1033         int ret;                                 787         int ret;
1034                                                  788 
1035         workqueue = create_singlethread_workq    789         workqueue = create_singlethread_workqueue("kmmcd");
1036         if (!workqueue)                          790         if (!workqueue)
1037                 return -ENOMEM;                  791                 return -ENOMEM;
1038                                                  792 
1039         ret = mmc_register_bus();                793         ret = mmc_register_bus();
1040         if (ret)                                 794         if (ret)
1041                 goto destroy_workqueue;          795                 goto destroy_workqueue;
1042                                                  796 
1043         ret = mmc_register_host_class();         797         ret = mmc_register_host_class();
1044         if (ret)                                 798         if (ret)
1045                 goto unregister_bus;             799                 goto unregister_bus;
1046                                                  800 
1047         ret = sdio_register_bus();               801         ret = sdio_register_bus();
1048         if (ret)                                 802         if (ret)
1049                 goto unregister_host_class;      803                 goto unregister_host_class;
1050                                                  804 
1051         return 0;                                805         return 0;
1052                                                  806 
1053 unregister_host_class:                           807 unregister_host_class:
1054         mmc_unregister_host_class();             808         mmc_unregister_host_class();
1055 unregister_bus:                                  809 unregister_bus:
1056         mmc_unregister_bus();                    810         mmc_unregister_bus();
1057 destroy_workqueue:                               811 destroy_workqueue:
1058         destroy_workqueue(workqueue);            812         destroy_workqueue(workqueue);
1059                                                  813 
1060         return ret;                              814         return ret;
1061 }                                                815 }
1062                                                  816 
1063 static void __exit mmc_exit(void)                817 static void __exit mmc_exit(void)
1064 {                                                818 {
1065         sdio_unregister_bus();                   819         sdio_unregister_bus();
1066         mmc_unregister_host_class();             820         mmc_unregister_host_class();
1067         mmc_unregister_bus();                    821         mmc_unregister_bus();
1068         destroy_workqueue(workqueue);            822         destroy_workqueue(workqueue);
1069 }                                                823 }
1070                                                  824 
1071 subsys_initcall(mmc_init);                       825 subsys_initcall(mmc_init);
1072 module_exit(mmc_exit);                           826 module_exit(mmc_exit);
1073                                                  827 
1074 MODULE_LICENSE("GPL");                           828 MODULE_LICENSE("GPL");
1075                                                  829 
  This page was automatically generated by the LXR engine.