1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/arch/arm/mach-integrator/core.c
4 *
5 * Copyright (C) 2000-2003 Deep Blue Solutions Ltd
6 */
7 #include <linux/types.h>
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/device.h>
11 #include <linux/export.h>
12 #include <linux/spinlock.h>
13 #include <linux/interrupt.h>
14 #include <linux/irq.h>
15 #include <linux/memblock.h>
16 #include <linux/sched.h>
17 #include <linux/smp.h>
18 #include <linux/amba/bus.h>
19 #include <linux/amba/serial.h>
20 #include <linux/io.h>
21 #include <linux/stat.h>
22 #include <linux/of.h>
23 #include <linux/of_address.h>
24 #include <linux/pgtable.h>
25
26 #include <asm/mach-types.h>
27 #include <asm/mach/time.h>
28
29 #include "hardware.h"
30 #include "cm.h"
31 #include "common.h"
32
33 static DEFINE_RAW_SPINLOCK(cm_lock);
34 static void __iomem *cm_base;
35
36 /**
37 * cm_get - get the value from the CM_CTRL register
38 */
cm_get(void)39 u32 cm_get(void)
40 {
41 return readl(cm_base + INTEGRATOR_HDR_CTRL_OFFSET);
42 }
43
44 /**
45 * cm_control - update the CM_CTRL register.
46 * @mask: bits to change
47 * @set: bits to set
48 */
cm_control(u32 mask,u32 set)49 void cm_control(u32 mask, u32 set)
50 {
51 unsigned long flags;
52 u32 val;
53
54 raw_spin_lock_irqsave(&cm_lock, flags);
55 val = readl(cm_base + INTEGRATOR_HDR_CTRL_OFFSET) & ~mask;
56 writel(val | set, cm_base + INTEGRATOR_HDR_CTRL_OFFSET);
57 raw_spin_unlock_irqrestore(&cm_lock, flags);
58 }
59
cm_clear_irqs(void)60 void cm_clear_irqs(void)
61 {
62 /* disable core module IRQs */
63 writel(0xffffffffU, cm_base + INTEGRATOR_HDR_IC_OFFSET +
64 IRQ_ENABLE_CLEAR);
65 }
66
67 static const struct of_device_id cm_match[] = {
68 { .compatible = "arm,core-module-integrator"},
69 { },
70 };
71
cm_init(void)72 void cm_init(void)
73 {
74 struct device_node *cm = of_find_matching_node(NULL, cm_match);
75
76 if (!cm) {
77 pr_crit("no core module node found in device tree\n");
78 return;
79 }
80 cm_base = of_iomap(cm, 0);
81 if (!cm_base) {
82 pr_crit("could not remap core module\n");
83 return;
84 }
85 cm_clear_irqs();
86 }
87
88 /*
89 * We need to stop things allocating the low memory; ideally we need a
90 * better implementation of GFP_DMA which does not assume that DMA-able
91 * memory starts at zero.
92 */
integrator_reserve(void)93 void __init integrator_reserve(void)
94 {
95 memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
96 }
97