Srinidhi Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 1 | /* |
| 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 Vincent | 94bdc0e | 2010-03-03 04:54:37 +0100 | [diff] [blame^] | 16 | #include <linux/gpio.h> |
Srinidhi Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
Rabin Vincent | cc2c133 | 2010-03-01 05:03:31 +0100 | [diff] [blame] | 18 | #include <linux/io.h> |
Srinidhi Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 19 | |
Rabin Vincent | cc2c133 | 2010-03-01 05:03:31 +0100 | [diff] [blame] | 20 | #include <asm/localtimer.h> |
Srinidhi Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 21 | #include <asm/hardware/gic.h> |
| 22 | #include <asm/mach/map.h> |
Rabin Vincent | cc2c133 | 2010-03-01 05:03:31 +0100 | [diff] [blame] | 23 | #include <plat/mtu.h> |
Srinidhi Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 24 | #include <mach/hardware.h> |
Rabin Vincent | cc2c133 | 2010-03-01 05:03:31 +0100 | [diff] [blame] | 25 | #include <mach/setup.h> |
Srinidhi Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 26 | |
Rabin Vincent | 94bdc0e | 2010-03-03 04:54:37 +0100 | [diff] [blame^] | 27 | #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 | |
| 57 | static 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 | |
| 69 | static 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 | |
| 81 | static 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 Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 93 | static struct platform_device *platform_devs[] __initdata = { |
Rabin Vincent | 94bdc0e | 2010-03-03 04:54:37 +0100 | [diff] [blame^] | 94 | &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 Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 103 | }; |
| 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 */ |
| 113 | static struct map_desc u8500_io_desc[] __initdata = { |
Rabin Vincent | 59778fb | 2010-02-12 06:23:07 +0100 | [diff] [blame] | 114 | __IO_DEV_DESC(U8500_UART2_BASE, SZ_4K), |
Srinidhi Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 115 | __IO_DEV_DESC(U8500_GIC_CPU_BASE, SZ_4K), |
| 116 | __IO_DEV_DESC(U8500_GIC_DIST_BASE, SZ_4K), |
Srinidhi Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 117 | __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 Vincent | 1df20af | 2010-03-01 05:07:47 +0100 | [diff] [blame] | 120 | __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 Vincent | 94bdc0e | 2010-03-03 04:54:37 +0100 | [diff] [blame^] | 126 | __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 Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 130 | }; |
| 131 | |
Rabin Vincent | 75a36ee | 2010-03-01 05:05:56 +0100 | [diff] [blame] | 132 | static struct map_desc u8500ed_io_desc[] __initdata = { |
| 133 | __IO_DEV_DESC(U8500_MTU0_BASE_ED, SZ_4K), |
Rabin Vincent | 1df20af | 2010-03-01 05:07:47 +0100 | [diff] [blame] | 134 | __IO_DEV_DESC(U8500_CLKRST7_BASE_ED, SZ_8K), |
Rabin Vincent | 75a36ee | 2010-03-01 05:05:56 +0100 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | static struct map_desc u8500v1_io_desc[] __initdata = { |
| 138 | __IO_DEV_DESC(U8500_MTU0_BASE_V1, SZ_4K), |
| 139 | }; |
| 140 | |
Srinidhi Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 141 | void __init u8500_map_io(void) |
| 142 | { |
| 143 | iotable_init(u8500_io_desc, ARRAY_SIZE(u8500_io_desc)); |
Rabin Vincent | 75a36ee | 2010-03-01 05:05:56 +0100 | [diff] [blame] | 144 | |
| 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 Kasagar | aa44ef4 | 2009-11-28 08:17:18 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | void __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 | */ |
| 160 | void __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 Vincent | cc2c133 | 2010-03-01 05:03:31 +0100 | [diff] [blame] | 167 | |
| 168 | static 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 Vincent | 75a36ee | 2010-03-01 05:05:56 +0100 | [diff] [blame] | 175 | 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 Vincent | cc2c133 | 2010-03-01 05:03:31 +0100 | [diff] [blame] | 179 | |
| 180 | nmdk_timer_init(); |
| 181 | } |
| 182 | |
| 183 | struct sys_timer u8500_timer = { |
| 184 | .init = u8500_timer_init, |
| 185 | }; |