blob: a04d386098398420359a1ab082b0b77606e40e95 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/sched.h>
Russell King20cf33e2005-06-18 10:15:46 +010018#include <linux/smp.h>
Russell Kingfbb18a22006-03-26 23:13:39 +010019#include <linux/termios.h>
Russell Kinga62c80e2006-01-07 13:52:45 +000020#include <linux/amba/bus.h>
Russell Kingfbb18a22006-03-26 23:13:39 +010021#include <linux/amba/serial.h>
Russell Kingfced80c2008-09-06 12:10:45 +010022#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Russell Kingd72fbdf2008-11-08 20:08:08 +000024#include <asm/clkdev.h>
25#include <mach/clkdev.h>
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>
33
Russell Kingfbb18a22006-03-26 23:13:39 +010034static struct amba_pl010_data integrator_uart_data;
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036static struct amba_device rtc_device = {
37 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -080038 .init_name = "mb:15",
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 },
40 .res = {
41 .start = INTEGRATOR_RTC_BASE,
42 .end = INTEGRATOR_RTC_BASE + SZ_4K - 1,
43 .flags = IORESOURCE_MEM,
44 },
45 .irq = { IRQ_RTCINT, NO_IRQ },
46 .periphid = 0x00041030,
47};
48
49static struct amba_device uart0_device = {
50 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -080051 .init_name = "mb:16",
Russell Kingfbb18a22006-03-26 23:13:39 +010052 .platform_data = &integrator_uart_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 },
54 .res = {
55 .start = INTEGRATOR_UART0_BASE,
56 .end = INTEGRATOR_UART0_BASE + SZ_4K - 1,
57 .flags = IORESOURCE_MEM,
58 },
59 .irq = { IRQ_UARTINT0, NO_IRQ },
60 .periphid = 0x0041010,
61};
62
63static struct amba_device uart1_device = {
64 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -080065 .init_name = "mb:17",
Russell Kingfbb18a22006-03-26 23:13:39 +010066 .platform_data = &integrator_uart_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 },
68 .res = {
69 .start = INTEGRATOR_UART1_BASE,
70 .end = INTEGRATOR_UART1_BASE + SZ_4K - 1,
71 .flags = IORESOURCE_MEM,
72 },
73 .irq = { IRQ_UARTINT1, NO_IRQ },
74 .periphid = 0x0041010,
75};
76
77static struct amba_device kmi0_device = {
78 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -080079 .init_name = "mb:18",
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 },
81 .res = {
82 .start = KMI0_BASE,
83 .end = KMI0_BASE + SZ_4K - 1,
84 .flags = IORESOURCE_MEM,
85 },
86 .irq = { IRQ_KMIINT0, NO_IRQ },
87 .periphid = 0x00041050,
88};
89
90static struct amba_device kmi1_device = {
91 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -080092 .init_name = "mb:19",
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 },
94 .res = {
95 .start = KMI1_BASE,
96 .end = KMI1_BASE + SZ_4K - 1,
97 .flags = IORESOURCE_MEM,
98 },
99 .irq = { IRQ_KMIINT1, NO_IRQ },
100 .periphid = 0x00041050,
101};
102
103static struct amba_device *amba_devs[] __initdata = {
104 &rtc_device,
105 &uart0_device,
106 &uart1_device,
107 &kmi0_device,
108 &kmi1_device,
109};
110
Russell Kingd72fbdf2008-11-08 20:08:08 +0000111/*
112 * These are fixed clocks.
113 */
114static struct clk clk24mhz = {
115 .rate = 24000000,
116};
117
118static struct clk uartclk = {
119 .rate = 14745600,
120};
121
Russell King3126c7b2010-07-15 11:01:17 +0100122static struct clk dummy_apb_pclk;
123
Rabin Vincenta93ea9b2009-05-18 17:26:08 +0100124static struct clk_lookup lookups[] = {
Russell King3126c7b2010-07-15 11:01:17 +0100125 { /* Bus clock */
126 .con_id = "apb_pclk",
127 .clk = &dummy_apb_pclk,
128 }, { /* UART0 */
Russell Kingd72fbdf2008-11-08 20:08:08 +0000129 .dev_id = "mb:16",
130 .clk = &uartclk,
131 }, { /* UART1 */
132 .dev_id = "mb:17",
133 .clk = &uartclk,
134 }, { /* KMI0 */
135 .dev_id = "mb:18",
136 .clk = &clk24mhz,
137 }, { /* KMI1 */
138 .dev_id = "mb:19",
139 .clk = &clk24mhz,
140 }, { /* MMCI - IntegratorCP */
141 .dev_id = "mb:1c",
142 .clk = &uartclk,
143 }
144};
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146static int __init integrator_init(void)
147{
148 int i;
149
Russell King0a0300d2010-01-12 12:28:00 +0000150 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
Russell Kingd72fbdf2008-11-08 20:08:08 +0000151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
153 struct amba_device *d = amba_devs[i];
154 amba_device_register(d, &iomem_resource);
155 }
156
157 return 0;
158}
159
160arch_initcall(integrator_init);
161
Russell Kingfbb18a22006-03-26 23:13:39 +0100162/*
163 * On the Integrator platform, the port RTS and DTR are provided by
164 * bits in the following SC_CTRLS register bits:
165 * RTS DTR
166 * UART0 7 6
167 * UART1 5 4
168 */
Russell Kingb830b9b2010-01-17 20:45:12 +0000169#define SC_CTRLC IO_ADDRESS(INTEGRATOR_SC_CTRLC)
170#define SC_CTRLS IO_ADDRESS(INTEGRATOR_SC_CTRLS)
Russell Kingfbb18a22006-03-26 23:13:39 +0100171
172static void integrator_uart_set_mctrl(struct amba_device *dev, void __iomem *base, unsigned int mctrl)
173{
174 unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
175
176 if (dev == &uart0_device) {
177 rts_mask = 1 << 4;
178 dtr_mask = 1 << 5;
179 } else {
180 rts_mask = 1 << 6;
181 dtr_mask = 1 << 7;
182 }
183
184 if (mctrl & TIOCM_RTS)
185 ctrlc |= rts_mask;
186 else
187 ctrls |= rts_mask;
188
189 if (mctrl & TIOCM_DTR)
190 ctrlc |= dtr_mask;
191 else
192 ctrls |= dtr_mask;
193
194 __raw_writel(ctrls, SC_CTRLS);
195 __raw_writel(ctrlc, SC_CTRLC);
196}
197
198static struct amba_pl010_data integrator_uart_data = {
199 .set_mctrl = integrator_uart_set_mctrl,
200};
201
Russell Kingb830b9b2010-01-17 20:45:12 +0000202#define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_CTRL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204static DEFINE_SPINLOCK(cm_lock);
205
206/**
207 * cm_control - update the CM_CTRL register.
208 * @mask: bits to change
209 * @set: bits to set
210 */
211void cm_control(u32 mask, u32 set)
212{
213 unsigned long flags;
214 u32 val;
215
216 spin_lock_irqsave(&cm_lock, flags);
217 val = readl(CM_CTRL) & ~mask;
218 writel(val | set, CM_CTRL);
219 spin_unlock_irqrestore(&cm_lock, flags);
220}
221
222EXPORT_SYMBOL(cm_control);