2 * Synopsys DesignWare Multimedia Card Interface driver
4 * Copyright (C) 2009 NXP Semiconductors
5 * Copyright (C) 2009, 2010 Imagination Technologies Ltd.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
13 #include <linux/err.h>
14 #include <linux/interrupt.h>
15 #include <linux/module.h>
17 #include <linux/irq.h>
18 #include <linux/platform_device.h>
19 #include <linux/slab.h>
20 #include <linux/mmc/host.h>
21 #include <linux/mmc/mmc.h>
22 #include <linux/mmc/dw_mmc.h>
24 #include <linux/clk.h>
27 #include "dw_mmc-pltfm.h"
29 #define RK3288_CLKGEN_DIV 2
31 static void dw_mci_pltfm_prepare_command(struct dw_mci *host, u32 *cmdr)
33 *cmdr |= SDMMC_CMD_USE_HOLD_REG;
36 static int dw_mci_rk3288_setup_clock(struct dw_mci *host)
38 host->bus_hz /= RK3288_CLKGEN_DIV;
43 static void dw_mci_rk3288_set_ios(struct dw_mci *host, struct mmc_ios *ios)
50 * cclkin: source clock of mmc controller.
51 * bus_hz: card interface clock generated by CLKGEN.
52 * bus_hz = cclkin / RK3288_CLKGEN_DIV;
53 * ios->clock = (div == 0) ? bus_hz : (bus_hz / (2 * div))
55 * Note: div can only be 0 or 1
56 * if DDR50 8bit mode(only emmc work in 8bit mode),
59 if ((ios->bus_width == MMC_BUS_WIDTH_8) &&
60 (ios->timing == MMC_TIMING_MMC_DDR52))
61 cclkin = 2 * ios->clock * RK3288_CLKGEN_DIV;
63 cclkin = ios->clock * RK3288_CLKGEN_DIV;
65 ret = clk_set_rate(host->ciu_clk, cclkin);
67 dev_warn(host->dev, "failed to set rate %uHz\n", ios->clock);
69 bus_hz = clk_get_rate(host->ciu_clk) / RK3288_CLKGEN_DIV;
70 if (bus_hz != host->bus_hz) {
71 host->bus_hz = bus_hz;
72 /* force dw_mci_setup_bus() */
73 host->current_speed = 0;
77 static const struct dw_mci_drv_data rk2928_drv_data = {
78 .prepare_command = dw_mci_pltfm_prepare_command,
81 static const struct dw_mci_drv_data rk3288_drv_data = {
82 .prepare_command = dw_mci_pltfm_prepare_command,
83 .set_ios = dw_mci_rk3288_set_ios,
84 .setup_clock = dw_mci_rk3288_setup_clock,
87 static const struct dw_mci_drv_data socfpga_drv_data = {
88 .prepare_command = dw_mci_pltfm_prepare_command,
91 int dw_mci_pltfm_register(struct platform_device *pdev,
92 const struct dw_mci_drv_data *drv_data)
95 struct resource *regs;
97 host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL);
101 host->irq = platform_get_irq(pdev, 0);
105 host->drv_data = drv_data;
106 host->dev = &pdev->dev;
108 host->pdata = pdev->dev.platform_data;
110 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
111 host->regs = devm_ioremap_resource(&pdev->dev, regs);
112 if (IS_ERR(host->regs))
113 return PTR_ERR(host->regs);
115 platform_set_drvdata(pdev, host);
116 return dw_mci_probe(host);
118 EXPORT_SYMBOL_GPL(dw_mci_pltfm_register);
120 #ifdef CONFIG_PM_SLEEP
122 * TODO: we should probably disable the clock to the card in the suspend path.
124 static int dw_mci_pltfm_suspend(struct device *dev)
126 struct dw_mci *host = dev_get_drvdata(dev);
128 return dw_mci_suspend(host);
131 static int dw_mci_pltfm_resume(struct device *dev)
133 struct dw_mci *host = dev_get_drvdata(dev);
135 return dw_mci_resume(host);
138 #define dw_mci_pltfm_suspend NULL
139 #define dw_mci_pltfm_resume NULL
140 #endif /* CONFIG_PM_SLEEP */
142 SIMPLE_DEV_PM_OPS(dw_mci_pltfm_pmops, dw_mci_pltfm_suspend, dw_mci_pltfm_resume);
143 EXPORT_SYMBOL_GPL(dw_mci_pltfm_pmops);
145 static const struct of_device_id dw_mci_pltfm_match[] = {
146 { .compatible = "snps,dw-mshc", },
147 { .compatible = "rockchip,rk2928-dw-mshc",
148 .data = &rk2928_drv_data },
149 { .compatible = "rockchip,rk3288-dw-mshc",
150 .data = &rk3288_drv_data },
151 { .compatible = "altr,socfpga-dw-mshc",
152 .data = &socfpga_drv_data },
155 MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match);
157 static int dw_mci_pltfm_probe(struct platform_device *pdev)
159 const struct dw_mci_drv_data *drv_data = NULL;
160 const struct of_device_id *match;
162 if (pdev->dev.of_node) {
163 match = of_match_node(dw_mci_pltfm_match, pdev->dev.of_node);
164 drv_data = match->data;
167 return dw_mci_pltfm_register(pdev, drv_data);
170 int dw_mci_pltfm_remove(struct platform_device *pdev)
172 struct dw_mci *host = platform_get_drvdata(pdev);
177 EXPORT_SYMBOL_GPL(dw_mci_pltfm_remove);
179 static struct platform_driver dw_mci_pltfm_driver = {
180 .probe = dw_mci_pltfm_probe,
181 .remove = dw_mci_pltfm_remove,
184 .of_match_table = dw_mci_pltfm_match,
185 .pm = &dw_mci_pltfm_pmops,
189 module_platform_driver(dw_mci_pltfm_driver);
191 MODULE_DESCRIPTION("DW Multimedia Card Interface driver");
192 MODULE_AUTHOR("NXP Semiconductor VietNam");
193 MODULE_AUTHOR("Imagination Technologies Ltd");
194 MODULE_LICENSE("GPL v2");