2 * linux/drivers/mmc/host/au1xmmc.c - AU1XX0 MMC driver
4 * Copyright (c) 2005, Advanced Micro Devices, Inc.
6 * Developed with help from the 2.4.30 MMC AU1XXX controller including
7 * the following copyright notices:
8 * Copyright (c) 2003-2004 Embedded Edge, LLC.
9 * Portions Copyright (C) 2002 Embedix, Inc
10 * Copyright 2002 Hewlett-Packard Company
12 * 2.6 version of this driver inspired by:
13 * (drivers/mmc/wbsd.c) Copyright (C) 2004-2005 Pierre Ossman,
14 * All Rights Reserved.
15 * (drivers/mmc/pxa.c) Copyright (C) 2003 Russell King,
16 * All Rights Reserved.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License version 2 as
21 * published by the Free Software Foundation.
24 /* Why is a timer used to detect insert events?
26 * From the AU1100 MMC application guide:
27 * If the Au1100-based design is intended to support both MultiMediaCards
28 * and 1- or 4-data bit SecureDigital cards, then the solution is to
29 * connect a weak (560KOhm) pull-up resistor to connector pin 1.
30 * In doing so, a MMC card never enters SPI-mode communications,
31 * but now the SecureDigital card-detect feature of CD/DAT3 is ineffective
32 * (the low to high transition will not occur).
34 * So we use the timer to check the status manually.
37 #include <linux/module.h>
38 #include <linux/init.h>
39 #include <linux/platform_device.h>
41 #include <linux/interrupt.h>
42 #include <linux/dma-mapping.h>
44 #include <linux/mmc/host.h>
46 #include <asm/mach-au1x00/au1000.h>
47 #include <asm/mach-au1x00/au1xxx_dbdma.h>
48 #include <asm/mach-au1x00/au1100_mmc.h>
49 #include <asm/scatterlist.h>
54 #define DRIVER_NAME "au1xxx-mmc"
56 /* Set this to enable special debugging macros */
59 #define DBG(fmt, idx, args...) printk("au1xx(%d): DEBUG: " fmt, idx, ##args)
61 #define DBG(fmt, idx, args...)
66 u32 tx_devid, rx_devid;
70 } au1xmmc_card_table[] = {
71 { SD0_BASE, DSCR_CMD0_SDMS_TX0, DSCR_CMD0_SDMS_RX0,
72 BCSR_BOARD_SD0PWR, BCSR_INT_SD0INSERT, BCSR_STATUS_SD0WP },
73 #ifndef CONFIG_MIPS_DB1200
74 { SD1_BASE, DSCR_CMD0_SDMS_TX1, DSCR_CMD0_SDMS_RX1,
75 BCSR_BOARD_DS1PWR, BCSR_INT_SD1INSERT, BCSR_STATUS_SD1WP }
79 #define AU1XMMC_CONTROLLER_COUNT (ARRAY_SIZE(au1xmmc_card_table))
81 /* This array stores pointers for the hosts (used by the IRQ handler) */
82 struct au1xmmc_host *au1xmmc_hosts[AU1XMMC_CONTROLLER_COUNT];
86 module_param(dma, bool, 0);
87 MODULE_PARM_DESC(dma, "Use DMA engine for data transfers (0 = disabled)");
90 static inline void IRQ_ON(struct au1xmmc_host *host, u32 mask)
92 u32 val = au_readl(HOST_CONFIG(host));
94 au_writel(val, HOST_CONFIG(host));
98 static inline void FLUSH_FIFO(struct au1xmmc_host *host)
100 u32 val = au_readl(HOST_CONFIG2(host));
102 au_writel(val | SD_CONFIG2_FF, HOST_CONFIG2(host));
105 /* SEND_STOP will turn off clock control - this re-enables it */
106 val &= ~SD_CONFIG2_DF;
108 au_writel(val, HOST_CONFIG2(host));
112 static inline void IRQ_OFF(struct au1xmmc_host *host, u32 mask)
114 u32 val = au_readl(HOST_CONFIG(host));
116 au_writel(val, HOST_CONFIG(host));
120 static inline void SEND_STOP(struct au1xmmc_host *host)
123 /* We know the value of CONFIG2, so avoid a read we don't need */
124 u32 mask = SD_CONFIG2_EN;
126 WARN_ON(host->status != HOST_S_DATA);
127 host->status = HOST_S_STOP;
129 au_writel(mask | SD_CONFIG2_DF, HOST_CONFIG2(host));
132 /* Send the stop commmand */
133 au_writel(STOP_CMD, HOST_CMD(host));
136 static void au1xmmc_set_power(struct au1xmmc_host *host, int state)
139 u32 val = au1xmmc_card_table[host->id].bcsrpwr;
142 if (state) bcsr->board |= val;
147 static inline int au1xmmc_card_inserted(struct au1xmmc_host *host)
149 return (bcsr->sig_status & au1xmmc_card_table[host->id].bcsrstatus)
153 static int au1xmmc_card_readonly(struct mmc_host *mmc)
155 struct au1xmmc_host *host = mmc_priv(mmc);
156 return (bcsr->status & au1xmmc_card_table[host->id].wpstatus)
160 static void au1xmmc_finish_request(struct au1xmmc_host *host)
163 struct mmc_request *mrq = host->mrq;
166 host->flags &= HOST_F_ACTIVE;
172 host->pio.offset = 0;
175 host->status = HOST_S_IDLE;
177 bcsr->disk_leds |= (1 << 8);
179 mmc_request_done(host->mmc, mrq);
182 static void au1xmmc_tasklet_finish(unsigned long param)
184 struct au1xmmc_host *host = (struct au1xmmc_host *) param;
185 au1xmmc_finish_request(host);
188 static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
189 struct mmc_command *cmd, struct mmc_data *data)
191 u32 mmccmd = (cmd->opcode << SD_CMD_CI_SHIFT);
193 switch (mmc_resp_type(cmd)) {
197 mmccmd |= SD_CMD_RT_1;
200 mmccmd |= SD_CMD_RT_1B;
203 mmccmd |= SD_CMD_RT_2;
206 mmccmd |= SD_CMD_RT_3;
209 printk(KERN_INFO "au1xmmc: unhandled response type %02x\n",
215 if (flags & MMC_DATA_READ) {
216 if (data->blocks > 1)
217 mmccmd |= SD_CMD_CT_4;
219 mmccmd |= SD_CMD_CT_2;
220 } else if (flags & MMC_DATA_WRITE) {
221 if (data->blocks > 1)
222 mmccmd |= SD_CMD_CT_3;
224 mmccmd |= SD_CMD_CT_1;
228 au_writel(cmd->arg, HOST_CMDARG(host));
232 IRQ_OFF(host, SD_CONFIG_CR);
234 au_writel((mmccmd | SD_CMD_GO), HOST_CMD(host));
237 /* Wait for the command to go on the line */
240 if (!(au_readl(HOST_CMD(host)) & SD_CMD_GO))
244 /* Wait for the command to come back */
247 u32 status = au_readl(HOST_STATUS(host));
249 while(!(status & SD_STATUS_CR))
250 status = au_readl(HOST_STATUS(host));
252 /* Clear the CR status */
253 au_writel(SD_STATUS_CR, HOST_STATUS(host));
255 IRQ_ON(host, SD_CONFIG_CR);
261 static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status)
264 struct mmc_request *mrq = host->mrq;
265 struct mmc_data *data;
268 WARN_ON(host->status != HOST_S_DATA && host->status != HOST_S_STOP);
270 if (host->mrq == NULL)
273 data = mrq->cmd->data;
276 status = au_readl(HOST_STATUS(host));
278 /* The transaction is really over when the SD_STATUS_DB bit is clear */
280 while((host->flags & HOST_F_XMIT) && (status & SD_STATUS_DB))
281 status = au_readl(HOST_STATUS(host));
284 dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir);
286 /* Process any errors */
288 crc = (status & (SD_STATUS_WC | SD_STATUS_RC));
289 if (host->flags & HOST_F_XMIT)
290 crc |= ((status & 0x07) == 0x02) ? 0 : 1;
293 data->error = -EILSEQ;
295 /* Clear the CRC bits */
296 au_writel(SD_STATUS_WC | SD_STATUS_RC, HOST_STATUS(host));
298 data->bytes_xfered = 0;
301 if (host->flags & HOST_F_DMA) {
302 u32 chan = DMA_CHANNEL(host);
304 chan_tab_t *c = *((chan_tab_t **) chan);
305 au1x_dma_chan_t *cp = c->chan_ptr;
306 data->bytes_xfered = cp->ddma_bytecnt;
310 (data->blocks * data->blksz) -
314 au1xmmc_finish_request(host);
317 static void au1xmmc_tasklet_data(unsigned long param)
319 struct au1xmmc_host *host = (struct au1xmmc_host *) param;
321 u32 status = au_readl(HOST_STATUS(host));
322 au1xmmc_data_complete(host, status);
325 #define AU1XMMC_MAX_TRANSFER 8
327 static void au1xmmc_send_pio(struct au1xmmc_host *host)
330 struct mmc_data *data = 0;
331 int sg_len, max, count = 0;
332 unsigned char *sg_ptr;
334 struct scatterlist *sg;
336 data = host->mrq->data;
338 if (!(host->flags & HOST_F_XMIT))
341 /* This is the pointer to the data buffer */
342 sg = &data->sg[host->pio.index];
343 sg_ptr = page_address(sg->page) + sg->offset + host->pio.offset;
345 /* This is the space left inside the buffer */
346 sg_len = data->sg[host->pio.index].length - host->pio.offset;
348 /* Check to if we need less then the size of the sg_buffer */
350 max = (sg_len > host->pio.len) ? host->pio.len : sg_len;
351 if (max > AU1XMMC_MAX_TRANSFER) max = AU1XMMC_MAX_TRANSFER;
353 for(count = 0; count < max; count++ ) {
356 status = au_readl(HOST_STATUS(host));
358 if (!(status & SD_STATUS_TH))
363 au_writel((unsigned long) val, HOST_TXPORT(host));
367 host->pio.len -= count;
368 host->pio.offset += count;
370 if (count == sg_len) {
372 host->pio.offset = 0;
375 if (host->pio.len == 0) {
376 IRQ_OFF(host, SD_CONFIG_TH);
378 if (host->flags & HOST_F_STOP)
381 tasklet_schedule(&host->data_task);
385 static void au1xmmc_receive_pio(struct au1xmmc_host *host)
388 struct mmc_data *data = 0;
389 int sg_len = 0, max = 0, count = 0;
390 unsigned char *sg_ptr = 0;
392 struct scatterlist *sg;
394 data = host->mrq->data;
396 if (!(host->flags & HOST_F_RECV))
401 if (host->pio.index < host->dma.len) {
402 sg = &data->sg[host->pio.index];
403 sg_ptr = page_address(sg->page) + sg->offset + host->pio.offset;
405 /* This is the space left inside the buffer */
406 sg_len = sg_dma_len(&data->sg[host->pio.index]) - host->pio.offset;
408 /* Check to if we need less then the size of the sg_buffer */
409 if (sg_len < max) max = sg_len;
412 if (max > AU1XMMC_MAX_TRANSFER)
413 max = AU1XMMC_MAX_TRANSFER;
415 for(count = 0; count < max; count++ ) {
417 status = au_readl(HOST_STATUS(host));
419 if (!(status & SD_STATUS_NE))
422 if (status & SD_STATUS_RC) {
423 DBG("RX CRC Error [%d + %d].\n", host->id,
424 host->pio.len, count);
428 if (status & SD_STATUS_RO) {
429 DBG("RX Overrun [%d + %d]\n", host->id,
430 host->pio.len, count);
433 else if (status & SD_STATUS_RU) {
434 DBG("RX Underrun [%d + %d]\n", host->id,
435 host->pio.len, count);
439 val = au_readl(HOST_RXPORT(host));
442 *sg_ptr++ = (unsigned char) (val & 0xFF);
445 host->pio.len -= count;
446 host->pio.offset += count;
448 if (sg_len && count == sg_len) {
450 host->pio.offset = 0;
453 if (host->pio.len == 0) {
454 //IRQ_OFF(host, SD_CONFIG_RA | SD_CONFIG_RF);
455 IRQ_OFF(host, SD_CONFIG_NE);
457 if (host->flags & HOST_F_STOP)
460 tasklet_schedule(&host->data_task);
464 /* static void au1xmmc_cmd_complete
465 This is called when a command has been completed - grab the response
466 and check for errors. Then start the data transfer if it is indicated.
469 static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status)
472 struct mmc_request *mrq = host->mrq;
473 struct mmc_command *cmd;
482 if (cmd->flags & MMC_RSP_PRESENT) {
483 if (cmd->flags & MMC_RSP_136) {
487 r[0] = au_readl(host->iobase + SD_RESP3);
488 r[1] = au_readl(host->iobase + SD_RESP2);
489 r[2] = au_readl(host->iobase + SD_RESP1);
490 r[3] = au_readl(host->iobase + SD_RESP0);
492 /* The CRC is omitted from the response, so really
493 * we only got 120 bytes, but the engine expects
494 * 128 bits, so we have to shift things up
497 for(i = 0; i < 4; i++) {
498 cmd->resp[i] = (r[i] & 0x00FFFFFF) << 8;
500 cmd->resp[i] |= (r[i + 1] & 0xFF000000) >> 24;
503 /* Techincally, we should be getting all 48 bits of
504 * the response (SD_RESP1 + SD_RESP2), but because
505 * our response omits the CRC, our data ends up
506 * being shifted 8 bits to the right. In this case,
507 * that means that the OSR data starts at bit 31,
508 * so we can just read RESP0 and return that
510 cmd->resp[0] = au_readl(host->iobase + SD_RESP0);
514 /* Figure out errors */
516 if (status & (SD_STATUS_SC | SD_STATUS_WC | SD_STATUS_RC))
517 cmd->error = -EILSEQ;
519 trans = host->flags & (HOST_F_XMIT | HOST_F_RECV);
521 if (!trans || cmd->error) {
523 IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA|SD_CONFIG_RF);
524 tasklet_schedule(&host->finish_task);
528 host->status = HOST_S_DATA;
530 if (host->flags & HOST_F_DMA) {
531 u32 channel = DMA_CHANNEL(host);
533 /* Start the DMA as soon as the buffer gets something in it */
535 if (host->flags & HOST_F_RECV) {
536 u32 mask = SD_STATUS_DB | SD_STATUS_NE;
538 while((status & mask) != mask)
539 status = au_readl(HOST_STATUS(host));
542 au1xxx_dbdma_start(channel);
546 static void au1xmmc_set_clock(struct au1xmmc_host *host, int rate)
549 unsigned int pbus = get_au1x00_speed();
550 unsigned int divisor;
554 divisor = ((((cpuclock / sbus_divisor) / 2) / mmcclock) / 2) - 1
557 pbus /= ((au_readl(SYS_POWERCTRL) & 0x3) + 2);
560 divisor = ((pbus / rate) / 2) - 1;
562 config = au_readl(HOST_CONFIG(host));
564 config &= ~(SD_CONFIG_DIV);
565 config |= (divisor & SD_CONFIG_DIV) | SD_CONFIG_DE;
567 au_writel(config, HOST_CONFIG(host));
572 au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data)
575 int datalen = data->blocks * data->blksz;
578 host->flags |= HOST_F_DMA;
580 if (data->flags & MMC_DATA_READ)
581 host->flags |= HOST_F_RECV;
583 host->flags |= HOST_F_XMIT;
586 host->flags |= HOST_F_STOP;
588 host->dma.dir = DMA_BIDIRECTIONAL;
590 host->dma.len = dma_map_sg(mmc_dev(host->mmc), data->sg,
591 data->sg_len, host->dma.dir);
593 if (host->dma.len == 0)
596 au_writel(data->blksz - 1, HOST_BLKSIZE(host));
598 if (host->flags & HOST_F_DMA) {
600 u32 channel = DMA_CHANNEL(host);
602 au1xxx_dbdma_stop(channel);
604 for(i = 0; i < host->dma.len; i++) {
605 u32 ret = 0, flags = DDMA_FLAGS_NOIE;
606 struct scatterlist *sg = &data->sg[i];
607 int sg_len = sg->length;
609 int len = (datalen > sg_len) ? sg_len : datalen;
611 if (i == host->dma.len - 1)
612 flags = DDMA_FLAGS_IE;
614 if (host->flags & HOST_F_XMIT){
615 ret = au1xxx_dbdma_put_source_flags(channel,
616 (void *) (page_address(sg->page) +
621 ret = au1xxx_dbdma_put_dest_flags(channel,
622 (void *) (page_address(sg->page) +
635 host->pio.offset = 0;
636 host->pio.len = datalen;
638 if (host->flags & HOST_F_XMIT)
639 IRQ_ON(host, SD_CONFIG_TH);
641 IRQ_ON(host, SD_CONFIG_NE);
642 //IRQ_ON(host, SD_CONFIG_RA|SD_CONFIG_RF);
648 dma_unmap_sg(mmc_dev(host->mmc),data->sg,data->sg_len,host->dma.dir);
652 /* static void au1xmmc_request
653 This actually starts a command or data transaction
656 static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq)
659 struct au1xmmc_host *host = mmc_priv(mmc);
660 unsigned int flags = 0;
663 WARN_ON(irqs_disabled());
664 WARN_ON(host->status != HOST_S_IDLE);
667 host->status = HOST_S_CMD;
669 bcsr->disk_leds &= ~(1 << 8);
673 flags = mrq->data->flags;
674 ret = au1xmmc_prepare_data(host, mrq->data);
678 ret = au1xmmc_send_command(host, 0, mrq->cmd, mrq->data);
681 mrq->cmd->error = ret;
682 au1xmmc_finish_request(host);
686 static void au1xmmc_reset_controller(struct au1xmmc_host *host)
689 /* Apply the clock */
690 au_writel(SD_ENABLE_CE, HOST_ENABLE(host));
693 au_writel(SD_ENABLE_R | SD_ENABLE_CE, HOST_ENABLE(host));
696 au_writel(~0, HOST_STATUS(host));
699 au_writel(0, HOST_BLKSIZE(host));
700 au_writel(0x001fffff, HOST_TIMEOUT(host));
703 au_writel(SD_CONFIG2_EN, HOST_CONFIG2(host));
706 au_writel(SD_CONFIG2_EN | SD_CONFIG2_FF, HOST_CONFIG2(host));
709 au_writel(SD_CONFIG2_EN, HOST_CONFIG2(host));
712 /* Configure interrupts */
713 au_writel(AU1XMMC_INTERRUPTS, HOST_CONFIG(host));
718 static void au1xmmc_set_ios(struct mmc_host* mmc, struct mmc_ios* ios)
720 struct au1xmmc_host *host = mmc_priv(mmc);
722 if (ios->power_mode == MMC_POWER_OFF)
723 au1xmmc_set_power(host, 0);
724 else if (ios->power_mode == MMC_POWER_ON) {
725 au1xmmc_set_power(host, 1);
728 if (ios->clock && ios->clock != host->clock) {
729 au1xmmc_set_clock(host, ios->clock);
730 host->clock = ios->clock;
734 static void au1xmmc_dma_callback(int irq, void *dev_id)
736 struct au1xmmc_host *host = (struct au1xmmc_host *) dev_id;
738 /* Avoid spurious interrupts */
743 if (host->flags & HOST_F_STOP)
746 tasklet_schedule(&host->data_task);
749 #define STATUS_TIMEOUT (SD_STATUS_RAT | SD_STATUS_DT)
750 #define STATUS_DATA_IN (SD_STATUS_NE)
751 #define STATUS_DATA_OUT (SD_STATUS_TH)
753 static irqreturn_t au1xmmc_irq(int irq, void *dev_id)
759 disable_irq(AU1100_SD_IRQ);
761 for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) {
762 struct au1xmmc_host * host = au1xmmc_hosts[i];
765 status = au_readl(HOST_STATUS(host));
767 if (host->mrq && (status & STATUS_TIMEOUT)) {
768 if (status & SD_STATUS_RAT)
769 host->mrq->cmd->error = -ETIMEDOUT;
771 else if (status & SD_STATUS_DT)
772 host->mrq->data->error = -ETIMEDOUT;
774 /* In PIO mode, interrupts might still be enabled */
775 IRQ_OFF(host, SD_CONFIG_NE | SD_CONFIG_TH);
777 //IRQ_OFF(host, SD_CONFIG_TH|SD_CONFIG_RA|SD_CONFIG_RF);
778 tasklet_schedule(&host->finish_task);
781 else if (status & SD_STATUS_DD) {
783 /* Sometimes we get a DD before a NE in PIO mode */
785 if (!(host->flags & HOST_F_DMA) &&
786 (status & SD_STATUS_NE))
787 au1xmmc_receive_pio(host);
789 au1xmmc_data_complete(host, status);
790 //tasklet_schedule(&host->data_task);
794 else if (status & (SD_STATUS_CR)) {
795 if (host->status == HOST_S_CMD)
796 au1xmmc_cmd_complete(host,status);
798 else if (!(host->flags & HOST_F_DMA)) {
799 if ((host->flags & HOST_F_XMIT) &&
800 (status & STATUS_DATA_OUT))
801 au1xmmc_send_pio(host);
802 else if ((host->flags & HOST_F_RECV) &&
803 (status & STATUS_DATA_IN))
804 au1xmmc_receive_pio(host);
806 else if (status & 0x203FBC70) {
807 DBG("Unhandled status %8.8x\n", host->id, status);
811 au_writel(status, HOST_STATUS(host));
817 enable_irq(AU1100_SD_IRQ);
821 static void au1xmmc_poll_event(unsigned long arg)
823 struct au1xmmc_host *host = (struct au1xmmc_host *) arg;
825 int card = au1xmmc_card_inserted(host);
826 int controller = (host->flags & HOST_F_ACTIVE) ? 1 : 0;
828 if (card != controller) {
829 host->flags &= ~HOST_F_ACTIVE;
830 if (card) host->flags |= HOST_F_ACTIVE;
831 mmc_detect_change(host->mmc, 0);
834 if (host->mrq != NULL) {
835 u32 status = au_readl(HOST_STATUS(host));
836 DBG("PENDING - %8.8x\n", host->id, status);
839 mod_timer(&host->timer, jiffies + AU1XMMC_DETECT_TIMEOUT);
842 static dbdev_tab_t au1xmmc_mem_dbdev =
844 DSCR_CMD0_ALWAYS, DEV_FLAGS_ANYUSE, 0, 8, 0x00000000, 0, 0
847 static void au1xmmc_init_dma(struct au1xmmc_host *host)
852 int txid = au1xmmc_card_table[host->id].tx_devid;
853 int rxid = au1xmmc_card_table[host->id].rx_devid;
855 /* DSCR_CMD0_ALWAYS has a stride of 32 bits, we need a stride
856 of 8 bits. And since devices are shared, we need to create
857 our own to avoid freaking out other devices
860 int memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev);
862 txchan = au1xxx_dbdma_chan_alloc(memid, txid,
863 au1xmmc_dma_callback, (void *) host);
865 rxchan = au1xxx_dbdma_chan_alloc(rxid, memid,
866 au1xmmc_dma_callback, (void *) host);
868 au1xxx_dbdma_set_devwidth(txchan, 8);
869 au1xxx_dbdma_set_devwidth(rxchan, 8);
871 au1xxx_dbdma_ring_alloc(txchan, AU1XMMC_DESCRIPTOR_COUNT);
872 au1xxx_dbdma_ring_alloc(rxchan, AU1XMMC_DESCRIPTOR_COUNT);
874 host->tx_chan = txchan;
875 host->rx_chan = rxchan;
878 static const struct mmc_host_ops au1xmmc_ops = {
879 .request = au1xmmc_request,
880 .set_ios = au1xmmc_set_ios,
881 .get_ro = au1xmmc_card_readonly,
884 static int __devinit au1xmmc_probe(struct platform_device *pdev)
889 /* THe interrupt is shared among all controllers */
890 ret = request_irq(AU1100_SD_IRQ, au1xmmc_irq, IRQF_DISABLED, "MMC", 0);
893 printk(DRIVER_NAME "ERROR: Couldn't get int %d: %d\n",
898 disable_irq(AU1100_SD_IRQ);
900 for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) {
901 struct mmc_host *mmc = mmc_alloc_host(sizeof(struct au1xmmc_host), &pdev->dev);
902 struct au1xmmc_host *host = 0;
905 printk(DRIVER_NAME "ERROR: no mem for host %d\n", i);
906 au1xmmc_hosts[i] = 0;
910 mmc->ops = &au1xmmc_ops;
913 mmc->f_max = 24000000;
915 mmc->max_seg_size = AU1XMMC_DESCRIPTOR_SIZE;
916 mmc->max_phys_segs = AU1XMMC_DESCRIPTOR_COUNT;
918 mmc->max_blk_size = 2048;
919 mmc->max_blk_count = 512;
921 mmc->ocr_avail = AU1XMMC_OCR;
923 host = mmc_priv(mmc);
927 host->iobase = au1xmmc_card_table[host->id].iobase;
929 host->power_mode = MMC_POWER_OFF;
931 host->flags = au1xmmc_card_inserted(host) ? HOST_F_ACTIVE : 0;
932 host->status = HOST_S_IDLE;
934 init_timer(&host->timer);
936 host->timer.function = au1xmmc_poll_event;
937 host->timer.data = (unsigned long) host;
938 host->timer.expires = jiffies + AU1XMMC_DETECT_TIMEOUT;
940 tasklet_init(&host->data_task, au1xmmc_tasklet_data,
941 (unsigned long) host);
943 tasklet_init(&host->finish_task, au1xmmc_tasklet_finish,
944 (unsigned long) host);
946 spin_lock_init(&host->lock);
949 au1xmmc_init_dma(host);
951 au1xmmc_reset_controller(host);
954 au1xmmc_hosts[i] = host;
956 add_timer(&host->timer);
958 printk(KERN_INFO DRIVER_NAME ": MMC Controller %d set up at %8.8X (mode=%s)\n",
959 host->id, host->iobase, dma ? "dma" : "pio");
962 enable_irq(AU1100_SD_IRQ);
967 static int __devexit au1xmmc_remove(struct platform_device *pdev)
972 disable_irq(AU1100_SD_IRQ);
974 for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) {
975 struct au1xmmc_host *host = au1xmmc_hosts[i];
978 tasklet_kill(&host->data_task);
979 tasklet_kill(&host->finish_task);
981 del_timer_sync(&host->timer);
982 au1xmmc_set_power(host, 0);
984 mmc_remove_host(host->mmc);
986 au1xxx_dbdma_chan_free(host->tx_chan);
987 au1xxx_dbdma_chan_free(host->rx_chan);
989 au_writel(0x0, HOST_ENABLE(host));
993 free_irq(AU1100_SD_IRQ, 0);
997 static struct platform_driver au1xmmc_driver = {
998 .probe = au1xmmc_probe,
999 .remove = au1xmmc_remove,
1003 .name = DRIVER_NAME,
1007 static int __init au1xmmc_init(void)
1009 return platform_driver_register(&au1xmmc_driver);
1012 static void __exit au1xmmc_exit(void)
1014 platform_driver_unregister(&au1xmmc_driver);
1017 module_init(au1xmmc_init);
1018 module_exit(au1xmmc_exit);
1021 MODULE_AUTHOR("Advanced Micro Devices, Inc");
1022 MODULE_DESCRIPTION("MMC/SD driver for the Alchemy Au1XXX");
1023 MODULE_LICENSE("GPL");