diff options
Diffstat (limited to 'firmware/target/arm/imx233/sd-imx233.c')
-rw-r--r-- | firmware/target/arm/imx233/sd-imx233.c | 53 |
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 @@ | |||
22 | #include "system.h" | 22 | #include "system.h" |
23 | #include "sd.h" | 23 | #include "sd.h" |
24 | #include "sdmmc.h" | 24 | #include "sdmmc.h" |
25 | #include "ssp-imx233.h" | ||
26 | #include "pinctrl-imx233.h" | ||
27 | #include "button-target.h" | ||
28 | |||
29 | /** | ||
30 | * This code assumes a single SD card slot | ||
31 | */ | ||
32 | |||
33 | #ifdef SANSA_FUZEPLUS | ||
34 | #define SD_SSP 1 | ||
35 | #else | ||
36 | #error You need to configure the ssp to use | ||
37 | #endif | ||
38 | |||
39 | static tCardInfo card_info; | ||
40 | static struct mutex sd_mutex; | ||
41 | |||
42 | static void sd_detect_callback(int ssp) | ||
43 | { | ||
44 | (void)ssp; | ||
45 | |||
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); | ||
54 | } | ||
25 | 55 | ||
26 | int sd_init(void) | 56 | int sd_init(void) |
27 | { | 57 | { |
58 | mutex_init(&sd_mutex); | ||
59 | |||
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); | ||
72 | |||
28 | return 0; | 73 | return 0; |
29 | } | 74 | } |
30 | 75 | ||
@@ -57,6 +102,12 @@ tCardInfo *card_get_info_target(int card_no) | |||
57 | int sd_num_drives(int first_drive) | 102 | int sd_num_drives(int first_drive) |
58 | { | 103 | { |
59 | (void) first_drive; | 104 | (void) first_drive; |
60 | return 0; | 105 | return 1; |
106 | } | ||
107 | |||
108 | bool sd_present(IF_MD(int drive)) | ||
109 | { | ||
110 | IF_MD((void) drive); | ||
111 | return imx233_ssp_sdmmc_detect(SD_SSP); | ||
61 | } | 112 | } |
62 | 113 | ||