summaryrefslogtreecommitdiff
path: root/firmware/target/arm/ata-sd-pp.c
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2009-07-01 10:07:22 +0000
committerRafaël Carré <rafael.carre@gmail.com>2009-07-01 10:07:22 +0000
commite0e24cbf0a3b11cb161e0ae057e4c383c6134801 (patch)
treefcfdb14a4b2984f4bc2c1bbc9657f11dcb03dcd7 /firmware/target/arm/ata-sd-pp.c
parentc929310e55bf337e4a31675a30031a7818f5deda (diff)
downloadrockbox-e0e24cbf0a3b11cb161e0ae057e4c383c6134801.tar.gz
rockbox-e0e24cbf0a3b11cb161e0ae057e4c383c6134801.zip
Merge tCardInfo struct (MMC) and tSDCardInfo struct (SD)
Put specific members under #ifdef (CONFIG_STORAGE & STORAGE_xx) (2 members for SD and 1 for MMC) Fix a typo: tsac doesn't exist and must be read taac Move card_get_info functions declaration inside hotswap.h to remove mutual inclusion of ata_mmc.h and hotswap.h Move static const data structures from SD drivers into sd.h (sd_exponent and sd_mantissa) Fix sd_command prototypes in SD drivers (card registers are unsigned long) Fix speed calculation in Sansa AMS driver (PP SD driver needs to be checked) Move ata-sd-target.h to sd-pp-target.h to reflect the PP specifity. Now it only contains declaration of microsd_int() Remove unused ata-sd-target.h for injenic TODO: - check if CSD register bits are extracted correctly in PP driver - correctly define read_timeout and write_timeout unit for MMC & SD, and use timeouts in Sansa AMS driver git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21586 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/ata-sd-pp.c')
-rw-r--r--firmware/target/arm/ata-sd-pp.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/firmware/target/arm/ata-sd-pp.c b/firmware/target/arm/ata-sd-pp.c
index cd3b5ca3f9..ade5b8090b 100644
--- a/firmware/target/arm/ata-sd-pp.c
+++ b/firmware/target/arm/ata-sd-pp.c
@@ -21,7 +21,9 @@
21#include "config.h" /* for HAVE_MULTIVOLUME */ 21#include "config.h" /* for HAVE_MULTIVOLUME */
22#include "fat.h" 22#include "fat.h"
23#include "hotswap.h" 23#include "hotswap.h"
24#include "ata-sd-target.h" 24#ifdef HAVE_HOTSWAP
25#include "sd-pp-target.h"
26#endif
25#include "ata_idle_notify.h" 27#include "ata_idle_notify.h"
26#include "system.h" 28#include "system.h"
27#include <string.h> 29#include <string.h>
@@ -156,8 +158,8 @@ static bool initialized = false;
156static long next_yield = 0; 158static long next_yield = 0;
157#define MIN_YIELD_PERIOD 1000 159#define MIN_YIELD_PERIOD 1000
158 160
159static tSDCardInfo card_info[2]; 161static tCardInfo card_info[2];
160static tSDCardInfo *currcard = NULL; /* current active card */ 162static tCardInfo *currcard = NULL; /* current active card */
161 163
162struct sd_card_status 164struct sd_card_status
163{ 165{
@@ -222,7 +224,7 @@ static bool sd_poll_status(unsigned int trigger, long timeout)
222} 224}
223 225
224static int sd_command(unsigned int cmd, unsigned long arg1, 226static int sd_command(unsigned int cmd, unsigned long arg1,
225 unsigned int *response, unsigned int cmdat) 227 unsigned long *response, unsigned int cmdat)
226{ 228{
227 int i, words; /* Number of 16 bit words to read from MMC_RES */ 229 int i, words; /* Number of 16 bit words to read from MMC_RES */
228 unsigned int data[9]; 230 unsigned int data[9];
@@ -303,7 +305,7 @@ static int sd_command(unsigned int cmd, unsigned long arg1,
303 305
304static int sd_wait_for_state(unsigned int state, int id) 306static int sd_wait_for_state(unsigned int state, int id)
305{ 307{
306 unsigned int response = 0; 308 unsigned long response = 0;
307 unsigned int timeout = 0x80000; 309 unsigned int timeout = 0x80000;
308 310
309 check_time[id] = USEC_TIMER; 311 check_time[id] = USEC_TIMER;
@@ -647,7 +649,7 @@ static void sd_init_device(int card_no)
647{ 649{
648/* SD Protocol registers */ 650/* SD Protocol registers */
649#ifdef HAVE_HOTSWAP 651#ifdef HAVE_HOTSWAP
650 unsigned int response = 0; 652 unsigned long response = 0;
651#endif 653#endif
652 unsigned int i; 654 unsigned int i;
653 unsigned int c_size; 655 unsigned int c_size;
@@ -746,23 +748,21 @@ static void sd_init_device(int card_no)
746 /* These calculations come from the Sandisk SD card product manual */ 748 /* These calculations come from the Sandisk SD card product manual */
747 if( (currcard->csd[3]>>30) == 0) 749 if( (currcard->csd[3]>>30) == 0)
748 { 750 {
751 int max_read_bl_len;
749 /* CSD version 1.0 */ 752 /* CSD version 1.0 */
750 c_size = ((currcard->csd[2] & 0x3ff) << 2) + (currcard->csd[1]>>30) + 1; 753 c_size = ((currcard->csd[2] & 0x3ff) << 2) + (currcard->csd[1]>>30) + 1;
751 c_mult = 4 << ((currcard->csd[1] >> 15) & 7); 754 c_mult = 4 << ((currcard->csd[1] >> 15) & 7);
752 currcard->max_read_bl_len = 1 << ((currcard->csd[2] >> 16) & 15); 755 max_read_bl_len = 1 << ((currcard->csd[2] >> 16) & 15);
753 currcard->block_size = BLOCK_SIZE; /* Always use 512 byte blocks */ 756 currcard->blocksize = BLOCK_SIZE; /* Always use 512 byte blocks */
754 currcard->numblocks = c_size * c_mult * (currcard->max_read_bl_len/512); 757 currcard->numblocks = c_size * c_mult * (max_read_bl_len/512);
755 currcard->capacity = currcard->numblocks * currcard->block_size;
756 } 758 }
757#ifdef HAVE_HOTSWAP 759#ifdef HAVE_HOTSWAP
758 else if( (currcard->csd[3]>>30) == 1) 760 else if( (currcard->csd[3]>>30) == 1)
759 { 761 {
760 /* CSD version 2.0 */ 762 /* CSD version 2.0 */
761 c_size = ((currcard->csd[2] & 0x3f) << 16) + (currcard->csd[1]>>16) + 1; 763 c_size = ((currcard->csd[2] & 0x3f) << 16) + (currcard->csd[1]>>16) + 1;
762 currcard->max_read_bl_len = 1 << ((currcard->csd[2] >> 16) & 0xf); 764 currcard->blocksize = BLOCK_SIZE; /* Always use 512 byte blocks */
763 currcard->block_size = BLOCK_SIZE; /* Always use 512 byte blocks */
764 currcard->numblocks = c_size << 10; 765 currcard->numblocks = c_size << 10;
765 currcard->capacity = currcard->numblocks * currcard->block_size;
766 } 766 }
767#endif /* HAVE_HOTSWAP */ 767#endif /* HAVE_HOTSWAP */
768 768
@@ -782,12 +782,12 @@ static void sd_init_device(int card_no)
782 if (ret < 0) 782 if (ret < 0)
783 goto card_init_error; 783 goto card_init_error;
784 784
785 ret = sd_command(SD_SET_BLOCKLEN, currcard->block_size, NULL, 785 ret = sd_command(SD_SET_BLOCKLEN, currcard->blocksize, NULL,
786 CMDAT_RES_TYPE1); 786 CMDAT_RES_TYPE1);
787 if (ret < 0) 787 if (ret < 0)
788 goto card_init_error; 788 goto card_init_error;
789 789
790 MMC_BLKLEN = currcard->block_size; 790 MMC_BLKLEN = currcard->blocksize;
791 791
792 /* If this card is >4GB & not SDHC, then we need to enable bank switching */ 792 /* If this card is >4GB & not SDHC, then we need to enable bank switching */
793 if( (currcard->numblocks >= BLOCKS_PER_BANK) && 793 if( (currcard->numblocks >= BLOCKS_PER_BANK) &&
@@ -867,7 +867,7 @@ int sd_read_sectors(IF_MV2(int drive,) unsigned long start, int incount,
867#endif 867#endif
868 int ret; 868 int ret;
869 unsigned char *buf, *buf_end; 869 unsigned char *buf, *buf_end;
870 int bank; 870 unsigned int bank;
871 871
872 /* TODO: Add DMA support. */ 872 /* TODO: Add DMA support. */
873 873
@@ -932,7 +932,7 @@ sd_read_retry:
932 932
933 /* TODO: Don't assume BLOCK_SIZE == SECTOR_SIZE */ 933 /* TODO: Don't assume BLOCK_SIZE == SECTOR_SIZE */
934 934
935 buf_end = (unsigned char *)inbuf + incount * currcard->block_size; 935 buf_end = (unsigned char *)inbuf + incount * currcard->blocksize;
936 for (buf = inbuf; buf < buf_end;) 936 for (buf = inbuf; buf < buf_end;)
937 { 937 {
938 /* Wait for the FIFO to be full */ 938 /* Wait for the FIFO to be full */
@@ -987,7 +987,7 @@ int sd_write_sectors(IF_MV2(int drive,) unsigned long start, int count,
987#endif 987#endif
988 int ret; 988 int ret;
989 const unsigned char *buf, *buf_end; 989 const unsigned char *buf, *buf_end;
990 int bank; 990 unsigned int bank;
991 991
992 mutex_lock(&sd_mtx); 992 mutex_lock(&sd_mtx);
993 sd_enable(true); 993 sd_enable(true);
@@ -1048,7 +1048,7 @@ sd_write_retry:
1048 if (ret < 0) 1048 if (ret < 0)
1049 goto sd_write_error; 1049 goto sd_write_error;
1050 1050
1051 buf_end = outbuf + count * currcard->block_size - 2*FIFO_LEN; 1051 buf_end = outbuf + count * currcard->blocksize - 2*FIFO_LEN;
1052 1052
1053 for (buf = outbuf; buf <= buf_end;) 1053 for (buf = outbuf; buf <= buf_end;)
1054 { 1054 {
@@ -1305,13 +1305,13 @@ tCardInfo *card_get_info_target(int card_no)
1305 for(i=0; i<4; i++) card.csd[i] = card_info[card_no].csd[3-i]; 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]; 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; 1307 card.numblocks = card_info[card_no].numblocks;
1308 card.blocksize = card_info[card_no].block_size; 1308 card.blocksize = card_info[card_no].blocksize;
1309 temp = card_extract_bits(card.csd, 29, 3); 1309 temp = card_extract_bits(card.csd, 29, 3);
1310 card.speed = mantissa[card_extract_bits(card.csd, 25, 4)] 1310 card.speed = mantissa[card_extract_bits(card.csd, 25, 4)]
1311 * exponent[temp > 2 ? 7 : temp + 4]; 1311 * exponent[temp > 2 ? 7 : temp + 4];
1312 card.nsac = 100 * card_extract_bits(card.csd, 16, 8); 1312 card.nsac = 100 * card_extract_bits(card.csd, 16, 8);
1313 temp = card_extract_bits(card.csd, 13, 3); 1313 temp = card_extract_bits(card.csd, 13, 3);
1314 card.tsac = mantissa[card_extract_bits(card.csd, 9, 4)] 1314 card.taac = mantissa[card_extract_bits(card.csd, 9, 4)]
1315 * exponent[temp] / 10; 1315 * exponent[temp] / 10;
1316 card.cid[0] = htobe32(card.cid[0]); /* ascii chars here */ 1316 card.cid[0] = htobe32(card.cid[0]); /* ascii chars here */
1317 card.cid[1] = htobe32(card.cid[1]); /* ascii chars here */ 1317 card.cid[1] = htobe32(card.cid[1]); /* ascii chars here */
@@ -1381,7 +1381,7 @@ void sd_get_info(IF_MV2(int drive,) struct storage_info *info)
1381#ifndef HAVE_MULTIVOLUME 1381#ifndef HAVE_MULTIVOLUME
1382 const int drive=0; 1382 const int drive=0;
1383#endif 1383#endif
1384 info->sector_size=card_info[drive].block_size; 1384 info->sector_size=card_info[drive].blocksize;
1385 info->num_sectors=card_info[drive].numblocks; 1385 info->num_sectors=card_info[drive].numblocks;
1386 info->vendor="Rockbox"; 1386 info->vendor="Rockbox";
1387 if(drive==0) 1387 if(drive==0)