Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-iop32x/n2100.c |
| 3 | * |
| 4 | * Board support code for the Thecus N2100 platform. |
| 5 | * |
| 6 | * Author: Rory Bolt <rorybolt@pacbell.net> |
| 7 | * Copyright (C) 2002 Rory Bolt |
| 8 | * Copyright 2003 (c) MontaVista, Software, Inc. |
| 9 | * Copyright (C) 2004 Intel Corp. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by the |
| 13 | * Free Software Foundation; either version 2 of the License, or (at your |
| 14 | * option) any later version. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/mm.h> |
| 18 | #include <linux/init.h> |
Riku Voipio | 9aa6933 | 2007-10-16 13:08:57 +0300 | [diff] [blame] | 19 | #include <linux/f75375s.h> |
Riku Voipio | 30be048 | 2008-05-31 14:45:16 +0100 | [diff] [blame] | 20 | #include <linux/leds-pca9532.h> |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 21 | #include <linux/delay.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/pm.h> |
| 25 | #include <linux/string.h> |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 26 | #include <linux/serial_core.h> |
| 27 | #include <linux/serial_8250.h> |
| 28 | #include <linux/mtd/physmap.h> |
Martin Michlmayr | c00593f | 2007-07-17 04:04:57 -0700 | [diff] [blame] | 29 | #include <linux/i2c.h> |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 30 | #include <linux/platform_device.h> |
| 31 | #include <linux/reboot.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 32 | #include <linux/io.h> |
Linus Walleij | 7111f87 | 2013-09-09 14:45:47 +0200 | [diff] [blame] | 33 | #include <linux/gpio.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 34 | #include <mach/hardware.h> |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 35 | #include <asm/irq.h> |
| 36 | #include <asm/mach/arch.h> |
| 37 | #include <asm/mach/map.h> |
| 38 | #include <asm/mach/pci.h> |
| 39 | #include <asm/mach/time.h> |
| 40 | #include <asm/mach-types.h> |
| 41 | #include <asm/page.h> |
| 42 | #include <asm/pgtable.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 43 | #include <mach/time.h> |
Linus Walleij | 7b85b86 | 2013-09-09 16:39:51 +0200 | [diff] [blame] | 44 | #include "gpio-iop32x.h" |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * N2100 timer tick configuration. |
| 48 | */ |
| 49 | static void __init n2100_timer_init(void) |
| 50 | { |
| 51 | /* 33.000 MHz crystal. */ |
Dan Williams | 3668b45 | 2007-02-13 17:13:34 +0100 | [diff] [blame] | 52 | iop_init_time(198000000); |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 53 | } |
| 54 | |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 55 | |
| 56 | /* |
| 57 | * N2100 I/O. |
| 58 | */ |
| 59 | static struct map_desc n2100_io_desc[] __initdata = { |
| 60 | { /* on-board devices */ |
| 61 | .virtual = N2100_UART, |
| 62 | .pfn = __phys_to_pfn(N2100_UART), |
| 63 | .length = 0x00100000, |
| 64 | .type = MT_DEVICE |
| 65 | }, |
| 66 | }; |
| 67 | |
| 68 | void __init n2100_map_io(void) |
| 69 | { |
| 70 | iop3xx_map_io(); |
| 71 | iotable_init(n2100_io_desc, ARRAY_SIZE(n2100_io_desc)); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | /* |
| 76 | * N2100 PCI. |
| 77 | */ |
Dan Williams | d73d801 | 2007-05-15 01:03:36 +0100 | [diff] [blame] | 78 | static int __init |
Ralf Baechle | d534194 | 2011-06-10 15:30:21 +0100 | [diff] [blame] | 79 | n2100_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 80 | { |
| 81 | int irq; |
| 82 | |
| 83 | if (PCI_SLOT(dev->devfn) == 1) { |
| 84 | /* RTL8110SB #1 */ |
| 85 | irq = IRQ_IOP32X_XINT0; |
| 86 | } else if (PCI_SLOT(dev->devfn) == 2) { |
| 87 | /* RTL8110SB #2 */ |
Lennert Buytenhek | 811c9a4 | 2006-10-29 14:15:10 +0100 | [diff] [blame] | 88 | irq = IRQ_IOP32X_XINT3; |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 89 | } else if (PCI_SLOT(dev->devfn) == 3) { |
| 90 | /* Sil3512 */ |
| 91 | irq = IRQ_IOP32X_XINT2; |
| 92 | } else if (PCI_SLOT(dev->devfn) == 4 && pin == 1) { |
| 93 | /* VT6212 INTA */ |
| 94 | irq = IRQ_IOP32X_XINT1; |
| 95 | } else if (PCI_SLOT(dev->devfn) == 4 && pin == 2) { |
| 96 | /* VT6212 INTB */ |
| 97 | irq = IRQ_IOP32X_XINT0; |
| 98 | } else if (PCI_SLOT(dev->devfn) == 4 && pin == 3) { |
| 99 | /* VT6212 INTC */ |
| 100 | irq = IRQ_IOP32X_XINT2; |
| 101 | } else if (PCI_SLOT(dev->devfn) == 5) { |
| 102 | /* Mini-PCI slot */ |
| 103 | irq = IRQ_IOP32X_XINT3; |
| 104 | } else { |
| 105 | printk(KERN_ERR "n2100_pci_map_irq() called for unknown " |
| 106 | "device PCI:%d:%d:%d\n", dev->bus->number, |
| 107 | PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); |
| 108 | irq = -1; |
| 109 | } |
| 110 | |
| 111 | return irq; |
| 112 | } |
| 113 | |
| 114 | static struct hw_pci n2100_pci __initdata = { |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 115 | .nr_controllers = 1, |
Russell King | c23bfc3 | 2012-03-10 12:49:16 +0000 | [diff] [blame] | 116 | .ops = &iop3xx_ops, |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 117 | .setup = iop3xx_pci_setup, |
| 118 | .preinit = iop3xx_pci_preinit, |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 119 | .map_irq = n2100_pci_map_irq, |
| 120 | }; |
| 121 | |
Lennert Buytenhek | 66822b2 | 2007-02-08 01:03:17 +0100 | [diff] [blame] | 122 | /* |
| 123 | * Both r8169 chips on the n2100 exhibit PCI parity problems. Set |
| 124 | * the ->broken_parity_status flag for both ports so that the r8169 |
| 125 | * driver knows it should ignore error interrupts. |
| 126 | */ |
| 127 | static void n2100_fixup_r8169(struct pci_dev *dev) |
| 128 | { |
| 129 | if (dev->bus->number == 0 && |
| 130 | (dev->devfn == PCI_DEVFN(1, 0) || |
| 131 | dev->devfn == PCI_DEVFN(2, 0))) |
| 132 | dev->broken_parity_status = 1; |
| 133 | } |
| 134 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, PCI_ANY_ID, n2100_fixup_r8169); |
| 135 | |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 136 | static int __init n2100_pci_init(void) |
| 137 | { |
| 138 | if (machine_is_n2100()) |
| 139 | pci_common_init(&n2100_pci); |
| 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | subsys_initcall(n2100_pci_init); |
| 145 | |
| 146 | |
| 147 | /* |
| 148 | * N2100 machine initialisation. |
| 149 | */ |
| 150 | static struct physmap_flash_data n2100_flash_data = { |
| 151 | .width = 2, |
| 152 | }; |
| 153 | |
| 154 | static struct resource n2100_flash_resource = { |
| 155 | .start = 0xf0000000, |
| 156 | .end = 0xf0ffffff, |
| 157 | .flags = IORESOURCE_MEM, |
| 158 | }; |
| 159 | |
| 160 | static struct platform_device n2100_flash_device = { |
| 161 | .name = "physmap-flash", |
| 162 | .id = 0, |
| 163 | .dev = { |
| 164 | .platform_data = &n2100_flash_data, |
| 165 | }, |
| 166 | .num_resources = 1, |
| 167 | .resource = &n2100_flash_resource, |
| 168 | }; |
| 169 | |
| 170 | |
| 171 | static struct plat_serial8250_port n2100_serial_port[] = { |
| 172 | { |
| 173 | .mapbase = N2100_UART, |
| 174 | .membase = (char *)N2100_UART, |
| 175 | .irq = 0, |
Aaro Koskinen | cc761be | 2010-02-16 22:06:14 +0100 | [diff] [blame] | 176 | .flags = UPF_SKIP_TEST | UPF_AUTO_IRQ | UPF_SHARE_IRQ, |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 177 | .iotype = UPIO_MEM, |
| 178 | .regshift = 0, |
| 179 | .uartclk = 1843200, |
| 180 | }, |
| 181 | { }, |
| 182 | }; |
| 183 | |
| 184 | static struct resource n2100_uart_resource = { |
| 185 | .start = N2100_UART, |
| 186 | .end = N2100_UART + 7, |
| 187 | .flags = IORESOURCE_MEM, |
| 188 | }; |
| 189 | |
| 190 | static struct platform_device n2100_serial_device = { |
| 191 | .name = "serial8250", |
| 192 | .id = PLAT8250_DEV_PLATFORM, |
| 193 | .dev = { |
| 194 | .platform_data = n2100_serial_port, |
| 195 | }, |
| 196 | .num_resources = 1, |
| 197 | .resource = &n2100_uart_resource, |
| 198 | }; |
| 199 | |
Riku Voipio | 9aa6933 | 2007-10-16 13:08:57 +0300 | [diff] [blame] | 200 | static struct f75375s_platform_data n2100_f75375s = { |
| 201 | .pwm = { 255, 255 }, |
| 202 | .pwm_enable = { 0, 0 }, |
| 203 | }; |
| 204 | |
Riku Voipio | 30be048 | 2008-05-31 14:45:16 +0100 | [diff] [blame] | 205 | static struct pca9532_platform_data n2100_leds = { |
| 206 | .leds = { |
| 207 | { .name = "n2100:red:satafail0", |
| 208 | .state = PCA9532_OFF, |
| 209 | .type = PCA9532_TYPE_LED, |
| 210 | }, |
| 211 | { .name = "n2100:red:satafail1", |
| 212 | .state = PCA9532_OFF, |
| 213 | .type = PCA9532_TYPE_LED, |
| 214 | }, |
| 215 | { .name = "n2100:blue:usb", |
| 216 | .state = PCA9532_OFF, |
| 217 | .type = PCA9532_TYPE_LED, |
| 218 | }, |
| 219 | { .type = PCA9532_TYPE_NONE }, |
| 220 | |
| 221 | { .type = PCA9532_TYPE_NONE }, |
| 222 | { .type = PCA9532_TYPE_NONE }, |
| 223 | { .type = PCA9532_TYPE_NONE }, |
| 224 | { .name = "n2100:red:usb", |
| 225 | .state = PCA9532_OFF, |
| 226 | .type = PCA9532_TYPE_LED, |
| 227 | }, |
| 228 | |
| 229 | { .type = PCA9532_TYPE_NONE }, /* power OFF gpio */ |
| 230 | { .type = PCA9532_TYPE_NONE }, /* reset gpio */ |
| 231 | { .type = PCA9532_TYPE_NONE }, |
| 232 | { .type = PCA9532_TYPE_NONE }, |
| 233 | |
| 234 | { .type = PCA9532_TYPE_NONE }, |
| 235 | { .name = "n2100:orange:system", |
| 236 | .state = PCA9532_OFF, |
| 237 | .type = PCA9532_TYPE_LED, |
| 238 | }, |
| 239 | { .name = "n2100:red:system", |
| 240 | .state = PCA9532_OFF, |
| 241 | .type = PCA9532_TYPE_LED, |
| 242 | }, |
| 243 | { .name = "N2100 beeper" , |
| 244 | .state = PCA9532_OFF, |
| 245 | .type = PCA9532_TYPE_N2100_BEEP, |
| 246 | }, |
| 247 | }, |
| 248 | .psc = { 0, 0 }, |
| 249 | .pwm = { 0, 0 }, |
| 250 | }; |
| 251 | |
Martin Michlmayr | c00593f | 2007-07-17 04:04:57 -0700 | [diff] [blame] | 252 | static struct i2c_board_info __initdata n2100_i2c_devices[] = { |
| 253 | { |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 254 | I2C_BOARD_INFO("rs5c372b", 0x32), |
Martin Michlmayr | c00593f | 2007-07-17 04:04:57 -0700 | [diff] [blame] | 255 | }, |
Riku Voipio | 9aa6933 | 2007-10-16 13:08:57 +0300 | [diff] [blame] | 256 | { |
| 257 | I2C_BOARD_INFO("f75375", 0x2e), |
Riku Voipio | 9aa6933 | 2007-10-16 13:08:57 +0300 | [diff] [blame] | 258 | .platform_data = &n2100_f75375s, |
| 259 | }, |
Riku Voipio | 30be048 | 2008-05-31 14:45:16 +0100 | [diff] [blame] | 260 | { |
| 261 | I2C_BOARD_INFO("pca9532", 0x60), |
| 262 | .platform_data = &n2100_leds, |
| 263 | }, |
Martin Michlmayr | c00593f | 2007-07-17 04:04:57 -0700 | [diff] [blame] | 264 | }; |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 265 | |
| 266 | /* |
| 267 | * Pull PCA9532 GPIO #8 low to power off the machine. |
| 268 | */ |
| 269 | static void n2100_power_off(void) |
| 270 | { |
| 271 | local_irq_disable(); |
| 272 | |
| 273 | /* Start condition, I2C address of PCA9532, write transaction. */ |
| 274 | *IOP3XX_IDBR0 = 0xc0; |
| 275 | *IOP3XX_ICR0 = 0xe9; |
| 276 | mdelay(1); |
| 277 | |
| 278 | /* Write address 0x08. */ |
| 279 | *IOP3XX_IDBR0 = 0x08; |
| 280 | *IOP3XX_ICR0 = 0xe8; |
| 281 | mdelay(1); |
| 282 | |
| 283 | /* Write data 0x01, stop condition. */ |
| 284 | *IOP3XX_IDBR0 = 0x01; |
| 285 | *IOP3XX_ICR0 = 0xea; |
| 286 | |
| 287 | while (1) |
| 288 | ; |
| 289 | } |
| 290 | |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 291 | static void n2100_restart(enum reboot_mode mode, const char *cmd) |
Russell King | bec92b1 | 2011-11-05 11:26:32 +0000 | [diff] [blame] | 292 | { |
Linus Walleij | 7111f87 | 2013-09-09 14:45:47 +0200 | [diff] [blame] | 293 | int ret; |
| 294 | |
| 295 | ret = gpio_direction_output(N2100_HARDWARE_RESET, 0); |
| 296 | if (ret) { |
| 297 | pr_crit("could not drive reset GPIO low\n"); |
| 298 | return; |
| 299 | } |
| 300 | /* Wait for reset to happen */ |
Russell King | bec92b1 | 2011-11-05 11:26:32 +0000 | [diff] [blame] | 301 | while (1) |
| 302 | ; |
| 303 | } |
| 304 | |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 305 | |
| 306 | static struct timer_list power_button_poll_timer; |
| 307 | |
| 308 | static void power_button_poll(unsigned long dummy) |
| 309 | { |
Linus Walleij | afc3b79 | 2013-09-09 14:53:02 +0200 | [diff] [blame] | 310 | if (gpio_get_value(N2100_POWER_BUTTON) == 0) { |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 311 | ctrl_alt_del(); |
| 312 | return; |
| 313 | } |
| 314 | |
| 315 | power_button_poll_timer.expires = jiffies + (HZ / 10); |
| 316 | add_timer(&power_button_poll_timer); |
| 317 | } |
| 318 | |
Linus Walleij | 7111f87 | 2013-09-09 14:45:47 +0200 | [diff] [blame] | 319 | static int __init n2100_request_gpios(void) |
| 320 | { |
| 321 | int ret; |
| 322 | |
| 323 | if (!machine_is_n2100()) |
| 324 | return 0; |
| 325 | |
| 326 | ret = gpio_request(N2100_HARDWARE_RESET, "reset"); |
| 327 | if (ret) |
| 328 | pr_err("could not request reset GPIO\n"); |
Linus Walleij | afc3b79 | 2013-09-09 14:53:02 +0200 | [diff] [blame] | 329 | |
| 330 | ret = gpio_request(N2100_POWER_BUTTON, "power"); |
| 331 | if (ret) |
| 332 | pr_err("could not request power GPIO\n"); |
| 333 | else { |
| 334 | ret = gpio_direction_input(N2100_POWER_BUTTON); |
| 335 | if (ret) |
| 336 | pr_err("could not set power GPIO as input\n"); |
| 337 | } |
| 338 | /* Set up power button poll timer */ |
| 339 | init_timer(&power_button_poll_timer); |
| 340 | power_button_poll_timer.function = power_button_poll; |
| 341 | power_button_poll_timer.expires = jiffies + (HZ / 10); |
| 342 | add_timer(&power_button_poll_timer); |
Linus Walleij | 7111f87 | 2013-09-09 14:45:47 +0200 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | device_initcall(n2100_request_gpios); |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 346 | |
| 347 | static void __init n2100_init_machine(void) |
| 348 | { |
Linus Walleij | 7b85b86 | 2013-09-09 16:39:51 +0200 | [diff] [blame] | 349 | register_iop32x_gpio(); |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 350 | platform_device_register(&iop3xx_i2c0_device); |
| 351 | platform_device_register(&n2100_flash_device); |
| 352 | platform_device_register(&n2100_serial_device); |
Dan Williams | 2492c84 | 2007-01-02 13:52:31 -0700 | [diff] [blame] | 353 | platform_device_register(&iop3xx_dma_0_channel); |
| 354 | platform_device_register(&iop3xx_dma_1_channel); |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 355 | |
Martin Michlmayr | c00593f | 2007-07-17 04:04:57 -0700 | [diff] [blame] | 356 | i2c_register_board_info(0, n2100_i2c_devices, |
| 357 | ARRAY_SIZE(n2100_i2c_devices)); |
| 358 | |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 359 | pm_power_off = n2100_power_off; |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | MACHINE_START(N2100, "Thecus N2100") |
| 363 | /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */ |
Nicolas Pitre | 1896746 | 2011-07-05 22:38:12 -0400 | [diff] [blame] | 364 | .atag_offset = 0x100, |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 365 | .map_io = n2100_map_io, |
| 366 | .init_irq = iop32x_init_irq, |
Stephen Warren | 6bb27d7 | 2012-11-08 12:40:59 -0700 | [diff] [blame] | 367 | .init_time = n2100_timer_init, |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 368 | .init_machine = n2100_init_machine, |
Russell King | bec92b1 | 2011-11-05 11:26:32 +0000 | [diff] [blame] | 369 | .restart = n2100_restart, |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 370 | MACHINE_END |