2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-11-08 23:18:09 +00:00
|
|
|
/*
|
|
|
|
* Freescale i.MX28 SSP MMC driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
|
|
|
|
* on behalf of DENX Software Engineering GmbH
|
|
|
|
*
|
|
|
|
* Based on code from LTIB:
|
|
|
|
* (C) Copyright 2008-2010 Freescale Semiconductor, Inc.
|
|
|
|
* Terry Lv
|
|
|
|
*
|
|
|
|
* Copyright 2007, Freescale Semiconductor, Inc
|
|
|
|
* Andy Fleming
|
|
|
|
*
|
|
|
|
* Based vaguely on the pxa mmc code:
|
|
|
|
* (C) Copyright 2003
|
|
|
|
* Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <mmc.h>
|
2016-09-21 02:28:55 +00:00
|
|
|
#include <linux/errno.h>
|
2011-11-08 23:18:09 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/clock.h>
|
|
|
|
#include <asm/arch/imx-regs.h>
|
|
|
|
#include <asm/arch/sys_proto.h>
|
2017-06-29 08:16:06 +00:00
|
|
|
#include <asm/mach-imx/dma.h>
|
2012-08-26 15:19:07 +00:00
|
|
|
#include <bouncebuf.h>
|
2011-11-08 23:18:09 +00:00
|
|
|
|
|
|
|
struct mxsmmc_priv {
|
|
|
|
int id;
|
2012-08-05 09:05:31 +00:00
|
|
|
struct mxs_ssp_regs *regs;
|
2011-11-08 23:18:09 +00:00
|
|
|
uint32_t buswidth;
|
|
|
|
int (*mmc_is_wp)(int);
|
2013-01-22 15:01:03 +00:00
|
|
|
int (*mmc_cd)(int);
|
2012-03-15 18:33:21 +00:00
|
|
|
struct mxs_dma_desc *desc;
|
2014-03-11 17:34:20 +00:00
|
|
|
struct mmc_config cfg; /* mmc configuration */
|
2011-11-08 23:18:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define MXSMMC_MAX_TIMEOUT 10000
|
2012-07-06 21:25:56 +00:00
|
|
|
#define MXSMMC_SMALL_TRANSFER 512
|
2011-11-08 23:18:09 +00:00
|
|
|
|
2013-01-22 15:01:03 +00:00
|
|
|
static int mxsmmc_cd(struct mxsmmc_priv *priv)
|
|
|
|
{
|
|
|
|
struct mxs_ssp_regs *ssp_regs = priv->regs;
|
|
|
|
|
|
|
|
if (priv->mmc_cd)
|
|
|
|
return priv->mmc_cd(priv->id);
|
|
|
|
|
|
|
|
return !(readl(&ssp_regs->hw_ssp_status) & SSP_STATUS_CARD_DETECT);
|
|
|
|
}
|
|
|
|
|
2012-07-06 21:25:55 +00:00
|
|
|
static int mxsmmc_send_cmd_pio(struct mxsmmc_priv *priv, struct mmc_data *data)
|
|
|
|
{
|
|
|
|
struct mxs_ssp_regs *ssp_regs = priv->regs;
|
|
|
|
uint32_t *data_ptr;
|
|
|
|
int timeout = MXSMMC_MAX_TIMEOUT;
|
|
|
|
uint32_t reg;
|
|
|
|
uint32_t data_count = data->blocksize * data->blocks;
|
|
|
|
|
|
|
|
if (data->flags & MMC_DATA_READ) {
|
|
|
|
data_ptr = (uint32_t *)data->dest;
|
|
|
|
while (data_count && --timeout) {
|
|
|
|
reg = readl(&ssp_regs->hw_ssp_status);
|
|
|
|
if (!(reg & SSP_STATUS_FIFO_EMPTY)) {
|
|
|
|
*data_ptr++ = readl(&ssp_regs->hw_ssp_data);
|
|
|
|
data_count -= 4;
|
|
|
|
timeout = MXSMMC_MAX_TIMEOUT;
|
|
|
|
} else
|
|
|
|
udelay(1000);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data_ptr = (uint32_t *)data->src;
|
|
|
|
timeout *= 100;
|
|
|
|
while (data_count && --timeout) {
|
|
|
|
reg = readl(&ssp_regs->hw_ssp_status);
|
|
|
|
if (!(reg & SSP_STATUS_FIFO_FULL)) {
|
|
|
|
writel(*data_ptr++, &ssp_regs->hw_ssp_data);
|
|
|
|
data_count -= 4;
|
|
|
|
timeout = MXSMMC_MAX_TIMEOUT;
|
|
|
|
} else
|
|
|
|
udelay(1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 07:33:36 +00:00
|
|
|
return timeout ? 0 : -ECOMM;
|
2012-07-06 21:25:55 +00:00
|
|
|
}
|
2012-07-06 21:25:56 +00:00
|
|
|
|
2012-07-06 21:25:55 +00:00
|
|
|
static int mxsmmc_send_cmd_dma(struct mxsmmc_priv *priv, struct mmc_data *data)
|
|
|
|
{
|
|
|
|
uint32_t data_count = data->blocksize * data->blocks;
|
|
|
|
int dmach;
|
2012-07-06 21:25:57 +00:00
|
|
|
struct mxs_dma_desc *desc = priv->desc;
|
2012-11-06 11:27:29 +00:00
|
|
|
void *addr;
|
|
|
|
unsigned int flags;
|
|
|
|
struct bounce_buffer bbstate;
|
2012-07-06 21:25:57 +00:00
|
|
|
|
|
|
|
memset(desc, 0, sizeof(struct mxs_dma_desc));
|
|
|
|
desc->address = (dma_addr_t)desc;
|
2012-07-06 21:25:55 +00:00
|
|
|
|
|
|
|
if (data->flags & MMC_DATA_READ) {
|
|
|
|
priv->desc->cmd.data = MXS_DMA_DESC_COMMAND_DMA_WRITE;
|
2012-08-26 15:19:07 +00:00
|
|
|
addr = data->dest;
|
|
|
|
flags = GEN_BB_WRITE;
|
2012-07-06 21:25:55 +00:00
|
|
|
} else {
|
|
|
|
priv->desc->cmd.data = MXS_DMA_DESC_COMMAND_DMA_READ;
|
2012-08-26 15:19:07 +00:00
|
|
|
addr = (void *)data->src;
|
|
|
|
flags = GEN_BB_READ;
|
|
|
|
}
|
|
|
|
|
2012-11-06 11:27:29 +00:00
|
|
|
bounce_buffer_start(&bbstate, addr, data_count, flags);
|
2012-08-26 15:19:07 +00:00
|
|
|
|
2012-11-06 11:27:29 +00:00
|
|
|
priv->desc->cmd.address = (dma_addr_t)bbstate.bounce_buffer;
|
2012-08-31 16:18:10 +00:00
|
|
|
|
2012-07-06 21:25:55 +00:00
|
|
|
priv->desc->cmd.data |= MXS_DMA_DESC_IRQ | MXS_DMA_DESC_DEC_SEM |
|
|
|
|
(data_count << MXS_DMA_DESC_BYTES_OFFSET);
|
|
|
|
|
mxs: mmc: spi: dma: Better wrap the MXS differences
This patch streamlines the differences between the MX23 and MX28 by
implementing a few helper functions to handle different DMA channel
mapping, different clock domain for SSP block and fixes a few minor
bugs.
First of all, the DMA channel mapping is now fixed in dma.h by defining
the actual channel map for both MX23 and MX28. Thus, MX23 now does no
longer use MX28 channel map which was wrong. Also, there is a fix for
MX28 DMA channel map, where the last four channels were incorrect.
Next, because correct DMA channel map is in place, the mxs_dma_init_channel()
call now bases the channel ID starting from SSP port #0. This removes the
need for DMA channel offset being added and cleans up the code. For the
same reason, the SSP0 offset can now be used in mxs_dma_desc_append(), thus
no need to adjust dma channel number in the driver either.
Lastly, the SSP clock ID is now retrieved by calling mxs_ssp_clock_by_bus()
which handles the fact that MX23 has shared SSP clock for both ports, while
MX28 has per-port SSP clock.
Finally, the mxs_ssp_bus_id_valid() pulls out two implementations of the
same functionality from MMC and SPI driver into common code.
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Otavio Salvador <otavio@ossystems.com.br>
Cc: Stefano Babic <sbabic@denx.de>
2013-02-23 02:42:58 +00:00
|
|
|
dmach = MXS_DMA_CHANNEL_AHB_APBH_SSP0 + priv->id;
|
2012-07-06 21:25:55 +00:00
|
|
|
mxs_dma_desc_append(dmach, priv->desc);
|
2012-08-26 15:19:07 +00:00
|
|
|
if (mxs_dma_go(dmach)) {
|
2012-11-06 11:27:29 +00:00
|
|
|
bounce_buffer_stop(&bbstate);
|
2016-07-19 07:33:36 +00:00
|
|
|
return -ECOMM;
|
2012-08-26 15:19:07 +00:00
|
|
|
}
|
2012-07-06 21:25:55 +00:00
|
|
|
|
2012-11-06 11:27:29 +00:00
|
|
|
bounce_buffer_stop(&bbstate);
|
2012-08-26 15:19:07 +00:00
|
|
|
|
2012-07-06 21:25:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-08 23:18:09 +00:00
|
|
|
/*
|
|
|
|
* Sends a command out on the bus. Takes the mmc pointer,
|
|
|
|
* a command pointer, and an optional data pointer.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
mxsmmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
|
|
|
|
{
|
2014-03-11 17:34:20 +00:00
|
|
|
struct mxsmmc_priv *priv = mmc->priv;
|
2012-08-05 09:05:31 +00:00
|
|
|
struct mxs_ssp_regs *ssp_regs = priv->regs;
|
2011-11-08 23:18:09 +00:00
|
|
|
uint32_t reg;
|
|
|
|
int timeout;
|
|
|
|
uint32_t ctrl0;
|
2012-07-06 21:25:55 +00:00
|
|
|
int ret;
|
2011-11-08 23:18:09 +00:00
|
|
|
|
2016-02-29 22:25:51 +00:00
|
|
|
debug("MMC%d: CMD%d\n", mmc->block_dev.devnum, cmd->cmdidx);
|
2011-11-08 23:18:09 +00:00
|
|
|
|
|
|
|
/* Check bus busy */
|
|
|
|
timeout = MXSMMC_MAX_TIMEOUT;
|
|
|
|
while (--timeout) {
|
|
|
|
udelay(1000);
|
|
|
|
reg = readl(&ssp_regs->hw_ssp_status);
|
|
|
|
if (!(reg &
|
|
|
|
(SSP_STATUS_BUSY | SSP_STATUS_DATA_BUSY |
|
|
|
|
SSP_STATUS_CMD_BUSY))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!timeout) {
|
2016-02-29 22:25:51 +00:00
|
|
|
printf("MMC%d: Bus busy timeout!\n", mmc->block_dev.devnum);
|
2016-07-19 07:33:36 +00:00
|
|
|
return -ETIMEDOUT;
|
2011-11-08 23:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* See if card is present */
|
2013-01-22 15:01:03 +00:00
|
|
|
if (!mxsmmc_cd(priv)) {
|
2016-02-29 22:25:51 +00:00
|
|
|
printf("MMC%d: No card detected!\n", mmc->block_dev.devnum);
|
2016-07-19 07:33:36 +00:00
|
|
|
return -ENOMEDIUM;
|
2011-11-08 23:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Start building CTRL0 contents */
|
|
|
|
ctrl0 = priv->buswidth;
|
|
|
|
|
|
|
|
/* Set up command */
|
|
|
|
if (!(cmd->resp_type & MMC_RSP_CRC))
|
|
|
|
ctrl0 |= SSP_CTRL0_IGNORE_CRC;
|
|
|
|
if (cmd->resp_type & MMC_RSP_PRESENT) /* Need to get response */
|
|
|
|
ctrl0 |= SSP_CTRL0_GET_RESP;
|
|
|
|
if (cmd->resp_type & MMC_RSP_136) /* It's a 136 bits response */
|
|
|
|
ctrl0 |= SSP_CTRL0_LONG_RESP;
|
|
|
|
|
2012-07-06 21:25:57 +00:00
|
|
|
if (data && (data->blocksize * data->blocks < MXSMMC_SMALL_TRANSFER))
|
|
|
|
writel(SSP_CTRL1_DMA_ENABLE, &ssp_regs->hw_ssp_ctrl1_clr);
|
|
|
|
else
|
|
|
|
writel(SSP_CTRL1_DMA_ENABLE, &ssp_regs->hw_ssp_ctrl1_set);
|
|
|
|
|
2011-11-08 23:18:09 +00:00
|
|
|
/* Command index */
|
|
|
|
reg = readl(&ssp_regs->hw_ssp_cmd0);
|
|
|
|
reg &= ~(SSP_CMD0_CMD_MASK | SSP_CMD0_APPEND_8CYC);
|
|
|
|
reg |= cmd->cmdidx << SSP_CMD0_CMD_OFFSET;
|
|
|
|
if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
|
|
|
|
reg |= SSP_CMD0_APPEND_8CYC;
|
|
|
|
writel(reg, &ssp_regs->hw_ssp_cmd0);
|
|
|
|
|
|
|
|
/* Command argument */
|
|
|
|
writel(cmd->cmdarg, &ssp_regs->hw_ssp_cmd1);
|
|
|
|
|
|
|
|
/* Set up data */
|
|
|
|
if (data) {
|
|
|
|
/* READ or WRITE */
|
|
|
|
if (data->flags & MMC_DATA_READ) {
|
|
|
|
ctrl0 |= SSP_CTRL0_READ;
|
2012-05-01 11:09:52 +00:00
|
|
|
} else if (priv->mmc_is_wp &&
|
2016-02-29 22:25:51 +00:00
|
|
|
priv->mmc_is_wp(mmc->block_dev.devnum)) {
|
2011-11-08 23:18:09 +00:00
|
|
|
printf("MMC%d: Can not write a locked card!\n",
|
2016-02-29 22:25:51 +00:00
|
|
|
mmc->block_dev.devnum);
|
2016-07-19 07:33:36 +00:00
|
|
|
return -EOPNOTSUPP;
|
2011-11-08 23:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctrl0 |= SSP_CTRL0_DATA_XFER;
|
2013-01-22 15:01:04 +00:00
|
|
|
|
|
|
|
reg = data->blocksize * data->blocks;
|
|
|
|
#if defined(CONFIG_MX23)
|
|
|
|
ctrl0 |= reg & SSP_CTRL0_XFER_COUNT_MASK;
|
|
|
|
|
|
|
|
clrsetbits_le32(&ssp_regs->hw_ssp_cmd0,
|
|
|
|
SSP_CMD0_BLOCK_SIZE_MASK | SSP_CMD0_BLOCK_COUNT_MASK,
|
|
|
|
((data->blocks - 1) << SSP_CMD0_BLOCK_COUNT_OFFSET) |
|
|
|
|
((ffs(data->blocksize) - 1) <<
|
|
|
|
SSP_CMD0_BLOCK_SIZE_OFFSET));
|
|
|
|
#elif defined(CONFIG_MX28)
|
|
|
|
writel(reg, &ssp_regs->hw_ssp_xfer_size);
|
|
|
|
|
2011-11-08 23:18:09 +00:00
|
|
|
reg = ((data->blocks - 1) <<
|
|
|
|
SSP_BLOCK_SIZE_BLOCK_COUNT_OFFSET) |
|
|
|
|
((ffs(data->blocksize) - 1) <<
|
|
|
|
SSP_BLOCK_SIZE_BLOCK_SIZE_OFFSET);
|
|
|
|
writel(reg, &ssp_regs->hw_ssp_block_size);
|
2013-01-22 15:01:04 +00:00
|
|
|
#endif
|
2011-11-08 23:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Kick off the command */
|
|
|
|
ctrl0 |= SSP_CTRL0_WAIT_FOR_IRQ | SSP_CTRL0_ENABLE | SSP_CTRL0_RUN;
|
|
|
|
writel(ctrl0, &ssp_regs->hw_ssp_ctrl0);
|
|
|
|
|
|
|
|
/* Wait for the command to complete */
|
|
|
|
timeout = MXSMMC_MAX_TIMEOUT;
|
|
|
|
while (--timeout) {
|
|
|
|
udelay(1000);
|
|
|
|
reg = readl(&ssp_regs->hw_ssp_status);
|
|
|
|
if (!(reg & SSP_STATUS_CMD_BUSY))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!timeout) {
|
|
|
|
printf("MMC%d: Command %d busy\n",
|
2016-02-29 22:25:51 +00:00
|
|
|
mmc->block_dev.devnum, cmd->cmdidx);
|
2016-07-19 07:33:36 +00:00
|
|
|
return -ETIMEDOUT;
|
2011-11-08 23:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check command timeout */
|
|
|
|
if (reg & SSP_STATUS_RESP_TIMEOUT) {
|
|
|
|
printf("MMC%d: Command %d timeout (status 0x%08x)\n",
|
2016-02-29 22:25:51 +00:00
|
|
|
mmc->block_dev.devnum, cmd->cmdidx, reg);
|
2016-07-19 07:33:36 +00:00
|
|
|
return -ETIMEDOUT;
|
2011-11-08 23:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check command errors */
|
|
|
|
if (reg & (SSP_STATUS_RESP_CRC_ERR | SSP_STATUS_RESP_ERR)) {
|
|
|
|
printf("MMC%d: Command %d error (status 0x%08x)!\n",
|
2016-02-29 22:25:51 +00:00
|
|
|
mmc->block_dev.devnum, cmd->cmdidx, reg);
|
2016-07-19 07:33:36 +00:00
|
|
|
return -ECOMM;
|
2011-11-08 23:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy response to response buffer */
|
|
|
|
if (cmd->resp_type & MMC_RSP_136) {
|
|
|
|
cmd->response[3] = readl(&ssp_regs->hw_ssp_sdresp0);
|
|
|
|
cmd->response[2] = readl(&ssp_regs->hw_ssp_sdresp1);
|
|
|
|
cmd->response[1] = readl(&ssp_regs->hw_ssp_sdresp2);
|
|
|
|
cmd->response[0] = readl(&ssp_regs->hw_ssp_sdresp3);
|
|
|
|
} else
|
|
|
|
cmd->response[0] = readl(&ssp_regs->hw_ssp_sdresp0);
|
|
|
|
|
|
|
|
/* Return if no data to process */
|
|
|
|
if (!data)
|
|
|
|
return 0;
|
|
|
|
|
2012-07-06 21:25:56 +00:00
|
|
|
if (data->blocksize * data->blocks < MXSMMC_SMALL_TRANSFER) {
|
|
|
|
ret = mxsmmc_send_cmd_pio(priv, data);
|
|
|
|
if (ret) {
|
|
|
|
printf("MMC%d: Data timeout with command %d "
|
|
|
|
"(status 0x%08x)!\n",
|
2016-02-29 22:25:51 +00:00
|
|
|
mmc->block_dev.devnum, cmd->cmdidx, reg);
|
2012-07-06 21:25:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2012-07-06 21:25:57 +00:00
|
|
|
} else {
|
|
|
|
ret = mxsmmc_send_cmd_dma(priv, data);
|
|
|
|
if (ret) {
|
|
|
|
printf("MMC%d: DMA transfer failed\n",
|
2016-02-29 22:25:51 +00:00
|
|
|
mmc->block_dev.devnum);
|
2012-07-06 21:25:57 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2012-04-05 03:30:35 +00:00
|
|
|
}
|
2012-03-15 18:33:21 +00:00
|
|
|
|
2011-11-08 23:18:09 +00:00
|
|
|
/* Check data errors */
|
|
|
|
reg = readl(&ssp_regs->hw_ssp_status);
|
|
|
|
if (reg &
|
|
|
|
(SSP_STATUS_TIMEOUT | SSP_STATUS_DATA_CRC_ERR |
|
|
|
|
SSP_STATUS_FIFO_OVRFLW | SSP_STATUS_FIFO_UNDRFLW)) {
|
|
|
|
printf("MMC%d: Data error with command %d (status 0x%08x)!\n",
|
2016-02-29 22:25:51 +00:00
|
|
|
mmc->block_dev.devnum, cmd->cmdidx, reg);
|
2016-07-19 07:33:36 +00:00
|
|
|
return -ECOMM;
|
2011-11-08 23:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-30 06:30:16 +00:00
|
|
|
static int mxsmmc_set_ios(struct mmc *mmc)
|
2011-11-08 23:18:09 +00:00
|
|
|
{
|
2014-03-11 17:34:20 +00:00
|
|
|
struct mxsmmc_priv *priv = mmc->priv;
|
2012-08-05 09:05:31 +00:00
|
|
|
struct mxs_ssp_regs *ssp_regs = priv->regs;
|
2011-11-08 23:18:09 +00:00
|
|
|
|
|
|
|
/* Set the clock speed */
|
|
|
|
if (mmc->clock)
|
2013-01-11 03:19:03 +00:00
|
|
|
mxs_set_ssp_busclock(priv->id, mmc->clock / 1000);
|
2011-11-08 23:18:09 +00:00
|
|
|
|
|
|
|
switch (mmc->bus_width) {
|
|
|
|
case 1:
|
|
|
|
priv->buswidth = SSP_CTRL0_BUS_WIDTH_ONE_BIT;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
priv->buswidth = SSP_CTRL0_BUS_WIDTH_FOUR_BIT;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
priv->buswidth = SSP_CTRL0_BUS_WIDTH_EIGHT_BIT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the bus width */
|
|
|
|
clrsetbits_le32(&ssp_regs->hw_ssp_ctrl0,
|
|
|
|
SSP_CTRL0_BUS_WIDTH_MASK, priv->buswidth);
|
|
|
|
|
|
|
|
debug("MMC%d: Set %d bits bus width\n",
|
2016-02-29 22:25:51 +00:00
|
|
|
mmc->block_dev.devnum, mmc->bus_width);
|
2016-12-30 06:30:16 +00:00
|
|
|
|
|
|
|
return 0;
|
2011-11-08 23:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mxsmmc_init(struct mmc *mmc)
|
|
|
|
{
|
2014-03-11 17:34:20 +00:00
|
|
|
struct mxsmmc_priv *priv = mmc->priv;
|
2012-08-05 09:05:31 +00:00
|
|
|
struct mxs_ssp_regs *ssp_regs = priv->regs;
|
2011-11-08 23:18:09 +00:00
|
|
|
|
|
|
|
/* Reset SSP */
|
2012-08-13 09:53:12 +00:00
|
|
|
mxs_reset_block(&ssp_regs->hw_ssp_ctrl0_reg);
|
2011-11-08 23:18:09 +00:00
|
|
|
|
2013-01-22 15:01:02 +00:00
|
|
|
/* Reconfigure the SSP block for MMC operation */
|
|
|
|
writel(SSP_CTRL1_SSP_MODE_SD_MMC |
|
|
|
|
SSP_CTRL1_WORD_LENGTH_EIGHT_BITS |
|
|
|
|
SSP_CTRL1_DMA_ENABLE |
|
|
|
|
SSP_CTRL1_POLARITY |
|
|
|
|
SSP_CTRL1_RECV_TIMEOUT_IRQ_EN |
|
|
|
|
SSP_CTRL1_DATA_CRC_IRQ_EN |
|
|
|
|
SSP_CTRL1_DATA_TIMEOUT_IRQ_EN |
|
|
|
|
SSP_CTRL1_RESP_TIMEOUT_IRQ_EN |
|
|
|
|
SSP_CTRL1_RESP_ERR_IRQ_EN,
|
|
|
|
&ssp_regs->hw_ssp_ctrl1_set);
|
2011-11-08 23:18:09 +00:00
|
|
|
|
|
|
|
/* Set initial bit clock 400 KHz */
|
2013-01-11 03:19:03 +00:00
|
|
|
mxs_set_ssp_busclock(priv->id, 400);
|
2011-11-08 23:18:09 +00:00
|
|
|
|
|
|
|
/* Send initial 74 clock cycles (185 us @ 400 KHz)*/
|
|
|
|
writel(SSP_CMD0_CONT_CLKING_EN, &ssp_regs->hw_ssp_cmd0_set);
|
|
|
|
udelay(200);
|
|
|
|
writel(SSP_CMD0_CONT_CLKING_EN, &ssp_regs->hw_ssp_cmd0_clr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-26 17:28:45 +00:00
|
|
|
static const struct mmc_ops mxsmmc_ops = {
|
|
|
|
.send_cmd = mxsmmc_send_cmd,
|
|
|
|
.set_ios = mxsmmc_set_ios,
|
|
|
|
.init = mxsmmc_init,
|
|
|
|
};
|
|
|
|
|
2013-01-22 15:01:03 +00:00
|
|
|
int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int))
|
2011-11-08 23:18:09 +00:00
|
|
|
{
|
|
|
|
struct mmc *mmc = NULL;
|
|
|
|
struct mxsmmc_priv *priv = NULL;
|
2012-04-08 17:34:46 +00:00
|
|
|
int ret;
|
mxs: mmc: spi: dma: Better wrap the MXS differences
This patch streamlines the differences between the MX23 and MX28 by
implementing a few helper functions to handle different DMA channel
mapping, different clock domain for SSP block and fixes a few minor
bugs.
First of all, the DMA channel mapping is now fixed in dma.h by defining
the actual channel map for both MX23 and MX28. Thus, MX23 now does no
longer use MX28 channel map which was wrong. Also, there is a fix for
MX28 DMA channel map, where the last four channels were incorrect.
Next, because correct DMA channel map is in place, the mxs_dma_init_channel()
call now bases the channel ID starting from SSP port #0. This removes the
need for DMA channel offset being added and cleans up the code. For the
same reason, the SSP0 offset can now be used in mxs_dma_desc_append(), thus
no need to adjust dma channel number in the driver either.
Lastly, the SSP clock ID is now retrieved by calling mxs_ssp_clock_by_bus()
which handles the fact that MX23 has shared SSP clock for both ports, while
MX28 has per-port SSP clock.
Finally, the mxs_ssp_bus_id_valid() pulls out two implementations of the
same functionality from MMC and SPI driver into common code.
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Otavio Salvador <otavio@ossystems.com.br>
Cc: Stefano Babic <sbabic@denx.de>
2013-02-23 02:42:58 +00:00
|
|
|
const unsigned int mxsmmc_clk_id = mxs_ssp_clock_by_bus(id);
|
2013-01-11 03:19:14 +00:00
|
|
|
|
mxs: mmc: spi: dma: Better wrap the MXS differences
This patch streamlines the differences between the MX23 and MX28 by
implementing a few helper functions to handle different DMA channel
mapping, different clock domain for SSP block and fixes a few minor
bugs.
First of all, the DMA channel mapping is now fixed in dma.h by defining
the actual channel map for both MX23 and MX28. Thus, MX23 now does no
longer use MX28 channel map which was wrong. Also, there is a fix for
MX28 DMA channel map, where the last four channels were incorrect.
Next, because correct DMA channel map is in place, the mxs_dma_init_channel()
call now bases the channel ID starting from SSP port #0. This removes the
need for DMA channel offset being added and cleans up the code. For the
same reason, the SSP0 offset can now be used in mxs_dma_desc_append(), thus
no need to adjust dma channel number in the driver either.
Lastly, the SSP clock ID is now retrieved by calling mxs_ssp_clock_by_bus()
which handles the fact that MX23 has shared SSP clock for both ports, while
MX28 has per-port SSP clock.
Finally, the mxs_ssp_bus_id_valid() pulls out two implementations of the
same functionality from MMC and SPI driver into common code.
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Otavio Salvador <otavio@ossystems.com.br>
Cc: Stefano Babic <sbabic@denx.de>
2013-02-23 02:42:58 +00:00
|
|
|
if (!mxs_ssp_bus_id_valid(id))
|
2013-01-11 03:19:14 +00:00
|
|
|
return -ENODEV;
|
2011-11-08 23:18:09 +00:00
|
|
|
|
|
|
|
priv = malloc(sizeof(struct mxsmmc_priv));
|
2014-03-11 17:34:20 +00:00
|
|
|
if (!priv)
|
2011-11-08 23:18:09 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-03-15 18:33:21 +00:00
|
|
|
priv->desc = mxs_dma_desc_alloc();
|
|
|
|
if (!priv->desc) {
|
|
|
|
free(priv);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
mxs: mmc: spi: dma: Better wrap the MXS differences
This patch streamlines the differences between the MX23 and MX28 by
implementing a few helper functions to handle different DMA channel
mapping, different clock domain for SSP block and fixes a few minor
bugs.
First of all, the DMA channel mapping is now fixed in dma.h by defining
the actual channel map for both MX23 and MX28. Thus, MX23 now does no
longer use MX28 channel map which was wrong. Also, there is a fix for
MX28 DMA channel map, where the last four channels were incorrect.
Next, because correct DMA channel map is in place, the mxs_dma_init_channel()
call now bases the channel ID starting from SSP port #0. This removes the
need for DMA channel offset being added and cleans up the code. For the
same reason, the SSP0 offset can now be used in mxs_dma_desc_append(), thus
no need to adjust dma channel number in the driver either.
Lastly, the SSP clock ID is now retrieved by calling mxs_ssp_clock_by_bus()
which handles the fact that MX23 has shared SSP clock for both ports, while
MX28 has per-port SSP clock.
Finally, the mxs_ssp_bus_id_valid() pulls out two implementations of the
same functionality from MMC and SPI driver into common code.
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Otavio Salvador <otavio@ossystems.com.br>
Cc: Stefano Babic <sbabic@denx.de>
2013-02-23 02:42:58 +00:00
|
|
|
ret = mxs_dma_init_channel(MXS_DMA_CHANNEL_AHB_APBH_SSP0 + id);
|
2012-04-08 17:34:46 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2011-11-08 23:18:09 +00:00
|
|
|
priv->mmc_is_wp = wp;
|
2013-01-22 15:01:03 +00:00
|
|
|
priv->mmc_cd = cd;
|
2011-11-08 23:18:09 +00:00
|
|
|
priv->id = id;
|
2013-01-11 03:19:02 +00:00
|
|
|
priv->regs = mxs_ssp_regs_by_bus(id);
|
2011-11-08 23:18:09 +00:00
|
|
|
|
2014-03-11 17:34:20 +00:00
|
|
|
priv->cfg.name = "MXS MMC";
|
|
|
|
priv->cfg.ops = &mxsmmc_ops;
|
2011-11-08 23:18:09 +00:00
|
|
|
|
2014-03-11 17:34:20 +00:00
|
|
|
priv->cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
|
2011-11-08 23:18:09 +00:00
|
|
|
|
2014-03-11 17:34:20 +00:00
|
|
|
priv->cfg.host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT |
|
2015-03-23 22:56:59 +00:00
|
|
|
MMC_MODE_HS_52MHz | MMC_MODE_HS;
|
2011-11-08 23:18:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* SSPCLK = 480 * 18 / 29 / 1 = 297.731 MHz
|
|
|
|
* SSP bit rate = SSPCLK / (CLOCK_DIVIDE * (1 + CLOCK_RATE)),
|
|
|
|
* CLOCK_DIVIDE has to be an even value from 2 to 254, and
|
|
|
|
* CLOCK_RATE could be any integer from 0 to 255.
|
|
|
|
*/
|
2014-03-11 17:34:20 +00:00
|
|
|
priv->cfg.f_min = 400000;
|
|
|
|
priv->cfg.f_max = mxc_get_clock(MXC_SSP0_CLK + mxsmmc_clk_id) * 1000 / 2;
|
|
|
|
priv->cfg.b_max = 0x20;
|
2011-11-08 23:18:09 +00:00
|
|
|
|
2014-03-11 17:34:20 +00:00
|
|
|
mmc = mmc_create(&priv->cfg, priv);
|
|
|
|
if (mmc == NULL) {
|
|
|
|
mxs_dma_desc_free(priv->desc);
|
|
|
|
free(priv);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2011-11-08 23:18:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|