35 #include <linux/module.h>
44 #include <linux/slab.h>
51 #define DRIVER_NAME "au1xxx-mmc"
57 #define DBG(fmt, idx, args...) \
58 pr_debug("au1xmmc(%d): DEBUG: " fmt, idx, ##args)
60 #define DBG(fmt, idx, args...) do {} while (0)
64 #define AU1XMMC_DESCRIPTOR_COUNT 1
67 #define AU1100_MMC_DESCRIPTOR_SIZE 0x0000ffff
68 #define AU1200_MMC_DESCRIPTOR_SIZE 0x003fffff
70 #define AU1XMMC_OCR (MMC_VDD_27_28 | MMC_VDD_28_29 | MMC_VDD_29_30 | \
71 MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 | \
72 MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36)
78 (SD_CMD_RT_1B | SD_CMD_CT_7 | (0xC << SD_CMD_CI_SHIFT) | SD_CMD_GO)
81 #define AU1XMMC_INTERRUPTS \
82 (SD_CONFIG_SC | SD_CONFIG_DT | SD_CONFIG_RAT | \
83 SD_CONFIG_CR | SD_CONFIG_I)
86 #define AU1XMMC_DETECT_TIMEOUT (HZ/2)
124 #define HOST_F_XMIT 0x0001
125 #define HOST_F_RECV 0x0002
126 #define HOST_F_DMA 0x0010
127 #define HOST_F_DBDMA 0x0020
128 #define HOST_F_ACTIVE 0x0100
129 #define HOST_F_STOP 0x1000
131 #define HOST_S_IDLE 0x0001
132 #define HOST_S_CMD 0x0002
133 #define HOST_S_DATA 0x0003
134 #define HOST_S_STOP 0x0004
137 #define HOST_STATUS(h) ((h)->iobase + SD_STATUS)
138 #define HOST_CONFIG(h) ((h)->iobase + SD_CONFIG)
139 #define HOST_ENABLE(h) ((h)->iobase + SD_ENABLE)
140 #define HOST_TXPORT(h) ((h)->iobase + SD_TXPORT)
141 #define HOST_RXPORT(h) ((h)->iobase + SD_RXPORT)
142 #define HOST_CMDARG(h) ((h)->iobase + SD_CMDARG)
143 #define HOST_BLKSIZE(h) ((h)->iobase + SD_BLKSIZE)
144 #define HOST_CMD(h) ((h)->iobase + SD_CMD)
145 #define HOST_CONFIG2(h) ((h)->iobase + SD_CONFIG2)
146 #define HOST_TIMEOUT(h) ((h)->iobase + SD_TIMEOUT)
147 #define HOST_DEBUG(h) ((h)->iobase + SD_DEBUG)
149 #define DMA_CHANNEL(h) \
150 (((h)->flags & HOST_F_XMIT) ? (h)->tx_chan : (h)->rx_chan)
152 static inline int has_dbdma(
void)
154 switch (alchemy_get_cputype()) {
214 static int au1xmmc_card_inserted(
struct mmc_host *mmc)
224 static int au1xmmc_card_readonly(
struct mmc_host *mmc)
229 return !!host->
platdata->card_readonly(mmc);
234 static void au1xmmc_finish_request(
struct au1xmmc_host *host)
245 host->
pio.offset = 0;
253 static void au1xmmc_tasklet_finish(
unsigned long param)
256 au1xmmc_finish_request(host);
280 pr_info(
"au1xmmc: unhandled response type %02x\n",
328 static void au1xmmc_data_complete(
struct au1xmmc_host *host,
u32 status)
339 data = mrq->
cmd->data;
354 crc |= ((status & 0x07) == 0x02) ? 0 : 1;
376 au1xmmc_finish_request(host);
379 static void au1xmmc_tasklet_data(
unsigned long param)
384 au1xmmc_data_complete(host, status);
387 #define AU1XMMC_MAX_TRANSFER 8
393 unsigned char *sg_ptr,
val;
397 data = host->
mrq->data;
403 sg = &data->
sg[host->
pio.index];
404 sg_ptr = sg_virt(sg) + host->
pio.offset;
407 sg_len = data->
sg[host->
pio.index].length - host->
pio.offset;
410 max = (sg_len > host->
pio.len) ? host->
pio.len : sg_len;
414 for (count = 0; count <
max; count++) {
429 if (count == sg_len) {
431 host->
pio.offset = 0;
434 if (host->
pio.len == 0) {
444 static void au1xmmc_receive_pio(
struct au1xmmc_host *host)
448 unsigned char *sg_ptr =
NULL;
452 data = host->
mrq->data;
459 if (host->
pio.index < host->
dma.len) {
460 sg = &data->
sg[host->
pio.index];
461 sg_ptr = sg_virt(sg) + host->
pio.offset;
474 for (count = 0; count <
max; count++) {
481 DBG(
"RX CRC Error [%d + %d].\n", host->
pdev->id,
482 host->
pio.len, count);
487 DBG(
"RX Overrun [%d + %d]\n", host->
pdev->id,
488 host->
pio.len, count);
492 DBG(
"RX Underrun [%d + %d]\n", host->
pdev->id,
493 host->
pio.len, count);
500 *sg_ptr++ = (
unsigned char)(val & 0xFF);
506 if (sg_len && count == sg_len) {
508 host->
pio.offset = 0;
511 if (host->
pio.len == 0) {
525 static void au1xmmc_cmd_complete(
struct au1xmmc_host *host,
u32 status)
549 for (i = 0; i < 4; i++) {
550 cmd->
resp[
i] = (r[
i] & 0x00FFFFFF) << 8;
552 cmd->
resp[
i] |= (r[i + 1] & 0xFF000000) >> 24;
572 if (!trans || cmd->
error) {
588 while((status & mask) != mask)
607 divisor = ((pbus /
rate) / 2) - 1;
618 static int au1xmmc_prepare_data(
struct au1xmmc_host *host,
636 if (host->
dma.len == 0)
647 for (i = 0; i < host->
dma.len; i++) {
652 int len = (datalen > sg_len) ? sg_len : datalen;
654 if (i == host->
dma.len - 1)
672 host->
pio.offset = 0;
703 if (0 == au1xmmc_card_inserted(mmc)) {
705 au1xmmc_finish_request(host);
711 ret = au1xmmc_prepare_data(host, mrq->
data);
715 ret = au1xmmc_send_command(host, 0, mrq->
cmd, mrq->
data);
719 au1xmmc_finish_request(host);
723 static void au1xmmc_reset_controller(
struct au1xmmc_host *host)
760 au1xmmc_set_power(host, 0);
762 au1xmmc_set_power(host, 1);
766 au1xmmc_set_clock(host, ios->
clock);
787 #define STATUS_TIMEOUT (SD_STATUS_RAT | SD_STATUS_DT)
788 #define STATUS_DATA_IN (SD_STATUS_NE)
789 #define STATUS_DATA_OUT (SD_STATUS_TH)
802 mmc_signal_sdio_irq(host->
mmc);
820 au1xmmc_receive_pio(host);
822 au1xmmc_data_complete(host, status);
827 else if (status & SD_STATUS_CR) {
829 au1xmmc_cmd_complete(host, status);
833 au1xmmc_send_pio(host);
835 au1xmmc_receive_pio(host);
837 }
else if (status & 0x203F3C70) {
838 DBG(
"Unhandled status %8.8x\n", host->
pdev->id,
854 .dev_physaddr = 0x00000000,
856 .dev_intpolarity = 0,
860 static void au1xmmc_dbdma_callback(
int irq,
void *
dev_id)
874 static int au1xmmc_dbdma_init(
struct au1xmmc_host *host)
893 au1xmmc_dbdma_callback, (
void *)host);
895 dev_err(&host->
pdev->dev,
"cannot allocate TX DMA\n");
900 au1xmmc_dbdma_callback, (
void *)host);
902 dev_err(&host->
pdev->dev,
"cannot allocate RX DMA\n");
919 static void au1xmmc_dbdma_shutdown(
struct au1xmmc_host *host)
928 static void au1xmmc_enable_sdio_irq(
struct mmc_host *mmc,
int en)
939 .request = au1xmmc_request,
940 .set_ios = au1xmmc_set_ios,
941 .get_ro = au1xmmc_card_readonly,
942 .get_cd = au1xmmc_card_inserted,
943 .enable_sdio_irq = au1xmmc_enable_sdio_irq,
955 dev_err(&pdev->
dev,
"no memory for mmc_host\n");
960 host = mmc_priv(mmc);
992 mmc->
ops = &au1xmmc_ops;
995 mmc->
f_max = 24000000;
1006 switch (alchemy_get_cputype()) {
1016 mmc->
f_max = 52000000;
1032 ret = host->
platdata->cd_setup(mmc, 1);
1045 (
unsigned long)host);
1048 (
unsigned long)host);
1051 ret = au1xmmc_dbdma_init(host);
1056 #ifdef CONFIG_LEDS_CLASS
1068 au1xmmc_reset_controller(host);
1072 dev_err(&pdev->
dev,
"cannot add mmc host\n");
1076 platform_set_drvdata(pdev, host);
1079 " (mode=%s)\n", pdev->
id, host->
iobase,
1085 #ifdef CONFIG_LEDS_CLASS
1096 au1xmmc_dbdma_shutdown(host);
1119 struct au1xmmc_host *host = platform_get_drvdata(pdev);
1124 #ifdef CONFIG_LEDS_CLASS
1142 au1xmmc_dbdma_shutdown(host);
1144 au1xmmc_set_power(host, 0);
1152 platform_set_drvdata(pdev,
NULL);
1160 struct au1xmmc_host *host = platform_get_drvdata(pdev);
1178 struct au1xmmc_host *host = platform_get_drvdata(pdev);
1180 au1xmmc_reset_controller(host);
1185 #define au1xmmc_suspend NULL
1186 #define au1xmmc_resume NULL
1190 .probe = au1xmmc_probe,
1191 .remove = au1xmmc_remove,
1200 static int __init au1xmmc_init(
void)
1209 pr_err(
"au1xmmc: cannot add memory dbdma\n");
1214 static void __exit au1xmmc_exit(
void)
1216 if (has_dbdma() && memid)