Commit | Line | Data |
---|---|---|
585cf175 TP |
1 | /* |
2 | * arch/arm/mach-orion/common.c | |
3 | * | |
4 | * Core functions for Marvell Orion System On Chip | |
5 | * | |
6 | * Maintainer: Tzachi Perelstein <tzachi@marvell.com> | |
7 | * | |
159ffb3a LB |
8 | * This file is licensed under the terms of the GNU General Public |
9 | * License version 2. This program is licensed "as is" without any | |
585cf175 TP |
10 | * warranty of any kind, whether express or implied. |
11 | */ | |
12 | ||
13 | #include <linux/kernel.h> | |
14 | #include <linux/init.h> | |
ca26f7d3 TP |
15 | #include <linux/platform_device.h> |
16 | #include <linux/serial_8250.h> | |
83b6d822 | 17 | #include <linux/mbus.h> |
e07c9d85 | 18 | #include <linux/mv643xx_eth.h> |
144aa3db | 19 | #include <linux/mv643xx_i2c.h> |
15a32632 | 20 | #include <linux/ata_platform.h> |
585cf175 | 21 | #include <asm/page.h> |
be73a347 | 22 | #include <asm/setup.h> |
c67de5b3 | 23 | #include <asm/timex.h> |
be73a347 | 24 | #include <asm/mach/arch.h> |
585cf175 | 25 | #include <asm/mach/map.h> |
2bac1de2 | 26 | #include <asm/mach/time.h> |
f244baa3 | 27 | #include <asm/arch/hardware.h> |
2bac1de2 | 28 | #include <asm/arch/orion.h> |
705a7521 | 29 | #include <asm/plat-orion/ehci-orion.h> |
5d4294c5 | 30 | #include <asm/plat-orion/orion_nand.h> |
2bac1de2 | 31 | #include <asm/plat-orion/time.h> |
585cf175 TP |
32 | #include "common.h" |
33 | ||
34 | /***************************************************************************** | |
35 | * I/O Address Mapping | |
36 | ****************************************************************************/ | |
37 | static struct map_desc orion_io_desc[] __initdata = { | |
38 | { | |
7f74c2c7 LB |
39 | .virtual = ORION_REGS_VIRT_BASE, |
40 | .pfn = __phys_to_pfn(ORION_REGS_PHYS_BASE), | |
585cf175 TP |
41 | .length = ORION_REGS_SIZE, |
42 | .type = MT_DEVICE | |
43 | }, | |
44 | { | |
7f74c2c7 LB |
45 | .virtual = ORION_PCIE_IO_VIRT_BASE, |
46 | .pfn = __phys_to_pfn(ORION_PCIE_IO_PHYS_BASE), | |
585cf175 TP |
47 | .length = ORION_PCIE_IO_SIZE, |
48 | .type = MT_DEVICE | |
49 | }, | |
50 | { | |
7f74c2c7 LB |
51 | .virtual = ORION_PCI_IO_VIRT_BASE, |
52 | .pfn = __phys_to_pfn(ORION_PCI_IO_PHYS_BASE), | |
585cf175 TP |
53 | .length = ORION_PCI_IO_SIZE, |
54 | .type = MT_DEVICE | |
55 | }, | |
56 | { | |
7f74c2c7 LB |
57 | .virtual = ORION_PCIE_WA_VIRT_BASE, |
58 | .pfn = __phys_to_pfn(ORION_PCIE_WA_PHYS_BASE), | |
585cf175 TP |
59 | .length = ORION_PCIE_WA_SIZE, |
60 | .type = MT_DEVICE | |
61 | }, | |
62 | }; | |
63 | ||
64 | void __init orion_map_io(void) | |
65 | { | |
66 | iotable_init(orion_io_desc, ARRAY_SIZE(orion_io_desc)); | |
67 | } | |
c67de5b3 | 68 | |
ca26f7d3 TP |
69 | /***************************************************************************** |
70 | * UART | |
71 | ****************************************************************************/ | |
72 | ||
73 | static struct resource orion_uart_resources[] = { | |
74 | { | |
7f74c2c7 LB |
75 | .start = UART0_PHYS_BASE, |
76 | .end = UART0_PHYS_BASE + 0xff, | |
ca26f7d3 TP |
77 | .flags = IORESOURCE_MEM, |
78 | }, | |
79 | { | |
80 | .start = IRQ_ORION_UART0, | |
81 | .end = IRQ_ORION_UART0, | |
82 | .flags = IORESOURCE_IRQ, | |
83 | }, | |
84 | { | |
7f74c2c7 LB |
85 | .start = UART1_PHYS_BASE, |
86 | .end = UART1_PHYS_BASE + 0xff, | |
ca26f7d3 TP |
87 | .flags = IORESOURCE_MEM, |
88 | }, | |
89 | { | |
90 | .start = IRQ_ORION_UART1, | |
91 | .end = IRQ_ORION_UART1, | |
92 | .flags = IORESOURCE_IRQ, | |
93 | }, | |
94 | }; | |
95 | ||
96 | static struct plat_serial8250_port orion_uart_data[] = { | |
97 | { | |
7f74c2c7 LB |
98 | .mapbase = UART0_PHYS_BASE, |
99 | .membase = (char *)UART0_VIRT_BASE, | |
ca26f7d3 TP |
100 | .irq = IRQ_ORION_UART0, |
101 | .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF, | |
102 | .iotype = UPIO_MEM, | |
103 | .regshift = 2, | |
104 | .uartclk = ORION_TCLK, | |
105 | }, | |
106 | { | |
7f74c2c7 LB |
107 | .mapbase = UART1_PHYS_BASE, |
108 | .membase = (char *)UART1_VIRT_BASE, | |
ca26f7d3 TP |
109 | .irq = IRQ_ORION_UART1, |
110 | .flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF, | |
111 | .iotype = UPIO_MEM, | |
112 | .regshift = 2, | |
113 | .uartclk = ORION_TCLK, | |
114 | }, | |
115 | { }, | |
116 | }; | |
117 | ||
118 | static struct platform_device orion_uart = { | |
119 | .name = "serial8250", | |
120 | .id = PLAT8250_DEV_PLATFORM, | |
121 | .dev = { | |
122 | .platform_data = orion_uart_data, | |
123 | }, | |
124 | .resource = orion_uart_resources, | |
125 | .num_resources = ARRAY_SIZE(orion_uart_resources), | |
126 | }; | |
127 | ||
128 | /******************************************************************************* | |
129 | * USB Controller - 2 interfaces | |
130 | ******************************************************************************/ | |
131 | ||
132 | static struct resource orion_ehci0_resources[] = { | |
133 | { | |
7f74c2c7 LB |
134 | .start = ORION_USB0_PHYS_BASE, |
135 | .end = ORION_USB0_PHYS_BASE + SZ_4K, | |
ca26f7d3 TP |
136 | .flags = IORESOURCE_MEM, |
137 | }, | |
138 | { | |
139 | .start = IRQ_ORION_USB0_CTRL, | |
140 | .end = IRQ_ORION_USB0_CTRL, | |
141 | .flags = IORESOURCE_IRQ, | |
142 | }, | |
143 | }; | |
144 | ||
145 | static struct resource orion_ehci1_resources[] = { | |
146 | { | |
7f74c2c7 LB |
147 | .start = ORION_USB1_PHYS_BASE, |
148 | .end = ORION_USB1_PHYS_BASE + SZ_4K, | |
ca26f7d3 TP |
149 | .flags = IORESOURCE_MEM, |
150 | }, | |
151 | { | |
152 | .start = IRQ_ORION_USB1_CTRL, | |
153 | .end = IRQ_ORION_USB1_CTRL, | |
154 | .flags = IORESOURCE_IRQ, | |
155 | }, | |
156 | }; | |
157 | ||
92aecfa9 LB |
158 | static struct orion_ehci_data orion_ehci_data = { |
159 | .dram = &orion_mbus_dram_info, | |
160 | }; | |
161 | ||
ca26f7d3 TP |
162 | static u64 ehci_dmamask = 0xffffffffUL; |
163 | ||
164 | static struct platform_device orion_ehci0 = { | |
165 | .name = "orion-ehci", | |
166 | .id = 0, | |
167 | .dev = { | |
168 | .dma_mask = &ehci_dmamask, | |
169 | .coherent_dma_mask = 0xffffffff, | |
92aecfa9 | 170 | .platform_data = &orion_ehci_data, |
ca26f7d3 TP |
171 | }, |
172 | .resource = orion_ehci0_resources, | |
173 | .num_resources = ARRAY_SIZE(orion_ehci0_resources), | |
174 | }; | |
175 | ||
176 | static struct platform_device orion_ehci1 = { | |
177 | .name = "orion-ehci", | |
178 | .id = 1, | |
179 | .dev = { | |
180 | .dma_mask = &ehci_dmamask, | |
181 | .coherent_dma_mask = 0xffffffff, | |
92aecfa9 | 182 | .platform_data = &orion_ehci_data, |
ca26f7d3 TP |
183 | }, |
184 | .resource = orion_ehci1_resources, | |
185 | .num_resources = ARRAY_SIZE(orion_ehci1_resources), | |
186 | }; | |
187 | ||
e07c9d85 TP |
188 | /***************************************************************************** |
189 | * Gigabit Ethernet port | |
190 | * (The Orion and Discovery (MV643xx) families use the same Ethernet driver) | |
191 | ****************************************************************************/ | |
192 | ||
193 | static struct resource orion_eth_shared_resources[] = { | |
194 | { | |
88603f1d LB |
195 | .start = ORION_ETH_PHYS_BASE + 0x2000, |
196 | .end = ORION_ETH_PHYS_BASE + 0x3fff, | |
e07c9d85 TP |
197 | .flags = IORESOURCE_MEM, |
198 | }, | |
199 | }; | |
200 | ||
201 | static struct platform_device orion_eth_shared = { | |
202 | .name = MV643XX_ETH_SHARED_NAME, | |
203 | .id = 0, | |
204 | .num_resources = 1, | |
205 | .resource = orion_eth_shared_resources, | |
206 | }; | |
207 | ||
208 | static struct resource orion_eth_resources[] = { | |
209 | { | |
210 | .name = "eth irq", | |
211 | .start = IRQ_ORION_ETH_SUM, | |
212 | .end = IRQ_ORION_ETH_SUM, | |
213 | .flags = IORESOURCE_IRQ, | |
214 | } | |
215 | }; | |
216 | ||
217 | static struct platform_device orion_eth = { | |
218 | .name = MV643XX_ETH_NAME, | |
219 | .id = 0, | |
220 | .num_resources = 1, | |
221 | .resource = orion_eth_resources, | |
222 | }; | |
223 | ||
224 | void __init orion_eth_init(struct mv643xx_eth_platform_data *eth_data) | |
225 | { | |
226 | orion_eth.dev.platform_data = eth_data; | |
227 | platform_device_register(&orion_eth_shared); | |
228 | platform_device_register(&orion_eth); | |
229 | } | |
230 | ||
144aa3db HVR |
231 | /***************************************************************************** |
232 | * I2C controller | |
233 | * (The Orion and Discovery (MV643xx) families share the same I2C controller) | |
234 | ****************************************************************************/ | |
235 | ||
236 | static struct mv64xxx_i2c_pdata orion_i2c_pdata = { | |
237 | .freq_m = 8, /* assumes 166 MHz TCLK */ | |
238 | .freq_n = 3, | |
239 | .timeout = 1000, /* Default timeout of 1 second */ | |
240 | }; | |
241 | ||
242 | static struct resource orion_i2c_resources[] = { | |
243 | { | |
244 | .name = "i2c base", | |
7f74c2c7 LB |
245 | .start = I2C_PHYS_BASE, |
246 | .end = I2C_PHYS_BASE + 0x20 -1, | |
144aa3db HVR |
247 | .flags = IORESOURCE_MEM, |
248 | }, | |
249 | { | |
250 | .name = "i2c irq", | |
251 | .start = IRQ_ORION_I2C, | |
252 | .end = IRQ_ORION_I2C, | |
253 | .flags = IORESOURCE_IRQ, | |
254 | }, | |
255 | }; | |
256 | ||
257 | static struct platform_device orion_i2c = { | |
258 | .name = MV64XXX_I2C_CTLR_NAME, | |
259 | .id = 0, | |
260 | .num_resources = ARRAY_SIZE(orion_i2c_resources), | |
261 | .resource = orion_i2c_resources, | |
262 | .dev = { | |
263 | .platform_data = &orion_i2c_pdata, | |
264 | }, | |
265 | }; | |
266 | ||
f244baa3 SB |
267 | /***************************************************************************** |
268 | * Sata port | |
269 | ****************************************************************************/ | |
270 | static struct resource orion_sata_resources[] = { | |
271 | { | |
272 | .name = "sata base", | |
7f74c2c7 LB |
273 | .start = ORION_SATA_PHYS_BASE, |
274 | .end = ORION_SATA_PHYS_BASE + 0x5000 - 1, | |
f244baa3 SB |
275 | .flags = IORESOURCE_MEM, |
276 | }, | |
277 | { | |
278 | .name = "sata irq", | |
279 | .start = IRQ_ORION_SATA, | |
280 | .end = IRQ_ORION_SATA, | |
281 | .flags = IORESOURCE_IRQ, | |
282 | }, | |
283 | }; | |
284 | ||
285 | static struct platform_device orion_sata = { | |
286 | .name = "sata_mv", | |
287 | .id = 0, | |
288 | .dev = { | |
289 | .coherent_dma_mask = 0xffffffff, | |
290 | }, | |
291 | .num_resources = ARRAY_SIZE(orion_sata_resources), | |
292 | .resource = orion_sata_resources, | |
293 | }; | |
294 | ||
295 | void __init orion_sata_init(struct mv_sata_platform_data *sata_data) | |
296 | { | |
15a32632 | 297 | sata_data->dram = &orion_mbus_dram_info; |
f244baa3 SB |
298 | orion_sata.dev.platform_data = sata_data; |
299 | platform_device_register(&orion_sata); | |
300 | } | |
301 | ||
2bac1de2 LB |
302 | /***************************************************************************** |
303 | * Time handling | |
304 | ****************************************************************************/ | |
305 | ||
306 | static void orion_timer_init(void) | |
307 | { | |
308 | orion_time_init(IRQ_ORION_BRIDGE, ORION_TCLK); | |
309 | } | |
310 | ||
311 | struct sys_timer orion_timer = { | |
312 | .init = orion_timer_init, | |
313 | }; | |
314 | ||
c67de5b3 TP |
315 | /***************************************************************************** |
316 | * General | |
317 | ****************************************************************************/ | |
318 | ||
319 | /* | |
320 | * Identify device ID and rev from PCIE configuration header space '0'. | |
321 | */ | |
a9984270 | 322 | static void __init orion_id(u32 *dev, u32 *rev, char **dev_name) |
c67de5b3 TP |
323 | { |
324 | orion_pcie_id(dev, rev); | |
325 | ||
326 | if (*dev == MV88F5281_DEV_ID) { | |
327 | if (*rev == MV88F5281_REV_D2) { | |
328 | *dev_name = "MV88F5281-D2"; | |
329 | } else if (*rev == MV88F5281_REV_D1) { | |
330 | *dev_name = "MV88F5281-D1"; | |
331 | } else { | |
332 | *dev_name = "MV88F5281-Rev-Unsupported"; | |
333 | } | |
334 | } else if (*dev == MV88F5182_DEV_ID) { | |
335 | if (*rev == MV88F5182_REV_A2) { | |
336 | *dev_name = "MV88F5182-A2"; | |
337 | } else { | |
338 | *dev_name = "MV88F5182-Rev-Unsupported"; | |
339 | } | |
c9e3de94 HVR |
340 | } else if (*dev == MV88F5181_DEV_ID) { |
341 | if (*rev == MV88F5181_REV_B1) { | |
342 | *dev_name = "MV88F5181-Rev-B1"; | |
343 | } else { | |
344 | *dev_name = "MV88F5181-Rev-Unsupported"; | |
345 | } | |
c67de5b3 TP |
346 | } else { |
347 | *dev_name = "Device-Unknown"; | |
348 | } | |
349 | } | |
350 | ||
351 | void __init orion_init(void) | |
352 | { | |
353 | char *dev_name; | |
354 | u32 dev, rev; | |
355 | ||
356 | orion_id(&dev, &rev, &dev_name); | |
357 | printk(KERN_INFO "Orion ID: %s. TCLK=%d.\n", dev_name, ORION_TCLK); | |
358 | ||
359 | /* | |
360 | * Setup Orion address map | |
361 | */ | |
98f79d1e | 362 | orion_setup_cpu_mbus_bridge(); |
c67de5b3 | 363 | orion_setup_eth_wins(); |
ca26f7d3 TP |
364 | |
365 | /* | |
159ffb3a | 366 | * Register devices. |
ca26f7d3 TP |
367 | */ |
368 | platform_device_register(&orion_uart); | |
369 | platform_device_register(&orion_ehci0); | |
370 | if (dev == MV88F5182_DEV_ID) | |
371 | platform_device_register(&orion_ehci1); | |
144aa3db | 372 | platform_device_register(&orion_i2c); |
c67de5b3 | 373 | } |
be73a347 GL |
374 | |
375 | /* | |
376 | * Many orion-based systems have buggy bootloader implementations. | |
377 | * This is a common fixup for bogus memory tags. | |
378 | */ | |
379 | void __init tag_fixup_mem32(struct machine_desc *mdesc, struct tag *t, | |
380 | char **from, struct meminfo *meminfo) | |
381 | { | |
382 | for (; t->hdr.size; t = tag_next(t)) | |
383 | if (t->hdr.tag == ATAG_MEM && | |
384 | (!t->u.mem.size || t->u.mem.size & ~PAGE_MASK || | |
385 | t->u.mem.start & ~PAGE_MASK)) { | |
386 | printk(KERN_WARNING | |
387 | "Clearing invalid memory bank %dKB@0x%08x\n", | |
388 | t->u.mem.size / 1024, t->u.mem.start); | |
389 | t->hdr.tag = 0; | |
390 | } | |
391 | } |