2 * linux/drivers/mmc/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, unsigned int flags)
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",
211 return MMC_ERR_INVALID;
214 if (flags & MMC_DATA_READ) {
215 if (flags & MMC_DATA_MULTI)
216 mmccmd |= SD_CMD_CT_4;
218 mmccmd |= SD_CMD_CT_2;
219 } else if (flags & MMC_DATA_WRITE) {
220 if (flags & MMC_DATA_MULTI)
221 mmccmd |= SD_CMD_CT_3;
223 mmccmd |= SD_CMD_CT_1;
226 au_writel(cmd->arg, HOST_CMDARG(host));
230 IRQ_OFF(host, SD_CONFIG_CR);
232 au_writel((mmccmd | SD_CMD_GO), HOST_CMD(host));
235 /* Wait for the command to go on the line */
238 if (!(au_readl(HOST_CMD(host)) & SD_CMD_GO))
242 /* Wait for the command to come back */
245 u32 status = au_readl(HOST_STATUS(host));
247 while(!(status & SD_STATUS_CR))
248 status = au_readl(HOST_STATUS(host));
250 /* Clear the CR status */
251 au_writel(SD_STATUS_CR, HOST_STATUS(host));
253 IRQ_ON(host, SD_CONFIG_CR);
259 static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status)
262 struct mmc_request *mrq = host->mrq;
263 struct mmc_data *data;
266 WARN_ON(host->status != HOST_S_DATA && host->status != HOST_S_STOP);
268 if (host->mrq == NULL)
271 data = mrq->cmd->data;
274 status = au_readl(HOST_STATUS(host));
276 /* The transaction is really over when the SD_STATUS_DB bit is clear */
278 while((host->flags & HOST_F_XMIT) && (status & SD_STATUS_DB))
279 status = au_readl(HOST_STATUS(host));
281 data->error = MMC_ERR_NONE;
282 dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir);
284 /* Process any errors */
286 crc = (status & (SD_STATUS_WC | SD_STATUS_RC));
287 if (host->flags & HOST_F_XMIT)
288 crc |= ((status & 0x07) == 0x02) ? 0 : 1;
291 data->error = MMC_ERR_BADCRC;
293 /* Clear the CRC bits */
294 au_writel(SD_STATUS_WC | SD_STATUS_RC, HOST_STATUS(host));
296 data->bytes_xfered = 0;
298 if (data->error == MMC_ERR_NONE) {
299 if (host->flags & HOST_F_DMA) {
300 u32 chan = DMA_CHANNEL(host);
302 chan_tab_t *c = *((chan_tab_t **) chan);
303 au1x_dma_chan_t *cp = c->chan_ptr;
304 data->bytes_xfered = cp->ddma_bytecnt;
308 (data->blocks * data->blksz) -
312 au1xmmc_finish_request(host);
315 static void au1xmmc_tasklet_data(unsigned long param)
317 struct au1xmmc_host *host = (struct au1xmmc_host *) param;
319 u32 status = au_readl(HOST_STATUS(host));
320 au1xmmc_data_complete(host, status);
323 #define AU1XMMC_MAX_TRANSFER 8
325 static void au1xmmc_send_pio(struct au1xmmc_host *host)
328 struct mmc_data *data = 0;
329 int sg_len, max, count = 0;
330 unsigned char *sg_ptr;
332 struct scatterlist *sg;
334 data = host->mrq->data;
336 if (!(host->flags & HOST_F_XMIT))
339 /* This is the pointer to the data buffer */
340 sg = &data->sg[host->pio.index];
341 sg_ptr = page_address(sg->page) + sg->offset + host->pio.offset;
343 /* This is the space left inside the buffer */
344 sg_len = data->sg[host->pio.index].length - host->pio.offset;
346 /* Check to if we need less then the size of the sg_buffer */
348 max = (sg_len > host->pio.len) ? host->pio.len : sg_len;
349 if (max > AU1XMMC_MAX_TRANSFER) max = AU1XMMC_MAX_TRANSFER;
351 for(count = 0; count < max; count++ ) {
354 status = au_readl(HOST_STATUS(host));
356 if (!(status & SD_STATUS_TH))
361 au_writel((unsigned long) val, HOST_TXPORT(host));
365 host->pio.len -= count;
366 host->pio.offset += count;
368 if (count == sg_len) {
370 host->pio.offset = 0;
373 if (host->pio.len == 0) {
374 IRQ_OFF(host, SD_CONFIG_TH);
376 if (host->flags & HOST_F_STOP)
379 tasklet_schedule(&host->data_task);
383 static void au1xmmc_receive_pio(struct au1xmmc_host *host)
386 struct mmc_data *data = 0;
387 int sg_len = 0, max = 0, count = 0;
388 unsigned char *sg_ptr = 0;
390 struct scatterlist *sg;
392 data = host->mrq->data;
394 if (!(host->flags & HOST_F_RECV))
399 if (host->pio.index < host->dma.len) {
400 sg = &data->sg[host->pio.index];
401 sg_ptr = page_address(sg->page) + sg->offset + host->pio.offset;
403 /* This is the space left inside the buffer */
404 sg_len = sg_dma_len(&data->sg[host->pio.index]) - host->pio.offset;
406 /* Check to if we need less then the size of the sg_buffer */
407 if (sg_len < max) max = sg_len;
410 if (max > AU1XMMC_MAX_TRANSFER)
411 max = AU1XMMC_MAX_TRANSFER;
413 for(count = 0; count < max; count++ ) {
415 status = au_readl(HOST_STATUS(host));
417 if (!(status & SD_STATUS_NE))
420 if (status & SD_STATUS_RC) {
421 DBG("RX CRC Error [%d + %d].\n", host->id,
422 host->pio.len, count);
426 if (status & SD_STATUS_RO) {
427 DBG("RX Overrun [%d + %d]\n", host->id,
428 host->pio.len, count);
431 else if (status & SD_STATUS_RU) {
432 DBG("RX Underrun [%d + %d]\n", host->id,
433 host->pio.len, count);
437 val = au_readl(HOST_RXPORT(host));
440 *sg_ptr++ = (unsigned char) (val & 0xFF);
443 host->pio.len -= count;
444 host->pio.offset += count;
446 if (sg_len && count == sg_len) {
448 host->pio.offset = 0;
451 if (host->pio.len == 0) {
452 //IRQ_OFF(host, SD_CONFIG_RA | SD_CONFIG_RF);
453 IRQ_OFF(host, SD_CONFIG_NE);
455 if (host->flags & HOST_F_STOP)
458 tasklet_schedule(&host->data_task);
462 /* static void au1xmmc_cmd_complete
463 This is called when a command has been completed - grab the response
464 and check for errors. Then start the data transfer if it is indicated.
467 static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status)
470 struct mmc_request *mrq = host->mrq;
471 struct mmc_command *cmd;
478 cmd->error = MMC_ERR_NONE;
480 if (cmd->flags & MMC_RSP_PRESENT) {
481 if (cmd->flags & MMC_RSP_136) {
485 r[0] = au_readl(host->iobase + SD_RESP3);
486 r[1] = au_readl(host->iobase + SD_RESP2);
487 r[2] = au_readl(host->iobase + SD_RESP1);
488 r[3] = au_readl(host->iobase + SD_RESP0);
490 /* The CRC is omitted from the response, so really
491 * we only got 120 bytes, but the engine expects
492 * 128 bits, so we have to shift things up
495 for(i = 0; i < 4; i++) {
496 cmd->resp[i] = (r[i] & 0x00FFFFFF) << 8;
498 cmd->resp[i] |= (r[i + 1] & 0xFF000000) >> 24;
501 /* Techincally, we should be getting all 48 bits of
502 * the response (SD_RESP1 + SD_RESP2), but because
503 * our response omits the CRC, our data ends up
504 * being shifted 8 bits to the right. In this case,
505 * that means that the OSR data starts at bit 31,
506 * so we can just read RESP0 and return that
508 cmd->resp[0] = au_readl(host->iobase + SD_RESP0);
512 /* Figure out errors */
514 if (status & (SD_STATUS_SC | SD_STATUS_WC | SD_STATUS_RC))
515 cmd->error = MMC_ERR_BADCRC;
517 trans = host->flags & (HOST_F_XMIT | HOST_F_RECV);
519 if (!trans || cmd->error != MMC_ERR_NONE) {
521 IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA|SD_CONFIG_RF);
522 tasklet_schedule(&host->finish_task);
526 host->status = HOST_S_DATA;
528 if (host->flags & HOST_F_DMA) {
529 u32 channel = DMA_CHANNEL(host);
531 /* Start the DMA as soon as the buffer gets something in it */
533 if (host->flags & HOST_F_RECV) {
534 u32 mask = SD_STATUS_DB | SD_STATUS_NE;
536 while((status & mask) != mask)
537 status = au_readl(HOST_STATUS(host));
540 au1xxx_dbdma_start(channel);
544 static void au1xmmc_set_clock(struct au1xmmc_host *host, int rate)
547 unsigned int pbus = get_au1x00_speed();
548 unsigned int divisor;
552 divisor = ((((cpuclock / sbus_divisor) / 2) / mmcclock) / 2) - 1
555 pbus /= ((au_readl(SYS_POWERCTRL) & 0x3) + 2);
558 divisor = ((pbus / rate) / 2) - 1;
560 config = au_readl(HOST_CONFIG(host));
562 config &= ~(SD_CONFIG_DIV);
563 config |= (divisor & SD_CONFIG_DIV) | SD_CONFIG_DE;
565 au_writel(config, HOST_CONFIG(host));
570 au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data)
573 int datalen = data->blocks * data->blksz;
576 host->flags |= HOST_F_DMA;
578 if (data->flags & MMC_DATA_READ)
579 host->flags |= HOST_F_RECV;
581 host->flags |= HOST_F_XMIT;
584 host->flags |= HOST_F_STOP;
586 host->dma.dir = DMA_BIDIRECTIONAL;
588 host->dma.len = dma_map_sg(mmc_dev(host->mmc), data->sg,
589 data->sg_len, host->dma.dir);
591 if (host->dma.len == 0)
592 return MMC_ERR_TIMEOUT;
594 au_writel(data->blksz - 1, HOST_BLKSIZE(host));
596 if (host->flags & HOST_F_DMA) {
598 u32 channel = DMA_CHANNEL(host);
600 au1xxx_dbdma_stop(channel);
602 for(i = 0; i < host->dma.len; i++) {
603 u32 ret = 0, flags = DDMA_FLAGS_NOIE;
604 struct scatterlist *sg = &data->sg[i];
605 int sg_len = sg->length;
607 int len = (datalen > sg_len) ? sg_len : datalen;
609 if (i == host->dma.len - 1)
610 flags = DDMA_FLAGS_IE;
612 if (host->flags & HOST_F_XMIT){
613 ret = au1xxx_dbdma_put_source_flags(channel,
614 (void *) (page_address(sg->page) +
619 ret = au1xxx_dbdma_put_dest_flags(channel,
620 (void *) (page_address(sg->page) +
633 host->pio.offset = 0;
634 host->pio.len = datalen;
636 if (host->flags & HOST_F_XMIT)
637 IRQ_ON(host, SD_CONFIG_TH);
639 IRQ_ON(host, SD_CONFIG_NE);
640 //IRQ_ON(host, SD_CONFIG_RA|SD_CONFIG_RF);
646 dma_unmap_sg(mmc_dev(host->mmc),data->sg,data->sg_len,host->dma.dir);
647 return MMC_ERR_TIMEOUT;
650 /* static void au1xmmc_request
651 This actually starts a command or data transaction
654 static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq)
657 struct au1xmmc_host *host = mmc_priv(mmc);
658 unsigned int flags = 0;
659 int ret = MMC_ERR_NONE;
661 WARN_ON(irqs_disabled());
662 WARN_ON(host->status != HOST_S_IDLE);
665 host->status = HOST_S_CMD;
667 bcsr->disk_leds &= ~(1 << 8);
671 flags = mrq->data->flags;
672 ret = au1xmmc_prepare_data(host, mrq->data);
675 if (ret == MMC_ERR_NONE)
676 ret = au1xmmc_send_command(host, 0, mrq->cmd, flags);
678 if (ret != MMC_ERR_NONE) {
679 mrq->cmd->error = ret;
680 au1xmmc_finish_request(host);
684 static void au1xmmc_reset_controller(struct au1xmmc_host *host)
687 /* Apply the clock */
688 au_writel(SD_ENABLE_CE, HOST_ENABLE(host));
691 au_writel(SD_ENABLE_R | SD_ENABLE_CE, HOST_ENABLE(host));
694 au_writel(~0, HOST_STATUS(host));
697 au_writel(0, HOST_BLKSIZE(host));
698 au_writel(0x001fffff, HOST_TIMEOUT(host));
701 au_writel(SD_CONFIG2_EN, HOST_CONFIG2(host));
704 au_writel(SD_CONFIG2_EN | SD_CONFIG2_FF, HOST_CONFIG2(host));
707 au_writel(SD_CONFIG2_EN, HOST_CONFIG2(host));
710 /* Configure interrupts */
711 au_writel(AU1XMMC_INTERRUPTS, HOST_CONFIG(host));
716 static void au1xmmc_set_ios(struct mmc_host* mmc, struct mmc_ios* ios)
718 struct au1xmmc_host *host = mmc_priv(mmc);
720 if (ios->power_mode == MMC_POWER_OFF)
721 au1xmmc_set_power(host, 0);
722 else if (ios->power_mode == MMC_POWER_ON) {
723 au1xmmc_set_power(host, 1);
726 if (ios->clock && ios->clock != host->clock) {
727 au1xmmc_set_clock(host, ios->clock);
728 host->clock = ios->clock;
732 static void au1xmmc_dma_callback(int irq, void *dev_id)
734 struct au1xmmc_host *host = (struct au1xmmc_host *) dev_id;
736 /* Avoid spurious interrupts */
741 if (host->flags & HOST_F_STOP)
744 tasklet_schedule(&host->data_task);
747 #define STATUS_TIMEOUT (SD_STATUS_RAT | SD_STATUS_DT)
748 #define STATUS_DATA_IN (SD_STATUS_NE)
749 #define STATUS_DATA_OUT (SD_STATUS_TH)
751 static irqreturn_t au1xmmc_irq(int irq, void *dev_id)
757 disable_irq(AU1100_SD_IRQ);
759 for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) {
760 struct au1xmmc_host * host = au1xmmc_hosts[i];
763 status = au_readl(HOST_STATUS(host));
765 if (host->mrq && (status & STATUS_TIMEOUT)) {
766 if (status & SD_STATUS_RAT)
767 host->mrq->cmd->error = MMC_ERR_TIMEOUT;
769 else if (status & SD_STATUS_DT)
770 host->mrq->data->error = MMC_ERR_TIMEOUT;
772 /* In PIO mode, interrupts might still be enabled */
773 IRQ_OFF(host, SD_CONFIG_NE | SD_CONFIG_TH);
775 //IRQ_OFF(host, SD_CONFIG_TH|SD_CONFIG_RA|SD_CONFIG_RF);
776 tasklet_schedule(&host->finish_task);
779 else if (status & SD_STATUS_DD) {
781 /* Sometimes we get a DD before a NE in PIO mode */
783 if (!(host->flags & HOST_F_DMA) &&
784 (status & SD_STATUS_NE))
785 au1xmmc_receive_pio(host);
787 au1xmmc_data_complete(host, status);
788 //tasklet_schedule(&host->data_task);
792 else if (status & (SD_STATUS_CR)) {
793 if (host->status == HOST_S_CMD)
794 au1xmmc_cmd_complete(host,status);
796 else if (!(host->flags & HOST_F_DMA)) {
797 if ((host->flags & HOST_F_XMIT) &&
798 (status & STATUS_DATA_OUT))
799 au1xmmc_send_pio(host);
800 else if ((host->flags & HOST_F_RECV) &&
801 (status & STATUS_DATA_IN))
802 au1xmmc_receive_pio(host);
804 else if (status & 0x203FBC70) {
805 DBG("Unhandled status %8.8x\n", host->id, status);
809 au_writel(status, HOST_STATUS(host));
815 enable_irq(AU1100_SD_IRQ);
819 static void au1xmmc_poll_event(unsigned long arg)
821 struct au1xmmc_host *host = (struct au1xmmc_host *) arg;
823 int card = au1xmmc_card_inserted(host);
824 int controller = (host->flags & HOST_F_ACTIVE) ? 1 : 0;
826 if (card != controller) {
827 host->flags &= ~HOST_F_ACTIVE;
828 if (card) host->flags |= HOST_F_ACTIVE;
829 mmc_detect_change(host->mmc, 0);
832 if (host->mrq != NULL) {
833 u32 status = au_readl(HOST_STATUS(host));
834 DBG("PENDING - %8.8x\n", host->id, status);
837 mod_timer(&host->timer, jiffies + AU1XMMC_DETECT_TIMEOUT);
840 static dbdev_tab_t au1xmmc_mem_dbdev =
842 DSCR_CMD0_ALWAYS, DEV_FLAGS_ANYUSE, 0, 8, 0x00000000, 0, 0
845 static void au1xmmc_init_dma(struct au1xmmc_host *host)
850 int txid = au1xmmc_card_table[host->id].tx_devid;
851 int rxid = au1xmmc_card_table[host->id].rx_devid;
853 /* DSCR_CMD0_ALWAYS has a stride of 32 bits, we need a stride
854 of 8 bits. And since devices are shared, we need to create
855 our own to avoid freaking out other devices
858 int memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev);
860 txchan = au1xxx_dbdma_chan_alloc(memid, txid,
861 au1xmmc_dma_callback, (void *) host);
863 rxchan = au1xxx_dbdma_chan_alloc(rxid, memid,
864 au1xmmc_dma_callback, (void *) host);
866 au1xxx_dbdma_set_devwidth(txchan, 8);
867 au1xxx_dbdma_set_devwidth(rxchan, 8);
869 au1xxx_dbdma_ring_alloc(txchan, AU1XMMC_DESCRIPTOR_COUNT);
870 au1xxx_dbdma_ring_alloc(rxchan, AU1XMMC_DESCRIPTOR_COUNT);
872 host->tx_chan = txchan;
873 host->rx_chan = rxchan;
876 static const struct mmc_host_ops au1xmmc_ops = {
877 .request = au1xmmc_request,
878 .set_ios = au1xmmc_set_ios,
879 .get_ro = au1xmmc_card_readonly,
882 static int __devinit au1xmmc_probe(struct platform_device *pdev)
887 /* THe interrupt is shared among all controllers */
888 ret = request_irq(AU1100_SD_IRQ, au1xmmc_irq, IRQF_DISABLED, "MMC", 0);
891 printk(DRIVER_NAME "ERROR: Couldn't get int %d: %d\n",
896 disable_irq(AU1100_SD_IRQ);
898 for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) {
899 struct mmc_host *mmc = mmc_alloc_host(sizeof(struct au1xmmc_host), &pdev->dev);
900 struct au1xmmc_host *host = 0;
903 printk(DRIVER_NAME "ERROR: no mem for host %d\n", i);
904 au1xmmc_hosts[i] = 0;
908 mmc->ops = &au1xmmc_ops;
911 mmc->f_max = 24000000;
913 mmc->max_seg_size = AU1XMMC_DESCRIPTOR_SIZE;
914 mmc->max_phys_segs = AU1XMMC_DESCRIPTOR_COUNT;
916 mmc->max_blk_size = 2048;
917 mmc->max_blk_count = 512;
919 mmc->ocr_avail = AU1XMMC_OCR;
921 host = mmc_priv(mmc);
925 host->iobase = au1xmmc_card_table[host->id].iobase;
927 host->power_mode = MMC_POWER_OFF;
929 host->flags = au1xmmc_card_inserted(host) ? HOST_F_ACTIVE : 0;
930 host->status = HOST_S_IDLE;
932 init_timer(&host->timer);
934 host->timer.function = au1xmmc_poll_event;
935 host->timer.data = (unsigned long) host;
936 host->timer.expires = jiffies + AU1XMMC_DETECT_TIMEOUT;
938 tasklet_init(&host->data_task, au1xmmc_tasklet_data,
939 (unsigned long) host);
941 tasklet_init(&host->finish_task, au1xmmc_tasklet_finish,
942 (unsigned long) host);
944 spin_lock_init(&host->lock);
947 au1xmmc_init_dma(host);
949 au1xmmc_reset_controller(host);
952 au1xmmc_hosts[i] = host;
954 add_timer(&host->timer);
956 printk(KERN_INFO DRIVER_NAME ": MMC Controller %d set up at %8.8X (mode=%s)\n",
957 host->id, host->iobase, dma ? "dma" : "pio");
960 enable_irq(AU1100_SD_IRQ);
965 static int __devexit au1xmmc_remove(struct platform_device *pdev)
970 disable_irq(AU1100_SD_IRQ);
972 for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) {
973 struct au1xmmc_host *host = au1xmmc_hosts[i];
976 tasklet_kill(&host->data_task);
977 tasklet_kill(&host->finish_task);
979 del_timer_sync(&host->timer);
980 au1xmmc_set_power(host, 0);
982 mmc_remove_host(host->mmc);
984 au1xxx_dbdma_chan_free(host->tx_chan);
985 au1xxx_dbdma_chan_free(host->rx_chan);
987 au_writel(0x0, HOST_ENABLE(host));
991 free_irq(AU1100_SD_IRQ, 0);
995 static struct platform_driver au1xmmc_driver = {
996 .probe = au1xmmc_probe,
997 .remove = au1xmmc_remove,
1001 .name = DRIVER_NAME,
1005 static int __init au1xmmc_init(void)
1007 return platform_driver_register(&au1xmmc_driver);
1010 static void __exit au1xmmc_exit(void)
1012 platform_driver_unregister(&au1xmmc_driver);
1015 module_init(au1xmmc_init);
1016 module_exit(au1xmmc_exit);
1019 MODULE_AUTHOR("Advanced Micro Devices, Inc");
1020 MODULE_DESCRIPTION("MMC/SD driver for the Alchemy Au1XXX");
1021 MODULE_LICENSE("GPL");