summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/imx233/sd-imx233.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx233/sd-imx233.c')
-rw-r--r--firmware/target/arm/imx233/sd-imx233.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/firmware/target/arm/imx233/sd-imx233.c b/firmware/target/arm/imx233/sd-imx233.c
index ccd8bf35c1..5e9f2cf030 100644
--- a/firmware/target/arm/imx233/sd-imx233.c
+++ b/firmware/target/arm/imx233/sd-imx233.c
@@ -22,9 +22,54 @@
#include "system.h"
#include "sd.h"
#include "sdmmc.h"
+#include "ssp-imx233.h"
+#include "pinctrl-imx233.h"
+#include "button-target.h"
+
+/**
+ * This code assumes a single SD card slot
+ */
+
+#ifdef SANSA_FUZEPLUS
+#define SD_SSP 1
+#else
+#error You need to configure the ssp to use
+#endif
+
+static tCardInfo card_info;
+static struct mutex sd_mutex;
+
+static void sd_detect_callback(int ssp)
+{
+ (void)ssp;
+
+ /* This is called only if the state was stable for 300ms - check state
+ * and post appropriate event. */
+ if(imx233_ssp_sdmmc_detect(SD_SSP))
+ queue_broadcast(SYS_HOTSWAP_INSERTED, 0);
+ else
+ queue_broadcast(SYS_HOTSWAP_EXTRACTED, 0);
+ printf("sd_detect_callback(%d)", imx233_ssp_sdmmc_detect(SD_SSP));
+ imx233_ssp_sdmmc_setup_detect(SD_SSP, true, sd_detect_callback);
+}
int sd_init(void)
{
+ mutex_init(&sd_mutex);
+
+ imx233_ssp_start(SD_SSP);
+ imx233_ssp_softreset(SD_SSP);
+ imx233_ssp_set_mode(SD_SSP, HW_SSP_CTRL1__SSP_MODE__SD_MMC);
+ #ifdef SANSA_FUZEPLUS
+ imx233_ssp_setup_ssp1_sd_mmc_pins(true, 4, PINCTRL_DRIVE_8mA, false);
+ #endif
+ imx233_ssp_sdmmc_setup_detect(SD_SSP, true, sd_detect_callback);
+ /* SSPCLK @ 96MHz
+ * gives bitrate of 96000 / 240 / 1 = 400kHz */
+ imx233_ssp_set_timings(SD_SSP, 240, 0, 0xffff);
+ imx233_ssp_set_bus_width(SD_SSP, 1);
+ imx233_ssp_set_block_size(SD_SSP, 9);
+
return 0;
}
@@ -57,6 +102,12 @@ tCardInfo *card_get_info_target(int card_no)
int sd_num_drives(int first_drive)
{
(void) first_drive;
- return 0;
+ return 1;
+}
+
+bool sd_present(IF_MD(int drive))
+{
+ IF_MD((void) drive);
+ return imx233_ssp_sdmmc_detect(SD_SSP);
}