1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * arch/arm/mach-iop32x/n2100.c
5 * Board support code for the Thecus N2100 platform.
7 * Author: Rory Bolt <rorybolt@pacbell.net>
8 * Copyright (C) 2002 Rory Bolt
9 * Copyright 2003 (c) MontaVista, Software, Inc.
10 * Copyright (C) 2004 Intel Corp.
14 #include <linux/init.h>
15 #include <linux/f75375s.h>
16 #include <linux/leds-pca9532.h>
17 #include <linux/delay.h>
18 #include <linux/kernel.h>
19 #include <linux/pci.h>
21 #include <linux/string.h>
22 #include <linux/serial_core.h>
23 #include <linux/serial_8250.h>
24 #include <linux/mtd/physmap.h>
25 #include <linux/i2c.h>
26 #include <linux/platform_device.h>
27 #include <linux/reboot.h>
29 #include <linux/gpio.h>
30 #include <mach/hardware.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34 #include <asm/mach/pci.h>
35 #include <asm/mach/time.h>
36 #include <asm/mach-types.h>
38 #include <asm/pgtable.h>
39 #include <mach/time.h>
40 #include "gpio-iop32x.h"
43 * N2100 timer tick configuration.
45 static void __init n2100_timer_init(void)
47 /* 33.000 MHz crystal. */
48 iop_init_time(198000000);
55 static struct map_desc n2100_io_desc[] __initdata = {
56 { /* on-board devices */
57 .virtual = N2100_UART,
58 .pfn = __phys_to_pfn(N2100_UART),
64 void __init n2100_map_io(void)
67 iotable_init(n2100_io_desc, ARRAY_SIZE(n2100_io_desc));
74 static int n2100_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
78 if (PCI_SLOT(dev->devfn) == 1) {
80 irq = IRQ_IOP32X_XINT0;
81 } else if (PCI_SLOT(dev->devfn) == 2) {
83 irq = IRQ_IOP32X_XINT3;
84 } else if (PCI_SLOT(dev->devfn) == 3) {
86 irq = IRQ_IOP32X_XINT2;
87 } else if (PCI_SLOT(dev->devfn) == 4 && pin == 1) {
89 irq = IRQ_IOP32X_XINT1;
90 } else if (PCI_SLOT(dev->devfn) == 4 && pin == 2) {
92 irq = IRQ_IOP32X_XINT0;
93 } else if (PCI_SLOT(dev->devfn) == 4 && pin == 3) {
95 irq = IRQ_IOP32X_XINT2;
96 } else if (PCI_SLOT(dev->devfn) == 5) {
98 irq = IRQ_IOP32X_XINT3;
100 printk(KERN_ERR "n2100_pci_map_irq() called for unknown "
101 "device PCI:%d:%d:%d\n", dev->bus->number,
102 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
109 static struct hw_pci n2100_pci __initdata = {
112 .setup = iop3xx_pci_setup,
113 .preinit = iop3xx_pci_preinit,
114 .map_irq = n2100_pci_map_irq,
118 * Both r8169 chips on the n2100 exhibit PCI parity problems. Set
119 * the ->broken_parity_status flag for both ports so that the r8169
120 * driver knows it should ignore error interrupts.
122 static void n2100_fixup_r8169(struct pci_dev *dev)
124 if (dev->bus->number == 0 &&
125 (dev->devfn == PCI_DEVFN(1, 0) ||
126 dev->devfn == PCI_DEVFN(2, 0)))
127 dev->broken_parity_status = 1;
129 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, PCI_ANY_ID, n2100_fixup_r8169);
131 static int __init n2100_pci_init(void)
133 if (machine_is_n2100())
134 pci_common_init(&n2100_pci);
139 subsys_initcall(n2100_pci_init);
143 * N2100 machine initialisation.
145 static struct physmap_flash_data n2100_flash_data = {
149 static struct resource n2100_flash_resource = {
152 .flags = IORESOURCE_MEM,
155 static struct platform_device n2100_flash_device = {
156 .name = "physmap-flash",
159 .platform_data = &n2100_flash_data,
162 .resource = &n2100_flash_resource,
166 static struct plat_serial8250_port n2100_serial_port[] = {
168 .mapbase = N2100_UART,
169 .membase = (char *)N2100_UART,
171 .flags = UPF_SKIP_TEST | UPF_AUTO_IRQ | UPF_SHARE_IRQ,
179 static struct resource n2100_uart_resource = {
181 .end = N2100_UART + 7,
182 .flags = IORESOURCE_MEM,
185 static struct platform_device n2100_serial_device = {
186 .name = "serial8250",
187 .id = PLAT8250_DEV_PLATFORM,
189 .platform_data = n2100_serial_port,
192 .resource = &n2100_uart_resource,
195 static struct f75375s_platform_data n2100_f75375s = {
197 .pwm_enable = { 0, 0 },
200 static struct pca9532_platform_data n2100_leds = {
202 { .name = "n2100:red:satafail0",
203 .state = PCA9532_OFF,
204 .type = PCA9532_TYPE_LED,
206 { .name = "n2100:red:satafail1",
207 .state = PCA9532_OFF,
208 .type = PCA9532_TYPE_LED,
210 { .name = "n2100:blue:usb",
211 .state = PCA9532_OFF,
212 .type = PCA9532_TYPE_LED,
214 { .type = PCA9532_TYPE_NONE },
216 { .type = PCA9532_TYPE_NONE },
217 { .type = PCA9532_TYPE_NONE },
218 { .type = PCA9532_TYPE_NONE },
219 { .name = "n2100:red:usb",
220 .state = PCA9532_OFF,
221 .type = PCA9532_TYPE_LED,
224 { .type = PCA9532_TYPE_NONE }, /* power OFF gpio */
225 { .type = PCA9532_TYPE_NONE }, /* reset gpio */
226 { .type = PCA9532_TYPE_NONE },
227 { .type = PCA9532_TYPE_NONE },
229 { .type = PCA9532_TYPE_NONE },
230 { .name = "n2100:orange:system",
231 .state = PCA9532_OFF,
232 .type = PCA9532_TYPE_LED,
234 { .name = "n2100:red:system",
235 .state = PCA9532_OFF,
236 .type = PCA9532_TYPE_LED,
238 { .name = "N2100 beeper" ,
239 .state = PCA9532_OFF,
240 .type = PCA9532_TYPE_N2100_BEEP,
247 static struct i2c_board_info __initdata n2100_i2c_devices[] = {
249 I2C_BOARD_INFO("rs5c372b", 0x32),
252 I2C_BOARD_INFO("f75375", 0x2e),
253 .platform_data = &n2100_f75375s,
256 I2C_BOARD_INFO("pca9532", 0x60),
257 .platform_data = &n2100_leds,
262 * Pull PCA9532 GPIO #8 low to power off the machine.
264 static void n2100_power_off(void)
268 /* Start condition, I2C address of PCA9532, write transaction. */
269 *IOP3XX_IDBR0 = 0xc0;
273 /* Write address 0x08. */
274 *IOP3XX_IDBR0 = 0x08;
278 /* Write data 0x01, stop condition. */
279 *IOP3XX_IDBR0 = 0x01;
286 static void n2100_restart(enum reboot_mode mode, const char *cmd)
290 ret = gpio_direction_output(N2100_HARDWARE_RESET, 0);
292 pr_crit("could not drive reset GPIO low\n");
295 /* Wait for reset to happen */
301 static struct timer_list power_button_poll_timer;
303 static void power_button_poll(struct timer_list *unused)
305 if (gpio_get_value(N2100_POWER_BUTTON) == 0) {
310 power_button_poll_timer.expires = jiffies + (HZ / 10);
311 add_timer(&power_button_poll_timer);
314 static int __init n2100_request_gpios(void)
318 if (!machine_is_n2100())
321 ret = gpio_request(N2100_HARDWARE_RESET, "reset");
323 pr_err("could not request reset GPIO\n");
325 ret = gpio_request(N2100_POWER_BUTTON, "power");
327 pr_err("could not request power GPIO\n");
329 ret = gpio_direction_input(N2100_POWER_BUTTON);
331 pr_err("could not set power GPIO as input\n");
333 /* Set up power button poll timer */
334 timer_setup(&power_button_poll_timer, power_button_poll, 0);
335 power_button_poll_timer.expires = jiffies + (HZ / 10);
336 add_timer(&power_button_poll_timer);
339 device_initcall(n2100_request_gpios);
341 static void __init n2100_init_machine(void)
343 register_iop32x_gpio();
344 platform_device_register(&iop3xx_i2c0_device);
345 platform_device_register(&n2100_flash_device);
346 platform_device_register(&n2100_serial_device);
347 platform_device_register(&iop3xx_dma_0_channel);
348 platform_device_register(&iop3xx_dma_1_channel);
350 i2c_register_board_info(0, n2100_i2c_devices,
351 ARRAY_SIZE(n2100_i2c_devices));
353 pm_power_off = n2100_power_off;
356 MACHINE_START(N2100, "Thecus N2100")
357 /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */
358 .atag_offset = 0x100,
359 .map_io = n2100_map_io,
360 .init_irq = iop32x_init_irq,
361 .init_time = n2100_timer_init,
362 .init_machine = n2100_init_machine,
363 .restart = n2100_restart,