summaryrefslogtreecommitdiff
path: root/firmware/target/arm
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/as3525/sd-as3525.c15
-rw-r--r--firmware/target/arm/as3525/sd-as3525v2.c8
-rw-r--r--firmware/target/arm/ata-nand-telechips.c92
-rw-r--r--firmware/target/arm/imx233/nand-imx233.c4
-rw-r--r--firmware/target/arm/imx233/partitions-imx233.c8
-rw-r--r--firmware/target/arm/imx233/partitions-imx233.h6
-rw-r--r--firmware/target/arm/imx233/sdmmc-imx233.c20
-rw-r--r--firmware/target/arm/pp/ata-pp5020.c24
-rw-r--r--firmware/target/arm/pp/ata-sd-pp.c40
-rw-r--r--firmware/target/arm/rk27xx/ata-nand-rk27xx.c8
-rw-r--r--firmware/target/arm/rk27xx/sd-rk27xx.c9
-rw-r--r--firmware/target/arm/s3c2440/sd-s3c2440.c171
-rw-r--r--firmware/target/arm/s5l8700/ata-nand-s5l8700.c8
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c11
-rw-r--r--firmware/target/arm/tcc780x/sd-tcc780x.c94
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c22
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/ata-target.h4
-rw-r--r--firmware/target/arm/tms320dm320/sdmmc-dm320.c23
18 files changed, 290 insertions, 277 deletions
diff --git a/firmware/target/arm/as3525/sd-as3525.c b/firmware/target/arm/as3525/sd-as3525.c
index 70e0778d2b..df39cba495 100644
--- a/firmware/target/arm/as3525/sd-as3525.c
+++ b/firmware/target/arm/as3525/sd-as3525.c
@@ -446,7 +446,7 @@ static int sd_init_card(const int drive)
446 sd_parse_csd(&card_info[drive]); 446 sd_parse_csd(&card_info[drive]);
447 447
448#if defined(HAVE_MULTIDRIVE) 448#if defined(HAVE_MULTIDRIVE)
449 hs_card = (card_info[drive].speed == 50000000); 449 hs_card = (card_info[drive].speed >= 50000000);
450#endif 450#endif
451 451
452 /* Boost MCICLK to operating speed */ 452 /* Boost MCICLK to operating speed */
@@ -455,7 +455,7 @@ static int sd_init_card(const int drive)
455#if defined(HAVE_MULTIDRIVE) 455#if defined(HAVE_MULTIDRIVE)
456 else 456 else
457 /* MCICLK = PCLK/2 = 31MHz(HS) or PCLK/4 = 15.5 Mhz (STD)*/ 457 /* MCICLK = PCLK/2 = 31MHz(HS) or PCLK/4 = 15.5 Mhz (STD)*/
458 MCI_CLOCK(drive) = (hs_card ? MCI_HALFSPEED : MCI_QUARTERSPEED) | 458 MCI_CLOCK(drive) = (hs_card ? MCI_HALFSPEED : MCI_QUARTERSPEED) |
459 MCI_CLOCK_POWERSAVE; /* SD supports powersave */ 459 MCI_CLOCK_POWERSAVE; /* SD supports powersave */
460#endif 460#endif
461 461
@@ -680,7 +680,7 @@ static int sd_select_bank(signed char bank)
680 return 0; 680 return 0;
681} 681}
682 682
683static int sd_transfer_sectors(IF_MD(int drive,) unsigned long start, 683static int sd_transfer_sectors(IF_MD(int drive,) sector_t start,
684 int count, void* buf, const bool write) 684 int count, void* buf, const bool write)
685{ 685{
686#ifndef HAVE_MULTIDRIVE 686#ifndef HAVE_MULTIDRIVE
@@ -735,7 +735,8 @@ static int sd_transfer_sectors(IF_MD(int drive,) unsigned long start,
735 unsigned int transfer = (count >= 128) ? 127 : count; /* sectors */ 735 unsigned int transfer = (count >= 128) ? 127 : count; /* sectors */
736 void *dma_buf; 736 void *dma_buf;
737 737
738 unsigned long bank_start = start; 738 sector_t bank_start = start;
739 // XXX 64-bit sectors?
739 740
740 /* Only switch banks for internal storage */ 741 /* Only switch banks for internal storage */
741 if(drive == INTERNAL_AS3525) 742 if(drive == INTERNAL_AS3525)
@@ -869,7 +870,7 @@ sd_transfer_error_nodma:
869 return ret; 870 return ret;
870} 871}
871 872
872int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count, 873int sd_read_sectors(IF_MD(int drive,) sector_t start, int count,
873 void* buf) 874 void* buf)
874{ 875{
875 int ret; 876 int ret;
@@ -881,11 +882,11 @@ int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count,
881 return ret; 882 return ret;
882} 883}
883 884
884int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count, 885int sd_write_sectors(IF_MD(int drive,) sector_t start, int count,
885 const void* buf) 886 const void* buf)
886{ 887{
887#ifdef VERIFY_WRITE 888#ifdef VERIFY_WRITE
888 unsigned long saved_start = start; 889 sector_t saved_start = start;
889 int saved_count = count; 890 int saved_count = count;
890 void *saved_buf = (void*)buf; 891 void *saved_buf = (void*)buf;
891#endif 892#endif
diff --git a/firmware/target/arm/as3525/sd-as3525v2.c b/firmware/target/arm/as3525/sd-as3525v2.c
index b512cc2ea4..f9ef7d9c97 100644
--- a/firmware/target/arm/as3525/sd-as3525v2.c
+++ b/firmware/target/arm/as3525/sd-as3525v2.c
@@ -677,7 +677,7 @@ int sd_init(void)
677 return 0; 677 return 0;
678} 678}
679 679
680static int sd_transfer_sectors(IF_MD(int drive,) unsigned long start, 680static int sd_transfer_sectors(IF_MD(int drive,) sector_t start,
681 int count, void* buf, bool write) 681 int count, void* buf, bool write)
682{ 682{
683 unsigned long response; 683 unsigned long response;
@@ -776,7 +776,7 @@ retry_with_reinit:
776 776
777 MCI_BYTCNT = transfer * SD_BLOCK_SIZE; 777 MCI_BYTCNT = transfer * SD_BLOCK_SIZE;
778 778
779 int arg = start; 779 sector_t arg = start; // XXX 64-bit
780 if(!(card_info[drive].ocr & (1<<30))) /* not SDHC */ 780 if(!(card_info[drive].ocr & (1<<30))) /* not SDHC */
781 arg *= SD_BLOCK_SIZE; 781 arg *= SD_BLOCK_SIZE;
782 782
@@ -858,13 +858,13 @@ exit:
858 return ret; 858 return ret;
859} 859}
860 860
861int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count, 861int sd_read_sectors(IF_MD(int drive,) sector_t start, int count,
862 void* buf) 862 void* buf)
863{ 863{
864 return sd_transfer_sectors(IF_MD(drive,) start, count, buf, false); 864 return sd_transfer_sectors(IF_MD(drive,) start, count, buf, false);
865} 865}
866 866
867int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count, 867int sd_write_sectors(IF_MD(int drive,) sector_t start, int count,
868 const void* buf) 868 const void* buf)
869{ 869{
870 return sd_transfer_sectors(IF_MD(drive,) start, count, (void*)buf, true); 870 return sd_transfer_sectors(IF_MD(drive,) start, count, (void*)buf, true);
diff --git a/firmware/target/arm/ata-nand-telechips.c b/firmware/target/arm/ata-nand-telechips.c
index d61c223219..453a51ed1b 100644
--- a/firmware/target/arm/ata-nand-telechips.c
+++ b/firmware/target/arm/ata-nand-telechips.c
@@ -179,7 +179,7 @@ static int phys_segment_to_page_addr(int phys_segment, int page_in_seg)
179 break; 179 break;
180 } 180 }
181 } 181 }
182 182
183 page_addr += (page_in_seg / nand_data->planes); 183 page_addr += (page_in_seg / nand_data->planes);
184 184
185 return page_addr; 185 return page_addr;
@@ -222,7 +222,7 @@ static void nand_chip_select(int bank)
222static void nand_read_id(int bank, unsigned char* id_buf) 222static void nand_read_id(int bank, unsigned char* id_buf)
223{ 223{
224 int i; 224 int i;
225 225
226 /* Enable NFC bus clock */ 226 /* Enable NFC bus clock */
227 BCLKCTR |= DEV_NAND; 227 BCLKCTR |= DEV_NAND;
228 228
@@ -358,7 +358,7 @@ static void nand_setup_read(int bank, int row, int column)
358static void nand_end_read(void) 358static void nand_end_read(void)
359{ 359{
360 nand_chip_select(-1); 360 nand_chip_select(-1);
361 361
362 /* Disable NFC bus clock */ 362 /* Disable NFC bus clock */
363 BCLKCTR &= ~DEV_NAND; 363 BCLKCTR &= ~DEV_NAND;
364} 364}
@@ -367,7 +367,7 @@ static void nand_end_read(void)
367static void nand_read_raw(int bank, int row, int column, int size, void* buf) 367static void nand_read_raw(int bank, int row, int column, int size, void* buf)
368{ 368{
369 int i; 369 int i;
370 370
371 nand_setup_read(bank, row, column); 371 nand_setup_read(bank, row, column);
372 372
373 /* Read data into page buffer */ 373 /* Read data into page buffer */
@@ -388,7 +388,7 @@ static void nand_read_raw(int bank, int row, int column, int size, void* buf)
388 ((unsigned int*)buf)[i] = NFC_WDATA; 388 ((unsigned int*)buf)[i] = NFC_WDATA;
389 } 389 }
390 } 390 }
391 391
392 nand_end_read(); 392 nand_end_read();
393} 393}
394 394
@@ -422,7 +422,7 @@ static void nand_get_chip_info(void)
422 sectors_per_page = nand_data->page_size / SECTOR_SIZE; 422 sectors_per_page = nand_data->page_size / SECTOR_SIZE;
423 423
424 sectors_per_segment = bytes_per_segment / SECTOR_SIZE; 424 sectors_per_segment = bytes_per_segment / SECTOR_SIZE;
425 425
426 pages_per_segment = sectors_per_segment / sectors_per_page; 426 pages_per_segment = sectors_per_segment / sectors_per_page;
427 427
428 /* Establish how many banks are present */ 428 /* Establish how many banks are present */
@@ -494,7 +494,7 @@ static bool nand_read_sector_of_phys_page(int bank, int page,
494 494
495#ifdef USE_ECC_CORRECTION 495#ifdef USE_ECC_CORRECTION
496 unsigned long spare_buf[4]; 496 unsigned long spare_buf[4];
497 497
498 /* Set up the ECC controller to monitor reads from NFC_WDATA */ 498 /* Set up the ECC controller to monitor reads from NFC_WDATA */
499 BCLKCTR |= DEV_ECC; 499 BCLKCTR |= DEV_ECC;
500 ECC_BASE = (unsigned long)&NFC_WDATA; 500 ECC_BASE = (unsigned long)&NFC_WDATA;
@@ -514,27 +514,27 @@ static bool nand_read_sector_of_phys_page(int bank, int page,
514 This way, reads are always done through NFC_WDATA - otherwise they 514 This way, reads are always done through NFC_WDATA - otherwise they
515 would not be 'seen' by the ECC controller. */ 515 would not be 'seen' by the ECC controller. */
516 static char temp_buf[SECTOR_SIZE]; 516 static char temp_buf[SECTOR_SIZE];
517 517
518 unsigned int* ptr = (unsigned int*) temp_buf; 518 unsigned int* ptr = (unsigned int*) temp_buf;
519 519
520 for (i = 0; i < (SECTOR_SIZE/4); i++) 520 for (i = 0; i < (SECTOR_SIZE/4); i++)
521 { 521 {
522 *ptr++ = NFC_WDATA; 522 *ptr++ = NFC_WDATA;
523 } 523 }
524 524
525 memcpy(buf, temp_buf, SECTOR_SIZE); 525 memcpy(buf, temp_buf, SECTOR_SIZE);
526 } 526 }
527 else 527 else
528 { 528 {
529 /* Use straight word copy as buffer and size are both word-aligned */ 529 /* Use straight word copy as buffer and size are both word-aligned */
530 unsigned int* ptr = (unsigned int*) buf; 530 unsigned int* ptr = (unsigned int*) buf;
531 531
532 for (i = 0; i < (SECTOR_SIZE/4); i++) 532 for (i = 0; i < (SECTOR_SIZE/4); i++)
533 { 533 {
534 *ptr++ = NFC_WDATA; 534 *ptr++ = NFC_WDATA;
535 } 535 }
536 } 536 }
537 537
538#ifdef USE_ECC_CORRECTION 538#ifdef USE_ECC_CORRECTION
539 /* Stop monitoring before we read the OOB data */ 539 /* Stop monitoring before we read the OOB data */
540 ECC_CTRL &= ~ECC_M4EN; 540 ECC_CTRL &= ~ECC_M4EN;
@@ -549,29 +549,29 @@ static bool nand_read_sector_of_phys_page(int bank, int page,
549 /* Calculate MLC4 ECC using bytes 0,1,8-15 */ 549 /* Calculate MLC4 ECC using bytes 0,1,8-15 */
550 BCLKCTR |= DEV_ECC; 550 BCLKCTR |= DEV_ECC;
551 ECC_CTRL |= ECC_M4EN; 551 ECC_CTRL |= ECC_M4EN;
552 552
553 MLC_ECC0W = *(unsigned short*)spare_buf; 553 MLC_ECC0W = *(unsigned short*)spare_buf;
554 MLC_ECC1W = spare_buf[2]; 554 MLC_ECC1W = spare_buf[2];
555 MLC_ECC2W = spare_buf[3]; 555 MLC_ECC2W = spare_buf[3];
556 556
557 while (!(ECC_CTRL & ECC_READY)) {}; 557 while (!(ECC_CTRL & ECC_READY)) {};
558 558
559 int errors = ECC_ERR_NUM & 7; 559 int errors = ECC_ERR_NUM & 7;
560 560
561 switch (errors) 561 switch (errors)
562 { 562 {
563 case 4: /* nothing to correct */ 563 case 4: /* nothing to correct */
564 break; 564 break;
565 565
566 case 7: /* fail, can't correct */ 566 case 7: /* fail, can't correct */
567 ret = false; 567 ret = false;
568 break; 568 break;
569 569
570 default: /* between 1 and 4 errors */ 570 default: /* between 1 and 4 errors */
571 { 571 {
572 int i; 572 int i;
573 unsigned char* char_buf = (unsigned char*)buf; 573 unsigned char* char_buf = (unsigned char*)buf;
574 574
575 for (i = 0; i < errors + 1; i++) 575 for (i = 0; i < errors + 1; i++)
576 { 576 {
577 int offset = 0x207 - ECC_ERRADDR(i); 577 int offset = 0x207 - ECC_ERRADDR(i);
@@ -584,7 +584,7 @@ static bool nand_read_sector_of_phys_page(int bank, int page,
584 ECC_CTRL &= ~ECC_M4EN; 584 ECC_CTRL &= ~ECC_M4EN;
585 BCLKCTR &= ~DEV_ECC; 585 BCLKCTR &= ~DEV_ECC;
586#endif 586#endif
587 587
588 nand_end_read(); 588 nand_end_read();
589 589
590 return ret; 590 return ret;
@@ -619,7 +619,7 @@ static bool nand_read_sector_of_logical_segment(int log_segment, int sector,
619 619
620 int cache_num = 0; 620 int cache_num = 0;
621 bool found = false; 621 bool found = false;
622 622
623 while (!found && cache_num < write_caches_in_use) 623 while (!found && cache_num < write_caches_in_use)
624 { 624 {
625 if (write_caches[cache_num].log_segment == log_segment) 625 if (write_caches[cache_num].log_segment == log_segment)
@@ -628,10 +628,10 @@ static bool nand_read_sector_of_logical_segment(int log_segment, int sector,
628 { 628 {
629 /* data is located in random pages cache */ 629 /* data is located in random pages cache */
630 found = true; 630 found = true;
631 631
632 bank = write_caches[cache_num].random_bank; 632 bank = write_caches[cache_num].random_bank;
633 phys_segment = write_caches[cache_num].random_phys_segment; 633 phys_segment = write_caches[cache_num].random_phys_segment;
634 634
635 page_in_segment = 635 page_in_segment =
636 write_caches[cache_num].page_map[page_in_segment]; 636 write_caches[cache_num].page_map[page_in_segment];
637 } 637 }
@@ -640,7 +640,7 @@ static bool nand_read_sector_of_logical_segment(int log_segment, int sector,
640 { 640 {
641 /* data is located in in-place pages cache */ 641 /* data is located in in-place pages cache */
642 found = true; 642 found = true;
643 643
644 bank = write_caches[cache_num].inplace_bank; 644 bank = write_caches[cache_num].inplace_bank;
645 phys_segment = write_caches[cache_num].inplace_phys_segment; 645 phys_segment = write_caches[cache_num].inplace_phys_segment;
646 } 646 }
@@ -664,7 +664,7 @@ static inline unsigned char get_sector_type(char* spare_buf)
664static inline unsigned short get_log_segment_id(int phys_seg, char* spare_buf) 664static inline unsigned short get_log_segment_id(int phys_seg, char* spare_buf)
665{ 665{
666 (void)phys_seg; 666 (void)phys_seg;
667 667
668 return ((spare_buf[OFF_LOG_SEG_HIBYTE] << 8) | 668 return ((spare_buf[OFF_LOG_SEG_HIBYTE] << 8) |
669 spare_buf[OFF_LOG_SEG_LOBYTE]) 669 spare_buf[OFF_LOG_SEG_LOBYTE])
670#if defined(FTL_V1) 670#if defined(FTL_V1)
@@ -702,7 +702,7 @@ static void read_random_writes_cache(int bank, int phys_segment)
702 16, spare_buf); 702 16, spare_buf);
703 703
704 log_segment = get_log_segment_id(phys_segment, spare_buf); 704 log_segment = get_log_segment_id(phys_segment, spare_buf);
705 705
706 if (log_segment == -1) 706 if (log_segment == -1)
707 return; 707 return;
708 708
@@ -734,13 +734,13 @@ static void read_random_writes_cache(int bank, int phys_segment)
734 page++) 734 page++)
735 { 735 {
736 unsigned short cached_page; 736 unsigned short cached_page;
737 737
738 nand_read_raw(bank, phys_segment_to_page_addr(phys_segment, page), 738 nand_read_raw(bank, phys_segment_to_page_addr(phys_segment, page),
739 SECTOR_SIZE, /* offset to first sector's spare */ 739 SECTOR_SIZE, /* offset to first sector's spare */
740 16, spare_buf); 740 16, spare_buf);
741 741
742 cached_page = get_cached_page_id(spare_buf); 742 cached_page = get_cached_page_id(spare_buf);
743 743
744 if (cached_page != 0xFFFF) 744 if (cached_page != 0xFFFF)
745 write_caches[cache_no].page_map[cached_page] = page; 745 write_caches[cache_no].page_map[cached_page] = page;
746 } 746 }
@@ -759,10 +759,10 @@ static void read_inplace_writes_cache(int bank, int phys_segment)
759 16, spare_buf); 759 16, spare_buf);
760 760
761 log_segment = get_log_segment_id(phys_segment, spare_buf); 761 log_segment = get_log_segment_id(phys_segment, spare_buf);
762 762
763 if (log_segment == -1) 763 if (log_segment == -1)
764 return; 764 return;
765 765
766 /* Find which cache this is related to */ 766 /* Find which cache this is related to */
767 int cache_no = find_write_cache(log_segment); 767 int cache_no = find_write_cache(log_segment);
768 768
@@ -780,7 +780,7 @@ static void read_inplace_writes_cache(int bank, int phys_segment)
780 } 780 }
781 781
782 write_caches[cache_no].log_segment = log_segment; 782 write_caches[cache_no].log_segment = log_segment;
783 783
784 /* Find how many pages have been written to the new segment */ 784 /* Find how many pages have been written to the new segment */
785 while (log_segment != -1 && 785 while (log_segment != -1 &&
786 page < (nand_data->pages_per_block * nand_data->planes) - 1) 786 page < (nand_data->pages_per_block * nand_data->planes) - 1)
@@ -791,7 +791,7 @@ static void read_inplace_writes_cache(int bank, int phys_segment)
791 791
792 log_segment = get_log_segment_id(phys_segment, spare_buf); 792 log_segment = get_log_segment_id(phys_segment, spare_buf);
793 } 793 }
794 794
795 if (page != 0) 795 if (page != 0)
796 { 796 {
797 write_caches[cache_no].inplace_bank = bank; 797 write_caches[cache_no].inplace_bank = bank;
@@ -801,7 +801,7 @@ static void read_inplace_writes_cache(int bank, int phys_segment)
801} 801}
802 802
803 803
804int nand_read_sectors(IF_MD(int drive,) unsigned long start, int incount, 804int nand_read_sectors(IF_MD(int drive,) sector_t start, int incount,
805 void* inbuf) 805 void* inbuf)
806{ 806{
807#ifdef HAVE_MULTIDRIVE 807#ifdef HAVE_MULTIDRIVE
@@ -809,15 +809,15 @@ int nand_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
809#endif 809#endif
810 810
811 int ret = 0; 811 int ret = 0;
812 812
813 mutex_lock(&ata_mtx); 813 mutex_lock(&ata_mtx);
814 814
815 led(true); 815 led(true);
816 816
817 while (incount > 0) 817 while (incount > 0)
818 { 818 {
819 int done = 0; 819 int done = 0;
820 int segment = start / sectors_per_segment; 820 sector_t segment = start / sectors_per_segment;
821 int secmod = start % sectors_per_segment; 821 int secmod = start % sectors_per_segment;
822 822
823 while (incount > 0 && secmod < sectors_per_segment) 823 while (incount > 0 && secmod < sectors_per_segment)
@@ -839,7 +839,7 @@ int nand_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
839 secmod++; 839 secmod++;
840 done++; 840 done++;
841 } 841 }
842 842
843 if (done < 0) 843 if (done < 0)
844 { 844 {
845 ret = -1; 845 ret = -1;
@@ -852,11 +852,11 @@ nand_read_error:
852 852
853 mutex_unlock(&ata_mtx); 853 mutex_unlock(&ata_mtx);
854 led(false); 854 led(false);
855 855
856 return ret; 856 return ret;
857} 857}
858 858
859int nand_write_sectors(IF_MD(int drive,) unsigned long start, int count, 859int nand_write_sectors(IF_MD(int drive,) sector_t start, int count,
860 const void* outbuf) 860 const void* outbuf)
861{ 861{
862#ifdef HAVE_MULTIDRIVE 862#ifdef HAVE_MULTIDRIVE
@@ -903,7 +903,7 @@ int nand_init(void)
903 unsigned char spare_buf[16]; 903 unsigned char spare_buf[16];
904 904
905 if (initialized) return 0; 905 if (initialized) return 0;
906 906
907 mutex_init(&ata_mtx); 907 mutex_init(&ata_mtx);
908 908
909 /* Set GPIO direction for chip select & write protect */ 909 /* Set GPIO direction for chip select & write protect */
@@ -924,7 +924,7 @@ int nand_init(void)
924 924
925 memset(lpt_lookup, 0xff, lptbuf_size); 925 memset(lpt_lookup, 0xff, lptbuf_size);
926 memset(write_caches, 0xff, sizeof(write_caches)); 926 memset(write_caches, 0xff, sizeof(write_caches));
927 927
928 write_caches_in_use = 0; 928 write_caches_in_use = 0;
929 929
930 /* Scan banks to build up block translation table */ 930 /* Scan banks to build up block translation table */
@@ -936,7 +936,7 @@ int nand_init(void)
936 nand_read_raw(bank, phys_segment_to_page_addr(phys_segment, 0), 936 nand_read_raw(bank, phys_segment_to_page_addr(phys_segment, 0),
937 SECTOR_SIZE, /* offset */ 937 SECTOR_SIZE, /* offset */
938 16, spare_buf); 938 16, spare_buf);
939 939
940 int type = get_sector_type(spare_buf); 940 int type = get_sector_type(spare_buf);
941 941
942#ifdef FTL_V2 942#ifdef FTL_V2
@@ -948,7 +948,7 @@ int nand_init(void)
948 nand_read_raw(bank, phys_segment_to_page_addr 948 nand_read_raw(bank, phys_segment_to_page_addr
949 (phys_segment, pages_per_segment - 1), 949 (phys_segment, pages_per_segment - 1),
950 SECTOR_SIZE, 16, spare_buf); 950 SECTOR_SIZE, 16, spare_buf);
951 951
952 if (get_sector_type(spare_buf) != 0xff) 952 if (get_sector_type(spare_buf) != 0xff)
953 { 953 {
954 type = SECTYPE_MAIN_DATA; 954 type = SECTYPE_MAIN_DATA;
@@ -982,14 +982,14 @@ int nand_init(void)
982 } 982 }
983 break; 983 break;
984 } 984 }
985 985
986 case SECTYPE_MAIN_RANDOM_CACHE: 986 case SECTYPE_MAIN_RANDOM_CACHE:
987 { 987 {
988 /* Newly-written random page data (Main data area) */ 988 /* Newly-written random page data (Main data area) */
989 read_random_writes_cache(bank, phys_segment); 989 read_random_writes_cache(bank, phys_segment);
990 break; 990 break;
991 } 991 }
992 992
993 case SECTYPE_MAIN_INPLACE_CACHE: 993 case SECTYPE_MAIN_INPLACE_CACHE:
994 { 994 {
995 /* Newly-written sequential page data (Main data area) */ 995 /* Newly-written sequential page data (Main data area) */
@@ -999,7 +999,7 @@ int nand_init(void)
999 } 999 }
1000 } 1000 }
1001 } 1001 }
1002 1002
1003 initialized = true; 1003 initialized = true;
1004 1004
1005 return 0; 1005 return 0;
@@ -1029,7 +1029,7 @@ int nand_num_drives(int first_drive)
1029{ 1029{
1030 /* We don't care which logical drive number we have been assigned */ 1030 /* We don't care which logical drive number we have been assigned */
1031 (void)first_drive; 1031 (void)first_drive;
1032 1032
1033 return 1; 1033 return 1;
1034} 1034}
1035 1035
diff --git a/firmware/target/arm/imx233/nand-imx233.c b/firmware/target/arm/imx233/nand-imx233.c
index a7afba7d43..22da408e05 100644
--- a/firmware/target/arm/imx233/nand-imx233.c
+++ b/firmware/target/arm/imx233/nand-imx233.c
@@ -36,13 +36,13 @@ int nand_init(void)
36{ 36{
37 return -1; 37 return -1;
38} 38}
39int nand_read_sectors(IF_MD(int drive,) unsigned long start, int count, 39int nand_read_sectors(IF_MD(int drive,) sector_t start, int count,
40 void* buf) 40 void* buf)
41{ 41{
42 return -1; 42 return -1;
43} 43}
44 44
45int nand_write_sectors(IF_MD(int drive,) unsigned long start, int count, 45int nand_write_sectors(IF_MD(int drive,) sector_t start, int count,
46 const void* buf) 46 const void* buf)
47{ 47{
48 return -1; 48 return -1;
diff --git a/firmware/target/arm/imx233/partitions-imx233.c b/firmware/target/arm/imx233/partitions-imx233.c
index 83a0bf8b42..69d0ba4199 100644
--- a/firmware/target/arm/imx233/partitions-imx233.c
+++ b/firmware/target/arm/imx233/partitions-imx233.c
@@ -71,7 +71,7 @@ static const char *creative_part_name(enum imx233_part_t part)
71} 71}
72 72
73static int compute_window_creative(intptr_t user, part_read_fn_t read_fn, 73static int compute_window_creative(intptr_t user, part_read_fn_t read_fn,
74 enum imx233_part_t part, unsigned *start, unsigned *end) 74 enum imx233_part_t part, sector_t *start, sector_t *end)
75{ 75{
76 uint8_t mblk[512]; 76 uint8_t mblk[512];
77 int ret = read_fn(user, MBLK_ADDR / 512, 1, mblk); 77 int ret = read_fn(user, MBLK_ADDR / 512, 1, mblk);
@@ -99,7 +99,7 @@ static int compute_window_creative(intptr_t user, part_read_fn_t read_fn,
99 } 99 }
100 else 100 else
101 *end = *start + ent[i].size * hdr->block_size / 512; 101 *end = *start + ent[i].size * hdr->block_size / 512;
102 102
103 return 0; 103 return 0;
104 } 104 }
105 } 105 }
@@ -109,7 +109,7 @@ static int compute_window_creative(intptr_t user, part_read_fn_t read_fn,
109 109
110#if (IMX233_PARTITIONS & IMX233_FREESCALE) 110#if (IMX233_PARTITIONS & IMX233_FREESCALE)
111static int compute_window_freescale(intptr_t user, part_read_fn_t read_fn, 111static int compute_window_freescale(intptr_t user, part_read_fn_t read_fn,
112 enum imx233_part_t part, unsigned *start, unsigned *end) 112 enum imx233_part_t part, sector_t *start, sector_t *end)
113{ 113{
114 uint8_t mbr[512]; 114 uint8_t mbr[512];
115 int ret = read_fn(user, 0, 1, mbr); 115 int ret = read_fn(user, 0, 1, mbr);
@@ -179,7 +179,7 @@ static int compute_window_freescale(intptr_t user, part_read_fn_t read_fn,
179#endif /* (IMX233_PARTITIONS & IMX233_FREESCALE) */ 179#endif /* (IMX233_PARTITIONS & IMX233_FREESCALE) */
180 180
181int imx233_partitions_compute_window(intptr_t user, part_read_fn_t read_fn, 181int imx233_partitions_compute_window(intptr_t user, part_read_fn_t read_fn,
182 enum imx233_part_t part, unsigned *start, unsigned *end) 182 enum imx233_part_t part, sector_t *start, sector_t *end)
183{ 183{
184 int ret = -1; 184 int ret = -1;
185#if (IMX233_PARTITIONS & IMX233_CREATIVE) 185#if (IMX233_PARTITIONS & IMX233_CREATIVE)
diff --git a/firmware/target/arm/imx233/partitions-imx233.h b/firmware/target/arm/imx233/partitions-imx233.h
index e5378dadbb..edc6c1b2f4 100644
--- a/firmware/target/arm/imx233/partitions-imx233.h
+++ b/firmware/target/arm/imx233/partitions-imx233.h
@@ -45,7 +45,7 @@ enum imx233_part_t
45/** The computation function can be called very early in the boot, at which point 45/** The computation function can be called very early in the boot, at which point
46 * usual storage read/write function may not be available. To workaround this 46 * usual storage read/write function may not be available. To workaround this
47 * issue, one must provide a read function. */ 47 * issue, one must provide a read function. */
48typedef int (*part_read_fn_t)(intptr_t user, unsigned long start, int count, void* buf); 48typedef int (*part_read_fn_t)(intptr_t user, sector_t start, int count, void* buf);
49/* Enable/Disable window computations for internal storage following the 49/* Enable/Disable window computations for internal storage following the
50 * Freescale/Creative convention */ 50 * Freescale/Creative convention */
51void imx233_partitions_enable_window(bool enable); 51void imx233_partitions_enable_window(bool enable);
@@ -55,6 +55,6 @@ bool imx233_partitions_is_window_enabled(void);
55 * for a whole disk, *end should be the size of the disk when the function is 55 * for a whole disk, *end should be the size of the disk when the function is
56 * called */ 56 * called */
57int imx233_partitions_compute_window(intptr_t user, part_read_fn_t read_fn, 57int imx233_partitions_compute_window(intptr_t user, part_read_fn_t read_fn,
58 enum imx233_part_t part, unsigned *start, unsigned *end); 58 enum imx233_part_t part, sector_t *start, sector_t *end);
59 59
60#endif /* __PARTITIONS_IMX233__ */ \ No newline at end of file 60#endif /* __PARTITIONS_IMX233__ */
diff --git a/firmware/target/arm/imx233/sdmmc-imx233.c b/firmware/target/arm/imx233/sdmmc-imx233.c
index af090e8a07..02f59a50f4 100644
--- a/firmware/target/arm/imx233/sdmmc-imx233.c
+++ b/firmware/target/arm/imx233/sdmmc-imx233.c
@@ -203,8 +203,8 @@ struct sdmmc_status_t
203 * the RCA is the 16-bit msb. Be careful that this is not the actuall RCA ! */ 203 * the RCA is the 16-bit msb. Be careful that this is not the actuall RCA ! */
204 204
205/* common */ 205/* common */
206static unsigned window_start[SDMMC_NUM_DRIVES]; 206static sector_t window_start[SDMMC_NUM_DRIVES];
207static unsigned window_end[SDMMC_NUM_DRIVES]; 207static sector_t window_end[SDMMC_NUM_DRIVES];
208static uint8_t aligned_buffer[SDMMC_NUM_DRIVES][512] CACHEALIGN_ATTR; 208static uint8_t aligned_buffer[SDMMC_NUM_DRIVES][512] CACHEALIGN_ATTR;
209static tCardInfo sdmmc_card_info[SDMMC_NUM_DRIVES]; 209static tCardInfo sdmmc_card_info[SDMMC_NUM_DRIVES];
210static struct mutex mutex[SDMMC_NUM_DRIVES]; 210static struct mutex mutex[SDMMC_NUM_DRIVES];
@@ -648,7 +648,7 @@ int mmc_event(long id, intptr_t data)
648#endif /* CONFIG_STORAGE & STORAGE_MMC */ 648#endif /* CONFIG_STORAGE & STORAGE_MMC */
649 649
650/* low-level function, don't call directly! */ 650/* low-level function, don't call directly! */
651static int __xfer_sectors(int drive, unsigned long start, int count, void *buf, bool read) 651static int __xfer_sectors(int drive, sector_t start, int count, void *buf, bool read)
652{ 652{
653 uint32_t resp; 653 uint32_t resp;
654 int ret = 0; 654 int ret = 0;
@@ -660,7 +660,7 @@ static int __xfer_sectors(int drive, unsigned long start, int count, void *buf,
660 need_stop = false; 660 need_stop = false;
661 /* Set bank_start to the correct unit (blocks or bytes). 661 /* Set bank_start to the correct unit (blocks or bytes).
662 * MMC drives use block addressing, SD cards bytes or blocks */ 662 * MMC drives use block addressing, SD cards bytes or blocks */
663 int bank_start = start; 663 sector_t bank_start = start;
664 if(SDMMC_MODE(drive) == SD_MODE && !(SDMMC_INFO(drive).ocr & (1<<30))) /* not SDHC */ 664 if(SDMMC_MODE(drive) == SD_MODE && !(SDMMC_INFO(drive).ocr & (1<<30))) /* not SDHC */
665 bank_start *= SD_BLOCK_SIZE; 665 bank_start *= SD_BLOCK_SIZE;
666 /* issue read/write 666 /* issue read/write
@@ -686,7 +686,7 @@ static int __xfer_sectors(int drive, unsigned long start, int count, void *buf,
686 return ret; 686 return ret;
687} 687}
688 688
689static int transfer_sectors(int drive, unsigned long start, int count, void *buf, bool read) 689static int transfer_sectors(int drive, sector_t start, int count, void *buf, bool read)
690{ 690{
691 int ret = 0; 691 int ret = 0;
692 /* the function doesn't work when count is 0 */ 692 /* the function doesn't work when count is 0 */
@@ -806,7 +806,7 @@ static int transfer_sectors(int drive, unsigned long start, int count, void *buf
806} 806}
807 807
808/* user specifies the sdmmc drive */ 808/* user specifies the sdmmc drive */
809static int part_read_fn(intptr_t user, unsigned long start, int count, void* buf) 809static int part_read_fn(intptr_t user, sector_t start, int count, void* buf)
810{ 810{
811 return transfer_sectors(user, start, count, buf, true); 811 return transfer_sectors(user, start, count, buf, true);
812} 812}
@@ -917,7 +917,7 @@ void sd_enable(bool on)
917 (void) on; 917 (void) on;
918} 918}
919 919
920int sd_read_sectors(IF_MD(int sd_drive,) unsigned long start, int count, void *buf) 920int sd_read_sectors(IF_MD(int sd_drive,) sector_t start, int count, void *buf)
921{ 921{
922#ifndef HAVE_MULTIDRIVE 922#ifndef HAVE_MULTIDRIVE
923 int sd_drive = 0; 923 int sd_drive = 0;
@@ -925,7 +925,7 @@ int sd_read_sectors(IF_MD(int sd_drive,) unsigned long start, int count, void *b
925 return transfer_sectors(sd_map[sd_drive], start, count, buf, true); 925 return transfer_sectors(sd_map[sd_drive], start, count, buf, true);
926} 926}
927 927
928int sd_write_sectors(IF_MD(int sd_drive,) unsigned long start, int count, const void* buf) 928int sd_write_sectors(IF_MD(int sd_drive,) sector_t start, int count, const void* buf)
929{ 929{
930#ifndef HAVE_MULTIDRIVE 930#ifndef HAVE_MULTIDRIVE
931 int sd_drive = 0; 931 int sd_drive = 0;
@@ -1039,7 +1039,7 @@ int mmc_spinup_time(void)
1039 return 0; 1039 return 0;
1040} 1040}
1041 1041
1042int mmc_read_sectors(IF_MD(int mmc_drive,) unsigned long start, int count, void *buf) 1042int mmc_read_sectors(IF_MD(int mmc_drive,) sector_t start, int count, void *buf)
1043{ 1043{
1044#ifndef HAVE_MULTIDRIVE 1044#ifndef HAVE_MULTIDRIVE
1045 int mmc_drive = 0; 1045 int mmc_drive = 0;
@@ -1047,7 +1047,7 @@ int mmc_read_sectors(IF_MD(int mmc_drive,) unsigned long start, int count, void
1047 return transfer_sectors(mmc_map[mmc_drive], start, count, buf, true); 1047 return transfer_sectors(mmc_map[mmc_drive], start, count, buf, true);
1048} 1048}
1049 1049
1050int mmc_write_sectors(IF_MD(int mmc_drive,) unsigned long start, int count, const void* buf) 1050int mmc_write_sectors(IF_MD(int mmc_drive,) sector_t start, int count, const void* buf)
1051{ 1051{
1052#ifndef HAVE_MULTIDRIVE 1052#ifndef HAVE_MULTIDRIVE
1053 int mmc_drive = 0; 1053 int mmc_drive = 0;
diff --git a/firmware/target/arm/pp/ata-pp5020.c b/firmware/target/arm/pp/ata-pp5020.c
index 176e74993c..7351215693 100644
--- a/firmware/target/arm/pp/ata-pp5020.c
+++ b/firmware/target/arm/pp/ata-pp5020.c
@@ -48,8 +48,8 @@ bool ata_is_coldstart()
48 rest are the same. They go in IDE0_PRI_TIMING0. 48 rest are the same. They go in IDE0_PRI_TIMING0.
49 49
50 Rockbox used to use 0x10, and test_disk shows that leads to faster PIO. 50 Rockbox used to use 0x10, and test_disk shows that leads to faster PIO.
51 However on some disks connected with mSATA adapters this causes corrupt data 51 However when used with mSATA and some SD adapters this causes corrupt data
52 so we now just use these timings from the OF. 52 so we now unconditionally use these timings from the OF.
53*/ 53*/
54static const unsigned long pio80mhz[] = { 54static const unsigned long pio80mhz[] = {
55 0xC293, 0x43A2, 0x11A1, 0x7232, 0x3131 55 0xC293, 0x43A2, 0x11A1, 0x7232, 0x3131
@@ -83,10 +83,7 @@ void ata_device_init()
83/* Setup the timing for PIO mode */ 83/* Setup the timing for PIO mode */
84void ata_set_pio_timings(int mode) 84void ata_set_pio_timings(int mode)
85{ 85{
86 if (ata_disk_isssd()) 86 IDE0_PRI_TIMING0 = pio80mhz[mode];
87 IDE0_PRI_TIMING0 = pio80mhz[mode];
88 else
89 IDE0_PRI_TIMING0 = 0x10;
90} 87}
91 88
92#ifdef HAVE_ATA_DMA 89#ifdef HAVE_ATA_DMA
@@ -109,6 +106,8 @@ static bool dma_boosted = false;
109static bool dma_needs_boost; 106static bool dma_needs_boost;
110#endif 107#endif
111 108
109static int ata_is_ssd = 0;
110
112/* This function sets up registers for 80 Mhz. 111/* This function sets up registers for 80 Mhz.
113 Ultra DMA mode 2 works at 30 Mhz. 112 Ultra DMA mode 2 works at 30 Mhz.
114 */ 113 */
@@ -136,6 +135,8 @@ void ata_dma_set_mode(unsigned char mode) {
136#if !defined(IPOD_NANO) 135#if !defined(IPOD_NANO)
137 IDE0_CFG |= 0x20000000; /* >= 50 Mhz */ 136 IDE0_CFG |= 0x20000000; /* >= 50 Mhz */
138#endif 137#endif
138
139 ata_is_ssd = ata_disk_isssd();
139} 140}
140 141
141#define IDE_CFG_INTRQ 8 142#define IDE_CFG_INTRQ 8
@@ -175,11 +176,12 @@ bool ata_dma_setup(void *addr, unsigned long bytes, bool write) {
175 /* Writes only need to be word-aligned, but by default DMA 176 /* Writes only need to be word-aligned, but by default DMA
176 * is not used for writing on non-SSDs as it appears to be slower. 177 * is not used for writing on non-SSDs as it appears to be slower.
177 */ 178 */
178 if (!ata_disk_isssd()) 179 if (write) {
179 return false; 180 if ((unsigned long)addr & 3)
180 181 return false;
181 if (write && ((unsigned long)addr & 3)) 182 if (!ata_is_ssd)
182 return false; 183 return false;
184 }
183 185
184#if ATA_MAX_UDMA > 2 186#if ATA_MAX_UDMA > 2
185 if (dma_needs_boost && !dma_boosted) { 187 if (dma_needs_boost && !dma_boosted) {
diff --git a/firmware/target/arm/pp/ata-sd-pp.c b/firmware/target/arm/pp/ata-sd-pp.c
index fb0a9e150e..b998afd21e 100644
--- a/firmware/target/arm/pp/ata-sd-pp.c
+++ b/firmware/target/arm/pp/ata-sd-pp.c
@@ -82,7 +82,7 @@
82#define STAT_TIME_OUT_RES (1 << 1) 82#define STAT_TIME_OUT_RES (1 << 1)
83#define STAT_TIME_OUT_READ (1) 83#define STAT_TIME_OUT_READ (1)
84#define STAT_ERROR_BITS (0x3f) 84#define STAT_ERROR_BITS (0x3f)
85 85
86/* MMC_CMDAT bits */ 86/* MMC_CMDAT bits */
87/* Some of the bits used by the OF don't make much sense with these */ 87/* Some of the bits used by the OF don't make much sense with these */
88/* definitions. So they're probably different between PXA and PP502x */ 88/* definitions. So they're probably different between PXA and PP502x */
@@ -101,7 +101,7 @@
101#define CMDAT_RES_TYPE3 (3) 101#define CMDAT_RES_TYPE3 (3)
102#define CMDAT_RES_TYPE2 (2) 102#define CMDAT_RES_TYPE2 (2)
103#define CMDAT_RES_TYPE1 (1) 103#define CMDAT_RES_TYPE1 (1)
104 104
105/* MMC_I_MASK bits */ 105/* MMC_I_MASK bits */
106/* PP502x apparently only has bits 0-3 */ 106/* PP502x apparently only has bits 0-3 */
107#define I_MASK_SDIO_SUSPEND_ACK (1 << 12) 107#define I_MASK_SDIO_SUSPEND_ACK (1 << 12)
@@ -499,18 +499,18 @@ static inline void copy_write_sectors(const unsigned char** buf)
499 { 499 {
500 asm volatile ( 500 asm volatile (
501 "ldmia %[buf]!, { r3, r5, r7, r9 } \r\n" 501 "ldmia %[buf]!, { r3, r5, r7, r9 } \r\n"
502 "mov r4, r3, lsr #16 \r\n" 502 "mov r4, r3, lsr #16 \r\n"
503 "mov r6, r5, lsr #16 \r\n" 503 "mov r6, r5, lsr #16 \r\n"
504 "mov r8, r7, lsr #16 \r\n" 504 "mov r8, r7, lsr #16 \r\n"
505 "mov r10, r9, lsr #16 \r\n" 505 "mov r10, r9, lsr #16 \r\n"
506 "stmia %[data], { r3-r10 } \r\n" 506 "stmia %[data], { r3-r10 } \r\n"
507 "ldmia %[buf]!, { r3, r5, r7, r9 } \r\n" 507 "ldmia %[buf]!, { r3, r5, r7, r9 } \r\n"
508 "mov r4, r3, lsr #16 \r\n" 508 "mov r4, r3, lsr #16 \r\n"
509 "mov r6, r5, lsr #16 \r\n" 509 "mov r6, r5, lsr #16 \r\n"
510 "mov r8, r7, lsr #16 \r\n" 510 "mov r8, r7, lsr #16 \r\n"
511 "mov %[t], r9, lsr #16 \r\n" 511 "mov %[t], r9, lsr #16 \r\n"
512 "stmia %[data], { r3-r9 } \r\n" 512 "stmia %[data], { r3-r9 } \r\n"
513 : [buf]"+&r"(*buf), [t]"=&r"(t) 513 : [buf]"+&r"(*buf), [t]"=&r"(t)
514 : [data]"r"(&MMC_DATA_FIFO) 514 : [data]"r"(&MMC_DATA_FIFO)
515 : "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10" 515 : "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10"
516 ); 516 );
@@ -760,7 +760,7 @@ static void sd_init_device(int card_no)
760 currcard->csd[i] = temp_reg[3-i]; 760 currcard->csd[i] = temp_reg[3-i];
761 761
762 sd_parse_csd(currcard); 762 sd_parse_csd(currcard);
763 763
764 MMC_CLKRT = 0; /* switch to highest clock rate */ 764 MMC_CLKRT = 0; /* switch to highest clock rate */
765 765
766 ret = sd_command(SD_SELECT_CARD, currcard->rca, NULL, 766 ret = sd_command(SD_SELECT_CARD, currcard->rca, NULL,
@@ -849,7 +849,7 @@ static void sd_select_device(int card_no)
849 849
850/* API Functions */ 850/* API Functions */
851 851
852int sd_read_sectors(IF_MD(int drive,) unsigned long start, int incount, 852int sd_read_sectors(IF_MD(int drive,) sector_t start, int incount,
853 void* inbuf) 853 void* inbuf)
854{ 854{
855#ifndef HAVE_MULTIDRIVE 855#ifndef HAVE_MULTIDRIVE
@@ -857,8 +857,8 @@ int sd_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
857#endif 857#endif
858 int ret; 858 int ret;
859 unsigned char *buf, *buf_end; 859 unsigned char *buf, *buf_end;
860 unsigned int bank; 860 sector_t bank;
861 861
862 /* TODO: Add DMA support. */ 862 /* TODO: Add DMA support. */
863 863
864 mutex_lock(&sd_mtx); 864 mutex_lock(&sd_mtx);
@@ -894,7 +894,7 @@ sd_read_retry:
894 if (ret < 0) 894 if (ret < 0)
895 goto sd_read_error; 895 goto sd_read_error;
896 } 896 }
897 897
898 start -= bank * BLOCKS_PER_BANK; 898 start -= bank * BLOCKS_PER_BANK;
899 } 899 }
900 900
@@ -904,6 +904,8 @@ sd_read_retry:
904 904
905 MMC_NUMBLK = incount; 905 MMC_NUMBLK = incount;
906 906
907 // XXX 64-bit addresses..
908
907#ifdef HAVE_HOTSWAP 909#ifdef HAVE_HOTSWAP
908 if(currcard->ocr & (1<<30) ) 910 if(currcard->ocr & (1<<30) )
909 { 911 {
@@ -966,7 +968,7 @@ sd_read_error:
966 } 968 }
967} 969}
968 970
969int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count, 971int sd_write_sectors(IF_MD(int drive,) sector_t start, int count,
970 const void* outbuf) 972 const void* outbuf)
971{ 973{
972/* Write support is not finished yet */ 974/* Write support is not finished yet */
@@ -1010,7 +1012,7 @@ sd_write_retry:
1010 if (ret < 0) 1012 if (ret < 0)
1011 goto sd_write_error; 1013 goto sd_write_error;
1012 } 1014 }
1013 1015
1014 start -= bank * BLOCKS_PER_BANK; 1016 start -= bank * BLOCKS_PER_BANK;
1015 } 1017 }
1016 1018
@@ -1250,7 +1252,7 @@ int sd_num_drives(int first_drive)
1250#else 1252#else
1251 (void)first_drive; 1253 (void)first_drive;
1252#endif 1254#endif
1253 1255
1254#ifdef HAVE_MULTIDRIVE 1256#ifdef HAVE_MULTIDRIVE
1255 return 2; 1257 return 2;
1256#else 1258#else
diff --git a/firmware/target/arm/rk27xx/ata-nand-rk27xx.c b/firmware/target/arm/rk27xx/ata-nand-rk27xx.c
index e257416cd0..54a1223cfc 100644
--- a/firmware/target/arm/rk27xx/ata-nand-rk27xx.c
+++ b/firmware/target/arm/rk27xx/ata-nand-rk27xx.c
@@ -31,18 +31,18 @@
31 31
32/* This file provides only STUBS for now */ 32/* This file provides only STUBS for now */
33 33
34/** static, private data **/ 34/** static, private data **/
35static bool initialized = false; 35static bool initialized = false;
36 36
37/* API Functions */ 37/* API Functions */
38int nand_read_sectors(IF_MD(int drive,) unsigned long start, int incount, 38int nand_read_sectors(IF_MD(int drive,) sector_t start, int incount,
39 void* inbuf) 39 void* inbuf)
40{ 40{
41 (void)drive; 41 (void)drive;
42 return ftl_read(start, incount, inbuf); 42 return ftl_read(start, incount, inbuf);
43} 43}
44 44
45int nand_write_sectors(IF_MD(int drive,) unsigned long start, int count, 45int nand_write_sectors(IF_MD(int drive,) sector_t start, int count,
46 const void* outbuf) 46 const void* outbuf)
47{ 47{
48 (void)drive; 48 (void)drive;
@@ -112,7 +112,7 @@ int nand_num_drives(int first_drive)
112{ 112{
113 /* We don't care which logical drive number(s) we have been assigned */ 113 /* We don't care which logical drive number(s) we have been assigned */
114 (void)first_drive; 114 (void)first_drive;
115 115
116 return 1; 116 return 1;
117} 117}
118#endif 118#endif
diff --git a/firmware/target/arm/rk27xx/sd-rk27xx.c b/firmware/target/arm/rk27xx/sd-rk27xx.c
index 2ddf91a67e..e082a8bf2e 100644
--- a/firmware/target/arm/rk27xx/sd-rk27xx.c
+++ b/firmware/target/arm/rk27xx/sd-rk27xx.c
@@ -35,7 +35,7 @@
35#include "panic.h" 35#include "panic.h"
36#include "stdbool.h" 36#include "stdbool.h"
37#include "storage.h" 37#include "storage.h"
38 38#include "timeout.h"
39#include "lcd.h" 39#include "lcd.h"
40#include <stdarg.h> 40#include <stdarg.h>
41#include "sysfont.h" 41#include "sysfont.h"
@@ -453,7 +453,7 @@ static inline void write_sd_data(unsigned char **src)
453 *src += 512; 453 *src += 512;
454} 454}
455 455
456int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count, 456int sd_read_sectors(IF_MD(int drive,) sector_t start, int count,
457 void* buf) 457 void* buf)
458{ 458{
459#ifdef HAVE_MULTIDRIVE 459#ifdef HAVE_MULTIDRIVE
@@ -498,6 +498,8 @@ int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count,
498 DATA_XFER_MULTI; 498 DATA_XFER_MULTI;
499 } 499 }
500 500
501 // XXX 64-bit
502
501 /* issue read command to the card */ 503 /* issue read command to the card */
502 if (!send_cmd(SD_READ_MULTIPLE_BLOCK, start, RES_R1, &response)) 504 if (!send_cmd(SD_READ_MULTIPLE_BLOCK, start, RES_R1, &response))
503 { 505 {
@@ -576,7 +578,7 @@ int sd_read_sectors(IF_MD(int drive,) unsigned long start, int count,
576} 578}
577 579
578/* Not tested */ 580/* Not tested */
579int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count, 581int sd_write_sectors(IF_MD(int drive,) sector_t start, int count,
580 const void* buf) 582 const void* buf)
581{ 583{
582#ifdef HAVE_MULTIDRIVE 584#ifdef HAVE_MULTIDRIVE
@@ -620,6 +622,7 @@ int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count,
620 622
621 write_sd_data(&src); /* put data into transfer buffer */ 623 write_sd_data(&src); /* put data into transfer buffer */
622 624
625 // XXX 64-bit
623 if (!send_cmd(SD_WRITE_MULTIPLE_BLOCK, start, RES_R1, &response)) 626 if (!send_cmd(SD_WRITE_MULTIPLE_BLOCK, start, RES_R1, &response))
624 { 627 {
625 ret = -3; 628 ret = -3;
diff --git a/firmware/target/arm/s3c2440/sd-s3c2440.c b/firmware/target/arm/s3c2440/sd-s3c2440.c
index 2ff68aa4ee..82fd60c711 100644
--- a/firmware/target/arm/s3c2440/sd-s3c2440.c
+++ b/firmware/target/arm/s3c2440/sd-s3c2440.c
@@ -18,7 +18,7 @@
18 * KIND, either express or implied. 18 * KIND, either express or implied.
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22//#define SD_DEBUG 22//#define SD_DEBUG
23 23
24#include "system.h" 24#include "system.h"
@@ -33,7 +33,7 @@
33#include "sdmmc.h" 33#include "sdmmc.h"
34#endif 34#endif
35#include "storage.h" 35#include "storage.h"
36#include "dma-target.h" 36#include "dma-target.h"
37#include "system-target.h" 37#include "system-target.h"
38#include "led-mini2440.h" 38#include "led-mini2440.h"
39 39
@@ -83,7 +83,7 @@ struct sd_card_status
83 int retry_max; 83 int retry_max;
84}; 84};
85 85
86/** static, private data **/ 86/** static, private data **/
87 87
88/* for compatibility */ 88/* for compatibility */
89static long last_disk_activity = -1; 89static long last_disk_activity = -1;
@@ -117,13 +117,13 @@ static struct mutex sd_mtx SHAREDBSS_ATTR;
117static struct semaphore transfer_completion_signal; 117static struct semaphore transfer_completion_signal;
118static volatile unsigned int transfer_error[NUM_DRIVES]; 118static volatile unsigned int transfer_error[NUM_DRIVES];
119/* align on cache line size */ 119/* align on cache line size */
120static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS * SD_BLOCK_SIZE] 120static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS * SD_BLOCK_SIZE]
121 __attribute__((aligned(32))); 121 __attribute__((aligned(32)));
122static unsigned char * uncached_buffer; 122static unsigned char * uncached_buffer;
123 123
124static inline void mci_delay(void) 124static inline void mci_delay(void)
125{ 125{
126 int i = 0xffff; 126 int i = 0xffff;
127 while (i--) 127 while (i--)
128 asm volatile ("nop\n"); 128 asm volatile ("nop\n");
129} 129}
@@ -146,7 +146,7 @@ static void get_regs (unsigned *regs)
146{ 146{
147 unsigned j; 147 unsigned j;
148 volatile unsigned long *sdi_reg = &SDICON; 148 volatile unsigned long *sdi_reg = &SDICON;
149 149
150 for (j=0; j < 16;j++) 150 for (j=0; j < 16;j++)
151 { 151 {
152 *regs++ = *sdi_reg++; 152 *regs++ = *sdi_reg++;
@@ -158,7 +158,7 @@ static void dump_regs (unsigned *regs1, unsigned *regs2)
158 unsigned j; 158 unsigned j;
159 volatile unsigned long*sdi_reg = &SDICON; 159 volatile unsigned long*sdi_reg = &SDICON;
160 unsigned long diff; 160 unsigned long diff;
161 161
162 for (j=0; j < 16;j++) 162 for (j=0; j < 16;j++)
163 { 163 {
164 diff = *regs1 ^ *regs2; 164 diff = *regs1 ^ *regs2;
@@ -174,23 +174,23 @@ static void dump_regs (unsigned *regs1, unsigned *regs2)
174static void debug_r1(int cmd) 174static void debug_r1(int cmd)
175{ 175{
176#if defined(SD_DEBUG) 176#if defined(SD_DEBUG)
177 dbgprintf("CMD%2.2d:SDICSTA=%04x [%c%c%c%c%c-%c%c%c%c%c%c%c] SDIRSP0=%08x [%d %s] \n", 177 dbgprintf("CMD%2.2d:SDICSTA=%04x [%c%c%c%c%c-%c%c%c%c%c%c%c] SDIRSP0=%08x [%d %s] \n",
178 cmd, 178 cmd,
179 SDICSTA, 179 SDICSTA,
180 (SDICSTA & S3C2410_SDICMDSTAT_CRCFAIL) ? 'C' : ' ', 180 (SDICSTA & S3C2410_SDICMDSTAT_CRCFAIL) ? 'C' : ' ',
181 (SDICSTA & S3C2410_SDICMDSTAT_CMDSENT) ? 'S' : ' ', 181 (SDICSTA & S3C2410_SDICMDSTAT_CMDSENT) ? 'S' : ' ',
182 (SDICSTA & S3C2410_SDICMDSTAT_CMDTIMEOUT) ? 'T' : ' ', 182 (SDICSTA & S3C2410_SDICMDSTAT_CMDTIMEOUT) ? 'T' : ' ',
183 (SDICSTA & S3C2410_SDICMDSTAT_RSPFIN) ? 'R' : ' ', 183 (SDICSTA & S3C2410_SDICMDSTAT_RSPFIN) ? 'R' : ' ',
184 (SDICSTA & S3C2410_SDICMDSTAT_XFERING) ? 'X' : ' ', 184 (SDICSTA & S3C2410_SDICMDSTAT_XFERING) ? 'X' : ' ',
185 185
186 (SDICSTA & 0x40) ? 'P' : ' ', 186 (SDICSTA & 0x40) ? 'P' : ' ',
187 (SDICSTA & 0x20) ? 'A' : ' ', 187 (SDICSTA & 0x20) ? 'A' : ' ',
188 (SDICSTA & 0x10) ? 'E' : ' ', 188 (SDICSTA & 0x10) ? 'E' : ' ',
189 (SDICSTA & 0x08) ? 'C' : ' ', 189 (SDICSTA & 0x08) ? 'C' : ' ',
190 (SDICSTA & 0x04) ? 'I' : ' ', 190 (SDICSTA & 0x04) ? 'I' : ' ',
191 (SDICSTA & 0x02) ? 'R' : ' ', 191 (SDICSTA & 0x02) ? 'R' : ' ',
192 (SDICSTA & 0x01) ? 'Z' : ' ', 192 (SDICSTA & 0x01) ? 'Z' : ' ',
193 193
194 SDIRSP0, 194 SDIRSP0,
195 SD_R1_CURRENT_STATE(SDIRSP0), 195 SD_R1_CURRENT_STATE(SDIRSP0),
196 (SDIRSP0 & SD_R1_READY_FOR_DATA) ? "RDY " : " " 196 (SDIRSP0 & SD_R1_READY_FOR_DATA) ? "RDY " : " "
@@ -205,8 +205,8 @@ void SDI (void)
205 int status = SDIDSTA; 205 int status = SDIDSTA;
206#ifndef HAVE_MULTIDRIVE 206#ifndef HAVE_MULTIDRIVE
207 const int curr_card = 0; 207 const int curr_card = 0;
208#endif 208#endif
209 209
210 transfer_error[curr_card] = status 210 transfer_error[curr_card] = status
211#if 0 211#if 0
212 & ( S3C2410_SDIDSTA_CRCFAIL | S3C2410_SDIDSTA_RXCRCFAIL | 212 & ( S3C2410_SDIDSTA_CRCFAIL | S3C2410_SDIDSTA_RXCRCFAIL |
@@ -217,7 +217,7 @@ void SDI (void)
217 SDIDSTA |= S3C2410_SDIDSTA_CLEAR_BITS; /* needed to clear int */ 217 SDIDSTA |= S3C2410_SDIDSTA_CLEAR_BITS; /* needed to clear int */
218 218
219 dbgprintf ("SDI %x\n", transfer_error[curr_card]); 219 dbgprintf ("SDI %x\n", transfer_error[curr_card]);
220 220
221 semaphore_release(&transfer_completion_signal); 221 semaphore_release(&transfer_completion_signal);
222 222
223 /* Ack the interrupt */ 223 /* Ack the interrupt */
@@ -229,13 +229,13 @@ void SDI (void)
229void dma_callback (void) 229void dma_callback (void)
230{ 230{
231 const int status = SDIDSTA; 231 const int status = SDIDSTA;
232 232
233 transfer_error[0] = status & (S3C2410_SDIDSTA_CRCFAIL | 233 transfer_error[0] = status & (S3C2410_SDIDSTA_CRCFAIL |
234 S3C2410_SDIDSTA_RXCRCFAIL | 234 S3C2410_SDIDSTA_RXCRCFAIL |
235 S3C2410_SDIDSTA_DATATIMEOUT ); 235 S3C2410_SDIDSTA_DATATIMEOUT );
236 236
237 SDIDSTA |= S3C2410_SDIDSTA_CLEAR_BITS; /* needed to clear int */ 237 SDIDSTA |= S3C2410_SDIDSTA_CLEAR_BITS; /* needed to clear int */
238 238
239 dbgprintf ("dma_cb\n"); 239 dbgprintf ("dma_cb\n");
240 semaphore_release(&transfer_completion_signal); 240 semaphore_release(&transfer_completion_signal);
241} 241}
@@ -248,14 +248,14 @@ static void init_sdi_controller(const int card_no)
248/*****************************************************************************/ 248/*****************************************************************************/
249#ifdef MINI2440 249#ifdef MINI2440
250 /* Specific to Mini2440 */ 250 /* Specific to Mini2440 */
251 251
252 /* Enable pullups on SDCMD and SDDAT pins */ 252 /* Enable pullups on SDCMD and SDDAT pins */
253 S3C2440_GPIO_PULLUP (GPEUP, 6, GPIO_PULLUP_ENABLE); 253 S3C2440_GPIO_PULLUP (GPEUP, 6, GPIO_PULLUP_ENABLE);
254 S3C2440_GPIO_PULLUP (GPEUP, 7, GPIO_PULLUP_ENABLE); 254 S3C2440_GPIO_PULLUP (GPEUP, 7, GPIO_PULLUP_ENABLE);
255 S3C2440_GPIO_PULLUP (GPEUP, 8, GPIO_PULLUP_ENABLE); 255 S3C2440_GPIO_PULLUP (GPEUP, 8, GPIO_PULLUP_ENABLE);
256 S3C2440_GPIO_PULLUP (GPEUP, 9, GPIO_PULLUP_ENABLE); 256 S3C2440_GPIO_PULLUP (GPEUP, 9, GPIO_PULLUP_ENABLE);
257 S3C2440_GPIO_PULLUP (GPEUP, 10, GPIO_PULLUP_ENABLE); 257 S3C2440_GPIO_PULLUP (GPEUP, 10, GPIO_PULLUP_ENABLE);
258 258
259 /* Enable special function for SDCMD, SDCLK and SDDAT pins */ 259 /* Enable special function for SDCMD, SDCLK and SDDAT pins */
260 S3C2440_GPIO_CONFIG (GPECON, 5, GPIO_FUNCTION); 260 S3C2440_GPIO_CONFIG (GPECON, 5, GPIO_FUNCTION);
261 S3C2440_GPIO_CONFIG (GPECON, 6, GPIO_FUNCTION); 261 S3C2440_GPIO_CONFIG (GPECON, 6, GPIO_FUNCTION);
@@ -263,15 +263,15 @@ static void init_sdi_controller(const int card_no)
263 S3C2440_GPIO_CONFIG (GPECON, 8, GPIO_FUNCTION); 263 S3C2440_GPIO_CONFIG (GPECON, 8, GPIO_FUNCTION);
264 S3C2440_GPIO_CONFIG (GPECON, 9, GPIO_FUNCTION); 264 S3C2440_GPIO_CONFIG (GPECON, 9, GPIO_FUNCTION);
265 S3C2440_GPIO_CONFIG (GPECON, 10, GPIO_FUNCTION); 265 S3C2440_GPIO_CONFIG (GPECON, 10, GPIO_FUNCTION);
266 266
267 /* Card Detect input */ 267 /* Card Detect input */
268 S3C2440_GPIO_CONFIG (GPGCON, 8, GPIO_INPUT); 268 S3C2440_GPIO_CONFIG (GPGCON, 8, GPIO_INPUT);
269 /* enable external irq 8-23 on the internal interrupt controller */ 269 /* enable external irq 8-23 on the internal interrupt controller */
270 INTMSK &= ~1<<5; 270 INTMSK &= ~1<<5;
271 /* enable GPG8 IRQ on the external interrupt controller */ 271 /* enable GPG8 IRQ on the external interrupt controller */
272 EINTMASK &= ~(1<<16); 272 EINTMASK &= ~(1<<16);
273 273
274 274
275 /* Write Protect input */ 275 /* Write Protect input */
276 S3C2440_GPIO_CONFIG (GPHCON, 8, GPIO_INPUT); 276 S3C2440_GPIO_CONFIG (GPHCON, 8, GPIO_INPUT);
277/*****************************************************************************/ 277/*****************************************************************************/
@@ -279,11 +279,11 @@ static void init_sdi_controller(const int card_no)
279#error Unsupported target 279#error Unsupported target
280#endif 280#endif
281/*****************************************************************************/ 281/*****************************************************************************/
282 282
283 /* About 400KHz for initial comms with card */ 283 /* About 400KHz for initial comms with card */
284 SDIPRE = PCLK / INITIAL_CLK - 1; 284 SDIPRE = PCLK / INITIAL_CLK - 1;
285 /* Byte order=Type A (Little Endian), clock enable */ 285 /* Byte order=Type A (Little Endian), clock enable */
286 SDICON = S3C2410_SDICON_CLOCKTYPE; 286 SDICON = S3C2410_SDICON_CLOCKTYPE;
287 SDIFSTA |= S3C2440_SDIFSTA_FIFORESET; 287 SDIFSTA |= S3C2440_SDIFSTA_FIFORESET;
288 SDIBSIZE = SD_BLOCK_SIZE; 288 SDIBSIZE = SD_BLOCK_SIZE;
289 SDIDTIMER= 0x7fffff; /* Set timeout count - max value */ 289 SDIDTIMER= 0x7fffff; /* Set timeout count - max value */
@@ -297,11 +297,11 @@ static void init_sdi_controller(const int card_no)
297 /* Enable interrupt in controller */ 297 /* Enable interrupt in controller */
298 bitclr32(&INTMOD, SDI_MASK); 298 bitclr32(&INTMOD, SDI_MASK);
299 bitclr32(&INTMSK, SDI_MASK); 299 bitclr32(&INTMSK, SDI_MASK);
300 300
301 SDIIMSK |= S3C2410_SDIIMSK_DATAFINISH 301 SDIIMSK |= S3C2410_SDIIMSK_DATAFINISH
302 | S3C2410_SDIIMSK_DATATIMEOUT 302 | S3C2410_SDIIMSK_DATATIMEOUT
303 | S3C2410_SDIIMSK_DATACRC 303 | S3C2410_SDIIMSK_DATACRC
304 | S3C2410_SDIIMSK_CRCSTATUS 304 | S3C2410_SDIIMSK_CRCSTATUS
305 | S3C2410_SDIIMSK_FIFOFAIL 305 | S3C2410_SDIIMSK_FIFOFAIL
306 ; 306 ;
307#endif 307#endif
@@ -325,18 +325,18 @@ static bool send_cmd(const int card_no, const int cmd, const int arg,
325 get_regs (reg_copy2); 325 get_regs (reg_copy2);
326 dump_regs (reg_copy, reg_copy2); 326 dump_regs (reg_copy, reg_copy2);
327#endif 327#endif
328 328
329#if 0 329#if 0
330 while (SDICSTA & S3C2410_SDICMDSTAT_XFERING) 330 while (SDICSTA & S3C2410_SDICMDSTAT_XFERING)
331 ; /* wait ?? */ 331 ; /* wait ?? */
332#endif 332#endif
333 /* set up new command */ 333 /* set up new command */
334 334
335 if (flags & MCI_ARG) 335 if (flags & MCI_ARG)
336 SDICARG = arg; 336 SDICARG = arg;
337 else 337 else
338 SDICARG = 0; 338 SDICARG = 0;
339 339
340 val = cmd | S3C2410_SDICMDCON_CMDSTART | S3C2410_SDICMDCON_SENDERHOST; 340 val = cmd | S3C2410_SDICMDCON_CMDSTART | S3C2410_SDICMDCON_SENDERHOST;
341 if(flags & MCI_RESP) 341 if(flags & MCI_RESP)
342 { 342 {
@@ -344,27 +344,27 @@ static bool send_cmd(const int card_no, const int cmd, const int arg,
344 if(flags & MCI_LONG_RESP) 344 if(flags & MCI_LONG_RESP)
345 val |= S3C2410_SDICMDCON_LONGRSP; 345 val |= S3C2410_SDICMDCON_LONGRSP;
346 } 346 }
347 347
348 /* Clear command/data status flags */ 348 /* Clear command/data status flags */
349 SDICSTA |= 0x0f << 9; 349 SDICSTA |= 0x0f << 9;
350 SDIDSTA |= S3C2410_SDIDSTA_CLEAR_BITS; 350 SDIDSTA |= S3C2410_SDIDSTA_CLEAR_BITS;
351 351
352 /* Initiate the command */ 352 /* Initiate the command */
353 SDICCON = val; 353 SDICCON = val;
354 354
355 if (flags & MCI_RESP) 355 if (flags & MCI_RESP)
356 { 356 {
357 /* wait for response or timeout */ 357 /* wait for response or timeout */
358 do 358 do
359 { 359 {
360 status = SDICSTA; 360 status = SDICSTA;
361 } while ( (status & (S3C2410_SDICMDSTAT_RSPFIN | 361 } while ( (status & (S3C2410_SDICMDSTAT_RSPFIN |
362 S3C2410_SDICMDSTAT_CMDTIMEOUT) ) == 0); 362 S3C2410_SDICMDSTAT_CMDTIMEOUT) ) == 0);
363 debug_r1(cmd); 363 debug_r1(cmd);
364 if (status & S3C2410_SDICMDSTAT_CMDTIMEOUT) 364 if (status & S3C2410_SDICMDSTAT_CMDTIMEOUT)
365 ret = false; 365 ret = false;
366 else if (status & (S3C2410_SDICMDSTAT_RSPFIN)) 366 else if (status & (S3C2410_SDICMDSTAT_RSPFIN))
367 { 367 {
368 /* resp received */ 368 /* resp received */
369 if(flags & MCI_LONG_RESP) 369 if(flags & MCI_LONG_RESP)
370 { 370 {
@@ -381,10 +381,10 @@ static bool send_cmd(const int card_no, const int cmd, const int arg,
381 else 381 else
382 ret = true; 382 ret = true;
383 } 383 }
384 else 384 else
385 { 385 {
386 /* wait for command completion or timeout */ 386 /* wait for command completion or timeout */
387 do 387 do
388 { 388 {
389 status = SDICSTA; 389 status = SDICSTA;
390 } while ( (status & (S3C2410_SDICMDSTAT_CMDSENT | 390 } while ( (status & (S3C2410_SDICMDSTAT_CMDSENT |
@@ -395,12 +395,12 @@ static bool send_cmd(const int card_no, const int cmd, const int arg,
395 else 395 else
396 ret = true; 396 ret = true;
397 } 397 }
398 398
399 /* Clear Command status flags */ 399 /* Clear Command status flags */
400 SDICSTA |= 0x0f << 9; 400 SDICSTA |= 0x0f << 9;
401 401
402 mci_delay(); 402 mci_delay();
403 403
404 return ret; 404 return ret;
405} 405}
406 406
@@ -558,7 +558,7 @@ bool sd_removable(IF_MD_NONVOID(int card_no))
558 const int card_no = 0; 558 const int card_no = 0;
559#endif 559#endif
560 (void)card_no; 560 (void)card_no;
561 561
562 /* not applicable */ 562 /* not applicable */
563 dbgprintf ("sd_remov"); 563 dbgprintf ("sd_remov");
564 return false; 564 return false;
@@ -596,7 +596,7 @@ static int sd_wait_for_state(const int card_no, unsigned int state)
596 } 596 }
597} 597}
598 598
599static int sd_transfer_sectors(int card_no, unsigned long start, 599static int sd_transfer_sectors(int card_no, sector_t start,
600 int count, void* buf, const bool write) 600 int count, void* buf, const bool write)
601{ 601{
602 int ret = EC_OK; 602 int ret = EC_OK;
@@ -636,7 +636,7 @@ static int sd_transfer_sectors(int card_no, unsigned long start,
636 void *dma_buf; 636 void *dma_buf;
637 const int cmd = 637 const int cmd =
638 write ? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK; 638 write ? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK;
639 unsigned long start_addr = start; 639 sector_t start_addr = start;
640 640
641 dma_buf = aligned_buffer; 641 dma_buf = aligned_buffer;
642 if(transfer > UNALIGNED_NUM_SECTORS) 642 if(transfer > UNALIGNED_NUM_SECTORS)
@@ -650,10 +650,10 @@ static int sd_transfer_sectors(int card_no, unsigned long start,
650 650
651 /* TODO? */ 651 /* TODO? */
652 SDIFSTA = SDIFSTA | S3C2440_SDIFSTA_FIFORESET; 652 SDIFSTA = SDIFSTA | S3C2440_SDIFSTA_FIFORESET;
653 SDIDCON = S3C2440_SDIDCON_DS_WORD | 653 SDIDCON = S3C2440_SDIDCON_DS_WORD |
654 S3C2410_SDIDCON_BLOCKMODE | S3C2410_SDIDCON_WIDEBUS | 654 S3C2410_SDIDCON_BLOCKMODE | S3C2410_SDIDCON_WIDEBUS |
655 S3C2410_SDIDCON_DMAEN | 655 S3C2410_SDIDCON_DMAEN |
656 S3C2440_SDIDCON_DATSTART | 656 S3C2440_SDIDCON_DATSTART |
657 ( transfer << 0); 657 ( transfer << 0);
658 if (write) 658 if (write)
659 SDIDCON |= S3C2410_SDIDCON_TXAFTERRESP | S3C2410_SDIDCON_XFER_TXSTART; 659 SDIDCON |= S3C2410_SDIDCON_TXAFTERRESP | S3C2410_SDIDCON_XFER_TXSTART;
@@ -665,6 +665,7 @@ static int sd_transfer_sectors(int card_no, unsigned long start,
665 INTPND = SDI_MASK; 665 INTPND = SDI_MASK;
666 666
667 /* Initiate read/write command */ 667 /* Initiate read/write command */
668 // XXX 64-bit
668 if(!send_cmd(card_no, cmd, start_addr, MCI_ARG | MCI_RESP, NULL)) 669 if(!send_cmd(card_no, cmd, start_addr, MCI_ARG | MCI_RESP, NULL))
669 { 670 {
670 ret -= 3*20; 671 ret -= 3*20;
@@ -674,32 +675,32 @@ static int sd_transfer_sectors(int card_no, unsigned long start,
674 if(write) 675 if(write)
675 { 676 {
676 request.source_addr = dma_buf; 677 request.source_addr = dma_buf;
677 request.source_control = DISRCC_LOC_AHB | DISRCC_INC_AUTO; 678 request.source_control = DISRCC_LOC_AHB | DISRCC_INC_AUTO;
678 request.dest_addr = &SDIDAT_LLE; 679 request.dest_addr = &SDIDAT_LLE;
679 request.dest_control = DISRCC_LOC_APB | DISRCC_INC_FIXED; 680 request.dest_control = DISRCC_LOC_APB | DISRCC_INC_FIXED;
680 request.count = transfer * SD_BLOCK_SIZE / sizeof(long); 681 request.count = transfer * SD_BLOCK_SIZE / sizeof(long);
681 request.source_map = DMA_SRC_MAP_SDI; 682 request.source_map = DMA_SRC_MAP_SDI;
682 request.control = DCON_DMD_HS | DCON_SYNC_APB | 683 request.control = DCON_DMD_HS | DCON_SYNC_APB |
683 DCON_HW_SEL | 684 DCON_HW_SEL |
684 DCON_NO_RELOAD | DCON_DSZ_WORD; 685 DCON_NO_RELOAD | DCON_DSZ_WORD;
685 request.callback = NULL; 686 request.callback = NULL;
686 687
687 dma_enable_channel(0, &request); 688 dma_enable_channel(0, &request);
688 } 689 }
689 else 690 else
690 { 691 {
691 request.source_addr = &SDIDAT_LLE; 692 request.source_addr = &SDIDAT_LLE;
692 request.source_control = DISRCC_LOC_APB | DISRCC_INC_FIXED; 693 request.source_control = DISRCC_LOC_APB | DISRCC_INC_FIXED;
693 request.dest_addr = dma_buf; 694 request.dest_addr = dma_buf;
694 request.dest_control = DISRCC_LOC_AHB | DISRCC_INC_AUTO; 695 request.dest_control = DISRCC_LOC_AHB | DISRCC_INC_AUTO;
695 request.count = transfer * SD_BLOCK_SIZE / sizeof(long); 696 request.count = transfer * SD_BLOCK_SIZE / sizeof(long);
696 request.source_map = DMA_SRC_MAP_SDI; 697 request.source_map = DMA_SRC_MAP_SDI;
697 request.control = DCON_DMD_HS | DCON_SYNC_APB | 698 request.control = DCON_DMD_HS | DCON_SYNC_APB |
698 DCON_HW_SEL | 699 DCON_HW_SEL |
699 DCON_NO_RELOAD | DCON_DSZ_WORD; 700 DCON_NO_RELOAD | DCON_DSZ_WORD;
700 request.callback = NULL; 701 request.callback = NULL;
701 702
702 dma_enable_channel(0, &request); 703 dma_enable_channel(0, &request);
703 } 704 }
704 705
705#if 0 706#if 0
@@ -716,12 +717,12 @@ static int sd_transfer_sectors(int card_no, unsigned long start,
716#endif 717#endif
717 718
718 semaphore_wait(&transfer_completion_signal, 100 /*TIMEOUT_BLOCK*/); 719 semaphore_wait(&transfer_completion_signal, 100 /*TIMEOUT_BLOCK*/);
719 720
720 /* wait for DMA to finish */ 721 /* wait for DMA to finish */
721 while (DSTAT0 & DSTAT_STAT_BUSY) 722 while (DSTAT0 & DSTAT_STAT_BUSY)
722 ; 723 ;
723 724
724#if 0 725#if 0
725 status = SDIDSTA; 726 status = SDIDSTA;
726 while ((status & (S3C2410_SDIDSTA_DATATIMEOUT|S3C2410_SDIDSTA_XFERFINISH)) == 0) 727 while ((status & (S3C2410_SDIDSTA_DATATIMEOUT|S3C2410_SDIDSTA_XFERFINISH)) == 0)
727 { 728 {
@@ -738,10 +739,10 @@ static int sd_transfer_sectors(int card_no, unsigned long start,
738 count -= transfer; 739 count -= transfer;
739 loops = 0; /* reset errors counter */ 740 loops = 0; /* reset errors counter */
740 } 741 }
741 else 742 else
742 { 743 {
743 dbgprintf ("SD transfer error : 0x%x\n", transfer_error[card_no]); 744 dbgprintf ("SD transfer error : 0x%x\n", transfer_error[card_no]);
744 745
745 if(loops++ > MAX_TRANSFER_ERRORS) 746 if(loops++ > MAX_TRANSFER_ERRORS)
746 { 747 {
747 led_flash(LED1|LED2, LED3|LED4); 748 led_flash(LED1|LED2, LED3|LED4);
@@ -783,11 +784,11 @@ sd_transfer_error:
783 return ret; 784 return ret;
784} 785}
785 786
786int sd_read_sectors(IF_MD(int card_no,) unsigned long start, int incount, 787int sd_read_sectors(IF_MD(int card_no,) sector_t start, int incount,
787 void* inbuf) 788 void* inbuf)
788{ 789{
789 int ret; 790 int ret;
790 791
791#ifdef HAVE_MULTIDRIVE 792#ifdef HAVE_MULTIDRIVE
792 dbgprintf ("sd_read %d %x %d\n", card_no, start, incount); 793 dbgprintf ("sd_read %d %x %d\n", card_no, start, incount);
793#else 794#else
@@ -804,7 +805,7 @@ int sd_read_sectors(IF_MD(int card_no,) unsigned long start, int incount,
804} 805}
805 806
806/*****************************************************************************/ 807/*****************************************************************************/
807int sd_write_sectors(IF_MD(int drive,) unsigned long start, int count, 808int sd_write_sectors(IF_MD(int drive,) sector_t start, int count,
808 const void* outbuf) 809 const void* outbuf)
809{ 810{
810#ifdef BOOTLOADER /* we don't need write support in bootloader */ 811#ifdef BOOTLOADER /* we don't need write support in bootloader */
@@ -835,7 +836,7 @@ void sd_enable(bool on)
835{ 836{
836 dbgprintf ("sd_enable %d\n", on); 837 dbgprintf ("sd_enable %d\n", on);
837 /* TODO: enable/disable SDI clock */ 838 /* TODO: enable/disable SDI clock */
838 839
839 if (sd_enabled == on) 840 if (sd_enabled == on)
840 return; /* nothing to do */ 841 return; /* nothing to do */
841 if (on) 842 if (on)
@@ -847,14 +848,14 @@ void sd_enable(bool on)
847 sd_enabled = false; 848 sd_enabled = false;
848 } 849 }
849} 850}
850 851
851int sd_init(void) 852int sd_init(void)
852{ 853{
853 int ret = EC_OK; 854 int ret = EC_OK;
854 dbgprintf ("\n==============================\n"); 855 dbgprintf ("\n==============================\n");
855 dbgprintf (" sd_init\n"); 856 dbgprintf (" sd_init\n");
856 dbgprintf ("==============================\n"); 857 dbgprintf ("==============================\n");
857 858
858 init_sdi_controller (0); 859 init_sdi_controller (0);
859#ifndef BOOTLOADER 860#ifndef BOOTLOADER
860 sd_enabled = true; 861 sd_enabled = true;
@@ -893,7 +894,7 @@ long sd_last_disk_activity(void)
893} 894}
894 895
895tCardInfo *card_get_info_target(int card_no) 896tCardInfo *card_get_info_target(int card_no)
896{ 897{
897 return &card_info[card_no]; 898 return &card_info[card_no];
898} 899}
899 900
diff --git a/firmware/target/arm/s5l8700/ata-nand-s5l8700.c b/firmware/target/arm/s5l8700/ata-nand-s5l8700.c
index 7f68b82a0d..34a1c46043 100644
--- a/firmware/target/arm/s5l8700/ata-nand-s5l8700.c
+++ b/firmware/target/arm/s5l8700/ata-nand-s5l8700.c
@@ -29,17 +29,17 @@
29#include "ftl-target.h" 29#include "ftl-target.h"
30#include "nand-target.h" 30#include "nand-target.h"
31 31
32/** static, private data **/ 32/** static, private data **/
33static bool initialized = false; 33static bool initialized = false;
34 34
35/* API Functions */ 35/* API Functions */
36int nand_read_sectors(IF_MD(int drive,) unsigned long start, int incount, 36int nand_read_sectors(IF_MD(int drive,) sector_t start, int incount,
37 void* inbuf) 37 void* inbuf)
38{ 38{
39 return ftl_read(start, incount, inbuf); 39 return ftl_read(start, incount, inbuf);
40} 40}
41 41
42int nand_write_sectors(IF_MD(int drive,) unsigned long start, int count, 42int nand_write_sectors(IF_MD(int drive,) sector_t start, int count,
43 const void* outbuf) 43 const void* outbuf)
44{ 44{
45 return ftl_write(start, count, outbuf); 45 return ftl_write(start, count, outbuf);
@@ -106,7 +106,7 @@ int nand_num_drives(int first_drive)
106{ 106{
107 /* We don't care which logical drive number(s) we have been assigned */ 107 /* We don't care which logical drive number(s) we have been assigned */
108 (void)first_drive; 108 (void)first_drive;
109 109
110 return 1; 110 return 1;
111} 111}
112#endif 112#endif
diff --git a/firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c b/firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c
index 7a3be20577..9629b3e30f 100644
--- a/firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c
+++ b/firmware/target/arm/s5l8702/ipod6g/storage_ata-6g.c
@@ -58,10 +58,9 @@
58#define CEATA_DAT_NONBUSY_TIMEOUT 5000000 58#define CEATA_DAT_NONBUSY_TIMEOUT 5000000
59#define CEATA_MMC_RCA 1 59#define CEATA_MMC_RCA 1
60 60
61
62/** static, private data **/ 61/** static, private data **/
63static uint8_t ceata_taskfile[16] STORAGE_ALIGN_ATTR; 62static uint8_t ceata_taskfile[16] STORAGE_ALIGN_ATTR;
64static uint16_t ata_identify_data[0x100] STORAGE_ALIGN_ATTR; 63static uint16_t ata_identify_data[ATA_IDENTIFY_WORDS] STORAGE_ALIGN_ATTR;
65static bool ceata; 64static bool ceata;
66static bool ata_lba48; 65static bool ata_lba48;
67static bool ata_dma; 66static bool ata_dma;
@@ -510,7 +509,7 @@ static int ata_identify(uint16_t* buf)
510 ata_write_cbr(&ATA_PIO_DVR, 0); 509 ata_write_cbr(&ATA_PIO_DVR, 0);
511 ata_write_cbr(&ATA_PIO_CSD, CMD_IDENTIFY); 510 ata_write_cbr(&ATA_PIO_CSD, CMD_IDENTIFY);
512 PASS_RC(ata_wait_for_start_of_transfer(10000000), 1, 1); 511 PASS_RC(ata_wait_for_start_of_transfer(10000000), 1, 1);
513 for (i = 0; i < 0x100; i++) buf[i] = ata_read_cbr(&ATA_PIO_DTR); 512 for (i = 0; i < ATA_IDENTIFY_WORDS; i++) buf[i] = ata_read_cbr(&ATA_PIO_DTR);
514 } 513 }
515 return 0; 514 return 0;
516} 515}
@@ -701,7 +700,7 @@ static int ata_power_up(void)
701 | (((uint64_t)ata_identify_data[103]) << 48); 700 | (((uint64_t)ata_identify_data[103]) << 48);
702 else 701 else
703 ata_total_sectors = ata_identify_data[60] | (((uint32_t)ata_identify_data[61]) << 16); 702 ata_total_sectors = ata_identify_data[60] | (((uint32_t)ata_identify_data[61]) << 16);
704 ata_total_sectors >>= 3; 703 ata_total_sectors >>= 3; /* ie SECTOR_SIZE/512. */
705 ata_powered = true; 704 ata_powered = true;
706 ata_set_active(); 705 ata_set_active();
707 return 0; 706 return 0;
@@ -966,7 +965,7 @@ static int ata_reset(void)
966 return rc; 965 return rc;
967} 966}
968 967
969int ata_read_sectors(IF_MD(int drive,) unsigned long start, int incount, 968int ata_read_sectors(IF_MD(int drive,) sector_t start, int incount,
970 void* inbuf) 969 void* inbuf)
971{ 970{
972 mutex_lock(&ata_mutex); 971 mutex_lock(&ata_mutex);
@@ -975,7 +974,7 @@ int ata_read_sectors(IF_MD(int drive,) unsigned long start, int incount,
975 return rc; 974 return rc;
976} 975}
977 976
978int ata_write_sectors(IF_MD(int drive,) unsigned long start, int count, 977int ata_write_sectors(IF_MD(int drive,) sector_t start, int count,
979 const void* outbuf) 978 const void* outbuf)
980{ 979{
981 mutex_lock(&ata_mutex); 980 mutex_lock(&ata_mutex);
diff --git a/firmware/target/arm/tcc780x/sd-tcc780x.c b/firmware/target/arm/tcc780x/sd-tcc780x.c
index c80c3b746f..3ef8972ee9 100644
--- a/firmware/target/arm/tcc780x/sd-tcc780x.c
+++ b/firmware/target/arm/tcc780x/sd-tcc780x.c
@@ -104,19 +104,19 @@ static bool sd_poll_status(unsigned int trigger, long timeout)
104 return true; 104 return true;
105} 105}
106 106
107static int sd_command(unsigned int cmd, unsigned int arg, 107static int sd_command(unsigned int cmd, unsigned int arg,
108 unsigned long* response, unsigned int resp_type) 108 unsigned long* response, unsigned int resp_type)
109{ 109{
110 int sdi_cmd = cmd; 110 int sdi_cmd = cmd;
111 111
112 sdi_cmd |= (127<<12) | (1<<11); /* max wait time | enable */ 112 sdi_cmd |= (127<<12) | (1<<11); /* max wait time | enable */
113 113
114 if (resp_type) 114 if (resp_type)
115 { 115 {
116 /* response type & response required flag */ 116 /* response type & response required flag */
117 sdi_cmd |= (resp_type<<7) | (1<<6); 117 sdi_cmd |= (resp_type<<7) | (1<<6);
118 } 118 }
119 119
120 if (cmd == SD_READ_SINGLE_BLOCK || 120 if (cmd == SD_READ_SINGLE_BLOCK ||
121 cmd == SD_READ_MULTIPLE_BLOCK || 121 cmd == SD_READ_MULTIPLE_BLOCK ||
122 cmd == SD_WRITE_BLOCK || 122 cmd == SD_WRITE_BLOCK ||
@@ -124,18 +124,18 @@ static int sd_command(unsigned int cmd, unsigned int arg,
124 { 124 {
125 sdi_cmd |= (1<<10); /* request data transfer */ 125 sdi_cmd |= (1<<10); /* request data transfer */
126 } 126 }
127 127
128 if (!sd_poll_status(SDISTATUS_CMD_PATH_RDY, 100000)) 128 if (!sd_poll_status(SDISTATUS_CMD_PATH_RDY, 100000))
129 return -EC_COMMAND; 129 return -EC_COMMAND;
130 130
131 SDIARGU = arg; 131 SDIARGU = arg;
132 SDICMD = sdi_cmd; 132 SDICMD = sdi_cmd;
133 133
134 udelay(10); 134 udelay(10);
135 135
136 if (response == NULL) 136 if (response == NULL)
137 return 0; 137 return 0;
138 138
139 if (!sd_poll_status(SDISTATUS_RESP_RCVD, 100000)) 139 if (!sd_poll_status(SDISTATUS_RESP_RCVD, 100000))
140 return -EC_COMMAND; 140 return -EC_COMMAND;
141 141
@@ -150,7 +150,7 @@ static int sd_command(unsigned int cmd, unsigned int arg,
150 { 150 {
151 response[0] = SDIRSPARGU0; 151 response[0] = SDIRSPARGU0;
152 } 152 }
153 153
154 return 0; 154 return 0;
155} 155}
156 156
@@ -220,7 +220,7 @@ static int sd1_oneshot_callback(struct timeout *tmo)
220void EXT0(void) 220void EXT0(void)
221{ 221{
222 static struct timeout sd1_oneshot; 222 static struct timeout sd1_oneshot;
223 223
224 timeout_register(&sd1_oneshot, sd1_oneshot_callback, (3*HZ/10), 0); 224 timeout_register(&sd1_oneshot, sd1_oneshot_callback, (3*HZ/10), 0);
225} 225}
226 226
@@ -248,7 +248,7 @@ bool sd_removable(IF_MD_NONVOID(int card_no))
248 const int card_no = 0; 248 const int card_no = 0;
249#endif 249#endif
250 (void)card_no; 250 (void)card_no;
251 251
252 return false; 252 return false;
253} 253}
254 254
@@ -259,7 +259,7 @@ static void sd_init_device(int card_no)
259{ 259{
260 int ret; 260 int ret;
261 unsigned long response; 261 unsigned long response;
262 262
263 /* Initialise card data as blank */ 263 /* Initialise card data as blank */
264 memset(currcard, 0, sizeof(*currcard)); 264 memset(currcard, 0, sizeof(*currcard));
265 265
@@ -282,7 +282,7 @@ static void sd_init_device(int card_no)
282#endif 282#endif
283 283
284 ret = sd_command(SD_GO_IDLE_STATE, 0, NULL, SDICMD_RES_TYPE1); 284 ret = sd_command(SD_GO_IDLE_STATE, 0, NULL, SDICMD_RES_TYPE1);
285 285
286 if (ret < 0) 286 if (ret < 0)
287 goto card_init_error; 287 goto card_init_error;
288 288
@@ -290,30 +290,30 @@ static void sd_init_device(int card_no)
290 SDICLK = (1<<12) | 59; 290 SDICLK = (1<<12) | 59;
291 291
292 sd_command(SD_SEND_IF_COND, 0x1aa, &response, SDICMD_RES_TYPE3); 292 sd_command(SD_SEND_IF_COND, 0x1aa, &response, SDICMD_RES_TYPE3);
293 293
294 if (!sd_poll_status(SDISTATUS_CMD_PATH_RDY, 100000)) 294 if (!sd_poll_status(SDISTATUS_CMD_PATH_RDY, 100000))
295 goto card_init_error; 295 goto card_init_error;
296 296
297 currcard->ocr = 0; 297 currcard->ocr = 0;
298 298
299 long start_tick = current_tick; 299 long start_tick = current_tick;
300 300
301 while ((currcard->ocr & (1<<31)) == 0 301 while ((currcard->ocr & (1<<31)) == 0
302 && TIME_BEFORE(current_tick, start_tick + HZ)) 302 && TIME_BEFORE(current_tick, start_tick + HZ))
303 { 303 {
304 udelay(100); 304 udelay(100);
305 sd_command(SD_APP_CMD, 0, NULL, SDICMD_RES_TYPE1); 305 sd_command(SD_APP_CMD, 0, NULL, SDICMD_RES_TYPE1);
306 306
307 int arg = 0x100000 | ((response == 0x1aa) ? (1<<30):0); 307 int arg = 0x100000 | ((response == 0x1aa) ? (1<<30):0);
308 sd_command(SD_APP_OP_COND, arg, &currcard->ocr, SDICMD_RES_TYPE3); 308 sd_command(SD_APP_OP_COND, arg, &currcard->ocr, SDICMD_RES_TYPE3);
309 } 309 }
310 310
311 if ((currcard->ocr & (1<<31)) == 0) 311 if ((currcard->ocr & (1<<31)) == 0)
312 { 312 {
313 ret = -EC_POWER_UP; 313 ret = -EC_POWER_UP;
314 goto card_init_error; 314 goto card_init_error;
315 } 315 }
316 316
317 ret = sd_command 317 ret = sd_command
318 (SD_ALL_SEND_CID, 0, currcard->cid, SDICMD_RES_TYPE2); 318 (SD_ALL_SEND_CID, 0, currcard->cid, SDICMD_RES_TYPE2);
319 319
@@ -322,39 +322,39 @@ static void sd_init_device(int card_no)
322 322
323 ret = sd_command 323 ret = sd_command
324 (SD_SEND_RELATIVE_ADDR, 0, &currcard->rca, SDICMD_RES_TYPE1); 324 (SD_SEND_RELATIVE_ADDR, 0, &currcard->rca, SDICMD_RES_TYPE1);
325 325
326 if (ret < 0) 326 if (ret < 0)
327 goto card_init_error; 327 goto card_init_error;
328 328
329 ret = sd_command 329 ret = sd_command
330 (SD_SEND_CSD, currcard->rca, currcard->csd, SDICMD_RES_TYPE2); 330 (SD_SEND_CSD, currcard->rca, currcard->csd, SDICMD_RES_TYPE2);
331 331
332 if (ret < 0) 332 if (ret < 0)
333 goto card_init_error; 333 goto card_init_error;
334 334
335 sd_parse_csd(currcard); 335 sd_parse_csd(currcard);
336 336
337 ret = sd_command 337 ret = sd_command
338 (SD_SELECT_CARD, currcard->rca, NULL, SDICMD_RES_TYPE1); 338 (SD_SELECT_CARD, currcard->rca, NULL, SDICMD_RES_TYPE1);
339 339
340 if (ret < 0) 340 if (ret < 0)
341 goto card_init_error; 341 goto card_init_error;
342 342
343 ret = sd_command 343 ret = sd_command
344 (SD_APP_CMD, currcard->rca, NULL, SDICMD_RES_TYPE1); 344 (SD_APP_CMD, currcard->rca, NULL, SDICMD_RES_TYPE1);
345 345
346 if (ret < 0) 346 if (ret < 0)
347 goto card_init_error; 347 goto card_init_error;
348 348
349 ret = sd_command /* 4 bit */ 349 ret = sd_command /* 4 bit */
350 (SD_SET_BUS_WIDTH, currcard->rca | 2, NULL, SDICMD_RES_TYPE1); 350 (SD_SET_BUS_WIDTH, currcard->rca | 2, NULL, SDICMD_RES_TYPE1);
351 351
352 if (ret < 0) 352 if (ret < 0)
353 goto card_init_error; 353 goto card_init_error;
354 354
355 ret = sd_command 355 ret = sd_command
356 (SD_SET_BLOCKLEN, currcard->blocksize, NULL, SDICMD_RES_TYPE1); 356 (SD_SET_BLOCKLEN, currcard->blocksize, NULL, SDICMD_RES_TYPE1);
357 357
358 if (ret < 0) 358 if (ret < 0)
359 goto card_init_error; 359 goto card_init_error;
360 360
@@ -386,7 +386,7 @@ static void sd_select_device(int card_no)
386 } 386 }
387} 387}
388 388
389int sd_read_sectors(IF_MD(int card_no,) unsigned long start, int incount, 389int sd_read_sectors(IF_MD(int card_no,) sector_t start, int incount,
390 void* inbuf) 390 void* inbuf)
391{ 391{
392#ifndef HAVE_MULTIDRIVE 392#ifndef HAVE_MULTIDRIVE
@@ -416,23 +416,24 @@ sd_read_retry:
416 ret = currcard->initialized; 416 ret = currcard->initialized;
417 goto sd_read_error; 417 goto sd_read_error;
418 } 418 }
419 419
420 last_disk_activity = current_tick; 420 last_disk_activity = current_tick;
421 421
422 ret = sd_wait_for_state(SD_TRAN, EC_TRAN_READ_ENTRY); 422 ret = sd_wait_for_state(SD_TRAN, EC_TRAN_READ_ENTRY);
423 423
424 if (ret < 0) 424 if (ret < 0)
425 goto sd_read_error; 425 goto sd_read_error;
426 426
427 /* Use full SD clock for data transfer (PCK_SDMMC) */ 427 /* Use full SD clock for data transfer (PCK_SDMMC) */
428 SDICLK = (1<<13) | (1<<12); /* bypass divider | enable */ 428 SDICLK = (1<<13) | (1<<12); /* bypass divider | enable */
429 429
430 /* Block count | FIFO count | Block size (2^9) | 4-bit bus */ 430 /* Block count | FIFO count | Block size (2^9) | 4-bit bus */
431 SDIDCTRL = (incount << 13) | (4<<8) | (9<<4) | (1<<2); 431 SDIDCTRL = (incount << 13) | (4<<8) | (9<<4) | (1<<2);
432 SDIDCTRL |= (1<<12); /* nReset */ 432 SDIDCTRL |= (1<<12); /* nReset */
433 433
434 SDIDCTRL2 = (1<<2); /* multi block, read */ 434 SDIDCTRL2 = (1<<2); /* multi block, read */
435 435
436 // XXX 64-bit
436 if (currcard->ocr & (1<<30)) 437 if (currcard->ocr & (1<<30))
437 ret = sd_command(SD_READ_MULTIPLE_BLOCK, start, NULL, SDICMD_RES_TYPE1); 438 ret = sd_command(SD_READ_MULTIPLE_BLOCK, start, NULL, SDICMD_RES_TYPE1);
438 else 439 else
@@ -500,7 +501,7 @@ sd_read_error:
500 } 501 }
501} 502}
502 503
503int sd_write_sectors(IF_MD(int card_no,) unsigned long start, int count, 504int sd_write_sectors(IF_MD(int card_no,) sector_t start, int count,
504 const void* outbuf) 505 const void* outbuf)
505{ 506{
506/* Write support is not finished yet */ 507/* Write support is not finished yet */
@@ -538,21 +539,22 @@ sd_write_retry:
538 ret = currcard->initialized; 539 ret = currcard->initialized;
539 goto sd_write_error; 540 goto sd_write_error;
540 } 541 }
541 542
542 ret = sd_wait_for_state(SD_TRAN, EC_TRAN_WRITE_ENTRY); 543 ret = sd_wait_for_state(SD_TRAN, EC_TRAN_WRITE_ENTRY);
543 544
544 if (ret < 0) 545 if (ret < 0)
545 goto sd_write_error; 546 goto sd_write_error;
546 547
547 /* Use full SD clock for data transfer (PCK_SDMMC) */ 548 /* Use full SD clock for data transfer (PCK_SDMMC) */
548 SDICLK = (1<<13) | (1<<12); /* bypass divider | enable */ 549 SDICLK = (1<<13) | (1<<12); /* bypass divider | enable */
549 550
550 /* Block count | FIFO count | Block size (2^9) | 4-bit bus */ 551 /* Block count | FIFO count | Block size (2^9) | 4-bit bus */
551 SDIDCTRL = (count<<13) | (4<<8) | (9<<4) | (1<<2); 552 SDIDCTRL = (count<<13) | (4<<8) | (9<<4) | (1<<2);
552 SDIDCTRL |= (1<<12); /* nReset */ 553 SDIDCTRL |= (1<<12); /* nReset */
553 554
554 SDIDCTRL2 = (1<<2) | (1<<1); /* multi block, write */ 555 SDIDCTRL2 = (1<<2) | (1<<1); /* multi block, write */
555 556
557 // XXX 64-bit
556 if (currcard->ocr & (1<<30)) 558 if (currcard->ocr & (1<<30))
557 ret = sd_command(SD_WRITE_MULTIPLE_BLOCK, start, NULL, SDICMD_RES_TYPE1); 559 ret = sd_command(SD_WRITE_MULTIPLE_BLOCK, start, NULL, SDICMD_RES_TYPE1);
558 else 560 else
@@ -578,7 +580,7 @@ sd_write_retry:
578 else 580 else
579 { 581 {
580 int tmp_buf[4]; 582 int tmp_buf[4];
581 583
582 memcpy(tmp_buf, outbuf, 16); 584 memcpy(tmp_buf, outbuf, 16);
583 585
584 SDIWDATA = tmp_buf[0]; 586 SDIWDATA = tmp_buf[0];
@@ -646,12 +648,12 @@ void sd_enable(bool on)
646 PCLK_SDMMC &= ~PCK_EN; 648 PCLK_SDMMC &= ~PCK_EN;
647 } 649 }
648} 650}
649 651
650int sd_init(void) 652int sd_init(void)
651{ 653{
652 static bool initialized = false; 654 static bool initialized = false;
653 int ret = 0; 655 int ret = 0;
654 656
655 if (!initialized) 657 if (!initialized)
656 mutex_init(&sd_mtx); 658 mutex_init(&sd_mtx);
657 659
@@ -678,7 +680,7 @@ int sd_init(void)
678 GPIOC_DIR |= (1<<24); 680 GPIOC_DIR |= (1<<24);
679 681
680 sleep(HZ/10); 682 sleep(HZ/10);
681 683
682#ifdef HAVE_HOTSWAP 684#ifdef HAVE_HOTSWAP
683 /* Configure interrupts for the card slot */ 685 /* Configure interrupts for the card slot */
684 TMODE &= ~EXT0_IRQ_MASK; /* edge-triggered */ 686 TMODE &= ~EXT0_IRQ_MASK; /* edge-triggered */
@@ -696,7 +698,7 @@ long sd_last_disk_activity(void)
696} 698}
697 699
698tCardInfo *card_get_info_target(int card_no) 700tCardInfo *card_get_info_target(int card_no)
699{ 701{
700 return &card_info[card_no]; 702 return &card_info[card_no];
701} 703}
702 704
@@ -706,7 +708,7 @@ int sd_num_drives(int first_drive)
706{ 708{
707 /* Store which logical drive number(s) we have been assigned */ 709 /* Store which logical drive number(s) we have been assigned */
708 sd_first_drive = first_drive; 710 sd_first_drive = first_drive;
709 711
710#if defined(HAVE_INTERNAL_SD) && defined(HAVE_HOTSWAP) 712#if defined(HAVE_INTERNAL_SD) && defined(HAVE_HOTSWAP)
711 return 2; 713 return 2;
712#else 714#else
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c
index a1985472a0..76929e603e 100644
--- a/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c
+++ b/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c
@@ -126,8 +126,10 @@ void GIO2(void)
126 126
127#define VFAT_SECTOR_SIZE(x) ( (x)/0x8000 ) /* 1GB array requires 80kB of RAM */ 127#define VFAT_SECTOR_SIZE(x) ( (x)/0x8000 ) /* 1GB array requires 80kB of RAM */
128 128
129extern int ata_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf); 129extern int ata_read_sectors(IF_MD(int drive,) sector_t start, int count, void* buf);
130extern int ata_write_sectors(IF_MD(int drive,) unsigned long start, int count, const void* buf); 130extern int ata_write_sectors(IF_MD(int drive,) sector_t start, int count, const void* buf);
131
132// XXX 64-bit: Due to this it's not likely that this target will ever handle 64-bit storage.
131 133
132struct main_header 134struct main_header
133{ 135{
@@ -253,9 +255,9 @@ static void cfs_init(void)
253 /* Read root inode */ 255 /* Read root inode */
254 _ata_read_sectors(CFS_CLUSTER2CLUSTER(cfs->first_inode), 64, &sector2); 256 _ata_read_sectors(CFS_CLUSTER2CLUSTER(cfs->first_inode), 64, &sector2);
255 root_inode = (struct cfs_inode*)&sector2; 257 root_inode = (struct cfs_inode*)&sector2;
256 258
257 logf("Root inode = 0x%x", root_inode); 259 logf("Root inode = 0x%x", root_inode);
258 260
259 logf("0x%x 0x%x", CFS_CLUSTER2CLUSTER(root_inode->first_class_chain[0]), root_inode->first_class_chain[0]); 261 logf("0x%x 0x%x", CFS_CLUSTER2CLUSTER(root_inode->first_class_chain[0]), root_inode->first_class_chain[0]);
260 262
261 /* Read root inode's first sector */ 263 /* Read root inode's first sector */
@@ -277,9 +279,9 @@ static void cfs_init(void)
277 vfat_inode_nr = root_direntry_items[i].inode_number; 279 vfat_inode_nr = root_direntry_items[i].inode_number;
278 } 280 }
279 } 281 }
280 282
281 logf("VFAT inode = 0x%x", vfat_inode_nr); 283 logf("VFAT inode = 0x%x", vfat_inode_nr);
282 284
283 if(vfat_inode_nr != 0) 285 if(vfat_inode_nr != 0)
284 { 286 {
285 /* Read VFAT inode */ 287 /* Read VFAT inode */
@@ -384,19 +386,19 @@ static void cfs_init(void)
384 cfs_inited = true; 386 cfs_inited = true;
385} 387}
386 388
387static inline unsigned long map_sector(unsigned long sector) 389static inline sector_t map_sector(sector_t sector)
388{ 390{
389 /* 391 /*
390 * Sector mapping: start of CFS + FAT_SECTOR2CFS_SECTOR(sector) + missing part 392 * Sector mapping: start of CFS + FAT_SECTOR2CFS_SECTOR(sector) + missing part
391 * FAT works with sectors of 0x200 bytes, CFS with sectors of 0x8000 bytes. 393 * FAT works with sectors of 0x200 bytes, CFS with sectors of 0x8000 bytes.
392 */ 394 */
393#ifndef BOOTLOADER 395#ifndef BOOTLOADER
394 unsigned long *sectors = core_get_data(sectors_handle); 396 sector_t *sectors = core_get_data(sectors_handle);
395#endif 397#endif
396 return cfs_start+sectors[sector/64]*64+sector%64; 398 return cfs_start+sectors[sector/64]*64+sector%64;
397} 399}
398 400
399int ata_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf) 401int ata_read_sectors(IF_MD(int drive,) sector_t start, int count, void* buf)
400{ 402{
401 if(!cfs_inited) 403 if(!cfs_inited)
402 cfs_init(); 404 cfs_init();
@@ -423,7 +425,7 @@ int ata_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf
423 } 425 }
424} 426}
425 427
426int ata_write_sectors(IF_MD(int drive,) unsigned long start, int count, const void* buf) 428int ata_write_sectors(IF_MD(int drive,) sector_t start, int count, const void* buf)
427{ 429{
428 if(!cfs_inited) 430 if(!cfs_inited)
429 cfs_init(); 431 cfs_init();
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h b/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h
index d0aa12e040..41b8e73ad4 100644
--- a/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h
+++ b/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h
@@ -36,8 +36,8 @@
36/* Nasty hack, but Creative is nasty... */ 36/* Nasty hack, but Creative is nasty... */
37#define ata_read_sectors _ata_read_sectors 37#define ata_read_sectors _ata_read_sectors
38#define ata_write_sectors _ata_write_sectors 38#define ata_write_sectors _ata_write_sectors
39extern int _ata_read_sectors(IF_MD(int drive,) unsigned long start, int count, void* buf); 39extern int _ata_read_sectors(IF_MD(int drive,) sector_t start, int count, void* buf);
40extern int _ata_write_sectors(IF_MD(int drive,) unsigned long start, int count, const void* buf); 40extern int _ata_write_sectors(IF_MD(int drive,) sector_t start, int count, const void* buf);
41 41
42/* General purpose memory region #1 */ 42/* General purpose memory region #1 */
43#define ATA_IOBASE 0x50FEE000 43#define ATA_IOBASE 0x50FEE000
diff --git a/firmware/target/arm/tms320dm320/sdmmc-dm320.c b/firmware/target/arm/tms320dm320/sdmmc-dm320.c
index e66a4cb3c7..17cb239374 100644
--- a/firmware/target/arm/tms320dm320/sdmmc-dm320.c
+++ b/firmware/target/arm/tms320dm320/sdmmc-dm320.c
@@ -18,7 +18,7 @@
18 * KIND, either express or implied. 18 * KIND, either express or implied.
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22#include "system.h" 22#include "system.h"
23#include <string.h> 23#include <string.h>
24#include "gcc_extensions.h" 24#include "gcc_extensions.h"
@@ -97,7 +97,7 @@ struct sd_card_status
97 int retry_max; 97 int retry_max;
98}; 98};
99 99
100/** static, private data **/ 100/** static, private data **/
101 101
102/* for compatibility */ 102/* for compatibility */
103static long last_disk_activity = -1; 103static long last_disk_activity = -1;
@@ -123,7 +123,7 @@ static struct mutex sd_mtx SHAREDBSS_ATTR;
123static struct semaphore data_done SHAREDBSS_ATTR; 123static struct semaphore data_done SHAREDBSS_ATTR;
124static volatile unsigned int transfer_error[NUM_DRIVES]; 124static volatile unsigned int transfer_error[NUM_DRIVES];
125/* align on cache line size */ 125/* align on cache line size */
126static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS * SD_BLOCK_SIZE] 126static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS * SD_BLOCK_SIZE]
127 __attribute__((aligned(32))); 127 __attribute__((aligned(32)));
128 128
129static void sd_card_mux(int card_no) 129static void sd_card_mux(int card_no)
@@ -397,7 +397,7 @@ static int sd_init_card(const int card_no)
397 SDHC_RESP_FMT_1, &currcard->rca); 397 SDHC_RESP_FMT_1, &currcard->rca);
398 if (ret < 0) 398 if (ret < 0)
399 { 399 {
400 dbgprintf("SD_SEND_RELATIVE_ADDR failed"); 400 dbgprintf("SD_SEND_RELATIVE_ADDR failed");
401 return -1; 401 return -1;
402 } 402 }
403 403
@@ -559,7 +559,7 @@ bool sd_removable(IF_MD_NONVOID(int card_no))
559#ifdef HAVE_MULTIDRIVE 559#ifdef HAVE_MULTIDRIVE
560 (void)card_no; 560 (void)card_no;
561#endif 561#endif
562 562
563 /* not applicable */ 563 /* not applicable */
564 return false; 564 return false;
565} 565}
@@ -597,17 +597,17 @@ static int sd_wait_for_state(unsigned int state)
597 } 597 }
598} 598}
599 599
600static int sd_transfer_sectors(int card_no, unsigned long start, 600static int sd_transfer_sectors(int card_no, sector_t start,
601 int count, void *buffer, bool write) 601 int count, void *buffer, bool write)
602{ 602{
603 int ret; 603 int ret;
604 unsigned long start_addr; 604 sector_t start_addr;
605 int dma_channel = -1; 605 int dma_channel = -1;
606 bool use_direct_dma; 606 bool use_direct_dma;
607 int count_per_dma; 607 int count_per_dma;
608 unsigned long rel_addr; 608 unsigned long rel_addr;
609 609
610 dbgprintf("transfer %d %d %d", card_no, start, count); 610 dbgprintf("transfer %d %lu %d", card_no, start, count);
611 mutex_lock(&sd_mtx); 611 mutex_lock(&sd_mtx);
612 enable_controller(true); 612 enable_controller(true);
613 613
@@ -673,6 +673,7 @@ sd_transfer_retry:
673 if (!(card_info[card_no].ocr & SD_OCR_CARD_CAPACITY_STATUS)) 673 if (!(card_info[card_no].ocr & SD_OCR_CARD_CAPACITY_STATUS))
674 start_addr *= SD_BLOCK_SIZE; /* not SDHC */ 674 start_addr *= SD_BLOCK_SIZE; /* not SDHC */
675 675
676 // XXX 64-bit
676 ret = sd_command(write ? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK, 677 ret = sd_command(write ? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK,
677 start_addr, MMC_CMD_DCLR | MMC_CMD_DATA | 678 start_addr, MMC_CMD_DCLR | MMC_CMD_DATA |
678 SDHC_RESP_FMT_1 | (write ? MMC_CMD_WRITE : 0), 679 SDHC_RESP_FMT_1 | (write ? MMC_CMD_WRITE : 0),
@@ -765,7 +766,7 @@ sd_transfer_error:
765 } 766 }
766} 767}
767 768
768int sd_read_sectors(IF_MD(int card_no,) unsigned long start, int incount, 769int sd_read_sectors(IF_MD(int card_no,) sector_t start, int incount,
769 void* inbuf) 770 void* inbuf)
770{ 771{
771#ifndef HAVE_MULTIDRIVE 772#ifndef HAVE_MULTIDRIVE
@@ -774,7 +775,7 @@ int sd_read_sectors(IF_MD(int card_no,) unsigned long start, int incount,
774 return sd_transfer_sectors(card_no, start, incount, inbuf, false); 775 return sd_transfer_sectors(card_no, start, incount, inbuf, false);
775} 776}
776 777
777int sd_write_sectors(IF_MD(int card_no,) unsigned long start, int count, 778int sd_write_sectors(IF_MD(int card_no,) sector_t start, int count,
778 const void* outbuf) 779 const void* outbuf)
779{ 780{
780#ifndef HAVE_MULTIDRIVE 781#ifndef HAVE_MULTIDRIVE
@@ -862,7 +863,7 @@ long sd_last_disk_activity(void)
862} 863}
863 864
864tCardInfo *card_get_info_target(int card_no) 865tCardInfo *card_get_info_target(int card_no)
865{ 866{
866 return &card_info[card_no]; 867 return &card_info[card_no];
867} 868}
868 869