2 * linux/arch/arm/mach-pxa/generic.c
4 * Author: Nicolas Pitre
5 * Created: Jun 15, 2001
6 * Copyright: MontaVista Software Inc.
8 * Code common to all PXA machines.
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.
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
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/delay.h>
23 #include <linux/platform_device.h>
24 #include <linux/ioport.h>
26 #include <linux/string.h>
28 #include <linux/sched.h>
29 #include <asm/cnt32_to_63.h>
30 #include <asm/div64.h>
32 #include <asm/hardware.h>
34 #include <asm/system.h>
35 #include <asm/pgtable.h>
36 #include <asm/mach/map.h>
38 #include <asm/arch/pxa-regs.h>
39 #include <asm/arch/gpio.h>
40 #include <asm/arch/udc.h>
41 #include <asm/arch/pxafb.h>
42 #include <asm/arch/mmc.h>
43 #include <asm/arch/irda.h>
44 #include <asm/arch/i2c.h>
50 * This is the PXA2xx sched_clock implementation. This has a resolution
51 * of at least 308ns and a maximum value that depends on the value of
54 * The return value is guaranteed to be monotonic in that range as
55 * long as there is always less than 582 seconds between successive
56 * calls to this function.
58 unsigned long long sched_clock(void)
60 unsigned long long v = cnt32_to_63(OSCR);
61 /* Note: top bit ov v needs cleared unless multiplier is even. */
63 #if CLOCK_TICK_RATE == 3686400
64 /* 1E9 / 3686400 => 78125 / 288, max value = 32025597s (370 days). */
65 /* The <<1 is used to get rid of tick.hi top bit */
68 #elif CLOCK_TICK_RATE == 3250000
69 /* 1E9 / 3250000 => 4000 / 13, max value = 709490156s (8211 days) */
72 #elif CLOCK_TICK_RATE == 3249600
73 /* 1E9 / 3249600 => 625000 / 2031, max value = 4541295s (52 days) */
77 #warning "consider fixing sched_clock for your value of CLOCK_TICK_RATE"
79 * 96-bit math to perform tick * NSEC_PER_SEC / CLOCK_TICK_RATE for
80 * any value of CLOCK_TICK_RATE. Max value is in the 80 thousand
81 * years range and truncation to unsigned long long limits it to
82 * sched_clock's max range of ~584 years. This is nice but with
83 * higher computation cost.
87 unsigned long long val;
88 struct { unsigned long lo, hi; };
94 y = (unsigned long long)x.lo * NSEC_PER_SEC;
96 y = (y >> 32) + (unsigned long long)x.hi * NSEC_PER_SEC;
97 x.hi = do_div(y, CLOCK_TICK_RATE);
98 do_div(x.val, CLOCK_TICK_RATE);
108 * Handy function to set GPIO alternate functions
111 int pxa_gpio_mode(int gpio_mode)
114 int gpio = gpio_mode & GPIO_MD_MASK_NR;
115 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
118 if (gpio > PXA_LAST_GPIO)
121 local_irq_save(flags);
122 if (gpio_mode & GPIO_DFLT_LOW)
123 GPCR(gpio) = GPIO_bit(gpio);
124 else if (gpio_mode & GPIO_DFLT_HIGH)
125 GPSR(gpio) = GPIO_bit(gpio);
126 if (gpio_mode & GPIO_MD_MASK_DIR)
127 GPDR(gpio) |= GPIO_bit(gpio);
129 GPDR(gpio) &= ~GPIO_bit(gpio);
130 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
131 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
132 local_irq_restore(flags);
137 EXPORT_SYMBOL(pxa_gpio_mode);
142 int pxa_gpio_get_value(unsigned gpio)
144 return __gpio_get_value(gpio);
147 EXPORT_SYMBOL(pxa_gpio_get_value);
150 * Set output GPIO level
152 void pxa_gpio_set_value(unsigned gpio, int value)
154 __gpio_set_value(gpio, value);
157 EXPORT_SYMBOL(pxa_gpio_set_value);
160 * Routine to safely enable or disable a clock in the CKEN
162 void pxa_set_cken(int clock, int enable)
165 local_irq_save(flags);
168 CKEN |= (1 << clock);
170 CKEN &= ~(1 << clock);
172 local_irq_restore(flags);
175 EXPORT_SYMBOL(pxa_set_cken);
178 * Intel PXA2xx internal register mapping.
180 * Note 1: not all PXA2xx variants implement all those addresses.
182 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
183 * and cache flush area.
185 static struct map_desc standard_io_desc[] __initdata = {
187 .virtual = 0xf2000000,
188 .pfn = __phys_to_pfn(0x40000000),
189 .length = 0x02000000,
192 .virtual = 0xf4000000,
193 .pfn = __phys_to_pfn(0x44000000),
194 .length = 0x00100000,
197 .virtual = 0xf6000000,
198 .pfn = __phys_to_pfn(0x48000000),
199 .length = 0x00100000,
202 .virtual = 0xf8000000,
203 .pfn = __phys_to_pfn(0x4c000000),
204 .length = 0x00100000,
207 .virtual = 0xfa000000,
208 .pfn = __phys_to_pfn(0x50000000),
209 .length = 0x00100000,
212 .virtual = 0xfe000000,
213 .pfn = __phys_to_pfn(0x58000000),
214 .length = 0x00100000,
216 }, { /* UNCACHED_PHYS_0 */
217 .virtual = 0xff000000,
218 .pfn = __phys_to_pfn(0x00000000),
219 .length = 0x00100000,
224 void __init pxa_map_io(void)
226 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
227 get_clk_frequency_khz(1);
231 static struct resource pxamci_resources[] = {
235 .flags = IORESOURCE_MEM,
240 .flags = IORESOURCE_IRQ,
244 static u64 pxamci_dmamask = 0xffffffffUL;
246 struct platform_device pxa_device_mci = {
247 .name = "pxa2xx-mci",
250 .dma_mask = &pxamci_dmamask,
251 .coherent_dma_mask = 0xffffffff,
253 .num_resources = ARRAY_SIZE(pxamci_resources),
254 .resource = pxamci_resources,
257 void __init pxa_set_mci_info(struct pxamci_platform_data *info)
259 pxa_device_mci.dev.platform_data = info;
263 static struct pxa2xx_udc_mach_info pxa_udc_info;
265 void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
267 memcpy(&pxa_udc_info, info, sizeof *info);
270 static struct resource pxa2xx_udc_resources[] = {
274 .flags = IORESOURCE_MEM,
279 .flags = IORESOURCE_IRQ,
283 static u64 udc_dma_mask = ~(u32)0;
285 struct platform_device pxa_device_udc = {
286 .name = "pxa2xx-udc",
288 .resource = pxa2xx_udc_resources,
289 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
291 .platform_data = &pxa_udc_info,
292 .dma_mask = &udc_dma_mask,
296 static struct resource pxafb_resources[] = {
300 .flags = IORESOURCE_MEM,
305 .flags = IORESOURCE_IRQ,
309 static u64 fb_dma_mask = ~(u64)0;
311 struct platform_device pxa_device_fb = {
315 .dma_mask = &fb_dma_mask,
316 .coherent_dma_mask = 0xffffffff,
318 .num_resources = ARRAY_SIZE(pxafb_resources),
319 .resource = pxafb_resources,
322 void __init set_pxa_fb_info(struct pxafb_mach_info *info)
324 pxa_device_fb.dev.platform_data = info;
327 void __init set_pxa_fb_parent(struct device *parent_dev)
329 pxa_device_fb.dev.parent = parent_dev;
332 struct platform_device pxa_device_ffuart= {
333 .name = "pxa2xx-uart",
336 struct platform_device pxa_device_btuart = {
337 .name = "pxa2xx-uart",
340 struct platform_device pxa_device_stuart = {
341 .name = "pxa2xx-uart",
344 struct platform_device pxa_device_hwuart = {
345 .name = "pxa2xx-uart",
349 static struct resource pxai2c_resources[] = {
353 .flags = IORESOURCE_MEM,
357 .flags = IORESOURCE_IRQ,
361 struct platform_device pxa_device_i2c = {
362 .name = "pxa2xx-i2c",
364 .resource = pxai2c_resources,
365 .num_resources = ARRAY_SIZE(pxai2c_resources),
368 void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
370 pxa_device_i2c.dev.platform_data = info;
373 static struct resource pxai2s_resources[] = {
377 .flags = IORESOURCE_MEM,
381 .flags = IORESOURCE_IRQ,
385 struct platform_device pxa_device_i2s = {
386 .name = "pxa2xx-i2s",
388 .resource = pxai2s_resources,
389 .num_resources = ARRAY_SIZE(pxai2s_resources),
392 static u64 pxaficp_dmamask = ~(u32)0;
394 struct platform_device pxa_device_ficp = {
398 .dma_mask = &pxaficp_dmamask,
399 .coherent_dma_mask = 0xffffffff,
403 void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
405 pxa_device_ficp.dev.platform_data = info;
408 struct platform_device pxa_device_rtc = {
409 .name = "sa1100-rtc",