2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2018-04-08 13:22:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Socionext Inc.
|
|
|
|
* Author: Masahiro Yamada <yamada.masahiro@socionext.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <clk.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <cpu_func.h>
|
2018-04-08 13:22:58 +00:00
|
|
|
#include <fdtdec.h>
|
|
|
|
#include <mmc.h>
|
|
|
|
#include <dm.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2017-09-25 21:06:22 +00:00
|
|
|
#include <dm/pinctrl.h>
|
2018-04-08 13:22:58 +00:00
|
|
|
#include <linux/compat.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2020-02-14 07:40:19 +00:00
|
|
|
#include <linux/dma-mapping.h>
|
2018-04-08 13:22:58 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/sizes.h>
|
|
|
|
#include <power/regulator.h>
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
#include "tmio-common.h"
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
static u64 tmio_sd_readq(struct tmio_sd_priv *priv, unsigned int reg)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
2018-04-08 15:25:49 +00:00
|
|
|
return readq(priv->regbase + (reg << 1));
|
2018-04-08 13:22:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
static void tmio_sd_writeq(struct tmio_sd_priv *priv,
|
2018-04-08 13:22:58 +00:00
|
|
|
u64 val, unsigned int reg)
|
|
|
|
{
|
2018-04-08 15:25:49 +00:00
|
|
|
writeq(val, priv->regbase + (reg << 1));
|
2018-04-08 13:22:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
static u16 tmio_sd_readw(struct tmio_sd_priv *priv, unsigned int reg)
|
2018-04-08 15:41:14 +00:00
|
|
|
{
|
|
|
|
return readw(priv->regbase + (reg >> 1));
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
static void tmio_sd_writew(struct tmio_sd_priv *priv,
|
2018-04-08 15:41:14 +00:00
|
|
|
u16 val, unsigned int reg)
|
|
|
|
{
|
|
|
|
writew(val, priv->regbase + (reg >> 1));
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
u32 tmio_sd_readl(struct tmio_sd_priv *priv, unsigned int reg)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
2018-04-08 15:41:14 +00:00
|
|
|
u32 val;
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
if (priv->caps & TMIO_SD_CAP_64BIT)
|
2018-04-08 13:22:58 +00:00
|
|
|
return readl(priv->regbase + (reg << 1));
|
2018-04-13 21:51:33 +00:00
|
|
|
else if (priv->caps & TMIO_SD_CAP_16BIT) {
|
2018-04-08 15:41:14 +00:00
|
|
|
val = readw(priv->regbase + (reg >> 1)) & 0xffff;
|
2018-04-13 21:51:33 +00:00
|
|
|
if ((reg == TMIO_SD_RSP10) || (reg == TMIO_SD_RSP32) ||
|
|
|
|
(reg == TMIO_SD_RSP54) || (reg == TMIO_SD_RSP76)) {
|
2018-04-08 15:41:14 +00:00
|
|
|
val |= readw(priv->regbase + (reg >> 1) + 2) << 16;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
} else
|
2018-04-08 13:22:58 +00:00
|
|
|
return readl(priv->regbase + reg);
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
void tmio_sd_writel(struct tmio_sd_priv *priv,
|
2018-04-08 13:22:58 +00:00
|
|
|
u32 val, unsigned int reg)
|
|
|
|
{
|
2018-04-13 21:51:33 +00:00
|
|
|
if (priv->caps & TMIO_SD_CAP_64BIT)
|
2018-04-08 13:22:58 +00:00
|
|
|
writel(val, priv->regbase + (reg << 1));
|
2018-04-13 21:51:33 +00:00
|
|
|
else if (priv->caps & TMIO_SD_CAP_16BIT) {
|
2018-04-08 15:41:14 +00:00
|
|
|
writew(val & 0xffff, priv->regbase + (reg >> 1));
|
2018-04-13 21:51:33 +00:00
|
|
|
if (reg == TMIO_SD_INFO1 || reg == TMIO_SD_INFO1_MASK ||
|
|
|
|
reg == TMIO_SD_INFO2 || reg == TMIO_SD_INFO2_MASK ||
|
|
|
|
reg == TMIO_SD_ARG)
|
2018-04-08 15:41:14 +00:00
|
|
|
writew(val >> 16, priv->regbase + (reg >> 1) + 2);
|
|
|
|
} else
|
2018-04-08 13:22:58 +00:00
|
|
|
writel(val, priv->regbase + reg);
|
|
|
|
}
|
|
|
|
|
2018-10-30 21:05:54 +00:00
|
|
|
static int tmio_sd_check_error(struct udevice *dev, struct mmc_cmd *cmd)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
2018-04-13 21:51:33 +00:00
|
|
|
struct tmio_sd_priv *priv = dev_get_priv(dev);
|
|
|
|
u32 info2 = tmio_sd_readl(priv, TMIO_SD_INFO2);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
if (info2 & TMIO_SD_INFO2_ERR_RTO) {
|
2018-04-08 13:22:58 +00:00
|
|
|
/*
|
|
|
|
* TIMEOUT must be returned for unsupported command. Do not
|
|
|
|
* display error log since this might be a part of sequence to
|
|
|
|
* distinguish between SD and MMC.
|
|
|
|
*/
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
if (info2 & TMIO_SD_INFO2_ERR_TO) {
|
2018-04-08 13:22:58 +00:00
|
|
|
dev_err(dev, "timeout error\n");
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
if (info2 & (TMIO_SD_INFO2_ERR_END | TMIO_SD_INFO2_ERR_CRC |
|
|
|
|
TMIO_SD_INFO2_ERR_IDX)) {
|
2018-10-30 21:05:54 +00:00
|
|
|
if ((cmd->cmdidx != MMC_CMD_SEND_TUNING_BLOCK) &&
|
|
|
|
(cmd->cmdidx != MMC_CMD_SEND_TUNING_BLOCK_HS200))
|
|
|
|
dev_err(dev, "communication out of sync\n");
|
2018-04-08 13:22:58 +00:00
|
|
|
return -EILSEQ;
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
if (info2 & (TMIO_SD_INFO2_ERR_ILA | TMIO_SD_INFO2_ERR_ILR |
|
|
|
|
TMIO_SD_INFO2_ERR_ILW)) {
|
2018-04-08 13:22:58 +00:00
|
|
|
dev_err(dev, "illegal access\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-30 21:05:54 +00:00
|
|
|
static int tmio_sd_wait_for_irq(struct udevice *dev, struct mmc_cmd *cmd,
|
|
|
|
unsigned int reg, u32 flag)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
2018-04-13 21:51:33 +00:00
|
|
|
struct tmio_sd_priv *priv = dev_get_priv(dev);
|
2018-04-08 13:22:58 +00:00
|
|
|
long wait = 1000000;
|
|
|
|
int ret;
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
while (!(tmio_sd_readl(priv, reg) & flag)) {
|
2018-04-08 13:22:58 +00:00
|
|
|
if (wait-- < 0) {
|
|
|
|
dev_err(dev, "timeout\n");
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2018-10-30 21:05:54 +00:00
|
|
|
ret = tmio_sd_check_error(dev, cmd);
|
2018-04-08 13:22:58 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
#define tmio_pio_read_fifo(__width, __suffix) \
|
|
|
|
static void tmio_pio_read_fifo_##__width(struct tmio_sd_priv *priv, \
|
2018-04-08 15:14:42 +00:00
|
|
|
char *pbuf, uint blksz) \
|
|
|
|
{ \
|
|
|
|
u##__width *buf = (u##__width *)pbuf; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
if (likely(IS_ALIGNED((uintptr_t)buf, ((__width) / 8)))) { \
|
|
|
|
for (i = 0; i < blksz / ((__width) / 8); i++) { \
|
2018-04-13 21:51:33 +00:00
|
|
|
*buf++ = tmio_sd_read##__suffix(priv, \
|
|
|
|
TMIO_SD_BUF); \
|
2018-04-08 15:14:42 +00:00
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
for (i = 0; i < blksz / ((__width) / 8); i++) { \
|
|
|
|
u##__width data; \
|
2018-04-13 21:51:33 +00:00
|
|
|
data = tmio_sd_read##__suffix(priv, \
|
|
|
|
TMIO_SD_BUF); \
|
2018-04-08 15:14:42 +00:00
|
|
|
put_unaligned(data, buf++); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_pio_read_fifo(64, q)
|
|
|
|
tmio_pio_read_fifo(32, l)
|
|
|
|
tmio_pio_read_fifo(16, w)
|
2018-04-08 15:14:42 +00:00
|
|
|
|
2018-10-30 21:05:54 +00:00
|
|
|
static int tmio_sd_pio_read_one_block(struct udevice *dev, struct mmc_cmd *cmd,
|
|
|
|
char *pbuf, uint blocksize)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
2018-04-13 21:51:33 +00:00
|
|
|
struct tmio_sd_priv *priv = dev_get_priv(dev);
|
2018-04-08 15:14:42 +00:00
|
|
|
int ret;
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
/* wait until the buffer is filled with data */
|
2018-10-30 21:05:54 +00:00
|
|
|
ret = tmio_sd_wait_for_irq(dev, cmd, TMIO_SD_INFO2,
|
|
|
|
TMIO_SD_INFO2_BRE);
|
2018-04-08 13:22:58 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the status flag _before_ read the buffer out because
|
2018-04-13 21:51:33 +00:00
|
|
|
* TMIO_SD_INFO2_BRE is edge-triggered, not level-triggered.
|
2018-04-08 13:22:58 +00:00
|
|
|
*/
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, 0, TMIO_SD_INFO2);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
if (priv->caps & TMIO_SD_CAP_64BIT)
|
|
|
|
tmio_pio_read_fifo_64(priv, pbuf, blocksize);
|
|
|
|
else if (priv->caps & TMIO_SD_CAP_16BIT)
|
|
|
|
tmio_pio_read_fifo_16(priv, pbuf, blocksize);
|
2018-04-08 15:14:42 +00:00
|
|
|
else
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_pio_read_fifo_32(priv, pbuf, blocksize);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
#define tmio_pio_write_fifo(__width, __suffix) \
|
|
|
|
static void tmio_pio_write_fifo_##__width(struct tmio_sd_priv *priv, \
|
2018-04-08 15:14:42 +00:00
|
|
|
const char *pbuf, uint blksz)\
|
|
|
|
{ \
|
|
|
|
const u##__width *buf = (const u##__width *)pbuf; \
|
|
|
|
int i; \
|
|
|
|
\
|
|
|
|
if (likely(IS_ALIGNED((uintptr_t)buf, ((__width) / 8)))) { \
|
|
|
|
for (i = 0; i < blksz / ((__width) / 8); i++) { \
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_write##__suffix(priv, *buf++, \
|
|
|
|
TMIO_SD_BUF); \
|
2018-04-08 15:14:42 +00:00
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
for (i = 0; i < blksz / ((__width) / 8); i++) { \
|
|
|
|
u##__width data = get_unaligned(buf++); \
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_write##__suffix(priv, data, \
|
|
|
|
TMIO_SD_BUF); \
|
2018-04-08 15:14:42 +00:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_pio_write_fifo(64, q)
|
|
|
|
tmio_pio_write_fifo(32, l)
|
|
|
|
tmio_pio_write_fifo(16, w)
|
2018-04-08 15:14:42 +00:00
|
|
|
|
2018-10-30 21:05:54 +00:00
|
|
|
static int tmio_sd_pio_write_one_block(struct udevice *dev, struct mmc_cmd *cmd,
|
2018-04-08 13:22:58 +00:00
|
|
|
const char *pbuf, uint blocksize)
|
|
|
|
{
|
2018-04-13 21:51:33 +00:00
|
|
|
struct tmio_sd_priv *priv = dev_get_priv(dev);
|
2018-04-08 15:14:42 +00:00
|
|
|
int ret;
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
/* wait until the buffer becomes empty */
|
2018-10-30 21:05:54 +00:00
|
|
|
ret = tmio_sd_wait_for_irq(dev, cmd, TMIO_SD_INFO2,
|
|
|
|
TMIO_SD_INFO2_BWE);
|
2018-04-08 13:22:58 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, 0, TMIO_SD_INFO2);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
if (priv->caps & TMIO_SD_CAP_64BIT)
|
|
|
|
tmio_pio_write_fifo_64(priv, pbuf, blocksize);
|
|
|
|
else if (priv->caps & TMIO_SD_CAP_16BIT)
|
|
|
|
tmio_pio_write_fifo_16(priv, pbuf, blocksize);
|
2018-04-08 15:14:42 +00:00
|
|
|
else
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_pio_write_fifo_32(priv, pbuf, blocksize);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-30 21:05:54 +00:00
|
|
|
static int tmio_sd_pio_xfer(struct udevice *dev, struct mmc_cmd *cmd,
|
|
|
|
struct mmc_data *data)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
|
|
|
const char *src = data->src;
|
|
|
|
char *dest = data->dest;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
for (i = 0; i < data->blocks; i++) {
|
|
|
|
if (data->flags & MMC_DATA_READ)
|
2018-10-30 21:05:54 +00:00
|
|
|
ret = tmio_sd_pio_read_one_block(dev, cmd, dest,
|
2018-04-08 13:22:58 +00:00
|
|
|
data->blocksize);
|
|
|
|
else
|
2018-10-30 21:05:54 +00:00
|
|
|
ret = tmio_sd_pio_write_one_block(dev, cmd, src,
|
2018-04-08 13:22:58 +00:00
|
|
|
data->blocksize);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (data->flags & MMC_DATA_READ)
|
|
|
|
dest += data->blocksize;
|
|
|
|
else
|
|
|
|
src += data->blocksize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
static void tmio_sd_dma_start(struct tmio_sd_priv *priv,
|
2018-04-08 13:22:58 +00:00
|
|
|
dma_addr_t dma_addr)
|
|
|
|
{
|
|
|
|
u32 tmp;
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, 0, TMIO_SD_DMA_INFO1);
|
|
|
|
tmio_sd_writel(priv, 0, TMIO_SD_DMA_INFO2);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
/* enable DMA */
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp = tmio_sd_readl(priv, TMIO_SD_EXTMODE);
|
|
|
|
tmp |= TMIO_SD_EXTMODE_DMA_EN;
|
|
|
|
tmio_sd_writel(priv, tmp, TMIO_SD_EXTMODE);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, dma_addr & U32_MAX, TMIO_SD_DMA_ADDR_L);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
/* suppress the warning "right shift count >= width of type" */
|
|
|
|
dma_addr >>= min_t(int, 32, 8 * sizeof(dma_addr));
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, dma_addr & U32_MAX, TMIO_SD_DMA_ADDR_H);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, TMIO_SD_DMA_CTL_START, TMIO_SD_DMA_CTL);
|
2018-04-08 13:22:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
static int tmio_sd_dma_wait_for_irq(struct udevice *dev, u32 flag,
|
2018-04-08 13:22:58 +00:00
|
|
|
unsigned int blocks)
|
|
|
|
{
|
2018-04-13 21:51:33 +00:00
|
|
|
struct tmio_sd_priv *priv = dev_get_priv(dev);
|
2018-04-08 13:22:58 +00:00
|
|
|
long wait = 1000000 + 10 * blocks;
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
while (!(tmio_sd_readl(priv, TMIO_SD_DMA_INFO1) & flag)) {
|
2018-04-08 13:22:58 +00:00
|
|
|
if (wait-- < 0) {
|
|
|
|
dev_err(dev, "timeout during DMA\n");
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
udelay(10);
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
if (tmio_sd_readl(priv, TMIO_SD_DMA_INFO2)) {
|
2018-04-08 13:22:58 +00:00
|
|
|
dev_err(dev, "error during DMA\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
static int tmio_sd_dma_xfer(struct udevice *dev, struct mmc_data *data)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
2018-04-13 21:51:33 +00:00
|
|
|
struct tmio_sd_priv *priv = dev_get_priv(dev);
|
2018-04-08 13:22:58 +00:00
|
|
|
size_t len = data->blocks * data->blocksize;
|
|
|
|
void *buf;
|
|
|
|
enum dma_data_direction dir;
|
|
|
|
dma_addr_t dma_addr;
|
|
|
|
u32 poll_flag, tmp;
|
|
|
|
int ret;
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp = tmio_sd_readl(priv, TMIO_SD_DMA_MODE);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2021-01-03 10:38:25 +00:00
|
|
|
tmp |= priv->idma_bus_width;
|
|
|
|
|
2018-04-08 13:22:58 +00:00
|
|
|
if (data->flags & MMC_DATA_READ) {
|
|
|
|
buf = data->dest;
|
|
|
|
dir = DMA_FROM_DEVICE;
|
2018-01-02 18:40:49 +00:00
|
|
|
/*
|
|
|
|
* The DMA READ completion flag position differs on Socionext
|
|
|
|
* and Renesas SoCs. It is bit 20 on Socionext SoCs and using
|
2019-01-11 22:45:54 +00:00
|
|
|
* bit 17 is a hardware bug and forbidden. It is either bit 17
|
|
|
|
* or bit 20 on Renesas SoCs, depending on SoC.
|
2018-01-02 18:40:49 +00:00
|
|
|
*/
|
2019-01-11 22:45:54 +00:00
|
|
|
poll_flag = priv->read_poll_flag;
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp |= TMIO_SD_DMA_MODE_DIR_RD;
|
2018-04-08 13:22:58 +00:00
|
|
|
} else {
|
|
|
|
buf = (void *)data->src;
|
|
|
|
dir = DMA_TO_DEVICE;
|
2018-04-13 21:51:33 +00:00
|
|
|
poll_flag = TMIO_SD_DMA_INFO1_END_WR;
|
|
|
|
tmp &= ~TMIO_SD_DMA_MODE_DIR_RD;
|
2018-04-08 13:22:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, tmp, TMIO_SD_DMA_MODE);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2020-01-16 08:53:46 +00:00
|
|
|
dma_addr = dma_map_single(buf, len, dir);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_dma_start(priv, dma_addr);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
ret = tmio_sd_dma_wait_for_irq(dev, poll_flag, data->blocks);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2019-01-11 22:38:07 +00:00
|
|
|
if (poll_flag == TMIO_SD_DMA_INFO1_END_RD)
|
|
|
|
udelay(1);
|
|
|
|
|
2020-02-14 07:40:18 +00:00
|
|
|
dma_unmap_single(dma_addr, len, dir);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if the address is DMA'able */
|
2020-03-07 16:32:59 +00:00
|
|
|
static bool tmio_sd_addr_is_dmaable(struct mmc_data *data)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
2020-03-07 16:32:59 +00:00
|
|
|
uintptr_t addr = (uintptr_t)data->src;
|
2018-10-02 22:44:37 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
if (!IS_ALIGNED(addr, TMIO_SD_DMA_MINALIGN))
|
2018-04-08 13:22:58 +00:00
|
|
|
return false;
|
|
|
|
|
2018-10-02 22:46:24 +00:00
|
|
|
#if defined(CONFIG_RCAR_GEN3)
|
2020-03-07 16:32:59 +00:00
|
|
|
if (!(data->flags & MMC_DATA_READ) && !IS_ALIGNED(addr, 128))
|
|
|
|
return false;
|
2018-10-02 22:46:24 +00:00
|
|
|
/* Gen3 DMA has 32bit limit */
|
|
|
|
if (addr >> 32)
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
2018-04-08 13:22:58 +00:00
|
|
|
#if defined(CONFIG_ARCH_UNIPHIER) && !defined(CONFIG_ARM64) && \
|
|
|
|
defined(CONFIG_SPL_BUILD)
|
|
|
|
/*
|
|
|
|
* For UniPhier ARMv7 SoCs, the stack is allocated in the locked ways
|
|
|
|
* of L2, which is unreachable from the DMA engine.
|
|
|
|
*/
|
|
|
|
if (addr < CONFIG_SPL_STACK)
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
int tmio_sd_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
|
2018-04-08 13:22:58 +00:00
|
|
|
struct mmc_data *data)
|
|
|
|
{
|
2018-04-13 21:51:33 +00:00
|
|
|
struct tmio_sd_priv *priv = dev_get_priv(dev);
|
2018-04-08 13:22:58 +00:00
|
|
|
int ret;
|
|
|
|
u32 tmp;
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
if (tmio_sd_readl(priv, TMIO_SD_INFO2) & TMIO_SD_INFO2_CBSY) {
|
2018-04-08 13:22:58 +00:00
|
|
|
dev_err(dev, "command busy\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear all status flags */
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, 0, TMIO_SD_INFO1);
|
|
|
|
tmio_sd_writel(priv, 0, TMIO_SD_INFO2);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
/* disable DMA once */
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp = tmio_sd_readl(priv, TMIO_SD_EXTMODE);
|
|
|
|
tmp &= ~TMIO_SD_EXTMODE_DMA_EN;
|
|
|
|
tmio_sd_writel(priv, tmp, TMIO_SD_EXTMODE);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, cmd->cmdarg, TMIO_SD_ARG);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
tmp = cmd->cmdidx;
|
|
|
|
|
|
|
|
if (data) {
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, data->blocksize, TMIO_SD_SIZE);
|
|
|
|
tmio_sd_writel(priv, data->blocks, TMIO_SD_SECCNT);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
/* Do not send CMD12 automatically */
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp |= TMIO_SD_CMD_NOSTOP | TMIO_SD_CMD_DATA;
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
if (data->blocks > 1)
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp |= TMIO_SD_CMD_MULTI;
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
if (data->flags & MMC_DATA_READ)
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp |= TMIO_SD_CMD_RD;
|
2018-04-08 13:22:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not use the response type auto-detection on this hardware.
|
|
|
|
* CMD8, for example, has different response types on SD and eMMC,
|
|
|
|
* while this controller always assumes the response type for SD.
|
|
|
|
* Set the response type manually.
|
|
|
|
*/
|
|
|
|
switch (cmd->resp_type) {
|
|
|
|
case MMC_RSP_NONE:
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp |= TMIO_SD_CMD_RSP_NONE;
|
2018-04-08 13:22:58 +00:00
|
|
|
break;
|
|
|
|
case MMC_RSP_R1:
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp |= TMIO_SD_CMD_RSP_R1;
|
2018-04-08 13:22:58 +00:00
|
|
|
break;
|
|
|
|
case MMC_RSP_R1b:
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp |= TMIO_SD_CMD_RSP_R1B;
|
2018-04-08 13:22:58 +00:00
|
|
|
break;
|
|
|
|
case MMC_RSP_R2:
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp |= TMIO_SD_CMD_RSP_R2;
|
2018-04-08 13:22:58 +00:00
|
|
|
break;
|
|
|
|
case MMC_RSP_R3:
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp |= TMIO_SD_CMD_RSP_R3;
|
2018-04-08 13:22:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(dev, "unknown response type\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(dev, "sending CMD%d (SD_CMD=%08x, SD_ARG=%08x)\n",
|
|
|
|
cmd->cmdidx, tmp, cmd->cmdarg);
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, tmp, TMIO_SD_CMD);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-10-30 21:05:54 +00:00
|
|
|
ret = tmio_sd_wait_for_irq(dev, cmd, TMIO_SD_INFO1,
|
|
|
|
TMIO_SD_INFO1_RSP);
|
2018-04-08 13:22:58 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (cmd->resp_type & MMC_RSP_136) {
|
2018-04-13 21:51:33 +00:00
|
|
|
u32 rsp_127_104 = tmio_sd_readl(priv, TMIO_SD_RSP76);
|
|
|
|
u32 rsp_103_72 = tmio_sd_readl(priv, TMIO_SD_RSP54);
|
|
|
|
u32 rsp_71_40 = tmio_sd_readl(priv, TMIO_SD_RSP32);
|
|
|
|
u32 rsp_39_8 = tmio_sd_readl(priv, TMIO_SD_RSP10);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
cmd->response[0] = ((rsp_127_104 & 0x00ffffff) << 8) |
|
|
|
|
((rsp_103_72 & 0xff000000) >> 24);
|
|
|
|
cmd->response[1] = ((rsp_103_72 & 0x00ffffff) << 8) |
|
|
|
|
((rsp_71_40 & 0xff000000) >> 24);
|
|
|
|
cmd->response[2] = ((rsp_71_40 & 0x00ffffff) << 8) |
|
|
|
|
((rsp_39_8 & 0xff000000) >> 24);
|
|
|
|
cmd->response[3] = (rsp_39_8 & 0xffffff) << 8;
|
|
|
|
} else {
|
|
|
|
/* bit 39-8 */
|
2018-04-13 21:51:33 +00:00
|
|
|
cmd->response[0] = tmio_sd_readl(priv, TMIO_SD_RSP10);
|
2018-04-08 13:22:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
/* use DMA if the HW supports it and the buffer is aligned */
|
2018-04-13 21:51:33 +00:00
|
|
|
if (priv->caps & TMIO_SD_CAP_DMA_INTERNAL &&
|
2020-03-07 16:32:59 +00:00
|
|
|
tmio_sd_addr_is_dmaable(data))
|
2018-04-13 21:51:33 +00:00
|
|
|
ret = tmio_sd_dma_xfer(dev, data);
|
2018-04-08 13:22:58 +00:00
|
|
|
else
|
2018-10-30 21:05:54 +00:00
|
|
|
ret = tmio_sd_pio_xfer(dev, cmd, data);
|
2018-10-30 20:53:29 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-10-30 21:05:54 +00:00
|
|
|
ret = tmio_sd_wait_for_irq(dev, cmd, TMIO_SD_INFO1,
|
|
|
|
TMIO_SD_INFO1_CMP);
|
2018-04-08 13:22:58 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-30 21:05:54 +00:00
|
|
|
return tmio_sd_wait_for_irq(dev, cmd, TMIO_SD_INFO2,
|
2018-10-30 20:53:29 +00:00
|
|
|
TMIO_SD_INFO2_SCLKDIVEN);
|
2018-04-08 13:22:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
static int tmio_sd_set_bus_width(struct tmio_sd_priv *priv,
|
2018-04-08 13:22:58 +00:00
|
|
|
struct mmc *mmc)
|
|
|
|
{
|
|
|
|
u32 val, tmp;
|
|
|
|
|
|
|
|
switch (mmc->bus_width) {
|
2018-01-29 23:41:42 +00:00
|
|
|
case 0:
|
2018-04-08 13:22:58 +00:00
|
|
|
case 1:
|
2018-04-13 21:51:33 +00:00
|
|
|
val = TMIO_SD_OPTION_WIDTH_1;
|
2018-04-08 13:22:58 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2018-04-13 21:51:33 +00:00
|
|
|
val = TMIO_SD_OPTION_WIDTH_4;
|
2018-04-08 13:22:58 +00:00
|
|
|
break;
|
|
|
|
case 8:
|
2018-04-13 21:51:33 +00:00
|
|
|
val = TMIO_SD_OPTION_WIDTH_8;
|
2018-04-08 13:22:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp = tmio_sd_readl(priv, TMIO_SD_OPTION);
|
|
|
|
tmp &= ~TMIO_SD_OPTION_WIDTH_MASK;
|
2018-04-08 13:22:58 +00:00
|
|
|
tmp |= val;
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, tmp, TMIO_SD_OPTION);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
static void tmio_sd_set_ddr_mode(struct tmio_sd_priv *priv,
|
2018-04-08 13:22:58 +00:00
|
|
|
struct mmc *mmc)
|
|
|
|
{
|
|
|
|
u32 tmp;
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp = tmio_sd_readl(priv, TMIO_SD_IF_MODE);
|
2018-04-08 13:22:58 +00:00
|
|
|
if (mmc->ddr_mode)
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp |= TMIO_SD_IF_MODE_DDR;
|
2018-04-08 13:22:58 +00:00
|
|
|
else
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp &= ~TMIO_SD_IF_MODE_DDR;
|
|
|
|
tmio_sd_writel(priv, tmp, TMIO_SD_IF_MODE);
|
2018-04-08 13:22:58 +00:00
|
|
|
}
|
|
|
|
|
2018-06-13 06:02:55 +00:00
|
|
|
static ulong tmio_sd_clk_get_rate(struct tmio_sd_priv *priv)
|
|
|
|
{
|
|
|
|
return priv->clk_get_rate(priv);
|
|
|
|
}
|
|
|
|
|
mmc: tmio: Reorder TMIO clock handling
Reorder the tmio_sd_set_clk_rate() function such that it handles all
of the clock requiests correctly. Specifically, before this patch,
clock request with (mmc->clock == 0 && mmc->clk_disable) could leave
the clock enabled, as the function would exit on if (!mmc->clock)
condition on top and will not handle the mmc->clk_disable at all.
Rather than band-aid fixing just that particular problem, reorder
the entire function to make it easier to understand and verify that
all the cases are covered. The function has three sections now:
First, if mmc->clock != 0, we calculate divider for the SD block.
Second, if mmc->clock != 0 and SD block clock are enabled and
current divider is not equal to the new divider, then
stop the clock and update the divider.
Third, if mmc->clk_disable is set, disable the clock, otherwise
enable the clock. This happens independently of divider
update now.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-11-15 21:01:33 +00:00
|
|
|
static void tmio_sd_set_clk_rate(struct tmio_sd_priv *priv, struct mmc *mmc)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
|
|
|
unsigned int divisor;
|
mmc: tmio: Reorder TMIO clock handling
Reorder the tmio_sd_set_clk_rate() function such that it handles all
of the clock requiests correctly. Specifically, before this patch,
clock request with (mmc->clock == 0 && mmc->clk_disable) could leave
the clock enabled, as the function would exit on if (!mmc->clock)
condition on top and will not handle the mmc->clk_disable at all.
Rather than band-aid fixing just that particular problem, reorder
the entire function to make it easier to understand and verify that
all the cases are covered. The function has three sections now:
First, if mmc->clock != 0, we calculate divider for the SD block.
Second, if mmc->clock != 0 and SD block clock are enabled and
current divider is not equal to the new divider, then
stop the clock and update the divider.
Third, if mmc->clk_disable is set, disable the clock, otherwise
enable the clock. This happens independently of divider
update now.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-11-15 21:01:33 +00:00
|
|
|
u32 tmp, val = 0;
|
2018-06-13 06:02:55 +00:00
|
|
|
ulong mclk;
|
2018-04-08 13:22:58 +00:00
|
|
|
|
mmc: tmio: Reorder TMIO clock handling
Reorder the tmio_sd_set_clk_rate() function such that it handles all
of the clock requiests correctly. Specifically, before this patch,
clock request with (mmc->clock == 0 && mmc->clk_disable) could leave
the clock enabled, as the function would exit on if (!mmc->clock)
condition on top and will not handle the mmc->clk_disable at all.
Rather than band-aid fixing just that particular problem, reorder
the entire function to make it easier to understand and verify that
all the cases are covered. The function has three sections now:
First, if mmc->clock != 0, we calculate divider for the SD block.
Second, if mmc->clock != 0 and SD block clock are enabled and
current divider is not equal to the new divider, then
stop the clock and update the divider.
Third, if mmc->clk_disable is set, disable the clock, otherwise
enable the clock. This happens independently of divider
update now.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-11-15 21:01:33 +00:00
|
|
|
if (mmc->clock) {
|
|
|
|
mclk = tmio_sd_clk_get_rate(priv);
|
|
|
|
|
|
|
|
divisor = DIV_ROUND_UP(mclk, mmc->clock);
|
|
|
|
|
|
|
|
/* Do not set divider to 0xff in DDR mode */
|
|
|
|
if (mmc->ddr_mode && (divisor == 1))
|
|
|
|
divisor = 2;
|
|
|
|
|
|
|
|
if (divisor <= 1)
|
|
|
|
val = (priv->caps & TMIO_SD_CAP_RCAR) ?
|
|
|
|
TMIO_SD_CLKCTL_RCAR_DIV1 : TMIO_SD_CLKCTL_DIV1;
|
|
|
|
else if (divisor <= 2)
|
|
|
|
val = TMIO_SD_CLKCTL_DIV2;
|
|
|
|
else if (divisor <= 4)
|
|
|
|
val = TMIO_SD_CLKCTL_DIV4;
|
|
|
|
else if (divisor <= 8)
|
|
|
|
val = TMIO_SD_CLKCTL_DIV8;
|
|
|
|
else if (divisor <= 16)
|
|
|
|
val = TMIO_SD_CLKCTL_DIV16;
|
|
|
|
else if (divisor <= 32)
|
|
|
|
val = TMIO_SD_CLKCTL_DIV32;
|
|
|
|
else if (divisor <= 64)
|
|
|
|
val = TMIO_SD_CLKCTL_DIV64;
|
|
|
|
else if (divisor <= 128)
|
|
|
|
val = TMIO_SD_CLKCTL_DIV128;
|
|
|
|
else if (divisor <= 256)
|
|
|
|
val = TMIO_SD_CLKCTL_DIV256;
|
|
|
|
else if (divisor <= 512 || !(priv->caps & TMIO_SD_CAP_DIV1024))
|
|
|
|
val = TMIO_SD_CLKCTL_DIV512;
|
|
|
|
else
|
|
|
|
val = TMIO_SD_CLKCTL_DIV1024;
|
|
|
|
}
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp = tmio_sd_readl(priv, TMIO_SD_CLKCTL);
|
mmc: tmio: Reorder TMIO clock handling
Reorder the tmio_sd_set_clk_rate() function such that it handles all
of the clock requiests correctly. Specifically, before this patch,
clock request with (mmc->clock == 0 && mmc->clk_disable) could leave
the clock enabled, as the function would exit on if (!mmc->clock)
condition on top and will not handle the mmc->clk_disable at all.
Rather than band-aid fixing just that particular problem, reorder
the entire function to make it easier to understand and verify that
all the cases are covered. The function has three sections now:
First, if mmc->clock != 0, we calculate divider for the SD block.
Second, if mmc->clock != 0 and SD block clock are enabled and
current divider is not equal to the new divider, then
stop the clock and update the divider.
Third, if mmc->clk_disable is set, disable the clock, otherwise
enable the clock. This happens independently of divider
update now.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-11-15 21:01:33 +00:00
|
|
|
if (mmc->clock &&
|
|
|
|
!((tmp & TMIO_SD_CLKCTL_SCLKEN) &&
|
|
|
|
((tmp & TMIO_SD_CLKCTL_DIV_MASK) == val))) {
|
|
|
|
/*
|
|
|
|
* Stop the clock before changing its rate
|
|
|
|
* to avoid a glitch signal
|
|
|
|
*/
|
|
|
|
tmp &= ~TMIO_SD_CLKCTL_SCLKEN;
|
|
|
|
tmio_sd_writel(priv, tmp, TMIO_SD_CLKCTL);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
mmc: tmio: Reorder TMIO clock handling
Reorder the tmio_sd_set_clk_rate() function such that it handles all
of the clock requiests correctly. Specifically, before this patch,
clock request with (mmc->clock == 0 && mmc->clk_disable) could leave
the clock enabled, as the function would exit on if (!mmc->clock)
condition on top and will not handle the mmc->clk_disable at all.
Rather than band-aid fixing just that particular problem, reorder
the entire function to make it easier to understand and verify that
all the cases are covered. The function has three sections now:
First, if mmc->clock != 0, we calculate divider for the SD block.
Second, if mmc->clock != 0 and SD block clock are enabled and
current divider is not equal to the new divider, then
stop the clock and update the divider.
Third, if mmc->clk_disable is set, disable the clock, otherwise
enable the clock. This happens independently of divider
update now.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-11-15 21:01:33 +00:00
|
|
|
/* Change the clock rate. */
|
|
|
|
tmp &= ~TMIO_SD_CLKCTL_DIV_MASK;
|
|
|
|
tmp |= val;
|
|
|
|
}
|
2018-04-08 13:22:58 +00:00
|
|
|
|
mmc: tmio: Reorder TMIO clock handling
Reorder the tmio_sd_set_clk_rate() function such that it handles all
of the clock requiests correctly. Specifically, before this patch,
clock request with (mmc->clock == 0 && mmc->clk_disable) could leave
the clock enabled, as the function would exit on if (!mmc->clock)
condition on top and will not handle the mmc->clk_disable at all.
Rather than band-aid fixing just that particular problem, reorder
the entire function to make it easier to understand and verify that
all the cases are covered. The function has three sections now:
First, if mmc->clock != 0, we calculate divider for the SD block.
Second, if mmc->clock != 0 and SD block clock are enabled and
current divider is not equal to the new divider, then
stop the clock and update the divider.
Third, if mmc->clk_disable is set, disable the clock, otherwise
enable the clock. This happens independently of divider
update now.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-11-15 21:01:33 +00:00
|
|
|
/* Enable or Disable the clock */
|
|
|
|
if (mmc->clk_disable) {
|
2018-06-13 06:02:55 +00:00
|
|
|
tmp |= TMIO_SD_CLKCTL_OFFEN;
|
|
|
|
tmp &= ~TMIO_SD_CLKCTL_SCLKEN;
|
mmc: tmio: Reorder TMIO clock handling
Reorder the tmio_sd_set_clk_rate() function such that it handles all
of the clock requiests correctly. Specifically, before this patch,
clock request with (mmc->clock == 0 && mmc->clk_disable) could leave
the clock enabled, as the function would exit on if (!mmc->clock)
condition on top and will not handle the mmc->clk_disable at all.
Rather than band-aid fixing just that particular problem, reorder
the entire function to make it easier to understand and verify that
all the cases are covered. The function has three sections now:
First, if mmc->clock != 0, we calculate divider for the SD block.
Second, if mmc->clock != 0 and SD block clock are enabled and
current divider is not equal to the new divider, then
stop the clock and update the divider.
Third, if mmc->clk_disable is set, disable the clock, otherwise
enable the clock. This happens independently of divider
update now.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-11-15 21:01:33 +00:00
|
|
|
} else {
|
|
|
|
tmp &= ~TMIO_SD_CLKCTL_OFFEN;
|
|
|
|
tmp |= TMIO_SD_CLKCTL_SCLKEN;
|
2018-06-13 06:02:55 +00:00
|
|
|
}
|
mmc: tmio: Reorder TMIO clock handling
Reorder the tmio_sd_set_clk_rate() function such that it handles all
of the clock requiests correctly. Specifically, before this patch,
clock request with (mmc->clock == 0 && mmc->clk_disable) could leave
the clock enabled, as the function would exit on if (!mmc->clock)
condition on top and will not handle the mmc->clk_disable at all.
Rather than band-aid fixing just that particular problem, reorder
the entire function to make it easier to understand and verify that
all the cases are covered. The function has three sections now:
First, if mmc->clock != 0, we calculate divider for the SD block.
Second, if mmc->clock != 0 and SD block clock are enabled and
current divider is not equal to the new divider, then
stop the clock and update the divider.
Third, if mmc->clk_disable is set, disable the clock, otherwise
enable the clock. This happens independently of divider
update now.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-11-15 21:01:33 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, tmp, TMIO_SD_CLKCTL);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
udelay(1000);
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
static void tmio_sd_set_pins(struct udevice *dev)
|
2017-09-25 21:06:22 +00:00
|
|
|
{
|
|
|
|
__maybe_unused struct mmc *mmc = mmc_get_mmc_dev(dev);
|
|
|
|
|
|
|
|
#ifdef CONFIG_DM_REGULATOR
|
2018-04-13 21:51:33 +00:00
|
|
|
struct tmio_sd_priv *priv = dev_get_priv(dev);
|
2017-09-25 21:06:22 +00:00
|
|
|
|
|
|
|
if (priv->vqmmc_dev) {
|
|
|
|
if (mmc->signal_voltage == MMC_SIGNAL_VOLTAGE_180)
|
|
|
|
regulator_set_value(priv->vqmmc_dev, 1800000);
|
|
|
|
else
|
|
|
|
regulator_set_value(priv->vqmmc_dev, 3300000);
|
|
|
|
regulator_set_enable(priv->vqmmc_dev, true);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PINCTRL
|
mmc: tmio: Simplify pinmux handling
The SD UHS SDR12, SDR25, SDR50, SDR104, DDR50 and MMC HS200, HS400
modes all use 1.8V signaling, while all the legacy modes use 3.3V
signaling. While there are extra modes which use 1.2V signaling,
the existing hardware does not support those.
Simplify the pinmux such that 3.3V signaling implies legacy mode
pinmux and the rest implies UHS mode pinmux. This prevents the
massive case statement from growing further. Moreover, it fixes
an edge case where during SD 1.8V switch, the bus mode is still
set to default while the signaling is already set to 1.8V, which
results in an attempt to communicate with a 1.8V card using pins
in 3.3V mode and thus communication failure.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-10-28 12:54:10 +00:00
|
|
|
if (mmc->signal_voltage == MMC_SIGNAL_VOLTAGE_180)
|
2017-09-25 21:06:22 +00:00
|
|
|
pinctrl_select_state(dev, "state_uhs");
|
mmc: tmio: Simplify pinmux handling
The SD UHS SDR12, SDR25, SDR50, SDR104, DDR50 and MMC HS200, HS400
modes all use 1.8V signaling, while all the legacy modes use 3.3V
signaling. While there are extra modes which use 1.2V signaling,
the existing hardware does not support those.
Simplify the pinmux such that 3.3V signaling implies legacy mode
pinmux and the rest implies UHS mode pinmux. This prevents the
massive case statement from growing further. Moreover, it fixes
an edge case where during SD 1.8V switch, the bus mode is still
set to default while the signaling is already set to 1.8V, which
results in an attempt to communicate with a 1.8V card using pins
in 3.3V mode and thus communication failure.
Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-10-28 12:54:10 +00:00
|
|
|
else
|
|
|
|
pinctrl_select_state(dev, "default");
|
2017-09-25 21:06:22 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
int tmio_sd_set_ios(struct udevice *dev)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
2018-04-13 21:51:33 +00:00
|
|
|
struct tmio_sd_priv *priv = dev_get_priv(dev);
|
2018-04-08 13:22:58 +00:00
|
|
|
struct mmc *mmc = mmc_get_mmc_dev(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_dbg(dev, "clock %uHz, DDRmode %d, width %u\n",
|
|
|
|
mmc->clock, mmc->ddr_mode, mmc->bus_width);
|
|
|
|
|
2018-06-13 06:02:55 +00:00
|
|
|
tmio_sd_set_clk_rate(priv, mmc);
|
2018-04-13 21:51:33 +00:00
|
|
|
ret = tmio_sd_set_bus_width(priv, mmc);
|
2018-04-08 13:22:58 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_set_ddr_mode(priv, mmc);
|
|
|
|
tmio_sd_set_pins(dev);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
int tmio_sd_get_cd(struct udevice *dev)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
2018-04-13 21:51:33 +00:00
|
|
|
struct tmio_sd_priv *priv = dev_get_priv(dev);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
if (priv->caps & TMIO_SD_CAP_NONREMOVABLE)
|
2018-04-08 13:22:58 +00:00
|
|
|
return 1;
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
return !!(tmio_sd_readl(priv, TMIO_SD_INFO1) &
|
|
|
|
TMIO_SD_INFO1_CD);
|
2018-04-08 13:22:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
static void tmio_sd_host_init(struct tmio_sd_priv *priv)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
/* soft reset of the host */
|
2018-04-13 21:51:33 +00:00
|
|
|
tmp = tmio_sd_readl(priv, TMIO_SD_SOFT_RST);
|
|
|
|
tmp &= ~TMIO_SD_SOFT_RST_RSTX;
|
|
|
|
tmio_sd_writel(priv, tmp, TMIO_SD_SOFT_RST);
|
|
|
|
tmp |= TMIO_SD_SOFT_RST_RSTX;
|
|
|
|
tmio_sd_writel(priv, tmp, TMIO_SD_SOFT_RST);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
/* FIXME: implement eMMC hw_reset */
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, TMIO_SD_STOP_SEC, TMIO_SD_STOP);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Connected to 32bit AXI.
|
|
|
|
* This register dropped backward compatibility at version 0x10.
|
|
|
|
* Write an appropriate value depending on the IP version.
|
|
|
|
*/
|
2019-02-14 14:16:24 +00:00
|
|
|
if (priv->version >= 0x10) {
|
|
|
|
if (priv->caps & TMIO_SD_CAP_64BIT)
|
2019-02-19 18:20:14 +00:00
|
|
|
tmio_sd_writel(priv, 0x000, TMIO_SD_HOST_MODE);
|
2019-02-14 14:16:24 +00:00
|
|
|
else
|
|
|
|
tmio_sd_writel(priv, 0x101, TMIO_SD_HOST_MODE);
|
|
|
|
} else {
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, 0x0, TMIO_SD_HOST_MODE);
|
2019-02-14 14:16:24 +00:00
|
|
|
}
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
if (priv->caps & TMIO_SD_CAP_DMA_INTERNAL) {
|
|
|
|
tmp = tmio_sd_readl(priv, TMIO_SD_DMA_MODE);
|
|
|
|
tmp |= TMIO_SD_DMA_MODE_ADDR_INC;
|
2021-01-03 10:38:25 +00:00
|
|
|
tmp |= priv->idma_bus_width;
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_writel(priv, tmp, TMIO_SD_DMA_MODE);
|
2018-04-08 13:22:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
int tmio_sd_bind(struct udevice *dev)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct tmio_sd_plat *plat = dev_get_plat(dev);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
return mmc_bind(dev, &plat->mmc, &plat->cfg);
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
int tmio_sd_probe(struct udevice *dev, u32 quirks)
|
2018-04-08 13:22:58 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct tmio_sd_plat *plat = dev_get_plat(dev);
|
2018-04-13 21:51:33 +00:00
|
|
|
struct tmio_sd_priv *priv = dev_get_priv(dev);
|
2018-04-08 13:22:58 +00:00
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
|
|
|
|
fdt_addr_t base;
|
2018-06-13 06:02:55 +00:00
|
|
|
ulong mclk;
|
2018-04-08 13:22:58 +00:00
|
|
|
int ret;
|
|
|
|
|
2020-07-17 05:36:48 +00:00
|
|
|
base = dev_read_addr(dev);
|
2018-04-08 13:22:58 +00:00
|
|
|
if (base == FDT_ADDR_T_NONE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
priv->regbase = devm_ioremap(dev, base, SZ_2K);
|
|
|
|
if (!priv->regbase)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
#ifdef CONFIG_DM_REGULATOR
|
2017-09-25 21:06:22 +00:00
|
|
|
device_get_supply_regulator(dev, "vqmmc-supply", &priv->vqmmc_dev);
|
2018-06-13 06:02:55 +00:00
|
|
|
if (priv->vqmmc_dev)
|
|
|
|
regulator_set_value(priv->vqmmc_dev, 3300000);
|
2018-04-08 13:22:58 +00:00
|
|
|
#endif
|
|
|
|
|
2017-09-23 11:22:14 +00:00
|
|
|
ret = mmc_of_parse(dev, &plat->cfg);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "failed to parse host caps\n");
|
|
|
|
return ret;
|
2018-04-08 13:22:58 +00:00
|
|
|
}
|
|
|
|
|
2017-09-23 11:22:14 +00:00
|
|
|
plat->cfg.name = dev->name;
|
|
|
|
plat->cfg.host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
|
|
|
|
|
2017-09-23 11:01:20 +00:00
|
|
|
if (quirks)
|
2018-04-08 13:22:58 +00:00
|
|
|
priv->caps = quirks;
|
2017-09-23 11:01:20 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
priv->version = tmio_sd_readl(priv, TMIO_SD_VERSION) &
|
|
|
|
TMIO_SD_VERSION_IP;
|
2017-09-23 11:01:20 +00:00
|
|
|
dev_dbg(dev, "version %x\n", priv->version);
|
|
|
|
if (priv->version >= 0x10) {
|
2018-04-13 21:51:33 +00:00
|
|
|
priv->caps |= TMIO_SD_CAP_DMA_INTERNAL;
|
|
|
|
priv->caps |= TMIO_SD_CAP_DIV1024;
|
2018-04-08 13:22:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fdt_get_property(gd->fdt_blob, dev_of_offset(dev), "non-removable",
|
|
|
|
NULL))
|
2018-04-13 21:51:33 +00:00
|
|
|
priv->caps |= TMIO_SD_CAP_NONREMOVABLE;
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-04-13 21:51:33 +00:00
|
|
|
tmio_sd_host_init(priv);
|
2018-04-08 13:22:58 +00:00
|
|
|
|
2018-06-13 06:02:55 +00:00
|
|
|
mclk = tmio_sd_clk_get_rate(priv);
|
|
|
|
|
2018-04-08 13:22:58 +00:00
|
|
|
plat->cfg.voltages = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34;
|
2018-06-13 06:02:55 +00:00
|
|
|
plat->cfg.f_min = mclk /
|
2018-04-13 21:51:33 +00:00
|
|
|
(priv->caps & TMIO_SD_CAP_DIV1024 ? 1024 : 512);
|
2018-06-13 06:02:55 +00:00
|
|
|
plat->cfg.f_max = mclk;
|
2019-03-18 22:43:10 +00:00
|
|
|
if (quirks & TMIO_SD_CAP_16BIT)
|
|
|
|
plat->cfg.b_max = U16_MAX; /* max value of TMIO_SD_SECCNT */
|
|
|
|
else
|
|
|
|
plat->cfg.b_max = U32_MAX; /* max value of TMIO_SD_SECCNT */
|
2018-04-08 13:22:58 +00:00
|
|
|
|
|
|
|
upriv->mmc = &plat->mmc;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|