1
2
3
4
5
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>
18#include "devices.h"
19#include <mach/regs-gpio.h>
20#include <mach/gpio-ks8695.h>
21#include "generic.h"
22
23static int og_pci_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
24{
25 if (machine_is_im4004() && (slot == 8))
26 return KS8695_IRQ_EXTERN1;
27 return KS8695_IRQ_EXTERN0;
28}
29
30static struct ks8695_pci_cfg __initdata og_pci = {
31 .mode = KS8695_MODE_PCI,
32 .map_irq = og_pci_map_irq,
33};
34
35static void __init og_register_pci(void)
36{
37
38 ks8695_gpio_interrupt(KS8695_GPIO_0, IRQ_TYPE_LEVEL_LOW);
39
40
41 if (machine_is_im4004())
42 ks8695_gpio_interrupt(KS8695_GPIO_1, IRQ_TYPE_LEVEL_LOW);
43
44 if (IS_ENABLED(CONFIG_PCI))
45 ks8695_init_pci(&og_pci);
46}
47
48
49
50
51
52static void __init og_pci_bus_reset(void)
53{
54 unsigned int rstline = 1;
55
56
57 if (machine_is_im4004())
58 rstline = 2;
59 else if (machine_is_im42xx())
60 rstline = 0;
61
62 gpio_request(rstline, "PCI reset");
63 gpio_direction_output(rstline, 0);
64
65
66 gpio_set_value(rstline, 1);
67 gpio_set_value(rstline, 0);
68 mdelay(100);
69 gpio_set_value(rstline, 1);
70 mdelay(100);
71}
72
73
74
75
76#define S8250_PHYS 0x03800000
77#define S8250_VIRT 0xf4000000
78#define S8250_SIZE 0x00100000
79
80static struct map_desc og_io_desc[] __initdata = {
81 {
82 .virtual = S8250_VIRT,
83 .pfn = __phys_to_pfn(S8250_PHYS),
84 .length = S8250_SIZE,
85 .type = MT_DEVICE,
86 }
87};
88
89static struct resource og_uart_resources[] = {
90 {
91 .start = S8250_VIRT,
92 .end = S8250_VIRT + S8250_SIZE,
93 .flags = IORESOURCE_MEM
94 },
95};
96
97static struct plat_serial8250_port og_uart_data[] = {
98 {
99 .mapbase = S8250_VIRT,
100 .membase = (char *) S8250_VIRT,
101 .irq = 3,
102 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
103 .iotype = UPIO_MEM,
104 .regshift = 2,
105 .uartclk = 115200 * 16,
106 },
107 { },
108};
109
110static struct platform_device og_uart = {
111 .name = "serial8250",
112 .id = 0,
113 .dev.platform_data = og_uart_data,
114 .num_resources = 1,
115 .resource = og_uart_resources
116};
117
118static struct platform_device *og_devices[] __initdata = {
119 &og_uart
120};
121
122static void __init og_init(void)
123{
124 ks8695_register_gpios();
125
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));
130 } else {
131 og_pci_bus_reset();
132 og_register_pci();
133 }
134
135 ks8695_add_device_lan();
136 ks8695_add_device_wan();
137}
138
139#ifdef CONFIG_MACH_CM4002
140MACHINE_START(CM4002, "OpenGear/CM4002")
141
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,
148MACHINE_END
149#endif
150
151#ifdef CONFIG_MACH_CM4008
152MACHINE_START(CM4008, "OpenGear/CM4008")
153
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,
160MACHINE_END
161#endif
162
163#ifdef CONFIG_MACH_CM41xx
164MACHINE_START(CM41XX, "OpenGear/CM41xx")
165
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,
172MACHINE_END
173#endif
174
175#ifdef CONFIG_MACH_IM4004
176MACHINE_START(IM4004, "OpenGear/IM4004")
177
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,
184MACHINE_END
185#endif
186
187#ifdef CONFIG_MACH_IM42xx
188MACHINE_START(IM42XX, "OpenGear/IM42xx")
189
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,
196MACHINE_END
197#endif
198