]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/arm/mach-pxa/generic.c
Merge iSeries include file move
[karo-tx-linux.git] / arch / arm / mach-pxa / generic.c
1 /*
2  *  linux/arch/arm/mach-pxa/generic.c
3  *
4  *  Author:     Nicolas Pitre
5  *  Created:    Jun 15, 2001
6  *  Copyright:  MontaVista Software Inc.
7  *
8  * Code common to all PXA machines.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  *
14  * Since this file should be linked before any other machine specific file,
15  * the __initcall() here will be executed first.  This serves as default
16  * initialization stuff for PXA machines which can be overridden later if
17  * need be.
18  */
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/delay.h>
23 #include <linux/device.h>
24 #include <linux/ioport.h>
25 #include <linux/pm.h>
26 #include <linux/string.h>
27
28 #include <asm/hardware.h>
29 #include <asm/irq.h>
30 #include <asm/system.h>
31 #include <asm/pgtable.h>
32 #include <asm/mach/map.h>
33
34 #include <asm/arch/pxa-regs.h>
35 #include <asm/arch/udc.h>
36 #include <asm/arch/pxafb.h>
37 #include <asm/arch/mmc.h>
38 #include <asm/arch/irda.h>
39 #include <asm/arch/i2c.h>
40
41 #include "generic.h"
42
43 /*
44  * Handy function to set GPIO alternate functions
45  */
46
47 void pxa_gpio_mode(int gpio_mode)
48 {
49         unsigned long flags;
50         int gpio = gpio_mode & GPIO_MD_MASK_NR;
51         int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
52         int gafr;
53
54         local_irq_save(flags);
55         if (gpio_mode & GPIO_DFLT_LOW)
56                 GPCR(gpio) = GPIO_bit(gpio);
57         else if (gpio_mode & GPIO_DFLT_HIGH)
58                 GPSR(gpio) = GPIO_bit(gpio);
59         if (gpio_mode & GPIO_MD_MASK_DIR)
60                 GPDR(gpio) |= GPIO_bit(gpio);
61         else
62                 GPDR(gpio) &= ~GPIO_bit(gpio);
63         gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
64         GAFR(gpio) = gafr |  (fn  << (((gpio) & 0xf)*2));
65         local_irq_restore(flags);
66 }
67
68 EXPORT_SYMBOL(pxa_gpio_mode);
69
70 /*
71  * Routine to safely enable or disable a clock in the CKEN
72  */
73 void pxa_set_cken(int clock, int enable)
74 {
75         unsigned long flags;
76         local_irq_save(flags);
77
78         if (enable)
79                 CKEN |= clock;
80         else
81                 CKEN &= ~clock;
82
83         local_irq_restore(flags);
84 }
85
86 EXPORT_SYMBOL(pxa_set_cken);
87
88 /*
89  * Intel PXA2xx internal register mapping.
90  *
91  * Note 1: not all PXA2xx variants implement all those addresses.
92  *
93  * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
94  *         and cache flush area.
95  */
96 static struct map_desc standard_io_desc[] __initdata = {
97         {       /* Devs */
98                 .virtual        =  0xf2000000,
99                 .pfn            = __phys_to_pfn(0x40000000),
100                 .length         = 0x02000000,
101                 .type           = MT_DEVICE
102         }, {    /* LCD */
103                 .virtual        =  0xf4000000,
104                 .pfn            = __phys_to_pfn(0x44000000),
105                 .length         = 0x00100000,
106                 .type           = MT_DEVICE
107         }, {    /* Mem Ctl */
108                 .virtual        =  0xf6000000,
109                 .pfn            = __phys_to_pfn(0x48000000),
110                 .length         = 0x00100000,
111                 .type           = MT_DEVICE
112         }, {    /* USB host */
113                 .virtual        =  0xf8000000,
114                 .pfn            = __phys_to_pfn(0x4c000000),
115                 .length         = 0x00100000,
116                 .type           = MT_DEVICE
117         }, {    /* Camera */
118                 .virtual        =  0xfa000000,
119                 .pfn            = __phys_to_pfn(0x50000000),
120                 .length         = 0x00100000,
121                 .type           = MT_DEVICE
122         }, {    /* IMem ctl */
123                 .virtual        =  0xfe000000,
124                 .pfn            = __phys_to_pfn(0x58000000),
125                 .length         = 0x00100000,
126                 .type           = MT_DEVICE
127         }, {    /* UNCACHED_PHYS_0 */
128                 .virtual        = 0xff000000,
129                 .pfn            = __phys_to_pfn(0x00000000),
130                 .length         = 0x00100000,
131                 .type           = MT_DEVICE
132         }
133 };
134
135 void __init pxa_map_io(void)
136 {
137         iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
138         get_clk_frequency_khz(1);
139 }
140
141
142 static struct resource pxamci_resources[] = {
143         [0] = {
144                 .start  = 0x41100000,
145                 .end    = 0x41100fff,
146                 .flags  = IORESOURCE_MEM,
147         },
148         [1] = {
149                 .start  = IRQ_MMC,
150                 .end    = IRQ_MMC,
151                 .flags  = IORESOURCE_IRQ,
152         },
153 };
154
155 static u64 pxamci_dmamask = 0xffffffffUL;
156
157 static struct platform_device pxamci_device = {
158         .name           = "pxa2xx-mci",
159         .id             = -1,
160         .dev            = {
161                 .dma_mask = &pxamci_dmamask,
162                 .coherent_dma_mask = 0xffffffff,
163         },
164         .num_resources  = ARRAY_SIZE(pxamci_resources),
165         .resource       = pxamci_resources,
166 };
167
168 void __init pxa_set_mci_info(struct pxamci_platform_data *info)
169 {
170         pxamci_device.dev.platform_data = info;
171 }
172
173
174 static struct pxa2xx_udc_mach_info pxa_udc_info;
175
176 void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
177 {
178         memcpy(&pxa_udc_info, info, sizeof *info);
179 }
180
181 static struct resource pxa2xx_udc_resources[] = {
182         [0] = {
183                 .start  = 0x40600000,
184                 .end    = 0x4060ffff,
185                 .flags  = IORESOURCE_MEM,
186         },
187         [1] = {
188                 .start  = IRQ_USB,
189                 .end    = IRQ_USB,
190                 .flags  = IORESOURCE_IRQ,
191         },
192 };
193
194 static u64 udc_dma_mask = ~(u32)0;
195
196 static struct platform_device udc_device = {
197         .name           = "pxa2xx-udc",
198         .id             = -1,
199         .resource       = pxa2xx_udc_resources,
200         .num_resources  = ARRAY_SIZE(pxa2xx_udc_resources),
201         .dev            =  {
202                 .platform_data  = &pxa_udc_info,
203                 .dma_mask       = &udc_dma_mask,
204         }
205 };
206
207 static struct pxafb_mach_info pxa_fb_info;
208
209 void __init set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info)
210 {
211         memcpy(&pxa_fb_info,hard_pxa_fb_info,sizeof(struct pxafb_mach_info));
212 }
213
214 static struct resource pxafb_resources[] = {
215         [0] = {
216                 .start  = 0x44000000,
217                 .end    = 0x4400ffff,
218                 .flags  = IORESOURCE_MEM,
219         },
220         [1] = {
221                 .start  = IRQ_LCD,
222                 .end    = IRQ_LCD,
223                 .flags  = IORESOURCE_IRQ,
224         },
225 };
226
227 static u64 fb_dma_mask = ~(u64)0;
228
229 static struct platform_device pxafb_device = {
230         .name           = "pxa2xx-fb",
231         .id             = -1,
232         .dev            = {
233                 .platform_data  = &pxa_fb_info,
234                 .dma_mask       = &fb_dma_mask,
235                 .coherent_dma_mask = 0xffffffff,
236         },
237         .num_resources  = ARRAY_SIZE(pxafb_resources),
238         .resource       = pxafb_resources,
239 };
240
241 void __init set_pxa_fb_parent(struct device *parent_dev)
242 {
243         pxafb_device.dev.parent = parent_dev;
244 }
245
246 static struct platform_device ffuart_device = {
247         .name           = "pxa2xx-uart",
248         .id             = 0,
249 };
250 static struct platform_device btuart_device = {
251         .name           = "pxa2xx-uart",
252         .id             = 1,
253 };
254 static struct platform_device stuart_device = {
255         .name           = "pxa2xx-uart",
256         .id             = 2,
257 };
258 static struct platform_device hwuart_device = {
259         .name           = "pxa2xx-uart",
260         .id             = 3,
261 };
262
263 static struct resource i2c_resources[] = {
264         {
265                 .start  = 0x40301680,
266                 .end    = 0x403016a3,
267                 .flags  = IORESOURCE_MEM,
268         }, {
269                 .start  = IRQ_I2C,
270                 .end    = IRQ_I2C,
271                 .flags  = IORESOURCE_IRQ,
272         },
273 };
274
275 static struct platform_device i2c_device = {
276         .name           = "pxa2xx-i2c",
277         .id             = 0,
278         .resource       = i2c_resources,
279         .num_resources  = ARRAY_SIZE(i2c_resources),
280 };
281
282 void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
283 {
284         i2c_device.dev.platform_data = info;
285 }
286
287 static struct resource i2s_resources[] = {
288         {
289                 .start  = 0x40400000,
290                 .end    = 0x40400083,
291                 .flags  = IORESOURCE_MEM,
292         }, {
293                 .start  = IRQ_I2S,
294                 .end    = IRQ_I2S,
295                 .flags  = IORESOURCE_IRQ,
296         },
297 };
298
299 static struct platform_device i2s_device = {
300         .name           = "pxa2xx-i2s",
301         .id             = -1,
302         .resource       = i2s_resources,
303         .num_resources  = ARRAY_SIZE(i2s_resources),
304 };
305
306 static u64 pxaficp_dmamask = ~(u32)0;
307
308 static struct platform_device pxaficp_device = {
309         .name           = "pxa2xx-ir",
310         .id             = -1,
311         .dev            = {
312                 .dma_mask = &pxaficp_dmamask,
313                 .coherent_dma_mask = 0xffffffff,
314         },
315 };
316
317 void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
318 {
319         pxaficp_device.dev.platform_data = info;
320 }
321
322 static struct platform_device *devices[] __initdata = {
323         &pxamci_device,
324         &udc_device,
325         &pxafb_device,
326         &ffuart_device,
327         &btuart_device,
328         &stuart_device,
329         &pxaficp_device,
330         &i2c_device,
331         &i2s_device,
332 };
333
334 static int __init pxa_init(void)
335 {
336         int cpuid, ret;
337
338         ret = platform_add_devices(devices, ARRAY_SIZE(devices));
339         if (ret)
340                 return ret;
341
342         /* Only add HWUART for PXA255/26x; PXA210/250/27x do not have it. */
343         cpuid = read_cpuid(CPUID_ID);
344         if (((cpuid >> 4) & 0xfff) == 0x2d0 ||
345             ((cpuid >> 4) & 0xfff) == 0x290)
346                 ret = platform_device_register(&hwuart_device);
347
348         return ret;
349 }
350
351 subsys_initcall(pxa_init);