]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - arch/arm/mach-iop32x/n2100.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152
[mirror_ubuntu-jammy-kernel.git] / arch / arm / mach-iop32x / n2100.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
e60d07b6
LB
2/*
3 * arch/arm/mach-iop32x/n2100.c
4 *
5 * Board support code for the Thecus N2100 platform.
6 *
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.
e60d07b6
LB
11 */
12
13#include <linux/mm.h>
14#include <linux/init.h>
9aa69338 15#include <linux/f75375s.h>
30be0486 16#include <linux/leds-pca9532.h>
e60d07b6
LB
17#include <linux/delay.h>
18#include <linux/kernel.h>
19#include <linux/pci.h>
20#include <linux/pm.h>
21#include <linux/string.h>
e60d07b6
LB
22#include <linux/serial_core.h>
23#include <linux/serial_8250.h>
24#include <linux/mtd/physmap.h>
c00593f6 25#include <linux/i2c.h>
e60d07b6
LB
26#include <linux/platform_device.h>
27#include <linux/reboot.h>
fced80c7 28#include <linux/io.h>
7111f878 29#include <linux/gpio.h>
a09e64fb 30#include <mach/hardware.h>
e60d07b6
LB
31#include <asm/irq.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>
37#include <asm/page.h>
38#include <asm/pgtable.h>
a09e64fb 39#include <mach/time.h>
7b85b867 40#include "gpio-iop32x.h"
e60d07b6
LB
41
42/*
43 * N2100 timer tick configuration.
44 */
45static void __init n2100_timer_init(void)
46{
47 /* 33.000 MHz crystal. */
3668b45d 48 iop_init_time(198000000);
e60d07b6
LB
49}
50
e60d07b6
LB
51
52/*
53 * N2100 I/O.
54 */
55static struct map_desc n2100_io_desc[] __initdata = {
56 { /* on-board devices */
57 .virtual = N2100_UART,
58 .pfn = __phys_to_pfn(N2100_UART),
59 .length = 0x00100000,
60 .type = MT_DEVICE
61 },
62};
63
64void __init n2100_map_io(void)
65{
66 iop3xx_map_io();
67 iotable_init(n2100_io_desc, ARRAY_SIZE(n2100_io_desc));
68}
69
70
71/*
72 * N2100 PCI.
73 */
db409092 74static int n2100_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
e60d07b6
LB
75{
76 int irq;
77
78 if (PCI_SLOT(dev->devfn) == 1) {
79 /* RTL8110SB #1 */
80 irq = IRQ_IOP32X_XINT0;
81 } else if (PCI_SLOT(dev->devfn) == 2) {
82 /* RTL8110SB #2 */
811c9a4b 83 irq = IRQ_IOP32X_XINT3;
e60d07b6
LB
84 } else if (PCI_SLOT(dev->devfn) == 3) {
85 /* Sil3512 */
86 irq = IRQ_IOP32X_XINT2;
87 } else if (PCI_SLOT(dev->devfn) == 4 && pin == 1) {
88 /* VT6212 INTA */
89 irq = IRQ_IOP32X_XINT1;
90 } else if (PCI_SLOT(dev->devfn) == 4 && pin == 2) {
91 /* VT6212 INTB */
92 irq = IRQ_IOP32X_XINT0;
93 } else if (PCI_SLOT(dev->devfn) == 4 && pin == 3) {
94 /* VT6212 INTC */
95 irq = IRQ_IOP32X_XINT2;
96 } else if (PCI_SLOT(dev->devfn) == 5) {
97 /* Mini-PCI slot */
98 irq = IRQ_IOP32X_XINT3;
99 } else {
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));
103 irq = -1;
104 }
105
106 return irq;
107}
108
109static struct hw_pci n2100_pci __initdata = {
e60d07b6 110 .nr_controllers = 1,
c23bfc38 111 .ops = &iop3xx_ops,
e60d07b6
LB
112 .setup = iop3xx_pci_setup,
113 .preinit = iop3xx_pci_preinit,
e60d07b6
LB
114 .map_irq = n2100_pci_map_irq,
115};
116
66822b2e
LB
117/*
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.
121 */
122static void n2100_fixup_r8169(struct pci_dev *dev)
123{
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;
128}
129DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, PCI_ANY_ID, n2100_fixup_r8169);
130
e60d07b6
LB
131static int __init n2100_pci_init(void)
132{
133 if (machine_is_n2100())
134 pci_common_init(&n2100_pci);
135
136 return 0;
137}
138
139subsys_initcall(n2100_pci_init);
140
141
142/*
143 * N2100 machine initialisation.
144 */
145static struct physmap_flash_data n2100_flash_data = {
146 .width = 2,
147};
148
149static struct resource n2100_flash_resource = {
150 .start = 0xf0000000,
151 .end = 0xf0ffffff,
152 .flags = IORESOURCE_MEM,
153};
154
155static struct platform_device n2100_flash_device = {
156 .name = "physmap-flash",
157 .id = 0,
158 .dev = {
159 .platform_data = &n2100_flash_data,
160 },
161 .num_resources = 1,
162 .resource = &n2100_flash_resource,
163};
164
165
166static struct plat_serial8250_port n2100_serial_port[] = {
167 {
168 .mapbase = N2100_UART,
169 .membase = (char *)N2100_UART,
170 .irq = 0,
cc761bed 171 .flags = UPF_SKIP_TEST | UPF_AUTO_IRQ | UPF_SHARE_IRQ,
e60d07b6
LB
172 .iotype = UPIO_MEM,
173 .regshift = 0,
174 .uartclk = 1843200,
175 },
176 { },
177};
178
179static struct resource n2100_uart_resource = {
180 .start = N2100_UART,
181 .end = N2100_UART + 7,
182 .flags = IORESOURCE_MEM,
183};
184
185static struct platform_device n2100_serial_device = {
186 .name = "serial8250",
187 .id = PLAT8250_DEV_PLATFORM,
188 .dev = {
189 .platform_data = n2100_serial_port,
190 },
191 .num_resources = 1,
192 .resource = &n2100_uart_resource,
193};
194
9aa69338
RV
195static struct f75375s_platform_data n2100_f75375s = {
196 .pwm = { 255, 255 },
197 .pwm_enable = { 0, 0 },
198};
199
30be0486
RV
200static struct pca9532_platform_data n2100_leds = {
201 .leds = {
202 { .name = "n2100:red:satafail0",
203 .state = PCA9532_OFF,
204 .type = PCA9532_TYPE_LED,
205 },
206 { .name = "n2100:red:satafail1",
207 .state = PCA9532_OFF,
208 .type = PCA9532_TYPE_LED,
209 },
210 { .name = "n2100:blue:usb",
211 .state = PCA9532_OFF,
212 .type = PCA9532_TYPE_LED,
213 },
214 { .type = PCA9532_TYPE_NONE },
215
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,
222 },
223
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 },
228
229 { .type = PCA9532_TYPE_NONE },
230 { .name = "n2100:orange:system",
231 .state = PCA9532_OFF,
232 .type = PCA9532_TYPE_LED,
233 },
234 { .name = "n2100:red:system",
235 .state = PCA9532_OFF,
236 .type = PCA9532_TYPE_LED,
237 },
238 { .name = "N2100 beeper" ,
239 .state = PCA9532_OFF,
240 .type = PCA9532_TYPE_N2100_BEEP,
241 },
242 },
243 .psc = { 0, 0 },
244 .pwm = { 0, 0 },
245};
246
c00593f6
MM
247static struct i2c_board_info __initdata n2100_i2c_devices[] = {
248 {
3760f736 249 I2C_BOARD_INFO("rs5c372b", 0x32),
c00593f6 250 },
9aa69338
RV
251 {
252 I2C_BOARD_INFO("f75375", 0x2e),
9aa69338
RV
253 .platform_data = &n2100_f75375s,
254 },
30be0486
RV
255 {
256 I2C_BOARD_INFO("pca9532", 0x60),
257 .platform_data = &n2100_leds,
258 },
c00593f6 259};
e60d07b6
LB
260
261/*
262 * Pull PCA9532 GPIO #8 low to power off the machine.
263 */
264static void n2100_power_off(void)
265{
266 local_irq_disable();
267
268 /* Start condition, I2C address of PCA9532, write transaction. */
269 *IOP3XX_IDBR0 = 0xc0;
270 *IOP3XX_ICR0 = 0xe9;
271 mdelay(1);
272
273 /* Write address 0x08. */
274 *IOP3XX_IDBR0 = 0x08;
275 *IOP3XX_ICR0 = 0xe8;
276 mdelay(1);
277
278 /* Write data 0x01, stop condition. */
279 *IOP3XX_IDBR0 = 0x01;
280 *IOP3XX_ICR0 = 0xea;
281
282 while (1)
283 ;
284}
285
7b6d864b 286static void n2100_restart(enum reboot_mode mode, const char *cmd)
bec92b1e 287{
7111f878
LW
288 int ret;
289
290 ret = gpio_direction_output(N2100_HARDWARE_RESET, 0);
291 if (ret) {
292 pr_crit("could not drive reset GPIO low\n");
293 return;
294 }
295 /* Wait for reset to happen */
bec92b1e
RK
296 while (1)
297 ;
298}
299
e60d07b6
LB
300
301static struct timer_list power_button_poll_timer;
302
e99e88a9 303static void power_button_poll(struct timer_list *unused)
e60d07b6 304{
afc3b79f 305 if (gpio_get_value(N2100_POWER_BUTTON) == 0) {
e60d07b6
LB
306 ctrl_alt_del();
307 return;
308 }
309
310 power_button_poll_timer.expires = jiffies + (HZ / 10);
311 add_timer(&power_button_poll_timer);
312}
313
7111f878
LW
314static int __init n2100_request_gpios(void)
315{
316 int ret;
317
318 if (!machine_is_n2100())
319 return 0;
320
321 ret = gpio_request(N2100_HARDWARE_RESET, "reset");
322 if (ret)
323 pr_err("could not request reset GPIO\n");
afc3b79f
LW
324
325 ret = gpio_request(N2100_POWER_BUTTON, "power");
326 if (ret)
327 pr_err("could not request power GPIO\n");
328 else {
329 ret = gpio_direction_input(N2100_POWER_BUTTON);
330 if (ret)
331 pr_err("could not set power GPIO as input\n");
332 }
333 /* Set up power button poll timer */
e99e88a9 334 timer_setup(&power_button_poll_timer, power_button_poll, 0);
afc3b79f
LW
335 power_button_poll_timer.expires = jiffies + (HZ / 10);
336 add_timer(&power_button_poll_timer);
7111f878
LW
337 return 0;
338}
339device_initcall(n2100_request_gpios);
e60d07b6
LB
340
341static void __init n2100_init_machine(void)
342{
7b85b867 343 register_iop32x_gpio();
e60d07b6
LB
344 platform_device_register(&iop3xx_i2c0_device);
345 platform_device_register(&n2100_flash_device);
346 platform_device_register(&n2100_serial_device);
2492c845
DW
347 platform_device_register(&iop3xx_dma_0_channel);
348 platform_device_register(&iop3xx_dma_1_channel);
e60d07b6 349
c00593f6
MM
350 i2c_register_board_info(0, n2100_i2c_devices,
351 ARRAY_SIZE(n2100_i2c_devices));
352
e60d07b6 353 pm_power_off = n2100_power_off;
e60d07b6
LB
354}
355
356MACHINE_START(N2100, "Thecus N2100")
357 /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */
1896746d 358 .atag_offset = 0x100,
e60d07b6
LB
359 .map_io = n2100_map_io,
360 .init_irq = iop32x_init_irq,
6bb27d73 361 .init_time = n2100_timer_init,
e60d07b6 362 .init_machine = n2100_init_machine,
bec92b1e 363 .restart = n2100_restart,
e60d07b6 364MACHINE_END