]>
Commit | Line | Data |
---|---|---|
cbdfb426 IM |
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> | |
7acb706c | 15 | #include <linux/clk.h> |
cbdfb426 IM |
16 | #include <linux/err.h> |
17 | #include <linux/mfd/core.h> | |
18 | #include <linux/mfd/tmio.h> | |
19 | #include <linux/mfd/tc6387xb.h> | |
5a0e3ad6 | 20 | #include <linux/slab.h> |
cbdfb426 | 21 | |
d2432a63 IM |
22 | enum { |
23 | TC6387XB_CELL_MMC, | |
24 | }; | |
25 | ||
64e8867b IM |
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 | ||
cbdfb426 IM |
47 | #ifdef CONFIG_PM |
48 | static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state) | |
49 | { | |
64e8867b | 50 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
334a41ce | 51 | struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev); |
cbdfb426 IM |
52 | |
53 | if (pdata && pdata->suspend) | |
54 | pdata->suspend(dev); | |
64e8867b | 55 | clk_disable(tc6387xb->clk32k); |
cbdfb426 IM |
56 | |
57 | return 0; | |
58 | } | |
59 | ||
60 | static int tc6387xb_resume(struct platform_device *dev) | |
61 | { | |
64e8867b | 62 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
334a41ce | 63 | struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev); |
cbdfb426 | 64 | |
64e8867b | 65 | clk_enable(tc6387xb->clk32k); |
cbdfb426 IM |
66 | if (pdata && pdata->resume) |
67 | pdata->resume(dev); | |
68 | ||
64e8867b IM |
69 | tmio_core_mmc_resume(tc6387xb->scr + 0x200, 0, |
70 | tc6387xb_mmc_resources[0].start & 0xfffe); | |
71 | ||
cbdfb426 IM |
72 | return 0; |
73 | } | |
74 | #else | |
75 | #define tc6387xb_suspend NULL | |
76 | #define tc6387xb_resume NULL | |
77 | #endif | |
78 | ||
79 | /*--------------------------------------------------------------------------*/ | |
80 | ||
64e8867b IM |
81 | static void tc6387xb_mmc_pwr(struct platform_device *mmc, int state) |
82 | { | |
83 | struct platform_device *dev = to_platform_device(mmc->dev.parent); | |
84 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); | |
85 | ||
86 | tmio_core_mmc_pwr(tc6387xb->scr + 0x200, 0, state); | |
87 | } | |
88 | ||
89 | static void tc6387xb_mmc_clk_div(struct platform_device *mmc, int state) | |
90 | { | |
91 | struct platform_device *dev = to_platform_device(mmc->dev.parent); | |
92 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); | |
93 | ||
94 | tmio_core_mmc_clk_div(tc6387xb->scr + 0x200, 0, state); | |
95 | } | |
96 | ||
97 | ||
cbdfb426 IM |
98 | static int tc6387xb_mmc_enable(struct platform_device *mmc) |
99 | { | |
100 | struct platform_device *dev = to_platform_device(mmc->dev.parent); | |
64e8867b | 101 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
cbdfb426 | 102 | |
64e8867b IM |
103 | clk_enable(tc6387xb->clk32k); |
104 | ||
105 | tmio_core_mmc_enable(tc6387xb->scr + 0x200, 0, | |
106 | tc6387xb_mmc_resources[0].start & 0xfffe); | |
cbdfb426 IM |
107 | |
108 | return 0; | |
109 | } | |
110 | ||
111 | static int tc6387xb_mmc_disable(struct platform_device *mmc) | |
112 | { | |
113 | struct platform_device *dev = to_platform_device(mmc->dev.parent); | |
64e8867b | 114 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
cbdfb426 | 115 | |
64e8867b | 116 | clk_disable(tc6387xb->clk32k); |
cbdfb426 IM |
117 | |
118 | return 0; | |
119 | } | |
120 | ||
4d3792e0 | 121 | static struct tmio_mmc_data tc6387xb_mmc_data = { |
f0e46cc4 | 122 | .hclk = 24000000, |
64e8867b IM |
123 | .set_pwr = tc6387xb_mmc_pwr, |
124 | .set_clk_div = tc6387xb_mmc_clk_div, | |
f0e46cc4 PZ |
125 | }; |
126 | ||
64e8867b | 127 | /*--------------------------------------------------------------------------*/ |
cbdfb426 IM |
128 | |
129 | static struct mfd_cell tc6387xb_cells[] = { | |
d2432a63 | 130 | [TC6387XB_CELL_MMC] = { |
cbdfb426 IM |
131 | .name = "tmio-mmc", |
132 | .enable = tc6387xb_mmc_enable, | |
133 | .disable = tc6387xb_mmc_disable, | |
ec71974f SO |
134 | .platform_data = &tc6387xb_mmc_data, |
135 | .pdata_size = sizeof(tc6387xb_mmc_data), | |
cbdfb426 IM |
136 | .num_resources = ARRAY_SIZE(tc6387xb_mmc_resources), |
137 | .resources = tc6387xb_mmc_resources, | |
138 | }, | |
139 | }; | |
140 | ||
f791be49 | 141 | static int tc6387xb_probe(struct platform_device *dev) |
cbdfb426 | 142 | { |
334a41ce | 143 | struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev); |
64e8867b | 144 | struct resource *iomem, *rscr; |
7acb706c | 145 | struct clk *clk32k; |
64e8867b | 146 | struct tc6387xb *tc6387xb; |
cbdfb426 IM |
147 | int irq, ret; |
148 | ||
149 | iomem = platform_get_resource(dev, IORESOURCE_MEM, 0); | |
150 | if (!iomem) { | |
7acb706c | 151 | return -EINVAL; |
cbdfb426 IM |
152 | } |
153 | ||
64e8867b IM |
154 | tc6387xb = kzalloc(sizeof *tc6387xb, GFP_KERNEL); |
155 | if (!tc6387xb) | |
156 | return -ENOMEM; | |
157 | ||
cbdfb426 IM |
158 | ret = platform_get_irq(dev, 0); |
159 | if (ret >= 0) | |
160 | irq = ret; | |
161 | else | |
64e8867b | 162 | goto err_no_irq; |
cbdfb426 | 163 | |
7acb706c IM |
164 | clk32k = clk_get(&dev->dev, "CLK_CK32K"); |
165 | if (IS_ERR(clk32k)) { | |
166 | ret = PTR_ERR(clk32k); | |
64e8867b IM |
167 | goto err_no_clk; |
168 | } | |
169 | ||
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; | |
175 | ||
176 | ret = request_resource(iomem, rscr); | |
177 | if (ret) | |
7acb706c | 178 | goto err_resource; |
64e8867b | 179 | |
28f65c11 | 180 | tc6387xb->scr = ioremap(rscr->start, resource_size(rscr)); |
64e8867b IM |
181 | if (!tc6387xb->scr) { |
182 | ret = -ENOMEM; | |
183 | goto err_ioremap; | |
7acb706c | 184 | } |
64e8867b IM |
185 | |
186 | tc6387xb->clk32k = clk32k; | |
187 | platform_set_drvdata(dev, tc6387xb); | |
7acb706c IM |
188 | |
189 | if (pdata && pdata->enable) | |
190 | pdata->enable(dev); | |
cbdfb426 IM |
191 | |
192 | printk(KERN_INFO "Toshiba tc6387xb initialised\n"); | |
193 | ||
56bf2bda | 194 | ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells, |
0848c94f | 195 | ARRAY_SIZE(tc6387xb_cells), iomem, irq, NULL); |
cbdfb426 IM |
196 | |
197 | if (!ret) | |
198 | return 0; | |
199 | ||
08b877b8 | 200 | iounmap(tc6387xb->scr); |
64e8867b IM |
201 | err_ioremap: |
202 | release_resource(&tc6387xb->rscr); | |
cbdfb426 | 203 | err_resource: |
64e8867b IM |
204 | clk_put(clk32k); |
205 | err_no_clk: | |
206 | err_no_irq: | |
207 | kfree(tc6387xb); | |
cbdfb426 IM |
208 | return ret; |
209 | } | |
210 | ||
4740f73f | 211 | static int tc6387xb_remove(struct platform_device *dev) |
cbdfb426 | 212 | { |
08b877b8 | 213 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
cbdfb426 | 214 | |
7acb706c | 215 | mfd_remove_devices(&dev->dev); |
08b877b8 AL |
216 | iounmap(tc6387xb->scr); |
217 | release_resource(&tc6387xb->rscr); | |
218 | clk_disable(tc6387xb->clk32k); | |
219 | clk_put(tc6387xb->clk32k); | |
08b877b8 | 220 | kfree(tc6387xb); |
cbdfb426 IM |
221 | |
222 | return 0; | |
223 | } | |
224 | ||
225 | ||
226 | static struct platform_driver tc6387xb_platform_driver = { | |
227 | .driver = { | |
228 | .name = "tc6387xb", | |
229 | }, | |
230 | .probe = tc6387xb_probe, | |
84449216 | 231 | .remove = tc6387xb_remove, |
cbdfb426 IM |
232 | .suspend = tc6387xb_suspend, |
233 | .resume = tc6387xb_resume, | |
234 | }; | |
235 | ||
65349d60 | 236 | module_platform_driver(tc6387xb_platform_driver); |
cbdfb426 IM |
237 | |
238 | MODULE_DESCRIPTION("Toshiba TC6387XB core driver"); | |
239 | MODULE_LICENSE("GPL v2"); | |
240 | MODULE_AUTHOR("Ian Molton"); | |
241 | MODULE_ALIAS("platform:tc6387xb"); | |
64e8867b | 242 |