mmc: sdhci-dove: Prepare for common clock framework
[deliverable/linux.git] / drivers / mmc / host / sdhci-dove.c
CommitLineData
985b1aa0
MR
1/*
2 * sdhci-dove.c Support for SDHCI on Marvell's Dove SoC
3 *
4 * Author: Saeed Bishara <saeed@marvell.com>
5 * Mike Rapoport <mike@compulab.co.il>
6 * Based on sdhci-cns3xxx.c
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/io.h>
30b87c60
SH
23#include <linux/clk.h>
24#include <linux/err.h>
8c2fc8e4 25#include <linux/module.h>
985b1aa0
MR
26#include <linux/mmc/host.h>
27
985b1aa0
MR
28#include "sdhci-pltfm.h"
29
30b87c60
SH
30struct sdhci_dove_priv {
31 struct clk *clk;
32};
33
985b1aa0
MR
34static u16 sdhci_dove_readw(struct sdhci_host *host, int reg)
35{
36 u16 ret;
37
38 switch (reg) {
39 case SDHCI_HOST_VERSION:
40 case SDHCI_SLOT_INT_STATUS:
41 /* those registers don't exist */
42 return 0;
43 default:
44 ret = readw(host->ioaddr + reg);
45 }
46 return ret;
47}
48
49static u32 sdhci_dove_readl(struct sdhci_host *host, int reg)
50{
51 u32 ret;
52
53 switch (reg) {
54 case SDHCI_CAPABILITIES:
55 ret = readl(host->ioaddr + reg);
56 /* Mask the support for 3.0V */
57 ret &= ~SDHCI_CAN_VDD_300;
58 break;
59 default:
60 ret = readl(host->ioaddr + reg);
61 }
62 return ret;
63}
64
65static struct sdhci_ops sdhci_dove_ops = {
66 .read_w = sdhci_dove_readw,
67 .read_l = sdhci_dove_readl,
68};
69
85d6509d 70static struct sdhci_pltfm_data sdhci_dove_pdata = {
985b1aa0
MR
71 .ops = &sdhci_dove_ops,
72 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
73 SDHCI_QUIRK_NO_BUSY_IRQ |
74 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
a9ca1d54
SH
75 SDHCI_QUIRK_FORCE_DMA |
76 SDHCI_QUIRK_NO_HISPD_BIT,
985b1aa0 77};
85d6509d
SG
78
79static int __devinit sdhci_dove_probe(struct platform_device *pdev)
80{
30b87c60
SH
81 struct sdhci_host *host;
82 struct sdhci_pltfm_host *pltfm_host;
83 struct sdhci_dove_priv *priv;
84 int ret;
85
86 ret = sdhci_pltfm_register(pdev, &sdhci_dove_pdata);
87 if (ret)
88 goto sdhci_dove_register_fail;
89
90 priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_dove_priv),
91 GFP_KERNEL);
92 if (!priv) {
93 dev_err(&pdev->dev, "unable to allocate private data");
94 ret = -ENOMEM;
95 goto sdhci_dove_allocate_fail;
96 }
97
98 host = platform_get_drvdata(pdev);
99 pltfm_host = sdhci_priv(host);
100 pltfm_host->priv = priv;
101
102 priv->clk = clk_get(&pdev->dev, NULL);
103 if (!IS_ERR(priv->clk))
104 clk_prepare_enable(priv->clk);
105 return 0;
106
107sdhci_dove_allocate_fail:
108 sdhci_pltfm_unregister(pdev);
109sdhci_dove_register_fail:
110 return ret;
85d6509d
SG
111}
112
113static int __devexit sdhci_dove_remove(struct platform_device *pdev)
114{
30b87c60
SH
115 struct sdhci_host *host = platform_get_drvdata(pdev);
116 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
117 struct sdhci_dove_priv *priv = pltfm_host->priv;
118
119 if (priv->clk) {
120 if (!IS_ERR(priv->clk)) {
121 clk_disable_unprepare(priv->clk);
122 clk_put(priv->clk);
123 }
124 devm_kfree(&pdev->dev, priv->clk);
125 }
85d6509d
SG
126 return sdhci_pltfm_unregister(pdev);
127}
128
129static struct platform_driver sdhci_dove_driver = {
130 .driver = {
131 .name = "sdhci-dove",
132 .owner = THIS_MODULE,
29495aa0 133 .pm = SDHCI_PLTFM_PMOPS,
85d6509d
SG
134 },
135 .probe = sdhci_dove_probe,
136 .remove = __devexit_p(sdhci_dove_remove),
85d6509d
SG
137};
138
d1f81a64 139module_platform_driver(sdhci_dove_driver);
85d6509d
SG
140
141MODULE_DESCRIPTION("SDHCI driver for Dove");
142MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>, "
143 "Mike Rapoport <mike@compulab.co.il>");
144MODULE_LICENSE("GPL v2");
This page took 0.127589 seconds and 5 git commands to generate.