2 * arch/arm/mach-imx/generic.c
5 * Created: april 20th, 2004
6 * Copyright: Synertronixx GmbH
8 * Common code for i.MX 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 as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
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.
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
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>
31 #include <asm/arch/imxfb.h>
32 #include <asm/hardware.h>
33 #include <asm/arch/imx-regs.h>
35 #include <asm/mach/map.h>
36 #include <asm/arch/mmc.h>
38 void imx_gpio_mode(int gpio_mode)
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;
46 if(gpio_mode & GPIO_PUEN)
47 PUEN(port) |= (1<<pin);
49 PUEN(port) &= ~(1<<pin);
52 if(gpio_mode & GPIO_OUT)
55 DDIR(port) &= ~(1<<pin);
57 /* Primary / alternate function */
58 if(gpio_mode & GPIO_AF)
59 GPR(port) |= (1<<pin);
61 GPR(port) &= ~(1<<pin);
64 if(gpio_mode & GPIO_GIUS)
65 GIUS(port) |= (1<<pin);
67 GIUS(port) &= ~(1<<pin);
69 /* Output / input configuration */
70 /* FIXME: I'm not very sure about OCR and ICONF, someone
71 * should have a look over it
75 tmp &= ~( 3<<(pin*2));
76 tmp |= (ocr << (pin*2));
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);
85 tmp &= ~( 3<<((pin-16)*2));
86 tmp |= (ocr << ((pin-16)*2));
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);
96 EXPORT_SYMBOL(imx_gpio_mode);
99 * get the system pll clock in Hz
101 * mfi + mfn / (mfd +1)
102 * f = 2 * f_ref * --------------------
105 static unsigned int imx_decode_pll(unsigned int pll, u32 f_ref)
107 unsigned long long ll;
110 u32 mfi = (pll >> 10) & 0xf;
111 u32 mfn = pll & 0x3ff;
112 u32 mfd = (pll >> 16) & 0x3ff;
113 u32 pd = (pll >> 26) & 0xf;
115 mfi = mfi <= 5 ? 5 : mfi;
117 ll = 2 * (unsigned long long)f_ref * ( (mfi<<16) + (mfn<<16) / (mfd+1) );
118 quot = (pd+1) * (1<<16);
121 return (unsigned int) ll;
124 unsigned int imx_get_system_clk(void)
126 u32 f_ref = (CSCR & CSCR_SYSTEM_SEL) ? 16000000 : (CLK32 * 512);
128 return imx_decode_pll(SPCTL0, f_ref);
130 EXPORT_SYMBOL(imx_get_system_clk);
132 unsigned int imx_get_mcu_clk(void)
134 return imx_decode_pll(MPCTL0, CLK32 * 512);
136 EXPORT_SYMBOL(imx_get_mcu_clk);
139 * get peripheral clock 1 ( UART[12], Timer[12], PWM )
141 unsigned int imx_get_perclk1(void)
143 return imx_get_system_clk() / (((PCDR) & 0xf)+1);
145 EXPORT_SYMBOL(imx_get_perclk1);
148 * get peripheral clock 2 ( LCD, SD, SPI[12] )
150 unsigned int imx_get_perclk2(void)
152 return imx_get_system_clk() / (((PCDR>>4) & 0xf)+1);
154 EXPORT_SYMBOL(imx_get_perclk2);
157 * get peripheral clock 3 ( SSI )
159 unsigned int imx_get_perclk3(void)
161 return imx_get_system_clk() / (((PCDR>>16) & 0x7f)+1);
163 EXPORT_SYMBOL(imx_get_perclk3);
166 * get hclk ( SDRAM, CSI, Memory Stick, I2C, DMA )
168 unsigned int imx_get_hclk(void)
170 return imx_get_system_clk() / (((CSCR>>10) & 0xf)+1);
172 EXPORT_SYMBOL(imx_get_hclk);
174 static struct resource imx_mmc_resources[] = {
178 .flags = IORESOURCE_MEM,
183 .flags = IORESOURCE_IRQ,
187 static u64 imxmmmc_dmamask = 0xffffffffUL;
189 static struct platform_device imx_mmc_device = {
193 .dma_mask = &imxmmmc_dmamask,
194 .coherent_dma_mask = 0xffffffff,
196 .num_resources = ARRAY_SIZE(imx_mmc_resources),
197 .resource = imx_mmc_resources,
200 void __init imx_set_mmc_info(struct imxmmc_platform_data *info)
202 imx_mmc_device.dev.platform_data = info;
204 EXPORT_SYMBOL(imx_set_mmc_info);
206 static struct imxfb_mach_info imx_fb_info;
208 void __init set_imx_fb_info(struct imxfb_mach_info *hard_imx_fb_info)
210 memcpy(&imx_fb_info,hard_imx_fb_info,sizeof(struct imxfb_mach_info));
212 EXPORT_SYMBOL(set_imx_fb_info);
214 static struct resource imxfb_resources[] = {
218 .flags = IORESOURCE_MEM,
223 .flags = IORESOURCE_IRQ,
227 static u64 fb_dma_mask = ~(u64)0;
229 static struct platform_device imxfb_device = {
233 .platform_data = &imx_fb_info,
234 .dma_mask = &fb_dma_mask,
235 .coherent_dma_mask = 0xffffffff,
237 .num_resources = ARRAY_SIZE(imxfb_resources),
238 .resource = imxfb_resources,
241 static struct platform_device *devices[] __initdata = {
246 static struct map_desc imx_io_desc[] __initdata = {
248 .virtual = IMX_IO_BASE,
249 .pfn = __phys_to_pfn(IMX_IO_PHYS),
250 .length = IMX_IO_SIZE,
258 iotable_init(imx_io_desc, ARRAY_SIZE(imx_io_desc));
261 static int __init imx_init(void)
263 return platform_add_devices(devices, ARRAY_SIZE(devices));
266 subsys_initcall(imx_init);