15
15
#include <linux/err.h>
16
#include <linux/module.h>
16
17
#include <linux/init.h>
17
18
#include <linux/platform_device.h>
18
19
#include <linux/clk.h>
19
20
#include <linux/io.h>
22
#include <linux/of_gpio.h>
20
23
#include <linux/gpio.h>
21
24
#include <linux/mmc/card.h>
22
25
#include <linux/mmc/host.h>
24
#include <mach/gpio.h>
26
#include <linux/module.h>
30
#include <mach/gpio-tegra.h>
25
31
#include <mach/sdhci.h>
28
33
#include "sdhci-pltfm.h"
30
35
static u32 tegra_sdhci_readl(struct sdhci_host *host, int reg)
96
99
static int tegra_sdhci_8bit(struct sdhci_host *host, int bus_width)
98
struct platform_device *pdev = to_platform_device(mmc_dev(host->mmc));
99
struct tegra_sdhci_platform_data *plat;
101
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
102
struct tegra_sdhci_platform_data *plat = pltfm_host->priv;
102
plat = pdev->dev.platform_data;
104
105
ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
105
106
if (plat->is_8bit && bus_width == MMC_BUS_WIDTH_8) {
106
107
ctrl &= ~SDHCI_CTRL_4BITBUS;
120
static int tegra_sdhci_pltfm_init(struct sdhci_host *host,
121
struct sdhci_pltfm_data *pdata)
123
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
124
struct platform_device *pdev = to_platform_device(mmc_dev(host->mmc));
125
struct tegra_sdhci_platform_data *plat;
120
static struct sdhci_ops tegra_sdhci_ops = {
121
.get_ro = tegra_sdhci_get_ro,
122
.read_l = tegra_sdhci_readl,
123
.read_w = tegra_sdhci_readw,
124
.write_l = tegra_sdhci_writel,
125
.platform_8bit_width = tegra_sdhci_8bit,
128
static struct sdhci_pltfm_data sdhci_tegra_pdata = {
129
.quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
130
SDHCI_QUIRK_SINGLE_POWER_WRITE |
131
SDHCI_QUIRK_NO_HISPD_BIT |
132
SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC,
133
.ops = &tegra_sdhci_ops,
136
static const struct of_device_id sdhci_tegra_dt_match[] __devinitdata = {
137
{ .compatible = "nvidia,tegra20-sdhci", },
140
MODULE_DEVICE_TABLE(of, sdhci_dt_ids);
142
static struct tegra_sdhci_platform_data * __devinit sdhci_tegra_dt_parse_pdata(
143
struct platform_device *pdev)
145
struct tegra_sdhci_platform_data *plat;
146
struct device_node *np = pdev->dev.of_node;
151
plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
153
dev_err(&pdev->dev, "Can't allocate platform data\n");
157
plat->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0);
158
plat->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0);
159
plat->power_gpio = of_get_named_gpio(np, "power-gpios", 0);
160
if (of_find_property(np, "support-8bit", NULL))
166
static int __devinit sdhci_tegra_probe(struct platform_device *pdev)
168
struct sdhci_pltfm_host *pltfm_host;
169
struct tegra_sdhci_platform_data *plat;
170
struct sdhci_host *host;
174
host = sdhci_pltfm_init(pdev, &sdhci_tegra_pdata);
176
return PTR_ERR(host);
178
pltfm_host = sdhci_priv(host);
129
180
plat = pdev->dev.platform_data;
183
plat = sdhci_tegra_dt_parse_pdata(pdev);
130
185
if (plat == NULL) {
131
186
dev_err(mmc_dev(host->mmc), "missing platform data\n");
191
pltfm_host->priv = plat;
135
193
if (gpio_is_valid(plat->power_gpio)) {
136
194
rc = gpio_request(plat->power_gpio, "sdhci_power");
138
196
dev_err(mmc_dev(host->mmc),
139
197
"failed to allocate power gpio\n");
142
200
tegra_gpio_enable(plat->power_gpio);
143
201
gpio_direction_output(plat->power_gpio, 1);
189
247
if (plat->is_8bit)
190
248
host->mmc->caps |= MMC_CAP_8_BIT_DATA;
250
rc = sdhci_add_host(host);
257
clk_disable(pltfm_host->clk);
258
clk_put(pltfm_host->clk);
195
260
if (gpio_is_valid(plat->wp_gpio)) {
196
261
tegra_gpio_disable(plat->wp_gpio);
197
262
gpio_free(plat->wp_gpio);
201
265
if (gpio_is_valid(plat->cd_gpio))
202
266
free_irq(gpio_to_irq(plat->cd_gpio), host);
204
268
if (gpio_is_valid(plat->cd_gpio)) {
205
269
tegra_gpio_disable(plat->cd_gpio);
206
270
gpio_free(plat->cd_gpio);
210
273
if (gpio_is_valid(plat->power_gpio)) {
211
274
tegra_gpio_disable(plat->power_gpio);
212
275
gpio_free(plat->power_gpio);
279
sdhci_pltfm_free(pdev);
219
static void tegra_sdhci_pltfm_exit(struct sdhci_host *host)
283
static int __devexit sdhci_tegra_remove(struct platform_device *pdev)
285
struct sdhci_host *host = platform_get_drvdata(pdev);
221
286
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
222
struct platform_device *pdev = to_platform_device(mmc_dev(host->mmc));
223
struct tegra_sdhci_platform_data *plat;
287
struct tegra_sdhci_platform_data *plat = pltfm_host->priv;
288
int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
225
plat = pdev->dev.platform_data;
290
sdhci_remove_host(host, dead);
227
292
if (gpio_is_valid(plat->wp_gpio)) {
228
293
tegra_gpio_disable(plat->wp_gpio);
243
308
clk_disable(pltfm_host->clk);
244
309
clk_put(pltfm_host->clk);
247
static struct sdhci_ops tegra_sdhci_ops = {
248
.get_ro = tegra_sdhci_get_ro,
249
.read_l = tegra_sdhci_readl,
250
.read_w = tegra_sdhci_readw,
251
.write_l = tegra_sdhci_writel,
252
.platform_8bit_width = tegra_sdhci_8bit,
255
struct sdhci_pltfm_data sdhci_tegra_pdata = {
256
.quirks = SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
257
SDHCI_QUIRK_SINGLE_POWER_WRITE |
258
SDHCI_QUIRK_NO_HISPD_BIT |
259
SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC,
260
.ops = &tegra_sdhci_ops,
261
.init = tegra_sdhci_pltfm_init,
262
.exit = tegra_sdhci_pltfm_exit,
311
sdhci_pltfm_free(pdev);
316
static struct platform_driver sdhci_tegra_driver = {
318
.name = "sdhci-tegra",
319
.owner = THIS_MODULE,
320
.of_match_table = sdhci_tegra_dt_match,
322
.probe = sdhci_tegra_probe,
323
.remove = __devexit_p(sdhci_tegra_remove),
325
.suspend = sdhci_pltfm_suspend,
326
.resume = sdhci_pltfm_resume,
330
static int __init sdhci_tegra_init(void)
332
return platform_driver_register(&sdhci_tegra_driver);
334
module_init(sdhci_tegra_init);
336
static void __exit sdhci_tegra_exit(void)
338
platform_driver_unregister(&sdhci_tegra_driver);
340
module_exit(sdhci_tegra_exit);
342
MODULE_DESCRIPTION("SDHCI driver for Tegra");
343
MODULE_AUTHOR(" Google, Inc.");
344
MODULE_LICENSE("GPL v2");