blob: bc40a97050a13ebc409b786b19fcbfe24e7ac3f1 [file] [log] [blame]
Lennert Buytenheke60d07b2006-09-21 02:42:12 +01001/*
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 Voipio9aa69332007-10-16 13:08:57 +030019#include <linux/f75375s.h>
Riku Voipio30be0482008-05-31 14:45:16 +010020#include <linux/leds-pca9532.h>
Lennert Buytenheke60d07b2006-09-21 02:42:12 +010021#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 Buytenheke60d07b2006-09-21 02:42:12 +010026#include <linux/serial_core.h>
27#include <linux/serial_8250.h>
28#include <linux/mtd/physmap.h>
Martin Michlmayrc00593f2007-07-17 04:04:57 -070029#include <linux/i2c.h>
Lennert Buytenheke60d07b2006-09-21 02:42:12 +010030#include <linux/platform_device.h>
31#include <linux/reboot.h>
Russell Kingfced80c2008-09-06 12:10:45 +010032#include <linux/io.h>
Linus Walleij7111f872013-09-09 14:45:47 +020033#include <linux/gpio.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010034#include <mach/hardware.h>
Lennert Buytenheke60d07b2006-09-21 02:42:12 +010035#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 Kinga09e64f2008-08-05 16:14:15 +010043#include <mach/time.h>
Lennert Buytenheke60d07b2006-09-21 02:42:12 +010044
45/*
46 * N2100 timer tick configuration.
47 */
48static void __init n2100_timer_init(void)
49{
50 /* 33.000 MHz crystal. */
Dan Williams3668b452007-02-13 17:13:34 +010051 iop_init_time(198000000);
Lennert Buytenheke60d07b2006-09-21 02:42:12 +010052}
53
Lennert Buytenheke60d07b2006-09-21 02:42:12 +010054
55/*
56 * N2100 I/O.
57 */
58static struct map_desc n2100_io_desc[] __initdata = {
59 { /* on-board devices */
60 .virtual = N2100_UART,
61 .pfn = __phys_to_pfn(N2100_UART),
62 .length = 0x00100000,
63 .type = MT_DEVICE
64 },
65};
66
67void __init n2100_map_io(void)
68{
69 iop3xx_map_io();
70 iotable_init(n2100_io_desc, ARRAY_SIZE(n2100_io_desc));
71}
72
73
74/*
75 * N2100 PCI.
76 */
Dan Williamsd73d8012007-05-15 01:03:36 +010077static int __init
Ralf Baechled5341942011-06-10 15:30:21 +010078n2100_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
Lennert Buytenheke60d07b2006-09-21 02:42:12 +010079{
80 int irq;
81
82 if (PCI_SLOT(dev->devfn) == 1) {
83 /* RTL8110SB #1 */
84 irq = IRQ_IOP32X_XINT0;
85 } else if (PCI_SLOT(dev->devfn) == 2) {
86 /* RTL8110SB #2 */
Lennert Buytenhek811c9a42006-10-29 14:15:10 +010087 irq = IRQ_IOP32X_XINT3;
Lennert Buytenheke60d07b2006-09-21 02:42:12 +010088 } else if (PCI_SLOT(dev->devfn) == 3) {
89 /* Sil3512 */
90 irq = IRQ_IOP32X_XINT2;
91 } else if (PCI_SLOT(dev->devfn) == 4 && pin == 1) {
92 /* VT6212 INTA */
93 irq = IRQ_IOP32X_XINT1;
94 } else if (PCI_SLOT(dev->devfn) == 4 && pin == 2) {
95 /* VT6212 INTB */
96 irq = IRQ_IOP32X_XINT0;
97 } else if (PCI_SLOT(dev->devfn) == 4 && pin == 3) {
98 /* VT6212 INTC */
99 irq = IRQ_IOP32X_XINT2;
100 } else if (PCI_SLOT(dev->devfn) == 5) {
101 /* Mini-PCI slot */
102 irq = IRQ_IOP32X_XINT3;
103 } else {
104 printk(KERN_ERR "n2100_pci_map_irq() called for unknown "
105 "device PCI:%d:%d:%d\n", dev->bus->number,
106 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
107 irq = -1;
108 }
109
110 return irq;
111}
112
113static struct hw_pci n2100_pci __initdata = {
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100114 .nr_controllers = 1,
Russell Kingc23bfc32012-03-10 12:49:16 +0000115 .ops = &iop3xx_ops,
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100116 .setup = iop3xx_pci_setup,
117 .preinit = iop3xx_pci_preinit,
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100118 .map_irq = n2100_pci_map_irq,
119};
120
Lennert Buytenhek66822b22007-02-08 01:03:17 +0100121/*
122 * Both r8169 chips on the n2100 exhibit PCI parity problems. Set
123 * the ->broken_parity_status flag for both ports so that the r8169
124 * driver knows it should ignore error interrupts.
125 */
126static void n2100_fixup_r8169(struct pci_dev *dev)
127{
128 if (dev->bus->number == 0 &&
129 (dev->devfn == PCI_DEVFN(1, 0) ||
130 dev->devfn == PCI_DEVFN(2, 0)))
131 dev->broken_parity_status = 1;
132}
133DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, PCI_ANY_ID, n2100_fixup_r8169);
134
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100135static int __init n2100_pci_init(void)
136{
137 if (machine_is_n2100())
138 pci_common_init(&n2100_pci);
139
140 return 0;
141}
142
143subsys_initcall(n2100_pci_init);
144
145
146/*
147 * N2100 machine initialisation.
148 */
149static struct physmap_flash_data n2100_flash_data = {
150 .width = 2,
151};
152
153static struct resource n2100_flash_resource = {
154 .start = 0xf0000000,
155 .end = 0xf0ffffff,
156 .flags = IORESOURCE_MEM,
157};
158
159static struct platform_device n2100_flash_device = {
160 .name = "physmap-flash",
161 .id = 0,
162 .dev = {
163 .platform_data = &n2100_flash_data,
164 },
165 .num_resources = 1,
166 .resource = &n2100_flash_resource,
167};
168
169
170static struct plat_serial8250_port n2100_serial_port[] = {
171 {
172 .mapbase = N2100_UART,
173 .membase = (char *)N2100_UART,
174 .irq = 0,
Aaro Koskinencc761be2010-02-16 22:06:14 +0100175 .flags = UPF_SKIP_TEST | UPF_AUTO_IRQ | UPF_SHARE_IRQ,
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100176 .iotype = UPIO_MEM,
177 .regshift = 0,
178 .uartclk = 1843200,
179 },
180 { },
181};
182
183static struct resource n2100_uart_resource = {
184 .start = N2100_UART,
185 .end = N2100_UART + 7,
186 .flags = IORESOURCE_MEM,
187};
188
189static struct platform_device n2100_serial_device = {
190 .name = "serial8250",
191 .id = PLAT8250_DEV_PLATFORM,
192 .dev = {
193 .platform_data = n2100_serial_port,
194 },
195 .num_resources = 1,
196 .resource = &n2100_uart_resource,
197};
198
Riku Voipio9aa69332007-10-16 13:08:57 +0300199static struct f75375s_platform_data n2100_f75375s = {
200 .pwm = { 255, 255 },
201 .pwm_enable = { 0, 0 },
202};
203
Riku Voipio30be0482008-05-31 14:45:16 +0100204static struct pca9532_platform_data n2100_leds = {
205 .leds = {
206 { .name = "n2100:red:satafail0",
207 .state = PCA9532_OFF,
208 .type = PCA9532_TYPE_LED,
209 },
210 { .name = "n2100:red:satafail1",
211 .state = PCA9532_OFF,
212 .type = PCA9532_TYPE_LED,
213 },
214 { .name = "n2100:blue:usb",
215 .state = PCA9532_OFF,
216 .type = PCA9532_TYPE_LED,
217 },
218 { .type = PCA9532_TYPE_NONE },
219
220 { .type = PCA9532_TYPE_NONE },
221 { .type = PCA9532_TYPE_NONE },
222 { .type = PCA9532_TYPE_NONE },
223 { .name = "n2100:red:usb",
224 .state = PCA9532_OFF,
225 .type = PCA9532_TYPE_LED,
226 },
227
228 { .type = PCA9532_TYPE_NONE }, /* power OFF gpio */
229 { .type = PCA9532_TYPE_NONE }, /* reset gpio */
230 { .type = PCA9532_TYPE_NONE },
231 { .type = PCA9532_TYPE_NONE },
232
233 { .type = PCA9532_TYPE_NONE },
234 { .name = "n2100:orange:system",
235 .state = PCA9532_OFF,
236 .type = PCA9532_TYPE_LED,
237 },
238 { .name = "n2100:red:system",
239 .state = PCA9532_OFF,
240 .type = PCA9532_TYPE_LED,
241 },
242 { .name = "N2100 beeper" ,
243 .state = PCA9532_OFF,
244 .type = PCA9532_TYPE_N2100_BEEP,
245 },
246 },
247 .psc = { 0, 0 },
248 .pwm = { 0, 0 },
249};
250
Martin Michlmayrc00593f2007-07-17 04:04:57 -0700251static struct i2c_board_info __initdata n2100_i2c_devices[] = {
252 {
Jean Delvare3760f732008-04-29 23:11:40 +0200253 I2C_BOARD_INFO("rs5c372b", 0x32),
Martin Michlmayrc00593f2007-07-17 04:04:57 -0700254 },
Riku Voipio9aa69332007-10-16 13:08:57 +0300255 {
256 I2C_BOARD_INFO("f75375", 0x2e),
Riku Voipio9aa69332007-10-16 13:08:57 +0300257 .platform_data = &n2100_f75375s,
258 },
Riku Voipio30be0482008-05-31 14:45:16 +0100259 {
260 I2C_BOARD_INFO("pca9532", 0x60),
261 .platform_data = &n2100_leds,
262 },
Martin Michlmayrc00593f2007-07-17 04:04:57 -0700263};
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100264
265/*
266 * Pull PCA9532 GPIO #8 low to power off the machine.
267 */
268static void n2100_power_off(void)
269{
270 local_irq_disable();
271
272 /* Start condition, I2C address of PCA9532, write transaction. */
273 *IOP3XX_IDBR0 = 0xc0;
274 *IOP3XX_ICR0 = 0xe9;
275 mdelay(1);
276
277 /* Write address 0x08. */
278 *IOP3XX_IDBR0 = 0x08;
279 *IOP3XX_ICR0 = 0xe8;
280 mdelay(1);
281
282 /* Write data 0x01, stop condition. */
283 *IOP3XX_IDBR0 = 0x01;
284 *IOP3XX_ICR0 = 0xea;
285
286 while (1)
287 ;
288}
289
Robin Holt7b6d8642013-07-08 16:01:40 -0700290static void n2100_restart(enum reboot_mode mode, const char *cmd)
Russell Kingbec92b12011-11-05 11:26:32 +0000291{
Linus Walleij7111f872013-09-09 14:45:47 +0200292 int ret;
293
294 ret = gpio_direction_output(N2100_HARDWARE_RESET, 0);
295 if (ret) {
296 pr_crit("could not drive reset GPIO low\n");
297 return;
298 }
299 /* Wait for reset to happen */
Russell Kingbec92b12011-11-05 11:26:32 +0000300 while (1)
301 ;
302}
303
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100304
305static struct timer_list power_button_poll_timer;
306
307static void power_button_poll(unsigned long dummy)
308{
Linus Walleijafc3b792013-09-09 14:53:02 +0200309 if (gpio_get_value(N2100_POWER_BUTTON) == 0) {
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100310 ctrl_alt_del();
311 return;
312 }
313
314 power_button_poll_timer.expires = jiffies + (HZ / 10);
315 add_timer(&power_button_poll_timer);
316}
317
Linus Walleij7111f872013-09-09 14:45:47 +0200318static int __init n2100_request_gpios(void)
319{
320 int ret;
321
322 if (!machine_is_n2100())
323 return 0;
324
325 ret = gpio_request(N2100_HARDWARE_RESET, "reset");
326 if (ret)
327 pr_err("could not request reset GPIO\n");
Linus Walleijafc3b792013-09-09 14:53:02 +0200328
329 ret = gpio_request(N2100_POWER_BUTTON, "power");
330 if (ret)
331 pr_err("could not request power GPIO\n");
332 else {
333 ret = gpio_direction_input(N2100_POWER_BUTTON);
334 if (ret)
335 pr_err("could not set power GPIO as input\n");
336 }
337 /* Set up power button poll timer */
338 init_timer(&power_button_poll_timer);
339 power_button_poll_timer.function = power_button_poll;
340 power_button_poll_timer.expires = jiffies + (HZ / 10);
341 add_timer(&power_button_poll_timer);
Linus Walleij7111f872013-09-09 14:45:47 +0200342 return 0;
343}
344device_initcall(n2100_request_gpios);
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100345
346static void __init n2100_init_machine(void)
347{
348 platform_device_register(&iop3xx_i2c0_device);
349 platform_device_register(&n2100_flash_device);
350 platform_device_register(&n2100_serial_device);
Dan Williams2492c842007-01-02 13:52:31 -0700351 platform_device_register(&iop3xx_dma_0_channel);
352 platform_device_register(&iop3xx_dma_1_channel);
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100353
Martin Michlmayrc00593f2007-07-17 04:04:57 -0700354 i2c_register_board_info(0, n2100_i2c_devices,
355 ARRAY_SIZE(n2100_i2c_devices));
356
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100357 pm_power_off = n2100_power_off;
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100358}
359
360MACHINE_START(N2100, "Thecus N2100")
361 /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */
Nicolas Pitre18967462011-07-05 22:38:12 -0400362 .atag_offset = 0x100,
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100363 .map_io = n2100_map_io,
364 .init_irq = iop32x_init_irq,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700365 .init_time = n2100_timer_init,
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100366 .init_machine = n2100_init_machine,
Russell Kingbec92b12011-11-05 11:26:32 +0000367 .restart = n2100_restart,
Lennert Buytenheke60d07b2006-09-21 02:42:12 +0100368MACHINE_END