blob: 63115a6de935947df0e878715963631846751784 [file] [log] [blame]
Ian Molton4a489982008-07-15 16:02:21 +01001/*
2 * linux/drivers/mmc/tmio_mmc.c
3 *
4 * Copyright (C) 2004 Ian Molton
5 * Copyright (C) 2007 Ian Molton
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * Driver for the MMC / SD / SDIO cell found in:
12 *
Philipp Zabele6f2c7a2009-06-04 20:12:37 +020013 * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
Ian Molton4a489982008-07-15 16:02:21 +010014 *
15 * This driver draws mainly on scattered spec sheets, Reverse engineering
16 * of the toshiba e800 SD driver and some parts of the 2.4 ASIC3 driver (4 bit
17 * support). (Further 4 bit support from a later datasheet).
18 *
19 * TODO:
20 * Investigate using a workqueue for PIO transfers
21 * Eliminate FIXMEs
22 * SDIO support
23 * Better Power management
24 * Handle MMC errors better
25 * double buffer support
26 *
27 */
28#include <linux/module.h>
29#include <linux/irq.h>
30#include <linux/device.h>
31#include <linux/delay.h>
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +000032#include <linux/dmaengine.h>
Ian Molton4a489982008-07-15 16:02:21 +010033#include <linux/mmc/host.h>
34#include <linux/mfd/core.h>
35#include <linux/mfd/tmio.h>
36
37#include "tmio_mmc.h"
38
Ian Molton4a489982008-07-15 16:02:21 +010039static void tmio_mmc_set_clock(struct tmio_mmc_host *host, int new_clock)
40{
Ian Moltonda46a0b2009-06-12 21:53:05 +010041 u32 clk = 0, clock;
Ian Molton4a489982008-07-15 16:02:21 +010042
43 if (new_clock) {
Ian Moltonda46a0b2009-06-12 21:53:05 +010044 for (clock = host->mmc->f_min, clk = 0x80000080;
45 new_clock >= (clock<<1); clk >>= 1)
Ian Molton4a489982008-07-15 16:02:21 +010046 clock <<= 1;
Ian Molton4a489982008-07-15 16:02:21 +010047 clk |= 0x100;
48 }
49
Ian Molton64e88672010-01-06 13:51:48 +010050 if (host->set_clk_div)
51 host->set_clk_div(host->pdev, (clk>>22) & 1);
52
Ian Moltonda46a0b2009-06-12 21:53:05 +010053 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk & 0x1ff);
Ian Molton4a489982008-07-15 16:02:21 +010054}
55
56static void tmio_mmc_clk_stop(struct tmio_mmc_host *host)
57{
Philipp Zabel5e746722009-06-04 20:12:32 +020058 sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0000);
Ian Molton4a489982008-07-15 16:02:21 +010059 msleep(10);
Philipp Zabel5e746722009-06-04 20:12:32 +020060 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~0x0100 &
61 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
Ian Molton4a489982008-07-15 16:02:21 +010062 msleep(10);
63}
64
65static void tmio_mmc_clk_start(struct tmio_mmc_host *host)
66{
Philipp Zabel5e746722009-06-04 20:12:32 +020067 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, 0x0100 |
68 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
Ian Molton4a489982008-07-15 16:02:21 +010069 msleep(10);
Philipp Zabel5e746722009-06-04 20:12:32 +020070 sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0100);
Ian Molton4a489982008-07-15 16:02:21 +010071 msleep(10);
72}
73
74static void reset(struct tmio_mmc_host *host)
75{
Ian Molton4a489982008-07-15 16:02:21 +010076 /* FIXME - should we set stop clock reg here */
Philipp Zabel5e746722009-06-04 20:12:32 +020077 sd_ctrl_write16(host, CTL_RESET_SD, 0x0000);
78 sd_ctrl_write16(host, CTL_RESET_SDIO, 0x0000);
Ian Molton4a489982008-07-15 16:02:21 +010079 msleep(10);
Philipp Zabel5e746722009-06-04 20:12:32 +020080 sd_ctrl_write16(host, CTL_RESET_SD, 0x0001);
81 sd_ctrl_write16(host, CTL_RESET_SDIO, 0x0001);
Ian Molton4a489982008-07-15 16:02:21 +010082 msleep(10);
83}
84
85static void
86tmio_mmc_finish_request(struct tmio_mmc_host *host)
87{
88 struct mmc_request *mrq = host->mrq;
89
90 host->mrq = NULL;
91 host->cmd = NULL;
92 host->data = NULL;
93
94 mmc_request_done(host->mmc, mrq);
95}
96
97/* These are the bitmasks the tmio chip requires to implement the MMC response
98 * types. Note that R1 and R6 are the same in this scheme. */
99#define APP_CMD 0x0040
100#define RESP_NONE 0x0300
101#define RESP_R1 0x0400
102#define RESP_R1B 0x0500
103#define RESP_R2 0x0600
104#define RESP_R3 0x0700
105#define DATA_PRESENT 0x0800
106#define TRANSFER_READ 0x1000
107#define TRANSFER_MULTI 0x2000
108#define SECURITY_CMD 0x4000
109
110static int
111tmio_mmc_start_command(struct tmio_mmc_host *host, struct mmc_command *cmd)
112{
Ian Molton4a489982008-07-15 16:02:21 +0100113 struct mmc_data *data = host->data;
114 int c = cmd->opcode;
115
116 /* Command 12 is handled by hardware */
117 if (cmd->opcode == 12 && !cmd->arg) {
Philipp Zabel5e746722009-06-04 20:12:32 +0200118 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x001);
Ian Molton4a489982008-07-15 16:02:21 +0100119 return 0;
120 }
121
122 switch (mmc_resp_type(cmd)) {
123 case MMC_RSP_NONE: c |= RESP_NONE; break;
124 case MMC_RSP_R1: c |= RESP_R1; break;
125 case MMC_RSP_R1B: c |= RESP_R1B; break;
126 case MMC_RSP_R2: c |= RESP_R2; break;
127 case MMC_RSP_R3: c |= RESP_R3; break;
128 default:
129 pr_debug("Unknown response type %d\n", mmc_resp_type(cmd));
130 return -EINVAL;
131 }
132
133 host->cmd = cmd;
134
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000135/* FIXME - this seems to be ok commented out but the spec suggest this bit
136 * should be set when issuing app commands.
Ian Molton4a489982008-07-15 16:02:21 +0100137 * if(cmd->flags & MMC_FLAG_ACMD)
138 * c |= APP_CMD;
139 */
140 if (data) {
141 c |= DATA_PRESENT;
142 if (data->blocks > 1) {
Philipp Zabel5e746722009-06-04 20:12:32 +0200143 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x100);
Ian Molton4a489982008-07-15 16:02:21 +0100144 c |= TRANSFER_MULTI;
145 }
146 if (data->flags & MMC_DATA_READ)
147 c |= TRANSFER_READ;
148 }
149
Philipp Zabel5e746722009-06-04 20:12:32 +0200150 enable_mmc_irqs(host, TMIO_MASK_CMD);
Ian Molton4a489982008-07-15 16:02:21 +0100151
152 /* Fire off the command */
Philipp Zabel5e746722009-06-04 20:12:32 +0200153 sd_ctrl_write32(host, CTL_ARG_REG, cmd->arg);
154 sd_ctrl_write16(host, CTL_SD_CMD, c);
Ian Molton4a489982008-07-15 16:02:21 +0100155
156 return 0;
157}
158
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000159/*
160 * This chip always returns (at least?) as much data as you ask for.
Ian Molton4a489982008-07-15 16:02:21 +0100161 * I'm unsure what happens if you ask for less than a block. This should be
162 * looked into to ensure that a funny length read doesnt hose the controller.
Ian Molton4a489982008-07-15 16:02:21 +0100163 */
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000164static void tmio_mmc_pio_irq(struct tmio_mmc_host *host)
Ian Molton4a489982008-07-15 16:02:21 +0100165{
Ian Molton4a489982008-07-15 16:02:21 +0100166 struct mmc_data *data = host->data;
Guennadi Liakhovetski5600efb2010-09-09 16:37:43 -0700167 void *sg_virt;
Ian Molton4a489982008-07-15 16:02:21 +0100168 unsigned short *buf;
169 unsigned int count;
170 unsigned long flags;
171
172 if (!data) {
173 pr_debug("Spurious PIO IRQ\n");
174 return;
175 }
176
Guennadi Liakhovetski5600efb2010-09-09 16:37:43 -0700177 sg_virt = tmio_mmc_kmap_atomic(host->sg_ptr, &flags);
178 buf = (unsigned short *)(sg_virt + host->sg_off);
Ian Molton4a489982008-07-15 16:02:21 +0100179
180 count = host->sg_ptr->length - host->sg_off;
181 if (count > data->blksz)
182 count = data->blksz;
183
184 pr_debug("count: %08x offset: %08x flags %08x\n",
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000185 count, host->sg_off, data->flags);
Ian Molton4a489982008-07-15 16:02:21 +0100186
187 /* Transfer the data */
188 if (data->flags & MMC_DATA_READ)
Philipp Zabel5e746722009-06-04 20:12:32 +0200189 sd_ctrl_read16_rep(host, CTL_SD_DATA_PORT, buf, count >> 1);
Ian Molton4a489982008-07-15 16:02:21 +0100190 else
Philipp Zabel5e746722009-06-04 20:12:32 +0200191 sd_ctrl_write16_rep(host, CTL_SD_DATA_PORT, buf, count >> 1);
Ian Molton4a489982008-07-15 16:02:21 +0100192
193 host->sg_off += count;
194
Guennadi Liakhovetski5600efb2010-09-09 16:37:43 -0700195 tmio_mmc_kunmap_atomic(sg_virt, &flags);
Ian Molton4a489982008-07-15 16:02:21 +0100196
197 if (host->sg_off == host->sg_ptr->length)
198 tmio_mmc_next_sg(host);
199
200 return;
201}
202
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000203static void tmio_mmc_do_data_irq(struct tmio_mmc_host *host)
Ian Molton4a489982008-07-15 16:02:21 +0100204{
Ian Molton4a489982008-07-15 16:02:21 +0100205 struct mmc_data *data = host->data;
Julia Lawalla0d045ca2008-12-16 16:13:09 +0100206 struct mmc_command *stop;
Ian Molton4a489982008-07-15 16:02:21 +0100207
208 host->data = NULL;
209
210 if (!data) {
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000211 dev_warn(&host->pdev->dev, "Spurious data end IRQ\n");
Ian Molton4a489982008-07-15 16:02:21 +0100212 return;
213 }
Julia Lawalla0d045ca2008-12-16 16:13:09 +0100214 stop = data->stop;
Ian Molton4a489982008-07-15 16:02:21 +0100215
216 /* FIXME - return correct transfer count on errors */
217 if (!data->error)
218 data->bytes_xfered = data->blocks * data->blksz;
219 else
220 data->bytes_xfered = 0;
221
222 pr_debug("Completed data request\n");
223
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000224 /*
225 * FIXME: other drivers allow an optional stop command of any given type
Ian Molton4a489982008-07-15 16:02:21 +0100226 * which we dont do, as the chip can auto generate them.
227 * Perhaps we can be smarter about when to use auto CMD12 and
228 * only issue the auto request when we know this is the desired
229 * stop command, allowing fallback to the stop command the
230 * upper layers expect. For now, we do what works.
231 */
232
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000233 if (data->flags & MMC_DATA_READ) {
234 if (!host->chan_rx)
235 disable_mmc_irqs(host, TMIO_MASK_READOP);
236 dev_dbg(&host->pdev->dev, "Complete Rx request %p\n",
237 host->mrq);
238 } else {
239 if (!host->chan_tx)
240 disable_mmc_irqs(host, TMIO_MASK_WRITEOP);
241 dev_dbg(&host->pdev->dev, "Complete Tx request %p\n",
242 host->mrq);
243 }
Ian Molton4a489982008-07-15 16:02:21 +0100244
245 if (stop) {
246 if (stop->opcode == 12 && !stop->arg)
Philipp Zabel5e746722009-06-04 20:12:32 +0200247 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x000);
Ian Molton4a489982008-07-15 16:02:21 +0100248 else
249 BUG();
250 }
251
252 tmio_mmc_finish_request(host);
253}
254
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000255static void tmio_mmc_data_irq(struct tmio_mmc_host *host)
256{
257 struct mmc_data *data = host->data;
258
259 if (!data)
260 return;
261
262 if (host->chan_tx && (data->flags & MMC_DATA_WRITE)) {
263 /*
264 * Has all data been written out yet? Testing on SuperH showed,
265 * that in most cases the first interrupt comes already with the
266 * BUSY status bit clear, but on some operations, like mount or
267 * in the beginning of a write / sync / umount, there is one
268 * DATAEND interrupt with the BUSY bit set, in this cases
269 * waiting for one more interrupt fixes the problem.
270 */
271 if (!(sd_ctrl_read32(host, CTL_STATUS) & TMIO_STAT_CMD_BUSY)) {
272 disable_mmc_irqs(host, TMIO_STAT_DATAEND);
273 tasklet_schedule(&host->dma_complete);
274 }
275 } else if (host->chan_rx && (data->flags & MMC_DATA_READ)) {
276 disable_mmc_irqs(host, TMIO_STAT_DATAEND);
277 tasklet_schedule(&host->dma_complete);
278 } else {
279 tmio_mmc_do_data_irq(host);
280 }
281}
282
283static void tmio_mmc_cmd_irq(struct tmio_mmc_host *host,
Ian Molton4a489982008-07-15 16:02:21 +0100284 unsigned int stat)
285{
Ian Molton4a489982008-07-15 16:02:21 +0100286 struct mmc_command *cmd = host->cmd;
Philipp Zabel5e746722009-06-04 20:12:32 +0200287 int i, addr;
Ian Molton4a489982008-07-15 16:02:21 +0100288
289 if (!host->cmd) {
290 pr_debug("Spurious CMD irq\n");
291 return;
292 }
293
294 host->cmd = NULL;
295
296 /* This controller is sicker than the PXA one. Not only do we need to
297 * drop the top 8 bits of the first response word, we also need to
298 * modify the order of the response for short response command types.
299 */
300
Philipp Zabel5e746722009-06-04 20:12:32 +0200301 for (i = 3, addr = CTL_RESPONSE ; i >= 0 ; i--, addr += 4)
302 cmd->resp[i] = sd_ctrl_read32(host, addr);
Ian Molton4a489982008-07-15 16:02:21 +0100303
304 if (cmd->flags & MMC_RSP_136) {
305 cmd->resp[0] = (cmd->resp[0] << 8) | (cmd->resp[1] >> 24);
306 cmd->resp[1] = (cmd->resp[1] << 8) | (cmd->resp[2] >> 24);
307 cmd->resp[2] = (cmd->resp[2] << 8) | (cmd->resp[3] >> 24);
308 cmd->resp[3] <<= 8;
309 } else if (cmd->flags & MMC_RSP_R3) {
310 cmd->resp[0] = cmd->resp[3];
311 }
312
313 if (stat & TMIO_STAT_CMDTIMEOUT)
314 cmd->error = -ETIMEDOUT;
315 else if (stat & TMIO_STAT_CRCFAIL && cmd->flags & MMC_RSP_CRC)
316 cmd->error = -EILSEQ;
317
318 /* If there is data to handle we enable data IRQs here, and
319 * we will ultimatley finish the request in the data_end handler.
320 * If theres no data or we encountered an error, finish now.
321 */
322 if (host->data && !cmd->error) {
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000323 if (host->data->flags & MMC_DATA_READ) {
324 if (!host->chan_rx)
325 enable_mmc_irqs(host, TMIO_MASK_READOP);
326 } else {
327 struct dma_chan *chan = host->chan_tx;
328 if (!chan)
329 enable_mmc_irqs(host, TMIO_MASK_WRITEOP);
330 else
331 tasklet_schedule(&host->dma_issue);
332 }
Ian Molton4a489982008-07-15 16:02:21 +0100333 } else {
334 tmio_mmc_finish_request(host);
335 }
336
337 return;
338}
339
Ian Molton4a489982008-07-15 16:02:21 +0100340static irqreturn_t tmio_mmc_irq(int irq, void *devid)
341{
342 struct tmio_mmc_host *host = devid;
Ian Molton4a489982008-07-15 16:02:21 +0100343 unsigned int ireg, irq_mask, status;
344
345 pr_debug("MMC IRQ begin\n");
346
Philipp Zabel5e746722009-06-04 20:12:32 +0200347 status = sd_ctrl_read32(host, CTL_STATUS);
348 irq_mask = sd_ctrl_read32(host, CTL_IRQ_MASK);
Ian Molton4a489982008-07-15 16:02:21 +0100349 ireg = status & TMIO_MASK_IRQ & ~irq_mask;
350
351 pr_debug_status(status);
352 pr_debug_status(ireg);
353
354 if (!ireg) {
Philipp Zabel5e746722009-06-04 20:12:32 +0200355 disable_mmc_irqs(host, status & ~irq_mask);
Ian Molton4a489982008-07-15 16:02:21 +0100356
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000357 pr_warning("tmio_mmc: Spurious irq, disabling! "
Ian Molton4a489982008-07-15 16:02:21 +0100358 "0x%08x 0x%08x 0x%08x\n", status, irq_mask, ireg);
359 pr_debug_status(status);
360
361 goto out;
362 }
363
364 while (ireg) {
365 /* Card insert / remove attempts */
366 if (ireg & (TMIO_STAT_CARD_INSERT | TMIO_STAT_CARD_REMOVE)) {
Philipp Zabel5e746722009-06-04 20:12:32 +0200367 ack_mmc_irqs(host, TMIO_STAT_CARD_INSERT |
Ian Molton4a489982008-07-15 16:02:21 +0100368 TMIO_STAT_CARD_REMOVE);
Magnus Damm6d9af5a2010-02-17 16:38:04 +0900369 mmc_detect_change(host->mmc, msecs_to_jiffies(100));
Ian Molton4a489982008-07-15 16:02:21 +0100370 }
371
372 /* CRC and other errors */
373/* if (ireg & TMIO_STAT_ERR_IRQ)
374 * handled |= tmio_error_irq(host, irq, stat);
375 */
376
377 /* Command completion */
378 if (ireg & TMIO_MASK_CMD) {
Philipp Zabel5e746722009-06-04 20:12:32 +0200379 ack_mmc_irqs(host, TMIO_MASK_CMD);
Ian Molton4a489982008-07-15 16:02:21 +0100380 tmio_mmc_cmd_irq(host, status);
381 }
382
383 /* Data transfer */
384 if (ireg & (TMIO_STAT_RXRDY | TMIO_STAT_TXRQ)) {
Philipp Zabel5e746722009-06-04 20:12:32 +0200385 ack_mmc_irqs(host, TMIO_STAT_RXRDY | TMIO_STAT_TXRQ);
Ian Molton4a489982008-07-15 16:02:21 +0100386 tmio_mmc_pio_irq(host);
387 }
388
389 /* Data transfer completion */
390 if (ireg & TMIO_STAT_DATAEND) {
Philipp Zabel5e746722009-06-04 20:12:32 +0200391 ack_mmc_irqs(host, TMIO_STAT_DATAEND);
Ian Molton4a489982008-07-15 16:02:21 +0100392 tmio_mmc_data_irq(host);
393 }
394
395 /* Check status - keep going until we've handled it all */
Philipp Zabel5e746722009-06-04 20:12:32 +0200396 status = sd_ctrl_read32(host, CTL_STATUS);
397 irq_mask = sd_ctrl_read32(host, CTL_IRQ_MASK);
Ian Molton4a489982008-07-15 16:02:21 +0100398 ireg = status & TMIO_MASK_IRQ & ~irq_mask;
399
400 pr_debug("Status at end of loop: %08x\n", status);
401 pr_debug_status(status);
402 }
403 pr_debug("MMC IRQ end\n");
404
405out:
406 return IRQ_HANDLED;
407}
408
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000409#ifdef CONFIG_TMIO_MMC_DMA
410static void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable)
411{
412#if defined(CONFIG_SUPERH) || defined(CONFIG_ARCH_SHMOBILE)
413 /* Switch DMA mode on or off - SuperH specific? */
414 sd_ctrl_write16(host, 0xd8, enable ? 2 : 0);
415#endif
416}
417
418static void tmio_dma_complete(void *arg)
419{
420 struct tmio_mmc_host *host = arg;
421
422 dev_dbg(&host->pdev->dev, "Command completed\n");
423
424 if (!host->data)
425 dev_warn(&host->pdev->dev, "NULL data in DMA completion!\n");
426 else
427 enable_mmc_irqs(host, TMIO_STAT_DATAEND);
428}
429
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100430static void tmio_mmc_start_dma_rx(struct tmio_mmc_host *host)
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000431{
432 struct scatterlist *sg = host->sg_ptr;
433 struct dma_async_tx_descriptor *desc = NULL;
434 struct dma_chan *chan = host->chan_rx;
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100435 dma_cookie_t cookie;
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000436 int ret;
437
438 ret = dma_map_sg(&host->pdev->dev, sg, host->sg_len, DMA_FROM_DEVICE);
439 if (ret > 0) {
440 host->dma_sglen = ret;
441 desc = chan->device->device_prep_slave_sg(chan, sg, ret,
442 DMA_FROM_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
443 }
444
445 if (desc) {
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000446 desc->callback = tmio_dma_complete;
447 desc->callback_param = host;
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100448 cookie = desc->tx_submit(desc);
449 if (cookie < 0) {
450 desc = NULL;
451 ret = cookie;
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000452 } else {
453 chan->device->device_issue_pending(chan);
454 }
455 }
456 dev_dbg(&host->pdev->dev, "%s(): mapped %d -> %d, cookie %d, rq %p\n",
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100457 __func__, host->sg_len, ret, cookie, host->mrq);
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000458
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100459 if (!desc) {
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000460 /* DMA failed, fall back to PIO */
461 if (ret >= 0)
462 ret = -EIO;
463 host->chan_rx = NULL;
464 dma_release_channel(chan);
465 /* Free the Tx channel too */
466 chan = host->chan_tx;
467 if (chan) {
468 host->chan_tx = NULL;
469 dma_release_channel(chan);
470 }
471 dev_warn(&host->pdev->dev,
472 "DMA failed: %d, falling back to PIO\n", ret);
473 tmio_mmc_enable_dma(host, false);
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000474 }
475
476 dev_dbg(&host->pdev->dev, "%s(): desc %p, cookie %d, sg[%d]\n", __func__,
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100477 desc, cookie, host->sg_len);
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000478}
479
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100480static void tmio_mmc_start_dma_tx(struct tmio_mmc_host *host)
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000481{
482 struct scatterlist *sg = host->sg_ptr;
483 struct dma_async_tx_descriptor *desc = NULL;
484 struct dma_chan *chan = host->chan_tx;
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100485 dma_cookie_t cookie;
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000486 int ret;
487
488 ret = dma_map_sg(&host->pdev->dev, sg, host->sg_len, DMA_TO_DEVICE);
489 if (ret > 0) {
490 host->dma_sglen = ret;
491 desc = chan->device->device_prep_slave_sg(chan, sg, ret,
492 DMA_TO_DEVICE, DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
493 }
494
495 if (desc) {
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000496 desc->callback = tmio_dma_complete;
497 desc->callback_param = host;
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100498 cookie = desc->tx_submit(desc);
499 if (cookie < 0) {
500 desc = NULL;
501 ret = cookie;
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000502 }
503 }
504 dev_dbg(&host->pdev->dev, "%s(): mapped %d -> %d, cookie %d, rq %p\n",
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100505 __func__, host->sg_len, ret, cookie, host->mrq);
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000506
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100507 if (!desc) {
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000508 /* DMA failed, fall back to PIO */
509 if (ret >= 0)
510 ret = -EIO;
511 host->chan_tx = NULL;
512 dma_release_channel(chan);
513 /* Free the Rx channel too */
514 chan = host->chan_rx;
515 if (chan) {
516 host->chan_rx = NULL;
517 dma_release_channel(chan);
518 }
519 dev_warn(&host->pdev->dev,
520 "DMA failed: %d, falling back to PIO\n", ret);
521 tmio_mmc_enable_dma(host, false);
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000522 }
523
524 dev_dbg(&host->pdev->dev, "%s(): desc %p, cookie %d\n", __func__,
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100525 desc, cookie);
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000526}
527
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100528static void tmio_mmc_start_dma(struct tmio_mmc_host *host,
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000529 struct mmc_data *data)
530{
531 if (data->flags & MMC_DATA_READ) {
532 if (host->chan_rx)
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100533 tmio_mmc_start_dma_rx(host);
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000534 } else {
535 if (host->chan_tx)
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100536 tmio_mmc_start_dma_tx(host);
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000537 }
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000538}
539
540static void tmio_issue_tasklet_fn(unsigned long priv)
541{
542 struct tmio_mmc_host *host = (struct tmio_mmc_host *)priv;
543 struct dma_chan *chan = host->chan_tx;
544
545 chan->device->device_issue_pending(chan);
546}
547
548static void tmio_tasklet_fn(unsigned long arg)
549{
550 struct tmio_mmc_host *host = (struct tmio_mmc_host *)arg;
551
552 if (host->data->flags & MMC_DATA_READ)
553 dma_unmap_sg(&host->pdev->dev, host->sg_ptr, host->dma_sglen,
554 DMA_FROM_DEVICE);
555 else
556 dma_unmap_sg(&host->pdev->dev, host->sg_ptr, host->dma_sglen,
557 DMA_TO_DEVICE);
558
559 tmio_mmc_do_data_irq(host);
560}
561
562/* It might be necessary to make filter MFD specific */
563static bool tmio_mmc_filter(struct dma_chan *chan, void *arg)
564{
565 dev_dbg(chan->device->dev, "%s: slave data %p\n", __func__, arg);
566 chan->private = arg;
567 return true;
568}
569
570static void tmio_mmc_request_dma(struct tmio_mmc_host *host,
571 struct tmio_mmc_data *pdata)
572{
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000573 /* We can only either use DMA for both Tx and Rx or not use it at all */
574 if (pdata->dma) {
575 dma_cap_mask_t mask;
576
577 dma_cap_zero(mask);
578 dma_cap_set(DMA_SLAVE, mask);
579
580 host->chan_tx = dma_request_channel(mask, tmio_mmc_filter,
581 pdata->dma->chan_priv_tx);
582 dev_dbg(&host->pdev->dev, "%s: TX: got channel %p\n", __func__,
583 host->chan_tx);
584
585 if (!host->chan_tx)
586 return;
587
588 host->chan_rx = dma_request_channel(mask, tmio_mmc_filter,
589 pdata->dma->chan_priv_rx);
590 dev_dbg(&host->pdev->dev, "%s: RX: got channel %p\n", __func__,
591 host->chan_rx);
592
593 if (!host->chan_rx) {
594 dma_release_channel(host->chan_tx);
595 host->chan_tx = NULL;
596 return;
597 }
598
599 tasklet_init(&host->dma_complete, tmio_tasklet_fn, (unsigned long)host);
600 tasklet_init(&host->dma_issue, tmio_issue_tasklet_fn, (unsigned long)host);
601
602 tmio_mmc_enable_dma(host, true);
603 }
604}
605
606static void tmio_mmc_release_dma(struct tmio_mmc_host *host)
607{
608 if (host->chan_tx) {
609 struct dma_chan *chan = host->chan_tx;
610 host->chan_tx = NULL;
611 dma_release_channel(chan);
612 }
613 if (host->chan_rx) {
614 struct dma_chan *chan = host->chan_rx;
615 host->chan_rx = NULL;
616 dma_release_channel(chan);
617 }
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000618}
619#else
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100620static void tmio_mmc_start_dma(struct tmio_mmc_host *host,
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000621 struct mmc_data *data)
622{
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000623}
624
625static void tmio_mmc_request_dma(struct tmio_mmc_host *host,
626 struct tmio_mmc_data *pdata)
627{
628 host->chan_tx = NULL;
629 host->chan_rx = NULL;
630}
631
632static void tmio_mmc_release_dma(struct tmio_mmc_host *host)
633{
634}
635#endif
636
Ian Molton4a489982008-07-15 16:02:21 +0100637static int tmio_mmc_start_data(struct tmio_mmc_host *host,
638 struct mmc_data *data)
639{
Yusuke Godaf1334fb2010-08-30 11:50:19 +0100640 struct mfd_cell *cell = host->pdev->dev.platform_data;
641 struct tmio_mmc_data *pdata = cell->driver_data;
642
Ian Molton4a489982008-07-15 16:02:21 +0100643 pr_debug("setup data transfer: blocksize %08x nr_blocks %d\n",
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000644 data->blksz, data->blocks);
Ian Molton4a489982008-07-15 16:02:21 +0100645
Yusuke Godaf1334fb2010-08-30 11:50:19 +0100646 /* Some hardware cannot perform 2 byte requests in 4 bit mode */
647 if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4) {
648 int blksz_2bytes = pdata->flags & TMIO_MMC_BLKSZ_2BYTES;
649
650 if (data->blksz < 2 || (data->blksz < 4 && !blksz_2bytes)) {
651 pr_err("%s: %d byte block unsupported in 4 bit mode\n",
652 mmc_hostname(host->mmc), data->blksz);
653 return -EINVAL;
654 }
Ian Molton4a489982008-07-15 16:02:21 +0100655 }
656
657 tmio_mmc_init_sg(host, data);
658 host->data = data;
659
660 /* Set transfer length / blocksize */
Philipp Zabel5e746722009-06-04 20:12:32 +0200661 sd_ctrl_write16(host, CTL_SD_XFER_LEN, data->blksz);
662 sd_ctrl_write16(host, CTL_XFER_BLK_COUNT, data->blocks);
Ian Molton4a489982008-07-15 16:02:21 +0100663
Guennadi Liakhovetskief17fee2010-11-11 12:19:47 +0100664 tmio_mmc_start_dma(host, data);
665
666 return 0;
Ian Molton4a489982008-07-15 16:02:21 +0100667}
668
669/* Process requests from the MMC layer */
670static void tmio_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
671{
672 struct tmio_mmc_host *host = mmc_priv(mmc);
673 int ret;
674
675 if (host->mrq)
676 pr_debug("request not null\n");
677
678 host->mrq = mrq;
679
680 if (mrq->data) {
681 ret = tmio_mmc_start_data(host, mrq->data);
682 if (ret)
683 goto fail;
684 }
685
686 ret = tmio_mmc_start_command(host, mrq->cmd);
Ian Molton4a489982008-07-15 16:02:21 +0100687 if (!ret)
688 return;
689
690fail:
691 mrq->cmd->error = ret;
692 mmc_request_done(mmc, mrq);
693}
694
695/* Set MMC clock / power.
696 * Note: This controller uses a simple divider scheme therefore it cannot
697 * run a MMC card at full speed (20MHz). The max clock is 24MHz on SD, but as
698 * MMC wont run that fast, it has to be clocked at 12MHz which is the next
699 * slowest setting.
700 */
701static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
702{
703 struct tmio_mmc_host *host = mmc_priv(mmc);
Ian Molton4a489982008-07-15 16:02:21 +0100704
705 if (ios->clock)
706 tmio_mmc_set_clock(host, ios->clock);
707
708 /* Power sequence - OFF -> ON -> UP */
709 switch (ios->power_mode) {
710 case MMC_POWER_OFF: /* power down SD bus */
Ian Molton64e88672010-01-06 13:51:48 +0100711 if (host->set_pwr)
712 host->set_pwr(host->pdev, 0);
Ian Molton4a489982008-07-15 16:02:21 +0100713 tmio_mmc_clk_stop(host);
714 break;
715 case MMC_POWER_ON: /* power up SD bus */
Ian Molton64e88672010-01-06 13:51:48 +0100716 if (host->set_pwr)
717 host->set_pwr(host->pdev, 1);
Ian Molton4a489982008-07-15 16:02:21 +0100718 break;
719 case MMC_POWER_UP: /* start bus clock */
720 tmio_mmc_clk_start(host);
721 break;
722 }
723
724 switch (ios->bus_width) {
725 case MMC_BUS_WIDTH_1:
Philipp Zabel5e746722009-06-04 20:12:32 +0200726 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x80e0);
Ian Molton4a489982008-07-15 16:02:21 +0100727 break;
728 case MMC_BUS_WIDTH_4:
Philipp Zabel5e746722009-06-04 20:12:32 +0200729 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x00e0);
Ian Molton4a489982008-07-15 16:02:21 +0100730 break;
731 }
732
733 /* Let things settle. delay taken from winCE driver */
734 udelay(140);
735}
736
737static int tmio_mmc_get_ro(struct mmc_host *mmc)
738{
739 struct tmio_mmc_host *host = mmc_priv(mmc);
Guennadi Liakhovetskiac8fb3e2010-05-19 18:36:02 +0000740 struct mfd_cell *cell = host->pdev->dev.platform_data;
741 struct tmio_mmc_data *pdata = cell->driver_data;
Ian Molton4a489982008-07-15 16:02:21 +0100742
Guennadi Liakhovetskiac8fb3e2010-05-19 18:36:02 +0000743 return ((pdata->flags & TMIO_MMC_WRPROTECT_DISABLE) ||
744 (sd_ctrl_read32(host, CTL_STATUS) & TMIO_STAT_WRPROTECT)) ? 0 : 1;
Ian Molton4a489982008-07-15 16:02:21 +0100745}
746
Arnd Hannemann19ca7502010-08-24 17:26:59 +0200747static int tmio_mmc_get_cd(struct mmc_host *mmc)
748{
749 struct tmio_mmc_host *host = mmc_priv(mmc);
750 struct mfd_cell *cell = host->pdev->dev.platform_data;
751 struct tmio_mmc_data *pdata = cell->driver_data;
752
753 if (!pdata->get_cd)
754 return -ENOSYS;
755 else
756 return pdata->get_cd(host->pdev);
757}
758
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000759static const struct mmc_host_ops tmio_mmc_ops = {
Ian Molton4a489982008-07-15 16:02:21 +0100760 .request = tmio_mmc_request,
761 .set_ios = tmio_mmc_set_ios,
762 .get_ro = tmio_mmc_get_ro,
Arnd Hannemann19ca7502010-08-24 17:26:59 +0200763 .get_cd = tmio_mmc_get_cd,
Ian Molton4a489982008-07-15 16:02:21 +0100764};
765
766#ifdef CONFIG_PM
767static int tmio_mmc_suspend(struct platform_device *dev, pm_message_t state)
768{
769 struct mfd_cell *cell = (struct mfd_cell *)dev->dev.platform_data;
770 struct mmc_host *mmc = platform_get_drvdata(dev);
771 int ret;
772
Matt Fleming1a13f8f2010-05-26 14:42:08 -0700773 ret = mmc_suspend_host(mmc);
Ian Molton4a489982008-07-15 16:02:21 +0100774
775 /* Tell MFD core it can disable us now.*/
776 if (!ret && cell->disable)
777 cell->disable(dev);
778
779 return ret;
780}
781
782static int tmio_mmc_resume(struct platform_device *dev)
783{
784 struct mfd_cell *cell = (struct mfd_cell *)dev->dev.platform_data;
785 struct mmc_host *mmc = platform_get_drvdata(dev);
Ian Molton4a489982008-07-15 16:02:21 +0100786 int ret = 0;
787
Ian Molton4a489982008-07-15 16:02:21 +0100788 /* Tell the MFD core we are ready to be enabled */
Ian Molton64e88672010-01-06 13:51:48 +0100789 if (cell->resume) {
790 ret = cell->resume(dev);
Ian Molton4a489982008-07-15 16:02:21 +0100791 if (ret)
792 goto out;
793 }
794
795 mmc_resume_host(mmc);
796
797out:
798 return ret;
799}
800#else
801#define tmio_mmc_suspend NULL
802#define tmio_mmc_resume NULL
803#endif
804
805static int __devinit tmio_mmc_probe(struct platform_device *dev)
806{
807 struct mfd_cell *cell = (struct mfd_cell *)dev->dev.platform_data;
Philipp Zabelf0e46cc2009-06-04 20:12:31 +0200808 struct tmio_mmc_data *pdata;
Ian Molton64e88672010-01-06 13:51:48 +0100809 struct resource *res_ctl;
Ian Molton4a489982008-07-15 16:02:21 +0100810 struct tmio_mmc_host *host;
811 struct mmc_host *mmc;
Philipp Zabeld6c9b5e2009-06-04 20:12:34 +0200812 int ret = -EINVAL;
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000813 u32 irq_mask = TMIO_MASK_CMD;
Ian Molton4a489982008-07-15 16:02:21 +0100814
Ian Molton64e88672010-01-06 13:51:48 +0100815 if (dev->num_resources != 2)
Ian Molton4a489982008-07-15 16:02:21 +0100816 goto out;
817
818 res_ctl = platform_get_resource(dev, IORESOURCE_MEM, 0);
Ian Molton64e88672010-01-06 13:51:48 +0100819 if (!res_ctl)
Ian Molton4a489982008-07-15 16:02:21 +0100820 goto out;
Ian Molton4a489982008-07-15 16:02:21 +0100821
Philipp Zabelf0e46cc2009-06-04 20:12:31 +0200822 pdata = cell->driver_data;
Philipp Zabeld6c9b5e2009-06-04 20:12:34 +0200823 if (!pdata || !pdata->hclk)
Philipp Zabelf0e46cc2009-06-04 20:12:31 +0200824 goto out;
Philipp Zabeld6c9b5e2009-06-04 20:12:34 +0200825
826 ret = -ENOMEM;
Philipp Zabelf0e46cc2009-06-04 20:12:31 +0200827
Ian Molton4a489982008-07-15 16:02:21 +0100828 mmc = mmc_alloc_host(sizeof(struct tmio_mmc_host), &dev->dev);
829 if (!mmc)
830 goto out;
831
832 host = mmc_priv(mmc);
833 host->mmc = mmc;
Ian Molton64e88672010-01-06 13:51:48 +0100834 host->pdev = dev;
Ian Molton4a489982008-07-15 16:02:21 +0100835 platform_set_drvdata(dev, mmc);
836
Ian Molton64e88672010-01-06 13:51:48 +0100837 host->set_pwr = pdata->set_pwr;
838 host->set_clk_div = pdata->set_clk_div;
839
Philipp Zabel5e746722009-06-04 20:12:32 +0200840 /* SD control register space size is 0x200, 0x400 for bus_shift=1 */
841 host->bus_shift = resource_size(res_ctl) >> 10;
842
Magnus Dammbc6772a2009-03-11 21:58:54 +0900843 host->ctl = ioremap(res_ctl->start, resource_size(res_ctl));
Ian Molton4a489982008-07-15 16:02:21 +0100844 if (!host->ctl)
845 goto host_free;
846
Ian Molton4a489982008-07-15 16:02:21 +0100847 mmc->ops = &tmio_mmc_ops;
Guennadi Liakhovetski729b0c72010-11-11 12:15:06 +0100848 mmc->caps = MMC_CAP_4_BIT_DATA | pdata->capabilities;
Philipp Zabelf0e46cc2009-06-04 20:12:31 +0200849 mmc->f_max = pdata->hclk;
850 mmc->f_min = mmc->f_max / 512;
Guennadi Liakhovetski729b0c72010-11-11 12:15:06 +0100851 mmc->max_segs = 32;
852 mmc->max_blk_size = 512;
853 mmc->max_blk_count = (PAGE_CACHE_SIZE / mmc->max_blk_size) *
854 mmc->max_segs;
855 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
856 mmc->max_seg_size = mmc->max_req_size;
Guennadi Liakhovetskia2b14dc2010-05-19 18:37:25 +0000857 if (pdata->ocr_mask)
858 mmc->ocr_avail = pdata->ocr_mask;
859 else
860 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
Ian Molton4a489982008-07-15 16:02:21 +0100861
Ian Molton4a489982008-07-15 16:02:21 +0100862 /* Tell the MFD core we are ready to be enabled */
863 if (cell->enable) {
864 ret = cell->enable(dev);
865 if (ret)
Ian Molton64e88672010-01-06 13:51:48 +0100866 goto unmap_ctl;
Ian Molton4a489982008-07-15 16:02:21 +0100867 }
868
Ian Molton4a489982008-07-15 16:02:21 +0100869 tmio_mmc_clk_stop(host);
870 reset(host);
871
872 ret = platform_get_irq(dev, 0);
873 if (ret >= 0)
874 host->irq = ret;
875 else
Magnus Damm7ee422d2010-02-17 16:38:23 +0900876 goto cell_disable;
Ian Molton4a489982008-07-15 16:02:21 +0100877
Philipp Zabel5e746722009-06-04 20:12:32 +0200878 disable_mmc_irqs(host, TMIO_MASK_ALL);
Ian Molton4a489982008-07-15 16:02:21 +0100879
Philipp Zabel6c413cc2009-06-04 20:12:33 +0200880 ret = request_irq(host->irq, tmio_mmc_irq, IRQF_DISABLED |
Magnus Damm14f1b752009-12-14 18:01:33 -0800881 IRQF_TRIGGER_FALLING, dev_name(&dev->dev), host);
Ian Molton4a489982008-07-15 16:02:21 +0100882 if (ret)
Magnus Damm7ee422d2010-02-17 16:38:23 +0900883 goto cell_disable;
Ian Molton4a489982008-07-15 16:02:21 +0100884
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000885 /* See if we also get DMA */
886 tmio_mmc_request_dma(host, pdata);
887
Ian Molton4a489982008-07-15 16:02:21 +0100888 mmc_add_host(mmc);
889
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000890 pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
891 (unsigned long)host->ctl, host->irq);
Ian Molton4a489982008-07-15 16:02:21 +0100892
893 /* Unmask the IRQs we want to know about */
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000894 if (!host->chan_rx)
895 irq_mask |= TMIO_MASK_READOP;
896 if (!host->chan_tx)
897 irq_mask |= TMIO_MASK_WRITEOP;
898 enable_mmc_irqs(host, irq_mask);
Ian Molton4a489982008-07-15 16:02:21 +0100899
900 return 0;
901
Magnus Damm7ee422d2010-02-17 16:38:23 +0900902cell_disable:
903 if (cell->disable)
904 cell->disable(dev);
Ian Molton4a489982008-07-15 16:02:21 +0100905unmap_ctl:
906 iounmap(host->ctl);
907host_free:
908 mmc_free_host(mmc);
909out:
910 return ret;
911}
912
913static int __devexit tmio_mmc_remove(struct platform_device *dev)
914{
Magnus Damm7ee422d2010-02-17 16:38:23 +0900915 struct mfd_cell *cell = (struct mfd_cell *)dev->dev.platform_data;
Ian Molton4a489982008-07-15 16:02:21 +0100916 struct mmc_host *mmc = platform_get_drvdata(dev);
917
918 platform_set_drvdata(dev, NULL);
919
920 if (mmc) {
921 struct tmio_mmc_host *host = mmc_priv(mmc);
922 mmc_remove_host(mmc);
Guennadi Liakhovetski311f3ac2010-05-19 18:34:22 +0000923 tmio_mmc_release_dma(host);
Ian Molton4a489982008-07-15 16:02:21 +0100924 free_irq(host->irq, host);
Magnus Damm7ee422d2010-02-17 16:38:23 +0900925 if (cell->disable)
926 cell->disable(dev);
Ian Molton4a489982008-07-15 16:02:21 +0100927 iounmap(host->ctl);
Magnus Dammbedcc452009-03-11 21:59:03 +0900928 mmc_free_host(mmc);
Ian Molton4a489982008-07-15 16:02:21 +0100929 }
930
931 return 0;
932}
933
934/* ------------------- device registration ----------------------- */
935
936static struct platform_driver tmio_mmc_driver = {
937 .driver = {
938 .name = "tmio-mmc",
939 .owner = THIS_MODULE,
940 },
941 .probe = tmio_mmc_probe,
942 .remove = __devexit_p(tmio_mmc_remove),
943 .suspend = tmio_mmc_suspend,
944 .resume = tmio_mmc_resume,
945};
946
947
948static int __init tmio_mmc_init(void)
949{
950 return platform_driver_register(&tmio_mmc_driver);
951}
952
953static void __exit tmio_mmc_exit(void)
954{
955 platform_driver_unregister(&tmio_mmc_driver);
956}
957
958module_init(tmio_mmc_init);
959module_exit(tmio_mmc_exit);
960
961MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
962MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
963MODULE_LICENSE("GPL v2");
964MODULE_ALIAS("platform:tmio-mmc");