# BRCM_VERSION=3
[bcm963xx.git] / kernel / linux / 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
27 #include <asm/hardware.h>
28 #include <asm/irq.h>
29 #include <asm/system.h>
30 #include <asm/pgtable.h>
31 #include <asm/mach/map.h>
32
33 #include <asm/arch/udc.h>
34 #include <asm/arch/pxafb.h>
35
36 #include "generic.h"
37
38 /*
39  * Handy function to set GPIO alternate functions
40  */
41
42 void pxa_gpio_mode(int gpio_mode)
43 {
44         unsigned long flags;
45         int gpio = gpio_mode & GPIO_MD_MASK_NR;
46         int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
47         int gafr;
48
49         local_irq_save(flags);
50         if (gpio_mode & GPIO_MD_MASK_DIR)
51                 GPDR(gpio) |= GPIO_bit(gpio);
52         else
53                 GPDR(gpio) &= ~GPIO_bit(gpio);
54         gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
55         GAFR(gpio) = gafr |  (fn  << (((gpio) & 0xf)*2));
56         local_irq_restore(flags);
57 }
58
59 EXPORT_SYMBOL(pxa_gpio_mode);
60
61 /*
62  * Routine to safely enable or disable a clock in the CKEN
63  */
64 void pxa_set_cken(int clock, int enable)
65 {
66         unsigned long flags;
67         local_irq_save(flags);
68
69         if (enable)
70                 CKEN |= clock;
71         else
72                 CKEN &= ~clock;
73
74         local_irq_restore(flags);
75 }
76
77 EXPORT_SYMBOL(pxa_set_cken);
78
79 /*
80  * Intel PXA2xx internal register mapping.
81  *
82  * Note 1: not all PXA2xx variants implement all those addresses.
83  *
84  * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
85  *         and cache flush area.
86  */
87 static struct map_desc standard_io_desc[] __initdata = {
88  /* virtual     physical    length      type */
89   { 0xf2000000, 0x40000000, 0x01800000, MT_DEVICE }, /* Devs */
90   { 0xf4000000, 0x44000000, 0x00100000, MT_DEVICE }, /* LCD */
91   { 0xf6000000, 0x48000000, 0x00100000, MT_DEVICE }, /* Mem Ctl */
92   { 0xf8000000, 0x4c000000, 0x00100000, MT_DEVICE }, /* USB host */
93   { 0xfa000000, 0x50000000, 0x00100000, MT_DEVICE }, /* Camera */
94   { 0xfe000000, 0x58000000, 0x00100000, MT_DEVICE }, /* IMem ctl */
95   { 0xff000000, 0x00000000, 0x00100000, MT_DEVICE }  /* UNCACHED_PHYS_0 */
96 };
97
98 void __init pxa_map_io(void)
99 {
100         iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
101         get_clk_frequency_khz(1);
102 }
103
104
105 static struct resource pxamci_resources[] = {
106         [0] = {
107                 .start  = 0x41100000,
108                 .end    = 0x41100fff,
109                 .flags  = IORESOURCE_MEM,
110         },
111         [1] = {
112                 .start  = IRQ_MMC,
113                 .end    = IRQ_MMC,
114                 .flags  = IORESOURCE_IRQ,
115         },
116 };
117
118 static u64 pxamci_dmamask = 0xffffffffUL;
119
120 static struct platform_device pxamci_device = {
121         .name           = "pxa2xx-mci",
122         .id             = -1,
123         .dev            = {
124                 .dma_mask = &pxamci_dmamask,
125                 .coherent_dma_mask = 0xffffffff,
126         },
127         .num_resources  = ARRAY_SIZE(pxamci_resources),
128         .resource       = pxamci_resources,
129 };
130
131
132 static struct pxa2xx_udc_mach_info pxa_udc_info;
133
134 void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
135 {
136         memcpy(&pxa_udc_info, info, sizeof *info);
137 }
138 EXPORT_SYMBOL(pxa_set_udc_info);
139
140 static struct resource pxa2xx_udc_resources[] = {
141         [0] = {
142                 .start  = 0x40600000,
143                 .end    = 0x4060ffff,
144                 .flags  = IORESOURCE_MEM,
145         },
146         [1] = {
147                 .start  = IRQ_USB,
148                 .end    = IRQ_USB,
149                 .flags  = IORESOURCE_IRQ,
150         },
151 };
152
153 static u64 udc_dma_mask = ~(u32)0;
154
155 static struct platform_device udc_device = {
156         .name           = "pxa2xx-udc",
157         .id             = -1,
158         .resource       = pxa2xx_udc_resources,
159         .num_resources  = ARRAY_SIZE(pxa2xx_udc_resources),
160         .dev            =  {
161                 .platform_data  = &pxa_udc_info,
162                 .dma_mask       = &udc_dma_mask,
163         }
164 };
165
166 static struct pxafb_mach_info pxa_fb_info;
167
168 void __init set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info)
169 {
170         memcpy(&pxa_fb_info,hard_pxa_fb_info,sizeof(struct pxafb_mach_info));
171 }
172 EXPORT_SYMBOL(set_pxa_fb_info);
173
174 static struct resource pxafb_resources[] = {
175         [0] = {
176                 .start  = 0x44000000,
177                 .end    = 0x4400ffff,
178                 .flags  = IORESOURCE_MEM,
179         },
180         [1] = {
181                 .start  = IRQ_LCD,
182                 .end    = IRQ_LCD,
183                 .flags  = IORESOURCE_IRQ,
184         },
185 };
186
187 static u64 fb_dma_mask = ~(u64)0;
188
189 static struct platform_device pxafb_device = {
190         .name           = "pxa2xx-fb",
191         .id             = -1,
192         .dev            = {
193                 .platform_data  = &pxa_fb_info,
194                 .dma_mask       = &fb_dma_mask,
195                 .coherent_dma_mask = 0xffffffff,
196         },
197         .num_resources  = ARRAY_SIZE(pxafb_resources),
198         .resource       = pxafb_resources,
199 };
200
201 static struct platform_device ffuart_device = {
202         .name           = "pxa2xx-uart",
203         .id             = 0,
204 };
205 static struct platform_device btuart_device = {
206         .name           = "pxa2xx-uart",
207         .id             = 1,
208 };
209 static struct platform_device stuart_device = {
210         .name           = "pxa2xx-uart",
211         .id             = 2,
212 };
213
214 static struct platform_device *devices[] __initdata = {
215         &pxamci_device,
216         &udc_device,
217         &pxafb_device,
218         &ffuart_device,
219         &btuart_device,
220         &stuart_device,
221 };
222
223 static int __init pxa_init(void)
224 {
225         return platform_add_devices(devices, ARRAY_SIZE(devices));
226 }
227
228 subsys_initcall(pxa_init);