blob: 714afd92e303a0f6d187dd19a4cbf2c1104093b8 [file] [log] [blame]
Patrice Chotard2eea7d82017-02-21 13:37:09 +01001/*
2 * Copyright (c) 2017
3 * Patrice Chotard <patrice.chotard@st.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0
6 */
7
8#include <common.h>
9#include <dm.h>
10#include <mmc.h>
11#include <sdhci.h>
12#include <asm/arch/sdhci.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16struct sti_sdhci_plat {
17 struct mmc_config cfg;
18 struct mmc mmc;
Patrice Chotard1b888b82017-09-05 11:04:18 +020019 int instance;
Patrice Chotard2eea7d82017-02-21 13:37:09 +010020};
21
22/*
23 * used to get access to MMC1 reset,
24 * will be removed when STi reset driver will be available
25 */
26#define STIH410_SYSCONF5_BASE 0x092b0000
27
28/**
29 * sti_mmc_core_config: configure the Arasan HC
Patrice Chotard1b888b82017-09-05 11:04:18 +020030 * @dev : udevice
31 *
Patrice Chotard2eea7d82017-02-21 13:37:09 +010032 * Description: this function is to configure the Arasan MMC HC.
33 * This should be called when the system starts in case of, on the SoC,
34 * it is needed to configure the host controller.
35 * This happens on some SoCs, i.e. StiH410, where the MMC0 inside the flashSS
36 * needs to be configured as MMC 4.5 to have full capabilities.
37 * W/o these settings the SDHCI could configure and use the embedded controller
38 * with limited features.
39 */
Patrice Chotard1b888b82017-09-05 11:04:18 +020040static void sti_mmc_core_config(struct udevice *dev)
Patrice Chotard2eea7d82017-02-21 13:37:09 +010041{
Patrice Chotard1b888b82017-09-05 11:04:18 +020042 struct sti_sdhci_plat *plat = dev_get_platdata(dev);
43 struct sdhci_host *host = dev_get_priv(dev);
Patrice Chotard2eea7d82017-02-21 13:37:09 +010044 unsigned long *sysconf;
45
46 /* only MMC1 has a reset line */
Patrice Chotard1b888b82017-09-05 11:04:18 +020047 if (plat->instance) {
Patrice Chotard2eea7d82017-02-21 13:37:09 +010048 sysconf = (unsigned long *)(STIH410_SYSCONF5_BASE +
49 ST_MMC_CCONFIG_REG_5);
50 generic_set_bit(SYSCONF_MMC1_ENABLE_BIT, sysconf);
51 }
52
53 writel(STI_FLASHSS_MMC_CORE_CONFIG_1,
Patrice Chotard1b888b82017-09-05 11:04:18 +020054 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_1);
Patrice Chotard2eea7d82017-02-21 13:37:09 +010055
Patrice Chotard1b888b82017-09-05 11:04:18 +020056 if (plat->instance) {
Patrice Chotard2eea7d82017-02-21 13:37:09 +010057 writel(STI_FLASHSS_MMC_CORE_CONFIG2,
Patrice Chotard1b888b82017-09-05 11:04:18 +020058 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2);
Patrice Chotard2eea7d82017-02-21 13:37:09 +010059 writel(STI_FLASHSS_MMC_CORE_CONFIG3,
Patrice Chotard1b888b82017-09-05 11:04:18 +020060 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3);
Patrice Chotard2eea7d82017-02-21 13:37:09 +010061 } else {
62 writel(STI_FLASHSS_SDCARD_CORE_CONFIG2,
Patrice Chotard1b888b82017-09-05 11:04:18 +020063 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_2);
Patrice Chotard2eea7d82017-02-21 13:37:09 +010064 writel(STI_FLASHSS_SDCARD_CORE_CONFIG3,
Patrice Chotard1b888b82017-09-05 11:04:18 +020065 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_3);
Patrice Chotard2eea7d82017-02-21 13:37:09 +010066 }
67 writel(STI_FLASHSS_MMC_CORE_CONFIG4,
Patrice Chotard1b888b82017-09-05 11:04:18 +020068 host->ioaddr + FLASHSS_MMC_CORE_CONFIG_4);
Patrice Chotard2eea7d82017-02-21 13:37:09 +010069}
70
71static int sti_sdhci_probe(struct udevice *dev)
72{
73 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
74 struct sti_sdhci_plat *plat = dev_get_platdata(dev);
75 struct sdhci_host *host = dev_get_priv(dev);
Patrice Chotard1b888b82017-09-05 11:04:18 +020076 int ret;
Patrice Chotard2eea7d82017-02-21 13:37:09 +010077
78 /*
79 * identify current mmc instance, mmc1 has a reset, not mmc0
80 * MMC0 is wired to the SD slot,
81 * MMC1 is wired on the high speed connector
82 */
83
84 if (fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "resets", NULL))
Patrice Chotard1b888b82017-09-05 11:04:18 +020085 plat->instance = 1;
Patrice Chotard2eea7d82017-02-21 13:37:09 +010086 else
Patrice Chotard1b888b82017-09-05 11:04:18 +020087 plat->instance = 0;
Patrice Chotard2eea7d82017-02-21 13:37:09 +010088
Patrice Chotard1b888b82017-09-05 11:04:18 +020089 sti_mmc_core_config(dev);
Patrice Chotard2eea7d82017-02-21 13:37:09 +010090
91 host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
92 SDHCI_QUIRK_32BIT_DMA_ADDR |
93 SDHCI_QUIRK_NO_HISPD_BIT;
94
95 host->host_caps = MMC_MODE_DDR_52MHz;
96
97 ret = sdhci_setup_cfg(&plat->cfg, host, 50000000, 400000);
98 if (ret)
99 return ret;
100
101 host->mmc = &plat->mmc;
102 host->mmc->priv = host;
103 host->mmc->dev = dev;
104 upriv->mmc = host->mmc;
105
106 return sdhci_probe(dev);
107}
108
109static int sti_sdhci_ofdata_to_platdata(struct udevice *dev)
110{
111 struct sdhci_host *host = dev_get_priv(dev);
112
113 host->name = strdup(dev->name);
Simon Glassba1dea42017-05-17 17:18:05 -0600114 host->ioaddr = (void *)devfdt_get_addr(dev);
Patrice Chotard2eea7d82017-02-21 13:37:09 +0100115
116 host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
117 "bus-width", 4);
118
119 return 0;
120}
121
122static int sti_sdhci_bind(struct udevice *dev)
123{
124 struct sti_sdhci_plat *plat = dev_get_platdata(dev);
125
126 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
127}
128
129static const struct udevice_id sti_sdhci_ids[] = {
130 { .compatible = "st,sdhci" },
131 { }
132};
133
134U_BOOT_DRIVER(sti_mmc) = {
135 .name = "sti_sdhci",
136 .id = UCLASS_MMC,
137 .of_match = sti_sdhci_ids,
138 .bind = sti_sdhci_bind,
139 .ops = &sdhci_ops,
140 .ofdata_to_platdata = sti_sdhci_ofdata_to_platdata,
141 .probe = sti_sdhci_probe,
142 .priv_auto_alloc_size = sizeof(struct sdhci_host),
143 .platdata_auto_alloc_size = sizeof(struct sti_sdhci_plat),
144};