1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78#undef DEBUG
79
80#include <linux/kernel.h>
81#include <linux/export.h>
82#include <linux/platform_device.h>
83#include <linux/slab.h>
84#include <linux/err.h>
85#include <linux/io.h>
86#include <linux/clk.h>
87#include <linux/clkdev.h>
88#include <linux/pm_runtime.h>
89#include <linux/of.h>
90#include <linux/notifier.h>
91
92#include <plat/omap_device.h>
93#include <plat/omap_hwmod.h>
94#include <plat/clock.h>
95
96
97#define USE_WAKEUP_LAT 0
98#define IGNORE_WAKEUP_LAT 1
99
100static int omap_early_device_register(struct platform_device *pdev);
101
102static struct omap_device_pm_latency omap_default_latency[] = {
103 {
104 .deactivate_func = omap_device_idle_hwmods,
105 .activate_func = omap_device_enable_hwmods,
106 .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
107 }
108};
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)
127{
128 struct timespec a, b, c;
129
130 dev_dbg(&od->pdev->dev, "omap_device: activating\n");
131
132 while (od->pm_lat_level > 0) {
133 struct omap_device_pm_latency *odpl;
134 unsigned long long act_lat = 0;
135
136 od->pm_lat_level--;
137
138 odpl = od->pm_lats + od->pm_lat_level;
139
140 if (!ignore_lat &&
141 (od->dev_wakeup_lat <= od->_dev_wakeup_lat_limit))
142 break;
143
144 read_persistent_clock(&a);
145
146
147 odpl->activate_func(od);
148
149 read_persistent_clock(&b);
150
151 c = timespec_sub(b, a);
152 act_lat = timespec_to_ns(&c);
153
154 dev_dbg(&od->pdev->dev,
155 "omap_device: pm_lat %d: activate: elapsed time %llu nsec\n",
156 od->pm_lat_level, act_lat);
157
158 if (act_lat > odpl->activate_lat) {
159 odpl->activate_lat_worst = act_lat;
160 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
161 odpl->activate_lat = act_lat;
162 dev_dbg(&od->pdev->dev,
163 "new worst case activate latency %d: %llu\n",
164 od->pm_lat_level, act_lat);
165 } else
166 dev_warn(&od->pdev->dev,
167 "activate latency %d higher than expected. (%llu > %d)\n",
168 od->pm_lat_level, act_lat,
169 odpl->activate_lat);
170 }
171
172 od->dev_wakeup_lat -= odpl->activate_lat;
173 }
174
175 return 0;
176}
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat)
193{
194 struct timespec a, b, c;
195
196 dev_dbg(&od->pdev->dev, "omap_device: deactivating\n");
197
198 while (od->pm_lat_level < od->pm_lats_cnt) {
199 struct omap_device_pm_latency *odpl;
200 unsigned long long deact_lat = 0;
201
202 odpl = od->pm_lats + od->pm_lat_level;
203
204 if (!ignore_lat &&
205 ((od->dev_wakeup_lat + odpl->activate_lat) >
206 od->_dev_wakeup_lat_limit))
207 break;
208
209 read_persistent_clock(&a);
210
211
212 odpl->deactivate_func(od);
213
214 read_persistent_clock(&b);
215
216 c = timespec_sub(b, a);
217 deact_lat = timespec_to_ns(&c);
218
219 dev_dbg(&od->pdev->dev,
220 "omap_device: pm_lat %d: deactivate: elapsed time %llu nsec\n",
221 od->pm_lat_level, deact_lat);
222
223 if (deact_lat > odpl->deactivate_lat) {
224 odpl->deactivate_lat_worst = deact_lat;
225 if (odpl->flags & OMAP_DEVICE_LATENCY_AUTO_ADJUST) {
226 odpl->deactivate_lat = deact_lat;
227 dev_dbg(&od->pdev->dev,
228 "new worst case deactivate latency %d: %llu\n",
229 od->pm_lat_level, deact_lat);
230 } else
231 dev_warn(&od->pdev->dev,
232 "deactivate latency %d higher than expected. (%llu > %d)\n",
233 od->pm_lat_level, deact_lat,
234 odpl->deactivate_lat);
235 }
236
237 od->dev_wakeup_lat += odpl->activate_lat;
238
239 od->pm_lat_level++;
240 }
241
242 return 0;
243}
244
245static void _add_clkdev(struct omap_device *od, const char *clk_alias,
246 const char *clk_name)
247{
248 struct clk *r;
249 struct clk_lookup *l;
250
251 if (!clk_alias || !clk_name)
252 return;
253
254 dev_dbg(&od->pdev->dev, "Creating %s -> %s\n", clk_alias, clk_name);
255
256 r = clk_get_sys(dev_name(&od->pdev->dev), clk_alias);
257 if (!IS_ERR(r)) {
258 dev_warn(&od->pdev->dev,
259 "alias %s already exists\n", clk_alias);
260 clk_put(r);
261 return;
262 }
263
264 r = clk_get(NULL, clk_name);
265 if (IS_ERR(r)) {
266 dev_err(&od->pdev->dev,
267 "clk_get for %s failed\n", clk_name);
268 return;
269 }
270
271 l = clkdev_alloc(r, clk_alias, dev_name(&od->pdev->dev));
272 if (!l) {
273 dev_err(&od->pdev->dev,
274 "clkdev_alloc for %s failed\n", clk_alias);
275 return;
276 }
277
278 clkdev_add(l);
279}
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300static void _add_hwmod_clocks_clkdev(struct omap_device *od,
301 struct omap_hwmod *oh)
302{
303 int i;
304
305 _add_clkdev(od, "fck", oh->main_clk);
306
307 for (i = 0; i < oh->opt_clks_cnt; i++)
308 _add_clkdev(od, oh->opt_clks[i].role, oh->opt_clks[i].clk);
309}
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327static int omap_device_build_from_dt(struct platform_device *pdev)
328{
329 struct omap_hwmod **hwmods;
330 struct omap_device *od;
331 struct omap_hwmod *oh;
332 struct device_node *node = pdev->dev.of_node;
333 const char *oh_name;
334 int oh_cnt, i, ret = 0;
335
336 oh_cnt = of_property_count_strings(node, "ti,hwmods");
337 if (!oh_cnt || IS_ERR_VALUE(oh_cnt)) {
338 dev_dbg(&pdev->dev, "No 'hwmods' to build omap_device\n");
339 return -ENODEV;
340 }
341
342 hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
343 if (!hwmods) {
344 ret = -ENOMEM;
345 goto odbfd_exit;
346 }
347
348 for (i = 0; i < oh_cnt; i++) {
349 of_property_read_string_index(node, "ti,hwmods", i, &oh_name);
350 oh = omap_hwmod_lookup(oh_name);
351 if (!oh) {
352 dev_err(&pdev->dev, "Cannot lookup hwmod '%s'\n",
353 oh_name);
354 ret = -EINVAL;
355 goto odbfd_exit1;
356 }
357 hwmods[i] = oh;
358 }
359
360 od = omap_device_alloc(pdev, hwmods, oh_cnt, NULL, 0);
361 if (!od) {
362 dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n",
363 oh_name);
364 ret = PTR_ERR(od);
365 goto odbfd_exit1;
366 }
367
368
369 for (i = 0; i < pdev->num_resources; i++) {
370 struct resource *r = &pdev->resource[i];
371
372 if (r->name == NULL)
373 r->name = dev_name(&pdev->dev);
374 }
375
376 if (of_get_property(node, "ti,no_idle_on_suspend", NULL))
377 omap_device_disable_idle_on_suspend(pdev);
378
379 pdev->dev.pm_domain = &omap_device_pm_domain;
380
381odbfd_exit1:
382 kfree(hwmods);
383odbfd_exit:
384 return ret;
385}
386
387static int _omap_device_notifier_call(struct notifier_block *nb,
388 unsigned long event, void *dev)
389{
390 struct platform_device *pdev = to_platform_device(dev);
391 struct omap_device *od;
392
393 switch (event) {
394 case BUS_NOTIFY_DEL_DEVICE:
395 if (pdev->archdata.od)
396 omap_device_delete(pdev->archdata.od);
397 break;
398 case BUS_NOTIFY_ADD_DEVICE:
399 if (pdev->dev.of_node)
400 omap_device_build_from_dt(pdev);
401
402 default:
403 od = to_omap_device(pdev);
404 if (od)
405 od->_driver_status = event;
406 }
407
408 return NOTIFY_DONE;
409}
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429int omap_device_get_context_loss_count(struct platform_device *pdev)
430{
431 struct omap_device *od;
432 u32 ret = 0;
433
434 od = to_omap_device(pdev);
435
436 if (od->hwmods_cnt)
437 ret = omap_hwmod_get_context_loss_count(od->hwmods[0]);
438
439 return ret;
440}
441
442
443
444
445
446
447
448
449
450
451static int omap_device_count_resources(struct omap_device *od)
452{
453 int c = 0;
454 int i;
455
456 for (i = 0; i < od->hwmods_cnt; i++)
457 c += omap_hwmod_count_resources(od->hwmods[i]);
458
459 pr_debug("omap_device: %s: counted %d total resources across %d hwmods\n",
460 od->pdev->name, c, od->hwmods_cnt);
461
462 return c;
463}
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482static int omap_device_fill_resources(struct omap_device *od,
483 struct resource *res)
484{
485 int i, r;
486
487 for (i = 0; i < od->hwmods_cnt; i++) {
488 r = omap_hwmod_fill_resources(od->hwmods[i], res);
489 res += r;
490 }
491
492 return 0;
493}
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509static int _od_fill_dma_resources(struct omap_device *od,
510 struct resource *res)
511{
512 int i, r;
513
514 for (i = 0; i < od->hwmods_cnt; i++) {
515 r = omap_hwmod_fill_dma_resources(od->hwmods[i], res);
516 res += r;
517 }
518
519 return 0;
520}
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536struct omap_device *omap_device_alloc(struct platform_device *pdev,
537 struct omap_hwmod **ohs, int oh_cnt,
538 struct omap_device_pm_latency *pm_lats,
539 int pm_lats_cnt)
540{
541 int ret = -ENOMEM;
542 struct omap_device *od;
543 struct resource *res = NULL;
544 int i, res_count;
545 struct omap_hwmod **hwmods;
546
547 od = kzalloc(sizeof(struct omap_device), GFP_KERNEL);
548 if (!od) {
549 ret = -ENOMEM;
550 goto oda_exit1;
551 }
552 od->hwmods_cnt = oh_cnt;
553
554 hwmods = kmemdup(ohs, sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL);
555 if (!hwmods)
556 goto oda_exit2;
557
558 od->hwmods = hwmods;
559 od->pdev = pdev;
560
561 res_count = omap_device_count_resources(od);
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577 if (res_count > pdev->num_resources) {
578
579 res = kzalloc(sizeof(struct resource) * res_count, GFP_KERNEL);
580 if (!res)
581 goto oda_exit3;
582
583
584
585
586
587
588 if (pdev->num_resources && pdev->resource) {
589 dev_dbg(&pdev->dev, "%s(): resources already allocated %d\n",
590 __func__, res_count);
591 memcpy(res, pdev->resource,
592 sizeof(struct resource) * pdev->num_resources);
593 _od_fill_dma_resources(od, &res[pdev->num_resources]);
594 } else {
595 dev_dbg(&pdev->dev, "%s(): using resources from hwmod %d\n",
596 __func__, res_count);
597 omap_device_fill_resources(od, res);
598 }
599
600 ret = platform_device_add_resources(pdev, res, res_count);
601 kfree(res);
602
603 if (ret)
604 goto oda_exit3;
605 }
606
607 if (!pm_lats) {
608 pm_lats = omap_default_latency;
609 pm_lats_cnt = ARRAY_SIZE(omap_default_latency);
610 }
611
612 od->pm_lats_cnt = pm_lats_cnt;
613 od->pm_lats = kmemdup(pm_lats,
614 sizeof(struct omap_device_pm_latency) * pm_lats_cnt,
615 GFP_KERNEL);
616 if (!od->pm_lats)
617 goto oda_exit3;
618
619 pdev->archdata.od = od;
620
621 for (i = 0; i < oh_cnt; i++) {
622 hwmods[i]->od = od;
623 _add_hwmod_clocks_clkdev(od, hwmods[i]);
624 }
625
626 return od;
627
628oda_exit3:
629 kfree(hwmods);
630oda_exit2:
631 kfree(od);
632oda_exit1:
633 dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret);
634
635 return ERR_PTR(ret);
636}
637
638void omap_device_delete(struct omap_device *od)
639{
640 if (!od)
641 return;
642
643 od->pdev->archdata.od = NULL;
644 kfree(od->pm_lats);
645 kfree(od->hwmods);
646 kfree(od);
647}
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666struct platform_device __init *omap_device_build(const char *pdev_name, int pdev_id,
667 struct omap_hwmod *oh, void *pdata,
668 int pdata_len,
669 struct omap_device_pm_latency *pm_lats,
670 int pm_lats_cnt, int is_early_device)
671{
672 struct omap_hwmod *ohs[] = { oh };
673
674 if (!oh)
675 return ERR_PTR(-EINVAL);
676
677 return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
678 pdata_len, pm_lats, pm_lats_cnt,
679 is_early_device);
680}
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699struct platform_device __init *omap_device_build_ss(const char *pdev_name, int pdev_id,
700 struct omap_hwmod **ohs, int oh_cnt,
701 void *pdata, int pdata_len,
702 struct omap_device_pm_latency *pm_lats,
703 int pm_lats_cnt, int is_early_device)
704{
705 int ret = -ENOMEM;
706 struct platform_device *pdev;
707 struct omap_device *od;
708
709 if (!ohs || oh_cnt == 0 || !pdev_name)
710 return ERR_PTR(-EINVAL);
711
712 if (!pdata && pdata_len > 0)
713 return ERR_PTR(-EINVAL);
714
715 pdev = platform_device_alloc(pdev_name, pdev_id);
716 if (!pdev) {
717 ret = -ENOMEM;
718 goto odbs_exit;
719 }
720
721
722 if (pdev->id != -1)
723 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
724 else
725 dev_set_name(&pdev->dev, "%s", pdev->name);
726
727 od = omap_device_alloc(pdev, ohs, oh_cnt, pm_lats, pm_lats_cnt);
728 if (IS_ERR(od))
729 goto odbs_exit1;
730
731 ret = platform_device_add_data(pdev, pdata, pdata_len);
732 if (ret)
733 goto odbs_exit2;
734
735 if (is_early_device)
736 ret = omap_early_device_register(pdev);
737 else
738 ret = omap_device_register(pdev);
739 if (ret)
740 goto odbs_exit2;
741
742 return pdev;
743
744odbs_exit2:
745 omap_device_delete(od);
746odbs_exit1:
747 platform_device_put(pdev);
748odbs_exit:
749
750 pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
751
752 return ERR_PTR(ret);
753}
754
755
756
757
758
759
760
761
762
763
764static int __init omap_early_device_register(struct platform_device *pdev)
765{
766 struct platform_device *devices[1];
767
768 devices[0] = pdev;
769 early_platform_add_devices(devices, 1);
770 return 0;
771}
772
773#ifdef CONFIG_PM_RUNTIME
774static int _od_runtime_suspend(struct device *dev)
775{
776 struct platform_device *pdev = to_platform_device(dev);
777 int ret;
778
779 ret = pm_generic_runtime_suspend(dev);
780
781 if (!ret)
782 omap_device_idle(pdev);
783
784 return ret;
785}
786
787static int _od_runtime_idle(struct device *dev)
788{
789 return pm_generic_runtime_idle(dev);
790}
791
792static int _od_runtime_resume(struct device *dev)
793{
794 struct platform_device *pdev = to_platform_device(dev);
795
796 omap_device_enable(pdev);
797
798 return pm_generic_runtime_resume(dev);
799}
800#endif
801
802#ifdef CONFIG_SUSPEND
803static int _od_suspend_noirq(struct device *dev)
804{
805 struct platform_device *pdev = to_platform_device(dev);
806 struct omap_device *od = to_omap_device(pdev);
807 int ret;
808
809
810 if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER)
811 return 0;
812
813 ret = pm_generic_suspend_noirq(dev);
814
815 if (!ret && !pm_runtime_status_suspended(dev)) {
816 if (pm_generic_runtime_suspend(dev) == 0) {
817 if (!(od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND))
818 omap_device_idle(pdev);
819 od->flags |= OMAP_DEVICE_SUSPENDED;
820 }
821 }
822
823 return ret;
824}
825
826static int _od_resume_noirq(struct device *dev)
827{
828 struct platform_device *pdev = to_platform_device(dev);
829 struct omap_device *od = to_omap_device(pdev);
830
831 if ((od->flags & OMAP_DEVICE_SUSPENDED) &&
832 !pm_runtime_status_suspended(dev)) {
833 od->flags &= ~OMAP_DEVICE_SUSPENDED;
834 if (!(od->flags & OMAP_DEVICE_NO_IDLE_ON_SUSPEND))
835 omap_device_enable(pdev);
836 pm_generic_runtime_resume(dev);
837 }
838
839 return pm_generic_resume_noirq(dev);
840}
841#else
842#define _od_suspend_noirq NULL
843#define _od_resume_noirq NULL
844#endif
845
846struct dev_pm_domain omap_device_pm_domain = {
847 .ops = {
848 SET_RUNTIME_PM_OPS(_od_runtime_suspend, _od_runtime_resume,
849 _od_runtime_idle)
850 USE_PLATFORM_PM_SLEEP_OPS
851 .suspend_noirq = _od_suspend_noirq,
852 .resume_noirq = _od_resume_noirq,
853 }
854};
855
856
857
858
859
860
861
862
863
864int omap_device_register(struct platform_device *pdev)
865{
866 pr_debug("omap_device: %s: registering\n", pdev->name);
867
868 pdev->dev.pm_domain = &omap_device_pm_domain;
869 return platform_device_add(pdev);
870}
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888int omap_device_enable(struct platform_device *pdev)
889{
890 int ret;
891 struct omap_device *od;
892
893 od = to_omap_device(pdev);
894
895 if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
896 dev_warn(&pdev->dev,
897 "omap_device: %s() called from invalid state %d\n",
898 __func__, od->_state);
899 return -EINVAL;
900 }
901
902
903 if (od->_state == OMAP_DEVICE_STATE_UNKNOWN)
904 od->pm_lat_level = od->pm_lats_cnt;
905
906 ret = _omap_device_activate(od, IGNORE_WAKEUP_LAT);
907
908 od->dev_wakeup_lat = 0;
909 od->_dev_wakeup_lat_limit = UINT_MAX;
910 od->_state = OMAP_DEVICE_STATE_ENABLED;
911
912 return ret;
913}
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928int omap_device_idle(struct platform_device *pdev)
929{
930 int ret;
931 struct omap_device *od;
932
933 od = to_omap_device(pdev);
934
935 if (od->_state != OMAP_DEVICE_STATE_ENABLED) {
936 dev_warn(&pdev->dev,
937 "omap_device: %s() called from invalid state %d\n",
938 __func__, od->_state);
939 return -EINVAL;
940 }
941
942 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
943
944 od->_state = OMAP_DEVICE_STATE_IDLE;
945
946 return ret;
947}
948
949
950
951
952
953
954
955
956
957
958
959
960int omap_device_shutdown(struct platform_device *pdev)
961{
962 int ret, i;
963 struct omap_device *od;
964
965 od = to_omap_device(pdev);
966
967 if (od->_state != OMAP_DEVICE_STATE_ENABLED &&
968 od->_state != OMAP_DEVICE_STATE_IDLE) {
969 dev_warn(&pdev->dev,
970 "omap_device: %s() called from invalid state %d\n",
971 __func__, od->_state);
972 return -EINVAL;
973 }
974
975 ret = _omap_device_deactivate(od, IGNORE_WAKEUP_LAT);
976
977 for (i = 0; i < od->hwmods_cnt; i++)
978 omap_hwmod_shutdown(od->hwmods[i]);
979
980 od->_state = OMAP_DEVICE_STATE_SHUTDOWN;
981
982 return ret;
983}
984
985
986
987
988
989
990
991
992
993
994
995
996
997int omap_device_assert_hardreset(struct platform_device *pdev, const char *name)
998{
999 struct omap_device *od = to_omap_device(pdev);
1000 int ret = 0;
1001 int i;
1002
1003 for (i = 0; i < od->hwmods_cnt; i++) {
1004 ret = omap_hwmod_assert_hardreset(od->hwmods[i], name);
1005 if (ret)
1006 break;
1007 }
1008
1009 return ret;
1010}
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024int omap_device_deassert_hardreset(struct platform_device *pdev,
1025 const char *name)
1026{
1027 struct omap_device *od = to_omap_device(pdev);
1028 int ret = 0;
1029 int i;
1030
1031 for (i = 0; i < od->hwmods_cnt; i++) {
1032 ret = omap_hwmod_deassert_hardreset(od->hwmods[i], name);
1033 if (ret)
1034 break;
1035 }
1036
1037 return ret;
1038}
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056int omap_device_align_pm_lat(struct platform_device *pdev,
1057 u32 new_wakeup_lat_limit)
1058{
1059 int ret = -EINVAL;
1060 struct omap_device *od;
1061
1062 od = to_omap_device(pdev);
1063
1064 if (new_wakeup_lat_limit == od->dev_wakeup_lat)
1065 return 0;
1066
1067 od->_dev_wakeup_lat_limit = new_wakeup_lat_limit;
1068
1069 if (od->_state != OMAP_DEVICE_STATE_IDLE)
1070 return 0;
1071 else if (new_wakeup_lat_limit > od->dev_wakeup_lat)
1072 ret = _omap_device_deactivate(od, USE_WAKEUP_LAT);
1073 else if (new_wakeup_lat_limit < od->dev_wakeup_lat)
1074 ret = _omap_device_activate(od, USE_WAKEUP_LAT);
1075
1076 return ret;
1077}
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088struct powerdomain *omap_device_get_pwrdm(struct omap_device *od)
1089{
1090
1091
1092
1093
1094
1095 if (!od->hwmods_cnt)
1096 return NULL;
1097
1098 return omap_hwmod_get_pwrdm(od->hwmods[0]);
1099}
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112void __iomem *omap_device_get_rt_va(struct omap_device *od)
1113{
1114 if (od->hwmods_cnt != 1)
1115 return NULL;
1116
1117 return omap_hwmod_get_mpu_rt_va(od->hwmods[0]);
1118}
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128struct device *omap_device_get_by_hwmod_name(const char *oh_name)
1129{
1130 struct omap_hwmod *oh;
1131
1132 if (!oh_name) {
1133 WARN(1, "%s: no hwmod name!\n", __func__);
1134 return ERR_PTR(-EINVAL);
1135 }
1136
1137 oh = omap_hwmod_lookup(oh_name);
1138 if (IS_ERR_OR_NULL(oh)) {
1139 WARN(1, "%s: no hwmod for %s\n", __func__,
1140 oh_name);
1141 return ERR_PTR(oh ? PTR_ERR(oh) : -ENODEV);
1142 }
1143 if (IS_ERR_OR_NULL(oh->od)) {
1144 WARN(1, "%s: no omap_device for %s\n", __func__,
1145 oh_name);
1146 return ERR_PTR(oh->od ? PTR_ERR(oh->od) : -ENODEV);
1147 }
1148
1149 if (IS_ERR_OR_NULL(oh->od->pdev))
1150 return ERR_PTR(oh->od->pdev ? PTR_ERR(oh->od->pdev) : -ENODEV);
1151
1152 return &oh->od->pdev->dev;
1153}
1154EXPORT_SYMBOL(omap_device_get_by_hwmod_name);
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167int omap_device_enable_hwmods(struct omap_device *od)
1168{
1169 int i;
1170
1171 for (i = 0; i < od->hwmods_cnt; i++)
1172 omap_hwmod_enable(od->hwmods[i]);
1173
1174
1175 return 0;
1176}
1177
1178
1179
1180
1181
1182
1183
1184int omap_device_idle_hwmods(struct omap_device *od)
1185{
1186 int i;
1187
1188 for (i = 0; i < od->hwmods_cnt; i++)
1189 omap_hwmod_idle(od->hwmods[i]);
1190
1191
1192 return 0;
1193}
1194
1195
1196
1197
1198
1199
1200
1201
1202int omap_device_disable_clocks(struct omap_device *od)
1203{
1204 int i;
1205
1206 for (i = 0; i < od->hwmods_cnt; i++)
1207 omap_hwmod_disable_clocks(od->hwmods[i]);
1208
1209
1210 return 0;
1211}
1212
1213
1214
1215
1216
1217
1218
1219
1220int omap_device_enable_clocks(struct omap_device *od)
1221{
1222 int i;
1223
1224 for (i = 0; i < od->hwmods_cnt; i++)
1225 omap_hwmod_enable_clocks(od->hwmods[i]);
1226
1227
1228 return 0;
1229}
1230
1231static struct notifier_block platform_nb = {
1232 .notifier_call = _omap_device_notifier_call,
1233};
1234
1235static int __init omap_device_init(void)
1236{
1237 bus_register_notifier(&platform_bus_type, &platform_nb);
1238 return 0;
1239}
1240core_initcall(omap_device_init);
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250static int __init omap_device_late_idle(struct device *dev, void *data)
1251{
1252 struct platform_device *pdev = to_platform_device(dev);
1253 struct omap_device *od = to_omap_device(pdev);
1254
1255 if (!od)
1256 return 0;
1257
1258
1259
1260
1261
1262 if (od->_driver_status != BUS_NOTIFY_BOUND_DRIVER) {
1263 if (od->_state == OMAP_DEVICE_STATE_ENABLED) {
1264 dev_warn(dev, "%s: enabled but no driver. Idling\n",
1265 __func__);
1266 omap_device_idle(pdev);
1267 }
1268 }
1269
1270 return 0;
1271}
1272
1273static int __init omap_device_late_init(void)
1274{
1275 bus_for_each_dev(&platform_bus_type, NULL, NULL, omap_device_late_idle);
1276 return 0;
1277}
1278late_initcall(omap_device_late_init);
1279