Quickscreen: add more check for case that qs item is not set.
[kugel-rb.git] / firmware / drivers / sd.c
blob94b7c0a7f40d0ced9621fdc8acb7d153d772c23e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include "config.h"
23 #include "logf.h"
24 #include "hotswap.h"
25 #include "storage.h"
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);
36 if(csd_version == 0)
38 /* CSD version 1.0 */
39 int max_read_bl_len;
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)
48 /* CSD version 2.0 */
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:%ld speed:%ld", csd_version+1, card->numblocks, card->speed);
66 logf("nsac: %d taac: %ld r2w: %d", card->nsac, card->taac, card->r2w_factor);
69 void sd_sleep(void)
73 void sd_spin(void)
77 void sd_spindown(int seconds)
79 (void)seconds;
82 #ifdef STORAGE_GET_INFO
83 void sd_get_info(IF_MD2(int drive,) struct storage_info *info)
85 #ifndef HAVE_MULTIDRIVE
86 const int drive=0;
87 #endif
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";
98 #endif
99 info->revision="0.00";
101 #endif