Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Thomas Gleixner | a03d4d2 | 2006-07-01 22:32:32 +0100 | [diff] [blame] | 16 | #include <linux/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/sched.h> |
Russell King | 20cf33e | 2005-06-18 10:15:46 +0100 | [diff] [blame] | 18 | #include <linux/smp.h> |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 19 | #include <linux/termios.h> |
Russell King | a62c80e | 2006-01-07 13:52:45 +0000 | [diff] [blame] | 20 | #include <linux/amba/bus.h> |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 21 | #include <linux/amba/serial.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 22 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Russell King | d72fbdf | 2008-11-08 20:08:08 +0000 | [diff] [blame] | 24 | #include <asm/clkdev.h> |
| 25 | #include <mach/clkdev.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 26 | #include <mach/hardware.h> |
Russell King | a285edc | 2010-01-14 19:59:37 +0000 | [diff] [blame] | 27 | #include <mach/platform.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/irq.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 29 | #include <mach/cm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/system.h> |
| 31 | #include <asm/leds.h> |
| 32 | #include <asm/mach/time.h> |
| 33 | |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 34 | static struct amba_pl010_data integrator_uart_data; |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | static struct amba_device rtc_device = { |
| 37 | .dev = { |
Kay Sievers | 1d559e2 | 2009-01-06 10:44:43 -0800 | [diff] [blame] | 38 | .init_name = "mb:15", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | }, |
| 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 | |
| 49 | static struct amba_device uart0_device = { |
| 50 | .dev = { |
Kay Sievers | 1d559e2 | 2009-01-06 10:44:43 -0800 | [diff] [blame] | 51 | .init_name = "mb:16", |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 52 | .platform_data = &integrator_uart_data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | }, |
| 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 | |
| 63 | static struct amba_device uart1_device = { |
| 64 | .dev = { |
Kay Sievers | 1d559e2 | 2009-01-06 10:44:43 -0800 | [diff] [blame] | 65 | .init_name = "mb:17", |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 66 | .platform_data = &integrator_uart_data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | }, |
| 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 | |
| 77 | static struct amba_device kmi0_device = { |
| 78 | .dev = { |
Kay Sievers | 1d559e2 | 2009-01-06 10:44:43 -0800 | [diff] [blame] | 79 | .init_name = "mb:18", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | }, |
| 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 | |
| 90 | static struct amba_device kmi1_device = { |
| 91 | .dev = { |
Kay Sievers | 1d559e2 | 2009-01-06 10:44:43 -0800 | [diff] [blame] | 92 | .init_name = "mb:19", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | }, |
| 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 | |
| 103 | static struct amba_device *amba_devs[] __initdata = { |
| 104 | &rtc_device, |
| 105 | &uart0_device, |
| 106 | &uart1_device, |
| 107 | &kmi0_device, |
| 108 | &kmi1_device, |
| 109 | }; |
| 110 | |
Russell King | d72fbdf | 2008-11-08 20:08:08 +0000 | [diff] [blame] | 111 | /* |
| 112 | * These are fixed clocks. |
| 113 | */ |
| 114 | static struct clk clk24mhz = { |
| 115 | .rate = 24000000, |
| 116 | }; |
| 117 | |
| 118 | static struct clk uartclk = { |
| 119 | .rate = 14745600, |
| 120 | }; |
| 121 | |
Russell King | 3126c7b | 2010-07-15 11:01:17 +0100 | [diff] [blame^] | 122 | static struct clk dummy_apb_pclk; |
| 123 | |
Rabin Vincent | a93ea9b | 2009-05-18 17:26:08 +0100 | [diff] [blame] | 124 | static struct clk_lookup lookups[] = { |
Russell King | 3126c7b | 2010-07-15 11:01:17 +0100 | [diff] [blame^] | 125 | { /* Bus clock */ |
| 126 | .con_id = "apb_pclk", |
| 127 | .clk = &dummy_apb_pclk, |
| 128 | }, { /* UART0 */ |
Russell King | d72fbdf | 2008-11-08 20:08:08 +0000 | [diff] [blame] | 129 | .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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | static int __init integrator_init(void) |
| 147 | { |
| 148 | int i; |
| 149 | |
Russell King | 0a0300d | 2010-01-12 12:28:00 +0000 | [diff] [blame] | 150 | clkdev_add_table(lookups, ARRAY_SIZE(lookups)); |
Russell King | d72fbdf | 2008-11-08 20:08:08 +0000 | [diff] [blame] | 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | 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 | |
| 160 | arch_initcall(integrator_init); |
| 161 | |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 162 | /* |
| 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 King | b830b9b | 2010-01-17 20:45:12 +0000 | [diff] [blame] | 169 | #define SC_CTRLC IO_ADDRESS(INTEGRATOR_SC_CTRLC) |
| 170 | #define SC_CTRLS IO_ADDRESS(INTEGRATOR_SC_CTRLS) |
Russell King | fbb18a2 | 2006-03-26 23:13:39 +0100 | [diff] [blame] | 171 | |
| 172 | static 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 | |
| 198 | static struct amba_pl010_data integrator_uart_data = { |
| 199 | .set_mctrl = integrator_uart_set_mctrl, |
| 200 | }; |
| 201 | |
Russell King | b830b9b | 2010-01-17 20:45:12 +0000 | [diff] [blame] | 202 | #define CM_CTRL IO_ADDRESS(INTEGRATOR_HDR_CTRL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | static 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 | */ |
| 211 | void 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 | |
| 222 | EXPORT_SYMBOL(cm_control); |