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