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