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