mm-only debug patch...
[mmotm.git] / drivers / mfd / tc6387xb.c
blobfa8da0264a9f9f41fac7d53abe09804eaf84fd76
1 /*
2 * Toshiba TC6387XB support
3 * Copyright (c) 2005 Ian Molton
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.
9 * This file contains TC6387XB base support.
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/clk.h>
16 #include <linux/err.h>
17 #include <linux/mfd/core.h>
18 #include <linux/mfd/tmio.h>
19 #include <linux/mfd/tc6387xb.h>
21 enum {
22 TC6387XB_CELL_MMC,
25 struct tc6387xb {
26 void __iomem *scr;
27 struct clk *clk32k;
28 struct resource rscr;
31 static struct resource tc6387xb_mmc_resources[];
33 /*--------------------------------------------------------------------------*/
35 #ifdef CONFIG_PM
36 static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state)
38 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
39 struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
41 if (pdata && pdata->suspend)
42 pdata->suspend(dev);
43 clk_disable(tc6387xb->clk32k);
45 return 0;
48 static int tc6387xb_resume(struct platform_device *dev)
50 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
51 struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
53 clk_enable(tc6387xb->clk32k);
54 if (pdata && pdata->resume)
55 pdata->resume(dev);
57 tmio_core_mmc_resume(tc6387xb->scr + 0x200,
58 tc6387xb_mmc_resources[0].start & 0xfffe);
60 return 0;
62 #else
63 #define tc6387xb_suspend NULL
64 #define tc6387xb_resume NULL
65 #endif
67 /*--------------------------------------------------------------------------*/
69 static void tc6387xb_mmc_pwr(struct platform_device *mmc, int state)
71 struct platform_device *dev = to_platform_device(mmc->dev.parent);
72 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
74 tmio_core_mmc_pwr(tc6387xb->scr + 0x200, state);
77 static void tc6387xb_mmc_clk_div(struct platform_device *mmc, int state)
79 struct platform_device *dev = to_platform_device(mmc->dev.parent);
80 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
82 tmio_core_mmc_clk_div(tc6387xb->scr + 0x200, state);
86 static int tc6387xb_mmc_enable(struct platform_device *mmc)
88 struct platform_device *dev = to_platform_device(mmc->dev.parent);
89 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
91 clk_enable(tc6387xb->clk32k);
93 tmio_core_mmc_enable(tc6387xb->scr + 0x200,
94 tc6387xb_mmc_resources[0].start & 0xfffe);
96 return 0;
99 static int tc6387xb_mmc_disable(struct platform_device *mmc)
101 struct platform_device *dev = to_platform_device(mmc->dev.parent);
102 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
104 clk_disable(tc6387xb->clk32k);
106 return 0;
109 static struct tmio_mmc_data tc6387xb_mmc_data = {
110 .hclk = 24000000,
111 .set_pwr = tc6387xb_mmc_pwr,
112 .set_no_clk_div = tc6387xb_mmc_clk_div,
115 /*--------------------------------------------------------------------------*/
117 static struct resource tc6387xb_mmc_resources[] = {
119 .start = 0x800,
120 .end = 0x9ff,
121 .flags = IORESOURCE_MEM,
124 .start = 0,
125 .end = 0,
126 .flags = IORESOURCE_IRQ,
130 static struct mfd_cell tc6387xb_cells[] = {
131 [TC6387XB_CELL_MMC] = {
132 .name = "tmio-mmc",
133 .enable = tc6387xb_mmc_enable,
134 .disable = tc6387xb_mmc_disable,
135 .driver_data = &tc6387xb_mmc_data,
136 .num_resources = ARRAY_SIZE(tc6387xb_mmc_resources),
137 .resources = tc6387xb_mmc_resources,
141 static int tc6387xb_probe(struct platform_device *dev)
143 struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
144 struct resource *iomem, *rscr;
145 struct clk *clk32k;
146 struct tc6387xb *tc6387xb;
147 int irq, ret;
149 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
150 if (!iomem) {
151 return -EINVAL;
154 tc6387xb = kzalloc(sizeof *tc6387xb, GFP_KERNEL);
155 if (!tc6387xb)
156 return -ENOMEM;
158 ret = platform_get_irq(dev, 0);
159 if (ret >= 0)
160 irq = ret;
161 else
162 goto err_no_irq;
164 clk32k = clk_get(&dev->dev, "CLK_CK32K");
165 if (IS_ERR(clk32k)) {
166 ret = PTR_ERR(clk32k);
167 goto err_no_clk;
170 rscr = &tc6387xb->rscr;
171 rscr->name = "tc6387xb-core";
172 rscr->start = iomem->start;
173 rscr->end = iomem->start + 0xff;
174 rscr->flags = IORESOURCE_MEM;
176 ret = request_resource(iomem, rscr);
177 if (ret)
178 goto err_resource;
180 tc6387xb->scr = ioremap(rscr->start, rscr->end - rscr->start + 1);
181 if (!tc6387xb->scr) {
182 ret = -ENOMEM;
183 goto err_ioremap;
186 tc6387xb->clk32k = clk32k;
187 platform_set_drvdata(dev, tc6387xb);
189 if (pdata && pdata->enable)
190 pdata->enable(dev);
192 printk(KERN_INFO "Toshiba tc6387xb initialised\n");
194 tc6387xb_cells[TC6387XB_CELL_MMC].platform_data =
195 &tc6387xb_cells[TC6387XB_CELL_MMC];
196 tc6387xb_cells[TC6387XB_CELL_MMC].data_size =
197 sizeof(tc6387xb_cells[TC6387XB_CELL_MMC]);
199 ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells,
200 ARRAY_SIZE(tc6387xb_cells), iomem, irq);
202 if (!ret)
203 return 0;
205 err_ioremap:
206 release_resource(&tc6387xb->rscr);
207 err_resource:
208 clk_put(clk32k);
209 err_no_clk:
210 err_no_irq:
211 kfree(tc6387xb);
212 return ret;
215 static int tc6387xb_remove(struct platform_device *dev)
217 struct clk *clk32k = platform_get_drvdata(dev);
219 mfd_remove_devices(&dev->dev);
220 clk_disable(clk32k);
221 clk_put(clk32k);
222 platform_set_drvdata(dev, NULL);
224 return 0;
228 static struct platform_driver tc6387xb_platform_driver = {
229 .driver = {
230 .name = "tc6387xb",
232 .probe = tc6387xb_probe,
233 .remove = tc6387xb_remove,
234 .suspend = tc6387xb_suspend,
235 .resume = tc6387xb_resume,
239 static int __init tc6387xb_init(void)
241 return platform_driver_register(&tc6387xb_platform_driver);
244 static void __exit tc6387xb_exit(void)
246 platform_driver_unregister(&tc6387xb_platform_driver);
249 module_init(tc6387xb_init);
250 module_exit(tc6387xb_exit);
252 MODULE_DESCRIPTION("Toshiba TC6387XB core driver");
253 MODULE_LICENSE("GPL v2");
254 MODULE_AUTHOR("Ian Molton");
255 MODULE_ALIAS("platform:tc6387xb");