summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/imx233/ssp-imx233.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2012-05-19 13:45:29 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2012-05-19 16:10:52 +0200
commit8b53c0f9a9cd421c90913032081b1c292ddb0806 (patch)
tree7afac426c344ec686d4202a78c854199b3cd6a3c /firmware/target/arm/imx233/ssp-imx233.c
parent3f59cf97089d2efef51fd7f231712bef2c154b21 (diff)
downloadrockbox-8b53c0f9a9cd421c90913032081b1c292ddb0806.tar.gz
rockbox-8b53c0f9a9cd421c90913032081b1c292ddb0806.tar.bz2
rockbox-8b53c0f9a9cd421c90913032081b1c292ddb0806.zip
imx233: completely rework the sd driver
Change-Id: I456df0d9f5eaee435bdfd5a3f667055715e53d2a
Diffstat (limited to 'firmware/target/arm/imx233/ssp-imx233.c')
-rw-r--r--firmware/target/arm/imx233/ssp-imx233.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/firmware/target/arm/imx233/ssp-imx233.c b/firmware/target/arm/imx233/ssp-imx233.c
index 1dd2d767ba..21dcba67aa 100644
--- a/firmware/target/arm/imx233/ssp-imx233.c
+++ b/firmware/target/arm/imx233/ssp-imx233.c
@@ -28,6 +28,13 @@
#include "pinctrl-imx233.h"
#include "dma-imx233.h"
+/* for debug purpose */
+#if 0
+#define ASSERT_SSP(ssp) if(ssp < 1 || ssp > 2) panicf("ssp=%d in %s", ssp, __func__);
+#else
+#define ASSERT_SSP(ssp)
+#endif
+
/* Used for DMA */
struct ssp_dma_command_t
{
@@ -46,6 +53,7 @@ static struct ssp_dma_command_t ssp_dma_cmd[2];
static uint32_t ssp_bus_width[2];
static unsigned ssp_log_block_size[2];
static ssp_detect_cb_t ssp_detect_cb[2];
+static bool ssp_detect_invert[2];
void INT_SSP(int ssp)
{
@@ -93,6 +101,7 @@ void imx233_ssp_init(void)
void imx233_ssp_start(int ssp)
{
+ ASSERT_SSP(ssp)
if(ssp_in_use[ssp - 1])
return;
ssp_in_use[ssp - 1] = true;
@@ -117,6 +126,7 @@ void imx233_ssp_start(int ssp)
void imx233_ssp_stop(int ssp)
{
+ ASSERT_SSP(ssp)
if(!ssp_in_use[ssp - 1])
return;
ssp_in_use[ssp - 1] = false;
@@ -135,11 +145,13 @@ void imx233_ssp_stop(int ssp)
void imx233_ssp_softreset(int ssp)
{
+ ASSERT_SSP(ssp)
imx233_reset_block(&HW_SSP_CTRL0(ssp));
}
void imx233_ssp_set_timings(int ssp, int divide, int rate, int timeout)
{
+ ASSERT_SSP(ssp)
HW_SSP_TIMING(ssp) = divide << HW_SSP_TIMING__CLOCK_DIVIDE_BP | rate |
timeout << HW_SSP_TIMING__CLOCK_TIMEOUT_BP;
}
@@ -209,6 +221,7 @@ void imx233_ssp_setup_ssp2_sd_mmc_pins(bool enable_pullups, unsigned bus_width,
void imx233_ssp_set_mode(int ssp, unsigned mode)
{
+ ASSERT_SSP(ssp)
switch(mode)
{
case HW_SSP_CTRL1__SSP_MODE__SD_MMC:
@@ -226,6 +239,7 @@ void imx233_ssp_set_mode(int ssp, unsigned mode)
void imx233_ssp_set_bus_width(int ssp, unsigned width)
{
+ ASSERT_SSP(ssp)
switch(width)
{
case 1: ssp_bus_width[ssp - 1] = HW_SSP_CTRL0__BUS_WIDTH__ONE_BIT; break;
@@ -236,6 +250,7 @@ void imx233_ssp_set_bus_width(int ssp, unsigned width)
void imx233_ssp_set_block_size(int ssp, unsigned log_block_size)
{
+ ASSERT_SSP(ssp)
ssp_log_block_size[ssp - 1] = log_block_size;
}
@@ -243,6 +258,7 @@ enum imx233_ssp_error_t imx233_ssp_sd_mmc_transfer(int ssp, uint8_t cmd,
uint32_t cmd_arg, enum imx233_ssp_resp_t resp, void *buffer, unsigned block_count,
bool wait4irq, bool read, uint32_t *resp_ptr)
{
+ ASSERT_SSP(ssp)
mutex_lock(&ssp_mutex[ssp - 1]);
/* Enable all interrupts */
imx233_icoll_enable_interrupt(INT_SRC_SSP_DMA(ssp), true);
@@ -312,6 +328,7 @@ enum imx233_ssp_error_t imx233_ssp_sd_mmc_transfer(int ssp, uint8_t cmd,
void imx233_ssp_sd_mmc_power_up_sequence(int ssp)
{
+ ASSERT_SSP(ssp)
__REG_CLR(HW_SSP_CMD0(ssp)) = HW_SSP_CMD0__SLOW_CLKING_EN;
__REG_SET(HW_SSP_CMD0(ssp)) = HW_SSP_CMD0__CONT_CLKING_EN;
mdelay(1);
@@ -320,6 +337,7 @@ void imx233_ssp_sd_mmc_power_up_sequence(int ssp)
static int ssp_detect_oneshot_callback(int ssp)
{
+ ASSERT_SSP(ssp)
if(ssp_detect_cb[ssp - 1])
ssp_detect_cb[ssp - 1](ssp);
@@ -348,11 +366,14 @@ static void detect_irq(int bank, int pin)
timeout_register(&ssp2_detect_oneshot, ssp2_detect_oneshot_callback, (3*HZ/10), 0);
}
-void imx233_ssp_sdmmc_setup_detect(int ssp, bool enable, ssp_detect_cb_t fn, bool first_time)
+void imx233_ssp_sdmmc_setup_detect(int ssp, bool enable, ssp_detect_cb_t fn,
+ bool first_time, bool invert)
{
+ ASSERT_SSP(ssp)
int bank = ssp == 1 ? 2 : 0;
int pin = ssp == 1 ? 1 : 19;
ssp_detect_cb[ssp - 1] = fn;
+ ssp_detect_invert[ssp - 1] = invert;
if(enable)
{
imx233_pinctrl_acquire_pin(bank, pin, ssp == 1 ? "ssp1 detect" : "ssp2 detect");
@@ -361,10 +382,23 @@ void imx233_ssp_sdmmc_setup_detect(int ssp, bool enable, ssp_detect_cb_t fn, boo
}
if(first_time && imx233_ssp_sdmmc_detect(ssp))
detect_irq(bank, pin);
- imx233_setup_pin_irq(bank, pin, enable, true, !imx233_ssp_sdmmc_detect(ssp), detect_irq);
+ imx233_setup_pin_irq(bank, pin, enable, true, !imx233_ssp_sdmmc_detect_raw(ssp), detect_irq);
}
-bool imx233_ssp_sdmmc_detect(int ssp)
+bool imx233_ssp_sdmmc_is_detect_inverted(int ssp)
+{
+ ASSERT_SSP(ssp)
+ return ssp_detect_invert[ssp - 1];
+}
+
+bool imx233_ssp_sdmmc_detect_raw(int ssp)
{
+ ASSERT_SSP(ssp)
return !!(HW_SSP_STATUS(ssp) & HW_SSP_STATUS__CARD_DETECT);
}
+
+bool imx233_ssp_sdmmc_detect(int ssp)
+{
+ ASSERT_SSP(ssp)
+ return imx233_ssp_sdmmc_detect_raw(ssp) != ssp_detect_invert[ssp - 1];
+}