2018-08-22 06:02:17 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2009-10-02 10:22:09 +08:00
|
|
|
/*
|
2017-05-10 17:25:30 +08:00
|
|
|
* Renesas SDHI
|
2009-10-02 10:22:09 +08:00
|
|
|
*
|
2019-03-15 06:54:41 +08:00
|
|
|
* Copyright (C) 2015-19 Renesas Electronics Corporation
|
|
|
|
* Copyright (C) 2016-19 Sang Engineering, Wolfram Sang
|
2017-05-30 20:50:52 +08:00
|
|
|
* Copyright (C) 2016-17 Horms Solutions, Simon Horman
|
2009-10-02 10:22:09 +08:00
|
|
|
* Copyright (C) 2009 Magnus Damm
|
|
|
|
*
|
|
|
|
* Based on "Compaq ASIC3 support":
|
|
|
|
*
|
|
|
|
* Copyright 2001 Compaq Computer Corporation.
|
|
|
|
* Copyright 2004-2005 Phil Blundell
|
|
|
|
* Copyright 2007-2008 OpenedHand Ltd.
|
|
|
|
*
|
|
|
|
* Authors: Phil Blundell <pb@handhelds.org>,
|
|
|
|
* Samuel Ortiz <sameo@openedhand.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk.h>
|
2020-11-11 18:02:44 +08:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mfd/tmio.h>
|
2010-02-22 12:37:09 +08:00
|
|
|
#include <linux/mmc/host.h>
|
2020-09-02 16:18:12 +08:00
|
|
|
#include <linux/mmc/mmc.h>
|
2018-06-01 19:00:37 +08:00
|
|
|
#include <linux/mmc/slot-gpio.h>
|
2020-11-11 18:02:44 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of_device.h>
|
2016-04-01 23:44:37 +08:00
|
|
|
#include <linux/pinctrl/consumer.h>
|
|
|
|
#include <linux/pinctrl/pinctrl-state.h>
|
2020-11-11 18:02:44 +08:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/pm_domain.h>
|
2016-04-01 23:44:37 +08:00
|
|
|
#include <linux/regulator/consumer.h>
|
2020-11-11 18:02:44 +08:00
|
|
|
#include <linux/sh_dma.h>
|
|
|
|
#include <linux/slab.h>
|
2018-11-29 00:18:27 +08:00
|
|
|
#include <linux/sys_soc.h>
|
2009-10-02 10:22:09 +08:00
|
|
|
|
2017-05-10 17:25:28 +08:00
|
|
|
#include "renesas_sdhi.h"
|
2011-03-14 16:52:33 +08:00
|
|
|
#include "tmio_mmc.h"
|
|
|
|
|
2020-11-11 18:02:42 +08:00
|
|
|
#define CTL_HOST_MODE 0xe4
|
|
|
|
#define HOST_MODE_GEN2_SDR50_WMODE BIT(0)
|
|
|
|
#define HOST_MODE_GEN2_SDR104_WMODE BIT(0)
|
|
|
|
#define HOST_MODE_GEN3_WMODE BIT(0)
|
|
|
|
#define HOST_MODE_GEN3_BUSWIDTH BIT(8)
|
|
|
|
|
|
|
|
#define HOST_MODE_GEN3_16BIT HOST_MODE_GEN3_WMODE
|
|
|
|
#define HOST_MODE_GEN3_32BIT (HOST_MODE_GEN3_WMODE | HOST_MODE_GEN3_BUSWIDTH)
|
|
|
|
#define HOST_MODE_GEN3_64BIT 0
|
2013-11-20 16:31:13 +08:00
|
|
|
|
2020-11-11 18:02:43 +08:00
|
|
|
#define CTL_SDIF_MODE 0xe6
|
|
|
|
#define SDIF_MODE_HS400 BIT(0)
|
|
|
|
|
2016-05-11 20:46:00 +08:00
|
|
|
#define SDHI_VER_GEN2_SDR50 0x490c
|
2017-08-10 03:14:52 +08:00
|
|
|
#define SDHI_VER_RZ_A1 0x820b
|
2016-05-11 20:46:00 +08:00
|
|
|
/* very old datasheets said 0x490c for SDR104, too. They are wrong! */
|
|
|
|
#define SDHI_VER_GEN2_SDR104 0xcb0d
|
|
|
|
#define SDHI_VER_GEN3_SD 0xcc10
|
|
|
|
#define SDHI_VER_GEN3_SDMMC 0xcd10
|
|
|
|
|
2020-09-02 16:18:12 +08:00
|
|
|
#define SDHI_GEN3_MMC0_ADDR 0xee140000
|
|
|
|
|
2017-05-10 17:25:29 +08:00
|
|
|
static void renesas_sdhi_sdbuf_width(struct tmio_mmc_host *host, int width)
|
2015-01-13 13:00:07 +08:00
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* see also
|
2017-05-10 17:25:29 +08:00
|
|
|
* renesas_sdhi_of_data :: dma_buswidth
|
2015-01-13 13:00:07 +08:00
|
|
|
*/
|
|
|
|
switch (sd_ctrl_read16(host, CTL_VERSION)) {
|
2016-05-11 20:46:00 +08:00
|
|
|
case SDHI_VER_GEN2_SDR50:
|
2020-11-11 18:02:42 +08:00
|
|
|
val = (width == 32) ? HOST_MODE_GEN2_SDR50_WMODE : 0;
|
2015-01-13 13:00:07 +08:00
|
|
|
break;
|
2016-05-11 20:46:00 +08:00
|
|
|
case SDHI_VER_GEN2_SDR104:
|
2020-11-11 18:02:42 +08:00
|
|
|
val = (width == 32) ? 0 : HOST_MODE_GEN2_SDR104_WMODE;
|
2015-01-13 13:00:07 +08:00
|
|
|
break;
|
2016-05-11 20:46:00 +08:00
|
|
|
case SDHI_VER_GEN3_SD:
|
|
|
|
case SDHI_VER_GEN3_SDMMC:
|
2016-02-15 23:01:48 +08:00
|
|
|
if (width == 64)
|
2020-11-11 18:02:42 +08:00
|
|
|
val = HOST_MODE_GEN3_64BIT;
|
2016-02-15 23:01:48 +08:00
|
|
|
else if (width == 32)
|
2020-11-11 18:02:42 +08:00
|
|
|
val = HOST_MODE_GEN3_32BIT;
|
2016-02-15 23:01:48 +08:00
|
|
|
else
|
2020-11-11 18:02:42 +08:00
|
|
|
val = HOST_MODE_GEN3_16BIT;
|
2016-02-15 23:01:48 +08:00
|
|
|
break;
|
2015-01-13 13:00:07 +08:00
|
|
|
default:
|
|
|
|
/* nothing to do */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-11 18:02:42 +08:00
|
|
|
sd_ctrl_write16(host, CTL_HOST_MODE, val);
|
2015-01-13 13:00:07 +08:00
|
|
|
}
|
|
|
|
|
2017-05-10 17:25:29 +08:00
|
|
|
static int renesas_sdhi_clk_enable(struct tmio_mmc_host *host)
|
2012-06-21 01:10:32 +08:00
|
|
|
{
|
2016-04-01 23:44:31 +08:00
|
|
|
struct mmc_host *mmc = host->mmc;
|
2017-05-10 17:25:29 +08:00
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
2020-05-20 00:42:51 +08:00
|
|
|
int ret;
|
2012-06-21 01:10:32 +08:00
|
|
|
|
2017-01-26 04:28:08 +08:00
|
|
|
ret = clk_prepare_enable(priv->clk_cd);
|
2020-05-20 00:42:51 +08:00
|
|
|
if (ret < 0)
|
2017-01-26 04:28:08 +08:00
|
|
|
return ret;
|
|
|
|
|
2016-04-01 23:44:32 +08:00
|
|
|
/*
|
|
|
|
* The clock driver may not know what maximum frequency
|
|
|
|
* actually works, so it should be set with the max-frequency
|
|
|
|
* property which will already have been read to f_max. If it
|
|
|
|
* was missing, assume the current frequency is the maximum.
|
|
|
|
*/
|
|
|
|
if (!mmc->f_max)
|
|
|
|
mmc->f_max = clk_get_rate(priv->clk);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Minimum frequency is the minimum input clock frequency
|
|
|
|
* divided by our maximum divider.
|
|
|
|
*/
|
|
|
|
mmc->f_min = max(clk_round_rate(priv->clk, 1) / 512, 1L);
|
2015-01-13 13:00:07 +08:00
|
|
|
|
|
|
|
/* enable 16bit data access on SDBUF as default */
|
2017-05-10 17:25:29 +08:00
|
|
|
renesas_sdhi_sdbuf_width(host, 16);
|
2015-01-13 13:00:07 +08:00
|
|
|
|
2012-06-21 01:10:32 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:25:29 +08:00
|
|
|
static unsigned int renesas_sdhi_clk_update(struct tmio_mmc_host *host,
|
2017-06-17 00:11:04 +08:00
|
|
|
unsigned int new_clock)
|
2016-04-01 23:44:32 +08:00
|
|
|
{
|
2017-05-10 17:25:29 +08:00
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
2016-05-03 04:25:39 +08:00
|
|
|
unsigned int freq, diff, best_freq = 0, diff_min = ~0;
|
2019-08-30 02:36:34 +08:00
|
|
|
int i;
|
2016-04-01 23:44:32 +08:00
|
|
|
|
2020-09-01 23:02:49 +08:00
|
|
|
/*
|
|
|
|
* We simply return the current rate if a) we are not on a R-Car Gen2+
|
|
|
|
* SoC (may work for others, but untested) or b) if the SCC needs its
|
|
|
|
* clock during tuning, so we don't change the external clock setup.
|
|
|
|
*/
|
|
|
|
if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2) || mmc_doing_tune(host->mmc))
|
2016-05-03 04:25:41 +08:00
|
|
|
return clk_get_rate(priv->clk);
|
|
|
|
|
2016-04-01 23:44:32 +08:00
|
|
|
/*
|
|
|
|
* We want the bus clock to be as close as possible to, but no
|
|
|
|
* greater than, new_clock. As we can divide by 1 << i for
|
|
|
|
* any i in [0, 9] we want the input clock to be as close as
|
|
|
|
* possible, but no greater than, new_clock << i.
|
|
|
|
*/
|
|
|
|
for (i = min(9, ilog2(UINT_MAX / new_clock)); i >= 0; i--) {
|
|
|
|
freq = clk_round_rate(priv->clk, new_clock << i);
|
|
|
|
if (freq > (new_clock << i)) {
|
|
|
|
/* Too fast; look for a slightly slower option */
|
|
|
|
freq = clk_round_rate(priv->clk,
|
|
|
|
(new_clock << i) / 4 * 3);
|
|
|
|
if (freq > (new_clock << i))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff = new_clock - (freq >> i);
|
|
|
|
if (diff <= diff_min) {
|
|
|
|
best_freq = freq;
|
|
|
|
diff_min = diff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-30 02:36:34 +08:00
|
|
|
clk_set_rate(priv->clk, best_freq);
|
2016-04-01 23:44:32 +08:00
|
|
|
|
2019-08-30 02:36:34 +08:00
|
|
|
return clk_get_rate(priv->clk);
|
2016-04-01 23:44:32 +08:00
|
|
|
}
|
|
|
|
|
2018-08-23 12:44:19 +08:00
|
|
|
static void renesas_sdhi_set_clock(struct tmio_mmc_host *host,
|
|
|
|
unsigned int new_clock)
|
2018-08-23 12:44:16 +08:00
|
|
|
{
|
2018-08-23 12:44:19 +08:00
|
|
|
u32 clk = 0, clock;
|
2018-08-23 12:44:16 +08:00
|
|
|
|
|
|
|
sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
|
|
|
|
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
|
|
|
|
|
2019-08-30 02:36:34 +08:00
|
|
|
if (new_clock == 0) {
|
|
|
|
host->mmc->actual_clock = 0;
|
2018-08-23 12:44:19 +08:00
|
|
|
goto out;
|
2019-08-30 02:36:34 +08:00
|
|
|
}
|
2018-08-23 12:44:16 +08:00
|
|
|
|
2019-08-30 02:36:34 +08:00
|
|
|
host->mmc->actual_clock = renesas_sdhi_clk_update(host, new_clock);
|
|
|
|
clock = host->mmc->actual_clock / 512;
|
2018-08-23 12:44:16 +08:00
|
|
|
|
|
|
|
for (clk = 0x80000080; new_clock >= (clock << 1); clk >>= 1)
|
|
|
|
clock <<= 1;
|
|
|
|
|
|
|
|
/* 1/1 clock is option */
|
|
|
|
if ((host->pdata->flags & TMIO_MMC_CLK_ACTUAL) && ((clk >> 22) & 0x1)) {
|
|
|
|
if (!(host->mmc->ios.timing == MMC_TIMING_MMC_HS400))
|
|
|
|
clk |= 0xff;
|
|
|
|
else
|
|
|
|
clk &= ~0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk & CLK_CTL_DIV_MASK);
|
|
|
|
if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2))
|
|
|
|
usleep_range(10000, 11000);
|
|
|
|
|
2018-08-23 12:44:19 +08:00
|
|
|
sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN |
|
|
|
|
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* HW engineers overrode docs: no sleep needed on R-Car2+ */
|
|
|
|
if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2))
|
|
|
|
usleep_range(10000, 11000);
|
2018-08-23 12:44:16 +08:00
|
|
|
}
|
|
|
|
|
2017-05-10 17:25:29 +08:00
|
|
|
static void renesas_sdhi_clk_disable(struct tmio_mmc_host *host)
|
2012-06-21 01:10:32 +08:00
|
|
|
{
|
2017-05-10 17:25:29 +08:00
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
2016-04-01 23:44:31 +08:00
|
|
|
|
2017-01-26 04:28:08 +08:00
|
|
|
clk_disable_unprepare(priv->clk_cd);
|
2012-06-21 01:10:32 +08:00
|
|
|
}
|
|
|
|
|
2017-05-10 17:25:29 +08:00
|
|
|
static int renesas_sdhi_card_busy(struct mmc_host *mmc)
|
2016-08-24 17:34:37 +08:00
|
|
|
{
|
|
|
|
struct tmio_mmc_host *host = mmc_priv(mmc);
|
|
|
|
|
2017-06-17 00:11:04 +08:00
|
|
|
return !(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) &
|
|
|
|
TMIO_STAT_DAT0);
|
2016-08-24 17:34:37 +08:00
|
|
|
}
|
|
|
|
|
2017-05-10 17:25:29 +08:00
|
|
|
static int renesas_sdhi_start_signal_voltage_switch(struct mmc_host *mmc,
|
2017-06-17 00:11:04 +08:00
|
|
|
struct mmc_ios *ios)
|
2016-04-01 23:44:37 +08:00
|
|
|
{
|
|
|
|
struct tmio_mmc_host *host = mmc_priv(mmc);
|
2017-05-10 17:25:29 +08:00
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
2016-04-01 23:44:37 +08:00
|
|
|
struct pinctrl_state *pin_state;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (ios->signal_voltage) {
|
|
|
|
case MMC_SIGNAL_VOLTAGE_330:
|
|
|
|
pin_state = priv->pins_default;
|
|
|
|
break;
|
|
|
|
case MMC_SIGNAL_VOLTAGE_180:
|
|
|
|
pin_state = priv->pins_uhs;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If anything is missing, assume signal voltage is fixed at
|
|
|
|
* 3.3V and succeed/fail accordingly.
|
|
|
|
*/
|
|
|
|
if (IS_ERR(priv->pinctrl) || IS_ERR(pin_state))
|
|
|
|
return ios->signal_voltage ==
|
|
|
|
MMC_SIGNAL_VOLTAGE_330 ? 0 : -EINVAL;
|
|
|
|
|
|
|
|
ret = mmc_regulator_set_vqmmc(host->mmc, ios);
|
2020-04-17 00:36:47 +08:00
|
|
|
if (ret < 0)
|
2016-04-01 23:44:37 +08:00
|
|
|
return ret;
|
|
|
|
|
2016-04-26 23:55:27 +08:00
|
|
|
return pinctrl_select_state(priv->pinctrl, pin_state);
|
2016-04-01 23:44:37 +08:00
|
|
|
}
|
|
|
|
|
2016-11-03 22:16:04 +08:00
|
|
|
/* SCC registers */
|
|
|
|
#define SH_MOBILE_SDHI_SCC_DTCNTL 0x000
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TAPSET 0x002
|
|
|
|
#define SH_MOBILE_SDHI_SCC_DT2FF 0x004
|
|
|
|
#define SH_MOBILE_SDHI_SCC_CKSEL 0x006
|
|
|
|
#define SH_MOBILE_SDHI_SCC_RVSCNTL 0x008
|
|
|
|
#define SH_MOBILE_SDHI_SCC_RVSREQ 0x00A
|
2019-12-17 19:40:32 +08:00
|
|
|
#define SH_MOBILE_SDHI_SCC_SMPCMP 0x00C
|
2018-06-18 20:57:51 +08:00
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT2 0x00E
|
2020-09-02 16:18:12 +08:00
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT3 0x014
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT4 0x016
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT5 0x018
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT6 0x01A
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT7 0x01C
|
2016-11-03 22:16:04 +08:00
|
|
|
|
|
|
|
#define SH_MOBILE_SDHI_SCC_DTCNTL_TAPEN BIT(0)
|
|
|
|
#define SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_SHIFT 16
|
|
|
|
#define SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_MASK 0xff
|
|
|
|
|
|
|
|
#define SH_MOBILE_SDHI_SCC_CKSEL_DTSEL BIT(0)
|
2019-12-17 19:40:34 +08:00
|
|
|
|
2016-11-03 22:16:04 +08:00
|
|
|
#define SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN BIT(0)
|
2019-12-17 19:40:34 +08:00
|
|
|
|
2019-12-17 19:40:31 +08:00
|
|
|
#define SH_MOBILE_SDHI_SCC_RVSREQ_REQTAPDOWN BIT(0)
|
2019-12-17 19:40:34 +08:00
|
|
|
#define SH_MOBILE_SDHI_SCC_RVSREQ_REQTAPUP BIT(1)
|
|
|
|
#define SH_MOBILE_SDHI_SCC_RVSREQ_RVSERR BIT(2)
|
|
|
|
|
2019-12-17 19:40:32 +08:00
|
|
|
#define SH_MOBILE_SDHI_SCC_SMPCMP_CMD_REQDOWN BIT(8)
|
2019-12-17 19:40:34 +08:00
|
|
|
#define SH_MOBILE_SDHI_SCC_SMPCMP_CMD_REQUP BIT(24)
|
|
|
|
#define SH_MOBILE_SDHI_SCC_SMPCMP_CMD_ERR (BIT(8) | BIT(24))
|
|
|
|
|
2018-06-18 20:57:51 +08:00
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT2_HS400OSEL BIT(4)
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT2_HS400EN BIT(31)
|
2016-11-03 22:16:04 +08:00
|
|
|
|
2020-09-02 16:18:12 +08:00
|
|
|
/* Definitions for values the SH_MOBILE_SDHI_SCC_TMPPORT4 register */
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT4_DLL_ACC_START BIT(0)
|
|
|
|
|
|
|
|
/* Definitions for values the SH_MOBILE_SDHI_SCC_TMPPORT5 register */
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT5_DLL_RW_SEL_R BIT(8)
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT5_DLL_RW_SEL_W (0 << 8)
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT5_DLL_ADR_MASK 0x3F
|
|
|
|
|
|
|
|
/* Definitions for values the SH_MOBILE_SDHI_SCC register */
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT_DISABLE_WP_CODE 0xa5000000
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT_CALIB_CODE_MASK 0x1f
|
|
|
|
#define SH_MOBILE_SDHI_SCC_TMPPORT_MANUAL_MODE BIT(7)
|
|
|
|
|
|
|
|
static const u8 r8a7796_es13_calib_table[2][SDHI_CALIB_TABLE_MAX] = {
|
|
|
|
{ 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 6, 7, 8, 9, 10, 15,
|
|
|
|
16, 16, 16, 16, 16, 16, 17, 18, 18, 19, 20, 21, 22, 23, 24, 25 },
|
|
|
|
{ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 7, 8, 11,
|
|
|
|
12, 17, 18, 18, 18, 18, 18, 18, 18, 19, 20, 21, 22, 23, 25, 25 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const u8 r8a77965_calib_table[2][SDHI_CALIB_TABLE_MAX] = {
|
|
|
|
{ 1, 2, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 15, 15, 16,
|
|
|
|
17, 18, 19, 20, 21, 22, 23, 24, 25, 25, 26, 27, 28, 29, 30, 31 },
|
|
|
|
{ 2, 3, 4, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
|
|
|
17, 17, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 31, 31, 31 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const u8 r8a77990_calib_table[2][SDHI_CALIB_TABLE_MAX] = {
|
|
|
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
|
|
|
{ 0, 0, 0, 1, 2, 3, 3, 4, 4, 4, 5, 5, 6, 8, 9, 10,
|
|
|
|
11, 12, 13, 15, 16, 17, 17, 18, 18, 19, 20, 22, 24, 25, 26, 26 }
|
|
|
|
};
|
|
|
|
|
2016-11-03 22:16:04 +08:00
|
|
|
static inline u32 sd_scc_read32(struct tmio_mmc_host *host,
|
2017-05-10 17:25:29 +08:00
|
|
|
struct renesas_sdhi *priv, int addr)
|
2016-11-03 22:16:04 +08:00
|
|
|
{
|
|
|
|
return readl(priv->scc_ctl + (addr << host->bus_shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void sd_scc_write32(struct tmio_mmc_host *host,
|
2017-05-10 17:25:29 +08:00
|
|
|
struct renesas_sdhi *priv,
|
2016-11-03 22:16:04 +08:00
|
|
|
int addr, u32 val)
|
|
|
|
{
|
|
|
|
writel(val, priv->scc_ctl + (addr << host->bus_shift));
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:25:29 +08:00
|
|
|
static unsigned int renesas_sdhi_init_tuning(struct tmio_mmc_host *host)
|
2016-11-03 22:16:04 +08:00
|
|
|
{
|
2017-05-10 17:25:29 +08:00
|
|
|
struct renesas_sdhi *priv;
|
2016-11-03 22:16:04 +08:00
|
|
|
|
|
|
|
priv = host_to_priv(host);
|
|
|
|
|
|
|
|
/* Initialize SCC */
|
|
|
|
sd_ctrl_write32_as_16_and_16(host, CTL_STATUS, 0x0);
|
|
|
|
|
|
|
|
sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
|
|
|
|
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
|
|
|
|
|
2018-06-18 20:57:51 +08:00
|
|
|
/* set sampling clock selection range */
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_DTCNTL,
|
|
|
|
SH_MOBILE_SDHI_SCC_DTCNTL_TAPEN |
|
|
|
|
0x8 << SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_SHIFT);
|
|
|
|
|
2016-11-03 22:16:04 +08:00
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_CKSEL,
|
|
|
|
SH_MOBILE_SDHI_SCC_CKSEL_DTSEL |
|
|
|
|
sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_CKSEL));
|
|
|
|
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL,
|
|
|
|
~SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN &
|
|
|
|
sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL));
|
|
|
|
|
2017-11-25 00:24:49 +08:00
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_DT2FF, priv->scc_tappos);
|
2016-11-03 22:16:04 +08:00
|
|
|
|
2018-06-18 20:57:51 +08:00
|
|
|
sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN |
|
|
|
|
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
|
|
|
|
|
2016-11-03 22:16:04 +08:00
|
|
|
/* Read TAPNUM */
|
|
|
|
return (sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_DTCNTL) >>
|
|
|
|
SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_SHIFT) &
|
|
|
|
SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_MASK;
|
|
|
|
}
|
|
|
|
|
2020-01-30 04:37:09 +08:00
|
|
|
static void renesas_sdhi_hs400_complete(struct mmc_host *mmc)
|
2018-06-18 20:57:51 +08:00
|
|
|
{
|
2020-01-30 04:37:09 +08:00
|
|
|
struct tmio_mmc_host *host = mmc_priv(mmc);
|
2018-06-18 20:57:51 +08:00
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
u32 bad_taps = priv->quirks ? priv->quirks->hs400_bad_taps : 0;
|
|
|
|
bool use_4tap = priv->quirks && priv->quirks->hs400_4taps;
|
2018-06-18 20:57:51 +08:00
|
|
|
|
|
|
|
sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
|
|
|
|
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
|
|
|
|
|
|
|
|
/* Set HS400 mode */
|
2020-11-11 18:02:43 +08:00
|
|
|
sd_ctrl_write16(host, CTL_SDIF_MODE, SDIF_MODE_HS400 |
|
2018-06-18 20:57:51 +08:00
|
|
|
sd_ctrl_read16(host, CTL_SDIF_MODE));
|
2019-02-09 03:30:02 +08:00
|
|
|
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_DT2FF,
|
|
|
|
priv->scc_tappos_hs400);
|
|
|
|
|
2019-12-17 19:40:33 +08:00
|
|
|
/* Gen3 can't do automatic tap correction with HS400, so disable it */
|
|
|
|
if (sd_ctrl_read16(host, CTL_VERSION) == SDHI_VER_GEN3_SDMMC)
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL,
|
|
|
|
~SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN &
|
|
|
|
sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL));
|
|
|
|
|
2018-06-18 20:57:51 +08:00
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT2,
|
|
|
|
(SH_MOBILE_SDHI_SCC_TMPPORT2_HS400EN |
|
|
|
|
SH_MOBILE_SDHI_SCC_TMPPORT2_HS400OSEL) |
|
|
|
|
sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT2));
|
|
|
|
|
|
|
|
/* Set the sampling clock selection range of HS400 mode */
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_DTCNTL,
|
|
|
|
SH_MOBILE_SDHI_SCC_DTCNTL_TAPEN |
|
|
|
|
0x4 << SH_MOBILE_SDHI_SCC_DTCNTL_TAPNUM_SHIFT);
|
|
|
|
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
/* Avoid bad TAP */
|
|
|
|
if (bad_taps & BIT(priv->tap_set)) {
|
|
|
|
u32 new_tap = (priv->tap_set + 1) % priv->tap_num;
|
|
|
|
|
|
|
|
if (bad_taps & BIT(new_tap))
|
|
|
|
new_tap = (priv->tap_set - 1) % priv->tap_num;
|
2018-06-18 20:57:51 +08:00
|
|
|
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
if (bad_taps & BIT(new_tap)) {
|
|
|
|
new_tap = priv->tap_set;
|
|
|
|
dev_dbg(&host->pdev->dev, "Can't handle three bad tap in a row\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->tap_set = new_tap;
|
|
|
|
}
|
|
|
|
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TAPSET,
|
|
|
|
priv->tap_set / (use_4tap ? 2 : 1));
|
2018-06-18 20:57:51 +08:00
|
|
|
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_CKSEL,
|
|
|
|
SH_MOBILE_SDHI_SCC_CKSEL_DTSEL |
|
|
|
|
sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_CKSEL));
|
|
|
|
|
|
|
|
sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN |
|
|
|
|
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
|
2020-09-02 16:18:12 +08:00
|
|
|
|
|
|
|
if (priv->adjust_hs400_calib_table)
|
|
|
|
priv->needs_adjust_hs400 = true;
|
2018-06-18 20:57:51 +08:00
|
|
|
}
|
|
|
|
|
2020-11-11 00:21:50 +08:00
|
|
|
static void renesas_sdhi_disable_scc(struct mmc_host *mmc)
|
2018-06-18 20:57:51 +08:00
|
|
|
{
|
2020-11-11 00:21:50 +08:00
|
|
|
struct tmio_mmc_host *host = mmc_priv(mmc);
|
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
|
|
|
|
2018-06-18 20:57:51 +08:00
|
|
|
sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
|
|
|
|
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
|
|
|
|
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_CKSEL,
|
|
|
|
~SH_MOBILE_SDHI_SCC_CKSEL_DTSEL &
|
|
|
|
sd_scc_read32(host, priv,
|
|
|
|
SH_MOBILE_SDHI_SCC_CKSEL));
|
|
|
|
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_DTCNTL,
|
|
|
|
~SH_MOBILE_SDHI_SCC_DTCNTL_TAPEN &
|
|
|
|
sd_scc_read32(host, priv,
|
|
|
|
SH_MOBILE_SDHI_SCC_DTCNTL));
|
|
|
|
|
|
|
|
sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN |
|
|
|
|
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
|
|
|
|
}
|
|
|
|
|
2020-09-02 16:18:12 +08:00
|
|
|
static u32 sd_scc_tmpport_read32(struct tmio_mmc_host *host,
|
|
|
|
struct renesas_sdhi *priv, u32 addr)
|
|
|
|
{
|
|
|
|
/* read mode */
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT5,
|
|
|
|
SH_MOBILE_SDHI_SCC_TMPPORT5_DLL_RW_SEL_R |
|
|
|
|
(SH_MOBILE_SDHI_SCC_TMPPORT5_DLL_ADR_MASK & addr));
|
|
|
|
|
|
|
|
/* access start and stop */
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT4,
|
|
|
|
SH_MOBILE_SDHI_SCC_TMPPORT4_DLL_ACC_START);
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT4, 0);
|
|
|
|
|
|
|
|
return sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT7);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sd_scc_tmpport_write32(struct tmio_mmc_host *host,
|
|
|
|
struct renesas_sdhi *priv, u32 addr, u32 val)
|
|
|
|
{
|
|
|
|
/* write mode */
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT5,
|
|
|
|
SH_MOBILE_SDHI_SCC_TMPPORT5_DLL_RW_SEL_W |
|
|
|
|
(SH_MOBILE_SDHI_SCC_TMPPORT5_DLL_ADR_MASK & addr));
|
|
|
|
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT6, val);
|
|
|
|
|
|
|
|
/* access start and stop */
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT4,
|
|
|
|
SH_MOBILE_SDHI_SCC_TMPPORT4_DLL_ACC_START);
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT4, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void renesas_sdhi_adjust_hs400_mode_enable(struct tmio_mmc_host *host)
|
|
|
|
{
|
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
|
|
|
u32 calib_code;
|
|
|
|
|
|
|
|
/* disable write protect */
|
|
|
|
sd_scc_tmpport_write32(host, priv, 0x00,
|
|
|
|
SH_MOBILE_SDHI_SCC_TMPPORT_DISABLE_WP_CODE);
|
|
|
|
/* read calibration code and adjust */
|
|
|
|
calib_code = sd_scc_tmpport_read32(host, priv, 0x26);
|
|
|
|
calib_code &= SH_MOBILE_SDHI_SCC_TMPPORT_CALIB_CODE_MASK;
|
|
|
|
|
|
|
|
sd_scc_tmpport_write32(host, priv, 0x22,
|
|
|
|
SH_MOBILE_SDHI_SCC_TMPPORT_MANUAL_MODE |
|
|
|
|
priv->adjust_hs400_calib_table[calib_code]);
|
|
|
|
|
|
|
|
/* set offset value to TMPPORT3, hardcoded to OFFSET0 (= 0x3) for now */
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT3, 0x3);
|
|
|
|
|
|
|
|
/* adjustment done, clear flag */
|
|
|
|
priv->needs_adjust_hs400 = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void renesas_sdhi_adjust_hs400_mode_disable(struct tmio_mmc_host *host)
|
|
|
|
{
|
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
|
|
|
|
|
|
|
/* disable write protect */
|
|
|
|
sd_scc_tmpport_write32(host, priv, 0x00,
|
|
|
|
SH_MOBILE_SDHI_SCC_TMPPORT_DISABLE_WP_CODE);
|
|
|
|
/* disable manual calibration */
|
|
|
|
sd_scc_tmpport_write32(host, priv, 0x22, 0);
|
|
|
|
/* clear offset value of TMPPORT3 */
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT3, 0);
|
|
|
|
}
|
|
|
|
|
2018-06-18 20:57:51 +08:00
|
|
|
static void renesas_sdhi_reset_hs400_mode(struct tmio_mmc_host *host,
|
|
|
|
struct renesas_sdhi *priv)
|
|
|
|
{
|
|
|
|
sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
|
|
|
|
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
|
|
|
|
|
|
|
|
/* Reset HS400 mode */
|
2020-11-11 18:02:43 +08:00
|
|
|
sd_ctrl_write16(host, CTL_SDIF_MODE, ~SDIF_MODE_HS400 &
|
2018-06-18 20:57:51 +08:00
|
|
|
sd_ctrl_read16(host, CTL_SDIF_MODE));
|
2019-02-09 03:30:02 +08:00
|
|
|
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_DT2FF, priv->scc_tappos);
|
|
|
|
|
2018-06-18 20:57:51 +08:00
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT2,
|
|
|
|
~(SH_MOBILE_SDHI_SCC_TMPPORT2_HS400EN |
|
|
|
|
SH_MOBILE_SDHI_SCC_TMPPORT2_HS400OSEL) &
|
|
|
|
sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT2));
|
|
|
|
|
2020-09-02 16:18:12 +08:00
|
|
|
if (priv->adjust_hs400_calib_table)
|
|
|
|
renesas_sdhi_adjust_hs400_mode_disable(host);
|
|
|
|
|
2018-06-18 20:57:51 +08:00
|
|
|
sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN |
|
|
|
|
sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
|
|
|
|
}
|
|
|
|
|
2020-01-30 04:37:09 +08:00
|
|
|
static int renesas_sdhi_prepare_hs400_tuning(struct mmc_host *mmc, struct mmc_ios *ios)
|
2018-06-18 20:57:51 +08:00
|
|
|
{
|
2020-01-30 04:37:09 +08:00
|
|
|
struct tmio_mmc_host *host = mmc_priv(mmc);
|
|
|
|
|
2018-06-18 20:57:51 +08:00
|
|
|
renesas_sdhi_reset_hs400_mode(host, host_to_priv(host));
|
2020-01-30 04:37:09 +08:00
|
|
|
return 0;
|
2018-06-18 20:57:51 +08:00
|
|
|
}
|
|
|
|
|
2020-11-10 22:20:58 +08:00
|
|
|
/* only populated for TMIO_MMC_MIN_RCAR2 */
|
2020-08-20 21:25:37 +08:00
|
|
|
static void renesas_sdhi_reset(struct tmio_mmc_host *host)
|
|
|
|
{
|
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
2020-11-26 05:30:01 +08:00
|
|
|
u16 val;
|
2020-08-20 21:25:37 +08:00
|
|
|
|
2020-11-10 22:20:55 +08:00
|
|
|
if (priv->scc_ctl) {
|
2020-11-11 00:21:49 +08:00
|
|
|
renesas_sdhi_disable_scc(host->mmc);
|
2020-11-10 22:20:55 +08:00
|
|
|
renesas_sdhi_reset_hs400_mode(host, priv);
|
|
|
|
priv->needs_adjust_hs400 = false;
|
2020-08-20 21:25:37 +08:00
|
|
|
|
2020-11-10 22:20:55 +08:00
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL,
|
|
|
|
~SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN &
|
|
|
|
sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL));
|
|
|
|
}
|
2020-08-20 21:25:37 +08:00
|
|
|
|
2020-11-10 22:20:58 +08:00
|
|
|
sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, TMIO_MASK_INIT_RCAR2);
|
2020-11-26 05:30:01 +08:00
|
|
|
|
|
|
|
if (sd_ctrl_read16(host, CTL_VERSION) >= SDHI_VER_GEN3_SD) {
|
|
|
|
val = sd_ctrl_read16(host, CTL_SD_MEM_CARD_OPT);
|
|
|
|
val |= CARD_OPT_EXTOP;
|
|
|
|
sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int renesas_sdhi_gen3_get_cycles(struct tmio_mmc_host *host)
|
|
|
|
{
|
|
|
|
u16 num, val = sd_ctrl_read16(host, CTL_SD_MEM_CARD_OPT);
|
|
|
|
|
|
|
|
num = (val & CARD_OPT_TOP_MASK) >> CARD_OPT_TOP_SHIFT;
|
|
|
|
return 1 << ((val & CARD_OPT_EXTOP ? 14 : 13) + num);
|
|
|
|
|
2020-08-20 21:25:37 +08:00
|
|
|
}
|
|
|
|
|
2020-04-08 17:46:37 +08:00
|
|
|
#define SH_MOBILE_SDHI_MIN_TAP_ROW 3
|
2016-11-03 22:16:04 +08:00
|
|
|
|
2017-05-10 17:25:29 +08:00
|
|
|
static int renesas_sdhi_select_tuning(struct tmio_mmc_host *host)
|
2016-11-03 22:16:04 +08:00
|
|
|
{
|
2017-05-10 17:25:29 +08:00
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
2020-04-08 17:46:36 +08:00
|
|
|
unsigned int tap_start = 0, tap_end = 0, tap_cnt = 0, rs, re, i;
|
2020-04-08 17:46:38 +08:00
|
|
|
unsigned int taps_size = priv->tap_num * 2, min_tap_row;
|
|
|
|
unsigned long *bitmap;
|
2016-11-03 22:16:04 +08:00
|
|
|
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSREQ, 0);
|
|
|
|
|
2018-07-24 22:51:38 +08:00
|
|
|
/*
|
|
|
|
* When tuning CMD19 is issued twice for each tap, merge the
|
|
|
|
* result requiring the tap to be good in both runs before
|
|
|
|
* considering it for tuning selection.
|
|
|
|
*/
|
2020-04-08 17:46:36 +08:00
|
|
|
for (i = 0; i < taps_size; i++) {
|
2020-01-30 04:37:08 +08:00
|
|
|
int offset = priv->tap_num * (i < priv->tap_num ? 1 : -1);
|
2018-07-24 22:51:38 +08:00
|
|
|
|
2020-01-30 04:37:08 +08:00
|
|
|
if (!test_bit(i, priv->taps))
|
|
|
|
clear_bit(i + offset, priv->taps);
|
2020-04-08 17:46:38 +08:00
|
|
|
|
|
|
|
if (!test_bit(i, priv->smpcmp))
|
|
|
|
clear_bit(i + offset, priv->smpcmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If all TAP are OK, the sampling clock position is selected by
|
|
|
|
* identifying the change point of data.
|
|
|
|
*/
|
|
|
|
if (bitmap_full(priv->taps, taps_size)) {
|
|
|
|
bitmap = priv->smpcmp;
|
|
|
|
min_tap_row = 1;
|
|
|
|
} else {
|
|
|
|
bitmap = priv->taps;
|
|
|
|
min_tap_row = SH_MOBILE_SDHI_MIN_TAP_ROW;
|
2018-07-24 22:51:38 +08:00
|
|
|
}
|
|
|
|
|
2016-11-03 22:16:04 +08:00
|
|
|
/*
|
2020-04-08 17:46:37 +08:00
|
|
|
* Find the longest consecutive run of successful probes. If that
|
|
|
|
* is at least SH_MOBILE_SDHI_MIN_TAP_ROW probes long then use the
|
|
|
|
* center index as the tap, otherwise bail out.
|
2016-11-03 22:16:04 +08:00
|
|
|
*/
|
2020-04-08 17:46:38 +08:00
|
|
|
bitmap_for_each_set_region(bitmap, rs, re, 0, taps_size) {
|
2020-04-08 17:46:36 +08:00
|
|
|
if (re - rs > tap_cnt) {
|
|
|
|
tap_end = re;
|
|
|
|
tap_start = rs;
|
|
|
|
tap_cnt = tap_end - tap_start;
|
2016-11-03 22:16:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 17:46:38 +08:00
|
|
|
if (tap_cnt >= min_tap_row)
|
2020-01-30 04:37:08 +08:00
|
|
|
priv->tap_set = (tap_start + tap_end) / 2 % priv->tap_num;
|
2016-11-03 22:16:04 +08:00
|
|
|
else
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
/* Set SCC */
|
2020-01-30 04:37:08 +08:00
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TAPSET, priv->tap_set);
|
2016-11-03 22:16:04 +08:00
|
|
|
|
|
|
|
/* Enable auto re-tuning */
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL,
|
|
|
|
SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN |
|
|
|
|
sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-20 21:25:38 +08:00
|
|
|
static int renesas_sdhi_execute_tuning(struct mmc_host *mmc, u32 opcode)
|
2020-01-30 04:37:04 +08:00
|
|
|
{
|
2020-08-20 21:25:38 +08:00
|
|
|
struct tmio_mmc_host *host = mmc_priv(mmc);
|
2020-01-30 04:37:04 +08:00
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
2020-08-20 21:25:37 +08:00
|
|
|
int i, ret;
|
2020-01-30 04:37:04 +08:00
|
|
|
|
2020-01-30 04:37:08 +08:00
|
|
|
priv->tap_num = renesas_sdhi_init_tuning(host);
|
|
|
|
if (!priv->tap_num)
|
2020-01-30 04:37:04 +08:00
|
|
|
return 0; /* Tuning is not supported */
|
|
|
|
|
2020-01-30 04:37:08 +08:00
|
|
|
if (priv->tap_num * 2 >= sizeof(priv->taps) * BITS_PER_BYTE) {
|
2020-01-30 04:37:05 +08:00
|
|
|
dev_err(&host->pdev->dev,
|
|
|
|
"Too many taps, please update 'taps' in tmio_mmc_host!\n");
|
|
|
|
return -EINVAL;
|
2020-01-30 04:37:04 +08:00
|
|
|
}
|
|
|
|
|
2020-01-30 04:37:08 +08:00
|
|
|
bitmap_zero(priv->taps, priv->tap_num * 2);
|
2020-04-08 17:46:38 +08:00
|
|
|
bitmap_zero(priv->smpcmp, priv->tap_num * 2);
|
2020-01-30 04:37:04 +08:00
|
|
|
|
|
|
|
/* Issue CMD19 twice for each tap */
|
2020-01-30 04:37:08 +08:00
|
|
|
for (i = 0; i < 2 * priv->tap_num; i++) {
|
2020-01-30 04:37:04 +08:00
|
|
|
/* Set sampling clock position */
|
2020-01-30 04:37:08 +08:00
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TAPSET, i % priv->tap_num);
|
2020-01-30 04:37:04 +08:00
|
|
|
|
2020-08-20 21:25:38 +08:00
|
|
|
if (mmc_send_tuning(mmc, opcode, NULL) == 0)
|
2020-01-30 04:37:08 +08:00
|
|
|
set_bit(i, priv->taps);
|
2020-04-08 17:46:38 +08:00
|
|
|
|
|
|
|
if (sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_SMPCMP) == 0)
|
|
|
|
set_bit(i, priv->smpcmp);
|
2020-01-30 04:37:04 +08:00
|
|
|
}
|
|
|
|
|
2020-08-20 21:25:37 +08:00
|
|
|
ret = renesas_sdhi_select_tuning(host);
|
|
|
|
if (ret < 0)
|
|
|
|
renesas_sdhi_reset(host);
|
|
|
|
return ret;
|
2020-01-30 04:37:04 +08:00
|
|
|
}
|
|
|
|
|
2019-12-17 19:40:31 +08:00
|
|
|
static bool renesas_sdhi_manual_correction(struct tmio_mmc_host *host, bool use_4tap)
|
|
|
|
{
|
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
unsigned int new_tap = priv->tap_set, error_tap = priv->tap_set;
|
2019-12-17 19:40:31 +08:00
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSREQ);
|
|
|
|
if (!val)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSREQ, 0);
|
|
|
|
|
|
|
|
/* Change TAP position according to correction status */
|
2019-12-17 19:40:32 +08:00
|
|
|
if (sd_ctrl_read16(host, CTL_VERSION) == SDHI_VER_GEN3_SDMMC &&
|
|
|
|
host->mmc->ios.timing == MMC_TIMING_MMC_HS400) {
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
u32 bad_taps = priv->quirks ? priv->quirks->hs400_bad_taps : 0;
|
2019-12-17 19:40:32 +08:00
|
|
|
/*
|
|
|
|
* With HS400, the DAT signal is based on DS, not CLK.
|
|
|
|
* Therefore, use only CMD status.
|
|
|
|
*/
|
|
|
|
u32 smpcmp = sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_SMPCMP) &
|
|
|
|
SH_MOBILE_SDHI_SCC_SMPCMP_CMD_ERR;
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
if (!smpcmp) {
|
2019-12-17 19:40:32 +08:00
|
|
|
return false; /* no error in CMD signal */
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
} else if (smpcmp == SH_MOBILE_SDHI_SCC_SMPCMP_CMD_REQUP) {
|
2019-12-17 19:40:32 +08:00
|
|
|
new_tap++;
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
error_tap--;
|
|
|
|
} else if (smpcmp == SH_MOBILE_SDHI_SCC_SMPCMP_CMD_REQDOWN) {
|
2019-12-17 19:40:32 +08:00
|
|
|
new_tap--;
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
error_tap++;
|
|
|
|
} else {
|
2019-12-17 19:40:32 +08:00
|
|
|
return true; /* need retune */
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When new_tap is a bad tap, we cannot change. Then, we compare
|
|
|
|
* with the HS200 tuning result. When smpcmp[error_tap] is OK,
|
|
|
|
* we can at least retune.
|
|
|
|
*/
|
|
|
|
if (bad_taps & BIT(new_tap % priv->tap_num))
|
|
|
|
return test_bit(error_tap % priv->tap_num, priv->smpcmp);
|
2019-12-17 19:40:32 +08:00
|
|
|
} else {
|
|
|
|
if (val & SH_MOBILE_SDHI_SCC_RVSREQ_RVSERR)
|
|
|
|
return true; /* need retune */
|
|
|
|
else if (val & SH_MOBILE_SDHI_SCC_RVSREQ_REQTAPUP)
|
|
|
|
new_tap++;
|
|
|
|
else if (val & SH_MOBILE_SDHI_SCC_RVSREQ_REQTAPDOWN)
|
|
|
|
new_tap--;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-17 19:40:31 +08:00
|
|
|
|
2020-01-30 04:37:08 +08:00
|
|
|
priv->tap_set = (new_tap % priv->tap_num);
|
2019-12-17 19:40:31 +08:00
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_TAPSET,
|
2020-01-30 04:37:08 +08:00
|
|
|
priv->tap_set / (use_4tap ? 2 : 1));
|
2019-12-17 19:40:31 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool renesas_sdhi_auto_correction(struct tmio_mmc_host *host)
|
|
|
|
{
|
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
|
|
|
|
|
|
|
/* Check SCC error */
|
|
|
|
if (sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSREQ) &
|
|
|
|
SH_MOBILE_SDHI_SCC_RVSREQ_RVSERR) {
|
|
|
|
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSREQ, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-23 15:30:22 +08:00
|
|
|
static bool renesas_sdhi_check_scc_error(struct tmio_mmc_host *host,
|
|
|
|
struct mmc_request *mrq)
|
2016-11-03 22:16:04 +08:00
|
|
|
{
|
2017-05-10 17:25:29 +08:00
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
2019-12-04 04:05:12 +08:00
|
|
|
bool use_4tap = priv->quirks && priv->quirks->hs400_4taps;
|
2020-12-23 15:30:22 +08:00
|
|
|
bool ret = false;
|
2018-08-30 07:32:06 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip checking SCC errors when running on 4 taps in HS400 mode as
|
|
|
|
* any retuning would still result in the same 4 taps being used.
|
|
|
|
*/
|
|
|
|
if (!(host->mmc->ios.timing == MMC_TIMING_UHS_SDR104) &&
|
|
|
|
!(host->mmc->ios.timing == MMC_TIMING_MMC_HS200) &&
|
|
|
|
!(host->mmc->ios.timing == MMC_TIMING_MMC_HS400 && !use_4tap))
|
|
|
|
return false;
|
|
|
|
|
2020-09-23 01:22:53 +08:00
|
|
|
if (mmc_doing_tune(host->mmc))
|
2018-08-30 07:32:06 +08:00
|
|
|
return false;
|
2016-11-03 22:16:04 +08:00
|
|
|
|
2020-12-23 15:30:22 +08:00
|
|
|
if (((mrq->cmd->error == -ETIMEDOUT) ||
|
|
|
|
(mrq->data && mrq->data->error == -ETIMEDOUT)) &&
|
|
|
|
((host->mmc->caps & MMC_CAP_NONREMOVABLE) ||
|
|
|
|
(host->ops.get_cd && host->ops.get_cd(host->mmc))))
|
|
|
|
ret |= true;
|
|
|
|
|
2016-11-03 22:16:04 +08:00
|
|
|
if (sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_RVSCNTL) &
|
2019-12-17 19:40:31 +08:00
|
|
|
SH_MOBILE_SDHI_SCC_RVSCNTL_RVSEN)
|
2020-12-23 15:30:22 +08:00
|
|
|
ret |= renesas_sdhi_auto_correction(host);
|
|
|
|
else
|
|
|
|
ret |= renesas_sdhi_manual_correction(host, use_4tap);
|
2016-11-03 22:16:04 +08:00
|
|
|
|
2020-12-23 15:30:22 +08:00
|
|
|
return ret;
|
2016-11-03 22:16:04 +08:00
|
|
|
}
|
|
|
|
|
2017-06-28 23:21:56 +08:00
|
|
|
static int renesas_sdhi_wait_idle(struct tmio_mmc_host *host, u32 bit)
|
2011-06-21 07:00:10 +08:00
|
|
|
{
|
|
|
|
int timeout = 1000;
|
2017-06-28 23:21:56 +08:00
|
|
|
/* CBSY is set when busy, SCLKDIVEN is cleared when busy */
|
|
|
|
u32 wait_state = (bit == TMIO_STAT_CMD_BUSY ? TMIO_STAT_CMD_BUSY : 0);
|
2011-06-21 07:00:10 +08:00
|
|
|
|
2017-06-28 23:21:56 +08:00
|
|
|
while (--timeout && (sd_ctrl_read16_and_16_as_32(host, CTL_STATUS)
|
|
|
|
& bit) == wait_state)
|
2011-06-21 07:00:10 +08:00
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
if (!timeout) {
|
2015-01-13 12:57:22 +08:00
|
|
|
dev_warn(&host->pdev->dev, "timeout waiting for SD bus idle\n");
|
2011-06-21 07:00:10 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:25:29 +08:00
|
|
|
static int renesas_sdhi_write16_hook(struct tmio_mmc_host *host, int addr)
|
2011-06-21 07:00:10 +08:00
|
|
|
{
|
2017-06-28 23:21:56 +08:00
|
|
|
u32 bit = TMIO_STAT_SCLKDIVEN;
|
|
|
|
|
2017-06-17 00:11:04 +08:00
|
|
|
switch (addr) {
|
2011-06-21 07:00:10 +08:00
|
|
|
case CTL_SD_CMD:
|
|
|
|
case CTL_STOP_INTERNAL_ACTION:
|
|
|
|
case CTL_XFER_BLK_COUNT:
|
|
|
|
case CTL_SD_XFER_LEN:
|
|
|
|
case CTL_SD_MEM_CARD_OPT:
|
|
|
|
case CTL_TRANSACTION_CTL:
|
|
|
|
case CTL_DMA_ENABLE:
|
2020-11-11 18:02:42 +08:00
|
|
|
case CTL_HOST_MODE:
|
2017-08-10 03:00:41 +08:00
|
|
|
if (host->pdata->flags & TMIO_MMC_HAVE_CBSY)
|
2017-06-28 23:21:56 +08:00
|
|
|
bit = TMIO_STAT_CMD_BUSY;
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2017-06-28 23:21:56 +08:00
|
|
|
case CTL_SD_CARD_CLK_CTL:
|
|
|
|
return renesas_sdhi_wait_idle(host, bit);
|
2011-06-21 07:00:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:25:29 +08:00
|
|
|
static int renesas_sdhi_multi_io_quirk(struct mmc_card *card,
|
2017-06-17 00:11:04 +08:00
|
|
|
unsigned int direction, int blk_size)
|
2014-09-09 14:45:46 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* In Renesas controllers, when performing a
|
|
|
|
* multiple block read of one or two blocks,
|
|
|
|
* depending on the timing with which the
|
|
|
|
* response register is read, the response
|
|
|
|
* value may not be read properly.
|
|
|
|
* Use single block read for this HW bug
|
|
|
|
*/
|
|
|
|
if ((direction == MMC_DATA_READ) &&
|
|
|
|
blk_size == 2)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return blk_size;
|
|
|
|
}
|
|
|
|
|
2020-09-02 16:18:12 +08:00
|
|
|
static void renesas_sdhi_fixup_request(struct tmio_mmc_host *host, struct mmc_request *mrq)
|
|
|
|
{
|
|
|
|
struct renesas_sdhi *priv = host_to_priv(host);
|
|
|
|
|
|
|
|
if (priv->needs_adjust_hs400 && mrq->cmd->opcode == MMC_SEND_STATUS)
|
|
|
|
renesas_sdhi_adjust_hs400_mode_enable(host);
|
|
|
|
}
|
2017-05-10 17:25:29 +08:00
|
|
|
static void renesas_sdhi_enable_dma(struct tmio_mmc_host *host, bool enable)
|
2015-01-13 12:59:56 +08:00
|
|
|
{
|
2017-08-10 02:29:26 +08:00
|
|
|
/* Iff regs are 8 byte apart, sdbuf is 64 bit. Otherwise always 32. */
|
|
|
|
int width = (host->bus_shift == 2) ? 64 : 32;
|
2015-01-13 13:00:07 +08:00
|
|
|
|
2017-08-10 02:29:26 +08:00
|
|
|
sd_ctrl_write16(host, CTL_DMA_ENABLE, enable ? DMA_ENABLE_DMASDRW : 0);
|
|
|
|
renesas_sdhi_sdbuf_width(host, enable ? width : 16);
|
2015-01-13 12:59:56 +08:00
|
|
|
}
|
|
|
|
|
2019-06-06 19:35:36 +08:00
|
|
|
static const struct renesas_sdhi_quirks sdhi_quirks_4tap_nohs400 = {
|
2018-11-29 00:18:29 +08:00
|
|
|
.hs400_disabled = true,
|
|
|
|
.hs400_4taps = true,
|
|
|
|
};
|
|
|
|
|
2019-06-06 19:35:36 +08:00
|
|
|
static const struct renesas_sdhi_quirks sdhi_quirks_4tap = {
|
2018-11-29 00:18:27 +08:00
|
|
|
.hs400_4taps = true,
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
.hs400_bad_taps = BIT(2) | BIT(3) | BIT(6) | BIT(7),
|
2018-11-29 00:18:27 +08:00
|
|
|
};
|
|
|
|
|
2019-06-06 19:35:35 +08:00
|
|
|
static const struct renesas_sdhi_quirks sdhi_quirks_nohs400 = {
|
|
|
|
.hs400_disabled = true,
|
|
|
|
};
|
|
|
|
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
static const struct renesas_sdhi_quirks sdhi_quirks_bad_taps1357 = {
|
|
|
|
.hs400_bad_taps = BIT(1) | BIT(3) | BIT(5) | BIT(7),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct renesas_sdhi_quirks sdhi_quirks_bad_taps2367 = {
|
|
|
|
.hs400_bad_taps = BIT(2) | BIT(3) | BIT(6) | BIT(7),
|
|
|
|
};
|
|
|
|
|
2020-09-02 16:18:12 +08:00
|
|
|
static const struct renesas_sdhi_quirks sdhi_quirks_r8a7796_es13 = {
|
|
|
|
.hs400_4taps = true,
|
|
|
|
.hs400_bad_taps = BIT(2) | BIT(3) | BIT(6) | BIT(7),
|
|
|
|
.hs400_calib_table = r8a7796_es13_calib_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct renesas_sdhi_quirks sdhi_quirks_r8a77965 = {
|
|
|
|
.hs400_bad_taps = BIT(2) | BIT(3) | BIT(6) | BIT(7),
|
|
|
|
.hs400_calib_table = r8a77965_calib_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct renesas_sdhi_quirks sdhi_quirks_r8a77990 = {
|
|
|
|
.hs400_calib_table = r8a77990_calib_table,
|
|
|
|
};
|
|
|
|
|
2020-04-23 21:04:31 +08:00
|
|
|
/*
|
|
|
|
* Note for r8a7796 / r8a774a1: we can't distinguish ES1.1 and 1.2 as of now.
|
|
|
|
* So, we want to treat them equally and only have a match for ES1.2 to enforce
|
|
|
|
* this if there ever will be a way to distinguish ES1.2.
|
|
|
|
*/
|
2018-11-29 00:18:27 +08:00
|
|
|
static const struct soc_device_attribute sdhi_quirks_match[] = {
|
2019-12-04 04:05:09 +08:00
|
|
|
{ .soc_id = "r8a774a1", .revision = "ES1.[012]", .data = &sdhi_quirks_4tap_nohs400 },
|
2019-06-06 19:35:36 +08:00
|
|
|
{ .soc_id = "r8a7795", .revision = "ES1.*", .data = &sdhi_quirks_4tap_nohs400 },
|
|
|
|
{ .soc_id = "r8a7795", .revision = "ES2.0", .data = &sdhi_quirks_4tap },
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
{ .soc_id = "r8a7795", .revision = "ES3.*", .data = &sdhi_quirks_bad_taps2367 },
|
2019-06-06 19:35:36 +08:00
|
|
|
{ .soc_id = "r8a7796", .revision = "ES1.[012]", .data = &sdhi_quirks_4tap_nohs400 },
|
2020-09-02 16:18:12 +08:00
|
|
|
{ .soc_id = "r8a7796", .revision = "ES1.*", .data = &sdhi_quirks_r8a7796_es13 },
|
mmc: renesas_sdhi: Avoid bad TAP in HS400
With R-Car Gen3, CRC error occue at the following TAPs.
H3, M3W 1.3, M3N... TAP=2,3,6,7
M3W 3.0 ... TAP=1,3,5,7
(Note: for 4tap SoCs, the numbers get divided by 2)
Do not use these TAPs in HS400, and also don't use auto correction but
manual correction.
We check for bad taps in two places:
1) After tuning HS400: Then, we select a neighbouring TAP. One of them
must be good, because there are never three bad taps in a row.
Retuning won't help because we just finished tuning.
2) After a manual correction request: Here, we can't switch to the
requested TAP. But we can retune (if the HS200 tuning was good)
because the environment might have changed since the last tuning.
If not, we stay on the same TAP.
Signed-off-by: Takeshi Saito <takeshi.saito.xv@renesas.com>
[wsa: refactored to match upstream driver, reworded commit msg]
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200423130432.9990-3-wsa+renesas@sang-engineering.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2020-04-23 21:04:32 +08:00
|
|
|
{ .soc_id = "r8a7796", .revision = "ES3.*", .data = &sdhi_quirks_bad_taps1357 },
|
2020-09-02 16:18:12 +08:00
|
|
|
{ .soc_id = "r8a77965", .data = &sdhi_quirks_r8a77965 },
|
2019-06-06 19:35:35 +08:00
|
|
|
{ .soc_id = "r8a77980", .data = &sdhi_quirks_nohs400 },
|
2020-09-02 16:18:12 +08:00
|
|
|
{ .soc_id = "r8a77990", .data = &sdhi_quirks_r8a77990 },
|
2018-11-29 00:18:27 +08:00
|
|
|
{ /* Sentinel. */ },
|
|
|
|
};
|
|
|
|
|
2017-05-10 17:25:30 +08:00
|
|
|
int renesas_sdhi_probe(struct platform_device *pdev,
|
|
|
|
const struct tmio_mmc_dma_ops *dma_ops)
|
2009-10-02 10:22:09 +08:00
|
|
|
{
|
2015-02-24 10:06:43 +08:00
|
|
|
struct tmio_mmc_data *mmd = pdev->dev.platform_data;
|
2018-11-29 00:18:27 +08:00
|
|
|
const struct renesas_sdhi_quirks *quirks = NULL;
|
2017-06-17 00:11:04 +08:00
|
|
|
const struct renesas_sdhi_of_data *of_data;
|
2018-11-29 00:18:27 +08:00
|
|
|
const struct soc_device_attribute *attr;
|
2017-06-17 00:11:04 +08:00
|
|
|
struct tmio_mmc_data *mmc_data;
|
|
|
|
struct tmio_mmc_dma *dma_priv;
|
2011-03-14 16:52:33 +08:00
|
|
|
struct tmio_mmc_host *host;
|
2017-06-17 00:11:04 +08:00
|
|
|
struct renesas_sdhi *priv;
|
2019-10-02 23:29:46 +08:00
|
|
|
int num_irqs, irq, ret, i;
|
2013-11-20 16:30:55 +08:00
|
|
|
struct resource *res;
|
2019-03-19 18:12:59 +08:00
|
|
|
u16 ver;
|
2017-06-17 00:11:04 +08:00
|
|
|
|
|
|
|
of_data = of_device_get_match_data(&pdev->dev);
|
2009-10-02 10:22:09 +08:00
|
|
|
|
2018-11-29 00:18:27 +08:00
|
|
|
attr = soc_device_match(sdhi_quirks_match);
|
|
|
|
if (attr)
|
|
|
|
quirks = attr->data;
|
|
|
|
|
2013-11-20 16:30:55 +08:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-06-17 00:11:04 +08:00
|
|
|
priv = devm_kzalloc(&pdev->dev, sizeof(struct renesas_sdhi),
|
|
|
|
GFP_KERNEL);
|
2016-01-19 18:42:22 +08:00
|
|
|
if (!priv)
|
2009-10-02 10:22:09 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-12-04 04:05:11 +08:00
|
|
|
priv->quirks = quirks;
|
2010-05-20 02:34:16 +08:00
|
|
|
mmc_data = &priv->mmc_data;
|
2013-04-26 23:47:19 +08:00
|
|
|
dma_priv = &priv->dma_priv;
|
2010-05-20 02:34:16 +08:00
|
|
|
|
2013-02-15 23:13:58 +08:00
|
|
|
priv->clk = devm_clk_get(&pdev->dev, NULL);
|
2009-10-02 10:22:09 +08:00
|
|
|
if (IS_ERR(priv->clk)) {
|
|
|
|
ret = PTR_ERR(priv->clk);
|
2012-11-28 17:24:21 +08:00
|
|
|
dev_err(&pdev->dev, "cannot get clock: %d\n", ret);
|
2017-11-25 00:24:38 +08:00
|
|
|
return ret;
|
2009-10-02 10:22:09 +08:00
|
|
|
}
|
|
|
|
|
2017-01-26 04:28:08 +08:00
|
|
|
/*
|
|
|
|
* Some controllers provide a 2nd clock just to run the internal card
|
|
|
|
* detection logic. Unfortunately, the existing driver architecture does
|
|
|
|
* not support a separation of clocks for runtime PM usage. When
|
|
|
|
* native hotplug is used, the tmio driver assumes that the core
|
|
|
|
* must continue to run for card detect to stay active, so we cannot
|
|
|
|
* disable it.
|
|
|
|
* Additionally, it is prohibited to supply a clock to the core but not
|
|
|
|
* to the card detect circuit. That leaves us with if separate clocks
|
|
|
|
* are presented, we must treat them both as virtually 1 clock.
|
|
|
|
*/
|
|
|
|
priv->clk_cd = devm_clk_get(&pdev->dev, "cd");
|
|
|
|
if (IS_ERR(priv->clk_cd))
|
|
|
|
priv->clk_cd = NULL;
|
|
|
|
|
2016-04-01 23:44:37 +08:00
|
|
|
priv->pinctrl = devm_pinctrl_get(&pdev->dev);
|
|
|
|
if (!IS_ERR(priv->pinctrl)) {
|
|
|
|
priv->pins_default = pinctrl_lookup_state(priv->pinctrl,
|
|
|
|
PINCTRL_STATE_DEFAULT);
|
|
|
|
priv->pins_uhs = pinctrl_lookup_state(priv->pinctrl,
|
|
|
|
"state_uhs");
|
|
|
|
}
|
|
|
|
|
2018-01-18 00:28:02 +08:00
|
|
|
host = tmio_mmc_host_alloc(pdev, mmc_data);
|
2018-01-18 00:28:01 +08:00
|
|
|
if (IS_ERR(host))
|
|
|
|
return PTR_ERR(host);
|
2015-01-13 12:57:22 +08:00
|
|
|
|
2016-12-13 03:51:20 +08:00
|
|
|
if (of_data) {
|
2016-02-15 23:01:48 +08:00
|
|
|
mmc_data->flags |= of_data->tmio_flags;
|
2016-09-12 22:15:05 +08:00
|
|
|
mmc_data->ocr_mask = of_data->tmio_ocr_mask;
|
2016-02-15 23:01:48 +08:00
|
|
|
mmc_data->capabilities |= of_data->capabilities;
|
|
|
|
mmc_data->capabilities2 |= of_data->capabilities2;
|
|
|
|
mmc_data->dma_rx_offset = of_data->dma_rx_offset;
|
2017-06-21 22:00:27 +08:00
|
|
|
mmc_data->max_blk_count = of_data->max_blk_count;
|
|
|
|
mmc_data->max_segs = of_data->max_segs;
|
2016-02-15 23:01:48 +08:00
|
|
|
dma_priv->dma_buswidth = of_data->dma_buswidth;
|
|
|
|
host->bus_shift = of_data->bus_shift;
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:25:29 +08:00
|
|
|
host->write16_hook = renesas_sdhi_write16_hook;
|
|
|
|
host->clk_enable = renesas_sdhi_clk_enable;
|
|
|
|
host->clk_disable = renesas_sdhi_clk_disable;
|
2018-08-23 12:44:16 +08:00
|
|
|
host->set_clock = renesas_sdhi_set_clock;
|
2017-05-10 17:25:29 +08:00
|
|
|
host->multi_io_quirk = renesas_sdhi_multi_io_quirk;
|
2018-01-18 00:28:04 +08:00
|
|
|
host->dma_ops = dma_ops;
|
2016-08-24 17:34:38 +08:00
|
|
|
|
2018-11-29 00:18:29 +08:00
|
|
|
if (quirks && quirks->hs400_disabled)
|
|
|
|
host->mmc->caps2 &= ~(MMC_CAP2_HS400 | MMC_CAP2_HS400_ES);
|
|
|
|
|
2018-06-01 19:00:37 +08:00
|
|
|
/* For some SoC, we disable internal WP. GPIO may override this */
|
|
|
|
if (mmc_can_gpio_ro(host->mmc))
|
|
|
|
mmc_data->capabilities2 &= ~MMC_CAP2_NO_WRITE_PROTECT;
|
|
|
|
|
2016-08-24 17:34:38 +08:00
|
|
|
/* SDR speeds are only available on Gen2+ */
|
|
|
|
if (mmc_data->flags & TMIO_MMC_MIN_RCAR2) {
|
|
|
|
/* card_busy caused issues on r8a73a4 (pre-Gen2) CD-less SDHI */
|
2017-11-25 00:24:42 +08:00
|
|
|
host->ops.card_busy = renesas_sdhi_card_busy;
|
|
|
|
host->ops.start_signal_voltage_switch =
|
2017-05-10 17:25:29 +08:00
|
|
|
renesas_sdhi_start_signal_voltage_switch;
|
2018-11-19 21:13:57 +08:00
|
|
|
host->sdcard_irq_setbit_mask = TMIO_STAT_ALWAYS_SET_27;
|
2020-11-10 22:20:57 +08:00
|
|
|
host->reset = renesas_sdhi_reset;
|
2016-08-24 17:34:38 +08:00
|
|
|
}
|
2016-02-15 23:01:48 +08:00
|
|
|
|
|
|
|
/* Orginally registers were 16 bit apart, could be 32 or 64 nowadays */
|
|
|
|
if (!host->bus_shift && resource_size(res) > 0x100) /* old way to determine the shift */
|
2015-01-13 12:59:33 +08:00
|
|
|
host->bus_shift = 1;
|
2015-01-13 12:57:33 +08:00
|
|
|
|
2015-02-24 10:07:07 +08:00
|
|
|
if (mmd)
|
2015-02-24 10:06:43 +08:00
|
|
|
*mmc_data = *mmd;
|
2015-02-24 10:07:07 +08:00
|
|
|
|
2013-04-26 23:47:19 +08:00
|
|
|
dma_priv->filter = shdma_chan_filter;
|
2017-05-10 17:25:29 +08:00
|
|
|
dma_priv->enable = renesas_sdhi_enable_dma;
|
2013-04-26 23:47:19 +08:00
|
|
|
|
2015-01-13 12:58:46 +08:00
|
|
|
mmc_data->alignment_shift = 1; /* 2-byte alignment */
|
2015-02-24 10:06:43 +08:00
|
|
|
mmc_data->capabilities |= MMC_CAP_MMC_HIGHSPEED;
|
2015-01-13 12:58:46 +08:00
|
|
|
|
2010-08-30 18:50:19 +08:00
|
|
|
/*
|
|
|
|
* All SDHI blocks support 2-byte and larger block sizes in 4-bit
|
|
|
|
* bus width mode.
|
|
|
|
*/
|
|
|
|
mmc_data->flags |= TMIO_MMC_BLKSZ_2BYTES;
|
|
|
|
|
2010-12-29 06:22:32 +08:00
|
|
|
/*
|
|
|
|
* All SDHI blocks support SDIO IRQ signalling.
|
|
|
|
*/
|
|
|
|
mmc_data->flags |= TMIO_MMC_SDIO_IRQ;
|
|
|
|
|
2017-06-17 00:11:04 +08:00
|
|
|
/* All SDHI have CMD12 control bit */
|
2014-08-25 11:00:25 +08:00
|
|
|
mmc_data->flags |= TMIO_MMC_HAVE_CMD12_CTRL;
|
|
|
|
|
2017-01-20 04:07:17 +08:00
|
|
|
/* All SDHI have SDIO status bits which must be 1 */
|
|
|
|
mmc_data->flags |= TMIO_MMC_SDIO_STATUS_SETBITS;
|
2014-08-25 11:00:52 +08:00
|
|
|
|
2020-11-26 05:29:59 +08:00
|
|
|
/* All SDHI support HW busy detection */
|
|
|
|
mmc_data->flags |= TMIO_MMC_USE_BUSY_TIMEOUT;
|
|
|
|
|
2020-05-19 23:24:45 +08:00
|
|
|
dev_pm_domain_start(&pdev->dev);
|
|
|
|
|
2018-01-18 00:28:02 +08:00
|
|
|
ret = renesas_sdhi_clk_enable(host);
|
|
|
|
if (ret)
|
2015-01-13 12:57:22 +08:00
|
|
|
goto efree;
|
2009-10-02 10:22:09 +08:00
|
|
|
|
2019-03-19 18:12:59 +08:00
|
|
|
ver = sd_ctrl_read16(host, CTL_VERSION);
|
|
|
|
/* GEN2_SDR104 is first known SDHI to use 32bit block count */
|
|
|
|
if (ver < SDHI_VER_GEN2_SDR104 && mmc_data->max_blk_count > U16_MAX)
|
|
|
|
mmc_data->max_blk_count = U16_MAX;
|
|
|
|
|
2017-08-10 03:00:41 +08:00
|
|
|
/* One Gen2 SDHI incarnation does NOT have a CBSY bit */
|
2019-03-19 18:12:59 +08:00
|
|
|
if (ver == SDHI_VER_GEN2_SDR50)
|
2017-08-10 03:00:41 +08:00
|
|
|
mmc_data->flags &= ~TMIO_MMC_HAVE_CBSY;
|
|
|
|
|
2020-09-02 16:18:12 +08:00
|
|
|
if (ver == SDHI_VER_GEN3_SDMMC && quirks && quirks->hs400_calib_table) {
|
|
|
|
host->fixup_request = renesas_sdhi_fixup_request;
|
|
|
|
priv->adjust_hs400_calib_table = *(
|
|
|
|
res->start == SDHI_GEN3_MMC0_ADDR ?
|
|
|
|
quirks->hs400_calib_table :
|
|
|
|
quirks->hs400_calib_table + 1);
|
|
|
|
}
|
|
|
|
|
2020-11-26 05:30:01 +08:00
|
|
|
/* these have an EXTOP bit */
|
|
|
|
if (ver >= SDHI_VER_GEN3_SD)
|
|
|
|
host->get_timeout_cycles = renesas_sdhi_gen3_get_cycles;
|
|
|
|
|
2016-12-13 03:51:22 +08:00
|
|
|
/* Enable tuning iff we have an SCC and a supported mode */
|
2016-12-13 03:51:26 +08:00
|
|
|
if (of_data && of_data->scc_offset &&
|
|
|
|
(host->mmc->caps & MMC_CAP_UHS_SDR104 ||
|
2018-06-18 20:57:51 +08:00
|
|
|
host->mmc->caps2 & (MMC_CAP2_HS200_1_8V_SDR |
|
|
|
|
MMC_CAP2_HS400_1_8V))) {
|
2017-05-10 17:25:29 +08:00
|
|
|
const struct renesas_sdhi_scc *taps = of_data->taps;
|
2019-12-04 04:05:13 +08:00
|
|
|
bool use_4tap = priv->quirks && priv->quirks->hs400_4taps;
|
2016-12-13 03:51:21 +08:00
|
|
|
bool hit = false;
|
|
|
|
|
|
|
|
for (i = 0; i < of_data->taps_num; i++) {
|
|
|
|
if (taps[i].clk_rate == 0 ||
|
|
|
|
taps[i].clk_rate == host->mmc->f_max) {
|
2017-11-25 00:24:49 +08:00
|
|
|
priv->scc_tappos = taps->tap;
|
2019-12-04 04:05:13 +08:00
|
|
|
priv->scc_tappos_hs400 = use_4tap ?
|
|
|
|
taps->tap_hs400_4tap :
|
|
|
|
taps->tap;
|
2016-12-13 03:51:21 +08:00
|
|
|
hit = true;
|
|
|
|
break;
|
2016-11-03 22:16:04 +08:00
|
|
|
}
|
2016-12-13 03:51:21 +08:00
|
|
|
}
|
2016-11-03 22:16:04 +08:00
|
|
|
|
2016-12-13 03:51:21 +08:00
|
|
|
if (!hit)
|
2019-12-04 04:05:10 +08:00
|
|
|
dev_warn(&host->pdev->dev, "Unknown clock rate for tuning\n");
|
2016-11-03 22:16:04 +08:00
|
|
|
|
2020-11-10 22:20:57 +08:00
|
|
|
priv->scc_ctl = host->ctl + of_data->scc_offset;
|
2020-01-30 04:37:06 +08:00
|
|
|
host->check_retune = renesas_sdhi_check_scc_error;
|
2020-08-20 21:25:38 +08:00
|
|
|
host->ops.execute_tuning = renesas_sdhi_execute_tuning;
|
2020-01-30 04:37:09 +08:00
|
|
|
host->ops.prepare_hs400_tuning = renesas_sdhi_prepare_hs400_tuning;
|
|
|
|
host->ops.hs400_downgrade = renesas_sdhi_disable_scc;
|
|
|
|
host->ops.hs400_complete = renesas_sdhi_hs400_complete;
|
2016-11-03 22:16:04 +08:00
|
|
|
}
|
|
|
|
|
2020-11-10 22:20:56 +08:00
|
|
|
ret = tmio_mmc_host_probe(host);
|
|
|
|
if (ret < 0)
|
|
|
|
goto edisclk;
|
|
|
|
|
2019-10-02 23:29:46 +08:00
|
|
|
num_irqs = platform_irq_count(pdev);
|
|
|
|
if (num_irqs < 0) {
|
|
|
|
ret = num_irqs;
|
|
|
|
goto eirq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There must be at least one IRQ source */
|
|
|
|
if (!num_irqs) {
|
|
|
|
ret = -ENXIO;
|
|
|
|
goto eirq;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < num_irqs; i++) {
|
2016-04-26 23:55:23 +08:00
|
|
|
irq = platform_get_irq(pdev, i);
|
2019-10-02 23:29:46 +08:00
|
|
|
if (irq < 0) {
|
|
|
|
ret = irq;
|
|
|
|
goto eirq;
|
|
|
|
}
|
|
|
|
|
2016-04-26 23:55:23 +08:00
|
|
|
ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq, 0,
|
2017-06-17 00:11:04 +08:00
|
|
|
dev_name(&pdev->dev), host);
|
2011-08-26 16:42:39 +08:00
|
|
|
if (ret)
|
2013-02-15 23:13:58 +08:00
|
|
|
goto eirq;
|
2011-08-26 16:42:39 +08:00
|
|
|
}
|
|
|
|
|
2020-04-08 22:22:52 +08:00
|
|
|
dev_info(&pdev->dev, "%s base at %pa, max clock rate %u MHz\n",
|
|
|
|
mmc_hostname(host->mmc), &res->start, host->mmc->f_max / 1000000);
|
2009-10-02 10:22:09 +08:00
|
|
|
|
2011-03-14 16:52:33 +08:00
|
|
|
return ret;
|
2009-10-02 10:22:09 +08:00
|
|
|
|
2013-02-15 23:13:58 +08:00
|
|
|
eirq:
|
2011-05-06 19:02:33 +08:00
|
|
|
tmio_mmc_host_remove(host);
|
2018-01-18 00:28:02 +08:00
|
|
|
edisclk:
|
|
|
|
renesas_sdhi_clk_disable(host);
|
2015-01-13 12:57:22 +08:00
|
|
|
efree:
|
|
|
|
tmio_mmc_host_free(host);
|
2017-11-25 00:24:38 +08:00
|
|
|
|
2009-10-02 10:22:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2017-05-10 17:25:30 +08:00
|
|
|
EXPORT_SYMBOL_GPL(renesas_sdhi_probe);
|
2009-10-02 10:22:09 +08:00
|
|
|
|
2017-05-10 17:25:30 +08:00
|
|
|
int renesas_sdhi_remove(struct platform_device *pdev)
|
2009-10-02 10:22:09 +08:00
|
|
|
{
|
2017-11-25 00:24:39 +08:00
|
|
|
struct tmio_mmc_host *host = platform_get_drvdata(pdev);
|
2011-05-06 19:02:45 +08:00
|
|
|
|
2011-05-27 22:54:05 +08:00
|
|
|
tmio_mmc_host_remove(host);
|
2018-01-18 00:28:02 +08:00
|
|
|
renesas_sdhi_clk_disable(host);
|
2020-11-06 17:25:30 +08:00
|
|
|
tmio_mmc_host_free(host);
|
2011-05-27 22:54:05 +08:00
|
|
|
|
2009-10-02 10:22:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-10 17:25:30 +08:00
|
|
|
EXPORT_SYMBOL_GPL(renesas_sdhi_remove);
|
2017-12-13 10:33:00 +08:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL v2");
|