2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-07-25 19:07:30 +00:00
|
|
|
/*
|
|
|
|
* Marvell MMC/SD/SDIO driver
|
|
|
|
*
|
2014-12-13 20:35:31 +00:00
|
|
|
* (C) Copyright 2012-2014
|
2014-07-25 19:07:30 +00:00
|
|
|
* Marvell Semiconductor <www.marvell.com>
|
|
|
|
* Written-by: Maen Suleiman, Gerald Kerma
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-07-19 07:33:36 +00:00
|
|
|
#include <errno.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2014-07-25 19:07:30 +00:00
|
|
|
#include <malloc.h>
|
2021-03-30 08:19:41 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <fdtdec.h>
|
2014-07-25 19:07:30 +00:00
|
|
|
#include <part.h>
|
|
|
|
#include <mmc.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/cpu.h>
|
2014-10-22 10:13:06 +00:00
|
|
|
#include <asm/arch/soc.h>
|
2014-07-25 19:07:30 +00:00
|
|
|
#include <mvebu_mmc.h>
|
2021-03-30 08:19:41 +00:00
|
|
|
#include <dm/device_compat.h>
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2014-08-25 12:12:26 +00:00
|
|
|
#define MVEBU_TARGET_DRAM 0
|
|
|
|
|
2014-12-13 20:35:32 +00:00
|
|
|
#define TIMEOUT_DELAY 5*CONFIG_SYS_HZ /* wait 5 seconds */
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
static inline void *get_regbase(const struct mmc *mmc)
|
2014-07-25 19:07:30 +00:00
|
|
|
{
|
2021-03-30 08:19:41 +00:00
|
|
|
struct mvebu_mmc_plat *pdata = mmc->priv;
|
|
|
|
|
|
|
|
return pdata->iobase;
|
2014-07-25 19:07:30 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
static void mvebu_mmc_write(const struct mmc *mmc, u32 offs, u32 val)
|
2014-07-25 19:07:30 +00:00
|
|
|
{
|
2021-03-30 08:19:41 +00:00
|
|
|
writel(val, get_regbase(mmc) + (offs));
|
2014-07-25 19:07:30 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
static u32 mvebu_mmc_read(const struct mmc *mmc, u32 offs)
|
2014-07-25 19:07:30 +00:00
|
|
|
{
|
2021-03-30 08:19:41 +00:00
|
|
|
return readl(get_regbase(mmc) + (offs));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mvebu_mmc_setup_data(struct udevice *dev, struct mmc_data *data)
|
|
|
|
{
|
|
|
|
struct mvebu_mmc_plat *pdata = dev_get_plat(dev);
|
|
|
|
struct mmc *mmc = &pdata->mmc;
|
2014-07-25 19:07:30 +00:00
|
|
|
u32 ctrl_reg;
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
dev_dbg(dev, "data %s : blocks=%d blksz=%d\n",
|
|
|
|
(data->flags & MMC_DATA_READ) ? "read" : "write",
|
|
|
|
data->blocks, data->blocksize);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
/* default to maximum timeout */
|
2021-03-30 08:19:41 +00:00
|
|
|
ctrl_reg = mvebu_mmc_read(mmc, SDIO_HOST_CTRL);
|
2014-07-25 19:07:30 +00:00
|
|
|
ctrl_reg |= SDIO_HOST_CTRL_TMOUT(SDIO_HOST_CTRL_TMOUT_MAX);
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_HOST_CTRL, ctrl_reg);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
if (data->flags & MMC_DATA_READ) {
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_SYS_ADDR_LOW, (u32)data->dest & 0xffff);
|
|
|
|
mvebu_mmc_write(mmc, SDIO_SYS_ADDR_HI, (u32)data->dest >> 16);
|
2014-07-25 19:07:30 +00:00
|
|
|
} else {
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_SYS_ADDR_LOW, (u32)data->src & 0xffff);
|
|
|
|
mvebu_mmc_write(mmc, SDIO_SYS_ADDR_HI, (u32)data->src >> 16);
|
2014-07-25 19:07:30 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_BLK_COUNT, data->blocks);
|
|
|
|
mvebu_mmc_write(mmc, SDIO_BLK_SIZE, data->blocksize);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
static int mvebu_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
|
2014-07-25 19:07:30 +00:00
|
|
|
struct mmc_data *data)
|
|
|
|
{
|
2014-12-13 20:35:32 +00:00
|
|
|
ulong start;
|
2014-07-25 19:07:30 +00:00
|
|
|
ushort waittype = 0;
|
|
|
|
ushort resptype = 0;
|
|
|
|
ushort xfertype = 0;
|
|
|
|
ushort resp_indx = 0;
|
2021-03-30 08:19:41 +00:00
|
|
|
struct mvebu_mmc_plat *pdata = dev_get_plat(dev);
|
|
|
|
struct mmc *mmc = &pdata->mmc;
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
dev_dbg(dev, "cmdidx [0x%x] resp_type[0x%x] cmdarg[0x%x]\n",
|
|
|
|
cmd->cmdidx, cmd->resp_type, cmd->cmdarg);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
dev_dbg(dev, "cmd %d (hw state 0x%04x)\n",
|
|
|
|
cmd->cmdidx, mvebu_mmc_read(mmc, SDIO_HW_STATE));
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2014-12-13 20:35:32 +00:00
|
|
|
/*
|
|
|
|
* Hardware weirdness. The FIFO_EMPTY bit of the HW_STATE
|
|
|
|
* register is sometimes not set before a while when some
|
|
|
|
* "unusual" data block sizes are used (such as with the SWITCH
|
|
|
|
* command), even despite the fact that the XFER_DONE interrupt
|
|
|
|
* was raised. And if another data transfer starts before
|
|
|
|
* this bit comes to good sense (which eventually happens by
|
|
|
|
* itself) then the new transfer simply fails with a timeout.
|
|
|
|
*/
|
2021-03-30 08:19:41 +00:00
|
|
|
if (!(mvebu_mmc_read(mmc, SDIO_HW_STATE) & CMD_FIFO_EMPTY)) {
|
2014-12-13 20:35:32 +00:00
|
|
|
ushort hw_state, count = 0;
|
|
|
|
|
|
|
|
start = get_timer(0);
|
|
|
|
do {
|
2021-03-30 08:19:41 +00:00
|
|
|
hw_state = mvebu_mmc_read(mmc, SDIO_HW_STATE);
|
2014-12-13 20:35:32 +00:00
|
|
|
if ((get_timer(0) - start) > TIMEOUT_DELAY) {
|
|
|
|
printf("%s : FIFO_EMPTY bit missing\n",
|
2021-03-30 08:19:41 +00:00
|
|
|
dev->name);
|
2014-12-13 20:35:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
} while (!(hw_state & CMD_FIFO_EMPTY));
|
2021-03-30 08:19:41 +00:00
|
|
|
dev_dbg(dev, "*** wait for FIFO_EMPTY bit (hw=0x%04x, count=%d, jiffies=%ld)\n",
|
|
|
|
hw_state, count, (get_timer(0) - (start)));
|
2014-07-25 19:07:30 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 20:35:35 +00:00
|
|
|
/* Clear status */
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_NOR_INTR_STATUS, SDIO_POLL_MASK);
|
|
|
|
mvebu_mmc_write(mmc, SDIO_ERR_INTR_STATUS, SDIO_POLL_MASK);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
resptype = SDIO_CMD_INDEX(cmd->cmdidx);
|
|
|
|
|
|
|
|
/* Analyzing resptype/xfertype/waittype for the command */
|
|
|
|
if (cmd->resp_type & MMC_RSP_BUSY)
|
|
|
|
resptype |= SDIO_CMD_RSP_48BUSY;
|
|
|
|
else if (cmd->resp_type & MMC_RSP_136)
|
|
|
|
resptype |= SDIO_CMD_RSP_136;
|
|
|
|
else if (cmd->resp_type & MMC_RSP_PRESENT)
|
|
|
|
resptype |= SDIO_CMD_RSP_48;
|
|
|
|
else
|
|
|
|
resptype |= SDIO_CMD_RSP_NONE;
|
|
|
|
|
|
|
|
if (cmd->resp_type & MMC_RSP_CRC)
|
|
|
|
resptype |= SDIO_CMD_CHECK_CMDCRC;
|
|
|
|
|
|
|
|
if (cmd->resp_type & MMC_RSP_OPCODE)
|
|
|
|
resptype |= SDIO_CMD_INDX_CHECK;
|
|
|
|
|
|
|
|
if (cmd->resp_type & MMC_RSP_PRESENT) {
|
|
|
|
resptype |= SDIO_UNEXPECTED_RESP;
|
|
|
|
waittype |= SDIO_NOR_UNEXP_RSP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data) {
|
2021-03-30 08:19:41 +00:00
|
|
|
int err = mvebu_mmc_setup_data(dev, data);
|
2014-12-13 20:35:35 +00:00
|
|
|
|
|
|
|
if (err) {
|
2021-03-30 08:19:41 +00:00
|
|
|
dev_dbg(dev, "command DATA error :%x\n", err);
|
2014-12-13 20:35:35 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-07-25 19:07:30 +00:00
|
|
|
resptype |= SDIO_CMD_DATA_PRESENT | SDIO_CMD_CHECK_DATACRC16;
|
|
|
|
xfertype |= SDIO_XFER_MODE_HW_WR_DATA_EN;
|
|
|
|
if (data->flags & MMC_DATA_READ) {
|
|
|
|
xfertype |= SDIO_XFER_MODE_TO_HOST;
|
|
|
|
waittype = SDIO_NOR_DMA_INI;
|
|
|
|
} else {
|
|
|
|
waittype |= SDIO_NOR_XFER_DONE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
waittype |= SDIO_NOR_CMD_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setting cmd arguments */
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_ARG_LOW, cmd->cmdarg & 0xffff);
|
|
|
|
mvebu_mmc_write(mmc, SDIO_ARG_HI, cmd->cmdarg >> 16);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
/* Setting Xfer mode */
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_XFER_MODE, xfertype);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
/* Sending command */
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_CMD, resptype);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2014-12-13 20:35:32 +00:00
|
|
|
start = get_timer(0);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
while (!((mvebu_mmc_read(mmc, SDIO_NOR_INTR_STATUS)) & waittype)) {
|
|
|
|
if (mvebu_mmc_read(mmc, SDIO_NOR_INTR_STATUS) & SDIO_NOR_ERROR) {
|
|
|
|
dev_dbg(dev, "error! cmdidx : %d, err reg: %04x\n",
|
|
|
|
cmd->cmdidx,
|
|
|
|
mvebu_mmc_read(mmc, SDIO_ERR_INTR_STATUS));
|
|
|
|
if (mvebu_mmc_read(mmc, SDIO_ERR_INTR_STATUS) &
|
2014-12-13 20:35:33 +00:00
|
|
|
(SDIO_ERR_CMD_TIMEOUT | SDIO_ERR_DATA_TIMEOUT)) {
|
2021-03-30 08:19:41 +00:00
|
|
|
dev_dbg(dev, "command READ timed out\n");
|
2016-07-19 07:33:36 +00:00
|
|
|
return -ETIMEDOUT;
|
2014-12-13 20:35:33 +00:00
|
|
|
}
|
2021-03-30 08:19:41 +00:00
|
|
|
dev_dbg(dev, "command READ error\n");
|
2016-07-19 07:33:36 +00:00
|
|
|
return -ECOMM;
|
2014-07-25 19:07:30 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 20:35:32 +00:00
|
|
|
if ((get_timer(0) - start) > TIMEOUT_DELAY) {
|
2021-03-30 08:19:41 +00:00
|
|
|
dev_dbg(dev, "command timed out\n");
|
2016-07-19 07:33:36 +00:00
|
|
|
return -ETIMEDOUT;
|
2014-07-25 19:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-13 20:35:32 +00:00
|
|
|
|
2014-07-25 19:07:30 +00:00
|
|
|
/* Handling response */
|
|
|
|
if (cmd->resp_type & MMC_RSP_136) {
|
|
|
|
uint response[8];
|
|
|
|
|
|
|
|
for (resp_indx = 0; resp_indx < 8; resp_indx++)
|
2021-03-30 08:19:41 +00:00
|
|
|
response[resp_indx] = mvebu_mmc_read(mmc, SDIO_RSP(resp_indx));
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
cmd->response[0] = ((response[0] & 0x03ff) << 22) |
|
|
|
|
((response[1] & 0xffff) << 6) |
|
|
|
|
((response[2] & 0xfc00) >> 10);
|
|
|
|
cmd->response[1] = ((response[2] & 0x03ff) << 22) |
|
|
|
|
((response[3] & 0xffff) << 6) |
|
|
|
|
((response[4] & 0xfc00) >> 10);
|
|
|
|
cmd->response[2] = ((response[4] & 0x03ff) << 22) |
|
|
|
|
((response[5] & 0xffff) << 6) |
|
|
|
|
((response[6] & 0xfc00) >> 10);
|
|
|
|
cmd->response[3] = ((response[6] & 0x03ff) << 22) |
|
|
|
|
((response[7] & 0x3fff) << 8);
|
|
|
|
} else if (cmd->resp_type & MMC_RSP_PRESENT) {
|
|
|
|
uint response[3];
|
|
|
|
|
|
|
|
for (resp_indx = 0; resp_indx < 3; resp_indx++)
|
2021-03-30 08:19:41 +00:00
|
|
|
response[resp_indx] = mvebu_mmc_read(mmc, SDIO_RSP(resp_indx));
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
cmd->response[0] = ((response[2] & 0x003f) << (8 - 8)) |
|
|
|
|
((response[1] & 0xffff) << (14 - 8)) |
|
|
|
|
((response[0] & 0x03ff) << (30 - 8));
|
|
|
|
cmd->response[1] = ((response[0] & 0xfc00) >> 10);
|
|
|
|
cmd->response[2] = 0;
|
|
|
|
cmd->response[3] = 0;
|
2014-12-13 20:35:35 +00:00
|
|
|
} else {
|
|
|
|
cmd->response[0] = 0;
|
|
|
|
cmd->response[1] = 0;
|
|
|
|
cmd->response[2] = 0;
|
|
|
|
cmd->response[3] = 0;
|
2014-07-25 19:07:30 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
dev_dbg(dev, "resp[0x%x] ", cmd->resp_type);
|
2014-07-25 19:07:30 +00:00
|
|
|
debug("[0x%x] ", cmd->response[0]);
|
|
|
|
debug("[0x%x] ", cmd->response[1]);
|
|
|
|
debug("[0x%x] ", cmd->response[2]);
|
|
|
|
debug("[0x%x] ", cmd->response[3]);
|
|
|
|
debug("\n");
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
if (mvebu_mmc_read(mmc, SDIO_ERR_INTR_STATUS) &
|
2014-12-13 20:35:35 +00:00
|
|
|
(SDIO_ERR_CMD_TIMEOUT | SDIO_ERR_DATA_TIMEOUT))
|
2016-07-19 07:33:36 +00:00
|
|
|
return -ETIMEDOUT;
|
2014-12-13 20:35:35 +00:00
|
|
|
|
2014-07-25 19:07:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
static void mvebu_mmc_power_up(struct udevice *dev)
|
2014-07-25 19:07:30 +00:00
|
|
|
{
|
2021-03-30 08:19:41 +00:00
|
|
|
struct mvebu_mmc_plat *pdata = dev_get_plat(dev);
|
|
|
|
struct mmc *mmc = &pdata->mmc;
|
|
|
|
|
|
|
|
dev_dbg(dev, "power up\n");
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
/* disable interrupts */
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_NOR_INTR_EN, 0);
|
|
|
|
mvebu_mmc_write(mmc, SDIO_ERR_INTR_EN, 0);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
/* SW reset */
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_SW_RESET, SDIO_SW_RESET_NOW);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_XFER_MODE, 0);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
/* enable status */
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_NOR_STATUS_EN, SDIO_POLL_MASK);
|
|
|
|
mvebu_mmc_write(mmc, SDIO_ERR_STATUS_EN, SDIO_POLL_MASK);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
/* enable interrupts status */
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_NOR_INTR_STATUS, SDIO_POLL_MASK);
|
|
|
|
mvebu_mmc_write(mmc, SDIO_ERR_INTR_STATUS, SDIO_POLL_MASK);
|
2014-07-25 19:07:30 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
static void mvebu_mmc_set_clk(struct udevice *dev, unsigned int clock)
|
2014-07-25 19:07:30 +00:00
|
|
|
{
|
|
|
|
unsigned int m;
|
2021-03-30 08:19:41 +00:00
|
|
|
struct mvebu_mmc_plat *pdata = dev_get_plat(dev);
|
|
|
|
struct mmc *mmc = &pdata->mmc;
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
if (clock == 0) {
|
2021-03-30 08:19:41 +00:00
|
|
|
dev_dbg(dev, "clock off\n");
|
|
|
|
mvebu_mmc_write(mmc, SDIO_XFER_MODE, SDIO_XFER_MODE_STOP_CLK);
|
|
|
|
mvebu_mmc_write(mmc, SDIO_CLK_DIV, MVEBU_MMC_BASE_DIV_MAX);
|
2014-07-25 19:07:30 +00:00
|
|
|
} else {
|
|
|
|
m = MVEBU_MMC_BASE_FAST_CLOCK/(2*clock) - 1;
|
|
|
|
if (m > MVEBU_MMC_BASE_DIV_MAX)
|
|
|
|
m = MVEBU_MMC_BASE_DIV_MAX;
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_CLK_DIV, m & MVEBU_MMC_BASE_DIV_MAX);
|
|
|
|
dev_dbg(dev, "clock (%d) div : %d\n", clock, m);
|
2014-07-25 19:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
static void mvebu_mmc_set_bus(struct udevice *dev, unsigned int bus)
|
2014-07-25 19:07:30 +00:00
|
|
|
{
|
2021-03-30 08:19:41 +00:00
|
|
|
struct mvebu_mmc_plat *pdata = dev_get_plat(dev);
|
|
|
|
struct mmc *mmc = &pdata->mmc;
|
2014-07-25 19:07:30 +00:00
|
|
|
u32 ctrl_reg = 0;
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
ctrl_reg = mvebu_mmc_read(mmc, SDIO_HOST_CTRL);
|
2014-07-25 19:07:30 +00:00
|
|
|
ctrl_reg &= ~SDIO_HOST_CTRL_DATA_WIDTH_4_BITS;
|
|
|
|
|
|
|
|
switch (bus) {
|
|
|
|
case 4:
|
|
|
|
ctrl_reg |= SDIO_HOST_CTRL_DATA_WIDTH_4_BITS;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
default:
|
|
|
|
ctrl_reg |= SDIO_HOST_CTRL_DATA_WIDTH_1_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default transfer mode */
|
|
|
|
ctrl_reg |= SDIO_HOST_CTRL_BIG_ENDIAN;
|
|
|
|
ctrl_reg &= ~SDIO_HOST_CTRL_LSB_FIRST;
|
|
|
|
|
|
|
|
/* default to maximum timeout */
|
|
|
|
ctrl_reg |= SDIO_HOST_CTRL_TMOUT(SDIO_HOST_CTRL_TMOUT_MAX);
|
2014-08-25 12:12:26 +00:00
|
|
|
ctrl_reg |= SDIO_HOST_CTRL_TMOUT_EN;
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
ctrl_reg |= SDIO_HOST_CTRL_PUSH_PULL_EN;
|
|
|
|
|
|
|
|
ctrl_reg |= SDIO_HOST_CTRL_CARD_TYPE_MEM_ONLY;
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
dev_dbg(dev, "ctrl 0x%04x: %s %s %s\n", ctrl_reg,
|
|
|
|
(ctrl_reg & SDIO_HOST_CTRL_PUSH_PULL_EN) ?
|
|
|
|
"push-pull" : "open-drain",
|
|
|
|
(ctrl_reg & SDIO_HOST_CTRL_DATA_WIDTH_4_BITS) ?
|
|
|
|
"4bit-width" : "1bit-width",
|
|
|
|
(ctrl_reg & SDIO_HOST_CTRL_HI_SPEED_EN) ?
|
|
|
|
"high-speed" : "");
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_HOST_CTRL, ctrl_reg);
|
2014-07-25 19:07:30 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
static int mvebu_mmc_set_ios(struct udevice *dev)
|
2014-07-25 19:07:30 +00:00
|
|
|
{
|
2021-03-30 08:19:41 +00:00
|
|
|
struct mvebu_mmc_plat *pdata = dev_get_plat(dev);
|
|
|
|
struct mmc *mmc = &pdata->mmc;
|
|
|
|
|
|
|
|
dev_dbg(dev, "bus[%d] clock[%d]\n",
|
|
|
|
mmc->bus_width, mmc->clock);
|
|
|
|
mvebu_mmc_set_bus(dev, mmc->bus_width);
|
|
|
|
mvebu_mmc_set_clk(dev, mmc->clock);
|
2016-12-30 06:30:16 +00:00
|
|
|
|
|
|
|
return 0;
|
2014-07-25 19:07:30 +00:00
|
|
|
}
|
|
|
|
|
2014-08-25 12:12:26 +00:00
|
|
|
/*
|
|
|
|
* Set window register.
|
|
|
|
*/
|
2021-03-30 08:19:41 +00:00
|
|
|
static void mvebu_window_setup(const struct mmc *mmc)
|
2014-08-25 12:12:26 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, WINDOW_CTRL(i), 0);
|
|
|
|
mvebu_mmc_write(mmc, WINDOW_BASE(i), 0);
|
2014-08-25 12:12:26 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
|
|
|
|
u32 size, base, attrib;
|
|
|
|
|
|
|
|
/* Enable DRAM bank */
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
attrib = KWCPU_ATTR_DRAM_CS0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
attrib = KWCPU_ATTR_DRAM_CS1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
attrib = KWCPU_ATTR_DRAM_CS2;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
attrib = KWCPU_ATTR_DRAM_CS3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* invalide bank, disable access */
|
|
|
|
attrib = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = gd->bd->bi_dram[i].size;
|
|
|
|
base = gd->bd->bi_dram[i].start;
|
|
|
|
if (size && attrib) {
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, WINDOW_CTRL(i),
|
2014-08-25 12:12:26 +00:00
|
|
|
MVCPU_WIN_CTRL_DATA(size,
|
|
|
|
MVEBU_TARGET_DRAM,
|
|
|
|
attrib,
|
|
|
|
MVCPU_WIN_ENABLE));
|
|
|
|
} else {
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, WINDOW_CTRL(i), MVCPU_WIN_DISABLE);
|
2014-08-25 12:12:26 +00:00
|
|
|
}
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, WINDOW_BASE(i), base);
|
2014-08-25 12:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
static int mvebu_mmc_initialize(struct udevice *dev)
|
2014-07-25 19:07:30 +00:00
|
|
|
{
|
2021-03-30 08:19:41 +00:00
|
|
|
struct mvebu_mmc_plat *pdata = dev_get_plat(dev);
|
|
|
|
struct mmc *mmc = &pdata->mmc;
|
|
|
|
|
|
|
|
dev_dbg(dev, "%s\n", __func__);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setting host parameters
|
|
|
|
* Initial Host Ctrl : Timeout : max , Normal Speed mode,
|
|
|
|
* 4-bit data mode, Big Endian, SD memory Card, Push_pull CMD Line
|
|
|
|
*/
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_HOST_CTRL,
|
2014-07-25 19:07:30 +00:00
|
|
|
SDIO_HOST_CTRL_TMOUT(SDIO_HOST_CTRL_TMOUT_MAX) |
|
|
|
|
SDIO_HOST_CTRL_DATA_WIDTH_4_BITS |
|
|
|
|
SDIO_HOST_CTRL_BIG_ENDIAN |
|
|
|
|
SDIO_HOST_CTRL_PUSH_PULL_EN |
|
|
|
|
SDIO_HOST_CTRL_CARD_TYPE_MEM_ONLY);
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_CLK_CTRL, 0);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
/* enable status */
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_NOR_STATUS_EN, SDIO_POLL_MASK);
|
|
|
|
mvebu_mmc_write(mmc, SDIO_ERR_STATUS_EN, SDIO_POLL_MASK);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
/* disable interrupts */
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_NOR_INTR_EN, 0);
|
|
|
|
mvebu_mmc_write(mmc, SDIO_ERR_INTR_EN, 0);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_window_setup(mmc);
|
2014-08-25 12:12:26 +00:00
|
|
|
|
2014-07-25 19:07:30 +00:00
|
|
|
/* SW reset */
|
2021-03-30 08:19:41 +00:00
|
|
|
mvebu_mmc_write(mmc, SDIO_SW_RESET, SDIO_SW_RESET_NOW);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
static int mvebu_mmc_of_to_plat(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mvebu_mmc_plat *pdata = dev_get_plat(dev);
|
|
|
|
fdt_addr_t addr;
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
addr = dev_read_addr(dev);
|
|
|
|
if (addr == FDT_ADDR_T_NONE)
|
|
|
|
return -EINVAL;
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
pdata->iobase = (void *)addr;
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-07-25 19:07:30 +00:00
|
|
|
|
2021-03-30 08:19:41 +00:00
|
|
|
static int mvebu_mmc_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mvebu_mmc_plat *pdata = dev_get_plat(dev);
|
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
|
|
|
|
struct mmc *mmc = &pdata->mmc;
|
|
|
|
struct mmc_config *cfg = &pdata->cfg;
|
|
|
|
|
|
|
|
cfg->name = dev->name;
|
|
|
|
cfg->f_min = MVEBU_MMC_BASE_FAST_CLOCK / MVEBU_MMC_BASE_DIV_MAX;
|
|
|
|
cfg->f_max = MVEBU_MMC_CLOCKRATE_MAX;
|
|
|
|
cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
|
|
|
|
cfg->host_caps = MMC_MODE_4BIT | MMC_MODE_HS | MMC_MODE_HS_52MHz;
|
|
|
|
cfg->part_type = PART_TYPE_DOS;
|
|
|
|
cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
|
|
|
|
|
|
|
|
mmc->cfg = cfg;
|
|
|
|
mmc->priv = pdata;
|
|
|
|
mmc->dev = dev;
|
|
|
|
upriv->mmc = mmc;
|
|
|
|
|
|
|
|
mvebu_mmc_power_up(dev);
|
|
|
|
mvebu_mmc_initialize(dev);
|
2014-07-25 19:07:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-03-30 08:19:41 +00:00
|
|
|
|
|
|
|
static const struct dm_mmc_ops mvebu_dm_mmc_ops = {
|
|
|
|
.send_cmd = mvebu_mmc_send_cmd,
|
|
|
|
.set_ios = mvebu_mmc_set_ios,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int mvebu_mmc_bind(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mvebu_mmc_plat *pdata = dev_get_plat(dev);
|
|
|
|
|
|
|
|
return mmc_bind(dev, &pdata->mmc, &pdata->cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id mvebu_mmc_match[] = {
|
|
|
|
{ .compatible = "marvell,orion-sdio" },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(mvebu_mmc) = {
|
|
|
|
.name = "mvebu_mmc",
|
|
|
|
.id = UCLASS_MMC,
|
|
|
|
.of_match = mvebu_mmc_match,
|
|
|
|
.ops = &mvebu_dm_mmc_ops,
|
|
|
|
.probe = mvebu_mmc_probe,
|
|
|
|
.bind = mvebu_mmc_bind,
|
|
|
|
.of_to_plat = mvebu_mmc_of_to_plat,
|
|
|
|
.plat_auto = sizeof(struct mvebu_mmc_plat),
|
|
|
|
};
|