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 <linux/gpio/machine.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>
42 #include "gpio-iop32x.h"
45 * N2100 timer tick configuration.
47 static void __init
n2100_timer_init(void)
49 /* 33.000 MHz crystal. */
50 iop_init_time(198000000);
57 static struct map_desc n2100_io_desc
[] __initdata
= {
58 { /* on-board devices */
59 .virtual = N2100_UART
,
60 .pfn
= __phys_to_pfn(N2100_UART
),
66 void __init
n2100_map_io(void)
69 iotable_init(n2100_io_desc
, ARRAY_SIZE(n2100_io_desc
));
76 static int n2100_pci_map_irq(const struct pci_dev
*dev
, u8 slot
, u8 pin
)
80 if (PCI_SLOT(dev
->devfn
) == 1) {
82 irq
= IRQ_IOP32X_XINT0
;
83 } else if (PCI_SLOT(dev
->devfn
) == 2) {
85 irq
= IRQ_IOP32X_XINT3
;
86 } else if (PCI_SLOT(dev
->devfn
) == 3) {
88 irq
= IRQ_IOP32X_XINT2
;
89 } else if (PCI_SLOT(dev
->devfn
) == 4 && pin
== 1) {
91 irq
= IRQ_IOP32X_XINT1
;
92 } else if (PCI_SLOT(dev
->devfn
) == 4 && pin
== 2) {
94 irq
= IRQ_IOP32X_XINT0
;
95 } else if (PCI_SLOT(dev
->devfn
) == 4 && pin
== 3) {
97 irq
= IRQ_IOP32X_XINT2
;
98 } else if (PCI_SLOT(dev
->devfn
) == 5) {
100 irq
= IRQ_IOP32X_XINT3
;
102 printk(KERN_ERR
"n2100_pci_map_irq() called for unknown "
103 "device PCI:%d:%d:%d\n", dev
->bus
->number
,
104 PCI_SLOT(dev
->devfn
), PCI_FUNC(dev
->devfn
));
111 static struct hw_pci n2100_pci __initdata
= {
114 .setup
= iop3xx_pci_setup
,
115 .preinit
= iop3xx_pci_preinit
,
116 .map_irq
= n2100_pci_map_irq
,
120 * Both r8169 chips on the n2100 exhibit PCI parity problems. Set
121 * the ->broken_parity_status flag for both ports so that the r8169
122 * driver knows it should ignore error interrupts.
124 static void n2100_fixup_r8169(struct pci_dev
*dev
)
126 if (dev
->bus
->number
== 0 &&
127 (dev
->devfn
== PCI_DEVFN(1, 0) ||
128 dev
->devfn
== PCI_DEVFN(2, 0)))
129 dev
->broken_parity_status
= 1;
131 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK
, PCI_ANY_ID
, n2100_fixup_r8169
);
133 static int __init
n2100_pci_init(void)
135 if (machine_is_n2100())
136 pci_common_init(&n2100_pci
);
141 subsys_initcall(n2100_pci_init
);
145 * N2100 machine initialisation.
147 static struct physmap_flash_data n2100_flash_data
= {
151 static struct resource n2100_flash_resource
= {
154 .flags
= IORESOURCE_MEM
,
157 static struct platform_device n2100_flash_device
= {
158 .name
= "physmap-flash",
161 .platform_data
= &n2100_flash_data
,
164 .resource
= &n2100_flash_resource
,
168 static struct plat_serial8250_port n2100_serial_port
[] = {
170 .mapbase
= N2100_UART
,
171 .membase
= (char *)N2100_UART
,
173 .flags
= UPF_SKIP_TEST
| UPF_AUTO_IRQ
| UPF_SHARE_IRQ
,
181 static struct resource n2100_uart_resource
= {
183 .end
= N2100_UART
+ 7,
184 .flags
= IORESOURCE_MEM
,
187 static struct platform_device n2100_serial_device
= {
188 .name
= "serial8250",
189 .id
= PLAT8250_DEV_PLATFORM
,
191 .platform_data
= n2100_serial_port
,
194 .resource
= &n2100_uart_resource
,
197 static struct f75375s_platform_data n2100_f75375s
= {
199 .pwm_enable
= { 0, 0 },
202 static struct pca9532_platform_data n2100_leds
= {
204 { .name
= "n2100:red:satafail0",
205 .state
= PCA9532_OFF
,
206 .type
= PCA9532_TYPE_LED
,
208 { .name
= "n2100:red:satafail1",
209 .state
= PCA9532_OFF
,
210 .type
= PCA9532_TYPE_LED
,
212 { .name
= "n2100:blue:usb",
213 .state
= PCA9532_OFF
,
214 .type
= PCA9532_TYPE_LED
,
216 { .type
= PCA9532_TYPE_NONE
},
218 { .type
= PCA9532_TYPE_NONE
},
219 { .type
= PCA9532_TYPE_NONE
},
220 { .type
= PCA9532_TYPE_NONE
},
221 { .name
= "n2100:red:usb",
222 .state
= PCA9532_OFF
,
223 .type
= PCA9532_TYPE_LED
,
226 { .type
= PCA9532_TYPE_NONE
}, /* power OFF gpio */
227 { .type
= PCA9532_TYPE_NONE
}, /* reset gpio */
228 { .type
= PCA9532_TYPE_NONE
},
229 { .type
= PCA9532_TYPE_NONE
},
231 { .type
= PCA9532_TYPE_NONE
},
232 { .name
= "n2100:orange:system",
233 .state
= PCA9532_OFF
,
234 .type
= PCA9532_TYPE_LED
,
236 { .name
= "n2100:red:system",
237 .state
= PCA9532_OFF
,
238 .type
= PCA9532_TYPE_LED
,
240 { .name
= "N2100 beeper" ,
241 .state
= PCA9532_OFF
,
242 .type
= PCA9532_TYPE_N2100_BEEP
,
249 static struct i2c_board_info __initdata n2100_i2c_devices
[] = {
251 I2C_BOARD_INFO("rs5c372b", 0x32),
254 I2C_BOARD_INFO("f75375", 0x2e),
255 .platform_data
= &n2100_f75375s
,
258 I2C_BOARD_INFO("pca9532", 0x60),
259 .platform_data
= &n2100_leds
,
264 * Pull PCA9532 GPIO #8 low to power off the machine.
266 static void n2100_power_off(void)
270 /* Start condition, I2C address of PCA9532, write transaction. */
271 *IOP3XX_IDBR0
= 0xc0;
275 /* Write address 0x08. */
276 *IOP3XX_IDBR0
= 0x08;
280 /* Write data 0x01, stop condition. */
281 *IOP3XX_IDBR0
= 0x01;
288 static void n2100_restart(enum reboot_mode mode
, const char *cmd
)
292 ret
= gpio_direction_output(N2100_HARDWARE_RESET
, 0);
294 pr_crit("could not drive reset GPIO low\n");
297 /* Wait for reset to happen */
303 static struct timer_list power_button_poll_timer
;
305 static void power_button_poll(struct timer_list
*unused
)
307 if (gpio_get_value(N2100_POWER_BUTTON
) == 0) {
312 power_button_poll_timer
.expires
= jiffies
+ (HZ
/ 10);
313 add_timer(&power_button_poll_timer
);
316 static int __init
n2100_request_gpios(void)
320 if (!machine_is_n2100())
323 ret
= gpio_request(N2100_HARDWARE_RESET
, "reset");
325 pr_err("could not request reset GPIO\n");
327 ret
= gpio_request(N2100_POWER_BUTTON
, "power");
329 pr_err("could not request power GPIO\n");
331 ret
= gpio_direction_input(N2100_POWER_BUTTON
);
333 pr_err("could not set power GPIO as input\n");
335 /* Set up power button poll timer */
336 timer_setup(&power_button_poll_timer
, power_button_poll
, 0);
337 power_button_poll_timer
.expires
= jiffies
+ (HZ
/ 10);
338 add_timer(&power_button_poll_timer
);
341 device_initcall(n2100_request_gpios
);
343 static void __init
n2100_init_machine(void)
345 register_iop32x_gpio();
346 gpiod_add_lookup_table(&iop3xx_i2c0_gpio_lookup
);
347 platform_device_register(&iop3xx_i2c0_device
);
348 platform_device_register(&n2100_flash_device
);
349 platform_device_register(&n2100_serial_device
);
350 platform_device_register(&iop3xx_dma_0_channel
);
351 platform_device_register(&iop3xx_dma_1_channel
);
353 i2c_register_board_info(0, n2100_i2c_devices
,
354 ARRAY_SIZE(n2100_i2c_devices
));
356 pm_power_off
= n2100_power_off
;
359 MACHINE_START(N2100
, "Thecus N2100")
360 /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */
361 .atag_offset
= 0x100,
362 .map_io
= n2100_map_io
,
363 .init_irq
= iop32x_init_irq
,
364 .init_time
= n2100_timer_init
,
365 .init_machine
= n2100_init_machine
,
366 .restart
= n2100_restart
,