mmc: sh_mmcif: revision-specific Command Completion Signal handling
[linux-2.6-block.git] / drivers / mmc / host / sh_mmcif.c
CommitLineData
fdc50a94
YG
1/*
2 * MMCIF eMMC driver.
3 *
4 * Copyright (C) 2010 Renesas Solutions Corp.
5 * Yusuke Goda <yusuke.goda.sx@renesas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License.
10 *
11 *
12 * TODO
13 * 1. DMA
14 * 2. Power management
15 * 3. Handle MMC errors better
16 *
17 */
18
f985da17
GL
19/*
20 * The MMCIF driver is now processing MMC requests asynchronously, according
21 * to the Linux MMC API requirement.
22 *
23 * The MMCIF driver processes MMC requests in up to 3 stages: command, optional
24 * data, and optional stop. To achieve asynchronous processing each of these
25 * stages is split into two halves: a top and a bottom half. The top half
26 * initialises the hardware, installs a timeout handler to handle completion
27 * timeouts, and returns. In case of the command stage this immediately returns
28 * control to the caller, leaving all further processing to run asynchronously.
29 * All further request processing is performed by the bottom halves.
30 *
31 * The bottom half further consists of a "hard" IRQ handler, an IRQ handler
32 * thread, a DMA completion callback, if DMA is used, a timeout work, and
33 * request- and stage-specific handler methods.
34 *
35 * Each bottom half run begins with either a hardware interrupt, a DMA callback
36 * invocation, or a timeout work run. In case of an error or a successful
37 * processing completion, the MMC core is informed and the request processing is
38 * finished. In case processing has to continue, i.e., if data has to be read
39 * from or written to the card, or if a stop command has to be sent, the next
40 * top half is called, which performs the necessary hardware handling and
41 * reschedules the timeout work. This returns the driver state machine into the
42 * bottom half waiting state.
43 */
44
86df1745 45#include <linux/bitops.h>
aa0787a9
GL
46#include <linux/clk.h>
47#include <linux/completion.h>
e47bf32a 48#include <linux/delay.h>
fdc50a94 49#include <linux/dma-mapping.h>
a782d688 50#include <linux/dmaengine.h>
fdc50a94
YG
51#include <linux/mmc/card.h>
52#include <linux/mmc/core.h>
e47bf32a 53#include <linux/mmc/host.h>
fdc50a94
YG
54#include <linux/mmc/mmc.h>
55#include <linux/mmc/sdio.h>
fdc50a94 56#include <linux/mmc/sh_mmcif.h>
e480606a 57#include <linux/mmc/slot-gpio.h>
bf68a812 58#include <linux/mod_devicetable.h>
8047310e 59#include <linux/mutex.h>
a782d688 60#include <linux/pagemap.h>
e47bf32a 61#include <linux/platform_device.h>
efe6a8ad 62#include <linux/pm_qos.h>
faca6648 63#include <linux/pm_runtime.h>
d00cadac 64#include <linux/sh_dma.h>
3b0beafc 65#include <linux/spinlock.h>
88b47679 66#include <linux/module.h>
fdc50a94
YG
67
68#define DRIVER_NAME "sh_mmcif"
69#define DRIVER_VERSION "2010-04-28"
70
fdc50a94
YG
71/* CE_CMD_SET */
72#define CMD_MASK 0x3f000000
73#define CMD_SET_RTYP_NO ((0 << 23) | (0 << 22))
74#define CMD_SET_RTYP_6B ((0 << 23) | (1 << 22)) /* R1/R1b/R3/R4/R5 */
75#define CMD_SET_RTYP_17B ((1 << 23) | (0 << 22)) /* R2 */
76#define CMD_SET_RBSY (1 << 21) /* R1b */
77#define CMD_SET_CCSEN (1 << 20)
78#define CMD_SET_WDAT (1 << 19) /* 1: on data, 0: no data */
79#define CMD_SET_DWEN (1 << 18) /* 1: write, 0: read */
80#define CMD_SET_CMLTE (1 << 17) /* 1: multi block trans, 0: single */
81#define CMD_SET_CMD12EN (1 << 16) /* 1: CMD12 auto issue */
82#define CMD_SET_RIDXC_INDEX ((0 << 15) | (0 << 14)) /* index check */
83#define CMD_SET_RIDXC_BITS ((0 << 15) | (1 << 14)) /* check bits check */
84#define CMD_SET_RIDXC_NO ((1 << 15) | (0 << 14)) /* no check */
85#define CMD_SET_CRC7C ((0 << 13) | (0 << 12)) /* CRC7 check*/
86#define CMD_SET_CRC7C_BITS ((0 << 13) | (1 << 12)) /* check bits check*/
87#define CMD_SET_CRC7C_INTERNAL ((1 << 13) | (0 << 12)) /* internal CRC7 check*/
88#define CMD_SET_CRC16C (1 << 10) /* 0: CRC16 check*/
89#define CMD_SET_CRCSTE (1 << 8) /* 1: not receive CRC status */
90#define CMD_SET_TBIT (1 << 7) /* 1: tran mission bit "Low" */
91#define CMD_SET_OPDM (1 << 6) /* 1: open/drain */
92#define CMD_SET_CCSH (1 << 5)
555061f9 93#define CMD_SET_DARS (1 << 2) /* Dual Data Rate */
fdc50a94
YG
94#define CMD_SET_DATW_1 ((0 << 1) | (0 << 0)) /* 1bit */
95#define CMD_SET_DATW_4 ((0 << 1) | (1 << 0)) /* 4bit */
96#define CMD_SET_DATW_8 ((1 << 1) | (0 << 0)) /* 8bit */
97
98/* CE_CMD_CTRL */
99#define CMD_CTRL_BREAK (1 << 0)
100
101/* CE_BLOCK_SET */
102#define BLOCK_SIZE_MASK 0x0000ffff
103
fdc50a94
YG
104/* CE_INT */
105#define INT_CCSDE (1 << 29)
106#define INT_CMD12DRE (1 << 26)
107#define INT_CMD12RBE (1 << 25)
108#define INT_CMD12CRE (1 << 24)
109#define INT_DTRANE (1 << 23)
110#define INT_BUFRE (1 << 22)
111#define INT_BUFWEN (1 << 21)
112#define INT_BUFREN (1 << 20)
113#define INT_CCSRCV (1 << 19)
114#define INT_RBSYE (1 << 17)
115#define INT_CRSPE (1 << 16)
116#define INT_CMDVIO (1 << 15)
117#define INT_BUFVIO (1 << 14)
118#define INT_WDATERR (1 << 11)
119#define INT_RDATERR (1 << 10)
120#define INT_RIDXERR (1 << 9)
121#define INT_RSPERR (1 << 8)
122#define INT_CCSTO (1 << 5)
123#define INT_CRCSTO (1 << 4)
124#define INT_WDATTO (1 << 3)
125#define INT_RDATTO (1 << 2)
126#define INT_RBSYTO (1 << 1)
127#define INT_RSPTO (1 << 0)
128#define INT_ERR_STS (INT_CMDVIO | INT_BUFVIO | INT_WDATERR | \
129 INT_RDATERR | INT_RIDXERR | INT_RSPERR | \
130 INT_CCSTO | INT_CRCSTO | INT_WDATTO | \
131 INT_RDATTO | INT_RBSYTO | INT_RSPTO)
132
8af50750
GL
133#define INT_ALL (INT_RBSYE | INT_CRSPE | INT_BUFREN | \
134 INT_BUFWEN | INT_CMD12DRE | INT_BUFRE | \
135 INT_DTRANE | INT_CMD12RBE | INT_CMD12CRE)
136
967bcb77
GL
137#define INT_CCS (INT_CCSTO | INT_CCSRCV | INT_CCSDE)
138
fdc50a94
YG
139/* CE_INT_MASK */
140#define MASK_ALL 0x00000000
141#define MASK_MCCSDE (1 << 29)
142#define MASK_MCMD12DRE (1 << 26)
143#define MASK_MCMD12RBE (1 << 25)
144#define MASK_MCMD12CRE (1 << 24)
145#define MASK_MDTRANE (1 << 23)
146#define MASK_MBUFRE (1 << 22)
147#define MASK_MBUFWEN (1 << 21)
148#define MASK_MBUFREN (1 << 20)
149#define MASK_MCCSRCV (1 << 19)
150#define MASK_MRBSYE (1 << 17)
151#define MASK_MCRSPE (1 << 16)
152#define MASK_MCMDVIO (1 << 15)
153#define MASK_MBUFVIO (1 << 14)
154#define MASK_MWDATERR (1 << 11)
155#define MASK_MRDATERR (1 << 10)
156#define MASK_MRIDXERR (1 << 9)
157#define MASK_MRSPERR (1 << 8)
158#define MASK_MCCSTO (1 << 5)
159#define MASK_MCRCSTO (1 << 4)
160#define MASK_MWDATTO (1 << 3)
161#define MASK_MRDATTO (1 << 2)
162#define MASK_MRBSYTO (1 << 1)
163#define MASK_MRSPTO (1 << 0)
164
ee4b8887
GL
165#define MASK_START_CMD (MASK_MCMDVIO | MASK_MBUFVIO | MASK_MWDATERR | \
166 MASK_MRDATERR | MASK_MRIDXERR | MASK_MRSPERR | \
967bcb77 167 MASK_MCRCSTO | MASK_MWDATTO | \
ee4b8887
GL
168 MASK_MRDATTO | MASK_MRBSYTO | MASK_MRSPTO)
169
8af50750
GL
170#define MASK_CLEAN (INT_ERR_STS | MASK_MRBSYE | MASK_MCRSPE | \
171 MASK_MBUFREN | MASK_MBUFWEN | \
172 MASK_MCMD12DRE | MASK_MBUFRE | MASK_MDTRANE | \
173 MASK_MCMD12RBE | MASK_MCMD12CRE)
174
fdc50a94
YG
175/* CE_HOST_STS1 */
176#define STS1_CMDSEQ (1 << 31)
177
178/* CE_HOST_STS2 */
179#define STS2_CRCSTE (1 << 31)
180#define STS2_CRC16E (1 << 30)
181#define STS2_AC12CRCE (1 << 29)
182#define STS2_RSPCRC7E (1 << 28)
183#define STS2_CRCSTEBE (1 << 27)
184#define STS2_RDATEBE (1 << 26)
185#define STS2_AC12REBE (1 << 25)
186#define STS2_RSPEBE (1 << 24)
187#define STS2_AC12IDXE (1 << 23)
188#define STS2_RSPIDXE (1 << 22)
189#define STS2_CCSTO (1 << 15)
190#define STS2_RDATTO (1 << 14)
191#define STS2_DATBSYTO (1 << 13)
192#define STS2_CRCSTTO (1 << 12)
193#define STS2_AC12BSYTO (1 << 11)
194#define STS2_RSPBSYTO (1 << 10)
195#define STS2_AC12RSPTO (1 << 9)
196#define STS2_RSPTO (1 << 8)
197#define STS2_CRC_ERR (STS2_CRCSTE | STS2_CRC16E | \
198 STS2_AC12CRCE | STS2_RSPCRC7E | STS2_CRCSTEBE)
199#define STS2_TIMEOUT_ERR (STS2_CCSTO | STS2_RDATTO | \
200 STS2_DATBSYTO | STS2_CRCSTTO | \
201 STS2_AC12BSYTO | STS2_RSPBSYTO | \
202 STS2_AC12RSPTO | STS2_RSPTO)
203
fdc50a94
YG
204#define CLKDEV_EMMC_DATA 52000000 /* 52MHz */
205#define CLKDEV_MMC_DATA 20000000 /* 20MHz */
206#define CLKDEV_INIT 400000 /* 400 KHz */
207
3b0beafc
GL
208enum mmcif_state {
209 STATE_IDLE,
210 STATE_REQUEST,
211 STATE_IOS,
8047310e 212 STATE_TIMEOUT,
3b0beafc
GL
213};
214
f985da17
GL
215enum mmcif_wait_for {
216 MMCIF_WAIT_FOR_REQUEST,
217 MMCIF_WAIT_FOR_CMD,
218 MMCIF_WAIT_FOR_MREAD,
219 MMCIF_WAIT_FOR_MWRITE,
220 MMCIF_WAIT_FOR_READ,
221 MMCIF_WAIT_FOR_WRITE,
222 MMCIF_WAIT_FOR_READ_END,
223 MMCIF_WAIT_FOR_WRITE_END,
224 MMCIF_WAIT_FOR_STOP,
225};
226
fdc50a94
YG
227struct sh_mmcif_host {
228 struct mmc_host *mmc;
f985da17 229 struct mmc_request *mrq;
fdc50a94
YG
230 struct platform_device *pd;
231 struct clk *hclk;
232 unsigned int clk;
233 int bus_width;
555061f9 234 unsigned char timing;
aa0787a9 235 bool sd_error;
f985da17 236 bool dying;
fdc50a94
YG
237 long timeout;
238 void __iomem *addr;
f985da17 239 u32 *pio_ptr;
ee4b8887 240 spinlock_t lock; /* protect sh_mmcif_host::state */
3b0beafc 241 enum mmcif_state state;
f985da17
GL
242 enum mmcif_wait_for wait_for;
243 struct delayed_work timeout_work;
244 size_t blocksize;
245 int sg_idx;
246 int sg_blkidx;
faca6648 247 bool power;
c9b0cef2 248 bool card_present;
967bcb77 249 bool ccs_enable; /* Command Completion Signal support */
8047310e 250 struct mutex thread_lock;
fdc50a94 251
a782d688
GL
252 /* DMA support */
253 struct dma_chan *chan_rx;
254 struct dma_chan *chan_tx;
255 struct completion dma_complete;
f38f94c6 256 bool dma_active;
a782d688 257};
fdc50a94
YG
258
259static inline void sh_mmcif_bitset(struct sh_mmcif_host *host,
260 unsigned int reg, u32 val)
261{
487d9fc5 262 writel(val | readl(host->addr + reg), host->addr + reg);
fdc50a94
YG
263}
264
265static inline void sh_mmcif_bitclr(struct sh_mmcif_host *host,
266 unsigned int reg, u32 val)
267{
487d9fc5 268 writel(~val & readl(host->addr + reg), host->addr + reg);
fdc50a94
YG
269}
270
a782d688
GL
271static void mmcif_dma_complete(void *arg)
272{
273 struct sh_mmcif_host *host = arg;
8047310e 274 struct mmc_request *mrq = host->mrq;
69983404 275
a782d688
GL
276 dev_dbg(&host->pd->dev, "Command completed\n");
277
8047310e 278 if (WARN(!mrq || !mrq->data, "%s: NULL data in DMA completion!\n",
a782d688
GL
279 dev_name(&host->pd->dev)))
280 return;
281
a782d688
GL
282 complete(&host->dma_complete);
283}
284
285static void sh_mmcif_start_dma_rx(struct sh_mmcif_host *host)
286{
69983404
GL
287 struct mmc_data *data = host->mrq->data;
288 struct scatterlist *sg = data->sg;
a782d688
GL
289 struct dma_async_tx_descriptor *desc = NULL;
290 struct dma_chan *chan = host->chan_rx;
291 dma_cookie_t cookie = -EINVAL;
292 int ret;
293
69983404 294 ret = dma_map_sg(chan->device->dev, sg, data->sg_len,
1ed828db 295 DMA_FROM_DEVICE);
a782d688 296 if (ret > 0) {
f38f94c6 297 host->dma_active = true;
16052827 298 desc = dmaengine_prep_slave_sg(chan, sg, ret,
05f5799c 299 DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
a782d688
GL
300 }
301
302 if (desc) {
303 desc->callback = mmcif_dma_complete;
304 desc->callback_param = host;
a5ece7d2
LW
305 cookie = dmaengine_submit(desc);
306 sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN);
307 dma_async_issue_pending(chan);
a782d688
GL
308 }
309 dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n",
69983404 310 __func__, data->sg_len, ret, cookie);
a782d688
GL
311
312 if (!desc) {
313 /* DMA failed, fall back to PIO */
314 if (ret >= 0)
315 ret = -EIO;
316 host->chan_rx = NULL;
f38f94c6 317 host->dma_active = false;
a782d688
GL
318 dma_release_channel(chan);
319 /* Free the Tx channel too */
320 chan = host->chan_tx;
321 if (chan) {
322 host->chan_tx = NULL;
323 dma_release_channel(chan);
324 }
325 dev_warn(&host->pd->dev,
326 "DMA failed: %d, falling back to PIO\n", ret);
327 sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
328 }
329
330 dev_dbg(&host->pd->dev, "%s(): desc %p, cookie %d, sg[%d]\n", __func__,
69983404 331 desc, cookie, data->sg_len);
a782d688
GL
332}
333
334static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host)
335{
69983404
GL
336 struct mmc_data *data = host->mrq->data;
337 struct scatterlist *sg = data->sg;
a782d688
GL
338 struct dma_async_tx_descriptor *desc = NULL;
339 struct dma_chan *chan = host->chan_tx;
340 dma_cookie_t cookie = -EINVAL;
341 int ret;
342
69983404 343 ret = dma_map_sg(chan->device->dev, sg, data->sg_len,
1ed828db 344 DMA_TO_DEVICE);
a782d688 345 if (ret > 0) {
f38f94c6 346 host->dma_active = true;
16052827 347 desc = dmaengine_prep_slave_sg(chan, sg, ret,
05f5799c 348 DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
a782d688
GL
349 }
350
351 if (desc) {
352 desc->callback = mmcif_dma_complete;
353 desc->callback_param = host;
a5ece7d2
LW
354 cookie = dmaengine_submit(desc);
355 sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAWEN);
356 dma_async_issue_pending(chan);
a782d688
GL
357 }
358 dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n",
69983404 359 __func__, data->sg_len, ret, cookie);
a782d688
GL
360
361 if (!desc) {
362 /* DMA failed, fall back to PIO */
363 if (ret >= 0)
364 ret = -EIO;
365 host->chan_tx = NULL;
f38f94c6 366 host->dma_active = false;
a782d688
GL
367 dma_release_channel(chan);
368 /* Free the Rx channel too */
369 chan = host->chan_rx;
370 if (chan) {
371 host->chan_rx = NULL;
372 dma_release_channel(chan);
373 }
374 dev_warn(&host->pd->dev,
375 "DMA failed: %d, falling back to PIO\n", ret);
376 sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
377 }
378
379 dev_dbg(&host->pd->dev, "%s(): desc %p, cookie %d\n", __func__,
380 desc, cookie);
381}
382
a782d688
GL
383static void sh_mmcif_request_dma(struct sh_mmcif_host *host,
384 struct sh_mmcif_plat_data *pdata)
385{
0e79f9ae
GL
386 struct resource *res = platform_get_resource(host->pd, IORESOURCE_MEM, 0);
387 struct dma_slave_config cfg;
388 dma_cap_mask_t mask;
389 int ret;
a782d688 390
f38f94c6 391 host->dma_active = false;
a782d688 392
acd6d772
GL
393 if (pdata) {
394 if (pdata->slave_id_tx <= 0 || pdata->slave_id_rx <= 0)
395 return;
396 } else if (!host->pd->dev.of_node) {
0e79f9ae 397 return;
acd6d772 398 }
a782d688 399
0e79f9ae
GL
400 /* We can only either use DMA for both Tx and Rx or not use it at all */
401 dma_cap_zero(mask);
402 dma_cap_set(DMA_SLAVE, mask);
a782d688 403
acd6d772
GL
404 host->chan_tx = dma_request_slave_channel_compat(mask, shdma_chan_filter,
405 pdata ? (void *)pdata->slave_id_tx : NULL,
406 &host->pd->dev, "tx");
0e79f9ae
GL
407 dev_dbg(&host->pd->dev, "%s: TX: got channel %p\n", __func__,
408 host->chan_tx);
a782d688 409
0e79f9ae
GL
410 if (!host->chan_tx)
411 return;
a782d688 412
acd6d772
GL
413 /* In the OF case the driver will get the slave ID from the DT */
414 if (pdata)
415 cfg.slave_id = pdata->slave_id_tx;
0e79f9ae
GL
416 cfg.direction = DMA_MEM_TO_DEV;
417 cfg.dst_addr = res->start + MMCIF_CE_DATA;
418 cfg.src_addr = 0;
419 ret = dmaengine_slave_config(host->chan_tx, &cfg);
420 if (ret < 0)
421 goto ecfgtx;
422
acd6d772
GL
423 host->chan_rx = dma_request_slave_channel_compat(mask, shdma_chan_filter,
424 pdata ? (void *)pdata->slave_id_rx : NULL,
425 &host->pd->dev, "rx");
0e79f9ae
GL
426 dev_dbg(&host->pd->dev, "%s: RX: got channel %p\n", __func__,
427 host->chan_rx);
428
429 if (!host->chan_rx)
430 goto erqrx;
431
acd6d772
GL
432 if (pdata)
433 cfg.slave_id = pdata->slave_id_rx;
0e79f9ae
GL
434 cfg.direction = DMA_DEV_TO_MEM;
435 cfg.dst_addr = 0;
436 cfg.src_addr = res->start + MMCIF_CE_DATA;
437 ret = dmaengine_slave_config(host->chan_rx, &cfg);
438 if (ret < 0)
439 goto ecfgrx;
440
0e79f9ae
GL
441 return;
442
443ecfgrx:
444 dma_release_channel(host->chan_rx);
445 host->chan_rx = NULL;
446erqrx:
447ecfgtx:
448 dma_release_channel(host->chan_tx);
449 host->chan_tx = NULL;
a782d688
GL
450}
451
452static void sh_mmcif_release_dma(struct sh_mmcif_host *host)
453{
454 sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
455 /* Descriptors are freed automatically */
456 if (host->chan_tx) {
457 struct dma_chan *chan = host->chan_tx;
458 host->chan_tx = NULL;
459 dma_release_channel(chan);
460 }
461 if (host->chan_rx) {
462 struct dma_chan *chan = host->chan_rx;
463 host->chan_rx = NULL;
464 dma_release_channel(chan);
465 }
466
f38f94c6 467 host->dma_active = false;
a782d688 468}
fdc50a94
YG
469
470static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk)
471{
472 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
bf68a812 473 bool sup_pclk = p ? p->sup_pclk : false;
fdc50a94
YG
474
475 sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
476 sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR);
477
478 if (!clk)
479 return;
bf68a812 480 if (sup_pclk && clk == host->clk)
fdc50a94
YG
481 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK);
482 else
483 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR &
f9388257
SH
484 ((fls(DIV_ROUND_UP(host->clk,
485 clk) - 1) - 1) << 16));
fdc50a94
YG
486
487 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
488}
489
490static void sh_mmcif_sync_reset(struct sh_mmcif_host *host)
491{
492 u32 tmp;
493
487d9fc5 494 tmp = 0x010f0000 & sh_mmcif_readl(host->addr, MMCIF_CE_CLK_CTRL);
fdc50a94 495
487d9fc5
MD
496 sh_mmcif_writel(host->addr, MMCIF_CE_VERSION, SOFT_RST_ON);
497 sh_mmcif_writel(host->addr, MMCIF_CE_VERSION, SOFT_RST_OFF);
967bcb77
GL
498 if (host->ccs_enable)
499 tmp |= SCCSTO_29;
fdc50a94 500 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, tmp |
967bcb77 501 SRSPTO_256 | SRBSYTO_29 | SRWDTO_29);
fdc50a94
YG
502 /* byte swap on */
503 sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_ATYP);
504}
505
506static int sh_mmcif_error_manage(struct sh_mmcif_host *host)
507{
508 u32 state1, state2;
ee4b8887 509 int ret, timeout;
fdc50a94 510
aa0787a9 511 host->sd_error = false;
fdc50a94 512
487d9fc5
MD
513 state1 = sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS1);
514 state2 = sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS2);
e47bf32a
GL
515 dev_dbg(&host->pd->dev, "ERR HOST_STS1 = %08x\n", state1);
516 dev_dbg(&host->pd->dev, "ERR HOST_STS2 = %08x\n", state2);
fdc50a94
YG
517
518 if (state1 & STS1_CMDSEQ) {
519 sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, CMD_CTRL_BREAK);
520 sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, ~CMD_CTRL_BREAK);
ee4b8887 521 for (timeout = 10000000; timeout; timeout--) {
487d9fc5 522 if (!(sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS1)
ee4b8887 523 & STS1_CMDSEQ))
fdc50a94
YG
524 break;
525 mdelay(1);
526 }
ee4b8887
GL
527 if (!timeout) {
528 dev_err(&host->pd->dev,
529 "Forced end of command sequence timeout err\n");
530 return -EIO;
531 }
fdc50a94 532 sh_mmcif_sync_reset(host);
e47bf32a 533 dev_dbg(&host->pd->dev, "Forced end of command sequence\n");
fdc50a94
YG
534 return -EIO;
535 }
536
537 if (state2 & STS2_CRC_ERR) {
e475b270
TK
538 dev_err(&host->pd->dev, " CRC error: state %u, wait %u\n",
539 host->state, host->wait_for);
fdc50a94
YG
540 ret = -EIO;
541 } else if (state2 & STS2_TIMEOUT_ERR) {
e475b270
TK
542 dev_err(&host->pd->dev, " Timeout: state %u, wait %u\n",
543 host->state, host->wait_for);
fdc50a94
YG
544 ret = -ETIMEDOUT;
545 } else {
e475b270
TK
546 dev_dbg(&host->pd->dev, " End/Index error: state %u, wait %u\n",
547 host->state, host->wait_for);
fdc50a94
YG
548 ret = -EIO;
549 }
550 return ret;
551}
552
f985da17 553static bool sh_mmcif_next_block(struct sh_mmcif_host *host, u32 *p)
fdc50a94 554{
f985da17
GL
555 struct mmc_data *data = host->mrq->data;
556
557 host->sg_blkidx += host->blocksize;
558
559 /* data->sg->length must be a multiple of host->blocksize? */
560 BUG_ON(host->sg_blkidx > data->sg->length);
561
562 if (host->sg_blkidx == data->sg->length) {
563 host->sg_blkidx = 0;
564 if (++host->sg_idx < data->sg_len)
565 host->pio_ptr = sg_virt(++data->sg);
566 } else {
567 host->pio_ptr = p;
568 }
569
99eb9d8d 570 return host->sg_idx != data->sg_len;
f985da17
GL
571}
572
573static void sh_mmcif_single_read(struct sh_mmcif_host *host,
574 struct mmc_request *mrq)
575{
576 host->blocksize = (sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) &
577 BLOCK_SIZE_MASK) + 3;
578
579 host->wait_for = MMCIF_WAIT_FOR_READ;
fdc50a94 580
fdc50a94
YG
581 /* buf read enable */
582 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
f985da17
GL
583}
584
585static bool sh_mmcif_read_block(struct sh_mmcif_host *host)
586{
587 struct mmc_data *data = host->mrq->data;
588 u32 *p = sg_virt(data->sg);
589 int i;
590
591 if (host->sd_error) {
592 data->error = sh_mmcif_error_manage(host);
e475b270 593 dev_dbg(&host->pd->dev, "%s(): %d\n", __func__, data->error);
f985da17
GL
594 return false;
595 }
596
597 for (i = 0; i < host->blocksize / 4; i++)
487d9fc5 598 *p++ = sh_mmcif_readl(host->addr, MMCIF_CE_DATA);
fdc50a94
YG
599
600 /* buffer read end */
601 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFRE);
f985da17 602 host->wait_for = MMCIF_WAIT_FOR_READ_END;
fdc50a94 603
f985da17 604 return true;
fdc50a94
YG
605}
606
f985da17
GL
607static void sh_mmcif_multi_read(struct sh_mmcif_host *host,
608 struct mmc_request *mrq)
fdc50a94
YG
609{
610 struct mmc_data *data = mrq->data;
f985da17
GL
611
612 if (!data->sg_len || !data->sg->length)
613 return;
614
615 host->blocksize = sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) &
616 BLOCK_SIZE_MASK;
617
618 host->wait_for = MMCIF_WAIT_FOR_MREAD;
619 host->sg_idx = 0;
620 host->sg_blkidx = 0;
621 host->pio_ptr = sg_virt(data->sg);
5df460b1 622
f985da17
GL
623 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
624}
625
626static bool sh_mmcif_mread_block(struct sh_mmcif_host *host)
627{
628 struct mmc_data *data = host->mrq->data;
629 u32 *p = host->pio_ptr;
630 int i;
631
632 if (host->sd_error) {
633 data->error = sh_mmcif_error_manage(host);
e475b270 634 dev_dbg(&host->pd->dev, "%s(): %d\n", __func__, data->error);
f985da17 635 return false;
fdc50a94 636 }
f985da17
GL
637
638 BUG_ON(!data->sg->length);
639
640 for (i = 0; i < host->blocksize / 4; i++)
641 *p++ = sh_mmcif_readl(host->addr, MMCIF_CE_DATA);
642
643 if (!sh_mmcif_next_block(host, p))
644 return false;
645
f985da17
GL
646 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
647
648 return true;
fdc50a94
YG
649}
650
f985da17 651static void sh_mmcif_single_write(struct sh_mmcif_host *host,
fdc50a94
YG
652 struct mmc_request *mrq)
653{
f985da17
GL
654 host->blocksize = (sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) &
655 BLOCK_SIZE_MASK) + 3;
fdc50a94 656
f985da17 657 host->wait_for = MMCIF_WAIT_FOR_WRITE;
fdc50a94
YG
658
659 /* buf write enable */
f985da17
GL
660 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
661}
662
663static bool sh_mmcif_write_block(struct sh_mmcif_host *host)
664{
665 struct mmc_data *data = host->mrq->data;
666 u32 *p = sg_virt(data->sg);
667 int i;
668
669 if (host->sd_error) {
670 data->error = sh_mmcif_error_manage(host);
e475b270 671 dev_dbg(&host->pd->dev, "%s(): %d\n", __func__, data->error);
f985da17
GL
672 return false;
673 }
674
675 for (i = 0; i < host->blocksize / 4; i++)
487d9fc5 676 sh_mmcif_writel(host->addr, MMCIF_CE_DATA, *p++);
fdc50a94
YG
677
678 /* buffer write end */
679 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MDTRANE);
f985da17 680 host->wait_for = MMCIF_WAIT_FOR_WRITE_END;
fdc50a94 681
f985da17 682 return true;
fdc50a94
YG
683}
684
f985da17
GL
685static void sh_mmcif_multi_write(struct sh_mmcif_host *host,
686 struct mmc_request *mrq)
fdc50a94
YG
687{
688 struct mmc_data *data = mrq->data;
fdc50a94 689
f985da17
GL
690 if (!data->sg_len || !data->sg->length)
691 return;
fdc50a94 692
f985da17
GL
693 host->blocksize = sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET) &
694 BLOCK_SIZE_MASK;
fdc50a94 695
f985da17
GL
696 host->wait_for = MMCIF_WAIT_FOR_MWRITE;
697 host->sg_idx = 0;
698 host->sg_blkidx = 0;
699 host->pio_ptr = sg_virt(data->sg);
5df460b1 700
f985da17
GL
701 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
702}
fdc50a94 703
f985da17
GL
704static bool sh_mmcif_mwrite_block(struct sh_mmcif_host *host)
705{
706 struct mmc_data *data = host->mrq->data;
707 u32 *p = host->pio_ptr;
708 int i;
709
710 if (host->sd_error) {
711 data->error = sh_mmcif_error_manage(host);
e475b270 712 dev_dbg(&host->pd->dev, "%s(): %d\n", __func__, data->error);
f985da17 713 return false;
fdc50a94 714 }
f985da17
GL
715
716 BUG_ON(!data->sg->length);
717
718 for (i = 0; i < host->blocksize / 4; i++)
719 sh_mmcif_writel(host->addr, MMCIF_CE_DATA, *p++);
720
721 if (!sh_mmcif_next_block(host, p))
722 return false;
723
f985da17
GL
724 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
725
726 return true;
fdc50a94
YG
727}
728
729static void sh_mmcif_get_response(struct sh_mmcif_host *host,
730 struct mmc_command *cmd)
731{
732 if (cmd->flags & MMC_RSP_136) {
487d9fc5
MD
733 cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP3);
734 cmd->resp[1] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP2);
735 cmd->resp[2] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP1);
736 cmd->resp[3] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP0);
fdc50a94 737 } else
487d9fc5 738 cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP0);
fdc50a94
YG
739}
740
741static void sh_mmcif_get_cmd12response(struct sh_mmcif_host *host,
742 struct mmc_command *cmd)
743{
487d9fc5 744 cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP_CMD12);
fdc50a94
YG
745}
746
747static u32 sh_mmcif_set_cmd(struct sh_mmcif_host *host,
69983404 748 struct mmc_request *mrq)
fdc50a94 749{
69983404
GL
750 struct mmc_data *data = mrq->data;
751 struct mmc_command *cmd = mrq->cmd;
752 u32 opc = cmd->opcode;
fdc50a94
YG
753 u32 tmp = 0;
754
755 /* Response Type check */
756 switch (mmc_resp_type(cmd)) {
757 case MMC_RSP_NONE:
758 tmp |= CMD_SET_RTYP_NO;
759 break;
760 case MMC_RSP_R1:
761 case MMC_RSP_R1B:
762 case MMC_RSP_R3:
763 tmp |= CMD_SET_RTYP_6B;
764 break;
765 case MMC_RSP_R2:
766 tmp |= CMD_SET_RTYP_17B;
767 break;
768 default:
e47bf32a 769 dev_err(&host->pd->dev, "Unsupported response type.\n");
fdc50a94
YG
770 break;
771 }
772 switch (opc) {
773 /* RBSY */
a812ba0f 774 case MMC_SLEEP_AWAKE:
fdc50a94
YG
775 case MMC_SWITCH:
776 case MMC_STOP_TRANSMISSION:
777 case MMC_SET_WRITE_PROT:
778 case MMC_CLR_WRITE_PROT:
779 case MMC_ERASE:
fdc50a94
YG
780 tmp |= CMD_SET_RBSY;
781 break;
782 }
783 /* WDAT / DATW */
69983404 784 if (data) {
fdc50a94
YG
785 tmp |= CMD_SET_WDAT;
786 switch (host->bus_width) {
787 case MMC_BUS_WIDTH_1:
788 tmp |= CMD_SET_DATW_1;
789 break;
790 case MMC_BUS_WIDTH_4:
791 tmp |= CMD_SET_DATW_4;
792 break;
793 case MMC_BUS_WIDTH_8:
794 tmp |= CMD_SET_DATW_8;
795 break;
796 default:
e47bf32a 797 dev_err(&host->pd->dev, "Unsupported bus width.\n");
fdc50a94
YG
798 break;
799 }
555061f9
TK
800 switch (host->timing) {
801 case MMC_TIMING_UHS_DDR50:
802 /*
803 * MMC core will only set this timing, if the host
804 * advertises the MMC_CAP_UHS_DDR50 capability. MMCIF
805 * implementations with this capability, e.g. sh73a0,
806 * will have to set it in their platform data.
807 */
808 tmp |= CMD_SET_DARS;
809 break;
810 }
fdc50a94
YG
811 }
812 /* DWEN */
813 if (opc == MMC_WRITE_BLOCK || opc == MMC_WRITE_MULTIPLE_BLOCK)
814 tmp |= CMD_SET_DWEN;
815 /* CMLTE/CMD12EN */
816 if (opc == MMC_READ_MULTIPLE_BLOCK || opc == MMC_WRITE_MULTIPLE_BLOCK) {
817 tmp |= CMD_SET_CMLTE | CMD_SET_CMD12EN;
818 sh_mmcif_bitset(host, MMCIF_CE_BLOCK_SET,
69983404 819 data->blocks << 16);
fdc50a94
YG
820 }
821 /* RIDXC[1:0] check bits */
822 if (opc == MMC_SEND_OP_COND || opc == MMC_ALL_SEND_CID ||
823 opc == MMC_SEND_CSD || opc == MMC_SEND_CID)
824 tmp |= CMD_SET_RIDXC_BITS;
825 /* RCRC7C[1:0] check bits */
826 if (opc == MMC_SEND_OP_COND)
827 tmp |= CMD_SET_CRC7C_BITS;
828 /* RCRC7C[1:0] internal CRC7 */
829 if (opc == MMC_ALL_SEND_CID ||
830 opc == MMC_SEND_CSD || opc == MMC_SEND_CID)
831 tmp |= CMD_SET_CRC7C_INTERNAL;
832
69983404 833 return (opc << 24) | tmp;
fdc50a94
YG
834}
835
e47bf32a 836static int sh_mmcif_data_trans(struct sh_mmcif_host *host,
f985da17 837 struct mmc_request *mrq, u32 opc)
fdc50a94 838{
fdc50a94
YG
839 switch (opc) {
840 case MMC_READ_MULTIPLE_BLOCK:
f985da17
GL
841 sh_mmcif_multi_read(host, mrq);
842 return 0;
fdc50a94 843 case MMC_WRITE_MULTIPLE_BLOCK:
f985da17
GL
844 sh_mmcif_multi_write(host, mrq);
845 return 0;
fdc50a94 846 case MMC_WRITE_BLOCK:
f985da17
GL
847 sh_mmcif_single_write(host, mrq);
848 return 0;
fdc50a94
YG
849 case MMC_READ_SINGLE_BLOCK:
850 case MMC_SEND_EXT_CSD:
f985da17
GL
851 sh_mmcif_single_read(host, mrq);
852 return 0;
fdc50a94 853 default:
e475b270 854 dev_err(&host->pd->dev, "Unsupported CMD%d\n", opc);
ee4b8887 855 return -EINVAL;
fdc50a94 856 }
fdc50a94
YG
857}
858
859static void sh_mmcif_start_cmd(struct sh_mmcif_host *host,
ee4b8887 860 struct mmc_request *mrq)
fdc50a94 861{
ee4b8887 862 struct mmc_command *cmd = mrq->cmd;
f985da17
GL
863 u32 opc = cmd->opcode;
864 u32 mask;
fdc50a94 865
fdc50a94 866 switch (opc) {
ee4b8887 867 /* response busy check */
a812ba0f 868 case MMC_SLEEP_AWAKE:
fdc50a94
YG
869 case MMC_SWITCH:
870 case MMC_STOP_TRANSMISSION:
871 case MMC_SET_WRITE_PROT:
872 case MMC_CLR_WRITE_PROT:
873 case MMC_ERASE:
ee4b8887 874 mask = MASK_START_CMD | MASK_MRBSYE;
fdc50a94
YG
875 break;
876 default:
ee4b8887 877 mask = MASK_START_CMD | MASK_MCRSPE;
fdc50a94
YG
878 break;
879 }
fdc50a94 880
967bcb77
GL
881 if (host->ccs_enable)
882 mask |= MASK_MCCSTO;
883
69983404 884 if (mrq->data) {
487d9fc5
MD
885 sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET, 0);
886 sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET,
887 mrq->data->blksz);
fdc50a94 888 }
69983404 889 opc = sh_mmcif_set_cmd(host, mrq);
fdc50a94 890
967bcb77
GL
891 if (host->ccs_enable)
892 sh_mmcif_writel(host->addr, MMCIF_CE_INT, 0xD80430C0);
893 else
894 sh_mmcif_writel(host->addr, MMCIF_CE_INT, 0xD80430C0 | INT_CCS);
487d9fc5 895 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, mask);
fdc50a94 896 /* set arg */
487d9fc5 897 sh_mmcif_writel(host->addr, MMCIF_CE_ARG, cmd->arg);
fdc50a94 898 /* set cmd */
487d9fc5 899 sh_mmcif_writel(host->addr, MMCIF_CE_CMD_SET, opc);
fdc50a94 900
f985da17
GL
901 host->wait_for = MMCIF_WAIT_FOR_CMD;
902 schedule_delayed_work(&host->timeout_work, host->timeout);
fdc50a94
YG
903}
904
905static void sh_mmcif_stop_cmd(struct sh_mmcif_host *host,
ee4b8887 906 struct mmc_request *mrq)
fdc50a94 907{
69983404
GL
908 switch (mrq->cmd->opcode) {
909 case MMC_READ_MULTIPLE_BLOCK:
fdc50a94 910 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12DRE);
69983404
GL
911 break;
912 case MMC_WRITE_MULTIPLE_BLOCK:
fdc50a94 913 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12RBE);
69983404
GL
914 break;
915 default:
e47bf32a 916 dev_err(&host->pd->dev, "unsupported stop cmd\n");
69983404 917 mrq->stop->error = sh_mmcif_error_manage(host);
fdc50a94
YG
918 return;
919 }
920
f985da17 921 host->wait_for = MMCIF_WAIT_FOR_STOP;
fdc50a94
YG
922}
923
924static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq)
925{
926 struct sh_mmcif_host *host = mmc_priv(mmc);
3b0beafc
GL
927 unsigned long flags;
928
929 spin_lock_irqsave(&host->lock, flags);
930 if (host->state != STATE_IDLE) {
e475b270 931 dev_dbg(&host->pd->dev, "%s() rejected, state %u\n", __func__, host->state);
3b0beafc
GL
932 spin_unlock_irqrestore(&host->lock, flags);
933 mrq->cmd->error = -EAGAIN;
934 mmc_request_done(mmc, mrq);
935 return;
936 }
937
938 host->state = STATE_REQUEST;
939 spin_unlock_irqrestore(&host->lock, flags);
fdc50a94
YG
940
941 switch (mrq->cmd->opcode) {
942 /* MMCIF does not support SD/SDIO command */
7541ca98
LP
943 case MMC_SLEEP_AWAKE: /* = SD_IO_SEND_OP_COND (5) */
944 case MMC_SEND_EXT_CSD: /* = SD_SEND_IF_COND (8) */
945 if ((mrq->cmd->flags & MMC_CMD_MASK) != MMC_CMD_BCR)
946 break;
fdc50a94 947 case MMC_APP_CMD:
92ff0c5b 948 case SD_IO_RW_DIRECT:
3b0beafc 949 host->state = STATE_IDLE;
fdc50a94
YG
950 mrq->cmd->error = -ETIMEDOUT;
951 mmc_request_done(mmc, mrq);
952 return;
fdc50a94
YG
953 default:
954 break;
955 }
f985da17
GL
956
957 host->mrq = mrq;
fdc50a94 958
f985da17 959 sh_mmcif_start_cmd(host, mrq);
fdc50a94
YG
960}
961
a6609267
GL
962static int sh_mmcif_clk_update(struct sh_mmcif_host *host)
963{
964 int ret = clk_enable(host->hclk);
965
966 if (!ret) {
967 host->clk = clk_get_rate(host->hclk);
968 host->mmc->f_max = host->clk / 2;
969 host->mmc->f_min = host->clk / 512;
970 }
971
972 return ret;
973}
974
7d17baa0
GL
975static void sh_mmcif_set_power(struct sh_mmcif_host *host, struct mmc_ios *ios)
976{
7d17baa0
GL
977 struct mmc_host *mmc = host->mmc;
978
7d17baa0
GL
979 if (!IS_ERR(mmc->supply.vmmc))
980 /* Errors ignored... */
981 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
982 ios->power_mode ? ios->vdd : 0);
983}
984
fdc50a94
YG
985static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
986{
987 struct sh_mmcif_host *host = mmc_priv(mmc);
3b0beafc
GL
988 unsigned long flags;
989
990 spin_lock_irqsave(&host->lock, flags);
991 if (host->state != STATE_IDLE) {
e475b270 992 dev_dbg(&host->pd->dev, "%s() rejected, state %u\n", __func__, host->state);
3b0beafc
GL
993 spin_unlock_irqrestore(&host->lock, flags);
994 return;
995 }
996
997 host->state = STATE_IOS;
998 spin_unlock_irqrestore(&host->lock, flags);
fdc50a94 999
f5e0cec4 1000 if (ios->power_mode == MMC_POWER_UP) {
c9b0cef2 1001 if (!host->card_present) {
faca6648
GL
1002 /* See if we also get DMA */
1003 sh_mmcif_request_dma(host, host->pd->dev.platform_data);
c9b0cef2 1004 host->card_present = true;
faca6648 1005 }
7d17baa0 1006 sh_mmcif_set_power(host, ios);
f5e0cec4 1007 } else if (ios->power_mode == MMC_POWER_OFF || !ios->clock) {
fdc50a94
YG
1008 /* clock stop */
1009 sh_mmcif_clock_control(host, 0);
faca6648 1010 if (ios->power_mode == MMC_POWER_OFF) {
c9b0cef2 1011 if (host->card_present) {
faca6648 1012 sh_mmcif_release_dma(host);
c9b0cef2 1013 host->card_present = false;
faca6648 1014 }
c9b0cef2
GL
1015 }
1016 if (host->power) {
f8a8ced7 1017 pm_runtime_put_sync(&host->pd->dev);
b289174f 1018 clk_disable(host->hclk);
c9b0cef2 1019 host->power = false;
7d17baa0
GL
1020 if (ios->power_mode == MMC_POWER_OFF)
1021 sh_mmcif_set_power(host, ios);
faca6648 1022 }
3b0beafc 1023 host->state = STATE_IDLE;
fdc50a94 1024 return;
fdc50a94
YG
1025 }
1026
c9b0cef2
GL
1027 if (ios->clock) {
1028 if (!host->power) {
a6609267 1029 sh_mmcif_clk_update(host);
c9b0cef2
GL
1030 pm_runtime_get_sync(&host->pd->dev);
1031 host->power = true;
1032 sh_mmcif_sync_reset(host);
1033 }
fdc50a94 1034 sh_mmcif_clock_control(host, ios->clock);
c9b0cef2 1035 }
fdc50a94 1036
555061f9 1037 host->timing = ios->timing;
fdc50a94 1038 host->bus_width = ios->bus_width;
3b0beafc 1039 host->state = STATE_IDLE;
fdc50a94
YG
1040}
1041
777271d0
AH
1042static int sh_mmcif_get_cd(struct mmc_host *mmc)
1043{
1044 struct sh_mmcif_host *host = mmc_priv(mmc);
1045 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
e480606a
GL
1046 int ret = mmc_gpio_get_cd(mmc);
1047
1048 if (ret >= 0)
1049 return ret;
777271d0 1050
bf68a812 1051 if (!p || !p->get_cd)
777271d0
AH
1052 return -ENOSYS;
1053 else
1054 return p->get_cd(host->pd);
1055}
1056
fdc50a94
YG
1057static struct mmc_host_ops sh_mmcif_ops = {
1058 .request = sh_mmcif_request,
1059 .set_ios = sh_mmcif_set_ios,
777271d0 1060 .get_cd = sh_mmcif_get_cd,
fdc50a94
YG
1061};
1062
f985da17
GL
1063static bool sh_mmcif_end_cmd(struct sh_mmcif_host *host)
1064{
1065 struct mmc_command *cmd = host->mrq->cmd;
69983404 1066 struct mmc_data *data = host->mrq->data;
f985da17
GL
1067 long time;
1068
1069 if (host->sd_error) {
1070 switch (cmd->opcode) {
1071 case MMC_ALL_SEND_CID:
1072 case MMC_SELECT_CARD:
1073 case MMC_APP_CMD:
1074 cmd->error = -ETIMEDOUT;
f985da17
GL
1075 break;
1076 default:
1077 cmd->error = sh_mmcif_error_manage(host);
f985da17
GL
1078 break;
1079 }
e475b270
TK
1080 dev_dbg(&host->pd->dev, "CMD%d error %d\n",
1081 cmd->opcode, cmd->error);
aba9d646 1082 host->sd_error = false;
f985da17
GL
1083 return false;
1084 }
1085 if (!(cmd->flags & MMC_RSP_PRESENT)) {
1086 cmd->error = 0;
1087 return false;
1088 }
1089
1090 sh_mmcif_get_response(host, cmd);
1091
69983404 1092 if (!data)
f985da17
GL
1093 return false;
1094
90f1cb43
GL
1095 /*
1096 * Completion can be signalled from DMA callback and error, so, have to
1097 * reset here, before setting .dma_active
1098 */
1099 init_completion(&host->dma_complete);
1100
69983404 1101 if (data->flags & MMC_DATA_READ) {
f985da17
GL
1102 if (host->chan_rx)
1103 sh_mmcif_start_dma_rx(host);
1104 } else {
1105 if (host->chan_tx)
1106 sh_mmcif_start_dma_tx(host);
1107 }
1108
1109 if (!host->dma_active) {
69983404 1110 data->error = sh_mmcif_data_trans(host, host->mrq, cmd->opcode);
99eb9d8d 1111 return !data->error;
f985da17
GL
1112 }
1113
1114 /* Running in the IRQ thread, can sleep */
1115 time = wait_for_completion_interruptible_timeout(&host->dma_complete,
1116 host->timeout);
eae30983
TK
1117
1118 if (data->flags & MMC_DATA_READ)
1119 dma_unmap_sg(host->chan_rx->device->dev,
1120 data->sg, data->sg_len,
1121 DMA_FROM_DEVICE);
1122 else
1123 dma_unmap_sg(host->chan_tx->device->dev,
1124 data->sg, data->sg_len,
1125 DMA_TO_DEVICE);
1126
f985da17
GL
1127 if (host->sd_error) {
1128 dev_err(host->mmc->parent,
1129 "Error IRQ while waiting for DMA completion!\n");
1130 /* Woken up by an error IRQ: abort DMA */
69983404 1131 data->error = sh_mmcif_error_manage(host);
f985da17 1132 } else if (!time) {
e475b270 1133 dev_err(host->mmc->parent, "DMA timeout!\n");
69983404 1134 data->error = -ETIMEDOUT;
f985da17 1135 } else if (time < 0) {
e475b270
TK
1136 dev_err(host->mmc->parent,
1137 "wait_for_completion_...() error %ld!\n", time);
69983404 1138 data->error = time;
f985da17
GL
1139 }
1140 sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC,
1141 BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
1142 host->dma_active = false;
1143
eae30983 1144 if (data->error) {
69983404 1145 data->bytes_xfered = 0;
eae30983
TK
1146 /* Abort DMA */
1147 if (data->flags & MMC_DATA_READ)
1148 dmaengine_terminate_all(host->chan_rx);
1149 else
1150 dmaengine_terminate_all(host->chan_tx);
1151 }
f985da17
GL
1152
1153 return false;
1154}
1155
1156static irqreturn_t sh_mmcif_irqt(int irq, void *dev_id)
1157{
1158 struct sh_mmcif_host *host = dev_id;
8047310e 1159 struct mmc_request *mrq;
5df460b1 1160 bool wait = false;
f985da17
GL
1161
1162 cancel_delayed_work_sync(&host->timeout_work);
1163
8047310e
GL
1164 mutex_lock(&host->thread_lock);
1165
1166 mrq = host->mrq;
1167 if (!mrq) {
1168 dev_dbg(&host->pd->dev, "IRQ thread state %u, wait %u: NULL mrq!\n",
1169 host->state, host->wait_for);
1170 mutex_unlock(&host->thread_lock);
1171 return IRQ_HANDLED;
1172 }
1173
f985da17
GL
1174 /*
1175 * All handlers return true, if processing continues, and false, if the
1176 * request has to be completed - successfully or not
1177 */
1178 switch (host->wait_for) {
1179 case MMCIF_WAIT_FOR_REQUEST:
1180 /* We're too late, the timeout has already kicked in */
8047310e 1181 mutex_unlock(&host->thread_lock);
f985da17
GL
1182 return IRQ_HANDLED;
1183 case MMCIF_WAIT_FOR_CMD:
5df460b1
GL
1184 /* Wait for data? */
1185 wait = sh_mmcif_end_cmd(host);
f985da17
GL
1186 break;
1187 case MMCIF_WAIT_FOR_MREAD:
5df460b1
GL
1188 /* Wait for more data? */
1189 wait = sh_mmcif_mread_block(host);
f985da17
GL
1190 break;
1191 case MMCIF_WAIT_FOR_READ:
5df460b1
GL
1192 /* Wait for data end? */
1193 wait = sh_mmcif_read_block(host);
f985da17
GL
1194 break;
1195 case MMCIF_WAIT_FOR_MWRITE:
5df460b1
GL
1196 /* Wait data to write? */
1197 wait = sh_mmcif_mwrite_block(host);
f985da17
GL
1198 break;
1199 case MMCIF_WAIT_FOR_WRITE:
5df460b1
GL
1200 /* Wait for data end? */
1201 wait = sh_mmcif_write_block(host);
f985da17
GL
1202 break;
1203 case MMCIF_WAIT_FOR_STOP:
1204 if (host->sd_error) {
1205 mrq->stop->error = sh_mmcif_error_manage(host);
e475b270 1206 dev_dbg(&host->pd->dev, "%s(): %d\n", __func__, mrq->stop->error);
f985da17
GL
1207 break;
1208 }
1209 sh_mmcif_get_cmd12response(host, mrq->stop);
1210 mrq->stop->error = 0;
1211 break;
1212 case MMCIF_WAIT_FOR_READ_END:
1213 case MMCIF_WAIT_FOR_WRITE_END:
e475b270 1214 if (host->sd_error) {
91ab252a 1215 mrq->data->error = sh_mmcif_error_manage(host);
e475b270
TK
1216 dev_dbg(&host->pd->dev, "%s(): %d\n", __func__, mrq->data->error);
1217 }
f985da17
GL
1218 break;
1219 default:
1220 BUG();
1221 }
1222
5df460b1
GL
1223 if (wait) {
1224 schedule_delayed_work(&host->timeout_work, host->timeout);
1225 /* Wait for more data */
8047310e 1226 mutex_unlock(&host->thread_lock);
5df460b1
GL
1227 return IRQ_HANDLED;
1228 }
1229
f985da17 1230 if (host->wait_for != MMCIF_WAIT_FOR_STOP) {
91ab252a 1231 struct mmc_data *data = mrq->data;
69983404
GL
1232 if (!mrq->cmd->error && data && !data->error)
1233 data->bytes_xfered =
1234 data->blocks * data->blksz;
f985da17 1235
69983404 1236 if (mrq->stop && !mrq->cmd->error && (!data || !data->error)) {
f985da17 1237 sh_mmcif_stop_cmd(host, mrq);
5df460b1
GL
1238 if (!mrq->stop->error) {
1239 schedule_delayed_work(&host->timeout_work, host->timeout);
8047310e 1240 mutex_unlock(&host->thread_lock);
f985da17 1241 return IRQ_HANDLED;
5df460b1 1242 }
f985da17
GL
1243 }
1244 }
1245
1246 host->wait_for = MMCIF_WAIT_FOR_REQUEST;
1247 host->state = STATE_IDLE;
69983404 1248 host->mrq = NULL;
f985da17
GL
1249 mmc_request_done(host->mmc, mrq);
1250
8047310e
GL
1251 mutex_unlock(&host->thread_lock);
1252
f985da17
GL
1253 return IRQ_HANDLED;
1254}
1255
fdc50a94
YG
1256static irqreturn_t sh_mmcif_intr(int irq, void *dev_id)
1257{
1258 struct sh_mmcif_host *host = dev_id;
967bcb77 1259 u32 state, mask;
fdc50a94 1260
487d9fc5 1261 state = sh_mmcif_readl(host->addr, MMCIF_CE_INT);
967bcb77
GL
1262 mask = sh_mmcif_readl(host->addr, MMCIF_CE_INT_MASK);
1263 if (host->ccs_enable)
1264 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~(state & mask));
1265 else
1266 sh_mmcif_writel(host->addr, MMCIF_CE_INT, INT_CCS | ~(state & mask));
8af50750 1267 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, state & MASK_CLEAN);
fdc50a94 1268
8af50750
GL
1269 if (state & ~MASK_CLEAN)
1270 dev_dbg(&host->pd->dev, "IRQ state = 0x%08x incompletely cleared\n",
1271 state);
1272
1273 if (state & INT_ERR_STS || state & ~INT_ALL) {
aa0787a9 1274 host->sd_error = true;
8af50750 1275 dev_dbg(&host->pd->dev, "int err state = 0x%08x\n", state);
fdc50a94 1276 }
f985da17 1277 if (state & ~(INT_CMD12RBE | INT_CMD12CRE)) {
8af50750
GL
1278 if (!host->mrq)
1279 dev_dbg(&host->pd->dev, "NULL IRQ state = 0x%08x\n", state);
f985da17
GL
1280 if (!host->dma_active)
1281 return IRQ_WAKE_THREAD;
1282 else if (host->sd_error)
1283 mmcif_dma_complete(host);
1284 } else {
aa0787a9 1285 dev_dbg(&host->pd->dev, "Unexpected IRQ 0x%x\n", state);
f985da17 1286 }
fdc50a94
YG
1287
1288 return IRQ_HANDLED;
1289}
1290
f985da17
GL
1291static void mmcif_timeout_work(struct work_struct *work)
1292{
1293 struct delayed_work *d = container_of(work, struct delayed_work, work);
1294 struct sh_mmcif_host *host = container_of(d, struct sh_mmcif_host, timeout_work);
1295 struct mmc_request *mrq = host->mrq;
8047310e 1296 unsigned long flags;
f985da17
GL
1297
1298 if (host->dying)
1299 /* Don't run after mmc_remove_host() */
1300 return;
1301
e475b270 1302 dev_err(&host->pd->dev, "Timeout waiting for %u on CMD%u\n",
8047310e
GL
1303 host->wait_for, mrq->cmd->opcode);
1304
1305 spin_lock_irqsave(&host->lock, flags);
1306 if (host->state == STATE_IDLE) {
1307 spin_unlock_irqrestore(&host->lock, flags);
1308 return;
1309 }
1310
1311 host->state = STATE_TIMEOUT;
1312 spin_unlock_irqrestore(&host->lock, flags);
1313
f985da17
GL
1314 /*
1315 * Handle races with cancel_delayed_work(), unless
1316 * cancel_delayed_work_sync() is used
1317 */
1318 switch (host->wait_for) {
1319 case MMCIF_WAIT_FOR_CMD:
1320 mrq->cmd->error = sh_mmcif_error_manage(host);
1321 break;
1322 case MMCIF_WAIT_FOR_STOP:
1323 mrq->stop->error = sh_mmcif_error_manage(host);
1324 break;
1325 case MMCIF_WAIT_FOR_MREAD:
1326 case MMCIF_WAIT_FOR_MWRITE:
1327 case MMCIF_WAIT_FOR_READ:
1328 case MMCIF_WAIT_FOR_WRITE:
1329 case MMCIF_WAIT_FOR_READ_END:
1330 case MMCIF_WAIT_FOR_WRITE_END:
69983404 1331 mrq->data->error = sh_mmcif_error_manage(host);
f985da17
GL
1332 break;
1333 default:
1334 BUG();
1335 }
1336
1337 host->state = STATE_IDLE;
1338 host->wait_for = MMCIF_WAIT_FOR_REQUEST;
f985da17
GL
1339 host->mrq = NULL;
1340 mmc_request_done(host->mmc, mrq);
1341}
1342
7d17baa0
GL
1343static void sh_mmcif_init_ocr(struct sh_mmcif_host *host)
1344{
1345 struct sh_mmcif_plat_data *pd = host->pd->dev.platform_data;
1346 struct mmc_host *mmc = host->mmc;
1347
1348 mmc_regulator_get_supply(mmc);
1349
bf68a812
GL
1350 if (!pd)
1351 return;
1352
7d17baa0
GL
1353 if (!mmc->ocr_avail)
1354 mmc->ocr_avail = pd->ocr;
1355 else if (pd->ocr)
1356 dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n");
1357}
1358
c3be1efd 1359static int sh_mmcif_probe(struct platform_device *pdev)
fdc50a94
YG
1360{
1361 int ret = 0, irq[2];
1362 struct mmc_host *mmc;
e47bf32a 1363 struct sh_mmcif_host *host;
e1aae2eb 1364 struct sh_mmcif_plat_data *pd = pdev->dev.platform_data;
fdc50a94
YG
1365 struct resource *res;
1366 void __iomem *reg;
2cd5b3e0 1367 const char *name;
fdc50a94
YG
1368
1369 irq[0] = platform_get_irq(pdev, 0);
1370 irq[1] = platform_get_irq(pdev, 1);
2cd5b3e0 1371 if (irq[0] < 0) {
e47bf32a 1372 dev_err(&pdev->dev, "Get irq error\n");
fdc50a94
YG
1373 return -ENXIO;
1374 }
1375 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1376 if (!res) {
1377 dev_err(&pdev->dev, "platform_get_resource error.\n");
1378 return -ENXIO;
1379 }
1380 reg = ioremap(res->start, resource_size(res));
1381 if (!reg) {
1382 dev_err(&pdev->dev, "ioremap error.\n");
1383 return -ENOMEM;
1384 }
e1aae2eb 1385
fdc50a94
YG
1386 mmc = mmc_alloc_host(sizeof(struct sh_mmcif_host), &pdev->dev);
1387 if (!mmc) {
1388 ret = -ENOMEM;
e1aae2eb 1389 goto ealloch;
fdc50a94 1390 }
2c9054dc
SB
1391
1392 ret = mmc_of_parse(mmc);
1393 if (ret < 0)
1394 goto eofparse;
1395
fdc50a94
YG
1396 host = mmc_priv(mmc);
1397 host->mmc = mmc;
1398 host->addr = reg;
f9fd54f2 1399 host->timeout = msecs_to_jiffies(1000);
967bcb77 1400 host->ccs_enable = !pd || !pd->ccs_unsupported;
fdc50a94 1401
fdc50a94
YG
1402 host->pd = pdev;
1403
3b0beafc 1404 spin_lock_init(&host->lock);
fdc50a94
YG
1405
1406 mmc->ops = &sh_mmcif_ops;
7d17baa0
GL
1407 sh_mmcif_init_ocr(host);
1408
eca889f6 1409 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_WAIT_WHILE_BUSY;
bf68a812 1410 if (pd && pd->caps)
fdc50a94 1411 mmc->caps |= pd->caps;
a782d688 1412 mmc->max_segs = 32;
fdc50a94 1413 mmc->max_blk_size = 512;
a782d688
GL
1414 mmc->max_req_size = PAGE_CACHE_SIZE * mmc->max_segs;
1415 mmc->max_blk_count = mmc->max_req_size / mmc->max_blk_size;
fdc50a94
YG
1416 mmc->max_seg_size = mmc->max_req_size;
1417
fdc50a94 1418 platform_set_drvdata(pdev, host);
a782d688 1419
faca6648
GL
1420 pm_runtime_enable(&pdev->dev);
1421 host->power = false;
1422
047a9ce7 1423 host->hclk = clk_get(&pdev->dev, NULL);
b289174f
GL
1424 if (IS_ERR(host->hclk)) {
1425 ret = PTR_ERR(host->hclk);
047a9ce7 1426 dev_err(&pdev->dev, "cannot get clock: %d\n", ret);
b289174f
GL
1427 goto eclkget;
1428 }
a6609267
GL
1429 ret = sh_mmcif_clk_update(host);
1430 if (ret < 0)
1431 goto eclkupdate;
b289174f 1432
faca6648
GL
1433 ret = pm_runtime_resume(&pdev->dev);
1434 if (ret < 0)
e1aae2eb 1435 goto eresume;
a782d688 1436
5ba85d95 1437 INIT_DELAYED_WORK(&host->timeout_work, mmcif_timeout_work);
fdc50a94 1438
b289174f 1439 sh_mmcif_sync_reset(host);
3b0beafc
GL
1440 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1441
2cd5b3e0
SK
1442 name = irq[1] < 0 ? dev_name(&pdev->dev) : "sh_mmc:error";
1443 ret = request_threaded_irq(irq[0], sh_mmcif_intr, sh_mmcif_irqt, 0, name, host);
fdc50a94 1444 if (ret) {
2cd5b3e0 1445 dev_err(&pdev->dev, "request_irq error (%s)\n", name);
e1aae2eb 1446 goto ereqirq0;
fdc50a94 1447 }
2cd5b3e0
SK
1448 if (irq[1] >= 0) {
1449 ret = request_threaded_irq(irq[1], sh_mmcif_intr, sh_mmcif_irqt,
1450 0, "sh_mmc:int", host);
1451 if (ret) {
1452 dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n");
1453 goto ereqirq1;
1454 }
fdc50a94
YG
1455 }
1456
e480606a 1457 if (pd && pd->use_cd_gpio) {
214fc309 1458 ret = mmc_gpio_request_cd(mmc, pd->cd_gpio, 0);
e480606a
GL
1459 if (ret < 0)
1460 goto erqcd;
1461 }
1462
8047310e
GL
1463 mutex_init(&host->thread_lock);
1464
b289174f 1465 clk_disable(host->hclk);
5ba85d95
GL
1466 ret = mmc_add_host(mmc);
1467 if (ret < 0)
e1aae2eb 1468 goto emmcaddh;
fdc50a94 1469
efe6a8ad
RW
1470 dev_pm_qos_expose_latency_limit(&pdev->dev, 100);
1471
e47bf32a
GL
1472 dev_info(&pdev->dev, "driver version %s\n", DRIVER_VERSION);
1473 dev_dbg(&pdev->dev, "chip ver H'%04x\n",
487d9fc5 1474 sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0x0000ffff);
fdc50a94
YG
1475 return ret;
1476
e1aae2eb 1477emmcaddh:
e480606a 1478erqcd:
2cd5b3e0
SK
1479 if (irq[1] >= 0)
1480 free_irq(irq[1], host);
e1aae2eb 1481ereqirq1:
5ba85d95 1482 free_irq(irq[0], host);
e1aae2eb 1483ereqirq0:
faca6648 1484 pm_runtime_suspend(&pdev->dev);
e1aae2eb 1485eresume:
fdc50a94 1486 clk_disable(host->hclk);
a6609267 1487eclkupdate:
b289174f 1488 clk_put(host->hclk);
e1aae2eb 1489eclkget:
b289174f 1490 pm_runtime_disable(&pdev->dev);
2c9054dc 1491eofparse:
fdc50a94 1492 mmc_free_host(mmc);
e1aae2eb
GL
1493ealloch:
1494 iounmap(reg);
fdc50a94
YG
1495 return ret;
1496}
1497
6e0ee714 1498static int sh_mmcif_remove(struct platform_device *pdev)
fdc50a94
YG
1499{
1500 struct sh_mmcif_host *host = platform_get_drvdata(pdev);
1501 int irq[2];
1502
f985da17 1503 host->dying = true;
b289174f 1504 clk_enable(host->hclk);
faca6648 1505 pm_runtime_get_sync(&pdev->dev);
fdc50a94 1506
efe6a8ad
RW
1507 dev_pm_qos_hide_latency_limit(&pdev->dev);
1508
faca6648 1509 mmc_remove_host(host->mmc);
3b0beafc
GL
1510 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1511
f985da17
GL
1512 /*
1513 * FIXME: cancel_delayed_work(_sync)() and free_irq() race with the
1514 * mmc_remove_host() call above. But swapping order doesn't help either
1515 * (a query on the linux-mmc mailing list didn't bring any replies).
1516 */
1517 cancel_delayed_work_sync(&host->timeout_work);
1518
fdc50a94
YG
1519 if (host->addr)
1520 iounmap(host->addr);
1521
aa0787a9
GL
1522 irq[0] = platform_get_irq(pdev, 0);
1523 irq[1] = platform_get_irq(pdev, 1);
fdc50a94
YG
1524
1525 free_irq(irq[0], host);
2cd5b3e0
SK
1526 if (irq[1] >= 0)
1527 free_irq(irq[1], host);
fdc50a94 1528
a0d28ba0 1529 clk_disable(host->hclk);
fdc50a94 1530 mmc_free_host(host->mmc);
faca6648
GL
1531 pm_runtime_put_sync(&pdev->dev);
1532 pm_runtime_disable(&pdev->dev);
fdc50a94
YG
1533
1534 return 0;
1535}
1536
faca6648
GL
1537#ifdef CONFIG_PM
1538static int sh_mmcif_suspend(struct device *dev)
1539{
b289174f 1540 struct sh_mmcif_host *host = dev_get_drvdata(dev);
faca6648
GL
1541 int ret = mmc_suspend_host(host->mmc);
1542
b289174f 1543 if (!ret)
faca6648 1544 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
faca6648
GL
1545
1546 return ret;
1547}
1548
1549static int sh_mmcif_resume(struct device *dev)
1550{
b289174f 1551 struct sh_mmcif_host *host = dev_get_drvdata(dev);
faca6648
GL
1552
1553 return mmc_resume_host(host->mmc);
1554}
1555#else
1556#define sh_mmcif_suspend NULL
1557#define sh_mmcif_resume NULL
1558#endif /* CONFIG_PM */
1559
bf68a812
GL
1560static const struct of_device_id mmcif_of_match[] = {
1561 { .compatible = "renesas,sh-mmcif" },
1562 { }
1563};
1564MODULE_DEVICE_TABLE(of, mmcif_of_match);
1565
faca6648
GL
1566static const struct dev_pm_ops sh_mmcif_dev_pm_ops = {
1567 .suspend = sh_mmcif_suspend,
1568 .resume = sh_mmcif_resume,
1569};
1570
fdc50a94
YG
1571static struct platform_driver sh_mmcif_driver = {
1572 .probe = sh_mmcif_probe,
1573 .remove = sh_mmcif_remove,
1574 .driver = {
1575 .name = DRIVER_NAME,
faca6648 1576 .pm = &sh_mmcif_dev_pm_ops,
bf68a812
GL
1577 .owner = THIS_MODULE,
1578 .of_match_table = mmcif_of_match,
fdc50a94
YG
1579 },
1580};
1581
d1f81a64 1582module_platform_driver(sh_mmcif_driver);
fdc50a94
YG
1583
1584MODULE_DESCRIPTION("SuperH on-chip MMC/eMMC interface driver");
1585MODULE_LICENSE("GPL");
aa0787a9 1586MODULE_ALIAS("platform:" DRIVER_NAME);
fdc50a94 1587MODULE_AUTHOR("Yusuke Goda <yusuke.goda.sx@renesas.com>");