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 if (prcm_irq_setup->xlate_irq)
222 irq = prcm_irq_setup->xlate_irq(prcm_irq_setup->irq);
223 else
224 irq = prcm_irq_setup->irq;
225 irq_set_chained_handler(irq, NULL);
226
227 if (prcm_irq_setup->base_irq > 0)
228 irq_free_descs(prcm_irq_setup->base_irq,
229 prcm_irq_setup->nr_regs * 32);
230 prcm_irq_setup->base_irq = 0;
231}
232
233void omap_prcm_irq_prepare(void)
234{
235 prcm_irq_setup->suspended = true;
236}
237
238void omap_prcm_irq_complete(void)
239{
240 prcm_irq_setup->suspended = false;
241
242
243 if (!prcm_irq_setup->suspend_save_flag)
244 return;
245
246 prcm_irq_setup->suspend_save_flag = false;
247
248
249
250
251
252
253 prcm_irq_setup->restore_irqen(prcm_irq_setup->saved_mask);
254}
255
256
257
258
259
260
261
262
263
264
265
266int omap_prcm_register_chain_handler(struct omap_prcm_irq_setup *irq_setup)
267{
268 int nr_regs;
269 u32 mask[OMAP_PRCM_MAX_NR_PENDING_REG];
270 int offset, i, irq;
271 struct irq_chip_generic *gc;
272 struct irq_chip_type *ct;
273
274 if (!irq_setup)
275 return -EINVAL;
276
277 nr_regs = irq_setup->nr_regs;
278
279 if (prcm_irq_setup) {
280 pr_err("PRCM: already initialized; won't reinitialize\n");
281 return -EINVAL;
282 }
283
284 if (nr_regs > OMAP_PRCM_MAX_NR_PENDING_REG) {
285 pr_err("PRCM: nr_regs too large\n");
286 return -EINVAL;
287 }
288
289 prcm_irq_setup = irq_setup;
290
291 prcm_irq_chips = kzalloc(sizeof(void *) * nr_regs, GFP_KERNEL);
292 prcm_irq_setup->saved_mask = kzalloc(sizeof(u32) * nr_regs, GFP_KERNEL);
293 prcm_irq_setup->priority_mask = kzalloc(sizeof(u32) * nr_regs,
294 GFP_KERNEL);
295
296 if (!prcm_irq_chips || !prcm_irq_setup->saved_mask ||
297 !prcm_irq_setup->priority_mask)
298 goto err;
299
300 memset(mask, 0, sizeof(mask));
301
302 for (i = 0; i < irq_setup->nr_irqs; i++) {
303 offset = irq_setup->irqs[i].offset;
304 mask[offset >> 5] |= 1 << (offset & 0x1f);
305 if (irq_setup->irqs[i].priority)
306 irq_setup->priority_mask[offset >> 5] |=
307 1 << (offset & 0x1f);
308 }
309
310 if (irq_setup->xlate_irq)
311 irq = irq_setup->xlate_irq(irq_setup->irq);
312 else
313 irq = irq_setup->irq;
314 irq_set_chained_handler(irq, omap_prcm_irq_handler);
315
316 irq_setup->base_irq = irq_alloc_descs(-1, 0, irq_setup->nr_regs * 32,
317 0);
318
319 if (irq_setup->base_irq < 0) {
320 pr_err("PRCM: failed to allocate irq descs: %d\n",
321 irq_setup->base_irq);
322 goto err;
323 }
324
325 for (i = 0; i < irq_setup->nr_regs; i++) {
326 gc = irq_alloc_generic_chip("PRCM", 1,
327 irq_setup->base_irq + i * 32, prm_base.va,
328 handle_level_irq);
329
330 if (!gc) {
331 pr_err("PRCM: failed to allocate generic chip\n");
332 goto err;
333 }
334 ct = gc->chip_types;
335 ct->chip.irq_ack = irq_gc_ack_set_bit;
336 ct->chip.irq_mask = irq_gc_mask_clr_bit;
337 ct->chip.irq_unmask = irq_gc_mask_set_bit;
338
339 ct->regs.ack = irq_setup->ack + i * 4;
340 ct->regs.mask = irq_setup->mask + i * 4;
341
342 irq_setup_generic_chip(gc, mask[i], 0, IRQ_NOREQUEST, 0);
343 prcm_irq_chips[i] = gc;
344 }
345
346 irq = omap_prcm_event_to_irq("io");
347 omap_pcs_legacy_init(irq, irq_setup->reconfigure_io_chain);
348
349 return 0;
350
351err:
352 omap_prcm_irq_cleanup();
353 return -ENOMEM;
354}
355
356
357
358
359
360
361
362void __init omap2_set_globals_prm(void __iomem *prm)
363{
364 prm_base.va = prm;
365}
366
367
368
369
370
371
372
373
374
375
376
377
378
379u32 prm_read_reset_sources(void)
380{
381 u32 ret = 1 << OMAP_UNKNOWN_RST_SRC_ID_SHIFT;
382
383 if (prm_ll_data->read_reset_sources)
384 ret = prm_ll_data->read_reset_sources();
385 else
386 WARN_ONCE(1, "prm: %s: no mapping function defined for reset sources\n", __func__);
387
388 return ret;
389}
390
391
392
393
394
395
396
397
398
399
400
401
402
403bool prm_was_any_context_lost_old(u8 part, s16 inst, u16 idx)
404{
405 bool ret = true;
406
407 if (prm_ll_data->was_any_context_lost_old)
408 ret = prm_ll_data->was_any_context_lost_old(part, inst, idx);
409 else
410 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
411 __func__);
412
413 return ret;
414}
415
416
417
418
419
420
421
422
423
424
425
426
427void prm_clear_context_loss_flags_old(u8 part, s16 inst, u16 idx)
428{
429 if (prm_ll_data->clear_context_loss_flags_old)
430 prm_ll_data->clear_context_loss_flags_old(part, inst, idx);
431 else
432 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
433 __func__);
434}
435
436
437
438
439
440
441
442
443
444
445int omap_prm_assert_hardreset(u8 shift, u8 part, s16 prm_mod, u16 offset)
446{
447 if (!prm_ll_data->assert_hardreset) {
448 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
449 __func__);
450 return -EINVAL;
451 }
452
453 return prm_ll_data->assert_hardreset(shift, part, prm_mod, offset);
454}
455
456
457
458
459
460
461
462
463
464
465
466
467int omap_prm_deassert_hardreset(u8 shift, u8 st_shift, u8 part, s16 prm_mod,
468 u16 offset, u16 st_offset)
469{
470 if (!prm_ll_data->deassert_hardreset) {
471 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
472 __func__);
473 return -EINVAL;
474 }
475
476 return prm_ll_data->deassert_hardreset(shift, st_shift, part, prm_mod,
477 offset, st_offset);
478}
479
480
481
482
483
484
485
486
487
488
489int omap_prm_is_hardreset_asserted(u8 shift, u8 part, s16 prm_mod, u16 offset)
490{
491 if (!prm_ll_data->is_hardreset_asserted) {
492 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
493 __func__);
494 return -EINVAL;
495 }
496
497 return prm_ll_data->is_hardreset_asserted(shift, part, prm_mod, offset);
498}
499
500
501
502
503
504
505
506
507
508void omap_prm_reconfigure_io_chain(void)
509{
510 if (!prcm_irq_setup || !prcm_irq_setup->reconfigure_io_chain)
511 return;
512
513 prcm_irq_setup->reconfigure_io_chain();
514}
515
516
517
518
519
520
521void omap_prm_reset_system(void)
522{
523 if (!prm_ll_data->reset_system) {
524 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
525 __func__);
526 return;
527 }
528
529 prm_ll_data->reset_system();
530
531 while (1)
532 cpu_relax();
533}
534
535
536
537
538
539
540
541
542
543
544
545int omap_prm_clear_mod_irqs(s16 module, u8 regs, u32 wkst_mask)
546{
547 if (!prm_ll_data->clear_mod_irqs) {
548 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
549 __func__);
550 return -EINVAL;
551 }
552
553 return prm_ll_data->clear_mod_irqs(module, regs, wkst_mask);
554}
555
556
557
558
559
560
561
562u32 omap_prm_vp_check_txdone(u8 vp_id)
563{
564 if (!prm_ll_data->vp_check_txdone) {
565 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
566 __func__);
567 return 0;
568 }
569
570 return prm_ll_data->vp_check_txdone(vp_id);
571}
572
573
574
575
576
577
578
579void omap_prm_vp_clear_txdone(u8 vp_id)
580{
581 if (!prm_ll_data->vp_clear_txdone) {
582 WARN_ONCE(1, "prm: %s: no mapping function defined\n",
583 __func__);
584 return;
585 }
586
587 prm_ll_data->vp_clear_txdone(vp_id);
588}
589
590
591
592
593
594
595
596
597
598
599
600
601int prm_register(struct prm_ll_data *pld)
602{
603 if (!pld)
604 return -EINVAL;
605
606 if (prm_ll_data != &null_prm_ll_data)
607 return -EEXIST;
608
609 prm_ll_data = pld;
610
611 return 0;
612}
613
614
615
616
617
618
619
620
621
622
623
624
625int prm_unregister(struct prm_ll_data *pld)
626{
627 if (!pld || prm_ll_data != pld)
628 return -EINVAL;
629
630 prm_ll_data = &null_prm_ll_data;
631
632 return 0;
633}
634
635#ifdef CONFIG_ARCH_OMAP2
636static struct omap_prcm_init_data omap2_prm_data __initdata = {
637 .index = TI_CLKM_PRM,
638 .init = omap2xxx_prm_init,
639};
640#endif
641
642#ifdef CONFIG_ARCH_OMAP3
643static struct omap_prcm_init_data omap3_prm_data __initdata = {
644 .index = TI_CLKM_PRM,
645 .init = omap3xxx_prm_init,
646
647
648
649
650
651 .offset = -OMAP3430_IVA2_MOD,
652};
653#endif
654
655#if defined(CONFIG_SOC_AM33XX) || defined(CONFIG_SOC_TI81XX)
656static struct omap_prcm_init_data am3_prm_data __initdata = {
657 .index = TI_CLKM_PRM,
658 .init = am33xx_prm_init,
659};
660#endif
661
662#ifdef CONFIG_SOC_TI81XX
663static struct omap_prcm_init_data dm814_pllss_data __initdata = {
664 .index = TI_CLKM_PLLSS,
665 .init = am33xx_prm_init,
666};
667#endif
668
669#ifdef CONFIG_ARCH_OMAP4
670static struct omap_prcm_init_data omap4_prm_data __initdata = {
671 .index = TI_CLKM_PRM,
672 .init = omap44xx_prm_init,
673 .device_inst_offset = OMAP4430_PRM_DEVICE_INST,
674 .flags = PRM_HAS_IO_WAKEUP | PRM_HAS_VOLTAGE | PRM_IRQ_DEFAULT,
675};
676#endif
677
678#ifdef CONFIG_SOC_OMAP5
679static struct omap_prcm_init_data omap5_prm_data __initdata = {
680 .index = TI_CLKM_PRM,
681 .init = omap44xx_prm_init,
682 .device_inst_offset = OMAP54XX_PRM_DEVICE_INST,
683 .flags = PRM_HAS_IO_WAKEUP | PRM_HAS_VOLTAGE,
684};
685#endif
686
687#ifdef CONFIG_SOC_DRA7XX
688static struct omap_prcm_init_data dra7_prm_data __initdata = {
689 .index = TI_CLKM_PRM,
690 .init = omap44xx_prm_init,
691 .device_inst_offset = DRA7XX_PRM_DEVICE_INST,
692 .flags = PRM_HAS_IO_WAKEUP,
693};
694#endif
695
696#ifdef CONFIG_SOC_AM43XX
697static struct omap_prcm_init_data am4_prm_data __initdata = {
698 .index = TI_CLKM_PRM,
699 .init = omap44xx_prm_init,
700 .device_inst_offset = AM43XX_PRM_DEVICE_INST,
701 .flags = PRM_HAS_IO_WAKEUP,
702};
703#endif
704
705#if defined(CONFIG_ARCH_OMAP4) || defined(CONFIG_SOC_OMAP5)
706static struct omap_prcm_init_data scrm_data __initdata = {
707 .index = TI_CLKM_SCRM,
708};
709#endif
710
711static const struct of_device_id omap_prcm_dt_match_table[] __initconst = {
712#ifdef CONFIG_SOC_AM33XX
713 { .compatible = "ti,am3-prcm", .data = &am3_prm_data },
714#endif
715#ifdef CONFIG_SOC_AM43XX
716 { .compatible = "ti,am4-prcm", .data = &am4_prm_data },
717#endif
718#ifdef CONFIG_SOC_TI81XX
719 { .compatible = "ti,dm814-prcm", .data = &am3_prm_data },
720 { .compatible = "ti,dm814-pllss", .data = &dm814_pllss_data },
721 { .compatible = "ti,dm816-prcm", .data = &am3_prm_data },
722#endif
723#ifdef CONFIG_ARCH_OMAP2
724 { .compatible = "ti,omap2-prcm", .data = &omap2_prm_data },
725#endif
726#ifdef CONFIG_ARCH_OMAP3
727 { .compatible = "ti,omap3-prm", .data = &omap3_prm_data },
728#endif
729#ifdef CONFIG_ARCH_OMAP4
730 { .compatible = "ti,omap4-prm", .data = &omap4_prm_data },
731 { .compatible = "ti,omap4-scrm", .data = &scrm_data },
732#endif
733#ifdef CONFIG_SOC_OMAP5
734 { .compatible = "ti,omap5-prm", .data = &omap5_prm_data },
735 { .compatible = "ti,omap5-scrm", .data = &scrm_data },
736#endif
737#ifdef CONFIG_SOC_DRA7XX
738 { .compatible = "ti,dra7-prm", .data = &dra7_prm_data },
739#endif
740 { }
741};
742
743
744
745
746
747
748
749
750int __init omap2_prm_base_init(void)
751{
752 struct device_node *np;
753 const struct of_device_id *match;
754 struct omap_prcm_init_data *data;
755 struct resource res;
756 int ret;
757
758 for_each_matching_node_and_match(np, omap_prcm_dt_match_table, &match) {
759 data = (struct omap_prcm_init_data *)match->data;
760
761 ret = of_address_to_resource(np, 0, &res);
762 if (ret)
763 return ret;
764
765 data->mem = ioremap(res.start, resource_size(&res));
766
767 if (data->index == TI_CLKM_PRM) {
768 prm_base.va = data->mem + data->offset;
769 prm_base.pa = res.start + data->offset;
770 }
771
772 data->np = np;
773
774 if (data->init)
775 data->init(data);
776 }
777
778 return 0;
779}
780
781int __init omap2_prcm_base_init(void)
782{
783 int ret;
784
785 ret = omap2_prm_base_init();
786 if (ret)
787 return ret;
788
789 return omap2_cm_base_init();
790}
791
792
793
794
795
796
797
798int __init omap_prcm_init(void)
799{
800 struct device_node *np;
801 const struct of_device_id *match;
802 const struct omap_prcm_init_data *data;
803 int ret;
804
805 for_each_matching_node_and_match(np, omap_prcm_dt_match_table, &match) {
806 data = match->data;
807
808 ret = omap2_clk_provider_init(np, data->index, NULL, data->mem);
809 if (ret)
810 return ret;
811 }
812
813 omap_cm_init();
814
815 return 0;
816}
817
818static int __init prm_late_init(void)
819{
820 if (prm_ll_data->late_init)
821 return prm_ll_data->late_init();
822 return 0;
823}
824subsys_initcall(prm_late_init);
825