This source file includes following definitions.
- _clkdm_lookup
- _clkdm_register
- _clkdm_deps_lookup
- _autodep_lookup
- _resolve_clkdm_deps
- _clkdm_add_wkdep
- _clkdm_del_wkdep
- _clkdm_add_sleepdep
- _clkdm_del_sleepdep
- clkdm_register_platform_funcs
- clkdm_register_clkdms
- clkdm_register_autodeps
- cpu_notifier
- clkdm_complete_init
- clkdm_lookup
- clkdm_for_each
- clkdm_get_pwrdm
- clkdm_add_wkdep
- clkdm_del_wkdep
- clkdm_read_wkdep
- clkdm_clear_all_wkdeps
- clkdm_add_sleepdep
- clkdm_del_sleepdep
- clkdm_read_sleepdep
- clkdm_clear_all_sleepdeps
- clkdm_sleep_nolock
- clkdm_sleep
- clkdm_wakeup_nolock
- clkdm_wakeup
- clkdm_allow_idle_nolock
- clkdm_allow_idle
- clkdm_deny_idle_nolock
- clkdm_deny_idle
- clkdm_in_hwsup
- clkdm_missing_idle_reporting
- clkdm_add_autodeps
- clkdm_del_autodeps
- _clkdm_clk_hwmod_enable
- clkdm_clk_enable
- clkdm_clk_disable
- clkdm_hwmod_enable
- clkdm_hwmod_disable
- _clkdm_save_context
- _clkdm_restore_context
- clkdm_save_context
- clkdm_restore_context
1
2
3
4
5
6
7
8
9
10
11 #undef DEBUG
12
13 #include <linux/kernel.h>
14 #include <linux/device.h>
15 #include <linux/list.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
18 #include <linux/delay.h>
19 #include <linux/clk.h>
20 #include <linux/limits.h>
21 #include <linux/err.h>
22 #include <linux/clk-provider.h>
23 #include <linux/cpu_pm.h>
24
25 #include <linux/io.h>
26
27 #include <linux/bitops.h>
28
29 #include "soc.h"
30 #include "clock.h"
31 #include "clockdomain.h"
32 #include "pm.h"
33
34
35 static LIST_HEAD(clkdm_list);
36
37
38 static struct clkdm_autodep *autodeps;
39
40 static struct clkdm_ops *arch_clkdm;
41 void clkdm_save_context(void);
42 void clkdm_restore_context(void);
43
44
45
46 static struct clockdomain *_clkdm_lookup(const char *name)
47 {
48 struct clockdomain *clkdm, *temp_clkdm;
49
50 if (!name)
51 return NULL;
52
53 clkdm = NULL;
54
55 list_for_each_entry(temp_clkdm, &clkdm_list, node) {
56 if (!strcmp(name, temp_clkdm->name)) {
57 clkdm = temp_clkdm;
58 break;
59 }
60 }
61
62 return clkdm;
63 }
64
65
66
67
68
69
70
71
72
73 static int _clkdm_register(struct clockdomain *clkdm)
74 {
75 struct powerdomain *pwrdm;
76
77 if (!clkdm || !clkdm->name)
78 return -EINVAL;
79
80 pwrdm = pwrdm_lookup(clkdm->pwrdm.name);
81 if (!pwrdm) {
82 pr_err("clockdomain: %s: powerdomain %s does not exist\n",
83 clkdm->name, clkdm->pwrdm.name);
84 return -EINVAL;
85 }
86 clkdm->pwrdm.ptr = pwrdm;
87
88
89 if (_clkdm_lookup(clkdm->name))
90 return -EEXIST;
91
92 list_add(&clkdm->node, &clkdm_list);
93
94 pwrdm_add_clkdm(pwrdm, clkdm);
95
96 pr_debug("clockdomain: registered %s\n", clkdm->name);
97
98 return 0;
99 }
100
101
102 static struct clkdm_dep *_clkdm_deps_lookup(struct clockdomain *clkdm,
103 struct clkdm_dep *deps)
104 {
105 struct clkdm_dep *cd;
106
107 if (!clkdm || !deps)
108 return ERR_PTR(-EINVAL);
109
110 for (cd = deps; cd->clkdm_name; cd++) {
111 if (!cd->clkdm && cd->clkdm_name)
112 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
113
114 if (cd->clkdm == clkdm)
115 break;
116 }
117
118 if (!cd->clkdm_name)
119 return ERR_PTR(-ENOENT);
120
121 return cd;
122 }
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140 static void _autodep_lookup(struct clkdm_autodep *autodep)
141 {
142 struct clockdomain *clkdm;
143
144 if (!autodep)
145 return;
146
147 clkdm = clkdm_lookup(autodep->clkdm.name);
148 if (!clkdm) {
149 pr_err("clockdomain: autodeps: clockdomain %s does not exist\n",
150 autodep->clkdm.name);
151 clkdm = ERR_PTR(-ENOENT);
152 }
153 autodep->clkdm.ptr = clkdm;
154 }
155
156
157
158
159
160
161
162
163
164
165 static void _resolve_clkdm_deps(struct clockdomain *clkdm,
166 struct clkdm_dep *clkdm_deps)
167 {
168 struct clkdm_dep *cd;
169
170 for (cd = clkdm_deps; cd && cd->clkdm_name; cd++) {
171 if (cd->clkdm)
172 continue;
173 cd->clkdm = _clkdm_lookup(cd->clkdm_name);
174
175 WARN(!cd->clkdm, "clockdomain: %s: could not find clkdm %s while resolving dependencies - should never happen",
176 clkdm->name, cd->clkdm_name);
177 }
178 }
179
180
181
182
183
184
185
186
187
188
189
190
191
192 static int _clkdm_add_wkdep(struct clockdomain *clkdm1,
193 struct clockdomain *clkdm2)
194 {
195 struct clkdm_dep *cd;
196 int ret = 0;
197
198 if (!clkdm1 || !clkdm2)
199 return -EINVAL;
200
201 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
202 if (IS_ERR(cd))
203 ret = PTR_ERR(cd);
204
205 if (!arch_clkdm || !arch_clkdm->clkdm_add_wkdep)
206 ret = -EINVAL;
207
208 if (ret) {
209 pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
210 clkdm1->name, clkdm2->name);
211 return ret;
212 }
213
214 cd->wkdep_usecount++;
215 if (cd->wkdep_usecount == 1) {
216 pr_debug("clockdomain: hardware will wake up %s when %s wakes up\n",
217 clkdm1->name, clkdm2->name);
218
219 ret = arch_clkdm->clkdm_add_wkdep(clkdm1, clkdm2);
220 }
221
222 return ret;
223 }
224
225
226
227
228
229
230
231
232
233
234
235 static int _clkdm_del_wkdep(struct clockdomain *clkdm1,
236 struct clockdomain *clkdm2)
237 {
238 struct clkdm_dep *cd;
239 int ret = 0;
240
241 if (!clkdm1 || !clkdm2)
242 return -EINVAL;
243
244 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
245 if (IS_ERR(cd))
246 ret = PTR_ERR(cd);
247
248 if (!arch_clkdm || !arch_clkdm->clkdm_del_wkdep)
249 ret = -EINVAL;
250
251 if (ret) {
252 pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
253 clkdm1->name, clkdm2->name);
254 return ret;
255 }
256
257 cd->wkdep_usecount--;
258 if (cd->wkdep_usecount == 0) {
259 pr_debug("clockdomain: hardware will no longer wake up %s after %s wakes up\n",
260 clkdm1->name, clkdm2->name);
261
262 ret = arch_clkdm->clkdm_del_wkdep(clkdm1, clkdm2);
263 }
264
265 return ret;
266 }
267
268
269
270
271
272
273
274
275
276
277
278
279
280 static int _clkdm_add_sleepdep(struct clockdomain *clkdm1,
281 struct clockdomain *clkdm2)
282 {
283 struct clkdm_dep *cd;
284 int ret = 0;
285
286 if (!clkdm1 || !clkdm2)
287 return -EINVAL;
288
289 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
290 if (IS_ERR(cd))
291 ret = PTR_ERR(cd);
292
293 if (!arch_clkdm || !arch_clkdm->clkdm_add_sleepdep)
294 ret = -EINVAL;
295
296 if (ret) {
297 pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
298 clkdm1->name, clkdm2->name);
299 return ret;
300 }
301
302 cd->sleepdep_usecount++;
303 if (cd->sleepdep_usecount == 1) {
304 pr_debug("clockdomain: will prevent %s from sleeping if %s is active\n",
305 clkdm1->name, clkdm2->name);
306
307 ret = arch_clkdm->clkdm_add_sleepdep(clkdm1, clkdm2);
308 }
309
310 return ret;
311 }
312
313
314
315
316
317
318
319
320
321
322
323
324
325 static int _clkdm_del_sleepdep(struct clockdomain *clkdm1,
326 struct clockdomain *clkdm2)
327 {
328 struct clkdm_dep *cd;
329 int ret = 0;
330
331 if (!clkdm1 || !clkdm2)
332 return -EINVAL;
333
334 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
335 if (IS_ERR(cd))
336 ret = PTR_ERR(cd);
337
338 if (!arch_clkdm || !arch_clkdm->clkdm_del_sleepdep)
339 ret = -EINVAL;
340
341 if (ret) {
342 pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
343 clkdm1->name, clkdm2->name);
344 return ret;
345 }
346
347 cd->sleepdep_usecount--;
348 if (cd->sleepdep_usecount == 0) {
349 pr_debug("clockdomain: will no longer prevent %s from sleeping if %s is active\n",
350 clkdm1->name, clkdm2->name);
351
352 ret = arch_clkdm->clkdm_del_sleepdep(clkdm1, clkdm2);
353 }
354
355 return ret;
356 }
357
358
359
360
361
362
363
364
365
366
367
368
369
370 int clkdm_register_platform_funcs(struct clkdm_ops *co)
371 {
372 if (!co)
373 return -EINVAL;
374
375 if (arch_clkdm)
376 return -EEXIST;
377
378 arch_clkdm = co;
379
380 return 0;
381 };
382
383
384
385
386
387
388
389
390
391
392
393 int clkdm_register_clkdms(struct clockdomain **cs)
394 {
395 struct clockdomain **c = NULL;
396
397 if (!arch_clkdm)
398 return -EACCES;
399
400 if (!cs)
401 return -EINVAL;
402
403 for (c = cs; *c; c++)
404 _clkdm_register(*c);
405
406 return 0;
407 }
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433 int clkdm_register_autodeps(struct clkdm_autodep *ia)
434 {
435 struct clkdm_autodep *a = NULL;
436
437 if (list_empty(&clkdm_list))
438 return -EACCES;
439
440 if (!ia)
441 return -EINVAL;
442
443 if (autodeps)
444 return -EEXIST;
445
446 autodeps = ia;
447 for (a = autodeps; a->clkdm.ptr; a++)
448 _autodep_lookup(a);
449
450 return 0;
451 }
452
453 static int cpu_notifier(struct notifier_block *nb, unsigned long cmd, void *v)
454 {
455 switch (cmd) {
456 case CPU_CLUSTER_PM_ENTER:
457 if (enable_off_mode)
458 clkdm_save_context();
459 break;
460 case CPU_CLUSTER_PM_EXIT:
461 if (enable_off_mode)
462 clkdm_restore_context();
463 break;
464 }
465
466 return NOTIFY_OK;
467 }
468
469
470
471
472
473
474
475
476
477 int clkdm_complete_init(void)
478 {
479 struct clockdomain *clkdm;
480 static struct notifier_block nb;
481
482 if (list_empty(&clkdm_list))
483 return -EACCES;
484
485 list_for_each_entry(clkdm, &clkdm_list, node) {
486 clkdm_deny_idle(clkdm);
487
488 _resolve_clkdm_deps(clkdm, clkdm->wkdep_srcs);
489 clkdm_clear_all_wkdeps(clkdm);
490
491 _resolve_clkdm_deps(clkdm, clkdm->sleepdep_srcs);
492 clkdm_clear_all_sleepdeps(clkdm);
493 }
494
495
496 if (soc_is_am43xx()) {
497 nb.notifier_call = cpu_notifier;
498 cpu_pm_register_notifier(&nb);
499 }
500
501 return 0;
502 }
503
504
505
506
507
508
509
510
511 struct clockdomain *clkdm_lookup(const char *name)
512 {
513 struct clockdomain *clkdm, *temp_clkdm;
514
515 if (!name)
516 return NULL;
517
518 clkdm = NULL;
519
520 list_for_each_entry(temp_clkdm, &clkdm_list, node) {
521 if (!strcmp(name, temp_clkdm->name)) {
522 clkdm = temp_clkdm;
523 break;
524 }
525 }
526
527 return clkdm;
528 }
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544 int clkdm_for_each(int (*fn)(struct clockdomain *clkdm, void *user),
545 void *user)
546 {
547 struct clockdomain *clkdm;
548 int ret = 0;
549
550 if (!fn)
551 return -EINVAL;
552
553 list_for_each_entry(clkdm, &clkdm_list, node) {
554 ret = (*fn)(clkdm, user);
555 if (ret)
556 break;
557 }
558
559 return ret;
560 }
561
562
563
564
565
566
567
568
569
570 struct powerdomain *clkdm_get_pwrdm(struct clockdomain *clkdm)
571 {
572 if (!clkdm)
573 return NULL;
574
575 return clkdm->pwrdm.ptr;
576 }
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593 int clkdm_add_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
594 {
595 struct clkdm_dep *cd;
596 int ret;
597
598 if (!clkdm1 || !clkdm2)
599 return -EINVAL;
600
601 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
602 if (IS_ERR(cd))
603 return PTR_ERR(cd);
604
605 pwrdm_lock(cd->clkdm->pwrdm.ptr);
606 ret = _clkdm_add_wkdep(clkdm1, clkdm2);
607 pwrdm_unlock(cd->clkdm->pwrdm.ptr);
608
609 return ret;
610 }
611
612
613
614
615
616
617
618
619
620
621
622 int clkdm_del_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
623 {
624 struct clkdm_dep *cd;
625 int ret;
626
627 if (!clkdm1 || !clkdm2)
628 return -EINVAL;
629
630 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
631 if (IS_ERR(cd))
632 return PTR_ERR(cd);
633
634 pwrdm_lock(cd->clkdm->pwrdm.ptr);
635 ret = _clkdm_del_wkdep(clkdm1, clkdm2);
636 pwrdm_unlock(cd->clkdm->pwrdm.ptr);
637
638 return ret;
639 }
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655 int clkdm_read_wkdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
656 {
657 struct clkdm_dep *cd;
658 int ret = 0;
659
660 if (!clkdm1 || !clkdm2)
661 return -EINVAL;
662
663 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
664 if (IS_ERR(cd))
665 ret = PTR_ERR(cd);
666
667 if (!arch_clkdm || !arch_clkdm->clkdm_read_wkdep)
668 ret = -EINVAL;
669
670 if (ret) {
671 pr_debug("clockdomain: hardware cannot set/clear wake up of %s when %s wakes up\n",
672 clkdm1->name, clkdm2->name);
673 return ret;
674 }
675
676
677 return arch_clkdm->clkdm_read_wkdep(clkdm1, clkdm2);
678 }
679
680
681
682
683
684
685
686
687
688
689
690 int clkdm_clear_all_wkdeps(struct clockdomain *clkdm)
691 {
692 if (!clkdm)
693 return -EINVAL;
694
695 if (!arch_clkdm || !arch_clkdm->clkdm_clear_all_wkdeps)
696 return -EINVAL;
697
698 return arch_clkdm->clkdm_clear_all_wkdeps(clkdm);
699 }
700
701
702
703
704
705
706
707
708
709
710
711
712
713 int clkdm_add_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
714 {
715 struct clkdm_dep *cd;
716 int ret;
717
718 if (!clkdm1 || !clkdm2)
719 return -EINVAL;
720
721 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
722 if (IS_ERR(cd))
723 return PTR_ERR(cd);
724
725 pwrdm_lock(cd->clkdm->pwrdm.ptr);
726 ret = _clkdm_add_sleepdep(clkdm1, clkdm2);
727 pwrdm_unlock(cd->clkdm->pwrdm.ptr);
728
729 return ret;
730 }
731
732
733
734
735
736
737
738
739
740
741
742
743
744 int clkdm_del_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
745 {
746 struct clkdm_dep *cd;
747 int ret;
748
749 if (!clkdm1 || !clkdm2)
750 return -EINVAL;
751
752 cd = _clkdm_deps_lookup(clkdm2, clkdm1->wkdep_srcs);
753 if (IS_ERR(cd))
754 return PTR_ERR(cd);
755
756 pwrdm_lock(cd->clkdm->pwrdm.ptr);
757 ret = _clkdm_del_sleepdep(clkdm1, clkdm2);
758 pwrdm_unlock(cd->clkdm->pwrdm.ptr);
759
760 return ret;
761 }
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779 int clkdm_read_sleepdep(struct clockdomain *clkdm1, struct clockdomain *clkdm2)
780 {
781 struct clkdm_dep *cd;
782 int ret = 0;
783
784 if (!clkdm1 || !clkdm2)
785 return -EINVAL;
786
787 cd = _clkdm_deps_lookup(clkdm2, clkdm1->sleepdep_srcs);
788 if (IS_ERR(cd))
789 ret = PTR_ERR(cd);
790
791 if (!arch_clkdm || !arch_clkdm->clkdm_read_sleepdep)
792 ret = -EINVAL;
793
794 if (ret) {
795 pr_debug("clockdomain: hardware cannot set/clear sleep dependency affecting %s from %s\n",
796 clkdm1->name, clkdm2->name);
797 return ret;
798 }
799
800
801 return arch_clkdm->clkdm_read_sleepdep(clkdm1, clkdm2);
802 }
803
804
805
806
807
808
809
810
811
812
813
814 int clkdm_clear_all_sleepdeps(struct clockdomain *clkdm)
815 {
816 if (!clkdm)
817 return -EINVAL;
818
819 if (!arch_clkdm || !arch_clkdm->clkdm_clear_all_sleepdeps)
820 return -EINVAL;
821
822 return arch_clkdm->clkdm_clear_all_sleepdeps(clkdm);
823 }
824
825
826
827
828
829
830
831
832
833
834 int clkdm_sleep_nolock(struct clockdomain *clkdm)
835 {
836 int ret;
837
838 if (!clkdm)
839 return -EINVAL;
840
841 if (!(clkdm->flags & CLKDM_CAN_FORCE_SLEEP)) {
842 pr_debug("clockdomain: %s does not support forcing sleep via software\n",
843 clkdm->name);
844 return -EINVAL;
845 }
846
847 if (!arch_clkdm || !arch_clkdm->clkdm_sleep)
848 return -EINVAL;
849
850 pr_debug("clockdomain: forcing sleep on %s\n", clkdm->name);
851
852 clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
853 ret = arch_clkdm->clkdm_sleep(clkdm);
854 ret |= pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
855
856 return ret;
857 }
858
859
860
861
862
863
864
865
866
867
868 int clkdm_sleep(struct clockdomain *clkdm)
869 {
870 int ret;
871
872 pwrdm_lock(clkdm->pwrdm.ptr);
873 ret = clkdm_sleep_nolock(clkdm);
874 pwrdm_unlock(clkdm->pwrdm.ptr);
875
876 return ret;
877 }
878
879
880
881
882
883
884
885
886
887
888 int clkdm_wakeup_nolock(struct clockdomain *clkdm)
889 {
890 int ret;
891
892 if (!clkdm)
893 return -EINVAL;
894
895 if (!(clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)) {
896 pr_debug("clockdomain: %s does not support forcing wakeup via software\n",
897 clkdm->name);
898 return -EINVAL;
899 }
900
901 if (!arch_clkdm || !arch_clkdm->clkdm_wakeup)
902 return -EINVAL;
903
904 pr_debug("clockdomain: forcing wakeup on %s\n", clkdm->name);
905
906 clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
907 ret = arch_clkdm->clkdm_wakeup(clkdm);
908 ret |= pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
909
910 return ret;
911 }
912
913
914
915
916
917
918
919
920
921
922 int clkdm_wakeup(struct clockdomain *clkdm)
923 {
924 int ret;
925
926 pwrdm_lock(clkdm->pwrdm.ptr);
927 ret = clkdm_wakeup_nolock(clkdm);
928 pwrdm_unlock(clkdm->pwrdm.ptr);
929
930 return ret;
931 }
932
933
934
935
936
937
938
939
940
941
942
943
944 void clkdm_allow_idle_nolock(struct clockdomain *clkdm)
945 {
946 if (!clkdm)
947 return;
948
949 if (!WARN_ON(!clkdm->forcewake_count))
950 clkdm->forcewake_count--;
951
952 if (clkdm->forcewake_count)
953 return;
954
955 if (!clkdm->usecount && (clkdm->flags & CLKDM_CAN_FORCE_SLEEP))
956 clkdm_sleep_nolock(clkdm);
957
958 if (!(clkdm->flags & CLKDM_CAN_ENABLE_AUTO))
959 return;
960
961 if (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING)
962 return;
963
964 if (!arch_clkdm || !arch_clkdm->clkdm_allow_idle)
965 return;
966
967 pr_debug("clockdomain: enabling automatic idle transitions for %s\n",
968 clkdm->name);
969
970 clkdm->_flags |= _CLKDM_FLAG_HWSUP_ENABLED;
971 arch_clkdm->clkdm_allow_idle(clkdm);
972 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
973 }
974
975
976
977
978
979
980
981
982
983
984
985 void clkdm_allow_idle(struct clockdomain *clkdm)
986 {
987 pwrdm_lock(clkdm->pwrdm.ptr);
988 clkdm_allow_idle_nolock(clkdm);
989 pwrdm_unlock(clkdm->pwrdm.ptr);
990 }
991
992
993
994
995
996
997
998
999
1000
1001
1002 void clkdm_deny_idle_nolock(struct clockdomain *clkdm)
1003 {
1004 if (!clkdm)
1005 return;
1006
1007 if (clkdm->forcewake_count++)
1008 return;
1009
1010 if (clkdm->flags & CLKDM_CAN_FORCE_WAKEUP)
1011 clkdm_wakeup_nolock(clkdm);
1012
1013 if (!(clkdm->flags & CLKDM_CAN_DISABLE_AUTO))
1014 return;
1015
1016 if (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING)
1017 return;
1018
1019 if (!arch_clkdm || !arch_clkdm->clkdm_deny_idle)
1020 return;
1021
1022 pr_debug("clockdomain: disabling automatic idle transitions for %s\n",
1023 clkdm->name);
1024
1025 clkdm->_flags &= ~_CLKDM_FLAG_HWSUP_ENABLED;
1026 arch_clkdm->clkdm_deny_idle(clkdm);
1027 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
1028 }
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039 void clkdm_deny_idle(struct clockdomain *clkdm)
1040 {
1041 pwrdm_lock(clkdm->pwrdm.ptr);
1042 clkdm_deny_idle_nolock(clkdm);
1043 pwrdm_unlock(clkdm->pwrdm.ptr);
1044 }
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057 bool clkdm_in_hwsup(struct clockdomain *clkdm)
1058 {
1059 bool ret;
1060
1061 if (!clkdm)
1062 return false;
1063
1064 ret = (clkdm->_flags & _CLKDM_FLAG_HWSUP_ENABLED) ? true : false;
1065
1066 return ret;
1067 }
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078 bool clkdm_missing_idle_reporting(struct clockdomain *clkdm)
1079 {
1080 if (!clkdm)
1081 return false;
1082
1083 return (clkdm->flags & CLKDM_MISSING_IDLE_REPORTING) ? true : false;
1084 }
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099 void clkdm_add_autodeps(struct clockdomain *clkdm)
1100 {
1101 struct clkdm_autodep *autodep;
1102
1103 if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
1104 return;
1105
1106 for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
1107 if (IS_ERR(autodep->clkdm.ptr))
1108 continue;
1109
1110 pr_debug("clockdomain: %s: adding %s sleepdep/wkdep\n",
1111 clkdm->name, autodep->clkdm.ptr->name);
1112
1113 _clkdm_add_sleepdep(clkdm, autodep->clkdm.ptr);
1114 _clkdm_add_wkdep(clkdm, autodep->clkdm.ptr);
1115 }
1116 }
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129 void clkdm_del_autodeps(struct clockdomain *clkdm)
1130 {
1131 struct clkdm_autodep *autodep;
1132
1133 if (!autodeps || clkdm->flags & CLKDM_NO_AUTODEPS)
1134 return;
1135
1136 for (autodep = autodeps; autodep->clkdm.ptr; autodep++) {
1137 if (IS_ERR(autodep->clkdm.ptr))
1138 continue;
1139
1140 pr_debug("clockdomain: %s: removing %s sleepdep/wkdep\n",
1141 clkdm->name, autodep->clkdm.ptr->name);
1142
1143 _clkdm_del_sleepdep(clkdm, autodep->clkdm.ptr);
1144 _clkdm_del_wkdep(clkdm, autodep->clkdm.ptr);
1145 }
1146 }
1147
1148
1149
1150 static int _clkdm_clk_hwmod_enable(struct clockdomain *clkdm)
1151 {
1152 if (!clkdm || !arch_clkdm || !arch_clkdm->clkdm_clk_enable)
1153 return -EINVAL;
1154
1155 pwrdm_lock(clkdm->pwrdm.ptr);
1156
1157
1158
1159
1160
1161
1162 clkdm->usecount++;
1163 if (clkdm->usecount > 1 && autodeps) {
1164 pwrdm_unlock(clkdm->pwrdm.ptr);
1165 return 0;
1166 }
1167
1168 arch_clkdm->clkdm_clk_enable(clkdm);
1169 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
1170 pwrdm_unlock(clkdm->pwrdm.ptr);
1171
1172 pr_debug("clockdomain: %s: enabled\n", clkdm->name);
1173
1174 return 0;
1175 }
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191 int clkdm_clk_enable(struct clockdomain *clkdm, struct clk *clk)
1192 {
1193
1194
1195
1196
1197
1198 if (!clk)
1199 return -EINVAL;
1200
1201 return _clkdm_clk_hwmod_enable(clkdm);
1202 }
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217 int clkdm_clk_disable(struct clockdomain *clkdm, struct clk *clk)
1218 {
1219 if (!clkdm || !clk || !arch_clkdm || !arch_clkdm->clkdm_clk_disable)
1220 return -EINVAL;
1221
1222 pwrdm_lock(clkdm->pwrdm.ptr);
1223
1224
1225 if ((__clk_get_enable_count(clk) == 0) && clkdm->usecount == 0)
1226 goto ccd_exit;
1227
1228 if (clkdm->usecount == 0) {
1229 pwrdm_unlock(clkdm->pwrdm.ptr);
1230 WARN_ON(1);
1231 return -ERANGE;
1232 }
1233
1234 clkdm->usecount--;
1235 if (clkdm->usecount > 0) {
1236 pwrdm_unlock(clkdm->pwrdm.ptr);
1237 return 0;
1238 }
1239
1240 arch_clkdm->clkdm_clk_disable(clkdm);
1241 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
1242
1243 pr_debug("clockdomain: %s: disabled\n", clkdm->name);
1244
1245 ccd_exit:
1246 pwrdm_unlock(clkdm->pwrdm.ptr);
1247
1248 return 0;
1249 }
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266 int clkdm_hwmod_enable(struct clockdomain *clkdm, struct omap_hwmod *oh)
1267 {
1268
1269 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1270 return 0;
1271
1272
1273
1274
1275
1276
1277 if (!oh)
1278 return -EINVAL;
1279
1280 return _clkdm_clk_hwmod_enable(clkdm);
1281 }
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297 int clkdm_hwmod_disable(struct clockdomain *clkdm, struct omap_hwmod *oh)
1298 {
1299
1300 if (cpu_is_omap24xx() || cpu_is_omap34xx())
1301 return 0;
1302
1303
1304
1305
1306
1307
1308 if (!clkdm || !oh || !arch_clkdm || !arch_clkdm->clkdm_clk_disable)
1309 return -EINVAL;
1310
1311 pwrdm_lock(clkdm->pwrdm.ptr);
1312
1313 if (clkdm->usecount == 0) {
1314 pwrdm_unlock(clkdm->pwrdm.ptr);
1315 WARN_ON(1);
1316 return -ERANGE;
1317 }
1318
1319 clkdm->usecount--;
1320 if (clkdm->usecount > 0) {
1321 pwrdm_unlock(clkdm->pwrdm.ptr);
1322 return 0;
1323 }
1324
1325 arch_clkdm->clkdm_clk_disable(clkdm);
1326 pwrdm_state_switch_nolock(clkdm->pwrdm.ptr);
1327 pwrdm_unlock(clkdm->pwrdm.ptr);
1328
1329 pr_debug("clockdomain: %s: disabled\n", clkdm->name);
1330
1331 return 0;
1332 }
1333
1334
1335
1336
1337
1338
1339
1340 static int _clkdm_save_context(struct clockdomain *clkdm, void *ununsed)
1341 {
1342 if (!arch_clkdm || !arch_clkdm->clkdm_save_context)
1343 return -EINVAL;
1344
1345 return arch_clkdm->clkdm_save_context(clkdm);
1346 }
1347
1348
1349
1350
1351
1352
1353 static int _clkdm_restore_context(struct clockdomain *clkdm, void *ununsed)
1354 {
1355 if (!arch_clkdm || !arch_clkdm->clkdm_restore_context)
1356 return -EINVAL;
1357
1358 return arch_clkdm->clkdm_restore_context(clkdm);
1359 }
1360
1361
1362
1363
1364
1365
1366 void clkdm_save_context(void)
1367 {
1368 clkdm_for_each(_clkdm_save_context, NULL);
1369 }
1370
1371
1372
1373
1374
1375
1376 void clkdm_restore_context(void)
1377 {
1378 clkdm_for_each(_clkdm_restore_context, NULL);
1379 }