diff options
author | Kevin Hilman <khilman@ti.com> | 2011-07-21 16:58:51 -0400 |
---|---|---|
committer | Kevin Hilman <khilman@ti.com> | 2011-09-15 19:35:47 -0400 |
commit | d66b3fe436a296f102e8944247972fc0c17ddf26 (patch) | |
tree | d1b15398c457f54380fb50ed3fb8d6756043cb0c /arch | |
parent | 9f8b6949d78f1306eef0edc14bc1fbcaf3e58ad0 (diff) |
OMAP: omap_device: decouple platform_device from omap_device
Rather than embedding a struct platform_device inside a struct
omap_device, decouple them, leaving only a pointer to the
platform_device inside the omap_device.
Use the arch-specific data field of the platform_device (pdev_archdata)
to add an omap_device pointer after the platform_device has been created.
Signed-off-by: Kevin Hilman <khilman@ti.com>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arm/mach-omap2/opp.c | 2 | ||||
-rw-r--r-- | arch/arm/plat-omap/include/plat/omap_device.h | 7 | ||||
-rw-r--r-- | arch/arm/plat-omap/omap_device.c | 100 |
3 files changed, 58 insertions, 51 deletions
diff --git a/arch/arm/mach-omap2/opp.c b/arch/arm/mach-omap2/opp.c index ab8b35b780b5..9262a6b47702 100644 --- a/arch/arm/mach-omap2/opp.c +++ b/arch/arm/mach-omap2/opp.c | |||
@@ -69,7 +69,7 @@ int __init omap_init_opp_table(struct omap_opp_def *opp_def, | |||
69 | opp_def->hwmod_name, i); | 69 | opp_def->hwmod_name, i); |
70 | return -EINVAL; | 70 | return -EINVAL; |
71 | } | 71 | } |
72 | dev = &oh->od->pdev.dev; | 72 | dev = &oh->od->pdev->dev; |
73 | 73 | ||
74 | r = opp_add(dev, opp_def->freq, opp_def->u_volt); | 74 | r = opp_add(dev, opp_def->freq, opp_def->u_volt); |
75 | if (r) { | 75 | if (r) { |
diff --git a/arch/arm/plat-omap/include/plat/omap_device.h b/arch/arm/plat-omap/include/plat/omap_device.h index 4f98770b1d8c..d4d9b96f961e 100644 --- a/arch/arm/plat-omap/include/plat/omap_device.h +++ b/arch/arm/plat-omap/include/plat/omap_device.h | |||
@@ -68,7 +68,7 @@ extern struct device omap_device_parent; | |||
68 | * | 68 | * |
69 | */ | 69 | */ |
70 | struct omap_device { | 70 | struct omap_device { |
71 | struct platform_device pdev; | 71 | struct platform_device *pdev; |
72 | struct omap_hwmod **hwmods; | 72 | struct omap_hwmod **hwmods; |
73 | struct omap_device_pm_latency *pm_lats; | 73 | struct omap_device_pm_latency *pm_lats; |
74 | u32 dev_wakeup_lat; | 74 | u32 dev_wakeup_lat; |
@@ -146,7 +146,10 @@ struct omap_device_pm_latency { | |||
146 | #define OMAP_DEVICE_LATENCY_AUTO_ADJUST BIT(1) | 146 | #define OMAP_DEVICE_LATENCY_AUTO_ADJUST BIT(1) |
147 | 147 | ||
148 | /* Get omap_device pointer from platform_device pointer */ | 148 | /* Get omap_device pointer from platform_device pointer */ |
149 | #define to_omap_device(x) container_of((x), struct omap_device, pdev) | 149 | static inline struct omap_device *to_omap_device(struct platform_device *pdev) |
150 | { | ||
151 | return pdev ? pdev->archdata.od : NULL; | ||
152 | } | ||
150 | 153 | ||
151 | static inline | 154 | static inline |
152 | void omap_device_disable_idle_on_suspend(struct platform_device *pdev) | 155 | void omap_device_disable_idle_on_suspend(struct platform_device *pdev) |
diff --git a/arch/arm/plat-omap/omap_device.c b/arch/arm/plat-omap/omap_device.c index a69567ed5905..26aee5cc1fc1 100644 --- a/arch/arm/plat-omap/omap_device.c +++ b/arch/arm/plat-omap/omap_device.c | |||
@@ -117,7 +117,7 @@ static int _omap_device_activate(struct omap_device *od, u8 ignore_lat) | |||
117 | { | 117 | { |
118 | struct timespec a, b, c; | 118 | struct timespec a, b, c; |
119 | 119 | ||
120 | dev_dbg(&od->pdev.dev, "omap_device: activating\n"); | 120 | dev_dbg(&od->pdev->dev, "omap_device: activating\n"); |
121 | 121 | ||
122 | while (od->pm_lat_level > 0) { | 122 | while (od->pm_lat_level > 0) { |
123 | struct omap_device_pm_latency *odpl; | 123 | struct omap_device_pm_latency *odpl; |
@@ -141,7 +141,7 @@ static int _omap_device_activate(struct omap_device *od, u8 ignore_lat) | |||
141 | c = timespec_sub(b, a); | 141 | c = timespec_sub(b, a); |
142 | act_lat = timespec_to_ns(&c); | 142 | act_lat = timespec_to_ns(&c); |
143 | 143 | ||
144 | dev_dbg(&od->pdev.dev, | 144 | dev_dbg(&od->pdev->dev, |
145 | "omap_device: pm_lat %d: activate: elapsed time " | 145 | "omap_device: pm_lat %d: activate: elapsed time " |
146 | "%llu nsec\n", od->pm_lat_level, act_lat); | 146 | "%llu nsec\n", od->pm_lat_level, act_lat); |
147 | 147 | ||
@@ -149,12 +149,12 @@ static int _omap_device_activate(struct omap_device *od, u8 ignore_lat) | |||
149 | odpl->activate_lat_worst = act_lat; | 149 | odpl->activate_lat_worst = act_lat; |
150 | if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) { | 150 | if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) { |
151 | odpl->activate_lat = act_lat; | 151 | odpl->activate_lat = act_lat; |
152 | dev_dbg(&od->pdev.dev, | 152 | dev_dbg(&od->pdev->dev, |
153 | "new worst case activate latency " | 153 | "new worst case activate latency " |
154 | "%d: %llu\n", | 154 | "%d: %llu\n", |
155 | od->pm_lat_level, act_lat); | 155 | od->pm_lat_level, act_lat); |
156 | } else | 156 | } else |
157 | dev_warn(&od->pdev.dev, | 157 | dev_warn(&od->pdev->dev, |
158 | "activate latency %d " | 158 | "activate latency %d " |
159 | "higher than exptected. (%llu > %d)\n", | 159 | "higher than exptected. (%llu > %d)\n", |
160 | od->pm_lat_level, act_lat, | 160 | od->pm_lat_level, act_lat, |
@@ -185,7 +185,7 @@ static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat) | |||
185 | { | 185 | { |
186 | struct timespec a, b, c; | 186 | struct timespec a, b, c; |
187 | 187 | ||
188 | dev_dbg(&od->pdev.dev, "omap_device: deactivating\n"); | 188 | dev_dbg(&od->pdev->dev, "omap_device: deactivating\n"); |
189 | 189 | ||
190 | while (od->pm_lat_level < od->pm_lats_cnt) { | 190 | while (od->pm_lat_level < od->pm_lats_cnt) { |
191 | struct omap_device_pm_latency *odpl; | 191 | struct omap_device_pm_latency *odpl; |
@@ -208,7 +208,7 @@ static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat) | |||
208 | c = timespec_sub(b, a); | 208 | c = timespec_sub(b, a); |
209 | deact_lat = timespec_to_ns(&c); | 209 | deact_lat = timespec_to_ns(&c); |
210 | 210 | ||
211 | dev_dbg(&od->pdev.dev, | 211 | dev_dbg(&od->pdev->dev, |
212 | "omap_device: pm_lat %d: deactivate: elapsed time " | 212 | "omap_device: pm_lat %d: deactivate: elapsed time " |
213 | "%llu nsec\n", od->pm_lat_level, deact_lat); | 213 | "%llu nsec\n", od->pm_lat_level, deact_lat); |
214 | 214 | ||
@@ -216,12 +216,12 @@ static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat) | |||
216 | odpl->deactivate_lat_worst = deact_lat; | 216 | odpl->deactivate_lat_worst = deact_lat; |
217 | if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) { | 217 | if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) { |
218 | odpl->deactivate_lat = deact_lat; | 218 | odpl->deactivate_lat = deact_lat; |
219 | dev_dbg(&od->pdev.dev, | 219 | dev_dbg(&od->pdev->dev, |
220 | "new worst case deactivate latency " | 220 | "new worst case deactivate latency " |
221 | "%d: %llu\n", | 221 | "%d: %llu\n", |
222 | od->pm_lat_level, deact_lat); | 222 | od->pm_lat_level, deact_lat); |
223 | } else | 223 | } else |
224 | dev_warn(&od->pdev.dev, | 224 | dev_warn(&od->pdev->dev, |
225 | "deactivate latency %d " | 225 | "deactivate latency %d " |
226 | "higher than exptected. (%llu > %d)\n", | 226 | "higher than exptected. (%llu > %d)\n", |
227 | od->pm_lat_level, deact_lat, | 227 | od->pm_lat_level, deact_lat, |
@@ -245,11 +245,11 @@ static void _add_clkdev(struct omap_device *od, const char *clk_alias, | |||
245 | if (!clk_alias || !clk_name) | 245 | if (!clk_alias || !clk_name) |
246 | return; | 246 | return; |
247 | 247 | ||
248 | dev_dbg(&od->pdev.dev, "Creating %s -> %s\n", clk_alias, clk_name); | 248 | dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name); |
249 | 249 | ||
250 | r = clk_get_sys(dev_name(&od->pdev.dev), clk_alias); | 250 | r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias); |
251 | if (!IS_ERR(r)) { | 251 | if (!IS_ERR(r)) { |
252 | dev_warn(&od->pdev.dev, | 252 | dev_warn(&od->pdev->dev, |
253 | "alias %s already exists\n", clk_alias); | 253 | "alias %s already exists\n", clk_alias); |
254 | clk_put(r); | 254 | clk_put(r); |
255 | return; | 255 | return; |
@@ -257,14 +257,14 @@ static void _add_clkdev(struct omap_device *od, const char *clk_alias, | |||
257 | 257 | ||
258 | r = omap_clk_get_by_name(clk_name); | 258 | r = omap_clk_get_by_name(clk_name); |
259 | if (IS_ERR(r)) { | 259 | if (IS_ERR(r)) { |
260 | dev_err(&od->pdev.dev, | 260 | dev_err(&od->pdev->dev, |
261 | "omap_clk_get_by_name for %s failed\n", clk_name); | 261 | "omap_clk_get_by_name for %s failed\n", clk_name); |
262 | return; | 262 | return; |
263 | } | 263 | } |
264 | 264 | ||
265 | l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev.dev)); | 265 | l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev->dev)); |
266 | if (!l) { | 266 | if (!l) { |
267 | dev_err(&od->pdev.dev, | 267 | dev_err(&od->pdev->dev, |
268 | "clkdev_alloc for %s failed\n", clk_alias); | 268 | "clkdev_alloc for %s failed\n", clk_alias); |
269 | return; | 269 | return; |
270 | } | 270 | } |
@@ -351,7 +351,7 @@ static int omap_device_count_resources(struct omap_device *od) | |||
351 | c += omap_hwmod_count_resources(od->hwmods[i]); | 351 | c += omap_hwmod_count_resources(od->hwmods[i]); |
352 | 352 | ||
353 | pr_debug("omap_device: %s: counted %d total resources across %d " | 353 | pr_debug("omap_device: %s: counted %d total resources across %d " |
354 | "hwmods\n", od->pdev.name, c, od->hwmods_cnt); | 354 | "hwmods\n", od->pdev->name, c, od->hwmods_cnt); |
355 | 355 | ||
356 | return c; | 356 | return c; |
357 | } | 357 | } |
@@ -445,8 +445,8 @@ struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id, | |||
445 | int pm_lats_cnt, int is_early_device) | 445 | int pm_lats_cnt, int is_early_device) |
446 | { | 446 | { |
447 | int ret = -ENOMEM; | 447 | int ret = -ENOMEM; |
448 | struct platform_device *pdev; | ||
448 | struct omap_device *od; | 449 | struct omap_device *od; |
449 | char *pdev_name2; | ||
450 | struct resource *res = NULL; | 450 | struct resource *res = NULL; |
451 | int i, res_count; | 451 | int i, res_count; |
452 | struct omap_hwmod **hwmods; | 452 | struct omap_hwmod **hwmods; |
@@ -457,72 +457,76 @@ struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id, | |||
457 | if (!pdata && pdata_len > 0) | 457 | if (!pdata && pdata_len > 0) |
458 | return ERR_PTR(-EINVAL); | 458 | return ERR_PTR(-EINVAL); |
459 | 459 | ||
460 | pdev = platform_device_alloc(pdev_name, pdev_id); | ||
461 | if (!pdev) { | ||
462 | ret = -ENOMEM; | ||
463 | goto odbs_exit; | ||
464 | } | ||
465 | |||
460 | pr_debug("omap_device: %s: building with %d hwmods\n", pdev_name, | 466 | pr_debug("omap_device: %s: building with %d hwmods\n", pdev_name, |
461 | oh_cnt); | 467 | oh_cnt); |
462 | 468 | ||
463 | od = kzalloc(sizeof(struct omap_device), GFP_KERNEL); | 469 | od = kzalloc(sizeof(struct omap_device), GFP_KERNEL); |
464 | if (!od) | 470 | if (!od) { |
465 | return ERR_PTR(-ENOMEM); | 471 | ret = -ENOMEM; |
466 | 472 | goto odbs_exit1; | |
473 | } | ||
467 | od->hwmods_cnt = oh_cnt; | 474 | od->hwmods_cnt = oh_cnt; |
468 | 475 | ||
469 | hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, | 476 | hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, |
470 | GFP_KERNEL); | 477 | GFP_KERNEL); |
471 | if (!hwmods) | 478 | if (!hwmods) |
472 | goto odbs_exit1; | 479 | goto odbs_exit2; |
473 | 480 | ||
474 | memcpy(hwmods, ohs, sizeof(struct omap_hwmod *) * oh_cnt); | 481 | memcpy(hwmods, ohs, sizeof(struct omap_hwmod *) * oh_cnt); |
475 | od->hwmods = hwmods; | 482 | od->hwmods = hwmods; |
476 | 483 | od->pdev = pdev; | |
477 | pdev_name2 = kzalloc(strlen(pdev_name) + 1, GFP_KERNEL); | ||
478 | if (!pdev_name2) | ||
479 | goto odbs_exit2; | ||
480 | strcpy(pdev_name2, pdev_name); | ||
481 | |||
482 | od->pdev.name = pdev_name2; | ||
483 | od->pdev.id = pdev_id; | ||
484 | 484 | ||
485 | res_count = omap_device_count_resources(od); | 485 | res_count = omap_device_count_resources(od); |
486 | if (res_count > 0) { | 486 | if (res_count > 0) { |
487 | res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL); | 487 | res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL); |
488 | if (!res) | 488 | if (!res) |
489 | goto odbs_exit3; | 489 | goto odbs_exit3; |
490 | } | ||
491 | omap_device_fill_resources(od, res); | ||
492 | 490 | ||
493 | od->pdev.num_resources = res_count; | 491 | omap_device_fill_resources(od, res); |
494 | od->pdev.resource = res; | ||
495 | 492 | ||
496 | ret = platform_device_add_data(&od->pdev, pdata, pdata_len); | 493 | ret = platform_device_add_resources(pdev, res, res_count); |
494 | kfree(res); | ||
495 | |||
496 | if (ret) | ||
497 | goto odbs_exit3; | ||
498 | } | ||
499 | |||
500 | ret = platform_device_add_data(pdev, pdata, pdata_len); | ||
497 | if (ret) | 501 | if (ret) |
498 | goto odbs_exit4; | 502 | goto odbs_exit3; |
499 | 503 | ||
500 | od->pm_lats = pm_lats; | 504 | pdev->archdata.od = od; |
501 | od->pm_lats_cnt = pm_lats_cnt; | ||
502 | 505 | ||
503 | if (is_early_device) | 506 | if (is_early_device) |
504 | ret = omap_early_device_register(&od->pdev); | 507 | ret = omap_early_device_register(pdev); |
505 | else | 508 | else |
506 | ret = omap_device_register(&od->pdev); | 509 | ret = omap_device_register(pdev); |
510 | if (ret) | ||
511 | goto odbs_exit3; | ||
512 | |||
513 | od->pm_lats = pm_lats; | ||
514 | od->pm_lats_cnt = pm_lats_cnt; | ||
507 | 515 | ||
508 | for (i = 0; i < oh_cnt; i++) { | 516 | for (i = 0; i < oh_cnt; i++) { |
509 | hwmods[i]->od = od; | 517 | hwmods[i]->od = od; |
510 | _add_hwmod_clocks_clkdev(od, hwmods[i]); | 518 | _add_hwmod_clocks_clkdev(od, hwmods[i]); |
511 | } | 519 | } |
512 | 520 | ||
513 | if (ret) | 521 | return pdev; |
514 | goto odbs_exit4; | ||
515 | |||
516 | return &od->pdev; | ||
517 | 522 | ||
518 | odbs_exit4: | ||
519 | kfree(res); | ||
520 | odbs_exit3: | 523 | odbs_exit3: |
521 | kfree(pdev_name2); | ||
522 | odbs_exit2: | ||
523 | kfree(hwmods); | 524 | kfree(hwmods); |
524 | odbs_exit1: | 525 | odbs_exit2: |
525 | kfree(od); | 526 | kfree(od); |
527 | odbs_exit1: | ||
528 | platform_device_put(pdev); | ||
529 | odbs_exit: | ||
526 | 530 | ||
527 | pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret); | 531 | pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret); |
528 | 532 | ||
@@ -644,7 +648,7 @@ static int omap_device_register(struct platform_device *pdev) | |||
644 | 648 | ||
645 | pdev->dev.parent = &omap_device_parent; | 649 | pdev->dev.parent = &omap_device_parent; |
646 | pdev->dev.pm_domain = &omap_device_pm_domain; | 650 | pdev->dev.pm_domain = &omap_device_pm_domain; |
647 | return platform_device_register(pdev); | 651 | return platform_device_add(pdev); |
648 | } | 652 | } |
649 | 653 | ||
650 | 654 | ||