Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Exynos Specific Extensions for Synopsys DW Multimedia Card Interface driver |
| 3 | * |
| 4 | * Copyright (C) 2012, Samsung Electronics Co., Ltd. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/clk.h> |
| 15 | #include <linux/mmc/host.h> |
| 16 | #include <linux/mmc/dw_mmc.h> |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 17 | #include <linux/mmc/mmc.h> |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 18 | #include <linux/of.h> |
| 19 | #include <linux/of_gpio.h> |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 21 | |
| 22 | #include "dw_mmc.h" |
| 23 | #include "dw_mmc-pltfm.h" |
Seungwon Jeon | 0b5fce4 | 2014-12-22 17:42:04 +0530 | [diff] [blame] | 24 | #include "dw_mmc-exynos.h" |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 25 | |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 26 | /* Variations in Exynos specific dw-mshc controller */ |
| 27 | enum dw_mci_exynos_type { |
| 28 | DW_MCI_TYPE_EXYNOS4210, |
| 29 | DW_MCI_TYPE_EXYNOS4412, |
| 30 | DW_MCI_TYPE_EXYNOS5250, |
Yuvaraj Kumar C D | 00fd041 | 2013-05-24 15:34:32 +0530 | [diff] [blame] | 31 | DW_MCI_TYPE_EXYNOS5420, |
Yuvaraj Kumar C D | 6bce431 | 2013-08-31 00:12:35 +0900 | [diff] [blame] | 32 | DW_MCI_TYPE_EXYNOS5420_SMU, |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 33 | DW_MCI_TYPE_EXYNOS7, |
| 34 | DW_MCI_TYPE_EXYNOS7_SMU, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | /* Exynos implementation specific driver private data */ |
| 38 | struct dw_mci_exynos_priv_data { |
| 39 | enum dw_mci_exynos_type ctrl_type; |
| 40 | u8 ciu_div; |
| 41 | u32 sdr_timing; |
| 42 | u32 ddr_timing; |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 43 | u32 hs400_timing; |
| 44 | u32 tuned_sample; |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 45 | u32 cur_speed; |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 46 | u32 dqs_delay; |
| 47 | u32 saved_dqs_en; |
| 48 | u32 saved_strobe_ctrl; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | static struct dw_mci_exynos_compatible { |
| 52 | char *compatible; |
| 53 | enum dw_mci_exynos_type ctrl_type; |
| 54 | } exynos_compat[] = { |
| 55 | { |
| 56 | .compatible = "samsung,exynos4210-dw-mshc", |
| 57 | .ctrl_type = DW_MCI_TYPE_EXYNOS4210, |
| 58 | }, { |
| 59 | .compatible = "samsung,exynos4412-dw-mshc", |
| 60 | .ctrl_type = DW_MCI_TYPE_EXYNOS4412, |
| 61 | }, { |
| 62 | .compatible = "samsung,exynos5250-dw-mshc", |
| 63 | .ctrl_type = DW_MCI_TYPE_EXYNOS5250, |
Yuvaraj Kumar C D | 00fd041 | 2013-05-24 15:34:32 +0530 | [diff] [blame] | 64 | }, { |
| 65 | .compatible = "samsung,exynos5420-dw-mshc", |
| 66 | .ctrl_type = DW_MCI_TYPE_EXYNOS5420, |
Yuvaraj Kumar C D | 6bce431 | 2013-08-31 00:12:35 +0900 | [diff] [blame] | 67 | }, { |
| 68 | .compatible = "samsung,exynos5420-dw-mshc-smu", |
| 69 | .ctrl_type = DW_MCI_TYPE_EXYNOS5420_SMU, |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 70 | }, { |
| 71 | .compatible = "samsung,exynos7-dw-mshc", |
| 72 | .ctrl_type = DW_MCI_TYPE_EXYNOS7, |
| 73 | }, { |
| 74 | .compatible = "samsung,exynos7-dw-mshc-smu", |
| 75 | .ctrl_type = DW_MCI_TYPE_EXYNOS7_SMU, |
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 || |
| 88 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) |
| 89 | return SDMMC_CLKSEL_GET_DIV(mci_readl(host, CLKSEL64)) + 1; |
| 90 | else |
| 91 | return SDMMC_CLKSEL_GET_DIV(mci_readl(host, CLKSEL)) + 1; |
| 92 | } |
| 93 | |
Jaehoon Chung | 5659eea | 2016-03-31 14:53:18 +0900 | [diff] [blame] | 94 | static void dw_mci_exynos_config_smu(struct dw_mci *host) |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 95 | { |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 96 | struct dw_mci_exynos_priv_data *priv = host->priv; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 97 | |
Jaehoon Chung | 5659eea | 2016-03-31 14:53:18 +0900 | [diff] [blame] | 98 | /* |
| 99 | * If Exynos is provided the Security management, |
| 100 | * set for non-ecryption mode at this time. |
| 101 | */ |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 102 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420_SMU || |
| 103 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) { |
Yuvaraj Kumar C D | 6bce431 | 2013-08-31 00:12:35 +0900 | [diff] [blame] | 104 | mci_writel(host, MPSBEGIN0, 0); |
Seungwon Jeon | 0b5fce4 | 2014-12-22 17:42:04 +0530 | [diff] [blame] | 105 | mci_writel(host, MPSEND0, SDMMC_ENDING_SEC_NR_MAX); |
| 106 | mci_writel(host, MPSCTRL0, SDMMC_MPSCTRL_SECURE_WRITE_BIT | |
| 107 | SDMMC_MPSCTRL_NON_SECURE_READ_BIT | |
| 108 | SDMMC_MPSCTRL_VALID | |
| 109 | SDMMC_MPSCTRL_NON_SECURE_WRITE_BIT); |
Yuvaraj Kumar C D | 6bce431 | 2013-08-31 00:12:35 +0900 | [diff] [blame] | 110 | } |
Jaehoon Chung | 5659eea | 2016-03-31 14:53:18 +0900 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static int dw_mci_exynos_priv_init(struct dw_mci *host) |
| 114 | { |
| 115 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 116 | |
| 117 | dw_mci_exynos_config_smu(host); |
Yuvaraj Kumar C D | 6bce431 | 2013-08-31 00:12:35 +0900 | [diff] [blame] | 118 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 119 | if (priv->ctrl_type >= DW_MCI_TYPE_EXYNOS5420) { |
| 120 | priv->saved_strobe_ctrl = mci_readl(host, HS400_DLINE_CTRL); |
| 121 | priv->saved_dqs_en = mci_readl(host, HS400_DQS_EN); |
| 122 | priv->saved_dqs_en |= AXI_NON_BLOCKING_WR; |
| 123 | mci_writel(host, HS400_DQS_EN, priv->saved_dqs_en); |
| 124 | if (!priv->dqs_delay) |
| 125 | priv->dqs_delay = |
| 126 | DQS_CTRL_GET_RD_DELAY(priv->saved_strobe_ctrl); |
| 127 | } |
| 128 | |
Seungwon Jeon | a2a1fed | 2014-12-22 17:42:03 +0530 | [diff] [blame] | 129 | host->bus_hz /= (priv->ciu_div + 1); |
| 130 | |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 131 | return 0; |
| 132 | } |
| 133 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 134 | static void dw_mci_exynos_set_clksel_timing(struct dw_mci *host, u32 timing) |
| 135 | { |
| 136 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 137 | u32 clksel; |
| 138 | |
| 139 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
| 140 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) |
| 141 | clksel = mci_readl(host, CLKSEL64); |
| 142 | else |
| 143 | clksel = mci_readl(host, CLKSEL); |
| 144 | |
| 145 | clksel = (clksel & ~SDMMC_CLKSEL_TIMING_MASK) | timing; |
| 146 | |
| 147 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
| 148 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) |
| 149 | mci_writel(host, CLKSEL64, clksel); |
| 150 | else |
| 151 | mci_writel(host, CLKSEL, clksel); |
Jaehoon Chung | aaaaeb7 | 2016-01-21 11:01:06 +0900 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * Exynos4412 and Exynos5250 extends the use of CMD register with the |
| 155 | * use of bit 29 (which is reserved on standard MSHC controllers) for |
| 156 | * optionally bypassing the HOLD register for command and data. The |
| 157 | * HOLD register should be bypassed in case there is no phase shift |
| 158 | * applied on CMD/DATA that is sent to the card. |
| 159 | */ |
Jaehoon Chung | e5a6135 | 2016-06-20 13:16:09 +0900 | [diff] [blame] | 160 | if (!SDMMC_CLKSEL_GET_DRV_WD3(clksel) && host->cur_slot) |
Jaehoon Chung | aaaaeb7 | 2016-01-21 11:01:06 +0900 | [diff] [blame] | 161 | set_bit(DW_MMC_CARD_NO_USE_HOLD, &host->cur_slot->flags); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 162 | } |
| 163 | |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 164 | #ifdef CONFIG_PM_SLEEP |
| 165 | static int dw_mci_exynos_suspend(struct device *dev) |
| 166 | { |
| 167 | struct dw_mci *host = dev_get_drvdata(dev); |
| 168 | |
| 169 | return dw_mci_suspend(host); |
| 170 | } |
| 171 | |
| 172 | static int dw_mci_exynos_resume(struct device *dev) |
| 173 | { |
| 174 | struct dw_mci *host = dev_get_drvdata(dev); |
| 175 | |
Jaehoon Chung | 5659eea | 2016-03-31 14:53:18 +0900 | [diff] [blame] | 176 | dw_mci_exynos_config_smu(host); |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 177 | return dw_mci_resume(host); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * dw_mci_exynos_resume_noirq - Exynos-specific resume code |
| 182 | * |
| 183 | * On exynos5420 there is a silicon errata that will sometimes leave the |
| 184 | * WAKEUP_INT bit in the CLKSEL register asserted. This bit is 1 to indicate |
| 185 | * that it fired and we can clear it by writing a 1 back. Clear it to prevent |
| 186 | * interrupts from going off constantly. |
| 187 | * |
| 188 | * We run this code on all exynos variants because it doesn't hurt. |
| 189 | */ |
| 190 | |
| 191 | static int dw_mci_exynos_resume_noirq(struct device *dev) |
| 192 | { |
| 193 | struct dw_mci *host = dev_get_drvdata(dev); |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 194 | struct dw_mci_exynos_priv_data *priv = host->priv; |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 195 | u32 clksel; |
| 196 | |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 197 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
| 198 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) |
| 199 | clksel = mci_readl(host, CLKSEL64); |
| 200 | else |
| 201 | clksel = mci_readl(host, CLKSEL); |
| 202 | |
| 203 | if (clksel & SDMMC_CLKSEL_WAKEUP_INT) { |
| 204 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
| 205 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) |
| 206 | mci_writel(host, CLKSEL64, clksel); |
| 207 | else |
| 208 | mci_writel(host, CLKSEL, clksel); |
| 209 | } |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | #else |
| 214 | #define dw_mci_exynos_suspend NULL |
| 215 | #define dw_mci_exynos_resume NULL |
| 216 | #define dw_mci_exynos_resume_noirq NULL |
| 217 | #endif /* CONFIG_PM_SLEEP */ |
| 218 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 219 | 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] | 220 | { |
| 221 | struct dw_mci_exynos_priv_data *priv = host->priv; |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 222 | u32 dqs, strobe; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 223 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 224 | /* |
| 225 | * Not supported to configure register |
| 226 | * related to HS400 |
| 227 | */ |
Krzysztof Kozlowski | 941a659 | 2016-07-14 15:22:27 +0200 | [diff] [blame] | 228 | if (priv->ctrl_type < DW_MCI_TYPE_EXYNOS5420) { |
| 229 | if (timing == MMC_TIMING_MMC_HS400) |
| 230 | dev_warn(host->dev, |
| 231 | "cannot configure HS400, unsupported chipset\n"); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 232 | return; |
Krzysztof Kozlowski | 941a659 | 2016-07-14 15:22:27 +0200 | [diff] [blame] | 233 | } |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 234 | |
| 235 | dqs = priv->saved_dqs_en; |
| 236 | strobe = priv->saved_strobe_ctrl; |
| 237 | |
| 238 | if (timing == MMC_TIMING_MMC_HS400) { |
| 239 | dqs |= DATA_STROBE_EN; |
| 240 | strobe = DQS_CTRL_RD_DELAY(strobe, priv->dqs_delay); |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 241 | } else { |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 242 | dqs &= ~DATA_STROBE_EN; |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 243 | } |
| 244 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 245 | mci_writel(host, HS400_DQS_EN, dqs); |
| 246 | mci_writel(host, HS400_DLINE_CTRL, strobe); |
| 247 | } |
| 248 | |
| 249 | static void dw_mci_exynos_adjust_clock(struct dw_mci *host, unsigned int wanted) |
| 250 | { |
| 251 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 252 | unsigned long actual; |
| 253 | u8 div; |
| 254 | int ret; |
Seungwon Jeon | a2a1fed | 2014-12-22 17:42:03 +0530 | [diff] [blame] | 255 | /* |
| 256 | * Don't care if wanted clock is zero or |
| 257 | * ciu clock is unavailable |
| 258 | */ |
| 259 | if (!wanted || IS_ERR(host->ciu_clk)) |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 260 | return; |
| 261 | |
| 262 | /* Guaranteed minimum frequency for cclkin */ |
| 263 | if (wanted < EXYNOS_CCLKIN_MIN) |
| 264 | wanted = EXYNOS_CCLKIN_MIN; |
| 265 | |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 266 | if (wanted == priv->cur_speed) |
| 267 | return; |
| 268 | |
| 269 | div = dw_mci_exynos_get_ciu_div(host); |
| 270 | ret = clk_set_rate(host->ciu_clk, wanted * div); |
| 271 | if (ret) |
| 272 | dev_warn(host->dev, |
| 273 | "failed to set clk-rate %u error: %d\n", |
| 274 | wanted * div, ret); |
| 275 | actual = clk_get_rate(host->ciu_clk); |
| 276 | host->bus_hz = actual / div; |
| 277 | priv->cur_speed = wanted; |
| 278 | host->current_speed = 0; |
| 279 | } |
| 280 | |
| 281 | static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios) |
| 282 | { |
| 283 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 284 | unsigned int wanted = ios->clock; |
| 285 | u32 timing = ios->timing, clksel; |
| 286 | |
| 287 | switch (timing) { |
| 288 | case MMC_TIMING_MMC_HS400: |
| 289 | /* Update tuned sample timing */ |
| 290 | clksel = SDMMC_CLKSEL_UP_SAMPLE( |
| 291 | priv->hs400_timing, priv->tuned_sample); |
| 292 | wanted <<= 1; |
| 293 | break; |
| 294 | case MMC_TIMING_MMC_DDR52: |
| 295 | clksel = priv->ddr_timing; |
| 296 | /* Should be double rate for DDR mode */ |
| 297 | if (ios->bus_width == MMC_BUS_WIDTH_8) |
| 298 | wanted <<= 1; |
| 299 | break; |
| 300 | default: |
| 301 | clksel = priv->sdr_timing; |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 302 | } |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 303 | |
| 304 | /* Set clock timing for the requested speed mode*/ |
| 305 | dw_mci_exynos_set_clksel_timing(host, clksel); |
| 306 | |
| 307 | /* Configure setting for HS400 */ |
| 308 | dw_mci_exynos_config_hs400(host, timing); |
| 309 | |
| 310 | /* Configure clock rate */ |
| 311 | dw_mci_exynos_adjust_clock(host, wanted); |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static int dw_mci_exynos_parse_dt(struct dw_mci *host) |
| 315 | { |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 316 | struct dw_mci_exynos_priv_data *priv; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 317 | struct device_node *np = host->dev->of_node; |
| 318 | u32 timing[2]; |
| 319 | u32 div = 0; |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 320 | int idx; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 321 | int ret; |
| 322 | |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 323 | priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); |
Beomho Seo | bf3707e | 2014-12-23 21:07:33 +0900 | [diff] [blame] | 324 | if (!priv) |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 325 | return -ENOMEM; |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 326 | |
| 327 | for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) { |
| 328 | if (of_device_is_compatible(np, exynos_compat[idx].compatible)) |
| 329 | priv->ctrl_type = exynos_compat[idx].ctrl_type; |
| 330 | } |
| 331 | |
Seungwon Jeon | c6d9ded | 2013-08-31 00:13:03 +0900 | [diff] [blame] | 332 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412) |
| 333 | priv->ciu_div = EXYNOS4412_FIXED_CIU_CLK_DIV - 1; |
| 334 | else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210) |
| 335 | priv->ciu_div = EXYNOS4210_FIXED_CIU_CLK_DIV - 1; |
| 336 | else { |
| 337 | of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div); |
| 338 | priv->ciu_div = div; |
| 339 | } |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 340 | |
| 341 | ret = of_property_read_u32_array(np, |
| 342 | "samsung,dw-mshc-sdr-timing", timing, 2); |
| 343 | if (ret) |
| 344 | return ret; |
| 345 | |
Yuvaraj Kumar C D | 2d9f0bd | 2013-10-22 14:41:56 +0530 | [diff] [blame] | 346 | priv->sdr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); |
| 347 | |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 348 | ret = of_property_read_u32_array(np, |
| 349 | "samsung,dw-mshc-ddr-timing", timing, 2); |
| 350 | if (ret) |
| 351 | return ret; |
| 352 | |
| 353 | priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 354 | |
| 355 | ret = of_property_read_u32_array(np, |
| 356 | "samsung,dw-mshc-hs400-timing", timing, 2); |
| 357 | if (!ret && of_property_read_u32(np, |
| 358 | "samsung,read-strobe-delay", &priv->dqs_delay)) |
| 359 | dev_dbg(host->dev, |
| 360 | "read-strobe-delay is not found, assuming usage of default value\n"); |
| 361 | |
| 362 | priv->hs400_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], |
| 363 | HS400_FIXED_CIU_CLK_DIV); |
Yuvaraj Kumar C D | e6c784e | 2013-08-31 00:11:57 +0900 | [diff] [blame] | 364 | host->priv = priv; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 365 | return 0; |
| 366 | } |
| 367 | |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 368 | static inline u8 dw_mci_exynos_get_clksmpl(struct dw_mci *host) |
| 369 | { |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 370 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 371 | |
| 372 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
| 373 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) |
| 374 | return SDMMC_CLKSEL_CCLK_SAMPLE(mci_readl(host, CLKSEL64)); |
| 375 | else |
| 376 | return SDMMC_CLKSEL_CCLK_SAMPLE(mci_readl(host, CLKSEL)); |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | static inline void dw_mci_exynos_set_clksmpl(struct dw_mci *host, u8 sample) |
| 380 | { |
| 381 | u32 clksel; |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 382 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 383 | |
| 384 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
| 385 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) |
| 386 | clksel = mci_readl(host, CLKSEL64); |
| 387 | else |
| 388 | clksel = mci_readl(host, CLKSEL); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 389 | clksel = SDMMC_CLKSEL_UP_SAMPLE(clksel, sample); |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 390 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
| 391 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) |
| 392 | mci_writel(host, CLKSEL64, clksel); |
| 393 | else |
| 394 | mci_writel(host, CLKSEL, clksel); |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | static inline u8 dw_mci_exynos_move_next_clksmpl(struct dw_mci *host) |
| 398 | { |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 399 | struct dw_mci_exynos_priv_data *priv = host->priv; |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 400 | u32 clksel; |
| 401 | u8 sample; |
| 402 | |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 403 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
| 404 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) |
| 405 | clksel = mci_readl(host, CLKSEL64); |
| 406 | else |
| 407 | clksel = mci_readl(host, CLKSEL); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 408 | |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 409 | sample = (clksel + 1) & 0x7; |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 410 | clksel = SDMMC_CLKSEL_UP_SAMPLE(clksel, sample); |
| 411 | |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 412 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 || |
| 413 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) |
| 414 | mci_writel(host, CLKSEL64, clksel); |
| 415 | else |
| 416 | mci_writel(host, CLKSEL, clksel); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 417 | |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 418 | return sample; |
| 419 | } |
| 420 | |
| 421 | static s8 dw_mci_exynos_get_best_clksmpl(u8 candiates) |
| 422 | { |
| 423 | const u8 iter = 8; |
| 424 | u8 __c; |
| 425 | s8 i, loc = -1; |
| 426 | |
| 427 | for (i = 0; i < iter; i++) { |
| 428 | __c = ror8(candiates, i); |
| 429 | if ((__c & 0xc7) == 0xc7) { |
| 430 | loc = i; |
| 431 | goto out; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | for (i = 0; i < iter; i++) { |
| 436 | __c = ror8(candiates, i); |
| 437 | if ((__c & 0x83) == 0x83) { |
| 438 | loc = i; |
| 439 | goto out; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | out: |
| 444 | return loc; |
| 445 | } |
| 446 | |
Chaotian Jing | 9979dbe | 2015-10-27 14:24:28 +0800 | [diff] [blame] | 447 | 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] | 448 | { |
| 449 | struct dw_mci *host = slot->host; |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 450 | struct dw_mci_exynos_priv_data *priv = host->priv; |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 451 | struct mmc_host *mmc = slot->mmc; |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 452 | u8 start_smpl, smpl, candiates = 0; |
| 453 | s8 found = -1; |
| 454 | int ret = 0; |
| 455 | |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 456 | start_smpl = dw_mci_exynos_get_clksmpl(host); |
| 457 | |
| 458 | do { |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 459 | mci_writel(host, TMOUT, ~0); |
| 460 | smpl = dw_mci_exynos_move_next_clksmpl(host); |
| 461 | |
Chaotian Jing | 9979dbe | 2015-10-27 14:24:28 +0800 | [diff] [blame] | 462 | if (!mmc_send_tuning(mmc, opcode, NULL)) |
Ulf Hansson | 6c2c650 | 2014-12-01 16:13:39 +0100 | [diff] [blame] | 463 | candiates |= (1 << smpl); |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 464 | |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 465 | } while (start_smpl != smpl); |
| 466 | |
| 467 | found = dw_mci_exynos_get_best_clksmpl(candiates); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 468 | if (found >= 0) { |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 469 | dw_mci_exynos_set_clksmpl(host, found); |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 470 | priv->tuned_sample = found; |
| 471 | } else { |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 472 | ret = -EIO; |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 473 | } |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 474 | |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 475 | return ret; |
| 476 | } |
| 477 | |
Wu Fengguang | c22f5e1 | 2015-03-05 18:02:54 +0800 | [diff] [blame] | 478 | static int dw_mci_exynos_prepare_hs400_tuning(struct dw_mci *host, |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 479 | struct mmc_ios *ios) |
| 480 | { |
| 481 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 482 | |
| 483 | dw_mci_exynos_set_clksel_timing(host, priv->hs400_timing); |
| 484 | dw_mci_exynos_adjust_clock(host, (ios->clock) << 1); |
| 485 | |
| 486 | return 0; |
| 487 | } |
| 488 | |
Dongjin Kim | 0f6e73d | 2013-02-23 00:17:45 +0900 | [diff] [blame] | 489 | /* Common capabilities of Exynos4/Exynos5 SoC */ |
| 490 | static unsigned long exynos_dwmmc_caps[4] = { |
Seungwon Jeon | cab3a80 | 2014-03-14 21:12:43 +0900 | [diff] [blame] | 491 | MMC_CAP_1_8V_DDR | MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 492 | MMC_CAP_CMD23, |
| 493 | MMC_CAP_CMD23, |
| 494 | MMC_CAP_CMD23, |
| 495 | }; |
| 496 | |
Dongjin Kim | 0f6e73d | 2013-02-23 00:17:45 +0900 | [diff] [blame] | 497 | static const struct dw_mci_drv_data exynos_drv_data = { |
| 498 | .caps = exynos_dwmmc_caps, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 499 | .init = dw_mci_exynos_priv_init, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 500 | .set_ios = dw_mci_exynos_set_ios, |
| 501 | .parse_dt = dw_mci_exynos_parse_dt, |
Seungwon Jeon | c537a1c | 2013-08-31 00:12:50 +0900 | [diff] [blame] | 502 | .execute_tuning = dw_mci_exynos_execute_tuning, |
Seungwon Jeon | 8011313 | 2015-01-29 08:11:57 +0530 | [diff] [blame] | 503 | .prepare_hs400_tuning = dw_mci_exynos_prepare_hs400_tuning, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 504 | }; |
| 505 | |
| 506 | static const struct of_device_id dw_mci_exynos_match[] = { |
Dongjin Kim | 0f6e73d | 2013-02-23 00:17:45 +0900 | [diff] [blame] | 507 | { .compatible = "samsung,exynos4412-dw-mshc", |
| 508 | .data = &exynos_drv_data, }, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 509 | { .compatible = "samsung,exynos5250-dw-mshc", |
Dongjin Kim | 0f6e73d | 2013-02-23 00:17:45 +0900 | [diff] [blame] | 510 | .data = &exynos_drv_data, }, |
Yuvaraj Kumar C D | 00fd041 | 2013-05-24 15:34:32 +0530 | [diff] [blame] | 511 | { .compatible = "samsung,exynos5420-dw-mshc", |
| 512 | .data = &exynos_drv_data, }, |
Yuvaraj Kumar C D | 6bce431 | 2013-08-31 00:12:35 +0900 | [diff] [blame] | 513 | { .compatible = "samsung,exynos5420-dw-mshc-smu", |
| 514 | .data = &exynos_drv_data, }, |
Abhilash Kesavan | 89ad2be | 2014-08-28 18:48:53 +0530 | [diff] [blame] | 515 | { .compatible = "samsung,exynos7-dw-mshc", |
| 516 | .data = &exynos_drv_data, }, |
| 517 | { .compatible = "samsung,exynos7-dw-mshc-smu", |
| 518 | .data = &exynos_drv_data, }, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 519 | {}, |
| 520 | }; |
Arnd Bergmann | 517cb9f | 2012-11-06 22:55:30 +0100 | [diff] [blame] | 521 | MODULE_DEVICE_TABLE(of, dw_mci_exynos_match); |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 522 | |
Sachin Kamat | 9665f7f | 2013-02-18 14:23:08 +0530 | [diff] [blame] | 523 | static int dw_mci_exynos_probe(struct platform_device *pdev) |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 524 | { |
Arnd Bergmann | 8e2b36e | 2012-11-06 22:55:31 +0100 | [diff] [blame] | 525 | const struct dw_mci_drv_data *drv_data; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 526 | const struct of_device_id *match; |
| 527 | |
| 528 | match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node); |
| 529 | drv_data = match->data; |
| 530 | return dw_mci_pltfm_register(pdev, drv_data); |
| 531 | } |
| 532 | |
Sachin Kamat | 15a2e2a | 2014-03-04 10:33:25 +0530 | [diff] [blame] | 533 | static const struct dev_pm_ops dw_mci_exynos_pmops = { |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 534 | SET_SYSTEM_SLEEP_PM_OPS(dw_mci_exynos_suspend, dw_mci_exynos_resume) |
| 535 | .resume_noirq = dw_mci_exynos_resume_noirq, |
| 536 | .thaw_noirq = dw_mci_exynos_resume_noirq, |
| 537 | .restore_noirq = dw_mci_exynos_resume_noirq, |
| 538 | }; |
| 539 | |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 540 | static struct platform_driver dw_mci_exynos_pltfm_driver = { |
| 541 | .probe = dw_mci_exynos_probe, |
Dmitry Torokhov | 7d589ed | 2015-01-23 16:33:40 -0800 | [diff] [blame] | 542 | .remove = dw_mci_pltfm_remove, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 543 | .driver = { |
| 544 | .name = "dwmmc_exynos", |
Sachin Kamat | 20183d5 | 2013-02-18 14:23:09 +0530 | [diff] [blame] | 545 | .of_match_table = dw_mci_exynos_match, |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame] | 546 | .pm = &dw_mci_exynos_pmops, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 547 | }, |
| 548 | }; |
| 549 | |
| 550 | module_platform_driver(dw_mci_exynos_pltfm_driver); |
| 551 | |
| 552 | MODULE_DESCRIPTION("Samsung Specific DW-MSHC Driver Extension"); |
| 553 | MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com"); |
| 554 | MODULE_LICENSE("GPL v2"); |
Zhangfei Gao | 2fc546f | 2015-05-14 16:59:45 +0800 | [diff] [blame] | 555 | MODULE_ALIAS("platform:dwmmc_exynos"); |