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> |
| 17 | #include <linux/of.h> |
| 18 | #include <linux/of_gpio.h> |
| 19 | |
| 20 | #include "dw_mmc.h" |
| 21 | #include "dw_mmc-pltfm.h" |
| 22 | |
| 23 | #define NUM_PINS(x) (x + 2) |
| 24 | |
| 25 | #define SDMMC_CLKSEL 0x09C |
| 26 | #define SDMMC_CLKSEL_CCLK_SAMPLE(x) (((x) & 7) << 0) |
| 27 | #define SDMMC_CLKSEL_CCLK_DRIVE(x) (((x) & 7) << 16) |
| 28 | #define SDMMC_CLKSEL_CCLK_DIVIDER(x) (((x) & 7) << 24) |
| 29 | #define SDMMC_CLKSEL_GET_DRV_WD3(x) (((x) >> 16) & 0x7) |
| 30 | #define SDMMC_CLKSEL_TIMING(x, y, z) (SDMMC_CLKSEL_CCLK_SAMPLE(x) | \ |
| 31 | SDMMC_CLKSEL_CCLK_DRIVE(y) | \ |
| 32 | SDMMC_CLKSEL_CCLK_DIVIDER(z)) |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame^] | 33 | #define SDMMC_CLKSEL_WAKEUP_INT BIT(11) |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 34 | |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 35 | #define EXYNOS4210_FIXED_CIU_CLK_DIV 2 |
| 36 | #define EXYNOS4412_FIXED_CIU_CLK_DIV 4 |
| 37 | |
| 38 | /* Variations in Exynos specific dw-mshc controller */ |
| 39 | enum dw_mci_exynos_type { |
| 40 | DW_MCI_TYPE_EXYNOS4210, |
| 41 | DW_MCI_TYPE_EXYNOS4412, |
| 42 | DW_MCI_TYPE_EXYNOS5250, |
Yuvaraj Kumar C D | 00fd041 | 2013-05-24 15:34:32 +0530 | [diff] [blame] | 43 | DW_MCI_TYPE_EXYNOS5420, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | /* Exynos implementation specific driver private data */ |
| 47 | struct dw_mci_exynos_priv_data { |
| 48 | enum dw_mci_exynos_type ctrl_type; |
| 49 | u8 ciu_div; |
| 50 | u32 sdr_timing; |
| 51 | u32 ddr_timing; |
| 52 | }; |
| 53 | |
| 54 | static struct dw_mci_exynos_compatible { |
| 55 | char *compatible; |
| 56 | enum dw_mci_exynos_type ctrl_type; |
| 57 | } exynos_compat[] = { |
| 58 | { |
| 59 | .compatible = "samsung,exynos4210-dw-mshc", |
| 60 | .ctrl_type = DW_MCI_TYPE_EXYNOS4210, |
| 61 | }, { |
| 62 | .compatible = "samsung,exynos4412-dw-mshc", |
| 63 | .ctrl_type = DW_MCI_TYPE_EXYNOS4412, |
| 64 | }, { |
| 65 | .compatible = "samsung,exynos5250-dw-mshc", |
| 66 | .ctrl_type = DW_MCI_TYPE_EXYNOS5250, |
Yuvaraj Kumar C D | 00fd041 | 2013-05-24 15:34:32 +0530 | [diff] [blame] | 67 | }, { |
| 68 | .compatible = "samsung,exynos5420-dw-mshc", |
| 69 | .ctrl_type = DW_MCI_TYPE_EXYNOS5420, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 70 | }, |
| 71 | }; |
| 72 | |
| 73 | static int dw_mci_exynos_priv_init(struct dw_mci *host) |
| 74 | { |
| 75 | struct dw_mci_exynos_priv_data *priv; |
| 76 | int idx; |
| 77 | |
| 78 | priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); |
| 79 | if (!priv) { |
| 80 | dev_err(host->dev, "mem alloc failed for private data\n"); |
| 81 | return -ENOMEM; |
| 82 | } |
| 83 | |
| 84 | for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) { |
| 85 | if (of_device_is_compatible(host->dev->of_node, |
| 86 | exynos_compat[idx].compatible)) |
| 87 | priv->ctrl_type = exynos_compat[idx].ctrl_type; |
| 88 | } |
| 89 | |
| 90 | host->priv = priv; |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static int dw_mci_exynos_setup_clock(struct dw_mci *host) |
| 95 | { |
| 96 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 97 | |
Yuvaraj Kumar C D | 00fd041 | 2013-05-24 15:34:32 +0530 | [diff] [blame] | 98 | if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5250 || |
| 99 | priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420) |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 100 | host->bus_hz /= (priv->ciu_div + 1); |
| 101 | else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412) |
| 102 | host->bus_hz /= EXYNOS4412_FIXED_CIU_CLK_DIV; |
| 103 | else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210) |
| 104 | host->bus_hz /= EXYNOS4210_FIXED_CIU_CLK_DIV; |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame^] | 109 | #ifdef CONFIG_PM_SLEEP |
| 110 | static int dw_mci_exynos_suspend(struct device *dev) |
| 111 | { |
| 112 | struct dw_mci *host = dev_get_drvdata(dev); |
| 113 | |
| 114 | return dw_mci_suspend(host); |
| 115 | } |
| 116 | |
| 117 | static int dw_mci_exynos_resume(struct device *dev) |
| 118 | { |
| 119 | struct dw_mci *host = dev_get_drvdata(dev); |
| 120 | |
| 121 | return dw_mci_resume(host); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * dw_mci_exynos_resume_noirq - Exynos-specific resume code |
| 126 | * |
| 127 | * On exynos5420 there is a silicon errata that will sometimes leave the |
| 128 | * WAKEUP_INT bit in the CLKSEL register asserted. This bit is 1 to indicate |
| 129 | * that it fired and we can clear it by writing a 1 back. Clear it to prevent |
| 130 | * interrupts from going off constantly. |
| 131 | * |
| 132 | * We run this code on all exynos variants because it doesn't hurt. |
| 133 | */ |
| 134 | |
| 135 | static int dw_mci_exynos_resume_noirq(struct device *dev) |
| 136 | { |
| 137 | struct dw_mci *host = dev_get_drvdata(dev); |
| 138 | u32 clksel; |
| 139 | |
| 140 | clksel = mci_readl(host, CLKSEL); |
| 141 | if (clksel & SDMMC_CLKSEL_WAKEUP_INT) |
| 142 | mci_writel(host, CLKSEL, clksel); |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | #else |
| 147 | #define dw_mci_exynos_suspend NULL |
| 148 | #define dw_mci_exynos_resume NULL |
| 149 | #define dw_mci_exynos_resume_noirq NULL |
| 150 | #endif /* CONFIG_PM_SLEEP */ |
| 151 | |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 152 | static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr) |
| 153 | { |
| 154 | /* |
| 155 | * Exynos4412 and Exynos5250 extends the use of CMD register with the |
| 156 | * use of bit 29 (which is reserved on standard MSHC controllers) for |
| 157 | * optionally bypassing the HOLD register for command and data. The |
| 158 | * HOLD register should be bypassed in case there is no phase shift |
| 159 | * applied on CMD/DATA that is sent to the card. |
| 160 | */ |
| 161 | if (SDMMC_CLKSEL_GET_DRV_WD3(mci_readl(host, CLKSEL))) |
| 162 | *cmdr |= SDMMC_CMD_USE_HOLD_REG; |
| 163 | } |
| 164 | |
| 165 | static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios) |
| 166 | { |
| 167 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 168 | |
| 169 | if (ios->timing == MMC_TIMING_UHS_DDR50) |
| 170 | mci_writel(host, CLKSEL, priv->ddr_timing); |
| 171 | else |
| 172 | mci_writel(host, CLKSEL, priv->sdr_timing); |
| 173 | } |
| 174 | |
| 175 | static int dw_mci_exynos_parse_dt(struct dw_mci *host) |
| 176 | { |
| 177 | struct dw_mci_exynos_priv_data *priv = host->priv; |
| 178 | struct device_node *np = host->dev->of_node; |
| 179 | u32 timing[2]; |
| 180 | u32 div = 0; |
| 181 | int ret; |
| 182 | |
| 183 | of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div); |
| 184 | priv->ciu_div = div; |
| 185 | |
| 186 | ret = of_property_read_u32_array(np, |
| 187 | "samsung,dw-mshc-sdr-timing", timing, 2); |
| 188 | if (ret) |
| 189 | return ret; |
| 190 | |
| 191 | priv->sdr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); |
| 192 | |
| 193 | ret = of_property_read_u32_array(np, |
| 194 | "samsung,dw-mshc-ddr-timing", timing, 2); |
| 195 | if (ret) |
| 196 | return ret; |
| 197 | |
| 198 | priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); |
| 199 | return 0; |
| 200 | } |
| 201 | |
Dongjin Kim | 0f6e73d | 2013-02-23 00:17:45 +0900 | [diff] [blame] | 202 | /* Common capabilities of Exynos4/Exynos5 SoC */ |
| 203 | static unsigned long exynos_dwmmc_caps[4] = { |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 204 | MMC_CAP_UHS_DDR50 | MMC_CAP_1_8V_DDR | |
| 205 | MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23, |
| 206 | MMC_CAP_CMD23, |
| 207 | MMC_CAP_CMD23, |
| 208 | MMC_CAP_CMD23, |
| 209 | }; |
| 210 | |
Dongjin Kim | 0f6e73d | 2013-02-23 00:17:45 +0900 | [diff] [blame] | 211 | static const struct dw_mci_drv_data exynos_drv_data = { |
| 212 | .caps = exynos_dwmmc_caps, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 213 | .init = dw_mci_exynos_priv_init, |
| 214 | .setup_clock = dw_mci_exynos_setup_clock, |
| 215 | .prepare_command = dw_mci_exynos_prepare_command, |
| 216 | .set_ios = dw_mci_exynos_set_ios, |
| 217 | .parse_dt = dw_mci_exynos_parse_dt, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | static const struct of_device_id dw_mci_exynos_match[] = { |
Dongjin Kim | 0f6e73d | 2013-02-23 00:17:45 +0900 | [diff] [blame] | 221 | { .compatible = "samsung,exynos4412-dw-mshc", |
| 222 | .data = &exynos_drv_data, }, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 223 | { .compatible = "samsung,exynos5250-dw-mshc", |
Dongjin Kim | 0f6e73d | 2013-02-23 00:17:45 +0900 | [diff] [blame] | 224 | .data = &exynos_drv_data, }, |
Yuvaraj Kumar C D | 00fd041 | 2013-05-24 15:34:32 +0530 | [diff] [blame] | 225 | { .compatible = "samsung,exynos5420-dw-mshc", |
| 226 | .data = &exynos_drv_data, }, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 227 | {}, |
| 228 | }; |
Arnd Bergmann | 517cb9f | 2012-11-06 22:55:30 +0100 | [diff] [blame] | 229 | MODULE_DEVICE_TABLE(of, dw_mci_exynos_match); |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 230 | |
Sachin Kamat | 9665f7f | 2013-02-18 14:23:08 +0530 | [diff] [blame] | 231 | static int dw_mci_exynos_probe(struct platform_device *pdev) |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 232 | { |
Arnd Bergmann | 8e2b36e | 2012-11-06 22:55:31 +0100 | [diff] [blame] | 233 | const struct dw_mci_drv_data *drv_data; |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 234 | const struct of_device_id *match; |
| 235 | |
| 236 | match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node); |
| 237 | drv_data = match->data; |
| 238 | return dw_mci_pltfm_register(pdev, drv_data); |
| 239 | } |
| 240 | |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame^] | 241 | const struct dev_pm_ops dw_mci_exynos_pmops = { |
| 242 | SET_SYSTEM_SLEEP_PM_OPS(dw_mci_exynos_suspend, dw_mci_exynos_resume) |
| 243 | .resume_noirq = dw_mci_exynos_resume_noirq, |
| 244 | .thaw_noirq = dw_mci_exynos_resume_noirq, |
| 245 | .restore_noirq = dw_mci_exynos_resume_noirq, |
| 246 | }; |
| 247 | |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 248 | static struct platform_driver dw_mci_exynos_pltfm_driver = { |
| 249 | .probe = dw_mci_exynos_probe, |
| 250 | .remove = __exit_p(dw_mci_pltfm_remove), |
| 251 | .driver = { |
| 252 | .name = "dwmmc_exynos", |
Sachin Kamat | 20183d5 | 2013-02-18 14:23:09 +0530 | [diff] [blame] | 253 | .of_match_table = dw_mci_exynos_match, |
Doug Anderson | e2c6359 | 2013-08-31 00:11:21 +0900 | [diff] [blame^] | 254 | .pm = &dw_mci_exynos_pmops, |
Thomas Abraham | c366500 | 2012-09-17 18:16:43 +0000 | [diff] [blame] | 255 | }, |
| 256 | }; |
| 257 | |
| 258 | module_platform_driver(dw_mci_exynos_pltfm_driver); |
| 259 | |
| 260 | MODULE_DESCRIPTION("Samsung Specific DW-MSHC Driver Extension"); |
| 261 | MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com"); |
| 262 | MODULE_LICENSE("GPL v2"); |
| 263 | MODULE_ALIAS("platform:dwmmc-exynos"); |