1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
25 #include "ssp-imx233.h"
26 #include "pinctrl-imx233.h"
27 #include "button-target.h"
30 * This code assumes a single SD card slot
36 #error You need to configure the ssp to use
39 static tCardInfo card_info
;
40 static struct mutex sd_mutex
;
42 static void sd_detect_callback(int 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);
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
);
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
);
64 imx233_ssp_setup_ssp1_sd_mmc_pins(true, 4, PINCTRL_DRIVE_8mA
, false);
66 imx233_ssp_sdmmc_setup_detect(SD_SSP
, true, sd_detect_callback
);
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);
76 int sd_read_sectors(IF_MD2(int drive
,) unsigned long start
, int count
,
86 int sd_write_sectors(IF_MD2(int drive
,) unsigned long start
, int count
,
96 tCardInfo
*card_get_info_target(int card_no
)
102 int sd_num_drives(int first_drive
)
108 bool sd_present(IF_MD(int drive
))
111 return imx233_ssp_sdmmc_detect(SD_SSP
);