ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.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
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
35 #include "generic.h"
36
37 /*
38  * Various clock factors driven by the CCCR register.
39  */
40
41 /* Crystal Frequency to Memory Frequency Multiplier (L) */
42 static unsigned char L_clk_mult[32] = { 0, 27, 32, 36, 40, 45, 0, };
43
44 /* Memory Frequency to Run Mode Frequency Multiplier (M) */
45 static unsigned char M_clk_mult[4] = { 0, 1, 2, 4 };
46
47 /* Run Mode Frequency to Turbo Mode Frequency Multiplier (N) */
48 /* Note: we store the value N * 2 here. */
49 static unsigned char N2_clk_mult[8] = { 0, 0, 2, 3, 4, 0, 6, 0 };
50
51 /* Crystal clock */
52 #define BASE_CLK        3686400
53
54 /*
55  * Get the clock frequency as reflected by CCCR and the turbo flag.
56  * We assume these values have been applied via a fcs.
57  * If info is not 0 we also display the current settings.
58  */
59 unsigned int get_clk_frequency_khz(int info)
60 {
61         unsigned long cccr, turbo;
62         unsigned int l, L, m, M, n2, N;
63
64         cccr = CCCR;
65         asm( "mrc\tp14, 0, %0, c6, c0, 0" : "=r" (turbo) );
66
67         l  =  L_clk_mult[(cccr >> 0) & 0x1f];
68         m  =  M_clk_mult[(cccr >> 5) & 0x03];
69         n2 = N2_clk_mult[(cccr >> 7) & 0x07];
70
71         L = l * BASE_CLK;
72         M = m * L;
73         N = n2 * M / 2;
74
75         if(info)
76         {
77                 L += 5000;
78                 printk( KERN_INFO "Memory clock: %d.%02dMHz (*%d)\n",
79                         L / 1000000, (L % 1000000) / 10000, l );
80                 M += 5000;
81                 printk( KERN_INFO "Run Mode clock: %d.%02dMHz (*%d)\n",
82                         M / 1000000, (M % 1000000) / 10000, m );
83                 N += 5000;
84                 printk( KERN_INFO "Turbo Mode clock: %d.%02dMHz (*%d.%d, %sactive)\n",
85                         N / 1000000, (N % 1000000) / 10000, n2 / 2, (n2 % 2) * 5,
86                         (turbo & 1) ? "" : "in" );
87         }
88
89         return (turbo & 1) ? (N/1000) : (M/1000);
90 }
91
92 EXPORT_SYMBOL(get_clk_frequency_khz);
93
94 /*
95  * Return the current lclk requency in units of 10kHz
96  */
97 unsigned int get_lclk_frequency_10khz(void)
98 {
99         return L_clk_mult[(CCCR >> 0) & 0x1f] * BASE_CLK / 10000;
100 }
101
102 EXPORT_SYMBOL(get_lclk_frequency_10khz);
103
104 /*
105  * Handy function to set GPIO alternate functions
106  */
107
108 void pxa_gpio_mode(int gpio_mode)
109 {
110         unsigned long flags;
111         int gpio = gpio_mode & GPIO_MD_MASK_NR;
112         int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
113         int gafr;
114
115         local_irq_save(flags);
116         if (gpio_mode & GPIO_MD_MASK_DIR)
117                 GPDR(gpio) |= GPIO_bit(gpio);
118         else
119                 GPDR(gpio) &= ~GPIO_bit(gpio);
120         gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
121         GAFR(gpio) = gafr |  (fn  << (((gpio) & 0xf)*2));
122         local_irq_restore(flags);
123 }
124
125 EXPORT_SYMBOL(pxa_gpio_mode);
126
127 /*
128  * Note that 0xfffe0000-0xffffffff is reserved for the vector table and
129  * cache flush area.
130  */
131 static struct map_desc standard_io_desc[] __initdata = {
132  /* virtual     physical    length      type */
133   { 0xf6000000, 0x20000000, 0x01000000, MT_DEVICE }, /* PCMCIA0 IO */
134   { 0xf7000000, 0x30000000, 0x01000000, MT_DEVICE }, /* PCMCIA1 IO */
135   { 0xf8000000, 0x40000000, 0x01400000, MT_DEVICE }, /* Devs */
136   { 0xfa000000, 0x44000000, 0x00100000, MT_DEVICE }, /* LCD */
137   { 0xfc000000, 0x48000000, 0x00100000, MT_DEVICE }, /* Mem Ctl */
138   { 0xff000000, 0x00000000, 0x00100000, MT_DEVICE }  /* UNCACHED_PHYS_0 */
139 };
140
141 void __init pxa_map_io(void)
142 {
143         iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
144         get_clk_frequency_khz(1);
145 }
146
147
148 static struct resource pxamci_resources[] = {
149         [0] = {
150                 .start  = 0x41100000,
151                 .end    = 0x41100fff,
152                 .flags  = IORESOURCE_MEM,
153         },
154         [1] = {
155                 .start  = IRQ_MMC,
156                 .end    = IRQ_MMC,
157                 .flags  = IORESOURCE_IRQ,
158         },
159 };
160
161 static u64 pxamci_dmamask = 0xffffffffUL;
162
163 static struct platform_device pxamci_device = {
164         .name           = "pxamci",
165         .id             = 0,
166         .dev            = {
167                 .dma_mask = &pxamci_dmamask,
168         },
169         .num_resources  = ARRAY_SIZE(pxamci_resources),
170         .resource       = pxamci_resources,
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 EXPORT_SYMBOL(pxa_set_udc_info);
181
182 static struct resource pxa2xx_udc_resources[] = {
183         [0] = {
184                 .start  = 0x40600000,
185                 .end    = 0x4060ffff,
186                 .flags  = IORESOURCE_MEM,
187         },
188         [1] = {
189                 .start  = IRQ_USB,
190                 .end    = IRQ_USB,
191                 .flags  = IORESOURCE_IRQ,
192         },
193 };
194
195 static u64 udc_dma_mask = ~(u32)0;
196
197 static struct platform_device udc_device = {
198         .name           = "pxa2xx_udc",
199         .id             = 0,
200         .resource       = pxa2xx_udc_resources,
201         .num_resources  = ARRAY_SIZE(pxa2xx_udc_resources),
202         .dev            =  {
203                 .platform_data  = &pxa_udc_info,
204                 .dma_mask       = &udc_dma_mask,
205         }
206 };
207
208 static struct platform_device *devices[] __initdata = {
209         &pxamci_device,
210         &udc_device,
211 };
212
213 static int __init pxa_init(void)
214 {
215         return platform_add_devices(devices, ARRAY_SIZE(devices));
216 }
217
218 subsys_initcall(pxa_init);