blob: 8aee127e60b8c49812cc54d8ab68d62002389ca4 [file] [log] [blame]
Yusuke Godafdc50a92010-05-26 14:41:59 -07001/*
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
Guennadi Liakhovetski86df1742011-11-23 15:52:30 +010019#include <linux/bitops.h>
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +000020#include <linux/clk.h>
21#include <linux/completion.h>
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +000022#include <linux/delay.h>
Yusuke Godafdc50a92010-05-26 14:41:59 -070023#include <linux/dma-mapping.h>
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +000024#include <linux/dmaengine.h>
Yusuke Godafdc50a92010-05-26 14:41:59 -070025#include <linux/mmc/card.h>
26#include <linux/mmc/core.h>
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +000027#include <linux/mmc/host.h>
Yusuke Godafdc50a92010-05-26 14:41:59 -070028#include <linux/mmc/mmc.h>
29#include <linux/mmc/sdio.h>
Yusuke Godafdc50a92010-05-26 14:41:59 -070030#include <linux/mmc/sh_mmcif.h>
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +000031#include <linux/pagemap.h>
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +000032#include <linux/platform_device.h>
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +000033#include <linux/pm_runtime.h>
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +000034#include <linux/spinlock.h>
Paul Gortmaker88b47672011-07-03 15:15:51 -040035#include <linux/module.h>
Yusuke Godafdc50a92010-05-26 14:41:59 -070036
37#define DRIVER_NAME "sh_mmcif"
38#define DRIVER_VERSION "2010-04-28"
39
Yusuke Godafdc50a92010-05-26 14:41:59 -070040/* CE_CMD_SET */
41#define CMD_MASK 0x3f000000
42#define CMD_SET_RTYP_NO ((0 << 23) | (0 << 22))
43#define CMD_SET_RTYP_6B ((0 << 23) | (1 << 22)) /* R1/R1b/R3/R4/R5 */
44#define CMD_SET_RTYP_17B ((1 << 23) | (0 << 22)) /* R2 */
45#define CMD_SET_RBSY (1 << 21) /* R1b */
46#define CMD_SET_CCSEN (1 << 20)
47#define CMD_SET_WDAT (1 << 19) /* 1: on data, 0: no data */
48#define CMD_SET_DWEN (1 << 18) /* 1: write, 0: read */
49#define CMD_SET_CMLTE (1 << 17) /* 1: multi block trans, 0: single */
50#define CMD_SET_CMD12EN (1 << 16) /* 1: CMD12 auto issue */
51#define CMD_SET_RIDXC_INDEX ((0 << 15) | (0 << 14)) /* index check */
52#define CMD_SET_RIDXC_BITS ((0 << 15) | (1 << 14)) /* check bits check */
53#define CMD_SET_RIDXC_NO ((1 << 15) | (0 << 14)) /* no check */
54#define CMD_SET_CRC7C ((0 << 13) | (0 << 12)) /* CRC7 check*/
55#define CMD_SET_CRC7C_BITS ((0 << 13) | (1 << 12)) /* check bits check*/
56#define CMD_SET_CRC7C_INTERNAL ((1 << 13) | (0 << 12)) /* internal CRC7 check*/
57#define CMD_SET_CRC16C (1 << 10) /* 0: CRC16 check*/
58#define CMD_SET_CRCSTE (1 << 8) /* 1: not receive CRC status */
59#define CMD_SET_TBIT (1 << 7) /* 1: tran mission bit "Low" */
60#define CMD_SET_OPDM (1 << 6) /* 1: open/drain */
61#define CMD_SET_CCSH (1 << 5)
62#define CMD_SET_DATW_1 ((0 << 1) | (0 << 0)) /* 1bit */
63#define CMD_SET_DATW_4 ((0 << 1) | (1 << 0)) /* 4bit */
64#define CMD_SET_DATW_8 ((1 << 1) | (0 << 0)) /* 8bit */
65
66/* CE_CMD_CTRL */
67#define CMD_CTRL_BREAK (1 << 0)
68
69/* CE_BLOCK_SET */
70#define BLOCK_SIZE_MASK 0x0000ffff
71
Yusuke Godafdc50a92010-05-26 14:41:59 -070072/* CE_INT */
73#define INT_CCSDE (1 << 29)
74#define INT_CMD12DRE (1 << 26)
75#define INT_CMD12RBE (1 << 25)
76#define INT_CMD12CRE (1 << 24)
77#define INT_DTRANE (1 << 23)
78#define INT_BUFRE (1 << 22)
79#define INT_BUFWEN (1 << 21)
80#define INT_BUFREN (1 << 20)
81#define INT_CCSRCV (1 << 19)
82#define INT_RBSYE (1 << 17)
83#define INT_CRSPE (1 << 16)
84#define INT_CMDVIO (1 << 15)
85#define INT_BUFVIO (1 << 14)
86#define INT_WDATERR (1 << 11)
87#define INT_RDATERR (1 << 10)
88#define INT_RIDXERR (1 << 9)
89#define INT_RSPERR (1 << 8)
90#define INT_CCSTO (1 << 5)
91#define INT_CRCSTO (1 << 4)
92#define INT_WDATTO (1 << 3)
93#define INT_RDATTO (1 << 2)
94#define INT_RBSYTO (1 << 1)
95#define INT_RSPTO (1 << 0)
96#define INT_ERR_STS (INT_CMDVIO | INT_BUFVIO | INT_WDATERR | \
97 INT_RDATERR | INT_RIDXERR | INT_RSPERR | \
98 INT_CCSTO | INT_CRCSTO | INT_WDATTO | \
99 INT_RDATTO | INT_RBSYTO | INT_RSPTO)
100
101/* CE_INT_MASK */
102#define MASK_ALL 0x00000000
103#define MASK_MCCSDE (1 << 29)
104#define MASK_MCMD12DRE (1 << 26)
105#define MASK_MCMD12RBE (1 << 25)
106#define MASK_MCMD12CRE (1 << 24)
107#define MASK_MDTRANE (1 << 23)
108#define MASK_MBUFRE (1 << 22)
109#define MASK_MBUFWEN (1 << 21)
110#define MASK_MBUFREN (1 << 20)
111#define MASK_MCCSRCV (1 << 19)
112#define MASK_MRBSYE (1 << 17)
113#define MASK_MCRSPE (1 << 16)
114#define MASK_MCMDVIO (1 << 15)
115#define MASK_MBUFVIO (1 << 14)
116#define MASK_MWDATERR (1 << 11)
117#define MASK_MRDATERR (1 << 10)
118#define MASK_MRIDXERR (1 << 9)
119#define MASK_MRSPERR (1 << 8)
120#define MASK_MCCSTO (1 << 5)
121#define MASK_MCRCSTO (1 << 4)
122#define MASK_MWDATTO (1 << 3)
123#define MASK_MRDATTO (1 << 2)
124#define MASK_MRBSYTO (1 << 1)
125#define MASK_MRSPTO (1 << 0)
126
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100127#define MASK_START_CMD (MASK_MCMDVIO | MASK_MBUFVIO | MASK_MWDATERR | \
128 MASK_MRDATERR | MASK_MRIDXERR | MASK_MRSPERR | \
129 MASK_MCCSTO | MASK_MCRCSTO | MASK_MWDATTO | \
130 MASK_MRDATTO | MASK_MRBSYTO | MASK_MRSPTO)
131
Yusuke Godafdc50a92010-05-26 14:41:59 -0700132/* CE_HOST_STS1 */
133#define STS1_CMDSEQ (1 << 31)
134
135/* CE_HOST_STS2 */
136#define STS2_CRCSTE (1 << 31)
137#define STS2_CRC16E (1 << 30)
138#define STS2_AC12CRCE (1 << 29)
139#define STS2_RSPCRC7E (1 << 28)
140#define STS2_CRCSTEBE (1 << 27)
141#define STS2_RDATEBE (1 << 26)
142#define STS2_AC12REBE (1 << 25)
143#define STS2_RSPEBE (1 << 24)
144#define STS2_AC12IDXE (1 << 23)
145#define STS2_RSPIDXE (1 << 22)
146#define STS2_CCSTO (1 << 15)
147#define STS2_RDATTO (1 << 14)
148#define STS2_DATBSYTO (1 << 13)
149#define STS2_CRCSTTO (1 << 12)
150#define STS2_AC12BSYTO (1 << 11)
151#define STS2_RSPBSYTO (1 << 10)
152#define STS2_AC12RSPTO (1 << 9)
153#define STS2_RSPTO (1 << 8)
154#define STS2_CRC_ERR (STS2_CRCSTE | STS2_CRC16E | \
155 STS2_AC12CRCE | STS2_RSPCRC7E | STS2_CRCSTEBE)
156#define STS2_TIMEOUT_ERR (STS2_CCSTO | STS2_RDATTO | \
157 STS2_DATBSYTO | STS2_CRCSTTO | \
158 STS2_AC12BSYTO | STS2_RSPBSYTO | \
159 STS2_AC12RSPTO | STS2_RSPTO)
160
Yusuke Godafdc50a92010-05-26 14:41:59 -0700161#define CLKDEV_EMMC_DATA 52000000 /* 52MHz */
162#define CLKDEV_MMC_DATA 20000000 /* 20MHz */
163#define CLKDEV_INIT 400000 /* 400 KHz */
164
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +0000165enum mmcif_state {
166 STATE_IDLE,
167 STATE_REQUEST,
168 STATE_IOS,
169};
170
Yusuke Godafdc50a92010-05-26 14:41:59 -0700171struct sh_mmcif_host {
172 struct mmc_host *mmc;
173 struct mmc_data *data;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700174 struct platform_device *pd;
Guennadi Liakhovetski714c4a62011-08-30 18:26:39 +0200175 struct sh_dmae_slave dma_slave_tx;
176 struct sh_dmae_slave dma_slave_rx;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700177 struct clk *hclk;
178 unsigned int clk;
179 int bus_width;
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000180 bool sd_error;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700181 long timeout;
182 void __iomem *addr;
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000183 struct completion intr_wait;
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100184 spinlock_t lock; /* protect sh_mmcif_host::state */
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +0000185 enum mmcif_state state;
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +0000186 bool power;
Guennadi Liakhovetskic9b0cef2011-05-26 15:33:30 +0200187 bool card_present;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700188
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000189 /* DMA support */
190 struct dma_chan *chan_rx;
191 struct dma_chan *chan_tx;
192 struct completion dma_complete;
Linus Walleijf38f94c2011-02-10 16:09:50 +0100193 bool dma_active;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000194};
Yusuke Godafdc50a92010-05-26 14:41:59 -0700195
196static inline void sh_mmcif_bitset(struct sh_mmcif_host *host,
197 unsigned int reg, u32 val)
198{
Magnus Damm487d9fc2010-05-18 14:42:51 +0000199 writel(val | readl(host->addr + reg), host->addr + reg);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700200}
201
202static inline void sh_mmcif_bitclr(struct sh_mmcif_host *host,
203 unsigned int reg, u32 val)
204{
Magnus Damm487d9fc2010-05-18 14:42:51 +0000205 writel(~val & readl(host->addr + reg), host->addr + reg);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700206}
207
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000208static void mmcif_dma_complete(void *arg)
209{
210 struct sh_mmcif_host *host = arg;
211 dev_dbg(&host->pd->dev, "Command completed\n");
212
213 if (WARN(!host->data, "%s: NULL data in DMA completion!\n",
214 dev_name(&host->pd->dev)))
215 return;
216
217 if (host->data->flags & MMC_DATA_READ)
Linus Walleij1ed828d2011-02-10 16:09:29 +0100218 dma_unmap_sg(host->chan_rx->device->dev,
Linus Walleij9dc3fb52011-02-10 16:09:40 +0100219 host->data->sg, host->data->sg_len,
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000220 DMA_FROM_DEVICE);
221 else
Linus Walleij1ed828d2011-02-10 16:09:29 +0100222 dma_unmap_sg(host->chan_tx->device->dev,
Linus Walleij9dc3fb52011-02-10 16:09:40 +0100223 host->data->sg, host->data->sg_len,
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000224 DMA_TO_DEVICE);
225
226 complete(&host->dma_complete);
227}
228
229static void sh_mmcif_start_dma_rx(struct sh_mmcif_host *host)
230{
231 struct scatterlist *sg = host->data->sg;
232 struct dma_async_tx_descriptor *desc = NULL;
233 struct dma_chan *chan = host->chan_rx;
234 dma_cookie_t cookie = -EINVAL;
235 int ret;
236
Linus Walleij1ed828d2011-02-10 16:09:29 +0100237 ret = dma_map_sg(chan->device->dev, sg, host->data->sg_len,
238 DMA_FROM_DEVICE);
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000239 if (ret > 0) {
Linus Walleijf38f94c2011-02-10 16:09:50 +0100240 host->dma_active = true;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000241 desc = chan->device->device_prep_slave_sg(chan, sg, ret,
242 DMA_FROM_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
243 }
244
245 if (desc) {
246 desc->callback = mmcif_dma_complete;
247 desc->callback_param = host;
Linus Walleija5ece7d2011-02-10 16:10:00 +0100248 cookie = dmaengine_submit(desc);
249 sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN);
250 dma_async_issue_pending(chan);
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000251 }
252 dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n",
253 __func__, host->data->sg_len, ret, cookie);
254
255 if (!desc) {
256 /* DMA failed, fall back to PIO */
257 if (ret >= 0)
258 ret = -EIO;
259 host->chan_rx = NULL;
Linus Walleijf38f94c2011-02-10 16:09:50 +0100260 host->dma_active = false;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000261 dma_release_channel(chan);
262 /* Free the Tx channel too */
263 chan = host->chan_tx;
264 if (chan) {
265 host->chan_tx = NULL;
266 dma_release_channel(chan);
267 }
268 dev_warn(&host->pd->dev,
269 "DMA failed: %d, falling back to PIO\n", ret);
270 sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
271 }
272
273 dev_dbg(&host->pd->dev, "%s(): desc %p, cookie %d, sg[%d]\n", __func__,
274 desc, cookie, host->data->sg_len);
275}
276
277static void sh_mmcif_start_dma_tx(struct sh_mmcif_host *host)
278{
279 struct scatterlist *sg = host->data->sg;
280 struct dma_async_tx_descriptor *desc = NULL;
281 struct dma_chan *chan = host->chan_tx;
282 dma_cookie_t cookie = -EINVAL;
283 int ret;
284
Linus Walleij1ed828d2011-02-10 16:09:29 +0100285 ret = dma_map_sg(chan->device->dev, sg, host->data->sg_len,
286 DMA_TO_DEVICE);
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000287 if (ret > 0) {
Linus Walleijf38f94c2011-02-10 16:09:50 +0100288 host->dma_active = true;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000289 desc = chan->device->device_prep_slave_sg(chan, sg, ret,
290 DMA_TO_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
291 }
292
293 if (desc) {
294 desc->callback = mmcif_dma_complete;
295 desc->callback_param = host;
Linus Walleija5ece7d2011-02-10 16:10:00 +0100296 cookie = dmaengine_submit(desc);
297 sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAWEN);
298 dma_async_issue_pending(chan);
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000299 }
300 dev_dbg(&host->pd->dev, "%s(): mapped %d -> %d, cookie %d\n",
301 __func__, host->data->sg_len, ret, cookie);
302
303 if (!desc) {
304 /* DMA failed, fall back to PIO */
305 if (ret >= 0)
306 ret = -EIO;
307 host->chan_tx = NULL;
Linus Walleijf38f94c2011-02-10 16:09:50 +0100308 host->dma_active = false;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000309 dma_release_channel(chan);
310 /* Free the Rx channel too */
311 chan = host->chan_rx;
312 if (chan) {
313 host->chan_rx = NULL;
314 dma_release_channel(chan);
315 }
316 dev_warn(&host->pd->dev,
317 "DMA failed: %d, falling back to PIO\n", ret);
318 sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
319 }
320
321 dev_dbg(&host->pd->dev, "%s(): desc %p, cookie %d\n", __func__,
322 desc, cookie);
323}
324
325static bool sh_mmcif_filter(struct dma_chan *chan, void *arg)
326{
327 dev_dbg(chan->device->dev, "%s: slave data %p\n", __func__, arg);
328 chan->private = arg;
329 return true;
330}
331
332static void sh_mmcif_request_dma(struct sh_mmcif_host *host,
333 struct sh_mmcif_plat_data *pdata)
334{
Guennadi Liakhovetski714c4a62011-08-30 18:26:39 +0200335 struct sh_dmae_slave *tx, *rx;
Linus Walleijf38f94c2011-02-10 16:09:50 +0100336 host->dma_active = false;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000337
338 /* We can only either use DMA for both Tx and Rx or not use it at all */
339 if (pdata->dma) {
Guennadi Liakhovetski714c4a62011-08-30 18:26:39 +0200340 dev_warn(&host->pd->dev,
341 "Update your platform to use embedded DMA slave IDs\n");
342 tx = &pdata->dma->chan_priv_tx;
343 rx = &pdata->dma->chan_priv_rx;
344 } else {
345 tx = &host->dma_slave_tx;
346 tx->slave_id = pdata->slave_id_tx;
347 rx = &host->dma_slave_rx;
348 rx->slave_id = pdata->slave_id_rx;
349 }
350 if (tx->slave_id > 0 && rx->slave_id > 0) {
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000351 dma_cap_mask_t mask;
352
353 dma_cap_zero(mask);
354 dma_cap_set(DMA_SLAVE, mask);
355
Guennadi Liakhovetski714c4a62011-08-30 18:26:39 +0200356 host->chan_tx = dma_request_channel(mask, sh_mmcif_filter, tx);
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000357 dev_dbg(&host->pd->dev, "%s: TX: got channel %p\n", __func__,
358 host->chan_tx);
359
360 if (!host->chan_tx)
361 return;
362
Guennadi Liakhovetski714c4a62011-08-30 18:26:39 +0200363 host->chan_rx = dma_request_channel(mask, sh_mmcif_filter, rx);
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000364 dev_dbg(&host->pd->dev, "%s: RX: got channel %p\n", __func__,
365 host->chan_rx);
366
367 if (!host->chan_rx) {
368 dma_release_channel(host->chan_tx);
369 host->chan_tx = NULL;
370 return;
371 }
372
373 init_completion(&host->dma_complete);
374 }
375}
376
377static void sh_mmcif_release_dma(struct sh_mmcif_host *host)
378{
379 sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC, BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
380 /* Descriptors are freed automatically */
381 if (host->chan_tx) {
382 struct dma_chan *chan = host->chan_tx;
383 host->chan_tx = NULL;
384 dma_release_channel(chan);
385 }
386 if (host->chan_rx) {
387 struct dma_chan *chan = host->chan_rx;
388 host->chan_rx = NULL;
389 dma_release_channel(chan);
390 }
391
Linus Walleijf38f94c2011-02-10 16:09:50 +0100392 host->dma_active = false;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000393}
Yusuke Godafdc50a92010-05-26 14:41:59 -0700394
395static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk)
396{
397 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
398
399 sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
400 sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR);
401
402 if (!clk)
403 return;
404 if (p->sup_pclk && clk == host->clk)
405 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK);
406 else
407 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR &
Guennadi Liakhovetski86df1742011-11-23 15:52:30 +0100408 ((fls(host->clk / clk) - 1) << 16));
Yusuke Godafdc50a92010-05-26 14:41:59 -0700409
410 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
411}
412
413static void sh_mmcif_sync_reset(struct sh_mmcif_host *host)
414{
415 u32 tmp;
416
Magnus Damm487d9fc2010-05-18 14:42:51 +0000417 tmp = 0x010f0000 & sh_mmcif_readl(host->addr, MMCIF_CE_CLK_CTRL);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700418
Magnus Damm487d9fc2010-05-18 14:42:51 +0000419 sh_mmcif_writel(host->addr, MMCIF_CE_VERSION, SOFT_RST_ON);
420 sh_mmcif_writel(host->addr, MMCIF_CE_VERSION, SOFT_RST_OFF);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700421 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, tmp |
422 SRSPTO_256 | SRBSYTO_29 | SRWDTO_29 | SCCSTO_29);
423 /* byte swap on */
424 sh_mmcif_bitset(host, MMCIF_CE_BUF_ACC, BUF_ACC_ATYP);
425}
426
427static int sh_mmcif_error_manage(struct sh_mmcif_host *host)
428{
429 u32 state1, state2;
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100430 int ret, timeout;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700431
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000432 host->sd_error = false;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700433
Magnus Damm487d9fc2010-05-18 14:42:51 +0000434 state1 = sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS1);
435 state2 = sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS2);
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +0000436 dev_dbg(&host->pd->dev, "ERR HOST_STS1 = %08x\n", state1);
437 dev_dbg(&host->pd->dev, "ERR HOST_STS2 = %08x\n", state2);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700438
439 if (state1 & STS1_CMDSEQ) {
440 sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, CMD_CTRL_BREAK);
441 sh_mmcif_bitset(host, MMCIF_CE_CMD_CTRL, ~CMD_CTRL_BREAK);
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100442 for (timeout = 10000000; timeout; timeout--) {
Magnus Damm487d9fc2010-05-18 14:42:51 +0000443 if (!(sh_mmcif_readl(host->addr, MMCIF_CE_HOST_STS1)
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100444 & STS1_CMDSEQ))
Yusuke Godafdc50a92010-05-26 14:41:59 -0700445 break;
446 mdelay(1);
447 }
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100448 if (!timeout) {
449 dev_err(&host->pd->dev,
450 "Forced end of command sequence timeout err\n");
451 return -EIO;
452 }
Yusuke Godafdc50a92010-05-26 14:41:59 -0700453 sh_mmcif_sync_reset(host);
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +0000454 dev_dbg(&host->pd->dev, "Forced end of command sequence\n");
Yusuke Godafdc50a92010-05-26 14:41:59 -0700455 return -EIO;
456 }
457
458 if (state2 & STS2_CRC_ERR) {
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100459 dev_dbg(&host->pd->dev, ": CRC error\n");
Yusuke Godafdc50a92010-05-26 14:41:59 -0700460 ret = -EIO;
461 } else if (state2 & STS2_TIMEOUT_ERR) {
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100462 dev_dbg(&host->pd->dev, ": Timeout\n");
Yusuke Godafdc50a92010-05-26 14:41:59 -0700463 ret = -ETIMEDOUT;
464 } else {
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100465 dev_dbg(&host->pd->dev, ": End/Index error\n");
Yusuke Godafdc50a92010-05-26 14:41:59 -0700466 ret = -EIO;
467 }
468 return ret;
469}
470
471static int sh_mmcif_single_read(struct sh_mmcif_host *host,
472 struct mmc_request *mrq)
473{
474 struct mmc_data *data = mrq->data;
475 long time;
476 u32 blocksize, i, *p = sg_virt(data->sg);
477
Yusuke Godafdc50a92010-05-26 14:41:59 -0700478 /* buf read enable */
479 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000480 time = wait_for_completion_interruptible_timeout(&host->intr_wait,
481 host->timeout);
482 if (time <= 0 || host->sd_error)
Yusuke Godafdc50a92010-05-26 14:41:59 -0700483 return sh_mmcif_error_manage(host);
484
Yusuke Godafdc50a92010-05-26 14:41:59 -0700485 blocksize = (BLOCK_SIZE_MASK &
Magnus Damm487d9fc2010-05-18 14:42:51 +0000486 sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET)) + 3;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700487 for (i = 0; i < blocksize / 4; i++)
Magnus Damm487d9fc2010-05-18 14:42:51 +0000488 *p++ = sh_mmcif_readl(host->addr, MMCIF_CE_DATA);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700489
490 /* buffer read end */
491 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFRE);
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000492 time = wait_for_completion_interruptible_timeout(&host->intr_wait,
493 host->timeout);
494 if (time <= 0 || host->sd_error)
Yusuke Godafdc50a92010-05-26 14:41:59 -0700495 return sh_mmcif_error_manage(host);
496
Yusuke Godafdc50a92010-05-26 14:41:59 -0700497 return 0;
498}
499
500static int sh_mmcif_multi_read(struct sh_mmcif_host *host,
501 struct mmc_request *mrq)
502{
503 struct mmc_data *data = mrq->data;
504 long time;
505 u32 blocksize, i, j, sec, *p;
506
Magnus Damm487d9fc2010-05-18 14:42:51 +0000507 blocksize = BLOCK_SIZE_MASK & sh_mmcif_readl(host->addr,
508 MMCIF_CE_BLOCK_SET);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700509 for (j = 0; j < data->sg_len; j++) {
510 p = sg_virt(data->sg);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700511 for (sec = 0; sec < data->sg->length / blocksize; sec++) {
512 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
513 /* buf read enable */
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000514 time = wait_for_completion_interruptible_timeout(&host->intr_wait,
515 host->timeout);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700516
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000517 if (time <= 0 || host->sd_error)
Yusuke Godafdc50a92010-05-26 14:41:59 -0700518 return sh_mmcif_error_manage(host);
519
Yusuke Godafdc50a92010-05-26 14:41:59 -0700520 for (i = 0; i < blocksize / 4; i++)
Magnus Damm487d9fc2010-05-18 14:42:51 +0000521 *p++ = sh_mmcif_readl(host->addr,
522 MMCIF_CE_DATA);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700523 }
524 if (j < data->sg_len - 1)
525 data->sg++;
526 }
527 return 0;
528}
529
530static int sh_mmcif_single_write(struct sh_mmcif_host *host,
531 struct mmc_request *mrq)
532{
533 struct mmc_data *data = mrq->data;
534 long time;
535 u32 blocksize, i, *p = sg_virt(data->sg);
536
Yusuke Godafdc50a92010-05-26 14:41:59 -0700537 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
538
539 /* buf write enable */
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000540 time = wait_for_completion_interruptible_timeout(&host->intr_wait,
541 host->timeout);
542 if (time <= 0 || host->sd_error)
Yusuke Godafdc50a92010-05-26 14:41:59 -0700543 return sh_mmcif_error_manage(host);
544
Yusuke Godafdc50a92010-05-26 14:41:59 -0700545 blocksize = (BLOCK_SIZE_MASK &
Magnus Damm487d9fc2010-05-18 14:42:51 +0000546 sh_mmcif_readl(host->addr, MMCIF_CE_BLOCK_SET)) + 3;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700547 for (i = 0; i < blocksize / 4; i++)
Magnus Damm487d9fc2010-05-18 14:42:51 +0000548 sh_mmcif_writel(host->addr, MMCIF_CE_DATA, *p++);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700549
550 /* buffer write end */
551 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MDTRANE);
552
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000553 time = wait_for_completion_interruptible_timeout(&host->intr_wait,
554 host->timeout);
555 if (time <= 0 || host->sd_error)
Yusuke Godafdc50a92010-05-26 14:41:59 -0700556 return sh_mmcif_error_manage(host);
557
Yusuke Godafdc50a92010-05-26 14:41:59 -0700558 return 0;
559}
560
561static int sh_mmcif_multi_write(struct sh_mmcif_host *host,
562 struct mmc_request *mrq)
563{
564 struct mmc_data *data = mrq->data;
565 long time;
566 u32 i, sec, j, blocksize, *p;
567
Magnus Damm487d9fc2010-05-18 14:42:51 +0000568 blocksize = BLOCK_SIZE_MASK & sh_mmcif_readl(host->addr,
569 MMCIF_CE_BLOCK_SET);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700570
571 for (j = 0; j < data->sg_len; j++) {
572 p = sg_virt(data->sg);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700573 for (sec = 0; sec < data->sg->length / blocksize; sec++) {
574 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
575 /* buf write enable*/
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000576 time = wait_for_completion_interruptible_timeout(&host->intr_wait,
577 host->timeout);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700578
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000579 if (time <= 0 || host->sd_error)
Yusuke Godafdc50a92010-05-26 14:41:59 -0700580 return sh_mmcif_error_manage(host);
581
Yusuke Godafdc50a92010-05-26 14:41:59 -0700582 for (i = 0; i < blocksize / 4; i++)
Magnus Damm487d9fc2010-05-18 14:42:51 +0000583 sh_mmcif_writel(host->addr,
584 MMCIF_CE_DATA, *p++);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700585 }
586 if (j < data->sg_len - 1)
587 data->sg++;
588 }
589 return 0;
590}
591
592static void sh_mmcif_get_response(struct sh_mmcif_host *host,
593 struct mmc_command *cmd)
594{
595 if (cmd->flags & MMC_RSP_136) {
Magnus Damm487d9fc2010-05-18 14:42:51 +0000596 cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP3);
597 cmd->resp[1] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP2);
598 cmd->resp[2] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP1);
599 cmd->resp[3] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP0);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700600 } else
Magnus Damm487d9fc2010-05-18 14:42:51 +0000601 cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP0);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700602}
603
604static void sh_mmcif_get_cmd12response(struct sh_mmcif_host *host,
605 struct mmc_command *cmd)
606{
Magnus Damm487d9fc2010-05-18 14:42:51 +0000607 cmd->resp[0] = sh_mmcif_readl(host->addr, MMCIF_CE_RESP_CMD12);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700608}
609
610static u32 sh_mmcif_set_cmd(struct sh_mmcif_host *host,
611 struct mmc_request *mrq, struct mmc_command *cmd, u32 opc)
612{
613 u32 tmp = 0;
614
615 /* Response Type check */
616 switch (mmc_resp_type(cmd)) {
617 case MMC_RSP_NONE:
618 tmp |= CMD_SET_RTYP_NO;
619 break;
620 case MMC_RSP_R1:
621 case MMC_RSP_R1B:
622 case MMC_RSP_R3:
623 tmp |= CMD_SET_RTYP_6B;
624 break;
625 case MMC_RSP_R2:
626 tmp |= CMD_SET_RTYP_17B;
627 break;
628 default:
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +0000629 dev_err(&host->pd->dev, "Unsupported response type.\n");
Yusuke Godafdc50a92010-05-26 14:41:59 -0700630 break;
631 }
632 switch (opc) {
633 /* RBSY */
634 case MMC_SWITCH:
635 case MMC_STOP_TRANSMISSION:
636 case MMC_SET_WRITE_PROT:
637 case MMC_CLR_WRITE_PROT:
638 case MMC_ERASE:
639 case MMC_GEN_CMD:
640 tmp |= CMD_SET_RBSY;
641 break;
642 }
643 /* WDAT / DATW */
644 if (host->data) {
645 tmp |= CMD_SET_WDAT;
646 switch (host->bus_width) {
647 case MMC_BUS_WIDTH_1:
648 tmp |= CMD_SET_DATW_1;
649 break;
650 case MMC_BUS_WIDTH_4:
651 tmp |= CMD_SET_DATW_4;
652 break;
653 case MMC_BUS_WIDTH_8:
654 tmp |= CMD_SET_DATW_8;
655 break;
656 default:
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +0000657 dev_err(&host->pd->dev, "Unsupported bus width.\n");
Yusuke Godafdc50a92010-05-26 14:41:59 -0700658 break;
659 }
660 }
661 /* DWEN */
662 if (opc == MMC_WRITE_BLOCK || opc == MMC_WRITE_MULTIPLE_BLOCK)
663 tmp |= CMD_SET_DWEN;
664 /* CMLTE/CMD12EN */
665 if (opc == MMC_READ_MULTIPLE_BLOCK || opc == MMC_WRITE_MULTIPLE_BLOCK) {
666 tmp |= CMD_SET_CMLTE | CMD_SET_CMD12EN;
667 sh_mmcif_bitset(host, MMCIF_CE_BLOCK_SET,
668 mrq->data->blocks << 16);
669 }
670 /* RIDXC[1:0] check bits */
671 if (opc == MMC_SEND_OP_COND || opc == MMC_ALL_SEND_CID ||
672 opc == MMC_SEND_CSD || opc == MMC_SEND_CID)
673 tmp |= CMD_SET_RIDXC_BITS;
674 /* RCRC7C[1:0] check bits */
675 if (opc == MMC_SEND_OP_COND)
676 tmp |= CMD_SET_CRC7C_BITS;
677 /* RCRC7C[1:0] internal CRC7 */
678 if (opc == MMC_ALL_SEND_CID ||
679 opc == MMC_SEND_CSD || opc == MMC_SEND_CID)
680 tmp |= CMD_SET_CRC7C_INTERNAL;
681
682 return opc = ((opc << 24) | tmp);
683}
684
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +0000685static int sh_mmcif_data_trans(struct sh_mmcif_host *host,
Yusuke Godafdc50a92010-05-26 14:41:59 -0700686 struct mmc_request *mrq, u32 opc)
687{
Yusuke Godafdc50a92010-05-26 14:41:59 -0700688 switch (opc) {
689 case MMC_READ_MULTIPLE_BLOCK:
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100690 return sh_mmcif_multi_read(host, mrq);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700691 case MMC_WRITE_MULTIPLE_BLOCK:
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100692 return sh_mmcif_multi_write(host, mrq);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700693 case MMC_WRITE_BLOCK:
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100694 return sh_mmcif_single_write(host, mrq);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700695 case MMC_READ_SINGLE_BLOCK:
696 case MMC_SEND_EXT_CSD:
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100697 return sh_mmcif_single_read(host, mrq);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700698 default:
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +0000699 dev_err(&host->pd->dev, "UNSUPPORTED CMD = d'%08d\n", opc);
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100700 return -EINVAL;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700701 }
Yusuke Godafdc50a92010-05-26 14:41:59 -0700702}
703
704static void sh_mmcif_start_cmd(struct sh_mmcif_host *host,
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100705 struct mmc_request *mrq)
Yusuke Godafdc50a92010-05-26 14:41:59 -0700706{
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100707 struct mmc_command *cmd = mrq->cmd;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700708 long time;
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100709 int ret = 0;
710 u32 mask, opc = cmd->opcode;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700711
Yusuke Godafdc50a92010-05-26 14:41:59 -0700712 switch (opc) {
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100713 /* response busy check */
Yusuke Godafdc50a92010-05-26 14:41:59 -0700714 case MMC_SWITCH:
715 case MMC_STOP_TRANSMISSION:
716 case MMC_SET_WRITE_PROT:
717 case MMC_CLR_WRITE_PROT:
718 case MMC_ERASE:
719 case MMC_GEN_CMD:
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100720 mask = MASK_START_CMD | MASK_MRBSYE;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700721 break;
722 default:
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100723 mask = MASK_START_CMD | MASK_MCRSPE;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700724 break;
725 }
Yusuke Godafdc50a92010-05-26 14:41:59 -0700726
727 if (host->data) {
Magnus Damm487d9fc2010-05-18 14:42:51 +0000728 sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET, 0);
729 sh_mmcif_writel(host->addr, MMCIF_CE_BLOCK_SET,
730 mrq->data->blksz);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700731 }
732 opc = sh_mmcif_set_cmd(host, mrq, cmd, opc);
733
Magnus Damm487d9fc2010-05-18 14:42:51 +0000734 sh_mmcif_writel(host->addr, MMCIF_CE_INT, 0xD80430C0);
735 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, mask);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700736 /* set arg */
Magnus Damm487d9fc2010-05-18 14:42:51 +0000737 sh_mmcif_writel(host->addr, MMCIF_CE_ARG, cmd->arg);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700738 /* set cmd */
Magnus Damm487d9fc2010-05-18 14:42:51 +0000739 sh_mmcif_writel(host->addr, MMCIF_CE_CMD_SET, opc);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700740
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000741 time = wait_for_completion_interruptible_timeout(&host->intr_wait,
742 host->timeout);
743 if (time <= 0) {
Yusuke Godafdc50a92010-05-26 14:41:59 -0700744 cmd->error = sh_mmcif_error_manage(host);
745 return;
746 }
747 if (host->sd_error) {
748 switch (cmd->opcode) {
749 case MMC_ALL_SEND_CID:
750 case MMC_SELECT_CARD:
751 case MMC_APP_CMD:
752 cmd->error = -ETIMEDOUT;
753 break;
754 default:
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +0000755 dev_dbg(&host->pd->dev, "Cmd(d'%d) err\n",
756 cmd->opcode);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700757 cmd->error = sh_mmcif_error_manage(host);
758 break;
759 }
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000760 host->sd_error = false;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700761 return;
762 }
763 if (!(cmd->flags & MMC_RSP_PRESENT)) {
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +0000764 cmd->error = 0;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700765 return;
766 }
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000767 sh_mmcif_get_response(host, cmd);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700768 if (host->data) {
Linus Walleijf38f94c2011-02-10 16:09:50 +0100769 if (!host->dma_active) {
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000770 ret = sh_mmcif_data_trans(host, mrq, cmd->opcode);
771 } else {
772 long time =
773 wait_for_completion_interruptible_timeout(&host->dma_complete,
774 host->timeout);
775 if (!time)
776 ret = -ETIMEDOUT;
777 else if (time < 0)
778 ret = time;
779 sh_mmcif_bitclr(host, MMCIF_CE_BUF_ACC,
780 BUF_ACC_DMAREN | BUF_ACC_DMAWEN);
Linus Walleijf38f94c2011-02-10 16:09:50 +0100781 host->dma_active = false;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000782 }
Yusuke Godafdc50a92010-05-26 14:41:59 -0700783 if (ret < 0)
784 mrq->data->bytes_xfered = 0;
785 else
786 mrq->data->bytes_xfered =
787 mrq->data->blocks * mrq->data->blksz;
788 }
789 cmd->error = ret;
790}
791
792static void sh_mmcif_stop_cmd(struct sh_mmcif_host *host,
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100793 struct mmc_request *mrq)
Yusuke Godafdc50a92010-05-26 14:41:59 -0700794{
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100795 struct mmc_command *cmd = mrq->stop;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700796 long time;
797
798 if (mrq->cmd->opcode == MMC_READ_MULTIPLE_BLOCK)
799 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12DRE);
800 else if (mrq->cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK)
801 sh_mmcif_bitset(host, MMCIF_CE_INT_MASK, MASK_MCMD12RBE);
802 else {
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +0000803 dev_err(&host->pd->dev, "unsupported stop cmd\n");
Yusuke Godafdc50a92010-05-26 14:41:59 -0700804 cmd->error = sh_mmcif_error_manage(host);
805 return;
806 }
807
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000808 time = wait_for_completion_interruptible_timeout(&host->intr_wait,
809 host->timeout);
810 if (time <= 0 || host->sd_error) {
Yusuke Godafdc50a92010-05-26 14:41:59 -0700811 cmd->error = sh_mmcif_error_manage(host);
812 return;
813 }
814 sh_mmcif_get_cmd12response(host, cmd);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700815 cmd->error = 0;
816}
817
818static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq)
819{
820 struct sh_mmcif_host *host = mmc_priv(mmc);
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +0000821 unsigned long flags;
822
823 spin_lock_irqsave(&host->lock, flags);
824 if (host->state != STATE_IDLE) {
825 spin_unlock_irqrestore(&host->lock, flags);
826 mrq->cmd->error = -EAGAIN;
827 mmc_request_done(mmc, mrq);
828 return;
829 }
830
831 host->state = STATE_REQUEST;
832 spin_unlock_irqrestore(&host->lock, flags);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700833
834 switch (mrq->cmd->opcode) {
835 /* MMCIF does not support SD/SDIO command */
836 case SD_IO_SEND_OP_COND:
837 case MMC_APP_CMD:
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +0000838 host->state = STATE_IDLE;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700839 mrq->cmd->error = -ETIMEDOUT;
840 mmc_request_done(mmc, mrq);
841 return;
842 case MMC_SEND_EXT_CSD: /* = SD_SEND_IF_COND (8) */
843 if (!mrq->data) {
844 /* send_if_cond cmd (not support) */
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +0000845 host->state = STATE_IDLE;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700846 mrq->cmd->error = -ETIMEDOUT;
847 mmc_request_done(mmc, mrq);
848 return;
849 }
850 break;
851 default:
852 break;
853 }
854 host->data = mrq->data;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +0000855 if (mrq->data) {
856 if (mrq->data->flags & MMC_DATA_READ) {
857 if (host->chan_rx)
858 sh_mmcif_start_dma_rx(host);
859 } else {
860 if (host->chan_tx)
861 sh_mmcif_start_dma_tx(host);
862 }
863 }
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100864 sh_mmcif_start_cmd(host, mrq);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700865 host->data = NULL;
866
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +0000867 if (!mrq->cmd->error && mrq->stop)
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +0100868 sh_mmcif_stop_cmd(host, mrq);
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +0000869 host->state = STATE_IDLE;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700870 mmc_request_done(mmc, mrq);
871}
872
873static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
874{
875 struct sh_mmcif_host *host = mmc_priv(mmc);
876 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +0000877 unsigned long flags;
878
879 spin_lock_irqsave(&host->lock, flags);
880 if (host->state != STATE_IDLE) {
881 spin_unlock_irqrestore(&host->lock, flags);
882 return;
883 }
884
885 host->state = STATE_IOS;
886 spin_unlock_irqrestore(&host->lock, flags);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700887
Guennadi Liakhovetskif5e0cec2011-02-25 16:58:38 +0100888 if (ios->power_mode == MMC_POWER_UP) {
Guennadi Liakhovetskic9b0cef2011-05-26 15:33:30 +0200889 if (!host->card_present) {
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +0000890 /* See if we also get DMA */
891 sh_mmcif_request_dma(host, host->pd->dev.platform_data);
Guennadi Liakhovetskic9b0cef2011-05-26 15:33:30 +0200892 host->card_present = true;
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +0000893 }
Guennadi Liakhovetskif5e0cec2011-02-25 16:58:38 +0100894 } else if (ios->power_mode == MMC_POWER_OFF || !ios->clock) {
895 /* clock stop */
896 sh_mmcif_clock_control(host, 0);
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +0000897 if (ios->power_mode == MMC_POWER_OFF) {
Guennadi Liakhovetskic9b0cef2011-05-26 15:33:30 +0200898 if (host->card_present) {
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +0000899 sh_mmcif_release_dma(host);
Guennadi Liakhovetskic9b0cef2011-05-26 15:33:30 +0200900 host->card_present = false;
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +0000901 }
Guennadi Liakhovetskic9b0cef2011-05-26 15:33:30 +0200902 }
903 if (host->power) {
904 pm_runtime_put(&host->pd->dev);
905 host->power = false;
Guennadi Liakhovetskif6bc41f2011-11-16 10:10:41 +0100906 if (p->down_pwr && ios->power_mode == MMC_POWER_OFF)
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +0000907 p->down_pwr(host->pd);
908 }
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +0000909 host->state = STATE_IDLE;
Guennadi Liakhovetskif5e0cec2011-02-25 16:58:38 +0100910 return;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700911 }
912
Guennadi Liakhovetskic9b0cef2011-05-26 15:33:30 +0200913 if (ios->clock) {
914 if (!host->power) {
915 if (p->set_pwr)
916 p->set_pwr(host->pd, ios->power_mode);
917 pm_runtime_get_sync(&host->pd->dev);
918 host->power = true;
919 sh_mmcif_sync_reset(host);
920 }
Yusuke Godafdc50a92010-05-26 14:41:59 -0700921 sh_mmcif_clock_control(host, ios->clock);
Guennadi Liakhovetskic9b0cef2011-05-26 15:33:30 +0200922 }
Yusuke Godafdc50a92010-05-26 14:41:59 -0700923
924 host->bus_width = ios->bus_width;
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +0000925 host->state = STATE_IDLE;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700926}
927
Arnd Hannemann777271d2010-08-24 17:27:01 +0200928static int sh_mmcif_get_cd(struct mmc_host *mmc)
929{
930 struct sh_mmcif_host *host = mmc_priv(mmc);
931 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
932
933 if (!p->get_cd)
934 return -ENOSYS;
935 else
936 return p->get_cd(host->pd);
937}
938
Yusuke Godafdc50a92010-05-26 14:41:59 -0700939static struct mmc_host_ops sh_mmcif_ops = {
940 .request = sh_mmcif_request,
941 .set_ios = sh_mmcif_set_ios,
Arnd Hannemann777271d2010-08-24 17:27:01 +0200942 .get_cd = sh_mmcif_get_cd,
Yusuke Godafdc50a92010-05-26 14:41:59 -0700943};
944
Yusuke Godafdc50a92010-05-26 14:41:59 -0700945static irqreturn_t sh_mmcif_intr(int irq, void *dev_id)
946{
947 struct sh_mmcif_host *host = dev_id;
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000948 u32 state;
Yusuke Godafdc50a92010-05-26 14:41:59 -0700949 int err = 0;
950
Magnus Damm487d9fc2010-05-18 14:42:51 +0000951 state = sh_mmcif_readl(host->addr, MMCIF_CE_INT);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700952
Guennadi Liakhovetski8a8284a2011-12-14 19:31:51 +0100953 if (state & INT_ERR_STS) {
954 /* error interrupts - process first */
955 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~state);
956 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, state);
957 err = 1;
958 } else if (state & INT_RBSYE) {
Magnus Damm487d9fc2010-05-18 14:42:51 +0000959 sh_mmcif_writel(host->addr, MMCIF_CE_INT,
960 ~(INT_RBSYE | INT_CRSPE));
Yusuke Godafdc50a92010-05-26 14:41:59 -0700961 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MRBSYE);
962 } else if (state & INT_CRSPE) {
Magnus Damm487d9fc2010-05-18 14:42:51 +0000963 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_CRSPE);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700964 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MCRSPE);
965 } else if (state & INT_BUFREN) {
Magnus Damm487d9fc2010-05-18 14:42:51 +0000966 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_BUFREN);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700967 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MBUFREN);
968 } else if (state & INT_BUFWEN) {
Magnus Damm487d9fc2010-05-18 14:42:51 +0000969 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_BUFWEN);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700970 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MBUFWEN);
971 } else if (state & INT_CMD12DRE) {
Magnus Damm487d9fc2010-05-18 14:42:51 +0000972 sh_mmcif_writel(host->addr, MMCIF_CE_INT,
Yusuke Godafdc50a92010-05-26 14:41:59 -0700973 ~(INT_CMD12DRE | INT_CMD12RBE |
974 INT_CMD12CRE | INT_BUFRE));
975 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MCMD12DRE);
976 } else if (state & INT_BUFRE) {
Magnus Damm487d9fc2010-05-18 14:42:51 +0000977 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_BUFRE);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700978 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MBUFRE);
979 } else if (state & INT_DTRANE) {
Magnus Damm487d9fc2010-05-18 14:42:51 +0000980 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~INT_DTRANE);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700981 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MDTRANE);
982 } else if (state & INT_CMD12RBE) {
Magnus Damm487d9fc2010-05-18 14:42:51 +0000983 sh_mmcif_writel(host->addr, MMCIF_CE_INT,
Yusuke Godafdc50a92010-05-26 14:41:59 -0700984 ~(INT_CMD12RBE | INT_CMD12CRE));
985 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, MASK_MCMD12RBE);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700986 } else {
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +0000987 dev_dbg(&host->pd->dev, "Unsupported interrupt: 0x%x\n", state);
Magnus Damm487d9fc2010-05-18 14:42:51 +0000988 sh_mmcif_writel(host->addr, MMCIF_CE_INT, ~state);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700989 sh_mmcif_bitclr(host, MMCIF_CE_INT_MASK, state);
990 err = 1;
991 }
992 if (err) {
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000993 host->sd_error = true;
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +0000994 dev_dbg(&host->pd->dev, "int err state = %08x\n", state);
Yusuke Godafdc50a92010-05-26 14:41:59 -0700995 }
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +0000996 if (state & ~(INT_CMD12RBE | INT_CMD12CRE))
997 complete(&host->intr_wait);
998 else
999 dev_dbg(&host->pd->dev, "Unexpected IRQ 0x%x\n", state);
Yusuke Godafdc50a92010-05-26 14:41:59 -07001000
1001 return IRQ_HANDLED;
1002}
1003
1004static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1005{
1006 int ret = 0, irq[2];
1007 struct mmc_host *mmc;
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +00001008 struct sh_mmcif_host *host;
1009 struct sh_mmcif_plat_data *pd;
Yusuke Godafdc50a92010-05-26 14:41:59 -07001010 struct resource *res;
1011 void __iomem *reg;
1012 char clk_name[8];
1013
1014 irq[0] = platform_get_irq(pdev, 0);
1015 irq[1] = platform_get_irq(pdev, 1);
1016 if (irq[0] < 0 || irq[1] < 0) {
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +00001017 dev_err(&pdev->dev, "Get irq error\n");
Yusuke Godafdc50a92010-05-26 14:41:59 -07001018 return -ENXIO;
1019 }
1020 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1021 if (!res) {
1022 dev_err(&pdev->dev, "platform_get_resource error.\n");
1023 return -ENXIO;
1024 }
1025 reg = ioremap(res->start, resource_size(res));
1026 if (!reg) {
1027 dev_err(&pdev->dev, "ioremap error.\n");
1028 return -ENOMEM;
1029 }
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +00001030 pd = pdev->dev.platform_data;
Yusuke Godafdc50a92010-05-26 14:41:59 -07001031 if (!pd) {
1032 dev_err(&pdev->dev, "sh_mmcif plat data error.\n");
1033 ret = -ENXIO;
1034 goto clean_up;
1035 }
1036 mmc = mmc_alloc_host(sizeof(struct sh_mmcif_host), &pdev->dev);
1037 if (!mmc) {
1038 ret = -ENOMEM;
1039 goto clean_up;
1040 }
1041 host = mmc_priv(mmc);
1042 host->mmc = mmc;
1043 host->addr = reg;
1044 host->timeout = 1000;
1045
1046 snprintf(clk_name, sizeof(clk_name), "mmc%d", pdev->id);
1047 host->hclk = clk_get(&pdev->dev, clk_name);
1048 if (IS_ERR(host->hclk)) {
1049 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name);
1050 ret = PTR_ERR(host->hclk);
1051 goto clean_up1;
1052 }
1053 clk_enable(host->hclk);
1054 host->clk = clk_get_rate(host->hclk);
1055 host->pd = pdev;
1056
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +00001057 init_completion(&host->intr_wait);
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +00001058 spin_lock_init(&host->lock);
Yusuke Godafdc50a92010-05-26 14:41:59 -07001059
1060 mmc->ops = &sh_mmcif_ops;
1061 mmc->f_max = host->clk;
1062 /* close to 400KHz */
1063 if (mmc->f_max < 51200000)
1064 mmc->f_min = mmc->f_max / 128;
1065 else if (mmc->f_max < 102400000)
1066 mmc->f_min = mmc->f_max / 256;
1067 else
1068 mmc->f_min = mmc->f_max / 512;
1069 if (pd->ocr)
1070 mmc->ocr_avail = pd->ocr;
1071 mmc->caps = MMC_CAP_MMC_HIGHSPEED;
1072 if (pd->caps)
1073 mmc->caps |= pd->caps;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +00001074 mmc->max_segs = 32;
Yusuke Godafdc50a92010-05-26 14:41:59 -07001075 mmc->max_blk_size = 512;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +00001076 mmc->max_req_size = PAGE_CACHE_SIZE * mmc->max_segs;
1077 mmc->max_blk_count = mmc->max_req_size / mmc->max_blk_size;
Yusuke Godafdc50a92010-05-26 14:41:59 -07001078 mmc->max_seg_size = mmc->max_req_size;
1079
1080 sh_mmcif_sync_reset(host);
1081 platform_set_drvdata(pdev, host);
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +00001082
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +00001083 pm_runtime_enable(&pdev->dev);
1084 host->power = false;
1085
1086 ret = pm_runtime_resume(&pdev->dev);
1087 if (ret < 0)
1088 goto clean_up2;
Guennadi Liakhovetskia782d682010-11-24 10:05:22 +00001089
Yusuke Godafdc50a92010-05-26 14:41:59 -07001090 mmc_add_host(mmc);
1091
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +00001092 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1093
Yusuke Godafdc50a92010-05-26 14:41:59 -07001094 ret = request_irq(irq[0], sh_mmcif_intr, 0, "sh_mmc:error", host);
1095 if (ret) {
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +00001096 dev_err(&pdev->dev, "request_irq error (sh_mmc:error)\n");
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +00001097 goto clean_up3;
Yusuke Godafdc50a92010-05-26 14:41:59 -07001098 }
1099 ret = request_irq(irq[1], sh_mmcif_intr, 0, "sh_mmc:int", host);
1100 if (ret) {
1101 free_irq(irq[0], host);
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +00001102 dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n");
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +00001103 goto clean_up3;
Yusuke Godafdc50a92010-05-26 14:41:59 -07001104 }
1105
Guennadi Liakhovetskiee4b8882011-12-14 19:31:52 +01001106 mmc_detect_change(host->mmc, 0);
Yusuke Godafdc50a92010-05-26 14:41:59 -07001107
Guennadi Liakhovetskie47bf322010-11-24 10:05:18 +00001108 dev_info(&pdev->dev, "driver version %s\n", DRIVER_VERSION);
1109 dev_dbg(&pdev->dev, "chip ver H'%04x\n",
Magnus Damm487d9fc2010-05-18 14:42:51 +00001110 sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0x0000ffff);
Yusuke Godafdc50a92010-05-26 14:41:59 -07001111 return ret;
1112
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +00001113clean_up3:
1114 mmc_remove_host(mmc);
1115 pm_runtime_suspend(&pdev->dev);
Yusuke Godafdc50a92010-05-26 14:41:59 -07001116clean_up2:
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +00001117 pm_runtime_disable(&pdev->dev);
Yusuke Godafdc50a92010-05-26 14:41:59 -07001118 clk_disable(host->hclk);
1119clean_up1:
1120 mmc_free_host(mmc);
1121clean_up:
1122 if (reg)
1123 iounmap(reg);
1124 return ret;
1125}
1126
1127static int __devexit sh_mmcif_remove(struct platform_device *pdev)
1128{
1129 struct sh_mmcif_host *host = platform_get_drvdata(pdev);
1130 int irq[2];
1131
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +00001132 pm_runtime_get_sync(&pdev->dev);
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +00001133
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +00001134 mmc_remove_host(host->mmc);
Guennadi Liakhovetski3b0beaf2011-04-15 18:30:47 +00001135 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1136
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +00001137 if (host->addr)
1138 iounmap(host->addr);
1139
Yusuke Godafdc50a92010-05-26 14:41:59 -07001140 irq[0] = platform_get_irq(pdev, 0);
1141 irq[1] = platform_get_irq(pdev, 1);
1142
Yusuke Godafdc50a92010-05-26 14:41:59 -07001143 free_irq(irq[0], host);
1144 free_irq(irq[1], host);
1145
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +00001146 platform_set_drvdata(pdev, NULL);
1147
Yusuke Godafdc50a92010-05-26 14:41:59 -07001148 clk_disable(host->hclk);
1149 mmc_free_host(host->mmc);
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +00001150 pm_runtime_put_sync(&pdev->dev);
1151 pm_runtime_disable(&pdev->dev);
Yusuke Godafdc50a92010-05-26 14:41:59 -07001152
1153 return 0;
1154}
1155
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +00001156#ifdef CONFIG_PM
1157static int sh_mmcif_suspend(struct device *dev)
1158{
1159 struct platform_device *pdev = to_platform_device(dev);
1160 struct sh_mmcif_host *host = platform_get_drvdata(pdev);
1161 int ret = mmc_suspend_host(host->mmc);
1162
1163 if (!ret) {
1164 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1165 clk_disable(host->hclk);
1166 }
1167
1168 return ret;
1169}
1170
1171static int sh_mmcif_resume(struct device *dev)
1172{
1173 struct platform_device *pdev = to_platform_device(dev);
1174 struct sh_mmcif_host *host = platform_get_drvdata(pdev);
1175
1176 clk_enable(host->hclk);
1177
1178 return mmc_resume_host(host->mmc);
1179}
1180#else
1181#define sh_mmcif_suspend NULL
1182#define sh_mmcif_resume NULL
1183#endif /* CONFIG_PM */
1184
1185static const struct dev_pm_ops sh_mmcif_dev_pm_ops = {
1186 .suspend = sh_mmcif_suspend,
1187 .resume = sh_mmcif_resume,
1188};
1189
Yusuke Godafdc50a92010-05-26 14:41:59 -07001190static struct platform_driver sh_mmcif_driver = {
1191 .probe = sh_mmcif_probe,
1192 .remove = sh_mmcif_remove,
1193 .driver = {
1194 .name = DRIVER_NAME,
Guennadi Liakhovetskifaca6642011-05-05 16:20:48 +00001195 .pm = &sh_mmcif_dev_pm_ops,
Yusuke Godafdc50a92010-05-26 14:41:59 -07001196 },
1197};
1198
Axel Lind1f81a62011-11-26 12:55:43 +08001199module_platform_driver(sh_mmcif_driver);
Yusuke Godafdc50a92010-05-26 14:41:59 -07001200
1201MODULE_DESCRIPTION("SuperH on-chip MMC/eMMC interface driver");
1202MODULE_LICENSE("GPL");
Guennadi Liakhovetskiaa0787a2010-11-24 10:05:12 +00001203MODULE_ALIAS("platform:" DRIVER_NAME);
Yusuke Godafdc50a92010-05-26 14:41:59 -07001204MODULE_AUTHOR("Yusuke Goda <yusuke.goda.sx@renesas.com>");