imx233/fuze+: add SD detection support
[kugel-rb.git] / firmware / target / arm / imx233 / sd-imx233.c
blob5e9f2cf0304f51e3ba5b93173cea38795f52a4b6
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2011 by Amaury Pouly
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 "system.h"
23 #include "sd.h"
24 #include "sdmmc.h"
25 #include "ssp-imx233.h"
26 #include "pinctrl-imx233.h"
27 #include "button-target.h"
29 /**
30 * This code assumes a single SD card slot
33 #ifdef SANSA_FUZEPLUS
34 #define SD_SSP 1
35 #else
36 #error You need to configure the ssp to use
37 #endif
39 static tCardInfo card_info;
40 static struct mutex sd_mutex;
42 static void sd_detect_callback(int ssp)
44 (void)ssp;
46 /* This is called only if the state was stable for 300ms - check state
47 * and post appropriate event. */
48 if(imx233_ssp_sdmmc_detect(SD_SSP))
49 queue_broadcast(SYS_HOTSWAP_INSERTED, 0);
50 else
51 queue_broadcast(SYS_HOTSWAP_EXTRACTED, 0);
52 printf("sd_detect_callback(%d)", imx233_ssp_sdmmc_detect(SD_SSP));
53 imx233_ssp_sdmmc_setup_detect(SD_SSP, true, sd_detect_callback);
56 int sd_init(void)
58 mutex_init(&sd_mutex);
60 imx233_ssp_start(SD_SSP);
61 imx233_ssp_softreset(SD_SSP);
62 imx233_ssp_set_mode(SD_SSP, HW_SSP_CTRL1__SSP_MODE__SD_MMC);
63 #ifdef SANSA_FUZEPLUS
64 imx233_ssp_setup_ssp1_sd_mmc_pins(true, 4, PINCTRL_DRIVE_8mA, false);
65 #endif
66 imx233_ssp_sdmmc_setup_detect(SD_SSP, true, sd_detect_callback);
67 /* SSPCLK @ 96MHz
68 * gives bitrate of 96000 / 240 / 1 = 400kHz */
69 imx233_ssp_set_timings(SD_SSP, 240, 0, 0xffff);
70 imx233_ssp_set_bus_width(SD_SSP, 1);
71 imx233_ssp_set_block_size(SD_SSP, 9);
73 return 0;
76 int sd_read_sectors(IF_MD2(int drive,) unsigned long start, int count,
77 void* buf)
79 IF_MD((void) drive);
80 (void) start;
81 (void) count;
82 (void) buf;
83 return -1;
86 int sd_write_sectors(IF_MD2(int drive,) unsigned long start, int count,
87 const void* buf)
89 IF_MD((void) drive);
90 (void) start;
91 (void) count;
92 (void) buf;
93 return -1;
96 tCardInfo *card_get_info_target(int card_no)
98 (void)card_no;
99 return NULL;
102 int sd_num_drives(int first_drive)
104 (void) first_drive;
105 return 1;
108 bool sd_present(IF_MD(int drive))
110 IF_MD((void) drive);
111 return imx233_ssp_sdmmc_detect(SD_SSP);