blob: 4af64f32c6d1e84606eccae9eede04e2a8321845 [file] [log] [blame]
Mike Rapoport985b1aa2010-11-07 16:57:12 -05001/*
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
Russell King - ARM Linuxee3298a2012-10-29 21:43:07 +000022#include <linux/err.h>
Mike Rapoport985b1aa2010-11-07 16:57:12 -050023#include <linux/io.h>
Sebastian Hesselbarth30b87c62012-07-05 12:14:01 +020024#include <linux/clk.h>
25#include <linux/err.h>
Alf Høgemark8c2fc8e2012-04-04 12:27:09 -040026#include <linux/module.h>
Mike Rapoport985b1aa2010-11-07 16:57:12 -050027#include <linux/mmc/host.h>
Sebastian Hesselbarth4ee7ed02012-07-31 10:12:59 +020028#include <linux/of.h>
Mike Rapoport985b1aa2010-11-07 16:57:12 -050029
Mike Rapoport985b1aa2010-11-07 16:57:12 -050030#include "sdhci-pltfm.h"
31
Sebastian Hesselbarth30b87c62012-07-05 12:14:01 +020032struct sdhci_dove_priv {
33 struct clk *clk;
34};
35
Mike Rapoport985b1aa2010-11-07 16:57:12 -050036static u16 sdhci_dove_readw(struct sdhci_host *host, int reg)
37{
38 u16 ret;
39
40 switch (reg) {
41 case SDHCI_HOST_VERSION:
42 case SDHCI_SLOT_INT_STATUS:
43 /* those registers don't exist */
44 return 0;
45 default:
46 ret = readw(host->ioaddr + reg);
47 }
48 return ret;
49}
50
51static u32 sdhci_dove_readl(struct sdhci_host *host, int reg)
52{
53 u32 ret;
54
55 switch (reg) {
56 case SDHCI_CAPABILITIES:
57 ret = readl(host->ioaddr + reg);
58 /* Mask the support for 3.0V */
59 ret &= ~SDHCI_CAN_VDD_300;
60 break;
61 default:
62 ret = readl(host->ioaddr + reg);
63 }
64 return ret;
65}
66
67static struct sdhci_ops sdhci_dove_ops = {
68 .read_w = sdhci_dove_readw,
69 .read_l = sdhci_dove_readl,
70};
71
Shawn Guo85d65092011-05-27 23:48:12 +080072static struct sdhci_pltfm_data sdhci_dove_pdata = {
Mike Rapoport985b1aa2010-11-07 16:57:12 -050073 .ops = &sdhci_dove_ops,
74 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
75 SDHCI_QUIRK_NO_BUSY_IRQ |
76 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
Sebastian Hesselbartha9ca1d52012-07-21 19:26:19 -040077 SDHCI_QUIRK_FORCE_DMA |
78 SDHCI_QUIRK_NO_HISPD_BIT,
Mike Rapoport985b1aa2010-11-07 16:57:12 -050079};
Shawn Guo85d65092011-05-27 23:48:12 +080080
81static int __devinit sdhci_dove_probe(struct platform_device *pdev)
82{
Sebastian Hesselbarth30b87c62012-07-05 12:14:01 +020083 struct sdhci_host *host;
84 struct sdhci_pltfm_host *pltfm_host;
85 struct sdhci_dove_priv *priv;
86 int ret;
87
Sebastian Hesselbarth30b87c62012-07-05 12:14:01 +020088 priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_dove_priv),
89 GFP_KERNEL);
90 if (!priv) {
91 dev_err(&pdev->dev, "unable to allocate private data");
Russell King - ARM Linuxee3298a2012-10-29 21:43:07 +000092 return -ENOMEM;
Sebastian Hesselbarth30b87c62012-07-05 12:14:01 +020093 }
94
Russell King7430e772012-11-22 23:55:10 +000095 priv->clk = devm_clk_get(&pdev->dev, NULL);
Russell King - ARM Linuxee3298a2012-10-29 21:43:07 +000096
Russell Kingc4306892012-11-22 23:55:30 +000097 host = sdhci_pltfm_init(pdev, &sdhci_dove_pdata);
98 if (IS_ERR(host)) {
99 ret = PTR_ERR(host);
100 goto err_sdhci_pltfm_init;
101 }
Russell King - ARM Linuxee3298a2012-10-29 21:43:07 +0000102
Sebastian Hesselbarth30b87c62012-07-05 12:14:01 +0200103 pltfm_host = sdhci_priv(host);
104 pltfm_host->priv = priv;
105
Russell Kingc4306892012-11-22 23:55:30 +0000106 if (!IS_ERR(priv->clk))
107 clk_prepare_enable(priv->clk);
108
109 sdhci_get_of_property(pdev);
110
111 ret = sdhci_add_host(host);
112 if (ret)
113 goto err_sdhci_add;
114
Sebastian Hesselbarth30b87c62012-07-05 12:14:01 +0200115 return 0;
116
Russell Kingc4306892012-11-22 23:55:30 +0000117err_sdhci_add:
Russell King7430e772012-11-22 23:55:10 +0000118 if (!IS_ERR(priv->clk))
Russell King - ARM Linuxee3298a2012-10-29 21:43:07 +0000119 clk_disable_unprepare(priv->clk);
Russell Kingc4306892012-11-22 23:55:30 +0000120 sdhci_pltfm_free(pdev);
121err_sdhci_pltfm_init:
Sebastian Hesselbarth30b87c62012-07-05 12:14:01 +0200122 return ret;
Shawn Guo85d65092011-05-27 23:48:12 +0800123}
124
125static int __devexit sdhci_dove_remove(struct platform_device *pdev)
126{
Sebastian Hesselbarth30b87c62012-07-05 12:14:01 +0200127 struct sdhci_host *host = platform_get_drvdata(pdev);
128 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
129 struct sdhci_dove_priv *priv = pltfm_host->priv;
130
Russell King - ARM Linuxee3298a2012-10-29 21:43:07 +0000131 sdhci_pltfm_unregister(pdev);
132
Russell King7430e772012-11-22 23:55:10 +0000133 if (!IS_ERR(priv->clk))
Russell King - ARM Linuxee3298a2012-10-29 21:43:07 +0000134 clk_disable_unprepare(priv->clk);
Russell King7430e772012-11-22 23:55:10 +0000135
Russell King - ARM Linuxee3298a2012-10-29 21:43:07 +0000136 return 0;
Shawn Guo85d65092011-05-27 23:48:12 +0800137}
138
Sebastian Hesselbarth4ee7ed02012-07-31 10:12:59 +0200139static const struct of_device_id sdhci_dove_of_match_table[] __devinitdata = {
140 { .compatible = "marvell,dove-sdhci", },
141 {}
142};
143MODULE_DEVICE_TABLE(of, sdhci_dove_of_match_table);
144
Shawn Guo85d65092011-05-27 23:48:12 +0800145static struct platform_driver sdhci_dove_driver = {
146 .driver = {
147 .name = "sdhci-dove",
148 .owner = THIS_MODULE,
Manuel Lauss29495aa2011-11-03 11:09:45 +0100149 .pm = SDHCI_PLTFM_PMOPS,
Sebastian Hesselbarth4ee7ed02012-07-31 10:12:59 +0200150 .of_match_table = of_match_ptr(sdhci_dove_of_match_table),
Shawn Guo85d65092011-05-27 23:48:12 +0800151 },
152 .probe = sdhci_dove_probe,
153 .remove = __devexit_p(sdhci_dove_remove),
Shawn Guo85d65092011-05-27 23:48:12 +0800154};
155
Axel Lind1f81a62011-11-26 12:55:43 +0800156module_platform_driver(sdhci_dove_driver);
Shawn Guo85d65092011-05-27 23:48:12 +0800157
158MODULE_DESCRIPTION("SDHCI driver for Dove");
159MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>, "
160 "Mike Rapoport <mike@compulab.co.il>");
161MODULE_LICENSE("GPL v2");