diff options
author | Eric Miao <eric.miao@marvell.com> | 2009-04-13 03:59:03 -0400 |
---|---|---|
committer | Eric Miao <eric.y.miao@gmail.com> | 2009-06-04 22:32:02 -0400 |
commit | 3d2a98cd5e17052f461390c72efe1076c18fd62d (patch) | |
tree | c90bf62174751504b1a95bc0197374c38ebe5ad4 /arch/arm/mach-pxa/pwm.c | |
parent | 1a77920e4cbe508c8dc40fef1d0beb21aac8cc17 (diff) |
[ARM] pxa: simplify secondary PWM handling and use platform_device_id table
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Diffstat (limited to 'arch/arm/mach-pxa/pwm.c')
-rw-r--r-- | arch/arm/mach-pxa/pwm.c | 116 |
1 files changed, 49 insertions, 67 deletions
diff --git a/arch/arm/mach-pxa/pwm.c b/arch/arm/mach-pxa/pwm.c index fcdd374437a8..dec6f2c8dbf9 100644 --- a/arch/arm/mach-pxa/pwm.c +++ b/arch/arm/mach-pxa/pwm.c | |||
@@ -21,6 +21,16 @@ | |||
21 | 21 | ||
22 | #include <asm/div64.h> | 22 | #include <asm/div64.h> |
23 | 23 | ||
24 | #define HAS_SECONDARY_PWM 0x10 | ||
25 | |||
26 | static const struct platform_device_id pwm_id_table[] = { | ||
27 | /* PWM has_secondary_pwm? */ | ||
28 | { "pxa25x-pwm", 0 }, | ||
29 | { "pxa27x-pwm", HAS_SECONDARY_PWM }, | ||
30 | { }, | ||
31 | }; | ||
32 | MODULE_DEVICE_TABLE(platform, pwm_id_table); | ||
33 | |||
24 | /* PWM registers and bits definitions */ | 34 | /* PWM registers and bits definitions */ |
25 | #define PWMCR (0x00) | 35 | #define PWMCR (0x00) |
26 | #define PWMDCR (0x04) | 36 | #define PWMDCR (0x04) |
@@ -31,7 +41,8 @@ | |||
31 | 41 | ||
32 | struct pwm_device { | 42 | struct pwm_device { |
33 | struct list_head node; | 43 | struct list_head node; |
34 | struct platform_device *pdev; | 44 | struct pwm_device *secondary; |
45 | struct platform_device *pdev; | ||
35 | 46 | ||
36 | const char *label; | 47 | const char *label; |
37 | struct clk *clk; | 48 | struct clk *clk; |
@@ -159,17 +170,17 @@ static inline void __add_pwm(struct pwm_device *pwm) | |||
159 | mutex_unlock(&pwm_lock); | 170 | mutex_unlock(&pwm_lock); |
160 | } | 171 | } |
161 | 172 | ||
162 | static struct pwm_device *pwm_probe(struct platform_device *pdev, | 173 | static int __devinit pwm_probe(struct platform_device *pdev) |
163 | unsigned int pwm_id, struct pwm_device *parent_pwm) | ||
164 | { | 174 | { |
165 | struct pwm_device *pwm; | 175 | struct platform_device_id *id = platform_get_device_id(pdev); |
176 | struct pwm_device *pwm, *secondary = NULL; | ||
166 | struct resource *r; | 177 | struct resource *r; |
167 | int ret = 0; | 178 | int ret = 0; |
168 | 179 | ||
169 | pwm = kzalloc(sizeof(struct pwm_device), GFP_KERNEL); | 180 | pwm = kzalloc(sizeof(struct pwm_device), GFP_KERNEL); |
170 | if (pwm == NULL) { | 181 | if (pwm == NULL) { |
171 | dev_err(&pdev->dev, "failed to allocate memory\n"); | 182 | dev_err(&pdev->dev, "failed to allocate memory\n"); |
172 | return ERR_PTR(-ENOMEM); | 183 | return -ENOMEM; |
173 | } | 184 | } |
174 | 185 | ||
175 | pwm->clk = clk_get(&pdev->dev, NULL); | 186 | pwm->clk = clk_get(&pdev->dev, NULL); |
@@ -180,16 +191,9 @@ static struct pwm_device *pwm_probe(struct platform_device *pdev, | |||
180 | pwm->clk_enabled = 0; | 191 | pwm->clk_enabled = 0; |
181 | 192 | ||
182 | pwm->use_count = 0; | 193 | pwm->use_count = 0; |
183 | pwm->pwm_id = pwm_id; | 194 | pwm->pwm_id = pdev->id; |
184 | pwm->pdev = pdev; | 195 | pwm->pdev = pdev; |
185 | 196 | ||
186 | if (parent_pwm != NULL) { | ||
187 | /* registers for the second PWM has offset of 0x10 */ | ||
188 | pwm->mmio_base = parent_pwm->mmio_base + 0x10; | ||
189 | __add_pwm(pwm); | ||
190 | return pwm; | ||
191 | } | ||
192 | |||
193 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 197 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
194 | if (r == NULL) { | 198 | if (r == NULL) { |
195 | dev_err(&pdev->dev, "no memory resource defined\n"); | 199 | dev_err(&pdev->dev, "no memory resource defined\n"); |
@@ -211,9 +215,27 @@ static struct pwm_device *pwm_probe(struct platform_device *pdev, | |||
211 | goto err_free_mem; | 215 | goto err_free_mem; |
212 | } | 216 | } |
213 | 217 | ||
218 | if (id->driver_data & HAS_SECONDARY_PWM) { | ||
219 | secondary = kzalloc(sizeof(struct pwm_device), GFP_KERNEL); | ||
220 | if (secondary == NULL) { | ||
221 | ret = -ENOMEM; | ||
222 | goto err_free_mem; | ||
223 | } | ||
224 | |||
225 | *secondary = *pwm; | ||
226 | pwm->secondary = secondary; | ||
227 | |||
228 | /* registers for the second PWM has offset of 0x10 */ | ||
229 | secondary->mmio_base = pwm->mmio_base + 0x10; | ||
230 | secondary->pwm_id = pdev->id + 2; | ||
231 | } | ||
232 | |||
214 | __add_pwm(pwm); | 233 | __add_pwm(pwm); |
234 | if (secondary) | ||
235 | __add_pwm(secondary); | ||
236 | |||
215 | platform_set_drvdata(pdev, pwm); | 237 | platform_set_drvdata(pdev, pwm); |
216 | return pwm; | 238 | return 0; |
217 | 239 | ||
218 | err_free_mem: | 240 | err_free_mem: |
219 | release_mem_region(r->start, r->end - r->start + 1); | 241 | release_mem_region(r->start, r->end - r->start + 1); |
@@ -221,32 +243,7 @@ err_free_clk: | |||
221 | clk_put(pwm->clk); | 243 | clk_put(pwm->clk); |
222 | err_free: | 244 | err_free: |
223 | kfree(pwm); | 245 | kfree(pwm); |
224 | return ERR_PTR(ret); | 246 | return ret; |
225 | } | ||
226 | |||
227 | static int __devinit pxa25x_pwm_probe(struct platform_device *pdev) | ||
228 | { | ||
229 | struct pwm_device *pwm = pwm_probe(pdev, pdev->id, NULL); | ||
230 | |||
231 | if (IS_ERR(pwm)) | ||
232 | return PTR_ERR(pwm); | ||
233 | |||
234 | return 0; | ||
235 | } | ||
236 | |||
237 | static int __devinit pxa27x_pwm_probe(struct platform_device *pdev) | ||
238 | { | ||
239 | struct pwm_device *pwm; | ||
240 | |||
241 | pwm = pwm_probe(pdev, pdev->id, NULL); | ||
242 | if (IS_ERR(pwm)) | ||
243 | return PTR_ERR(pwm); | ||
244 | |||
245 | pwm = pwm_probe(pdev, pdev->id + 2, pwm); | ||
246 | if (IS_ERR(pwm)) | ||
247 | return PTR_ERR(pwm); | ||
248 | |||
249 | return 0; | ||
250 | } | 247 | } |
251 | 248 | ||
252 | static int __devexit pwm_remove(struct platform_device *pdev) | 249 | static int __devexit pwm_remove(struct platform_device *pdev) |
@@ -259,6 +256,12 @@ static int __devexit pwm_remove(struct platform_device *pdev) | |||
259 | return -ENODEV; | 256 | return -ENODEV; |
260 | 257 | ||
261 | mutex_lock(&pwm_lock); | 258 | mutex_lock(&pwm_lock); |
259 | |||
260 | if (pwm->secondary) { | ||
261 | list_del(&pwm->secondary->node); | ||
262 | kfree(pwm->secondary); | ||
263 | } | ||
264 | |||
262 | list_del(&pwm->node); | 265 | list_del(&pwm->node); |
263 | mutex_unlock(&pwm_lock); | 266 | mutex_unlock(&pwm_lock); |
264 | 267 | ||
@@ -272,46 +275,25 @@ static int __devexit pwm_remove(struct platform_device *pdev) | |||
272 | return 0; | 275 | return 0; |
273 | } | 276 | } |
274 | 277 | ||
275 | static struct platform_driver pxa25x_pwm_driver = { | 278 | static struct platform_driver pwm_driver = { |
276 | .driver = { | 279 | .driver = { |
277 | .name = "pxa25x-pwm", | 280 | .name = "pxa25x-pwm", |
281 | .owner = THIS_MODULE, | ||
278 | }, | 282 | }, |
279 | .probe = pxa25x_pwm_probe, | 283 | .probe = pwm_probe, |
280 | .remove = __devexit_p(pwm_remove), | ||
281 | }; | ||
282 | |||
283 | static struct platform_driver pxa27x_pwm_driver = { | ||
284 | .driver = { | ||
285 | .name = "pxa27x-pwm", | ||
286 | }, | ||
287 | .probe = pxa27x_pwm_probe, | ||
288 | .remove = __devexit_p(pwm_remove), | 284 | .remove = __devexit_p(pwm_remove), |
285 | .id_table = pwm_id_table, | ||
289 | }; | 286 | }; |
290 | 287 | ||
291 | static int __init pwm_init(void) | 288 | static int __init pwm_init(void) |
292 | { | 289 | { |
293 | int ret = 0; | 290 | return platform_driver_register(&pwm_driver); |
294 | |||
295 | ret = platform_driver_register(&pxa25x_pwm_driver); | ||
296 | if (ret) { | ||
297 | printk(KERN_ERR "failed to register pxa25x_pwm_driver\n"); | ||
298 | return ret; | ||
299 | } | ||
300 | |||
301 | ret = platform_driver_register(&pxa27x_pwm_driver); | ||
302 | if (ret) { | ||
303 | printk(KERN_ERR "failed to register pxa27x_pwm_driver\n"); | ||
304 | return ret; | ||
305 | } | ||
306 | |||
307 | return ret; | ||
308 | } | 291 | } |
309 | arch_initcall(pwm_init); | 292 | arch_initcall(pwm_init); |
310 | 293 | ||
311 | static void __exit pwm_exit(void) | 294 | static void __exit pwm_exit(void) |
312 | { | 295 | { |
313 | platform_driver_unregister(&pxa25x_pwm_driver); | 296 | platform_driver_unregister(&pwm_driver); |
314 | platform_driver_unregister(&pxa27x_pwm_driver); | ||
315 | } | 297 | } |
316 | module_exit(pwm_exit); | 298 | module_exit(pwm_exit); |
317 | 299 | ||