blob: 43222c12fec14fc906993322c31f3cbad89f3e41 [file] [log] [blame]
Ian Moltoncbdfb422008-07-15 15:12:52 +01001/*
2 * Toshiba TC6387XB support
3 * Copyright (c) 2005 Ian Molton
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This file contains TC6387XB base support.
10 *
11 */
12
13#include <linux/module.h>
14#include <linux/platform_device.h>
Ian Molton7acb7062008-10-09 20:06:09 +020015#include <linux/clk.h>
Ian Moltoncbdfb422008-07-15 15:12:52 +010016#include <linux/err.h>
17#include <linux/mfd/core.h>
18#include <linux/mfd/tmio.h>
19#include <linux/mfd/tc6387xb.h>
20
Ian Moltond2432a62008-08-04 18:58:18 +020021enum {
22 TC6387XB_CELL_MMC,
23};
24
Ian Moltoncbdfb422008-07-15 15:12:52 +010025#ifdef CONFIG_PM
26static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state)
27{
Ian Molton7acb7062008-10-09 20:06:09 +020028 struct clk *clk32k = platform_get_drvdata(dev);
29 struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
Ian Moltoncbdfb422008-07-15 15:12:52 +010030
31 if (pdata && pdata->suspend)
32 pdata->suspend(dev);
Ian Molton7acb7062008-10-09 20:06:09 +020033 clk_disable(clk32k);
Ian Moltoncbdfb422008-07-15 15:12:52 +010034
35 return 0;
36}
37
38static int tc6387xb_resume(struct platform_device *dev)
39{
Ian Molton7acb7062008-10-09 20:06:09 +020040 struct clk *clk32k = platform_get_drvdata(dev);
41 struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
Ian Moltoncbdfb422008-07-15 15:12:52 +010042
Ian Molton7acb7062008-10-09 20:06:09 +020043 clk_enable(clk32k);
Ian Moltoncbdfb422008-07-15 15:12:52 +010044 if (pdata && pdata->resume)
45 pdata->resume(dev);
46
47 return 0;
48}
49#else
50#define tc6387xb_suspend NULL
51#define tc6387xb_resume NULL
52#endif
53
54/*--------------------------------------------------------------------------*/
55
56static int tc6387xb_mmc_enable(struct platform_device *mmc)
57{
58 struct platform_device *dev = to_platform_device(mmc->dev.parent);
Ian Molton7acb7062008-10-09 20:06:09 +020059 struct clk *clk32k = platform_get_drvdata(dev);
Ian Moltoncbdfb422008-07-15 15:12:52 +010060
Ian Molton7acb7062008-10-09 20:06:09 +020061 clk_enable(clk32k);
Ian Moltoncbdfb422008-07-15 15:12:52 +010062
63 return 0;
64}
65
66static int tc6387xb_mmc_disable(struct platform_device *mmc)
67{
68 struct platform_device *dev = to_platform_device(mmc->dev.parent);
Ian Molton7acb7062008-10-09 20:06:09 +020069 struct clk *clk32k = platform_get_drvdata(dev);
Ian Moltoncbdfb422008-07-15 15:12:52 +010070
Ian Molton7acb7062008-10-09 20:06:09 +020071 clk_disable(clk32k);
Ian Moltoncbdfb422008-07-15 15:12:52 +010072
73 return 0;
74}
75
76/*--------------------------------------------------------------------------*/
77
78static struct resource tc6387xb_mmc_resources[] = {
79 {
80 .start = 0x800,
81 .end = 0x9ff,
82 .flags = IORESOURCE_MEM,
83 },
84 {
85 .start = 0x200,
86 .end = 0x2ff,
87 .flags = IORESOURCE_MEM,
88 },
89 {
90 .start = 0,
91 .end = 0,
92 .flags = IORESOURCE_IRQ,
93 },
94};
95
96static struct mfd_cell tc6387xb_cells[] = {
Ian Moltond2432a62008-08-04 18:58:18 +020097 [TC6387XB_CELL_MMC] = {
Ian Moltoncbdfb422008-07-15 15:12:52 +010098 .name = "tmio-mmc",
99 .enable = tc6387xb_mmc_enable,
100 .disable = tc6387xb_mmc_disable,
101 .num_resources = ARRAY_SIZE(tc6387xb_mmc_resources),
102 .resources = tc6387xb_mmc_resources,
103 },
104};
105
106static int tc6387xb_probe(struct platform_device *dev)
107{
Ian Molton7acb7062008-10-09 20:06:09 +0200108 struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
Ian Moltoncbdfb422008-07-15 15:12:52 +0100109 struct resource *iomem;
Ian Molton7acb7062008-10-09 20:06:09 +0200110 struct clk *clk32k;
Ian Moltoncbdfb422008-07-15 15:12:52 +0100111 int irq, ret;
112
113 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
114 if (!iomem) {
Ian Molton7acb7062008-10-09 20:06:09 +0200115 return -EINVAL;
Ian Moltoncbdfb422008-07-15 15:12:52 +0100116 }
117
118 ret = platform_get_irq(dev, 0);
119 if (ret >= 0)
120 irq = ret;
121 else
122 goto err_resource;
123
Ian Molton7acb7062008-10-09 20:06:09 +0200124 clk32k = clk_get(&dev->dev, "CLK_CK32K");
125 if (IS_ERR(clk32k)) {
126 ret = PTR_ERR(clk32k);
127 goto err_resource;
128 }
129 platform_set_drvdata(dev, clk32k);
130
131 if (pdata && pdata->enable)
132 pdata->enable(dev);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100133
134 printk(KERN_INFO "Toshiba tc6387xb initialised\n");
135
Ian Moltond2432a62008-08-04 18:58:18 +0200136 tc6387xb_cells[TC6387XB_CELL_MMC].platform_data =
137 &tc6387xb_cells[TC6387XB_CELL_MMC];
138 tc6387xb_cells[TC6387XB_CELL_MMC].data_size =
139 sizeof(tc6387xb_cells[TC6387XB_CELL_MMC]);
140
Samuel Ortiz56bf2bd2008-08-01 00:16:13 +0200141 ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells,
142 ARRAY_SIZE(tc6387xb_cells), iomem, irq);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100143
144 if (!ret)
145 return 0;
146
Ian Molton7acb7062008-10-09 20:06:09 +0200147 clk_put(clk32k);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100148err_resource:
149 return ret;
150}
151
152static int tc6387xb_remove(struct platform_device *dev)
153{
Ian Molton7acb7062008-10-09 20:06:09 +0200154 struct clk *clk32k = platform_get_drvdata(dev);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100155
Ian Molton7acb7062008-10-09 20:06:09 +0200156 mfd_remove_devices(&dev->dev);
157 clk_disable(clk32k);
158 clk_put(clk32k);
159 platform_set_drvdata(dev, NULL);
Ian Moltoncbdfb422008-07-15 15:12:52 +0100160
161 return 0;
162}
163
164
165static struct platform_driver tc6387xb_platform_driver = {
166 .driver = {
167 .name = "tc6387xb",
168 },
169 .probe = tc6387xb_probe,
170 .remove = tc6387xb_remove,
171 .suspend = tc6387xb_suspend,
172 .resume = tc6387xb_resume,
173};
174
175
176static int __init tc6387xb_init(void)
177{
178 return platform_driver_register(&tc6387xb_platform_driver);
179}
180
181static void __exit tc6387xb_exit(void)
182{
183 platform_driver_unregister(&tc6387xb_platform_driver);
184}
185
186module_init(tc6387xb_init);
187module_exit(tc6387xb_exit);
188
189MODULE_DESCRIPTION("Toshiba TC6387XB core driver");
190MODULE_LICENSE("GPL v2");
191MODULE_AUTHOR("Ian Molton");
192MODULE_ALIAS("platform:tc6387xb");