x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / mmc / host / dw_mmc-socfpga.c
blob14b5961a851c43ed3a78e0df34d7be79e3cc0162
1 /*
2 * Altera SoCFPGA Specific Extensions for Synopsys DW Multimedia Card Interface
3 * driver
5 * Copyright (C) 2012, Samsung Electronics Co., Ltd.
6 * Copyright (C) 2013 Altera Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Taken from dw_mmc-exynos.c
15 #include <linux/clk.h>
16 #include <linux/mfd/syscon.h>
17 #include <linux/mmc/host.h>
18 #include <linux/mmc/dw_mmc.h>
19 #include <linux/module.h>
20 #include <linux/of.h>
21 #include <linux/platform_device.h>
22 #include <linux/regmap.h>
24 #include "dw_mmc.h"
25 #include "dw_mmc-pltfm.h"
27 #define SYSMGR_SDMMCGRP_CTRL_OFFSET 0x108
28 #define DRV_CLK_PHASE_SHIFT_SEL_MASK 0x7
29 #define SYSMGR_SDMMC_CTRL_SET(smplsel, drvsel) \
30 ((((smplsel) & 0x7) << 3) | (((drvsel) & 0x7) << 0))
32 /* SOCFPGA implementation specific driver private data */
33 struct dw_mci_socfpga_priv_data {
34 u8 ciu_div; /* card interface unit divisor */
35 u32 hs_timing; /* bitmask for CIU clock phase shift */
36 struct regmap *sysreg; /* regmap for system manager register */
39 static int dw_mci_socfpga_priv_init(struct dw_mci *host)
41 struct dw_mci_socfpga_priv_data *priv;
43 priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL);
44 if (!priv) {
45 dev_err(host->dev, "mem alloc failed for private data\n");
46 return -ENOMEM;
49 priv->sysreg = syscon_regmap_lookup_by_compatible("altr,sys-mgr");
50 if (IS_ERR(priv->sysreg)) {
51 dev_err(host->dev, "regmap for altr,sys-mgr lookup failed.\n");
52 return PTR_ERR(priv->sysreg);
54 host->priv = priv;
56 return 0;
59 static int dw_mci_socfpga_setup_clock(struct dw_mci *host)
61 struct dw_mci_socfpga_priv_data *priv = host->priv;
63 clk_disable_unprepare(host->ciu_clk);
64 regmap_write(priv->sysreg, SYSMGR_SDMMCGRP_CTRL_OFFSET,
65 priv->hs_timing);
66 clk_prepare_enable(host->ciu_clk);
68 host->bus_hz /= (priv->ciu_div + 1);
69 return 0;
72 static void dw_mci_socfpga_prepare_command(struct dw_mci *host, u32 *cmdr)
74 struct dw_mci_socfpga_priv_data *priv = host->priv;
76 if (priv->hs_timing & DRV_CLK_PHASE_SHIFT_SEL_MASK)
77 *cmdr |= SDMMC_CMD_USE_HOLD_REG;
80 static int dw_mci_socfpga_parse_dt(struct dw_mci *host)
82 struct dw_mci_socfpga_priv_data *priv = host->priv;
83 struct device_node *np = host->dev->of_node;
84 u32 timing[2];
85 u32 div = 0;
86 int ret;
88 ret = of_property_read_u32(np, "altr,dw-mshc-ciu-div", &div);
89 if (ret)
90 dev_info(host->dev, "No dw-mshc-ciu-div specified, assuming 1");
91 priv->ciu_div = div;
93 ret = of_property_read_u32_array(np,
94 "altr,dw-mshc-sdr-timing", timing, 2);
95 if (ret)
96 return ret;
98 priv->hs_timing = SYSMGR_SDMMC_CTRL_SET(timing[0], timing[1]);
99 return 0;
102 static const struct dw_mci_drv_data socfpga_drv_data = {
103 .init = dw_mci_socfpga_priv_init,
104 .setup_clock = dw_mci_socfpga_setup_clock,
105 .prepare_command = dw_mci_socfpga_prepare_command,
106 .parse_dt = dw_mci_socfpga_parse_dt,
109 static const struct of_device_id dw_mci_socfpga_match[] = {
110 { .compatible = "altr,socfpga-dw-mshc",
111 .data = &socfpga_drv_data, },
114 MODULE_DEVICE_TABLE(of, dw_mci_socfpga_match);
116 int dw_mci_socfpga_probe(struct platform_device *pdev)
118 const struct dw_mci_drv_data *drv_data;
119 const struct of_device_id *match;
121 match = of_match_node(dw_mci_socfpga_match, pdev->dev.of_node);
122 drv_data = match->data;
123 return dw_mci_pltfm_register(pdev, drv_data);
126 static struct platform_driver dw_mci_socfpga_pltfm_driver = {
127 .probe = dw_mci_socfpga_probe,
128 .remove = __exit_p(dw_mci_pltfm_remove),
129 .driver = {
130 .name = "dwmmc_socfpga",
131 .of_match_table = of_match_ptr(dw_mci_socfpga_match),
132 .pm = &dw_mci_pltfm_pmops,
136 module_platform_driver(dw_mci_socfpga_pltfm_driver);
138 MODULE_DESCRIPTION("Altera SOCFPGA Specific DW-MSHC Driver Extension");
139 MODULE_LICENSE("GPL v2");
140 MODULE_ALIAS("platform:dwmmc-socfpga");