summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/ata_sd_as3525.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525/ata_sd_as3525.c')
-rw-r--r--firmware/target/arm/as3525/ata_sd_as3525.c25
1 files changed, 10 insertions, 15 deletions
diff --git a/firmware/target/arm/as3525/ata_sd_as3525.c b/firmware/target/arm/as3525/ata_sd_as3525.c
index b3ab31b293..91d65235ef 100644
--- a/firmware/target/arm/as3525/ata_sd_as3525.c
+++ b/firmware/target/arm/as3525/ata_sd_as3525.c
@@ -595,7 +595,7 @@ static int sd_select_bank(signed char bank)
595 dma_enable_channel(0, card_data, MCI_FIFO(INTERNAL_AS3525), DMA_PERI_SD, 595 dma_enable_channel(0, card_data, MCI_FIFO(INTERNAL_AS3525), DMA_PERI_SD,
596 DMAC_FLOWCTRL_PERI_MEM_TO_PERI, true, false, 0, DMA_S8, NULL); 596 DMAC_FLOWCTRL_PERI_MEM_TO_PERI, true, false, 0, DMA_S8, NULL);
597 597
598 MCI_DATA_TIMER(INTERNAL_AS3525) = 0x1000000; /* FIXME: arbitrary */ 598 MCI_DATA_TIMER(INTERNAL_AS3525) = 0xffffffff;/* FIXME: arbitrary */
599 MCI_DATA_LENGTH(INTERNAL_AS3525) = 512; 599 MCI_DATA_LENGTH(INTERNAL_AS3525) = 512;
600 MCI_DATA_CTRL(INTERNAL_AS3525) = (1<<0) /* enable */ | 600 MCI_DATA_CTRL(INTERNAL_AS3525) = (1<<0) /* enable */ |
601 (0<<1) /* transfer direction */ | 601 (0<<1) /* transfer direction */ |
@@ -618,7 +618,8 @@ static int sd_select_bank(signed char bank)
618} 618}
619 619
620#define UNALIGNED_NUM_SECTORS 10 620#define UNALIGNED_NUM_SECTORS 10
621static int32_t aligned_buffer[UNALIGNED_NUM_SECTORS* (SECTOR_SIZE / 4)]; 621static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS* SECTOR_SIZE] __attribute__((aligned(32))); /* align on cache line size */
622static unsigned char *uncached_buffer = UNCACHED_ADDR(aligned_buffer);
622 623
623static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, 624static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start,
624 int count, void* buf, const bool write) 625 int count, void* buf, const bool write)
@@ -627,7 +628,6 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start,
627 const int drive = 0; 628 const int drive = 0;
628#endif 629#endif
629 int ret = 0; 630 int ret = 0;
630 bool unaligned_transfer = (int)buf & 3;
631 631
632 /* skip SanDisk OF */ 632 /* skip SanDisk OF */
633 if (drive == INTERNAL_AS3525) 633 if (drive == INTERNAL_AS3525)
@@ -693,16 +693,11 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start,
693 transfer = BLOCKS_PER_BANK - bank_start; 693 transfer = BLOCKS_PER_BANK - bank_start;
694 } 694 }
695 695
696 if(unaligned_transfer) 696 dma_buf = aligned_buffer;
697 { 697 if(transfer > UNALIGNED_NUM_SECTORS)
698 dma_buf = aligned_buffer; 698 transfer = UNALIGNED_NUM_SECTORS;
699 if(transfer > UNALIGNED_NUM_SECTORS) 699 if(write)
700 transfer = UNALIGNED_NUM_SECTORS; 700 memcpy(uncached_buffer, buf, transfer * SECTOR_SIZE);
701 if(write)
702 memcpy(aligned_buffer, buf, transfer * SECTOR_SIZE);
703 }
704 else /* Aligned transfers are faster : no memcpy */
705 dma_buf = buf;
706 701
707 /* Set bank_start to the correct unit (blocks or bytes) */ 702 /* Set bank_start to the correct unit (blocks or bytes) */
708 if(!(card_info[drive].ocr & (1<<30))) /* not SDHC */ 703 if(!(card_info[drive].ocr & (1<<30))) /* not SDHC */
@@ -734,8 +729,8 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start,
734 wakeup_wait(&transfer_completion_signal, TIMEOUT_BLOCK); 729 wakeup_wait(&transfer_completion_signal, TIMEOUT_BLOCK);
735 if(!retry) 730 if(!retry)
736 { 731 {
737 if(unaligned_transfer && !write) 732 if(!write)
738 memcpy(buf, aligned_buffer, transfer * SECTOR_SIZE); 733 memcpy(buf, uncached_buffer, transfer * SECTOR_SIZE);
739 buf += transfer * SECTOR_SIZE; 734 buf += transfer * SECTOR_SIZE;
740 start += transfer; 735 start += transfer;
741 count -= transfer; 736 count -= transfer;