Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Exynos Specific Extensions for Synopsys DW Multimedia Card Interface driver |
| 4 | * |
| 5 | * Copyright (C) 2012, Samsung Electronics Co., Ltd. |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/platform_device.h> |
| 10 | #include <linux/clk.h> |
| 11 | #include <linux/mmc/host.h> |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 12 | #include <linux/mmc/mmc.h> |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 13 | #include <linux/of.h> |
| 14 | #include <linux/of_gpio.h> |
Shawn Lin | cf5237e | 2016-10-12 10:55:55 +0800 | [diff] [blame] | 15 | #include <linux/pm_runtime.h> |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 17 | |
| 18 | #include "dw_mmc.h" |
| 19 | #include "dw_mmc-pltfm.h" |
Seungwon Jeon | 0b5fce4 | 2014-12-22 17:42:04 +0530 | [diff] [blame] | 20 | #include "dw_mmc-exynos.h" |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 21 | |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 22 | /* Variations in Exynos specific dw-mshc controller */ |
| 23 | enum dw_mci_exynos_type { |
| 24 | DW_MCI_TYPE_EXYNOS4210, |
| 25 | DW_MCI_TYPE_EXYNOS4412, |
| 26 | DW_MCI_TYPE_EXYNOS5250, |
Yuvaraj Kumar C D | 00fd041 | 2013-05-24 15:34:32 +0530 | [diff] [blame] | 27 | DW_MCI_TYPE_EXYNOS5420, |
Yuvaraj Kumar C D | 6bce431 | 2013-08-31 00:12:35 +0900 | [diff] [blame] | 28 | DW_MCI_TYPE_EXYNOS5420_SMU, |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 29 | DW_MCI_TYPE_EXYNOS7, |
| 30 | DW_MCI_TYPE_EXYNOS7_SMU, |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 31 | DW_MCI_TYPE_ARTPEC8, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | /* Exynos implementation specific driver private data */ |
| 35 | struct dw_mci_exynos_priv_data { |
| 36 | enum dw_mci_exynos_type ctrl_type; |
| 37 | u8 ciu_div; |
| 38 | u32 sdr_timing; |
| 39 | u32 ddr_timing; |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 40 | u32 hs400_timing; |
| 41 | u32 tuned_sample; |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 42 | u32 cur_speed; |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 43 | u32 dqs_delay; |
| 44 | u32 saved_dqs_en; |
| 45 | u32 saved_strobe_ctrl; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | static struct dw_mci_exynos_compatible { |
| 49 | char *compatible; |
| 50 | enum dw_mci_exynos_type ctrl_type; |
| 51 | } exynos_compat[] = { |
| 52 | { |
| 53 | .compatible = "samsung,exynos4210-dw-mshc", |
| 54 | .ctrl_type = DW_MCI_TYPE_EXYNOS4210, |
| 55 | }, { |
| 56 | .compatible = "samsung,exynos4412-dw-mshc", |
| 57 | .ctrl_type = DW_MCI_TYPE_EXYNOS4412, |
| 58 | }, { |
| 59 | .compatible = "samsung,exynos5250-dw-mshc", |
| 60 | .ctrl_type = DW_MCI_TYPE_EXYNOS5250, |
Yuvaraj Kumar C D | 00fd041 | 2013-05-24 15:34:32 +0530 | [diff] [blame] | 61 | }, { |
| 62 | .compatible = "samsung,exynos5420-dw-mshc", |
| 63 | .ctrl_type = DW_MCI_TYPE_EXYNOS5420, |
Yuvaraj Kumar C D | 6bce431 | 2013-08-31 00:12:35 +0900 | [diff] [blame] | 64 | }, { |
| 65 | .compatible = "samsung,exynos5420-dw-mshc-smu", |
| 66 | .ctrl_type = DW_MCI_TYPE_EXYNOS5420_SMU, |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 67 | }, { |
| 68 | .compatible = "samsung,exynos7-dw-mshc", |
| 69 | .ctrl_type = DW_MCI_TYPE_EXYNOS7, |
| 70 | }, { |
| 71 | .compatible = "samsung,exynos7-dw-mshc-smu", |
| 72 | .ctrl_type = DW_MCI_TYPE_EXYNOS7_SMU, |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 73 | }, { |
| 74 | .compatible = "axis,artpec8-dw-mshc", |
| 75 | .ctrl_type = DW_MCI_TYPE_ARTPEC8, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 76 | }, |
| 77 | }; |
| 78 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 79 | static inline u8 dw_mci_exynos_get_ciu_div(struct dw_mci *host) |
| 80 | { |
| 81 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 82 | |
| 83 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412) |
| 84 | return EXYNOS4412_FIXED_CIU_CLK_DIV; |
| 85 | else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210) |
| 86 | return EXYNOS4210_FIXED_CIU_CLK_DIV; |
| 87 | else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 88 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || |
| 89 | priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 90 | return SDMMC_CLKSEL_GET_DIV(mci_readl(host, CLKSEL64)) + 1; |
| 91 | else |
| 92 | return SDMMC_CLKSEL_GET_DIV(mci_readl(host, CLKSEL)) + 1; |
| 93 | } |
| 94 | |
Jaehoon Chung | 5659eea | 2016-03-31 14:53:18 +0900 | [diff] [blame] | 95 | static void dw_mci_exynos_config_smu(struct dw_mci *host) |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 96 | { |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 97 | struct dw_mci_exynos_priv_data *priv = host->priv; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 98 | |
Jaehoon Chung | 5659eea | 2016-03-31 14:53:18 +0900 | [diff] [blame] | 99 | /* |
| 100 | * If Exynos is provided the Security management, |
| 101 | * set for non-ecryption mode at this time. |
| 102 | */ |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 103 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420_SMU || |
| 104 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) { |
Yuvaraj Kumar C D | 6bce431 | 2013-08-31 00:12:35 +0900 | [diff] [blame] | 105 | mci_writel(host, MPSBEGIN0, 0); |
Seungwon Jeon | 0b5fce4 | 2014-12-22 17:42:04 +0530 | [diff] [blame] | 106 | mci_writel(host, MPSEND0, SDMMC_ENDING_SEC_NR_MAX); |
| 107 | mci_writel(host, MPSCTRL0, SDMMC_MPSCTRL_SECURE_WRITE_BIT | |
| 108 | SDMMC_MPSCTRL_NON_SECURE_READ_BIT | |
| 109 | SDMMC_MPSCTRL_VALID | |
| 110 | SDMMC_MPSCTRL_NON_SECURE_WRITE_BIT); |
Yuvaraj Kumar C D | 6bce431 | 2013-08-31 00:12:35 +0900 | [diff] [blame] | 111 | } |
Jaehoon Chung | 5659eea | 2016-03-31 14:53:18 +0900 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static int dw_mci_exynos_priv_init(struct dw_mci *host) |
| 115 | { |
| 116 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 117 | |
| 118 | dw_mci_exynos_config_smu(host); |
Yuvaraj Kumar C D | 6bce431 | 2013-08-31 00:12:35 +0900 | [diff] [blame] | 119 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 120 | if (priv->ctrl_type >= DW_MCI_TYPE_EXYNOS5420) { |
| 121 | priv->saved_strobe_ctrl = mci_readl(host, HS400_DLINE_CTRL); |
| 122 | priv->saved_dqs_en = mci_readl(host, HS400_DQS_EN); |
| 123 | priv->saved_dqs_en |= AXI_NON_BLOCKING_WR; |
| 124 | mci_writel(host, HS400_DQS_EN, priv->saved_dqs_en); |
| 125 | if (!priv->dqs_delay) |
| 126 | priv->dqs_delay = |
| 127 | DQS_CTRL_GET_RD_DELAY(priv->saved_strobe_ctrl); |
| 128 | } |
| 129 | |
Mårten Lindahl | 1a6fe7b | 2021-12-20 12:30:26 +0100 | [diff] [blame] | 130 | if (priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) { |
| 131 | /* Quirk needed for the ARTPEC-8 SoC */ |
| 132 | host->quirks |= DW_MMC_QUIRK_EXTENDED_TMOUT; |
| 133 | } |
| 134 | |
Seungwon Jeon | a2a1fed | 2014-12-22 17:42:03 +0530 | [diff] [blame] | 135 | host->bus_hz /= (priv->ciu_div + 1); |
| 136 | |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 137 | return 0; |
| 138 | } |
| 139 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 140 | static void dw_mci_exynos_set_clksel_timing(struct dw_mci *host, u32 timing) |
| 141 | { |
| 142 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 143 | u32 clksel; |
| 144 | |
| 145 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 146 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || |
| 147 | priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 148 | clksel = mci_readl(host, CLKSEL64); |
| 149 | else |
| 150 | clksel = mci_readl(host, CLKSEL); |
| 151 | |
| 152 | clksel = (clksel & ~SDMMC_CLKSEL_TIMING_MASK) | timing; |
| 153 | |
| 154 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 155 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || |
| 156 | priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 157 | mci_writel(host, CLKSEL64, clksel); |
| 158 | else |
| 159 | mci_writel(host, CLKSEL, clksel); |
Jaehoon Chung | aaaaeb7 | 2016-01-21 11:01:06 +0900 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * Exynos4412 and Exynos5250 extends the use of CMD register with the |
| 163 | * use of bit 29 (which is reserved on standard MSHC controllers) for |
| 164 | * optionally bypassing the HOLD register for command and data. The |
| 165 | * HOLD register should be bypassed in case there is no phase shift |
| 166 | * applied on CMD/DATA that is sent to the card. |
| 167 | */ |
Jaehoon Chung | 42f989c | 2017-06-05 13:41:34 +0900 | [diff] [blame] | 168 | if (!SDMMC_CLKSEL_GET_DRV_WD3(clksel) && host->slot) |
| 169 | set_bit(DW_MMC_CARD_NO_USE_HOLD, &host->slot->flags); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 170 | } |
| 171 | |
Shawn Lin | cf5237e | 2016-10-12 10:55:55 +0800 | [diff] [blame] | 172 | #ifdef CONFIG_PM |
| 173 | static int dw_mci_exynos_runtime_resume(struct device *dev) |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 174 | { |
| 175 | struct dw_mci *host = dev_get_drvdata(dev); |
Jaehoon Chung | e22842d | 2018-03-09 15:10:21 +0900 | [diff] [blame] | 176 | int ret; |
| 177 | |
| 178 | ret = dw_mci_runtime_resume(dev); |
| 179 | if (ret) |
| 180 | return ret; |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 181 | |
Jaehoon Chung | 5659eea | 2016-03-31 14:53:18 +0900 | [diff] [blame] | 182 | dw_mci_exynos_config_smu(host); |
Jaehoon Chung | e22842d | 2018-03-09 15:10:21 +0900 | [diff] [blame] | 183 | |
| 184 | return ret; |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 185 | } |
Marek Szyprowski | ecf7c7c | 2018-06-12 12:55:23 +0200 | [diff] [blame] | 186 | #endif /* CONFIG_PM */ |
| 187 | |
| 188 | #ifdef CONFIG_PM_SLEEP |
| 189 | /** |
| 190 | * dw_mci_exynos_suspend_noirq - Exynos-specific suspend code |
Lee Jones | 306c59c | 2020-07-01 13:46:55 +0100 | [diff] [blame] | 191 | * @dev: Device to suspend (this device) |
Marek Szyprowski | ecf7c7c | 2018-06-12 12:55:23 +0200 | [diff] [blame] | 192 | * |
| 193 | * This ensures that device will be in runtime active state in |
| 194 | * dw_mci_exynos_resume_noirq after calling pm_runtime_force_resume() |
| 195 | */ |
| 196 | static int dw_mci_exynos_suspend_noirq(struct device *dev) |
| 197 | { |
| 198 | pm_runtime_get_noresume(dev); |
| 199 | return pm_runtime_force_suspend(dev); |
| 200 | } |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 201 | |
| 202 | /** |
| 203 | * dw_mci_exynos_resume_noirq - Exynos-specific resume code |
Lee Jones | 306c59c | 2020-07-01 13:46:55 +0100 | [diff] [blame] | 204 | * @dev: Device to resume (this device) |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 205 | * |
| 206 | * On exynos5420 there is a silicon errata that will sometimes leave the |
| 207 | * WAKEUP_INT bit in the CLKSEL register asserted. This bit is 1 to indicate |
| 208 | * that it fired and we can clear it by writing a 1 back. Clear it to prevent |
| 209 | * interrupts from going off constantly. |
| 210 | * |
| 211 | * We run this code on all exynos variants because it doesn't hurt. |
| 212 | */ |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 213 | static int dw_mci_exynos_resume_noirq(struct device *dev) |
| 214 | { |
| 215 | struct dw_mci *host = dev_get_drvdata(dev); |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 216 | struct dw_mci_exynos_priv_data *priv = host->priv; |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 217 | u32 clksel; |
Marek Szyprowski | ecf7c7c | 2018-06-12 12:55:23 +0200 | [diff] [blame] | 218 | int ret; |
| 219 | |
| 220 | ret = pm_runtime_force_resume(dev); |
| 221 | if (ret) |
| 222 | return ret; |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 223 | |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 224 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 225 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || |
| 226 | priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 227 | clksel = mci_readl(host, CLKSEL64); |
| 228 | else |
| 229 | clksel = mci_readl(host, CLKSEL); |
| 230 | |
| 231 | if (clksel & SDMMC_CLKSEL_WAKEUP_INT) { |
| 232 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 233 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || |
| 234 | priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 235 | mci_writel(host, CLKSEL64, clksel); |
| 236 | else |
| 237 | mci_writel(host, CLKSEL, clksel); |
| 238 | } |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 239 | |
Marek Szyprowski | ecf7c7c | 2018-06-12 12:55:23 +0200 | [diff] [blame] | 240 | pm_runtime_put(dev); |
| 241 | |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 242 | return 0; |
| 243 | } |
Marek Szyprowski | ecf7c7c | 2018-06-12 12:55:23 +0200 | [diff] [blame] | 244 | #endif /* CONFIG_PM_SLEEP */ |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 245 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 246 | static void dw_mci_exynos_config_hs400(struct dw_mci *host, u32 timing) |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 247 | { |
| 248 | struct dw_mci_exynos_priv_data *priv = host->priv; |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 249 | u32 dqs, strobe; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 250 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 251 | /* |
| 252 | * Not supported to configure register |
| 253 | * related to HS400 |
| 254 | */ |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 255 | if ((priv->ctrl_type < DW_MCI_TYPE_EXYNOS5420) || |
| 256 | (priv->ctrl_type == DW_MCI_TYPE_ARTPEC8)) { |
Krzysztof Kozlowski | 941a659 | 2016-07-14 15:22:27 +0200 | [diff] [blame] | 257 | if (timing == MMC_TIMING_MMC_HS400) |
| 258 | dev_warn(host->dev, |
| 259 | "cannot configure HS400, unsupported chipset\n"); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 260 | return; |
Krzysztof Kozlowski | 941a659 | 2016-07-14 15:22:27 +0200 | [diff] [blame] | 261 | } |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 262 | |
| 263 | dqs = priv->saved_dqs_en; |
| 264 | strobe = priv->saved_strobe_ctrl; |
| 265 | |
| 266 | if (timing == MMC_TIMING_MMC_HS400) { |
| 267 | dqs |= DATA_STROBE_EN; |
| 268 | strobe = DQS_CTRL_RD_DELAY(strobe, priv->dqs_delay); |
Anand Moon | 32b64b0 | 2018-09-27 14:07:38 +0000 | [diff] [blame] | 269 | } else if (timing == MMC_TIMING_UHS_SDR104) { |
| 270 | dqs &= 0xffffff00; |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 271 | } else { |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 272 | dqs &= ~DATA_STROBE_EN; |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 273 | } |
| 274 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 275 | mci_writel(host, HS400_DQS_EN, dqs); |
| 276 | mci_writel(host, HS400_DLINE_CTRL, strobe); |
| 277 | } |
| 278 | |
| 279 | static void dw_mci_exynos_adjust_clock(struct dw_mci *host, unsigned int wanted) |
| 280 | { |
| 281 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 282 | unsigned long actual; |
| 283 | u8 div; |
| 284 | int ret; |
Seungwon Jeon | a2a1fed | 2014-12-22 17:42:03 +0530 | [diff] [blame] | 285 | /* |
| 286 | * Don't care if wanted clock is zero or |
| 287 | * ciu clock is unavailable |
| 288 | */ |
| 289 | if (!wanted || IS_ERR(host->ciu_clk)) |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 290 | return; |
| 291 | |
| 292 | /* Guaranteed minimum frequency for cclkin */ |
| 293 | if (wanted < EXYNOS_CCLKIN_MIN) |
| 294 | wanted = EXYNOS_CCLKIN_MIN; |
| 295 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 296 | if (wanted == priv->cur_speed) |
| 297 | return; |
| 298 | |
| 299 | div = dw_mci_exynos_get_ciu_div(host); |
| 300 | ret = clk_set_rate(host->ciu_clk, wanted * div); |
| 301 | if (ret) |
| 302 | dev_warn(host->dev, |
| 303 | "failed to set clk-rate %u error: %d\n", |
| 304 | wanted * div, ret); |
| 305 | actual = clk_get_rate(host->ciu_clk); |
| 306 | host->bus_hz = actual / div; |
| 307 | priv->cur_speed = wanted; |
| 308 | host->current_speed = 0; |
| 309 | } |
| 310 | |
| 311 | static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios) |
| 312 | { |
| 313 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 314 | unsigned int wanted = ios->clock; |
| 315 | u32 timing = ios->timing, clksel; |
| 316 | |
| 317 | switch (timing) { |
| 318 | case MMC_TIMING_MMC_HS400: |
| 319 | /* Update tuned sample timing */ |
| 320 | clksel = SDMMC_CLKSEL_UP_SAMPLE( |
| 321 | priv->hs400_timing, priv->tuned_sample); |
| 322 | wanted <<= 1; |
| 323 | break; |
| 324 | case MMC_TIMING_MMC_DDR52: |
| 325 | clksel = priv->ddr_timing; |
| 326 | /* Should be double rate for DDR mode */ |
| 327 | if (ios->bus_width == MMC_BUS_WIDTH_8) |
| 328 | wanted <<= 1; |
| 329 | break; |
Anand Moon | 32b64b0 | 2018-09-27 14:07:38 +0000 | [diff] [blame] | 330 | case MMC_TIMING_UHS_SDR104: |
| 331 | case MMC_TIMING_UHS_SDR50: |
| 332 | clksel = (priv->sdr_timing & 0xfff8ffff) | |
| 333 | (priv->ciu_div << 16); |
| 334 | break; |
| 335 | case MMC_TIMING_UHS_DDR50: |
| 336 | clksel = (priv->ddr_timing & 0xfff8ffff) | |
| 337 | (priv->ciu_div << 16); |
| 338 | break; |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 339 | default: |
| 340 | clksel = priv->sdr_timing; |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 341 | } |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 342 | |
| 343 | /* Set clock timing for the requested speed mode*/ |
| 344 | dw_mci_exynos_set_clksel_timing(host, clksel); |
| 345 | |
| 346 | /* Configure setting for HS400 */ |
| 347 | dw_mci_exynos_config_hs400(host, timing); |
| 348 | |
| 349 | /* Configure clock rate */ |
| 350 | dw_mci_exynos_adjust_clock(host, wanted); |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static int dw_mci_exynos_parse_dt(struct dw_mci *host) |
| 354 | { |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 355 | struct dw_mci_exynos_priv_data *priv; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 356 | struct device_node *np = host->dev->of_node; |
| 357 | u32 timing[2]; |
| 358 | u32 div = 0; |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 359 | int idx; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 360 | int ret; |
| 361 | |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 362 | priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); |
Beomho Seo | bf3707e | 2014-12-23 21:07:33 +0900 | [diff] [blame] | 363 | if (!priv) |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 364 | return -ENOMEM; |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 365 | |
| 366 | for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) { |
| 367 | if (of_device_is_compatible(np, exynos_compat[idx].compatible)) |
| 368 | priv->ctrl_type = exynos_compat[idx].ctrl_type; |
| 369 | } |
| 370 | |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 371 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412) |
| 372 | priv->ciu_div = EXYNOS4412_FIXED_CIU_CLK_DIV - 1; |
| 373 | else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210) |
| 374 | priv->ciu_div = EXYNOS4210_FIXED_CIU_CLK_DIV - 1; |
| 375 | else { |
| 376 | of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div); |
| 377 | priv->ciu_div = div; |
| 378 | } |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 379 | |
| 380 | ret = of_property_read_u32_array(np, |
| 381 | "samsung,dw-mshc-sdr-timing", timing, 2); |
| 382 | if (ret) |
| 383 | return ret; |
| 384 | |
Yuvaraj Kumar C D | 2d9f0bd | 2013-10-22 14:41:56 +0530 | [diff] [blame] | 385 | priv->sdr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); |
| 386 | |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 387 | ret = of_property_read_u32_array(np, |
| 388 | "samsung,dw-mshc-ddr-timing", timing, 2); |
| 389 | if (ret) |
| 390 | return ret; |
| 391 | |
| 392 | priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 393 | |
| 394 | ret = of_property_read_u32_array(np, |
| 395 | "samsung,dw-mshc-hs400-timing", timing, 2); |
| 396 | if (!ret && of_property_read_u32(np, |
| 397 | "samsung,read-strobe-delay", &priv->dqs_delay)) |
| 398 | dev_dbg(host->dev, |
| 399 | "read-strobe-delay is not found, assuming usage of default value\n"); |
| 400 | |
| 401 | priv->hs400_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], |
| 402 | HS400_FIXED_CIU_CLK_DIV); |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 403 | host->priv = priv; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 407 | static inline u8 dw_mci_exynos_get_clksmpl(struct dw_mci *host) |
| 408 | { |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 409 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 410 | |
| 411 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 412 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || |
| 413 | priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 414 | return SDMMC_CLKSEL_CCLK_SAMPLE(mci_readl(host, CLKSEL64)); |
| 415 | else |
| 416 | return SDMMC_CLKSEL_CCLK_SAMPLE(mci_readl(host, CLKSEL)); |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static inline void dw_mci_exynos_set_clksmpl(struct dw_mci *host, u8 sample) |
| 420 | { |
| 421 | u32 clksel; |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 422 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 423 | |
| 424 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 425 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || |
| 426 | priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 427 | clksel = mci_readl(host, CLKSEL64); |
| 428 | else |
| 429 | clksel = mci_readl(host, CLKSEL); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 430 | clksel = SDMMC_CLKSEL_UP_SAMPLE(clksel, sample); |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 431 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 432 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || |
| 433 | priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 434 | mci_writel(host, CLKSEL64, clksel); |
| 435 | else |
| 436 | mci_writel(host, CLKSEL, clksel); |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static inline u8 dw_mci_exynos_move_next_clksmpl(struct dw_mci *host) |
| 440 | { |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 441 | struct dw_mci_exynos_priv_data *priv = host->priv; |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 442 | u32 clksel; |
| 443 | u8 sample; |
| 444 | |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 445 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 446 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || |
| 447 | priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 448 | clksel = mci_readl(host, CLKSEL64); |
| 449 | else |
| 450 | clksel = mci_readl(host, CLKSEL); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 451 | |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 452 | sample = (clksel + 1) & 0x7; |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 453 | clksel = SDMMC_CLKSEL_UP_SAMPLE(clksel, sample); |
| 454 | |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 455 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 456 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU || |
| 457 | priv->ctrl_type == DW_MCI_TYPE_ARTPEC8) |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 458 | mci_writel(host, CLKSEL64, clksel); |
| 459 | else |
| 460 | mci_writel(host, CLKSEL, clksel); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 461 | |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 462 | return sample; |
| 463 | } |
| 464 | |
Colin Ian King | c3ed028 | 2021-10-27 14:08:12 +0100 | [diff] [blame] | 465 | static s8 dw_mci_exynos_get_best_clksmpl(u8 candidates) |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 466 | { |
| 467 | const u8 iter = 8; |
| 468 | u8 __c; |
| 469 | s8 i, loc = -1; |
| 470 | |
| 471 | for (i = 0; i < iter; i++) { |
Colin Ian King | c3ed028 | 2021-10-27 14:08:12 +0100 | [diff] [blame] | 472 | __c = ror8(candidates, i); |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 473 | if ((__c & 0xc7) == 0xc7) { |
| 474 | loc = i; |
| 475 | goto out; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | for (i = 0; i < iter; i++) { |
Colin Ian King | c3ed028 | 2021-10-27 14:08:12 +0100 | [diff] [blame] | 480 | __c = ror8(candidates, i); |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 481 | if ((__c & 0x83) == 0x83) { |
| 482 | loc = i; |
| 483 | goto out; |
| 484 | } |
| 485 | } |
| 486 | |
Jaehoon Chung | 697542b | 2021-10-22 17:21:06 +0900 | [diff] [blame] | 487 | /* |
| 488 | * If there is no cadiates value, then it needs to return -EIO. |
Colin Ian King | c3ed028 | 2021-10-27 14:08:12 +0100 | [diff] [blame] | 489 | * If there are candidates values and don't find bset clk sample value, |
| 490 | * then use a first candidates clock sample value. |
Jaehoon Chung | 697542b | 2021-10-22 17:21:06 +0900 | [diff] [blame] | 491 | */ |
| 492 | for (i = 0; i < iter; i++) { |
Colin Ian King | c3ed028 | 2021-10-27 14:08:12 +0100 | [diff] [blame] | 493 | __c = ror8(candidates, i); |
Jaehoon Chung | 697542b | 2021-10-22 17:21:06 +0900 | [diff] [blame] | 494 | if ((__c & 0x1) == 0x1) { |
| 495 | loc = i; |
| 496 | goto out; |
| 497 | } |
| 498 | } |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 499 | out: |
| 500 | return loc; |
| 501 | } |
| 502 | |
Chaotian Jing | 9979dbe | 2015-10-27 14:24:28 +0800 | [diff] [blame] | 503 | static int dw_mci_exynos_execute_tuning(struct dw_mci_slot *slot, u32 opcode) |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 504 | { |
| 505 | struct dw_mci *host = slot->host; |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 506 | struct dw_mci_exynos_priv_data *priv = host->priv; |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 507 | struct mmc_host *mmc = slot->mmc; |
Colin Ian King | c3ed028 | 2021-10-27 14:08:12 +0100 | [diff] [blame] | 508 | u8 start_smpl, smpl, candidates = 0; |
Colin Ian King | 479cb7cf | 2020-07-06 17:30:31 +0100 | [diff] [blame] | 509 | s8 found; |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 510 | int ret = 0; |
| 511 | |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 512 | start_smpl = dw_mci_exynos_get_clksmpl(host); |
| 513 | |
| 514 | do { |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 515 | mci_writel(host, TMOUT, ~0); |
| 516 | smpl = dw_mci_exynos_move_next_clksmpl(host); |
| 517 | |
Chaotian Jing | 9979dbe | 2015-10-27 14:24:28 +0800 | [diff] [blame] | 518 | if (!mmc_send_tuning(mmc, opcode, NULL)) |
Colin Ian King | c3ed028 | 2021-10-27 14:08:12 +0100 | [diff] [blame] | 519 | candidates |= (1 << smpl); |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 520 | |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 521 | } while (start_smpl != smpl); |
| 522 | |
Colin Ian King | c3ed028 | 2021-10-27 14:08:12 +0100 | [diff] [blame] | 523 | found = dw_mci_exynos_get_best_clksmpl(candidates); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 524 | if (found >= 0) { |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 525 | dw_mci_exynos_set_clksmpl(host, found); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 526 | priv->tuned_sample = found; |
| 527 | } else { |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 528 | ret = -EIO; |
Jaehoon Chung | 697542b | 2021-10-22 17:21:06 +0900 | [diff] [blame] | 529 | dev_warn(&mmc->class_dev, |
Colin Ian King | c3ed028 | 2021-10-27 14:08:12 +0100 | [diff] [blame] | 530 | "There is no candidates value about clksmpl!\n"); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 531 | } |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 532 | |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 533 | return ret; |
| 534 | } |
| 535 | |
Wu Fengguang | c22f5e1 | 2015-03-05 18:02:54 +0800 | [diff] [blame] | 536 | static int dw_mci_exynos_prepare_hs400_tuning(struct dw_mci *host, |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 537 | struct mmc_ios *ios) |
| 538 | { |
| 539 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 540 | |
| 541 | dw_mci_exynos_set_clksel_timing(host, priv->hs400_timing); |
| 542 | dw_mci_exynos_adjust_clock(host, (ios->clock) << 1); |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
Mårten Lindahl | 25d5417 | 2021-12-20 12:30:25 +0100 | [diff] [blame] | 547 | static void dw_mci_exynos_set_data_timeout(struct dw_mci *host, |
| 548 | unsigned int timeout_ns) |
| 549 | { |
| 550 | u32 clk_div, tmout; |
| 551 | u64 tmp; |
| 552 | unsigned int tmp2; |
| 553 | |
| 554 | clk_div = (mci_readl(host, CLKDIV) & 0xFF) * 2; |
| 555 | if (clk_div == 0) |
| 556 | clk_div = 1; |
| 557 | |
| 558 | tmp = DIV_ROUND_UP_ULL((u64)timeout_ns * host->bus_hz, NSEC_PER_SEC); |
| 559 | tmp = DIV_ROUND_UP_ULL(tmp, clk_div); |
| 560 | |
| 561 | /* TMOUT[7:0] (RESPONSE_TIMEOUT) */ |
| 562 | tmout = 0xFF; /* Set maximum */ |
| 563 | |
| 564 | /* |
| 565 | * Extended HW timer (max = 0x6FFFFF2): |
| 566 | * ((TMOUT[10:8] - 1) * 0xFFFFFF + TMOUT[31:11] * 8) |
| 567 | */ |
| 568 | if (!tmp || tmp > 0x6FFFFF2) |
| 569 | tmout |= (0xFFFFFF << 8); |
| 570 | else { |
| 571 | /* TMOUT[10:8] */ |
| 572 | tmp2 = (((unsigned int)tmp / 0xFFFFFF) + 1) & 0x7; |
| 573 | tmout |= tmp2 << 8; |
| 574 | |
| 575 | /* TMOUT[31:11] */ |
| 576 | tmp = tmp - ((tmp2 - 1) * 0xFFFFFF); |
| 577 | tmout |= (tmp & 0xFFFFF8) << 8; |
| 578 | } |
| 579 | |
| 580 | mci_writel(host, TMOUT, tmout); |
| 581 | dev_dbg(host->dev, "timeout_ns: %u => TMOUT[31:8]: %#08x", |
| 582 | timeout_ns, tmout >> 8); |
| 583 | } |
| 584 | |
| 585 | static u32 dw_mci_exynos_get_drto_clks(struct dw_mci *host) |
| 586 | { |
| 587 | u32 drto_clks; |
| 588 | |
| 589 | drto_clks = mci_readl(host, TMOUT) >> 8; |
| 590 | |
| 591 | return (((drto_clks & 0x7) - 1) * 0xFFFFFF) + ((drto_clks & 0xFFFFF8)); |
| 592 | } |
| 593 | |
Dongjin Kim | 0f6e73d | 2013-02-23 00:17:45 +0900 | [diff] [blame] | 594 | /* Common capabilities of Exynos4/Exynos5 SoC */ |
| 595 | static unsigned long exynos_dwmmc_caps[4] = { |
John Keeping | a13e8ef | 2021-11-24 18:46:02 +0000 | [diff] [blame] | 596 | MMC_CAP_1_8V_DDR | MMC_CAP_8_BIT_DATA, |
| 597 | 0, |
| 598 | 0, |
| 599 | 0, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 600 | }; |
| 601 | |
Dongjin Kim | 0f6e73d | 2013-02-23 00:17:45 +0900 | [diff] [blame] | 602 | static const struct dw_mci_drv_data exynos_drv_data = { |
| 603 | .caps = exynos_dwmmc_caps, |
Shawn Lin | 0d84b9e | 2018-02-24 14:17:23 +0800 | [diff] [blame] | 604 | .num_caps = ARRAY_SIZE(exynos_dwmmc_caps), |
John Keeping | a13e8ef | 2021-11-24 18:46:02 +0000 | [diff] [blame] | 605 | .common_caps = MMC_CAP_CMD23, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 606 | .init = dw_mci_exynos_priv_init, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 607 | .set_ios = dw_mci_exynos_set_ios, |
| 608 | .parse_dt = dw_mci_exynos_parse_dt, |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 609 | .execute_tuning = dw_mci_exynos_execute_tuning, |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 610 | .prepare_hs400_tuning = dw_mci_exynos_prepare_hs400_tuning, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 611 | }; |
| 612 | |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 613 | static const struct dw_mci_drv_data artpec_drv_data = { |
| 614 | .common_caps = MMC_CAP_CMD23, |
| 615 | .init = dw_mci_exynos_priv_init, |
| 616 | .set_ios = dw_mci_exynos_set_ios, |
| 617 | .parse_dt = dw_mci_exynos_parse_dt, |
| 618 | .execute_tuning = dw_mci_exynos_execute_tuning, |
Mårten Lindahl | 25d5417 | 2021-12-20 12:30:25 +0100 | [diff] [blame] | 619 | .set_data_timeout = dw_mci_exynos_set_data_timeout, |
| 620 | .get_drto_clks = dw_mci_exynos_get_drto_clks, |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 621 | }; |
| 622 | |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 623 | static const struct of_device_id dw_mci_exynos_match[] = { |
Dongjin Kim | 0f6e73d | 2013-02-23 00:17:45 +0900 | [diff] [blame] | 624 | { .compatible = "samsung,exynos4412-dw-mshc", |
| 625 | .data = &exynos_drv_data, }, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 626 | { .compatible = "samsung,exynos5250-dw-mshc", |
Dongjin Kim | 0f6e73d | 2013-02-23 00:17:45 +0900 | [diff] [blame] | 627 | .data = &exynos_drv_data, }, |
Yuvaraj Kumar C D | 00fd041 | 2013-05-24 15:34:32 +0530 | [diff] [blame] | 628 | { .compatible = "samsung,exynos5420-dw-mshc", |
| 629 | .data = &exynos_drv_data, }, |
Yuvaraj Kumar C D | 6bce431 | 2013-08-31 00:12:35 +0900 | [diff] [blame] | 630 | { .compatible = "samsung,exynos5420-dw-mshc-smu", |
| 631 | .data = &exynos_drv_data, }, |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 632 | { .compatible = "samsung,exynos7-dw-mshc", |
| 633 | .data = &exynos_drv_data, }, |
| 634 | { .compatible = "samsung,exynos7-dw-mshc-smu", |
| 635 | .data = &exynos_drv_data, }, |
Mårten Lindahl | 91e2ca2 | 2021-12-20 12:30:24 +0100 | [diff] [blame] | 636 | { .compatible = "axis,artpec8-dw-mshc", |
| 637 | .data = &artpec_drv_data, }, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 638 | {}, |
| 639 | }; |
Arnd Bergmann | 517cb9f | 2012-11-06 22:55:30 +0100 | [diff] [blame] | 640 | MODULE_DEVICE_TABLE(of, dw_mci_exynos_match); |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 641 | |
Sachin Kamat | 9665f7f | 2013-02-18 14:23:08 +0530 | [diff] [blame] | 642 | static int dw_mci_exynos_probe(struct platform_device *pdev) |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 643 | { |
Arnd Bergmann | 8e2b36e | 2012-11-06 22:55:31 +0100 | [diff] [blame] | 644 | const struct dw_mci_drv_data *drv_data; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 645 | const struct of_device_id *match; |
Joonyoung Shim | 9b93d392 | 2016-11-23 18:36:02 +0900 | [diff] [blame] | 646 | int ret; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 647 | |
| 648 | match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node); |
| 649 | drv_data = match->data; |
Joonyoung Shim | 9b93d392 | 2016-11-23 18:36:02 +0900 | [diff] [blame] | 650 | |
| 651 | pm_runtime_get_noresume(&pdev->dev); |
| 652 | pm_runtime_set_active(&pdev->dev); |
| 653 | pm_runtime_enable(&pdev->dev); |
| 654 | |
| 655 | ret = dw_mci_pltfm_register(pdev, drv_data); |
| 656 | if (ret) { |
| 657 | pm_runtime_disable(&pdev->dev); |
| 658 | pm_runtime_set_suspended(&pdev->dev); |
| 659 | pm_runtime_put_noidle(&pdev->dev); |
| 660 | |
| 661 | return ret; |
| 662 | } |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static int dw_mci_exynos_remove(struct platform_device *pdev) |
| 668 | { |
| 669 | pm_runtime_disable(&pdev->dev); |
| 670 | pm_runtime_set_suspended(&pdev->dev); |
| 671 | pm_runtime_put_noidle(&pdev->dev); |
| 672 | |
| 673 | return dw_mci_pltfm_remove(pdev); |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Sachin Kamat | 15a2e2a | 2014-03-04 10:33:25 +0530 | [diff] [blame] | 676 | static const struct dev_pm_ops dw_mci_exynos_pmops = { |
Marek Szyprowski | ecf7c7c | 2018-06-12 12:55:23 +0200 | [diff] [blame] | 677 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(dw_mci_exynos_suspend_noirq, |
| 678 | dw_mci_exynos_resume_noirq) |
Shawn Lin | cf5237e | 2016-10-12 10:55:55 +0800 | [diff] [blame] | 679 | SET_RUNTIME_PM_OPS(dw_mci_runtime_suspend, |
| 680 | dw_mci_exynos_runtime_resume, |
| 681 | NULL) |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 682 | }; |
| 683 | |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 684 | static struct platform_driver dw_mci_exynos_pltfm_driver = { |
| 685 | .probe = dw_mci_exynos_probe, |
Joonyoung Shim | 9b93d392 | 2016-11-23 18:36:02 +0900 | [diff] [blame] | 686 | .remove = dw_mci_exynos_remove, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 687 | .driver = { |
| 688 | .name = "dwmmc_exynos", |
Douglas Anderson | 21b2cec | 2020-09-03 16:24:36 -0700 | [diff] [blame] | 689 | .probe_type = PROBE_PREFER_ASYNCHRONOUS, |
Sachin Kamat | 20183d5 | 2013-02-18 14:23:09 +0530 | [diff] [blame] | 690 | .of_match_table = dw_mci_exynos_match, |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 691 | .pm = &dw_mci_exynos_pmops, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 692 | }, |
| 693 | }; |
| 694 | |
| 695 | module_platform_driver(dw_mci_exynos_pltfm_driver); |
| 696 | |
| 697 | MODULE_DESCRIPTION("Samsung Specific DW-MSHC Driver Extension"); |
| 698 | MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com"); |
| 699 | MODULE_LICENSE("GPL v2"); |
Zhangfei Gao | 2fc546f | 2015-05-14 16:59:45 +0800 | [diff] [blame] | 700 | MODULE_ALIAS("platform:dwmmc_exynos"); |