aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
authorGeorgi Djakov <gdjakov@mm-sol.com>2014-03-10 11:37:12 -0400
committerChris Ball <chris@printf.net>2014-03-26 21:27:30 -0400
commit0eb0d9f4de34a7702974807e2107a49c6c6e2daa (patch)
tree8b96ef7294acac763466752973989aab21490372 /drivers/mmc
parentd2529500813c77db1d0fc9d23da0de05486859d8 (diff)
mmc: sdhci-msm: Initial support for Qualcomm chipsets
This platform driver adds the initial support of Secure Digital Host Controller Interface compliant controller found in Qualcomm chipsets. Signed-off-by: Asutosh Das <asutoshd@codeaurora.org> Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org> Tested-by: Ivan T. Ivanov <iivanov@mm-sol.com> Signed-off-by: Georgi Djakov <gdjakov@mm-sol.com> Acked-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Chris Ball <chris@printf.net>
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/host/Kconfig13
-rw-r--r--drivers/mmc/host/Makefile1
-rw-r--r--drivers/mmc/host/sdhci-msm.c208
3 files changed, 222 insertions, 0 deletions
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 8555a7afa056..8aaf8c1f3f63 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -334,6 +334,19 @@ config MMC_ATMELMCI
334 334
335 If unsure, say N. 335 If unsure, say N.
336 336
337config MMC_SDHCI_MSM
338 tristate "Qualcomm SDHCI Controller Support"
339 depends on ARCH_QCOM
340 depends on MMC_SDHCI_PLTFM
341 help
342 This selects the Secure Digital Host Controller Interface (SDHCI)
343 support present in Qualcomm SOCs. The controller supports
344 SD/MMC/SDIO devices.
345
346 If you have a controller with this interface, say Y or M here.
347
348 If unsure, say N.
349
337config MMC_MSM 350config MMC_MSM
338 tristate "Qualcomm SDCC Controller Support" 351 tristate "Qualcomm SDCC Controller Support"
339 depends on MMC && (ARCH_MSM7X00A || ARCH_MSM7X30 || ARCH_QSD8X50) 352 depends on MMC && (ARCH_MSM7X00A || ARCH_MSM7X30 || ARCH_QSD8X50)
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index f162f87a049c..0c8aa5e1e304 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -63,6 +63,7 @@ obj-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o
63obj-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o 63obj-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o
64obj-$(CONFIG_MMC_SDHCI_BCM_KONA) += sdhci-bcm-kona.o 64obj-$(CONFIG_MMC_SDHCI_BCM_KONA) += sdhci-bcm-kona.o
65obj-$(CONFIG_MMC_SDHCI_BCM2835) += sdhci-bcm2835.o 65obj-$(CONFIG_MMC_SDHCI_BCM2835) += sdhci-bcm2835.o
66obj-$(CONFIG_MMC_SDHCI_MSM) += sdhci-msm.o
66 67
67ifeq ($(CONFIG_CB710_DEBUG),y) 68ifeq ($(CONFIG_CB710_DEBUG),y)
68 CFLAGS-cb710-mmc += -DDEBUG 69 CFLAGS-cb710-mmc += -DDEBUG
diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
new file mode 100644
index 000000000000..3b0606fe6891
--- /dev/null
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -0,0 +1,208 @@
1/*
2 * drivers/mmc/host/sdhci-msm.c - Qualcomm SDHCI Platform driver
3 *
4 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
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 version 2 and
8 * only version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/of_device.h>
19#include <linux/regulator/consumer.h>
20#include <linux/delay.h>
21
22#include "sdhci-pltfm.h"
23
24#define CORE_HC_MODE 0x78
25#define HC_MODE_EN 0x1
26#define CORE_POWER 0x0
27#define CORE_SW_RST BIT(7)
28
29
30struct sdhci_msm_host {
31 struct platform_device *pdev;
32 void __iomem *core_mem; /* MSM SDCC mapped address */
33 struct clk *clk; /* main SD/MMC bus clock */
34 struct clk *pclk; /* SDHC peripheral bus clock */
35 struct clk *bus_clk; /* SDHC bus voter clock */
36 struct mmc_host *mmc;
37 struct sdhci_pltfm_data sdhci_msm_pdata;
38};
39
40/* Platform specific tuning */
41static int sdhci_msm_execute_tuning(struct sdhci_host *host, u32 opcode)
42{
43 /*
44 * Tuning is required for SDR104, HS200 and HS400 cards and if the clock
45 * frequency greater than 100MHz in those modes. The standard tuning
46 * procedure should not be executed, but a custom implementation will be
47 * added here instead.
48 */
49 return 0;
50}
51
52static const struct of_device_id sdhci_msm_dt_match[] = {
53 { .compatible = "qcom,sdhci-msm-v4" },
54 {},
55};
56
57MODULE_DEVICE_TABLE(of, sdhci_msm_dt_match);
58
59static struct sdhci_ops sdhci_msm_ops = {
60 .platform_execute_tuning = sdhci_msm_execute_tuning,
61};
62
63static int sdhci_msm_probe(struct platform_device *pdev)
64{
65 struct sdhci_host *host;
66 struct sdhci_pltfm_host *pltfm_host;
67 struct sdhci_msm_host *msm_host;
68 struct resource *core_memres;
69 int ret;
70 u16 host_version;
71
72 msm_host = devm_kzalloc(&pdev->dev, sizeof(*msm_host), GFP_KERNEL);
73 if (!msm_host)
74 return -ENOMEM;
75
76 msm_host->sdhci_msm_pdata.ops = &sdhci_msm_ops;
77 host = sdhci_pltfm_init(pdev, &msm_host->sdhci_msm_pdata, 0);
78 if (IS_ERR(host))
79 return PTR_ERR(host);
80
81 pltfm_host = sdhci_priv(host);
82 pltfm_host->priv = msm_host;
83 msm_host->mmc = host->mmc;
84 msm_host->pdev = pdev;
85
86 ret = mmc_of_parse(host->mmc);
87 if (ret)
88 goto pltfm_free;
89
90 sdhci_get_of_property(pdev);
91
92 /* Setup SDCC bus voter clock. */
93 msm_host->bus_clk = devm_clk_get(&pdev->dev, "bus");
94 if (!IS_ERR(msm_host->bus_clk)) {
95 /* Vote for max. clk rate for max. performance */
96 ret = clk_set_rate(msm_host->bus_clk, INT_MAX);
97 if (ret)
98 goto pltfm_free;
99 ret = clk_prepare_enable(msm_host->bus_clk);
100 if (ret)
101 goto pltfm_free;
102 }
103
104 /* Setup main peripheral bus clock */
105 msm_host->pclk = devm_clk_get(&pdev->dev, "iface");
106 if (IS_ERR(msm_host->pclk)) {
107 ret = PTR_ERR(msm_host->pclk);
108 dev_err(&pdev->dev, "Perpheral clk setup failed (%d)\n", ret);
109 goto bus_clk_disable;
110 }
111
112 ret = clk_prepare_enable(msm_host->pclk);
113 if (ret)
114 goto bus_clk_disable;
115
116 /* Setup SDC MMC clock */
117 msm_host->clk = devm_clk_get(&pdev->dev, "core");
118 if (IS_ERR(msm_host->clk)) {
119 ret = PTR_ERR(msm_host->clk);
120 dev_err(&pdev->dev, "SDC MMC clk setup failed (%d)\n", ret);
121 goto pclk_disable;
122 }
123
124 ret = clk_prepare_enable(msm_host->clk);
125 if (ret)
126 goto pclk_disable;
127
128 core_memres = platform_get_resource(pdev, IORESOURCE_MEM, 1);
129 msm_host->core_mem = devm_ioremap_resource(&pdev->dev, core_memres);
130
131 if (IS_ERR(msm_host->core_mem)) {
132 dev_err(&pdev->dev, "Failed to remap registers\n");
133 ret = PTR_ERR(msm_host->core_mem);
134 goto clk_disable;
135 }
136
137 /* Reset the core and Enable SDHC mode */
138 writel_relaxed(readl_relaxed(msm_host->core_mem + CORE_POWER) |
139 CORE_SW_RST, msm_host->core_mem + CORE_POWER);
140
141 /* SW reset can take upto 10HCLK + 15MCLK cycles. (min 40us) */
142 usleep_range(1000, 5000);
143 if (readl(msm_host->core_mem + CORE_POWER) & CORE_SW_RST) {
144 dev_err(&pdev->dev, "Stuck in reset\n");
145 ret = -ETIMEDOUT;
146 goto clk_disable;
147 }
148
149 /* Set HC_MODE_EN bit in HC_MODE register */
150 writel_relaxed(HC_MODE_EN, (msm_host->core_mem + CORE_HC_MODE));
151
152 host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION;
153 host->quirks |= SDHCI_QUIRK_SINGLE_POWER_WRITE;
154
155 host_version = readw_relaxed((host->ioaddr + SDHCI_HOST_VERSION));
156 dev_dbg(&pdev->dev, "Host Version: 0x%x Vendor Version 0x%x\n",
157 host_version, ((host_version & SDHCI_VENDOR_VER_MASK) >>
158 SDHCI_VENDOR_VER_SHIFT));
159
160 ret = sdhci_add_host(host);
161 if (ret)
162 goto clk_disable;
163
164 return 0;
165
166clk_disable:
167 clk_disable_unprepare(msm_host->clk);
168pclk_disable:
169 clk_disable_unprepare(msm_host->pclk);
170bus_clk_disable:
171 if (!IS_ERR(msm_host->bus_clk))
172 clk_disable_unprepare(msm_host->bus_clk);
173pltfm_free:
174 sdhci_pltfm_free(pdev);
175 return ret;
176}
177
178static int sdhci_msm_remove(struct platform_device *pdev)
179{
180 struct sdhci_host *host = platform_get_drvdata(pdev);
181 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
182 struct sdhci_msm_host *msm_host = pltfm_host->priv;
183 int dead = (readl_relaxed(host->ioaddr + SDHCI_INT_STATUS) ==
184 0xffffffff);
185
186 sdhci_remove_host(host, dead);
187 sdhci_pltfm_free(pdev);
188 clk_disable_unprepare(msm_host->clk);
189 clk_disable_unprepare(msm_host->pclk);
190 if (!IS_ERR(msm_host->bus_clk))
191 clk_disable_unprepare(msm_host->bus_clk);
192 return 0;
193}
194
195static struct platform_driver sdhci_msm_driver = {
196 .probe = sdhci_msm_probe,
197 .remove = sdhci_msm_remove,
198 .driver = {
199 .name = "sdhci_msm",
200 .owner = THIS_MODULE,
201 .of_match_table = sdhci_msm_dt_match,
202 },
203};
204
205module_platform_driver(sdhci_msm_driver);
206
207MODULE_DESCRIPTION("Qualcomm Secure Digital Host Controller Interface driver");
208MODULE_LICENSE("GPL v2");