blob: df6207909fe7602686c328a47fc64944919a69d0 [file] [log] [blame]
Will Newtonf95f3852011-01-02 01:11:59 -05001/*
2 * Synopsys DesignWare Multimedia Card Interface driver
3 * (Based on NXP driver for lpc 31xx)
4 *
5 * Copyright (C) 2009 NXP Semiconductors
6 * Copyright (C) 2009, 2010 Imagination Technologies Ltd.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/blkdev.h>
15#include <linux/clk.h>
16#include <linux/debugfs.h>
17#include <linux/device.h>
18#include <linux/dma-mapping.h>
19#include <linux/err.h>
20#include <linux/init.h>
21#include <linux/interrupt.h>
22#include <linux/ioport.h>
23#include <linux/module.h>
24#include <linux/platform_device.h>
Will Newtonf95f3852011-01-02 01:11:59 -050025#include <linux/seq_file.h>
26#include <linux/slab.h>
27#include <linux/stat.h>
28#include <linux/delay.h>
29#include <linux/irq.h>
30#include <linux/mmc/host.h>
31#include <linux/mmc/mmc.h>
32#include <linux/mmc/dw_mmc.h>
33#include <linux/bitops.h>
Jaehoon Chungc07946a2011-02-25 11:08:14 +090034#include <linux/regulator/consumer.h>
James Hogan1791b13e2011-06-24 13:55:55 +010035#include <linux/workqueue.h>
Thomas Abrahamc91eab42012-09-17 18:16:40 +000036#include <linux/of.h>
Doug Anderson55a6ceb2013-01-11 17:03:53 +000037#include <linux/of_gpio.h>
Will Newtonf95f3852011-01-02 01:11:59 -050038
39#include "dw_mmc.h"
40
41/* Common flag combinations */
42#define DW_MCI_DATA_ERROR_FLAGS (SDMMC_INT_DTO | SDMMC_INT_DCRC | \
43 SDMMC_INT_HTO | SDMMC_INT_SBE | \
44 SDMMC_INT_EBE)
45#define DW_MCI_CMD_ERROR_FLAGS (SDMMC_INT_RTO | SDMMC_INT_RCRC | \
46 SDMMC_INT_RESP_ERR)
47#define DW_MCI_ERROR_FLAGS (DW_MCI_DATA_ERROR_FLAGS | \
48 DW_MCI_CMD_ERROR_FLAGS | SDMMC_INT_HLE)
49#define DW_MCI_SEND_STATUS 1
50#define DW_MCI_RECV_STATUS 2
51#define DW_MCI_DMA_THRESHOLD 16
52
53#ifdef CONFIG_MMC_DW_IDMAC
54struct idmac_desc {
55 u32 des0; /* Control Descriptor */
56#define IDMAC_DES0_DIC BIT(1)
57#define IDMAC_DES0_LD BIT(2)
58#define IDMAC_DES0_FD BIT(3)
59#define IDMAC_DES0_CH BIT(4)
60#define IDMAC_DES0_ER BIT(5)
61#define IDMAC_DES0_CES BIT(30)
62#define IDMAC_DES0_OWN BIT(31)
63
64 u32 des1; /* Buffer sizes */
65#define IDMAC_SET_BUFFER1_SIZE(d, s) \
Shashidhar Hiremath9b7bbe12011-07-29 08:49:50 -040066 ((d)->des1 = ((d)->des1 & 0x03ffe000) | ((s) & 0x1fff))
Will Newtonf95f3852011-01-02 01:11:59 -050067
68 u32 des2; /* buffer 1 physical address */
69
70 u32 des3; /* buffer 2 physical address */
71};
72#endif /* CONFIG_MMC_DW_IDMAC */
73
74/**
75 * struct dw_mci_slot - MMC slot state
76 * @mmc: The mmc_host representing this slot.
77 * @host: The MMC controller this slot is using.
Doug Andersona70aaa62013-01-11 17:03:50 +000078 * @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX)
Doug Anderson55a6ceb2013-01-11 17:03:53 +000079 * @wp_gpio: If gpio_is_valid() we'll use this to read write protect.
Will Newtonf95f3852011-01-02 01:11:59 -050080 * @ctype: Card type for this slot.
81 * @mrq: mmc_request currently being processed or waiting to be
82 * processed, or NULL when the slot is idle.
83 * @queue_node: List node for placing this node in the @queue list of
84 * &struct dw_mci.
85 * @clock: Clock rate configured by set_ios(). Protected by host->lock.
86 * @flags: Random state bits associated with the slot.
87 * @id: Number of this slot.
88 * @last_detect_state: Most recently observed card detect state.
89 */
90struct dw_mci_slot {
91 struct mmc_host *mmc;
92 struct dw_mci *host;
93
Doug Andersona70aaa62013-01-11 17:03:50 +000094 int quirks;
Doug Anderson55a6ceb2013-01-11 17:03:53 +000095 int wp_gpio;
Doug Andersona70aaa62013-01-11 17:03:50 +000096
Will Newtonf95f3852011-01-02 01:11:59 -050097 u32 ctype;
98
99 struct mmc_request *mrq;
100 struct list_head queue_node;
101
102 unsigned int clock;
103 unsigned long flags;
104#define DW_MMC_CARD_PRESENT 0
105#define DW_MMC_CARD_NEED_INIT 1
106 int id;
107 int last_detect_state;
108};
109
110#if defined(CONFIG_DEBUG_FS)
111static int dw_mci_req_show(struct seq_file *s, void *v)
112{
113 struct dw_mci_slot *slot = s->private;
114 struct mmc_request *mrq;
115 struct mmc_command *cmd;
116 struct mmc_command *stop;
117 struct mmc_data *data;
118
119 /* Make sure we get a consistent snapshot */
120 spin_lock_bh(&slot->host->lock);
121 mrq = slot->mrq;
122
123 if (mrq) {
124 cmd = mrq->cmd;
125 data = mrq->data;
126 stop = mrq->stop;
127
128 if (cmd)
129 seq_printf(s,
130 "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
131 cmd->opcode, cmd->arg, cmd->flags,
132 cmd->resp[0], cmd->resp[1], cmd->resp[2],
133 cmd->resp[2], cmd->error);
134 if (data)
135 seq_printf(s, "DATA %u / %u * %u flg %x err %d\n",
136 data->bytes_xfered, data->blocks,
137 data->blksz, data->flags, data->error);
138 if (stop)
139 seq_printf(s,
140 "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
141 stop->opcode, stop->arg, stop->flags,
142 stop->resp[0], stop->resp[1], stop->resp[2],
143 stop->resp[2], stop->error);
144 }
145
146 spin_unlock_bh(&slot->host->lock);
147
148 return 0;
149}
150
151static int dw_mci_req_open(struct inode *inode, struct file *file)
152{
153 return single_open(file, dw_mci_req_show, inode->i_private);
154}
155
156static const struct file_operations dw_mci_req_fops = {
157 .owner = THIS_MODULE,
158 .open = dw_mci_req_open,
159 .read = seq_read,
160 .llseek = seq_lseek,
161 .release = single_release,
162};
163
164static int dw_mci_regs_show(struct seq_file *s, void *v)
165{
166 seq_printf(s, "STATUS:\t0x%08x\n", SDMMC_STATUS);
167 seq_printf(s, "RINTSTS:\t0x%08x\n", SDMMC_RINTSTS);
168 seq_printf(s, "CMD:\t0x%08x\n", SDMMC_CMD);
169 seq_printf(s, "CTRL:\t0x%08x\n", SDMMC_CTRL);
170 seq_printf(s, "INTMASK:\t0x%08x\n", SDMMC_INTMASK);
171 seq_printf(s, "CLKENA:\t0x%08x\n", SDMMC_CLKENA);
172
173 return 0;
174}
175
176static int dw_mci_regs_open(struct inode *inode, struct file *file)
177{
178 return single_open(file, dw_mci_regs_show, inode->i_private);
179}
180
181static const struct file_operations dw_mci_regs_fops = {
182 .owner = THIS_MODULE,
183 .open = dw_mci_regs_open,
184 .read = seq_read,
185 .llseek = seq_lseek,
186 .release = single_release,
187};
188
189static void dw_mci_init_debugfs(struct dw_mci_slot *slot)
190{
191 struct mmc_host *mmc = slot->mmc;
192 struct dw_mci *host = slot->host;
193 struct dentry *root;
194 struct dentry *node;
195
196 root = mmc->debugfs_root;
197 if (!root)
198 return;
199
200 node = debugfs_create_file("regs", S_IRUSR, root, host,
201 &dw_mci_regs_fops);
202 if (!node)
203 goto err;
204
205 node = debugfs_create_file("req", S_IRUSR, root, slot,
206 &dw_mci_req_fops);
207 if (!node)
208 goto err;
209
210 node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state);
211 if (!node)
212 goto err;
213
214 node = debugfs_create_x32("pending_events", S_IRUSR, root,
215 (u32 *)&host->pending_events);
216 if (!node)
217 goto err;
218
219 node = debugfs_create_x32("completed_events", S_IRUSR, root,
220 (u32 *)&host->completed_events);
221 if (!node)
222 goto err;
223
224 return;
225
226err:
227 dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n");
228}
229#endif /* defined(CONFIG_DEBUG_FS) */
230
231static void dw_mci_set_timeout(struct dw_mci *host)
232{
233 /* timeout (maximum) */
234 mci_writel(host, TMOUT, 0xffffffff);
235}
236
237static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
238{
239 struct mmc_data *data;
Thomas Abraham800d78b2012-09-17 18:16:42 +0000240 struct dw_mci_slot *slot = mmc_priv(mmc);
Arnd Bergmanne95baf12012-11-08 14:26:11 +0000241 const struct dw_mci_drv_data *drv_data = slot->host->drv_data;
Will Newtonf95f3852011-01-02 01:11:59 -0500242 u32 cmdr;
243 cmd->error = -EINPROGRESS;
244
245 cmdr = cmd->opcode;
246
247 if (cmdr == MMC_STOP_TRANSMISSION)
248 cmdr |= SDMMC_CMD_STOP;
249 else
250 cmdr |= SDMMC_CMD_PRV_DAT_WAIT;
251
252 if (cmd->flags & MMC_RSP_PRESENT) {
253 /* We expect a response, so set this bit */
254 cmdr |= SDMMC_CMD_RESP_EXP;
255 if (cmd->flags & MMC_RSP_136)
256 cmdr |= SDMMC_CMD_RESP_LONG;
257 }
258
259 if (cmd->flags & MMC_RSP_CRC)
260 cmdr |= SDMMC_CMD_RESP_CRC;
261
262 data = cmd->data;
263 if (data) {
264 cmdr |= SDMMC_CMD_DAT_EXP;
265 if (data->flags & MMC_DATA_STREAM)
266 cmdr |= SDMMC_CMD_STRM_MODE;
267 if (data->flags & MMC_DATA_WRITE)
268 cmdr |= SDMMC_CMD_DAT_WR;
269 }
270
James Hogancb27a842012-10-16 09:43:08 +0100271 if (drv_data && drv_data->prepare_command)
272 drv_data->prepare_command(slot->host, &cmdr);
Thomas Abraham800d78b2012-09-17 18:16:42 +0000273
Will Newtonf95f3852011-01-02 01:11:59 -0500274 return cmdr;
275}
276
277static void dw_mci_start_command(struct dw_mci *host,
278 struct mmc_command *cmd, u32 cmd_flags)
279{
280 host->cmd = cmd;
Thomas Abraham4a909202012-09-17 18:16:35 +0000281 dev_vdbg(host->dev,
Will Newtonf95f3852011-01-02 01:11:59 -0500282 "start command: ARGR=0x%08x CMDR=0x%08x\n",
283 cmd->arg, cmd_flags);
284
285 mci_writel(host, CMDARG, cmd->arg);
286 wmb();
287
288 mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START);
289}
290
291static void send_stop_cmd(struct dw_mci *host, struct mmc_data *data)
292{
293 dw_mci_start_command(host, data->stop, host->stop_cmdr);
294}
295
296/* DMA interface functions */
297static void dw_mci_stop_dma(struct dw_mci *host)
298{
James Hogan03e8cb532011-06-29 09:28:43 +0100299 if (host->using_dma) {
Will Newtonf95f3852011-01-02 01:11:59 -0500300 host->dma_ops->stop(host);
301 host->dma_ops->cleanup(host);
302 } else {
303 /* Data transfer was stopped by the interrupt handler */
304 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
305 }
306}
307
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900308static int dw_mci_get_dma_dir(struct mmc_data *data)
309{
310 if (data->flags & MMC_DATA_WRITE)
311 return DMA_TO_DEVICE;
312 else
313 return DMA_FROM_DEVICE;
314}
315
Jaehoon Chung9beee912012-02-16 11:19:38 +0900316#ifdef CONFIG_MMC_DW_IDMAC
Will Newtonf95f3852011-01-02 01:11:59 -0500317static void dw_mci_dma_cleanup(struct dw_mci *host)
318{
319 struct mmc_data *data = host->data;
320
321 if (data)
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900322 if (!data->host_cookie)
Thomas Abraham4a909202012-09-17 18:16:35 +0000323 dma_unmap_sg(host->dev,
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900324 data->sg,
325 data->sg_len,
326 dw_mci_get_dma_dir(data));
Will Newtonf95f3852011-01-02 01:11:59 -0500327}
328
329static void dw_mci_idmac_stop_dma(struct dw_mci *host)
330{
331 u32 temp;
332
333 /* Disable and reset the IDMAC interface */
334 temp = mci_readl(host, CTRL);
335 temp &= ~SDMMC_CTRL_USE_IDMAC;
336 temp |= SDMMC_CTRL_DMA_RESET;
337 mci_writel(host, CTRL, temp);
338
339 /* Stop the IDMAC running */
340 temp = mci_readl(host, BMOD);
Jaehoon Chunga5289a42011-02-25 11:08:13 +0900341 temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB);
Will Newtonf95f3852011-01-02 01:11:59 -0500342 mci_writel(host, BMOD, temp);
343}
344
345static void dw_mci_idmac_complete_dma(struct dw_mci *host)
346{
347 struct mmc_data *data = host->data;
348
Thomas Abraham4a909202012-09-17 18:16:35 +0000349 dev_vdbg(host->dev, "DMA complete\n");
Will Newtonf95f3852011-01-02 01:11:59 -0500350
351 host->dma_ops->cleanup(host);
352
353 /*
354 * If the card was removed, data will be NULL. No point in trying to
355 * send the stop command or waiting for NBUSY in this case.
356 */
357 if (data) {
358 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
359 tasklet_schedule(&host->tasklet);
360 }
361}
362
363static void dw_mci_translate_sglist(struct dw_mci *host, struct mmc_data *data,
364 unsigned int sg_len)
365{
366 int i;
367 struct idmac_desc *desc = host->sg_cpu;
368
369 for (i = 0; i < sg_len; i++, desc++) {
370 unsigned int length = sg_dma_len(&data->sg[i]);
371 u32 mem_addr = sg_dma_address(&data->sg[i]);
372
373 /* Set the OWN bit and disable interrupts for this descriptor */
374 desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC | IDMAC_DES0_CH;
375
376 /* Buffer length */
377 IDMAC_SET_BUFFER1_SIZE(desc, length);
378
379 /* Physical address to DMA to/from */
380 desc->des2 = mem_addr;
381 }
382
383 /* Set first descriptor */
384 desc = host->sg_cpu;
385 desc->des0 |= IDMAC_DES0_FD;
386
387 /* Set last descriptor */
388 desc = host->sg_cpu + (i - 1) * sizeof(struct idmac_desc);
389 desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC);
390 desc->des0 |= IDMAC_DES0_LD;
391
392 wmb();
393}
394
395static void dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len)
396{
397 u32 temp;
398
399 dw_mci_translate_sglist(host, host->data, sg_len);
400
401 /* Select IDMAC interface */
402 temp = mci_readl(host, CTRL);
403 temp |= SDMMC_CTRL_USE_IDMAC;
404 mci_writel(host, CTRL, temp);
405
406 wmb();
407
408 /* Enable the IDMAC */
409 temp = mci_readl(host, BMOD);
Jaehoon Chunga5289a42011-02-25 11:08:13 +0900410 temp |= SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB;
Will Newtonf95f3852011-01-02 01:11:59 -0500411 mci_writel(host, BMOD, temp);
412
413 /* Start it running */
414 mci_writel(host, PLDMND, 1);
415}
416
417static int dw_mci_idmac_init(struct dw_mci *host)
418{
419 struct idmac_desc *p;
Seungwon Jeon897b69e2012-09-19 13:58:31 +0800420 int i;
Will Newtonf95f3852011-01-02 01:11:59 -0500421
422 /* Number of descriptors in the ring buffer */
423 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc);
424
425 /* Forward link the descriptor list */
426 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++)
427 p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * (i + 1));
428
429 /* Set the last descriptor as the end-of-ring descriptor */
430 p->des3 = host->sg_dma;
431 p->des0 = IDMAC_DES0_ER;
432
Seungwon Jeon141a7122012-05-22 13:01:03 +0900433 mci_writel(host, BMOD, SDMMC_IDMAC_SWRESET);
434
Will Newtonf95f3852011-01-02 01:11:59 -0500435 /* Mask out interrupts - get Tx & Rx complete only */
436 mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI | SDMMC_IDMAC_INT_RI |
437 SDMMC_IDMAC_INT_TI);
438
439 /* Set the descriptor base address */
440 mci_writel(host, DBADDR, host->sg_dma);
441 return 0;
442}
443
Arnd Bergmann8e2b36e2012-11-06 22:55:31 +0100444static const struct dw_mci_dma_ops dw_mci_idmac_ops = {
Seungwon Jeon885c3e82012-02-20 11:01:43 +0900445 .init = dw_mci_idmac_init,
446 .start = dw_mci_idmac_start_dma,
447 .stop = dw_mci_idmac_stop_dma,
448 .complete = dw_mci_idmac_complete_dma,
449 .cleanup = dw_mci_dma_cleanup,
450};
451#endif /* CONFIG_MMC_DW_IDMAC */
452
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900453static int dw_mci_pre_dma_transfer(struct dw_mci *host,
454 struct mmc_data *data,
455 bool next)
Will Newtonf95f3852011-01-02 01:11:59 -0500456{
457 struct scatterlist *sg;
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900458 unsigned int i, sg_len;
Will Newtonf95f3852011-01-02 01:11:59 -0500459
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900460 if (!next && data->host_cookie)
461 return data->host_cookie;
Will Newtonf95f3852011-01-02 01:11:59 -0500462
463 /*
464 * We don't do DMA on "complex" transfers, i.e. with
465 * non-word-aligned buffers or lengths. Also, we don't bother
466 * with all the DMA setup overhead for short transfers.
467 */
468 if (data->blocks * data->blksz < DW_MCI_DMA_THRESHOLD)
469 return -EINVAL;
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900470
Will Newtonf95f3852011-01-02 01:11:59 -0500471 if (data->blksz & 3)
472 return -EINVAL;
473
474 for_each_sg(data->sg, sg, data->sg_len, i) {
475 if (sg->offset & 3 || sg->length & 3)
476 return -EINVAL;
477 }
478
Thomas Abraham4a909202012-09-17 18:16:35 +0000479 sg_len = dma_map_sg(host->dev,
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900480 data->sg,
481 data->sg_len,
482 dw_mci_get_dma_dir(data));
483 if (sg_len == 0)
484 return -EINVAL;
485
486 if (next)
487 data->host_cookie = sg_len;
488
489 return sg_len;
490}
491
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900492static void dw_mci_pre_req(struct mmc_host *mmc,
493 struct mmc_request *mrq,
494 bool is_first_req)
495{
496 struct dw_mci_slot *slot = mmc_priv(mmc);
497 struct mmc_data *data = mrq->data;
498
499 if (!slot->host->use_dma || !data)
500 return;
501
502 if (data->host_cookie) {
503 data->host_cookie = 0;
504 return;
505 }
506
507 if (dw_mci_pre_dma_transfer(slot->host, mrq->data, 1) < 0)
508 data->host_cookie = 0;
509}
510
511static void dw_mci_post_req(struct mmc_host *mmc,
512 struct mmc_request *mrq,
513 int err)
514{
515 struct dw_mci_slot *slot = mmc_priv(mmc);
516 struct mmc_data *data = mrq->data;
517
518 if (!slot->host->use_dma || !data)
519 return;
520
521 if (data->host_cookie)
Thomas Abraham4a909202012-09-17 18:16:35 +0000522 dma_unmap_sg(slot->host->dev,
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900523 data->sg,
524 data->sg_len,
525 dw_mci_get_dma_dir(data));
526 data->host_cookie = 0;
527}
528
529static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
530{
531 int sg_len;
532 u32 temp;
533
534 host->using_dma = 0;
535
536 /* If we don't have a channel, we can't do DMA */
537 if (!host->use_dma)
538 return -ENODEV;
539
540 sg_len = dw_mci_pre_dma_transfer(host, data, 0);
Seungwon Jeona99aa9b2012-04-10 09:53:32 +0900541 if (sg_len < 0) {
542 host->dma_ops->stop(host);
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900543 return sg_len;
Seungwon Jeona99aa9b2012-04-10 09:53:32 +0900544 }
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900545
James Hogan03e8cb532011-06-29 09:28:43 +0100546 host->using_dma = 1;
547
Thomas Abraham4a909202012-09-17 18:16:35 +0000548 dev_vdbg(host->dev,
Will Newtonf95f3852011-01-02 01:11:59 -0500549 "sd sg_cpu: %#lx sg_dma: %#lx sg_len: %d\n",
550 (unsigned long)host->sg_cpu, (unsigned long)host->sg_dma,
551 sg_len);
552
553 /* Enable the DMA interface */
554 temp = mci_readl(host, CTRL);
555 temp |= SDMMC_CTRL_DMA_ENABLE;
556 mci_writel(host, CTRL, temp);
557
558 /* Disable RX/TX IRQs, let DMA handle it */
559 temp = mci_readl(host, INTMASK);
560 temp &= ~(SDMMC_INT_RXDR | SDMMC_INT_TXDR);
561 mci_writel(host, INTMASK, temp);
562
563 host->dma_ops->start(host, sg_len);
564
565 return 0;
566}
567
568static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
569{
570 u32 temp;
571
572 data->error = -EINPROGRESS;
573
574 WARN_ON(host->data);
575 host->sg = NULL;
576 host->data = data;
577
James Hogan55c5efbc2011-06-29 09:29:58 +0100578 if (data->flags & MMC_DATA_READ)
579 host->dir_status = DW_MCI_RECV_STATUS;
580 else
581 host->dir_status = DW_MCI_SEND_STATUS;
582
Will Newtonf95f3852011-01-02 01:11:59 -0500583 if (dw_mci_submit_data_dma(host, data)) {
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +0900584 int flags = SG_MITER_ATOMIC;
585 if (host->data->flags & MMC_DATA_READ)
586 flags |= SG_MITER_TO_SG;
587 else
588 flags |= SG_MITER_FROM_SG;
589
590 sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
Will Newtonf95f3852011-01-02 01:11:59 -0500591 host->sg = data->sg;
James Hogan34b664a2011-06-24 13:57:56 +0100592 host->part_buf_start = 0;
593 host->part_buf_count = 0;
Will Newtonf95f3852011-01-02 01:11:59 -0500594
James Hoganb40af3a2011-06-24 13:54:06 +0100595 mci_writel(host, RINTSTS, SDMMC_INT_TXDR | SDMMC_INT_RXDR);
Will Newtonf95f3852011-01-02 01:11:59 -0500596 temp = mci_readl(host, INTMASK);
597 temp |= SDMMC_INT_TXDR | SDMMC_INT_RXDR;
598 mci_writel(host, INTMASK, temp);
599
600 temp = mci_readl(host, CTRL);
601 temp &= ~SDMMC_CTRL_DMA_ENABLE;
602 mci_writel(host, CTRL, temp);
603 }
604}
605
606static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
607{
608 struct dw_mci *host = slot->host;
609 unsigned long timeout = jiffies + msecs_to_jiffies(500);
610 unsigned int cmd_status = 0;
611
612 mci_writel(host, CMDARG, arg);
613 wmb();
614 mci_writel(host, CMD, SDMMC_CMD_START | cmd);
615
616 while (time_before(jiffies, timeout)) {
617 cmd_status = mci_readl(host, CMD);
618 if (!(cmd_status & SDMMC_CMD_START))
619 return;
620 }
621 dev_err(&slot->mmc->class_dev,
622 "Timeout sending command (cmd %#x arg %#x status %#x)\n",
623 cmd, arg, cmd_status);
624}
625
Abhilash Kesavanab269122012-11-19 10:26:21 +0530626static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
Will Newtonf95f3852011-01-02 01:11:59 -0500627{
628 struct dw_mci *host = slot->host;
629 u32 div;
Doug Anderson9623b5b2012-07-25 08:33:17 -0700630 u32 clk_en_a;
Will Newtonf95f3852011-01-02 01:11:59 -0500631
Abhilash Kesavanab269122012-11-19 10:26:21 +0530632 if (slot->clock != host->current_speed || force_clkinit) {
Seungwon Jeone4199902012-05-22 13:01:21 +0900633 div = host->bus_hz / slot->clock;
634 if (host->bus_hz % slot->clock && host->bus_hz > slot->clock)
Will Newtonf95f3852011-01-02 01:11:59 -0500635 /*
636 * move the + 1 after the divide to prevent
637 * over-clocking the card.
638 */
Seungwon Jeone4199902012-05-22 13:01:21 +0900639 div += 1;
640
641 div = (host->bus_hz != slot->clock) ? DIV_ROUND_UP(div, 2) : 0;
Will Newtonf95f3852011-01-02 01:11:59 -0500642
643 dev_info(&slot->mmc->class_dev,
644 "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ"
645 " div = %d)\n", slot->id, host->bus_hz, slot->clock,
646 div ? ((host->bus_hz / div) >> 1) : host->bus_hz, div);
647
648 /* disable clock */
649 mci_writel(host, CLKENA, 0);
650 mci_writel(host, CLKSRC, 0);
651
652 /* inform CIU */
653 mci_send_cmd(slot,
654 SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
655
656 /* set clock to desired speed */
657 mci_writel(host, CLKDIV, div);
658
659 /* inform CIU */
660 mci_send_cmd(slot,
661 SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
662
Doug Anderson9623b5b2012-07-25 08:33:17 -0700663 /* enable clock; only low power if no SDIO */
664 clk_en_a = SDMMC_CLKEN_ENABLE << slot->id;
665 if (!(mci_readl(host, INTMASK) & SDMMC_INT_SDIO(slot->id)))
666 clk_en_a |= SDMMC_CLKEN_LOW_PWR << slot->id;
667 mci_writel(host, CLKENA, clk_en_a);
Will Newtonf95f3852011-01-02 01:11:59 -0500668
669 /* inform CIU */
670 mci_send_cmd(slot,
671 SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT, 0);
672
673 host->current_speed = slot->clock;
674 }
675
676 /* Set the current slot bus width */
Seungwon Jeon1d56c452011-06-20 17:23:53 +0900677 mci_writel(host, CTYPE, (slot->ctype << slot->id));
Will Newtonf95f3852011-01-02 01:11:59 -0500678}
679
Seungwon Jeon053b3ce2011-12-22 18:01:29 +0900680static void __dw_mci_start_request(struct dw_mci *host,
681 struct dw_mci_slot *slot,
682 struct mmc_command *cmd)
Will Newtonf95f3852011-01-02 01:11:59 -0500683{
684 struct mmc_request *mrq;
Will Newtonf95f3852011-01-02 01:11:59 -0500685 struct mmc_data *data;
686 u32 cmdflags;
687
688 mrq = slot->mrq;
689 if (host->pdata->select_slot)
690 host->pdata->select_slot(slot->id);
691
Will Newtonf95f3852011-01-02 01:11:59 -0500692 host->cur_slot = slot;
693 host->mrq = mrq;
694
695 host->pending_events = 0;
696 host->completed_events = 0;
697 host->data_status = 0;
698
Seungwon Jeon053b3ce2011-12-22 18:01:29 +0900699 data = cmd->data;
Will Newtonf95f3852011-01-02 01:11:59 -0500700 if (data) {
701 dw_mci_set_timeout(host);
702 mci_writel(host, BYTCNT, data->blksz*data->blocks);
703 mci_writel(host, BLKSIZ, data->blksz);
704 }
705
Will Newtonf95f3852011-01-02 01:11:59 -0500706 cmdflags = dw_mci_prepare_command(slot->mmc, cmd);
707
708 /* this is the first command, send the initialization clock */
709 if (test_and_clear_bit(DW_MMC_CARD_NEED_INIT, &slot->flags))
710 cmdflags |= SDMMC_CMD_INIT;
711
712 if (data) {
713 dw_mci_submit_data(host, data);
714 wmb();
715 }
716
717 dw_mci_start_command(host, cmd, cmdflags);
718
719 if (mrq->stop)
720 host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
721}
722
Seungwon Jeon053b3ce2011-12-22 18:01:29 +0900723static void dw_mci_start_request(struct dw_mci *host,
724 struct dw_mci_slot *slot)
725{
726 struct mmc_request *mrq = slot->mrq;
727 struct mmc_command *cmd;
728
729 cmd = mrq->sbc ? mrq->sbc : mrq->cmd;
730 __dw_mci_start_request(host, slot, cmd);
731}
732
James Hogan7456caa2011-06-24 13:55:10 +0100733/* must be called with host->lock held */
Will Newtonf95f3852011-01-02 01:11:59 -0500734static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot,
735 struct mmc_request *mrq)
736{
737 dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d\n",
738 host->state);
739
Will Newtonf95f3852011-01-02 01:11:59 -0500740 slot->mrq = mrq;
741
742 if (host->state == STATE_IDLE) {
743 host->state = STATE_SENDING_CMD;
744 dw_mci_start_request(host, slot);
745 } else {
746 list_add_tail(&slot->queue_node, &host->queue);
747 }
Will Newtonf95f3852011-01-02 01:11:59 -0500748}
749
750static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
751{
752 struct dw_mci_slot *slot = mmc_priv(mmc);
753 struct dw_mci *host = slot->host;
754
755 WARN_ON(slot->mrq);
756
James Hogan7456caa2011-06-24 13:55:10 +0100757 /*
758 * The check for card presence and queueing of the request must be
759 * atomic, otherwise the card could be removed in between and the
760 * request wouldn't fail until another card was inserted.
761 */
762 spin_lock_bh(&host->lock);
763
Will Newtonf95f3852011-01-02 01:11:59 -0500764 if (!test_bit(DW_MMC_CARD_PRESENT, &slot->flags)) {
James Hogan7456caa2011-06-24 13:55:10 +0100765 spin_unlock_bh(&host->lock);
Will Newtonf95f3852011-01-02 01:11:59 -0500766 mrq->cmd->error = -ENOMEDIUM;
767 mmc_request_done(mmc, mrq);
768 return;
769 }
770
Will Newtonf95f3852011-01-02 01:11:59 -0500771 dw_mci_queue_request(host, slot, mrq);
James Hogan7456caa2011-06-24 13:55:10 +0100772
773 spin_unlock_bh(&host->lock);
Will Newtonf95f3852011-01-02 01:11:59 -0500774}
775
776static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
777{
778 struct dw_mci_slot *slot = mmc_priv(mmc);
Arnd Bergmanne95baf12012-11-08 14:26:11 +0000779 const struct dw_mci_drv_data *drv_data = slot->host->drv_data;
Jaehoon Chung41babf72011-02-24 13:46:11 +0900780 u32 regs;
Will Newtonf95f3852011-01-02 01:11:59 -0500781
Will Newtonf95f3852011-01-02 01:11:59 -0500782 switch (ios->bus_width) {
Will Newtonf95f3852011-01-02 01:11:59 -0500783 case MMC_BUS_WIDTH_4:
784 slot->ctype = SDMMC_CTYPE_4BIT;
785 break;
Jaehoon Chungc9b2a062011-02-17 16:12:38 +0900786 case MMC_BUS_WIDTH_8:
787 slot->ctype = SDMMC_CTYPE_8BIT;
788 break;
Jaehoon Chungb2f7cb42012-11-08 17:35:31 +0900789 default:
790 /* set default 1 bit mode */
791 slot->ctype = SDMMC_CTYPE_1BIT;
Will Newtonf95f3852011-01-02 01:11:59 -0500792 }
793
Seungwon Jeon3f514292012-01-02 16:00:02 +0900794 regs = mci_readl(slot->host, UHS_REG);
795
Jaehoon Chung41babf72011-02-24 13:46:11 +0900796 /* DDR mode set */
Seungwon Jeon3f514292012-01-02 16:00:02 +0900797 if (ios->timing == MMC_TIMING_UHS_DDR50)
Jaehoon Chung41babf72011-02-24 13:46:11 +0900798 regs |= (0x1 << slot->id) << 16;
Seungwon Jeon3f514292012-01-02 16:00:02 +0900799 else
800 regs &= ~(0x1 << slot->id) << 16;
801
802 mci_writel(slot->host, UHS_REG, regs);
Jaehoon Chung41babf72011-02-24 13:46:11 +0900803
Will Newtonf95f3852011-01-02 01:11:59 -0500804 if (ios->clock) {
805 /*
806 * Use mirror of ios->clock to prevent race with mmc
807 * core ios update when finding the minimum.
808 */
809 slot->clock = ios->clock;
810 }
811
James Hogancb27a842012-10-16 09:43:08 +0100812 if (drv_data && drv_data->set_ios)
813 drv_data->set_ios(slot->host, ios);
Thomas Abraham800d78b2012-09-17 18:16:42 +0000814
Jaehoon Chungbf7cb222012-11-08 17:35:29 +0900815 /* Slot specific timing and width adjustment */
816 dw_mci_setup_bus(slot, false);
817
Will Newtonf95f3852011-01-02 01:11:59 -0500818 switch (ios->power_mode) {
819 case MMC_POWER_UP:
820 set_bit(DW_MMC_CARD_NEED_INIT, &slot->flags);
821 break;
822 default:
823 break;
824 }
825}
826
827static int dw_mci_get_ro(struct mmc_host *mmc)
828{
829 int read_only;
830 struct dw_mci_slot *slot = mmc_priv(mmc);
831 struct dw_mci_board *brd = slot->host->pdata;
832
833 /* Use platform get_ro function, else try on board write protect */
Doug Andersona70aaa62013-01-11 17:03:50 +0000834
835 /*
836 * NOTE: DW_MCI_QUIRK_NO_WRITE_PROTECT will be removed in a future
837 * patch in the series once reference to it is removed.
838 */
839 if ((brd->quirks & DW_MCI_QUIRK_NO_WRITE_PROTECT) ||
840 (slot->quirks & DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT))
Thomas Abrahamb4967aa2012-09-17 18:16:39 +0000841 read_only = 0;
842 else if (brd->get_ro)
Will Newtonf95f3852011-01-02 01:11:59 -0500843 read_only = brd->get_ro(slot->id);
Doug Anderson55a6ceb2013-01-11 17:03:53 +0000844 else if (gpio_is_valid(slot->wp_gpio))
845 read_only = gpio_get_value(slot->wp_gpio);
Will Newtonf95f3852011-01-02 01:11:59 -0500846 else
847 read_only =
848 mci_readl(slot->host, WRTPRT) & (1 << slot->id) ? 1 : 0;
849
850 dev_dbg(&mmc->class_dev, "card is %s\n",
851 read_only ? "read-only" : "read-write");
852
853 return read_only;
854}
855
856static int dw_mci_get_cd(struct mmc_host *mmc)
857{
858 int present;
859 struct dw_mci_slot *slot = mmc_priv(mmc);
860 struct dw_mci_board *brd = slot->host->pdata;
861
862 /* Use platform get_cd function, else try onboard card detect */
Jaehoon Chungfc3d7722011-02-25 11:08:15 +0900863 if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION)
864 present = 1;
865 else if (brd->get_cd)
Will Newtonf95f3852011-01-02 01:11:59 -0500866 present = !brd->get_cd(slot->id);
867 else
868 present = (mci_readl(slot->host, CDETECT) & (1 << slot->id))
869 == 0 ? 1 : 0;
870
871 if (present)
872 dev_dbg(&mmc->class_dev, "card is present\n");
873 else
874 dev_dbg(&mmc->class_dev, "card is not present\n");
875
876 return present;
877}
878
Doug Anderson9623b5b2012-07-25 08:33:17 -0700879/*
880 * Disable lower power mode.
881 *
882 * Low power mode will stop the card clock when idle. According to the
883 * description of the CLKENA register we should disable low power mode
884 * for SDIO cards if we need SDIO interrupts to work.
885 *
886 * This function is fast if low power mode is already disabled.
887 */
888static void dw_mci_disable_low_power(struct dw_mci_slot *slot)
889{
890 struct dw_mci *host = slot->host;
891 u32 clk_en_a;
892 const u32 clken_low_pwr = SDMMC_CLKEN_LOW_PWR << slot->id;
893
894 clk_en_a = mci_readl(host, CLKENA);
895
896 if (clk_en_a & clken_low_pwr) {
897 mci_writel(host, CLKENA, clk_en_a & ~clken_low_pwr);
898 mci_send_cmd(slot, SDMMC_CMD_UPD_CLK |
899 SDMMC_CMD_PRV_DAT_WAIT, 0);
900 }
901}
902
Shashidhar Hiremath1a5c8e12011-08-29 13:11:46 +0530903static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb)
904{
905 struct dw_mci_slot *slot = mmc_priv(mmc);
906 struct dw_mci *host = slot->host;
907 u32 int_mask;
908
909 /* Enable/disable Slot Specific SDIO interrupt */
910 int_mask = mci_readl(host, INTMASK);
911 if (enb) {
Doug Anderson9623b5b2012-07-25 08:33:17 -0700912 /*
913 * Turn off low power mode if it was enabled. This is a bit of
914 * a heavy operation and we disable / enable IRQs a lot, so
915 * we'll leave low power mode disabled and it will get
916 * re-enabled again in dw_mci_setup_bus().
917 */
918 dw_mci_disable_low_power(slot);
919
Shashidhar Hiremath1a5c8e12011-08-29 13:11:46 +0530920 mci_writel(host, INTMASK,
Kyoungil Kim705ad042012-05-14 17:38:48 +0900921 (int_mask | SDMMC_INT_SDIO(slot->id)));
Shashidhar Hiremath1a5c8e12011-08-29 13:11:46 +0530922 } else {
923 mci_writel(host, INTMASK,
Kyoungil Kim705ad042012-05-14 17:38:48 +0900924 (int_mask & ~SDMMC_INT_SDIO(slot->id)));
Shashidhar Hiremath1a5c8e12011-08-29 13:11:46 +0530925 }
926}
927
Will Newtonf95f3852011-01-02 01:11:59 -0500928static const struct mmc_host_ops dw_mci_ops = {
Shashidhar Hiremath1a5c8e12011-08-29 13:11:46 +0530929 .request = dw_mci_request,
Seungwon Jeon9aa51402012-02-06 16:55:07 +0900930 .pre_req = dw_mci_pre_req,
931 .post_req = dw_mci_post_req,
Shashidhar Hiremath1a5c8e12011-08-29 13:11:46 +0530932 .set_ios = dw_mci_set_ios,
933 .get_ro = dw_mci_get_ro,
934 .get_cd = dw_mci_get_cd,
935 .enable_sdio_irq = dw_mci_enable_sdio_irq,
Will Newtonf95f3852011-01-02 01:11:59 -0500936};
937
938static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
939 __releases(&host->lock)
940 __acquires(&host->lock)
941{
942 struct dw_mci_slot *slot;
943 struct mmc_host *prev_mmc = host->cur_slot->mmc;
944
945 WARN_ON(host->cmd || host->data);
946
947 host->cur_slot->mrq = NULL;
948 host->mrq = NULL;
949 if (!list_empty(&host->queue)) {
950 slot = list_entry(host->queue.next,
951 struct dw_mci_slot, queue_node);
952 list_del(&slot->queue_node);
Thomas Abraham4a909202012-09-17 18:16:35 +0000953 dev_vdbg(host->dev, "list not empty: %s is next\n",
Will Newtonf95f3852011-01-02 01:11:59 -0500954 mmc_hostname(slot->mmc));
955 host->state = STATE_SENDING_CMD;
956 dw_mci_start_request(host, slot);
957 } else {
Thomas Abraham4a909202012-09-17 18:16:35 +0000958 dev_vdbg(host->dev, "list empty\n");
Will Newtonf95f3852011-01-02 01:11:59 -0500959 host->state = STATE_IDLE;
960 }
961
962 spin_unlock(&host->lock);
963 mmc_request_done(prev_mmc, mrq);
964 spin_lock(&host->lock);
965}
966
967static void dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd)
968{
969 u32 status = host->cmd_status;
970
971 host->cmd_status = 0;
972
973 /* Read the response from the card (up to 16 bytes) */
974 if (cmd->flags & MMC_RSP_PRESENT) {
975 if (cmd->flags & MMC_RSP_136) {
976 cmd->resp[3] = mci_readl(host, RESP0);
977 cmd->resp[2] = mci_readl(host, RESP1);
978 cmd->resp[1] = mci_readl(host, RESP2);
979 cmd->resp[0] = mci_readl(host, RESP3);
980 } else {
981 cmd->resp[0] = mci_readl(host, RESP0);
982 cmd->resp[1] = 0;
983 cmd->resp[2] = 0;
984 cmd->resp[3] = 0;
985 }
986 }
987
988 if (status & SDMMC_INT_RTO)
989 cmd->error = -ETIMEDOUT;
990 else if ((cmd->flags & MMC_RSP_CRC) && (status & SDMMC_INT_RCRC))
991 cmd->error = -EILSEQ;
992 else if (status & SDMMC_INT_RESP_ERR)
993 cmd->error = -EIO;
994 else
995 cmd->error = 0;
996
997 if (cmd->error) {
998 /* newer ip versions need a delay between retries */
999 if (host->quirks & DW_MCI_QUIRK_RETRY_DELAY)
1000 mdelay(20);
1001
1002 if (cmd->data) {
Will Newtonf95f3852011-01-02 01:11:59 -05001003 dw_mci_stop_dma(host);
Seungwon Jeonfda5f732012-05-22 13:01:13 +09001004 host->data = NULL;
Will Newtonf95f3852011-01-02 01:11:59 -05001005 }
1006 }
1007}
1008
1009static void dw_mci_tasklet_func(unsigned long priv)
1010{
1011 struct dw_mci *host = (struct dw_mci *)priv;
1012 struct mmc_data *data;
1013 struct mmc_command *cmd;
1014 enum dw_mci_state state;
1015 enum dw_mci_state prev_state;
James Hogan94dd5b32011-06-29 09:30:47 +01001016 u32 status, ctrl;
Will Newtonf95f3852011-01-02 01:11:59 -05001017
1018 spin_lock(&host->lock);
1019
1020 state = host->state;
1021 data = host->data;
1022
1023 do {
1024 prev_state = state;
1025
1026 switch (state) {
1027 case STATE_IDLE:
1028 break;
1029
1030 case STATE_SENDING_CMD:
1031 if (!test_and_clear_bit(EVENT_CMD_COMPLETE,
1032 &host->pending_events))
1033 break;
1034
1035 cmd = host->cmd;
1036 host->cmd = NULL;
1037 set_bit(EVENT_CMD_COMPLETE, &host->completed_events);
Seungwon Jeon053b3ce2011-12-22 18:01:29 +09001038 dw_mci_command_complete(host, cmd);
1039 if (cmd == host->mrq->sbc && !cmd->error) {
1040 prev_state = state = STATE_SENDING_CMD;
1041 __dw_mci_start_request(host, host->cur_slot,
1042 host->mrq->cmd);
1043 goto unlock;
1044 }
1045
Will Newtonf95f3852011-01-02 01:11:59 -05001046 if (!host->mrq->data || cmd->error) {
1047 dw_mci_request_end(host, host->mrq);
1048 goto unlock;
1049 }
1050
1051 prev_state = state = STATE_SENDING_DATA;
1052 /* fall through */
1053
1054 case STATE_SENDING_DATA:
1055 if (test_and_clear_bit(EVENT_DATA_ERROR,
1056 &host->pending_events)) {
1057 dw_mci_stop_dma(host);
1058 if (data->stop)
1059 send_stop_cmd(host, data);
1060 state = STATE_DATA_ERROR;
1061 break;
1062 }
1063
1064 if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
1065 &host->pending_events))
1066 break;
1067
1068 set_bit(EVENT_XFER_COMPLETE, &host->completed_events);
1069 prev_state = state = STATE_DATA_BUSY;
1070 /* fall through */
1071
1072 case STATE_DATA_BUSY:
1073 if (!test_and_clear_bit(EVENT_DATA_COMPLETE,
1074 &host->pending_events))
1075 break;
1076
1077 host->data = NULL;
1078 set_bit(EVENT_DATA_COMPLETE, &host->completed_events);
1079 status = host->data_status;
1080
1081 if (status & DW_MCI_DATA_ERROR_FLAGS) {
1082 if (status & SDMMC_INT_DTO) {
Will Newtonf95f3852011-01-02 01:11:59 -05001083 data->error = -ETIMEDOUT;
1084 } else if (status & SDMMC_INT_DCRC) {
Will Newtonf95f3852011-01-02 01:11:59 -05001085 data->error = -EILSEQ;
James Hogan55c5efbc2011-06-29 09:29:58 +01001086 } else if (status & SDMMC_INT_EBE &&
1087 host->dir_status ==
1088 DW_MCI_SEND_STATUS) {
1089 /*
1090 * No data CRC status was returned.
1091 * The number of bytes transferred will
1092 * be exaggerated in PIO mode.
1093 */
1094 data->bytes_xfered = 0;
1095 data->error = -ETIMEDOUT;
Will Newtonf95f3852011-01-02 01:11:59 -05001096 } else {
Thomas Abraham4a909202012-09-17 18:16:35 +00001097 dev_err(host->dev,
Will Newtonf95f3852011-01-02 01:11:59 -05001098 "data FIFO error "
1099 "(status=%08x)\n",
1100 status);
1101 data->error = -EIO;
1102 }
James Hogan94dd5b32011-06-29 09:30:47 +01001103 /*
1104 * After an error, there may be data lingering
1105 * in the FIFO, so reset it - doing so
1106 * generates a block interrupt, hence setting
1107 * the scatter-gather pointer to NULL.
1108 */
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001109 sg_miter_stop(&host->sg_miter);
James Hogan94dd5b32011-06-29 09:30:47 +01001110 host->sg = NULL;
1111 ctrl = mci_readl(host, CTRL);
1112 ctrl |= SDMMC_CTRL_FIFO_RESET;
1113 mci_writel(host, CTRL, ctrl);
Will Newtonf95f3852011-01-02 01:11:59 -05001114 } else {
1115 data->bytes_xfered = data->blocks * data->blksz;
1116 data->error = 0;
1117 }
1118
1119 if (!data->stop) {
1120 dw_mci_request_end(host, host->mrq);
1121 goto unlock;
1122 }
1123
Seungwon Jeon053b3ce2011-12-22 18:01:29 +09001124 if (host->mrq->sbc && !data->error) {
1125 data->stop->error = 0;
1126 dw_mci_request_end(host, host->mrq);
1127 goto unlock;
1128 }
1129
Will Newtonf95f3852011-01-02 01:11:59 -05001130 prev_state = state = STATE_SENDING_STOP;
1131 if (!data->error)
1132 send_stop_cmd(host, data);
1133 /* fall through */
1134
1135 case STATE_SENDING_STOP:
1136 if (!test_and_clear_bit(EVENT_CMD_COMPLETE,
1137 &host->pending_events))
1138 break;
1139
1140 host->cmd = NULL;
1141 dw_mci_command_complete(host, host->mrq->stop);
1142 dw_mci_request_end(host, host->mrq);
1143 goto unlock;
1144
1145 case STATE_DATA_ERROR:
1146 if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
1147 &host->pending_events))
1148 break;
1149
1150 state = STATE_DATA_BUSY;
1151 break;
1152 }
1153 } while (state != prev_state);
1154
1155 host->state = state;
1156unlock:
1157 spin_unlock(&host->lock);
1158
1159}
1160
James Hogan34b664a2011-06-24 13:57:56 +01001161/* push final bytes to part_buf, only use during push */
1162static void dw_mci_set_part_bytes(struct dw_mci *host, void *buf, int cnt)
1163{
1164 memcpy((void *)&host->part_buf, buf, cnt);
1165 host->part_buf_count = cnt;
1166}
1167
1168/* append bytes to part_buf, only use during push */
1169static int dw_mci_push_part_bytes(struct dw_mci *host, void *buf, int cnt)
1170{
1171 cnt = min(cnt, (1 << host->data_shift) - host->part_buf_count);
1172 memcpy((void *)&host->part_buf + host->part_buf_count, buf, cnt);
1173 host->part_buf_count += cnt;
1174 return cnt;
1175}
1176
1177/* pull first bytes from part_buf, only use during pull */
1178static int dw_mci_pull_part_bytes(struct dw_mci *host, void *buf, int cnt)
1179{
1180 cnt = min(cnt, (int)host->part_buf_count);
1181 if (cnt) {
1182 memcpy(buf, (void *)&host->part_buf + host->part_buf_start,
1183 cnt);
1184 host->part_buf_count -= cnt;
1185 host->part_buf_start += cnt;
1186 }
1187 return cnt;
1188}
1189
1190/* pull final bytes from the part_buf, assuming it's just been filled */
1191static void dw_mci_pull_final_bytes(struct dw_mci *host, void *buf, int cnt)
1192{
1193 memcpy(buf, &host->part_buf, cnt);
1194 host->part_buf_start = cnt;
1195 host->part_buf_count = (1 << host->data_shift) - cnt;
1196}
1197
Will Newtonf95f3852011-01-02 01:11:59 -05001198static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
1199{
James Hogan34b664a2011-06-24 13:57:56 +01001200 /* try and push anything in the part_buf */
1201 if (unlikely(host->part_buf_count)) {
1202 int len = dw_mci_push_part_bytes(host, buf, cnt);
1203 buf += len;
1204 cnt -= len;
1205 if (!sg_next(host->sg) || host->part_buf_count == 2) {
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001206 mci_writew(host, DATA(host->data_offset),
1207 host->part_buf16);
James Hogan34b664a2011-06-24 13:57:56 +01001208 host->part_buf_count = 0;
1209 }
1210 }
1211#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1212 if (unlikely((unsigned long)buf & 0x1)) {
1213 while (cnt >= 2) {
1214 u16 aligned_buf[64];
1215 int len = min(cnt & -2, (int)sizeof(aligned_buf));
1216 int items = len >> 1;
1217 int i;
1218 /* memcpy from input buffer into aligned buffer */
1219 memcpy(aligned_buf, buf, len);
1220 buf += len;
1221 cnt -= len;
1222 /* push data from aligned buffer into fifo */
1223 for (i = 0; i < items; ++i)
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001224 mci_writew(host, DATA(host->data_offset),
1225 aligned_buf[i]);
James Hogan34b664a2011-06-24 13:57:56 +01001226 }
1227 } else
1228#endif
1229 {
1230 u16 *pdata = buf;
1231 for (; cnt >= 2; cnt -= 2)
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001232 mci_writew(host, DATA(host->data_offset), *pdata++);
James Hogan34b664a2011-06-24 13:57:56 +01001233 buf = pdata;
1234 }
1235 /* put anything remaining in the part_buf */
1236 if (cnt) {
1237 dw_mci_set_part_bytes(host, buf, cnt);
1238 if (!sg_next(host->sg))
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001239 mci_writew(host, DATA(host->data_offset),
1240 host->part_buf16);
Will Newtonf95f3852011-01-02 01:11:59 -05001241 }
1242}
1243
1244static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
1245{
James Hogan34b664a2011-06-24 13:57:56 +01001246#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1247 if (unlikely((unsigned long)buf & 0x1)) {
1248 while (cnt >= 2) {
1249 /* pull data from fifo into aligned buffer */
1250 u16 aligned_buf[64];
1251 int len = min(cnt & -2, (int)sizeof(aligned_buf));
1252 int items = len >> 1;
1253 int i;
1254 for (i = 0; i < items; ++i)
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001255 aligned_buf[i] = mci_readw(host,
1256 DATA(host->data_offset));
James Hogan34b664a2011-06-24 13:57:56 +01001257 /* memcpy from aligned buffer into output buffer */
1258 memcpy(buf, aligned_buf, len);
1259 buf += len;
1260 cnt -= len;
1261 }
1262 } else
1263#endif
1264 {
1265 u16 *pdata = buf;
1266 for (; cnt >= 2; cnt -= 2)
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001267 *pdata++ = mci_readw(host, DATA(host->data_offset));
James Hogan34b664a2011-06-24 13:57:56 +01001268 buf = pdata;
1269 }
1270 if (cnt) {
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001271 host->part_buf16 = mci_readw(host, DATA(host->data_offset));
James Hogan34b664a2011-06-24 13:57:56 +01001272 dw_mci_pull_final_bytes(host, buf, cnt);
Will Newtonf95f3852011-01-02 01:11:59 -05001273 }
1274}
1275
1276static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
1277{
James Hogan34b664a2011-06-24 13:57:56 +01001278 /* try and push anything in the part_buf */
1279 if (unlikely(host->part_buf_count)) {
1280 int len = dw_mci_push_part_bytes(host, buf, cnt);
1281 buf += len;
1282 cnt -= len;
1283 if (!sg_next(host->sg) || host->part_buf_count == 4) {
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001284 mci_writel(host, DATA(host->data_offset),
1285 host->part_buf32);
James Hogan34b664a2011-06-24 13:57:56 +01001286 host->part_buf_count = 0;
1287 }
1288 }
1289#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1290 if (unlikely((unsigned long)buf & 0x3)) {
1291 while (cnt >= 4) {
1292 u32 aligned_buf[32];
1293 int len = min(cnt & -4, (int)sizeof(aligned_buf));
1294 int items = len >> 2;
1295 int i;
1296 /* memcpy from input buffer into aligned buffer */
1297 memcpy(aligned_buf, buf, len);
1298 buf += len;
1299 cnt -= len;
1300 /* push data from aligned buffer into fifo */
1301 for (i = 0; i < items; ++i)
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001302 mci_writel(host, DATA(host->data_offset),
1303 aligned_buf[i]);
James Hogan34b664a2011-06-24 13:57:56 +01001304 }
1305 } else
1306#endif
1307 {
1308 u32 *pdata = buf;
1309 for (; cnt >= 4; cnt -= 4)
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001310 mci_writel(host, DATA(host->data_offset), *pdata++);
James Hogan34b664a2011-06-24 13:57:56 +01001311 buf = pdata;
1312 }
1313 /* put anything remaining in the part_buf */
1314 if (cnt) {
1315 dw_mci_set_part_bytes(host, buf, cnt);
1316 if (!sg_next(host->sg))
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001317 mci_writel(host, DATA(host->data_offset),
1318 host->part_buf32);
Will Newtonf95f3852011-01-02 01:11:59 -05001319 }
1320}
1321
1322static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
1323{
James Hogan34b664a2011-06-24 13:57:56 +01001324#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1325 if (unlikely((unsigned long)buf & 0x3)) {
1326 while (cnt >= 4) {
1327 /* pull data from fifo into aligned buffer */
1328 u32 aligned_buf[32];
1329 int len = min(cnt & -4, (int)sizeof(aligned_buf));
1330 int items = len >> 2;
1331 int i;
1332 for (i = 0; i < items; ++i)
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001333 aligned_buf[i] = mci_readl(host,
1334 DATA(host->data_offset));
James Hogan34b664a2011-06-24 13:57:56 +01001335 /* memcpy from aligned buffer into output buffer */
1336 memcpy(buf, aligned_buf, len);
1337 buf += len;
1338 cnt -= len;
1339 }
1340 } else
1341#endif
1342 {
1343 u32 *pdata = buf;
1344 for (; cnt >= 4; cnt -= 4)
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001345 *pdata++ = mci_readl(host, DATA(host->data_offset));
James Hogan34b664a2011-06-24 13:57:56 +01001346 buf = pdata;
1347 }
1348 if (cnt) {
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001349 host->part_buf32 = mci_readl(host, DATA(host->data_offset));
James Hogan34b664a2011-06-24 13:57:56 +01001350 dw_mci_pull_final_bytes(host, buf, cnt);
Will Newtonf95f3852011-01-02 01:11:59 -05001351 }
1352}
1353
1354static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
1355{
James Hogan34b664a2011-06-24 13:57:56 +01001356 /* try and push anything in the part_buf */
1357 if (unlikely(host->part_buf_count)) {
1358 int len = dw_mci_push_part_bytes(host, buf, cnt);
1359 buf += len;
1360 cnt -= len;
1361 if (!sg_next(host->sg) || host->part_buf_count == 8) {
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001362 mci_writew(host, DATA(host->data_offset),
1363 host->part_buf);
James Hogan34b664a2011-06-24 13:57:56 +01001364 host->part_buf_count = 0;
1365 }
1366 }
1367#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1368 if (unlikely((unsigned long)buf & 0x7)) {
1369 while (cnt >= 8) {
1370 u64 aligned_buf[16];
1371 int len = min(cnt & -8, (int)sizeof(aligned_buf));
1372 int items = len >> 3;
1373 int i;
1374 /* memcpy from input buffer into aligned buffer */
1375 memcpy(aligned_buf, buf, len);
1376 buf += len;
1377 cnt -= len;
1378 /* push data from aligned buffer into fifo */
1379 for (i = 0; i < items; ++i)
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001380 mci_writeq(host, DATA(host->data_offset),
1381 aligned_buf[i]);
James Hogan34b664a2011-06-24 13:57:56 +01001382 }
1383 } else
1384#endif
1385 {
1386 u64 *pdata = buf;
1387 for (; cnt >= 8; cnt -= 8)
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001388 mci_writeq(host, DATA(host->data_offset), *pdata++);
James Hogan34b664a2011-06-24 13:57:56 +01001389 buf = pdata;
1390 }
1391 /* put anything remaining in the part_buf */
1392 if (cnt) {
1393 dw_mci_set_part_bytes(host, buf, cnt);
1394 if (!sg_next(host->sg))
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001395 mci_writeq(host, DATA(host->data_offset),
1396 host->part_buf);
Will Newtonf95f3852011-01-02 01:11:59 -05001397 }
1398}
1399
1400static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
1401{
James Hogan34b664a2011-06-24 13:57:56 +01001402#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1403 if (unlikely((unsigned long)buf & 0x7)) {
1404 while (cnt >= 8) {
1405 /* pull data from fifo into aligned buffer */
1406 u64 aligned_buf[16];
1407 int len = min(cnt & -8, (int)sizeof(aligned_buf));
1408 int items = len >> 3;
1409 int i;
1410 for (i = 0; i < items; ++i)
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001411 aligned_buf[i] = mci_readq(host,
1412 DATA(host->data_offset));
James Hogan34b664a2011-06-24 13:57:56 +01001413 /* memcpy from aligned buffer into output buffer */
1414 memcpy(buf, aligned_buf, len);
1415 buf += len;
1416 cnt -= len;
1417 }
1418 } else
1419#endif
1420 {
1421 u64 *pdata = buf;
1422 for (; cnt >= 8; cnt -= 8)
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001423 *pdata++ = mci_readq(host, DATA(host->data_offset));
James Hogan34b664a2011-06-24 13:57:56 +01001424 buf = pdata;
Will Newtonf95f3852011-01-02 01:11:59 -05001425 }
James Hogan34b664a2011-06-24 13:57:56 +01001426 if (cnt) {
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09001427 host->part_buf = mci_readq(host, DATA(host->data_offset));
James Hogan34b664a2011-06-24 13:57:56 +01001428 dw_mci_pull_final_bytes(host, buf, cnt);
1429 }
1430}
1431
1432static void dw_mci_pull_data(struct dw_mci *host, void *buf, int cnt)
1433{
1434 int len;
1435
1436 /* get remaining partial bytes */
1437 len = dw_mci_pull_part_bytes(host, buf, cnt);
1438 if (unlikely(len == cnt))
1439 return;
1440 buf += len;
1441 cnt -= len;
1442
1443 /* get the rest of the data */
1444 host->pull_data(host, buf, cnt);
Will Newtonf95f3852011-01-02 01:11:59 -05001445}
1446
1447static void dw_mci_read_data_pio(struct dw_mci *host)
1448{
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001449 struct sg_mapping_iter *sg_miter = &host->sg_miter;
1450 void *buf;
1451 unsigned int offset;
Will Newtonf95f3852011-01-02 01:11:59 -05001452 struct mmc_data *data = host->data;
1453 int shift = host->data_shift;
1454 u32 status;
Chris Ballba6a9022011-02-28 16:45:10 -05001455 unsigned int nbytes = 0, len;
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001456 unsigned int remain, fcnt;
Will Newtonf95f3852011-01-02 01:11:59 -05001457
1458 do {
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001459 if (!sg_miter_next(sg_miter))
1460 goto done;
Will Newtonf95f3852011-01-02 01:11:59 -05001461
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001462 host->sg = sg_miter->__sg;
1463 buf = sg_miter->addr;
1464 remain = sg_miter->length;
1465 offset = 0;
1466
1467 do {
1468 fcnt = (SDMMC_GET_FCNT(mci_readl(host, STATUS))
1469 << shift) + host->part_buf_count;
1470 len = min(remain, fcnt);
1471 if (!len)
1472 break;
1473 dw_mci_pull_data(host, (void *)(buf + offset), len);
Will Newtonf95f3852011-01-02 01:11:59 -05001474 offset += len;
1475 nbytes += len;
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001476 remain -= len;
1477 } while (remain);
Will Newtonf95f3852011-01-02 01:11:59 -05001478
Seungwon Jeone74f3a92012-08-01 09:30:46 +09001479 sg_miter->consumed = offset;
Will Newtonf95f3852011-01-02 01:11:59 -05001480 status = mci_readl(host, MINTSTS);
1481 mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
Will Newtonf95f3852011-01-02 01:11:59 -05001482 } while (status & SDMMC_INT_RXDR); /*if the RXDR is ready read again*/
Will Newtonf95f3852011-01-02 01:11:59 -05001483 data->bytes_xfered += nbytes;
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001484
1485 if (!remain) {
1486 if (!sg_miter_next(sg_miter))
1487 goto done;
1488 sg_miter->consumed = 0;
1489 }
1490 sg_miter_stop(sg_miter);
Will Newtonf95f3852011-01-02 01:11:59 -05001491 return;
1492
1493done:
1494 data->bytes_xfered += nbytes;
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001495 sg_miter_stop(sg_miter);
1496 host->sg = NULL;
Will Newtonf95f3852011-01-02 01:11:59 -05001497 smp_wmb();
1498 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
1499}
1500
1501static void dw_mci_write_data_pio(struct dw_mci *host)
1502{
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001503 struct sg_mapping_iter *sg_miter = &host->sg_miter;
1504 void *buf;
1505 unsigned int offset;
Will Newtonf95f3852011-01-02 01:11:59 -05001506 struct mmc_data *data = host->data;
1507 int shift = host->data_shift;
1508 u32 status;
1509 unsigned int nbytes = 0, len;
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001510 unsigned int fifo_depth = host->fifo_depth;
1511 unsigned int remain, fcnt;
Will Newtonf95f3852011-01-02 01:11:59 -05001512
1513 do {
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001514 if (!sg_miter_next(sg_miter))
1515 goto done;
Will Newtonf95f3852011-01-02 01:11:59 -05001516
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001517 host->sg = sg_miter->__sg;
1518 buf = sg_miter->addr;
1519 remain = sg_miter->length;
1520 offset = 0;
1521
1522 do {
1523 fcnt = ((fifo_depth -
1524 SDMMC_GET_FCNT(mci_readl(host, STATUS)))
1525 << shift) - host->part_buf_count;
1526 len = min(remain, fcnt);
1527 if (!len)
1528 break;
1529 host->push_data(host, (void *)(buf + offset), len);
Will Newtonf95f3852011-01-02 01:11:59 -05001530 offset += len;
1531 nbytes += len;
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001532 remain -= len;
1533 } while (remain);
Will Newtonf95f3852011-01-02 01:11:59 -05001534
Seungwon Jeone74f3a92012-08-01 09:30:46 +09001535 sg_miter->consumed = offset;
Will Newtonf95f3852011-01-02 01:11:59 -05001536 status = mci_readl(host, MINTSTS);
1537 mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
Will Newtonf95f3852011-01-02 01:11:59 -05001538 } while (status & SDMMC_INT_TXDR); /* if TXDR write again */
Will Newtonf95f3852011-01-02 01:11:59 -05001539 data->bytes_xfered += nbytes;
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001540
1541 if (!remain) {
1542 if (!sg_miter_next(sg_miter))
1543 goto done;
1544 sg_miter->consumed = 0;
1545 }
1546 sg_miter_stop(sg_miter);
Will Newtonf95f3852011-01-02 01:11:59 -05001547 return;
1548
1549done:
1550 data->bytes_xfered += nbytes;
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001551 sg_miter_stop(sg_miter);
1552 host->sg = NULL;
Will Newtonf95f3852011-01-02 01:11:59 -05001553 smp_wmb();
1554 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
1555}
1556
1557static void dw_mci_cmd_interrupt(struct dw_mci *host, u32 status)
1558{
1559 if (!host->cmd_status)
1560 host->cmd_status = status;
1561
1562 smp_wmb();
1563
1564 set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
1565 tasklet_schedule(&host->tasklet);
1566}
1567
1568static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
1569{
1570 struct dw_mci *host = dev_id;
Seungwon Jeon182c9082012-08-01 09:30:30 +09001571 u32 pending;
Will Newtonf95f3852011-01-02 01:11:59 -05001572 unsigned int pass_count = 0;
Shashidhar Hiremath1a5c8e12011-08-29 13:11:46 +05301573 int i;
Will Newtonf95f3852011-01-02 01:11:59 -05001574
1575 do {
Will Newtonf95f3852011-01-02 01:11:59 -05001576 pending = mci_readl(host, MINTSTS); /* read-only mask reg */
1577
1578 /*
1579 * DTO fix - version 2.10a and below, and only if internal DMA
1580 * is configured.
1581 */
1582 if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) {
1583 if (!pending &&
1584 ((mci_readl(host, STATUS) >> 17) & 0x1fff))
1585 pending |= SDMMC_INT_DATA_OVER;
1586 }
1587
1588 if (!pending)
1589 break;
1590
1591 if (pending & DW_MCI_CMD_ERROR_FLAGS) {
1592 mci_writel(host, RINTSTS, DW_MCI_CMD_ERROR_FLAGS);
Seungwon Jeon182c9082012-08-01 09:30:30 +09001593 host->cmd_status = pending;
Will Newtonf95f3852011-01-02 01:11:59 -05001594 smp_wmb();
1595 set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
Will Newtonf95f3852011-01-02 01:11:59 -05001596 }
1597
1598 if (pending & DW_MCI_DATA_ERROR_FLAGS) {
1599 /* if there is an error report DATA_ERROR */
1600 mci_writel(host, RINTSTS, DW_MCI_DATA_ERROR_FLAGS);
Seungwon Jeon182c9082012-08-01 09:30:30 +09001601 host->data_status = pending;
Will Newtonf95f3852011-01-02 01:11:59 -05001602 smp_wmb();
1603 set_bit(EVENT_DATA_ERROR, &host->pending_events);
Seungwon Jeon9b2026a2012-08-01 09:30:40 +09001604 tasklet_schedule(&host->tasklet);
Will Newtonf95f3852011-01-02 01:11:59 -05001605 }
1606
1607 if (pending & SDMMC_INT_DATA_OVER) {
1608 mci_writel(host, RINTSTS, SDMMC_INT_DATA_OVER);
1609 if (!host->data_status)
Seungwon Jeon182c9082012-08-01 09:30:30 +09001610 host->data_status = pending;
Will Newtonf95f3852011-01-02 01:11:59 -05001611 smp_wmb();
1612 if (host->dir_status == DW_MCI_RECV_STATUS) {
1613 if (host->sg != NULL)
1614 dw_mci_read_data_pio(host);
1615 }
1616 set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
1617 tasklet_schedule(&host->tasklet);
1618 }
1619
1620 if (pending & SDMMC_INT_RXDR) {
1621 mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
James Hoganb40af3a2011-06-24 13:54:06 +01001622 if (host->dir_status == DW_MCI_RECV_STATUS && host->sg)
Will Newtonf95f3852011-01-02 01:11:59 -05001623 dw_mci_read_data_pio(host);
1624 }
1625
1626 if (pending & SDMMC_INT_TXDR) {
1627 mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
James Hoganb40af3a2011-06-24 13:54:06 +01001628 if (host->dir_status == DW_MCI_SEND_STATUS && host->sg)
Will Newtonf95f3852011-01-02 01:11:59 -05001629 dw_mci_write_data_pio(host);
1630 }
1631
1632 if (pending & SDMMC_INT_CMD_DONE) {
1633 mci_writel(host, RINTSTS, SDMMC_INT_CMD_DONE);
Seungwon Jeon182c9082012-08-01 09:30:30 +09001634 dw_mci_cmd_interrupt(host, pending);
Will Newtonf95f3852011-01-02 01:11:59 -05001635 }
1636
1637 if (pending & SDMMC_INT_CD) {
1638 mci_writel(host, RINTSTS, SDMMC_INT_CD);
Thomas Abraham95dcc2c2012-05-01 14:57:36 -07001639 queue_work(host->card_workqueue, &host->card_work);
Will Newtonf95f3852011-01-02 01:11:59 -05001640 }
1641
Shashidhar Hiremath1a5c8e12011-08-29 13:11:46 +05301642 /* Handle SDIO Interrupts */
1643 for (i = 0; i < host->num_slots; i++) {
1644 struct dw_mci_slot *slot = host->slot[i];
1645 if (pending & SDMMC_INT_SDIO(i)) {
1646 mci_writel(host, RINTSTS, SDMMC_INT_SDIO(i));
1647 mmc_signal_sdio_irq(slot->mmc);
1648 }
1649 }
1650
Will Newtonf95f3852011-01-02 01:11:59 -05001651 } while (pass_count++ < 5);
1652
1653#ifdef CONFIG_MMC_DW_IDMAC
1654 /* Handle DMA interrupts */
1655 pending = mci_readl(host, IDSTS);
1656 if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
1657 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI);
1658 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI);
Will Newtonf95f3852011-01-02 01:11:59 -05001659 host->dma_ops->complete(host);
1660 }
1661#endif
1662
1663 return IRQ_HANDLED;
1664}
1665
James Hogan1791b13e2011-06-24 13:55:55 +01001666static void dw_mci_work_routine_card(struct work_struct *work)
Will Newtonf95f3852011-01-02 01:11:59 -05001667{
James Hogan1791b13e2011-06-24 13:55:55 +01001668 struct dw_mci *host = container_of(work, struct dw_mci, card_work);
Will Newtonf95f3852011-01-02 01:11:59 -05001669 int i;
1670
1671 for (i = 0; i < host->num_slots; i++) {
1672 struct dw_mci_slot *slot = host->slot[i];
1673 struct mmc_host *mmc = slot->mmc;
1674 struct mmc_request *mrq;
1675 int present;
1676 u32 ctrl;
1677
1678 present = dw_mci_get_cd(mmc);
1679 while (present != slot->last_detect_state) {
Will Newtonf95f3852011-01-02 01:11:59 -05001680 dev_dbg(&slot->mmc->class_dev, "card %s\n",
1681 present ? "inserted" : "removed");
1682
James Hogan1791b13e2011-06-24 13:55:55 +01001683 /* Power up slot (before spin_lock, may sleep) */
1684 if (present != 0 && host->pdata->setpower)
1685 host->pdata->setpower(slot->id, mmc->ocr_avail);
1686
1687 spin_lock_bh(&host->lock);
1688
Will Newtonf95f3852011-01-02 01:11:59 -05001689 /* Card change detected */
1690 slot->last_detect_state = present;
1691
James Hogan1791b13e2011-06-24 13:55:55 +01001692 /* Mark card as present if applicable */
1693 if (present != 0)
Will Newtonf95f3852011-01-02 01:11:59 -05001694 set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
Will Newtonf95f3852011-01-02 01:11:59 -05001695
1696 /* Clean up queue if present */
1697 mrq = slot->mrq;
1698 if (mrq) {
1699 if (mrq == host->mrq) {
1700 host->data = NULL;
1701 host->cmd = NULL;
1702
1703 switch (host->state) {
1704 case STATE_IDLE:
1705 break;
1706 case STATE_SENDING_CMD:
1707 mrq->cmd->error = -ENOMEDIUM;
1708 if (!mrq->data)
1709 break;
1710 /* fall through */
1711 case STATE_SENDING_DATA:
1712 mrq->data->error = -ENOMEDIUM;
1713 dw_mci_stop_dma(host);
1714 break;
1715 case STATE_DATA_BUSY:
1716 case STATE_DATA_ERROR:
1717 if (mrq->data->error == -EINPROGRESS)
1718 mrq->data->error = -ENOMEDIUM;
1719 if (!mrq->stop)
1720 break;
1721 /* fall through */
1722 case STATE_SENDING_STOP:
1723 mrq->stop->error = -ENOMEDIUM;
1724 break;
1725 }
1726
1727 dw_mci_request_end(host, mrq);
1728 } else {
1729 list_del(&slot->queue_node);
1730 mrq->cmd->error = -ENOMEDIUM;
1731 if (mrq->data)
1732 mrq->data->error = -ENOMEDIUM;
1733 if (mrq->stop)
1734 mrq->stop->error = -ENOMEDIUM;
1735
1736 spin_unlock(&host->lock);
1737 mmc_request_done(slot->mmc, mrq);
1738 spin_lock(&host->lock);
1739 }
1740 }
1741
1742 /* Power down slot */
1743 if (present == 0) {
Will Newtonf95f3852011-01-02 01:11:59 -05001744 clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
1745
1746 /*
1747 * Clear down the FIFO - doing so generates a
1748 * block interrupt, hence setting the
1749 * scatter-gather pointer to NULL.
1750 */
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +09001751 sg_miter_stop(&host->sg_miter);
Will Newtonf95f3852011-01-02 01:11:59 -05001752 host->sg = NULL;
1753
1754 ctrl = mci_readl(host, CTRL);
1755 ctrl |= SDMMC_CTRL_FIFO_RESET;
1756 mci_writel(host, CTRL, ctrl);
1757
1758#ifdef CONFIG_MMC_DW_IDMAC
1759 ctrl = mci_readl(host, BMOD);
Seungwon Jeon141a7122012-05-22 13:01:03 +09001760 /* Software reset of DMA */
1761 ctrl |= SDMMC_IDMAC_SWRESET;
Will Newtonf95f3852011-01-02 01:11:59 -05001762 mci_writel(host, BMOD, ctrl);
1763#endif
1764
1765 }
1766
James Hogan1791b13e2011-06-24 13:55:55 +01001767 spin_unlock_bh(&host->lock);
1768
1769 /* Power down slot (after spin_unlock, may sleep) */
1770 if (present == 0 && host->pdata->setpower)
1771 host->pdata->setpower(slot->id, 0);
1772
Will Newtonf95f3852011-01-02 01:11:59 -05001773 present = dw_mci_get_cd(mmc);
1774 }
1775
1776 mmc_detect_change(slot->mmc,
1777 msecs_to_jiffies(host->pdata->detect_delay_ms));
1778 }
1779}
1780
Thomas Abrahamc91eab42012-09-17 18:16:40 +00001781#ifdef CONFIG_OF
1782/* given a slot id, find out the device node representing that slot */
1783static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot)
1784{
1785 struct device_node *np;
1786 const __be32 *addr;
1787 int len;
1788
1789 if (!dev || !dev->of_node)
1790 return NULL;
1791
1792 for_each_child_of_node(dev->of_node, np) {
1793 addr = of_get_property(np, "reg", &len);
1794 if (!addr || (len < sizeof(int)))
1795 continue;
1796 if (be32_to_cpup(addr) == slot)
1797 return np;
1798 }
1799 return NULL;
1800}
1801
Doug Andersona70aaa62013-01-11 17:03:50 +00001802static struct dw_mci_of_slot_quirks {
1803 char *quirk;
1804 int id;
1805} of_slot_quirks[] = {
1806 {
1807 .quirk = "disable-wp",
1808 .id = DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT,
1809 },
1810};
1811
1812static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot)
1813{
1814 struct device_node *np = dw_mci_of_find_slot_node(dev, slot);
1815 int quirks = 0;
1816 int idx;
1817
1818 /* get quirks */
1819 for (idx = 0; idx < ARRAY_SIZE(of_slot_quirks); idx++)
1820 if (of_get_property(np, of_slot_quirks[idx].quirk, NULL))
1821 quirks |= of_slot_quirks[idx].id;
1822
1823 return quirks;
1824}
1825
Thomas Abrahamc91eab42012-09-17 18:16:40 +00001826/* find out bus-width for a given slot */
1827static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot)
1828{
1829 struct device_node *np = dw_mci_of_find_slot_node(dev, slot);
1830 u32 bus_wd = 1;
1831
1832 if (!np)
1833 return 1;
1834
1835 if (of_property_read_u32(np, "bus-width", &bus_wd))
1836 dev_err(dev, "bus-width property not found, assuming width"
1837 " as 1\n");
1838 return bus_wd;
1839}
Doug Anderson55a6ceb2013-01-11 17:03:53 +00001840
1841/* find the write protect gpio for a given slot; or -1 if none specified */
1842static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot)
1843{
1844 struct device_node *np = dw_mci_of_find_slot_node(dev, slot);
1845 int gpio;
1846
1847 if (!np)
1848 return -EINVAL;
1849
1850 gpio = of_get_named_gpio(np, "wp-gpios", 0);
1851
1852 /* Having a missing entry is valid; return silently */
1853 if (!gpio_is_valid(gpio))
1854 return -EINVAL;
1855
1856 if (devm_gpio_request(dev, gpio, "dw-mci-wp")) {
1857 dev_warn(dev, "gpio [%d] request failed\n", gpio);
1858 return -EINVAL;
1859 }
1860
1861 return gpio;
1862}
Thomas Abrahamc91eab42012-09-17 18:16:40 +00001863#else /* CONFIG_OF */
Doug Andersona70aaa62013-01-11 17:03:50 +00001864static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot)
1865{
1866 return 0;
1867}
Thomas Abrahamc91eab42012-09-17 18:16:40 +00001868static u32 dw_mci_of_get_bus_wd(struct device *dev, u8 slot)
1869{
1870 return 1;
1871}
1872static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot)
1873{
1874 return NULL;
1875}
Doug Anderson55a6ceb2013-01-11 17:03:53 +00001876static int dw_mci_of_get_wp_gpio(struct device *dev, u8 slot)
1877{
1878 return -EINVAL;
1879}
Thomas Abrahamc91eab42012-09-17 18:16:40 +00001880#endif /* CONFIG_OF */
1881
Jaehoon Chung36c179a2012-08-23 20:31:48 +09001882static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
Will Newtonf95f3852011-01-02 01:11:59 -05001883{
1884 struct mmc_host *mmc;
1885 struct dw_mci_slot *slot;
Arnd Bergmanne95baf12012-11-08 14:26:11 +00001886 const struct dw_mci_drv_data *drv_data = host->drv_data;
Thomas Abraham800d78b2012-09-17 18:16:42 +00001887 int ctrl_id, ret;
Thomas Abrahamc91eab42012-09-17 18:16:40 +00001888 u8 bus_width;
Will Newtonf95f3852011-01-02 01:11:59 -05001889
Thomas Abraham4a909202012-09-17 18:16:35 +00001890 mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev);
Will Newtonf95f3852011-01-02 01:11:59 -05001891 if (!mmc)
1892 return -ENOMEM;
1893
1894 slot = mmc_priv(mmc);
1895 slot->id = id;
1896 slot->mmc = mmc;
1897 slot->host = host;
Thomas Abrahamc91eab42012-09-17 18:16:40 +00001898 host->slot[id] = slot;
Will Newtonf95f3852011-01-02 01:11:59 -05001899
Doug Andersona70aaa62013-01-11 17:03:50 +00001900 slot->quirks = dw_mci_of_get_slot_quirks(host->dev, slot->id);
1901
Will Newtonf95f3852011-01-02 01:11:59 -05001902 mmc->ops = &dw_mci_ops;
1903 mmc->f_min = DIV_ROUND_UP(host->bus_hz, 510);
1904 mmc->f_max = host->bus_hz;
1905
1906 if (host->pdata->get_ocr)
1907 mmc->ocr_avail = host->pdata->get_ocr(id);
1908 else
1909 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
1910
1911 /*
1912 * Start with slot power disabled, it will be enabled when a card
1913 * is detected.
1914 */
1915 if (host->pdata->setpower)
1916 host->pdata->setpower(id, 0);
1917
Jaehoon Chungfc3d7722011-02-25 11:08:15 +09001918 if (host->pdata->caps)
1919 mmc->caps = host->pdata->caps;
Jaehoon Chungfc3d7722011-02-25 11:08:15 +09001920
Abhilash Kesavanab269122012-11-19 10:26:21 +05301921 if (host->pdata->pm_caps)
1922 mmc->pm_caps = host->pdata->pm_caps;
1923
Thomas Abraham800d78b2012-09-17 18:16:42 +00001924 if (host->dev->of_node) {
1925 ctrl_id = of_alias_get_id(host->dev->of_node, "mshc");
1926 if (ctrl_id < 0)
1927 ctrl_id = 0;
1928 } else {
1929 ctrl_id = to_platform_device(host->dev)->id;
1930 }
James Hogancb27a842012-10-16 09:43:08 +01001931 if (drv_data && drv_data->caps)
1932 mmc->caps |= drv_data->caps[ctrl_id];
Thomas Abraham800d78b2012-09-17 18:16:42 +00001933
Seungwon Jeon4f408cc2011-12-09 14:55:52 +09001934 if (host->pdata->caps2)
1935 mmc->caps2 = host->pdata->caps2;
Seungwon Jeon4f408cc2011-12-09 14:55:52 +09001936
Will Newtonf95f3852011-01-02 01:11:59 -05001937 if (host->pdata->get_bus_wd)
Thomas Abrahamc91eab42012-09-17 18:16:40 +00001938 bus_width = host->pdata->get_bus_wd(slot->id);
1939 else if (host->dev->of_node)
1940 bus_width = dw_mci_of_get_bus_wd(host->dev, slot->id);
1941 else
1942 bus_width = 1;
1943
James Hogancb27a842012-10-16 09:43:08 +01001944 if (drv_data && drv_data->setup_bus) {
Thomas Abraham800d78b2012-09-17 18:16:42 +00001945 struct device_node *slot_np;
1946 slot_np = dw_mci_of_find_slot_node(host->dev, slot->id);
James Hogancb27a842012-10-16 09:43:08 +01001947 ret = drv_data->setup_bus(host, slot_np, bus_width);
Thomas Abraham800d78b2012-09-17 18:16:42 +00001948 if (ret)
1949 goto err_setup_bus;
1950 }
1951
Thomas Abrahamc91eab42012-09-17 18:16:40 +00001952 switch (bus_width) {
1953 case 8:
1954 mmc->caps |= MMC_CAP_8_BIT_DATA;
1955 case 4:
1956 mmc->caps |= MMC_CAP_4_BIT_DATA;
1957 }
Will Newtonf95f3852011-01-02 01:11:59 -05001958
1959 if (host->pdata->quirks & DW_MCI_QUIRK_HIGHSPEED)
Seungwon Jeon6daa7772011-08-05 12:35:03 +09001960 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
Will Newtonf95f3852011-01-02 01:11:59 -05001961
Will Newtonf95f3852011-01-02 01:11:59 -05001962 if (host->pdata->blk_settings) {
1963 mmc->max_segs = host->pdata->blk_settings->max_segs;
1964 mmc->max_blk_size = host->pdata->blk_settings->max_blk_size;
1965 mmc->max_blk_count = host->pdata->blk_settings->max_blk_count;
1966 mmc->max_req_size = host->pdata->blk_settings->max_req_size;
1967 mmc->max_seg_size = host->pdata->blk_settings->max_seg_size;
1968 } else {
1969 /* Useful defaults if platform data is unset. */
Jaehoon Chunga39e5742012-02-04 17:00:27 -05001970#ifdef CONFIG_MMC_DW_IDMAC
1971 mmc->max_segs = host->ring_size;
1972 mmc->max_blk_size = 65536;
1973 mmc->max_blk_count = host->ring_size;
1974 mmc->max_seg_size = 0x1000;
1975 mmc->max_req_size = mmc->max_seg_size * mmc->max_blk_count;
1976#else
Will Newtonf95f3852011-01-02 01:11:59 -05001977 mmc->max_segs = 64;
1978 mmc->max_blk_size = 65536; /* BLKSIZ is 16 bits */
1979 mmc->max_blk_count = 512;
1980 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
1981 mmc->max_seg_size = mmc->max_req_size;
Will Newtonf95f3852011-01-02 01:11:59 -05001982#endif /* CONFIG_MMC_DW_IDMAC */
Jaehoon Chunga39e5742012-02-04 17:00:27 -05001983 }
Will Newtonf95f3852011-01-02 01:11:59 -05001984
Seungwon Jeon780f22a2012-11-28 19:26:03 +09001985 host->vmmc = devm_regulator_get(mmc_dev(mmc), "vmmc");
Jaehoon Chungc07946a2011-02-25 11:08:14 +09001986 if (IS_ERR(host->vmmc)) {
Girish K Sa3c76eb2011-10-11 11:44:09 +05301987 pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
Jaehoon Chungc07946a2011-02-25 11:08:14 +09001988 host->vmmc = NULL;
1989 } else
1990 regulator_enable(host->vmmc);
1991
Will Newtonf95f3852011-01-02 01:11:59 -05001992 if (dw_mci_get_cd(mmc))
1993 set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
1994 else
1995 clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
1996
Doug Anderson55a6ceb2013-01-11 17:03:53 +00001997 slot->wp_gpio = dw_mci_of_get_wp_gpio(host->dev, slot->id);
1998
Will Newtonf95f3852011-01-02 01:11:59 -05001999 mmc_add_host(mmc);
2000
2001#if defined(CONFIG_DEBUG_FS)
2002 dw_mci_init_debugfs(slot);
2003#endif
2004
2005 /* Card initially undetected */
2006 slot->last_detect_state = 0;
2007
Will Newtondd6c4b92011-02-10 14:37:03 -05002008 /*
2009 * Card may have been plugged in prior to boot so we
2010 * need to run the detect tasklet
2011 */
Thomas Abraham95dcc2c2012-05-01 14:57:36 -07002012 queue_work(host->card_workqueue, &host->card_work);
Will Newtondd6c4b92011-02-10 14:37:03 -05002013
Will Newtonf95f3852011-01-02 01:11:59 -05002014 return 0;
Thomas Abraham800d78b2012-09-17 18:16:42 +00002015
2016err_setup_bus:
2017 mmc_free_host(mmc);
2018 return -EINVAL;
Will Newtonf95f3852011-01-02 01:11:59 -05002019}
2020
2021static void dw_mci_cleanup_slot(struct dw_mci_slot *slot, unsigned int id)
2022{
2023 /* Shutdown detect IRQ */
2024 if (slot->host->pdata->exit)
2025 slot->host->pdata->exit(id);
2026
2027 /* Debugfs stuff is cleaned up by mmc core */
2028 mmc_remove_host(slot->mmc);
2029 slot->host->slot[id] = NULL;
2030 mmc_free_host(slot->mmc);
2031}
2032
2033static void dw_mci_init_dma(struct dw_mci *host)
2034{
2035 /* Alloc memory for sg translation */
Seungwon Jeon780f22a2012-11-28 19:26:03 +09002036 host->sg_cpu = dmam_alloc_coherent(host->dev, PAGE_SIZE,
Will Newtonf95f3852011-01-02 01:11:59 -05002037 &host->sg_dma, GFP_KERNEL);
2038 if (!host->sg_cpu) {
Thomas Abraham4a909202012-09-17 18:16:35 +00002039 dev_err(host->dev, "%s: could not alloc DMA memory\n",
Will Newtonf95f3852011-01-02 01:11:59 -05002040 __func__);
2041 goto no_dma;
2042 }
2043
2044 /* Determine which DMA interface to use */
2045#ifdef CONFIG_MMC_DW_IDMAC
2046 host->dma_ops = &dw_mci_idmac_ops;
Seungwon Jeon00956ea2012-09-28 19:13:11 +09002047 dev_info(host->dev, "Using internal DMA controller.\n");
Will Newtonf95f3852011-01-02 01:11:59 -05002048#endif
2049
2050 if (!host->dma_ops)
2051 goto no_dma;
2052
Jaehoon Chunge1631f92012-04-18 15:42:31 +09002053 if (host->dma_ops->init && host->dma_ops->start &&
2054 host->dma_ops->stop && host->dma_ops->cleanup) {
Will Newtonf95f3852011-01-02 01:11:59 -05002055 if (host->dma_ops->init(host)) {
Thomas Abraham4a909202012-09-17 18:16:35 +00002056 dev_err(host->dev, "%s: Unable to initialize "
Will Newtonf95f3852011-01-02 01:11:59 -05002057 "DMA Controller.\n", __func__);
2058 goto no_dma;
2059 }
2060 } else {
Thomas Abraham4a909202012-09-17 18:16:35 +00002061 dev_err(host->dev, "DMA initialization not found.\n");
Will Newtonf95f3852011-01-02 01:11:59 -05002062 goto no_dma;
2063 }
2064
2065 host->use_dma = 1;
2066 return;
2067
2068no_dma:
Thomas Abraham4a909202012-09-17 18:16:35 +00002069 dev_info(host->dev, "Using PIO mode.\n");
Will Newtonf95f3852011-01-02 01:11:59 -05002070 host->use_dma = 0;
2071 return;
2072}
2073
2074static bool mci_wait_reset(struct device *dev, struct dw_mci *host)
2075{
2076 unsigned long timeout = jiffies + msecs_to_jiffies(500);
2077 unsigned int ctrl;
2078
2079 mci_writel(host, CTRL, (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET |
2080 SDMMC_CTRL_DMA_RESET));
2081
2082 /* wait till resets clear */
2083 do {
2084 ctrl = mci_readl(host, CTRL);
2085 if (!(ctrl & (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET |
2086 SDMMC_CTRL_DMA_RESET)))
2087 return true;
2088 } while (time_before(jiffies, timeout));
2089
2090 dev_err(dev, "Timeout resetting block (ctrl %#x)\n", ctrl);
2091
2092 return false;
2093}
2094
Thomas Abrahamc91eab42012-09-17 18:16:40 +00002095#ifdef CONFIG_OF
2096static struct dw_mci_of_quirks {
2097 char *quirk;
2098 int id;
2099} of_quirks[] = {
2100 {
2101 .quirk = "supports-highspeed",
2102 .id = DW_MCI_QUIRK_HIGHSPEED,
2103 }, {
2104 .quirk = "broken-cd",
2105 .id = DW_MCI_QUIRK_BROKEN_CARD_DETECTION,
2106 },
2107};
2108
2109static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
2110{
2111 struct dw_mci_board *pdata;
2112 struct device *dev = host->dev;
2113 struct device_node *np = dev->of_node;
Arnd Bergmanne95baf12012-11-08 14:26:11 +00002114 const struct dw_mci_drv_data *drv_data = host->drv_data;
Thomas Abraham800d78b2012-09-17 18:16:42 +00002115 int idx, ret;
Thomas Abrahamc91eab42012-09-17 18:16:40 +00002116
2117 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
2118 if (!pdata) {
2119 dev_err(dev, "could not allocate memory for pdata\n");
2120 return ERR_PTR(-ENOMEM);
2121 }
2122
2123 /* find out number of slots supported */
2124 if (of_property_read_u32(dev->of_node, "num-slots",
2125 &pdata->num_slots)) {
2126 dev_info(dev, "num-slots property not found, "
2127 "assuming 1 slot is available\n");
2128 pdata->num_slots = 1;
2129 }
2130
2131 /* get quirks */
2132 for (idx = 0; idx < ARRAY_SIZE(of_quirks); idx++)
2133 if (of_get_property(np, of_quirks[idx].quirk, NULL))
2134 pdata->quirks |= of_quirks[idx].id;
2135
2136 if (of_property_read_u32(np, "fifo-depth", &pdata->fifo_depth))
2137 dev_info(dev, "fifo-depth property not found, using "
2138 "value of FIFOTH register as default\n");
2139
2140 of_property_read_u32(np, "card-detect-delay", &pdata->detect_delay_ms);
2141
James Hogancb27a842012-10-16 09:43:08 +01002142 if (drv_data && drv_data->parse_dt) {
2143 ret = drv_data->parse_dt(host);
Thomas Abraham800d78b2012-09-17 18:16:42 +00002144 if (ret)
2145 return ERR_PTR(ret);
2146 }
2147
Abhilash Kesavanab269122012-11-19 10:26:21 +05302148 if (of_find_property(np, "keep-power-in-suspend", NULL))
2149 pdata->pm_caps |= MMC_PM_KEEP_POWER;
2150
2151 if (of_find_property(np, "enable-sdio-wakeup", NULL))
2152 pdata->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
2153
Thomas Abrahamc91eab42012-09-17 18:16:40 +00002154 return pdata;
2155}
2156
2157#else /* CONFIG_OF */
2158static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
2159{
2160 return ERR_PTR(-EINVAL);
2161}
2162#endif /* CONFIG_OF */
2163
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302164int dw_mci_probe(struct dw_mci *host)
Will Newtonf95f3852011-01-02 01:11:59 -05002165{
Arnd Bergmanne95baf12012-11-08 14:26:11 +00002166 const struct dw_mci_drv_data *drv_data = host->drv_data;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302167 int width, i, ret = 0;
Will Newtonf95f3852011-01-02 01:11:59 -05002168 u32 fifo_size;
Thomas Abraham1c2215b2012-09-17 18:16:37 +00002169 int init_slots = 0;
Will Newtonf95f3852011-01-02 01:11:59 -05002170
Thomas Abrahamc91eab42012-09-17 18:16:40 +00002171 if (!host->pdata) {
2172 host->pdata = dw_mci_parse_dt(host);
2173 if (IS_ERR(host->pdata)) {
2174 dev_err(host->dev, "platform data not available\n");
2175 return -EINVAL;
2176 }
Will Newtonf95f3852011-01-02 01:11:59 -05002177 }
2178
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302179 if (!host->pdata->select_slot && host->pdata->num_slots > 1) {
Thomas Abraham4a909202012-09-17 18:16:35 +00002180 dev_err(host->dev,
Will Newtonf95f3852011-01-02 01:11:59 -05002181 "Platform data must supply select_slot function\n");
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302182 return -ENODEV;
Will Newtonf95f3852011-01-02 01:11:59 -05002183 }
2184
Seungwon Jeon780f22a2012-11-28 19:26:03 +09002185 host->biu_clk = devm_clk_get(host->dev, "biu");
Thomas Abrahamf90a0612012-09-17 18:16:38 +00002186 if (IS_ERR(host->biu_clk)) {
2187 dev_dbg(host->dev, "biu clock not available\n");
2188 } else {
2189 ret = clk_prepare_enable(host->biu_clk);
2190 if (ret) {
2191 dev_err(host->dev, "failed to enable biu clock\n");
Thomas Abrahamf90a0612012-09-17 18:16:38 +00002192 return ret;
2193 }
Will Newtonf95f3852011-01-02 01:11:59 -05002194 }
2195
Seungwon Jeon780f22a2012-11-28 19:26:03 +09002196 host->ciu_clk = devm_clk_get(host->dev, "ciu");
Thomas Abrahamf90a0612012-09-17 18:16:38 +00002197 if (IS_ERR(host->ciu_clk)) {
2198 dev_dbg(host->dev, "ciu clock not available\n");
2199 } else {
2200 ret = clk_prepare_enable(host->ciu_clk);
2201 if (ret) {
2202 dev_err(host->dev, "failed to enable ciu clock\n");
Thomas Abrahamf90a0612012-09-17 18:16:38 +00002203 goto err_clk_biu;
2204 }
2205 }
2206
2207 if (IS_ERR(host->ciu_clk))
2208 host->bus_hz = host->pdata->bus_hz;
2209 else
2210 host->bus_hz = clk_get_rate(host->ciu_clk);
2211
James Hogancb27a842012-10-16 09:43:08 +01002212 if (drv_data && drv_data->setup_clock) {
2213 ret = drv_data->setup_clock(host);
Thomas Abraham800d78b2012-09-17 18:16:42 +00002214 if (ret) {
2215 dev_err(host->dev,
2216 "implementation specific clock setup failed\n");
2217 goto err_clk_ciu;
2218 }
2219 }
2220
Thomas Abrahamf90a0612012-09-17 18:16:38 +00002221 if (!host->bus_hz) {
2222 dev_err(host->dev,
2223 "Platform data must supply bus speed\n");
2224 ret = -ENODEV;
2225 goto err_clk_ciu;
2226 }
2227
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302228 host->quirks = host->pdata->quirks;
Will Newtonf95f3852011-01-02 01:11:59 -05002229
2230 spin_lock_init(&host->lock);
2231 INIT_LIST_HEAD(&host->queue);
2232
Will Newtonf95f3852011-01-02 01:11:59 -05002233 /*
2234 * Get the host data width - this assumes that HCON has been set with
2235 * the correct values.
2236 */
2237 i = (mci_readl(host, HCON) >> 7) & 0x7;
2238 if (!i) {
2239 host->push_data = dw_mci_push_data16;
2240 host->pull_data = dw_mci_pull_data16;
2241 width = 16;
2242 host->data_shift = 1;
2243 } else if (i == 2) {
2244 host->push_data = dw_mci_push_data64;
2245 host->pull_data = dw_mci_pull_data64;
2246 width = 64;
2247 host->data_shift = 3;
2248 } else {
2249 /* Check for a reserved value, and warn if it is */
2250 WARN((i != 1),
2251 "HCON reports a reserved host data width!\n"
2252 "Defaulting to 32-bit access.\n");
2253 host->push_data = dw_mci_push_data32;
2254 host->pull_data = dw_mci_pull_data32;
2255 width = 32;
2256 host->data_shift = 2;
2257 }
2258
2259 /* Reset all blocks */
Thomas Abraham4a909202012-09-17 18:16:35 +00002260 if (!mci_wait_reset(host->dev, host))
Seungwon Jeon141a7122012-05-22 13:01:03 +09002261 return -ENODEV;
2262
2263 host->dma_ops = host->pdata->dma_ops;
2264 dw_mci_init_dma(host);
Will Newtonf95f3852011-01-02 01:11:59 -05002265
2266 /* Clear the interrupts for the host controller */
2267 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2268 mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
2269
2270 /* Put in max timeout */
2271 mci_writel(host, TMOUT, 0xFFFFFFFF);
2272
2273 /*
2274 * FIFO threshold settings RxMark = fifo_size / 2 - 1,
2275 * Tx Mark = fifo_size / 2 DMA Size = 8
2276 */
James Hoganb86d8252011-06-24 13:57:18 +01002277 if (!host->pdata->fifo_depth) {
2278 /*
2279 * Power-on value of RX_WMark is FIFO_DEPTH-1, but this may
2280 * have been overwritten by the bootloader, just like we're
2281 * about to do, so if you know the value for your hardware, you
2282 * should put it in the platform data.
2283 */
2284 fifo_size = mci_readl(host, FIFOTH);
Jaehoon Chung8234e862012-01-11 09:28:21 +00002285 fifo_size = 1 + ((fifo_size >> 16) & 0xfff);
James Hoganb86d8252011-06-24 13:57:18 +01002286 } else {
2287 fifo_size = host->pdata->fifo_depth;
2288 }
2289 host->fifo_depth = fifo_size;
Jaehoon Chunge61cf112011-03-17 20:32:33 +09002290 host->fifoth_val = ((0x2 << 28) | ((fifo_size/2 - 1) << 16) |
2291 ((fifo_size/2) << 0));
2292 mci_writel(host, FIFOTH, host->fifoth_val);
Will Newtonf95f3852011-01-02 01:11:59 -05002293
2294 /* disable clock to CIU */
2295 mci_writel(host, CLKENA, 0);
2296 mci_writel(host, CLKSRC, 0);
2297
2298 tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host);
Thomas Abraham95dcc2c2012-05-01 14:57:36 -07002299 host->card_workqueue = alloc_workqueue("dw-mci-card",
James Hogan1791b13e2011-06-24 13:55:55 +01002300 WQ_MEM_RECLAIM | WQ_NON_REENTRANT, 1);
Thomas Abraham95dcc2c2012-05-01 14:57:36 -07002301 if (!host->card_workqueue)
James Hogan1791b13e2011-06-24 13:55:55 +01002302 goto err_dmaunmap;
2303 INIT_WORK(&host->card_work, dw_mci_work_routine_card);
Seungwon Jeon780f22a2012-11-28 19:26:03 +09002304 ret = devm_request_irq(host->dev, host->irq, dw_mci_interrupt,
2305 host->irq_flags, "dw-mci", host);
Will Newtonf95f3852011-01-02 01:11:59 -05002306 if (ret)
James Hogan1791b13e2011-06-24 13:55:55 +01002307 goto err_workqueue;
Will Newtonf95f3852011-01-02 01:11:59 -05002308
Will Newtonf95f3852011-01-02 01:11:59 -05002309 if (host->pdata->num_slots)
2310 host->num_slots = host->pdata->num_slots;
2311 else
2312 host->num_slots = ((mci_readl(host, HCON) >> 1) & 0x1F) + 1;
2313
Yuvaraj CD2da1d7f2012-10-08 14:29:51 +05302314 /*
2315 * Enable interrupts for command done, data over, data empty, card det,
2316 * receive ready and error such as transmit, receive timeout, crc error
2317 */
2318 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2319 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
2320 SDMMC_INT_TXDR | SDMMC_INT_RXDR |
2321 DW_MCI_ERROR_FLAGS | SDMMC_INT_CD);
2322 mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); /* Enable mci interrupt */
2323
2324 dev_info(host->dev, "DW MMC controller at irq %d, "
2325 "%d bit host data width, "
2326 "%u deep fifo\n",
2327 host->irq, width, fifo_size);
2328
Will Newtonf95f3852011-01-02 01:11:59 -05002329 /* We need at least one slot to succeed */
2330 for (i = 0; i < host->num_slots; i++) {
2331 ret = dw_mci_init_slot(host, i);
Thomas Abraham1c2215b2012-09-17 18:16:37 +00002332 if (ret)
2333 dev_dbg(host->dev, "slot %d init failed\n", i);
2334 else
2335 init_slots++;
2336 }
2337
2338 if (init_slots) {
2339 dev_info(host->dev, "%d slots initialized\n", init_slots);
2340 } else {
2341 dev_dbg(host->dev, "attempted to initialize %d slots, "
2342 "but failed on all\n", host->num_slots);
Seungwon Jeon780f22a2012-11-28 19:26:03 +09002343 goto err_workqueue;
Will Newtonf95f3852011-01-02 01:11:59 -05002344 }
2345
2346 /*
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09002347 * In 2.40a spec, Data offset is changed.
2348 * Need to check the version-id and set data-offset for DATA register.
2349 */
2350 host->verid = SDMMC_GET_VERID(mci_readl(host, VERID));
Thomas Abraham4a909202012-09-17 18:16:35 +00002351 dev_info(host->dev, "Version ID is %04x\n", host->verid);
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +09002352
2353 if (host->verid < DW_MMC_240A)
2354 host->data_offset = DATA_OFFSET;
2355 else
2356 host->data_offset = DATA_240A_OFFSET;
2357
Will Newtonf95f3852011-01-02 01:11:59 -05002358 if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO)
Thomas Abraham4a909202012-09-17 18:16:35 +00002359 dev_info(host->dev, "Internal DMAC interrupt fix enabled.\n");
Will Newtonf95f3852011-01-02 01:11:59 -05002360
2361 return 0;
2362
James Hogan1791b13e2011-06-24 13:55:55 +01002363err_workqueue:
Thomas Abraham95dcc2c2012-05-01 14:57:36 -07002364 destroy_workqueue(host->card_workqueue);
James Hogan1791b13e2011-06-24 13:55:55 +01002365
Will Newtonf95f3852011-01-02 01:11:59 -05002366err_dmaunmap:
2367 if (host->use_dma && host->dma_ops->exit)
2368 host->dma_ops->exit(host);
Will Newtonf95f3852011-01-02 01:11:59 -05002369
Seungwon Jeon780f22a2012-11-28 19:26:03 +09002370 if (host->vmmc)
Jaehoon Chungc07946a2011-02-25 11:08:14 +09002371 regulator_disable(host->vmmc);
Thomas Abrahamf90a0612012-09-17 18:16:38 +00002372
2373err_clk_ciu:
Seungwon Jeon780f22a2012-11-28 19:26:03 +09002374 if (!IS_ERR(host->ciu_clk))
Thomas Abrahamf90a0612012-09-17 18:16:38 +00002375 clk_disable_unprepare(host->ciu_clk);
Seungwon Jeon780f22a2012-11-28 19:26:03 +09002376
Thomas Abrahamf90a0612012-09-17 18:16:38 +00002377err_clk_biu:
Seungwon Jeon780f22a2012-11-28 19:26:03 +09002378 if (!IS_ERR(host->biu_clk))
Thomas Abrahamf90a0612012-09-17 18:16:38 +00002379 clk_disable_unprepare(host->biu_clk);
Seungwon Jeon780f22a2012-11-28 19:26:03 +09002380
Will Newtonf95f3852011-01-02 01:11:59 -05002381 return ret;
2382}
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302383EXPORT_SYMBOL(dw_mci_probe);
Will Newtonf95f3852011-01-02 01:11:59 -05002384
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302385void dw_mci_remove(struct dw_mci *host)
Will Newtonf95f3852011-01-02 01:11:59 -05002386{
Will Newtonf95f3852011-01-02 01:11:59 -05002387 int i;
2388
2389 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2390 mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
2391
Will Newtonf95f3852011-01-02 01:11:59 -05002392 for (i = 0; i < host->num_slots; i++) {
Thomas Abraham4a909202012-09-17 18:16:35 +00002393 dev_dbg(host->dev, "remove slot %d\n", i);
Will Newtonf95f3852011-01-02 01:11:59 -05002394 if (host->slot[i])
2395 dw_mci_cleanup_slot(host->slot[i], i);
2396 }
2397
2398 /* disable clock to CIU */
2399 mci_writel(host, CLKENA, 0);
2400 mci_writel(host, CLKSRC, 0);
2401
Thomas Abraham95dcc2c2012-05-01 14:57:36 -07002402 destroy_workqueue(host->card_workqueue);
Will Newtonf95f3852011-01-02 01:11:59 -05002403
2404 if (host->use_dma && host->dma_ops->exit)
2405 host->dma_ops->exit(host);
2406
Seungwon Jeon780f22a2012-11-28 19:26:03 +09002407 if (host->vmmc)
Jaehoon Chungc07946a2011-02-25 11:08:14 +09002408 regulator_disable(host->vmmc);
Jaehoon Chungc07946a2011-02-25 11:08:14 +09002409
Thomas Abrahamf90a0612012-09-17 18:16:38 +00002410 if (!IS_ERR(host->ciu_clk))
2411 clk_disable_unprepare(host->ciu_clk);
Seungwon Jeon780f22a2012-11-28 19:26:03 +09002412
Thomas Abrahamf90a0612012-09-17 18:16:38 +00002413 if (!IS_ERR(host->biu_clk))
2414 clk_disable_unprepare(host->biu_clk);
Will Newtonf95f3852011-01-02 01:11:59 -05002415}
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302416EXPORT_SYMBOL(dw_mci_remove);
2417
2418
Will Newtonf95f3852011-01-02 01:11:59 -05002419
Jaehoon Chung6fe88902011-12-08 19:23:03 +09002420#ifdef CONFIG_PM_SLEEP
Will Newtonf95f3852011-01-02 01:11:59 -05002421/*
2422 * TODO: we should probably disable the clock to the card in the suspend path.
2423 */
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302424int dw_mci_suspend(struct dw_mci *host)
Will Newtonf95f3852011-01-02 01:11:59 -05002425{
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302426 int i, ret = 0;
Will Newtonf95f3852011-01-02 01:11:59 -05002427
2428 for (i = 0; i < host->num_slots; i++) {
2429 struct dw_mci_slot *slot = host->slot[i];
2430 if (!slot)
2431 continue;
2432 ret = mmc_suspend_host(slot->mmc);
2433 if (ret < 0) {
2434 while (--i >= 0) {
2435 slot = host->slot[i];
2436 if (slot)
2437 mmc_resume_host(host->slot[i]->mmc);
2438 }
2439 return ret;
2440 }
2441 }
2442
Jaehoon Chungc07946a2011-02-25 11:08:14 +09002443 if (host->vmmc)
2444 regulator_disable(host->vmmc);
2445
Will Newtonf95f3852011-01-02 01:11:59 -05002446 return 0;
2447}
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302448EXPORT_SYMBOL(dw_mci_suspend);
Will Newtonf95f3852011-01-02 01:11:59 -05002449
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302450int dw_mci_resume(struct dw_mci *host)
Will Newtonf95f3852011-01-02 01:11:59 -05002451{
2452 int i, ret;
Will Newtonf95f3852011-01-02 01:11:59 -05002453
Jaehoon Chung1d6c4e02011-05-11 15:52:39 +09002454 if (host->vmmc)
2455 regulator_enable(host->vmmc);
2456
Thomas Abraham4a909202012-09-17 18:16:35 +00002457 if (!mci_wait_reset(host->dev, host)) {
Jaehoon Chunge61cf112011-03-17 20:32:33 +09002458 ret = -ENODEV;
2459 return ret;
2460 }
2461
Jonathan Kliegman3bfe6192012-06-14 13:31:55 -04002462 if (host->use_dma && host->dma_ops->init)
Seungwon Jeon141a7122012-05-22 13:01:03 +09002463 host->dma_ops->init(host);
2464
Jaehoon Chunge61cf112011-03-17 20:32:33 +09002465 /* Restore the old value at FIFOTH register */
2466 mci_writel(host, FIFOTH, host->fifoth_val);
2467
2468 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2469 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
2470 SDMMC_INT_TXDR | SDMMC_INT_RXDR |
2471 DW_MCI_ERROR_FLAGS | SDMMC_INT_CD);
2472 mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
2473
Will Newtonf95f3852011-01-02 01:11:59 -05002474 for (i = 0; i < host->num_slots; i++) {
2475 struct dw_mci_slot *slot = host->slot[i];
2476 if (!slot)
2477 continue;
Abhilash Kesavanab269122012-11-19 10:26:21 +05302478 if (slot->mmc->pm_flags & MMC_PM_KEEP_POWER) {
2479 dw_mci_set_ios(slot->mmc, &slot->mmc->ios);
2480 dw_mci_setup_bus(slot, true);
2481 }
2482
Will Newtonf95f3852011-01-02 01:11:59 -05002483 ret = mmc_resume_host(host->slot[i]->mmc);
2484 if (ret < 0)
2485 return ret;
2486 }
Will Newtonf95f3852011-01-02 01:11:59 -05002487 return 0;
2488}
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302489EXPORT_SYMBOL(dw_mci_resume);
Jaehoon Chung6fe88902011-12-08 19:23:03 +09002490#endif /* CONFIG_PM_SLEEP */
2491
Will Newtonf95f3852011-01-02 01:11:59 -05002492static int __init dw_mci_init(void)
2493{
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05302494 printk(KERN_INFO "Synopsys Designware Multimedia Card Interface Driver");
2495 return 0;
Will Newtonf95f3852011-01-02 01:11:59 -05002496}
2497
2498static void __exit dw_mci_exit(void)
2499{
Will Newtonf95f3852011-01-02 01:11:59 -05002500}
2501
2502module_init(dw_mci_init);
2503module_exit(dw_mci_exit);
2504
2505MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
2506MODULE_AUTHOR("NXP Semiconductor VietNam");
2507MODULE_AUTHOR("Imagination Technologies Ltd");
2508MODULE_LICENSE("GPL v2");