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> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/pci.h> |
| 22 | #include <linux/pm.h> |
| 23 | #include <linux/string.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/serial_core.h> |
| 26 | #include <linux/serial_8250.h> |
| 27 | #include <linux/mtd/physmap.h> |
| 28 | #include <linux/platform_device.h> |
| 29 | #include <linux/reboot.h> |
| 30 | #include <asm/hardware.h> |
| 31 | #include <asm/io.h> |
| 32 | #include <asm/irq.h> |
| 33 | #include <asm/mach/arch.h> |
| 34 | #include <asm/mach/map.h> |
| 35 | #include <asm/mach/pci.h> |
| 36 | #include <asm/mach/time.h> |
| 37 | #include <asm/mach-types.h> |
| 38 | #include <asm/page.h> |
| 39 | #include <asm/pgtable.h> |
Dan Williams | 3668b45 | 2007-02-13 17:13:34 +0100 | [diff] [blame] | 40 | #include <asm/arch/time.h> |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * N2100 timer tick configuration. |
| 44 | */ |
| 45 | static void __init n2100_timer_init(void) |
| 46 | { |
| 47 | /* 33.000 MHz crystal. */ |
Dan Williams | 3668b45 | 2007-02-13 17:13:34 +0100 | [diff] [blame] | 48 | iop_init_time(198000000); |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static struct sys_timer n2100_timer = { |
| 52 | .init = n2100_timer_init, |
Dan Williams | 3668b45 | 2007-02-13 17:13:34 +0100 | [diff] [blame] | 53 | .offset = iop_gettimeoffset, |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | |
| 57 | /* |
| 58 | * N2100 I/O. |
| 59 | */ |
| 60 | static struct map_desc n2100_io_desc[] __initdata = { |
| 61 | { /* on-board devices */ |
| 62 | .virtual = N2100_UART, |
| 63 | .pfn = __phys_to_pfn(N2100_UART), |
| 64 | .length = 0x00100000, |
| 65 | .type = MT_DEVICE |
| 66 | }, |
| 67 | }; |
| 68 | |
| 69 | void __init n2100_map_io(void) |
| 70 | { |
| 71 | iop3xx_map_io(); |
| 72 | iotable_init(n2100_io_desc, ARRAY_SIZE(n2100_io_desc)); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | /* |
| 77 | * N2100 PCI. |
| 78 | */ |
Dan Williams | d73d801 | 2007-05-15 01:03:36 +0100 | [diff] [blame^] | 79 | static int __init |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 80 | n2100_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin) |
| 81 | { |
| 82 | int irq; |
| 83 | |
| 84 | if (PCI_SLOT(dev->devfn) == 1) { |
| 85 | /* RTL8110SB #1 */ |
| 86 | irq = IRQ_IOP32X_XINT0; |
| 87 | } else if (PCI_SLOT(dev->devfn) == 2) { |
| 88 | /* RTL8110SB #2 */ |
Lennert Buytenhek | 811c9a4 | 2006-10-29 14:15:10 +0100 | [diff] [blame] | 89 | irq = IRQ_IOP32X_XINT3; |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 90 | } else if (PCI_SLOT(dev->devfn) == 3) { |
| 91 | /* Sil3512 */ |
| 92 | irq = IRQ_IOP32X_XINT2; |
| 93 | } else if (PCI_SLOT(dev->devfn) == 4 && pin == 1) { |
| 94 | /* VT6212 INTA */ |
| 95 | irq = IRQ_IOP32X_XINT1; |
| 96 | } else if (PCI_SLOT(dev->devfn) == 4 && pin == 2) { |
| 97 | /* VT6212 INTB */ |
| 98 | irq = IRQ_IOP32X_XINT0; |
| 99 | } else if (PCI_SLOT(dev->devfn) == 4 && pin == 3) { |
| 100 | /* VT6212 INTC */ |
| 101 | irq = IRQ_IOP32X_XINT2; |
| 102 | } else if (PCI_SLOT(dev->devfn) == 5) { |
| 103 | /* Mini-PCI slot */ |
| 104 | irq = IRQ_IOP32X_XINT3; |
| 105 | } else { |
| 106 | printk(KERN_ERR "n2100_pci_map_irq() called for unknown " |
| 107 | "device PCI:%d:%d:%d\n", dev->bus->number, |
| 108 | PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); |
| 109 | irq = -1; |
| 110 | } |
| 111 | |
| 112 | return irq; |
| 113 | } |
| 114 | |
| 115 | static struct hw_pci n2100_pci __initdata = { |
| 116 | .swizzle = pci_std_swizzle, |
| 117 | .nr_controllers = 1, |
| 118 | .setup = iop3xx_pci_setup, |
| 119 | .preinit = iop3xx_pci_preinit, |
| 120 | .scan = iop3xx_pci_scan_bus, |
| 121 | .map_irq = n2100_pci_map_irq, |
| 122 | }; |
| 123 | |
Lennert Buytenhek | 66822b2 | 2007-02-08 01:03:17 +0100 | [diff] [blame] | 124 | /* |
| 125 | * Both r8169 chips on the n2100 exhibit PCI parity problems. Set |
| 126 | * the ->broken_parity_status flag for both ports so that the r8169 |
| 127 | * driver knows it should ignore error interrupts. |
| 128 | */ |
| 129 | static void n2100_fixup_r8169(struct pci_dev *dev) |
| 130 | { |
| 131 | if (dev->bus->number == 0 && |
| 132 | (dev->devfn == PCI_DEVFN(1, 0) || |
| 133 | dev->devfn == PCI_DEVFN(2, 0))) |
| 134 | dev->broken_parity_status = 1; |
| 135 | } |
| 136 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, PCI_ANY_ID, n2100_fixup_r8169); |
| 137 | |
Lennert Buytenhek | e60d07b | 2006-09-21 02:42:12 +0100 | [diff] [blame] | 138 | static int __init n2100_pci_init(void) |
| 139 | { |
| 140 | if (machine_is_n2100()) |
| 141 | pci_common_init(&n2100_pci); |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | subsys_initcall(n2100_pci_init); |
| 147 | |
| 148 | |
| 149 | /* |
| 150 | * N2100 machine initialisation. |
| 151 | */ |
| 152 | static struct physmap_flash_data n2100_flash_data = { |
| 153 | .width = 2, |
| 154 | }; |
| 155 | |
| 156 | static struct resource n2100_flash_resource = { |
| 157 | .start = 0xf0000000, |
| 158 | .end = 0xf0ffffff, |
| 159 | .flags = IORESOURCE_MEM, |
| 160 | }; |
| 161 | |
| 162 | static struct platform_device n2100_flash_device = { |
| 163 | .name = "physmap-flash", |
| 164 | .id = 0, |
| 165 | .dev = { |
| 166 | .platform_data = &n2100_flash_data, |
| 167 | }, |
| 168 | .num_resources = 1, |
| 169 | .resource = &n2100_flash_resource, |
| 170 | }; |
| 171 | |
| 172 | |
| 173 | static struct plat_serial8250_port n2100_serial_port[] = { |
| 174 | { |
| 175 | .mapbase = N2100_UART, |
| 176 | .membase = (char *)N2100_UART, |
| 177 | .irq = 0, |
| 178 | .flags = UPF_SKIP_TEST, |
| 179 | .iotype = UPIO_MEM, |
| 180 | .regshift = 0, |
| 181 | .uartclk = 1843200, |
| 182 | }, |
| 183 | { }, |
| 184 | }; |
| 185 | |
| 186 | static struct resource n2100_uart_resource = { |
| 187 | .start = N2100_UART, |
| 188 | .end = N2100_UART + 7, |
| 189 | .flags = IORESOURCE_MEM, |
| 190 | }; |
| 191 | |
| 192 | static struct platform_device n2100_serial_device = { |
| 193 | .name = "serial8250", |
| 194 | .id = PLAT8250_DEV_PLATFORM, |
| 195 | .dev = { |
| 196 | .platform_data = n2100_serial_port, |
| 197 | }, |
| 198 | .num_resources = 1, |
| 199 | .resource = &n2100_uart_resource, |
| 200 | }; |
| 201 | |
| 202 | |
| 203 | /* |
| 204 | * Pull PCA9532 GPIO #8 low to power off the machine. |
| 205 | */ |
| 206 | static void n2100_power_off(void) |
| 207 | { |
| 208 | local_irq_disable(); |
| 209 | |
| 210 | /* Start condition, I2C address of PCA9532, write transaction. */ |
| 211 | *IOP3XX_IDBR0 = 0xc0; |
| 212 | *IOP3XX_ICR0 = 0xe9; |
| 213 | mdelay(1); |
| 214 | |
| 215 | /* Write address 0x08. */ |
| 216 | *IOP3XX_IDBR0 = 0x08; |
| 217 | *IOP3XX_ICR0 = 0xe8; |
| 218 | mdelay(1); |
| 219 | |
| 220 | /* Write data 0x01, stop condition. */ |
| 221 | *IOP3XX_IDBR0 = 0x01; |
| 222 | *IOP3XX_ICR0 = 0xea; |
| 223 | |
| 224 | while (1) |
| 225 | ; |
| 226 | } |
| 227 | |
| 228 | |
| 229 | static struct timer_list power_button_poll_timer; |
| 230 | |
| 231 | static void power_button_poll(unsigned long dummy) |
| 232 | { |
| 233 | if (gpio_line_get(N2100_POWER_BUTTON) == 0) { |
| 234 | ctrl_alt_del(); |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | power_button_poll_timer.expires = jiffies + (HZ / 10); |
| 239 | add_timer(&power_button_poll_timer); |
| 240 | } |
| 241 | |
| 242 | |
| 243 | static void __init n2100_init_machine(void) |
| 244 | { |
| 245 | platform_device_register(&iop3xx_i2c0_device); |
| 246 | platform_device_register(&n2100_flash_device); |
| 247 | platform_device_register(&n2100_serial_device); |
| 248 | |
| 249 | pm_power_off = n2100_power_off; |
| 250 | |
| 251 | init_timer(&power_button_poll_timer); |
| 252 | power_button_poll_timer.function = power_button_poll; |
| 253 | power_button_poll_timer.expires = jiffies + (HZ / 10); |
| 254 | add_timer(&power_button_poll_timer); |
| 255 | } |
| 256 | |
| 257 | MACHINE_START(N2100, "Thecus N2100") |
| 258 | /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */ |
| 259 | .phys_io = N2100_UART, |
| 260 | .io_pg_offst = ((N2100_UART) >> 18) & 0xfffc, |
| 261 | .boot_params = 0xa0000100, |
| 262 | .map_io = n2100_map_io, |
| 263 | .init_irq = iop32x_init_irq, |
| 264 | .timer = &n2100_timer, |
| 265 | .init_machine = n2100_init_machine, |
| 266 | MACHINE_END |