summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx233/mmc-imx233.c
diff options
context:
space:
mode:
authorAmaury Pouly <pamaury@rockbox.org>2011-06-17 22:30:58 +0000
committerAmaury Pouly <pamaury@rockbox.org>2011-06-17 22:30:58 +0000
commit2cf33133820ee17e4b5d2d622db15dedff1a1f6e (patch)
tree60eddf4c3f16d5d274bc111ce53db02cfe75a6e8 /firmware/target/arm/imx233/mmc-imx233.c
parentd4800fa3851d2d89c1be03ec99af81f277892579 (diff)
downloadrockbox-2cf33133820ee17e4b5d2d622db15dedff1a1f6e.tar.gz
rockbox-2cf33133820ee17e4b5d2d622db15dedff1a1f6e.zip
fuze+: add more clocking code, add dma code, add ssp code, add stub usb code, update storage to SD + MMC, beginning of the driver
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30010 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/imx233/mmc-imx233.c')
-rw-r--r--firmware/target/arm/imx233/mmc-imx233.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/mmc-imx233.c b/firmware/target/arm/imx233/mmc-imx233.c
new file mode 100644
index 0000000000..f56ff3725c
--- /dev/null
+++ b/firmware/target/arm/imx233/mmc-imx233.c
@@ -0,0 +1,100 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 by Amaury Pouly
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#include "config.h"
22#include "system.h"
23#include "mmc.h"
24#include "sdmmc.h"
25#include "ssp-imx233.h"
26#include "pinctrl-imx233.h"
27#include "button-target.h"
28
29#ifdef SANSA_FUZEPLUS
30#define MMC_SSP 2
31#else
32#error You need to configure the ssp to use
33#endif
34
35int mmc_init(void)
36{
37 imx233_ssp_start(MMC_SSP);
38 imx233_ssp_softreset(MMC_SSP);
39 imx233_ssp_set_mode(MMC_SSP, HW_SSP_CTRL1__SSP_MODE__SD_MMC);
40 #ifdef SANSA_FUZEPLUS
41 /** Sansa Fuze+ has an internal eMMC 8-bit wide flash, power gate is pin PWM3 */
42 imx233_set_pin_function(1, 29, PINCTRL_FUNCTION_GPIO);
43 imx233_enable_gpio_output(1, 29, true);
44 imx233_set_gpio_output(1, 29, false);
45
46 imx233_ssp_setup_ssp2_sd_mmc_pins(true, 8, PINCTRL_DRIVE_8mA);
47 #endif
48 /* SSPCLK @ 120MHz
49 * gives bitrate of 120 / 100 / 3 = 400kHz */
50 imx233_ssp_set_timings(MMC_SSP, 100, 2);
51 imx233_ssp_set_timeout(MMC_SSP, 0xffff);
52 imx233_ssp_sd_mmc_power_up_sequence(MMC_SSP);
53 /* go to idle state */
54 int ret = imx233_ssp_sd_mmc_transfer(MMC_SSP, SD_GO_IDLE_STATE, 0, SSP_NO_RESP, NULL, 0, false, NULL);
55 if(ret != 0)
56 return -1;
57 /* send op cond until the card respond with busy bit set; it must complete within 1sec */
58 unsigned timeout = current_tick + HZ;
59 do
60 {
61 uint32_t ocr;
62 ret = imx233_ssp_sd_mmc_transfer(MMC_SSP, 1, 0x40ff8000, SSP_SHORT_RESP, NULL, 0, false, &ocr);
63 if(ret == 0 && ocr & (1 << 31))
64 break;
65 }while(!TIME_AFTER(current_tick, timeout));
66
67 if(ret != 0)
68 return -2;
69
70 uint32_t cid[4];
71 ret = imx233_ssp_sd_mmc_transfer(MMC_SSP, 2, 0, SSP_LONG_RESP, NULL, 0, false, cid);
72 if(ret != 0)
73 return -3;
74
75 return 0;
76}
77
78int mmc_num_drives(int first_drive)
79{
80 (void) first_drive;
81 return 1;
82}
83
84int mmc_read_sectors(IF_MD2(int drive,) unsigned long start, int count, void* buf)
85{
86 IF_MD((void) drive);
87 (void) start;
88 (void) count;
89 (void) buf;
90 return -1;
91}
92
93int mmc_write_sectors(IF_MD2(int drive,) unsigned long start, int count, const void* buf)
94{
95 IF_MD((void) drive);
96 (void) start;
97 (void) count;
98 (void) buf;
99 return -1;
100}