* [PATCH 1/3] mci: rename mci_platformdata to mci_host, pass mci_host to host drivers
2010-10-07 15:37 Sascha Hauer
@ 2010-10-07 15:37 ` Sascha Hauer
2010-10-07 15:37 ` [PATCH 2/3] mci: Add i.MX27/31 driver Sascha Hauer
2010-10-07 15:37 ` [PATCH 3/3] ARM pca100: Add mci support Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2010-10-07 15:37 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mci/mci-core.c | 50 ++++++++++++++++++++++++------------------------
include/mci.h | 10 ++++----
2 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index a31b96f..323b899 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -60,9 +60,9 @@
*/
static int mci_send_cmd(struct device_d *mci_dev, struct mci_cmd *cmd, struct mci_data *data)
{
- struct mci_platformdata *pdata = GET_MCI_PDATA(mci_dev);
+ struct mci_host *host = GET_MCI_PDATA(mci_dev);
- return (pdata->send_cmd)(pdata->hw_dev, cmd, data);
+ return host->send_cmd(host, cmd, data);
}
/**
@@ -178,7 +178,7 @@ static int mci_go_idle(struct device_d *mci_dev)
static int sd_send_op_cond(struct device_d *mci_dev)
{
struct mci *mci = GET_MCI_DATA(mci_dev);
- struct mci_platformdata *pdata = GET_MCI_PDATA(mci_dev);
+ struct mci_host *host = GET_MCI_PDATA(mci_dev);
struct mci_cmd cmd;
int timeout = 1000;
int err;
@@ -192,7 +192,7 @@ static int sd_send_op_cond(struct device_d *mci_dev)
}
mci_setup_cmd(&cmd, SD_CMD_APP_SEND_OP_COND,
- pdata->voltages | (mci->version == SD_VERSION_2 ? OCR_HCS : 0),
+ host->voltages | (mci->version == SD_VERSION_2 ? OCR_HCS : 0),
MMC_RSP_R3);
err = mci_send_cmd(mci_dev, &cmd, NULL);
if (err) {
@@ -226,7 +226,7 @@ static int sd_send_op_cond(struct device_d *mci_dev)
static int mmc_send_op_cond(struct device_d *mci_dev)
{
struct mci *mci = GET_MCI_DATA(mci_dev);
- struct mci_platformdata *pdata = GET_MCI_PDATA(mci_dev);
+ struct mci_host *host = GET_MCI_PDATA(mci_dev);
struct mci_cmd cmd;
int timeout = 1000;
int err;
@@ -235,7 +235,7 @@ static int mmc_send_op_cond(struct device_d *mci_dev)
mci_go_idle(mci_dev);
do {
- mci_setup_cmd(&cmd, MMC_CMD_SEND_OP_COND, OCR_HCS | pdata->voltages, MMC_RSP_R3);
+ mci_setup_cmd(&cmd, MMC_CMD_SEND_OP_COND, OCR_HCS | host->voltages, MMC_RSP_R3);
err = mci_send_cmd(mci_dev, &cmd, NULL);
if (err) {
@@ -502,9 +502,9 @@ retry_scr:
*/
static void mci_set_ios(struct device_d *mci_dev)
{
- struct mci_platformdata *pdata = GET_MCI_PDATA(mci_dev);
+ struct mci_host *host = GET_MCI_PDATA(mci_dev);
- (pdata->set_ios)(pdata->hw_dev, mci_dev, pdata->bus_width, pdata->clock);
+ host->set_ios(host, mci_dev, host->bus_width, host->clock);
}
/**
@@ -514,16 +514,16 @@ static void mci_set_ios(struct device_d *mci_dev)
*/
static void mci_set_clock(struct device_d *mci_dev, unsigned clock)
{
- struct mci_platformdata *pdata = GET_MCI_PDATA(mci_dev);
+ struct mci_host *host = GET_MCI_PDATA(mci_dev);
/* check against any given limits */
- if (clock > pdata->f_max)
- clock = pdata->f_max;
+ if (clock > host->f_max)
+ clock = host->f_max;
- if (clock < pdata->f_min)
- clock = pdata->f_min;
+ if (clock < host->f_min)
+ clock = host->f_min;
- pdata->clock = clock; /* the new target frequency */
+ host->clock = clock; /* the new target frequency */
mci_set_ios(mci_dev);
}
@@ -534,9 +534,9 @@ static void mci_set_clock(struct device_d *mci_dev, unsigned clock)
*/
static void mci_set_bus_width(struct device_d *mci_dev, unsigned width)
{
- struct mci_platformdata *pdata = GET_MCI_PDATA(mci_dev);
+ struct mci_host *host = GET_MCI_PDATA(mci_dev);
- pdata->bus_width = width; /* the new target bus width */
+ host->bus_width = width; /* the new target bus width */
mci_set_ios(mci_dev);
}
@@ -690,7 +690,7 @@ static void mci_extract_card_capacity_from_csd(struct device_d *mci_dev)
static int mci_startup(struct device_d *mci_dev)
{
struct mci *mci = GET_MCI_DATA(mci_dev);
- struct mci_platformdata *pdata = GET_MCI_PDATA(mci_dev);
+ struct mci_host *host = GET_MCI_PDATA(mci_dev);
struct mci_cmd cmd;
int err;
@@ -773,7 +773,7 @@ static int mci_startup(struct device_d *mci_dev)
return err;
/* Restrict card's capabilities by what the host can do */
- mci->card_caps &= pdata->host_caps;
+ mci->card_caps &= host->host_caps;
if (IS_SD(mci)) {
if (mci->card_caps & MMC_MODE_4BIT) {
@@ -850,13 +850,13 @@ static int mci_startup(struct device_d *mci_dev)
static int sd_send_if_cond(struct device_d *mci_dev)
{
struct mci *mci = GET_MCI_DATA(mci_dev);
- struct mci_platformdata *pdata = GET_MCI_PDATA(mci_dev);
+ struct mci_host *host = GET_MCI_PDATA(mci_dev);
struct mci_cmd cmd;
int err;
mci_setup_cmd(&cmd, SD_CMD_SEND_IF_COND,
/* We set the bit if the host supports voltages between 2.7 and 3.6 V */
- ((pdata->voltages & 0x00ff8000) != 0) << 8 | 0xaa,
+ ((host->voltages & 0x00ff8000) != 0) << 8 | 0xaa,
MMC_RSP_R7);
err = mci_send_cmd(mci_dev, &cmd, NULL);
if (err) {
@@ -1095,13 +1095,13 @@ static int mci_check_if_already_initialized(struct device_d *mci_dev)
static int mci_card_probe(struct device_d *mci_dev)
{
struct mci *mci = GET_MCI_DATA(mci_dev);
- struct mci_platformdata *pdata = GET_MCI_PDATA(mci_dev);
+ struct mci_host *host = GET_MCI_PDATA(mci_dev);
struct device_d *disk_dev;
struct ata_interface *p;
int rc;
/* start with a host interface reset */
- rc = (pdata->init)(pdata->hw_dev, mci_dev);
+ rc = (host->init)(host, mci_dev);
if (rc) {
pr_err("Cannot reset the SD/MMC interface\n");
return rc;
@@ -1176,7 +1176,7 @@ static int mci_card_probe(struct device_d *mci_dev)
on_error:
if (rc != 0) {
- pdata->clock = 0; /* disable the MCI clock */
+ host->clock = 0; /* disable the MCI clock */
mci_set_ios(mci_dev);
}
@@ -1295,14 +1295,14 @@ device_initcall(mci_init);
* @param pdata MCI device's platform data for this MCI device
* @return 0 on success
*/
-int mci_register(struct mci_platformdata *pdata)
+int mci_register(struct mci_host *host)
{
struct device_d *mci_dev;
mci_dev = xzalloc(sizeof(struct device_d));
strcpy(mci_dev->name, mci_driver.name);
- mci_dev->platform_data = (void*)pdata;
+ mci_dev->platform_data = (void*)host;
return register_device(mci_dev);
}
diff --git a/include/mci.h b/include/mci.h
index b9d5c1c..1e758d3 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -189,7 +189,7 @@ struct mci_data {
};
/** host information */
-struct mci_platformdata {
+struct mci_host {
struct device_d *hw_dev; /**< the host MCI hardware device */
unsigned voltages;
unsigned host_caps; /**< Host's interface capabilities, refer MMC_VDD_* and FIXME */
@@ -198,9 +198,9 @@ struct mci_platformdata {
unsigned clock; /**< Current clock used to talk to the card */
unsigned bus_width; /**< used data bus width to the card */
- int (*init)(struct device_d*, struct device_d*); /**< init the host interface */
- void (*set_ios)(struct device_d*, struct device_d*, unsigned, unsigned); /**< change host interface settings */
- int (*send_cmd)(struct device_d*, struct mci_cmd*, struct mci_data*); /**< handle a command */
+ int (*init)(struct mci_host*, struct device_d*); /**< init the host interface */
+ void (*set_ios)(struct mci_host*, struct device_d*, unsigned, unsigned); /**< change host interface settings */
+ int (*send_cmd)(struct mci_host*, struct mci_cmd*, struct mci_data*); /**< handle a command */
};
/** MMC/SD and interface instance information */
@@ -220,7 +220,7 @@ struct mci {
int ready_for_use; /** true if already probed */
};
-int mci_register(struct mci_platformdata*);
+int mci_register(struct mci_host*);
#define GET_HOST_DATA(x) (x->priv)
#define GET_HOST_PDATA(x) (x->platform_data)
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] mci: Add i.MX27/31 driver
2010-10-07 15:37 Sascha Hauer
2010-10-07 15:37 ` [PATCH 1/3] mci: rename mci_platformdata to mci_host, pass mci_host to host drivers Sascha Hauer
@ 2010-10-07 15:37 ` Sascha Hauer
2010-10-07 15:37 ` [PATCH 3/3] ARM pca100: Add mci support Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2010-10-07 15:37 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mci/Kconfig | 7 +
drivers/mci/Makefile | 1 +
drivers/mci/imx.c | 521 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 529 insertions(+), 0 deletions(-)
create mode 100644 drivers/mci/imx.c
diff --git a/drivers/mci/Kconfig b/drivers/mci/Kconfig
index 644c0a3..0bc4254 100644
--- a/drivers/mci/Kconfig
+++ b/drivers/mci/Kconfig
@@ -41,4 +41,11 @@ config MCI_S3C
Enable this entry to add support to read and write SD cards on a
Samsung S3C24xx based system.
+config MCI_IMX
+ bool "i.MX"
+ depends on ARCH_IMX27 || ARCH_IMX31
+ help
+ Enable this entry to add support to read and write SD cards on a
+ Freescale i.MX based system.
+
endif
diff --git a/drivers/mci/Makefile b/drivers/mci/Makefile
index be18446..f393e93 100644
--- a/drivers/mci/Makefile
+++ b/drivers/mci/Makefile
@@ -1,3 +1,4 @@
obj-$(CONFIG_MCI) += mci-core.o
obj-$(CONFIG_MCI_STM378X) += stm378x.o
obj-$(CONFIG_MCI_S3C) += s3c.o
+obj-$(CONFIG_MCI_IMX) += imx.o
diff --git a/drivers/mci/imx.c b/drivers/mci/imx.c
new file mode 100644
index 0000000..91e1095
--- /dev/null
+++ b/drivers/mci/imx.c
@@ -0,0 +1,521 @@
+/*
+ * This is a driver for the SDHC controller found in Freescale MX2/MX3
+ * SoCs. It is basically the same hardware as found on MX1 (imxmmc.c).
+ * Unlike the hardware found on MX1, this hardware just works and does
+ * not need all the quirks found in imxmmc.c, hence the seperate driver.
+ *
+ * Copyright (C) 2009 Ilya Yanok, <yanok@emcraft.com>
+ * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
+ * Copyright (C) 2006 Pavel Pisa, PiKRON <ppisa@pikron.com>
+ *
+ * derived from pxamci.c by Russell King
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <config.h>
+#include <common.h>
+#include <command.h>
+#include <mci.h>
+#include <malloc.h>
+#include <errno.h>
+#include <clock.h>
+#include <init.h>
+#include <driver.h>
+#include <mach/clock.h>
+#include <asm/io.h>
+
+#define DRIVER_NAME "imx-mmc"
+
+struct mxcmci_regs {
+ u32 str_stp_clk;
+ u32 status;
+ u32 clk_rate;
+ u32 cmd_dat_cont;
+ u32 res_to;
+ u32 read_to;
+ u32 blk_len;
+ u32 nob;
+ u32 rev_no;
+ u32 int_cntr;
+ u32 cmd;
+ u32 arg;
+ u32 pad;
+ u32 res_fifo;
+ u32 buffer_access;
+};
+
+#define STR_STP_CLK_RESET (1 << 3)
+#define STR_STP_CLK_START_CLK (1 << 1)
+#define STR_STP_CLK_STOP_CLK (1 << 0)
+
+#define STATUS_CARD_INSERTION (1 << 31)
+#define STATUS_CARD_REMOVAL (1 << 30)
+#define STATUS_YBUF_EMPTY (1 << 29)
+#define STATUS_XBUF_EMPTY (1 << 28)
+#define STATUS_YBUF_FULL (1 << 27)
+#define STATUS_XBUF_FULL (1 << 26)
+#define STATUS_BUF_UND_RUN (1 << 25)
+#define STATUS_BUF_OVFL (1 << 24)
+#define STATUS_SDIO_INT_ACTIVE (1 << 14)
+#define STATUS_END_CMD_RESP (1 << 13)
+#define STATUS_WRITE_OP_DONE (1 << 12)
+#define STATUS_DATA_TRANS_DONE (1 << 11)
+#define STATUS_READ_OP_DONE (1 << 11)
+#define STATUS_WR_CRC_ERROR_CODE_MASK (3 << 10)
+#define STATUS_CARD_BUS_CLK_RUN (1 << 8)
+#define STATUS_BUF_READ_RDY (1 << 7)
+#define STATUS_BUF_WRITE_RDY (1 << 6)
+#define STATUS_RESP_CRC_ERR (1 << 5)
+#define STATUS_CRC_READ_ERR (1 << 3)
+#define STATUS_CRC_WRITE_ERR (1 << 2)
+#define STATUS_TIME_OUT_RESP (1 << 1)
+#define STATUS_TIME_OUT_READ (1 << 0)
+#define STATUS_ERR_MASK 0x2f
+
+#define CMD_DAT_CONT_CMD_RESP_LONG_OFF (1 << 12)
+#define CMD_DAT_CONT_STOP_READWAIT (1 << 11)
+#define CMD_DAT_CONT_START_READWAIT (1 << 10)
+#define CMD_DAT_CONT_BUS_WIDTH_4 (2 << 8)
+#define CMD_DAT_CONT_INIT (1 << 7)
+#define CMD_DAT_CONT_WRITE (1 << 4)
+#define CMD_DAT_CONT_DATA_ENABLE (1 << 3)
+#define CMD_DAT_CONT_RESPONSE_48BIT_CRC (1 << 0)
+#define CMD_DAT_CONT_RESPONSE_136BIT (2 << 0)
+#define CMD_DAT_CONT_RESPONSE_48BIT (3 << 0)
+
+#define INT_SDIO_INT_WKP_EN (1 << 18)
+#define INT_CARD_INSERTION_WKP_EN (1 << 17)
+#define INT_CARD_REMOVAL_WKP_EN (1 << 16)
+#define INT_CARD_INSERTION_EN (1 << 15)
+#define INT_CARD_REMOVAL_EN (1 << 14)
+#define INT_SDIO_IRQ_EN (1 << 13)
+#define INT_DAT0_EN (1 << 12)
+#define INT_BUF_READ_EN (1 << 4)
+#define INT_BUF_WRITE_EN (1 << 3)
+#define INT_END_CMD_RES_EN (1 << 2)
+#define INT_WRITE_OP_DONE_EN (1 << 1)
+#define INT_READ_OP_EN (1 << 0)
+
+struct mxcmci_host {
+ struct mci_host mci;
+ struct mxcmci_regs *base;
+ int irq;
+ int detect_irq;
+ int dma;
+ int do_dma;
+ unsigned int power_mode;
+
+ struct mci_cmd *cmd;
+ struct mci_data *data;
+
+ unsigned int dma_nents;
+ unsigned int datasize;
+ unsigned int dma_dir;
+
+ u16 rev_no;
+ unsigned int cmdat;
+
+ int clock;
+};
+
+#define to_mxcmci(mci) container_of(mci, struct mxcmci_host, mci)
+
+static void mxcmci_softreset(struct mxcmci_host *host)
+{
+ int i;
+
+ /* reset sequence */
+ writew(STR_STP_CLK_RESET, &host->base->str_stp_clk);
+ writew(STR_STP_CLK_RESET | STR_STP_CLK_START_CLK,
+ &host->base->str_stp_clk);
+
+ for (i = 0; i < 8; i++)
+ writew(STR_STP_CLK_START_CLK, &host->base->str_stp_clk);
+
+ writew(0xff, &host->base->res_to);
+}
+
+static void mxcmci_setup_data(struct mxcmci_host *host, struct mci_data *data)
+{
+ unsigned int nob = data->blocks;
+ unsigned int blksz = data->blocksize;
+ unsigned int datasize = nob * blksz;
+
+ host->data = data;
+
+ writew(nob, &host->base->nob);
+ writew(blksz, &host->base->blk_len);
+ host->datasize = datasize;
+}
+
+static int mxcmci_start_cmd(struct mxcmci_host *host, struct mci_cmd *cmd,
+ unsigned int cmdat)
+{
+ if (host->cmd != NULL)
+ printf("mxcmci: error!\n");
+ host->cmd = cmd;
+
+ switch (cmd->resp_type) {
+ case MMC_RSP_R1: /* short CRC, OPCODE */
+ case MMC_RSP_R1b:/* short CRC, OPCODE, BUSY */
+ cmdat |= CMD_DAT_CONT_RESPONSE_48BIT_CRC;
+ break;
+ case MMC_RSP_R2: /* long 136 bit + CRC */
+ cmdat |= CMD_DAT_CONT_RESPONSE_136BIT;
+ break;
+ case MMC_RSP_R3: /* short */
+ cmdat |= CMD_DAT_CONT_RESPONSE_48BIT;
+ break;
+ case MMC_RSP_NONE:
+ break;
+ default:
+ printf("mxcmci: unhandled response type 0x%x\n",
+ cmd->resp_type);
+ return -EINVAL;
+ }
+
+ writew(cmd->cmdidx, &host->base->cmd);
+ writel(cmd->cmdarg, &host->base->arg);
+ writew(cmdat, &host->base->cmd_dat_cont);
+
+ return 0;
+}
+
+static void mxcmci_finish_request(struct mxcmci_host *host,
+ struct mci_cmd *cmd, struct mci_data *data)
+{
+ host->cmd = NULL;
+ host->data = NULL;
+}
+
+static int mxcmci_finish_data(struct mxcmci_host *host, unsigned int stat)
+{
+ int data_error = 0;
+
+ if (stat & STATUS_ERR_MASK) {
+ printf("request failed. status: 0x%08x\n",
+ stat);
+ if (stat & STATUS_CRC_READ_ERR) {
+ data_error = -EILSEQ;
+ } else if (stat & STATUS_CRC_WRITE_ERR) {
+ u32 err_code = (stat >> 9) & 0x3;
+ if (err_code == 2) /* No CRC response */
+ data_error = -ETIMEDOUT;
+ else
+ data_error = -EILSEQ;
+ } else if (stat & STATUS_TIME_OUT_READ) {
+ data_error = -ETIMEDOUT;
+ } else {
+ data_error = -EIO;
+ }
+ }
+
+ host->data = NULL;
+
+ return data_error;
+}
+
+static int mxcmci_read_response(struct mxcmci_host *host, unsigned int stat)
+{
+ struct mci_cmd *cmd = host->cmd;
+ int i;
+ u32 a, b, c;
+ u32 *resp = (u32 *)cmd->response;
+
+ if (!cmd)
+ return 0;
+
+ if (stat & STATUS_TIME_OUT_RESP) {
+ printf("CMD TIMEOUT\n");
+ return -ETIMEDOUT;
+ } else if (stat & STATUS_RESP_CRC_ERR && cmd->resp_type & MMC_RSP_CRC) {
+ printf("cmd crc error\n");
+ return -EILSEQ;
+ }
+
+ if (cmd->resp_type & MMC_RSP_PRESENT) {
+ if (cmd->resp_type & MMC_RSP_136) {
+ for (i = 0; i < 4; i++) {
+ a = readw(&host->base->res_fifo);
+ b = readw(&host->base->res_fifo);
+ resp[i] = a << 16 | b;
+ }
+ } else {
+ a = readw(&host->base->res_fifo);
+ b = readw(&host->base->res_fifo);
+ c = readw(&host->base->res_fifo);
+ resp[0] = a << 24 | b << 8 | c >> 8;
+ }
+ }
+ return 0;
+}
+
+static int mxcmci_poll_status(struct mxcmci_host *host, u32 mask)
+{
+ u32 stat;
+ uint64_t start = get_time_ns();
+
+ do {
+ stat = readl(&host->base->status);
+ if (stat & STATUS_ERR_MASK)
+ return stat;
+ if (is_timeout(start, SECOND))
+ return STATUS_TIME_OUT_READ;
+ if (stat & mask)
+ return 0;
+ } while (1);
+}
+
+static int mxcmci_pull(struct mxcmci_host *host, void *_buf, int bytes)
+{
+ unsigned int stat;
+ u32 *buf = _buf;
+
+ while (bytes > 3) {
+ stat = mxcmci_poll_status(host,
+ STATUS_BUF_READ_RDY | STATUS_READ_OP_DONE);
+ if (stat)
+ return stat;
+ *buf++ = readl(&host->base->buffer_access);
+ bytes -= 4;
+ }
+
+ if (bytes) {
+ u8 *b = (u8 *)buf;
+ u32 tmp;
+
+ stat = mxcmci_poll_status(host,
+ STATUS_BUF_READ_RDY | STATUS_READ_OP_DONE);
+ if (stat)
+ return stat;
+ tmp = readl(&host->base->buffer_access);
+ memcpy(b, &tmp, bytes);
+ }
+
+ return 0;
+}
+
+static int mxcmci_push(struct mxcmci_host *host, const void *_buf, int bytes)
+{
+ unsigned int stat;
+ const u32 *buf = _buf;
+
+ while (bytes > 3) {
+ stat = mxcmci_poll_status(host, STATUS_BUF_WRITE_RDY);
+ if (stat)
+ return stat;
+ writel(*buf++, &host->base->buffer_access);
+ bytes -= 4;
+ }
+
+ if (bytes) {
+ const u8 *b = (u8 *)buf;
+ u32 tmp;
+
+ stat = mxcmci_poll_status(host, STATUS_BUF_WRITE_RDY);
+ if (stat)
+ return stat;
+
+ memcpy(&tmp, b, bytes);
+ writel(tmp, &host->base->buffer_access);
+ }
+
+ stat = mxcmci_poll_status(host, STATUS_BUF_WRITE_RDY);
+ if (stat)
+ return stat;
+
+ return 0;
+}
+
+static int mxcmci_transfer_data(struct mxcmci_host *host)
+{
+ struct mci_data *data = host->data;
+ int stat;
+ unsigned long length;
+
+ length = data->blocks * data->blocksize;
+ host->datasize = 0;
+
+ if (data->flags & MMC_DATA_READ) {
+ stat = mxcmci_pull(host, data->dest, length);
+ if (stat)
+ return stat;
+ host->datasize += length;
+ } else {
+ stat = mxcmci_push(host, (const void *)(data->src), length);
+ if (stat)
+ return stat;
+ host->datasize += length;
+ stat = mxcmci_poll_status(host, STATUS_WRITE_OP_DONE);
+ if (stat)
+ return stat;
+ }
+ return 0;
+}
+
+static int mxcmci_cmd_done(struct mxcmci_host *host, unsigned int stat)
+{
+ int datastat;
+ int ret;
+
+ ret = mxcmci_read_response(host, stat);
+
+ if (ret) {
+ mxcmci_finish_request(host, host->cmd, host->data);
+ return ret;
+ }
+
+ if (!host->data) {
+ mxcmci_finish_request(host, host->cmd, host->data);
+ return 0;
+ }
+
+ datastat = mxcmci_transfer_data(host);
+ ret = mxcmci_finish_data(host, datastat);
+ mxcmci_finish_request(host, host->cmd, host->data);
+ return ret;
+}
+
+static int mxcmci_request(struct mci_host *mci, struct mci_cmd *cmd,
+ struct mci_data *data)
+{
+ struct mxcmci_host *host = to_mxcmci(mci);
+ unsigned int cmdat = host->cmdat;
+ u32 stat;
+ int ret;
+
+ host->cmdat &= ~CMD_DAT_CONT_INIT;
+ if (data) {
+ mxcmci_setup_data(host, data);
+
+ cmdat |= CMD_DAT_CONT_DATA_ENABLE;
+
+ if (data->flags & MMC_DATA_WRITE)
+ cmdat |= CMD_DAT_CONT_WRITE;
+ }
+
+ if ((ret = mxcmci_start_cmd(host, cmd, cmdat))) {
+ mxcmci_finish_request(host, cmd, data);
+ return ret;
+ }
+
+ do {
+ stat = readl(&host->base->status);
+ writel(stat, &host->base->status);
+ } while (!(stat & STATUS_END_CMD_RESP));
+
+ return mxcmci_cmd_done(host, stat);
+}
+
+static void mxcmci_set_clk_rate(struct mxcmci_host *host, unsigned int clk_ios)
+{
+ unsigned int divider;
+ int prescaler = 0;
+ unsigned long clk_in = imx_get_mmcclk();
+
+ while (prescaler <= 0x800) {
+ for (divider = 1; divider <= 0xF; divider++) {
+ int x;
+
+ x = (clk_in / (divider + 1));
+
+ if (prescaler)
+ x /= (prescaler * 2);
+
+ if (x <= clk_ios)
+ break;
+ }
+ if (divider < 0x10)
+ break;
+
+ if (prescaler == 0)
+ prescaler = 1;
+ else
+ prescaler <<= 1;
+ }
+
+ writew((prescaler << 4) | divider, &host->base->clk_rate);
+}
+
+static void mxcmci_set_ios(struct mci_host *mci, struct device_d *dev,
+ unsigned bus_width, unsigned clock)
+{
+ struct mxcmci_host *host = to_mxcmci(mci);
+
+ if (bus_width == 4)
+ host->cmdat |= CMD_DAT_CONT_BUS_WIDTH_4;
+ else
+ host->cmdat &= ~CMD_DAT_CONT_BUS_WIDTH_4;
+
+ if (clock) {
+ mxcmci_set_clk_rate(host, clock);
+ writew(STR_STP_CLK_START_CLK, &host->base->str_stp_clk);
+ } else {
+ writew(STR_STP_CLK_STOP_CLK, &host->base->str_stp_clk);
+ }
+
+ host->clock = clock;
+}
+
+static int mxcmci_init(struct mci_host *mci, struct device_d *dev)
+{
+ struct mxcmci_host *host = to_mxcmci(mci);
+
+ mxcmci_softreset(host);
+
+ host->rev_no = readw(&host->base->rev_no);
+ if (host->rev_no != 0x400) {
+ printf("wrong rev.no. 0x%08x. aborting.\n",
+ host->rev_no);
+ return -ENODEV;
+ }
+
+ /* recommended in data sheet */
+ writew(0x2db4, &host->base->read_to);
+
+ writel(0, &host->base->int_cntr);
+
+ return 0;
+}
+
+static int mxcmci_probe(struct device_d *dev)
+{
+ struct mxcmci_host *host;
+
+ host = xzalloc(sizeof(*host));
+
+// sprintf(mci->name, "MXC MCI");
+ host->mci.send_cmd = mxcmci_request;
+ host->mci.set_ios = mxcmci_set_ios;
+ host->mci.init = mxcmci_init;
+ host->mci.host_caps = MMC_MODE_4BIT;
+
+ host->base = (struct mxcmci_regs *)dev->map_base;
+
+ host->mci.voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
+
+ host->mci.f_min = imx_get_mmcclk() >> 7;
+ host->mci.f_max = imx_get_mmcclk() >> 1;
+
+ mci_register(&host->mci);
+
+ return 0;
+}
+
+static struct driver_d mxcmci_driver = {
+ .name = DRIVER_NAME,
+ .probe = mxcmci_probe,
+};
+
+static int mxcmci_init_driver(void)
+{
+ register_driver(&mxcmci_driver);
+ return 0;
+}
+
+device_initcall(mxcmci_init_driver);
+
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] ARM pca100: Add mci support
2010-10-07 15:37 Sascha Hauer
2010-10-07 15:37 ` [PATCH 1/3] mci: rename mci_platformdata to mci_host, pass mci_host to host drivers Sascha Hauer
2010-10-07 15:37 ` [PATCH 2/3] mci: Add i.MX27/31 driver Sascha Hauer
@ 2010-10-07 15:37 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2010-10-07 15:37 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/phycard-i.MX27/pca100.c | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/arch/arm/boards/phycard-i.MX27/pca100.c b/arch/arm/boards/phycard-i.MX27/pca100.c
index 7328a6c..7460c00 100644
--- a/arch/arm/boards/phycard-i.MX27/pca100.c
+++ b/arch/arm/boards/phycard-i.MX27/pca100.c
@@ -109,6 +109,11 @@ static void pca100_usbh_init(void)
}
#endif
+static struct device_d mmc_dev = {
+ .name = "imx-mmc",
+ .map_base = 0x10014000,
+};
+
#ifdef CONFIG_MMU
static void pca100_mmu_init(void)
{
@@ -180,8 +185,17 @@ static int pca100_devices_init(void)
PD23_AF_USBH2_DATA2,
PD24_AF_USBH2_DATA1,
PD26_AF_USBH2_DATA5,
+ /* SDHC */
+ PB4_PF_SD2_D0,
+ PB5_PF_SD2_D1,
+ PB6_PF_SD2_D2,
+ PB7_PF_SD2_D3,
+ PB8_PF_SD2_CMD,
+ PB9_PF_SD2_CLK,
};
+ PCCR0 |= PCCR0_SDHC2_EN;
+
/* disable the usb phys */
imx_gpio_mode((GPIO_PORTB | 23) | GPIO_GPIO | GPIO_IN);
gpio_direction_output(GPIO_PORTB + 23, 1);
@@ -195,6 +209,7 @@ static int pca100_devices_init(void)
register_device(&nand_dev);
register_device(&sdram_dev);
register_device(&fec_dev);
+ register_device(&mmc_dev);
PCCR1 |= PCCR1_PERCLK2_EN;
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 4+ messages in thread