]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/mmc/host/dw_mmc.c
mmc: dw_mmc: Convert to mmc_send_tuning()
[mirror_ubuntu-artful-kernel.git] / drivers / mmc / host / dw_mmc.c
CommitLineData
f95f3850
WN
1/*
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>
f95f3850
WN
25#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>
b24c8b26 30#include <linux/mmc/card.h>
f95f3850
WN
31#include <linux/mmc/host.h>
32#include <linux/mmc/mmc.h>
01730558 33#include <linux/mmc/sd.h>
90c2143a 34#include <linux/mmc/sdio.h>
f95f3850
WN
35#include <linux/mmc/dw_mmc.h>
36#include <linux/bitops.h>
c07946a3 37#include <linux/regulator/consumer.h>
c91eab4b 38#include <linux/of.h>
55a6ceb2 39#include <linux/of_gpio.h>
bf626e55 40#include <linux/mmc/slot-gpio.h>
f95f3850
WN
41
42#include "dw_mmc.h"
43
44/* Common flag combinations */
3f7eec62 45#define DW_MCI_DATA_ERROR_FLAGS (SDMMC_INT_DRTO | SDMMC_INT_DCRC | \
f95f3850
WN
46 SDMMC_INT_HTO | SDMMC_INT_SBE | \
47 SDMMC_INT_EBE)
48#define DW_MCI_CMD_ERROR_FLAGS (SDMMC_INT_RTO | SDMMC_INT_RCRC | \
49 SDMMC_INT_RESP_ERR)
50#define DW_MCI_ERROR_FLAGS (DW_MCI_DATA_ERROR_FLAGS | \
51 DW_MCI_CMD_ERROR_FLAGS | SDMMC_INT_HLE)
52#define DW_MCI_SEND_STATUS 1
53#define DW_MCI_RECV_STATUS 2
54#define DW_MCI_DMA_THRESHOLD 16
55
1f44a2a5
SJ
56#define DW_MCI_FREQ_MAX 200000000 /* unit: HZ */
57#define DW_MCI_FREQ_MIN 400000 /* unit: HZ */
58
f95f3850 59#ifdef CONFIG_MMC_DW_IDMAC
fc79a4d6
JS
60#define IDMAC_INT_CLR (SDMMC_IDMAC_INT_AI | SDMMC_IDMAC_INT_NI | \
61 SDMMC_IDMAC_INT_CES | SDMMC_IDMAC_INT_DU | \
62 SDMMC_IDMAC_INT_FBE | SDMMC_IDMAC_INT_RI | \
63 SDMMC_IDMAC_INT_TI)
64
69d99fdc
PT
65struct idmac_desc_64addr {
66 u32 des0; /* Control Descriptor */
67
68 u32 des1; /* Reserved */
69
70 u32 des2; /*Buffer sizes */
71#define IDMAC_64ADDR_SET_BUFFER1_SIZE(d, s) \
72 ((d)->des2 = ((d)->des2 & 0x03ffe000) | ((s) & 0x1fff))
73
74 u32 des3; /* Reserved */
75
76 u32 des4; /* Lower 32-bits of Buffer Address Pointer 1*/
77 u32 des5; /* Upper 32-bits of Buffer Address Pointer 1*/
78
79 u32 des6; /* Lower 32-bits of Next Descriptor Address */
80 u32 des7; /* Upper 32-bits of Next Descriptor Address */
81};
82
f95f3850
WN
83struct idmac_desc {
84 u32 des0; /* Control Descriptor */
85#define IDMAC_DES0_DIC BIT(1)
86#define IDMAC_DES0_LD BIT(2)
87#define IDMAC_DES0_FD BIT(3)
88#define IDMAC_DES0_CH BIT(4)
89#define IDMAC_DES0_ER BIT(5)
90#define IDMAC_DES0_CES BIT(30)
91#define IDMAC_DES0_OWN BIT(31)
92
93 u32 des1; /* Buffer sizes */
94#define IDMAC_SET_BUFFER1_SIZE(d, s) \
9b7bbe10 95 ((d)->des1 = ((d)->des1 & 0x03ffe000) | ((s) & 0x1fff))
f95f3850
WN
96
97 u32 des2; /* buffer 1 physical address */
98
99 u32 des3; /* buffer 2 physical address */
100};
101#endif /* CONFIG_MMC_DW_IDMAC */
102
3a33a94c 103static bool dw_mci_reset(struct dw_mci *host);
536f6b91 104static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset);
31bff450 105
f95f3850
WN
106#if defined(CONFIG_DEBUG_FS)
107static int dw_mci_req_show(struct seq_file *s, void *v)
108{
109 struct dw_mci_slot *slot = s->private;
110 struct mmc_request *mrq;
111 struct mmc_command *cmd;
112 struct mmc_command *stop;
113 struct mmc_data *data;
114
115 /* Make sure we get a consistent snapshot */
116 spin_lock_bh(&slot->host->lock);
117 mrq = slot->mrq;
118
119 if (mrq) {
120 cmd = mrq->cmd;
121 data = mrq->data;
122 stop = mrq->stop;
123
124 if (cmd)
125 seq_printf(s,
126 "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
127 cmd->opcode, cmd->arg, cmd->flags,
128 cmd->resp[0], cmd->resp[1], cmd->resp[2],
129 cmd->resp[2], cmd->error);
130 if (data)
131 seq_printf(s, "DATA %u / %u * %u flg %x err %d\n",
132 data->bytes_xfered, data->blocks,
133 data->blksz, data->flags, data->error);
134 if (stop)
135 seq_printf(s,
136 "CMD%u(0x%x) flg %x rsp %x %x %x %x err %d\n",
137 stop->opcode, stop->arg, stop->flags,
138 stop->resp[0], stop->resp[1], stop->resp[2],
139 stop->resp[2], stop->error);
140 }
141
142 spin_unlock_bh(&slot->host->lock);
143
144 return 0;
145}
146
147static int dw_mci_req_open(struct inode *inode, struct file *file)
148{
149 return single_open(file, dw_mci_req_show, inode->i_private);
150}
151
152static const struct file_operations dw_mci_req_fops = {
153 .owner = THIS_MODULE,
154 .open = dw_mci_req_open,
155 .read = seq_read,
156 .llseek = seq_lseek,
157 .release = single_release,
158};
159
160static int dw_mci_regs_show(struct seq_file *s, void *v)
161{
162 seq_printf(s, "STATUS:\t0x%08x\n", SDMMC_STATUS);
163 seq_printf(s, "RINTSTS:\t0x%08x\n", SDMMC_RINTSTS);
164 seq_printf(s, "CMD:\t0x%08x\n", SDMMC_CMD);
165 seq_printf(s, "CTRL:\t0x%08x\n", SDMMC_CTRL);
166 seq_printf(s, "INTMASK:\t0x%08x\n", SDMMC_INTMASK);
167 seq_printf(s, "CLKENA:\t0x%08x\n", SDMMC_CLKENA);
168
169 return 0;
170}
171
172static int dw_mci_regs_open(struct inode *inode, struct file *file)
173{
174 return single_open(file, dw_mci_regs_show, inode->i_private);
175}
176
177static const struct file_operations dw_mci_regs_fops = {
178 .owner = THIS_MODULE,
179 .open = dw_mci_regs_open,
180 .read = seq_read,
181 .llseek = seq_lseek,
182 .release = single_release,
183};
184
185static void dw_mci_init_debugfs(struct dw_mci_slot *slot)
186{
187 struct mmc_host *mmc = slot->mmc;
188 struct dw_mci *host = slot->host;
189 struct dentry *root;
190 struct dentry *node;
191
192 root = mmc->debugfs_root;
193 if (!root)
194 return;
195
196 node = debugfs_create_file("regs", S_IRUSR, root, host,
197 &dw_mci_regs_fops);
198 if (!node)
199 goto err;
200
201 node = debugfs_create_file("req", S_IRUSR, root, slot,
202 &dw_mci_req_fops);
203 if (!node)
204 goto err;
205
206 node = debugfs_create_u32("state", S_IRUSR, root, (u32 *)&host->state);
207 if (!node)
208 goto err;
209
210 node = debugfs_create_x32("pending_events", S_IRUSR, root,
211 (u32 *)&host->pending_events);
212 if (!node)
213 goto err;
214
215 node = debugfs_create_x32("completed_events", S_IRUSR, root,
216 (u32 *)&host->completed_events);
217 if (!node)
218 goto err;
219
220 return;
221
222err:
223 dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n");
224}
225#endif /* defined(CONFIG_DEBUG_FS) */
226
01730558
DA
227static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg);
228
f95f3850
WN
229static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)
230{
231 struct mmc_data *data;
800d78bf 232 struct dw_mci_slot *slot = mmc_priv(mmc);
01730558 233 struct dw_mci *host = slot->host;
e95baf13 234 const struct dw_mci_drv_data *drv_data = slot->host->drv_data;
f95f3850
WN
235 u32 cmdr;
236 cmd->error = -EINPROGRESS;
237
238 cmdr = cmd->opcode;
239
90c2143a
SJ
240 if (cmd->opcode == MMC_STOP_TRANSMISSION ||
241 cmd->opcode == MMC_GO_IDLE_STATE ||
242 cmd->opcode == MMC_GO_INACTIVE_STATE ||
243 (cmd->opcode == SD_IO_RW_DIRECT &&
244 ((cmd->arg >> 9) & 0x1FFFF) == SDIO_CCCR_ABORT))
f95f3850 245 cmdr |= SDMMC_CMD_STOP;
4a1b27ad
JC
246 else if (cmd->opcode != MMC_SEND_STATUS && cmd->data)
247 cmdr |= SDMMC_CMD_PRV_DAT_WAIT;
f95f3850 248
01730558
DA
249 if (cmd->opcode == SD_SWITCH_VOLTAGE) {
250 u32 clk_en_a;
251
252 /* Special bit makes CMD11 not die */
253 cmdr |= SDMMC_CMD_VOLT_SWITCH;
254
255 /* Change state to continue to handle CMD11 weirdness */
256 WARN_ON(slot->host->state != STATE_SENDING_CMD);
257 slot->host->state = STATE_SENDING_CMD11;
258
259 /*
260 * We need to disable low power mode (automatic clock stop)
261 * while doing voltage switch so we don't confuse the card,
262 * since stopping the clock is a specific part of the UHS
263 * voltage change dance.
264 *
265 * Note that low power mode (SDMMC_CLKEN_LOW_PWR) will be
266 * unconditionally turned back on in dw_mci_setup_bus() if it's
267 * ever called with a non-zero clock. That shouldn't happen
268 * until the voltage change is all done.
269 */
270 clk_en_a = mci_readl(host, CLKENA);
271 clk_en_a &= ~(SDMMC_CLKEN_LOW_PWR << slot->id);
272 mci_writel(host, CLKENA, clk_en_a);
273 mci_send_cmd(slot, SDMMC_CMD_UPD_CLK |
274 SDMMC_CMD_PRV_DAT_WAIT, 0);
275 }
276
f95f3850
WN
277 if (cmd->flags & MMC_RSP_PRESENT) {
278 /* We expect a response, so set this bit */
279 cmdr |= SDMMC_CMD_RESP_EXP;
280 if (cmd->flags & MMC_RSP_136)
281 cmdr |= SDMMC_CMD_RESP_LONG;
282 }
283
284 if (cmd->flags & MMC_RSP_CRC)
285 cmdr |= SDMMC_CMD_RESP_CRC;
286
287 data = cmd->data;
288 if (data) {
289 cmdr |= SDMMC_CMD_DAT_EXP;
290 if (data->flags & MMC_DATA_STREAM)
291 cmdr |= SDMMC_CMD_STRM_MODE;
292 if (data->flags & MMC_DATA_WRITE)
293 cmdr |= SDMMC_CMD_DAT_WR;
294 }
295
cb27a843
JH
296 if (drv_data && drv_data->prepare_command)
297 drv_data->prepare_command(slot->host, &cmdr);
800d78bf 298
f95f3850
WN
299 return cmdr;
300}
301
90c2143a
SJ
302static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
303{
304 struct mmc_command *stop;
305 u32 cmdr;
306
307 if (!cmd->data)
308 return 0;
309
310 stop = &host->stop_abort;
311 cmdr = cmd->opcode;
312 memset(stop, 0, sizeof(struct mmc_command));
313
314 if (cmdr == MMC_READ_SINGLE_BLOCK ||
315 cmdr == MMC_READ_MULTIPLE_BLOCK ||
316 cmdr == MMC_WRITE_BLOCK ||
6c2c6506
UH
317 cmdr == MMC_WRITE_MULTIPLE_BLOCK ||
318 cmdr == MMC_SEND_TUNING_BLOCK ||
319 cmdr == MMC_SEND_TUNING_BLOCK_HS200) {
90c2143a
SJ
320 stop->opcode = MMC_STOP_TRANSMISSION;
321 stop->arg = 0;
322 stop->flags = MMC_RSP_R1B | MMC_CMD_AC;
323 } else if (cmdr == SD_IO_RW_EXTENDED) {
324 stop->opcode = SD_IO_RW_DIRECT;
325 stop->arg |= (1 << 31) | (0 << 28) | (SDIO_CCCR_ABORT << 9) |
326 ((cmd->arg >> 28) & 0x7);
327 stop->flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_AC;
328 } else {
329 return 0;
330 }
331
332 cmdr = stop->opcode | SDMMC_CMD_STOP |
333 SDMMC_CMD_RESP_CRC | SDMMC_CMD_RESP_EXP;
334
335 return cmdr;
336}
337
f95f3850
WN
338static void dw_mci_start_command(struct dw_mci *host,
339 struct mmc_command *cmd, u32 cmd_flags)
340{
341 host->cmd = cmd;
4a90920c 342 dev_vdbg(host->dev,
f95f3850
WN
343 "start command: ARGR=0x%08x CMDR=0x%08x\n",
344 cmd->arg, cmd_flags);
345
346 mci_writel(host, CMDARG, cmd->arg);
347 wmb();
348
349 mci_writel(host, CMD, cmd_flags | SDMMC_CMD_START);
350}
351
90c2143a 352static inline void send_stop_abort(struct dw_mci *host, struct mmc_data *data)
f95f3850 353{
90c2143a
SJ
354 struct mmc_command *stop = data->stop ? data->stop : &host->stop_abort;
355 dw_mci_start_command(host, stop, host->stop_cmdr);
f95f3850
WN
356}
357
358/* DMA interface functions */
359static void dw_mci_stop_dma(struct dw_mci *host)
360{
03e8cb53 361 if (host->using_dma) {
f95f3850
WN
362 host->dma_ops->stop(host);
363 host->dma_ops->cleanup(host);
f95f3850 364 }
aa50f259
SJ
365
366 /* Data transfer was stopped by the interrupt handler */
367 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
f95f3850
WN
368}
369
9aa51408
SJ
370static int dw_mci_get_dma_dir(struct mmc_data *data)
371{
372 if (data->flags & MMC_DATA_WRITE)
373 return DMA_TO_DEVICE;
374 else
375 return DMA_FROM_DEVICE;
376}
377
9beee912 378#ifdef CONFIG_MMC_DW_IDMAC
f95f3850
WN
379static void dw_mci_dma_cleanup(struct dw_mci *host)
380{
381 struct mmc_data *data = host->data;
382
383 if (data)
9aa51408 384 if (!data->host_cookie)
4a90920c 385 dma_unmap_sg(host->dev,
9aa51408
SJ
386 data->sg,
387 data->sg_len,
388 dw_mci_get_dma_dir(data));
f95f3850
WN
389}
390
5ce9d961
SJ
391static void dw_mci_idmac_reset(struct dw_mci *host)
392{
393 u32 bmod = mci_readl(host, BMOD);
394 /* Software reset of DMA */
395 bmod |= SDMMC_IDMAC_SWRESET;
396 mci_writel(host, BMOD, bmod);
397}
398
f95f3850
WN
399static void dw_mci_idmac_stop_dma(struct dw_mci *host)
400{
401 u32 temp;
402
403 /* Disable and reset the IDMAC interface */
404 temp = mci_readl(host, CTRL);
405 temp &= ~SDMMC_CTRL_USE_IDMAC;
406 temp |= SDMMC_CTRL_DMA_RESET;
407 mci_writel(host, CTRL, temp);
408
409 /* Stop the IDMAC running */
410 temp = mci_readl(host, BMOD);
a5289a43 411 temp &= ~(SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB);
5ce9d961 412 temp |= SDMMC_IDMAC_SWRESET;
f95f3850
WN
413 mci_writel(host, BMOD, temp);
414}
415
416static void dw_mci_idmac_complete_dma(struct dw_mci *host)
417{
418 struct mmc_data *data = host->data;
419
4a90920c 420 dev_vdbg(host->dev, "DMA complete\n");
f95f3850
WN
421
422 host->dma_ops->cleanup(host);
423
424 /*
425 * If the card was removed, data will be NULL. No point in trying to
426 * send the stop command or waiting for NBUSY in this case.
427 */
428 if (data) {
429 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
430 tasklet_schedule(&host->tasklet);
431 }
432}
433
434static void dw_mci_translate_sglist(struct dw_mci *host, struct mmc_data *data,
435 unsigned int sg_len)
436{
437 int i;
69d99fdc
PT
438 if (host->dma_64bit_address == 1) {
439 struct idmac_desc_64addr *desc = host->sg_cpu;
440
441 for (i = 0; i < sg_len; i++, desc++) {
442 unsigned int length = sg_dma_len(&data->sg[i]);
443 u64 mem_addr = sg_dma_address(&data->sg[i]);
f95f3850 444
69d99fdc
PT
445 /*
446 * Set the OWN bit and disable interrupts for this
447 * descriptor
448 */
449 desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC |
450 IDMAC_DES0_CH;
451 /* Buffer length */
452 IDMAC_64ADDR_SET_BUFFER1_SIZE(desc, length);
453
454 /* Physical address to DMA to/from */
455 desc->des4 = mem_addr & 0xffffffff;
456 desc->des5 = mem_addr >> 32;
457 }
f95f3850 458
69d99fdc
PT
459 /* Set first descriptor */
460 desc = host->sg_cpu;
461 desc->des0 |= IDMAC_DES0_FD;
f95f3850 462
69d99fdc
PT
463 /* Set last descriptor */
464 desc = host->sg_cpu + (i - 1) *
465 sizeof(struct idmac_desc_64addr);
466 desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC);
467 desc->des0 |= IDMAC_DES0_LD;
f95f3850 468
69d99fdc
PT
469 } else {
470 struct idmac_desc *desc = host->sg_cpu;
471
472 for (i = 0; i < sg_len; i++, desc++) {
473 unsigned int length = sg_dma_len(&data->sg[i]);
474 u32 mem_addr = sg_dma_address(&data->sg[i]);
475
476 /*
477 * Set the OWN bit and disable interrupts for this
478 * descriptor
479 */
480 desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC |
481 IDMAC_DES0_CH;
482 /* Buffer length */
483 IDMAC_SET_BUFFER1_SIZE(desc, length);
f95f3850 484
69d99fdc
PT
485 /* Physical address to DMA to/from */
486 desc->des2 = mem_addr;
487 }
488
489 /* Set first descriptor */
490 desc = host->sg_cpu;
491 desc->des0 |= IDMAC_DES0_FD;
f95f3850 492
69d99fdc
PT
493 /* Set last descriptor */
494 desc = host->sg_cpu + (i - 1) * sizeof(struct idmac_desc);
495 desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC);
496 desc->des0 |= IDMAC_DES0_LD;
497 }
f95f3850
WN
498
499 wmb();
500}
501
502static void dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len)
503{
504 u32 temp;
505
506 dw_mci_translate_sglist(host, host->data, sg_len);
507
536f6b91
SR
508 /* Make sure to reset DMA in case we did PIO before this */
509 dw_mci_ctrl_reset(host, SDMMC_CTRL_DMA_RESET);
510 dw_mci_idmac_reset(host);
511
f95f3850
WN
512 /* Select IDMAC interface */
513 temp = mci_readl(host, CTRL);
514 temp |= SDMMC_CTRL_USE_IDMAC;
515 mci_writel(host, CTRL, temp);
516
517 wmb();
518
519 /* Enable the IDMAC */
520 temp = mci_readl(host, BMOD);
a5289a43 521 temp |= SDMMC_IDMAC_ENABLE | SDMMC_IDMAC_FB;
f95f3850
WN
522 mci_writel(host, BMOD, temp);
523
524 /* Start it running */
525 mci_writel(host, PLDMND, 1);
526}
527
528static int dw_mci_idmac_init(struct dw_mci *host)
529{
897b69e7 530 int i;
f95f3850 531
69d99fdc
PT
532 if (host->dma_64bit_address == 1) {
533 struct idmac_desc_64addr *p;
534 /* Number of descriptors in the ring buffer */
535 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc_64addr);
536
537 /* Forward link the descriptor list */
538 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1;
539 i++, p++) {
540 p->des6 = (host->sg_dma +
541 (sizeof(struct idmac_desc_64addr) *
542 (i + 1))) & 0xffffffff;
543
544 p->des7 = (u64)(host->sg_dma +
545 (sizeof(struct idmac_desc_64addr) *
546 (i + 1))) >> 32;
547 /* Initialize reserved and buffer size fields to "0" */
548 p->des1 = 0;
549 p->des2 = 0;
550 p->des3 = 0;
551 }
f95f3850 552
69d99fdc
PT
553 /* Set the last descriptor as the end-of-ring descriptor */
554 p->des6 = host->sg_dma & 0xffffffff;
555 p->des7 = (u64)host->sg_dma >> 32;
556 p->des0 = IDMAC_DES0_ER;
f95f3850 557
69d99fdc
PT
558 } else {
559 struct idmac_desc *p;
560 /* Number of descriptors in the ring buffer */
561 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc);
562
563 /* Forward link the descriptor list */
564 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++)
565 p->des3 = host->sg_dma + (sizeof(struct idmac_desc) *
566 (i + 1));
567
568 /* Set the last descriptor as the end-of-ring descriptor */
569 p->des3 = host->sg_dma;
570 p->des0 = IDMAC_DES0_ER;
571 }
f95f3850 572
5ce9d961 573 dw_mci_idmac_reset(host);
141a712a 574
69d99fdc
PT
575 if (host->dma_64bit_address == 1) {
576 /* Mask out interrupts - get Tx & Rx complete only */
577 mci_writel(host, IDSTS64, IDMAC_INT_CLR);
578 mci_writel(host, IDINTEN64, SDMMC_IDMAC_INT_NI |
579 SDMMC_IDMAC_INT_RI | SDMMC_IDMAC_INT_TI);
580
581 /* Set the descriptor base address */
582 mci_writel(host, DBADDRL, host->sg_dma & 0xffffffff);
583 mci_writel(host, DBADDRU, (u64)host->sg_dma >> 32);
584
585 } else {
586 /* Mask out interrupts - get Tx & Rx complete only */
587 mci_writel(host, IDSTS, IDMAC_INT_CLR);
588 mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI |
589 SDMMC_IDMAC_INT_RI | SDMMC_IDMAC_INT_TI);
590
591 /* Set the descriptor base address */
592 mci_writel(host, DBADDR, host->sg_dma);
593 }
f95f3850 594
f95f3850
WN
595 return 0;
596}
597
8e2b36ea 598static const struct dw_mci_dma_ops dw_mci_idmac_ops = {
885c3e80
SJ
599 .init = dw_mci_idmac_init,
600 .start = dw_mci_idmac_start_dma,
601 .stop = dw_mci_idmac_stop_dma,
602 .complete = dw_mci_idmac_complete_dma,
603 .cleanup = dw_mci_dma_cleanup,
604};
605#endif /* CONFIG_MMC_DW_IDMAC */
606
9aa51408
SJ
607static int dw_mci_pre_dma_transfer(struct dw_mci *host,
608 struct mmc_data *data,
609 bool next)
f95f3850
WN
610{
611 struct scatterlist *sg;
9aa51408 612 unsigned int i, sg_len;
03e8cb53 613
9aa51408
SJ
614 if (!next && data->host_cookie)
615 return data->host_cookie;
f95f3850
WN
616
617 /*
618 * We don't do DMA on "complex" transfers, i.e. with
619 * non-word-aligned buffers or lengths. Also, we don't bother
620 * with all the DMA setup overhead for short transfers.
621 */
622 if (data->blocks * data->blksz < DW_MCI_DMA_THRESHOLD)
623 return -EINVAL;
9aa51408 624
f95f3850
WN
625 if (data->blksz & 3)
626 return -EINVAL;
627
628 for_each_sg(data->sg, sg, data->sg_len, i) {
629 if (sg->offset & 3 || sg->length & 3)
630 return -EINVAL;
631 }
632
4a90920c 633 sg_len = dma_map_sg(host->dev,
9aa51408
SJ
634 data->sg,
635 data->sg_len,
636 dw_mci_get_dma_dir(data));
637 if (sg_len == 0)
638 return -EINVAL;
03e8cb53 639
9aa51408
SJ
640 if (next)
641 data->host_cookie = sg_len;
f95f3850 642
9aa51408
SJ
643 return sg_len;
644}
645
9aa51408
SJ
646static void dw_mci_pre_req(struct mmc_host *mmc,
647 struct mmc_request *mrq,
648 bool is_first_req)
649{
650 struct dw_mci_slot *slot = mmc_priv(mmc);
651 struct mmc_data *data = mrq->data;
652
653 if (!slot->host->use_dma || !data)
654 return;
655
656 if (data->host_cookie) {
657 data->host_cookie = 0;
658 return;
659 }
660
661 if (dw_mci_pre_dma_transfer(slot->host, mrq->data, 1) < 0)
662 data->host_cookie = 0;
663}
664
665static void dw_mci_post_req(struct mmc_host *mmc,
666 struct mmc_request *mrq,
667 int err)
668{
669 struct dw_mci_slot *slot = mmc_priv(mmc);
670 struct mmc_data *data = mrq->data;
671
672 if (!slot->host->use_dma || !data)
673 return;
674
675 if (data->host_cookie)
4a90920c 676 dma_unmap_sg(slot->host->dev,
9aa51408
SJ
677 data->sg,
678 data->sg_len,
679 dw_mci_get_dma_dir(data));
680 data->host_cookie = 0;
681}
682
52426899
SJ
683static void dw_mci_adjust_fifoth(struct dw_mci *host, struct mmc_data *data)
684{
685#ifdef CONFIG_MMC_DW_IDMAC
686 unsigned int blksz = data->blksz;
687 const u32 mszs[] = {1, 4, 8, 16, 32, 64, 128, 256};
688 u32 fifo_width = 1 << host->data_shift;
689 u32 blksz_depth = blksz / fifo_width, fifoth_val;
690 u32 msize = 0, rx_wmark = 1, tx_wmark, tx_wmark_invers;
691 int idx = (sizeof(mszs) / sizeof(mszs[0])) - 1;
692
693 tx_wmark = (host->fifo_depth) / 2;
694 tx_wmark_invers = host->fifo_depth - tx_wmark;
695
696 /*
697 * MSIZE is '1',
698 * if blksz is not a multiple of the FIFO width
699 */
700 if (blksz % fifo_width) {
701 msize = 0;
702 rx_wmark = 1;
703 goto done;
704 }
705
706 do {
707 if (!((blksz_depth % mszs[idx]) ||
708 (tx_wmark_invers % mszs[idx]))) {
709 msize = idx;
710 rx_wmark = mszs[idx] - 1;
711 break;
712 }
713 } while (--idx > 0);
714 /*
715 * If idx is '0', it won't be tried
716 * Thus, initial values are uesed
717 */
718done:
719 fifoth_val = SDMMC_SET_FIFOTH(msize, rx_wmark, tx_wmark);
720 mci_writel(host, FIFOTH, fifoth_val);
721#endif
722}
723
f1d2736c
SJ
724static void dw_mci_ctrl_rd_thld(struct dw_mci *host, struct mmc_data *data)
725{
726 unsigned int blksz = data->blksz;
727 u32 blksz_depth, fifo_depth;
728 u16 thld_size;
729
730 WARN_ON(!(data->flags & MMC_DATA_READ));
731
66dfd101
JH
732 /*
733 * CDTHRCTL doesn't exist prior to 240A (in fact that register offset is
734 * in the FIFO region, so we really shouldn't access it).
735 */
736 if (host->verid < DW_MMC_240A)
737 return;
738
f1d2736c
SJ
739 if (host->timing != MMC_TIMING_MMC_HS200 &&
740 host->timing != MMC_TIMING_UHS_SDR104)
741 goto disable;
742
743 blksz_depth = blksz / (1 << host->data_shift);
744 fifo_depth = host->fifo_depth;
745
746 if (blksz_depth > fifo_depth)
747 goto disable;
748
749 /*
750 * If (blksz_depth) >= (fifo_depth >> 1), should be 'thld_size <= blksz'
751 * If (blksz_depth) < (fifo_depth >> 1), should be thld_size = blksz
752 * Currently just choose blksz.
753 */
754 thld_size = blksz;
755 mci_writel(host, CDTHRCTL, SDMMC_SET_RD_THLD(thld_size, 1));
756 return;
757
758disable:
759 mci_writel(host, CDTHRCTL, SDMMC_SET_RD_THLD(0, 0));
760}
761
9aa51408
SJ
762static int dw_mci_submit_data_dma(struct dw_mci *host, struct mmc_data *data)
763{
f8c58c11 764 unsigned long irqflags;
9aa51408
SJ
765 int sg_len;
766 u32 temp;
767
768 host->using_dma = 0;
769
770 /* If we don't have a channel, we can't do DMA */
771 if (!host->use_dma)
772 return -ENODEV;
773
774 sg_len = dw_mci_pre_dma_transfer(host, data, 0);
a99aa9b9
SJ
775 if (sg_len < 0) {
776 host->dma_ops->stop(host);
9aa51408 777 return sg_len;
a99aa9b9 778 }
9aa51408
SJ
779
780 host->using_dma = 1;
f95f3850 781
4a90920c 782 dev_vdbg(host->dev,
f95f3850
WN
783 "sd sg_cpu: %#lx sg_dma: %#lx sg_len: %d\n",
784 (unsigned long)host->sg_cpu, (unsigned long)host->sg_dma,
785 sg_len);
786
52426899
SJ
787 /*
788 * Decide the MSIZE and RX/TX Watermark.
789 * If current block size is same with previous size,
790 * no need to update fifoth.
791 */
792 if (host->prev_blksz != data->blksz)
793 dw_mci_adjust_fifoth(host, data);
794
f95f3850
WN
795 /* Enable the DMA interface */
796 temp = mci_readl(host, CTRL);
797 temp |= SDMMC_CTRL_DMA_ENABLE;
798 mci_writel(host, CTRL, temp);
799
800 /* Disable RX/TX IRQs, let DMA handle it */
f8c58c11 801 spin_lock_irqsave(&host->irq_lock, irqflags);
f95f3850
WN
802 temp = mci_readl(host, INTMASK);
803 temp &= ~(SDMMC_INT_RXDR | SDMMC_INT_TXDR);
804 mci_writel(host, INTMASK, temp);
f8c58c11 805 spin_unlock_irqrestore(&host->irq_lock, irqflags);
f95f3850
WN
806
807 host->dma_ops->start(host, sg_len);
808
809 return 0;
810}
811
812static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)
813{
f8c58c11 814 unsigned long irqflags;
f95f3850
WN
815 u32 temp;
816
817 data->error = -EINPROGRESS;
818
819 WARN_ON(host->data);
820 host->sg = NULL;
821 host->data = data;
822
f1d2736c 823 if (data->flags & MMC_DATA_READ) {
55c5efbc 824 host->dir_status = DW_MCI_RECV_STATUS;
f1d2736c
SJ
825 dw_mci_ctrl_rd_thld(host, data);
826 } else {
55c5efbc 827 host->dir_status = DW_MCI_SEND_STATUS;
f1d2736c 828 }
55c5efbc 829
f95f3850 830 if (dw_mci_submit_data_dma(host, data)) {
f9c2a0dc
SJ
831 int flags = SG_MITER_ATOMIC;
832 if (host->data->flags & MMC_DATA_READ)
833 flags |= SG_MITER_TO_SG;
834 else
835 flags |= SG_MITER_FROM_SG;
836
837 sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
f95f3850 838 host->sg = data->sg;
34b664a2
JH
839 host->part_buf_start = 0;
840 host->part_buf_count = 0;
f95f3850 841
b40af3aa 842 mci_writel(host, RINTSTS, SDMMC_INT_TXDR | SDMMC_INT_RXDR);
f8c58c11
DA
843
844 spin_lock_irqsave(&host->irq_lock, irqflags);
f95f3850
WN
845 temp = mci_readl(host, INTMASK);
846 temp |= SDMMC_INT_TXDR | SDMMC_INT_RXDR;
847 mci_writel(host, INTMASK, temp);
f8c58c11 848 spin_unlock_irqrestore(&host->irq_lock, irqflags);
f95f3850
WN
849
850 temp = mci_readl(host, CTRL);
851 temp &= ~SDMMC_CTRL_DMA_ENABLE;
852 mci_writel(host, CTRL, temp);
52426899
SJ
853
854 /*
855 * Use the initial fifoth_val for PIO mode.
856 * If next issued data may be transfered by DMA mode,
857 * prev_blksz should be invalidated.
858 */
859 mci_writel(host, FIFOTH, host->fifoth_val);
860 host->prev_blksz = 0;
861 } else {
862 /*
863 * Keep the current block size.
864 * It will be used to decide whether to update
865 * fifoth register next time.
866 */
867 host->prev_blksz = data->blksz;
f95f3850
WN
868 }
869}
870
871static void mci_send_cmd(struct dw_mci_slot *slot, u32 cmd, u32 arg)
872{
873 struct dw_mci *host = slot->host;
874 unsigned long timeout = jiffies + msecs_to_jiffies(500);
875 unsigned int cmd_status = 0;
876
877 mci_writel(host, CMDARG, arg);
878 wmb();
879 mci_writel(host, CMD, SDMMC_CMD_START | cmd);
880
881 while (time_before(jiffies, timeout)) {
882 cmd_status = mci_readl(host, CMD);
883 if (!(cmd_status & SDMMC_CMD_START))
884 return;
885 }
886 dev_err(&slot->mmc->class_dev,
887 "Timeout sending command (cmd %#x arg %#x status %#x)\n",
888 cmd, arg, cmd_status);
889}
890
ab269128 891static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
f95f3850
WN
892{
893 struct dw_mci *host = slot->host;
fdf492a1 894 unsigned int clock = slot->clock;
f95f3850 895 u32 div;
9623b5b9 896 u32 clk_en_a;
01730558
DA
897 u32 sdmmc_cmd_bits = SDMMC_CMD_UPD_CLK | SDMMC_CMD_PRV_DAT_WAIT;
898
899 /* We must continue to set bit 28 in CMD until the change is complete */
900 if (host->state == STATE_WAITING_CMD11_DONE)
901 sdmmc_cmd_bits |= SDMMC_CMD_VOLT_SWITCH;
f95f3850 902
fdf492a1
DA
903 if (!clock) {
904 mci_writel(host, CLKENA, 0);
01730558 905 mci_send_cmd(slot, sdmmc_cmd_bits, 0);
fdf492a1
DA
906 } else if (clock != host->current_speed || force_clkinit) {
907 div = host->bus_hz / clock;
908 if (host->bus_hz % clock && host->bus_hz > clock)
f95f3850
WN
909 /*
910 * move the + 1 after the divide to prevent
911 * over-clocking the card.
912 */
e419990b
SJ
913 div += 1;
914
fdf492a1 915 div = (host->bus_hz != clock) ? DIV_ROUND_UP(div, 2) : 0;
f95f3850 916
fdf492a1
DA
917 if ((clock << div) != slot->__clk_old || force_clkinit)
918 dev_info(&slot->mmc->class_dev,
919 "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n",
920 slot->id, host->bus_hz, clock,
921 div ? ((host->bus_hz / div) >> 1) :
922 host->bus_hz, div);
f95f3850
WN
923
924 /* disable clock */
925 mci_writel(host, CLKENA, 0);
926 mci_writel(host, CLKSRC, 0);
927
928 /* inform CIU */
01730558 929 mci_send_cmd(slot, sdmmc_cmd_bits, 0);
f95f3850
WN
930
931 /* set clock to desired speed */
932 mci_writel(host, CLKDIV, div);
933
934 /* inform CIU */
01730558 935 mci_send_cmd(slot, sdmmc_cmd_bits, 0);
f95f3850 936
9623b5b9
DA
937 /* enable clock; only low power if no SDIO */
938 clk_en_a = SDMMC_CLKEN_ENABLE << slot->id;
b24c8b26 939 if (!test_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags))
9623b5b9
DA
940 clk_en_a |= SDMMC_CLKEN_LOW_PWR << slot->id;
941 mci_writel(host, CLKENA, clk_en_a);
f95f3850
WN
942
943 /* inform CIU */
01730558 944 mci_send_cmd(slot, sdmmc_cmd_bits, 0);
f95f3850 945
fdf492a1
DA
946 /* keep the clock with reflecting clock dividor */
947 slot->__clk_old = clock << div;
f95f3850
WN
948 }
949
fdf492a1
DA
950 host->current_speed = clock;
951
f95f3850 952 /* Set the current slot bus width */
1d56c453 953 mci_writel(host, CTYPE, (slot->ctype << slot->id));
f95f3850
WN
954}
955
053b3ce6
SJ
956static void __dw_mci_start_request(struct dw_mci *host,
957 struct dw_mci_slot *slot,
958 struct mmc_command *cmd)
f95f3850
WN
959{
960 struct mmc_request *mrq;
f95f3850
WN
961 struct mmc_data *data;
962 u32 cmdflags;
963
964 mrq = slot->mrq;
f95f3850 965
f95f3850
WN
966 host->cur_slot = slot;
967 host->mrq = mrq;
968
969 host->pending_events = 0;
970 host->completed_events = 0;
e352c813 971 host->cmd_status = 0;
f95f3850 972 host->data_status = 0;
e352c813 973 host->dir_status = 0;
f95f3850 974
053b3ce6 975 data = cmd->data;
f95f3850 976 if (data) {
f16afa88 977 mci_writel(host, TMOUT, 0xFFFFFFFF);
f95f3850
WN
978 mci_writel(host, BYTCNT, data->blksz*data->blocks);
979 mci_writel(host, BLKSIZ, data->blksz);
980 }
981
f95f3850
WN
982 cmdflags = dw_mci_prepare_command(slot->mmc, cmd);
983
984 /* this is the first command, send the initialization clock */
985 if (test_and_clear_bit(DW_MMC_CARD_NEED_INIT, &slot->flags))
986 cmdflags |= SDMMC_CMD_INIT;
987
988 if (data) {
989 dw_mci_submit_data(host, data);
990 wmb();
991 }
992
993 dw_mci_start_command(host, cmd, cmdflags);
994
995 if (mrq->stop)
996 host->stop_cmdr = dw_mci_prepare_command(slot->mmc, mrq->stop);
90c2143a
SJ
997 else
998 host->stop_cmdr = dw_mci_prep_stop_abort(host, cmd);
f95f3850
WN
999}
1000
053b3ce6
SJ
1001static void dw_mci_start_request(struct dw_mci *host,
1002 struct dw_mci_slot *slot)
1003{
1004 struct mmc_request *mrq = slot->mrq;
1005 struct mmc_command *cmd;
1006
1007 cmd = mrq->sbc ? mrq->sbc : mrq->cmd;
1008 __dw_mci_start_request(host, slot, cmd);
1009}
1010
7456caae 1011/* must be called with host->lock held */
f95f3850
WN
1012static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot,
1013 struct mmc_request *mrq)
1014{
1015 dev_vdbg(&slot->mmc->class_dev, "queue request: state=%d\n",
1016 host->state);
1017
f95f3850
WN
1018 slot->mrq = mrq;
1019
01730558
DA
1020 if (host->state == STATE_WAITING_CMD11_DONE) {
1021 dev_warn(&slot->mmc->class_dev,
1022 "Voltage change didn't complete\n");
1023 /*
1024 * this case isn't expected to happen, so we can
1025 * either crash here or just try to continue on
1026 * in the closest possible state
1027 */
1028 host->state = STATE_IDLE;
1029 }
1030
f95f3850
WN
1031 if (host->state == STATE_IDLE) {
1032 host->state = STATE_SENDING_CMD;
1033 dw_mci_start_request(host, slot);
1034 } else {
1035 list_add_tail(&slot->queue_node, &host->queue);
1036 }
f95f3850
WN
1037}
1038
1039static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1040{
1041 struct dw_mci_slot *slot = mmc_priv(mmc);
1042 struct dw_mci *host = slot->host;
1043
1044 WARN_ON(slot->mrq);
1045
7456caae
JH
1046 /*
1047 * The check for card presence and queueing of the request must be
1048 * atomic, otherwise the card could be removed in between and the
1049 * request wouldn't fail until another card was inserted.
1050 */
1051 spin_lock_bh(&host->lock);
1052
f95f3850 1053 if (!test_bit(DW_MMC_CARD_PRESENT, &slot->flags)) {
7456caae 1054 spin_unlock_bh(&host->lock);
f95f3850
WN
1055 mrq->cmd->error = -ENOMEDIUM;
1056 mmc_request_done(mmc, mrq);
1057 return;
1058 }
1059
f95f3850 1060 dw_mci_queue_request(host, slot, mrq);
7456caae
JH
1061
1062 spin_unlock_bh(&host->lock);
f95f3850
WN
1063}
1064
1065static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1066{
1067 struct dw_mci_slot *slot = mmc_priv(mmc);
e95baf13 1068 const struct dw_mci_drv_data *drv_data = slot->host->drv_data;
41babf75 1069 u32 regs;
51da2240 1070 int ret;
f95f3850 1071
f95f3850 1072 switch (ios->bus_width) {
f95f3850
WN
1073 case MMC_BUS_WIDTH_4:
1074 slot->ctype = SDMMC_CTYPE_4BIT;
1075 break;
c9b2a06f
JC
1076 case MMC_BUS_WIDTH_8:
1077 slot->ctype = SDMMC_CTYPE_8BIT;
1078 break;
b2f7cb45
JC
1079 default:
1080 /* set default 1 bit mode */
1081 slot->ctype = SDMMC_CTYPE_1BIT;
f95f3850
WN
1082 }
1083
3f514291
SJ
1084 regs = mci_readl(slot->host, UHS_REG);
1085
41babf75 1086 /* DDR mode set */
cab3a802 1087 if (ios->timing == MMC_TIMING_MMC_DDR52)
c69042a5 1088 regs |= ((0x1 << slot->id) << 16);
3f514291 1089 else
c69042a5 1090 regs &= ~((0x1 << slot->id) << 16);
3f514291
SJ
1091
1092 mci_writel(slot->host, UHS_REG, regs);
f1d2736c 1093 slot->host->timing = ios->timing;
41babf75 1094
fdf492a1
DA
1095 /*
1096 * Use mirror of ios->clock to prevent race with mmc
1097 * core ios update when finding the minimum.
1098 */
1099 slot->clock = ios->clock;
f95f3850 1100
cb27a843
JH
1101 if (drv_data && drv_data->set_ios)
1102 drv_data->set_ios(slot->host, ios);
800d78bf 1103
bf7cb224
JC
1104 /* Slot specific timing and width adjustment */
1105 dw_mci_setup_bus(slot, false);
1106
01730558
DA
1107 if (slot->host->state == STATE_WAITING_CMD11_DONE && ios->clock != 0)
1108 slot->host->state = STATE_IDLE;
1109
f95f3850
WN
1110 switch (ios->power_mode) {
1111 case MMC_POWER_UP:
51da2240
YC
1112 if (!IS_ERR(mmc->supply.vmmc)) {
1113 ret = mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
1114 ios->vdd);
1115 if (ret) {
1116 dev_err(slot->host->dev,
1117 "failed to enable vmmc regulator\n");
1118 /*return, if failed turn on vmmc*/
1119 return;
1120 }
1121 }
1122 if (!IS_ERR(mmc->supply.vqmmc) && !slot->host->vqmmc_enabled) {
1123 ret = regulator_enable(mmc->supply.vqmmc);
1124 if (ret < 0)
1125 dev_err(slot->host->dev,
1126 "failed to enable vqmmc regulator\n");
1127 else
1128 slot->host->vqmmc_enabled = true;
1129 }
f95f3850 1130 set_bit(DW_MMC_CARD_NEED_INIT, &slot->flags);
4366dcc5
JC
1131 regs = mci_readl(slot->host, PWREN);
1132 regs |= (1 << slot->id);
1133 mci_writel(slot->host, PWREN, regs);
e6f34e2f
JH
1134 break;
1135 case MMC_POWER_OFF:
51da2240
YC
1136 if (!IS_ERR(mmc->supply.vmmc))
1137 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
1138
1139 if (!IS_ERR(mmc->supply.vqmmc) && slot->host->vqmmc_enabled) {
1140 regulator_disable(mmc->supply.vqmmc);
1141 slot->host->vqmmc_enabled = false;
1142 }
1143
4366dcc5
JC
1144 regs = mci_readl(slot->host, PWREN);
1145 regs &= ~(1 << slot->id);
1146 mci_writel(slot->host, PWREN, regs);
f95f3850
WN
1147 break;
1148 default:
1149 break;
1150 }
1151}
1152
01730558
DA
1153static int dw_mci_card_busy(struct mmc_host *mmc)
1154{
1155 struct dw_mci_slot *slot = mmc_priv(mmc);
1156 u32 status;
1157
1158 /*
1159 * Check the busy bit which is low when DAT[3:0]
1160 * (the data lines) are 0000
1161 */
1162 status = mci_readl(slot->host, STATUS);
1163
1164 return !!(status & SDMMC_STATUS_BUSY);
1165}
1166
1167static int dw_mci_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios)
1168{
1169 struct dw_mci_slot *slot = mmc_priv(mmc);
1170 struct dw_mci *host = slot->host;
1171 u32 uhs;
1172 u32 v18 = SDMMC_UHS_18V << slot->id;
1173 int min_uv, max_uv;
1174 int ret;
1175
1176 /*
1177 * Program the voltage. Note that some instances of dw_mmc may use
1178 * the UHS_REG for this. For other instances (like exynos) the UHS_REG
1179 * does no harm but you need to set the regulator directly. Try both.
1180 */
1181 uhs = mci_readl(host, UHS_REG);
1182 if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330) {
1183 min_uv = 2700000;
1184 max_uv = 3600000;
1185 uhs &= ~v18;
1186 } else {
1187 min_uv = 1700000;
1188 max_uv = 1950000;
1189 uhs |= v18;
1190 }
1191 if (!IS_ERR(mmc->supply.vqmmc)) {
1192 ret = regulator_set_voltage(mmc->supply.vqmmc, min_uv, max_uv);
1193
1194 if (ret) {
b19caf37 1195 dev_dbg(&mmc->class_dev,
01730558
DA
1196 "Regulator set error %d: %d - %d\n",
1197 ret, min_uv, max_uv);
1198 return ret;
1199 }
1200 }
1201 mci_writel(host, UHS_REG, uhs);
1202
1203 return 0;
1204}
1205
f95f3850
WN
1206static int dw_mci_get_ro(struct mmc_host *mmc)
1207{
1208 int read_only;
1209 struct dw_mci_slot *slot = mmc_priv(mmc);
9795a846 1210 int gpio_ro = mmc_gpio_get_ro(mmc);
f95f3850
WN
1211
1212 /* Use platform get_ro function, else try on board write protect */
26375b5c
JC
1213 if ((slot->quirks & DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT) ||
1214 (slot->host->quirks & DW_MCI_QUIRK_NO_WRITE_PROTECT))
b4967aa5 1215 read_only = 0;
9795a846
JC
1216 else if (!IS_ERR_VALUE(gpio_ro))
1217 read_only = gpio_ro;
f95f3850
WN
1218 else
1219 read_only =
1220 mci_readl(slot->host, WRTPRT) & (1 << slot->id) ? 1 : 0;
1221
1222 dev_dbg(&mmc->class_dev, "card is %s\n",
1223 read_only ? "read-only" : "read-write");
1224
1225 return read_only;
1226}
1227
1228static int dw_mci_get_cd(struct mmc_host *mmc)
1229{
1230 int present;
1231 struct dw_mci_slot *slot = mmc_priv(mmc);
1232 struct dw_mci_board *brd = slot->host->pdata;
7cf347bd
ZG
1233 struct dw_mci *host = slot->host;
1234 int gpio_cd = mmc_gpio_get_cd(mmc);
f95f3850
WN
1235
1236 /* Use platform get_cd function, else try onboard card detect */
fc3d7720
JC
1237 if (brd->quirks & DW_MCI_QUIRK_BROKEN_CARD_DETECTION)
1238 present = 1;
bf626e55 1239 else if (!IS_ERR_VALUE(gpio_cd))
7cf347bd 1240 present = gpio_cd;
f95f3850
WN
1241 else
1242 present = (mci_readl(slot->host, CDETECT) & (1 << slot->id))
1243 == 0 ? 1 : 0;
1244
7cf347bd 1245 spin_lock_bh(&host->lock);
bf626e55
ZG
1246 if (present) {
1247 set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
f95f3850 1248 dev_dbg(&mmc->class_dev, "card is present\n");
bf626e55
ZG
1249 } else {
1250 clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
f95f3850 1251 dev_dbg(&mmc->class_dev, "card is not present\n");
bf626e55 1252 }
7cf347bd 1253 spin_unlock_bh(&host->lock);
f95f3850
WN
1254
1255 return present;
1256}
1257
b24c8b26 1258static void dw_mci_init_card(struct mmc_host *mmc, struct mmc_card *card)
9623b5b9 1259{
b24c8b26 1260 struct dw_mci_slot *slot = mmc_priv(mmc);
9623b5b9 1261 struct dw_mci *host = slot->host;
9623b5b9 1262
b24c8b26
DA
1263 /*
1264 * Low power mode will stop the card clock when idle. According to the
1265 * description of the CLKENA register we should disable low power mode
1266 * for SDIO cards if we need SDIO interrupts to work.
1267 */
1268 if (mmc->caps & MMC_CAP_SDIO_IRQ) {
1269 const u32 clken_low_pwr = SDMMC_CLKEN_LOW_PWR << slot->id;
1270 u32 clk_en_a_old;
1271 u32 clk_en_a;
9623b5b9 1272
b24c8b26
DA
1273 clk_en_a_old = mci_readl(host, CLKENA);
1274
1275 if (card->type == MMC_TYPE_SDIO ||
1276 card->type == MMC_TYPE_SD_COMBO) {
1277 set_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags);
1278 clk_en_a = clk_en_a_old & ~clken_low_pwr;
1279 } else {
1280 clear_bit(DW_MMC_CARD_NO_LOW_PWR, &slot->flags);
1281 clk_en_a = clk_en_a_old | clken_low_pwr;
1282 }
1283
1284 if (clk_en_a != clk_en_a_old) {
1285 mci_writel(host, CLKENA, clk_en_a);
1286 mci_send_cmd(slot, SDMMC_CMD_UPD_CLK |
1287 SDMMC_CMD_PRV_DAT_WAIT, 0);
1288 }
9623b5b9
DA
1289 }
1290}
1291
1a5c8e1f
SH
1292static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb)
1293{
1294 struct dw_mci_slot *slot = mmc_priv(mmc);
1295 struct dw_mci *host = slot->host;
f8c58c11 1296 unsigned long irqflags;
1a5c8e1f
SH
1297 u32 int_mask;
1298
f8c58c11
DA
1299 spin_lock_irqsave(&host->irq_lock, irqflags);
1300
1a5c8e1f
SH
1301 /* Enable/disable Slot Specific SDIO interrupt */
1302 int_mask = mci_readl(host, INTMASK);
b24c8b26
DA
1303 if (enb)
1304 int_mask |= SDMMC_INT_SDIO(slot->sdio_id);
1305 else
1306 int_mask &= ~SDMMC_INT_SDIO(slot->sdio_id);
1307 mci_writel(host, INTMASK, int_mask);
f8c58c11
DA
1308
1309 spin_unlock_irqrestore(&host->irq_lock, irqflags);
1a5c8e1f
SH
1310}
1311
0976f16d
SJ
1312static int dw_mci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1313{
1314 struct dw_mci_slot *slot = mmc_priv(mmc);
1315 struct dw_mci *host = slot->host;
1316 const struct dw_mci_drv_data *drv_data = host->drv_data;
0976f16d
SJ
1317 int err = -ENOSYS;
1318
0976f16d 1319 if (drv_data && drv_data->execute_tuning)
6c2c6506 1320 err = drv_data->execute_tuning(slot);
0976f16d
SJ
1321 return err;
1322}
1323
f95f3850 1324static const struct mmc_host_ops dw_mci_ops = {
1a5c8e1f 1325 .request = dw_mci_request,
9aa51408
SJ
1326 .pre_req = dw_mci_pre_req,
1327 .post_req = dw_mci_post_req,
1a5c8e1f
SH
1328 .set_ios = dw_mci_set_ios,
1329 .get_ro = dw_mci_get_ro,
1330 .get_cd = dw_mci_get_cd,
1331 .enable_sdio_irq = dw_mci_enable_sdio_irq,
0976f16d 1332 .execute_tuning = dw_mci_execute_tuning,
01730558
DA
1333 .card_busy = dw_mci_card_busy,
1334 .start_signal_voltage_switch = dw_mci_switch_voltage,
b24c8b26 1335 .init_card = dw_mci_init_card,
f95f3850
WN
1336};
1337
1338static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
1339 __releases(&host->lock)
1340 __acquires(&host->lock)
1341{
1342 struct dw_mci_slot *slot;
1343 struct mmc_host *prev_mmc = host->cur_slot->mmc;
1344
1345 WARN_ON(host->cmd || host->data);
1346
1347 host->cur_slot->mrq = NULL;
1348 host->mrq = NULL;
1349 if (!list_empty(&host->queue)) {
1350 slot = list_entry(host->queue.next,
1351 struct dw_mci_slot, queue_node);
1352 list_del(&slot->queue_node);
4a90920c 1353 dev_vdbg(host->dev, "list not empty: %s is next\n",
f95f3850
WN
1354 mmc_hostname(slot->mmc));
1355 host->state = STATE_SENDING_CMD;
1356 dw_mci_start_request(host, slot);
1357 } else {
4a90920c 1358 dev_vdbg(host->dev, "list empty\n");
01730558
DA
1359
1360 if (host->state == STATE_SENDING_CMD11)
1361 host->state = STATE_WAITING_CMD11_DONE;
1362 else
1363 host->state = STATE_IDLE;
f95f3850
WN
1364 }
1365
1366 spin_unlock(&host->lock);
1367 mmc_request_done(prev_mmc, mrq);
1368 spin_lock(&host->lock);
1369}
1370
e352c813 1371static int dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd)
f95f3850
WN
1372{
1373 u32 status = host->cmd_status;
1374
1375 host->cmd_status = 0;
1376
1377 /* Read the response from the card (up to 16 bytes) */
1378 if (cmd->flags & MMC_RSP_PRESENT) {
1379 if (cmd->flags & MMC_RSP_136) {
1380 cmd->resp[3] = mci_readl(host, RESP0);
1381 cmd->resp[2] = mci_readl(host, RESP1);
1382 cmd->resp[1] = mci_readl(host, RESP2);
1383 cmd->resp[0] = mci_readl(host, RESP3);
1384 } else {
1385 cmd->resp[0] = mci_readl(host, RESP0);
1386 cmd->resp[1] = 0;
1387 cmd->resp[2] = 0;
1388 cmd->resp[3] = 0;
1389 }
1390 }
1391
1392 if (status & SDMMC_INT_RTO)
1393 cmd->error = -ETIMEDOUT;
1394 else if ((cmd->flags & MMC_RSP_CRC) && (status & SDMMC_INT_RCRC))
1395 cmd->error = -EILSEQ;
1396 else if (status & SDMMC_INT_RESP_ERR)
1397 cmd->error = -EIO;
1398 else
1399 cmd->error = 0;
1400
1401 if (cmd->error) {
1402 /* newer ip versions need a delay between retries */
1403 if (host->quirks & DW_MCI_QUIRK_RETRY_DELAY)
1404 mdelay(20);
f95f3850 1405 }
e352c813
SJ
1406
1407 return cmd->error;
1408}
1409
1410static int dw_mci_data_complete(struct dw_mci *host, struct mmc_data *data)
1411{
31bff450 1412 u32 status = host->data_status;
e352c813
SJ
1413
1414 if (status & DW_MCI_DATA_ERROR_FLAGS) {
1415 if (status & SDMMC_INT_DRTO) {
1416 data->error = -ETIMEDOUT;
1417 } else if (status & SDMMC_INT_DCRC) {
1418 data->error = -EILSEQ;
1419 } else if (status & SDMMC_INT_EBE) {
1420 if (host->dir_status ==
1421 DW_MCI_SEND_STATUS) {
1422 /*
1423 * No data CRC status was returned.
1424 * The number of bytes transferred
1425 * will be exaggerated in PIO mode.
1426 */
1427 data->bytes_xfered = 0;
1428 data->error = -ETIMEDOUT;
1429 } else if (host->dir_status ==
1430 DW_MCI_RECV_STATUS) {
1431 data->error = -EIO;
1432 }
1433 } else {
1434 /* SDMMC_INT_SBE is included */
1435 data->error = -EIO;
1436 }
1437
e6cc0123 1438 dev_dbg(host->dev, "data error, status 0x%08x\n", status);
e352c813
SJ
1439
1440 /*
1441 * After an error, there may be data lingering
31bff450 1442 * in the FIFO
e352c813 1443 */
3a33a94c 1444 dw_mci_reset(host);
e352c813
SJ
1445 } else {
1446 data->bytes_xfered = data->blocks * data->blksz;
1447 data->error = 0;
1448 }
1449
1450 return data->error;
f95f3850
WN
1451}
1452
1453static void dw_mci_tasklet_func(unsigned long priv)
1454{
1455 struct dw_mci *host = (struct dw_mci *)priv;
1456 struct mmc_data *data;
1457 struct mmc_command *cmd;
e352c813 1458 struct mmc_request *mrq;
f95f3850
WN
1459 enum dw_mci_state state;
1460 enum dw_mci_state prev_state;
e352c813 1461 unsigned int err;
f95f3850
WN
1462
1463 spin_lock(&host->lock);
1464
1465 state = host->state;
1466 data = host->data;
e352c813 1467 mrq = host->mrq;
f95f3850
WN
1468
1469 do {
1470 prev_state = state;
1471
1472 switch (state) {
1473 case STATE_IDLE:
01730558 1474 case STATE_WAITING_CMD11_DONE:
f95f3850
WN
1475 break;
1476
01730558 1477 case STATE_SENDING_CMD11:
f95f3850
WN
1478 case STATE_SENDING_CMD:
1479 if (!test_and_clear_bit(EVENT_CMD_COMPLETE,
1480 &host->pending_events))
1481 break;
1482
1483 cmd = host->cmd;
1484 host->cmd = NULL;
1485 set_bit(EVENT_CMD_COMPLETE, &host->completed_events);
e352c813
SJ
1486 err = dw_mci_command_complete(host, cmd);
1487 if (cmd == mrq->sbc && !err) {
053b3ce6
SJ
1488 prev_state = state = STATE_SENDING_CMD;
1489 __dw_mci_start_request(host, host->cur_slot,
e352c813 1490 mrq->cmd);
053b3ce6
SJ
1491 goto unlock;
1492 }
1493
e352c813 1494 if (cmd->data && err) {
71abb133 1495 dw_mci_stop_dma(host);
90c2143a
SJ
1496 send_stop_abort(host, data);
1497 state = STATE_SENDING_STOP;
1498 break;
71abb133
SJ
1499 }
1500
e352c813
SJ
1501 if (!cmd->data || err) {
1502 dw_mci_request_end(host, mrq);
f95f3850
WN
1503 goto unlock;
1504 }
1505
1506 prev_state = state = STATE_SENDING_DATA;
1507 /* fall through */
1508
1509 case STATE_SENDING_DATA:
2aa35465
DA
1510 /*
1511 * We could get a data error and never a transfer
1512 * complete so we'd better check for it here.
1513 *
1514 * Note that we don't really care if we also got a
1515 * transfer complete; stopping the DMA and sending an
1516 * abort won't hurt.
1517 */
f95f3850
WN
1518 if (test_and_clear_bit(EVENT_DATA_ERROR,
1519 &host->pending_events)) {
1520 dw_mci_stop_dma(host);
90c2143a 1521 send_stop_abort(host, data);
f95f3850
WN
1522 state = STATE_DATA_ERROR;
1523 break;
1524 }
1525
1526 if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
1527 &host->pending_events))
1528 break;
1529
1530 set_bit(EVENT_XFER_COMPLETE, &host->completed_events);
2aa35465
DA
1531
1532 /*
1533 * Handle an EVENT_DATA_ERROR that might have shown up
1534 * before the transfer completed. This might not have
1535 * been caught by the check above because the interrupt
1536 * could have gone off between the previous check and
1537 * the check for transfer complete.
1538 *
1539 * Technically this ought not be needed assuming we
1540 * get a DATA_COMPLETE eventually (we'll notice the
1541 * error and end the request), but it shouldn't hurt.
1542 *
1543 * This has the advantage of sending the stop command.
1544 */
1545 if (test_and_clear_bit(EVENT_DATA_ERROR,
1546 &host->pending_events)) {
1547 dw_mci_stop_dma(host);
1548 send_stop_abort(host, data);
1549 state = STATE_DATA_ERROR;
1550 break;
1551 }
f95f3850 1552 prev_state = state = STATE_DATA_BUSY;
2aa35465 1553
f95f3850
WN
1554 /* fall through */
1555
1556 case STATE_DATA_BUSY:
1557 if (!test_and_clear_bit(EVENT_DATA_COMPLETE,
1558 &host->pending_events))
1559 break;
1560
1561 host->data = NULL;
1562 set_bit(EVENT_DATA_COMPLETE, &host->completed_events);
e352c813
SJ
1563 err = dw_mci_data_complete(host, data);
1564
1565 if (!err) {
1566 if (!data->stop || mrq->sbc) {
17c8bc85 1567 if (mrq->sbc && data->stop)
e352c813
SJ
1568 data->stop->error = 0;
1569 dw_mci_request_end(host, mrq);
1570 goto unlock;
f95f3850 1571 }
f95f3850 1572
e352c813
SJ
1573 /* stop command for open-ended transfer*/
1574 if (data->stop)
1575 send_stop_abort(host, data);
2aa35465
DA
1576 } else {
1577 /*
1578 * If we don't have a command complete now we'll
1579 * never get one since we just reset everything;
1580 * better end the request.
1581 *
1582 * If we do have a command complete we'll fall
1583 * through to the SENDING_STOP command and
1584 * everything will be peachy keen.
1585 */
1586 if (!test_bit(EVENT_CMD_COMPLETE,
1587 &host->pending_events)) {
1588 host->cmd = NULL;
1589 dw_mci_request_end(host, mrq);
1590 goto unlock;
1591 }
053b3ce6
SJ
1592 }
1593
e352c813
SJ
1594 /*
1595 * If err has non-zero,
1596 * stop-abort command has been already issued.
1597 */
f95f3850 1598 prev_state = state = STATE_SENDING_STOP;
e352c813 1599
f95f3850
WN
1600 /* fall through */
1601
1602 case STATE_SENDING_STOP:
1603 if (!test_and_clear_bit(EVENT_CMD_COMPLETE,
1604 &host->pending_events))
1605 break;
1606
71abb133 1607 /* CMD error in data command */
31bff450 1608 if (mrq->cmd->error && mrq->data)
3a33a94c 1609 dw_mci_reset(host);
71abb133 1610
f95f3850 1611 host->cmd = NULL;
71abb133 1612 host->data = NULL;
90c2143a 1613
e352c813
SJ
1614 if (mrq->stop)
1615 dw_mci_command_complete(host, mrq->stop);
90c2143a
SJ
1616 else
1617 host->cmd_status = 0;
1618
e352c813 1619 dw_mci_request_end(host, mrq);
f95f3850
WN
1620 goto unlock;
1621
1622 case STATE_DATA_ERROR:
1623 if (!test_and_clear_bit(EVENT_XFER_COMPLETE,
1624 &host->pending_events))
1625 break;
1626
1627 state = STATE_DATA_BUSY;
1628 break;
1629 }
1630 } while (state != prev_state);
1631
1632 host->state = state;
1633unlock:
1634 spin_unlock(&host->lock);
1635
1636}
1637
34b664a2
JH
1638/* push final bytes to part_buf, only use during push */
1639static void dw_mci_set_part_bytes(struct dw_mci *host, void *buf, int cnt)
f95f3850 1640{
34b664a2
JH
1641 memcpy((void *)&host->part_buf, buf, cnt);
1642 host->part_buf_count = cnt;
1643}
f95f3850 1644
34b664a2
JH
1645/* append bytes to part_buf, only use during push */
1646static int dw_mci_push_part_bytes(struct dw_mci *host, void *buf, int cnt)
1647{
1648 cnt = min(cnt, (1 << host->data_shift) - host->part_buf_count);
1649 memcpy((void *)&host->part_buf + host->part_buf_count, buf, cnt);
1650 host->part_buf_count += cnt;
1651 return cnt;
1652}
f95f3850 1653
34b664a2
JH
1654/* pull first bytes from part_buf, only use during pull */
1655static int dw_mci_pull_part_bytes(struct dw_mci *host, void *buf, int cnt)
1656{
1657 cnt = min(cnt, (int)host->part_buf_count);
1658 if (cnt) {
1659 memcpy(buf, (void *)&host->part_buf + host->part_buf_start,
1660 cnt);
1661 host->part_buf_count -= cnt;
1662 host->part_buf_start += cnt;
f95f3850 1663 }
34b664a2 1664 return cnt;
f95f3850
WN
1665}
1666
34b664a2
JH
1667/* pull final bytes from the part_buf, assuming it's just been filled */
1668static void dw_mci_pull_final_bytes(struct dw_mci *host, void *buf, int cnt)
f95f3850 1669{
34b664a2
JH
1670 memcpy(buf, &host->part_buf, cnt);
1671 host->part_buf_start = cnt;
1672 host->part_buf_count = (1 << host->data_shift) - cnt;
1673}
f95f3850 1674
34b664a2
JH
1675static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
1676{
cfbeb59c
MC
1677 struct mmc_data *data = host->data;
1678 int init_cnt = cnt;
1679
34b664a2
JH
1680 /* try and push anything in the part_buf */
1681 if (unlikely(host->part_buf_count)) {
1682 int len = dw_mci_push_part_bytes(host, buf, cnt);
1683 buf += len;
1684 cnt -= len;
cfbeb59c 1685 if (host->part_buf_count == 2) {
4e0a5adf
JC
1686 mci_writew(host, DATA(host->data_offset),
1687 host->part_buf16);
34b664a2
JH
1688 host->part_buf_count = 0;
1689 }
1690 }
1691#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1692 if (unlikely((unsigned long)buf & 0x1)) {
1693 while (cnt >= 2) {
1694 u16 aligned_buf[64];
1695 int len = min(cnt & -2, (int)sizeof(aligned_buf));
1696 int items = len >> 1;
1697 int i;
1698 /* memcpy from input buffer into aligned buffer */
1699 memcpy(aligned_buf, buf, len);
1700 buf += len;
1701 cnt -= len;
1702 /* push data from aligned buffer into fifo */
1703 for (i = 0; i < items; ++i)
4e0a5adf
JC
1704 mci_writew(host, DATA(host->data_offset),
1705 aligned_buf[i]);
34b664a2
JH
1706 }
1707 } else
1708#endif
1709 {
1710 u16 *pdata = buf;
1711 for (; cnt >= 2; cnt -= 2)
4e0a5adf 1712 mci_writew(host, DATA(host->data_offset), *pdata++);
34b664a2
JH
1713 buf = pdata;
1714 }
1715 /* put anything remaining in the part_buf */
1716 if (cnt) {
1717 dw_mci_set_part_bytes(host, buf, cnt);
cfbeb59c
MC
1718 /* Push data if we have reached the expected data length */
1719 if ((data->bytes_xfered + init_cnt) ==
1720 (data->blksz * data->blocks))
4e0a5adf 1721 mci_writew(host, DATA(host->data_offset),
cfbeb59c 1722 host->part_buf16);
34b664a2
JH
1723 }
1724}
f95f3850 1725
34b664a2
JH
1726static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
1727{
1728#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1729 if (unlikely((unsigned long)buf & 0x1)) {
1730 while (cnt >= 2) {
1731 /* pull data from fifo into aligned buffer */
1732 u16 aligned_buf[64];
1733 int len = min(cnt & -2, (int)sizeof(aligned_buf));
1734 int items = len >> 1;
1735 int i;
1736 for (i = 0; i < items; ++i)
4e0a5adf
JC
1737 aligned_buf[i] = mci_readw(host,
1738 DATA(host->data_offset));
34b664a2
JH
1739 /* memcpy from aligned buffer into output buffer */
1740 memcpy(buf, aligned_buf, len);
1741 buf += len;
1742 cnt -= len;
1743 }
1744 } else
1745#endif
1746 {
1747 u16 *pdata = buf;
1748 for (; cnt >= 2; cnt -= 2)
4e0a5adf 1749 *pdata++ = mci_readw(host, DATA(host->data_offset));
34b664a2
JH
1750 buf = pdata;
1751 }
1752 if (cnt) {
4e0a5adf 1753 host->part_buf16 = mci_readw(host, DATA(host->data_offset));
34b664a2 1754 dw_mci_pull_final_bytes(host, buf, cnt);
f95f3850
WN
1755 }
1756}
1757
1758static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
1759{
cfbeb59c
MC
1760 struct mmc_data *data = host->data;
1761 int init_cnt = cnt;
1762
34b664a2
JH
1763 /* try and push anything in the part_buf */
1764 if (unlikely(host->part_buf_count)) {
1765 int len = dw_mci_push_part_bytes(host, buf, cnt);
1766 buf += len;
1767 cnt -= len;
cfbeb59c 1768 if (host->part_buf_count == 4) {
4e0a5adf
JC
1769 mci_writel(host, DATA(host->data_offset),
1770 host->part_buf32);
34b664a2
JH
1771 host->part_buf_count = 0;
1772 }
1773 }
1774#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1775 if (unlikely((unsigned long)buf & 0x3)) {
1776 while (cnt >= 4) {
1777 u32 aligned_buf[32];
1778 int len = min(cnt & -4, (int)sizeof(aligned_buf));
1779 int items = len >> 2;
1780 int i;
1781 /* memcpy from input buffer into aligned buffer */
1782 memcpy(aligned_buf, buf, len);
1783 buf += len;
1784 cnt -= len;
1785 /* push data from aligned buffer into fifo */
1786 for (i = 0; i < items; ++i)
4e0a5adf
JC
1787 mci_writel(host, DATA(host->data_offset),
1788 aligned_buf[i]);
34b664a2
JH
1789 }
1790 } else
1791#endif
1792 {
1793 u32 *pdata = buf;
1794 for (; cnt >= 4; cnt -= 4)
4e0a5adf 1795 mci_writel(host, DATA(host->data_offset), *pdata++);
34b664a2
JH
1796 buf = pdata;
1797 }
1798 /* put anything remaining in the part_buf */
1799 if (cnt) {
1800 dw_mci_set_part_bytes(host, buf, cnt);
cfbeb59c
MC
1801 /* Push data if we have reached the expected data length */
1802 if ((data->bytes_xfered + init_cnt) ==
1803 (data->blksz * data->blocks))
4e0a5adf 1804 mci_writel(host, DATA(host->data_offset),
cfbeb59c 1805 host->part_buf32);
f95f3850
WN
1806 }
1807}
1808
1809static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
1810{
34b664a2
JH
1811#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1812 if (unlikely((unsigned long)buf & 0x3)) {
1813 while (cnt >= 4) {
1814 /* pull data from fifo into aligned buffer */
1815 u32 aligned_buf[32];
1816 int len = min(cnt & -4, (int)sizeof(aligned_buf));
1817 int items = len >> 2;
1818 int i;
1819 for (i = 0; i < items; ++i)
4e0a5adf
JC
1820 aligned_buf[i] = mci_readl(host,
1821 DATA(host->data_offset));
34b664a2
JH
1822 /* memcpy from aligned buffer into output buffer */
1823 memcpy(buf, aligned_buf, len);
1824 buf += len;
1825 cnt -= len;
1826 }
1827 } else
1828#endif
1829 {
1830 u32 *pdata = buf;
1831 for (; cnt >= 4; cnt -= 4)
4e0a5adf 1832 *pdata++ = mci_readl(host, DATA(host->data_offset));
34b664a2
JH
1833 buf = pdata;
1834 }
1835 if (cnt) {
4e0a5adf 1836 host->part_buf32 = mci_readl(host, DATA(host->data_offset));
34b664a2 1837 dw_mci_pull_final_bytes(host, buf, cnt);
f95f3850
WN
1838 }
1839}
1840
1841static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
1842{
cfbeb59c
MC
1843 struct mmc_data *data = host->data;
1844 int init_cnt = cnt;
1845
34b664a2
JH
1846 /* try and push anything in the part_buf */
1847 if (unlikely(host->part_buf_count)) {
1848 int len = dw_mci_push_part_bytes(host, buf, cnt);
1849 buf += len;
1850 cnt -= len;
c09fbd74 1851
cfbeb59c 1852 if (host->part_buf_count == 8) {
c09fbd74 1853 mci_writeq(host, DATA(host->data_offset),
4e0a5adf 1854 host->part_buf);
34b664a2
JH
1855 host->part_buf_count = 0;
1856 }
1857 }
1858#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1859 if (unlikely((unsigned long)buf & 0x7)) {
1860 while (cnt >= 8) {
1861 u64 aligned_buf[16];
1862 int len = min(cnt & -8, (int)sizeof(aligned_buf));
1863 int items = len >> 3;
1864 int i;
1865 /* memcpy from input buffer into aligned buffer */
1866 memcpy(aligned_buf, buf, len);
1867 buf += len;
1868 cnt -= len;
1869 /* push data from aligned buffer into fifo */
1870 for (i = 0; i < items; ++i)
4e0a5adf
JC
1871 mci_writeq(host, DATA(host->data_offset),
1872 aligned_buf[i]);
34b664a2
JH
1873 }
1874 } else
1875#endif
1876 {
1877 u64 *pdata = buf;
1878 for (; cnt >= 8; cnt -= 8)
4e0a5adf 1879 mci_writeq(host, DATA(host->data_offset), *pdata++);
34b664a2
JH
1880 buf = pdata;
1881 }
1882 /* put anything remaining in the part_buf */
1883 if (cnt) {
1884 dw_mci_set_part_bytes(host, buf, cnt);
cfbeb59c
MC
1885 /* Push data if we have reached the expected data length */
1886 if ((data->bytes_xfered + init_cnt) ==
1887 (data->blksz * data->blocks))
4e0a5adf 1888 mci_writeq(host, DATA(host->data_offset),
cfbeb59c 1889 host->part_buf);
f95f3850
WN
1890 }
1891}
1892
1893static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
1894{
34b664a2
JH
1895#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
1896 if (unlikely((unsigned long)buf & 0x7)) {
1897 while (cnt >= 8) {
1898 /* pull data from fifo into aligned buffer */
1899 u64 aligned_buf[16];
1900 int len = min(cnt & -8, (int)sizeof(aligned_buf));
1901 int items = len >> 3;
1902 int i;
1903 for (i = 0; i < items; ++i)
4e0a5adf
JC
1904 aligned_buf[i] = mci_readq(host,
1905 DATA(host->data_offset));
34b664a2
JH
1906 /* memcpy from aligned buffer into output buffer */
1907 memcpy(buf, aligned_buf, len);
1908 buf += len;
1909 cnt -= len;
1910 }
1911 } else
1912#endif
1913 {
1914 u64 *pdata = buf;
1915 for (; cnt >= 8; cnt -= 8)
4e0a5adf 1916 *pdata++ = mci_readq(host, DATA(host->data_offset));
34b664a2
JH
1917 buf = pdata;
1918 }
1919 if (cnt) {
4e0a5adf 1920 host->part_buf = mci_readq(host, DATA(host->data_offset));
34b664a2
JH
1921 dw_mci_pull_final_bytes(host, buf, cnt);
1922 }
1923}
f95f3850 1924
34b664a2
JH
1925static void dw_mci_pull_data(struct dw_mci *host, void *buf, int cnt)
1926{
1927 int len;
f95f3850 1928
34b664a2
JH
1929 /* get remaining partial bytes */
1930 len = dw_mci_pull_part_bytes(host, buf, cnt);
1931 if (unlikely(len == cnt))
1932 return;
1933 buf += len;
1934 cnt -= len;
1935
1936 /* get the rest of the data */
1937 host->pull_data(host, buf, cnt);
f95f3850
WN
1938}
1939
87a74d39 1940static void dw_mci_read_data_pio(struct dw_mci *host, bool dto)
f95f3850 1941{
f9c2a0dc
SJ
1942 struct sg_mapping_iter *sg_miter = &host->sg_miter;
1943 void *buf;
1944 unsigned int offset;
f95f3850
WN
1945 struct mmc_data *data = host->data;
1946 int shift = host->data_shift;
1947 u32 status;
3e4b0d8b 1948 unsigned int len;
f9c2a0dc 1949 unsigned int remain, fcnt;
f95f3850
WN
1950
1951 do {
f9c2a0dc
SJ
1952 if (!sg_miter_next(sg_miter))
1953 goto done;
1954
4225fc85 1955 host->sg = sg_miter->piter.sg;
f9c2a0dc
SJ
1956 buf = sg_miter->addr;
1957 remain = sg_miter->length;
1958 offset = 0;
1959
1960 do {
1961 fcnt = (SDMMC_GET_FCNT(mci_readl(host, STATUS))
1962 << shift) + host->part_buf_count;
1963 len = min(remain, fcnt);
1964 if (!len)
1965 break;
34b664a2 1966 dw_mci_pull_data(host, (void *)(buf + offset), len);
3e4b0d8b 1967 data->bytes_xfered += len;
f95f3850 1968 offset += len;
f9c2a0dc
SJ
1969 remain -= len;
1970 } while (remain);
f95f3850 1971
e74f3a9c 1972 sg_miter->consumed = offset;
f95f3850
WN
1973 status = mci_readl(host, MINTSTS);
1974 mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
87a74d39
KK
1975 /* if the RXDR is ready read again */
1976 } while ((status & SDMMC_INT_RXDR) ||
1977 (dto && SDMMC_GET_FCNT(mci_readl(host, STATUS))));
f9c2a0dc
SJ
1978
1979 if (!remain) {
1980 if (!sg_miter_next(sg_miter))
1981 goto done;
1982 sg_miter->consumed = 0;
1983 }
1984 sg_miter_stop(sg_miter);
f95f3850
WN
1985 return;
1986
1987done:
f9c2a0dc
SJ
1988 sg_miter_stop(sg_miter);
1989 host->sg = NULL;
f95f3850
WN
1990 smp_wmb();
1991 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
1992}
1993
1994static void dw_mci_write_data_pio(struct dw_mci *host)
1995{
f9c2a0dc
SJ
1996 struct sg_mapping_iter *sg_miter = &host->sg_miter;
1997 void *buf;
1998 unsigned int offset;
f95f3850
WN
1999 struct mmc_data *data = host->data;
2000 int shift = host->data_shift;
2001 u32 status;
3e4b0d8b 2002 unsigned int len;
f9c2a0dc
SJ
2003 unsigned int fifo_depth = host->fifo_depth;
2004 unsigned int remain, fcnt;
f95f3850
WN
2005
2006 do {
f9c2a0dc
SJ
2007 if (!sg_miter_next(sg_miter))
2008 goto done;
2009
4225fc85 2010 host->sg = sg_miter->piter.sg;
f9c2a0dc
SJ
2011 buf = sg_miter->addr;
2012 remain = sg_miter->length;
2013 offset = 0;
2014
2015 do {
2016 fcnt = ((fifo_depth -
2017 SDMMC_GET_FCNT(mci_readl(host, STATUS)))
2018 << shift) - host->part_buf_count;
2019 len = min(remain, fcnt);
2020 if (!len)
2021 break;
f95f3850 2022 host->push_data(host, (void *)(buf + offset), len);
3e4b0d8b 2023 data->bytes_xfered += len;
f95f3850 2024 offset += len;
f9c2a0dc
SJ
2025 remain -= len;
2026 } while (remain);
f95f3850 2027
e74f3a9c 2028 sg_miter->consumed = offset;
f95f3850
WN
2029 status = mci_readl(host, MINTSTS);
2030 mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
f95f3850 2031 } while (status & SDMMC_INT_TXDR); /* if TXDR write again */
f9c2a0dc
SJ
2032
2033 if (!remain) {
2034 if (!sg_miter_next(sg_miter))
2035 goto done;
2036 sg_miter->consumed = 0;
2037 }
2038 sg_miter_stop(sg_miter);
f95f3850
WN
2039 return;
2040
2041done:
f9c2a0dc
SJ
2042 sg_miter_stop(sg_miter);
2043 host->sg = NULL;
f95f3850
WN
2044 smp_wmb();
2045 set_bit(EVENT_XFER_COMPLETE, &host->pending_events);
2046}
2047
2048static void dw_mci_cmd_interrupt(struct dw_mci *host, u32 status)
2049{
2050 if (!host->cmd_status)
2051 host->cmd_status = status;
2052
2053 smp_wmb();
2054
2055 set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
2056 tasklet_schedule(&host->tasklet);
2057}
2058
6130e7a9
DA
2059static void dw_mci_handle_cd(struct dw_mci *host)
2060{
2061 int i;
2062
2063 for (i = 0; i < host->num_slots; i++) {
2064 struct dw_mci_slot *slot = host->slot[i];
2065
2066 if (!slot)
2067 continue;
2068
2069 if (slot->mmc->ops->card_event)
2070 slot->mmc->ops->card_event(slot->mmc);
2071 mmc_detect_change(slot->mmc,
2072 msecs_to_jiffies(host->pdata->detect_delay_ms));
2073 }
2074}
2075
f95f3850
WN
2076static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
2077{
2078 struct dw_mci *host = dev_id;
182c9081 2079 u32 pending;
1a5c8e1f 2080 int i;
f95f3850 2081
1fb5f68a
MC
2082 pending = mci_readl(host, MINTSTS); /* read-only mask reg */
2083
476d79f1
DA
2084 /*
2085 * DTO fix - version 2.10a and below, and only if internal DMA
2086 * is configured.
2087 */
2088 if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) {
2089 if (!pending &&
2090 ((mci_readl(host, STATUS) >> 17) & 0x1fff))
2091 pending |= SDMMC_INT_DATA_OVER;
2092 }
f95f3850 2093
476d79f1 2094 if (pending) {
01730558
DA
2095 /* Check volt switch first, since it can look like an error */
2096 if ((host->state == STATE_SENDING_CMD11) &&
2097 (pending & SDMMC_INT_VOLT_SWITCH)) {
2098 mci_writel(host, RINTSTS, SDMMC_INT_VOLT_SWITCH);
2099 pending &= ~SDMMC_INT_VOLT_SWITCH;
2100 dw_mci_cmd_interrupt(host, pending);
2101 }
2102
f95f3850
WN
2103 if (pending & DW_MCI_CMD_ERROR_FLAGS) {
2104 mci_writel(host, RINTSTS, DW_MCI_CMD_ERROR_FLAGS);
182c9081 2105 host->cmd_status = pending;
f95f3850
WN
2106 smp_wmb();
2107 set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
f95f3850
WN
2108 }
2109
2110 if (pending & DW_MCI_DATA_ERROR_FLAGS) {
2111 /* if there is an error report DATA_ERROR */
2112 mci_writel(host, RINTSTS, DW_MCI_DATA_ERROR_FLAGS);
182c9081 2113 host->data_status = pending;
f95f3850
WN
2114 smp_wmb();
2115 set_bit(EVENT_DATA_ERROR, &host->pending_events);
9b2026a1 2116 tasklet_schedule(&host->tasklet);
f95f3850
WN
2117 }
2118
2119 if (pending & SDMMC_INT_DATA_OVER) {
2120 mci_writel(host, RINTSTS, SDMMC_INT_DATA_OVER);
2121 if (!host->data_status)
182c9081 2122 host->data_status = pending;
f95f3850
WN
2123 smp_wmb();
2124 if (host->dir_status == DW_MCI_RECV_STATUS) {
2125 if (host->sg != NULL)
87a74d39 2126 dw_mci_read_data_pio(host, true);
f95f3850
WN
2127 }
2128 set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
2129 tasklet_schedule(&host->tasklet);
2130 }
2131
2132 if (pending & SDMMC_INT_RXDR) {
2133 mci_writel(host, RINTSTS, SDMMC_INT_RXDR);
b40af3aa 2134 if (host->dir_status == DW_MCI_RECV_STATUS && host->sg)
87a74d39 2135 dw_mci_read_data_pio(host, false);
f95f3850
WN
2136 }
2137
2138 if (pending & SDMMC_INT_TXDR) {
2139 mci_writel(host, RINTSTS, SDMMC_INT_TXDR);
b40af3aa 2140 if (host->dir_status == DW_MCI_SEND_STATUS && host->sg)
f95f3850
WN
2141 dw_mci_write_data_pio(host);
2142 }
2143
2144 if (pending & SDMMC_INT_CMD_DONE) {
2145 mci_writel(host, RINTSTS, SDMMC_INT_CMD_DONE);
182c9081 2146 dw_mci_cmd_interrupt(host, pending);
f95f3850
WN
2147 }
2148
2149 if (pending & SDMMC_INT_CD) {
2150 mci_writel(host, RINTSTS, SDMMC_INT_CD);
6130e7a9 2151 dw_mci_handle_cd(host);
f95f3850
WN
2152 }
2153
1a5c8e1f
SH
2154 /* Handle SDIO Interrupts */
2155 for (i = 0; i < host->num_slots; i++) {
2156 struct dw_mci_slot *slot = host->slot[i];
76756234
AK
2157 if (pending & SDMMC_INT_SDIO(slot->sdio_id)) {
2158 mci_writel(host, RINTSTS,
2159 SDMMC_INT_SDIO(slot->sdio_id));
1a5c8e1f
SH
2160 mmc_signal_sdio_irq(slot->mmc);
2161 }
2162 }
2163
1fb5f68a 2164 }
f95f3850
WN
2165
2166#ifdef CONFIG_MMC_DW_IDMAC
2167 /* Handle DMA interrupts */
69d99fdc
PT
2168 if (host->dma_64bit_address == 1) {
2169 pending = mci_readl(host, IDSTS64);
2170 if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
2171 mci_writel(host, IDSTS64, SDMMC_IDMAC_INT_TI |
2172 SDMMC_IDMAC_INT_RI);
2173 mci_writel(host, IDSTS64, SDMMC_IDMAC_INT_NI);
2174 host->dma_ops->complete(host);
2175 }
2176 } else {
2177 pending = mci_readl(host, IDSTS);
2178 if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
2179 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI |
2180 SDMMC_IDMAC_INT_RI);
2181 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI);
2182 host->dma_ops->complete(host);
2183 }
f95f3850
WN
2184 }
2185#endif
2186
2187 return IRQ_HANDLED;
2188}
2189
c91eab4b
TA
2190#ifdef CONFIG_OF
2191/* given a slot id, find out the device node representing that slot */
2192static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot)
2193{
2194 struct device_node *np;
2195 const __be32 *addr;
2196 int len;
2197
2198 if (!dev || !dev->of_node)
2199 return NULL;
2200
2201 for_each_child_of_node(dev->of_node, np) {
2202 addr = of_get_property(np, "reg", &len);
2203 if (!addr || (len < sizeof(int)))
2204 continue;
2205 if (be32_to_cpup(addr) == slot)
2206 return np;
2207 }
2208 return NULL;
2209}
2210
a70aaa64
DA
2211static struct dw_mci_of_slot_quirks {
2212 char *quirk;
2213 int id;
2214} of_slot_quirks[] = {
2215 {
2216 .quirk = "disable-wp",
2217 .id = DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT,
2218 },
2219};
2220
2221static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot)
2222{
2223 struct device_node *np = dw_mci_of_find_slot_node(dev, slot);
2224 int quirks = 0;
2225 int idx;
2226
2227 /* get quirks */
2228 for (idx = 0; idx < ARRAY_SIZE(of_slot_quirks); idx++)
26375b5c
JC
2229 if (of_get_property(np, of_slot_quirks[idx].quirk, NULL)) {
2230 dev_warn(dev, "Slot quirk %s is deprecated\n",
2231 of_slot_quirks[idx].quirk);
a70aaa64 2232 quirks |= of_slot_quirks[idx].id;
26375b5c 2233 }
a70aaa64
DA
2234
2235 return quirks;
2236}
c91eab4b 2237#else /* CONFIG_OF */
a70aaa64
DA
2238static int dw_mci_of_get_slot_quirks(struct device *dev, u8 slot)
2239{
2240 return 0;
2241}
c91eab4b
TA
2242#endif /* CONFIG_OF */
2243
36c179a9 2244static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
f95f3850
WN
2245{
2246 struct mmc_host *mmc;
2247 struct dw_mci_slot *slot;
e95baf13 2248 const struct dw_mci_drv_data *drv_data = host->drv_data;
800d78bf 2249 int ctrl_id, ret;
1f44a2a5 2250 u32 freq[2];
f95f3850 2251
4a90920c 2252 mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev);
f95f3850
WN
2253 if (!mmc)
2254 return -ENOMEM;
2255
2256 slot = mmc_priv(mmc);
2257 slot->id = id;
76756234 2258 slot->sdio_id = host->sdio_id0 + id;
f95f3850
WN
2259 slot->mmc = mmc;
2260 slot->host = host;
c91eab4b 2261 host->slot[id] = slot;
f95f3850 2262
a70aaa64
DA
2263 slot->quirks = dw_mci_of_get_slot_quirks(host->dev, slot->id);
2264
f95f3850 2265 mmc->ops = &dw_mci_ops;
1f44a2a5
SJ
2266 if (of_property_read_u32_array(host->dev->of_node,
2267 "clock-freq-min-max", freq, 2)) {
2268 mmc->f_min = DW_MCI_FREQ_MIN;
2269 mmc->f_max = DW_MCI_FREQ_MAX;
2270 } else {
2271 mmc->f_min = freq[0];
2272 mmc->f_max = freq[1];
2273 }
f95f3850 2274
51da2240
YC
2275 /*if there are external regulators, get them*/
2276 ret = mmc_regulator_get_supply(mmc);
2277 if (ret == -EPROBE_DEFER)
3cf890fc 2278 goto err_host_allocated;
51da2240
YC
2279
2280 if (!mmc->ocr_avail)
2281 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
f95f3850 2282
fc3d7720
JC
2283 if (host->pdata->caps)
2284 mmc->caps = host->pdata->caps;
fc3d7720 2285
ab269128
AK
2286 if (host->pdata->pm_caps)
2287 mmc->pm_caps = host->pdata->pm_caps;
2288
800d78bf
TA
2289 if (host->dev->of_node) {
2290 ctrl_id = of_alias_get_id(host->dev->of_node, "mshc");
2291 if (ctrl_id < 0)
2292 ctrl_id = 0;
2293 } else {
2294 ctrl_id = to_platform_device(host->dev)->id;
2295 }
cb27a843
JH
2296 if (drv_data && drv_data->caps)
2297 mmc->caps |= drv_data->caps[ctrl_id];
800d78bf 2298
4f408cc6
SJ
2299 if (host->pdata->caps2)
2300 mmc->caps2 = host->pdata->caps2;
4f408cc6 2301
3cf890fc
DA
2302 ret = mmc_of_parse(mmc);
2303 if (ret)
2304 goto err_host_allocated;
f95f3850 2305
f95f3850
WN
2306 if (host->pdata->blk_settings) {
2307 mmc->max_segs = host->pdata->blk_settings->max_segs;
2308 mmc->max_blk_size = host->pdata->blk_settings->max_blk_size;
2309 mmc->max_blk_count = host->pdata->blk_settings->max_blk_count;
2310 mmc->max_req_size = host->pdata->blk_settings->max_req_size;
2311 mmc->max_seg_size = host->pdata->blk_settings->max_seg_size;
2312 } else {
2313 /* Useful defaults if platform data is unset. */
a39e5746
JC
2314#ifdef CONFIG_MMC_DW_IDMAC
2315 mmc->max_segs = host->ring_size;
2316 mmc->max_blk_size = 65536;
a39e5746 2317 mmc->max_seg_size = 0x1000;
1a25b1b4
SJ
2318 mmc->max_req_size = mmc->max_seg_size * host->ring_size;
2319 mmc->max_blk_count = mmc->max_req_size / 512;
a39e5746 2320#else
f95f3850
WN
2321 mmc->max_segs = 64;
2322 mmc->max_blk_size = 65536; /* BLKSIZ is 16 bits */
2323 mmc->max_blk_count = 512;
2324 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
2325 mmc->max_seg_size = mmc->max_req_size;
f95f3850 2326#endif /* CONFIG_MMC_DW_IDMAC */
a39e5746 2327 }
f95f3850 2328
ae0eb348
JC
2329 if (dw_mci_get_cd(mmc))
2330 set_bit(DW_MMC_CARD_PRESENT, &slot->flags);
2331 else
2332 clear_bit(DW_MMC_CARD_PRESENT, &slot->flags);
2333
0cea529d
JC
2334 ret = mmc_add_host(mmc);
2335 if (ret)
3cf890fc 2336 goto err_host_allocated;
f95f3850
WN
2337
2338#if defined(CONFIG_DEBUG_FS)
2339 dw_mci_init_debugfs(slot);
2340#endif
2341
f95f3850 2342 return 0;
800d78bf 2343
3cf890fc 2344err_host_allocated:
800d78bf 2345 mmc_free_host(mmc);
51da2240 2346 return ret;
f95f3850
WN
2347}
2348
2349static void dw_mci_cleanup_slot(struct dw_mci_slot *slot, unsigned int id)
2350{
f95f3850
WN
2351 /* Debugfs stuff is cleaned up by mmc core */
2352 mmc_remove_host(slot->mmc);
2353 slot->host->slot[id] = NULL;
2354 mmc_free_host(slot->mmc);
2355}
2356
2357static void dw_mci_init_dma(struct dw_mci *host)
2358{
69d99fdc
PT
2359 int addr_config;
2360 /* Check ADDR_CONFIG bit in HCON to find IDMAC address bus width */
2361 addr_config = (mci_readl(host, HCON) >> 27) & 0x01;
2362
2363 if (addr_config == 1) {
2364 /* host supports IDMAC in 64-bit address mode */
2365 host->dma_64bit_address = 1;
2366 dev_info(host->dev, "IDMAC supports 64-bit address mode.\n");
2367 if (!dma_set_mask(host->dev, DMA_BIT_MASK(64)))
2368 dma_set_coherent_mask(host->dev, DMA_BIT_MASK(64));
2369 } else {
2370 /* host supports IDMAC in 32-bit address mode */
2371 host->dma_64bit_address = 0;
2372 dev_info(host->dev, "IDMAC supports 32-bit address mode.\n");
2373 }
2374
f95f3850 2375 /* Alloc memory for sg translation */
780f22af 2376 host->sg_cpu = dmam_alloc_coherent(host->dev, PAGE_SIZE,
f95f3850
WN
2377 &host->sg_dma, GFP_KERNEL);
2378 if (!host->sg_cpu) {
4a90920c 2379 dev_err(host->dev, "%s: could not alloc DMA memory\n",
f95f3850
WN
2380 __func__);
2381 goto no_dma;
2382 }
2383
2384 /* Determine which DMA interface to use */
2385#ifdef CONFIG_MMC_DW_IDMAC
2386 host->dma_ops = &dw_mci_idmac_ops;
00956ea3 2387 dev_info(host->dev, "Using internal DMA controller.\n");
f95f3850
WN
2388#endif
2389
2390 if (!host->dma_ops)
2391 goto no_dma;
2392
e1631f98
JC
2393 if (host->dma_ops->init && host->dma_ops->start &&
2394 host->dma_ops->stop && host->dma_ops->cleanup) {
f95f3850 2395 if (host->dma_ops->init(host)) {
4a90920c 2396 dev_err(host->dev, "%s: Unable to initialize "
f95f3850
WN
2397 "DMA Controller.\n", __func__);
2398 goto no_dma;
2399 }
2400 } else {
4a90920c 2401 dev_err(host->dev, "DMA initialization not found.\n");
f95f3850
WN
2402 goto no_dma;
2403 }
2404
2405 host->use_dma = 1;
2406 return;
2407
2408no_dma:
4a90920c 2409 dev_info(host->dev, "Using PIO mode.\n");
f95f3850
WN
2410 host->use_dma = 0;
2411 return;
2412}
2413
31bff450 2414static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset)
f95f3850
WN
2415{
2416 unsigned long timeout = jiffies + msecs_to_jiffies(500);
31bff450 2417 u32 ctrl;
f95f3850 2418
31bff450
SJ
2419 ctrl = mci_readl(host, CTRL);
2420 ctrl |= reset;
2421 mci_writel(host, CTRL, ctrl);
f95f3850
WN
2422
2423 /* wait till resets clear */
2424 do {
2425 ctrl = mci_readl(host, CTRL);
31bff450 2426 if (!(ctrl & reset))
f95f3850
WN
2427 return true;
2428 } while (time_before(jiffies, timeout));
2429
31bff450
SJ
2430 dev_err(host->dev,
2431 "Timeout resetting block (ctrl reset %#x)\n",
2432 ctrl & reset);
f95f3850
WN
2433
2434 return false;
2435}
2436
3a33a94c 2437static bool dw_mci_reset(struct dw_mci *host)
31bff450 2438{
3a33a94c
SR
2439 u32 flags = SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET;
2440 bool ret = false;
2441
31bff450
SJ
2442 /*
2443 * Reseting generates a block interrupt, hence setting
2444 * the scatter-gather pointer to NULL.
2445 */
2446 if (host->sg) {
2447 sg_miter_stop(&host->sg_miter);
2448 host->sg = NULL;
2449 }
2450
3a33a94c
SR
2451 if (host->use_dma)
2452 flags |= SDMMC_CTRL_DMA_RESET;
31bff450 2453
3a33a94c
SR
2454 if (dw_mci_ctrl_reset(host, flags)) {
2455 /*
2456 * In all cases we clear the RAWINTS register to clear any
2457 * interrupts.
2458 */
2459 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2460
2461 /* if using dma we wait for dma_req to clear */
2462 if (host->use_dma) {
2463 unsigned long timeout = jiffies + msecs_to_jiffies(500);
2464 u32 status;
2465 do {
2466 status = mci_readl(host, STATUS);
2467 if (!(status & SDMMC_STATUS_DMA_REQ))
2468 break;
2469 cpu_relax();
2470 } while (time_before(jiffies, timeout));
2471
2472 if (status & SDMMC_STATUS_DMA_REQ) {
2473 dev_err(host->dev,
2474 "%s: Timeout waiting for dma_req to "
2475 "clear during reset\n", __func__);
2476 goto ciu_out;
2477 }
2478
2479 /* when using DMA next we reset the fifo again */
2480 if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_FIFO_RESET))
2481 goto ciu_out;
2482 }
2483 } else {
2484 /* if the controller reset bit did clear, then set clock regs */
2485 if (!(mci_readl(host, CTRL) & SDMMC_CTRL_RESET)) {
2486 dev_err(host->dev, "%s: fifo/dma reset bits didn't "
2487 "clear but ciu was reset, doing clock update\n",
2488 __func__);
2489 goto ciu_out;
2490 }
2491 }
2492
2493#if IS_ENABLED(CONFIG_MMC_DW_IDMAC)
2494 /* It is also recommended that we reset and reprogram idmac */
2495 dw_mci_idmac_reset(host);
2496#endif
2497
2498 ret = true;
2499
2500ciu_out:
2501 /* After a CTRL reset we need to have CIU set clock registers */
2502 mci_send_cmd(host->cur_slot, SDMMC_CMD_UPD_CLK, 0);
2503
2504 return ret;
31bff450
SJ
2505}
2506
c91eab4b
TA
2507#ifdef CONFIG_OF
2508static struct dw_mci_of_quirks {
2509 char *quirk;
2510 int id;
2511} of_quirks[] = {
2512 {
c91eab4b
TA
2513 .quirk = "broken-cd",
2514 .id = DW_MCI_QUIRK_BROKEN_CARD_DETECTION,
26375b5c
JC
2515 }, {
2516 .quirk = "disable-wp",
2517 .id = DW_MCI_QUIRK_NO_WRITE_PROTECT,
c91eab4b
TA
2518 },
2519};
2520
2521static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
2522{
2523 struct dw_mci_board *pdata;
2524 struct device *dev = host->dev;
2525 struct device_node *np = dev->of_node;
e95baf13 2526 const struct dw_mci_drv_data *drv_data = host->drv_data;
800d78bf 2527 int idx, ret;
3c6d89ea 2528 u32 clock_frequency;
c91eab4b
TA
2529
2530 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
bf3707ea 2531 if (!pdata)
c91eab4b 2532 return ERR_PTR(-ENOMEM);
c91eab4b
TA
2533
2534 /* find out number of slots supported */
2535 if (of_property_read_u32(dev->of_node, "num-slots",
2536 &pdata->num_slots)) {
2537 dev_info(dev, "num-slots property not found, "
2538 "assuming 1 slot is available\n");
2539 pdata->num_slots = 1;
2540 }
2541
2542 /* get quirks */
2543 for (idx = 0; idx < ARRAY_SIZE(of_quirks); idx++)
2544 if (of_get_property(np, of_quirks[idx].quirk, NULL))
2545 pdata->quirks |= of_quirks[idx].id;
2546
2547 if (of_property_read_u32(np, "fifo-depth", &pdata->fifo_depth))
2548 dev_info(dev, "fifo-depth property not found, using "
2549 "value of FIFOTH register as default\n");
2550
2551 of_property_read_u32(np, "card-detect-delay", &pdata->detect_delay_ms);
2552
3c6d89ea
DA
2553 if (!of_property_read_u32(np, "clock-frequency", &clock_frequency))
2554 pdata->bus_hz = clock_frequency;
2555
cb27a843
JH
2556 if (drv_data && drv_data->parse_dt) {
2557 ret = drv_data->parse_dt(host);
800d78bf
TA
2558 if (ret)
2559 return ERR_PTR(ret);
2560 }
2561
10b49841
SJ
2562 if (of_find_property(np, "supports-highspeed", NULL))
2563 pdata->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
2564
c91eab4b
TA
2565 return pdata;
2566}
2567
2568#else /* CONFIG_OF */
2569static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host)
2570{
2571 return ERR_PTR(-EINVAL);
2572}
2573#endif /* CONFIG_OF */
2574
62ca8034 2575int dw_mci_probe(struct dw_mci *host)
f95f3850 2576{
e95baf13 2577 const struct dw_mci_drv_data *drv_data = host->drv_data;
62ca8034 2578 int width, i, ret = 0;
f95f3850 2579 u32 fifo_size;
1c2215b7 2580 int init_slots = 0;
f95f3850 2581
c91eab4b
TA
2582 if (!host->pdata) {
2583 host->pdata = dw_mci_parse_dt(host);
2584 if (IS_ERR(host->pdata)) {
2585 dev_err(host->dev, "platform data not available\n");
2586 return -EINVAL;
2587 }
f95f3850
WN
2588 }
2589
907abd51 2590 if (host->pdata->num_slots > 1) {
4a90920c 2591 dev_err(host->dev,
907abd51 2592 "Platform data must supply num_slots.\n");
62ca8034 2593 return -ENODEV;
f95f3850
WN
2594 }
2595
780f22af 2596 host->biu_clk = devm_clk_get(host->dev, "biu");
f90a0612
TA
2597 if (IS_ERR(host->biu_clk)) {
2598 dev_dbg(host->dev, "biu clock not available\n");
2599 } else {
2600 ret = clk_prepare_enable(host->biu_clk);
2601 if (ret) {
2602 dev_err(host->dev, "failed to enable biu clock\n");
f90a0612
TA
2603 return ret;
2604 }
2605 }
2606
780f22af 2607 host->ciu_clk = devm_clk_get(host->dev, "ciu");
f90a0612
TA
2608 if (IS_ERR(host->ciu_clk)) {
2609 dev_dbg(host->dev, "ciu clock not available\n");
3c6d89ea 2610 host->bus_hz = host->pdata->bus_hz;
f90a0612
TA
2611 } else {
2612 ret = clk_prepare_enable(host->ciu_clk);
2613 if (ret) {
2614 dev_err(host->dev, "failed to enable ciu clock\n");
f90a0612
TA
2615 goto err_clk_biu;
2616 }
f90a0612 2617
3c6d89ea
DA
2618 if (host->pdata->bus_hz) {
2619 ret = clk_set_rate(host->ciu_clk, host->pdata->bus_hz);
2620 if (ret)
2621 dev_warn(host->dev,
612de4c1 2622 "Unable to set bus rate to %uHz\n",
3c6d89ea
DA
2623 host->pdata->bus_hz);
2624 }
f90a0612 2625 host->bus_hz = clk_get_rate(host->ciu_clk);
3c6d89ea 2626 }
f90a0612 2627
612de4c1
JC
2628 if (!host->bus_hz) {
2629 dev_err(host->dev,
2630 "Platform data must supply bus speed\n");
2631 ret = -ENODEV;
2632 goto err_clk_ciu;
2633 }
2634
002f0d5c
YK
2635 if (drv_data && drv_data->init) {
2636 ret = drv_data->init(host);
2637 if (ret) {
2638 dev_err(host->dev,
2639 "implementation specific init failed\n");
2640 goto err_clk_ciu;
2641 }
2642 }
2643
cb27a843
JH
2644 if (drv_data && drv_data->setup_clock) {
2645 ret = drv_data->setup_clock(host);
800d78bf
TA
2646 if (ret) {
2647 dev_err(host->dev,
2648 "implementation specific clock setup failed\n");
2649 goto err_clk_ciu;
2650 }
2651 }
2652
62ca8034 2653 host->quirks = host->pdata->quirks;
f95f3850
WN
2654
2655 spin_lock_init(&host->lock);
f8c58c11 2656 spin_lock_init(&host->irq_lock);
f95f3850
WN
2657 INIT_LIST_HEAD(&host->queue);
2658
f95f3850
WN
2659 /*
2660 * Get the host data width - this assumes that HCON has been set with
2661 * the correct values.
2662 */
2663 i = (mci_readl(host, HCON) >> 7) & 0x7;
2664 if (!i) {
2665 host->push_data = dw_mci_push_data16;
2666 host->pull_data = dw_mci_pull_data16;
2667 width = 16;
2668 host->data_shift = 1;
2669 } else if (i == 2) {
2670 host->push_data = dw_mci_push_data64;
2671 host->pull_data = dw_mci_pull_data64;
2672 width = 64;
2673 host->data_shift = 3;
2674 } else {
2675 /* Check for a reserved value, and warn if it is */
2676 WARN((i != 1),
2677 "HCON reports a reserved host data width!\n"
2678 "Defaulting to 32-bit access.\n");
2679 host->push_data = dw_mci_push_data32;
2680 host->pull_data = dw_mci_pull_data32;
2681 width = 32;
2682 host->data_shift = 2;
2683 }
2684
2685 /* Reset all blocks */
3a33a94c 2686 if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_ALL_RESET_FLAGS))
141a712a
SJ
2687 return -ENODEV;
2688
2689 host->dma_ops = host->pdata->dma_ops;
2690 dw_mci_init_dma(host);
f95f3850
WN
2691
2692 /* Clear the interrupts for the host controller */
2693 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2694 mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
2695
2696 /* Put in max timeout */
2697 mci_writel(host, TMOUT, 0xFFFFFFFF);
2698
2699 /*
2700 * FIFO threshold settings RxMark = fifo_size / 2 - 1,
2701 * Tx Mark = fifo_size / 2 DMA Size = 8
2702 */
b86d8253
JH
2703 if (!host->pdata->fifo_depth) {
2704 /*
2705 * Power-on value of RX_WMark is FIFO_DEPTH-1, but this may
2706 * have been overwritten by the bootloader, just like we're
2707 * about to do, so if you know the value for your hardware, you
2708 * should put it in the platform data.
2709 */
2710 fifo_size = mci_readl(host, FIFOTH);
8234e869 2711 fifo_size = 1 + ((fifo_size >> 16) & 0xfff);
b86d8253
JH
2712 } else {
2713 fifo_size = host->pdata->fifo_depth;
2714 }
2715 host->fifo_depth = fifo_size;
52426899
SJ
2716 host->fifoth_val =
2717 SDMMC_SET_FIFOTH(0x2, fifo_size / 2 - 1, fifo_size / 2);
e61cf118 2718 mci_writel(host, FIFOTH, host->fifoth_val);
f95f3850
WN
2719
2720 /* disable clock to CIU */
2721 mci_writel(host, CLKENA, 0);
2722 mci_writel(host, CLKSRC, 0);
2723
63008768
JH
2724 /*
2725 * In 2.40a spec, Data offset is changed.
2726 * Need to check the version-id and set data-offset for DATA register.
2727 */
2728 host->verid = SDMMC_GET_VERID(mci_readl(host, VERID));
2729 dev_info(host->dev, "Version ID is %04x\n", host->verid);
2730
2731 if (host->verid < DW_MMC_240A)
2732 host->data_offset = DATA_OFFSET;
2733 else
2734 host->data_offset = DATA_240A_OFFSET;
2735
f95f3850 2736 tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host);
780f22af
SJ
2737 ret = devm_request_irq(host->dev, host->irq, dw_mci_interrupt,
2738 host->irq_flags, "dw-mci", host);
f95f3850 2739 if (ret)
6130e7a9 2740 goto err_dmaunmap;
f95f3850 2741
f95f3850
WN
2742 if (host->pdata->num_slots)
2743 host->num_slots = host->pdata->num_slots;
2744 else
2745 host->num_slots = ((mci_readl(host, HCON) >> 1) & 0x1F) + 1;
2746
2da1d7f2
YC
2747 /*
2748 * Enable interrupts for command done, data over, data empty, card det,
2749 * receive ready and error such as transmit, receive timeout, crc error
2750 */
2751 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2752 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
2753 SDMMC_INT_TXDR | SDMMC_INT_RXDR |
2754 DW_MCI_ERROR_FLAGS | SDMMC_INT_CD);
2755 mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE); /* Enable mci interrupt */
2756
2757 dev_info(host->dev, "DW MMC controller at irq %d, "
2758 "%d bit host data width, "
2759 "%u deep fifo\n",
2760 host->irq, width, fifo_size);
2761
f95f3850
WN
2762 /* We need at least one slot to succeed */
2763 for (i = 0; i < host->num_slots; i++) {
2764 ret = dw_mci_init_slot(host, i);
1c2215b7
TA
2765 if (ret)
2766 dev_dbg(host->dev, "slot %d init failed\n", i);
2767 else
2768 init_slots++;
2769 }
2770
2771 if (init_slots) {
2772 dev_info(host->dev, "%d slots initialized\n", init_slots);
2773 } else {
2774 dev_dbg(host->dev, "attempted to initialize %d slots, "
2775 "but failed on all\n", host->num_slots);
6130e7a9 2776 goto err_dmaunmap;
f95f3850
WN
2777 }
2778
f95f3850 2779 if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO)
4a90920c 2780 dev_info(host->dev, "Internal DMAC interrupt fix enabled.\n");
f95f3850
WN
2781
2782 return 0;
2783
f95f3850
WN
2784err_dmaunmap:
2785 if (host->use_dma && host->dma_ops->exit)
2786 host->dma_ops->exit(host);
f90a0612
TA
2787
2788err_clk_ciu:
780f22af 2789 if (!IS_ERR(host->ciu_clk))
f90a0612 2790 clk_disable_unprepare(host->ciu_clk);
780f22af 2791
f90a0612 2792err_clk_biu:
780f22af 2793 if (!IS_ERR(host->biu_clk))
f90a0612 2794 clk_disable_unprepare(host->biu_clk);
780f22af 2795
f95f3850
WN
2796 return ret;
2797}
62ca8034 2798EXPORT_SYMBOL(dw_mci_probe);
f95f3850 2799
62ca8034 2800void dw_mci_remove(struct dw_mci *host)
f95f3850 2801{
f95f3850
WN
2802 int i;
2803
2804 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2805 mci_writel(host, INTMASK, 0); /* disable all mmc interrupt first */
2806
f95f3850 2807 for (i = 0; i < host->num_slots; i++) {
4a90920c 2808 dev_dbg(host->dev, "remove slot %d\n", i);
f95f3850
WN
2809 if (host->slot[i])
2810 dw_mci_cleanup_slot(host->slot[i], i);
2811 }
2812
2813 /* disable clock to CIU */
2814 mci_writel(host, CLKENA, 0);
2815 mci_writel(host, CLKSRC, 0);
2816
f95f3850
WN
2817 if (host->use_dma && host->dma_ops->exit)
2818 host->dma_ops->exit(host);
2819
f90a0612
TA
2820 if (!IS_ERR(host->ciu_clk))
2821 clk_disable_unprepare(host->ciu_clk);
780f22af 2822
f90a0612
TA
2823 if (!IS_ERR(host->biu_clk))
2824 clk_disable_unprepare(host->biu_clk);
f95f3850 2825}
62ca8034
SH
2826EXPORT_SYMBOL(dw_mci_remove);
2827
2828
f95f3850 2829
6fe8890d 2830#ifdef CONFIG_PM_SLEEP
f95f3850
WN
2831/*
2832 * TODO: we should probably disable the clock to the card in the suspend path.
2833 */
62ca8034 2834int dw_mci_suspend(struct dw_mci *host)
f95f3850 2835{
f95f3850
WN
2836 return 0;
2837}
62ca8034 2838EXPORT_SYMBOL(dw_mci_suspend);
f95f3850 2839
62ca8034 2840int dw_mci_resume(struct dw_mci *host)
f95f3850
WN
2841{
2842 int i, ret;
f95f3850 2843
3a33a94c 2844 if (!dw_mci_ctrl_reset(host, SDMMC_CTRL_ALL_RESET_FLAGS)) {
e61cf118
JC
2845 ret = -ENODEV;
2846 return ret;
2847 }
2848
3bfe619d 2849 if (host->use_dma && host->dma_ops->init)
141a712a
SJ
2850 host->dma_ops->init(host);
2851
52426899
SJ
2852 /*
2853 * Restore the initial value at FIFOTH register
2854 * And Invalidate the prev_blksz with zero
2855 */
e61cf118 2856 mci_writel(host, FIFOTH, host->fifoth_val);
52426899 2857 host->prev_blksz = 0;
e61cf118 2858
2eb2944f
DA
2859 /* Put in max timeout */
2860 mci_writel(host, TMOUT, 0xFFFFFFFF);
2861
e61cf118
JC
2862 mci_writel(host, RINTSTS, 0xFFFFFFFF);
2863 mci_writel(host, INTMASK, SDMMC_INT_CMD_DONE | SDMMC_INT_DATA_OVER |
2864 SDMMC_INT_TXDR | SDMMC_INT_RXDR |
2865 DW_MCI_ERROR_FLAGS | SDMMC_INT_CD);
2866 mci_writel(host, CTRL, SDMMC_CTRL_INT_ENABLE);
2867
f95f3850
WN
2868 for (i = 0; i < host->num_slots; i++) {
2869 struct dw_mci_slot *slot = host->slot[i];
2870 if (!slot)
2871 continue;
ab269128
AK
2872 if (slot->mmc->pm_flags & MMC_PM_KEEP_POWER) {
2873 dw_mci_set_ios(slot->mmc, &slot->mmc->ios);
2874 dw_mci_setup_bus(slot, true);
2875 }
f95f3850 2876 }
f95f3850
WN
2877 return 0;
2878}
62ca8034 2879EXPORT_SYMBOL(dw_mci_resume);
6fe8890d
JC
2880#endif /* CONFIG_PM_SLEEP */
2881
f95f3850
WN
2882static int __init dw_mci_init(void)
2883{
8e1c4e4d 2884 pr_info("Synopsys Designware Multimedia Card Interface Driver\n");
62ca8034 2885 return 0;
f95f3850
WN
2886}
2887
2888static void __exit dw_mci_exit(void)
2889{
f95f3850
WN
2890}
2891
2892module_init(dw_mci_init);
2893module_exit(dw_mci_exit);
2894
2895MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
2896MODULE_AUTHOR("NXP Semiconductor VietNam");
2897MODULE_AUTHOR("Imagination Technologies Ltd");
2898MODULE_LICENSE("GPL v2");