1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/io.h>
23#include <linux/irq.h>
24#include <linux/interrupt.h>
25#include <linux/slab.h>
26#include <linux/of.h>
27#include <linux/of_address.h>
28#include <linux/clk-provider.h>
29#include <linux/clk/ti.h>
30
31#include "soc.h"
32#include "prm2xxx_3xxx.h"
33#include "prm2xxx.h"
34#include "prm3xxx.h"
35#include "prm33xx.h"
36#include "prm44xx.h"
37#include "prm54xx.h"
38#include "prm7xx.h"
39#include "prcm43xx.h"
40#include "common.h"
41#include "clock.h"
42#include "cm.h"
43#include "control.h"
44
45
46
47
48
49
50
51#define OMAP_PRCM_MAX_NR_PENDING_REG 2
52
53
54
55
56
57
58
59static struct irq_chip_generic **prcm_irq_chips;
60
61
62
63
64
65
66static struct omap_prcm_irq_setup *prcm_irq_setup;
67
68
69struct omap_domain_base prm_base;
70
71u16 prm_features;
72
73
74
75
76
77static struct prm_ll_data null_prm_ll_data;
78static struct prm_ll_data *prm_ll_data = &null_prm_ll_data;
79
80
81
82
83
84
85static void omap_prcm_events_filter_priority(unsigned long *events,
86 unsigned long *priority_events)
87{
88 int i;
89
90 for (i = 0; i < prcm_irq_setup->nr_regs; i++) {
91 priority_events[i] =
92 events[i] & prcm_irq_setup->priority_mask[i];
93 events[i] ^= priority_events[i];
94 }
95}
96
97
98
99
100
101
102
103
104
105static void omap_prcm_irq_handler(struct irq_desc *desc)
106{
107 unsigned long pending[OMAP_PRCM_MAX_NR_PENDING_REG];
108 unsigned long priority_pending[OMAP_PRCM_MAX_NR_PENDING_REG];
109 struct irq_chip *chip = irq_desc_get_chip(desc);
110 unsigned int virtirq;
111 int nr_irq = prcm_irq_setup->nr_regs * 32;
112
113
114
115
116
117
118
119
120
121
122
123 if (prcm_irq_setup->suspended) {
124 prcm_irq_setup->save_and_clear_irqen(prcm_irq_setup->saved_mask);
125 prcm_irq_setup->suspend_save_flag = true;
126 }
127
128
129
130
131
132 while (!prcm_irq_setup->suspended) {
133 prcm_irq_setup->read_pending_irqs(pending);
134
135
136 if (find_first_bit(pending, nr_irq) >= nr_irq)
137 break;
138
139 omap_prcm_events_filter_priority(pending, priority_pending);
140
141
142
143
144
145
146
147 for_each_set_bit(virtirq, priority_pending, nr_irq)
148 generic_handle_irq(prcm_irq_setup->base_irq + virtirq);
149
150
151 for_each_set_bit(virtirq, pending, nr_irq)
152 generic_handle_irq(prcm_irq_setup->base_irq + virtirq);
153 }
154 if (chip->irq_ack)
155 chip->irq_ack(&desc->irq_data);
156 if (chip->irq_eoi)
157 chip->irq_eoi(&desc->irq_data);
158 chip->irq_unmask(&desc->irq_data);
159
160 prcm_irq_setup->ocp_barrier();
161}
162
163
164
165
166
167
168
169
170
171
172
173int omap_prcm_event_to_irq(const char *name)
174{
175 int i;
176
177 if (!prcm_irq_setup || !name)
178 return -ENOENT;
179
180 for (i = 0; i < prcm_irq_setup->nr_irqs; i++)
181 if (!strcmp(prcm_irq_setup->irqs[i].name, name))
182 return prcm_irq_setup->base_irq +
183 prcm_irq_setup->irqs[i].offset;
184
185 return -ENOENT;
186}
187
188
189
190
191
192
193
194void omap_prcm_irq_cleanup(void)
195{
196 unsigned int irq;
197 int i;
198
199 if (!prcm_irq_setup) {
200 pr_err("PRCM: IRQ handler not initialized; cannot cleanup\n");
201 return;
202 }
203
204 if (prcm_irq_chips) {
205 for (i = 0; i < prcm_irq_setup->nr_regs; i++) {
206 if (prcm_irq_chips[i])
207 irq_remove_generic_chip(prcm_irq_chips[i],
208 0xffffffff, 0, 0);
209 prcm_irq_chips[i] = NULL;
210 }
211 kfree(prcm_irq_chips);
212 prcm_irq_chips = NULL;
213 }
214
215 kfree(prcm_irq_setup->saved_mask);
216 prcm_irq_setup->saved_mask = NULL;
217
218 kfree(prcm_irq_setup->priority_mask);
219 prcm_irq_setup->priority_mask = NULL;
220
221 irq = prcm_irq_setup->irq;
222 irq_set_chained_handler(irq, NULL);
223
224 if (prcm_irq_setup->base_irq > 0)
225 irq_free_descs(prcm_irq_setup->base_irq,
226 prcm_irq_setup->nr_regs * 32);
227 prcm_irq_setup->base_irq = 0;
228}
229
230void omap_prcm_irq_prepare(void)
231{
232 prcm_irq_setup->suspended = true;
233}
234
235void omap_prcm_irq_complete(void)
236{
237 prcm_irq_setup->suspended = false;
238
239
240 if (!prcm_irq_setup->suspend_save_flag)
241 return;
242
243 prcm_irq_setup->suspend_save_flag = false;
244
245
246
247
248
249
250 prcm_irq_setup->restore_irqen(prcm_irq_setup->saved_mask);
251}
252
253
254
255
256
257
258
259
260
261
262
263int omap_prcm_register_chain_handler(struct omap_prcm_irq_setup *irq_setup)
264{
265 int nr_regs;
266 u32 mask[OMAP_PRCM_MAX_NR_PENDING_REG];
267 int offset, i, irq;
268 struct irq_chip_generic *gc;
269 struct irq_chip_type *ct;
270
271 if (!irq_setup)
272 return -EINVAL;
273
274 nr_regs = irq_setup->nr_regs;
275
276 if (prcm_irq_setup) {
277 pr_err("PRCM: already initialized; won't reinitialize\n");
278 return -EINVAL;
279 }
280
281 if (nr_regs > OMAP_PRCM_MAX_NR_PENDING_REG) {
282 pr_err("PRCM: nr_regs too large\n");
283 return -EINVAL;
284 }
285
286 prcm_irq_setup = irq_setup;
287
288 prcm_irq_chips = kcalloc(nr_regs, sizeof(void *), GFP_KERNEL);
289 prcm_irq_setup->saved_mask = kcalloc(nr_regs, sizeof(u32),
290 GFP_KERNEL);
291 prcm_irq_setup->priority_mask = kcalloc(nr_regs, sizeof(u32),
292 GFP_KERNEL);
293
294 if (!prcm_irq_chips || !prcm_irq_setup->saved_mask ||
295 !prcm_irq_setup->priority_mask)
296 goto err;
297
298 memset(mask, 0, sizeof(mask));
299
300 for (i = 0; i < irq_setup->nr_irqs; i++) {
301 offset = irq_setup->irqs[i].offset;
302 mask[offset >> 5] |= 1 << (offset & 0x1f);
303 if (irq_setup->irqs[i].priority)
304 irq_setup->priority_mask[offset >> 5] |=
305 1 << (offset & 0x1f);
306 }
307
308 irq = irq_setup->irq;
309 irq_set_chained_handler(irq, omap_prcm_irq_handler);
310
311 irq_setup->base_irq = irq_alloc_descs(-1, 0, irq_setup->nr_regs * 32,
312 0);
313
314 if (irq_setup->base_irq < 0) {
315 pr_err("PRCM: failed to allocate irq descs: %d\n",
316 irq_setup->base_irq);
317 goto err;
318 }
319
320 for (i = 0; i < irq_setup->nr_regs; i++) {
321 gc = irq_alloc_generic_chip("PRCM", 1,
322 irq_setup->base_irq + i * 32, prm_base.va,
323 handle_level_irq);
324
325 if (!gc) {
326 pr_err("PRCM: failed to allocate generic chip\n");
327 goto err;
328 }
329 ct = gc->chip_types;
330 ct->chip.irq_ack = irq_gc_ack_set_bit;
331 ct->chip.irq_mask = irq_gc_mask_clr_bit;
332 ct->chip.irq_unmask = irq_gc_mask_set_bit;
333
334 ct->regs.ack = irq_setup->ack + i * 4;
335 ct->regs.mask = irq_setup->mask + i * 4;
336
337 irq_setup_generic_chip(gc, mask[i], 0, IRQ_NOREQUEST, 0);
338 prcm_irq_chips[i] = gc;
339 }
340
341 irq = omap_prcm_event_to_irq("io");
342 omap_pcs_legacy_init(irq, irq_setup->reconfigure_io_chain);
343
344 return 0;
345
346err:
347 omap_prcm_irq_cleanup();
348 return -ENOMEM;
349}
350
351
352
353
354
355
356
357void __init omap2_set_globals_prm(void __iomem *prm)
358{
359 prm_base.va = prm;
360}
361
362
363
364
365
366
367
368
369
370
371
372
373
374u32 prm_read_reset_sources(void)
375{
376 u32 ret = 1 << OMAP_UNKNOWN_RST_SRC_ID_SHIFT;
377
378 if (prm_ll_data->read_reset_sources)
379 ret = prm_ll_data->read_reset_sources();
380 else
381 WARN_ONCE(1, "prm: %s: no mapping function defined for reset sources\n", __func__);
382
383 return ret;
384}
385
386
387
388
389
390
391
392
393
394
395
396
397
398bool prm_was_any_context_lost_old(u8 part, s16 inst, u16 idx)
399{
400 bool ret = true;
401
402 if (prm_ll_data->was_any_context_lost_old)
403 ret = prm_ll_data->was_any_context_lost_old(part, inst, idx);
404 else
405 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
406 __func__);
407
408 return ret;
409}
410
411
412
413
414
415
416
417
418
419
420
421
422void prm_clear_context_loss_flags_old(u8 part, s16 inst, u16 idx)
423{
424 if (prm_ll_data->clear_context_loss_flags_old)
425 prm_ll_data->clear_context_loss_flags_old(part, inst, idx);
426 else
427 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
428 __func__);
429}
430
431
432
433
434
435
436
437
438
439
440int omap_prm_assert_hardreset(u8 shift, u8 part, s16 prm_mod, u16 offset)
441{
442 if (!prm_ll_data->assert_hardreset) {
443 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
444 __func__);
445 return -EINVAL;
446 }
447
448 return prm_ll_data->assert_hardreset(shift, part, prm_mod, offset);
449}
450
451
452
453
454
455
456
457
458
459
460
461
462int omap_prm_deassert_hardreset(u8 shift, u8 st_shift, u8 part, s16 prm_mod,
463 u16 offset, u16 st_offset)
464{
465 if (!prm_ll_data->deassert_hardreset) {
466 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
467 __func__);
468 return -EINVAL;
469 }
470
471 return prm_ll_data->deassert_hardreset(shift, st_shift, part, prm_mod,
472 offset, st_offset);
473}
474
475
476
477
478
479
480
481
482
483
484int omap_prm_is_hardreset_asserted(u8 shift, u8 part, s16 prm_mod, u16 offset)
485{
486 if (!prm_ll_data->is_hardreset_asserted) {
487 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
488 __func__);
489 return -EINVAL;
490 }
491
492 return prm_ll_data->is_hardreset_asserted(shift, part, prm_mod, offset);
493}
494
495
496
497
498
499
500
501
502
503void omap_prm_reconfigure_io_chain(void)
504{
505 if (!prcm_irq_setup || !prcm_irq_setup->reconfigure_io_chain)
506 return;
507
508 prcm_irq_setup->reconfigure_io_chain();
509}
510
511
512
513
514
515
516void omap_prm_reset_system(void)
517{
518 if (!prm_ll_data->reset_system) {
519 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
520 __func__);
521 return;
522 }
523
524 prm_ll_data->reset_system();
525
526 while (1) {
527 cpu_relax();
528 wfe();
529 }
530}
531
532
533
534
535
536
537
538
539
540
541
542int omap_prm_clear_mod_irqs(s16 module, u8 regs, u32 wkst_mask)
543{
544 if (!prm_ll_data->clear_mod_irqs) {
545 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
546 __func__);
547 return -EINVAL;
548 }
549
550 return prm_ll_data->clear_mod_irqs(module, regs, wkst_mask);
551}
552
553
554
555
556
557
558
559u32 omap_prm_vp_check_txdone(u8 vp_id)
560{
561 if (!prm_ll_data->vp_check_txdone) {
562 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
563 __func__);
564 return 0;
565 }
566
567 return prm_ll_data->vp_check_txdone(vp_id);
568}
569
570
571
572
573
574
575
576void omap_prm_vp_clear_txdone(u8 vp_id)
577{
578 if (!prm_ll_data->vp_clear_txdone) {
579 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
580 __func__);
581 return;
582 }
583
584 prm_ll_data->vp_clear_txdone(vp_id);
585}
586
587
588
589
590
591
592
593
594
595
596
597
598int prm_register(struct prm_ll_data *pld)
599{
600 if (!pld)
601 return -EINVAL;
602
603 if (prm_ll_data != &null_prm_ll_data)
604 return -EEXIST;
605
606 prm_ll_data = pld;
607
608 return 0;
609}
610
611
612
613
614
615
616
617
618
619
620
621
622int prm_unregister(struct prm_ll_data *pld)
623{
624 if (!pld || prm_ll_data != pld)
625 return -EINVAL;
626
627 prm_ll_data = &null_prm_ll_data;
628
629 return 0;
630}
631
632#ifdef CONFIG_ARCH_OMAP2
633static struct omap_prcm_init_data omap2_prm_data __initdata = {
634 .index = TI_CLKM_PRM,
635 .init = omap2xxx_prm_init,
636};
637#endif
638
639#ifdef CONFIG_ARCH_OMAP3
640static struct omap_prcm_init_data omap3_prm_data __initdata = {
641 .index = TI_CLKM_PRM,
642 .init = omap3xxx_prm_init,
643
644
645
646
647
648 .offset = -OMAP3430_IVA2_MOD,
649};
650#endif
651
652#if defined(CONFIG_SOC_AM33XX) || defined(CONFIG_SOC_TI81XX)
653static struct omap_prcm_init_data am3_prm_data __initdata = {
654 .index = TI_CLKM_PRM,
655 .init = am33xx_prm_init,
656};
657#endif
658
659#ifdef CONFIG_SOC_TI81XX
660static struct omap_prcm_init_data dm814_pllss_data __initdata = {
661 .index = TI_CLKM_PLLSS,
662 .init = am33xx_prm_init,
663};
664#endif
665
666#ifdef CONFIG_ARCH_OMAP4
667static struct omap_prcm_init_data omap4_prm_data __initdata = {
668 .index = TI_CLKM_PRM,
669 .init = omap44xx_prm_init,
670 .device_inst_offset = OMAP4430_PRM_DEVICE_INST,
671 .flags = PRM_HAS_IO_WAKEUP | PRM_HAS_VOLTAGE,
672};
673#endif
674
675#ifdef CONFIG_SOC_OMAP5
676static struct omap_prcm_init_data omap5_prm_data __initdata = {
677 .index = TI_CLKM_PRM,
678 .init = omap44xx_prm_init,
679 .device_inst_offset = OMAP54XX_PRM_DEVICE_INST,
680 .flags = PRM_HAS_IO_WAKEUP | PRM_HAS_VOLTAGE,
681};
682#endif
683
684#ifdef CONFIG_SOC_DRA7XX
685static struct omap_prcm_init_data dra7_prm_data __initdata = {
686 .index = TI_CLKM_PRM,
687 .init = omap44xx_prm_init,
688 .device_inst_offset = DRA7XX_PRM_DEVICE_INST,
689 .flags = PRM_HAS_IO_WAKEUP,
690};
691#endif
692
693#ifdef CONFIG_SOC_AM43XX
694static struct omap_prcm_init_data am4_prm_data __initdata = {
695 .index = TI_CLKM_PRM,
696 .init = omap44xx_prm_init,
697 .device_inst_offset = AM43XX_PRM_DEVICE_INST,
698 .flags = PRM_HAS_IO_WAKEUP,
699};
700#endif
701
702#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
703static struct omap_prcm_init_data scrm_data __initdata = {
704 .index = TI_CLKM_SCRM,
705};
706#endif
707
708static const struct of_device_id omap_prcm_dt_match_table[] __initconst = {
709#ifdef CONFIG_SOC_AM33XX
710 { .compatible = "ti,am3-prcm", .data = &am3_prm_data },
711#endif
712#ifdef CONFIG_SOC_AM43XX
713 { .compatible = "ti,am4-prcm", .data = &am4_prm_data },
714#endif
715#ifdef CONFIG_SOC_TI81XX
716 { .compatible = "ti,dm814-prcm", .data = &am3_prm_data },
717 { .compatible = "ti,dm814-pllss", .data = &dm814_pllss_data },
718 { .compatible = "ti,dm816-prcm", .data = &am3_prm_data },
719#endif
720#ifdef CONFIG_ARCH_OMAP2
721 { .compatible = "ti,omap2-prcm", .data = &omap2_prm_data },
722#endif
723#ifdef CONFIG_ARCH_OMAP3
724 { .compatible = "ti,omap3-prm", .data = &omap3_prm_data },
725#endif
726#ifdef CONFIG_ARCH_OMAP4
727 { .compatible = "ti,omap4-prm", .data = &omap4_prm_data },
728 { .compatible = "ti,omap4-scrm", .data = &scrm_data },
729#endif
730#ifdef CONFIG_SOC_OMAP5
731 { .compatible = "ti,omap5-prm", .data = &omap5_prm_data },
732 { .compatible = "ti,omap5-scrm", .data = &scrm_data },
733#endif
734#ifdef CONFIG_SOC_DRA7XX
735 { .compatible = "ti,dra7-prm", .data = &dra7_prm_data },
736#endif
737 { }
738};
739
740
741
742
743
744
745
746
747int __init omap2_prm_base_init(void)
748{
749 struct device_node *np;
750 const struct of_device_id *match;
751 struct omap_prcm_init_data *data;
752 struct resource res;
753 int ret;
754
755 for_each_matching_node_and_match(np, omap_prcm_dt_match_table, &match) {
756 data = (struct omap_prcm_init_data *)match->data;
757
758 ret = of_address_to_resource(np, 0, &res);
759 if (ret)
760 return ret;
761
762 data->mem = ioremap(res.start, resource_size(&res));
763
764 if (data->index == TI_CLKM_PRM) {
765 prm_base.va = data->mem + data->offset;
766 prm_base.pa = res.start + data->offset;
767 }
768
769 data->np = np;
770
771 if (data->init)
772 data->init(data);
773 }
774
775 return 0;
776}
777
778int __init omap2_prcm_base_init(void)
779{
780 int ret;
781
782 ret = omap2_prm_base_init();
783 if (ret)
784 return ret;
785
786 return omap2_cm_base_init();
787}
788
789
790
791
792
793
794
795int __init omap_prcm_init(void)
796{
797 struct device_node *np;
798 const struct of_device_id *match;
799 const struct omap_prcm_init_data *data;
800 int ret;
801
802 for_each_matching_node_and_match(np, omap_prcm_dt_match_table, &match) {
803 data = match->data;
804
805 ret = omap2_clk_provider_init(np, data->index, NULL, data->mem);
806 if (ret)
807 return ret;
808 }
809
810 omap_cm_init();
811
812 return 0;
813}
814
815static int __init prm_late_init(void)
816{
817 if (prm_ll_data->late_init)
818 return prm_ll_data->late_init();
819 return 0;
820}
821subsys_initcall(prm_late_init);
822