9 #define DRIVER_NAME "bfin-sdh"
11 #include <linux/module.h>
22 #include <asm/cacheflush.h>
27 #if defined(CONFIG_BF51x) || defined(__ADSPBF60x__)
28 #define bfin_read_SDH_CLK_CTL bfin_read_RSI_CLK_CTL
29 #define bfin_write_SDH_CLK_CTL bfin_write_RSI_CLK_CTL
30 #define bfin_write_SDH_ARGUMENT bfin_write_RSI_ARGUMENT
31 #define bfin_write_SDH_COMMAND bfin_write_RSI_COMMAND
32 #define bfin_write_SDH_DATA_TIMER bfin_write_RSI_DATA_TIMER
33 #define bfin_read_SDH_RESPONSE0 bfin_read_RSI_RESPONSE0
34 #define bfin_read_SDH_RESPONSE1 bfin_read_RSI_RESPONSE1
35 #define bfin_read_SDH_RESPONSE2 bfin_read_RSI_RESPONSE2
36 #define bfin_read_SDH_RESPONSE3 bfin_read_RSI_RESPONSE3
37 #define bfin_write_SDH_DATA_LGTH bfin_write_RSI_DATA_LGTH
38 #define bfin_read_SDH_DATA_CTL bfin_read_RSI_DATA_CTL
39 #define bfin_write_SDH_DATA_CTL bfin_write_RSI_DATA_CTL
40 #define bfin_read_SDH_DATA_CNT bfin_read_RSI_DATA_CNT
41 #define bfin_write_SDH_STATUS_CLR bfin_write_RSI_STATUS_CLR
42 #define bfin_read_SDH_E_STATUS bfin_read_RSI_E_STATUS
43 #define bfin_write_SDH_E_STATUS bfin_write_RSI_E_STATUS
44 #define bfin_read_SDH_STATUS bfin_read_RSI_STATUS
45 #define bfin_write_SDH_MASK0 bfin_write_RSI_MASK0
46 #define bfin_write_SDH_E_MASK bfin_write_RSI_E_MASK
47 #define bfin_read_SDH_CFG bfin_read_RSI_CFG
48 #define bfin_write_SDH_CFG bfin_write_RSI_CFG
49 # if defined(__ADSPBF60x__)
50 # define bfin_read_SDH_BLK_SIZE bfin_read_RSI_BLKSZ
51 # define bfin_write_SDH_BLK_SIZE bfin_write_RSI_BLKSZ
53 # define bfin_read_SDH_PWR_CTL bfin_read_RSI_PWR_CTL
54 # define bfin_write_SDH_PWR_CTL bfin_write_RSI_PWR_CTL
83 return pdev->
dev.platform_data;
92 static void sdh_enable_stat_irq(
struct sdh_host *host,
unsigned int mask)
100 spin_unlock_irqrestore(&host->
lock, flags);
103 static void sdh_disable_stat_irq(
struct sdh_host *host,
unsigned int mask)
108 host->
imask &= ~mask;
111 spin_unlock_irqrestore(&host->
lock, flags);
117 unsigned int data_ctl;
119 unsigned int cycle_ns,
timeout;
138 data_ctl |= ((
ffs(data->
blksz) - 1) << 4);
140 bfin_write_SDH_BLK_SIZE(data->
blksz);
145 cycle_ns = 1000000000 / (host->
sclk / (2 * (host->
clk_div + 1)));
159 #if defined(CONFIG_BF54x) || defined(CONFIG_BF60x)
175 "cfg:0x%lx, x_count:0x%lx, x_modify:0x%lx\n",
176 i, host->
sg_cpu[i].start_addr,
178 host->
sg_cpu[i].x_modify);
182 (
unsigned int)host->
sg_cpu +
188 set_dma_curr_desc_addr(host->
dma_ch, (
unsigned long *)host->
sg_dma);
189 set_dma_x_count(host->
dma_ch, 0);
190 set_dma_x_modify(host->
dma_ch, 0);
192 set_dma_config(host->
dma_ch, dma_cfg);
193 #elif defined(CONFIG_BF51x)
197 set_dma_x_count(host->
dma_ch, length / 4);
198 set_dma_x_modify(host->
dma_ch, 4);
200 set_dma_config(host->
dma_ch, dma_cfg);
212 unsigned int sdh_cmd;
213 unsigned int stat_mask;
236 sdh_enable_stat_irq(host, stat_mask);
253 static int sdh_cmd_done(
struct sdh_host *host,
unsigned int stat)
281 ret = sdh_setup_data(host, host->
data);
288 sdh_finish_request(host, host->
mrq);
293 static int sdh_data_done(
struct sdh_host *host,
unsigned int stat)
323 if (host->
mrq->stop) {
324 sdh_stop_clock(host);
325 sdh_start_cmd(host, host->
mrq->stop);
327 sdh_finish_request(host, host->
mrq);
335 struct sdh_host *host = mmc_priv(mmc);
341 spin_lock(&host->
lock);
346 ret = sdh_setup_data(host, mrq->
data);
351 sdh_start_cmd(host, mrq->
cmd);
353 spin_unlock(&host->
lock);
364 host = mmc_priv(mmc);
366 spin_lock(&host->
lock);
378 clk_ctl |= WIDE_BUS_4;
387 clk_ctl |= BYTE_BUS_8;
399 # ifndef CONFIG_SDH_BFIN_MISSING_CMD_PULLUP_WORKAROUND
411 # ifndef CONFIG_SDH_BFIN_MISSING_CMD_PULLUP_WORKAROUND
431 clk_div =
min_t(
unsigned char, clk_div, 0xFF);
438 sdh_stop_clock(host);
449 spin_unlock(&host->
lock);
451 dev_dbg(
mmc_dev(host->
mmc),
"SDH: clk_div = 0x%x actual clock:%ld expected clock:%d\n",
458 .request = sdh_request,
459 .set_ios = sdh_set_ios,
467 get_dma_curr_irqstat(host->
dma_ch));
468 clear_dma_irqstat(host->
dma_ch);
474 static irqreturn_t sdh_stat_irq(
int irq,
void *devid)
482 spin_lock(&host->
lock);
491 handled |= sdh_cmd_done(host, status);
499 handled |= sdh_data_done(host, status);
501 spin_unlock(&host->
lock);
508 static void sdh_reset(
void)
510 #if defined(CONFIG_BF54x)
533 dev_err(&pdev->
dev,
"missing platform driver data\n");
545 #if defined(CONFIG_BF51x)
562 host = mmc_priv(mmc);
572 dev_err(&pdev->
dev,
"unable to request DMA channel\n");
578 dev_err(&pdev->
dev,
"unable to request DMA irq\n");
588 platform_set_drvdata(pdev, mmc);
590 ret =
request_irq(host->
irq, sdh_stat_irq, 0,
"SDH Status IRQ", host);
592 dev_err(&pdev->
dev,
"unable to request status irq\n");
598 dev_err(&pdev->
dev,
"unable to request peripheral pins\n");
622 struct mmc_host *mmc = platform_get_drvdata(pdev);
624 platform_set_drvdata(pdev,
NULL);
627 struct sdh_host *host = mmc_priv(mmc);
631 sdh_stop_clock(host);
645 struct mmc_host *mmc = platform_get_drvdata(dev);
659 struct mmc_host *mmc = platform_get_drvdata(dev);
665 dev_err(&dev->
dev,
"unable to request peripheral pins\n");
677 # define sdh_suspend NULL
678 # define sdh_resume NULL