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/config.h>
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/platform_device.h>
42 #include <linux/interrupt.h>
43 #include <linux/dma-mapping.h>
45 #include <linux/mmc/host.h>
46 #include <linux/mmc/protocol.h>
48 #include <asm/mach-au1x00/au1000.h>
49 #include <asm/mach-au1x00/au1xxx_dbdma.h>
50 #include <asm/mach-au1x00/au1100_mmc.h>
51 #include <asm/scatterlist.h>
56 #define DRIVER_NAME "au1xxx-mmc"
58 /* Set this to enable special debugging macros */
61 #define DBG(fmt, idx, args...) printk("au1xx(%d): DEBUG: " fmt, idx, ##args)
63 #define DBG(fmt, idx, args...)
68 u32 tx_devid, rx_devid;
72 } au1xmmc_card_table[] = {
73 { SD0_BASE, DSCR_CMD0_SDMS_TX0, DSCR_CMD0_SDMS_RX0,
74 BCSR_BOARD_SD0PWR, BCSR_INT_SD0INSERT, BCSR_STATUS_SD0WP },
75 #ifndef CONFIG_MIPS_DB1200
76 { SD1_BASE, DSCR_CMD0_SDMS_TX1, DSCR_CMD0_SDMS_RX1,
77 BCSR_BOARD_DS1PWR, BCSR_INT_SD1INSERT, BCSR_STATUS_SD1WP }
81 #define AU1XMMC_CONTROLLER_COUNT \
82 (sizeof(au1xmmc_card_table) / sizeof(au1xmmc_card_table[0]))
84 /* This array stores pointers for the hosts (used by the IRQ handler) */
85 struct au1xmmc_host *au1xmmc_hosts[AU1XMMC_CONTROLLER_COUNT];
89 module_param(dma, bool, 0);
90 MODULE_PARM_DESC(dma, "Use DMA engine for data transfers (0 = disabled)");
93 static inline void IRQ_ON(struct au1xmmc_host *host, u32 mask)
95 u32 val = au_readl(HOST_CONFIG(host));
97 au_writel(val, HOST_CONFIG(host));
101 static inline void FLUSH_FIFO(struct au1xmmc_host *host)
103 u32 val = au_readl(HOST_CONFIG2(host));
105 au_writel(val | SD_CONFIG2_FF, HOST_CONFIG2(host));
108 /* SEND_STOP will turn off clock control - this re-enables it */
109 val &= ~SD_CONFIG2_DF;
111 au_writel(val, HOST_CONFIG2(host));
115 static inline void IRQ_OFF(struct au1xmmc_host *host, u32 mask)
117 u32 val = au_readl(HOST_CONFIG(host));
119 au_writel(val, HOST_CONFIG(host));
123 static inline void SEND_STOP(struct au1xmmc_host *host)
126 /* We know the value of CONFIG2, so avoid a read we don't need */
127 u32 mask = SD_CONFIG2_EN;
129 WARN_ON(host->status != HOST_S_DATA);
130 host->status = HOST_S_STOP;
132 au_writel(mask | SD_CONFIG2_DF, HOST_CONFIG2(host));
135 /* Send the stop commmand */
136 au_writel(STOP_CMD, HOST_CMD(host));
139 static void au1xmmc_set_power(struct au1xmmc_host *host, int state)
142 u32 val = au1xmmc_card_table[host->id].bcsrpwr;
145 if (state) bcsr->board |= val;
150 static inline int au1xmmc_card_inserted(struct au1xmmc_host *host)
152 return (bcsr->sig_status & au1xmmc_card_table[host->id].bcsrstatus)
156 static inline int au1xmmc_card_readonly(struct au1xmmc_host *host)
158 return (bcsr->status & au1xmmc_card_table[host->id].wpstatus)
162 static void au1xmmc_finish_request(struct au1xmmc_host *host)
165 struct mmc_request *mrq = host->mrq;
168 host->flags &= HOST_F_ACTIVE;
174 host->pio.offset = 0;
177 host->status = HOST_S_IDLE;
179 bcsr->disk_leds |= (1 << 8);
181 mmc_request_done(host->mmc, mrq);
184 static void au1xmmc_tasklet_finish(unsigned long param)
186 struct au1xmmc_host *host = (struct au1xmmc_host *) param;
187 au1xmmc_finish_request(host);
190 static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
191 struct mmc_command *cmd)
194 u32 mmccmd = (cmd->opcode << SD_CMD_CI_SHIFT);
196 switch (mmc_resp_type(cmd)) {
198 mmccmd |= SD_CMD_RT_1;
201 mmccmd |= SD_CMD_RT_1B;
204 mmccmd |= SD_CMD_RT_2;
207 mmccmd |= SD_CMD_RT_3;
211 switch(cmd->opcode) {
212 case MMC_READ_SINGLE_BLOCK:
213 case SD_APP_SEND_SCR:
214 mmccmd |= SD_CMD_CT_2;
216 case MMC_READ_MULTIPLE_BLOCK:
217 mmccmd |= SD_CMD_CT_4;
219 case MMC_WRITE_BLOCK:
220 mmccmd |= SD_CMD_CT_1;
223 case MMC_WRITE_MULTIPLE_BLOCK:
224 mmccmd |= SD_CMD_CT_3;
226 case MMC_STOP_TRANSMISSION:
227 mmccmd |= SD_CMD_CT_7;
231 au_writel(cmd->arg, HOST_CMDARG(host));
235 IRQ_OFF(host, SD_CONFIG_CR);
237 au_writel((mmccmd | SD_CMD_GO), HOST_CMD(host));
240 /* Wait for the command to go on the line */
243 if (!(au_readl(HOST_CMD(host)) & SD_CMD_GO))
247 /* Wait for the command to come back */
250 u32 status = au_readl(HOST_STATUS(host));
252 while(!(status & SD_STATUS_CR))
253 status = au_readl(HOST_STATUS(host));
255 /* Clear the CR status */
256 au_writel(SD_STATUS_CR, HOST_STATUS(host));
258 IRQ_ON(host, SD_CONFIG_CR);
264 static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status)
267 struct mmc_request *mrq = host->mrq;
268 struct mmc_data *data;
271 WARN_ON(host->status != HOST_S_DATA && host->status != HOST_S_STOP);
273 if (host->mrq == NULL)
276 data = mrq->cmd->data;
279 status = au_readl(HOST_STATUS(host));
281 /* The transaction is really over when the SD_STATUS_DB bit is clear */
283 while((host->flags & HOST_F_XMIT) && (status & SD_STATUS_DB))
284 status = au_readl(HOST_STATUS(host));
286 data->error = MMC_ERR_NONE;
287 dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir);
289 /* Process any errors */
291 crc = (status & (SD_STATUS_WC | SD_STATUS_RC));
292 if (host->flags & HOST_F_XMIT)
293 crc |= ((status & 0x07) == 0x02) ? 0 : 1;
296 data->error = MMC_ERR_BADCRC;
298 /* Clear the CRC bits */
299 au_writel(SD_STATUS_WC | SD_STATUS_RC, HOST_STATUS(host));
301 data->bytes_xfered = 0;
303 if (data->error == MMC_ERR_NONE) {
304 if (host->flags & HOST_F_DMA) {
305 u32 chan = DMA_CHANNEL(host);
307 chan_tab_t *c = *((chan_tab_t **) chan);
308 au1x_dma_chan_t *cp = c->chan_ptr;
309 data->bytes_xfered = cp->ddma_bytecnt;
313 (data->blocks * (1 << data->blksz_bits)) -
317 au1xmmc_finish_request(host);
320 static void au1xmmc_tasklet_data(unsigned long param)
322 struct au1xmmc_host *host = (struct au1xmmc_host *) param;
324 u32 status = au_readl(HOST_STATUS(host));
325 au1xmmc_data_complete(host, status);
328 #define AU1XMMC_MAX_TRANSFER 8
330 static void au1xmmc_send_pio(struct au1xmmc_host *host)
333 struct mmc_data *data = 0;
334 int sg_len, max, count = 0;
335 unsigned char *sg_ptr;
337 struct scatterlist *sg;
339 data = host->mrq->data;
341 if (!(host->flags & HOST_F_XMIT))
344 /* This is the pointer to the data buffer */
345 sg = &data->sg[host->pio.index];
346 sg_ptr = page_address(sg->page) + sg->offset + host->pio.offset;
348 /* This is the space left inside the buffer */
349 sg_len = data->sg[host->pio.index].length - host->pio.offset;
351 /* Check to if we need less then the size of the sg_buffer */
353 max = (sg_len > host->pio.len) ? host->pio.len : sg_len;
354 if (max > AU1XMMC_MAX_TRANSFER) max = AU1XMMC_MAX_TRANSFER;
356 for(count = 0; count < max; count++ ) {
359 status = au_readl(HOST_STATUS(host));
361 if (!(status & SD_STATUS_TH))
366 au_writel((unsigned long) val, HOST_TXPORT(host));
370 host->pio.len -= count;
371 host->pio.offset += count;
373 if (count == sg_len) {
375 host->pio.offset = 0;
378 if (host->pio.len == 0) {
379 IRQ_OFF(host, SD_CONFIG_TH);
381 if (host->flags & HOST_F_STOP)
384 tasklet_schedule(&host->data_task);
388 static void au1xmmc_receive_pio(struct au1xmmc_host *host)
391 struct mmc_data *data = 0;
392 int sg_len = 0, max = 0, count = 0;
393 unsigned char *sg_ptr = 0;
395 struct scatterlist *sg;
397 data = host->mrq->data;
399 if (!(host->flags & HOST_F_RECV))
404 if (host->pio.index < host->dma.len) {
405 sg = &data->sg[host->pio.index];
406 sg_ptr = page_address(sg->page) + sg->offset + host->pio.offset;
408 /* This is the space left inside the buffer */
409 sg_len = sg_dma_len(&data->sg[host->pio.index]) - host->pio.offset;
411 /* Check to if we need less then the size of the sg_buffer */
412 if (sg_len < max) max = sg_len;
415 if (max > AU1XMMC_MAX_TRANSFER)
416 max = AU1XMMC_MAX_TRANSFER;
418 for(count = 0; count < max; count++ ) {
420 status = au_readl(HOST_STATUS(host));
422 if (!(status & SD_STATUS_NE))
425 if (status & SD_STATUS_RC) {
426 DBG("RX CRC Error [%d + %d].\n", host->id,
427 host->pio.len, count);
431 if (status & SD_STATUS_RO) {
432 DBG("RX Overrun [%d + %d]\n", host->id,
433 host->pio.len, count);
436 else if (status & SD_STATUS_RU) {
437 DBG("RX Underrun [%d + %d]\n", host->id,
438 host->pio.len, count);
442 val = au_readl(HOST_RXPORT(host));
445 *sg_ptr++ = (unsigned char) (val & 0xFF);
448 host->pio.len -= count;
449 host->pio.offset += count;
451 if (sg_len && count == sg_len) {
453 host->pio.offset = 0;
456 if (host->pio.len == 0) {
457 //IRQ_OFF(host, SD_CONFIG_RA | SD_CONFIG_RF);
458 IRQ_OFF(host, SD_CONFIG_NE);
460 if (host->flags & HOST_F_STOP)
463 tasklet_schedule(&host->data_task);
467 /* static void au1xmmc_cmd_complete
468 This is called when a command has been completed - grab the response
469 and check for errors. Then start the data transfer if it is indicated.
472 static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status)
475 struct mmc_request *mrq = host->mrq;
476 struct mmc_command *cmd;
483 cmd->error = MMC_ERR_NONE;
485 if (cmd->flags & MMC_RSP_PRESENT) {
486 if (cmd->flags & MMC_RSP_136) {
490 r[0] = au_readl(host->iobase + SD_RESP3);
491 r[1] = au_readl(host->iobase + SD_RESP2);
492 r[2] = au_readl(host->iobase + SD_RESP1);
493 r[3] = au_readl(host->iobase + SD_RESP0);
495 /* The CRC is omitted from the response, so really
496 * we only got 120 bytes, but the engine expects
497 * 128 bits, so we have to shift things up
500 for(i = 0; i < 4; i++) {
501 cmd->resp[i] = (r[i] & 0x00FFFFFF) << 8;
503 cmd->resp[i] |= (r[i + 1] & 0xFF000000) >> 24;
506 /* Techincally, we should be getting all 48 bits of
507 * the response (SD_RESP1 + SD_RESP2), but because
508 * our response omits the CRC, our data ends up
509 * being shifted 8 bits to the right. In this case,
510 * that means that the OSR data starts at bit 31,
511 * so we can just read RESP0 and return that
513 cmd->resp[0] = au_readl(host->iobase + SD_RESP0);
517 /* Figure out errors */
519 if (status & (SD_STATUS_SC | SD_STATUS_WC | SD_STATUS_RC))
520 cmd->error = MMC_ERR_BADCRC;
522 trans = host->flags & (HOST_F_XMIT | HOST_F_RECV);
524 if (!trans || cmd->error != MMC_ERR_NONE) {
526 IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA|SD_CONFIG_RF);
527 tasklet_schedule(&host->finish_task);
531 host->status = HOST_S_DATA;
533 if (host->flags & HOST_F_DMA) {
534 u32 channel = DMA_CHANNEL(host);
536 /* Start the DMA as soon as the buffer gets something in it */
538 if (host->flags & HOST_F_RECV) {
539 u32 mask = SD_STATUS_DB | SD_STATUS_NE;
541 while((status & mask) != mask)
542 status = au_readl(HOST_STATUS(host));
545 au1xxx_dbdma_start(channel);
549 static void au1xmmc_set_clock(struct au1xmmc_host *host, int rate)
552 unsigned int pbus = get_au1x00_speed();
553 unsigned int divisor;
557 divisor = ((((cpuclock / sbus_divisor) / 2) / mmcclock) / 2) - 1
560 pbus /= ((au_readl(SYS_POWERCTRL) & 0x3) + 2);
563 divisor = ((pbus / rate) / 2) - 1;
565 config = au_readl(HOST_CONFIG(host));
567 config &= ~(SD_CONFIG_DIV);
568 config |= (divisor & SD_CONFIG_DIV) | SD_CONFIG_DE;
570 au_writel(config, HOST_CONFIG(host));
575 au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data)
578 int datalen = data->blocks * (1 << data->blksz_bits);
581 host->flags |= HOST_F_DMA;
583 if (data->flags & MMC_DATA_READ)
584 host->flags |= HOST_F_RECV;
586 host->flags |= HOST_F_XMIT;
589 host->flags |= HOST_F_STOP;
591 host->dma.dir = DMA_BIDIRECTIONAL;
593 host->dma.len = dma_map_sg(mmc_dev(host->mmc), data->sg,
594 data->sg_len, host->dma.dir);
596 if (host->dma.len == 0)
597 return MMC_ERR_TIMEOUT;
599 au_writel((1 << data->blksz_bits) - 1, HOST_BLKSIZE(host));
601 if (host->flags & HOST_F_DMA) {
603 u32 channel = DMA_CHANNEL(host);
605 au1xxx_dbdma_stop(channel);
607 for(i = 0; i < host->dma.len; i++) {
608 u32 ret = 0, flags = DDMA_FLAGS_NOIE;
609 struct scatterlist *sg = &data->sg[i];
610 int sg_len = sg->length;
612 int len = (datalen > sg_len) ? sg_len : datalen;
614 if (i == host->dma.len - 1)
615 flags = DDMA_FLAGS_IE;
617 if (host->flags & HOST_F_XMIT){
618 ret = au1xxx_dbdma_put_source_flags(channel,
619 (void *) (page_address(sg->page) +
624 ret = au1xxx_dbdma_put_dest_flags(channel,
625 (void *) (page_address(sg->page) +
638 host->pio.offset = 0;
639 host->pio.len = datalen;
641 if (host->flags & HOST_F_XMIT)
642 IRQ_ON(host, SD_CONFIG_TH);
644 IRQ_ON(host, SD_CONFIG_NE);
645 //IRQ_ON(host, SD_CONFIG_RA|SD_CONFIG_RF);
651 dma_unmap_sg(mmc_dev(host->mmc),data->sg,data->sg_len,host->dma.dir);
652 return MMC_ERR_TIMEOUT;
655 /* static void au1xmmc_request
656 This actually starts a command or data transaction
659 static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq)
662 struct au1xmmc_host *host = mmc_priv(mmc);
663 int ret = MMC_ERR_NONE;
665 WARN_ON(irqs_disabled());
666 WARN_ON(host->status != HOST_S_IDLE);
669 host->status = HOST_S_CMD;
671 bcsr->disk_leds &= ~(1 << 8);
675 ret = au1xmmc_prepare_data(host, mrq->data);
678 if (ret == MMC_ERR_NONE)
679 ret = au1xmmc_send_command(host, 0, mrq->cmd);
681 if (ret != MMC_ERR_NONE) {
682 mrq->cmd->error = ret;
683 au1xmmc_finish_request(host);
687 static void au1xmmc_reset_controller(struct au1xmmc_host *host)
690 /* Apply the clock */
691 au_writel(SD_ENABLE_CE, HOST_ENABLE(host));
694 au_writel(SD_ENABLE_R | SD_ENABLE_CE, HOST_ENABLE(host));
697 au_writel(~0, HOST_STATUS(host));
700 au_writel(0, HOST_BLKSIZE(host));
701 au_writel(0x001fffff, HOST_TIMEOUT(host));
704 au_writel(SD_CONFIG2_EN, HOST_CONFIG2(host));
707 au_writel(SD_CONFIG2_EN | SD_CONFIG2_FF, HOST_CONFIG2(host));
710 au_writel(SD_CONFIG2_EN, HOST_CONFIG2(host));
713 /* Configure interrupts */
714 au_writel(AU1XMMC_INTERRUPTS, HOST_CONFIG(host));
719 static void au1xmmc_set_ios(struct mmc_host* mmc, struct mmc_ios* ios)
721 struct au1xmmc_host *host = mmc_priv(mmc);
723 DBG("set_ios (power=%u, clock=%uHz, vdd=%u, mode=%u)\n",
724 host->id, ios->power_mode, ios->clock, ios->vdd,
727 if (ios->power_mode == MMC_POWER_OFF)
728 au1xmmc_set_power(host, 0);
729 else if (ios->power_mode == MMC_POWER_ON) {
730 au1xmmc_set_power(host, 1);
733 if (ios->clock && ios->clock != host->clock) {
734 au1xmmc_set_clock(host, ios->clock);
735 host->clock = ios->clock;
739 static void au1xmmc_dma_callback(int irq, void *dev_id, struct pt_regs *regs)
741 struct au1xmmc_host *host = (struct au1xmmc_host *) dev_id;
743 /* Avoid spurious interrupts */
748 if (host->flags & HOST_F_STOP)
751 tasklet_schedule(&host->data_task);
754 #define STATUS_TIMEOUT (SD_STATUS_RAT | SD_STATUS_DT)
755 #define STATUS_DATA_IN (SD_STATUS_NE)
756 #define STATUS_DATA_OUT (SD_STATUS_TH)
758 static irqreturn_t au1xmmc_irq(int irq, void *dev_id, struct pt_regs *regs)
764 disable_irq(AU1100_SD_IRQ);
766 for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) {
767 struct au1xmmc_host * host = au1xmmc_hosts[i];
770 status = au_readl(HOST_STATUS(host));
772 if (host->mrq && (status & STATUS_TIMEOUT)) {
773 if (status & SD_STATUS_RAT)
774 host->mrq->cmd->error = MMC_ERR_TIMEOUT;
776 else if (status & SD_STATUS_DT)
777 host->mrq->data->error = MMC_ERR_TIMEOUT;
779 /* In PIO mode, interrupts might still be enabled */
780 IRQ_OFF(host, SD_CONFIG_NE | SD_CONFIG_TH);
782 //IRQ_OFF(host, SD_CONFIG_TH|SD_CONFIG_RA|SD_CONFIG_RF);
783 tasklet_schedule(&host->finish_task);
786 else if (status & SD_STATUS_DD) {
788 /* Sometimes we get a DD before a NE in PIO mode */
790 if (!(host->flags & HOST_F_DMA) &&
791 (status & SD_STATUS_NE))
792 au1xmmc_receive_pio(host);
794 au1xmmc_data_complete(host, status);
795 //tasklet_schedule(&host->data_task);
799 else if (status & (SD_STATUS_CR)) {
800 if (host->status == HOST_S_CMD)
801 au1xmmc_cmd_complete(host,status);
803 else if (!(host->flags & HOST_F_DMA)) {
804 if ((host->flags & HOST_F_XMIT) &&
805 (status & STATUS_DATA_OUT))
806 au1xmmc_send_pio(host);
807 else if ((host->flags & HOST_F_RECV) &&
808 (status & STATUS_DATA_IN))
809 au1xmmc_receive_pio(host);
811 else if (status & 0x203FBC70) {
812 DBG("Unhandled status %8.8x\n", host->id, status);
816 au_writel(status, HOST_STATUS(host));
822 enable_irq(AU1100_SD_IRQ);
826 static void au1xmmc_poll_event(unsigned long arg)
828 struct au1xmmc_host *host = (struct au1xmmc_host *) arg;
830 int card = au1xmmc_card_inserted(host);
831 int controller = (host->flags & HOST_F_ACTIVE) ? 1 : 0;
833 if (card != controller) {
834 host->flags &= ~HOST_F_ACTIVE;
835 if (card) host->flags |= HOST_F_ACTIVE;
836 mmc_detect_change(host->mmc, 0);
839 if (host->mrq != NULL) {
840 u32 status = au_readl(HOST_STATUS(host));
841 DBG("PENDING - %8.8x\n", host->id, status);
844 mod_timer(&host->timer, jiffies + AU1XMMC_DETECT_TIMEOUT);
847 static dbdev_tab_t au1xmmc_mem_dbdev =
849 DSCR_CMD0_ALWAYS, DEV_FLAGS_ANYUSE, 0, 8, 0x00000000, 0, 0
852 static void au1xmmc_init_dma(struct au1xmmc_host *host)
857 int txid = au1xmmc_card_table[host->id].tx_devid;
858 int rxid = au1xmmc_card_table[host->id].rx_devid;
860 /* DSCR_CMD0_ALWAYS has a stride of 32 bits, we need a stride
861 of 8 bits. And since devices are shared, we need to create
862 our own to avoid freaking out other devices
865 int memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev);
867 txchan = au1xxx_dbdma_chan_alloc(memid, txid,
868 au1xmmc_dma_callback, (void *) host);
870 rxchan = au1xxx_dbdma_chan_alloc(rxid, memid,
871 au1xmmc_dma_callback, (void *) host);
873 au1xxx_dbdma_set_devwidth(txchan, 8);
874 au1xxx_dbdma_set_devwidth(rxchan, 8);
876 au1xxx_dbdma_ring_alloc(txchan, AU1XMMC_DESCRIPTOR_COUNT);
877 au1xxx_dbdma_ring_alloc(rxchan, AU1XMMC_DESCRIPTOR_COUNT);
879 host->tx_chan = txchan;
880 host->rx_chan = rxchan;
883 struct mmc_host_ops au1xmmc_ops = {
884 .request = au1xmmc_request,
885 .set_ios = au1xmmc_set_ios,
888 static int __devinit au1xmmc_probe(struct platform_device *pdev)
893 /* THe interrupt is shared among all controllers */
894 ret = request_irq(AU1100_SD_IRQ, au1xmmc_irq, SA_INTERRUPT, "MMC", 0);
897 printk(DRIVER_NAME "ERROR: Couldn't get int %d: %d\n",
902 disable_irq(AU1100_SD_IRQ);
904 for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) {
905 struct mmc_host *mmc = mmc_alloc_host(sizeof(struct au1xmmc_host), &pdev->dev);
906 struct au1xmmc_host *host = 0;
909 printk(DRIVER_NAME "ERROR: no mem for host %d\n", i);
910 au1xmmc_hosts[i] = 0;
914 mmc->ops = &au1xmmc_ops;
917 mmc->f_max = 24000000;
919 mmc->max_seg_size = AU1XMMC_DESCRIPTOR_SIZE;
920 mmc->max_phys_segs = AU1XMMC_DESCRIPTOR_COUNT;
922 mmc->ocr_avail = AU1XMMC_OCR;
924 host = mmc_priv(mmc);
928 host->iobase = au1xmmc_card_table[host->id].iobase;
930 host->power_mode = MMC_POWER_OFF;
932 host->flags = au1xmmc_card_inserted(host) ? HOST_F_ACTIVE : 0;
933 host->status = HOST_S_IDLE;
935 init_timer(&host->timer);
937 host->timer.function = au1xmmc_poll_event;
938 host->timer.data = (unsigned long) host;
939 host->timer.expires = jiffies + AU1XMMC_DETECT_TIMEOUT;
941 tasklet_init(&host->data_task, au1xmmc_tasklet_data,
942 (unsigned long) host);
944 tasklet_init(&host->finish_task, au1xmmc_tasklet_finish,
945 (unsigned long) host);
947 spin_lock_init(&host->lock);
950 au1xmmc_init_dma(host);
952 au1xmmc_reset_controller(host);
955 au1xmmc_hosts[i] = host;
957 add_timer(&host->timer);
959 printk(KERN_INFO DRIVER_NAME ": MMC Controller %d set up at %8.8X (mode=%s)\n",
960 host->id, host->iobase, dma ? "dma" : "pio");
963 enable_irq(AU1100_SD_IRQ);
968 static int __devexit au1xmmc_remove(struct platform_device *pdev)
973 disable_irq(AU1100_SD_IRQ);
975 for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) {
976 struct au1xmmc_host *host = au1xmmc_hosts[i];
979 tasklet_kill(&host->data_task);
980 tasklet_kill(&host->finish_task);
982 del_timer_sync(&host->timer);
983 au1xmmc_set_power(host, 0);
985 mmc_remove_host(host->mmc);
987 au1xxx_dbdma_chan_free(host->tx_chan);
988 au1xxx_dbdma_chan_free(host->rx_chan);
990 au_writel(0x0, HOST_ENABLE(host));
994 free_irq(AU1100_SD_IRQ, 0);
998 static struct platform_driver au1xmmc_driver = {
999 .probe = au1xmmc_probe,
1000 .remove = au1xmmc_remove,
1004 .name = DRIVER_NAME,
1008 static int __init au1xmmc_init(void)
1010 return platform_driver_register(&au1xmmc_driver);
1013 static void __exit au1xmmc_exit(void)
1015 platform_driver_unregister(&au1xmmc_driver);
1018 module_init(au1xmmc_init);
1019 module_exit(au1xmmc_exit);
1022 MODULE_AUTHOR("Advanced Micro Devices, Inc");
1023 MODULE_DESCRIPTION("MMC/SD driver for the Alchemy Au1XXX");
1024 MODULE_LICENSE("GPL");