blob: 3fa6c51390da0723ab904e17aed5a2dc7b869afe [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Arnd Bergmannb434f5c2012-08-04 10:31:24 +000014#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/spinlock.h>
16#include <linux/interrupt.h>
Thomas Gleixnera03d4d22006-07-01 22:32:32 +010017#include <linux/irq.h>
Russell King8d717a52010-05-22 19:47:18 +010018#include <linux/memblock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/sched.h>
Russell King20cf33e2005-06-18 10:15:46 +010020#include <linux/smp.h>
Russell Kingfbb18a22006-03-26 23:13:39 +010021#include <linux/termios.h>
Russell Kinga62c80e2006-01-07 13:52:45 +000022#include <linux/amba/bus.h>
Russell Kingfbb18a22006-03-26 23:13:39 +010023#include <linux/amba/serial.h>
Russell Kingfced80c2008-09-06 12:10:45 +010024#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/hardware.h>
Russell Kinga285edc2010-01-14 19:59:37 +000027#include <mach/platform.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/cm.h>
Linus Walleij695436e2012-02-26 10:46:48 +010029#include <mach/irqs.h>
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/leds.h>
Linus Walleijee358872011-12-20 11:55:19 +010032#include <asm/mach-types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/mach/time.h>
Russell King98c672c2010-05-22 18:18:57 +010034#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Russell Kingfbb18a22006-03-26 23:13:39 +010036static struct amba_pl010_data integrator_uart_data;
37
Russell King2f64ccd2011-12-18 14:50:51 +000038#define INTEGRATOR_RTC_IRQ { IRQ_RTCINT }
39#define INTEGRATOR_UART0_IRQ { IRQ_UARTINT0 }
40#define INTEGRATOR_UART1_IRQ { IRQ_UARTINT1 }
41#define KMI0_IRQ { IRQ_KMIINT0 }
42#define KMI1_IRQ { IRQ_KMIINT1 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Linus Walleijd59fdcfc2012-06-11 00:14:15 +020044static AMBA_APB_DEVICE(rtc, "rtc", 0,
Russell King2f64ccd2011-12-18 14:50:51 +000045 INTEGRATOR_RTC_BASE, INTEGRATOR_RTC_IRQ, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Linus Walleijd59fdcfc2012-06-11 00:14:15 +020047static AMBA_APB_DEVICE(uart0, "uart0", 0,
Russell King2f64ccd2011-12-18 14:50:51 +000048 INTEGRATOR_UART0_BASE, INTEGRATOR_UART0_IRQ, &integrator_uart_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Walleijd59fdcfc2012-06-11 00:14:15 +020050static AMBA_APB_DEVICE(uart1, "uart1", 0,
Russell King2f64ccd2011-12-18 14:50:51 +000051 INTEGRATOR_UART1_BASE, INTEGRATOR_UART1_IRQ, &integrator_uart_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Linus Walleijd59fdcfc2012-06-11 00:14:15 +020053static AMBA_APB_DEVICE(kmi0, "kmi0", 0, KMI0_BASE, KMI0_IRQ, NULL);
54static AMBA_APB_DEVICE(kmi1, "kmi1", 0, KMI1_BASE, KMI1_IRQ, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56static struct amba_device *amba_devs[] __initdata = {
57 &rtc_device,
58 &uart0_device,
59 &uart1_device,
60 &kmi0_device,
61 &kmi1_device,
62};
63
64static int __init integrator_init(void)
65{
66 int i;
67
Linus Walleijee358872011-12-20 11:55:19 +010068 /*
69 * The Integrator/AP lacks necessary AMBA PrimeCell IDs, so we need to
70 * hard-code them. The Integator/CP and forward have proper cell IDs.
71 * Else we leave them undefined to the bus driver can autoprobe them.
72 */
73 if (machine_is_integrator()) {
74 rtc_device.periphid = 0x00041030;
75 uart0_device.periphid = 0x00041010;
76 uart1_device.periphid = 0x00041010;
77 kmi0_device.periphid = 0x00041050;
78 kmi1_device.periphid = 0x00041050;
79 }
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
82 struct amba_device *d = amba_devs[i];
83 amba_device_register(d, &iomem_resource);
84 }
85
86 return 0;
87}
88
89arch_initcall(integrator_init);
90
Russell Kingfbb18a22006-03-26 23:13:39 +010091/*
92 * On the Integrator platform, the port RTS and DTR are provided by
93 * bits in the following SC_CTRLS register bits:
94 * RTS DTR
95 * UART0 7 6
96 * UART1 5 4
97 */
Russell Kingb830b9b2010-01-17 20:45:12 +000098#define SC_CTRLC IO_ADDRESS(INTEGRATOR_SC_CTRLC)
99#define SC_CTRLS IO_ADDRESS(INTEGRATOR_SC_CTRLS)
Russell Kingfbb18a22006-03-26 23:13:39 +0100100
101static void integrator_uart_set_mctrl(struct amba_device *dev, void __iomem *base, unsigned int mctrl)
102{
103 unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
104
105 if (dev == &uart0_device) {
106 rts_mask = 1 << 4;
107 dtr_mask = 1 << 5;
108 } else {
109 rts_mask = 1 << 6;
110 dtr_mask = 1 << 7;
111 }
112
113 if (mctrl & TIOCM_RTS)
114 ctrlc |= rts_mask;
115 else
116 ctrls |= rts_mask;
117
118 if (mctrl & TIOCM_DTR)
119 ctrlc |= dtr_mask;
120 else
121 ctrls |= dtr_mask;
122
123 __raw_writel(ctrls, SC_CTRLS);
124 __raw_writel(ctrlc, SC_CTRLC);
125}
126
127static struct amba_pl010_data integrator_uart_data = {
128 .set_mctrl = integrator_uart_set_mctrl,
129};
130
Russell Kingb830b9b2010-01-17 20:45:12 +0000131#define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_CTRL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500133static DEFINE_RAW_SPINLOCK(cm_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135/**
136 * cm_control - update the CM_CTRL register.
137 * @mask: bits to change
138 * @set: bits to set
139 */
140void cm_control(u32 mask, u32 set)
141{
142 unsigned long flags;
143 u32 val;
144
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500145 raw_spin_lock_irqsave(&cm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 val = readl(CM_CTRL) & ~mask;
147 writel(val | set, CM_CTRL);
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500148 raw_spin_unlock_irqrestore(&cm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
151EXPORT_SYMBOL(cm_control);
Russell King98c672c2010-05-22 18:18:57 +0100152
153/*
154 * We need to stop things allocating the low memory; ideally we need a
155 * better implementation of GFP_DMA which does not assume that DMA-able
156 * memory starts at zero.
157 */
158void __init integrator_reserve(void)
159{
Russell King8d717a52010-05-22 19:47:18 +0100160 memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
Russell King98c672c2010-05-22 18:18:57 +0100161}
Russell King6338b662011-11-03 19:54:37 +0000162
163/*
164 * To reset, we hit the on-board reset register in the system FPGA
165 */
166void integrator_restart(char mode, const char *cmd)
167{
168 cm_control(CM_CTRL_RESET, CM_CTRL_RESET);
169}