Index: firmware/target/arm/sandisk/ata-c200_e200.c =================================================================== --- firmware/target/arm/sandisk/ata-c200_e200.c (Revision 17203) +++ firmware/target/arm/sandisk/ata-c200_e200.c (Arbeitskopie) @@ -36,33 +36,86 @@ #define SECTOR_SIZE 512 #define BLOCKS_PER_BANK 0x7a7800 -#define STATUS_REG (*(volatile unsigned int *)(0x70008204)) -#define REG_1 (*(volatile unsigned int *)(0x70008208)) -#define UNKNOWN (*(volatile unsigned int *)(0x70008210)) -#define BLOCK_SIZE_REG (*(volatile unsigned int *)(0x7000821c)) -#define BLOCK_COUNT_REG (*(volatile unsigned int *)(0x70008220)) -#define REG_5 (*(volatile unsigned int *)(0x70008224)) -#define CMD_REG0 (*(volatile unsigned int *)(0x70008228)) -#define CMD_REG1 (*(volatile unsigned int *)(0x7000822c)) -#define CMD_REG2 (*(volatile unsigned int *)(0x70008230)) -#define RESPONSE_REG (*(volatile unsigned int *)(0x70008234)) -#define SD_STATE_REG (*(volatile unsigned int *)(0x70008238)) +/* Register definitions are taken from the PXA27x Developers Manual */ +#define MMC_STRPCL (*(volatile unsigned int *)(0x70008200)) +#define MMC_STAT (*(volatile unsigned int *)(0x70008204)) +#define MMC_CLKRT (*(volatile unsigned int *)(0x70008208)) +#define MMC_SPI (*(volatile unsigned int *)(0x7000820c)) +#define MMC_CMDAT (*(volatile unsigned int *)(0x70008210)) +#define MMC_RESTO (*(volatile unsigned int *)(0x70008214)) +#define MMC_RDTO (*(volatile unsigned int *)(0x70008218)) +#define MMC_BLKLEN (*(volatile unsigned int *)(0x7000821c)) +#define MMC_NUMBLK (*(volatile unsigned int *)(0x70008220)) +#define MMC_I_MASK (*(volatile unsigned int *)(0x70008224)) +#define MMC_CMD (*(volatile unsigned int *)(0x70008228)) +#define MMC_ARGH (*(volatile unsigned int *)(0x7000822c)) +#define MMC_ARGL (*(volatile unsigned int *)(0x70008230)) +#define MMC_RES (*(volatile unsigned int *)(0x70008234)) +#define MMC_SD_STATE (*(volatile unsigned int *)(0x70008238)) /* PXA doesn't have this */ +/* PXA255/27x has separate RX/TX FIFOs with 32x8 bit */ +/* PP502x has a combined Data FIFO with 16x16 bit */ +#define MMC_DATA_FIFO (*(volatile unsigned int *)(0x70008280)) + +/* PP specific registers */ #define REG_11 (*(volatile unsigned int *)(0x70008240)) #define REG_12 (*(volatile unsigned int *)(0x70008244)) -#define DATA_REG (*(volatile unsigned int *)(0x70008280)) -/* STATUS_REG bits */ -#define DATA_DONE (1 << 12) -#define CMD_DONE (1 << 13) -#define ERROR_BITS (0x3f) -#define READY_FOR_DATA (1 << 8) -#define FIFO_FULL (1 << 7) -#define FIFO_EMPTY (1 << 6) +/* MMC_STAT bits */ +#define STAT_SDIO_SUSPEND_ACK (1 << 16) +#define STAT_SDIO_INT (1 << 15) +#define STAT_RD_STALLED (1 << 14) +#define STAT_END_CMD_RES (1 << 13) +#define STAT_PRG_DONE (1 << 12) +#define STAT_DATA_TRAN_DONE (1 << 11) +#define STAT_SPI_WR_ERR (1 << 10) +#define STAT_FLASH_ERR (1 << 9) +#define STAT_CLK_EN (1 << 8) +#define STAT_RECV_FIFO_FULL (1 << 7) /* PXA255 */ +#define STAT_XMIT_FIFO_EMPTY (1 << 6) /* PXA255 */ +#define STAT_RES_CRC_ERR (1 << 5) +#define STAT_DAT_ERR_TOKEN (1 << 4) +#define STAT_CRC_RD_ERR (1 << 3) +#define STAT_CRC_WR_ERR (1 << 2) +#define STAT_TIME_OUT_RES (1 << 1) +#define STAT_TIME_OUT_READ (1) +#define STAT_ERROR_BITS (0x3f) -#define CMD_OK 0x0 /* Command was successful */ -#define CMD_ERROR_2 0x2 /* SD did not respond to command (either it doesn't - understand the command or is not inserted) */ +/* MMC_CMDAT bits */ +/* Some of the bits used by the OF don't make much sense with these definitions. */ +/* So they're probably different between PXA and PP502x */ +/* Bits 0-5 should be correct though */ +#define CMDAT_SDIO_RESUME (1 << 13) +#define CMDAT_SDIO_SUSPEND (1 << 12) +#define CMDAT_SDIO_INT_EN (1 << 11) +#define CMDAT_STOP_TRAN (1 << 10) +#define CMDAT_SD_4DAT (1 << 8) +#define CMDAT_DMA_EN (1 << 7) +#define CMDAT_INIT (1 << 6) +#define CMDAT_BUSY (1 << 5) +#define CMDAT_STRM_BLK (1 << 4) +#define CMDAT_WR_RD (1 << 3) +#define CMDAT_DATA_EN (1 << 2) +#define CMDAT_RES_TYPE3 (3) +#define CMDAT_RES_TYPE2 (2) +#define CMDAT_RES_TYPE1 (1) +/* MMC_I_MASK bits */ +/* 1 = masked */ +/* PP502x probably has only bits 0-4, like PXA255 */ +#define I_MASK_SDIO_SUSPEND_ACK (1 << 12) +#define I_MASK_SDIO_INT (1 << 11) +#define I_MASK_RD_STALLED (1 << 10) +#define I_MASK_RES_ERR (1 << 9) +#define I_MASK_DAT_ERR (1 << 8) +#define I_MASK_TINT (1 << 7) +#define I_MASK_TXFIFO_WR_REQ (1 << 6) +#define I_MASK_RXFIFO_RD_REQ (1 << 5) +#define I_MASK_CLK_IS_OFF (1 << 4) +#define I_MASK_STOP_CMD (1 << 3) +#define I_MASK_END_CMD_RES (1 << 2) +#define I_MASK_PRG_DONE (1 << 1) +#define I_MASK_DATA_TRAN_DONE (1 << 0) + /* SD States */ #define IDLE 0 #define READY 1 @@ -191,7 +244,7 @@ { long t = USEC_TIMER; - while ((STATUS_REG & trigger) == 0) + while ((MMC_STAT & trigger) == 0) { long time = USEC_TIMER; @@ -211,36 +264,36 @@ } static int sd_command(unsigned int cmd, unsigned long arg1, - unsigned int *response, unsigned int type) + unsigned int *response, unsigned int cmdat) { - int i, words; /* Number of 16 bit words to read from RESPONSE_REG */ + int i, words; /* Number of 16 bit words to read from MMC_RES */ unsigned int data[9]; - CMD_REG0 = cmd; - CMD_REG1 = (unsigned int)((arg1 & 0xffff0000) >> 16); - CMD_REG2 = (unsigned int)((arg1 & 0xffff)); - UNKNOWN = type; + MMC_CMD = cmd; + MMC_ARGH = (unsigned int)((arg1 & 0xffff0000) >> 16); + MMC_ARGL = (unsigned int)((arg1 & 0xffff)); + MMC_CMDAT = cmdat; - if (!sd_poll_status(CMD_DONE, 100000)) + if (!sd_poll_status(STAT_END_CMD_RES, 100000)) return -EC_COMMAND; - if ((STATUS_REG & ERROR_BITS) != CMD_OK) + if ((MMC_STAT & STAT_ERROR_BITS) != 0) /* Error sending command */ - return -EC_COMMAND - (STATUS_REG & ERROR_BITS)*100; + return -EC_COMMAND - (MMC_STAT & STAT_ERROR_BITS)*100; if (cmd == GO_IDLE_STATE) return 0; /* no response here */ - words = (type == 2) ? 9 : 3; + words = ((cmdat & 3) == 2) ? 9 : 3; - for (i = 0; i < words; i++) /* RESPONSE_REG is read MSB first */ - data[i] = RESPONSE_REG; /* Read most significant 16-bit word */ + for (i = 0; i < words; i++) /* MMC_RES is read MSB first */ + data[i] = MMC_RES; /* Read most significant 16-bit word */ if (response == NULL) { /* response discarded */ } - else if (type == 2) + else if ((cmdat & 3) == 2) { /* Response type 2 has the following structure: * [135:135] Start Bit - '0' @@ -307,7 +360,7 @@ if (((response >> 9) & 0xf) == state) { - SD_STATE_REG = state; + MMC_SD_STATE = state; return 0; } @@ -344,7 +397,7 @@ "orr r8, r8, r9, lsl #16 \r\n" "stmia %[buf]!, { r2, r4, r6, r8 } \r\n" : [buf]"+&r"(*buf) - : [data]"r"(&DATA_REG) + : [data]"r"(&MMC_DATA_FIFO) : "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9" ); break; @@ -382,7 +435,7 @@ "stmia %[buf]!, { r2, r4, r6, r8 } \r\n" "strb r10, [%[buf]], #1 \r\n" : [buf]"+&r"(*buf) - : [data]"r"(&DATA_REG) + : [data]"r"(&MMC_DATA_FIFO) : "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10" ); break; @@ -402,7 +455,7 @@ "stmia %[buf]!, { r2, r3, r5, r7 } \r\n" "strh r10, [%[buf]], #2 \r\n" : [buf]"+&r"(*buf) - : [data]"r"(&DATA_REG) + : [data]"r"(&MMC_DATA_FIFO) : "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10" ); break; @@ -440,7 +493,7 @@ "mov r10, r10, lsr #16 \r\n" "strb r10, [%[buf]], #1 \r\n" : [buf]"+&r"(*buf) - : [data]"r"(&DATA_REG) + : [data]"r"(&MMC_DATA_FIFO) : "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10" ); break; @@ -463,7 +516,7 @@ "bgt 1b \r\n" : [cnt]"+&r"(cnt), [buf]"+&r"(*buf), [t]"=&r"(t) - : [data]"r"(&DATA_REG) + : [data]"r"(&MMC_DATA_FIFO) ); } @@ -477,7 +530,7 @@ { t = *(*buf)++; t |= *(*buf)++ << 8; - DATA_REG = t; + MMC_DATA_FIFO = t; } while (--cnt > 0); /* tail loop is faster */ } @@ -493,14 +546,14 @@ if (ret < 0) return ret; - BLOCK_SIZE_REG = 512; - BLOCK_COUNT_REG = 1; + MMC_BLKLEN = 512; + MMC_NUMBLK = 1; ret = sd_command(35, 0, NULL, 0x1c0d); /* CMD35 is vendor specific */ if (ret < 0) return ret; - SD_STATE_REG = PRG; + MMC_SD_STATE = PRG; card_data[0] = bank; @@ -509,7 +562,7 @@ for (i = 0; i < BLOCK_SIZE/2; i += FIFO_LEN) { /* Wait for the FIFO to empty */ - if (sd_poll_status(FIFO_EMPTY, 10000)) + if (sd_poll_status(STAT_XMIT_FIFO_EMPTY, 10000)) { copy_write_sectors(&write_buf); /* Copy one chunk of 16 words */ continue; @@ -518,7 +571,7 @@ return -EC_FIFO_SEL_BANK_EMPTY; } - if (!sd_poll_status(DATA_DONE, 10000)) + if (!sd_poll_status(STAT_PRG_DONE, 10000)) return -EC_FIFO_SEL_BANK_DONE; currcard->current_bank = bank; @@ -596,7 +649,7 @@ int ret; /* Enable and initialise controller */ - REG_1 = 6; + MMC_CLKRT = 6; /* switch down to 304 kHz */ /* Initialise card data as blank */ memset(currcard, 0, sizeof(*currcard)); @@ -616,9 +669,9 @@ DEV_RS |= DEV_ATA; /* Reset controller */ DEV_RS &=~DEV_ATA; /* Clear Reset */ - SD_STATE_REG = TRAN; + MMC_SD_STATE = TRAN; - REG_5 = 0xf; + MMC_I_MASK = 0xf; /* disable interrupts */ ret = sd_command(GO_IDLE_STATE, 0, NULL, 256); if (ret < 0) @@ -703,7 +756,7 @@ } #endif /* HAVE_HOTSWAP */ - REG_1 = 0; + MMC_CLKRT = 0; /* switch back to 19.5 MHz */ ret = sd_command(SELECT_CARD, currcard->rca, NULL, 129); if (ret < 0) @@ -721,14 +774,14 @@ if (ret < 0) goto card_init_error; - BLOCK_SIZE_REG = currcard->block_size; + MMC_BLKLEN = currcard->block_size; /* If this card is >4GB & not SDHC, then we need to enable bank switching */ if( (currcard->numblocks >= BLOCKS_PER_BANK) && ((currcard->ocr & (1<<30)) == 0) ) { - SD_STATE_REG = TRAN; - BLOCK_COUNT_REG = 1; + MMC_SD_STATE = TRAN; + MMC_NUMBLK = 1; ret = sd_command(SWITCH_FUNC, 0x80ffffef, NULL, 0x1c05); if (ret < 0) @@ -741,7 +794,7 @@ for (i = 0; i < BLOCK_SIZE/2; i += FIFO_LEN) { /* Wait for the FIFO to be full */ - if (sd_poll_status(FIFO_FULL, 100000)) + if (sd_poll_status(STAT_RECV_FIFO_FULL, 100000)) { copy_read_sectors_slow(&dataptr); continue; @@ -845,7 +898,7 @@ if (ret < 0) goto ata_read_error; - BLOCK_COUNT_REG = incount; + MMC_NUMBLK = incount; #ifdef HAVE_HOTSWAP if(currcard->ocr & (1<<30) ) @@ -867,7 +920,7 @@ for (buf = inbuf; buf < buf_end;) { /* Wait for the FIFO to be full */ - if (sd_poll_status(FIFO_FULL, 0x80000)) + if (sd_poll_status(STAT_RECV_FIFO_FULL, 0x80000)) { copy_read_sectors_fast(&buf); /* Copy one chunk of 16 words */ /* TODO: Switch bank if necessary */ @@ -960,7 +1013,7 @@ if (ret < 0) goto ata_write_error; - BLOCK_COUNT_REG = count; + MMC_NUMBLK = count; #ifdef HAVE_HOTSWAP if(currcard->ocr & (1<<30) ) @@ -982,14 +1035,14 @@ { if (buf == buf_end) { - /* Set SD_STATE_REG to PRG for the last buffer fill */ - SD_STATE_REG = PRG; + /* Set MMC_SD_STATE to PRG for the last buffer fill */ + MMC_SD_STATE = PRG; } udelay(2); /* needed here (loop is too fast :-) */ /* Wait for the FIFO to empty */ - if (sd_poll_status(FIFO_EMPTY, 0x80000)) + if (sd_poll_status(STAT_XMIT_FIFO_EMPTY, 0x80000)) { copy_write_sectors(&buf); /* Copy one chunk of 16 words */ /* TODO: Switch bank if necessary */ @@ -1002,7 +1055,7 @@ last_disk_activity = current_tick; - if (!sd_poll_status(DATA_DONE, 0x80000)) + if (!sd_poll_status(STAT_PRG_DONE, 0x80000)) { ret = -EC_FIFO_WR_DONE; goto ata_write_error;