Merge branch 'splice' of git://brick.kernel.dk/data/git/linux-2.6-block
[deliverable/linux.git] / arch / arm / mach-imx / generic.c
1 /*
2 * arch/arm/mach-imx/generic.c
3 *
4 * author: Sascha Hauer
5 * Created: april 20th, 2004
6 * Copyright: Synertronixx GmbH
7 *
8 * Common code for i.MX 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 as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25 #include <linux/platform_device.h>
26 #include <linux/init.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/string.h>
30
31 #include <asm/arch/imxfb.h>
32 #include <asm/hardware.h>
33 #include <asm/arch/imx-regs.h>
34
35 #include <asm/mach/map.h>
36 #include <asm/arch/mmc.h>
37
38 void imx_gpio_mode(int gpio_mode)
39 {
40 unsigned int pin = gpio_mode & GPIO_PIN_MASK;
41 unsigned int port = (gpio_mode & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT;
42 unsigned int ocr = (gpio_mode & GPIO_OCR_MASK) >> GPIO_OCR_SHIFT;
43 unsigned int tmp;
44
45 /* Pullup enable */
46 if(gpio_mode & GPIO_PUEN)
47 PUEN(port) |= (1<<pin);
48 else
49 PUEN(port) &= ~(1<<pin);
50
51 /* Data direction */
52 if(gpio_mode & GPIO_OUT)
53 DDIR(port) |= 1<<pin;
54 else
55 DDIR(port) &= ~(1<<pin);
56
57 /* Primary / alternate function */
58 if(gpio_mode & GPIO_AF)
59 GPR(port) |= (1<<pin);
60 else
61 GPR(port) &= ~(1<<pin);
62
63 /* use as gpio? */
64 if(gpio_mode & GPIO_GIUS)
65 GIUS(port) |= (1<<pin);
66 else
67 GIUS(port) &= ~(1<<pin);
68
69 /* Output / input configuration */
70 /* FIXME: I'm not very sure about OCR and ICONF, someone
71 * should have a look over it
72 */
73 if(pin<16) {
74 tmp = OCR1(port);
75 tmp &= ~( 3<<(pin*2));
76 tmp |= (ocr << (pin*2));
77 OCR1(port) = tmp;
78
79 ICONFA1(port) &= ~( 3<<(pin*2));
80 ICONFA1(port) |= ((gpio_mode >> GPIO_AOUT_SHIFT) & 3) << (pin * 2);
81 ICONFB1(port) &= ~( 3<<(pin*2));
82 ICONFB1(port) |= ((gpio_mode >> GPIO_BOUT_SHIFT) & 3) << (pin * 2);
83 } else {
84 tmp = OCR2(port);
85 tmp &= ~( 3<<((pin-16)*2));
86 tmp |= (ocr << ((pin-16)*2));
87 OCR2(port) = tmp;
88
89 ICONFA2(port) &= ~( 3<<((pin-16)*2));
90 ICONFA2(port) |= ((gpio_mode >> GPIO_AOUT_SHIFT) & 3) << ((pin-16) * 2);
91 ICONFB2(port) &= ~( 3<<((pin-16)*2));
92 ICONFB2(port) |= ((gpio_mode >> GPIO_BOUT_SHIFT) & 3) << ((pin-16) * 2);
93 }
94 }
95
96 EXPORT_SYMBOL(imx_gpio_mode);
97
98 /*
99 * get the system pll clock in Hz
100 *
101 * mfi + mfn / (mfd +1)
102 * f = 2 * f_ref * --------------------
103 * pd + 1
104 */
105 static unsigned int imx_decode_pll(unsigned int pll)
106 {
107 u32 mfi = (pll >> 10) & 0xf;
108 u32 mfn = pll & 0x3ff;
109 u32 mfd = (pll >> 16) & 0x3ff;
110 u32 pd = (pll >> 26) & 0xf;
111 u32 f_ref = (CSCR & CSCR_SYSTEM_SEL) ? 16000000 : (CLK32 * 512);
112
113 mfi = mfi <= 5 ? 5 : mfi;
114
115 return (2 * (f_ref>>10) * ( (mfi<<10) + (mfn<<10) / (mfd+1) )) / (pd+1);
116 }
117
118 unsigned int imx_get_system_clk(void)
119 {
120 return imx_decode_pll(SPCTL0);
121 }
122 EXPORT_SYMBOL(imx_get_system_clk);
123
124 unsigned int imx_get_mcu_clk(void)
125 {
126 return imx_decode_pll(MPCTL0);
127 }
128 EXPORT_SYMBOL(imx_get_mcu_clk);
129
130 /*
131 * get peripheral clock 1 ( UART[12], Timer[12], PWM )
132 */
133 unsigned int imx_get_perclk1(void)
134 {
135 return imx_get_system_clk() / (((PCDR) & 0xf)+1);
136 }
137 EXPORT_SYMBOL(imx_get_perclk1);
138
139 /*
140 * get peripheral clock 2 ( LCD, SD, SPI[12] )
141 */
142 unsigned int imx_get_perclk2(void)
143 {
144 return imx_get_system_clk() / (((PCDR>>4) & 0xf)+1);
145 }
146 EXPORT_SYMBOL(imx_get_perclk2);
147
148 /*
149 * get peripheral clock 3 ( SSI )
150 */
151 unsigned int imx_get_perclk3(void)
152 {
153 return imx_get_system_clk() / (((PCDR>>16) & 0x7f)+1);
154 }
155 EXPORT_SYMBOL(imx_get_perclk3);
156
157 /*
158 * get hclk ( SDRAM, CSI, Memory Stick, I2C, DMA )
159 */
160 unsigned int imx_get_hclk(void)
161 {
162 return imx_get_system_clk() / (((CSCR>>10) & 0xf)+1);
163 }
164 EXPORT_SYMBOL(imx_get_hclk);
165
166 static struct resource imx_mmc_resources[] = {
167 [0] = {
168 .start = 0x00214000,
169 .end = 0x002140FF,
170 .flags = IORESOURCE_MEM,
171 },
172 [1] = {
173 .start = (SDHC_INT),
174 .end = (SDHC_INT),
175 .flags = IORESOURCE_IRQ,
176 },
177 };
178
179 static u64 imxmmmc_dmamask = 0xffffffffUL;
180
181 static struct platform_device imx_mmc_device = {
182 .name = "imx-mmc",
183 .id = 0,
184 .dev = {
185 .dma_mask = &imxmmmc_dmamask,
186 .coherent_dma_mask = 0xffffffff,
187 },
188 .num_resources = ARRAY_SIZE(imx_mmc_resources),
189 .resource = imx_mmc_resources,
190 };
191
192 void __init imx_set_mmc_info(struct imxmmc_platform_data *info)
193 {
194 imx_mmc_device.dev.platform_data = info;
195 }
196 EXPORT_SYMBOL(imx_set_mmc_info);
197
198 static struct resource imx_uart1_resources[] = {
199 [0] = {
200 .start = 0x00206000,
201 .end = 0x002060FF,
202 .flags = IORESOURCE_MEM,
203 },
204 [1] = {
205 .start = (UART1_MINT_RX),
206 .end = (UART1_MINT_RX),
207 .flags = IORESOURCE_IRQ,
208 },
209 [2] = {
210 .start = (UART1_MINT_TX),
211 .end = (UART1_MINT_TX),
212 .flags = IORESOURCE_IRQ,
213 },
214 };
215
216 static struct platform_device imx_uart1_device = {
217 .name = "imx-uart",
218 .id = 0,
219 .num_resources = ARRAY_SIZE(imx_uart1_resources),
220 .resource = imx_uart1_resources,
221 };
222
223 static struct resource imx_uart2_resources[] = {
224 [0] = {
225 .start = 0x00207000,
226 .end = 0x002070FF,
227 .flags = IORESOURCE_MEM,
228 },
229 [1] = {
230 .start = (UART2_MINT_RX),
231 .end = (UART2_MINT_RX),
232 .flags = IORESOURCE_IRQ,
233 },
234 [2] = {
235 .start = (UART2_MINT_TX),
236 .end = (UART2_MINT_TX),
237 .flags = IORESOURCE_IRQ,
238 },
239 };
240
241 static struct platform_device imx_uart2_device = {
242 .name = "imx-uart",
243 .id = 1,
244 .num_resources = ARRAY_SIZE(imx_uart2_resources),
245 .resource = imx_uart2_resources,
246 };
247
248 static struct imxfb_mach_info imx_fb_info;
249
250 void __init set_imx_fb_info(struct imxfb_mach_info *hard_imx_fb_info)
251 {
252 memcpy(&imx_fb_info,hard_imx_fb_info,sizeof(struct imxfb_mach_info));
253 }
254 EXPORT_SYMBOL(set_imx_fb_info);
255
256 static struct resource imxfb_resources[] = {
257 [0] = {
258 .start = 0x00205000,
259 .end = 0x002050FF,
260 .flags = IORESOURCE_MEM,
261 },
262 [1] = {
263 .start = LCDC_INT,
264 .end = LCDC_INT,
265 .flags = IORESOURCE_IRQ,
266 },
267 };
268
269 static u64 fb_dma_mask = ~(u64)0;
270
271 static struct platform_device imxfb_device = {
272 .name = "imx-fb",
273 .id = 0,
274 .dev = {
275 .platform_data = &imx_fb_info,
276 .dma_mask = &fb_dma_mask,
277 .coherent_dma_mask = 0xffffffff,
278 },
279 .num_resources = ARRAY_SIZE(imxfb_resources),
280 .resource = imxfb_resources,
281 };
282
283 static struct platform_device *devices[] __initdata = {
284 &imx_mmc_device,
285 &imxfb_device,
286 &imx_uart1_device,
287 &imx_uart2_device,
288 };
289
290 static struct map_desc imx_io_desc[] __initdata = {
291 {
292 .virtual = IMX_IO_BASE,
293 .pfn = __phys_to_pfn(IMX_IO_PHYS),
294 .length = IMX_IO_SIZE,
295 .type = MT_DEVICE
296 }
297 };
298
299 void __init
300 imx_map_io(void)
301 {
302 iotable_init(imx_io_desc, ARRAY_SIZE(imx_io_desc));
303 }
304
305 static int __init imx_init(void)
306 {
307 return platform_add_devices(devices, ARRAY_SIZE(devices));
308 }
309
310 subsys_initcall(imx_init);
This page took 0.036839 seconds and 6 git commands to generate.