2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-09-04 15:56:22 +00:00
|
|
|
/*
|
2017-10-23 07:53:58 +00:00
|
|
|
* Copyright (C) 2017, STMicroelectronics - All Rights Reserved
|
2020-12-02 17:47:30 +00:00
|
|
|
* Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
|
2017-09-04 15:56:22 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
#define LOG_CATEGORY UCLASS_MMC
|
|
|
|
|
2017-09-04 15:56:22 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <clk.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <cpu_func.h>
|
2017-09-04 15:56:22 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <fdtdec.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <asm/bitops.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2020-11-06 18:01:37 +00:00
|
|
|
#include <dm/device_compat.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2017-09-04 15:56:22 +00:00
|
|
|
#include <mmc.h>
|
|
|
|
#include <reset.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/gpio.h>
|
|
|
|
#include <linux/iopoll.h>
|
2019-07-30 17:16:45 +00:00
|
|
|
#include <watchdog.h>
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
struct stm32_sdmmc2_plat {
|
|
|
|
struct mmc_config cfg;
|
|
|
|
struct mmc mmc;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stm32_sdmmc2_priv {
|
|
|
|
fdt_addr_t base;
|
|
|
|
struct clk clk;
|
|
|
|
struct reset_ctl reset_ctl;
|
|
|
|
struct gpio_desc cd_gpio;
|
|
|
|
u32 clk_reg_msk;
|
|
|
|
u32 pwr_reg_msk;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stm32_sdmmc2_ctx {
|
|
|
|
u32 cache_start;
|
|
|
|
u32 cache_end;
|
|
|
|
u32 data_length;
|
|
|
|
bool dpsm_abort;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* SDMMC REGISTERS OFFSET */
|
|
|
|
#define SDMMC_POWER 0x00 /* SDMMC power control */
|
|
|
|
#define SDMMC_CLKCR 0x04 /* SDMMC clock control */
|
|
|
|
#define SDMMC_ARG 0x08 /* SDMMC argument */
|
|
|
|
#define SDMMC_CMD 0x0C /* SDMMC command */
|
|
|
|
#define SDMMC_RESP1 0x14 /* SDMMC response 1 */
|
|
|
|
#define SDMMC_RESP2 0x18 /* SDMMC response 2 */
|
|
|
|
#define SDMMC_RESP3 0x1C /* SDMMC response 3 */
|
|
|
|
#define SDMMC_RESP4 0x20 /* SDMMC response 4 */
|
|
|
|
#define SDMMC_DTIMER 0x24 /* SDMMC data timer */
|
|
|
|
#define SDMMC_DLEN 0x28 /* SDMMC data length */
|
|
|
|
#define SDMMC_DCTRL 0x2C /* SDMMC data control */
|
|
|
|
#define SDMMC_DCOUNT 0x30 /* SDMMC data counter */
|
|
|
|
#define SDMMC_STA 0x34 /* SDMMC status */
|
|
|
|
#define SDMMC_ICR 0x38 /* SDMMC interrupt clear */
|
|
|
|
#define SDMMC_MASK 0x3C /* SDMMC mask */
|
|
|
|
#define SDMMC_IDMACTRL 0x50 /* SDMMC DMA control */
|
|
|
|
#define SDMMC_IDMABASE0 0x58 /* SDMMC DMA buffer 0 base address */
|
|
|
|
|
|
|
|
/* SDMMC_POWER register */
|
2018-06-27 08:15:33 +00:00
|
|
|
#define SDMMC_POWER_PWRCTRL_MASK GENMASK(1, 0)
|
|
|
|
#define SDMMC_POWER_PWRCTRL_OFF 0
|
|
|
|
#define SDMMC_POWER_PWRCTRL_CYCLE 2
|
|
|
|
#define SDMMC_POWER_PWRCTRL_ON 3
|
2017-09-04 15:56:22 +00:00
|
|
|
#define SDMMC_POWER_VSWITCH BIT(2)
|
|
|
|
#define SDMMC_POWER_VSWITCHEN BIT(3)
|
|
|
|
#define SDMMC_POWER_DIRPOL BIT(4)
|
|
|
|
|
|
|
|
/* SDMMC_CLKCR register */
|
|
|
|
#define SDMMC_CLKCR_CLKDIV GENMASK(9, 0)
|
|
|
|
#define SDMMC_CLKCR_CLKDIV_MAX SDMMC_CLKCR_CLKDIV
|
|
|
|
#define SDMMC_CLKCR_PWRSAV BIT(12)
|
|
|
|
#define SDMMC_CLKCR_WIDBUS_4 BIT(14)
|
|
|
|
#define SDMMC_CLKCR_WIDBUS_8 BIT(15)
|
|
|
|
#define SDMMC_CLKCR_NEGEDGE BIT(16)
|
|
|
|
#define SDMMC_CLKCR_HWFC_EN BIT(17)
|
|
|
|
#define SDMMC_CLKCR_DDR BIT(18)
|
|
|
|
#define SDMMC_CLKCR_BUSSPEED BIT(19)
|
2018-02-07 16:19:59 +00:00
|
|
|
#define SDMMC_CLKCR_SELCLKRX_MASK GENMASK(21, 20)
|
|
|
|
#define SDMMC_CLKCR_SELCLKRX_CK 0
|
|
|
|
#define SDMMC_CLKCR_SELCLKRX_CKIN BIT(20)
|
|
|
|
#define SDMMC_CLKCR_SELCLKRX_FBCK BIT(21)
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
/* SDMMC_CMD register */
|
|
|
|
#define SDMMC_CMD_CMDINDEX GENMASK(5, 0)
|
|
|
|
#define SDMMC_CMD_CMDTRANS BIT(6)
|
|
|
|
#define SDMMC_CMD_CMDSTOP BIT(7)
|
|
|
|
#define SDMMC_CMD_WAITRESP GENMASK(9, 8)
|
|
|
|
#define SDMMC_CMD_WAITRESP_0 BIT(8)
|
|
|
|
#define SDMMC_CMD_WAITRESP_1 BIT(9)
|
|
|
|
#define SDMMC_CMD_WAITINT BIT(10)
|
|
|
|
#define SDMMC_CMD_WAITPEND BIT(11)
|
|
|
|
#define SDMMC_CMD_CPSMEN BIT(12)
|
|
|
|
#define SDMMC_CMD_DTHOLD BIT(13)
|
|
|
|
#define SDMMC_CMD_BOOTMODE BIT(14)
|
|
|
|
#define SDMMC_CMD_BOOTEN BIT(15)
|
|
|
|
#define SDMMC_CMD_CMDSUSPEND BIT(16)
|
|
|
|
|
|
|
|
/* SDMMC_DCTRL register */
|
|
|
|
#define SDMMC_DCTRL_DTEN BIT(0)
|
|
|
|
#define SDMMC_DCTRL_DTDIR BIT(1)
|
|
|
|
#define SDMMC_DCTRL_DTMODE GENMASK(3, 2)
|
|
|
|
#define SDMMC_DCTRL_DBLOCKSIZE GENMASK(7, 4)
|
|
|
|
#define SDMMC_DCTRL_DBLOCKSIZE_SHIFT 4
|
|
|
|
#define SDMMC_DCTRL_RWSTART BIT(8)
|
|
|
|
#define SDMMC_DCTRL_RWSTOP BIT(9)
|
|
|
|
#define SDMMC_DCTRL_RWMOD BIT(10)
|
|
|
|
#define SDMMC_DCTRL_SDMMCEN BIT(11)
|
|
|
|
#define SDMMC_DCTRL_BOOTACKEN BIT(12)
|
|
|
|
#define SDMMC_DCTRL_FIFORST BIT(13)
|
|
|
|
|
|
|
|
/* SDMMC_STA register */
|
|
|
|
#define SDMMC_STA_CCRCFAIL BIT(0)
|
|
|
|
#define SDMMC_STA_DCRCFAIL BIT(1)
|
|
|
|
#define SDMMC_STA_CTIMEOUT BIT(2)
|
|
|
|
#define SDMMC_STA_DTIMEOUT BIT(3)
|
|
|
|
#define SDMMC_STA_TXUNDERR BIT(4)
|
|
|
|
#define SDMMC_STA_RXOVERR BIT(5)
|
|
|
|
#define SDMMC_STA_CMDREND BIT(6)
|
|
|
|
#define SDMMC_STA_CMDSENT BIT(7)
|
|
|
|
#define SDMMC_STA_DATAEND BIT(8)
|
|
|
|
#define SDMMC_STA_DHOLD BIT(9)
|
|
|
|
#define SDMMC_STA_DBCKEND BIT(10)
|
|
|
|
#define SDMMC_STA_DABORT BIT(11)
|
|
|
|
#define SDMMC_STA_DPSMACT BIT(12)
|
|
|
|
#define SDMMC_STA_CPSMACT BIT(13)
|
|
|
|
#define SDMMC_STA_TXFIFOHE BIT(14)
|
|
|
|
#define SDMMC_STA_RXFIFOHF BIT(15)
|
|
|
|
#define SDMMC_STA_TXFIFOF BIT(16)
|
|
|
|
#define SDMMC_STA_RXFIFOF BIT(17)
|
|
|
|
#define SDMMC_STA_TXFIFOE BIT(18)
|
|
|
|
#define SDMMC_STA_RXFIFOE BIT(19)
|
|
|
|
#define SDMMC_STA_BUSYD0 BIT(20)
|
|
|
|
#define SDMMC_STA_BUSYD0END BIT(21)
|
|
|
|
#define SDMMC_STA_SDMMCIT BIT(22)
|
|
|
|
#define SDMMC_STA_ACKFAIL BIT(23)
|
|
|
|
#define SDMMC_STA_ACKTIMEOUT BIT(24)
|
|
|
|
#define SDMMC_STA_VSWEND BIT(25)
|
|
|
|
#define SDMMC_STA_CKSTOP BIT(26)
|
|
|
|
#define SDMMC_STA_IDMATE BIT(27)
|
|
|
|
#define SDMMC_STA_IDMABTC BIT(28)
|
|
|
|
|
|
|
|
/* SDMMC_ICR register */
|
|
|
|
#define SDMMC_ICR_CCRCFAILC BIT(0)
|
|
|
|
#define SDMMC_ICR_DCRCFAILC BIT(1)
|
|
|
|
#define SDMMC_ICR_CTIMEOUTC BIT(2)
|
|
|
|
#define SDMMC_ICR_DTIMEOUTC BIT(3)
|
|
|
|
#define SDMMC_ICR_TXUNDERRC BIT(4)
|
|
|
|
#define SDMMC_ICR_RXOVERRC BIT(5)
|
|
|
|
#define SDMMC_ICR_CMDRENDC BIT(6)
|
|
|
|
#define SDMMC_ICR_CMDSENTC BIT(7)
|
|
|
|
#define SDMMC_ICR_DATAENDC BIT(8)
|
|
|
|
#define SDMMC_ICR_DHOLDC BIT(9)
|
|
|
|
#define SDMMC_ICR_DBCKENDC BIT(10)
|
|
|
|
#define SDMMC_ICR_DABORTC BIT(11)
|
|
|
|
#define SDMMC_ICR_BUSYD0ENDC BIT(21)
|
|
|
|
#define SDMMC_ICR_SDMMCITC BIT(22)
|
|
|
|
#define SDMMC_ICR_ACKFAILC BIT(23)
|
|
|
|
#define SDMMC_ICR_ACKTIMEOUTC BIT(24)
|
|
|
|
#define SDMMC_ICR_VSWENDC BIT(25)
|
|
|
|
#define SDMMC_ICR_CKSTOPC BIT(26)
|
|
|
|
#define SDMMC_ICR_IDMATEC BIT(27)
|
|
|
|
#define SDMMC_ICR_IDMABTCC BIT(28)
|
|
|
|
#define SDMMC_ICR_STATIC_FLAGS ((GENMASK(28, 21)) | (GENMASK(11, 0)))
|
|
|
|
|
|
|
|
/* SDMMC_MASK register */
|
|
|
|
#define SDMMC_MASK_CCRCFAILIE BIT(0)
|
|
|
|
#define SDMMC_MASK_DCRCFAILIE BIT(1)
|
|
|
|
#define SDMMC_MASK_CTIMEOUTIE BIT(2)
|
|
|
|
#define SDMMC_MASK_DTIMEOUTIE BIT(3)
|
|
|
|
#define SDMMC_MASK_TXUNDERRIE BIT(4)
|
|
|
|
#define SDMMC_MASK_RXOVERRIE BIT(5)
|
|
|
|
#define SDMMC_MASK_CMDRENDIE BIT(6)
|
|
|
|
#define SDMMC_MASK_CMDSENTIE BIT(7)
|
|
|
|
#define SDMMC_MASK_DATAENDIE BIT(8)
|
|
|
|
#define SDMMC_MASK_DHOLDIE BIT(9)
|
|
|
|
#define SDMMC_MASK_DBCKENDIE BIT(10)
|
|
|
|
#define SDMMC_MASK_DABORTIE BIT(11)
|
|
|
|
#define SDMMC_MASK_TXFIFOHEIE BIT(14)
|
|
|
|
#define SDMMC_MASK_RXFIFOHFIE BIT(15)
|
|
|
|
#define SDMMC_MASK_RXFIFOFIE BIT(17)
|
|
|
|
#define SDMMC_MASK_TXFIFOEIE BIT(18)
|
|
|
|
#define SDMMC_MASK_BUSYD0ENDIE BIT(21)
|
|
|
|
#define SDMMC_MASK_SDMMCITIE BIT(22)
|
|
|
|
#define SDMMC_MASK_ACKFAILIE BIT(23)
|
|
|
|
#define SDMMC_MASK_ACKTIMEOUTIE BIT(24)
|
|
|
|
#define SDMMC_MASK_VSWENDIE BIT(25)
|
|
|
|
#define SDMMC_MASK_CKSTOPIE BIT(26)
|
|
|
|
#define SDMMC_MASK_IDMABTCIE BIT(28)
|
|
|
|
|
|
|
|
/* SDMMC_IDMACTRL register */
|
|
|
|
#define SDMMC_IDMACTRL_IDMAEN BIT(0)
|
|
|
|
|
|
|
|
#define SDMMC_CMD_TIMEOUT 0xFFFFFFFF
|
mmc: stm32_sdmmc2: Increase SDMMC_BUSYD0END_TIMEOUT_US
Increase SDMMC_BUSYD0END_TIMEOUT_US from 1s to 2s to
avoid timeout error during blocks erase on some sdcard
Issue seen on Kingston 16GB :
Device: STM32 SDMMC2
Manufacturer ID: 27
OEM: 5048
Name: SD16G
Bus Speed: 50000000
Mode: SD High Speed (50MHz)
card capabilities: widths [4, 1] modes [SD Legacy, SD High Speed (50MHz)]
host capabilities: widths [4, 1] modes [MMC legacy, SD Legacy, MMC High Speed (26MHz), SD High Speed (50MHz), MMC High Speed (52MHz)]
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 14.5 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
Issue reproduced with following command:
STM32MP> mmc erase 0 100000
MMC erase: dev # 0, block # 0, count 1048576 ... mmc erase failed
16384 blocks erased: ERROR
By setting SDMMC_BUSYD0END_TIMEOUT_US at 2 seconds and by adding
time measurement in stm32_sdmmc2_end_cmd() as shown below:
+start = get_timer(0);
/* Polling status register */
ret = readl_poll_timeout(priv->base + SDMMC_STA,
status, status & mask,
SDMMC_BUSYD0END_TIMEOUT_US);
+printf("time = %ld ms\n", get_timer(start));
We get the following trace:
STM32MP> mmc erase 0 100000
MMC erase: dev # 0, block # 0, count 1048576 ...
time = 17 ms
time = 1 ms
time = 1025 ms
time = 54 ms
time = 56 ms
time = 1021 ms
time = 57 ms
time = 56 ms
time = 1020 ms
time = 53 ms
time = 57 ms
time = 1021 ms
time = 53 ms
time = 57 ms
time = 1313 ms
time = 54 ms
time = 56 ms
time = 1026 ms
time = 54 ms
time = 56 ms
time = 1036 ms
time = 54 ms
time = 56 ms
time = 1028 ms
time = 53 ms
time = 56 ms
time = 1027 ms
time = 54 ms
time = 56 ms
time = 1024 ms
time = 54 ms
time = 56 ms
time = 1020 ms
time = 54 ms
time = 57 ms
time = 1023 ms
time = 54 ms
time = 56 ms
time = 1033 ms
time = 53 ms
time = 57 ms
....
time = 53 ms
time = 57 ms
time = 1021 ms
time = 56 ms
time = 56 ms
time = 1026 ms
time = 54 ms
time = 56 ms
1048576 blocks erased: OK
We see that 1 second timeout is not enough, we also see one measurement
up to 1313 ms. Set the timeout to 2 second to keep a security margin.
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
2019-07-22 09:41:10 +00:00
|
|
|
#define SDMMC_BUSYD0END_TIMEOUT_US 2000000
|
2017-09-04 15:56:22 +00:00
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
static void stm32_sdmmc2_start_data(struct udevice *dev,
|
2017-09-04 15:56:22 +00:00
|
|
|
struct mmc_data *data,
|
|
|
|
struct stm32_sdmmc2_ctx *ctx)
|
|
|
|
{
|
2020-11-06 18:01:37 +00:00
|
|
|
struct stm32_sdmmc2_priv *priv = dev_get_priv(dev);
|
2017-09-04 15:56:22 +00:00
|
|
|
u32 data_ctrl, idmabase0;
|
|
|
|
|
|
|
|
/* Configure the SDMMC DPSM (Data Path State Machine) */
|
|
|
|
data_ctrl = (__ilog2(data->blocksize) <<
|
|
|
|
SDMMC_DCTRL_DBLOCKSIZE_SHIFT) &
|
|
|
|
SDMMC_DCTRL_DBLOCKSIZE;
|
|
|
|
|
|
|
|
if (data->flags & MMC_DATA_READ) {
|
|
|
|
data_ctrl |= SDMMC_DCTRL_DTDIR;
|
|
|
|
idmabase0 = (u32)data->dest;
|
|
|
|
} else {
|
|
|
|
idmabase0 = (u32)data->src;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the SDMMC DataLength value */
|
|
|
|
writel(ctx->data_length, priv->base + SDMMC_DLEN);
|
|
|
|
|
|
|
|
/* Write to SDMMC DCTRL */
|
|
|
|
writel(data_ctrl, priv->base + SDMMC_DCTRL);
|
|
|
|
|
|
|
|
/* Cache align */
|
|
|
|
ctx->cache_start = rounddown(idmabase0, ARCH_DMA_MINALIGN);
|
|
|
|
ctx->cache_end = roundup(idmabase0 + ctx->data_length,
|
|
|
|
ARCH_DMA_MINALIGN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush data cache before DMA start (clean and invalidate)
|
|
|
|
* Clean also needed for read
|
|
|
|
* Avoid issue on buffer not cached-aligned
|
|
|
|
*/
|
|
|
|
flush_dcache_range(ctx->cache_start, ctx->cache_end);
|
|
|
|
|
|
|
|
/* Enable internal DMA */
|
|
|
|
writel(idmabase0, priv->base + SDMMC_IDMABASE0);
|
|
|
|
writel(SDMMC_IDMACTRL_IDMAEN, priv->base + SDMMC_IDMACTRL);
|
|
|
|
}
|
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
static void stm32_sdmmc2_start_cmd(struct udevice *dev,
|
2018-12-06 14:58:10 +00:00
|
|
|
struct mmc_cmd *cmd, u32 cmd_param,
|
|
|
|
struct stm32_sdmmc2_ctx *ctx)
|
2017-09-04 15:56:22 +00:00
|
|
|
{
|
2020-11-06 18:01:37 +00:00
|
|
|
struct stm32_sdmmc2_priv *priv = dev_get_priv(dev);
|
2018-12-06 14:58:10 +00:00
|
|
|
u32 timeout = 0;
|
|
|
|
|
2018-05-17 14:53:57 +00:00
|
|
|
if (readl(priv->base + SDMMC_CMD) & SDMMC_CMD_CPSMEN)
|
|
|
|
writel(0, priv->base + SDMMC_CMD);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
cmd_param |= cmd->cmdidx | SDMMC_CMD_CPSMEN;
|
|
|
|
if (cmd->resp_type & MMC_RSP_PRESENT) {
|
|
|
|
if (cmd->resp_type & MMC_RSP_136)
|
|
|
|
cmd_param |= SDMMC_CMD_WAITRESP;
|
|
|
|
else if (cmd->resp_type & MMC_RSP_CRC)
|
|
|
|
cmd_param |= SDMMC_CMD_WAITRESP_0;
|
|
|
|
else
|
|
|
|
cmd_param |= SDMMC_CMD_WAITRESP_1;
|
|
|
|
}
|
|
|
|
|
2018-12-06 14:58:10 +00:00
|
|
|
/*
|
|
|
|
* SDMMC_DTIME must be set in two case:
|
|
|
|
* - on data transfert.
|
|
|
|
* - on busy request.
|
|
|
|
* If not done or too short, the dtimeout flag occurs and DPSM stays
|
|
|
|
* enabled/busy and waits for abort (stop transmission cmd).
|
|
|
|
* Next data command is not possible whereas DPSM is activated.
|
|
|
|
*/
|
|
|
|
if (ctx->data_length) {
|
|
|
|
timeout = SDMMC_CMD_TIMEOUT;
|
|
|
|
} else {
|
|
|
|
writel(0, priv->base + SDMMC_DCTRL);
|
|
|
|
|
|
|
|
if (cmd->resp_type & MMC_RSP_BUSY)
|
|
|
|
timeout = SDMMC_CMD_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the SDMMC Data TimeOut value */
|
|
|
|
writel(timeout, priv->base + SDMMC_DTIMER);
|
|
|
|
|
2017-09-04 15:56:22 +00:00
|
|
|
/* Clear flags */
|
|
|
|
writel(SDMMC_ICR_STATIC_FLAGS, priv->base + SDMMC_ICR);
|
|
|
|
|
|
|
|
/* Set SDMMC argument value */
|
|
|
|
writel(cmd->cmdarg, priv->base + SDMMC_ARG);
|
|
|
|
|
|
|
|
/* Set SDMMC command parameters */
|
|
|
|
writel(cmd_param, priv->base + SDMMC_CMD);
|
|
|
|
}
|
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
static int stm32_sdmmc2_end_cmd(struct udevice *dev,
|
2017-09-04 15:56:22 +00:00
|
|
|
struct mmc_cmd *cmd,
|
|
|
|
struct stm32_sdmmc2_ctx *ctx)
|
|
|
|
{
|
2020-11-06 18:01:37 +00:00
|
|
|
struct stm32_sdmmc2_priv *priv = dev_get_priv(dev);
|
2017-09-04 15:56:22 +00:00
|
|
|
u32 mask = SDMMC_STA_CTIMEOUT;
|
|
|
|
u32 status;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (cmd->resp_type & MMC_RSP_PRESENT) {
|
|
|
|
mask |= SDMMC_STA_CMDREND;
|
|
|
|
if (cmd->resp_type & MMC_RSP_CRC)
|
|
|
|
mask |= SDMMC_STA_CCRCFAIL;
|
|
|
|
} else {
|
|
|
|
mask |= SDMMC_STA_CMDSENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Polling status register */
|
|
|
|
ret = readl_poll_timeout(priv->base + SDMMC_STA, status, status & mask,
|
2017-10-09 15:02:28 +00:00
|
|
|
10000);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
if (ret < 0) {
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "timeout reading SDMMC_STA register\n");
|
2017-09-04 15:56:22 +00:00
|
|
|
ctx->dpsm_abort = true;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check status */
|
|
|
|
if (status & SDMMC_STA_CTIMEOUT) {
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "error SDMMC_STA_CTIMEOUT (0x%x) for cmd %d\n",
|
|
|
|
status, cmd->cmdidx);
|
2017-09-04 15:56:22 +00:00
|
|
|
ctx->dpsm_abort = true;
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & SDMMC_STA_CCRCFAIL && cmd->resp_type & MMC_RSP_CRC) {
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "error SDMMC_STA_CCRCFAIL (0x%x) for cmd %d\n",
|
|
|
|
status, cmd->cmdidx);
|
2017-09-04 15:56:22 +00:00
|
|
|
ctx->dpsm_abort = true;
|
|
|
|
return -EILSEQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & SDMMC_STA_CMDREND && cmd->resp_type & MMC_RSP_PRESENT) {
|
|
|
|
cmd->response[0] = readl(priv->base + SDMMC_RESP1);
|
|
|
|
if (cmd->resp_type & MMC_RSP_136) {
|
|
|
|
cmd->response[1] = readl(priv->base + SDMMC_RESP2);
|
|
|
|
cmd->response[2] = readl(priv->base + SDMMC_RESP3);
|
|
|
|
cmd->response[3] = readl(priv->base + SDMMC_RESP4);
|
|
|
|
}
|
2018-12-06 14:58:10 +00:00
|
|
|
|
|
|
|
/* Wait for BUSYD0END flag if busy status is detected */
|
|
|
|
if (cmd->resp_type & MMC_RSP_BUSY &&
|
|
|
|
status & SDMMC_STA_BUSYD0) {
|
|
|
|
mask = SDMMC_STA_DTIMEOUT | SDMMC_STA_BUSYD0END;
|
|
|
|
|
|
|
|
/* Polling status register */
|
|
|
|
ret = readl_poll_timeout(priv->base + SDMMC_STA,
|
|
|
|
status, status & mask,
|
|
|
|
SDMMC_BUSYD0END_TIMEOUT_US);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "timeout reading SDMMC_STA\n");
|
2018-12-06 14:58:10 +00:00
|
|
|
ctx->dpsm_abort = true;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & SDMMC_STA_DTIMEOUT) {
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev,
|
|
|
|
"error SDMMC_STA_DTIMEOUT (0x%x)\n",
|
|
|
|
status);
|
2018-12-06 14:58:10 +00:00
|
|
|
ctx->dpsm_abort = true;
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
}
|
2017-09-04 15:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
static int stm32_sdmmc2_end_data(struct udevice *dev,
|
2017-09-04 15:56:22 +00:00
|
|
|
struct mmc_cmd *cmd,
|
|
|
|
struct mmc_data *data,
|
|
|
|
struct stm32_sdmmc2_ctx *ctx)
|
|
|
|
{
|
2020-11-06 18:01:37 +00:00
|
|
|
struct stm32_sdmmc2_priv *priv = dev_get_priv(dev);
|
2017-09-04 15:56:22 +00:00
|
|
|
u32 mask = SDMMC_STA_DCRCFAIL | SDMMC_STA_DTIMEOUT |
|
|
|
|
SDMMC_STA_IDMATE | SDMMC_STA_DATAEND;
|
|
|
|
u32 status;
|
|
|
|
|
|
|
|
if (data->flags & MMC_DATA_READ)
|
|
|
|
mask |= SDMMC_STA_RXOVERR;
|
|
|
|
else
|
|
|
|
mask |= SDMMC_STA_TXUNDERR;
|
|
|
|
|
|
|
|
status = readl(priv->base + SDMMC_STA);
|
|
|
|
while (!(status & mask))
|
|
|
|
status = readl(priv->base + SDMMC_STA);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Need invalidate the dcache again to avoid any
|
|
|
|
* cache-refill during the DMA operations (pre-fetching)
|
|
|
|
*/
|
|
|
|
if (data->flags & MMC_DATA_READ)
|
|
|
|
invalidate_dcache_range(ctx->cache_start, ctx->cache_end);
|
|
|
|
|
|
|
|
if (status & SDMMC_STA_DCRCFAIL) {
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "error SDMMC_STA_DCRCFAIL (0x%x) for cmd %d\n",
|
|
|
|
status, cmd->cmdidx);
|
2017-09-04 15:56:22 +00:00
|
|
|
if (readl(priv->base + SDMMC_DCOUNT))
|
|
|
|
ctx->dpsm_abort = true;
|
|
|
|
return -EILSEQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & SDMMC_STA_DTIMEOUT) {
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "error SDMMC_STA_DTIMEOUT (0x%x) for cmd %d\n",
|
|
|
|
status, cmd->cmdidx);
|
2017-09-04 15:56:22 +00:00
|
|
|
ctx->dpsm_abort = true;
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & SDMMC_STA_TXUNDERR) {
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "error SDMMC_STA_TXUNDERR (0x%x) for cmd %d\n",
|
|
|
|
status, cmd->cmdidx);
|
2017-09-04 15:56:22 +00:00
|
|
|
ctx->dpsm_abort = true;
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & SDMMC_STA_RXOVERR) {
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "error SDMMC_STA_RXOVERR (0x%x) for cmd %d\n",
|
|
|
|
status, cmd->cmdidx);
|
2017-09-04 15:56:22 +00:00
|
|
|
ctx->dpsm_abort = true;
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & SDMMC_STA_IDMATE) {
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "error SDMMC_STA_IDMATE (0x%x) for cmd %d\n",
|
|
|
|
status, cmd->cmdidx);
|
2017-09-04 15:56:22 +00:00
|
|
|
ctx->dpsm_abort = true;
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stm32_sdmmc2_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
|
|
|
|
struct mmc_data *data)
|
|
|
|
{
|
|
|
|
struct stm32_sdmmc2_priv *priv = dev_get_priv(dev);
|
|
|
|
struct stm32_sdmmc2_ctx ctx;
|
|
|
|
u32 cmdat = data ? SDMMC_CMD_CMDTRANS : 0;
|
|
|
|
int ret, retry = 3;
|
|
|
|
|
2019-07-30 17:16:45 +00:00
|
|
|
WATCHDOG_RESET();
|
|
|
|
|
2017-09-04 15:56:22 +00:00
|
|
|
retry_cmd:
|
|
|
|
ctx.data_length = 0;
|
|
|
|
ctx.dpsm_abort = false;
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
ctx.data_length = data->blocks * data->blocksize;
|
2020-11-06 18:01:37 +00:00
|
|
|
stm32_sdmmc2_start_data(dev, data, &ctx);
|
2017-09-04 15:56:22 +00:00
|
|
|
}
|
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
stm32_sdmmc2_start_cmd(dev, cmd, cmdat, &ctx);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "send cmd %d data: 0x%x @ 0x%x\n",
|
|
|
|
cmd->cmdidx, data ? ctx.data_length : 0, (unsigned int)data);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
ret = stm32_sdmmc2_end_cmd(dev, cmd, &ctx);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
if (data && !ret)
|
2020-11-06 18:01:37 +00:00
|
|
|
ret = stm32_sdmmc2_end_data(dev, cmd, data, &ctx);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
/* Clear flags */
|
|
|
|
writel(SDMMC_ICR_STATIC_FLAGS, priv->base + SDMMC_ICR);
|
|
|
|
if (data)
|
|
|
|
writel(0x0, priv->base + SDMMC_IDMACTRL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To stop Data Path State Machine, a stop_transmission command
|
|
|
|
* shall be send on cmd or data errors.
|
|
|
|
*/
|
|
|
|
if (ctx.dpsm_abort && (cmd->cmdidx != MMC_CMD_STOP_TRANSMISSION)) {
|
|
|
|
struct mmc_cmd stop_cmd;
|
|
|
|
|
|
|
|
stop_cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
|
|
|
|
stop_cmd.cmdarg = 0;
|
|
|
|
stop_cmd.resp_type = MMC_RSP_R1b;
|
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "send STOP command to abort dpsm treatments\n");
|
2017-09-04 15:56:22 +00:00
|
|
|
|
2018-12-06 14:58:10 +00:00
|
|
|
ctx.data_length = 0;
|
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
stm32_sdmmc2_start_cmd(dev, &stop_cmd,
|
2018-12-06 14:58:10 +00:00
|
|
|
SDMMC_CMD_CMDSTOP, &ctx);
|
2020-11-06 18:01:37 +00:00
|
|
|
stm32_sdmmc2_end_cmd(dev, &stop_cmd, &ctx);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
writel(SDMMC_ICR_STATIC_FLAGS, priv->base + SDMMC_ICR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret != -ETIMEDOUT) && (ret != 0) && retry) {
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_err(dev, "cmd %d failed, retrying ...\n", cmd->cmdidx);
|
2017-09-04 15:56:22 +00:00
|
|
|
retry--;
|
|
|
|
goto retry_cmd;
|
|
|
|
}
|
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "end for CMD %d, ret = %d\n", cmd->cmdidx, ret);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-06-27 08:15:33 +00:00
|
|
|
/*
|
|
|
|
* Reset the SDMMC with the RCC.SDMMCxRST register bit.
|
|
|
|
* This will reset the SDMMC to the reset state and the CPSM and DPSM
|
|
|
|
* to the Idle state. SDMMC is disabled, Signals Hiz.
|
|
|
|
*/
|
|
|
|
static void stm32_sdmmc2_reset(struct stm32_sdmmc2_priv *priv)
|
2017-09-04 15:56:22 +00:00
|
|
|
{
|
|
|
|
/* Reset */
|
|
|
|
reset_assert(&priv->reset_ctl);
|
|
|
|
udelay(2);
|
|
|
|
reset_deassert(&priv->reset_ctl);
|
|
|
|
|
2018-06-27 08:15:33 +00:00
|
|
|
/* init the needed SDMMC register after reset */
|
|
|
|
writel(priv->pwr_reg_msk, priv->base + SDMMC_POWER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the SDMMC in power-cycle state.
|
|
|
|
* This will make that the SDMMC_D[7:0],
|
|
|
|
* SDMMC_CMD and SDMMC_CK are driven low, to prevent the card from being
|
|
|
|
* supplied through the signal lines.
|
|
|
|
*/
|
|
|
|
static void stm32_sdmmc2_pwrcycle(struct stm32_sdmmc2_priv *priv)
|
|
|
|
{
|
|
|
|
if ((readl(priv->base + SDMMC_POWER) & SDMMC_POWER_PWRCTRL_MASK) ==
|
|
|
|
SDMMC_POWER_PWRCTRL_CYCLE)
|
|
|
|
return;
|
2017-09-04 15:56:22 +00:00
|
|
|
|
2018-06-27 08:15:33 +00:00
|
|
|
stm32_sdmmc2_reset(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set the SDMMC state Power-on: the card is clocked
|
|
|
|
* manage the SDMMC state control:
|
|
|
|
* Reset => Power-Cycle => Power-Off => Power
|
|
|
|
* PWRCTRL=10 PWCTRL=00 PWCTRL=11
|
|
|
|
*/
|
|
|
|
static void stm32_sdmmc2_pwron(struct stm32_sdmmc2_priv *priv)
|
|
|
|
{
|
|
|
|
u32 pwrctrl =
|
|
|
|
readl(priv->base + SDMMC_POWER) & SDMMC_POWER_PWRCTRL_MASK;
|
|
|
|
|
|
|
|
if (pwrctrl == SDMMC_POWER_PWRCTRL_ON)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* warning: same PWRCTRL value after reset and for power-off state
|
|
|
|
* it is the reset state here = the only managed by the driver
|
|
|
|
*/
|
|
|
|
if (pwrctrl == SDMMC_POWER_PWRCTRL_OFF) {
|
|
|
|
writel(SDMMC_POWER_PWRCTRL_CYCLE | priv->pwr_reg_msk,
|
|
|
|
priv->base + SDMMC_POWER);
|
|
|
|
}
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
/*
|
2018-06-27 08:15:33 +00:00
|
|
|
* the remaining case is SDMMC_POWER_PWRCTRL_CYCLE
|
|
|
|
* switch to Power-Off state: SDMCC disable, signals drive 1
|
2017-09-04 15:56:22 +00:00
|
|
|
*/
|
2018-06-27 08:15:33 +00:00
|
|
|
writel(SDMMC_POWER_PWRCTRL_OFF | priv->pwr_reg_msk,
|
|
|
|
priv->base + SDMMC_POWER);
|
|
|
|
|
|
|
|
/* After the 1ms delay set the SDMMC to power-on */
|
|
|
|
mdelay(1);
|
|
|
|
writel(SDMMC_POWER_PWRCTRL_ON | priv->pwr_reg_msk,
|
|
|
|
priv->base + SDMMC_POWER);
|
|
|
|
|
|
|
|
/* during the first 74 SDMMC_CK cycles the SDMMC is still disabled. */
|
2017-09-04 15:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define IS_RISING_EDGE(reg) (reg & SDMMC_CLKCR_NEGEDGE ? 0 : 1)
|
|
|
|
static int stm32_sdmmc2_set_ios(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mmc *mmc = mmc_get_mmc_dev(dev);
|
|
|
|
struct stm32_sdmmc2_priv *priv = dev_get_priv(dev);
|
|
|
|
u32 desired = mmc->clock;
|
|
|
|
u32 sys_clock = clk_get_rate(&priv->clk);
|
|
|
|
u32 clk = 0;
|
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "bus_with = %d, clock = %d\n",
|
|
|
|
mmc->bus_width, mmc->clock);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
2018-06-27 08:15:33 +00:00
|
|
|
if (mmc->clk_disable)
|
|
|
|
stm32_sdmmc2_pwrcycle(priv);
|
|
|
|
else
|
2017-09-04 15:56:22 +00:00
|
|
|
stm32_sdmmc2_pwron(priv);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* clk_div = 0 => command and data generated on SDMMCCLK falling edge
|
|
|
|
* clk_div > 0 and NEGEDGE = 0 => command and data generated on
|
|
|
|
* SDMMCCLK rising edge
|
|
|
|
* clk_div > 0 and NEGEDGE = 1 => command and data generated on
|
|
|
|
* SDMMCCLK falling edge
|
|
|
|
*/
|
|
|
|
if (desired && ((sys_clock > desired) ||
|
|
|
|
IS_RISING_EDGE(priv->clk_reg_msk))) {
|
|
|
|
clk = DIV_ROUND_UP(sys_clock, 2 * desired);
|
|
|
|
if (clk > SDMMC_CLKCR_CLKDIV_MAX)
|
|
|
|
clk = SDMMC_CLKCR_CLKDIV_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mmc->bus_width == 4)
|
|
|
|
clk |= SDMMC_CLKCR_WIDBUS_4;
|
|
|
|
if (mmc->bus_width == 8)
|
|
|
|
clk |= SDMMC_CLKCR_WIDBUS_8;
|
|
|
|
|
2018-02-07 16:19:58 +00:00
|
|
|
writel(clk | priv->clk_reg_msk | SDMMC_CLKCR_HWFC_EN,
|
|
|
|
priv->base + SDMMC_CLKCR);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stm32_sdmmc2_getcd(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct stm32_sdmmc2_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2020-11-06 18:01:37 +00:00
|
|
|
dev_dbg(dev, "%s called\n", __func__);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
if (dm_gpio_is_valid(&priv->cd_gpio))
|
|
|
|
return dm_gpio_get_value(&priv->cd_gpio);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:56:13 +00:00
|
|
|
static int stm32_sdmmc2_host_power_cycle(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct stm32_sdmmc2_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
writel(SDMMC_POWER_PWRCTRL_CYCLE | priv->pwr_reg_msk,
|
|
|
|
priv->base + SDMMC_POWER);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-04 15:56:22 +00:00
|
|
|
static const struct dm_mmc_ops stm32_sdmmc2_ops = {
|
|
|
|
.send_cmd = stm32_sdmmc2_send_cmd,
|
|
|
|
.set_ios = stm32_sdmmc2_set_ios,
|
|
|
|
.get_cd = stm32_sdmmc2_getcd,
|
2019-09-19 15:56:13 +00:00
|
|
|
.host_power_cycle = stm32_sdmmc2_host_power_cycle,
|
2017-09-04 15:56:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int stm32_sdmmc2_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
|
2020-12-03 23:55:20 +00:00
|
|
|
struct stm32_sdmmc2_plat *plat = dev_get_plat(dev);
|
2017-09-04 15:56:22 +00:00
|
|
|
struct stm32_sdmmc2_priv *priv = dev_get_priv(dev);
|
|
|
|
struct mmc_config *cfg = &plat->cfg;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
priv->base = dev_read_addr(dev);
|
|
|
|
if (priv->base == FDT_ADDR_T_NONE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2018-11-16 09:25:54 +00:00
|
|
|
if (dev_read_bool(dev, "st,neg-edge"))
|
2017-09-04 15:56:22 +00:00
|
|
|
priv->clk_reg_msk |= SDMMC_CLKCR_NEGEDGE;
|
2018-11-16 09:25:54 +00:00
|
|
|
if (dev_read_bool(dev, "st,sig-dir"))
|
2017-09-04 15:56:22 +00:00
|
|
|
priv->pwr_reg_msk |= SDMMC_POWER_DIRPOL;
|
2018-11-16 09:25:54 +00:00
|
|
|
if (dev_read_bool(dev, "st,use-ckin"))
|
2018-02-07 16:19:59 +00:00
|
|
|
priv->clk_reg_msk |= SDMMC_CLKCR_SELCLKRX_CKIN;
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
ret = clk_get_by_index(dev, 0, &priv->clk);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = clk_enable(&priv->clk);
|
|
|
|
if (ret)
|
|
|
|
goto clk_free;
|
|
|
|
|
|
|
|
ret = reset_get_by_index(dev, 0, &priv->reset_ctl);
|
|
|
|
if (ret)
|
|
|
|
goto clk_disable;
|
|
|
|
|
|
|
|
gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio,
|
|
|
|
GPIOD_IS_IN);
|
|
|
|
|
|
|
|
cfg->f_min = 400000;
|
|
|
|
cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
|
|
|
|
cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
|
2020-04-30 07:52:13 +00:00
|
|
|
cfg->name = "STM32 SD/MMC";
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
cfg->host_caps = 0;
|
2020-09-09 21:54:02 +00:00
|
|
|
cfg->f_max = 52000000;
|
|
|
|
mmc_of_parse(dev, cfg);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
upriv->mmc = &plat->mmc;
|
|
|
|
|
2018-06-27 08:15:33 +00:00
|
|
|
/* SDMMC init */
|
|
|
|
stm32_sdmmc2_reset(priv);
|
2017-09-04 15:56:22 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
clk_disable:
|
|
|
|
clk_disable(&priv->clk);
|
|
|
|
clk_free:
|
|
|
|
clk_free(&priv->clk);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-21 13:26:42 +00:00
|
|
|
static int stm32_sdmmc_bind(struct udevice *dev)
|
2017-09-04 15:56:22 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct stm32_sdmmc2_plat *plat = dev_get_plat(dev);
|
2017-09-04 15:56:22 +00:00
|
|
|
|
|
|
|
return mmc_bind(dev, &plat->mmc, &plat->cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id stm32_sdmmc2_ids[] = {
|
|
|
|
{ .compatible = "st,stm32-sdmmc2" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(stm32_sdmmc2) = {
|
|
|
|
.name = "stm32_sdmmc2",
|
|
|
|
.id = UCLASS_MMC,
|
|
|
|
.of_match = stm32_sdmmc2_ids,
|
|
|
|
.ops = &stm32_sdmmc2_ops,
|
|
|
|
.probe = stm32_sdmmc2_probe,
|
|
|
|
.bind = stm32_sdmmc_bind,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct stm32_sdmmc2_priv),
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct stm32_sdmmc2_plat),
|
2017-09-04 15:56:22 +00:00
|
|
|
};
|