1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright © 2009 by Rafaël Carré
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
27 static const unsigned char sd_mantissa
[] = { /* *10 */
28 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 };
29 static const unsigned int sd_exponent
[] = { /* use varies */
30 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000 };
32 void sd_parse_csd(tCardInfo
*card
)
34 unsigned int c_size
, c_mult
;
35 const int csd_version
= card_extract_bits(card
->csd
, 127, 2);
41 c_size
= card_extract_bits(card
->csd
, 73, 12) + 1;
42 c_mult
= 4 << card_extract_bits(card
->csd
, 49, 3);
43 max_read_bl_len
= 1 << card_extract_bits(card
->csd
, 83, 4);
44 card
->numblocks
= c_size
* c_mult
* (max_read_bl_len
/512);
46 else if(csd_version
== 1)
49 c_size
= card_extract_bits(card
->csd
, 69, 22) + 1;
50 card
->numblocks
= c_size
<< 10;
53 card
->blocksize
= 512; /* Always use 512 byte blocks */
55 card
->speed
= sd_mantissa
[card_extract_bits(card
->csd
, 102, 4)] *
56 sd_exponent
[card_extract_bits(card
->csd
, 98, 3) + 4];
58 card
->nsac
= 100 * card_extract_bits(card
->csd
, 111, 8);
60 card
->taac
= sd_mantissa
[card_extract_bits(card
->csd
, 118, 4)] *
61 sd_exponent
[card_extract_bits(card
->csd
, 114, 3)];
63 card
->r2w_factor
= card_extract_bits(card
->csd
, 28, 3);
65 logf("CSD%d.0 numblocks:%d speed:%d", csd_version
+1, card
->numblocks
, card
->speed
);
66 logf("nsac: %d taac: %d r2w: %d", card
->nsac
, card
->taac
, card
->r2w_factor
);
77 void sd_spindown(int seconds
)
82 #ifdef STORAGE_GET_INFO
83 void sd_get_info(IF_MV2(int drive
,) struct storage_info
*info
)
85 #ifndef HAVE_MULTIVOLUME
89 tCardInfo
*card
= card_get_info_target(drive
);
91 info
->sector_size
=card
->blocksize
;
92 info
->num_sectors
=card
->numblocks
;
93 info
->vendor
="Rockbox";
94 #if CONFIG_STORAGE == STORAGE_SD
95 info
->product
= (drive
==0) ? "Internal Storage" : "SD Card Slot";
96 #else /* Internal storage is not SD */
97 info
->product
= "SD Card Slot";
99 info
->revision
="0.00";