Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sdhci-dove.c
Go to the documentation of this file.
1 /*
2  * sdhci-dove.c Support for SDHCI on Marvell's Dove SoC
3  *
4  * Author: Saeed Bishara <[email protected]>
5  * Mike Rapoport <[email protected]>
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/err.h>
23 #include <linux/io.h>
24 #include <linux/clk.h>
25 #include <linux/err.h>
26 #include <linux/module.h>
27 #include <linux/mmc/host.h>
28 #include <linux/of.h>
29 
30 #include "sdhci-pltfm.h"
31 
33  struct clk *clk;
34 };
35 
36 static u16 sdhci_dove_readw(struct sdhci_host *host, int reg)
37 {
38  u16 ret;
39 
40  switch (reg) {
41  case SDHCI_HOST_VERSION:
43  /* those registers don't exist */
44  return 0;
45  default:
46  ret = readw(host->ioaddr + reg);
47  }
48  return ret;
49 }
50 
51 static 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 
67 static struct sdhci_ops sdhci_dove_ops = {
68  .read_w = sdhci_dove_readw,
69  .read_l = sdhci_dove_readl,
70 };
71 
72 static struct sdhci_pltfm_data sdhci_dove_pdata = {
73  .ops = &sdhci_dove_ops,
79 };
80 
81 static int __devinit sdhci_dove_probe(struct platform_device *pdev)
82 {
83  struct sdhci_host *host;
84  struct sdhci_pltfm_host *pltfm_host;
85  struct sdhci_dove_priv *priv;
86  int ret;
87 
88  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");
92  return -ENOMEM;
93  }
94 
95  priv->clk = clk_get(&pdev->dev, NULL);
96  if (!IS_ERR(priv->clk))
97  clk_prepare_enable(priv->clk);
98 
99  ret = sdhci_pltfm_register(pdev, &sdhci_dove_pdata);
100  if (ret)
101  goto sdhci_dove_register_fail;
102 
103  host = platform_get_drvdata(pdev);
104  pltfm_host = sdhci_priv(host);
105  pltfm_host->priv = priv;
106 
107  return 0;
108 
109 sdhci_dove_register_fail:
110  if (!IS_ERR(priv->clk)) {
111  clk_disable_unprepare(priv->clk);
112  clk_put(priv->clk);
113  }
114  return ret;
115 }
116 
117 static int __devexit sdhci_dove_remove(struct platform_device *pdev)
118 {
119  struct sdhci_host *host = platform_get_drvdata(pdev);
120  struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
121  struct sdhci_dove_priv *priv = pltfm_host->priv;
122 
124 
125  if (!IS_ERR(priv->clk)) {
126  clk_disable_unprepare(priv->clk);
127  clk_put(priv->clk);
128  }
129  return 0;
130 }
131 
132 static const struct of_device_id sdhci_dove_of_match_table[] __devinitdata = {
133  { .compatible = "marvell,dove-sdhci", },
134  {}
135 };
136 MODULE_DEVICE_TABLE(of, sdhci_dove_of_match_table);
137 
138 static struct platform_driver sdhci_dove_driver = {
139  .driver = {
140  .name = "sdhci-dove",
141  .owner = THIS_MODULE,
142  .pm = SDHCI_PLTFM_PMOPS,
143  .of_match_table = of_match_ptr(sdhci_dove_of_match_table),
144  },
145  .probe = sdhci_dove_probe,
146  .remove = __devexit_p(sdhci_dove_remove),
147 };
148 
149 module_platform_driver(sdhci_dove_driver);
150 
151 MODULE_DESCRIPTION("SDHCI driver for Dove");
152 MODULE_AUTHOR("Saeed Bishara <[email protected]>, "
153  "Mike Rapoport <[email protected]>");
154 MODULE_LICENSE("GPL v2");