ARM: MXC: mxcmmc: Teach the driver SDIO operations
Successfully tested on MX31 hardware using libertas SDIO peripherals. Signed-off-by: Daniel Mack <daniel@caiaq.de> Cc: Sascha Hauer <s.hauer@pengutronix.de> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Volker Ernst <volker.ernst@txtr.com> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Michał Mirosław <mirqus@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
committed by
Sascha Hauer
parent
4725f6f176
commit
f441b99310
@@ -119,6 +119,7 @@ struct mxcmci_host {
|
|||||||
int detect_irq;
|
int detect_irq;
|
||||||
int dma;
|
int dma;
|
||||||
int do_dma;
|
int do_dma;
|
||||||
|
int use_sdio;
|
||||||
unsigned int power_mode;
|
unsigned int power_mode;
|
||||||
struct imxmmc_platform_data *pdata;
|
struct imxmmc_platform_data *pdata;
|
||||||
|
|
||||||
@@ -138,6 +139,7 @@ struct mxcmci_host {
|
|||||||
int clock;
|
int clock;
|
||||||
|
|
||||||
struct work_struct datawork;
|
struct work_struct datawork;
|
||||||
|
spinlock_t lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios);
|
static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios);
|
||||||
@@ -226,6 +228,9 @@ static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data)
|
|||||||
static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd,
|
static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd,
|
||||||
unsigned int cmdat)
|
unsigned int cmdat)
|
||||||
{
|
{
|
||||||
|
u32 int_cntr;
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
WARN_ON(host->cmd != NULL);
|
WARN_ON(host->cmd != NULL);
|
||||||
host->cmd = cmd;
|
host->cmd = cmd;
|
||||||
|
|
||||||
@@ -249,12 +254,16 @@ static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int_cntr = INT_END_CMD_RES_EN;
|
||||||
|
|
||||||
if (mxcmci_use_dma(host))
|
if (mxcmci_use_dma(host))
|
||||||
writel(INT_READ_OP_EN | INT_WRITE_OP_DONE_EN |
|
int_cntr |= INT_READ_OP_EN | INT_WRITE_OP_DONE_EN;
|
||||||
INT_END_CMD_RES_EN,
|
|
||||||
host->base + MMC_REG_INT_CNTR);
|
spin_lock_irqsave(&host->lock, flags);
|
||||||
else
|
if (host->use_sdio)
|
||||||
writel(INT_END_CMD_RES_EN, host->base + MMC_REG_INT_CNTR);
|
int_cntr |= INT_SDIO_IRQ_EN;
|
||||||
|
writel(int_cntr, host->base + MMC_REG_INT_CNTR);
|
||||||
|
spin_unlock_irqrestore(&host->lock, flags);
|
||||||
|
|
||||||
writew(cmd->opcode, host->base + MMC_REG_CMD);
|
writew(cmd->opcode, host->base + MMC_REG_CMD);
|
||||||
writel(cmd->arg, host->base + MMC_REG_ARG);
|
writel(cmd->arg, host->base + MMC_REG_ARG);
|
||||||
@@ -266,7 +275,14 @@ static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd,
|
|||||||
static void mxcmci_finish_request(struct mxcmci_host *host,
|
static void mxcmci_finish_request(struct mxcmci_host *host,
|
||||||
struct mmc_request *req)
|
struct mmc_request *req)
|
||||||
{
|
{
|
||||||
writel(0, host->base + MMC_REG_INT_CNTR);
|
u32 int_cntr = 0;
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
|
spin_lock_irqsave(&host->lock, flags);
|
||||||
|
if (host->use_sdio)
|
||||||
|
int_cntr |= INT_SDIO_IRQ_EN;
|
||||||
|
writel(int_cntr, host->base + MMC_REG_INT_CNTR);
|
||||||
|
spin_unlock_irqrestore(&host->lock, flags);
|
||||||
|
|
||||||
host->req = NULL;
|
host->req = NULL;
|
||||||
host->cmd = NULL;
|
host->cmd = NULL;
|
||||||
@@ -532,15 +548,27 @@ static void mxcmci_cmd_done(struct mxcmci_host *host, unsigned int stat)
|
|||||||
static irqreturn_t mxcmci_irq(int irq, void *devid)
|
static irqreturn_t mxcmci_irq(int irq, void *devid)
|
||||||
{
|
{
|
||||||
struct mxcmci_host *host = devid;
|
struct mxcmci_host *host = devid;
|
||||||
|
unsigned long flags;
|
||||||
|
bool sdio_irq;
|
||||||
u32 stat;
|
u32 stat;
|
||||||
|
|
||||||
stat = readl(host->base + MMC_REG_STATUS);
|
stat = readl(host->base + MMC_REG_STATUS);
|
||||||
writel(stat, host->base + MMC_REG_STATUS);
|
writel(stat & ~STATUS_SDIO_INT_ACTIVE, host->base + MMC_REG_STATUS);
|
||||||
|
|
||||||
dev_dbg(mmc_dev(host->mmc), "%s: 0x%08x\n", __func__, stat);
|
dev_dbg(mmc_dev(host->mmc), "%s: 0x%08x\n", __func__, stat);
|
||||||
|
|
||||||
|
spin_lock_irqsave(&host->lock, flags);
|
||||||
|
sdio_irq = (stat & STATUS_SDIO_INT_ACTIVE) && host->use_sdio;
|
||||||
|
spin_unlock_irqrestore(&host->lock, flags);
|
||||||
|
|
||||||
|
if (sdio_irq) {
|
||||||
|
writel(STATUS_SDIO_INT_ACTIVE, host->base + MMC_REG_STATUS);
|
||||||
|
mmc_signal_sdio_irq(host->mmc);
|
||||||
|
}
|
||||||
|
|
||||||
if (stat & STATUS_END_CMD_RESP)
|
if (stat & STATUS_END_CMD_RESP)
|
||||||
mxcmci_cmd_done(host, stat);
|
mxcmci_cmd_done(host, stat);
|
||||||
|
|
||||||
#ifdef HAS_DMA
|
#ifdef HAS_DMA
|
||||||
if (mxcmci_use_dma(host) &&
|
if (mxcmci_use_dma(host) &&
|
||||||
(stat & (STATUS_DATA_TRANS_DONE | STATUS_WRITE_OP_DONE)))
|
(stat & (STATUS_DATA_TRANS_DONE | STATUS_WRITE_OP_DONE)))
|
||||||
@@ -677,11 +705,30 @@ static int mxcmci_get_ro(struct mmc_host *mmc)
|
|||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mxcmci_enable_sdio_irq(struct mmc_host *mmc, int enable)
|
||||||
|
{
|
||||||
|
struct mxcmci_host *host = mmc_priv(mmc);
|
||||||
|
unsigned long flags;
|
||||||
|
u32 int_cntr;
|
||||||
|
|
||||||
|
spin_lock_irqsave(&host->lock, flags);
|
||||||
|
host->use_sdio = enable;
|
||||||
|
int_cntr = readl(host->base + MMC_REG_INT_CNTR);
|
||||||
|
|
||||||
|
if (enable)
|
||||||
|
int_cntr |= INT_SDIO_IRQ_EN;
|
||||||
|
else
|
||||||
|
int_cntr &= ~INT_SDIO_IRQ_EN;
|
||||||
|
|
||||||
|
writel(int_cntr, host->base + MMC_REG_INT_CNTR);
|
||||||
|
spin_unlock_irqrestore(&host->lock, flags);
|
||||||
|
}
|
||||||
|
|
||||||
static const struct mmc_host_ops mxcmci_ops = {
|
static const struct mmc_host_ops mxcmci_ops = {
|
||||||
.request = mxcmci_request,
|
.request = mxcmci_request,
|
||||||
.set_ios = mxcmci_set_ios,
|
.set_ios = mxcmci_set_ios,
|
||||||
.get_ro = mxcmci_get_ro,
|
.get_ro = mxcmci_get_ro,
|
||||||
|
.enable_sdio_irq = mxcmci_enable_sdio_irq,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int mxcmci_probe(struct platform_device *pdev)
|
static int mxcmci_probe(struct platform_device *pdev)
|
||||||
@@ -709,7 +756,7 @@ static int mxcmci_probe(struct platform_device *pdev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mmc->ops = &mxcmci_ops;
|
mmc->ops = &mxcmci_ops;
|
||||||
mmc->caps = MMC_CAP_4_BIT_DATA;
|
mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
|
||||||
|
|
||||||
/* MMC core transfer sizes tunable parameters */
|
/* MMC core transfer sizes tunable parameters */
|
||||||
mmc->max_hw_segs = 64;
|
mmc->max_hw_segs = 64;
|
||||||
@@ -728,6 +775,7 @@ static int mxcmci_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
host->mmc = mmc;
|
host->mmc = mmc;
|
||||||
host->pdata = pdev->dev.platform_data;
|
host->pdata = pdev->dev.platform_data;
|
||||||
|
spin_lock_init(&host->lock);
|
||||||
|
|
||||||
if (host->pdata && host->pdata->ocr_avail)
|
if (host->pdata && host->pdata->ocr_avail)
|
||||||
mmc->ocr_avail = host->pdata->ocr_avail;
|
mmc->ocr_avail = host->pdata->ocr_avail;
|
||||||
|
Reference in New Issue
Block a user