scsi: ibmvscsi: redo driver work thread to use enum action states
[linux-2.6-microblaze.git] / drivers / mfd / tc6387xb.c
1 /*
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>
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>
20 #include <linux/slab.h>
21
22 enum {
23         TC6387XB_CELL_MMC,
24 };
25
26 struct tc6387xb {
27         void __iomem *scr;
28         struct clk *clk32k;
29         struct resource rscr;
30 };
31
32 static struct resource tc6387xb_mmc_resources[] = {
33         {
34                 .start = 0x800,
35                 .end   = 0x9ff,
36                 .flags = IORESOURCE_MEM,
37         },
38         {
39                 .start = 0,
40                 .end   = 0,
41                 .flags = IORESOURCE_IRQ,
42         },
43 };
44
45 /*--------------------------------------------------------------------------*/
46
47 #ifdef CONFIG_PM
48 static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state)
49 {
50         struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
51         struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
52
53         if (pdata && pdata->suspend)
54                 pdata->suspend(dev);
55         clk_disable_unprepare(tc6387xb->clk32k);
56
57         return 0;
58 }
59
60 static int tc6387xb_resume(struct platform_device *dev)
61 {
62         struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
63         struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
64
65         clk_prepare_enable(tc6387xb->clk32k);
66         if (pdata && pdata->resume)
67                 pdata->resume(dev);
68
69         tmio_core_mmc_resume(tc6387xb->scr + 0x200, 0,
70                 tc6387xb_mmc_resources[0].start & 0xfffe);
71
72         return 0;
73 }
74 #else
75 #define tc6387xb_suspend  NULL
76 #define tc6387xb_resume   NULL
77 #endif
78
79 /*--------------------------------------------------------------------------*/
80
81 static void tc6387xb_mmc_pwr(struct platform_device *mmc, int state)
82 {
83         struct tc6387xb *tc6387xb = dev_get_drvdata(mmc->dev.parent);
84
85         tmio_core_mmc_pwr(tc6387xb->scr + 0x200, 0, state);
86 }
87
88 static void tc6387xb_mmc_clk_div(struct platform_device *mmc, int state)
89 {
90         struct tc6387xb *tc6387xb = dev_get_drvdata(mmc->dev.parent);
91
92         tmio_core_mmc_clk_div(tc6387xb->scr + 0x200, 0, state);
93 }
94
95
96 static int tc6387xb_mmc_enable(struct platform_device *mmc)
97 {
98         struct tc6387xb *tc6387xb = dev_get_drvdata(mmc->dev.parent);
99
100         clk_prepare_enable(tc6387xb->clk32k);
101
102         tmio_core_mmc_enable(tc6387xb->scr + 0x200, 0,
103                 tc6387xb_mmc_resources[0].start & 0xfffe);
104
105         return 0;
106 }
107
108 static int tc6387xb_mmc_disable(struct platform_device *mmc)
109 {
110         struct tc6387xb *tc6387xb = dev_get_drvdata(mmc->dev.parent);
111
112         clk_disable_unprepare(tc6387xb->clk32k);
113
114         return 0;
115 }
116
117 static struct tmio_mmc_data tc6387xb_mmc_data = {
118         .hclk = 24000000,
119         .set_pwr = tc6387xb_mmc_pwr,
120         .set_clk_div = tc6387xb_mmc_clk_div,
121 };
122
123 /*--------------------------------------------------------------------------*/
124
125 static const struct mfd_cell tc6387xb_cells[] = {
126         [TC6387XB_CELL_MMC] = {
127                 .name = "tmio-mmc",
128                 .enable = tc6387xb_mmc_enable,
129                 .disable = tc6387xb_mmc_disable,
130                 .platform_data = &tc6387xb_mmc_data,
131                 .pdata_size    = sizeof(tc6387xb_mmc_data),
132                 .num_resources = ARRAY_SIZE(tc6387xb_mmc_resources),
133                 .resources = tc6387xb_mmc_resources,
134         },
135 };
136
137 static int tc6387xb_probe(struct platform_device *dev)
138 {
139         struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
140         struct resource *iomem, *rscr;
141         struct clk *clk32k;
142         struct tc6387xb *tc6387xb;
143         int irq, ret;
144
145         iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
146         if (!iomem)
147                 return -EINVAL;
148
149         tc6387xb = kzalloc(sizeof(*tc6387xb), GFP_KERNEL);
150         if (!tc6387xb)
151                 return -ENOMEM;
152
153         ret  = platform_get_irq(dev, 0);
154         if (ret >= 0)
155                 irq = ret;
156         else
157                 goto err_no_irq;
158
159         clk32k = clk_get(&dev->dev, "CLK_CK32K");
160         if (IS_ERR(clk32k)) {
161                 ret = PTR_ERR(clk32k);
162                 goto err_no_clk;
163         }
164
165         rscr = &tc6387xb->rscr;
166         rscr->name = "tc6387xb-core";
167         rscr->start = iomem->start;
168         rscr->end = iomem->start + 0xff;
169         rscr->flags = IORESOURCE_MEM;
170
171         ret = request_resource(iomem, rscr);
172         if (ret)
173                 goto err_resource;
174
175         tc6387xb->scr = ioremap(rscr->start, resource_size(rscr));
176         if (!tc6387xb->scr) {
177                 ret = -ENOMEM;
178                 goto err_ioremap;
179         }
180
181         tc6387xb->clk32k = clk32k;
182         platform_set_drvdata(dev, tc6387xb);
183
184         if (pdata && pdata->enable)
185                 pdata->enable(dev);
186
187         dev_info(&dev->dev, "Toshiba tc6387xb initialised\n");
188
189         ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells,
190                               ARRAY_SIZE(tc6387xb_cells), iomem, irq, NULL);
191
192         if (!ret)
193                 return 0;
194
195         iounmap(tc6387xb->scr);
196 err_ioremap:
197         release_resource(&tc6387xb->rscr);
198 err_resource:
199         clk_put(clk32k);
200 err_no_clk:
201 err_no_irq:
202         kfree(tc6387xb);
203         return ret;
204 }
205
206 static int tc6387xb_remove(struct platform_device *dev)
207 {
208         struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
209
210         mfd_remove_devices(&dev->dev);
211         iounmap(tc6387xb->scr);
212         release_resource(&tc6387xb->rscr);
213         clk_disable_unprepare(tc6387xb->clk32k);
214         clk_put(tc6387xb->clk32k);
215         kfree(tc6387xb);
216
217         return 0;
218 }
219
220
221 static struct platform_driver tc6387xb_platform_driver = {
222         .driver = {
223                 .name           = "tc6387xb",
224         },
225         .probe          = tc6387xb_probe,
226         .remove         = tc6387xb_remove,
227         .suspend        = tc6387xb_suspend,
228         .resume         = tc6387xb_resume,
229 };
230
231 module_platform_driver(tc6387xb_platform_driver);
232
233 MODULE_DESCRIPTION("Toshiba TC6387XB core driver");
234 MODULE_LICENSE("GPL v2");
235 MODULE_AUTHOR("Ian Molton");
236 MODULE_ALIAS("platform:tc6387xb");
237