ARM: orion: Consolidate the creation of the uart platform data.
[linux-2.6-block.git] / arch / arm / plat-orion / common.c
1 /*
2  * arch/arm/plat-orion/common.c
3  *
4  * Marvell Orion SoC common setup code used by multiple mach-/common.c
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
16 /* Fill in the resources structure and link it into the platform
17    device structure. There is always a memory region, and nearly
18    always an interrupt.*/
19 static void fill_resources(struct platform_device *device,
20                            struct resource *resources,
21                            resource_size_t mapbase,
22                            resource_size_t size,
23                            unsigned int irq)
24 {
25         device->resource = resources;
26         device->num_resources = 1;
27         resources[0].flags = IORESOURCE_MEM;
28         resources[0].start = mapbase;
29         resources[0].end = mapbase + size;
30
31         if (irq != NO_IRQ) {
32                 device->num_resources++;
33                 resources[1].flags = IORESOURCE_IRQ;
34                 resources[1].start = irq;
35                 resources[1].end = irq;
36         }
37 }
38
39 /*****************************************************************************
40  * UART
41  ****************************************************************************/
42 static void __init uart_complete(
43         struct platform_device *orion_uart,
44         struct plat_serial8250_port *data,
45         struct resource *resources,
46         unsigned int membase,
47         resource_size_t mapbase,
48         unsigned int irq,
49         unsigned int uartclk)
50 {
51         data->mapbase = mapbase;
52         data->membase = (void __iomem *)membase;
53         data->irq = irq;
54         data->uartclk = uartclk;
55         orion_uart->dev.platform_data = data;
56
57         fill_resources(orion_uart, resources, mapbase, 0xff, irq);
58         platform_device_register(orion_uart);
59 }
60
61 /*****************************************************************************
62  * UART0
63  ****************************************************************************/
64 static struct plat_serial8250_port orion_uart0_data[] = {
65         {
66                 .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
67                 .iotype         = UPIO_MEM,
68                 .regshift       = 2,
69         }, {
70         },
71 };
72
73 static struct resource orion_uart0_resources[2];
74
75 static struct platform_device orion_uart0 = {
76         .name                   = "serial8250",
77         .id                     = PLAT8250_DEV_PLATFORM,
78 };
79
80 void __init orion_uart0_init(unsigned int membase,
81                              resource_size_t mapbase,
82                              unsigned int irq,
83                              unsigned int uartclk)
84 {
85         uart_complete(&orion_uart0, orion_uart0_data, orion_uart0_resources,
86                       membase, mapbase, irq, uartclk);
87 }
88
89 /*****************************************************************************
90  * UART1
91  ****************************************************************************/
92 static struct plat_serial8250_port orion_uart1_data[] = {
93         {
94                 .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
95                 .iotype         = UPIO_MEM,
96                 .regshift       = 2,
97         }, {
98         },
99 };
100
101 static struct resource orion_uart1_resources[2];
102
103 static struct platform_device orion_uart1 = {
104         .name                   = "serial8250",
105         .id                     = PLAT8250_DEV_PLATFORM1,
106 };
107
108 void __init orion_uart1_init(unsigned int membase,
109                              resource_size_t mapbase,
110                              unsigned int irq,
111                              unsigned int uartclk)
112 {
113         uart_complete(&orion_uart1, orion_uart1_data, orion_uart1_resources,
114                       membase, mapbase, irq, uartclk);
115 }
116
117 /*****************************************************************************
118  * UART2
119  ****************************************************************************/
120 static struct plat_serial8250_port orion_uart2_data[] = {
121         {
122                 .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
123                 .iotype         = UPIO_MEM,
124                 .regshift       = 2,
125         }, {
126         },
127 };
128
129 static struct resource orion_uart2_resources[2];
130
131 static struct platform_device orion_uart2 = {
132         .name                   = "serial8250",
133         .id                     = PLAT8250_DEV_PLATFORM2,
134 };
135
136 void __init orion_uart2_init(unsigned int membase,
137                              resource_size_t mapbase,
138                              unsigned int irq,
139                              unsigned int uartclk)
140 {
141         uart_complete(&orion_uart2, orion_uart2_data, orion_uart2_resources,
142                       membase, mapbase, irq, uartclk);
143 }
144
145 /*****************************************************************************
146  * UART3
147  ****************************************************************************/
148 static struct plat_serial8250_port orion_uart3_data[] = {
149         {
150                 .flags          = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
151                 .iotype         = UPIO_MEM,
152                 .regshift       = 2,
153         }, {
154         },
155 };
156
157 static struct resource orion_uart3_resources[2];
158
159 static struct platform_device orion_uart3 = {
160         .name                   = "serial8250",
161         .id                     = 3,
162 };
163
164 void __init orion_uart3_init(unsigned int membase,
165                              resource_size_t mapbase,
166                              unsigned int irq,
167                              unsigned int uartclk)
168 {
169         uart_complete(&orion_uart3, orion_uart3_data, orion_uart3_resources,
170                       membase, mapbase, irq, uartclk);
171 }