Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-sa1100/badge4.c |
| 3 | * |
| 4 | * BadgePAD 4 specific initialization |
| 5 | * |
| 6 | * Tim Connors <connors@hpl.hp.com> |
| 7 | * Christopher Hoover <ch@hpl.hp.com> |
| 8 | * |
| 9 | * Copyright (C) 2002 Hewlett-Packard Company |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | */ |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/kernel.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/delay.h> |
| 21 | #include <linux/tty.h> |
| 22 | #include <linux/mtd/mtd.h> |
| 23 | #include <linux/mtd/partitions.h> |
| 24 | #include <linux/errno.h> |
| 25 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 26 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/mach-types.h> |
| 28 | #include <asm/setup.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 29 | #include <mach/irqs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | #include <asm/mach/arch.h> |
| 32 | #include <asm/mach/flash.h> |
| 33 | #include <asm/mach/map.h> |
| 34 | #include <asm/hardware/sa1111.h> |
| 35 | #include <asm/mach/serial_sa1100.h> |
| 36 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 37 | #include <mach/badge4.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #include "generic.h" |
| 40 | |
| 41 | static struct resource sa1111_resources[] = { |
Russell King | a181099 | 2012-01-12 10:25:29 +0000 | [diff] [blame] | 42 | [0] = DEFINE_RES_MEM(BADGE4_SA1111_BASE, 0x2000), |
| 43 | [1] = DEFINE_RES_IRQ(BADGE4_IRQ_GPIO_SA1111), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
Russell King | 3259701 | 2012-01-26 13:28:35 +0000 | [diff] [blame] | 46 | static int badge4_sa1111_enable(void *data, unsigned devid) |
| 47 | { |
| 48 | if (devid == SA1111_DEVID_USB) |
| 49 | badge4_set_5V(BADGE4_5V_USB, 1); |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static void badge4_sa1111_disable(void *data, unsigned devid) |
| 54 | { |
| 55 | if (devid == SA1111_DEVID_USB) |
| 56 | badge4_set_5V(BADGE4_5V_USB, 0); |
| 57 | } |
| 58 | |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 59 | static struct sa1111_platform_data sa1111_info = { |
Russell King | 07be45f | 2012-01-26 13:34:21 +0000 | [diff] [blame] | 60 | .disable_devs = SA1111_DEVID_PS2_MSE, |
Russell King | 3259701 | 2012-01-26 13:28:35 +0000 | [diff] [blame] | 61 | .enable = badge4_sa1111_enable, |
| 62 | .disable = badge4_sa1111_disable, |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 63 | }; |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static u64 sa1111_dmamask = 0xffffffffUL; |
| 66 | |
| 67 | static struct platform_device sa1111_device = { |
| 68 | .name = "sa1111", |
| 69 | .id = 0, |
| 70 | .dev = { |
| 71 | .dma_mask = &sa1111_dmamask, |
| 72 | .coherent_dma_mask = 0xffffffff, |
Eric Miao | 19851c5 | 2009-12-26 16:23:02 +0800 | [diff] [blame] | 73 | .platform_data = &sa1111_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }, |
| 75 | .num_resources = ARRAY_SIZE(sa1111_resources), |
| 76 | .resource = sa1111_resources, |
| 77 | }; |
| 78 | |
| 79 | static struct platform_device *devices[] __initdata = { |
| 80 | &sa1111_device, |
| 81 | }; |
| 82 | |
| 83 | static int __init badge4_sa1111_init(void) |
| 84 | { |
| 85 | /* |
| 86 | * Ensure that the memory bus request/grant signals are setup, |
| 87 | * and the grant is held in its inactive state |
| 88 | */ |
| 89 | sa1110_mb_disable(); |
| 90 | |
| 91 | /* |
| 92 | * Probe for SA1111. |
| 93 | */ |
| 94 | return platform_add_devices(devices, ARRAY_SIZE(devices)); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | /* |
| 99 | * 1 x Intel 28F320C3 Advanced+ Boot Block Flash (32 Mi bit) |
| 100 | * Eight 4 KiW Parameter Bottom Blocks (64 KiB) |
| 101 | * Sixty-three 32 KiW Main Blocks (4032 Ki b) |
| 102 | * |
| 103 | * <or> |
| 104 | * |
| 105 | * 1 x Intel 28F640C3 Advanced+ Boot Block Flash (64 Mi bit) |
| 106 | * Eight 4 KiW Parameter Bottom Blocks (64 KiB) |
| 107 | * One-hundred-twenty-seven 32 KiW Main Blocks (8128 Ki b) |
| 108 | */ |
| 109 | static struct mtd_partition badge4_partitions[] = { |
Kristoffer Ericson | bda0308 | 2008-09-29 17:09:10 +0100 | [diff] [blame] | 110 | { |
| 111 | .name = "BLOB boot loader", |
| 112 | .offset = 0, |
| 113 | .size = 0x0000A000 |
| 114 | }, { |
| 115 | .name = "params", |
| 116 | .offset = MTDPART_OFS_APPEND, |
| 117 | .size = 0x00006000 |
| 118 | }, { |
| 119 | .name = "root", |
| 120 | .offset = MTDPART_OFS_APPEND, |
| 121 | .size = MTDPART_SIZ_FULL |
| 122 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | static struct flash_platform_data badge4_flash_data = { |
| 126 | .map_name = "cfi_probe", |
| 127 | .parts = badge4_partitions, |
| 128 | .nr_parts = ARRAY_SIZE(badge4_partitions), |
| 129 | }; |
| 130 | |
Russell King | a181099 | 2012-01-12 10:25:29 +0000 | [diff] [blame] | 131 | static struct resource badge4_flash_resource = |
| 132 | DEFINE_RES_MEM(SA1100_CS0_PHYS, SZ_64M); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | static int five_v_on __initdata = 0; |
| 135 | |
| 136 | static int __init five_v_on_setup(char *ignore) |
| 137 | { |
Kristoffer Ericson | bda0308 | 2008-09-29 17:09:10 +0100 | [diff] [blame] | 138 | five_v_on = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | return 1; |
| 140 | } |
| 141 | __setup("five_v_on", five_v_on_setup); |
| 142 | |
| 143 | |
| 144 | static int __init badge4_init(void) |
| 145 | { |
| 146 | int ret; |
| 147 | |
| 148 | if (!machine_is_badge4()) |
| 149 | return -ENODEV; |
| 150 | |
| 151 | /* LCD */ |
| 152 | GPCR = (BADGE4_GPIO_LGP2 | BADGE4_GPIO_LGP3 | |
| 153 | BADGE4_GPIO_LGP4 | BADGE4_GPIO_LGP5 | |
| 154 | BADGE4_GPIO_LGP6 | BADGE4_GPIO_LGP7 | |
| 155 | BADGE4_GPIO_LGP8 | BADGE4_GPIO_LGP9 | |
| 156 | BADGE4_GPIO_GPA_VID | BADGE4_GPIO_GPB_VID | |
| 157 | BADGE4_GPIO_GPC_VID); |
| 158 | GPDR &= ~BADGE4_GPIO_INT_VID; |
| 159 | GPDR |= (BADGE4_GPIO_LGP2 | BADGE4_GPIO_LGP3 | |
| 160 | BADGE4_GPIO_LGP4 | BADGE4_GPIO_LGP5 | |
| 161 | BADGE4_GPIO_LGP6 | BADGE4_GPIO_LGP7 | |
| 162 | BADGE4_GPIO_LGP8 | BADGE4_GPIO_LGP9 | |
| 163 | BADGE4_GPIO_GPA_VID | BADGE4_GPIO_GPB_VID | |
| 164 | BADGE4_GPIO_GPC_VID); |
| 165 | |
| 166 | /* SDRAM SPD i2c */ |
| 167 | GPCR = (BADGE4_GPIO_SDSDA | BADGE4_GPIO_SDSCL); |
| 168 | GPDR |= (BADGE4_GPIO_SDSDA | BADGE4_GPIO_SDSCL); |
| 169 | |
| 170 | /* uart */ |
| 171 | GPCR = (BADGE4_GPIO_UART_HS1 | BADGE4_GPIO_UART_HS2); |
| 172 | GPDR |= (BADGE4_GPIO_UART_HS1 | BADGE4_GPIO_UART_HS2); |
| 173 | |
| 174 | /* CPLD muxsel0 input for mux/adc chip select */ |
| 175 | GPCR = BADGE4_GPIO_MUXSEL0; |
| 176 | GPDR |= BADGE4_GPIO_MUXSEL0; |
| 177 | |
| 178 | /* test points: J5, J6 as inputs, J7 outputs */ |
| 179 | GPDR &= ~(BADGE4_GPIO_TESTPT_J5 | BADGE4_GPIO_TESTPT_J6); |
| 180 | GPCR = BADGE4_GPIO_TESTPT_J7; |
| 181 | GPDR |= BADGE4_GPIO_TESTPT_J7; |
| 182 | |
Kristoffer Ericson | bda0308 | 2008-09-29 17:09:10 +0100 | [diff] [blame] | 183 | /* 5V supply rail. */ |
| 184 | GPCR = BADGE4_GPIO_PCMEN5V; /* initially off */ |
| 185 | GPDR |= BADGE4_GPIO_PCMEN5V; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
| 187 | /* CPLD sdram type inputs; set up by blob */ |
| 188 | //GPDR |= (BADGE4_GPIO_SDTYP1 | BADGE4_GPIO_SDTYP0); |
| 189 | printk(KERN_DEBUG __FILE__ ": SDRAM CPLD typ1=%d typ0=%d\n", |
Kristoffer Ericson | bda0308 | 2008-09-29 17:09:10 +0100 | [diff] [blame] | 190 | !!(GPLR & BADGE4_GPIO_SDTYP1), |
| 191 | !!(GPLR & BADGE4_GPIO_SDTYP0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | /* SA1111 reset pin; set up by blob */ |
| 194 | //GPSR = BADGE4_GPIO_SA1111_NRST; |
| 195 | //GPDR |= BADGE4_GPIO_SA1111_NRST; |
| 196 | |
| 197 | |
| 198 | /* power management cruft */ |
| 199 | PGSR = 0; |
| 200 | PWER = 0; |
| 201 | PCFR = 0; |
| 202 | PSDR = 0; |
| 203 | |
| 204 | PWER |= PWER_GPIO26; /* wake up on an edge from TESTPT_J5 */ |
| 205 | PWER |= PWER_RTC; /* wake up if rtc fires */ |
| 206 | |
| 207 | /* drive sa1111_nrst during sleep */ |
| 208 | PGSR |= BADGE4_GPIO_SA1111_NRST; |
| 209 | /* drive CPLD as is during sleep */ |
| 210 | PGSR |= (GPLR & (BADGE4_GPIO_SDTYP0|BADGE4_GPIO_SDTYP1)); |
| 211 | |
| 212 | |
| 213 | /* Now bring up the SA-1111. */ |
| 214 | ret = badge4_sa1111_init(); |
| 215 | if (ret < 0) |
| 216 | printk(KERN_ERR |
Kristoffer Ericson | bda0308 | 2008-09-29 17:09:10 +0100 | [diff] [blame] | 217 | "%s: SA-1111 initialization failed (%d)\n", |
| 218 | __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | |
| 221 | /* maybe turn on 5v0 from the start */ |
| 222 | badge4_set_5V(BADGE4_5V_INITIALLY, five_v_on); |
| 223 | |
Russell King | 7a5b4e1 | 2009-10-06 14:55:53 +0100 | [diff] [blame] | 224 | sa11x0_register_mtd(&badge4_flash_data, &badge4_flash_resource, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | arch_initcall(badge4_init); |
| 230 | |
| 231 | |
| 232 | static unsigned badge4_5V_bitmap = 0; |
| 233 | |
| 234 | void badge4_set_5V(unsigned subsystem, int on) |
| 235 | { |
| 236 | unsigned long flags; |
| 237 | unsigned old_5V_bitmap; |
| 238 | |
| 239 | local_irq_save(flags); |
| 240 | |
| 241 | old_5V_bitmap = badge4_5V_bitmap; |
| 242 | |
| 243 | if (on) { |
| 244 | badge4_5V_bitmap |= subsystem; |
| 245 | } else { |
| 246 | badge4_5V_bitmap &= ~subsystem; |
| 247 | } |
| 248 | |
| 249 | /* detect on->off and off->on transitions */ |
| 250 | if ((!old_5V_bitmap) && (badge4_5V_bitmap)) { |
| 251 | /* was off, now on */ |
Harvey Harrison | 8e86f42 | 2008-03-04 15:08:02 -0800 | [diff] [blame] | 252 | printk(KERN_INFO "%s: enabling 5V supply rail\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | GPSR = BADGE4_GPIO_PCMEN5V; |
| 254 | } else if ((old_5V_bitmap) && (!badge4_5V_bitmap)) { |
| 255 | /* was on, now off */ |
Harvey Harrison | 8e86f42 | 2008-03-04 15:08:02 -0800 | [diff] [blame] | 256 | printk(KERN_INFO "%s: disabling 5V supply rail\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | GPCR = BADGE4_GPIO_PCMEN5V; |
| 258 | } |
| 259 | |
| 260 | local_irq_restore(flags); |
| 261 | } |
| 262 | EXPORT_SYMBOL(badge4_set_5V); |
| 263 | |
| 264 | |
| 265 | static struct map_desc badge4_io_desc[] __initdata = { |
Kristoffer Ericson | bda0308 | 2008-09-29 17:09:10 +0100 | [diff] [blame] | 266 | { /* SRAM bank 1 */ |
Deepak Saxena | 92519d8 | 2005-10-28 15:19:04 +0100 | [diff] [blame] | 267 | .virtual = 0xf1000000, |
| 268 | .pfn = __phys_to_pfn(0x08000000), |
| 269 | .length = 0x00100000, |
| 270 | .type = MT_DEVICE |
| 271 | }, { /* SRAM bank 2 */ |
| 272 | .virtual = 0xf2000000, |
| 273 | .pfn = __phys_to_pfn(0x10000000), |
| 274 | .length = 0x00100000, |
| 275 | .type = MT_DEVICE |
Deepak Saxena | 92519d8 | 2005-10-28 15:19:04 +0100 | [diff] [blame] | 276 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | static void |
| 280 | badge4_uart_pm(struct uart_port *port, u_int state, u_int oldstate) |
| 281 | { |
| 282 | if (!state) { |
| 283 | Ser1SDCR0 |= SDCR0_UART; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | static struct sa1100_port_fns badge4_port_fns __initdata = { |
| 288 | //.get_mctrl = badge4_get_mctrl, |
| 289 | //.set_mctrl = badge4_set_mctrl, |
| 290 | .pm = badge4_uart_pm, |
| 291 | }; |
| 292 | |
| 293 | static void __init badge4_map_io(void) |
| 294 | { |
| 295 | sa1100_map_io(); |
| 296 | iotable_init(badge4_io_desc, ARRAY_SIZE(badge4_io_desc)); |
| 297 | |
| 298 | sa1100_register_uart_fns(&badge4_port_fns); |
| 299 | sa1100_register_uart(0, 3); |
| 300 | sa1100_register_uart(1, 1); |
| 301 | } |
| 302 | |
| 303 | MACHINE_START(BADGE4, "Hewlett-Packard Laboratories BadgePAD 4") |
Nicolas Pitre | 17f4425 | 2011-07-05 22:38:17 -0400 | [diff] [blame] | 304 | .atag_offset = 0x100, |
Russell King | e9dea0c | 2005-07-03 17:38:58 +0100 | [diff] [blame] | 305 | .map_io = badge4_map_io, |
Rob Herring | f314f33 | 2012-02-24 00:06:51 +0100 | [diff] [blame] | 306 | .nr_irqs = SA1100_NR_IRQS, |
Russell King | e9dea0c | 2005-07-03 17:38:58 +0100 | [diff] [blame] | 307 | .init_irq = sa1100_init_irq, |
Shawn Guo | 7fea1ba | 2012-04-26 21:22:45 +0800 | [diff] [blame] | 308 | .init_late = sa11x0_init_late, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | .timer = &sa1100_timer, |
Nicolas Pitre | e9107ab | 2011-07-05 22:28:09 -0400 | [diff] [blame] | 310 | #ifdef CONFIG_SA1111 |
| 311 | .dma_zone_size = SZ_1M, |
| 312 | #endif |
Russell King | d9ca583 | 2011-11-05 10:28:50 +0000 | [diff] [blame] | 313 | .restart = sa11x0_restart, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | MACHINE_END |