1 // SPDX-License-Identifier: GPL-2.0-only
3 * board-og.c -- support for the OpenGear KS8695 based boards.
6 #include <linux/kernel.h>
7 #include <linux/types.h>
8 #include <linux/interrupt.h>
9 #include <linux/init.h>
10 #include <linux/delay.h>
11 #include <linux/platform_device.h>
12 #include <linux/serial_8250.h>
13 #include <linux/gpio.h>
14 #include <linux/irq.h>
15 #include <asm/mach-types.h>
16 #include <asm/mach/arch.h>
17 #include <asm/mach/map.h>
19 #include <mach/regs-gpio.h>
20 #include <mach/gpio-ks8695.h>
23 static int og_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
25 if (machine_is_im4004() && (slot == 8))
26 return KS8695_IRQ_EXTERN1;
27 return KS8695_IRQ_EXTERN0;
30 static struct ks8695_pci_cfg __initdata og_pci = {
31 .mode = KS8695_MODE_PCI,
32 .map_irq = og_pci_map_irq,
35 static void __init og_register_pci(void)
37 /* Initialize the GPIO lines for interrupt mode */
38 ks8695_gpio_interrupt(KS8695_GPIO_0, IRQ_TYPE_LEVEL_LOW);
41 if (machine_is_im4004())
42 ks8695_gpio_interrupt(KS8695_GPIO_1, IRQ_TYPE_LEVEL_LOW);
44 if (IS_ENABLED(CONFIG_PCI))
45 ks8695_init_pci(&og_pci);
49 * The PCI bus reset is driven by a dedicated GPIO line. Toggle it here
50 * and bring the PCI bus out of reset.
52 static void __init og_pci_bus_reset(void)
54 unsigned int rstline = 1;
56 /* Some boards use a different GPIO as the PCI reset line */
57 if (machine_is_im4004())
59 else if (machine_is_im42xx())
62 gpio_request(rstline, "PCI reset");
63 gpio_direction_output(rstline, 0);
65 /* Drive a reset on the PCI reset line */
66 gpio_set_value(rstline, 1);
67 gpio_set_value(rstline, 0);
69 gpio_set_value(rstline, 1);
74 * Direct connect serial ports (non-PCI that is).
76 #define S8250_PHYS 0x03800000
77 #define S8250_VIRT 0xf4000000
78 #define S8250_SIZE 0x00100000
80 static struct map_desc og_io_desc[] __initdata = {
82 .virtual = S8250_VIRT,
83 .pfn = __phys_to_pfn(S8250_PHYS),
89 static struct resource og_uart_resources[] = {
92 .end = S8250_VIRT + S8250_SIZE,
93 .flags = IORESOURCE_MEM
97 static struct plat_serial8250_port og_uart_data[] = {
99 .mapbase = S8250_VIRT,
100 .membase = (char *) S8250_VIRT,
102 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
105 .uartclk = 115200 * 16,
110 static struct platform_device og_uart = {
111 .name = "serial8250",
113 .dev.platform_data = og_uart_data,
115 .resource = og_uart_resources
118 static struct platform_device *og_devices[] __initdata = {
122 static void __init og_init(void)
124 ks8695_register_gpios();
126 if (machine_is_cm4002()) {
127 ks8695_gpio_interrupt(KS8695_GPIO_1, IRQ_TYPE_LEVEL_HIGH);
128 iotable_init(og_io_desc, ARRAY_SIZE(og_io_desc));
129 platform_add_devices(og_devices, ARRAY_SIZE(og_devices));
135 ks8695_add_device_lan();
136 ks8695_add_device_wan();
139 #ifdef CONFIG_MACH_CM4002
140 MACHINE_START(CM4002, "OpenGear/CM4002")
142 .atag_offset = 0x100,
143 .map_io = ks8695_map_io,
144 .init_irq = ks8695_init_irq,
145 .init_machine = og_init,
146 .init_time = ks8695_timer_init,
147 .restart = ks8695_restart,
151 #ifdef CONFIG_MACH_CM4008
152 MACHINE_START(CM4008, "OpenGear/CM4008")
154 .atag_offset = 0x100,
155 .map_io = ks8695_map_io,
156 .init_irq = ks8695_init_irq,
157 .init_machine = og_init,
158 .init_time = ks8695_timer_init,
159 .restart = ks8695_restart,
163 #ifdef CONFIG_MACH_CM41xx
164 MACHINE_START(CM41XX, "OpenGear/CM41xx")
166 .atag_offset = 0x100,
167 .map_io = ks8695_map_io,
168 .init_irq = ks8695_init_irq,
169 .init_machine = og_init,
170 .init_time = ks8695_timer_init,
171 .restart = ks8695_restart,
175 #ifdef CONFIG_MACH_IM4004
176 MACHINE_START(IM4004, "OpenGear/IM4004")
178 .atag_offset = 0x100,
179 .map_io = ks8695_map_io,
180 .init_irq = ks8695_init_irq,
181 .init_machine = og_init,
182 .init_time = ks8695_timer_init,
183 .restart = ks8695_restart,
187 #ifdef CONFIG_MACH_IM42xx
188 MACHINE_START(IM42XX, "OpenGear/IM42xx")
190 .atag_offset = 0x100,
191 .map_io = ks8695_map_io,
192 .init_irq = ks8695_init_irq,
193 .init_machine = og_init,
194 .init_time = ks8695_timer_init,
195 .restart = ks8695_restart,