Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[sfrench/cifs-2.6.git] / arch / arm / mach-kirkwood / common.c
1 /*
2  * arch/arm/mach-kirkwood/common.c
3  *
4  * Core functions for Marvell Kirkwood SoCs
5  *
6  * This file is licensed under the terms of the GNU General Public
7  * License version 2.  This program is licensed "as is" without any
8  * warranty of any kind, whether express or implied.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/serial_8250.h>
15 #include <linux/mbus.h>
16 #include <linux/mv643xx_eth.h>
17 #include <linux/ata_platform.h>
18 #include <asm/page.h>
19 #include <asm/timex.h>
20 #include <asm/mach/map.h>
21 #include <asm/mach/time.h>
22 #include <asm/arch/kirkwood.h>
23 #include <asm/plat-orion/cache-feroceon-l2.h>
24 #include <asm/plat-orion/ehci-orion.h>
25 #include <asm/plat-orion/orion_nand.h>
26 #include <asm/plat-orion/time.h>
27 #include "common.h"
28
29 /*****************************************************************************
30  * I/O Address Mapping
31  ****************************************************************************/
32 static struct map_desc kirkwood_io_desc[] __initdata = {
33         {
34                 .virtual        = KIRKWOOD_PCIE_IO_VIRT_BASE,
35                 .pfn            = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
36                 .length         = KIRKWOOD_PCIE_IO_SIZE,
37                 .type           = MT_DEVICE,
38         }, {
39                 .virtual        = KIRKWOOD_REGS_VIRT_BASE,
40                 .pfn            = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
41                 .length         = KIRKWOOD_REGS_SIZE,
42                 .type           = MT_DEVICE,
43         },
44 };
45
46 void __init kirkwood_map_io(void)
47 {
48         iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc));
49 }
50
51
52 /*****************************************************************************
53  * EHCI
54  ****************************************************************************/
55 static struct orion_ehci_data kirkwood_ehci_data = {
56         .dram           = &kirkwood_mbus_dram_info,
57 };
58
59 static u64 ehci_dmamask = 0xffffffffUL;
60
61
62 /*****************************************************************************
63  * EHCI0
64  ****************************************************************************/
65 static struct resource kirkwood_ehci_resources[] = {
66         {
67                 .start  = USB_PHYS_BASE,
68                 .end    = USB_PHYS_BASE + 0x0fff,
69                 .flags  = IORESOURCE_MEM,
70         }, {
71                 .start  = IRQ_KIRKWOOD_USB,
72                 .end    = IRQ_KIRKWOOD_USB,
73                 .flags  = IORESOURCE_IRQ,
74         },
75 };
76
77 static struct platform_device kirkwood_ehci = {
78         .name           = "orion-ehci",
79         .id             = 0,
80         .dev            = {
81                 .dma_mask               = &ehci_dmamask,
82                 .coherent_dma_mask      = 0xffffffff,
83                 .platform_data          = &kirkwood_ehci_data,
84         },
85         .resource       = kirkwood_ehci_resources,
86         .num_resources  = ARRAY_SIZE(kirkwood_ehci_resources),
87 };
88
89 void __init kirkwood_ehci_init(void)
90 {
91         platform_device_register(&kirkwood_ehci);
92 }
93
94
95 /*****************************************************************************
96  * GE00
97  ****************************************************************************/
98 struct mv643xx_eth_shared_platform_data kirkwood_ge00_shared_data = {
99         .t_clk          = KIRKWOOD_TCLK,
100         .dram           = &kirkwood_mbus_dram_info,
101 };
102
103 static struct resource kirkwood_ge00_shared_resources[] = {
104         {
105                 .name   = "ge00 base",
106                 .start  = GE00_PHYS_BASE + 0x2000,
107                 .end    = GE00_PHYS_BASE + 0x3fff,
108                 .flags  = IORESOURCE_MEM,
109         },
110 };
111
112 static struct platform_device kirkwood_ge00_shared = {
113         .name           = MV643XX_ETH_SHARED_NAME,
114         .id             = 0,
115         .dev            = {
116                 .platform_data  = &kirkwood_ge00_shared_data,
117         },
118         .num_resources  = 1,
119         .resource       = kirkwood_ge00_shared_resources,
120 };
121
122 static struct resource kirkwood_ge00_resources[] = {
123         {
124                 .name   = "ge00 irq",
125                 .start  = IRQ_KIRKWOOD_GE00_SUM,
126                 .end    = IRQ_KIRKWOOD_GE00_SUM,
127                 .flags  = IORESOURCE_IRQ,
128         },
129 };
130
131 static struct platform_device kirkwood_ge00 = {
132         .name           = MV643XX_ETH_NAME,
133         .id             = 0,
134         .num_resources  = 1,
135         .resource       = kirkwood_ge00_resources,
136 };
137
138 void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data)
139 {
140         eth_data->shared = &kirkwood_ge00_shared;
141         kirkwood_ge00.dev.platform_data = eth_data;
142
143         platform_device_register(&kirkwood_ge00_shared);
144         platform_device_register(&kirkwood_ge00);
145 }
146
147
148 /*****************************************************************************
149  * SoC RTC
150  ****************************************************************************/
151 static struct resource kirkwood_rtc_resource = {
152         .start  = RTC_PHYS_BASE,
153         .end    = RTC_PHYS_BASE + SZ_16 - 1,
154         .flags  = IORESOURCE_MEM,
155 };
156
157 void __init kirkwood_rtc_init(void)
158 {
159         platform_device_register_simple("rtc-mv", -1, &kirkwood_rtc_resource, 1);
160 }
161
162
163 /*****************************************************************************
164  * SATA
165  ****************************************************************************/
166 static struct resource kirkwood_sata_resources[] = {
167         {
168                 .name   = "sata base",
169                 .start  = SATA_PHYS_BASE,
170                 .end    = SATA_PHYS_BASE + 0x5000 - 1,
171                 .flags  = IORESOURCE_MEM,
172         }, {
173                 .name   = "sata irq",
174                 .start  = IRQ_KIRKWOOD_SATA,
175                 .end    = IRQ_KIRKWOOD_SATA,
176                 .flags  = IORESOURCE_IRQ,
177         },
178 };
179
180 static struct platform_device kirkwood_sata = {
181         .name           = "sata_mv",
182         .id             = 0,
183         .dev            = {
184                 .coherent_dma_mask      = 0xffffffff,
185         },
186         .num_resources  = ARRAY_SIZE(kirkwood_sata_resources),
187         .resource       = kirkwood_sata_resources,
188 };
189
190 void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data)
191 {
192         sata_data->dram = &kirkwood_mbus_dram_info;
193         kirkwood_sata.dev.platform_data = sata_data;
194         platform_device_register(&kirkwood_sata);
195 }
196
197
198 /*****************************************************************************
199  * UART0
200  ****************************************************************************/
201 static struct plat_serial8250_port kirkwood_uart0_data[] = {
202         {
203                 .mapbase        = UART0_PHYS_BASE,
204                 .membase        = (char *)UART0_VIRT_BASE,
205                 .irq            = IRQ_KIRKWOOD_UART_0,
206                 .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
207                 .iotype         = UPIO_MEM,
208                 .regshift       = 2,
209                 .uartclk        = KIRKWOOD_TCLK,
210         }, {
211         },
212 };
213
214 static struct resource kirkwood_uart0_resources[] = {
215         {
216                 .start          = UART0_PHYS_BASE,
217                 .end            = UART0_PHYS_BASE + 0xff,
218                 .flags          = IORESOURCE_MEM,
219         }, {
220                 .start          = IRQ_KIRKWOOD_UART_0,
221                 .end            = IRQ_KIRKWOOD_UART_0,
222                 .flags          = IORESOURCE_IRQ,
223         },
224 };
225
226 static struct platform_device kirkwood_uart0 = {
227         .name                   = "serial8250",
228         .id                     = 0,
229         .dev                    = {
230                 .platform_data  = kirkwood_uart0_data,
231         },
232         .resource               = kirkwood_uart0_resources,
233         .num_resources          = ARRAY_SIZE(kirkwood_uart0_resources),
234 };
235
236 void __init kirkwood_uart0_init(void)
237 {
238         platform_device_register(&kirkwood_uart0);
239 }
240
241
242 /*****************************************************************************
243  * UART1
244  ****************************************************************************/
245 static struct plat_serial8250_port kirkwood_uart1_data[] = {
246         {
247                 .mapbase        = UART1_PHYS_BASE,
248                 .membase        = (char *)UART1_VIRT_BASE,
249                 .irq            = IRQ_KIRKWOOD_UART_1,
250                 .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
251                 .iotype         = UPIO_MEM,
252                 .regshift       = 2,
253                 .uartclk        = KIRKWOOD_TCLK,
254         }, {
255         },
256 };
257
258 static struct resource kirkwood_uart1_resources[] = {
259         {
260                 .start          = UART1_PHYS_BASE,
261                 .end            = UART1_PHYS_BASE + 0xff,
262                 .flags          = IORESOURCE_MEM,
263         }, {
264                 .start          = IRQ_KIRKWOOD_UART_1,
265                 .end            = IRQ_KIRKWOOD_UART_1,
266                 .flags          = IORESOURCE_IRQ,
267         },
268 };
269
270 static struct platform_device kirkwood_uart1 = {
271         .name                   = "serial8250",
272         .id                     = 1,
273         .dev                    = {
274                 .platform_data  = kirkwood_uart1_data,
275         },
276         .resource               = kirkwood_uart1_resources,
277         .num_resources          = ARRAY_SIZE(kirkwood_uart1_resources),
278 };
279
280 void __init kirkwood_uart1_init(void)
281 {
282         platform_device_register(&kirkwood_uart1);
283 }
284
285
286 /*****************************************************************************
287  * Time handling
288  ****************************************************************************/
289 static void kirkwood_timer_init(void)
290 {
291         orion_time_init(IRQ_KIRKWOOD_BRIDGE, KIRKWOOD_TCLK);
292 }
293
294 struct sys_timer kirkwood_timer = {
295         .init = kirkwood_timer_init,
296 };
297
298
299 /*****************************************************************************
300  * General
301  ****************************************************************************/
302 static char * __init kirkwood_id(void)
303 {
304         switch (readl(DEVICE_ID) & 0x3) {
305         case 0:
306                 return "88F6180";
307         case 1:
308                 return "88F6192";
309         case 2:
310                 return "88F6281";
311         }
312
313         return "unknown 88F6000 variant";
314 }
315
316 static int __init is_l2_writethrough(void)
317 {
318         return !!(readl(L2_CONFIG_REG) & L2_WRITETHROUGH);
319 }
320
321 void __init kirkwood_init(void)
322 {
323         printk(KERN_INFO "Kirkwood: %s, TCLK=%d.\n",
324                 kirkwood_id(), KIRKWOOD_TCLK);
325
326         kirkwood_setup_cpu_mbus();
327
328 #ifdef CONFIG_CACHE_FEROCEON_L2
329         feroceon_l2_init(is_l2_writethrough());
330 #endif
331 }