summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2009-07-01 21:49:13 +0000
committerRafaël Carré <rafael.carre@gmail.com>2009-07-01 21:49:13 +0000
commitc0eb9aeb9e89ae33a9f084167147d8eacb9c7c60 (patch)
tree57e96460989d9cccc421486769befb5648601b8c /firmware/drivers
parent93f6e3df246ff50c24524c9d329f27a06e1845db (diff)
downloadrockbox-c0eb9aeb9e89ae33a9f084167147d8eacb9c7c60.tar.gz
rockbox-c0eb9aeb9e89ae33a9f084167147d8eacb9c7c60.zip
add firmware/driver/sd.c which contains common code between SD drivers
ingenic SD driver needs more cleanup so it still doesn't use the common code correct a comment in hotswap.c: card_extract_bits assume most significant word of register first (so, use this order) fix debug menu which used MMC specific commands / bits positions in csd/cid move the default block size of 512 into sd.h move the mantissa & exponent table into a single file (sd.c) to reduce binsize. we don't need to export it anymore anyway TODO : ingenic cleanup (will happen soon so building sd.c is not conditional) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21601 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/sd.c64
1 files changed, 64 insertions, 0 deletions
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
25static const unsigned char sd_mantissa[] = { /* *10 */
26 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 };
27static const unsigned int sd_exponent[] = { /* use varies */
28 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000 };
29
30void 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}