blob: 0c20cf638575fa600deace1488394b64698692fc [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>
14#include <linux/spinlock.h>
15#include <linux/interrupt.h>
Thomas Gleixnera03d4d22006-07-01 22:32:32 +010016#include <linux/irq.h>
Russell King8d717a52010-05-22 19:47:18 +010017#include <linux/memblock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/sched.h>
Russell King20cf33e2005-06-18 10:15:46 +010019#include <linux/smp.h>
Russell Kingfbb18a22006-03-26 23:13:39 +010020#include <linux/termios.h>
Russell Kinga62c80e2006-01-07 13:52:45 +000021#include <linux/amba/bus.h>
Russell Kingfbb18a22006-03-26 23:13:39 +010022#include <linux/amba/serial.h>
Russell Kingfced80c2008-09-06 12:10:45 +010023#include <linux/io.h>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010024#include <linux/clkdev.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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010029#include <mach/cm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/system.h>
31#include <asm/leds.h>
32#include <asm/mach/time.h>
Russell King98c672c2010-05-22 18:18:57 +010033#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Russell Kingfbb18a22006-03-26 23:13:39 +010035static struct amba_pl010_data integrator_uart_data;
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static struct amba_device rtc_device = {
38 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -080039 .init_name = "mb:15",
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 },
41 .res = {
42 .start = INTEGRATOR_RTC_BASE,
43 .end = INTEGRATOR_RTC_BASE + SZ_4K - 1,
44 .flags = IORESOURCE_MEM,
45 },
46 .irq = { IRQ_RTCINT, NO_IRQ },
47 .periphid = 0x00041030,
48};
49
50static struct amba_device uart0_device = {
51 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -080052 .init_name = "mb:16",
Russell Kingfbb18a22006-03-26 23:13:39 +010053 .platform_data = &integrator_uart_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 },
55 .res = {
56 .start = INTEGRATOR_UART0_BASE,
57 .end = INTEGRATOR_UART0_BASE + SZ_4K - 1,
58 .flags = IORESOURCE_MEM,
59 },
60 .irq = { IRQ_UARTINT0, NO_IRQ },
61 .periphid = 0x0041010,
62};
63
64static struct amba_device uart1_device = {
65 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -080066 .init_name = "mb:17",
Russell Kingfbb18a22006-03-26 23:13:39 +010067 .platform_data = &integrator_uart_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 },
69 .res = {
70 .start = INTEGRATOR_UART1_BASE,
71 .end = INTEGRATOR_UART1_BASE + SZ_4K - 1,
72 .flags = IORESOURCE_MEM,
73 },
74 .irq = { IRQ_UARTINT1, NO_IRQ },
75 .periphid = 0x0041010,
76};
77
78static struct amba_device kmi0_device = {
79 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -080080 .init_name = "mb:18",
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 },
82 .res = {
83 .start = KMI0_BASE,
84 .end = KMI0_BASE + SZ_4K - 1,
85 .flags = IORESOURCE_MEM,
86 },
87 .irq = { IRQ_KMIINT0, NO_IRQ },
88 .periphid = 0x00041050,
89};
90
91static struct amba_device kmi1_device = {
92 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -080093 .init_name = "mb:19",
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 },
95 .res = {
96 .start = KMI1_BASE,
97 .end = KMI1_BASE + SZ_4K - 1,
98 .flags = IORESOURCE_MEM,
99 },
100 .irq = { IRQ_KMIINT1, NO_IRQ },
101 .periphid = 0x00041050,
102};
103
104static struct amba_device *amba_devs[] __initdata = {
105 &rtc_device,
106 &uart0_device,
107 &uart1_device,
108 &kmi0_device,
109 &kmi1_device,
110};
111
Russell Kingd72fbdf2008-11-08 20:08:08 +0000112/*
113 * These are fixed clocks.
114 */
115static struct clk clk24mhz = {
116 .rate = 24000000,
117};
118
119static struct clk uartclk = {
120 .rate = 14745600,
121};
122
Russell King3126c7b2010-07-15 11:01:17 +0100123static struct clk dummy_apb_pclk;
124
Rabin Vincenta93ea9b2009-05-18 17:26:08 +0100125static struct clk_lookup lookups[] = {
Russell King3126c7b2010-07-15 11:01:17 +0100126 { /* Bus clock */
127 .con_id = "apb_pclk",
128 .clk = &dummy_apb_pclk,
129 }, { /* UART0 */
Russell Kingd72fbdf2008-11-08 20:08:08 +0000130 .dev_id = "mb:16",
131 .clk = &uartclk,
132 }, { /* UART1 */
133 .dev_id = "mb:17",
134 .clk = &uartclk,
135 }, { /* KMI0 */
136 .dev_id = "mb:18",
137 .clk = &clk24mhz,
138 }, { /* KMI1 */
139 .dev_id = "mb:19",
140 .clk = &clk24mhz,
141 }, { /* MMCI - IntegratorCP */
142 .dev_id = "mb:1c",
143 .clk = &uartclk,
144 }
145};
146
Russell Kingc735c982011-01-11 13:00:04 +0000147void __init integrator_init_early(void)
148{
149 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
150}
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152static int __init integrator_init(void)
153{
154 int i;
155
156 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
157 struct amba_device *d = amba_devs[i];
158 amba_device_register(d, &iomem_resource);
159 }
160
161 return 0;
162}
163
164arch_initcall(integrator_init);
165
Russell Kingfbb18a22006-03-26 23:13:39 +0100166/*
167 * On the Integrator platform, the port RTS and DTR are provided by
168 * bits in the following SC_CTRLS register bits:
169 * RTS DTR
170 * UART0 7 6
171 * UART1 5 4
172 */
Russell Kingb830b9b2010-01-17 20:45:12 +0000173#define SC_CTRLC IO_ADDRESS(INTEGRATOR_SC_CTRLC)
174#define SC_CTRLS IO_ADDRESS(INTEGRATOR_SC_CTRLS)
Russell Kingfbb18a22006-03-26 23:13:39 +0100175
176static void integrator_uart_set_mctrl(struct amba_device *dev, void __iomem *base, unsigned int mctrl)
177{
178 unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
179
180 if (dev == &uart0_device) {
181 rts_mask = 1 << 4;
182 dtr_mask = 1 << 5;
183 } else {
184 rts_mask = 1 << 6;
185 dtr_mask = 1 << 7;
186 }
187
188 if (mctrl & TIOCM_RTS)
189 ctrlc |= rts_mask;
190 else
191 ctrls |= rts_mask;
192
193 if (mctrl & TIOCM_DTR)
194 ctrlc |= dtr_mask;
195 else
196 ctrls |= dtr_mask;
197
198 __raw_writel(ctrls, SC_CTRLS);
199 __raw_writel(ctrlc, SC_CTRLC);
200}
201
202static struct amba_pl010_data integrator_uart_data = {
203 .set_mctrl = integrator_uart_set_mctrl,
204};
205
Russell Kingb830b9b2010-01-17 20:45:12 +0000206#define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_CTRL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500208static DEFINE_RAW_SPINLOCK(cm_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210/**
211 * cm_control - update the CM_CTRL register.
212 * @mask: bits to change
213 * @set: bits to set
214 */
215void cm_control(u32 mask, u32 set)
216{
217 unsigned long flags;
218 u32 val;
219
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500220 raw_spin_lock_irqsave(&cm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 val = readl(CM_CTRL) & ~mask;
222 writel(val | set, CM_CTRL);
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500223 raw_spin_unlock_irqrestore(&cm_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
225
226EXPORT_SYMBOL(cm_control);
Russell King98c672c2010-05-22 18:18:57 +0100227
228/*
229 * We need to stop things allocating the low memory; ideally we need a
230 * better implementation of GFP_DMA which does not assume that DMA-able
231 * memory starts at zero.
232 */
233void __init integrator_reserve(void)
234{
Russell King8d717a52010-05-22 19:47:18 +0100235 memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
Russell King98c672c2010-05-22 18:18:57 +0100236}