diff options
Diffstat (limited to 'firmware/target/arm')
-rw-r--r-- | firmware/target/arm/as3525/ata_sd_as3525.c | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/firmware/target/arm/as3525/ata_sd_as3525.c b/firmware/target/arm/as3525/ata_sd_as3525.c index f00badba69..4c1278b58f 100644 --- a/firmware/target/arm/as3525/ata_sd_as3525.c +++ b/firmware/target/arm/as3525/ata_sd_as3525.c | |||
@@ -188,36 +188,28 @@ void INT_MCI0(void) | |||
188 | static bool send_cmd(const int drive, const int cmd, const int arg, | 188 | static bool send_cmd(const int drive, const int cmd, const int arg, |
189 | const int flags, long *response) | 189 | const int flags, long *response) |
190 | { | 190 | { |
191 | int val, status; | 191 | int status; |
192 | |||
193 | while(MCI_STATUS(drive) & MCI_CMD_ACTIVE); | ||
194 | |||
195 | if(MCI_COMMAND(drive) & MCI_COMMAND_ENABLE) /* clears existing command */ | ||
196 | { | ||
197 | MCI_COMMAND(drive) = 0; | ||
198 | mci_delay(); | ||
199 | } | ||
200 | |||
201 | val = cmd | MCI_COMMAND_ENABLE; | ||
202 | if(flags & MCI_RESP) | ||
203 | { | ||
204 | val |= MCI_COMMAND_RESPONSE; | ||
205 | if(flags & MCI_LONG_RESP) | ||
206 | val |= MCI_COMMAND_LONG_RESPONSE; | ||
207 | } | ||
208 | 192 | ||
193 | /* Clear old status flags */ | ||
209 | MCI_CLEAR(drive) = 0x7ff; | 194 | MCI_CLEAR(drive) = 0x7ff; |
210 | 195 | ||
196 | /* Load command argument or clear if none */ | ||
211 | MCI_ARGUMENT(drive) = (flags & MCI_ARG) ? arg : 0; | 197 | MCI_ARGUMENT(drive) = (flags & MCI_ARG) ? arg : 0; |
212 | MCI_COMMAND(drive) = val; | ||
213 | 198 | ||
214 | while(MCI_STATUS(drive) & MCI_CMD_ACTIVE); /* wait for cmd completion */ | 199 | /* Construct MCI_COMMAND & enable CPSM */ |
200 | MCI_COMMAND(drive) = | ||
201 | /*b0:5*/ cmd | ||
202 | /* b6 */| ((flags & (MCI_RESP|MCI_LONG_RESP)) ? MCI_COMMAND_RESPONSE : 0) | ||
203 | /* b7 */| ((flags & MCI_LONG_RESP) ? MCI_COMMAND_LONG_RESPONSE : 0) | ||
204 | /* b8 | MCI_COMMAND_INTERRUPT */ | ||
205 | /* b9 | MCI_COMMAND_PENDING */ /*Only used with stream data transfer*/ | ||
206 | /* b10*/| MCI_COMMAND_ENABLE; /* Enables CPSM */ | ||
215 | 207 | ||
208 | /* Wait while cmd completes then disable CPSM */ | ||
209 | while(MCI_STATUS(drive) & MCI_CMD_ACTIVE); | ||
216 | MCI_COMMAND(drive) = 0; | 210 | MCI_COMMAND(drive) = 0; |
217 | MCI_ARGUMENT(drive) = ~0; | ||
218 | 211 | ||
219 | status = MCI_STATUS(drive); | 212 | status = MCI_STATUS(drive); |
220 | MCI_CLEAR(drive) = 0x7ff; | ||
221 | 213 | ||
222 | if(flags & MCI_RESP) | 214 | if(flags & MCI_RESP) |
223 | { | 215 | { |
@@ -723,12 +715,19 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, | |||
723 | if(!(card_info[drive].ocr & (1<<30))) /* not SDHC */ | 715 | if(!(card_info[drive].ocr & (1<<30))) /* not SDHC */ |
724 | bank_start *= SD_BLOCK_SIZE; | 716 | bank_start *= SD_BLOCK_SIZE; |
725 | 717 | ||
726 | if(!send_cmd(drive, cmd, bank_start, MCI_ARG, NULL)) | 718 | ret = sd_wait_for_state(drive, SD_TRAN); |
719 | if (ret < 0) | ||
727 | { | 720 | { |
728 | ret -= 3*20; | 721 | ret -= 3*20; |
729 | goto sd_transfer_error; | 722 | goto sd_transfer_error; |
730 | } | 723 | } |
731 | 724 | ||
725 | if(!send_cmd(drive, cmd, bank_start, MCI_ARG, NULL)) | ||
726 | { | ||
727 | ret -= 4*20; | ||
728 | goto sd_transfer_error; | ||
729 | } | ||
730 | |||
732 | if(write) | 731 | if(write) |
733 | dma_enable_channel(0, dma_buf, MCI_FIFO(drive), | 732 | dma_enable_channel(0, dma_buf, MCI_FIFO(drive), |
734 | (drive == INTERNAL_AS3525) ? DMA_PERI_SD : DMA_PERI_SD_SLOT, | 733 | (drive == INTERNAL_AS3525) ? DMA_PERI_SD : DMA_PERI_SD_SLOT, |
@@ -771,14 +770,7 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, | |||
771 | 770 | ||
772 | if(!send_cmd(drive, SD_STOP_TRANSMISSION, 0, MCI_NO_FLAGS, NULL)) | 771 | if(!send_cmd(drive, SD_STOP_TRANSMISSION, 0, MCI_NO_FLAGS, NULL)) |
773 | { | 772 | { |
774 | ret = -4*20; | 773 | ret = -5*20; |
775 | goto sd_transfer_error; | ||
776 | } | ||
777 | |||
778 | ret = sd_wait_for_state(drive, SD_TRAN); | ||
779 | if (ret < 0) | ||
780 | { | ||
781 | ret -= 5*20; | ||
782 | goto sd_transfer_error; | 774 | goto sd_transfer_error; |
783 | } | 775 | } |
784 | } | 776 | } |