blob: 5fb44661adaf35ea17f08f9c70d60aa16364f7b5 [file] [log] [blame]
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +01001/*
2 * Copyright (C) 2008-2009 ST-Ericsson
3 *
4 * Author: Srinidhi KASAGAR <srinidhi.kasagar@stericsson.com>
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 */
11#include <linux/types.h>
12#include <linux/init.h>
13#include <linux/device.h>
14#include <linux/amba/bus.h>
15#include <linux/irq.h>
Rabin Vincent94bdc0e2010-03-03 04:54:37 +010016#include <linux/gpio.h>
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010017#include <linux/platform_device.h>
Rabin Vincentcc2c1332010-03-01 05:03:31 +010018#include <linux/io.h>
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010019
Rabin Vincentcc2c1332010-03-01 05:03:31 +010020#include <asm/localtimer.h>
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010021#include <asm/hardware/gic.h>
22#include <asm/mach/map.h>
Rabin Vincentcc2c1332010-03-01 05:03:31 +010023#include <plat/mtu.h>
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010024#include <mach/hardware.h>
Rabin Vincentcc2c1332010-03-01 05:03:31 +010025#include <mach/setup.h>
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010026
Rabin Vincent94bdc0e2010-03-03 04:54:37 +010027#define GPIO_RESOURCE(block) \
28 { \
29 .start = U8500_GPIOBANK##block##_BASE, \
30 .end = U8500_GPIOBANK##block##_BASE + 127, \
31 .flags = IORESOURCE_MEM, \
32 }, \
33 { \
34 .start = IRQ_GPIO##block, \
35 .end = IRQ_GPIO##block, \
36 .flags = IORESOURCE_IRQ, \
37 }
38
39#define GPIO_DEVICE(block) \
40 { \
41 .name = "gpio", \
42 .id = block, \
43 .num_resources = 2, \
44 .resource = &u8500_gpio_resources[block * 2], \
45 .dev = { \
46 .platform_data = &u8500_gpio_data[block], \
47 }, \
48 }
49
50#define GPIO_DATA(_name, first) \
51 { \
52 .name = _name, \
53 .first_gpio = first, \
54 .first_irq = NOMADIK_GPIO_TO_IRQ(first), \
55 }
56
57static struct nmk_gpio_platform_data u8500_gpio_data[] = {
58 GPIO_DATA("GPIO-0-31", 0),
59 GPIO_DATA("GPIO-32-63", 32), /* 37..63 not routed to pin */
60 GPIO_DATA("GPIO-64-95", 64),
61 GPIO_DATA("GPIO-96-127", 96), /* 97..127 not routed to pin */
62 GPIO_DATA("GPIO-128-159", 128),
63 GPIO_DATA("GPIO-160-191", 160), /* 172..191 not routed to pin */
64 GPIO_DATA("GPIO-192-223", 192),
65 GPIO_DATA("GPIO-224-255", 224), /* 231..255 not routed to pin */
66 GPIO_DATA("GPIO-256-288", 256), /* 258..288 not routed to pin */
67};
68
69static struct resource u8500_gpio_resources[] = {
70 GPIO_RESOURCE(0),
71 GPIO_RESOURCE(1),
72 GPIO_RESOURCE(2),
73 GPIO_RESOURCE(3),
74 GPIO_RESOURCE(4),
75 GPIO_RESOURCE(5),
76 GPIO_RESOURCE(6),
77 GPIO_RESOURCE(7),
78 GPIO_RESOURCE(8),
79};
80
81static struct platform_device u8500_gpio_devs[] = {
82 GPIO_DEVICE(0),
83 GPIO_DEVICE(1),
84 GPIO_DEVICE(2),
85 GPIO_DEVICE(3),
86 GPIO_DEVICE(4),
87 GPIO_DEVICE(5),
88 GPIO_DEVICE(6),
89 GPIO_DEVICE(7),
90 GPIO_DEVICE(8),
91};
92
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +010093static struct platform_device *platform_devs[] __initdata = {
Rabin Vincent94bdc0e2010-03-03 04:54:37 +010094 &u8500_gpio_devs[0],
95 &u8500_gpio_devs[1],
96 &u8500_gpio_devs[2],
97 &u8500_gpio_devs[3],
98 &u8500_gpio_devs[4],
99 &u8500_gpio_devs[5],
100 &u8500_gpio_devs[6],
101 &u8500_gpio_devs[7],
102 &u8500_gpio_devs[8],
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100103};
104
105#define __IO_DEV_DESC(x, sz) { \
106 .virtual = IO_ADDRESS(x), \
107 .pfn = __phys_to_pfn(x), \
108 .length = sz, \
109 .type = MT_DEVICE, \
110}
111
112/* minimum static i/o mapping required to boot U8500 platforms */
113static struct map_desc u8500_io_desc[] __initdata = {
Rabin Vincent59778fb2010-02-12 06:23:07 +0100114 __IO_DEV_DESC(U8500_UART2_BASE, SZ_4K),
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100115 __IO_DEV_DESC(U8500_GIC_CPU_BASE, SZ_4K),
116 __IO_DEV_DESC(U8500_GIC_DIST_BASE, SZ_4K),
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100117 __IO_DEV_DESC(U8500_TWD_BASE, SZ_4K),
118 __IO_DEV_DESC(U8500_SCU_BASE, SZ_4K),
119 __IO_DEV_DESC(U8500_BACKUPRAM0_BASE, SZ_8K),
Rabin Vincent1df20af2010-03-01 05:07:47 +0100120 __IO_DEV_DESC(U8500_PRCMU_BASE, SZ_4K),
121 __IO_DEV_DESC(U8500_CLKRST1_BASE, SZ_4K),
122 __IO_DEV_DESC(U8500_CLKRST2_BASE, SZ_4K),
123 __IO_DEV_DESC(U8500_CLKRST3_BASE, SZ_4K),
124 __IO_DEV_DESC(U8500_CLKRST5_BASE, SZ_4K),
125 __IO_DEV_DESC(U8500_CLKRST6_BASE, SZ_4K),
Rabin Vincent94bdc0e2010-03-03 04:54:37 +0100126 __IO_DEV_DESC(U8500_GPIO1_BASE, SZ_4K),
127 __IO_DEV_DESC(U8500_GPIO2_BASE, SZ_4K),
128 __IO_DEV_DESC(U8500_GPIO3_BASE, SZ_4K),
129 __IO_DEV_DESC(U8500_GPIO5_BASE, SZ_4K),
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100130};
131
Rabin Vincent75a36ee2010-03-01 05:05:56 +0100132static struct map_desc u8500ed_io_desc[] __initdata = {
133 __IO_DEV_DESC(U8500_MTU0_BASE_ED, SZ_4K),
Rabin Vincent1df20af2010-03-01 05:07:47 +0100134 __IO_DEV_DESC(U8500_CLKRST7_BASE_ED, SZ_8K),
Rabin Vincent75a36ee2010-03-01 05:05:56 +0100135};
136
137static struct map_desc u8500v1_io_desc[] __initdata = {
138 __IO_DEV_DESC(U8500_MTU0_BASE_V1, SZ_4K),
139};
140
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100141void __init u8500_map_io(void)
142{
143 iotable_init(u8500_io_desc, ARRAY_SIZE(u8500_io_desc));
Rabin Vincent75a36ee2010-03-01 05:05:56 +0100144
145 if (cpu_is_u8500ed())
146 iotable_init(u8500ed_io_desc, ARRAY_SIZE(u8500ed_io_desc));
147 else
148 iotable_init(u8500v1_io_desc, ARRAY_SIZE(u8500v1_io_desc));
Srinidhi Kasagaraa44ef42009-11-28 08:17:18 +0100149}
150
151void __init u8500_init_irq(void)
152{
153 gic_dist_init(0, __io_address(U8500_GIC_DIST_BASE), 29);
154 gic_cpu_init(0, __io_address(U8500_GIC_CPU_BASE));
155}
156
157/*
158 * This function is called from the board init
159 */
160void __init u8500_init_devices(void)
161{
162 /* Register the platform devices */
163 platform_add_devices(platform_devs, ARRAY_SIZE(platform_devs));
164
165 return ;
166}
Rabin Vincentcc2c1332010-03-01 05:03:31 +0100167
168static void __init u8500_timer_init(void)
169{
170#ifdef CONFIG_LOCAL_TIMERS
171 /* Setup the local timer base */
172 twd_base = __io_address(U8500_TWD_BASE);
173#endif
174 /* Setup the MTU base */
Rabin Vincent75a36ee2010-03-01 05:05:56 +0100175 if (cpu_is_u8500ed())
176 mtu_base = __io_address(U8500_MTU0_BASE_ED);
177 else
178 mtu_base = __io_address(U8500_MTU0_BASE_V1);
Rabin Vincentcc2c1332010-03-01 05:03:31 +0100179
180 nmdk_timer_init();
181}
182
183struct sys_timer u8500_timer = {
184 .init = u8500_timer_init,
185};