Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-sa1100/simpad.c |
| 3 | */ |
| 4 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/module.h> |
| 6 | #include <linux/init.h> |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/tty.h> |
| 9 | #include <linux/proc_fs.h> |
| 10 | #include <linux/string.h> |
| 11 | #include <linux/pm.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 12 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/mtd/mtd.h> |
| 14 | #include <linux/mtd/partitions.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 15 | #include <linux/io.h> |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 16 | #include <linux/gpio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #include <asm/irq.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 19 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/setup.h> |
| 21 | |
| 22 | #include <asm/mach-types.h> |
| 23 | #include <asm/mach/arch.h> |
| 24 | #include <asm/mach/flash.h> |
| 25 | #include <asm/mach/map.h> |
| 26 | #include <asm/mach/serial_sa1100.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 27 | #include <mach/mcp.h> |
| 28 | #include <mach/simpad.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include <linux/serial_core.h> |
| 31 | #include <linux/ioport.h> |
Jochen Friedrich | dbd406f | 2011-08-18 21:51:06 +0100 | [diff] [blame^] | 32 | #include <linux/input.h> |
| 33 | #include <linux/gpio_keys.h> |
| 34 | #include <linux/i2c-gpio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #include "generic.h" |
| 37 | |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 38 | /* |
| 39 | * CS3 support |
| 40 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 42 | static long cs3_shadow; |
| 43 | static spinlock_t cs3_lock; |
| 44 | static struct gpio_chip cs3_gpio; |
| 45 | |
| 46 | long simpad_get_cs3_ro(void) |
| 47 | { |
| 48 | return readl(CS3_BASE); |
| 49 | } |
| 50 | EXPORT_SYMBOL(simpad_get_cs3_ro); |
| 51 | |
| 52 | long simpad_get_cs3_shadow(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
| 54 | return cs3_shadow; |
| 55 | } |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 56 | EXPORT_SYMBOL(simpad_get_cs3_shadow); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 58 | static void __simpad_write_cs3(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 60 | writel(cs3_shadow, CS3_BASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 63 | void simpad_set_cs3_bit(int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 65 | unsigned long flags; |
| 66 | |
| 67 | spin_lock_irqsave(&cs3_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | cs3_shadow |= value; |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 69 | __simpad_write_cs3(); |
| 70 | spin_unlock_irqrestore(&cs3_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 72 | EXPORT_SYMBOL(simpad_set_cs3_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 74 | void simpad_clear_cs3_bit(int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 76 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 78 | spin_lock_irqsave(&cs3_lock, flags); |
| 79 | cs3_shadow &= ~value; |
| 80 | __simpad_write_cs3(); |
| 81 | spin_unlock_irqrestore(&cs3_lock, flags); |
| 82 | } |
| 83 | EXPORT_SYMBOL(simpad_clear_cs3_bit); |
| 84 | |
| 85 | static void cs3_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
| 86 | { |
| 87 | if (offset > 15) |
| 88 | return; |
| 89 | if (value) |
| 90 | simpad_set_cs3_bit(1 << offset); |
| 91 | else |
| 92 | simpad_clear_cs3_bit(1 << offset); |
| 93 | }; |
| 94 | |
| 95 | static int cs3_gpio_get(struct gpio_chip *chip, unsigned offset) |
| 96 | { |
| 97 | if (offset > 15) |
| 98 | return simpad_get_cs3_ro() & (1 << (offset - 16)); |
| 99 | return simpad_get_cs3_shadow() & (1 << offset); |
| 100 | }; |
| 101 | |
| 102 | static int cs3_gpio_direction_input(struct gpio_chip *chip, unsigned offset) |
| 103 | { |
| 104 | if (offset > 15) |
| 105 | return 0; |
| 106 | return -EINVAL; |
| 107 | }; |
| 108 | |
| 109 | static int cs3_gpio_direction_output(struct gpio_chip *chip, unsigned offset, |
| 110 | int value) |
| 111 | { |
| 112 | if (offset > 15) |
| 113 | return -EINVAL; |
| 114 | cs3_gpio_set(chip, offset, value); |
| 115 | return 0; |
| 116 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
| 118 | static struct map_desc simpad_io_desc[] __initdata = { |
Deepak Saxena | 92519d8 | 2005-10-28 15:19:04 +0100 | [diff] [blame] | 119 | { /* MQ200 */ |
| 120 | .virtual = 0xf2800000, |
| 121 | .pfn = __phys_to_pfn(0x4b800000), |
| 122 | .length = 0x00800000, |
| 123 | .type = MT_DEVICE |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 124 | }, { /* Simpad CS3 */ |
| 125 | .virtual = CS3_BASE, |
| 126 | .pfn = __phys_to_pfn(SA1100_CS3_PHYS), |
Deepak Saxena | 92519d8 | 2005-10-28 15:19:04 +0100 | [diff] [blame] | 127 | .length = 0x00100000, |
| 128 | .type = MT_DEVICE |
| 129 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | |
| 133 | static void simpad_uart_pm(struct uart_port *port, u_int state, u_int oldstate) |
| 134 | { |
| 135 | if (port->mapbase == (u_int)&Ser1UTCR0) { |
| 136 | if (state) |
| 137 | { |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 138 | simpad_clear_cs3_bit(RS232_ON); |
| 139 | simpad_clear_cs3_bit(DECT_POWER_ON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | }else |
| 141 | { |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 142 | simpad_set_cs3_bit(RS232_ON); |
| 143 | simpad_set_cs3_bit(DECT_POWER_ON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | static struct sa1100_port_fns simpad_port_fns __initdata = { |
| 149 | .pm = simpad_uart_pm, |
| 150 | }; |
| 151 | |
| 152 | |
| 153 | static struct mtd_partition simpad_partitions[] = { |
| 154 | { |
| 155 | .name = "SIMpad boot firmware", |
| 156 | .size = 0x00080000, |
| 157 | .offset = 0, |
| 158 | .mask_flags = MTD_WRITEABLE, |
| 159 | }, { |
| 160 | .name = "SIMpad kernel", |
| 161 | .size = 0x0010000, |
| 162 | .offset = MTDPART_OFS_APPEND, |
| 163 | }, { |
| 164 | .name = "SIMpad root jffs2", |
| 165 | .size = MTDPART_SIZ_FULL, |
| 166 | .offset = MTDPART_OFS_APPEND, |
| 167 | } |
| 168 | }; |
| 169 | |
| 170 | static struct flash_platform_data simpad_flash_data = { |
| 171 | .map_name = "cfi_probe", |
| 172 | .parts = simpad_partitions, |
| 173 | .nr_parts = ARRAY_SIZE(simpad_partitions), |
| 174 | }; |
| 175 | |
| 176 | |
| 177 | static struct resource simpad_flash_resources [] = { |
| 178 | { |
| 179 | .start = SA1100_CS0_PHYS, |
| 180 | .end = SA1100_CS0_PHYS + SZ_16M -1, |
| 181 | .flags = IORESOURCE_MEM, |
| 182 | }, { |
| 183 | .start = SA1100_CS1_PHYS, |
| 184 | .end = SA1100_CS1_PHYS + SZ_16M -1, |
| 185 | .flags = IORESOURCE_MEM, |
| 186 | } |
| 187 | }; |
| 188 | |
Russell King | 323cdfc | 2005-08-18 10:10:46 +0100 | [diff] [blame] | 189 | static struct mcp_plat_data simpad_mcp_data = { |
| 190 | .mccr0 = MCCR0_ADM, |
| 191 | .sclk_rate = 11981000, |
Jochen Friedrich | f24dec9 | 2011-08-18 21:53:57 +0100 | [diff] [blame] | 192 | .gpio_base = SIMPAD_UCB1X00_GPIO_BASE, |
Russell King | 323cdfc | 2005-08-18 10:10:46 +0100 | [diff] [blame] | 193 | }; |
| 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | |
| 197 | static void __init simpad_map_io(void) |
| 198 | { |
| 199 | sa1100_map_io(); |
| 200 | |
| 201 | iotable_init(simpad_io_desc, ARRAY_SIZE(simpad_io_desc)); |
| 202 | |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 203 | /* Initialize CS3 */ |
| 204 | cs3_shadow = (EN1 | EN0 | LED2_ON | DISPLAY_ON | |
| 205 | RS232_ON | ENABLE_5V | RESET_SIMCARD | DECT_POWER_ON); |
| 206 | __simpad_write_cs3(); /* Spinlocks not yet initialized */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | sa1100_register_uart_fns(&simpad_port_fns); |
| 209 | sa1100_register_uart(0, 3); /* serial interface */ |
| 210 | sa1100_register_uart(1, 1); /* DECT */ |
| 211 | |
| 212 | // Reassign UART 1 pins |
| 213 | GAFR |= GPIO_UART_TXD | GPIO_UART_RXD; |
| 214 | GPDR |= GPIO_UART_TXD | GPIO_LDD13 | GPIO_LDD15; |
| 215 | GPDR &= ~GPIO_UART_RXD; |
| 216 | PPAR |= PPAR_UPR; |
| 217 | |
| 218 | /* |
| 219 | * Set up registers for sleep mode. |
| 220 | */ |
| 221 | |
| 222 | |
| 223 | PWER = PWER_GPIO0| PWER_RTC; |
| 224 | PGSR = 0x818; |
| 225 | PCFR = 0; |
| 226 | PSDR = 0; |
| 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static void simpad_power_off(void) |
| 231 | { |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 232 | local_irq_disable(); |
| 233 | cs3_shadow = SD_MEDIAQ; |
| 234 | __simpad_write_cs3(); /* Bypass spinlock here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
| 236 | /* disable internal oscillator, float CS lines */ |
| 237 | PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS); |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 238 | /* enable wake-up on GPIO0 */ |
| 239 | PWER = GFER = GRER = PWER_GPIO0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | /* |
| 241 | * set scratchpad to zero, just in case it is used as a |
| 242 | * restart address by the bootloader. |
| 243 | */ |
| 244 | PSPR = 0; |
| 245 | PGSR = 0; |
| 246 | /* enter sleep mode */ |
| 247 | PMCR = PMCR_SF; |
| 248 | while(1); |
| 249 | |
| 250 | local_irq_enable(); /* we won't ever call it */ |
| 251 | |
| 252 | |
| 253 | } |
| 254 | |
Jochen Friedrich | dbd406f | 2011-08-18 21:51:06 +0100 | [diff] [blame^] | 255 | /* |
| 256 | * gpio_keys |
| 257 | */ |
| 258 | |
| 259 | static struct gpio_keys_button simpad_button_table[] = { |
| 260 | { KEY_POWER, IRQ_GPIO_POWER_BUTTON, 1, "power button" }, |
| 261 | }; |
| 262 | |
| 263 | static struct gpio_keys_platform_data simpad_keys_data = { |
| 264 | .buttons = simpad_button_table, |
| 265 | .nbuttons = ARRAY_SIZE(simpad_button_table), |
| 266 | }; |
| 267 | |
| 268 | static struct platform_device simpad_keys = { |
| 269 | .name = "gpio-keys", |
| 270 | .dev = { |
| 271 | .platform_data = &simpad_keys_data, |
| 272 | }, |
| 273 | }; |
| 274 | |
| 275 | static struct gpio_keys_button simpad_polled_button_table[] = { |
| 276 | { KEY_PROG1, SIMPAD_UCB1X00_GPIO_PROG1, 1, "prog1 button" }, |
| 277 | { KEY_PROG2, SIMPAD_UCB1X00_GPIO_PROG2, 1, "prog2 button" }, |
| 278 | { KEY_UP, SIMPAD_UCB1X00_GPIO_UP, 1, "up button" }, |
| 279 | { KEY_DOWN, SIMPAD_UCB1X00_GPIO_DOWN, 1, "down button" }, |
| 280 | { KEY_LEFT, SIMPAD_UCB1X00_GPIO_LEFT, 1, "left button" }, |
| 281 | { KEY_RIGHT, SIMPAD_UCB1X00_GPIO_RIGHT, 1, "right button" }, |
| 282 | }; |
| 283 | |
| 284 | static struct gpio_keys_platform_data simpad_polled_keys_data = { |
| 285 | .buttons = simpad_polled_button_table, |
| 286 | .nbuttons = ARRAY_SIZE(simpad_polled_button_table), |
| 287 | .poll_interval = 50, |
| 288 | }; |
| 289 | |
| 290 | static struct platform_device simpad_polled_keys = { |
| 291 | .name = "gpio-keys-polled", |
| 292 | .dev = { |
| 293 | .platform_data = &simpad_polled_keys_data, |
| 294 | }, |
| 295 | }; |
| 296 | |
| 297 | /* |
| 298 | * i2c |
| 299 | */ |
| 300 | static struct i2c_gpio_platform_data simpad_i2c_data = { |
| 301 | .sda_pin = GPIO_GPIO21, |
| 302 | .scl_pin = GPIO_GPIO25, |
| 303 | .udelay = 10, |
| 304 | .timeout = HZ, |
| 305 | }; |
| 306 | |
| 307 | static struct platform_device simpad_i2c = { |
| 308 | .name = "i2c-gpio", |
| 309 | .id = 0, |
| 310 | .dev = { |
| 311 | .platform_data = &simpad_i2c_data, |
| 312 | }, |
| 313 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * MediaQ Video Device |
| 317 | */ |
| 318 | static struct platform_device simpad_mq200fb = { |
| 319 | .name = "simpad-mq200", |
| 320 | .id = 0, |
| 321 | }; |
| 322 | |
| 323 | static struct platform_device *devices[] __initdata = { |
Jochen Friedrich | dbd406f | 2011-08-18 21:51:06 +0100 | [diff] [blame^] | 324 | &simpad_keys, |
| 325 | &simpad_polled_keys, |
| 326 | &simpad_mq200fb, |
| 327 | &simpad_i2c, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | }; |
| 329 | |
| 330 | |
| 331 | |
| 332 | static int __init simpad_init(void) |
| 333 | { |
| 334 | int ret; |
| 335 | |
Jochen Friedrich | de0bc0d | 2011-08-18 21:50:31 +0100 | [diff] [blame] | 336 | spin_lock_init(&cs3_lock); |
| 337 | |
| 338 | cs3_gpio.label = "simpad_cs3"; |
| 339 | cs3_gpio.base = SIMPAD_CS3_GPIO_BASE; |
| 340 | cs3_gpio.ngpio = 24; |
| 341 | cs3_gpio.set = cs3_gpio_set; |
| 342 | cs3_gpio.get = cs3_gpio_get; |
| 343 | cs3_gpio.direction_input = cs3_gpio_direction_input; |
| 344 | cs3_gpio.direction_output = cs3_gpio_direction_output; |
| 345 | ret = gpiochip_add(&cs3_gpio); |
| 346 | if (ret) |
| 347 | printk(KERN_WARNING "simpad: Unable to register cs3 GPIO device"); |
| 348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | pm_power_off = simpad_power_off; |
| 350 | |
Jochen Friedrich | 4f444e2 | 2011-01-03 12:09:05 +0100 | [diff] [blame] | 351 | sa11x0_register_mtd(&simpad_flash_data, simpad_flash_resources, |
| 352 | ARRAY_SIZE(simpad_flash_resources)); |
| 353 | sa11x0_register_mcp(&simpad_mcp_data); |
| 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | ret = platform_add_devices(devices, ARRAY_SIZE(devices)); |
| 356 | if(ret) |
| 357 | printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device"); |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | arch_initcall(simpad_init); |
| 363 | |
| 364 | |
| 365 | MACHINE_START(SIMPAD, "Simpad") |
Russell King | e9dea0c | 2005-07-03 17:38:58 +0100 | [diff] [blame] | 366 | /* Maintainer: Holger Freyther */ |
Russell King | e9dea0c | 2005-07-03 17:38:58 +0100 | [diff] [blame] | 367 | .boot_params = 0xc0000100, |
| 368 | .map_io = simpad_map_io, |
| 369 | .init_irq = sa1100_init_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | .timer = &sa1100_timer, |
| 371 | MACHINE_END |