mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-08 12:45:26 -05:00
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
This commit is contained in:
parent
c929310e55
commit
e0e24cbf0a
11 changed files with 112 additions and 122 deletions
|
|
@ -99,7 +99,7 @@ static void init_pl180_controller(const int drive);
|
|||
#define SECTOR_SIZE 512
|
||||
#define BLOCKS_PER_BANK 0x7a7800
|
||||
|
||||
static tSDCardInfo card_info[NUM_VOLUMES];
|
||||
static tCardInfo card_info[NUM_VOLUMES];
|
||||
|
||||
/* maximum timeouts recommanded in the SD Specification v2.00 */
|
||||
#define SD_MAX_READ_TIMEOUT ((AS3525_PCLK_FREQ) / 1000 * 100) /* 100 ms */
|
||||
|
|
@ -181,7 +181,7 @@ void INT_MCI0(void)
|
|||
#endif
|
||||
|
||||
static bool send_cmd(const int drive, const int cmd, const int arg,
|
||||
const int flags, int *response)
|
||||
const int flags, long *response)
|
||||
{
|
||||
int val, status;
|
||||
|
||||
|
|
@ -243,9 +243,10 @@ static int sd_init_card(const int drive)
|
|||
{
|
||||
unsigned int c_size;
|
||||
unsigned long c_mult;
|
||||
int response;
|
||||
unsigned long response;
|
||||
int max_tries = 100; /* max acmd41 attemps */
|
||||
bool sdhc;
|
||||
unsigned char temp;
|
||||
|
||||
if(!send_cmd(drive, SD_GO_IDLE_STATE, 0, MCI_NO_FLAGS, NULL))
|
||||
return -1;
|
||||
|
|
@ -286,6 +287,15 @@ static int sd_init_card(const int drive)
|
|||
card_info[drive].cid))
|
||||
return -5;
|
||||
|
||||
/* ascii chars here */
|
||||
card_info[drive].cid[0] = htobe32(card_info[drive].cid[0]);
|
||||
card_info[drive].cid[1] = htobe32(card_info[drive].cid[1]);
|
||||
|
||||
/* adjust year<=>month, 1997 <=> 2000 */
|
||||
temp = *((char*)card_info[drive].cid+13);
|
||||
*((char*)card_info[drive].cid+13) =
|
||||
(unsigned char)((temp >> 4) | (temp << 4)) + 3;
|
||||
|
||||
/* send RCA */
|
||||
if(!send_cmd(drive, SD_SEND_RELATIVE_ADDR, 0, MCI_RESP|MCI_ARG,
|
||||
&card_info[drive].rca))
|
||||
|
|
@ -299,23 +309,21 @@ static int sd_init_card(const int drive)
|
|||
/* These calculations come from the Sandisk SD card product manual */
|
||||
if( (card_info[drive].csd[3]>>30) == 0)
|
||||
{
|
||||
int max_read_bl_len;
|
||||
/* CSD version 1.0 */
|
||||
c_size = ((card_info[drive].csd[2] & 0x3ff) << 2) + (card_info[drive].csd[1]>>30) + 1;
|
||||
c_mult = 4 << ((card_info[drive].csd[1] >> 15) & 7);
|
||||
card_info[drive].max_read_bl_len = 1 << ((card_info[drive].csd[2] >> 16) & 15);
|
||||
card_info[drive].block_size = BLOCK_SIZE; /* Always use 512 byte blocks */
|
||||
card_info[drive].numblocks = c_size * c_mult * (card_info[drive].max_read_bl_len/512);
|
||||
card_info[drive].capacity = card_info[drive].numblocks * card_info[drive].block_size;
|
||||
max_read_bl_len = 1 << ((card_info[drive].csd[2] >> 16) & 15);
|
||||
card_info[drive].blocksize = BLOCK_SIZE; /* Always use 512 byte blocks */
|
||||
card_info[drive].numblocks = c_size * c_mult * (max_read_bl_len/512);
|
||||
}
|
||||
#ifdef HAVE_MULTIVOLUME
|
||||
else if( (card_info[drive].csd[3]>>30) == 1)
|
||||
{
|
||||
/* CSD version 2.0 */
|
||||
c_size = ((card_info[drive].csd[2] & 0x3f) << 16) + (card_info[drive].csd[1]>>16) + 1;
|
||||
card_info[drive].max_read_bl_len = 1 << ((card_info[drive].csd[2] >> 16) & 0xf);
|
||||
card_info[drive].block_size = BLOCK_SIZE; /* Always use 512 byte blocks */
|
||||
card_info[drive].blocksize = BLOCK_SIZE; /* Always use 512 byte blocks */
|
||||
card_info[drive].numblocks = c_size << 10;
|
||||
card_info[drive].capacity = card_info[drive].numblocks * card_info[drive].block_size;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -328,7 +336,7 @@ static int sd_init_card(const int drive)
|
|||
if(!send_cmd(drive, SD_SET_BUS_WIDTH, card_info[drive].rca | 2, MCI_ARG, NULL))
|
||||
return -11;
|
||||
|
||||
if(!send_cmd(drive, SD_SET_BLOCKLEN, card_info[drive].block_size, MCI_ARG,
|
||||
if(!send_cmd(drive, SD_SET_BLOCKLEN, card_info[drive].blocksize, MCI_ARG,
|
||||
NULL))
|
||||
return -12;
|
||||
|
||||
|
|
@ -518,7 +526,7 @@ void sd_get_info(IF_MV2(int drive,) struct storage_info *info)
|
|||
#ifndef HAVE_MULTIVOLUME
|
||||
const int drive=0;
|
||||
#endif
|
||||
info->sector_size=card_info[drive].block_size;
|
||||
info->sector_size=card_info[drive].blocksize;
|
||||
info->num_sectors=card_info[drive].numblocks;
|
||||
info->vendor="Rockbox";
|
||||
info->product = (drive == 0) ? "Internal Storage" : "SD Card Slot";
|
||||
|
|
@ -546,7 +554,7 @@ bool sd_present(IF_MV_NONVOID(int drive))
|
|||
|
||||
static int sd_wait_for_state(const int drive, unsigned int state)
|
||||
{
|
||||
unsigned int response = 0;
|
||||
unsigned long response = 0;
|
||||
unsigned int timeout = 100; /* ticks */
|
||||
long t = current_tick;
|
||||
|
||||
|
|
@ -686,7 +694,7 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start,
|
|||
/* Only switch banks for internal storage */
|
||||
if(drive == INTERNAL_AS3525)
|
||||
{
|
||||
int bank = start / BLOCKS_PER_BANK; /* Current bank */
|
||||
unsigned int bank = start / BLOCKS_PER_BANK; /* Current bank */
|
||||
|
||||
/* Switch bank if needed */
|
||||
if(card_info[INTERNAL_AS3525].current_bank != bank)
|
||||
|
|
@ -737,7 +745,7 @@ static int sd_transfer_sectors(IF_MV2(int drive,) unsigned long start,
|
|||
* Note : the OF doesn't seem to use them anyway */
|
||||
MCI_DATA_TIMER(drive) = write ?
|
||||
SD_MAX_WRITE_TIMEOUT : SD_MAX_READ_TIMEOUT;
|
||||
MCI_DATA_LENGTH(drive) = transfer * card_info[drive].block_size;
|
||||
MCI_DATA_LENGTH(drive) = transfer * card_info[drive].blocksize;
|
||||
MCI_DATA_CTRL(drive) = (1<<0) /* enable */ |
|
||||
(!write<<1) /* transfer direction */ |
|
||||
(1<<3) /* DMA */ |
|
||||
|
|
@ -867,35 +875,24 @@ void sd_enable(bool on)
|
|||
}
|
||||
}
|
||||
|
||||
/* move the sd-card info to mmc struct */
|
||||
tCardInfo *card_get_info_target(int card_no)
|
||||
{
|
||||
int i, temp;
|
||||
static tCardInfo card;
|
||||
static const char mantissa[] = { /* *10 */
|
||||
0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 };
|
||||
static const int exponent[] = { /* use varies */
|
||||
1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000 };
|
||||
unsigned char temp;
|
||||
tCardInfo *card = &card_info[card_no];
|
||||
|
||||
card.initialized = card_info[card_no].initialized;
|
||||
card.ocr = card_info[card_no].ocr;
|
||||
for(i=0; i<4; i++) card.csd[i] = card_info[card_no].csd[i];
|
||||
for(i=0; i<4; i++) card.cid[i] = card_info[card_no].cid[i];
|
||||
card.numblocks = card_info[card_no].numblocks;
|
||||
card.blocksize = card_info[card_no].block_size;
|
||||
temp = card_extract_bits(card.csd, 29, 3);
|
||||
card.speed = mantissa[card_extract_bits(card.csd, 25, 4)]
|
||||
* exponent[temp > 2 ? 7 : temp + 4];
|
||||
card.nsac = 100 * card_extract_bits(card.csd, 16, 8);
|
||||
temp = card_extract_bits(card.csd, 13, 3);
|
||||
card.tsac = mantissa[card_extract_bits(card.csd, 9, 4)]
|
||||
* exponent[temp] / 10;
|
||||
card.cid[0] = htobe32(card.cid[0]); /* ascii chars here */
|
||||
card.cid[1] = htobe32(card.cid[1]); /* ascii chars here */
|
||||
temp = *((char*)card.cid+13); /* adjust year<=>month, 1997 <=> 2000 */
|
||||
*((char*)card.cid+13) = (unsigned char)((temp >> 4) | (temp << 4)) + 3;
|
||||
temp = card->csd[3];
|
||||
card->speed = sd_mantissa[temp & 7] * sd_exponent[(temp >> 3) & 0xf];
|
||||
|
||||
return &card;
|
||||
temp = card->csd[3] >> 8;
|
||||
card->nsac = 100 * temp;
|
||||
|
||||
temp = (card->csd[3] >> 16) & 0x7f; /* bit 7 reserved */
|
||||
card->taac = sd_mantissa[temp >> 3] * sd_exponent[temp & 7];
|
||||
|
||||
temp = (card->csd[0] >> 26) & 7;
|
||||
card->r2w_factor = temp;
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
bool card_detect_target(void)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@
|
|||
#include "config.h" /* for HAVE_MULTIVOLUME */
|
||||
#include "fat.h"
|
||||
#include "hotswap.h"
|
||||
#include "ata-sd-target.h"
|
||||
#ifdef HAVE_HOTSWAP
|
||||
#include "sd-pp-target.h"
|
||||
#endif
|
||||
#include "ata_idle_notify.h"
|
||||
#include "system.h"
|
||||
#include <string.h>
|
||||
|
|
@ -156,8 +158,8 @@ static bool initialized = false;
|
|||
static long next_yield = 0;
|
||||
#define MIN_YIELD_PERIOD 1000
|
||||
|
||||
static tSDCardInfo card_info[2];
|
||||
static tSDCardInfo *currcard = NULL; /* current active card */
|
||||
static tCardInfo card_info[2];
|
||||
static tCardInfo *currcard = NULL; /* current active card */
|
||||
|
||||
struct sd_card_status
|
||||
{
|
||||
|
|
@ -222,7 +224,7 @@ static bool sd_poll_status(unsigned int trigger, long timeout)
|
|||
}
|
||||
|
||||
static int sd_command(unsigned int cmd, unsigned long arg1,
|
||||
unsigned int *response, unsigned int cmdat)
|
||||
unsigned long *response, unsigned int cmdat)
|
||||
{
|
||||
int i, words; /* Number of 16 bit words to read from MMC_RES */
|
||||
unsigned int data[9];
|
||||
|
|
@ -303,7 +305,7 @@ static int sd_command(unsigned int cmd, unsigned long arg1,
|
|||
|
||||
static int sd_wait_for_state(unsigned int state, int id)
|
||||
{
|
||||
unsigned int response = 0;
|
||||
unsigned long response = 0;
|
||||
unsigned int timeout = 0x80000;
|
||||
|
||||
check_time[id] = USEC_TIMER;
|
||||
|
|
@ -647,7 +649,7 @@ static void sd_init_device(int card_no)
|
|||
{
|
||||
/* SD Protocol registers */
|
||||
#ifdef HAVE_HOTSWAP
|
||||
unsigned int response = 0;
|
||||
unsigned long response = 0;
|
||||
#endif
|
||||
unsigned int i;
|
||||
unsigned int c_size;
|
||||
|
|
@ -746,23 +748,21 @@ static void sd_init_device(int card_no)
|
|||
/* These calculations come from the Sandisk SD card product manual */
|
||||
if( (currcard->csd[3]>>30) == 0)
|
||||
{
|
||||
int max_read_bl_len;
|
||||
/* CSD version 1.0 */
|
||||
c_size = ((currcard->csd[2] & 0x3ff) << 2) + (currcard->csd[1]>>30) + 1;
|
||||
c_mult = 4 << ((currcard->csd[1] >> 15) & 7);
|
||||
currcard->max_read_bl_len = 1 << ((currcard->csd[2] >> 16) & 15);
|
||||
currcard->block_size = BLOCK_SIZE; /* Always use 512 byte blocks */
|
||||
currcard->numblocks = c_size * c_mult * (currcard->max_read_bl_len/512);
|
||||
currcard->capacity = currcard->numblocks * currcard->block_size;
|
||||
max_read_bl_len = 1 << ((currcard->csd[2] >> 16) & 15);
|
||||
currcard->blocksize = BLOCK_SIZE; /* Always use 512 byte blocks */
|
||||
currcard->numblocks = c_size * c_mult * (max_read_bl_len/512);
|
||||
}
|
||||
#ifdef HAVE_HOTSWAP
|
||||
else if( (currcard->csd[3]>>30) == 1)
|
||||
{
|
||||
/* CSD version 2.0 */
|
||||
c_size = ((currcard->csd[2] & 0x3f) << 16) + (currcard->csd[1]>>16) + 1;
|
||||
currcard->max_read_bl_len = 1 << ((currcard->csd[2] >> 16) & 0xf);
|
||||
currcard->block_size = BLOCK_SIZE; /* Always use 512 byte blocks */
|
||||
currcard->blocksize = BLOCK_SIZE; /* Always use 512 byte blocks */
|
||||
currcard->numblocks = c_size << 10;
|
||||
currcard->capacity = currcard->numblocks * currcard->block_size;
|
||||
}
|
||||
#endif /* HAVE_HOTSWAP */
|
||||
|
||||
|
|
@ -782,12 +782,12 @@ static void sd_init_device(int card_no)
|
|||
if (ret < 0)
|
||||
goto card_init_error;
|
||||
|
||||
ret = sd_command(SD_SET_BLOCKLEN, currcard->block_size, NULL,
|
||||
ret = sd_command(SD_SET_BLOCKLEN, currcard->blocksize, NULL,
|
||||
CMDAT_RES_TYPE1);
|
||||
if (ret < 0)
|
||||
goto card_init_error;
|
||||
|
||||
MMC_BLKLEN = currcard->block_size;
|
||||
MMC_BLKLEN = currcard->blocksize;
|
||||
|
||||
/* If this card is >4GB & not SDHC, then we need to enable bank switching */
|
||||
if( (currcard->numblocks >= BLOCKS_PER_BANK) &&
|
||||
|
|
@ -867,7 +867,7 @@ int sd_read_sectors(IF_MV2(int drive,) unsigned long start, int incount,
|
|||
#endif
|
||||
int ret;
|
||||
unsigned char *buf, *buf_end;
|
||||
int bank;
|
||||
unsigned int bank;
|
||||
|
||||
/* TODO: Add DMA support. */
|
||||
|
||||
|
|
@ -932,7 +932,7 @@ sd_read_retry:
|
|||
|
||||
/* TODO: Don't assume BLOCK_SIZE == SECTOR_SIZE */
|
||||
|
||||
buf_end = (unsigned char *)inbuf + incount * currcard->block_size;
|
||||
buf_end = (unsigned char *)inbuf + incount * currcard->blocksize;
|
||||
for (buf = inbuf; buf < buf_end;)
|
||||
{
|
||||
/* Wait for the FIFO to be full */
|
||||
|
|
@ -987,7 +987,7 @@ int sd_write_sectors(IF_MV2(int drive,) unsigned long start, int count,
|
|||
#endif
|
||||
int ret;
|
||||
const unsigned char *buf, *buf_end;
|
||||
int bank;
|
||||
unsigned int bank;
|
||||
|
||||
mutex_lock(&sd_mtx);
|
||||
sd_enable(true);
|
||||
|
|
@ -1048,7 +1048,7 @@ sd_write_retry:
|
|||
if (ret < 0)
|
||||
goto sd_write_error;
|
||||
|
||||
buf_end = outbuf + count * currcard->block_size - 2*FIFO_LEN;
|
||||
buf_end = outbuf + count * currcard->blocksize - 2*FIFO_LEN;
|
||||
|
||||
for (buf = outbuf; buf <= buf_end;)
|
||||
{
|
||||
|
|
@ -1305,13 +1305,13 @@ tCardInfo *card_get_info_target(int card_no)
|
|||
for(i=0; i<4; i++) card.csd[i] = card_info[card_no].csd[3-i];
|
||||
for(i=0; i<4; i++) card.cid[i] = card_info[card_no].cid[3-i];
|
||||
card.numblocks = card_info[card_no].numblocks;
|
||||
card.blocksize = card_info[card_no].block_size;
|
||||
card.blocksize = card_info[card_no].blocksize;
|
||||
temp = card_extract_bits(card.csd, 29, 3);
|
||||
card.speed = mantissa[card_extract_bits(card.csd, 25, 4)]
|
||||
* exponent[temp > 2 ? 7 : temp + 4];
|
||||
card.nsac = 100 * card_extract_bits(card.csd, 16, 8);
|
||||
temp = card_extract_bits(card.csd, 13, 3);
|
||||
card.tsac = mantissa[card_extract_bits(card.csd, 9, 4)]
|
||||
card.taac = mantissa[card_extract_bits(card.csd, 9, 4)]
|
||||
* exponent[temp] / 10;
|
||||
card.cid[0] = htobe32(card.cid[0]); /* ascii chars here */
|
||||
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)
|
|||
#ifndef HAVE_MULTIVOLUME
|
||||
const int drive=0;
|
||||
#endif
|
||||
info->sector_size=card_info[drive].block_size;
|
||||
info->sector_size=card_info[drive].blocksize;
|
||||
info->num_sectors=card_info[drive].numblocks;
|
||||
info->vendor="Rockbox";
|
||||
if(drive==0)
|
||||
|
|
|
|||
|
|
@ -21,32 +21,12 @@
|
|||
#ifndef ATA_SD_TARGET_H
|
||||
#define ATA_SD_TARGET_H
|
||||
|
||||
#include "inttypes.h"
|
||||
#include "hotswap.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int initialized;
|
||||
|
||||
unsigned int ocr; /* OCR register */
|
||||
unsigned int csd[4]; /* CSD register */
|
||||
unsigned int cid[4]; /* CID register */
|
||||
unsigned int rca;
|
||||
|
||||
uint64_t capacity; /* size in bytes */
|
||||
unsigned long numblocks; /* size in flash blocks */
|
||||
unsigned int block_size; /* block size in bytes */
|
||||
unsigned int max_read_bl_len;/* max read data block length */
|
||||
unsigned int block_exp; /* block size exponent */
|
||||
unsigned char current_bank; /* The bank that we are working with */
|
||||
} tSDCardInfo;
|
||||
|
||||
tCardInfo *card_get_info_target(int card_no);
|
||||
bool card_detect_target(void);
|
||||
#ifdef CPU_PP /* PortalPlayer specific functions */
|
||||
|
||||
#ifdef HAVE_HOTSWAP
|
||||
void card_enable_monitoring_target(bool on);
|
||||
void microsd_int(void);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -23,7 +23,9 @@
|
|||
#include "i2s.h"
|
||||
#include "i2c-pp.h"
|
||||
#include "as3514.h"
|
||||
#include "ata-sd-target.h"
|
||||
#ifdef HAVE_HOTSWAP
|
||||
#include "sd-pp-target.h"
|
||||
#endif
|
||||
#include "button-target.h"
|
||||
#include "usb-target.h"
|
||||
#include "usb_drv.h"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue