diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/SOURCES | 2 | ||||
-rw-r--r-- | firmware/drivers/sd.c | 64 | ||||
-rw-r--r-- | firmware/export/hotswap.h | 1 | ||||
-rw-r--r-- | firmware/export/sd.h | 7 | ||||
-rw-r--r-- | firmware/hotswap.c | 2 | ||||
-rw-r--r-- | firmware/target/arm/as3525/ata_sd_as3525.c | 66 | ||||
-rw-r--r-- | firmware/target/arm/ata-sd-pp.c | 73 | ||||
-rw-r--r-- | firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c | 25 |
8 files changed, 113 insertions, 127 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index 36f5070413..609521a4de 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -134,6 +134,8 @@ target/arm/ata-nand-telechips.c | |||
134 | target/arm/s5l8700/ata-nand-s5l8700.c | 134 | target/arm/s5l8700/ata-nand-s5l8700.c |
135 | #elif (CONFIG_STORAGE & STORAGE_ATA) | 135 | #elif (CONFIG_STORAGE & STORAGE_ATA) |
136 | drivers/ata.c | 136 | drivers/ata.c |
137 | #elif (CONFIG_STORAGE & STORAGE_SD) | ||
138 | drivers/sd.c | ||
137 | #elif (CONFIG_STORAGE & STORAGE_RAMDISK) | 139 | #elif (CONFIG_STORAGE & STORAGE_RAMDISK) |
138 | drivers/ramdisk.c | 140 | drivers/ramdisk.c |
139 | #endif /* CONFIG_STORAGE */ | 141 | #endif /* CONFIG_STORAGE */ |
diff --git a/firmware/drivers/sd.c b/firmware/drivers/sd.c new file mode 100644 index 0000000000..834d8a19fd --- /dev/null +++ b/firmware/drivers/sd.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright © 2009 by Rafaël Carré | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "hotswap.h" | ||
24 | |||
25 | static const unsigned char sd_mantissa[] = { /* *10 */ | ||
26 | 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 }; | ||
27 | static const unsigned int sd_exponent[] = { /* use varies */ | ||
28 | 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000 }; | ||
29 | |||
30 | void sd_parse_csd(tCardInfo *card) | ||
31 | { | ||
32 | unsigned int c_size, c_mult; | ||
33 | const int csd_version = card_extract_bits(card->csd, 127, 2); | ||
34 | if(csd_version == 0) | ||
35 | { | ||
36 | /* CSD version 1.0 */ | ||
37 | int max_read_bl_len; | ||
38 | |||
39 | c_size = card_extract_bits(card->csd, 73, 12) + 1; | ||
40 | c_mult = 4 << card_extract_bits(card->csd, 49, 3); | ||
41 | max_read_bl_len = 1 << card_extract_bits(card->csd, 83, 4); | ||
42 | card->numblocks = c_size * c_mult * (max_read_bl_len/512); | ||
43 | } | ||
44 | #ifdef HAVE_MULTIVOLUME | ||
45 | else if(csd_version == 1) | ||
46 | { | ||
47 | /* CSD version 2.0 */ | ||
48 | c_size = card_extract_bits(card->csd, 69, 22) + 1; | ||
49 | card->numblocks = c_size << 10; | ||
50 | } | ||
51 | #endif | ||
52 | |||
53 | card->blocksize = 512; /* Always use 512 byte blocks */ | ||
54 | |||
55 | card->speed = sd_mantissa[card_extract_bits(card->csd, 102, 4)] * | ||
56 | sd_exponent[card_extract_bits(card->csd, 98, 3) + 4]; | ||
57 | |||
58 | card->nsac = 100 * card_extract_bits(card->csd, 111, 8); | ||
59 | |||
60 | card->taac = sd_mantissa[card_extract_bits(card->csd, 118, 4)] * | ||
61 | sd_exponent[card_extract_bits(card->csd, 114, 3)]; | ||
62 | |||
63 | card->r2w_factor = card_extract_bits(card->csd, 28, 3); | ||
64 | } | ||
diff --git a/firmware/export/hotswap.h b/firmware/export/hotswap.h index a9bb745f38..455dee6bcc 100644 --- a/firmware/export/hotswap.h +++ b/firmware/export/hotswap.h | |||
@@ -56,6 +56,7 @@ typedef struct | |||
56 | #define card_detect card_detect_target | 56 | #define card_detect card_detect_target |
57 | #define card_get_info card_get_info_target | 57 | #define card_get_info card_get_info_target |
58 | tCardInfo *card_get_info_target(int card_no); | 58 | tCardInfo *card_get_info_target(int card_no); |
59 | void sd_parse_csd(tCardInfo *card); | ||
59 | 60 | ||
60 | #ifdef HAVE_HOTSWAP | 61 | #ifdef HAVE_HOTSWAP |
61 | #define card_enable_monitoring card_enable_monitoring_target | 62 | #define card_enable_monitoring card_enable_monitoring_target |
diff --git a/firmware/export/sd.h b/firmware/export/sd.h index 9d47290d85..6c848c34cf 100644 --- a/firmware/export/sd.h +++ b/firmware/export/sd.h | |||
@@ -25,6 +25,8 @@ | |||
25 | #include <stdbool.h> | 25 | #include <stdbool.h> |
26 | #include "mv.h" /* for HAVE_MULTIVOLUME or not */ | 26 | #include "mv.h" /* for HAVE_MULTIVOLUME or not */ |
27 | 27 | ||
28 | #define SD_BLOCK_SIZE 512 /* XXX : support other sizes ? */ | ||
29 | |||
28 | struct storage_info; | 30 | struct storage_info; |
29 | 31 | ||
30 | void sd_enable(bool on); | 32 | void sd_enable(bool on); |
@@ -51,11 +53,6 @@ bool card_detect_target(void); | |||
51 | 53 | ||
52 | long sd_last_disk_activity(void); | 54 | long sd_last_disk_activity(void); |
53 | 55 | ||
54 | static const unsigned char sd_mantissa[] = { /* *10 */ | ||
55 | 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 }; | ||
56 | static const unsigned int sd_exponent[] = { /* use varies */ | ||
57 | 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000 }; | ||
58 | |||
59 | /* SD States */ | 56 | /* SD States */ |
60 | #define SD_IDLE 0 | 57 | #define SD_IDLE 0 |
61 | #define SD_READY 1 | 58 | #define SD_READY 1 |
diff --git a/firmware/hotswap.c b/firmware/hotswap.c index ec298f7243..79595e4591 100644 --- a/firmware/hotswap.c +++ b/firmware/hotswap.c | |||
@@ -36,7 +36,7 @@ unsigned long card_extract_bits( | |||
36 | unsigned int long_index, bit_index; | 36 | unsigned int long_index, bit_index; |
37 | unsigned long result; | 37 | unsigned long result; |
38 | 38 | ||
39 | /* we assume words of CSD/CID are stored least significant word first */ | 39 | /* we assume words of CSD/CID are stored most significant word first */ |
40 | start = 127 - start; | 40 | start = 127 - start; |
41 | 41 | ||
42 | long_index = start / 32; | 42 | long_index = start / 32; |
diff --git a/firmware/target/arm/as3525/ata_sd_as3525.c b/firmware/target/arm/as3525/ata_sd_as3525.c index c0fad722b6..74bdb90ed0 100644 --- a/firmware/target/arm/as3525/ata_sd_as3525.c +++ b/firmware/target/arm/as3525/ata_sd_as3525.c | |||
@@ -94,9 +94,7 @@ static const int pl180_base[NUM_VOLUMES] = { | |||
94 | static int sd_select_bank(signed char bank); | 94 | static int sd_select_bank(signed char bank); |
95 | static int sd_init_card(const int drive); | 95 | static int sd_init_card(const int drive); |
96 | static void init_pl180_controller(const int drive); | 96 | static void init_pl180_controller(const int drive); |
97 | /* TODO : BLOCK_SIZE != SECTOR_SIZE ? */ | 97 | #define SECTOR_SIZE 512 /* XXX: different sector sizes ? */ |
98 | #define BLOCK_SIZE 512 | ||
99 | #define SECTOR_SIZE 512 | ||
100 | #define BLOCKS_PER_BANK 0x7a7800 | 98 | #define BLOCKS_PER_BANK 0x7a7800 |
101 | 99 | ||
102 | static tCardInfo card_info[NUM_VOLUMES]; | 100 | static tCardInfo card_info[NUM_VOLUMES]; |
@@ -241,12 +239,11 @@ static bool send_cmd(const int drive, const int cmd, const int arg, | |||
241 | 239 | ||
242 | static int sd_init_card(const int drive) | 240 | static int sd_init_card(const int drive) |
243 | { | 241 | { |
244 | unsigned int c_size; | ||
245 | unsigned long c_mult; | ||
246 | unsigned long response; | 242 | unsigned long response; |
247 | int max_tries = 100; /* max acmd41 attemps */ | 243 | int max_tries = 100; /* max acmd41 attemps */ |
248 | bool sdhc; | 244 | bool sdhc; |
249 | unsigned char temp; | 245 | unsigned long temp_reg[4]; |
246 | int i; | ||
250 | 247 | ||
251 | if(!send_cmd(drive, SD_GO_IDLE_STATE, 0, MCI_NO_FLAGS, NULL)) | 248 | if(!send_cmd(drive, SD_GO_IDLE_STATE, 0, MCI_NO_FLAGS, NULL)) |
252 | return -1; | 249 | return -1; |
@@ -284,17 +281,11 @@ static int sd_init_card(const int drive) | |||
284 | 281 | ||
285 | /* send CID */ | 282 | /* send CID */ |
286 | if(!send_cmd(drive, SD_ALL_SEND_CID, 0, MCI_RESP|MCI_LONG_RESP|MCI_ARG, | 283 | if(!send_cmd(drive, SD_ALL_SEND_CID, 0, MCI_RESP|MCI_LONG_RESP|MCI_ARG, |
287 | card_info[drive].cid)) | 284 | temp_reg)) |
288 | return -5; | 285 | return -5; |
289 | 286 | ||
290 | /* ascii chars here */ | 287 | for(i=0; i<4; i++) |
291 | card_info[drive].cid[0] = htobe32(card_info[drive].cid[0]); | 288 | card_info[drive].cid[3-i] = temp_reg[i]; |
292 | card_info[drive].cid[1] = htobe32(card_info[drive].cid[1]); | ||
293 | |||
294 | /* adjust year<=>month, 1997 <=> 2000 */ | ||
295 | temp = *((char*)card_info[drive].cid+13); | ||
296 | *((char*)card_info[drive].cid+13) = | ||
297 | (unsigned char)((temp >> 4) | (temp << 4)) + 3; | ||
298 | 289 | ||
299 | /* send RCA */ | 290 | /* send RCA */ |
300 | if(!send_cmd(drive, SD_SEND_RELATIVE_ADDR, 0, MCI_RESP|MCI_ARG, | 291 | if(!send_cmd(drive, SD_SEND_RELATIVE_ADDR, 0, MCI_RESP|MCI_ARG, |
@@ -303,29 +294,13 @@ static int sd_init_card(const int drive) | |||
303 | 294 | ||
304 | /* send CSD */ | 295 | /* send CSD */ |
305 | if(!send_cmd(drive, SD_SEND_CSD, card_info[drive].rca, | 296 | if(!send_cmd(drive, SD_SEND_CSD, card_info[drive].rca, |
306 | MCI_RESP|MCI_LONG_RESP|MCI_ARG, card_info[drive].csd)) | 297 | MCI_RESP|MCI_LONG_RESP|MCI_ARG, temp_reg)) |
307 | return -7; | 298 | return -7; |
308 | 299 | ||
309 | /* These calculations come from the Sandisk SD card product manual */ | 300 | for(i=0; i<4; i++) |
310 | if( (card_info[drive].csd[3]>>30) == 0) | 301 | card_info[drive].csd[3-i] = temp_reg[i]; |
311 | { | 302 | |
312 | int max_read_bl_len; | 303 | sd_parse_csd(&card_info[drive]); |
313 | /* CSD version 1.0 */ | ||
314 | c_size = ((card_info[drive].csd[2] & 0x3ff) << 2) + (card_info[drive].csd[1]>>30) + 1; | ||
315 | c_mult = 4 << ((card_info[drive].csd[1] >> 15) & 7); | ||
316 | max_read_bl_len = 1 << ((card_info[drive].csd[2] >> 16) & 15); | ||
317 | card_info[drive].blocksize = BLOCK_SIZE; /* Always use 512 byte blocks */ | ||
318 | card_info[drive].numblocks = c_size * c_mult * (max_read_bl_len/512); | ||
319 | } | ||
320 | #ifdef HAVE_MULTIVOLUME | ||
321 | else if( (card_info[drive].csd[3]>>30) == 1) | ||
322 | { | ||
323 | /* CSD version 2.0 */ | ||
324 | c_size = ((card_info[drive].csd[2] & 0x3f) << 16) + (card_info[drive].csd[1]>>16) + 1; | ||
325 | card_info[drive].blocksize = BLOCK_SIZE; /* Always use 512 byte blocks */ | ||
326 | card_info[drive].numblocks = c_size << 10; | ||
327 | } | ||
328 | #endif | ||
329 | 304 | ||
330 | if(!send_cmd(drive, SD_SELECT_CARD, card_info[drive].rca, MCI_ARG, NULL)) | 305 | if(!send_cmd(drive, SD_SELECT_CARD, card_info[drive].rca, MCI_ARG, NULL)) |
331 | return -9; | 306 | return -9; |
@@ -723,7 +698,7 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start, | |||
723 | 698 | ||
724 | /* Set bank_start to the correct unit (blocks or bytes) */ | 699 | /* Set bank_start to the correct unit (blocks or bytes) */ |
725 | if(!(card_info[drive].ocr & (1<<30))) /* not SDHC */ | 700 | if(!(card_info[drive].ocr & (1<<30))) /* not SDHC */ |
726 | bank_start *= BLOCK_SIZE; | 701 | bank_start *= SD_BLOCK_SIZE; |
727 | 702 | ||
728 | if(!send_cmd(drive, cmd, bank_start, MCI_ARG, NULL)) | 703 | if(!send_cmd(drive, cmd, bank_start, MCI_ARG, NULL)) |
729 | { | 704 | { |
@@ -877,22 +852,7 @@ void sd_enable(bool on) | |||
877 | 852 | ||
878 | tCardInfo *card_get_info_target(int card_no) | 853 | tCardInfo *card_get_info_target(int card_no) |
879 | { | 854 | { |
880 | unsigned char temp; | 855 | return &card_info[card_no]; |
881 | tCardInfo *card = &card_info[card_no]; | ||
882 | |||
883 | temp = card->csd[3]; | ||
884 | card->speed = sd_mantissa[temp & 7] * sd_exponent[(temp >> 3) & 0xf]; | ||
885 | |||
886 | temp = card->csd[3] >> 8; | ||
887 | card->nsac = 100 * temp; | ||
888 | |||
889 | temp = (card->csd[3] >> 16) & 0x7f; /* bit 7 reserved */ | ||
890 | card->taac = sd_mantissa[temp >> 3] * sd_exponent[temp & 7]; | ||
891 | |||
892 | temp = (card->csd[0] >> 26) & 7; | ||
893 | card->r2w_factor = temp; | ||
894 | |||
895 | return card; | ||
896 | } | 856 | } |
897 | 857 | ||
898 | bool card_detect_target(void) | 858 | bool card_detect_target(void) |
diff --git a/firmware/target/arm/ata-sd-pp.c b/firmware/target/arm/ata-sd-pp.c index 8f30195791..df13a119f8 100644 --- a/firmware/target/arm/ata-sd-pp.c +++ b/firmware/target/arm/ata-sd-pp.c | |||
@@ -36,7 +36,6 @@ | |||
36 | #include "sd.h" | 36 | #include "sd.h" |
37 | #include "storage.h" | 37 | #include "storage.h" |
38 | 38 | ||
39 | #define BLOCK_SIZE 512 | ||
40 | #define SECTOR_SIZE 512 | 39 | #define SECTOR_SIZE 512 |
41 | #define BLOCKS_PER_BANK 0x7a7800 | 40 | #define BLOCKS_PER_BANK 0x7a7800 |
42 | 41 | ||
@@ -552,7 +551,7 @@ static int sd_select_bank(unsigned char bank) | |||
552 | 551 | ||
553 | /* Write the card data */ | 552 | /* Write the card data */ |
554 | write_buf = card_data; | 553 | write_buf = card_data; |
555 | for (i = 0; i < BLOCK_SIZE/2; i += FIFO_LEN) | 554 | for (i = 0; i < SD_BLOCK_SIZE/2; i += FIFO_LEN) |
556 | { | 555 | { |
557 | /* Wait for the FIFO to empty */ | 556 | /* Wait for the FIFO to empty */ |
558 | if (sd_poll_status(STAT_XMIT_FIFO_EMPTY, 10000)) | 557 | if (sd_poll_status(STAT_XMIT_FIFO_EMPTY, 10000)) |
@@ -652,10 +651,9 @@ static void sd_init_device(int card_no) | |||
652 | unsigned long response = 0; | 651 | unsigned long response = 0; |
653 | #endif | 652 | #endif |
654 | unsigned int i; | 653 | unsigned int i; |
655 | unsigned int c_size; | ||
656 | unsigned long c_mult; | ||
657 | unsigned char carddata[512]; | 654 | unsigned char carddata[512]; |
658 | unsigned char *dataptr; | 655 | unsigned char *dataptr; |
656 | unsigned long temp_reg[4]; | ||
659 | int ret; | 657 | int ret; |
660 | 658 | ||
661 | /* Enable and initialise controller */ | 659 | /* Enable and initialise controller */ |
@@ -733,38 +731,25 @@ static void sd_init_device(int card_no) | |||
733 | } | 731 | } |
734 | } | 732 | } |
735 | 733 | ||
736 | ret = sd_command(SD_ALL_SEND_CID, 0, currcard->cid, CMDAT_RES_TYPE2); | 734 | ret = sd_command(SD_ALL_SEND_CID, 0, temp_reg, CMDAT_RES_TYPE2); |
737 | if (ret < 0) | 735 | if (ret < 0) |
738 | goto card_init_error; | 736 | goto card_init_error; |
739 | 737 | ||
738 | for(i=0; i<4; i++) | ||
739 | currcard->cid[i] = temp_reg[3-i]; | ||
740 | |||
740 | ret = sd_command(SD_SEND_RELATIVE_ADDR, 0, &currcard->rca, CMDAT_RES_TYPE1); | 741 | ret = sd_command(SD_SEND_RELATIVE_ADDR, 0, &currcard->rca, CMDAT_RES_TYPE1); |
741 | if (ret < 0) | 742 | if (ret < 0) |
742 | goto card_init_error; | 743 | goto card_init_error; |
743 | 744 | ||
744 | ret = sd_command(SD_SEND_CSD, currcard->rca, currcard->csd, CMDAT_RES_TYPE2); | 745 | ret = sd_command(SD_SEND_CSD, currcard->rca, temp_reg, CMDAT_RES_TYPE2); |
745 | if (ret < 0) | 746 | if (ret < 0) |
746 | goto card_init_error; | 747 | goto card_init_error; |
747 | 748 | ||
748 | /* These calculations come from the Sandisk SD card product manual */ | 749 | for(i=0; i<4; i++) |
749 | if( (currcard->csd[3]>>30) == 0) | 750 | currcard->csd[i] = temp_reg[3-i]; |
750 | { | 751 | |
751 | int max_read_bl_len; | 752 | sd_parse_csd(currcard); |
752 | /* CSD version 1.0 */ | ||
753 | c_size = ((currcard->csd[2] & 0x3ff) << 2) + (currcard->csd[1]>>30) + 1; | ||
754 | c_mult = 4 << ((currcard->csd[1] >> 15) & 7); | ||
755 | max_read_bl_len = 1 << ((currcard->csd[2] >> 16) & 15); | ||
756 | currcard->blocksize = BLOCK_SIZE; /* Always use 512 byte blocks */ | ||
757 | currcard->numblocks = c_size * c_mult * (max_read_bl_len/512); | ||
758 | } | ||
759 | #ifdef HAVE_HOTSWAP | ||
760 | else if( (currcard->csd[3]>>30) == 1) | ||
761 | { | ||
762 | /* CSD version 2.0 */ | ||
763 | c_size = ((currcard->csd[2] & 0x3f) << 16) + (currcard->csd[1]>>16) + 1; | ||
764 | currcard->blocksize = BLOCK_SIZE; /* Always use 512 byte blocks */ | ||
765 | currcard->numblocks = c_size << 10; | ||
766 | } | ||
767 | #endif /* HAVE_HOTSWAP */ | ||
768 | 753 | ||
769 | MMC_CLKRT = 0; /* switch to highest clock rate */ | 754 | MMC_CLKRT = 0; /* switch to highest clock rate */ |
770 | 755 | ||
@@ -805,7 +790,7 @@ static void sd_init_device(int card_no) | |||
805 | The first 512 bits contain the status information | 790 | The first 512 bits contain the status information |
806 | TODO: Do something useful with this! */ | 791 | TODO: Do something useful with this! */ |
807 | dataptr = carddata; | 792 | dataptr = carddata; |
808 | for (i = 0; i < BLOCK_SIZE/2; i += FIFO_LEN) | 793 | for (i = 0; i < SD_BLOCK_SIZE/2; i += FIFO_LEN) |
809 | { | 794 | { |
810 | /* Wait for the FIFO to be full */ | 795 | /* Wait for the FIFO to be full */ |
811 | if (sd_poll_status(STAT_RECV_FIFO_FULL, 100000)) | 796 | if (sd_poll_status(STAT_RECV_FIFO_FULL, 100000)) |
@@ -924,13 +909,13 @@ sd_read_retry: | |||
924 | else | 909 | else |
925 | #endif | 910 | #endif |
926 | { | 911 | { |
927 | ret = sd_command(SD_READ_MULTIPLE_BLOCK, start * BLOCK_SIZE, NULL, | 912 | ret = sd_command(SD_READ_MULTIPLE_BLOCK, start * SD_BLOCK_SIZE, NULL, |
928 | 0x1c00 | CMDAT_BUSY | CMDAT_DATA_EN | CMDAT_RES_TYPE1); | 913 | 0x1c00 | CMDAT_BUSY | CMDAT_DATA_EN | CMDAT_RES_TYPE1); |
929 | } | 914 | } |
930 | if (ret < 0) | 915 | if (ret < 0) |
931 | goto sd_read_error; | 916 | goto sd_read_error; |
932 | 917 | ||
933 | /* TODO: Don't assume BLOCK_SIZE == SECTOR_SIZE */ | 918 | /* TODO: Don't assume SD_BLOCK_SIZE == SECTOR_SIZE */ |
934 | 919 | ||
935 | buf_end = (unsigned char *)inbuf + incount * currcard->blocksize; | 920 | buf_end = (unsigned char *)inbuf + incount * currcard->blocksize; |
936 | for (buf = inbuf; buf < buf_end;) | 921 | for (buf = inbuf; buf < buf_end;) |
@@ -1042,7 +1027,7 @@ sd_write_retry: | |||
1042 | else | 1027 | else |
1043 | #endif | 1028 | #endif |
1044 | { | 1029 | { |
1045 | ret = sd_command(SD_WRITE_MULTIPLE_BLOCK, start*BLOCK_SIZE, NULL, | 1030 | ret = sd_command(SD_WRITE_MULTIPLE_BLOCK, start*SD_BLOCK_SIZE, NULL, |
1046 | CMDAT_WR_RD | CMDAT_DATA_EN | CMDAT_RES_TYPE1); | 1031 | CMDAT_WR_RD | CMDAT_DATA_EN | CMDAT_RES_TYPE1); |
1047 | } | 1032 | } |
1048 | if (ret < 0) | 1033 | if (ret < 0) |
@@ -1290,35 +1275,9 @@ int sd_init(void) | |||
1290 | return ret; | 1275 | return ret; |
1291 | } | 1276 | } |
1292 | 1277 | ||
1293 | /* move the sd-card info to mmc struct */ | ||
1294 | tCardInfo *card_get_info_target(int card_no) | 1278 | tCardInfo *card_get_info_target(int card_no) |
1295 | { | 1279 | { |
1296 | int i, temp; | 1280 | return &card_info[card_no]; |
1297 | static tCardInfo card; | ||
1298 | static const char mantissa[] = { /* *10 */ | ||
1299 | 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 }; | ||
1300 | static const int exponent[] = { /* use varies */ | ||
1301 | 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000 }; | ||
1302 | |||
1303 | card.initialized = card_info[card_no].initialized; | ||
1304 | card.ocr = card_info[card_no].ocr; | ||
1305 | for(i=0; i<4; i++) card.csd[i] = card_info[card_no].csd[3-i]; | ||
1306 | for(i=0; i<4; i++) card.cid[i] = card_info[card_no].cid[3-i]; | ||
1307 | card.numblocks = card_info[card_no].numblocks; | ||
1308 | card.blocksize = card_info[card_no].blocksize; | ||
1309 | temp = card_extract_bits(card.csd, 98, 3); | ||
1310 | card.speed = mantissa[card_extract_bits(card.csd, 102, 4)] | ||
1311 | * exponent[temp > 2 ? 7 : temp + 4]; | ||
1312 | card.nsac = 100 * card_extract_bits(card.csd, 111, 8); | ||
1313 | temp = card_extract_bits(card.csd, 114, 3); | ||
1314 | card.taac = mantissa[card_extract_bits(card.csd, 118, 4)] | ||
1315 | * exponent[temp] / 10; | ||
1316 | card.cid[0] = htobe32(card.cid[0]); /* ascii chars here */ | ||
1317 | card.cid[1] = htobe32(card.cid[1]); /* ascii chars here */ | ||
1318 | temp = *((char*)card.cid+13); /* adjust year<=>month, 1997 <=> 2000 */ | ||
1319 | *((char*)card.cid+13) = (unsigned char)((temp >> 4) | (temp << 4)) + 3; | ||
1320 | |||
1321 | return &card; | ||
1322 | } | 1281 | } |
1323 | 1282 | ||
1324 | bool card_detect_target(void) | 1283 | bool card_detect_target(void) |
diff --git a/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c b/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c index 6e7f62a2e5..d14715c192 100644 --- a/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c +++ b/firmware/target/mips/ingenic_jz47xx/ata-sd-jz4740.c | |||
@@ -41,8 +41,6 @@ static long last_disk_activity = -1; | |||
41 | 41 | ||
42 | #define DEBUG(x...) logf(x) | 42 | #define DEBUG(x...) logf(x) |
43 | 43 | ||
44 | #define BLOCK_SIZE 512 | ||
45 | |||
46 | #define MMC_INSERT_STATUS() __gpio_get_pin(MMC_CD_PIN) | 44 | #define MMC_INSERT_STATUS() __gpio_get_pin(MMC_CD_PIN) |
47 | #define MMC_RESET() __msc_reset() | 45 | #define MMC_RESET() __msc_reset() |
48 | 46 | ||
@@ -1668,7 +1666,12 @@ tCardInfo* card_get_info_target(int card_no) | |||
1668 | (void)card_no; | 1666 | (void)card_no; |
1669 | int i, temp; | 1667 | int i, temp; |
1670 | static tCardInfo card; | 1668 | static tCardInfo card; |
1671 | 1669 | ||
1670 | static const unsigned char sd_mantissa[] = { /* *10 */ | ||
1671 | 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 }; | ||
1672 | static const unsigned int sd_exponent[] = { /* use varies */ | ||
1673 | 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000 }; | ||
1674 | |||
1672 | card.initialized = true; | 1675 | card.initialized = true; |
1673 | card.ocr = mmcinfo.ocr; | 1676 | card.ocr = mmcinfo.ocr; |
1674 | for(i=0; i<4; i++) | 1677 | for(i=0; i<4; i++) |
@@ -1707,22 +1710,22 @@ int sd_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* buf | |||
1707 | if (retval && (retval != MMC_ERROR_STATE_MISMATCH)) | 1710 | if (retval && (retval != MMC_ERROR_STATE_MISMATCH)) |
1708 | return retval; | 1711 | return retval; |
1709 | 1712 | ||
1710 | mmc_simple_cmd(&request, MMC_SET_BLOCKLEN, BLOCK_SIZE, RESPONSE_R1); | 1713 | mmc_simple_cmd(&request, MMC_SET_BLOCKLEN, SD_BLOCK_SIZE, RESPONSE_R1); |
1711 | if ((retval = mmc_unpack_r1(&request, &r1))) | 1714 | if ((retval = mmc_unpack_r1(&request, &r1))) |
1712 | return retval; | 1715 | return retval; |
1713 | 1716 | ||
1714 | if (sd2_0) | 1717 | if (sd2_0) |
1715 | { | 1718 | { |
1716 | mmc_send_cmd(&request, MMC_READ_MULTIPLE_BLOCK, start, | 1719 | mmc_send_cmd(&request, MMC_READ_MULTIPLE_BLOCK, start, |
1717 | count, BLOCK_SIZE, RESPONSE_R1, buf); | 1720 | count, SD_BLOCK_SIZE, RESPONSE_R1, buf); |
1718 | if ((retval = mmc_unpack_r1(&request, &r1))) | 1721 | if ((retval = mmc_unpack_r1(&request, &r1))) |
1719 | return retval; | 1722 | return retval; |
1720 | } | 1723 | } |
1721 | else | 1724 | else |
1722 | { | 1725 | { |
1723 | mmc_send_cmd(&request, MMC_READ_MULTIPLE_BLOCK, | 1726 | mmc_send_cmd(&request, MMC_READ_MULTIPLE_BLOCK, |
1724 | start * BLOCK_SIZE, count, | 1727 | start * SD_BLOCK_SIZE, count, |
1725 | BLOCK_SIZE, RESPONSE_R1, buf); | 1728 | SD_BLOCK_SIZE, RESPONSE_R1, buf); |
1726 | if ((retval = mmc_unpack_r1(&request, &r1))) | 1729 | if ((retval = mmc_unpack_r1(&request, &r1))) |
1727 | return retval; | 1730 | return retval; |
1728 | } | 1731 | } |
@@ -1757,14 +1760,14 @@ int sd_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const vo | |||
1757 | if (retval && (retval != MMC_ERROR_STATE_MISMATCH)) | 1760 | if (retval && (retval != MMC_ERROR_STATE_MISMATCH)) |
1758 | return retval; | 1761 | return retval; |
1759 | 1762 | ||
1760 | mmc_simple_cmd(&request, MMC_SET_BLOCKLEN, BLOCK_SIZE, RESPONSE_R1); | 1763 | mmc_simple_cmd(&request, MMC_SET_BLOCKLEN, SD_BLOCK_SIZE, RESPONSE_R1); |
1761 | if ((retval = mmc_unpack_r1(&request, &r1))) | 1764 | if ((retval = mmc_unpack_r1(&request, &r1))) |
1762 | return retval; | 1765 | return retval; |
1763 | 1766 | ||
1764 | if (sd2_0) | 1767 | if (sd2_0) |
1765 | { | 1768 | { |
1766 | mmc_send_cmd(&request, MMC_WRITE_MULTIPLE_BLOCK, start, | 1769 | mmc_send_cmd(&request, MMC_WRITE_MULTIPLE_BLOCK, start, |
1767 | count, BLOCK_SIZE, RESPONSE_R1, | 1770 | count, SD_BLOCK_SIZE, RESPONSE_R1, |
1768 | (void*)buf); | 1771 | (void*)buf); |
1769 | if ((retval = mmc_unpack_r1(&request, &r1))) | 1772 | if ((retval = mmc_unpack_r1(&request, &r1))) |
1770 | return retval; | 1773 | return retval; |
@@ -1772,8 +1775,8 @@ int sd_write_sectors(IF_MV2(int drive,) unsigned long start, int count, const vo | |||
1772 | else | 1775 | else |
1773 | { | 1776 | { |
1774 | mmc_send_cmd(&request, MMC_WRITE_MULTIPLE_BLOCK, | 1777 | mmc_send_cmd(&request, MMC_WRITE_MULTIPLE_BLOCK, |
1775 | start * BLOCK_SIZE, count, | 1778 | start * SD_BLOCK_SIZE, count, |
1776 | BLOCK_SIZE, RESPONSE_R1, (void*)buf); | 1779 | SD_BLOCK_SIZE, RESPONSE_R1, (void*)buf); |
1777 | if ((retval = mmc_unpack_r1(&request, &r1))) | 1780 | if ((retval = mmc_unpack_r1(&request, &r1))) |
1778 | return retval; | 1781 | return retval; |
1779 | } | 1782 | } |