blob: d327c127eddbefb6ece11b25e8e91e9536c43b97 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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/pxa-regs.h>
34#include <asm/arch/udc.h>
35#include <asm/arch/pxafb.h>
36#include <asm/arch/mmc.h>
Russell Kingeb9181a2005-09-29 09:49:25 +010037#include <asm/arch/i2c.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39#include "generic.h"
40
41/*
42 * Handy function to set GPIO alternate functions
43 */
44
45void pxa_gpio_mode(int gpio_mode)
46{
47 unsigned long flags;
48 int gpio = gpio_mode & GPIO_MD_MASK_NR;
49 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
50 int gafr;
51
52 local_irq_save(flags);
53 if (gpio_mode & GPIO_DFLT_LOW)
54 GPCR(gpio) = GPIO_bit(gpio);
55 else if (gpio_mode & GPIO_DFLT_HIGH)
56 GPSR(gpio) = GPIO_bit(gpio);
57 if (gpio_mode & GPIO_MD_MASK_DIR)
58 GPDR(gpio) |= GPIO_bit(gpio);
59 else
60 GPDR(gpio) &= ~GPIO_bit(gpio);
61 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
62 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
63 local_irq_restore(flags);
64}
65
66EXPORT_SYMBOL(pxa_gpio_mode);
67
68/*
69 * Routine to safely enable or disable a clock in the CKEN
70 */
71void pxa_set_cken(int clock, int enable)
72{
73 unsigned long flags;
74 local_irq_save(flags);
75
76 if (enable)
77 CKEN |= clock;
78 else
79 CKEN &= ~clock;
80
81 local_irq_restore(flags);
82}
83
84EXPORT_SYMBOL(pxa_set_cken);
85
86/*
87 * Intel PXA2xx internal register mapping.
88 *
89 * Note 1: not all PXA2xx variants implement all those addresses.
90 *
91 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
92 * and cache flush area.
93 */
94static struct map_desc standard_io_desc[] __initdata = {
95 /* virtual physical length type */
96 { 0xf2000000, 0x40000000, 0x02000000, MT_DEVICE }, /* Devs */
97 { 0xf4000000, 0x44000000, 0x00100000, MT_DEVICE }, /* LCD */
98 { 0xf6000000, 0x48000000, 0x00100000, MT_DEVICE }, /* Mem Ctl */
99 { 0xf8000000, 0x4c000000, 0x00100000, MT_DEVICE }, /* USB host */
100 { 0xfa000000, 0x50000000, 0x00100000, MT_DEVICE }, /* Camera */
101 { 0xfe000000, 0x58000000, 0x00100000, MT_DEVICE }, /* IMem ctl */
102 { 0xff000000, 0x00000000, 0x00100000, MT_DEVICE } /* UNCACHED_PHYS_0 */
103};
104
105void __init pxa_map_io(void)
106{
107 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
108 get_clk_frequency_khz(1);
109}
110
111
112static struct resource pxamci_resources[] = {
113 [0] = {
114 .start = 0x41100000,
115 .end = 0x41100fff,
116 .flags = IORESOURCE_MEM,
117 },
118 [1] = {
119 .start = IRQ_MMC,
120 .end = IRQ_MMC,
121 .flags = IORESOURCE_IRQ,
122 },
123};
124
125static u64 pxamci_dmamask = 0xffffffffUL;
126
127static struct platform_device pxamci_device = {
128 .name = "pxa2xx-mci",
129 .id = -1,
130 .dev = {
131 .dma_mask = &pxamci_dmamask,
132 .coherent_dma_mask = 0xffffffff,
133 },
134 .num_resources = ARRAY_SIZE(pxamci_resources),
135 .resource = pxamci_resources,
136};
137
138void __init pxa_set_mci_info(struct pxamci_platform_data *info)
139{
140 pxamci_device.dev.platform_data = info;
141}
142
143
144static struct pxa2xx_udc_mach_info pxa_udc_info;
145
146void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
147{
148 memcpy(&pxa_udc_info, info, sizeof *info);
149}
150
151static struct resource pxa2xx_udc_resources[] = {
152 [0] = {
153 .start = 0x40600000,
154 .end = 0x4060ffff,
155 .flags = IORESOURCE_MEM,
156 },
157 [1] = {
158 .start = IRQ_USB,
159 .end = IRQ_USB,
160 .flags = IORESOURCE_IRQ,
161 },
162};
163
164static u64 udc_dma_mask = ~(u32)0;
165
166static struct platform_device udc_device = {
167 .name = "pxa2xx-udc",
168 .id = -1,
169 .resource = pxa2xx_udc_resources,
170 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
171 .dev = {
172 .platform_data = &pxa_udc_info,
173 .dma_mask = &udc_dma_mask,
174 }
175};
176
177static struct pxafb_mach_info pxa_fb_info;
178
179void __init set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info)
180{
181 memcpy(&pxa_fb_info,hard_pxa_fb_info,sizeof(struct pxafb_mach_info));
182}
183
184static struct resource pxafb_resources[] = {
185 [0] = {
186 .start = 0x44000000,
187 .end = 0x4400ffff,
188 .flags = IORESOURCE_MEM,
189 },
190 [1] = {
191 .start = IRQ_LCD,
192 .end = IRQ_LCD,
193 .flags = IORESOURCE_IRQ,
194 },
195};
196
197static u64 fb_dma_mask = ~(u64)0;
198
199static struct platform_device pxafb_device = {
200 .name = "pxa2xx-fb",
201 .id = -1,
202 .dev = {
203 .platform_data = &pxa_fb_info,
204 .dma_mask = &fb_dma_mask,
205 .coherent_dma_mask = 0xffffffff,
206 },
207 .num_resources = ARRAY_SIZE(pxafb_resources),
208 .resource = pxafb_resources,
209};
210
Richard Purdiecb38c562005-10-14 16:07:25 +0100211void __init set_pxa_fb_parent(struct device *parent_dev)
212{
213 pxafb_device.dev.parent = parent_dev;
214}
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216static struct platform_device ffuart_device = {
217 .name = "pxa2xx-uart",
218 .id = 0,
219};
220static struct platform_device btuart_device = {
221 .name = "pxa2xx-uart",
222 .id = 1,
223};
224static struct platform_device stuart_device = {
225 .name = "pxa2xx-uart",
226 .id = 2,
227};
228
Russell Kingbb9bffc2005-04-30 13:26:06 +0100229static struct resource i2c_resources[] = {
230 {
231 .start = 0x40301680,
232 .end = 0x403016a3,
233 .flags = IORESOURCE_MEM,
234 }, {
235 .start = IRQ_I2C,
236 .end = IRQ_I2C,
237 .flags = IORESOURCE_IRQ,
238 },
239};
240
241static struct platform_device i2c_device = {
242 .name = "pxa2xx-i2c",
243 .id = 0,
244 .resource = i2c_resources,
245 .num_resources = ARRAY_SIZE(i2c_resources),
246};
247
248void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
249{
250 i2c_device.dev.platform_data = info;
251}
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253static struct platform_device *devices[] __initdata = {
254 &pxamci_device,
255 &udc_device,
256 &pxafb_device,
257 &ffuart_device,
258 &btuart_device,
259 &stuart_device,
Russell Kingbb9bffc2005-04-30 13:26:06 +0100260 &i2c_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261};
262
263static int __init pxa_init(void)
264{
265 return platform_add_devices(devices, ARRAY_SIZE(devices));
266}
267
268subsys_initcall(pxa_init);