Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012 SAMSUNG Electronics |
| 4 | * Jaehoon Chung <jh80.chung@samsung.com> |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 7 | #include <clk.h> |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 8 | #include <dwmmc.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | #include <asm/global_data.h> |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 10 | #include <malloc.h> |
Jaehoon Chung | edd9d1dc | 2016-07-19 16:33:34 +0900 | [diff] [blame] | 11 | #include <errno.h> |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 12 | #include <asm/arch/dwmmc.h> |
| 13 | #include <asm/arch/clk.h> |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 14 | #include <asm/arch/pinmux.h> |
Przemyslaw Marczak | c3885b8 | 2015-02-20 12:29:26 +0100 | [diff] [blame] | 15 | #include <asm/arch/power.h> |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 16 | #include <asm/gpio.h> |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 17 | #include <linux/err.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 18 | #include <linux/printk.h> |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 19 | |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 20 | #define DWMMC_MAX_CH_NUM 4 |
| 21 | #define DWMMC_MAX_FREQ 52000000 |
| 22 | #define DWMMC_MIN_FREQ 400000 |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 23 | #define DWMMC_MMC0_SDR_TIMING_VAL 0x03030001 |
| 24 | #define DWMMC_MMC2_SDR_TIMING_VAL 0x03020001 |
| 25 | |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 26 | #ifdef CONFIG_DM_MMC |
| 27 | #include <dm.h> |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
| 30 | struct exynos_mmc_plat { |
| 31 | struct mmc_config cfg; |
| 32 | struct mmc mmc; |
| 33 | }; |
| 34 | #endif |
| 35 | |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 36 | /* Exynos implmentation specific drver private data */ |
| 37 | struct dwmci_exynos_priv_data { |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 38 | #ifdef CONFIG_DM_MMC |
| 39 | struct dwmci_host host; |
| 40 | #endif |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 41 | struct clk clk; |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 42 | u32 sdr_timing; |
| 43 | }; |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 44 | |
Sam Protsenko | 3192a64 | 2024-08-07 22:14:24 -0500 | [diff] [blame] | 45 | static struct dwmci_exynos_priv_data *exynos_dwmmc_get_priv( |
| 46 | struct dwmci_host *host) |
| 47 | { |
| 48 | #ifdef CONFIG_DM_MMC |
| 49 | return container_of(host, struct dwmci_exynos_priv_data, host); |
| 50 | #else |
| 51 | return host->priv; |
| 52 | #endif |
| 53 | } |
| 54 | |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 55 | /** |
| 56 | * exynos_dwmmc_get_sclk - Get source clock (SDCLKIN) rate |
| 57 | * @host: MMC controller object |
| 58 | * @rate: Will contain clock rate, Hz |
| 59 | * |
| 60 | * Return: 0 on success or negative value on error |
| 61 | */ |
| 62 | static int exynos_dwmmc_get_sclk(struct dwmci_host *host, unsigned long *rate) |
| 63 | { |
| 64 | #ifdef CONFIG_CPU_V7A |
| 65 | *rate = get_mmc_clk(host->dev_index); |
| 66 | #else |
| 67 | struct dwmci_exynos_priv_data *priv = exynos_dwmmc_get_priv(host); |
| 68 | |
| 69 | *rate = clk_get_rate(&priv->clk); |
| 70 | #endif |
| 71 | |
| 72 | if (IS_ERR_VALUE(*rate)) |
| 73 | return *rate; |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * exynos_dwmmc_set_sclk - Set source clock (SDCLKIN) rate |
| 80 | * @host: MMC controller object |
| 81 | * @rate: Desired clock rate, Hz |
| 82 | * |
| 83 | * Return: 0 on success or negative value on error |
| 84 | */ |
| 85 | static int exynos_dwmmc_set_sclk(struct dwmci_host *host, unsigned long rate) |
| 86 | { |
| 87 | int err; |
| 88 | |
| 89 | #ifdef CONFIG_CPU_V7A |
| 90 | unsigned long sclk; |
| 91 | unsigned int div; |
| 92 | |
| 93 | err = exynos_dwmmc_get_sclk(host, &sclk); |
| 94 | if (err) |
| 95 | return err; |
| 96 | |
| 97 | div = DIV_ROUND_UP(sclk, rate); |
| 98 | set_mmc_clk(host->dev_index, div); |
| 99 | #else |
| 100 | struct dwmci_exynos_priv_data *priv = exynos_dwmmc_get_priv(host); |
| 101 | |
| 102 | err = clk_set_rate(&priv->clk, rate); |
| 103 | if (err < 0) |
| 104 | return err; |
| 105 | #endif |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 110 | /* |
| 111 | * Function used as callback function to initialise the |
| 112 | * CLKSEL register for every mmc channel. |
| 113 | */ |
Siew Chin Lim | c51e7e1 | 2020-12-24 18:21:03 +0800 | [diff] [blame] | 114 | static int exynos_dwmci_clksel(struct dwmci_host *host) |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 115 | { |
Sam Protsenko | 3192a64 | 2024-08-07 22:14:24 -0500 | [diff] [blame] | 116 | struct dwmci_exynos_priv_data *priv = exynos_dwmmc_get_priv(host); |
| 117 | |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 118 | dwmci_writel(host, DWMCI_CLKSEL, priv->sdr_timing); |
Siew Chin Lim | c51e7e1 | 2020-12-24 18:21:03 +0800 | [diff] [blame] | 119 | |
| 120 | return 0; |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 121 | } |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 122 | |
Simon Glass | eff7668 | 2015-08-30 16:55:15 -0600 | [diff] [blame] | 123 | unsigned int exynos_dwmci_get_clk(struct dwmci_host *host, uint freq) |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 124 | { |
Rajeshwari S Shinde | ccfa20b | 2014-02-05 10:48:15 +0530 | [diff] [blame] | 125 | unsigned long sclk; |
| 126 | int8_t clk_div; |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 127 | int err; |
Rajeshwari S Shinde | ccfa20b | 2014-02-05 10:48:15 +0530 | [diff] [blame] | 128 | |
| 129 | /* |
| 130 | * Since SDCLKIN is divided inside controller by the DIVRATIO |
| 131 | * value set in the CLKSEL register, we need to use the same output |
| 132 | * clock value to calculate the CLKDIV value. |
| 133 | * as per user manual:cclk_in = SDCLKIN / (DIVRATIO + 1) |
| 134 | */ |
| 135 | clk_div = ((dwmci_readl(host, DWMCI_CLKSEL) >> DWMCI_DIVRATIO_BIT) |
| 136 | & DWMCI_DIVRATIO_MASK) + 1; |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 137 | |
| 138 | err = exynos_dwmmc_get_sclk(host, &sclk); |
| 139 | if (err) { |
| 140 | printf("DWMMC%d: failed to get clock rate (%d)\n", |
| 141 | host->dev_index, err); |
| 142 | return 0; |
| 143 | } |
Rajeshwari S Shinde | ccfa20b | 2014-02-05 10:48:15 +0530 | [diff] [blame] | 144 | |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 145 | /* |
| 146 | * Assume to know divider value. |
| 147 | * When clock unit is broken, need to set "host->div" |
| 148 | */ |
| 149 | return sclk / clk_div / (host->div + 1); |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Jaehoon Chung | 42f81a8 | 2013-11-29 20:08:57 +0900 | [diff] [blame] | 152 | static void exynos_dwmci_board_init(struct dwmci_host *host) |
| 153 | { |
Sam Protsenko | 3192a64 | 2024-08-07 22:14:24 -0500 | [diff] [blame] | 154 | struct dwmci_exynos_priv_data *priv = exynos_dwmmc_get_priv(host); |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 155 | |
Jaehoon Chung | 42f81a8 | 2013-11-29 20:08:57 +0900 | [diff] [blame] | 156 | if (host->quirks & DWMCI_QUIRK_DISABLE_SMU) { |
| 157 | dwmci_writel(host, EMMCP_MPSBEGIN0, 0); |
| 158 | dwmci_writel(host, EMMCP_SEND0, 0); |
| 159 | dwmci_writel(host, EMMCP_CTRL0, |
| 160 | MPSCTRL_SECURE_READ_BIT | |
| 161 | MPSCTRL_SECURE_WRITE_BIT | |
| 162 | MPSCTRL_NON_SECURE_READ_BIT | |
| 163 | MPSCTRL_NON_SECURE_WRITE_BIT | MPSCTRL_VALID); |
| 164 | } |
Jaehoon Chung | 3d12e55 | 2015-02-04 15:48:39 +0900 | [diff] [blame] | 165 | |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 166 | /* Set to timing value at initial time */ |
| 167 | if (priv->sdr_timing) |
Jaehoon Chung | 3d12e55 | 2015-02-04 15:48:39 +0900 | [diff] [blame] | 168 | exynos_dwmci_clksel(host); |
Jaehoon Chung | 42f81a8 | 2013-11-29 20:08:57 +0900 | [diff] [blame] | 169 | } |
| 170 | |
Jaehoon Chung | de61aaee | 2016-06-29 19:46:17 +0900 | [diff] [blame] | 171 | static int exynos_dwmci_core_init(struct dwmci_host *host) |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 172 | { |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 173 | unsigned long freq; |
| 174 | int err; |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 175 | |
| 176 | if (host->bus_hz) |
| 177 | freq = host->bus_hz; |
| 178 | else |
| 179 | freq = DWMMC_MAX_FREQ; |
| 180 | |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 181 | err = exynos_dwmmc_set_sclk(host, freq); |
| 182 | if (err) { |
| 183 | printf("DWMMC%d: failed to set clock rate on probe (%d); " |
| 184 | "continue anyway\n", host->dev_index, err); |
| 185 | } |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 186 | |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 187 | host->name = "EXYNOS DWMMC"; |
Rajeshwari Shinde | 7016309 | 2013-10-29 12:53:13 +0530 | [diff] [blame] | 188 | #ifdef CONFIG_EXYNOS5420 |
| 189 | host->quirks = DWMCI_QUIRK_DISABLE_SMU; |
| 190 | #endif |
Jaehoon Chung | 42f81a8 | 2013-11-29 20:08:57 +0900 | [diff] [blame] | 191 | host->board_init = exynos_dwmci_board_init; |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 192 | |
Jaehoon Chung | ef91dd5 | 2014-05-16 13:59:57 +0900 | [diff] [blame] | 193 | host->caps = MMC_MODE_DDR_52MHz; |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 194 | host->clksel = exynos_dwmci_clksel; |
Jaehoon Chung | d94735b | 2013-10-06 18:59:31 +0900 | [diff] [blame] | 195 | host->get_mmc_clk = exynos_dwmci_get_clk; |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 196 | |
| 197 | #ifndef CONFIG_DM_MMC |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 198 | /* Add the mmc channel to be registered with mmc core */ |
| 199 | if (add_dwmci(host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ)) { |
Jaehoon Chung | de61aaee | 2016-06-29 19:46:17 +0900 | [diff] [blame] | 200 | printf("DWMMC%d registration failed\n", host->dev_index); |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 201 | return -1; |
| 202 | } |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 203 | #endif |
| 204 | |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 205 | return 0; |
| 206 | } |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 207 | |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 208 | static int do_dwmci_init(struct dwmci_host *host) |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 209 | { |
Sam Protsenko | 0e28aa0 | 2024-08-07 22:14:25 -0500 | [diff] [blame] | 210 | #ifdef CONFIG_CPU_V7A |
Jaehoon Chung | de61aaee | 2016-06-29 19:46:17 +0900 | [diff] [blame] | 211 | int flag, err; |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 212 | |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 213 | flag = host->buswidth == 8 ? PINMUX_FLAG_8BIT_MODE : PINMUX_FLAG_NONE; |
| 214 | err = exynos_pinmux_config(host->dev_id, flag); |
| 215 | if (err) { |
Jaehoon Chung | de61aaee | 2016-06-29 19:46:17 +0900 | [diff] [blame] | 216 | printf("DWMMC%d not configure\n", host->dev_index); |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 217 | return err; |
| 218 | } |
Sam Protsenko | 0e28aa0 | 2024-08-07 22:14:25 -0500 | [diff] [blame] | 219 | #endif |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 220 | |
Jaehoon Chung | de61aaee | 2016-06-29 19:46:17 +0900 | [diff] [blame] | 221 | return exynos_dwmci_core_init(host); |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 222 | } |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 223 | |
Sam Protsenko | f78333a | 2024-08-07 22:14:27 -0500 | [diff] [blame] | 224 | #ifdef CONFIG_DM_MMC |
| 225 | static int exynos_dwmmc_of_to_plat(struct udevice *dev) |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 226 | { |
Sam Protsenko | f78333a | 2024-08-07 22:14:27 -0500 | [diff] [blame] | 227 | struct dwmci_exynos_priv_data *priv = dev_get_priv(dev); |
| 228 | struct dwmci_host *host = &priv->host; |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 229 | int err = 0; |
Sam Protsenko | 745edd6 | 2024-08-07 22:14:23 -0500 | [diff] [blame] | 230 | u32 timing[3]; |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 231 | |
Sam Protsenko | 0e28aa0 | 2024-08-07 22:14:25 -0500 | [diff] [blame] | 232 | #ifdef CONFIG_CPU_V7A |
Sam Protsenko | 6002ceb | 2024-08-07 22:14:28 -0500 | [diff] [blame^] | 233 | const void *blob = gd->fdt_blob; |
| 234 | int node = dev_of_offset(dev); |
| 235 | |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 236 | /* Extract device id for each mmc channel */ |
| 237 | host->dev_id = pinmux_decode_periph_id(blob, node); |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 238 | |
Sam Protsenko | 6002ceb | 2024-08-07 22:14:28 -0500 | [diff] [blame^] | 239 | host->dev_index = dev_read_u32_default(dev, "index", host->dev_id); |
Jaehoon Chung | db313bf | 2014-11-28 20:42:33 +0900 | [diff] [blame] | 240 | if (host->dev_index == host->dev_id) |
| 241 | host->dev_index = host->dev_id - PERIPH_ID_SDMMC0; |
| 242 | |
Jaehoon Chung | e0303c7 | 2016-06-29 19:46:16 +0900 | [diff] [blame] | 243 | if (host->dev_index > 4) { |
| 244 | printf("DWMMC%d: Can't get the dev index\n", host->dev_index); |
| 245 | return -EINVAL; |
| 246 | } |
Sam Protsenko | 0e28aa0 | 2024-08-07 22:14:25 -0500 | [diff] [blame] | 247 | #else |
| 248 | if (dev_read_bool(dev, "non-removable")) |
| 249 | host->dev_index = 0; /* eMMC */ |
| 250 | else |
| 251 | host->dev_index = 2; /* SD card */ |
| 252 | #endif |
Jaehoon Chung | e0303c7 | 2016-06-29 19:46:16 +0900 | [diff] [blame] | 253 | |
Jaehoon Chung | 865ecd9 | 2016-06-29 19:46:18 +0900 | [diff] [blame] | 254 | /* Get the bus width from the device node (Default is 4bit buswidth) */ |
Sam Protsenko | 6002ceb | 2024-08-07 22:14:28 -0500 | [diff] [blame^] | 255 | host->buswidth = dev_read_u32_default(dev, "samsung,bus-width", 4); |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 256 | |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 257 | /* Set the base address from the device node */ |
Sam Protsenko | 745edd6 | 2024-08-07 22:14:23 -0500 | [diff] [blame] | 258 | host->ioaddr = dev_read_addr_ptr(dev); |
| 259 | if (!host->ioaddr) { |
Jaehoon Chung | db313bf | 2014-11-28 20:42:33 +0900 | [diff] [blame] | 260 | printf("DWMMC%d: Can't get base address\n", host->dev_index); |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 261 | return -EINVAL; |
| 262 | } |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 263 | |
| 264 | /* Extract the timing info from the node */ |
Sam Protsenko | 6002ceb | 2024-08-07 22:14:28 -0500 | [diff] [blame^] | 265 | err = dev_read_u32_array(dev, "samsung,timing", timing, 3); |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 266 | if (err) { |
Jaehoon Chung | db313bf | 2014-11-28 20:42:33 +0900 | [diff] [blame] | 267 | printf("DWMMC%d: Can't get sdr-timings for devider\n", |
| 268 | host->dev_index); |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 269 | return -EINVAL; |
| 270 | } |
| 271 | |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 272 | priv->sdr_timing = (DWMCI_SET_SAMPLE_CLK(timing[0]) | |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 273 | DWMCI_SET_DRV_CLK(timing[1]) | |
| 274 | DWMCI_SET_DIV_RATIO(timing[2])); |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 275 | |
| 276 | /* sdr_timing didn't assigned anything, use the default value */ |
| 277 | if (!priv->sdr_timing) { |
| 278 | if (host->dev_index == 0) |
| 279 | priv->sdr_timing = DWMMC_MMC0_SDR_TIMING_VAL; |
| 280 | else if (host->dev_index == 2) |
| 281 | priv->sdr_timing = DWMMC_MMC2_SDR_TIMING_VAL; |
| 282 | } |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 283 | |
Sam Protsenko | 751fdf1 | 2024-08-07 22:14:17 -0500 | [diff] [blame] | 284 | host->fifo_depth = dev_read_u32_default(dev, "fifo-depth", 0); |
Sam Protsenko | 6002ceb | 2024-08-07 22:14:28 -0500 | [diff] [blame^] | 285 | host->bus_hz = dev_read_u32_default(dev, "bus_hz", 0); |
| 286 | host->div = dev_read_u32_default(dev, "div", 0); |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 287 | |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 288 | return 0; |
| 289 | } |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 290 | |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 291 | static int exynos_dwmmc_probe(struct udevice *dev) |
| 292 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 293 | struct exynos_mmc_plat *plat = dev_get_plat(dev); |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 294 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 295 | struct dwmci_exynos_priv_data *priv = dev_get_priv(dev); |
| 296 | struct dwmci_host *host = &priv->host; |
| 297 | int err; |
| 298 | |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 299 | #ifndef CONFIG_CPU_V7A |
| 300 | err = clk_get_by_index(dev, 1, &priv->clk); /* ciu */ |
| 301 | if (err) |
| 302 | return err; |
| 303 | #endif |
| 304 | |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 305 | err = do_dwmci_init(host); |
| 306 | if (err) |
| 307 | return err; |
| 308 | |
Jaehoon Chung | bf819d0 | 2016-09-23 19:13:16 +0900 | [diff] [blame] | 309 | dwmci_setup_cfg(&plat->cfg, host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ); |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 310 | host->mmc = &plat->mmc; |
| 311 | host->mmc->priv = &priv->host; |
| 312 | host->priv = dev; |
| 313 | upriv->mmc = host->mmc; |
| 314 | |
| 315 | return dwmci_probe(dev); |
| 316 | } |
| 317 | |
| 318 | static int exynos_dwmmc_bind(struct udevice *dev) |
| 319 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 320 | struct exynos_mmc_plat *plat = dev_get_plat(dev); |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 321 | |
Masahiro Yamada | cdb67f3 | 2016-09-06 22:17:32 +0900 | [diff] [blame] | 322 | return dwmci_bind(dev, &plat->mmc, &plat->cfg); |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | static const struct udevice_id exynos_dwmmc_ids[] = { |
| 326 | { .compatible = "samsung,exynos4412-dw-mshc" }, |
Lukasz Majewski | 03cf3af | 2018-08-01 14:49:00 +0200 | [diff] [blame] | 327 | { .compatible = "samsung,exynos-dwmmc" }, |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 328 | { } |
| 329 | }; |
| 330 | |
| 331 | U_BOOT_DRIVER(exynos_dwmmc_drv) = { |
| 332 | .name = "exynos_dwmmc", |
| 333 | .id = UCLASS_MMC, |
| 334 | .of_match = exynos_dwmmc_ids, |
Sam Protsenko | f78333a | 2024-08-07 22:14:27 -0500 | [diff] [blame] | 335 | .of_to_plat = exynos_dwmmc_of_to_plat, |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 336 | .bind = exynos_dwmmc_bind, |
| 337 | .ops = &dm_dwmci_ops, |
| 338 | .probe = exynos_dwmmc_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 339 | .priv_auto = sizeof(struct dwmci_exynos_priv_data), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 340 | .plat_auto = sizeof(struct exynos_mmc_plat), |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 341 | }; |
| 342 | #endif |