blob: 497f91b6138edc4dba97ff82c9c1845a83ca6454 [file] [log] [blame]
Magnus Damma87d5632009-10-02 02:22:09 +00001/*
2 * SuperH Mobile SDHI
3 *
4 * Copyright (C) 2009 Magnus Damm
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 as
8 * published by the Free Software Foundation.
9 *
10 * Based on "Compaq ASIC3 support":
11 *
12 * Copyright 2001 Compaq Computer Corporation.
13 * Copyright 2004-2005 Phil Blundell
14 * Copyright 2007-2008 OpenedHand Ltd.
15 *
16 * Authors: Phil Blundell <pb@handhelds.org>,
17 * Samuel Ortiz <sameo@openedhand.com>
18 *
19 */
20
21#include <linux/kernel.h>
22#include <linux/clk.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Magnus Damma87d5632009-10-02 02:22:09 +000024#include <linux/platform_device.h>
Magnus Damm3c49e812010-02-22 13:37:09 +090025#include <linux/mmc/host.h>
Magnus Damma87d5632009-10-02 02:22:09 +000026#include <linux/mfd/core.h>
27#include <linux/mfd/tmio.h>
Magnus Dammbe9cd7b2009-11-27 04:31:27 +000028#include <linux/mfd/sh_mobile_sdhi.h>
Magnus Damma87d5632009-10-02 02:22:09 +000029
30struct sh_mobile_sdhi {
31 struct clk *clk;
32 struct tmio_mmc_data mmc_data;
33 struct mfd_cell cell_mmc;
34};
35
36static struct resource sh_mobile_sdhi_resources[] = {
37 {
38 .start = 0x000,
39 .end = 0x1ff,
40 .flags = IORESOURCE_MEM,
41 },
42 {
43 .start = 0,
44 .end = 0,
45 .flags = IORESOURCE_IRQ,
46 },
47};
48
49static struct mfd_cell sh_mobile_sdhi_cell = {
50 .name = "tmio-mmc",
51 .num_resources = ARRAY_SIZE(sh_mobile_sdhi_resources),
52 .resources = sh_mobile_sdhi_resources,
53};
54
Magnus Dammbe9cd7b2009-11-27 04:31:27 +000055static void sh_mobile_sdhi_set_pwr(struct platform_device *tmio, int state)
56{
57 struct platform_device *pdev = to_platform_device(tmio->dev.parent);
58 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
59
60 if (p && p->set_pwr)
61 p->set_pwr(pdev, state);
62}
63
Magnus Damma87d5632009-10-02 02:22:09 +000064static int __init sh_mobile_sdhi_probe(struct platform_device *pdev)
65{
66 struct sh_mobile_sdhi *priv;
67 struct resource *mem;
68 char clk_name[8];
69 int ret, irq;
70
71 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
72 if (!mem)
73 dev_err(&pdev->dev, "missing MEM resource\n");
74
75 irq = platform_get_irq(pdev, 0);
76 if (irq < 0)
77 dev_err(&pdev->dev, "missing IRQ resource\n");
78
79 if (!mem || (irq < 0))
80 return -EINVAL;
81
82 priv = kzalloc(sizeof(struct sh_mobile_sdhi), GFP_KERNEL);
83 if (priv == NULL) {
84 dev_err(&pdev->dev, "kzalloc failed\n");
85 return -ENOMEM;
86 }
87
88 snprintf(clk_name, sizeof(clk_name), "sdhi%d", pdev->id);
89 priv->clk = clk_get(&pdev->dev, clk_name);
90 if (IS_ERR(priv->clk)) {
91 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name);
92 ret = PTR_ERR(priv->clk);
93 kfree(priv);
94 return ret;
95 }
96
97 clk_enable(priv->clk);
98
Magnus Damm3c49e812010-02-22 13:37:09 +090099 priv->mmc_data.hclk = clk_get_rate(priv->clk);
Magnus Dammbe9cd7b2009-11-27 04:31:27 +0000100 priv->mmc_data.set_pwr = sh_mobile_sdhi_set_pwr;
Magnus Damm3c49e812010-02-22 13:37:09 +0900101 priv->mmc_data.capabilities = MMC_CAP_MMC_HIGHSPEED;
Magnus Damma87d5632009-10-02 02:22:09 +0000102
103 memcpy(&priv->cell_mmc, &sh_mobile_sdhi_cell, sizeof(priv->cell_mmc));
104 priv->cell_mmc.driver_data = &priv->mmc_data;
105 priv->cell_mmc.platform_data = &priv->cell_mmc;
106 priv->cell_mmc.data_size = sizeof(priv->cell_mmc);
107
108 platform_set_drvdata(pdev, priv);
109
110 ret = mfd_add_devices(&pdev->dev, pdev->id,
111 &priv->cell_mmc, 1, mem, irq);
112 if (ret) {
113 clk_disable(priv->clk);
114 clk_put(priv->clk);
115 kfree(priv);
116 }
117
118 return ret;
119}
120
121static int sh_mobile_sdhi_remove(struct platform_device *pdev)
122{
123 struct sh_mobile_sdhi *priv = platform_get_drvdata(pdev);
124
125 mfd_remove_devices(&pdev->dev);
126 clk_disable(priv->clk);
127 clk_put(priv->clk);
128 kfree(priv);
129
130 return 0;
131}
132
133static struct platform_driver sh_mobile_sdhi_driver = {
134 .driver = {
135 .name = "sh_mobile_sdhi",
136 .owner = THIS_MODULE,
137 },
138 .probe = sh_mobile_sdhi_probe,
139 .remove = __devexit_p(sh_mobile_sdhi_remove),
140};
141
142static int __init sh_mobile_sdhi_init(void)
143{
144 return platform_driver_register(&sh_mobile_sdhi_driver);
145}
146
147static void __exit sh_mobile_sdhi_exit(void)
148{
149 platform_driver_unregister(&sh_mobile_sdhi_driver);
150}
151
152module_init(sh_mobile_sdhi_init);
153module_exit(sh_mobile_sdhi_exit);
154
155MODULE_DESCRIPTION("SuperH Mobile SDHI driver");
156MODULE_AUTHOR("Magnus Damm");
157MODULE_LICENSE("GPL v2");