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 | |
Sam Protsenko | 40ad20d | 2024-08-07 22:14:31 -0500 | [diff] [blame] | 26 | #define EXYNOS4412_FIXED_CIU_CLK_DIV 4 |
| 27 | |
Sam Protsenko | 3b26440 | 2024-08-07 22:14:34 -0500 | [diff] [blame] | 28 | /* Quirks */ |
| 29 | #define DWMCI_QUIRK_DISABLE_SMU BIT(0) |
| 30 | |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 31 | #ifdef CONFIG_DM_MMC |
| 32 | #include <dm.h> |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
| 35 | struct exynos_mmc_plat { |
| 36 | struct mmc_config cfg; |
| 37 | struct mmc mmc; |
| 38 | }; |
| 39 | #endif |
| 40 | |
Sam Protsenko | 60b63e4 | 2024-08-07 22:14:30 -0500 | [diff] [blame] | 41 | /* Chip specific data */ |
| 42 | struct exynos_dwmmc_variant { |
| 43 | u32 clksel; /* CLKSEL register offset */ |
Sam Protsenko | 40ad20d | 2024-08-07 22:14:31 -0500 | [diff] [blame] | 44 | u8 div; /* (optional) fixed clock divider value: 0..7 */ |
Sam Protsenko | 3b26440 | 2024-08-07 22:14:34 -0500 | [diff] [blame] | 45 | u32 quirks; /* quirk flags - see DWMCI_QUIRK_... */ |
Sam Protsenko | 60b63e4 | 2024-08-07 22:14:30 -0500 | [diff] [blame] | 46 | }; |
| 47 | |
Sam Protsenko | cda02f1 | 2024-08-07 22:14:41 -0500 | [diff] [blame] | 48 | /* Exynos implementation specific driver private data */ |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 49 | struct dwmci_exynos_priv_data { |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 50 | #ifdef CONFIG_DM_MMC |
| 51 | struct dwmci_host host; |
| 52 | #endif |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 53 | struct clk clk; |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 54 | u32 sdr_timing; |
Sam Protsenko | 4fe61da | 2024-08-07 22:14:35 -0500 | [diff] [blame] | 55 | u32 ddr_timing; |
Sam Protsenko | 60b63e4 | 2024-08-07 22:14:30 -0500 | [diff] [blame] | 56 | const struct exynos_dwmmc_variant *chip; |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 57 | }; |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 58 | |
Sam Protsenko | 3192a64 | 2024-08-07 22:14:24 -0500 | [diff] [blame] | 59 | static struct dwmci_exynos_priv_data *exynos_dwmmc_get_priv( |
| 60 | struct dwmci_host *host) |
| 61 | { |
| 62 | #ifdef CONFIG_DM_MMC |
| 63 | return container_of(host, struct dwmci_exynos_priv_data, host); |
| 64 | #else |
| 65 | return host->priv; |
| 66 | #endif |
| 67 | } |
| 68 | |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 69 | /** |
| 70 | * exynos_dwmmc_get_sclk - Get source clock (SDCLKIN) rate |
| 71 | * @host: MMC controller object |
| 72 | * @rate: Will contain clock rate, Hz |
| 73 | * |
| 74 | * Return: 0 on success or negative value on error |
| 75 | */ |
| 76 | static int exynos_dwmmc_get_sclk(struct dwmci_host *host, unsigned long *rate) |
| 77 | { |
| 78 | #ifdef CONFIG_CPU_V7A |
| 79 | *rate = get_mmc_clk(host->dev_index); |
| 80 | #else |
| 81 | struct dwmci_exynos_priv_data *priv = exynos_dwmmc_get_priv(host); |
| 82 | |
| 83 | *rate = clk_get_rate(&priv->clk); |
| 84 | #endif |
| 85 | |
| 86 | if (IS_ERR_VALUE(*rate)) |
| 87 | return *rate; |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * exynos_dwmmc_set_sclk - Set source clock (SDCLKIN) rate |
| 94 | * @host: MMC controller object |
| 95 | * @rate: Desired clock rate, Hz |
| 96 | * |
| 97 | * Return: 0 on success or negative value on error |
| 98 | */ |
| 99 | static int exynos_dwmmc_set_sclk(struct dwmci_host *host, unsigned long rate) |
| 100 | { |
| 101 | int err; |
| 102 | |
| 103 | #ifdef CONFIG_CPU_V7A |
| 104 | unsigned long sclk; |
| 105 | unsigned int div; |
| 106 | |
| 107 | err = exynos_dwmmc_get_sclk(host, &sclk); |
| 108 | if (err) |
| 109 | return err; |
| 110 | |
| 111 | div = DIV_ROUND_UP(sclk, rate); |
| 112 | set_mmc_clk(host->dev_index, div); |
| 113 | #else |
| 114 | struct dwmci_exynos_priv_data *priv = exynos_dwmmc_get_priv(host); |
| 115 | |
| 116 | err = clk_set_rate(&priv->clk, rate); |
| 117 | if (err < 0) |
| 118 | return err; |
| 119 | #endif |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Sam Protsenko | cda02f1 | 2024-08-07 22:14:41 -0500 | [diff] [blame] | 124 | /* Configure CLKSEL register with chosen timing values */ |
Siew Chin Lim | c51e7e1 | 2020-12-24 18:21:03 +0800 | [diff] [blame] | 125 | static int exynos_dwmci_clksel(struct dwmci_host *host) |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 126 | { |
Sam Protsenko | 3192a64 | 2024-08-07 22:14:24 -0500 | [diff] [blame] | 127 | struct dwmci_exynos_priv_data *priv = exynos_dwmmc_get_priv(host); |
Sam Protsenko | 4fe61da | 2024-08-07 22:14:35 -0500 | [diff] [blame] | 128 | u32 timing; |
Sam Protsenko | 3192a64 | 2024-08-07 22:14:24 -0500 | [diff] [blame] | 129 | |
Sam Protsenko | 4fe61da | 2024-08-07 22:14:35 -0500 | [diff] [blame] | 130 | if (host->mmc->selected_mode == MMC_DDR_52) |
| 131 | timing = priv->ddr_timing; |
| 132 | else |
| 133 | timing = priv->sdr_timing; |
| 134 | |
| 135 | dwmci_writel(host, priv->chip->clksel, timing); |
Siew Chin Lim | c51e7e1 | 2020-12-24 18:21:03 +0800 | [diff] [blame] | 136 | |
| 137 | return 0; |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 138 | } |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 139 | |
Sam Protsenko | 40ad20d | 2024-08-07 22:14:31 -0500 | [diff] [blame] | 140 | /** |
| 141 | * exynos_dwmmc_get_ciu_div - Get internal clock divider value |
| 142 | * @host: MMC controller object |
| 143 | * |
| 144 | * Returns: Divider value, in range of 1..8 |
| 145 | */ |
| 146 | static u8 exynos_dwmmc_get_ciu_div(struct dwmci_host *host) |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 147 | { |
Sam Protsenko | 60b63e4 | 2024-08-07 22:14:30 -0500 | [diff] [blame] | 148 | struct dwmci_exynos_priv_data *priv = exynos_dwmmc_get_priv(host); |
Sam Protsenko | 40ad20d | 2024-08-07 22:14:31 -0500 | [diff] [blame] | 149 | |
| 150 | if (priv->chip->div) |
| 151 | return priv->chip->div + 1; |
Rajeshwari S Shinde | ccfa20b | 2014-02-05 10:48:15 +0530 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * Since SDCLKIN is divided inside controller by the DIVRATIO |
| 155 | * value set in the CLKSEL register, we need to use the same output |
| 156 | * clock value to calculate the CLKDIV value. |
| 157 | * as per user manual:cclk_in = SDCLKIN / (DIVRATIO + 1) |
| 158 | */ |
Sam Protsenko | 40ad20d | 2024-08-07 22:14:31 -0500 | [diff] [blame] | 159 | return ((dwmci_readl(host, priv->chip->clksel) >> DWMCI_DIVRATIO_BIT) |
| 160 | & DWMCI_DIVRATIO_MASK) + 1; |
| 161 | } |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 162 | |
Sam Protsenko | cda02f1 | 2024-08-07 22:14:41 -0500 | [diff] [blame] | 163 | static unsigned int exynos_dwmci_get_clk(struct dwmci_host *host, uint freq) |
Sam Protsenko | 40ad20d | 2024-08-07 22:14:31 -0500 | [diff] [blame] | 164 | { |
| 165 | unsigned long sclk; |
| 166 | u8 clk_div; |
| 167 | int err; |
| 168 | |
Sam Protsenko | f35cd26 | 2024-08-07 22:14:36 -0500 | [diff] [blame] | 169 | /* Should be double rate for DDR mode */ |
| 170 | if (host->mmc->selected_mode == MMC_DDR_52 && host->mmc->bus_width == 8) |
| 171 | freq *= 2; |
| 172 | |
Sam Protsenko | 40ad20d | 2024-08-07 22:14:31 -0500 | [diff] [blame] | 173 | clk_div = exynos_dwmmc_get_ciu_div(host); |
Sam Protsenko | f35cd26 | 2024-08-07 22:14:36 -0500 | [diff] [blame] | 174 | err = exynos_dwmmc_set_sclk(host, freq * clk_div); |
| 175 | if (err) { |
| 176 | printf("DWMMC%d: failed to set clock rate (%d); " |
| 177 | "continue anyway\n", host->dev_index, err); |
| 178 | } |
| 179 | |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 180 | err = exynos_dwmmc_get_sclk(host, &sclk); |
| 181 | if (err) { |
| 182 | printf("DWMMC%d: failed to get clock rate (%d)\n", |
| 183 | host->dev_index, err); |
| 184 | return 0; |
| 185 | } |
Rajeshwari S Shinde | ccfa20b | 2014-02-05 10:48:15 +0530 | [diff] [blame] | 186 | |
Sam Protsenko | 40ad20d | 2024-08-07 22:14:31 -0500 | [diff] [blame] | 187 | return sclk / clk_div; |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Jaehoon Chung | 42f81a8 | 2013-11-29 20:08:57 +0900 | [diff] [blame] | 190 | static void exynos_dwmci_board_init(struct dwmci_host *host) |
| 191 | { |
Sam Protsenko | 3192a64 | 2024-08-07 22:14:24 -0500 | [diff] [blame] | 192 | struct dwmci_exynos_priv_data *priv = exynos_dwmmc_get_priv(host); |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 193 | |
Sam Protsenko | 3b26440 | 2024-08-07 22:14:34 -0500 | [diff] [blame] | 194 | if (priv->chip->quirks & DWMCI_QUIRK_DISABLE_SMU) { |
Jaehoon Chung | 42f81a8 | 2013-11-29 20:08:57 +0900 | [diff] [blame] | 195 | dwmci_writel(host, EMMCP_MPSBEGIN0, 0); |
| 196 | dwmci_writel(host, EMMCP_SEND0, 0); |
| 197 | dwmci_writel(host, EMMCP_CTRL0, |
| 198 | MPSCTRL_SECURE_READ_BIT | |
| 199 | MPSCTRL_SECURE_WRITE_BIT | |
| 200 | MPSCTRL_NON_SECURE_READ_BIT | |
| 201 | MPSCTRL_NON_SECURE_WRITE_BIT | MPSCTRL_VALID); |
| 202 | } |
Jaehoon Chung | 3d12e55 | 2015-02-04 15:48:39 +0900 | [diff] [blame] | 203 | |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 204 | if (priv->sdr_timing) |
Jaehoon Chung | 3d12e55 | 2015-02-04 15:48:39 +0900 | [diff] [blame] | 205 | exynos_dwmci_clksel(host); |
Jaehoon Chung | 42f81a8 | 2013-11-29 20:08:57 +0900 | [diff] [blame] | 206 | } |
| 207 | |
Sam Protsenko | f78333a | 2024-08-07 22:14:27 -0500 | [diff] [blame] | 208 | #ifdef CONFIG_DM_MMC |
| 209 | static int exynos_dwmmc_of_to_plat(struct udevice *dev) |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 210 | { |
Sam Protsenko | f78333a | 2024-08-07 22:14:27 -0500 | [diff] [blame] | 211 | struct dwmci_exynos_priv_data *priv = dev_get_priv(dev); |
| 212 | struct dwmci_host *host = &priv->host; |
Sam Protsenko | bab187c | 2024-08-07 22:14:29 -0500 | [diff] [blame] | 213 | u32 div, timing[2]; |
Sam Protsenko | cda02f1 | 2024-08-07 22:14:41 -0500 | [diff] [blame] | 214 | int err; |
Amar | d850121 | 2013-04-27 11:42:55 +0530 | [diff] [blame] | 215 | |
Sam Protsenko | 60b63e4 | 2024-08-07 22:14:30 -0500 | [diff] [blame] | 216 | priv->chip = (struct exynos_dwmmc_variant *)dev_get_driver_data(dev); |
| 217 | |
Sam Protsenko | 0e28aa0 | 2024-08-07 22:14:25 -0500 | [diff] [blame] | 218 | #ifdef CONFIG_CPU_V7A |
Sam Protsenko | 6002ceb | 2024-08-07 22:14:28 -0500 | [diff] [blame] | 219 | const void *blob = gd->fdt_blob; |
| 220 | int node = dev_of_offset(dev); |
| 221 | |
Sam Protsenko | cda02f1 | 2024-08-07 22:14:41 -0500 | [diff] [blame] | 222 | /* Obtain device ID for current MMC channel */ |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 223 | host->dev_id = pinmux_decode_periph_id(blob, node); |
Sam Protsenko | 6002ceb | 2024-08-07 22:14:28 -0500 | [diff] [blame] | 224 | host->dev_index = dev_read_u32_default(dev, "index", host->dev_id); |
Jaehoon Chung | db313bf | 2014-11-28 20:42:33 +0900 | [diff] [blame] | 225 | if (host->dev_index == host->dev_id) |
| 226 | host->dev_index = host->dev_id - PERIPH_ID_SDMMC0; |
| 227 | |
Jaehoon Chung | e0303c7 | 2016-06-29 19:46:16 +0900 | [diff] [blame] | 228 | if (host->dev_index > 4) { |
| 229 | printf("DWMMC%d: Can't get the dev index\n", host->dev_index); |
| 230 | return -EINVAL; |
| 231 | } |
Sam Protsenko | 0e28aa0 | 2024-08-07 22:14:25 -0500 | [diff] [blame] | 232 | #else |
| 233 | if (dev_read_bool(dev, "non-removable")) |
| 234 | host->dev_index = 0; /* eMMC */ |
| 235 | else |
| 236 | host->dev_index = 2; /* SD card */ |
| 237 | #endif |
Jaehoon Chung | e0303c7 | 2016-06-29 19:46:16 +0900 | [diff] [blame] | 238 | |
Sam Protsenko | 745edd6 | 2024-08-07 22:14:23 -0500 | [diff] [blame] | 239 | host->ioaddr = dev_read_addr_ptr(dev); |
| 240 | if (!host->ioaddr) { |
Jaehoon Chung | db313bf | 2014-11-28 20:42:33 +0900 | [diff] [blame] | 241 | printf("DWMMC%d: Can't get base address\n", host->dev_index); |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 242 | return -EINVAL; |
| 243 | } |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 244 | |
Sam Protsenko | 40ad20d | 2024-08-07 22:14:31 -0500 | [diff] [blame] | 245 | if (priv->chip->div) |
| 246 | div = priv->chip->div; |
| 247 | else |
| 248 | div = dev_read_u32_default(dev, "samsung,dw-mshc-ciu-div", 0); |
Sam Protsenko | cda02f1 | 2024-08-07 22:14:41 -0500 | [diff] [blame] | 249 | |
Sam Protsenko | bab187c | 2024-08-07 22:14:29 -0500 | [diff] [blame] | 250 | err = dev_read_u32_array(dev, "samsung,dw-mshc-sdr-timing", timing, 2); |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 251 | if (err) { |
Sam Protsenko | bab187c | 2024-08-07 22:14:29 -0500 | [diff] [blame] | 252 | printf("DWMMC%d: Can't get sdr-timings\n", host->dev_index); |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 253 | return -EINVAL; |
| 254 | } |
Sam Protsenko | bab187c | 2024-08-07 22:14:29 -0500 | [diff] [blame] | 255 | priv->sdr_timing = DWMCI_SET_SAMPLE_CLK(timing[0]) | |
| 256 | DWMCI_SET_DRV_CLK(timing[1]) | |
| 257 | DWMCI_SET_DIV_RATIO(div); |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 258 | |
Sam Protsenko | cda02f1 | 2024-08-07 22:14:41 -0500 | [diff] [blame] | 259 | /* sdr_timing wasn't set, use the default value */ |
Jaehoon Chung | bcb03eab | 2015-02-04 15:48:40 +0900 | [diff] [blame] | 260 | if (!priv->sdr_timing) { |
| 261 | if (host->dev_index == 0) |
| 262 | priv->sdr_timing = DWMMC_MMC0_SDR_TIMING_VAL; |
| 263 | else if (host->dev_index == 2) |
| 264 | priv->sdr_timing = DWMMC_MMC2_SDR_TIMING_VAL; |
| 265 | } |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 266 | |
Sam Protsenko | 4fe61da | 2024-08-07 22:14:35 -0500 | [diff] [blame] | 267 | err = dev_read_u32_array(dev, "samsung,dw-mshc-ddr-timing", timing, 2); |
| 268 | if (err) { |
| 269 | debug("DWMMC%d: Can't get ddr-timings, using sdr-timings\n", |
| 270 | host->dev_index); |
| 271 | priv->ddr_timing = priv->sdr_timing; |
| 272 | } else { |
| 273 | priv->ddr_timing = DWMCI_SET_SAMPLE_CLK(timing[0]) | |
| 274 | DWMCI_SET_DRV_CLK(timing[1]) | |
| 275 | DWMCI_SET_DIV_RATIO(div); |
| 276 | } |
| 277 | |
Sam Protsenko | cda02f1 | 2024-08-07 22:14:41 -0500 | [diff] [blame] | 278 | host->buswidth = dev_read_u32_default(dev, "bus-width", 4); |
Sam Protsenko | 751fdf1 | 2024-08-07 22:14:17 -0500 | [diff] [blame] | 279 | host->fifo_depth = dev_read_u32_default(dev, "fifo-depth", 0); |
Sam Protsenko | b4dbd28 | 2024-08-07 22:14:33 -0500 | [diff] [blame] | 280 | host->bus_hz = dev_read_u32_default(dev, "clock-frequency", 0); |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 281 | |
Jaehoon Chung | 7aff967 | 2012-10-15 19:10:31 +0000 | [diff] [blame] | 282 | return 0; |
| 283 | } |
Jaehoon Chung | 6281110 | 2014-05-16 13:59:52 +0900 | [diff] [blame] | 284 | |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 285 | static int exynos_dwmmc_probe(struct udevice *dev) |
| 286 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 287 | struct exynos_mmc_plat *plat = dev_get_plat(dev); |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 288 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
| 289 | struct dwmci_exynos_priv_data *priv = dev_get_priv(dev); |
| 290 | struct dwmci_host *host = &priv->host; |
Sam Protsenko | bb875e8 | 2024-08-07 22:14:38 -0500 | [diff] [blame] | 291 | unsigned long freq; |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 292 | int err; |
| 293 | |
Sam Protsenko | 57ddb37 | 2024-08-07 22:14:26 -0500 | [diff] [blame] | 294 | #ifndef CONFIG_CPU_V7A |
| 295 | err = clk_get_by_index(dev, 1, &priv->clk); /* ciu */ |
| 296 | if (err) |
| 297 | return err; |
| 298 | #endif |
| 299 | |
Sam Protsenko | bb875e8 | 2024-08-07 22:14:38 -0500 | [diff] [blame] | 300 | #ifdef CONFIG_CPU_V7A |
| 301 | int flag; |
| 302 | |
| 303 | flag = host->buswidth == 8 ? PINMUX_FLAG_8BIT_MODE : PINMUX_FLAG_NONE; |
| 304 | err = exynos_pinmux_config(host->dev_id, flag); |
| 305 | if (err) { |
| 306 | printf("DWMMC%d not configure\n", host->dev_index); |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 307 | return err; |
Sam Protsenko | bb875e8 | 2024-08-07 22:14:38 -0500 | [diff] [blame] | 308 | } |
| 309 | #endif |
| 310 | |
| 311 | if (host->bus_hz) |
| 312 | freq = host->bus_hz; |
| 313 | else |
| 314 | freq = DWMMC_MAX_FREQ; |
| 315 | |
| 316 | err = exynos_dwmmc_set_sclk(host, freq); |
| 317 | if (err) { |
| 318 | printf("DWMMC%d: failed to set clock rate on probe (%d); " |
| 319 | "continue anyway\n", host->dev_index, err); |
| 320 | } |
| 321 | |
Sam Protsenko | bb28ec5 | 2024-08-07 22:14:40 -0500 | [diff] [blame] | 322 | host->name = dev->name; |
Sam Protsenko | bb875e8 | 2024-08-07 22:14:38 -0500 | [diff] [blame] | 323 | host->board_init = exynos_dwmci_board_init; |
| 324 | host->caps = MMC_MODE_DDR_52MHz; |
| 325 | host->clksel = exynos_dwmci_clksel; |
| 326 | host->get_mmc_clk = exynos_dwmci_get_clk; |
| 327 | |
Sam Protsenko | 9deaa46 | 2024-08-07 22:14:39 -0500 | [diff] [blame] | 328 | #ifdef CONFIG_BLK |
| 329 | dwmci_setup_cfg(&plat->cfg, host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ); |
| 330 | host->mmc = &plat->mmc; |
| 331 | #else |
| 332 | err = add_dwmci(host, DWMMC_MAX_FREQ, DWMMC_MIN_FREQ); |
| 333 | if (err) { |
Sam Protsenko | bb875e8 | 2024-08-07 22:14:38 -0500 | [diff] [blame] | 334 | printf("DWMMC%d registration failed\n", host->dev_index); |
Sam Protsenko | 9deaa46 | 2024-08-07 22:14:39 -0500 | [diff] [blame] | 335 | return err; |
Sam Protsenko | bb875e8 | 2024-08-07 22:14:38 -0500 | [diff] [blame] | 336 | } |
| 337 | #endif |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 338 | |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 339 | host->mmc->priv = &priv->host; |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 340 | upriv->mmc = host->mmc; |
Sam Protsenko | 9deaa46 | 2024-08-07 22:14:39 -0500 | [diff] [blame] | 341 | host->mmc->dev = dev; |
| 342 | host->priv = dev; |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 343 | |
| 344 | return dwmci_probe(dev); |
| 345 | } |
| 346 | |
| 347 | static int exynos_dwmmc_bind(struct udevice *dev) |
| 348 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 349 | struct exynos_mmc_plat *plat = dev_get_plat(dev); |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 350 | |
Masahiro Yamada | cdb67f3 | 2016-09-06 22:17:32 +0900 | [diff] [blame] | 351 | return dwmci_bind(dev, &plat->mmc, &plat->cfg); |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 352 | } |
| 353 | |
Sam Protsenko | 60b63e4 | 2024-08-07 22:14:30 -0500 | [diff] [blame] | 354 | static const struct exynos_dwmmc_variant exynos4_drv_data = { |
| 355 | .clksel = DWMCI_CLKSEL, |
Sam Protsenko | 40ad20d | 2024-08-07 22:14:31 -0500 | [diff] [blame] | 356 | .div = EXYNOS4412_FIXED_CIU_CLK_DIV - 1, |
Sam Protsenko | 60b63e4 | 2024-08-07 22:14:30 -0500 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | static const struct exynos_dwmmc_variant exynos5_drv_data = { |
| 360 | .clksel = DWMCI_CLKSEL, |
Sam Protsenko | 3b26440 | 2024-08-07 22:14:34 -0500 | [diff] [blame] | 361 | #ifdef CONFIG_EXYNOS5420 |
| 362 | .quirks = DWMCI_QUIRK_DISABLE_SMU, |
| 363 | #endif |
Sam Protsenko | 60b63e4 | 2024-08-07 22:14:30 -0500 | [diff] [blame] | 364 | }; |
| 365 | |
Sam Protsenko | af9dcff | 2024-08-07 22:14:37 -0500 | [diff] [blame] | 366 | static const struct exynos_dwmmc_variant exynos7_smu_drv_data = { |
| 367 | .clksel = DWMCI_CLKSEL64, |
| 368 | .quirks = DWMCI_QUIRK_DISABLE_SMU, |
| 369 | }; |
| 370 | |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 371 | static const struct udevice_id exynos_dwmmc_ids[] = { |
Sam Protsenko | 60b63e4 | 2024-08-07 22:14:30 -0500 | [diff] [blame] | 372 | { |
| 373 | .compatible = "samsung,exynos4412-dw-mshc", |
| 374 | .data = (ulong)&exynos4_drv_data, |
| 375 | }, { |
| 376 | .compatible = "samsung,exynos-dwmmc", |
| 377 | .data = (ulong)&exynos5_drv_data, |
Sam Protsenko | af9dcff | 2024-08-07 22:14:37 -0500 | [diff] [blame] | 378 | }, { |
| 379 | .compatible = "samsung,exynos7-dw-mshc-smu", |
| 380 | .data = (ulong)&exynos7_smu_drv_data, |
Sam Protsenko | 60b63e4 | 2024-08-07 22:14:30 -0500 | [diff] [blame] | 381 | }, |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 382 | { } |
| 383 | }; |
| 384 | |
| 385 | U_BOOT_DRIVER(exynos_dwmmc_drv) = { |
| 386 | .name = "exynos_dwmmc", |
| 387 | .id = UCLASS_MMC, |
| 388 | .of_match = exynos_dwmmc_ids, |
Sam Protsenko | f78333a | 2024-08-07 22:14:27 -0500 | [diff] [blame] | 389 | .of_to_plat = exynos_dwmmc_of_to_plat, |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 390 | .bind = exynos_dwmmc_bind, |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 391 | .probe = exynos_dwmmc_probe, |
Sam Protsenko | cda02f1 | 2024-08-07 22:14:41 -0500 | [diff] [blame] | 392 | .ops = &dm_dwmci_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 393 | .priv_auto = sizeof(struct dwmci_exynos_priv_data), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 394 | .plat_auto = sizeof(struct exynos_mmc_plat), |
Jaehoon Chung | 98d18e9 | 2016-06-30 20:57:37 +0900 | [diff] [blame] | 395 | }; |
| 396 | #endif |