x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / mmc / host / dw_mmc-exynos.c
blob6a1fa2110a057b42d2a79cfb3407bb0f8fb8f3b8
1 /*
2 * Exynos Specific Extensions for Synopsys DW Multimedia Card Interface driver
4 * Copyright (C) 2012, Samsung Electronics Co., Ltd.
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.
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>
20 #include "dw_mmc.h"
21 #include "dw_mmc-pltfm.h"
23 #define NUM_PINS(x) (x + 2)
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))
34 #define EXYNOS4210_FIXED_CIU_CLK_DIV 2
35 #define EXYNOS4412_FIXED_CIU_CLK_DIV 4
37 /* Variations in Exynos specific dw-mshc controller */
38 enum dw_mci_exynos_type {
39 DW_MCI_TYPE_EXYNOS4210,
40 DW_MCI_TYPE_EXYNOS4412,
41 DW_MCI_TYPE_EXYNOS5250,
42 DW_MCI_TYPE_EXYNOS5420,
45 /* Exynos implementation specific driver private data */
46 struct dw_mci_exynos_priv_data {
47 enum dw_mci_exynos_type ctrl_type;
48 u8 ciu_div;
49 u32 sdr_timing;
50 u32 ddr_timing;
53 static struct dw_mci_exynos_compatible {
54 char *compatible;
55 enum dw_mci_exynos_type ctrl_type;
56 } exynos_compat[] = {
58 .compatible = "samsung,exynos4210-dw-mshc",
59 .ctrl_type = DW_MCI_TYPE_EXYNOS4210,
60 }, {
61 .compatible = "samsung,exynos4412-dw-mshc",
62 .ctrl_type = DW_MCI_TYPE_EXYNOS4412,
63 }, {
64 .compatible = "samsung,exynos5250-dw-mshc",
65 .ctrl_type = DW_MCI_TYPE_EXYNOS5250,
66 }, {
67 .compatible = "samsung,exynos5420-dw-mshc",
68 .ctrl_type = DW_MCI_TYPE_EXYNOS5420,
72 static int dw_mci_exynos_priv_init(struct dw_mci *host)
74 struct dw_mci_exynos_priv_data *priv;
75 int idx;
77 priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
78 if (!priv) {
79 dev_err(host->dev, "mem alloc failed for private data\n");
80 return -ENOMEM;
83 for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) {
84 if (of_device_is_compatible(host->dev->of_node,
85 exynos_compat[idx].compatible))
86 priv->ctrl_type = exynos_compat[idx].ctrl_type;
89 host->priv = priv;
90 return 0;
93 static int dw_mci_exynos_setup_clock(struct dw_mci *host)
95 struct dw_mci_exynos_priv_data *priv = host->priv;
97 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5250 ||
98 priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420)
99 host->bus_hz /= (priv->ciu_div + 1);
100 else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412)
101 host->bus_hz /= EXYNOS4412_FIXED_CIU_CLK_DIV;
102 else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210)
103 host->bus_hz /= EXYNOS4210_FIXED_CIU_CLK_DIV;
105 return 0;
108 static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr)
111 * Exynos4412 and Exynos5250 extends the use of CMD register with the
112 * use of bit 29 (which is reserved on standard MSHC controllers) for
113 * optionally bypassing the HOLD register for command and data. The
114 * HOLD register should be bypassed in case there is no phase shift
115 * applied on CMD/DATA that is sent to the card.
117 if (SDMMC_CLKSEL_GET_DRV_WD3(mci_readl(host, CLKSEL)))
118 *cmdr |= SDMMC_CMD_USE_HOLD_REG;
121 static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios)
123 struct dw_mci_exynos_priv_data *priv = host->priv;
125 if (ios->timing == MMC_TIMING_UHS_DDR50)
126 mci_writel(host, CLKSEL, priv->ddr_timing);
127 else
128 mci_writel(host, CLKSEL, priv->sdr_timing);
131 static int dw_mci_exynos_parse_dt(struct dw_mci *host)
133 struct dw_mci_exynos_priv_data *priv = host->priv;
134 struct device_node *np = host->dev->of_node;
135 u32 timing[2];
136 u32 div = 0;
137 int ret;
139 of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div);
140 priv->ciu_div = div;
142 ret = of_property_read_u32_array(np,
143 "samsung,dw-mshc-sdr-timing", timing, 2);
144 if (ret)
145 return ret;
147 priv->sdr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div);
149 ret = of_property_read_u32_array(np,
150 "samsung,dw-mshc-ddr-timing", timing, 2);
151 if (ret)
152 return ret;
154 priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div);
155 return 0;
158 /* Common capabilities of Exynos4/Exynos5 SoC */
159 static unsigned long exynos_dwmmc_caps[4] = {
160 MMC_CAP_UHS_DDR50 | MMC_CAP_1_8V_DDR |
161 MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23,
162 MMC_CAP_CMD23,
163 MMC_CAP_CMD23,
164 MMC_CAP_CMD23,
167 static const struct dw_mci_drv_data exynos_drv_data = {
168 .caps = exynos_dwmmc_caps,
169 .init = dw_mci_exynos_priv_init,
170 .setup_clock = dw_mci_exynos_setup_clock,
171 .prepare_command = dw_mci_exynos_prepare_command,
172 .set_ios = dw_mci_exynos_set_ios,
173 .parse_dt = dw_mci_exynos_parse_dt,
176 static const struct of_device_id dw_mci_exynos_match[] = {
177 { .compatible = "samsung,exynos4412-dw-mshc",
178 .data = &exynos_drv_data, },
179 { .compatible = "samsung,exynos5250-dw-mshc",
180 .data = &exynos_drv_data, },
181 { .compatible = "samsung,exynos5420-dw-mshc",
182 .data = &exynos_drv_data, },
185 MODULE_DEVICE_TABLE(of, dw_mci_exynos_match);
187 static int dw_mci_exynos_probe(struct platform_device *pdev)
189 const struct dw_mci_drv_data *drv_data;
190 const struct of_device_id *match;
192 match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node);
193 drv_data = match->data;
194 return dw_mci_pltfm_register(pdev, drv_data);
197 static struct platform_driver dw_mci_exynos_pltfm_driver = {
198 .probe = dw_mci_exynos_probe,
199 .remove = __exit_p(dw_mci_pltfm_remove),
200 .driver = {
201 .name = "dwmmc_exynos",
202 .of_match_table = dw_mci_exynos_match,
203 .pm = &dw_mci_pltfm_pmops,
207 module_platform_driver(dw_mci_exynos_pltfm_driver);
209 MODULE_DESCRIPTION("Samsung Specific DW-MSHC Driver Extension");
210 MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com");
211 MODULE_LICENSE("GPL v2");
212 MODULE_ALIAS("platform:dwmmc-exynos");