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