hm60x/hm801: Fix blinking white screen.
[maemo-rb.git] / firmware / sdmmc.c
blobbb3820f9300caae093d95517eaf8e0fafd0b8b87
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2004 by Jens Arnold
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 ****************************************************************************/
21 #include "config.h"
22 #include "sdmmc.h"
24 /* helper function to extract n (<=32) bits from an arbitrary position.
25 counting from MSB to LSB */
26 unsigned long card_extract_bits(
27 const unsigned long *p, /* the start of the bitfield array */
28 unsigned int start, /* bit no. to start reading */
29 unsigned int size) /* how many bits to read */
31 unsigned int long_index, bit_index;
32 unsigned long result;
34 /* we assume words of CSD/CID are stored most significant word first */
35 start = 127 - start;
37 long_index = start / 32;
38 bit_index = start % 32;
40 result = p[long_index] << bit_index;
42 if (bit_index + size > 32) /* crossing longword boundary */
43 result |= p[long_index+1] >> (32 - bit_index);
45 result >>= 32 - size;
47 return result;