Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Pierre Ossman | aaac1b4 | 2007-02-28 15:33:10 +0100 | [diff] [blame] | 2 | * linux/drivers/mmc/core/core.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2003-2004 Russell King, All Rights Reserved. |
Pierre Ossman | 5b4fd9a | 2005-09-06 15:18:56 -0700 | [diff] [blame] | 5 | * SD support Copyright (C) 2004 Ian Molton, All Rights Reserved. |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 6 | * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved. |
Philip Langdale | bce40a3 | 2006-10-21 12:35:02 +0200 | [diff] [blame] | 7 | * MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/completion.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/pagemap.h> |
| 20 | #include <linux/err.h> |
Pierre Ossman | b57c43a | 2005-09-06 15:18:53 -0700 | [diff] [blame] | 21 | #include <asm/scatterlist.h> |
| 22 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | #include <linux/mmc/card.h> |
| 25 | #include <linux/mmc/host.h> |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 26 | #include <linux/mmc/mmc.h> |
| 27 | #include <linux/mmc/sd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Pierre Ossman | aaac1b4 | 2007-02-28 15:33:10 +0100 | [diff] [blame] | 29 | #include "core.h" |
Pierre Ossman | ffce2e7 | 2007-05-19 14:32:22 +0200 | [diff] [blame] | 30 | #include "bus.h" |
| 31 | #include "host.h" |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 32 | |
| 33 | #include "mmc_ops.h" |
| 34 | #include "sd_ops.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 36 | extern int mmc_attach_mmc(struct mmc_host *host, u32 ocr); |
| 37 | extern int mmc_attach_sd(struct mmc_host *host, u32 ocr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Pierre Ossman | ffce2e7 | 2007-05-19 14:32:22 +0200 | [diff] [blame] | 39 | static struct workqueue_struct *workqueue; |
| 40 | |
| 41 | /* |
| 42 | * Internal function. Schedule delayed work in the MMC work queue. |
| 43 | */ |
| 44 | static int mmc_schedule_delayed_work(struct delayed_work *work, |
| 45 | unsigned long delay) |
| 46 | { |
| 47 | return queue_delayed_work(workqueue, work, delay); |
| 48 | } |
| 49 | |
| 50 | /* |
| 51 | * Internal function. Flush all scheduled work from the MMC work queue. |
| 52 | */ |
| 53 | static void mmc_flush_scheduled_work(void) |
| 54 | { |
| 55 | flush_workqueue(workqueue); |
| 56 | } |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | /** |
Russell King | fe10c6a | 2006-05-04 13:51:45 +0100 | [diff] [blame] | 59 | * mmc_request_done - finish processing an MMC request |
| 60 | * @host: MMC host which completed request |
| 61 | * @mrq: MMC request which request |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * |
| 63 | * MMC drivers should call this function when they have completed |
Russell King | fe10c6a | 2006-05-04 13:51:45 +0100 | [diff] [blame] | 64 | * their processing of a request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | */ |
| 66 | void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq) |
| 67 | { |
| 68 | struct mmc_command *cmd = mrq->cmd; |
Russell King | 920e70c | 2006-05-04 18:22:51 +0100 | [diff] [blame] | 69 | int err = cmd->error; |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | if (err && cmd->retries) { |
Pierre Ossman | e4d2170 | 2007-07-24 21:46:49 +0200 | [diff] [blame] | 72 | pr_debug("%s: req failed (CMD%u): %d, retrying...\n", |
| 73 | mmc_hostname(host), cmd->opcode, err); |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | cmd->retries--; |
| 76 | cmd->error = 0; |
| 77 | host->ops->request(host, mrq); |
Pierre Ossman | e4d2170 | 2007-07-24 21:46:49 +0200 | [diff] [blame] | 78 | } else { |
| 79 | pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n", |
| 80 | mmc_hostname(host), cmd->opcode, err, |
| 81 | cmd->resp[0], cmd->resp[1], |
| 82 | cmd->resp[2], cmd->resp[3]); |
| 83 | |
| 84 | if (mrq->data) { |
| 85 | pr_debug("%s: %d bytes transferred: %d\n", |
| 86 | mmc_hostname(host), |
| 87 | mrq->data->bytes_xfered, mrq->data->error); |
| 88 | } |
| 89 | |
| 90 | if (mrq->stop) { |
| 91 | pr_debug("%s: (CMD%u): %d: %08x %08x %08x %08x\n", |
| 92 | mmc_hostname(host), mrq->stop->opcode, |
| 93 | mrq->stop->error, |
| 94 | mrq->stop->resp[0], mrq->stop->resp[1], |
| 95 | mrq->stop->resp[2], mrq->stop->resp[3]); |
| 96 | } |
| 97 | |
| 98 | if (mrq->done) |
| 99 | mrq->done(mrq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
| 103 | EXPORT_SYMBOL(mmc_request_done); |
| 104 | |
| 105 | /** |
| 106 | * mmc_start_request - start a command on a host |
| 107 | * @host: MMC host to start command on |
| 108 | * @mrq: MMC request to start |
| 109 | * |
| 110 | * Queue a command on the specified host. We expect the |
| 111 | * caller to be holding the host lock with interrupts disabled. |
| 112 | */ |
| 113 | void |
| 114 | mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) |
| 115 | { |
Pierre Ossman | 976d927 | 2007-04-13 22:47:01 +0200 | [diff] [blame] | 116 | #ifdef CONFIG_MMC_DEBUG |
| 117 | unsigned int i, sz; |
| 118 | #endif |
| 119 | |
Russell King | 920e70c | 2006-05-04 18:22:51 +0100 | [diff] [blame] | 120 | pr_debug("%s: starting CMD%u arg %08x flags %08x\n", |
| 121 | mmc_hostname(host), mrq->cmd->opcode, |
| 122 | mrq->cmd->arg, mrq->cmd->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Pierre Ossman | e4d2170 | 2007-07-24 21:46:49 +0200 | [diff] [blame] | 124 | if (mrq->data) { |
| 125 | pr_debug("%s: blksz %d blocks %d flags %08x " |
| 126 | "tsac %d ms nsac %d\n", |
| 127 | mmc_hostname(host), mrq->data->blksz, |
| 128 | mrq->data->blocks, mrq->data->flags, |
| 129 | mrq->data->timeout_ns / 10000000, |
| 130 | mrq->data->timeout_clks); |
| 131 | } |
| 132 | |
| 133 | if (mrq->stop) { |
| 134 | pr_debug("%s: CMD%u arg %08x flags %08x\n", |
| 135 | mmc_hostname(host), mrq->stop->opcode, |
| 136 | mrq->stop->arg, mrq->stop->flags); |
| 137 | } |
| 138 | |
Pierre Ossman | f22ee4e | 2006-12-26 15:11:23 +0100 | [diff] [blame] | 139 | WARN_ON(!host->claimed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | mrq->cmd->error = 0; |
| 142 | mrq->cmd->mrq = mrq; |
| 143 | if (mrq->data) { |
Pierre Ossman | fe4a3c7 | 2006-11-21 17:54:23 +0100 | [diff] [blame] | 144 | BUG_ON(mrq->data->blksz > host->max_blk_size); |
Pierre Ossman | 55db890 | 2006-11-21 17:55:45 +0100 | [diff] [blame] | 145 | BUG_ON(mrq->data->blocks > host->max_blk_count); |
| 146 | BUG_ON(mrq->data->blocks * mrq->data->blksz > |
| 147 | host->max_req_size); |
Pierre Ossman | fe4a3c7 | 2006-11-21 17:54:23 +0100 | [diff] [blame] | 148 | |
Pierre Ossman | 976d927 | 2007-04-13 22:47:01 +0200 | [diff] [blame] | 149 | #ifdef CONFIG_MMC_DEBUG |
| 150 | sz = 0; |
| 151 | for (i = 0;i < mrq->data->sg_len;i++) |
| 152 | sz += mrq->data->sg[i].length; |
| 153 | BUG_ON(sz != mrq->data->blocks * mrq->data->blksz); |
| 154 | #endif |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | mrq->cmd->data = mrq->data; |
| 157 | mrq->data->error = 0; |
| 158 | mrq->data->mrq = mrq; |
| 159 | if (mrq->stop) { |
| 160 | mrq->data->stop = mrq->stop; |
| 161 | mrq->stop->error = 0; |
| 162 | mrq->stop->mrq = mrq; |
| 163 | } |
| 164 | } |
| 165 | host->ops->request(host, mrq); |
| 166 | } |
| 167 | |
| 168 | EXPORT_SYMBOL(mmc_start_request); |
| 169 | |
| 170 | static void mmc_wait_done(struct mmc_request *mrq) |
| 171 | { |
| 172 | complete(mrq->done_data); |
| 173 | } |
| 174 | |
Pierre Ossman | 67a61c4 | 2007-07-11 20:22:11 +0200 | [diff] [blame] | 175 | /** |
| 176 | * mmc_wait_for_req - start a request and wait for completion |
| 177 | * @host: MMC host to start command |
| 178 | * @mrq: MMC request to start |
| 179 | * |
| 180 | * Start a new MMC custom command request for a host, and wait |
| 181 | * for the command to complete. Does not attempt to parse the |
| 182 | * response. |
| 183 | */ |
| 184 | void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
Ingo Molnar | 0afffc7 | 2006-07-03 00:25:35 -0700 | [diff] [blame] | 186 | DECLARE_COMPLETION_ONSTACK(complete); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | mrq->done_data = &complete; |
| 189 | mrq->done = mmc_wait_done; |
| 190 | |
| 191 | mmc_start_request(host, mrq); |
| 192 | |
| 193 | wait_for_completion(&complete); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | EXPORT_SYMBOL(mmc_wait_for_req); |
| 197 | |
| 198 | /** |
| 199 | * mmc_wait_for_cmd - start a command and wait for completion |
| 200 | * @host: MMC host to start command |
| 201 | * @cmd: MMC command to start |
| 202 | * @retries: maximum number of retries |
| 203 | * |
| 204 | * Start a new MMC command for a host, and wait for the command |
| 205 | * to complete. Return any error that occurred while the command |
| 206 | * was executing. Do not attempt to parse the response. |
| 207 | */ |
| 208 | int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries) |
| 209 | { |
| 210 | struct mmc_request mrq; |
| 211 | |
Pierre Ossman | f22ee4e | 2006-12-26 15:11:23 +0100 | [diff] [blame] | 212 | BUG_ON(!host->claimed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | memset(&mrq, 0, sizeof(struct mmc_request)); |
| 215 | |
| 216 | memset(cmd->resp, 0, sizeof(cmd->resp)); |
| 217 | cmd->retries = retries; |
| 218 | |
| 219 | mrq.cmd = cmd; |
| 220 | cmd->data = NULL; |
| 221 | |
| 222 | mmc_wait_for_req(host, &mrq); |
| 223 | |
| 224 | return cmd->error; |
| 225 | } |
| 226 | |
| 227 | EXPORT_SYMBOL(mmc_wait_for_cmd); |
| 228 | |
Pierre Ossman | 335eadf | 2005-09-06 15:18:50 -0700 | [diff] [blame] | 229 | /** |
Russell King | d773d72 | 2006-09-07 15:57:12 +0100 | [diff] [blame] | 230 | * mmc_set_data_timeout - set the timeout for a data command |
| 231 | * @data: data phase for command |
| 232 | * @card: the MMC card associated with the data transfer |
| 233 | * @write: flag to differentiate reads from writes |
Pierre Ossman | 67a61c4 | 2007-07-11 20:22:11 +0200 | [diff] [blame] | 234 | * |
| 235 | * Computes the data timeout parameters according to the |
| 236 | * correct algorithm given the card type. |
Russell King | d773d72 | 2006-09-07 15:57:12 +0100 | [diff] [blame] | 237 | */ |
| 238 | void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card, |
| 239 | int write) |
| 240 | { |
| 241 | unsigned int mult; |
| 242 | |
| 243 | /* |
| 244 | * SD cards use a 100 multiplier rather than 10 |
| 245 | */ |
| 246 | mult = mmc_card_sd(card) ? 100 : 10; |
| 247 | |
| 248 | /* |
| 249 | * Scale up the multiplier (and therefore the timeout) by |
| 250 | * the r2w factor for writes. |
| 251 | */ |
| 252 | if (write) |
| 253 | mult <<= card->csd.r2w_factor; |
| 254 | |
| 255 | data->timeout_ns = card->csd.tacc_ns * mult; |
| 256 | data->timeout_clks = card->csd.tacc_clks * mult; |
| 257 | |
| 258 | /* |
| 259 | * SD cards also have an upper limit on the timeout. |
| 260 | */ |
| 261 | if (mmc_card_sd(card)) { |
| 262 | unsigned int timeout_us, limit_us; |
| 263 | |
| 264 | timeout_us = data->timeout_ns / 1000; |
| 265 | timeout_us += data->timeout_clks * 1000 / |
| 266 | (card->host->ios.clock / 1000); |
| 267 | |
| 268 | if (write) |
| 269 | limit_us = 250000; |
| 270 | else |
| 271 | limit_us = 100000; |
| 272 | |
Philip Langdale | fba68bd | 2007-01-04 06:57:32 -0800 | [diff] [blame] | 273 | /* |
| 274 | * SDHC cards always use these fixed values. |
| 275 | */ |
| 276 | if (timeout_us > limit_us || mmc_card_blockaddr(card)) { |
Russell King | d773d72 | 2006-09-07 15:57:12 +0100 | [diff] [blame] | 277 | data->timeout_ns = limit_us * 1000; |
| 278 | data->timeout_clks = 0; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | EXPORT_SYMBOL(mmc_set_data_timeout); |
| 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | /** |
Pierre Ossman | 67a61c4 | 2007-07-11 20:22:11 +0200 | [diff] [blame] | 285 | * mmc_claim_host - exclusively claim a host |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | * @host: mmc host to claim |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | * |
Pierre Ossman | 67a61c4 | 2007-07-11 20:22:11 +0200 | [diff] [blame] | 288 | * Claim a host for a set of operations. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | */ |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 290 | void mmc_claim_host(struct mmc_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | { |
| 292 | DECLARE_WAITQUEUE(wait, current); |
| 293 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
Pierre Ossman | cf795bf | 2007-07-11 20:28:02 +0200 | [diff] [blame] | 295 | might_sleep(); |
| 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | add_wait_queue(&host->wq, &wait); |
| 298 | spin_lock_irqsave(&host->lock, flags); |
| 299 | while (1) { |
| 300 | set_current_state(TASK_UNINTERRUPTIBLE); |
Pierre Ossman | f22ee4e | 2006-12-26 15:11:23 +0100 | [diff] [blame] | 301 | if (!host->claimed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | break; |
| 303 | spin_unlock_irqrestore(&host->lock, flags); |
| 304 | schedule(); |
| 305 | spin_lock_irqsave(&host->lock, flags); |
| 306 | } |
| 307 | set_current_state(TASK_RUNNING); |
Pierre Ossman | f22ee4e | 2006-12-26 15:11:23 +0100 | [diff] [blame] | 308 | host->claimed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | spin_unlock_irqrestore(&host->lock, flags); |
| 310 | remove_wait_queue(&host->wq, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 313 | EXPORT_SYMBOL(mmc_claim_host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
| 315 | /** |
| 316 | * mmc_release_host - release a host |
| 317 | * @host: mmc host to release |
| 318 | * |
| 319 | * Release a MMC host, allowing others to claim the host |
| 320 | * for their operations. |
| 321 | */ |
| 322 | void mmc_release_host(struct mmc_host *host) |
| 323 | { |
| 324 | unsigned long flags; |
| 325 | |
Pierre Ossman | f22ee4e | 2006-12-26 15:11:23 +0100 | [diff] [blame] | 326 | BUG_ON(!host->claimed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
| 328 | spin_lock_irqsave(&host->lock, flags); |
Pierre Ossman | f22ee4e | 2006-12-26 15:11:23 +0100 | [diff] [blame] | 329 | host->claimed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | spin_unlock_irqrestore(&host->lock, flags); |
| 331 | |
| 332 | wake_up(&host->wq); |
| 333 | } |
| 334 | |
| 335 | EXPORT_SYMBOL(mmc_release_host); |
| 336 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 337 | /* |
| 338 | * Internal function that does the actual ios call to the host driver, |
| 339 | * optionally printing some debug output. |
| 340 | */ |
Russell King | 920e70c | 2006-05-04 18:22:51 +0100 | [diff] [blame] | 341 | static inline void mmc_set_ios(struct mmc_host *host) |
| 342 | { |
| 343 | struct mmc_ios *ios = &host->ios; |
| 344 | |
Pierre Ossman | cd9277c | 2007-02-18 12:07:47 +0100 | [diff] [blame] | 345 | pr_debug("%s: clock %uHz busmode %u powermode %u cs %u Vdd %u " |
| 346 | "width %u timing %u\n", |
Russell King | 920e70c | 2006-05-04 18:22:51 +0100 | [diff] [blame] | 347 | mmc_hostname(host), ios->clock, ios->bus_mode, |
| 348 | ios->power_mode, ios->chip_select, ios->vdd, |
Pierre Ossman | cd9277c | 2007-02-18 12:07:47 +0100 | [diff] [blame] | 349 | ios->bus_width, ios->timing); |
Philip Langdale | fba68bd | 2007-01-04 06:57:32 -0800 | [diff] [blame] | 350 | |
Russell King | 920e70c | 2006-05-04 18:22:51 +0100 | [diff] [blame] | 351 | host->ops->set_ios(host, ios); |
| 352 | } |
| 353 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 354 | /* |
| 355 | * Control chip select pin on a host. |
| 356 | */ |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 357 | void mmc_set_chip_select(struct mmc_host *host, int mode) |
Pierre Ossman | b57c43a | 2005-09-06 15:18:53 -0700 | [diff] [blame] | 358 | { |
Pierre Ossman | da7fbe5 | 2006-12-24 22:46:55 +0100 | [diff] [blame] | 359 | host->ios.chip_select = mode; |
| 360 | mmc_set_ios(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /* |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 364 | * Sets the host clock to the highest possible frequency that |
| 365 | * is below "hz". |
| 366 | */ |
| 367 | void mmc_set_clock(struct mmc_host *host, unsigned int hz) |
| 368 | { |
| 369 | WARN_ON(hz < host->f_min); |
| 370 | |
| 371 | if (hz > host->f_max) |
| 372 | hz = host->f_max; |
| 373 | |
| 374 | host->ios.clock = hz; |
| 375 | mmc_set_ios(host); |
| 376 | } |
| 377 | |
| 378 | /* |
| 379 | * Change the bus mode (open drain/push-pull) of a host. |
| 380 | */ |
| 381 | void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode) |
| 382 | { |
| 383 | host->ios.bus_mode = mode; |
| 384 | mmc_set_ios(host); |
| 385 | } |
| 386 | |
| 387 | /* |
| 388 | * Change data bus width of a host. |
| 389 | */ |
| 390 | void mmc_set_bus_width(struct mmc_host *host, unsigned int width) |
| 391 | { |
| 392 | host->ios.bus_width = width; |
| 393 | mmc_set_ios(host); |
| 394 | } |
| 395 | |
| 396 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | * Mask off any voltages we don't support and select |
| 398 | * the lowest voltage |
| 399 | */ |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 400 | u32 mmc_select_voltage(struct mmc_host *host, u32 ocr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
| 402 | int bit; |
| 403 | |
| 404 | ocr &= host->ocr_avail; |
| 405 | |
| 406 | bit = ffs(ocr); |
| 407 | if (bit) { |
| 408 | bit -= 1; |
| 409 | |
Timo Teras | 63ef731 | 2006-11-02 19:43:27 +0100 | [diff] [blame] | 410 | ocr &= 3 << bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
| 412 | host->ios.vdd = bit; |
Russell King | 920e70c | 2006-05-04 18:22:51 +0100 | [diff] [blame] | 413 | mmc_set_ios(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } else { |
| 415 | ocr = 0; |
| 416 | } |
| 417 | |
| 418 | return ocr; |
| 419 | } |
| 420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | /* |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 422 | * Select timing parameters for host. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | */ |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 424 | void mmc_set_timing(struct mmc_host *host, unsigned int timing) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | { |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 426 | host->ios.timing = timing; |
| 427 | mmc_set_ios(host); |
Pierre Ossman | b57c43a | 2005-09-06 15:18:53 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | /* |
Russell King | 45f8245 | 2005-12-14 14:57:35 +0000 | [diff] [blame] | 431 | * Apply power to the MMC stack. This is a two-stage process. |
| 432 | * First, we enable power to the card without the clock running. |
| 433 | * We then wait a bit for the power to stabilise. Finally, |
| 434 | * enable the bus drivers and clock to the card. |
| 435 | * |
| 436 | * We must _NOT_ enable the clock prior to power stablising. |
| 437 | * |
| 438 | * If a host does all the power sequencing itself, ignore the |
| 439 | * initial MMC_POWER_UP stage. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | */ |
| 441 | static void mmc_power_up(struct mmc_host *host) |
| 442 | { |
| 443 | int bit = fls(host->ocr_avail) - 1; |
| 444 | |
| 445 | host->ios.vdd = bit; |
| 446 | host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; |
Pierre Ossman | 865e9f1 | 2005-09-03 16:45:02 +0100 | [diff] [blame] | 447 | host->ios.chip_select = MMC_CS_DONTCARE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | host->ios.power_mode = MMC_POWER_UP; |
Pierre Ossman | f218278 | 2005-09-06 15:18:55 -0700 | [diff] [blame] | 449 | host->ios.bus_width = MMC_BUS_WIDTH_1; |
Pierre Ossman | cd9277c | 2007-02-18 12:07:47 +0100 | [diff] [blame] | 450 | host->ios.timing = MMC_TIMING_LEGACY; |
Russell King | 920e70c | 2006-05-04 18:22:51 +0100 | [diff] [blame] | 451 | mmc_set_ios(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | mmc_delay(1); |
| 454 | |
| 455 | host->ios.clock = host->f_min; |
| 456 | host->ios.power_mode = MMC_POWER_ON; |
Russell King | 920e70c | 2006-05-04 18:22:51 +0100 | [diff] [blame] | 457 | mmc_set_ios(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
| 459 | mmc_delay(2); |
| 460 | } |
| 461 | |
| 462 | static void mmc_power_off(struct mmc_host *host) |
| 463 | { |
| 464 | host->ios.clock = 0; |
| 465 | host->ios.vdd = 0; |
| 466 | host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; |
Pierre Ossman | 865e9f1 | 2005-09-03 16:45:02 +0100 | [diff] [blame] | 467 | host->ios.chip_select = MMC_CS_DONTCARE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | host->ios.power_mode = MMC_POWER_OFF; |
Pierre Ossman | f218278 | 2005-09-06 15:18:55 -0700 | [diff] [blame] | 469 | host->ios.bus_width = MMC_BUS_WIDTH_1; |
Pierre Ossman | cd9277c | 2007-02-18 12:07:47 +0100 | [diff] [blame] | 470 | host->ios.timing = MMC_TIMING_LEGACY; |
Russell King | 920e70c | 2006-05-04 18:22:51 +0100 | [diff] [blame] | 471 | mmc_set_ios(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | /* |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 475 | * Assign a mmc bus handler to a host. Only one bus handler may control a |
| 476 | * host at any given time. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | */ |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 478 | void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 480 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 482 | BUG_ON(!host); |
| 483 | BUG_ON(!ops); |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 484 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 485 | BUG_ON(!host->claimed); |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 486 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 487 | spin_lock_irqsave(&host->lock, flags); |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 488 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 489 | BUG_ON(host->bus_ops); |
| 490 | BUG_ON(host->bus_refs); |
Pierre Ossman | b855885 | 2007-01-03 19:47:29 +0100 | [diff] [blame] | 491 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 492 | host->bus_ops = ops; |
| 493 | host->bus_refs = 1; |
| 494 | host->bus_dead = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 496 | spin_unlock_irqrestore(&host->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | /* |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 500 | * Remove the current bus handler from a host. Assumes that there are |
| 501 | * no interesting cards left, so the bus is powered down. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | */ |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 503 | void mmc_detach_bus(struct mmc_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 505 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 507 | BUG_ON(!host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 509 | BUG_ON(!host->claimed); |
| 510 | BUG_ON(!host->bus_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 512 | spin_lock_irqsave(&host->lock, flags); |
| 513 | |
| 514 | host->bus_dead = 1; |
| 515 | |
| 516 | spin_unlock_irqrestore(&host->lock, flags); |
| 517 | |
| 518 | mmc_power_off(host); |
| 519 | |
| 520 | mmc_bus_put(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 523 | /* |
| 524 | * Cleanup when the last reference to the bus operator is dropped. |
| 525 | */ |
| 526 | void __mmc_release_bus(struct mmc_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | { |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 528 | BUG_ON(!host); |
| 529 | BUG_ON(host->bus_refs); |
| 530 | BUG_ON(!host->bus_dead); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 532 | host->bus_ops = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
| 534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | /** |
| 536 | * mmc_detect_change - process change of state on a MMC socket |
| 537 | * @host: host which changed state. |
Richard Purdie | 8dc0033 | 2005-09-08 17:53:01 +0100 | [diff] [blame] | 538 | * @delay: optional delay to wait before detection (jiffies) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | * |
Pierre Ossman | 67a61c4 | 2007-07-11 20:22:11 +0200 | [diff] [blame] | 540 | * MMC drivers should call this when they detect a card has been |
| 541 | * inserted or removed. The MMC layer will confirm that any |
| 542 | * present card is still functional, and initialize any newly |
| 543 | * inserted. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | */ |
Richard Purdie | 8dc0033 | 2005-09-08 17:53:01 +0100 | [diff] [blame] | 545 | void mmc_detect_change(struct mmc_host *host, unsigned long delay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | { |
Pierre Ossman | 3b91e55 | 2007-02-11 20:43:19 +0100 | [diff] [blame] | 547 | #ifdef CONFIG_MMC_DEBUG |
Pierre Ossman | 1efd48b | 2007-05-08 22:35:17 +0200 | [diff] [blame] | 548 | unsigned long flags; |
Andrew Morton | 01f41ec | 2007-05-09 02:32:34 -0700 | [diff] [blame] | 549 | spin_lock_irqsave(&host->lock, flags); |
Pierre Ossman | 3b91e55 | 2007-02-11 20:43:19 +0100 | [diff] [blame] | 550 | BUG_ON(host->removed); |
Andrew Morton | 01f41ec | 2007-05-09 02:32:34 -0700 | [diff] [blame] | 551 | spin_unlock_irqrestore(&host->lock, flags); |
Pierre Ossman | 3b91e55 | 2007-02-11 20:43:19 +0100 | [diff] [blame] | 552 | #endif |
| 553 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 554 | mmc_schedule_delayed_work(&host->detect, delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | EXPORT_SYMBOL(mmc_detect_change); |
| 558 | |
| 559 | |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 560 | void mmc_rescan(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 562 | struct mmc_host *host = |
| 563 | container_of(work, struct mmc_host, detect.work); |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 564 | u32 ocr; |
| 565 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 567 | mmc_bus_get(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 569 | if (host->bus_ops == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | /* |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 571 | * Only we can add a new handler, so it's safe to |
| 572 | * release the lock here. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | */ |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 574 | mmc_bus_put(host); |
| 575 | |
| 576 | mmc_claim_host(host); |
| 577 | |
| 578 | mmc_power_up(host); |
| 579 | mmc_go_idle(host); |
| 580 | |
| 581 | mmc_send_if_cond(host, host->ocr_avail); |
| 582 | |
| 583 | err = mmc_send_app_op_cond(host, 0, &ocr); |
| 584 | if (err == MMC_ERR_NONE) { |
| 585 | if (mmc_attach_sd(host, ocr)) |
| 586 | mmc_power_off(host); |
| 587 | } else { |
| 588 | /* |
| 589 | * If we fail to detect any SD cards then try |
| 590 | * searching for MMC cards. |
| 591 | */ |
| 592 | err = mmc_send_op_cond(host, 0, &ocr); |
| 593 | if (err == MMC_ERR_NONE) { |
| 594 | if (mmc_attach_mmc(host, ocr)) |
| 595 | mmc_power_off(host); |
| 596 | } else { |
| 597 | mmc_power_off(host); |
| 598 | mmc_release_host(host); |
| 599 | } |
| 600 | } |
| 601 | } else { |
| 602 | if (host->bus_ops->detect && !host->bus_dead) |
| 603 | host->bus_ops->detect(host); |
| 604 | |
| 605 | mmc_bus_put(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 609 | void mmc_start_host(struct mmc_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 611 | mmc_power_off(host); |
| 612 | mmc_detect_change(host, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 615 | void mmc_stop_host(struct mmc_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | { |
Pierre Ossman | 3b91e55 | 2007-02-11 20:43:19 +0100 | [diff] [blame] | 617 | #ifdef CONFIG_MMC_DEBUG |
Pierre Ossman | 1efd48b | 2007-05-08 22:35:17 +0200 | [diff] [blame] | 618 | unsigned long flags; |
| 619 | spin_lock_irqsave(&host->lock, flags); |
Pierre Ossman | 3b91e55 | 2007-02-11 20:43:19 +0100 | [diff] [blame] | 620 | host->removed = 1; |
Pierre Ossman | 1efd48b | 2007-05-08 22:35:17 +0200 | [diff] [blame] | 621 | spin_unlock_irqrestore(&host->lock, flags); |
Pierre Ossman | 3b91e55 | 2007-02-11 20:43:19 +0100 | [diff] [blame] | 622 | #endif |
| 623 | |
| 624 | mmc_flush_scheduled_work(); |
| 625 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 626 | mmc_bus_get(host); |
| 627 | if (host->bus_ops && !host->bus_dead) { |
| 628 | if (host->bus_ops->remove) |
| 629 | host->bus_ops->remove(host); |
| 630 | |
| 631 | mmc_claim_host(host); |
| 632 | mmc_detach_bus(host); |
| 633 | mmc_release_host(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | } |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 635 | mmc_bus_put(host); |
| 636 | |
| 637 | BUG_ON(host->card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | |
| 639 | mmc_power_off(host); |
| 640 | } |
| 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | #ifdef CONFIG_PM |
| 643 | |
| 644 | /** |
| 645 | * mmc_suspend_host - suspend a host |
| 646 | * @host: mmc host |
| 647 | * @state: suspend mode (PM_SUSPEND_xxx) |
| 648 | */ |
Pavel Machek | e5378ca | 2005-04-16 15:25:29 -0700 | [diff] [blame] | 649 | int mmc_suspend_host(struct mmc_host *host, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | { |
Pierre Ossman | b5af25b | 2007-04-28 17:30:50 +0200 | [diff] [blame] | 651 | mmc_flush_scheduled_work(); |
| 652 | |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 653 | mmc_bus_get(host); |
| 654 | if (host->bus_ops && !host->bus_dead) { |
Pierre Ossman | 6abaa0c | 2007-05-01 16:00:02 +0200 | [diff] [blame] | 655 | if (host->bus_ops->suspend) |
| 656 | host->bus_ops->suspend(host); |
| 657 | if (!host->bus_ops->resume) { |
| 658 | if (host->bus_ops->remove) |
| 659 | host->bus_ops->remove(host); |
| 660 | |
| 661 | mmc_claim_host(host); |
| 662 | mmc_detach_bus(host); |
| 663 | mmc_release_host(host); |
| 664 | } |
Pierre Ossman | b5af25b | 2007-04-28 17:30:50 +0200 | [diff] [blame] | 665 | } |
Pierre Ossman | 7ea239d | 2006-12-31 00:11:32 +0100 | [diff] [blame] | 666 | mmc_bus_put(host); |
| 667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | mmc_power_off(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | EXPORT_SYMBOL(mmc_suspend_host); |
| 674 | |
| 675 | /** |
| 676 | * mmc_resume_host - resume a previously suspended host |
| 677 | * @host: mmc host |
| 678 | */ |
| 679 | int mmc_resume_host(struct mmc_host *host) |
| 680 | { |
Pierre Ossman | 6abaa0c | 2007-05-01 16:00:02 +0200 | [diff] [blame] | 681 | mmc_bus_get(host); |
| 682 | if (host->bus_ops && !host->bus_dead) { |
| 683 | mmc_power_up(host); |
| 684 | BUG_ON(!host->bus_ops->resume); |
| 685 | host->bus_ops->resume(host); |
| 686 | } |
| 687 | mmc_bus_put(host); |
| 688 | |
| 689 | /* |
| 690 | * We add a slight delay here so that resume can progress |
| 691 | * in parallel. |
| 692 | */ |
| 693 | mmc_detect_change(host, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | EXPORT_SYMBOL(mmc_resume_host); |
| 699 | |
| 700 | #endif |
| 701 | |
Pierre Ossman | ffce2e7 | 2007-05-19 14:32:22 +0200 | [diff] [blame] | 702 | static int __init mmc_init(void) |
| 703 | { |
| 704 | int ret; |
| 705 | |
| 706 | workqueue = create_singlethread_workqueue("kmmcd"); |
| 707 | if (!workqueue) |
| 708 | return -ENOMEM; |
| 709 | |
| 710 | ret = mmc_register_bus(); |
| 711 | if (ret == 0) { |
| 712 | ret = mmc_register_host_class(); |
| 713 | if (ret) |
| 714 | mmc_unregister_bus(); |
| 715 | } |
| 716 | return ret; |
| 717 | } |
| 718 | |
| 719 | static void __exit mmc_exit(void) |
| 720 | { |
| 721 | mmc_unregister_host_class(); |
| 722 | mmc_unregister_bus(); |
| 723 | destroy_workqueue(workqueue); |
| 724 | } |
| 725 | |
| 726 | module_init(mmc_init); |
| 727 | module_exit(mmc_exit); |
| 728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | MODULE_LICENSE("GPL"); |