pull master
[hh.org.git] / drivers / mmc / tmio_mmc.c
blobb7d1644cc304c8295c367dd580791e5c3d79c711
1 /*
2 * linux/drivers/mmc/tmio_mmc.c
4 * Copyright (C) 2004 Ian Molton
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Driver for the SD / SDIO cell found in:
12 * TC6393XB
14 * This driver draws mainly on scattered spec sheets, Reverse engineering
15 * of the toshiba e800 SD driver and some parts of the 2.4 ASIC3 driver (4 bit
16 * support).
18 * Supports MMC 1 bit transfers and SD 1 and 4 bit modes.
20 * TODO:
21 * Eliminate FIXMEs
22 * SDIO support
23 * Power management
24 * Handle MMC errors (at all)
27 #include <linux/module.h>
28 #include <linux/moduleparam.h>
29 #include <linux/init.h>
30 #include <linux/ioport.h>
31 #include <linux/irq.h>
32 #include <linux/device.h>
33 #include <linux/interrupt.h>
34 #include <linux/blkdev.h>
35 #include <linux/delay.h>
36 #include <linux/err.h>
37 #include <linux/mmc/mmc.h>
38 #include <linux/mmc/host.h>
39 #include <linux/mmc/card.h>
40 #include <linux/mmc/protocol.h>
41 #include <linux/scatterlist.h>
42 #include <linux/soc/tmio_mmc.h>
44 #include <asm/io.h>
45 #include <linux/clk.h>
46 #include <asm/mach-types.h>
48 #include "tmio_mmc.h"
50 #define DRIVER_NAME "tmio_mmc"
52 /* From wince:
53 TMIO_B(0xA1) |= 0x10; // Chip buffer of control
54 busy_wait(280);
56 TMIO_H(0x210) = 0x0800; // set sd base
57 TMIO_H(0x204) |= 0x0002; // sd command reg
58 TMIO_B(0x240) = 0x1F; // stop clock ctl
59 TMIO_B(0x24A) |= 0x02; // power_ctl_3
61 TMIO_H(0x820) = ~0x0018; // interrupt mask
62 TMIO_H(0x822) = 0x0000; // interrupt mask
63 TMIO_H(0x920) = 0x0000; // interrupt mask
64 TMIO_H(0x922) = 0x0000; // interrupt mask
65 TMIO_H(0x936) |= 0x0100; // card int ctl
66 TMIO_H(0x81C) = 0x0000; // set card stat to 0 (not buf/err status?)
67 TMIO_H(0x242) |= 0x01; // clock mode
70 static void reset_chip(struct tmio_mmc_host *host) {
71 /* Reset */
72 writew(0x0000, host->ctl_base + TMIO_CTRL_SD_SOFT_RESET_REG);
73 writew(0x0000, host->ctl_base + TMIO_CTRL_SDIO_SOFT_RESET_REG);
74 msleep(10);
75 writew(0x0001, host->ctl_base + TMIO_CTRL_SD_SOFT_RESET_REG);
76 writew(0x0001, host->ctl_base + TMIO_CTRL_SDIO_SOFT_RESET_REG);
77 msleep(10);
80 static void
81 tmio_mmc_finish_request(struct tmio_mmc_host *host)
83 struct mmc_request *mrq = host->mrq;
84 /* Write something to end the command */
85 host->mrq = NULL;
86 host->cmd = NULL;
87 host->data = NULL;
89 mmc_request_done(host->mmc, mrq);
92 /* These are the bitmasks the tmio chip requires to implement the MMC response
93 * types. Note that R1 and R6 are the same in this scheme. */
94 #define APP_CMD 0x0040
95 #define RESP_NONE 0x0300
96 #define RESP_R1 0x0400
97 #define RESP_R1B 0x0500
98 #define RESP_R2 0x0600
99 #define RESP_R3 0x0700
100 #define DATA_PRESENT 0x0800
101 #define TRANSFER_READ 0x1000
102 #define TRANSFER_MULTI 0x2000
103 #define SECURITY_CMD 0x4000
105 static void
106 tmio_mmc_start_command(struct tmio_mmc_host *host, struct mmc_command *cmd)
108 void *base = host->ctl_base;
109 struct mmc_data *data = host->data;
110 int c = cmd->opcode;
112 if(cmd->opcode == MMC_STOP_TRANSMISSION) {
113 writew(0x001, host->ctl_base + TMIO_CTRL_STOP_INTERNAL_ACTION_REG);
114 return;
117 switch(mmc_resp_type(cmd)) {
118 case MMC_RSP_NONE: c |= RESP_NONE; break;
119 case MMC_RSP_R1: c |= RESP_R1; break;
120 case MMC_RSP_R1B: c |= RESP_R1B; break;
121 case MMC_RSP_R2: c |= RESP_R2; break;
122 case MMC_RSP_R3: c |= RESP_R3; break;
123 default:
124 DBG("Unknown response type %d\n", mmc_resp_type(cmd));
127 host->cmd = cmd;
129 // FIXME - this seems to be ok comented out but the spec say this bit should
130 // be set when issuing app commands... the upper MC code doesnt help us
131 // here, though.
132 // if(cmd->flags & MMC_FLAG_ACMD)
133 // c |= APP_CMD;
134 if(data) {
135 c |= DATA_PRESENT;
136 if(data->blocks > 1) {
137 writew(0x100, host->ctl_base + TMIO_CTRL_STOP_INTERNAL_ACTION_REG);
138 c |= TRANSFER_MULTI;
140 if(data->flags & MMC_DATA_READ)
141 c |= TRANSFER_READ;
144 enable_mmc_irqs(host, TMIO_MASK_CMD);
146 /* Fire off the command */
147 write_long_reg(cmd->arg, base + TMIO_CTRL_ARG_REG_BASE);
148 writew(c, base + TMIO_CTRL_CMD_REG);
151 /* This chip always returns (at least?) as much data as you ask for.
152 * Im unsure what happens if you ask for less than a block. This should be
153 * looked into to ensure that a funny length read doesnt hose the controller
154 * data state machine.
155 * FIXME - this chip cannot do 1 and 2 byte data requests in 4 bit mode
157 static void tmio_mmc_pio_irq(struct tmio_mmc_host *host) {
158 struct mmc_data *data = host->data;
159 unsigned short *buf;
160 unsigned int count;
161 unsigned long flags;
163 if(!data){
164 DBG("Spurious PIO IRQ\n");
165 return;
168 buf = (unsigned short *)(tmio_mmc_kmap_atomic(host, &flags) +
169 host->sg_off);
171 /* Ensure we dont read more than one block. The chip will interrupt us
172 * When the next block is available.
173 * FIXME - this is probably not true now IRQ handling is fixed
175 count = host->sg_ptr->length - host->sg_off;
176 if(count > data->blksz)
177 count = data->blksz;
179 DBG("count: %08x offset: %08x flags %08x\n",
180 count, host->sg_off, data->flags);
182 /* Transfer the data */
183 if(data->flags & MMC_DATA_READ)
184 readsw(host->ctl_base + TMIO_CTRL_DATA_REG, buf, count >> 1);
185 else
186 writesw(host->ctl_base + TMIO_CTRL_DATA_REG, buf, count >> 1);
188 host->sg_off += count;
190 tmio_mmc_kunmap_atomic(host, &flags);
192 if(host->sg_off == host->sg_ptr->length)
193 tmio_mmc_next_sg(host);
195 return;
198 static void tmio_mmc_data_irq(struct tmio_mmc_host *host) {
199 struct mmc_data *data = host->data;
200 // FIXME - pxamci does checks for bad CRC, timeout, etc. here.
201 // Suspect we shouldnt but check anyhow.
203 host->data = NULL;
205 if(!data){
206 DBG("Spurious data end IRQ\n");
207 return;
210 // I suspect we can do better here too. PXA MCI cant do this right but
211 // we use PIO so we probably can.
212 if (data->error == MMC_ERR_NONE)
213 data->bytes_xfered = data->blocks * data->blksz;
214 else
215 data->bytes_xfered = 0;
217 DBG("Completed data request\n");
219 //FIXME - other drievrs allow an optional stop command of any given type
220 // which we dont do, as the chip can auto generate them.
221 // Perhaps we can be smarter about when to use auto CMD12 and
222 // only issue the auto request when we know this is the desired
223 // stop command, allowing fallback to the stop command the
224 // upper layers expect. For now, we do what works.
226 writew(0x000, host->ctl_base + TMIO_CTRL_STOP_INTERNAL_ACTION_REG);
228 if(data->flags & MMC_DATA_READ)
229 disable_mmc_irqs(host, TMIO_MASK_READOP);
230 else
231 disable_mmc_irqs(host, TMIO_MASK_WRITEOP);
233 tmio_mmc_finish_request(host);
236 static void tmio_mmc_cmd_irq(struct tmio_mmc_host *host, unsigned int stat) {
237 struct mmc_command *cmd = host->cmd;
239 if(!host->cmd) {
240 DBG("Spurious CMD irq\n");
241 return;
244 host->cmd = NULL;
246 /* This controller is sicker than the PXA one. not only do we need to
247 * drop the top 8 bits of the first response word, we also need to
248 * modify the order of the response for short response command types.
251 // FIXME - this works but readl is probably wrong...
252 cmd->resp[3] = readl(host->ctl_base + TMIO_CTRL_RESP_REG_BASE);
253 cmd->resp[2] = readl(host->ctl_base + TMIO_CTRL_RESP_REG_BASE + 4);
254 cmd->resp[1] = readl(host->ctl_base + TMIO_CTRL_RESP_REG_BASE + 8);
255 cmd->resp[0] = readl(host->ctl_base + TMIO_CTRL_RESP_REG_BASE + 12);
257 if(cmd->flags & MMC_RSP_136) {
258 cmd->resp[0] = (cmd->resp[0] <<8) | (cmd->resp[1] >>24);
259 cmd->resp[1] = (cmd->resp[1] <<8) | (cmd->resp[2] >>24);
260 cmd->resp[2] = (cmd->resp[2] <<8) | (cmd->resp[3] >>24);
261 cmd->resp[3] <<= 8;
263 else if(cmd->flags & MMC_RSP_R3) {
264 cmd->resp[0] = cmd->resp[3];
267 if (stat & TMIO_STAT_CMDTIMEOUT)
268 cmd->error = MMC_ERR_TIMEOUT;
269 else if (stat & TMIO_STAT_CRCFAIL && cmd->flags & MMC_RSP_CRC)
270 cmd->error = MMC_ERR_BADCRC;
272 if(cmd->error == MMC_ERR_NONE) {
273 switch (cmd->opcode) {
274 case SD_APP_SET_BUS_WIDTH: //FIXME - assumes 4 bit
275 writew(0x40e0, host->ctl_base + TMIO_CTRL_SD_MEMORY_CARD_OPTION_SETUP_REG);
276 break;
277 case MMC_SELECT_CARD:
278 if((cmd->arg >> 16) == 0) // deselect event
279 writew(0x80e0, host->ctl_base + TMIO_CTRL_SD_MEMORY_CARD_OPTION_SETUP_REG);
280 break;
284 /* If there is data to handle we enable data IRQs here, and
285 * we will ultimatley finish the request in the data_end handler.
286 * If theres no data or we encountered an error, finish now. */
287 if(host->data && cmd->error == MMC_ERR_NONE){
288 if(host->data->flags & MMC_DATA_READ)
289 enable_mmc_irqs(host, TMIO_MASK_READOP);
290 else
291 enable_mmc_irqs(host, TMIO_MASK_WRITEOP);
293 else {
294 tmio_mmc_finish_request(host);
297 return;
301 static irqreturn_t tmio_mmc_irq(int irq, void *devid)
303 struct tmio_mmc_host *host = devid;
304 unsigned int ireg, mask, status;
306 DBG("MMC IRQ begin\n");
308 status = read_long_reg(host->ctl_base + TMIO_CTRL_STATUS_REG_BASE);
309 mask = read_long_reg(host->ctl_base + TMIO_CTRL_IRQMASK_REG_BASE);
310 ireg = status & TMIO_MASK_IRQ & ~mask;
312 #ifdef CONFIG_MMC_DEBUG
313 debug_status(status);
314 debug_status(ireg);
315 #endif
316 if (!ireg) {
317 disable_mmc_irqs(host, status & ~mask);
318 #ifdef CONFIG_MMC_DEBUG
319 printk("tmio_mmc: Spurious MMC irq, disabling! 0x%08x 0x%08x 0x%08x\n", status, mask, ireg);
320 debug_status(status);
321 #endif
322 goto out;
325 while (ireg) {
326 /* Card insert / remove attempts */
327 if (ireg & (TMIO_STAT_CARD_INSERT | TMIO_STAT_CARD_REMOVE)){
328 ack_mmc_irqs(host, TMIO_STAT_CARD_INSERT | TMIO_STAT_CARD_REMOVE);
329 mmc_detect_change(host->mmc,0);
332 /* CRC and other errors */
333 // if (ireg & TMIO_STAT_ERR_IRQ)
334 // handled |= tmio_error_irq(host, irq, stat);
336 /* Command completion */
337 if (ireg & TMIO_MASK_CMD) {
338 tmio_mmc_cmd_irq(host, status);
339 ack_mmc_irqs(host, TMIO_MASK_CMD);
342 /* Data transfer */
343 if (ireg & (TMIO_STAT_RXRDY | TMIO_STAT_TXRQ)) {
344 ack_mmc_irqs(host, TMIO_STAT_RXRDY | TMIO_STAT_TXRQ);
345 tmio_mmc_pio_irq(host);
348 /* Data transfer completion */
349 if (ireg & TMIO_STAT_DATAEND) {
350 tmio_mmc_data_irq(host);
351 ack_mmc_irqs(host, TMIO_STAT_DATAEND);
354 /* Check status - keep going until we've handled it all */
355 status = read_long_reg(host->ctl_base + TMIO_CTRL_STATUS_REG_BASE);
356 mask = read_long_reg(host->ctl_base + TMIO_CTRL_IRQMASK_REG_BASE);
357 ireg = status & TMIO_MASK_IRQ & ~mask;
359 #ifdef CONFIG_MMC_DEBUG
360 DBG("Status at end of loop: %08x\n", status);
361 debug_status(status);
362 #endif
364 DBG("MMC IRQ end\n");
366 out:
367 return IRQ_HANDLED;
370 static void tmio_mmc_start_data(struct tmio_mmc_host *host, struct mmc_data *data)
372 DBG("setup data transfer: blocksize %08x nr_blocks %d\n",
373 data->blksz, data->blocks);
375 tmio_mmc_init_sg(host, data);
376 host->data = data;
378 /* Set transfer length / blocksize */
379 writew(data->blksz, host->ctl_base + TMIO_CTRL_DATALENGTH_REG);
380 writew(data->blocks, host->ctl_base + TMIO_CTRL_TRANSFER_BLOCK_COUNT_REG);
383 /* Process requests from the MMC layer */
384 static void tmio_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
386 struct tmio_mmc_host *host = mmc_priv(mmc);
388 WARN_ON(host->mrq != NULL);
390 host->mrq = mrq;
392 /* If we're performing a data request we need to setup some
393 extra information */
394 if (mrq->data)
395 tmio_mmc_start_data(host, mrq->data);
397 tmio_mmc_start_command(host, mrq->cmd);
400 /* Set MMC clock / power.
401 * Note: This controller uses a simple divider scheme therefore it cannot
402 * run a MMC card at full speed (20MHz). The max clock is 24MHz on SD, but as
403 * MMC wont run that fast, it has to be clocked at 12MHz which is the next
404 * slowest setting.
406 static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
408 struct tmio_mmc_host *host = mmc_priv(mmc);
409 u32 clk = 0, clock;
411 DBG("clock %uHz busmode %u powermode %u Vdd %u\n",
412 ios->clock, ios->bus_mode, ios->power_mode, ios->vdd);
413 //FIXME - this works but may not quite be the right way to do it
414 if (ios->clock) {
415 for(clock = 46875, clk = 512 ; ios->clock >= (clock<<1); ){
416 clock <<= 1;
417 clk >>= 1;
419 if(clk & 0x1)
420 clk = 0x20000;
421 clk >>= 2;
422 if(clk & 0x8000) // For 24MHz we disable the divider.
423 writew(0, host->cnf_base + TMIO_CONF_CLOCK_MODE_REG);
424 else
425 writew(1, host->cnf_base + TMIO_CONF_CLOCK_MODE_REG);
426 writew(clk | 0x100, host->ctl_base + TMIO_CTRL_SD_CARD_CLOCK_CONTROL_REG);
427 DBG("clk = %04x\n", clk | 0x100);
429 else
430 writew(0, host->ctl_base + TMIO_CTRL_SD_CARD_CLOCK_CONTROL_REG);
432 switch (ios->power_mode) {
433 case MMC_POWER_OFF:
434 writeb(0x00, host->cnf_base + TMIO_CONF_POWER_CNTL_REG_2);
435 break;
436 case MMC_POWER_UP:
437 //FIXME - investigate the possibility of turning on our main
438 // clock here.
439 break;
440 case MMC_POWER_ON:
441 writeb(0x02, host->cnf_base + TMIO_CONF_POWER_CNTL_REG_2);
442 break;
444 // Potentially we may need a 140us pause here. FIXME
445 udelay(140);
448 static int tmio_mmc_get_ro(struct mmc_host *mmc) {
449 struct tmio_mmc_host *host = mmc_priv(mmc);
451 return (readw(host->ctl_base + TMIO_CTRL_STATUS_REG_BASE) & TMIO_STAT_WRPROTECT)?0:1;
454 static struct mmc_host_ops tmio_mmc_ops = {
455 .request = tmio_mmc_request,
456 .set_ios = tmio_mmc_set_ios,
457 .get_ro = tmio_mmc_get_ro,
460 #define platform_get_platdata(d) ((void*)((d)->dev.platform_data))
462 static void hwinit(struct tmio_mmc_host *host, struct platform_device *dev) {
464 struct tmio_mmc_hwconfig *hwconfig = platform_get_platdata(dev);
465 unsigned long addr_shift = 0;
467 addr_shift = hwconfig?hwconfig->address_shift:0;
469 /* Enable the MMC function */
470 writeb(SDCREN, host->cnf_base + TMIO_CONF_COMMAND_REG);
472 /* Map the MMC registers into the chips config space*/
473 writel((dev->resource[0].start & 0xfffe) >> addr_shift, host->cnf_base + TMIO_CONF_SD_CTRL_BASE_ADDRESS_REG);
475 /* Enable our clock (if needed!) */
476 if(hwconfig && hwconfig->set_mmc_clock)
477 hwconfig->set_mmc_clock(dev, MMC_CLOCK_ENABLED);
479 writeb(0x01f, host->cnf_base + TMIO_CONF_STOP_CLOCK_CONTROL_REG);
480 writeb(readb(host->cnf_base + TMIO_CONF_POWER_CNTL_REG_3) | 0x02,
481 host->cnf_base + TMIO_CONF_POWER_CNTL_REG_3);
482 writeb(readb(host->cnf_base + TMIO_CONF_CLOCK_MODE_REG) | 0x01,
483 host->cnf_base + TMIO_CONF_CLOCK_MODE_REG);
485 /* disable clock */
486 writew(0x0000, host->ctl_base + TMIO_CTRL_CLOCK_AND_WAIT_CONTROL_REG);
487 msleep(10);
488 writew(readw(host->ctl_base + TMIO_CTRL_SD_CARD_CLOCK_CONTROL_REG) &
489 ~0x0100, host->ctl_base + TMIO_CTRL_SD_CARD_CLOCK_CONTROL_REG);
490 msleep(10);
492 /* power down */
493 writeb(0x0000, host->cnf_base + TMIO_CONF_POWER_CNTL_REG_2);
495 /* Reset */
496 reset_chip(host);
498 /* select 400kHz clock speed */
499 writew(0x180, host->ctl_base + TMIO_CTRL_SD_CARD_CLOCK_CONTROL_REG);
501 /* power up */
502 writeb(0x0002, host->cnf_base + TMIO_CONF_POWER_CNTL_REG_2);
504 /* enable clock */
505 writew(0x0100, host->ctl_base + TMIO_CTRL_CLOCK_AND_WAIT_CONTROL_REG);
506 msleep(10);
507 writew(readw(host->ctl_base + TMIO_CTRL_SD_CARD_CLOCK_CONTROL_REG) |
508 0x0100, host->ctl_base + TMIO_CTRL_SD_CARD_CLOCK_CONTROL_REG);
509 msleep(10);
511 /* Select 1 bit mode (daft chip starts in 4 bit mode) */
512 writew(0x80e0, host->ctl_base + TMIO_CTRL_SD_MEMORY_CARD_OPTION_SETUP_REG);
516 static int tmio_mmc_suspend(struct platform_device *dev, pm_message_t state) {
517 struct tmio_mmc_hwconfig *hwconfig = platform_get_platdata(dev);
518 struct mmc_host *mmc = platform_get_drvdata(dev);
519 struct tmio_mmc_host *host = mmc_priv(mmc);
520 int ret;
522 ret = mmc_suspend_host(mmc, state);
524 if (ret) {
525 printk(KERN_ERR DRIVER_NAME ": Could not suspend MMC host, hardware not suspended");
526 return ret;
529 /* disable clock */
530 writew(0x0000, host->ctl_base + TMIO_CTRL_CLOCK_AND_WAIT_CONTROL_REG);
531 msleep(10);
532 writew(readw(host->ctl_base + TMIO_CTRL_SD_CARD_CLOCK_CONTROL_REG) &
533 ~0x0100, host->ctl_base + TMIO_CTRL_SD_CARD_CLOCK_CONTROL_REG);
534 msleep(10);
536 /* power down */
537 writeb(0x0000, host->cnf_base + TMIO_CONF_POWER_CNTL_REG_2);
539 /* disable core clock */
540 if(hwconfig && hwconfig->set_mmc_clock)
541 hwconfig->set_mmc_clock(dev, MMC_CLOCK_DISABLED);
543 /* Disable SD/MMC function */
544 writeb(0, host->cnf_base + TMIO_CONF_COMMAND_REG);
545 return 0;
548 static int tmio_mmc_resume(struct platform_device *dev) {
549 struct mmc_host *mmc = platform_get_drvdata(dev);
550 struct tmio_mmc_host *host = mmc_priv(mmc);
552 hwinit(host, dev);
553 mmc_resume_host(mmc);
555 return 0;
558 static int tmio_mmc_probe(struct platform_device *dev)
560 struct tmio_mmc_host *host;
561 struct mmc_host *mmc;
562 int ret = -ENOMEM;
564 mmc = mmc_alloc_host(sizeof(struct tmio_mmc_host), &dev->dev);
565 if (!mmc) {
566 goto out;
569 host = mmc_priv(mmc);
570 host->mmc = mmc;
571 platform_set_drvdata(dev, mmc); // Used so we can de-init safely.
573 host->cnf_base = ioremap((unsigned long)dev->resource[1].start,
574 (unsigned long)dev->resource[1].end -
575 (unsigned long)dev->resource[1].start);
576 if(!host->cnf_base)
577 goto host_free;
579 host->ctl_base = ioremap((unsigned long)dev->resource[0].start,
580 (unsigned long)dev->resource[0].end -
581 (unsigned long)dev->resource[0].start);
582 if (!host->ctl_base) {
583 goto unmap_cnf_base;
586 printk( "%08x %08x\n", dev->resource[0].start, dev->resource[1].start);
587 mmc->ops = &tmio_mmc_ops;
588 mmc->caps = MMC_CAP_4_BIT_DATA;
589 mmc->f_min = 46875;
590 mmc->f_max = 24000000;
591 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
593 hwinit(host, dev);
595 host->irq = (unsigned long)dev->resource[2].start;
596 ret = request_irq(host->irq, tmio_mmc_irq, SA_INTERRUPT, DRIVER_NAME, host);
597 if (ret){
598 ret = -ENODEV;
599 goto unmap_ctl_base;
601 set_irq_type(host->irq, IRQT_FALLING);
603 mmc_add_host(mmc);
605 printk(KERN_INFO "%s at 0x%08lx irq %d\n",
606 mmc_hostname(host->mmc), (unsigned long)host->ctl_base, host->irq);
608 /* Lets unmask the IRQs we want to know about */
609 disable_mmc_irqs(host, TMIO_MASK_ALL);
610 enable_mmc_irqs(host, TMIO_MASK_IRQ);
611 /* FIXME - when we reset this chip, it will generate a card_insert IRQ
612 * this triggers a scan for cards. the MMC layer does a scan in anycase
613 * so its a bit wasteful.
614 * Ideally the MMC layer would not scan for cards by default.
617 return 0;
619 unmap_ctl_base:
620 iounmap(host->ctl_base);
621 unmap_cnf_base:
622 iounmap(host->cnf_base);
623 host_free:
624 mmc_free_host(mmc);
625 out:
626 return ret;
629 static int tmio_mmc_remove(struct platform_device *dev)
631 struct mmc_host *mmc = platform_get_drvdata(dev);
633 platform_set_drvdata(dev, NULL);
635 if (mmc) {
636 struct tmio_mmc_host *host = mmc_priv(mmc);
637 mmc_remove_host(mmc);
638 free_irq(host->irq, host);
639 // FIXME - we might want to consider stopping the chip here...
640 iounmap(host->ctl_base);
641 iounmap(host->cnf_base);
642 mmc_free_host(mmc); // FIXME - why does this call hang ?
644 return 0;
647 /* ------------------- device registration ----------------------- */
649 struct platform_driver tmio_mmc_driver = {
650 .driver = {
651 .name = DRIVER_NAME,
653 .probe = tmio_mmc_probe,
654 .remove = tmio_mmc_remove,
655 #ifdef CONFIG_PM
656 .suspend = tmio_mmc_suspend,
657 .resume = tmio_mmc_resume,
658 #endif
662 static int __init tmio_mmc_init(void)
664 return platform_driver_register (&tmio_mmc_driver);
665 return 0;
668 static void __exit tmio_mmc_exit(void)
670 return platform_driver_unregister (&tmio_mmc_driver);
673 module_init(tmio_mmc_init);
674 module_exit(tmio_mmc_exit);
676 MODULE_DESCRIPTION("Toshiba common SD/MMC driver");
677 MODULE_AUTHOR("Ian Molton");
678 MODULE_LICENSE("GPL");