Merge branch 'for-arm-soc' of git://git.kernel.org/pub/scm/linux/kernel/git/cooloney...
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-integrator / core.c
1 /*
2  *  linux/arch/arm/mach-integrator/core.c
3  *
4  *  Copyright (C) 2000-2003 Deep Blue Solutions Ltd
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2, as
8  * published by the Free Software Foundation.
9  */
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/device.h>
14 #include <linux/spinlock.h>
15 #include <linux/interrupt.h>
16 #include <linux/irq.h>
17 #include <linux/memblock.h>
18 #include <linux/sched.h>
19 #include <linux/smp.h>
20 #include <linux/termios.h>
21 #include <linux/amba/bus.h>
22 #include <linux/amba/serial.h>
23 #include <linux/io.h>
24
25 #include <mach/hardware.h>
26 #include <mach/platform.h>
27 #include <mach/cm.h>
28 #include <mach/irqs.h>
29
30 #include <asm/mach-types.h>
31 #include <asm/mach/time.h>
32 #include <asm/pgtable.h>
33
34 static struct amba_pl010_data integrator_uart_data;
35
36 #define INTEGRATOR_RTC_IRQ      { IRQ_RTCINT }
37 #define INTEGRATOR_UART0_IRQ    { IRQ_UARTINT0 }
38 #define INTEGRATOR_UART1_IRQ    { IRQ_UARTINT1 }
39 #define KMI0_IRQ                { IRQ_KMIINT0 }
40 #define KMI1_IRQ                { IRQ_KMIINT1 }
41
42 static AMBA_APB_DEVICE(rtc, "rtc", 0,
43         INTEGRATOR_RTC_BASE, INTEGRATOR_RTC_IRQ, NULL);
44
45 static AMBA_APB_DEVICE(uart0, "uart0", 0,
46         INTEGRATOR_UART0_BASE, INTEGRATOR_UART0_IRQ, &integrator_uart_data);
47
48 static AMBA_APB_DEVICE(uart1, "uart1", 0,
49         INTEGRATOR_UART1_BASE, INTEGRATOR_UART1_IRQ, &integrator_uart_data);
50
51 static AMBA_APB_DEVICE(kmi0, "kmi0", 0, KMI0_BASE, KMI0_IRQ, NULL);
52 static AMBA_APB_DEVICE(kmi1, "kmi1", 0, KMI1_BASE, KMI1_IRQ, NULL);
53
54 static struct amba_device *amba_devs[] __initdata = {
55         &rtc_device,
56         &uart0_device,
57         &uart1_device,
58         &kmi0_device,
59         &kmi1_device,
60 };
61
62 static int __init integrator_init(void)
63 {
64         int i;
65
66         /*
67          * The Integrator/AP lacks necessary AMBA PrimeCell IDs, so we need to
68          * hard-code them. The Integator/CP and forward have proper cell IDs.
69          * Else we leave them undefined to the bus driver can autoprobe them.
70          */
71         if (machine_is_integrator()) {
72                 rtc_device.periphid     = 0x00041030;
73                 uart0_device.periphid   = 0x00041010;
74                 uart1_device.periphid   = 0x00041010;
75                 kmi0_device.periphid    = 0x00041050;
76                 kmi1_device.periphid    = 0x00041050;
77         }
78
79         for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
80                 struct amba_device *d = amba_devs[i];
81                 amba_device_register(d, &iomem_resource);
82         }
83
84         return 0;
85 }
86
87 arch_initcall(integrator_init);
88
89 /*
90  * On the Integrator platform, the port RTS and DTR are provided by
91  * bits in the following SC_CTRLS register bits:
92  *        RTS  DTR
93  *  UART0  7    6
94  *  UART1  5    4
95  */
96 #define SC_CTRLC        IO_ADDRESS(INTEGRATOR_SC_CTRLC)
97 #define SC_CTRLS        IO_ADDRESS(INTEGRATOR_SC_CTRLS)
98
99 static void integrator_uart_set_mctrl(struct amba_device *dev, void __iomem *base, unsigned int mctrl)
100 {
101         unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
102
103         if (dev == &uart0_device) {
104                 rts_mask = 1 << 4;
105                 dtr_mask = 1 << 5;
106         } else {
107                 rts_mask = 1 << 6;
108                 dtr_mask = 1 << 7;
109         }
110
111         if (mctrl & TIOCM_RTS)
112                 ctrlc |= rts_mask;
113         else
114                 ctrls |= rts_mask;
115
116         if (mctrl & TIOCM_DTR)
117                 ctrlc |= dtr_mask;
118         else
119                 ctrls |= dtr_mask;
120
121         __raw_writel(ctrls, SC_CTRLS);
122         __raw_writel(ctrlc, SC_CTRLC);
123 }
124
125 static struct amba_pl010_data integrator_uart_data = {
126         .set_mctrl = integrator_uart_set_mctrl,
127 };
128
129 static DEFINE_RAW_SPINLOCK(cm_lock);
130
131 /**
132  * cm_control - update the CM_CTRL register.
133  * @mask: bits to change
134  * @set: bits to set
135  */
136 void cm_control(u32 mask, u32 set)
137 {
138         unsigned long flags;
139         u32 val;
140
141         raw_spin_lock_irqsave(&cm_lock, flags);
142         val = readl(CM_CTRL) & ~mask;
143         writel(val | set, CM_CTRL);
144         raw_spin_unlock_irqrestore(&cm_lock, flags);
145 }
146
147 EXPORT_SYMBOL(cm_control);
148
149 /*
150  * We need to stop things allocating the low memory; ideally we need a
151  * better implementation of GFP_DMA which does not assume that DMA-able
152  * memory starts at zero.
153  */
154 void __init integrator_reserve(void)
155 {
156         memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
157 }
158
159 /*
160  * To reset, we hit the on-board reset register in the system FPGA
161  */
162 void integrator_restart(char mode, const char *cmd)
163 {
164         cm_control(CM_CTRL_RESET, CM_CTRL_RESET);
165 }