blob: f4f7883271f0a4d0e171b6eac91a92bb62302017 [file] [log] [blame]
San Mehat9d2bd732009-09-22 16:44:22 -07001/*
2 * linux/drivers/mmc/host/msm_sdcc.c - Qualcomm MSM 7X00A SDCC Driver
3 *
4 * Copyright (C) 2007 Google Inc,
5 * Copyright (C) 2003 Deep Blue Solutions, Ltd, All Rights Reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * Based on mmci.c
12 *
13 * Author: San Mehat (san@android.com)
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/moduleparam.h>
19#include <linux/init.h>
20#include <linux/ioport.h>
21#include <linux/device.h>
22#include <linux/interrupt.h>
23#include <linux/delay.h>
24#include <linux/err.h>
25#include <linux/highmem.h>
26#include <linux/log2.h>
27#include <linux/mmc/host.h>
28#include <linux/mmc/card.h>
San Mehatb3fa5792009-11-02 18:46:09 -080029#include <linux/mmc/sdio.h>
San Mehat9d2bd732009-09-22 16:44:22 -070030#include <linux/clk.h>
31#include <linux/scatterlist.h>
32#include <linux/platform_device.h>
33#include <linux/dma-mapping.h>
34#include <linux/debugfs.h>
35#include <linux/io.h>
36#include <linux/memory.h>
37
38#include <asm/cacheflush.h>
39#include <asm/div64.h>
40#include <asm/sizes.h>
41
Pavel Machek3989d172009-12-08 11:11:36 -080042#include <mach/mmc.h>
San Mehat9d2bd732009-09-22 16:44:22 -070043#include <mach/msm_iomap.h>
44#include <mach/dma.h>
San Mehat9d2bd732009-09-22 16:44:22 -070045
San Mehat9d2bd732009-09-22 16:44:22 -070046#include "msm_sdcc.h"
47
48#define DRIVER_NAME "msm-sdcc"
49
50static unsigned int msmsdcc_fmin = 144000;
51static unsigned int msmsdcc_fmax = 50000000;
52static unsigned int msmsdcc_4bit = 1;
53static unsigned int msmsdcc_pwrsave = 1;
54static unsigned int msmsdcc_piopoll = 1;
55static unsigned int msmsdcc_sdioirq;
56
57#define PIO_SPINMAX 30
58#define CMD_SPINMAX 20
59
San Mehat9d2bd732009-09-22 16:44:22 -070060static void
61msmsdcc_start_command(struct msmsdcc_host *host, struct mmc_command *cmd,
62 u32 c);
63
64static void
65msmsdcc_request_end(struct msmsdcc_host *host, struct mmc_request *mrq)
66{
67 writel(0, host->base + MMCICOMMAND);
68
69 BUG_ON(host->curr.data);
70
71 host->curr.mrq = NULL;
72 host->curr.cmd = NULL;
73
74 if (mrq->data)
75 mrq->data->bytes_xfered = host->curr.data_xfered;
76 if (mrq->cmd->error == -ETIMEDOUT)
77 mdelay(5);
78
79 /*
80 * Need to drop the host lock here; mmc_request_done may call
81 * back into the driver...
82 */
83 spin_unlock(&host->lock);
84 mmc_request_done(host->mmc, mrq);
85 spin_lock(&host->lock);
86}
87
88static void
89msmsdcc_stop_data(struct msmsdcc_host *host)
90{
91 writel(0, host->base + MMCIDATACTRL);
92 host->curr.data = NULL;
93 host->curr.got_dataend = host->curr.got_datablkend = 0;
94}
95
96uint32_t msmsdcc_fifo_addr(struct msmsdcc_host *host)
97{
Joe Perches75d14522009-09-22 16:44:24 -070098 switch (host->pdev_id) {
99 case 1:
San Mehat9d2bd732009-09-22 16:44:22 -0700100 return MSM_SDC1_PHYS + MMCIFIFO;
Joe Perches75d14522009-09-22 16:44:24 -0700101 case 2:
San Mehat9d2bd732009-09-22 16:44:22 -0700102 return MSM_SDC2_PHYS + MMCIFIFO;
Joe Perches75d14522009-09-22 16:44:24 -0700103 case 3:
San Mehat9d2bd732009-09-22 16:44:22 -0700104 return MSM_SDC3_PHYS + MMCIFIFO;
Joe Perches75d14522009-09-22 16:44:24 -0700105 case 4:
San Mehat9d2bd732009-09-22 16:44:22 -0700106 return MSM_SDC4_PHYS + MMCIFIFO;
Joe Perches75d14522009-09-22 16:44:24 -0700107 }
108 BUG();
San Mehat9d2bd732009-09-22 16:44:22 -0700109 return 0;
110}
111
112static void
113msmsdcc_dma_complete_func(struct msm_dmov_cmd *cmd,
114 unsigned int result,
115 struct msm_dmov_errdata *err)
116{
117 struct msmsdcc_dma_data *dma_data =
118 container_of(cmd, struct msmsdcc_dma_data, hdr);
119 struct msmsdcc_host *host = dma_data->host;
120 unsigned long flags;
121 struct mmc_request *mrq;
122
123 spin_lock_irqsave(&host->lock, flags);
124 mrq = host->curr.mrq;
125 BUG_ON(!mrq);
126
127 if (!(result & DMOV_RSLT_VALID)) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700128 pr_err("msmsdcc: Invalid DataMover result\n");
San Mehat9d2bd732009-09-22 16:44:22 -0700129 goto out;
130 }
131
132 if (result & DMOV_RSLT_DONE) {
133 host->curr.data_xfered = host->curr.xfer_size;
134 } else {
135 /* Error or flush */
136 if (result & DMOV_RSLT_ERROR)
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700137 pr_err("%s: DMA error (0x%.8x)\n",
San Mehat9d2bd732009-09-22 16:44:22 -0700138 mmc_hostname(host->mmc), result);
139 if (result & DMOV_RSLT_FLUSH)
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700140 pr_err("%s: DMA channel flushed (0x%.8x)\n",
San Mehat9d2bd732009-09-22 16:44:22 -0700141 mmc_hostname(host->mmc), result);
142 if (err)
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700143 pr_err("Flush data: %.8x %.8x %.8x %.8x %.8x %.8x\n",
San Mehat9d2bd732009-09-22 16:44:22 -0700144 err->flush[0], err->flush[1], err->flush[2],
145 err->flush[3], err->flush[4], err->flush[5]);
146 if (!mrq->data->error)
147 mrq->data->error = -EIO;
148 }
149 host->dma.busy = 0;
150 dma_unmap_sg(mmc_dev(host->mmc), host->dma.sg, host->dma.num_ents,
151 host->dma.dir);
152
153 if (host->curr.user_pages) {
154 struct scatterlist *sg = host->dma.sg;
155 int i;
156
Joe Perches75d14522009-09-22 16:44:24 -0700157 for (i = 0; i < host->dma.num_ents; i++)
158 flush_dcache_page(sg_page(sg++));
San Mehat9d2bd732009-09-22 16:44:22 -0700159 }
160
161 host->dma.sg = NULL;
162
163 if ((host->curr.got_dataend && host->curr.got_datablkend)
164 || mrq->data->error) {
165
166 /*
167 * If we've already gotten our DATAEND / DATABLKEND
168 * for this request, then complete it through here.
169 */
170 msmsdcc_stop_data(host);
171
172 if (!mrq->data->error)
173 host->curr.data_xfered = host->curr.xfer_size;
174 if (!mrq->data->stop || mrq->cmd->error) {
175 writel(0, host->base + MMCICOMMAND);
176 host->curr.mrq = NULL;
177 host->curr.cmd = NULL;
178 mrq->data->bytes_xfered = host->curr.data_xfered;
179
180 spin_unlock_irqrestore(&host->lock, flags);
181 mmc_request_done(host->mmc, mrq);
182 return;
183 } else
184 msmsdcc_start_command(host, mrq->data->stop, 0);
185 }
186
187out:
188 spin_unlock_irqrestore(&host->lock, flags);
189 return;
190}
191
192static int validate_dma(struct msmsdcc_host *host, struct mmc_data *data)
193{
194 if (host->dma.channel == -1)
195 return -ENOENT;
196
197 if ((data->blksz * data->blocks) < MCI_FIFOSIZE)
198 return -EINVAL;
199 if ((data->blksz * data->blocks) % MCI_FIFOSIZE)
200 return -EINVAL;
201 return 0;
202}
203
204static int msmsdcc_config_dma(struct msmsdcc_host *host, struct mmc_data *data)
205{
206 struct msmsdcc_nc_dmadata *nc;
207 dmov_box *box;
208 uint32_t rows;
209 uint32_t crci;
210 unsigned int n;
211 int i, rc;
212 struct scatterlist *sg = data->sg;
213
214 rc = validate_dma(host, data);
215 if (rc)
216 return rc;
217
218 host->dma.sg = data->sg;
219 host->dma.num_ents = data->sg_len;
220
221 nc = host->dma.nc;
222
Joe Perches75d14522009-09-22 16:44:24 -0700223 switch (host->pdev_id) {
224 case 1:
San Mehat9d2bd732009-09-22 16:44:22 -0700225 crci = MSMSDCC_CRCI_SDC1;
Joe Perches75d14522009-09-22 16:44:24 -0700226 break;
227 case 2:
San Mehat9d2bd732009-09-22 16:44:22 -0700228 crci = MSMSDCC_CRCI_SDC2;
Joe Perches75d14522009-09-22 16:44:24 -0700229 break;
230 case 3:
San Mehat9d2bd732009-09-22 16:44:22 -0700231 crci = MSMSDCC_CRCI_SDC3;
Joe Perches75d14522009-09-22 16:44:24 -0700232 break;
233 case 4:
San Mehat9d2bd732009-09-22 16:44:22 -0700234 crci = MSMSDCC_CRCI_SDC4;
Joe Perches75d14522009-09-22 16:44:24 -0700235 break;
236 default:
San Mehat9d2bd732009-09-22 16:44:22 -0700237 host->dma.sg = NULL;
238 host->dma.num_ents = 0;
239 return -ENOENT;
240 }
241
242 if (data->flags & MMC_DATA_READ)
243 host->dma.dir = DMA_FROM_DEVICE;
244 else
245 host->dma.dir = DMA_TO_DEVICE;
246
247 host->curr.user_pages = 0;
248
249 n = dma_map_sg(mmc_dev(host->mmc), host->dma.sg,
Joe Perches75d14522009-09-22 16:44:24 -0700250 host->dma.num_ents, host->dma.dir);
San Mehat9d2bd732009-09-22 16:44:22 -0700251
252 if (n != host->dma.num_ents) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700253 pr_err("%s: Unable to map in all sg elements\n",
San Mehat9d2bd732009-09-22 16:44:22 -0700254 mmc_hostname(host->mmc));
255 host->dma.sg = NULL;
256 host->dma.num_ents = 0;
257 return -ENOMEM;
258 }
259
260 box = &nc->cmd[0];
261 for (i = 0; i < host->dma.num_ents; i++) {
262 box->cmd = CMD_MODE_BOX;
263
264 if (i == (host->dma.num_ents - 1))
265 box->cmd |= CMD_LC;
266 rows = (sg_dma_len(sg) % MCI_FIFOSIZE) ?
267 (sg_dma_len(sg) / MCI_FIFOSIZE) + 1 :
268 (sg_dma_len(sg) / MCI_FIFOSIZE) ;
269
270 if (data->flags & MMC_DATA_READ) {
271 box->src_row_addr = msmsdcc_fifo_addr(host);
272 box->dst_row_addr = sg_dma_address(sg);
273
274 box->src_dst_len = (MCI_FIFOSIZE << 16) |
275 (MCI_FIFOSIZE);
276 box->row_offset = MCI_FIFOSIZE;
277
278 box->num_rows = rows * ((1 << 16) + 1);
279 box->cmd |= CMD_SRC_CRCI(crci);
280 } else {
281 box->src_row_addr = sg_dma_address(sg);
282 box->dst_row_addr = msmsdcc_fifo_addr(host);
283
284 box->src_dst_len = (MCI_FIFOSIZE << 16) |
285 (MCI_FIFOSIZE);
286 box->row_offset = (MCI_FIFOSIZE << 16);
287
288 box->num_rows = rows * ((1 << 16) + 1);
289 box->cmd |= CMD_DST_CRCI(crci);
290 }
291 box++;
292 sg++;
293 }
294
295 /* location of command block must be 64 bit aligned */
296 BUG_ON(host->dma.cmd_busaddr & 0x07);
297
298 nc->cmdptr = (host->dma.cmd_busaddr >> 3) | CMD_PTR_LP;
299 host->dma.hdr.cmdptr = DMOV_CMD_PTR_LIST |
300 DMOV_CMD_ADDR(host->dma.cmdptr_busaddr);
301 host->dma.hdr.complete_func = msmsdcc_dma_complete_func;
302
303 return 0;
304}
305
306static void
307msmsdcc_start_data(struct msmsdcc_host *host, struct mmc_data *data)
308{
309 unsigned int datactrl, timeout;
310 unsigned long long clks;
311 void __iomem *base = host->base;
312 unsigned int pio_irqmask = 0;
313
314 host->curr.data = data;
315 host->curr.xfer_size = data->blksz * data->blocks;
316 host->curr.xfer_remain = host->curr.xfer_size;
317 host->curr.data_xfered = 0;
318 host->curr.got_dataend = 0;
319 host->curr.got_datablkend = 0;
320
321 memset(&host->pio, 0, sizeof(host->pio));
322
323 clks = (unsigned long long)data->timeout_ns * host->clk_rate;
Joe Perches75d14522009-09-22 16:44:24 -0700324 do_div(clks, NSEC_PER_SEC);
San Mehat9d2bd732009-09-22 16:44:22 -0700325 timeout = data->timeout_clks + (unsigned int)clks;
326 writel(timeout, base + MMCIDATATIMER);
327
328 writel(host->curr.xfer_size, base + MMCIDATALENGTH);
329
330 datactrl = MCI_DPSM_ENABLE | (data->blksz << 4);
331
332 if (!msmsdcc_config_dma(host, data))
333 datactrl |= MCI_DPSM_DMAENABLE;
334 else {
335 host->pio.sg = data->sg;
336 host->pio.sg_len = data->sg_len;
337 host->pio.sg_off = 0;
338
339 if (data->flags & MMC_DATA_READ) {
340 pio_irqmask = MCI_RXFIFOHALFFULLMASK;
341 if (host->curr.xfer_remain < MCI_FIFOSIZE)
342 pio_irqmask |= MCI_RXDATAAVLBLMASK;
343 } else
344 pio_irqmask = MCI_TXFIFOHALFEMPTYMASK;
345 }
346
347 if (data->flags & MMC_DATA_READ)
348 datactrl |= MCI_DPSM_DIRECTION;
349
350 writel(pio_irqmask, base + MMCIMASK1);
351 writel(datactrl, base + MMCIDATACTRL);
352
353 if (datactrl & MCI_DPSM_DMAENABLE) {
354 host->dma.busy = 1;
355 msm_dmov_enqueue_cmd(host->dma.channel, &host->dma.hdr);
356 }
357}
358
San Mehatb3fa5792009-11-02 18:46:09 -0800359static int
360snoop_cccr_abort(struct mmc_command *cmd)
361{
362 if ((cmd->opcode == 52) &&
363 (cmd->arg & 0x80000000) &&
364 (((cmd->arg >> 9) & 0x1ffff) == SDIO_CCCR_ABORT))
365 return 1;
366 return 0;
367}
368
San Mehat9d2bd732009-09-22 16:44:22 -0700369static void
370msmsdcc_start_command(struct msmsdcc_host *host, struct mmc_command *cmd, u32 c)
371{
372 void __iomem *base = host->base;
373
374 if (readl(base + MMCICOMMAND) & MCI_CPSM_ENABLE) {
375 writel(0, base + MMCICOMMAND);
376 udelay(2 + ((5 * 1000000) / host->clk_rate));
377 }
378
379 c |= cmd->opcode | MCI_CPSM_ENABLE;
380
381 if (cmd->flags & MMC_RSP_PRESENT) {
382 if (cmd->flags & MMC_RSP_136)
383 c |= MCI_CPSM_LONGRSP;
384 c |= MCI_CPSM_RESPONSE;
385 }
386
Joe Perches75d14522009-09-22 16:44:24 -0700387 if (cmd->opcode == 17 || cmd->opcode == 18 ||
388 cmd->opcode == 24 || cmd->opcode == 25 ||
389 cmd->opcode == 53)
San Mehat9d2bd732009-09-22 16:44:22 -0700390 c |= MCI_CSPM_DATCMD;
391
392 if (cmd == cmd->mrq->stop)
393 c |= MCI_CSPM_MCIABORT;
394
San Mehatb3fa5792009-11-02 18:46:09 -0800395 if (snoop_cccr_abort(cmd))
396 c |= MCI_CSPM_MCIABORT;
397
San Mehat9d2bd732009-09-22 16:44:22 -0700398 host->curr.cmd = cmd;
399
400 host->stats.cmds++;
401
402 writel(cmd->arg, base + MMCIARGUMENT);
403 writel(c, base + MMCICOMMAND);
404}
405
406static void
407msmsdcc_data_err(struct msmsdcc_host *host, struct mmc_data *data,
408 unsigned int status)
409{
410 if (status & MCI_DATACRCFAIL) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700411 pr_err("%s: Data CRC error\n", mmc_hostname(host->mmc));
412 pr_err("%s: opcode 0x%.8x\n", __func__,
San Mehat9d2bd732009-09-22 16:44:22 -0700413 data->mrq->cmd->opcode);
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700414 pr_err("%s: blksz %d, blocks %d\n", __func__,
San Mehat9d2bd732009-09-22 16:44:22 -0700415 data->blksz, data->blocks);
416 data->error = -EILSEQ;
417 } else if (status & MCI_DATATIMEOUT) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700418 pr_err("%s: Data timeout\n", mmc_hostname(host->mmc));
San Mehat9d2bd732009-09-22 16:44:22 -0700419 data->error = -ETIMEDOUT;
420 } else if (status & MCI_RXOVERRUN) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700421 pr_err("%s: RX overrun\n", mmc_hostname(host->mmc));
San Mehat9d2bd732009-09-22 16:44:22 -0700422 data->error = -EIO;
423 } else if (status & MCI_TXUNDERRUN) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700424 pr_err("%s: TX underrun\n", mmc_hostname(host->mmc));
San Mehat9d2bd732009-09-22 16:44:22 -0700425 data->error = -EIO;
426 } else {
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700427 pr_err("%s: Unknown error (0x%.8x)\n",
428 mmc_hostname(host->mmc), status);
San Mehat9d2bd732009-09-22 16:44:22 -0700429 data->error = -EIO;
430 }
431}
432
433
434static int
435msmsdcc_pio_read(struct msmsdcc_host *host, char *buffer, unsigned int remain)
436{
437 void __iomem *base = host->base;
438 uint32_t *ptr = (uint32_t *) buffer;
439 int count = 0;
440
441 while (readl(base + MMCISTATUS) & MCI_RXDATAAVLBL) {
442
443 *ptr = readl(base + MMCIFIFO + (count % MCI_FIFOSIZE));
444 ptr++;
445 count += sizeof(uint32_t);
446
447 remain -= sizeof(uint32_t);
448 if (remain == 0)
449 break;
450 }
451 return count;
452}
453
454static int
455msmsdcc_pio_write(struct msmsdcc_host *host, char *buffer,
456 unsigned int remain, u32 status)
457{
458 void __iomem *base = host->base;
459 char *ptr = buffer;
460
461 do {
462 unsigned int count, maxcnt;
463
464 maxcnt = status & MCI_TXFIFOEMPTY ? MCI_FIFOSIZE :
465 MCI_FIFOHALFSIZE;
466 count = min(remain, maxcnt);
467
468 writesl(base + MMCIFIFO, ptr, count >> 2);
469 ptr += count;
470 remain -= count;
471
472 if (remain == 0)
473 break;
474
475 status = readl(base + MMCISTATUS);
476 } while (status & MCI_TXFIFOHALFEMPTY);
477
478 return ptr - buffer;
479}
480
481static int
482msmsdcc_spin_on_status(struct msmsdcc_host *host, uint32_t mask, int maxspin)
483{
484 while (maxspin) {
485 if ((readl(host->base + MMCISTATUS) & mask))
486 return 0;
487 udelay(1);
488 --maxspin;
489 }
490 return -ETIMEDOUT;
491}
492
493static int
494msmsdcc_pio_irq(int irq, void *dev_id)
495{
496 struct msmsdcc_host *host = dev_id;
497 void __iomem *base = host->base;
498 uint32_t status;
499
500 status = readl(base + MMCISTATUS);
501
502 do {
503 unsigned long flags;
504 unsigned int remain, len;
505 char *buffer;
506
507 if (!(status & (MCI_TXFIFOHALFEMPTY | MCI_RXDATAAVLBL))) {
508 if (host->curr.xfer_remain == 0 || !msmsdcc_piopoll)
509 break;
510
511 if (msmsdcc_spin_on_status(host,
512 (MCI_TXFIFOHALFEMPTY |
513 MCI_RXDATAAVLBL),
514 PIO_SPINMAX)) {
515 break;
516 }
517 }
518
519 /* Map the current scatter buffer */
520 local_irq_save(flags);
521 buffer = kmap_atomic(sg_page(host->pio.sg),
522 KM_BIO_SRC_IRQ) + host->pio.sg->offset;
523 buffer += host->pio.sg_off;
524 remain = host->pio.sg->length - host->pio.sg_off;
525 len = 0;
526 if (status & MCI_RXACTIVE)
527 len = msmsdcc_pio_read(host, buffer, remain);
528 if (status & MCI_TXACTIVE)
529 len = msmsdcc_pio_write(host, buffer, remain, status);
530
531 /* Unmap the buffer */
532 kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
533 local_irq_restore(flags);
534
535 host->pio.sg_off += len;
536 host->curr.xfer_remain -= len;
537 host->curr.data_xfered += len;
538 remain -= len;
539
540 if (remain == 0) {
541 /* This sg page is full - do some housekeeping */
542 if (status & MCI_RXACTIVE && host->curr.user_pages)
543 flush_dcache_page(sg_page(host->pio.sg));
544
545 if (!--host->pio.sg_len) {
546 memset(&host->pio, 0, sizeof(host->pio));
547 break;
548 }
549
550 /* Advance to next sg */
551 host->pio.sg++;
552 host->pio.sg_off = 0;
553 }
554
555 status = readl(base + MMCISTATUS);
556 } while (1);
557
558 if (status & MCI_RXACTIVE && host->curr.xfer_remain < MCI_FIFOSIZE)
559 writel(MCI_RXDATAAVLBLMASK, base + MMCIMASK1);
560
561 if (!host->curr.xfer_remain)
562 writel(0, base + MMCIMASK1);
563
564 return IRQ_HANDLED;
565}
566
567static void msmsdcc_do_cmdirq(struct msmsdcc_host *host, uint32_t status)
568{
569 struct mmc_command *cmd = host->curr.cmd;
570 void __iomem *base = host->base;
571
572 host->curr.cmd = NULL;
573 cmd->resp[0] = readl(base + MMCIRESPONSE0);
574 cmd->resp[1] = readl(base + MMCIRESPONSE1);
575 cmd->resp[2] = readl(base + MMCIRESPONSE2);
576 cmd->resp[3] = readl(base + MMCIRESPONSE3);
577
578 del_timer(&host->command_timer);
579 if (status & MCI_CMDTIMEOUT) {
580 cmd->error = -ETIMEDOUT;
581 } else if (status & MCI_CMDCRCFAIL &&
582 cmd->flags & MMC_RSP_CRC) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700583 pr_err("%s: Command CRC error\n", mmc_hostname(host->mmc));
San Mehat9d2bd732009-09-22 16:44:22 -0700584 cmd->error = -EILSEQ;
585 }
586
587 if (!cmd->data || cmd->error) {
588 if (host->curr.data && host->dma.sg)
589 msm_dmov_stop_cmd(host->dma.channel,
590 &host->dma.hdr, 0);
591 else if (host->curr.data) { /* Non DMA */
592 msmsdcc_stop_data(host);
593 msmsdcc_request_end(host, cmd->mrq);
594 } else /* host->data == NULL */
595 msmsdcc_request_end(host, cmd->mrq);
596 } else if (!(cmd->data->flags & MMC_DATA_READ))
597 msmsdcc_start_data(host, cmd->data);
598}
599
Joe Perchesb5a74d62009-09-22 16:44:25 -0700600static void
601msmsdcc_handle_irq_data(struct msmsdcc_host *host, u32 status,
602 void __iomem *base)
603{
604 struct mmc_data *data = host->curr.data;
605
606 if (!data)
607 return;
608
609 /* Check for data errors */
610 if (status & (MCI_DATACRCFAIL | MCI_DATATIMEOUT |
611 MCI_TXUNDERRUN | MCI_RXOVERRUN)) {
612 msmsdcc_data_err(host, data, status);
613 host->curr.data_xfered = 0;
614 if (host->dma.sg)
615 msm_dmov_stop_cmd(host->dma.channel,
616 &host->dma.hdr, 0);
617 else {
618 msmsdcc_stop_data(host);
619 if (!data->stop)
620 msmsdcc_request_end(host, data->mrq);
621 else
622 msmsdcc_start_command(host, data->stop, 0);
623 }
624 }
625
626 /* Check for data done */
627 if (!host->curr.got_dataend && (status & MCI_DATAEND))
628 host->curr.got_dataend = 1;
629
630 if (!host->curr.got_datablkend && (status & MCI_DATABLOCKEND))
631 host->curr.got_datablkend = 1;
632
633 /*
634 * If DMA is still in progress, we complete via the completion handler
635 */
636 if (host->curr.got_dataend && host->curr.got_datablkend &&
637 !host->dma.busy) {
638 /*
639 * There appears to be an issue in the controller where
640 * if you request a small block transfer (< fifo size),
641 * you may get your DATAEND/DATABLKEND irq without the
642 * PIO data irq.
643 *
644 * Check to see if there is still data to be read,
645 * and simulate a PIO irq.
646 */
647 if (readl(base + MMCISTATUS) & MCI_RXDATAAVLBL)
648 msmsdcc_pio_irq(1, host);
649
650 msmsdcc_stop_data(host);
651 if (!data->error)
652 host->curr.data_xfered = host->curr.xfer_size;
653
654 if (!data->stop)
655 msmsdcc_request_end(host, data->mrq);
656 else
657 msmsdcc_start_command(host, data->stop, 0);
658 }
659}
660
San Mehat9d2bd732009-09-22 16:44:22 -0700661static irqreturn_t
662msmsdcc_irq(int irq, void *dev_id)
663{
664 struct msmsdcc_host *host = dev_id;
665 void __iomem *base = host->base;
666 u32 status;
667 int ret = 0;
668 int cardint = 0;
669
670 spin_lock(&host->lock);
671
672 do {
San Mehat9d2bd732009-09-22 16:44:22 -0700673 status = readl(base + MMCISTATUS);
674
Joe Perchesb5a74d62009-09-22 16:44:25 -0700675 status &= (readl(base + MMCIMASK0) | MCI_DATABLOCKENDMASK);
San Mehat9d2bd732009-09-22 16:44:22 -0700676 writel(status, base + MMCICLEAR);
677
Joe Perchesb5a74d62009-09-22 16:44:25 -0700678 msmsdcc_handle_irq_data(host, status, base);
San Mehat9d2bd732009-09-22 16:44:22 -0700679
680 if (status & (MCI_CMDSENT | MCI_CMDRESPEND | MCI_CMDCRCFAIL |
681 MCI_CMDTIMEOUT) && host->curr.cmd) {
682 msmsdcc_do_cmdirq(host, status);
683 }
684
685 if (status & MCI_SDIOINTOPER) {
686 cardint = 1;
687 status &= ~MCI_SDIOINTOPER;
688 }
689 ret = 1;
690 } while (status);
691
692 spin_unlock(&host->lock);
693
694 /*
695 * We have to delay handling the card interrupt as it calls
696 * back into the driver.
697 */
698 if (cardint)
699 mmc_signal_sdio_irq(host->mmc);
700
701 return IRQ_RETVAL(ret);
702}
703
704static void
705msmsdcc_request(struct mmc_host *mmc, struct mmc_request *mrq)
706{
707 struct msmsdcc_host *host = mmc_priv(mmc);
708 unsigned long flags;
709
710 WARN_ON(host->curr.mrq != NULL);
711 WARN_ON(host->pwr == 0);
712
713 spin_lock_irqsave(&host->lock, flags);
714
715 host->stats.reqs++;
716
717 if (host->eject) {
718 if (mrq->data && !(mrq->data->flags & MMC_DATA_READ)) {
719 mrq->cmd->error = 0;
720 mrq->data->bytes_xfered = mrq->data->blksz *
721 mrq->data->blocks;
722 } else
723 mrq->cmd->error = -ENOMEDIUM;
724
725 spin_unlock_irqrestore(&host->lock, flags);
726 mmc_request_done(mmc, mrq);
727 return;
728 }
729
730 host->curr.mrq = mrq;
731
732 if (mrq->data && mrq->data->flags & MMC_DATA_READ)
733 msmsdcc_start_data(host, mrq->data);
734
735 msmsdcc_start_command(host, mrq->cmd, 0);
736
737 if (host->cmdpoll && !msmsdcc_spin_on_status(host,
738 MCI_CMDRESPEND|MCI_CMDCRCFAIL|MCI_CMDTIMEOUT,
739 CMD_SPINMAX)) {
740 uint32_t status = readl(host->base + MMCISTATUS);
741 msmsdcc_do_cmdirq(host, status);
742 writel(MCI_CMDRESPEND | MCI_CMDCRCFAIL | MCI_CMDTIMEOUT,
743 host->base + MMCICLEAR);
744 host->stats.cmdpoll_hits++;
745 } else {
746 host->stats.cmdpoll_misses++;
747 mod_timer(&host->command_timer, jiffies + HZ);
748 }
749 spin_unlock_irqrestore(&host->lock, flags);
750}
751
San Mehat4adbbcc2009-11-08 13:00:37 -0800752static int inline
753msmsdcc_enable_clocks(struct msmsdcc_host *host, int enable)
754{
755 int rc;
756 if (enable) {
757 rc = clk_enable(host->pclk);
758 if (rc)
759 return rc;
760 rc = clk_enable(host->clk);
761 if (rc) {
762 clk_disable(host->pclk);
763 return rc;
764 }
765 host->clks_on = 1;
766 udelay(10);
767 } else {
768 clk_disable(host->clk);
769 clk_disable(host->pclk);
770 host->clks_on = 0;
771 }
772 return 0;
773}
774
San Mehat9d2bd732009-09-22 16:44:22 -0700775static void
776msmsdcc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
777{
778 struct msmsdcc_host *host = mmc_priv(mmc);
779 u32 clk = 0, pwr = 0;
780 int rc;
San Mehat4adbbcc2009-11-08 13:00:37 -0800781 unsigned long flags;
San Mehat9d2bd732009-09-22 16:44:22 -0700782
San Mehat4adbbcc2009-11-08 13:00:37 -0800783 spin_lock_irqsave(&host->lock, flags);
San Mehat9d2bd732009-09-22 16:44:22 -0700784 if (ios->clock) {
785
San Mehat4adbbcc2009-11-08 13:00:37 -0800786 if (!host->clks_on)
787 msmsdcc_enable_clocks(host, 1);
San Mehat9d2bd732009-09-22 16:44:22 -0700788 if (ios->clock != host->clk_rate) {
789 rc = clk_set_rate(host->clk, ios->clock);
790 if (rc < 0)
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700791 pr_err("%s: Error setting clock rate (%d)\n",
792 mmc_hostname(host->mmc), rc);
San Mehat9d2bd732009-09-22 16:44:22 -0700793 else
794 host->clk_rate = ios->clock;
795 }
796 clk |= MCI_CLK_ENABLE;
797 }
798
799 if (ios->bus_width == MMC_BUS_WIDTH_4)
800 clk |= (2 << 10); /* Set WIDEBUS */
801
802 if (ios->clock > 400000 && msmsdcc_pwrsave)
803 clk |= (1 << 9); /* PWRSAVE */
804
805 clk |= (1 << 12); /* FLOW_ENA */
806 clk |= (1 << 15); /* feedback clock */
807
808 if (host->plat->translate_vdd)
809 pwr |= host->plat->translate_vdd(mmc_dev(mmc), ios->vdd);
810
811 switch (ios->power_mode) {
812 case MMC_POWER_OFF:
San Mehat9d2bd732009-09-22 16:44:22 -0700813 break;
814 case MMC_POWER_UP:
815 pwr |= MCI_PWR_UP;
816 break;
817 case MMC_POWER_ON:
San Mehat9d2bd732009-09-22 16:44:22 -0700818 pwr |= MCI_PWR_ON;
819 break;
820 }
821
822 if (ios->bus_mode == MMC_BUSMODE_OPENDRAIN)
823 pwr |= MCI_OD;
824
825 writel(clk, host->base + MMCICLOCK);
826
827 if (host->pwr != pwr) {
828 host->pwr = pwr;
829 writel(pwr, host->base + MMCIPOWER);
830 }
831
San Mehat4adbbcc2009-11-08 13:00:37 -0800832 if (!(clk & MCI_CLK_ENABLE) && host->clks_on)
833 msmsdcc_enable_clocks(host, 0);
834 spin_unlock_irqrestore(&host->lock, flags);
San Mehat9d2bd732009-09-22 16:44:22 -0700835}
836
837static void msmsdcc_enable_sdio_irq(struct mmc_host *mmc, int enable)
838{
839 struct msmsdcc_host *host = mmc_priv(mmc);
840 unsigned long flags;
841 u32 status;
842
843 spin_lock_irqsave(&host->lock, flags);
844 if (msmsdcc_sdioirq == 1) {
845 status = readl(host->base + MMCIMASK0);
846 if (enable)
847 status |= MCI_SDIOINTOPERMASK;
848 else
849 status &= ~MCI_SDIOINTOPERMASK;
850 host->saved_irq0mask = status;
851 writel(status, host->base + MMCIMASK0);
852 }
853 spin_unlock_irqrestore(&host->lock, flags);
854}
855
856static const struct mmc_host_ops msmsdcc_ops = {
857 .request = msmsdcc_request,
858 .set_ios = msmsdcc_set_ios,
859 .enable_sdio_irq = msmsdcc_enable_sdio_irq,
860};
861
862static void
863msmsdcc_check_status(unsigned long data)
864{
865 struct msmsdcc_host *host = (struct msmsdcc_host *)data;
866 unsigned int status;
867
868 if (!host->plat->status) {
869 mmc_detect_change(host->mmc, 0);
870 goto out;
871 }
872
873 status = host->plat->status(mmc_dev(host->mmc));
874 host->eject = !status;
875 if (status ^ host->oldstat) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700876 pr_info("%s: Slot status change detected (%d -> %d)\n",
877 mmc_hostname(host->mmc), host->oldstat, status);
San Mehat9d2bd732009-09-22 16:44:22 -0700878 if (status)
879 mmc_detect_change(host->mmc, (5 * HZ) / 2);
880 else
881 mmc_detect_change(host->mmc, 0);
882 }
883
884 host->oldstat = status;
885
886out:
887 if (host->timer.function)
888 mod_timer(&host->timer, jiffies + HZ);
889}
890
891static irqreturn_t
892msmsdcc_platform_status_irq(int irq, void *dev_id)
893{
894 struct msmsdcc_host *host = dev_id;
895
896 printk(KERN_DEBUG "%s: %d\n", __func__, irq);
897 msmsdcc_check_status((unsigned long) host);
898 return IRQ_HANDLED;
899}
900
901static void
902msmsdcc_status_notify_cb(int card_present, void *dev_id)
903{
904 struct msmsdcc_host *host = dev_id;
905
906 printk(KERN_DEBUG "%s: card_present %d\n", mmc_hostname(host->mmc),
907 card_present);
908 msmsdcc_check_status((unsigned long) host);
909}
910
911/*
912 * called when a command expires.
913 * Dump some debugging, and then error
914 * out the transaction.
915 */
916static void
917msmsdcc_command_expired(unsigned long _data)
918{
919 struct msmsdcc_host *host = (struct msmsdcc_host *) _data;
920 struct mmc_request *mrq;
921 unsigned long flags;
922
923 spin_lock_irqsave(&host->lock, flags);
924 mrq = host->curr.mrq;
925
926 if (!mrq) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700927 pr_info("%s: Command expiry misfire\n",
928 mmc_hostname(host->mmc));
San Mehat9d2bd732009-09-22 16:44:22 -0700929 spin_unlock_irqrestore(&host->lock, flags);
930 return;
931 }
932
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700933 pr_err("%s: Command timeout (%p %p %p %p)\n",
San Mehat9d2bd732009-09-22 16:44:22 -0700934 mmc_hostname(host->mmc), mrq, mrq->cmd,
935 mrq->data, host->dma.sg);
San Mehat9d2bd732009-09-22 16:44:22 -0700936 mrq->cmd->error = -ETIMEDOUT;
937 msmsdcc_stop_data(host);
938
939 writel(0, host->base + MMCICOMMAND);
940
941 host->curr.mrq = NULL;
942 host->curr.cmd = NULL;
943
944 spin_unlock_irqrestore(&host->lock, flags);
945 mmc_request_done(host->mmc, mrq);
946}
947
948static int
949msmsdcc_init_dma(struct msmsdcc_host *host)
950{
951 memset(&host->dma, 0, sizeof(struct msmsdcc_dma_data));
952 host->dma.host = host;
953 host->dma.channel = -1;
954
955 if (!host->dmares)
956 return -ENODEV;
957
958 host->dma.nc = dma_alloc_coherent(NULL,
959 sizeof(struct msmsdcc_nc_dmadata),
960 &host->dma.nc_busaddr,
961 GFP_KERNEL);
962 if (host->dma.nc == NULL) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -0700963 pr_err("Unable to allocate DMA buffer\n");
San Mehat9d2bd732009-09-22 16:44:22 -0700964 return -ENOMEM;
965 }
966 memset(host->dma.nc, 0x00, sizeof(struct msmsdcc_nc_dmadata));
967 host->dma.cmd_busaddr = host->dma.nc_busaddr;
968 host->dma.cmdptr_busaddr = host->dma.nc_busaddr +
969 offsetof(struct msmsdcc_nc_dmadata, cmdptr);
970 host->dma.channel = host->dmares->start;
971
972 return 0;
973}
974
975#ifdef CONFIG_MMC_MSM7X00A_RESUME_IN_WQ
976static void
977do_resume_work(struct work_struct *work)
978{
979 struct msmsdcc_host *host =
980 container_of(work, struct msmsdcc_host, resume_task);
981 struct mmc_host *mmc = host->mmc;
982
983 if (mmc) {
984 mmc_resume_host(mmc);
985 if (host->stat_irq)
986 enable_irq(host->stat_irq);
987 }
988}
989#endif
990
991static int
992msmsdcc_probe(struct platform_device *pdev)
993{
994 struct mmc_platform_data *plat = pdev->dev.platform_data;
995 struct msmsdcc_host *host;
996 struct mmc_host *mmc;
997 struct resource *cmd_irqres = NULL;
998 struct resource *pio_irqres = NULL;
999 struct resource *stat_irqres = NULL;
1000 struct resource *memres = NULL;
1001 struct resource *dmares = NULL;
1002 int ret;
1003
1004 /* must have platform data */
1005 if (!plat) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -07001006 pr_err("%s: Platform data not available\n", __func__);
San Mehat9d2bd732009-09-22 16:44:22 -07001007 ret = -EINVAL;
1008 goto out;
1009 }
1010
1011 if (pdev->id < 1 || pdev->id > 4)
1012 return -EINVAL;
1013
1014 if (pdev->resource == NULL || pdev->num_resources < 2) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -07001015 pr_err("%s: Invalid resource\n", __func__);
San Mehat9d2bd732009-09-22 16:44:22 -07001016 return -ENXIO;
1017 }
1018
1019 memres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1020 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1021 cmd_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1022 "cmd_irq");
1023 pio_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1024 "pio_irq");
1025 stat_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1026 "status_irq");
1027
1028 if (!cmd_irqres || !pio_irqres || !memres) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -07001029 pr_err("%s: Invalid resource\n", __func__);
San Mehat9d2bd732009-09-22 16:44:22 -07001030 return -ENXIO;
1031 }
1032
1033 /*
1034 * Setup our host structure
1035 */
1036
1037 mmc = mmc_alloc_host(sizeof(struct msmsdcc_host), &pdev->dev);
1038 if (!mmc) {
1039 ret = -ENOMEM;
1040 goto out;
1041 }
1042
1043 host = mmc_priv(mmc);
1044 host->pdev_id = pdev->id;
1045 host->plat = plat;
1046 host->mmc = mmc;
1047
1048 host->cmdpoll = 1;
1049
1050 host->base = ioremap(memres->start, PAGE_SIZE);
1051 if (!host->base) {
1052 ret = -ENOMEM;
1053 goto out;
1054 }
1055
1056 host->cmd_irqres = cmd_irqres;
1057 host->pio_irqres = pio_irqres;
1058 host->memres = memres;
1059 host->dmares = dmares;
1060 spin_lock_init(&host->lock);
1061
1062 /*
1063 * Setup DMA
1064 */
1065 msmsdcc_init_dma(host);
1066
San Mehat4adbbcc2009-11-08 13:00:37 -08001067 /* Get our clocks */
San Mehat9d2bd732009-09-22 16:44:22 -07001068 host->pclk = clk_get(&pdev->dev, "sdc_pclk");
1069 if (IS_ERR(host->pclk)) {
1070 ret = PTR_ERR(host->pclk);
1071 goto host_free;
1072 }
1073
San Mehat9d2bd732009-09-22 16:44:22 -07001074 host->clk = clk_get(&pdev->dev, "sdc_clk");
1075 if (IS_ERR(host->clk)) {
1076 ret = PTR_ERR(host->clk);
San Mehat4adbbcc2009-11-08 13:00:37 -08001077 goto pclk_put;
San Mehat9d2bd732009-09-22 16:44:22 -07001078 }
1079
San Mehat4adbbcc2009-11-08 13:00:37 -08001080 /* Enable clocks */
1081 ret = msmsdcc_enable_clocks(host, 1);
San Mehat9d2bd732009-09-22 16:44:22 -07001082 if (ret)
1083 goto clk_put;
1084
1085 ret = clk_set_rate(host->clk, msmsdcc_fmin);
1086 if (ret) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -07001087 pr_err("%s: Clock rate set failed (%d)\n", __func__, ret);
San Mehat9d2bd732009-09-22 16:44:22 -07001088 goto clk_disable;
1089 }
1090
San Mehat4adbbcc2009-11-08 13:00:37 -08001091 host->pclk_rate = clk_get_rate(host->pclk);
San Mehat9d2bd732009-09-22 16:44:22 -07001092 host->clk_rate = clk_get_rate(host->clk);
1093
San Mehat9d2bd732009-09-22 16:44:22 -07001094 /*
1095 * Setup MMC host structure
1096 */
1097 mmc->ops = &msmsdcc_ops;
1098 mmc->f_min = msmsdcc_fmin;
1099 mmc->f_max = msmsdcc_fmax;
1100 mmc->ocr_avail = plat->ocr_mask;
1101
1102 if (msmsdcc_4bit)
1103 mmc->caps |= MMC_CAP_4_BIT_DATA;
1104 if (msmsdcc_sdioirq)
1105 mmc->caps |= MMC_CAP_SDIO_IRQ;
1106 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED;
1107
1108 mmc->max_phys_segs = NR_SG;
1109 mmc->max_hw_segs = NR_SG;
1110 mmc->max_blk_size = 4096; /* MCI_DATA_CTL BLOCKSIZE up to 4096 */
1111 mmc->max_blk_count = 65536;
1112
1113 mmc->max_req_size = 33554432; /* MCI_DATA_LENGTH is 25 bits */
1114 mmc->max_seg_size = mmc->max_req_size;
1115
1116 writel(0, host->base + MMCIMASK0);
1117 writel(0x5e007ff, host->base + MMCICLEAR); /* Add: 1 << 25 */
1118
1119 writel(MCI_IRQENABLE, host->base + MMCIMASK0);
1120 host->saved_irq0mask = MCI_IRQENABLE;
1121
1122 /*
1123 * Setup card detect change
1124 */
1125
1126 memset(&host->timer, 0, sizeof(host->timer));
1127
1128 if (stat_irqres && !(stat_irqres->flags & IORESOURCE_DISABLED)) {
1129 unsigned long irqflags = IRQF_SHARED |
1130 (stat_irqres->flags & IRQF_TRIGGER_MASK);
1131
1132 host->stat_irq = stat_irqres->start;
1133 ret = request_irq(host->stat_irq,
1134 msmsdcc_platform_status_irq,
1135 irqflags,
1136 DRIVER_NAME " (slot)",
1137 host);
1138 if (ret) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -07001139 pr_err("%s: Unable to get slot IRQ %d (%d)\n",
1140 mmc_hostname(mmc), host->stat_irq, ret);
San Mehat9d2bd732009-09-22 16:44:22 -07001141 goto clk_disable;
1142 }
1143 } else if (plat->register_status_notify) {
1144 plat->register_status_notify(msmsdcc_status_notify_cb, host);
1145 } else if (!plat->status)
Joe Perches0a7ff7c2009-09-22 16:44:23 -07001146 pr_err("%s: No card detect facilities available\n",
San Mehat9d2bd732009-09-22 16:44:22 -07001147 mmc_hostname(mmc));
1148 else {
1149 init_timer(&host->timer);
1150 host->timer.data = (unsigned long)host;
1151 host->timer.function = msmsdcc_check_status;
1152 host->timer.expires = jiffies + HZ;
1153 add_timer(&host->timer);
1154 }
1155
1156 if (plat->status) {
1157 host->oldstat = host->plat->status(mmc_dev(host->mmc));
1158 host->eject = !host->oldstat;
1159 }
1160
1161 /*
1162 * Setup a command timer. We currently need this due to
1163 * some 'strange' timeout / error handling situations.
1164 */
1165 init_timer(&host->command_timer);
1166 host->command_timer.data = (unsigned long) host;
1167 host->command_timer.function = msmsdcc_command_expired;
1168
1169 ret = request_irq(cmd_irqres->start, msmsdcc_irq, IRQF_SHARED,
1170 DRIVER_NAME " (cmd)", host);
1171 if (ret)
1172 goto stat_irq_free;
1173
1174 ret = request_irq(pio_irqres->start, msmsdcc_pio_irq, IRQF_SHARED,
1175 DRIVER_NAME " (pio)", host);
1176 if (ret)
1177 goto cmd_irq_free;
1178
1179 mmc_set_drvdata(pdev, mmc);
1180 mmc_add_host(mmc);
1181
Joe Perches0a7ff7c2009-09-22 16:44:23 -07001182 pr_info("%s: Qualcomm MSM SDCC at 0x%016llx irq %d,%d dma %d\n",
1183 mmc_hostname(mmc), (unsigned long long)memres->start,
1184 (unsigned int) cmd_irqres->start,
1185 (unsigned int) host->stat_irq, host->dma.channel);
1186 pr_info("%s: 4 bit data mode %s\n", mmc_hostname(mmc),
1187 (mmc->caps & MMC_CAP_4_BIT_DATA ? "enabled" : "disabled"));
1188 pr_info("%s: MMC clock %u -> %u Hz, PCLK %u Hz\n",
1189 mmc_hostname(mmc), msmsdcc_fmin, msmsdcc_fmax, host->pclk_rate);
1190 pr_info("%s: Slot eject status = %d\n", mmc_hostname(mmc), host->eject);
1191 pr_info("%s: Power save feature enable = %d\n",
1192 mmc_hostname(mmc), msmsdcc_pwrsave);
San Mehat9d2bd732009-09-22 16:44:22 -07001193
1194 if (host->dma.channel != -1) {
Joe Perches0a7ff7c2009-09-22 16:44:23 -07001195 pr_info("%s: DM non-cached buffer at %p, dma_addr 0x%.8x\n",
1196 mmc_hostname(mmc), host->dma.nc, host->dma.nc_busaddr);
1197 pr_info("%s: DM cmd busaddr 0x%.8x, cmdptr busaddr 0x%.8x\n",
1198 mmc_hostname(mmc), host->dma.cmd_busaddr,
1199 host->dma.cmdptr_busaddr);
San Mehat9d2bd732009-09-22 16:44:22 -07001200 } else
Joe Perches0a7ff7c2009-09-22 16:44:23 -07001201 pr_info("%s: PIO transfer enabled\n", mmc_hostname(mmc));
San Mehat9d2bd732009-09-22 16:44:22 -07001202 if (host->timer.function)
Joe Perches0a7ff7c2009-09-22 16:44:23 -07001203 pr_info("%s: Polling status mode enabled\n", mmc_hostname(mmc));
San Mehat9d2bd732009-09-22 16:44:22 -07001204
1205 return 0;
1206 cmd_irq_free:
1207 free_irq(cmd_irqres->start, host);
1208 stat_irq_free:
1209 if (host->stat_irq)
1210 free_irq(host->stat_irq, host);
1211 clk_disable:
San Mehat4adbbcc2009-11-08 13:00:37 -08001212 msmsdcc_enable_clocks(host, 0);
San Mehat9d2bd732009-09-22 16:44:22 -07001213 clk_put:
1214 clk_put(host->clk);
San Mehat9d2bd732009-09-22 16:44:22 -07001215 pclk_put:
1216 clk_put(host->pclk);
1217 host_free:
1218 mmc_free_host(mmc);
1219 out:
1220 return ret;
1221}
1222
1223static int
1224msmsdcc_suspend(struct platform_device *dev, pm_message_t state)
1225{
1226 struct mmc_host *mmc = mmc_get_drvdata(dev);
1227 int rc = 0;
1228
1229 if (mmc) {
1230 struct msmsdcc_host *host = mmc_priv(mmc);
1231
1232 if (host->stat_irq)
1233 disable_irq(host->stat_irq);
1234
1235 if (mmc->card && mmc->card->type != MMC_TYPE_SDIO)
1236 rc = mmc_suspend_host(mmc, state);
1237 if (!rc) {
1238 writel(0, host->base + MMCIMASK0);
1239
San Mehat4adbbcc2009-11-08 13:00:37 -08001240 if (host->clks_on)
1241 msmsdcc_enable_clocks(host, 0);
San Mehat9d2bd732009-09-22 16:44:22 -07001242 }
1243 }
1244 return rc;
1245}
1246
1247static int
1248msmsdcc_resume(struct platform_device *dev)
1249{
1250 struct mmc_host *mmc = mmc_get_drvdata(dev);
1251 unsigned long flags;
1252
1253 if (mmc) {
1254 struct msmsdcc_host *host = mmc_priv(mmc);
1255
1256 spin_lock_irqsave(&host->lock, flags);
1257
San Mehat4adbbcc2009-11-08 13:00:37 -08001258 if (!host->clks_on)
1259 msmsdcc_enable_clocks(host, 1);
San Mehat9d2bd732009-09-22 16:44:22 -07001260
1261 writel(host->saved_irq0mask, host->base + MMCIMASK0);
1262
1263 spin_unlock_irqrestore(&host->lock, flags);
1264
1265 if (mmc->card && mmc->card->type != MMC_TYPE_SDIO)
1266 mmc_resume_host(mmc);
Roel Kluin5b8a2fb2010-01-17 20:25:36 +01001267 if (host->stat_irq)
San Mehat9d2bd732009-09-22 16:44:22 -07001268 enable_irq(host->stat_irq);
1269 }
1270 return 0;
1271}
1272
1273static struct platform_driver msmsdcc_driver = {
1274 .probe = msmsdcc_probe,
1275 .suspend = msmsdcc_suspend,
1276 .resume = msmsdcc_resume,
1277 .driver = {
1278 .name = "msm_sdcc",
1279 },
1280};
1281
1282static int __init msmsdcc_init(void)
1283{
1284 return platform_driver_register(&msmsdcc_driver);
1285}
1286
1287static void __exit msmsdcc_exit(void)
1288{
1289 platform_driver_unregister(&msmsdcc_driver);
1290}
1291
1292module_init(msmsdcc_init);
1293module_exit(msmsdcc_exit);
1294
1295MODULE_DESCRIPTION("Qualcomm MSM 7X00A Multimedia Card Interface driver");
1296MODULE_LICENSE("GPL");