Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/device.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
Sascha Hauer | a493820 | 2005-05-03 22:57:56 +0100 | [diff] [blame] | 29 | #include <asm/arch/imxfb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/hardware.h> |
Sascha Hauer | 0a5b0aa | 2005-10-04 23:17:52 +0100 | [diff] [blame] | 31 | #include <asm/arch/imx-regs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | #include <asm/mach/map.h> |
| 34 | |
| 35 | void imx_gpio_mode(int gpio_mode) |
| 36 | { |
| 37 | unsigned int pin = gpio_mode & GPIO_PIN_MASK; |
Sascha Hauer | 0a5b0aa | 2005-10-04 23:17:52 +0100 | [diff] [blame] | 38 | unsigned int port = (gpio_mode & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT; |
| 39 | unsigned int ocr = (gpio_mode & GPIO_OCR_MASK) >> GPIO_OCR_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | unsigned int tmp; |
| 41 | |
| 42 | /* Pullup enable */ |
| 43 | if(gpio_mode & GPIO_PUEN) |
| 44 | PUEN(port) |= (1<<pin); |
| 45 | else |
| 46 | PUEN(port) &= ~(1<<pin); |
| 47 | |
| 48 | /* Data direction */ |
| 49 | if(gpio_mode & GPIO_OUT) |
| 50 | DDIR(port) |= 1<<pin; |
| 51 | else |
| 52 | DDIR(port) &= ~(1<<pin); |
| 53 | |
| 54 | /* Primary / alternate function */ |
| 55 | if(gpio_mode & GPIO_AF) |
| 56 | GPR(port) |= (1<<pin); |
| 57 | else |
| 58 | GPR(port) &= ~(1<<pin); |
| 59 | |
| 60 | /* use as gpio? */ |
Sascha Hauer | 0a5b0aa | 2005-10-04 23:17:52 +0100 | [diff] [blame] | 61 | if(gpio_mode & GPIO_GIUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | GIUS(port) |= (1<<pin); |
| 63 | else |
| 64 | GIUS(port) &= ~(1<<pin); |
| 65 | |
| 66 | /* Output / input configuration */ |
| 67 | /* FIXME: I'm not very sure about OCR and ICONF, someone |
| 68 | * should have a look over it |
| 69 | */ |
| 70 | if(pin<16) { |
| 71 | tmp = OCR1(port); |
| 72 | tmp &= ~( 3<<(pin*2)); |
| 73 | tmp |= (ocr << (pin*2)); |
| 74 | OCR1(port) = tmp; |
| 75 | |
Sascha Hauer | 0a5b0aa | 2005-10-04 23:17:52 +0100 | [diff] [blame] | 76 | ICONFA1(port) &= ~( 3<<(pin*2)); |
| 77 | ICONFA1(port) |= ((gpio_mode >> GPIO_AOUT_SHIFT) & 3) << (pin * 2); |
| 78 | ICONFB1(port) &= ~( 3<<(pin*2)); |
| 79 | ICONFB1(port) |= ((gpio_mode >> GPIO_BOUT_SHIFT) & 3) << (pin * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } else { |
| 81 | tmp = OCR2(port); |
| 82 | tmp &= ~( 3<<((pin-16)*2)); |
| 83 | tmp |= (ocr << ((pin-16)*2)); |
| 84 | OCR2(port) = tmp; |
| 85 | |
Sascha Hauer | 0a5b0aa | 2005-10-04 23:17:52 +0100 | [diff] [blame] | 86 | ICONFA2(port) &= ~( 3<<((pin-16)*2)); |
| 87 | ICONFA2(port) |= ((gpio_mode >> GPIO_AOUT_SHIFT) & 3) << ((pin-16) * 2); |
| 88 | ICONFB2(port) &= ~( 3<<((pin-16)*2)); |
| 89 | ICONFB2(port) |= ((gpio_mode >> GPIO_BOUT_SHIFT) & 3) << ((pin-16) * 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
| 93 | EXPORT_SYMBOL(imx_gpio_mode); |
| 94 | |
| 95 | /* |
| 96 | * get the system pll clock in Hz |
| 97 | * |
| 98 | * mfi + mfn / (mfd +1) |
| 99 | * f = 2 * f_ref * -------------------- |
| 100 | * pd + 1 |
| 101 | */ |
| 102 | static unsigned int imx_decode_pll(unsigned int pll) |
| 103 | { |
| 104 | u32 mfi = (pll >> 10) & 0xf; |
| 105 | u32 mfn = pll & 0x3ff; |
| 106 | u32 mfd = (pll >> 16) & 0x3ff; |
| 107 | u32 pd = (pll >> 26) & 0xf; |
| 108 | u32 f_ref = (CSCR & CSCR_SYSTEM_SEL) ? 16000000 : (CLK32 * 512); |
| 109 | |
| 110 | mfi = mfi <= 5 ? 5 : mfi; |
| 111 | |
| 112 | return (2 * (f_ref>>10) * ( (mfi<<10) + (mfn<<10) / (mfd+1) )) / (pd+1); |
| 113 | } |
| 114 | |
| 115 | unsigned int imx_get_system_clk(void) |
| 116 | { |
| 117 | return imx_decode_pll(SPCTL0); |
| 118 | } |
| 119 | EXPORT_SYMBOL(imx_get_system_clk); |
| 120 | |
| 121 | unsigned int imx_get_mcu_clk(void) |
| 122 | { |
| 123 | return imx_decode_pll(MPCTL0); |
| 124 | } |
| 125 | EXPORT_SYMBOL(imx_get_mcu_clk); |
| 126 | |
| 127 | /* |
| 128 | * get peripheral clock 1 ( UART[12], Timer[12], PWM ) |
| 129 | */ |
| 130 | unsigned int imx_get_perclk1(void) |
| 131 | { |
| 132 | return imx_get_system_clk() / (((PCDR) & 0xf)+1); |
| 133 | } |
| 134 | EXPORT_SYMBOL(imx_get_perclk1); |
| 135 | |
| 136 | /* |
| 137 | * get peripheral clock 2 ( LCD, SD, SPI[12] ) |
| 138 | */ |
| 139 | unsigned int imx_get_perclk2(void) |
| 140 | { |
| 141 | return imx_get_system_clk() / (((PCDR>>4) & 0xf)+1); |
| 142 | } |
| 143 | EXPORT_SYMBOL(imx_get_perclk2); |
| 144 | |
| 145 | /* |
| 146 | * get peripheral clock 3 ( SSI ) |
| 147 | */ |
| 148 | unsigned int imx_get_perclk3(void) |
| 149 | { |
| 150 | return imx_get_system_clk() / (((PCDR>>16) & 0x7f)+1); |
| 151 | } |
| 152 | EXPORT_SYMBOL(imx_get_perclk3); |
| 153 | |
| 154 | /* |
| 155 | * get hclk ( SDRAM, CSI, Memory Stick, I2C, DMA ) |
| 156 | */ |
| 157 | unsigned int imx_get_hclk(void) |
| 158 | { |
| 159 | return imx_get_system_clk() / (((CSCR>>10) & 0xf)+1); |
| 160 | } |
| 161 | EXPORT_SYMBOL(imx_get_hclk); |
| 162 | |
| 163 | static struct resource imx_mmc_resources[] = { |
| 164 | [0] = { |
| 165 | .start = 0x00214000, |
| 166 | .end = 0x002140FF, |
| 167 | .flags = IORESOURCE_MEM, |
| 168 | }, |
| 169 | [1] = { |
| 170 | .start = (SDHC_INT), |
| 171 | .end = (SDHC_INT), |
| 172 | .flags = IORESOURCE_IRQ, |
| 173 | }, |
| 174 | }; |
| 175 | |
| 176 | static struct platform_device imx_mmc_device = { |
| 177 | .name = "imx-mmc", |
| 178 | .id = 0, |
| 179 | .num_resources = ARRAY_SIZE(imx_mmc_resources), |
| 180 | .resource = imx_mmc_resources, |
| 181 | }; |
| 182 | |
| 183 | static struct resource imx_uart1_resources[] = { |
| 184 | [0] = { |
| 185 | .start = 0x00206000, |
| 186 | .end = 0x002060FF, |
| 187 | .flags = IORESOURCE_MEM, |
| 188 | }, |
| 189 | [1] = { |
| 190 | .start = (UART1_MINT_RX), |
| 191 | .end = (UART1_MINT_RX), |
| 192 | .flags = IORESOURCE_IRQ, |
| 193 | }, |
| 194 | [2] = { |
| 195 | .start = (UART1_MINT_TX), |
| 196 | .end = (UART1_MINT_TX), |
| 197 | .flags = IORESOURCE_IRQ, |
| 198 | }, |
| 199 | }; |
| 200 | |
| 201 | static struct platform_device imx_uart1_device = { |
| 202 | .name = "imx-uart", |
| 203 | .id = 0, |
| 204 | .num_resources = ARRAY_SIZE(imx_uart1_resources), |
| 205 | .resource = imx_uart1_resources, |
| 206 | }; |
| 207 | |
| 208 | static struct resource imx_uart2_resources[] = { |
| 209 | [0] = { |
| 210 | .start = 0x00207000, |
| 211 | .end = 0x002070FF, |
| 212 | .flags = IORESOURCE_MEM, |
| 213 | }, |
| 214 | [1] = { |
| 215 | .start = (UART2_MINT_RX), |
| 216 | .end = (UART2_MINT_RX), |
| 217 | .flags = IORESOURCE_IRQ, |
| 218 | }, |
| 219 | [2] = { |
| 220 | .start = (UART2_MINT_TX), |
| 221 | .end = (UART2_MINT_TX), |
| 222 | .flags = IORESOURCE_IRQ, |
| 223 | }, |
| 224 | }; |
| 225 | |
| 226 | static struct platform_device imx_uart2_device = { |
| 227 | .name = "imx-uart", |
| 228 | .id = 1, |
| 229 | .num_resources = ARRAY_SIZE(imx_uart2_resources), |
| 230 | .resource = imx_uart2_resources, |
| 231 | }; |
| 232 | |
Sascha Hauer | a493820 | 2005-05-03 22:57:56 +0100 | [diff] [blame] | 233 | static struct imxfb_mach_info imx_fb_info; |
| 234 | |
| 235 | void __init set_imx_fb_info(struct imxfb_mach_info *hard_imx_fb_info) |
| 236 | { |
| 237 | memcpy(&imx_fb_info,hard_imx_fb_info,sizeof(struct imxfb_mach_info)); |
| 238 | } |
| 239 | EXPORT_SYMBOL(set_imx_fb_info); |
| 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | static struct resource imxfb_resources[] = { |
| 242 | [0] = { |
| 243 | .start = 0x00205000, |
| 244 | .end = 0x002050FF, |
| 245 | .flags = IORESOURCE_MEM, |
| 246 | }, |
| 247 | [1] = { |
| 248 | .start = LCDC_INT, |
| 249 | .end = LCDC_INT, |
| 250 | .flags = IORESOURCE_IRQ, |
| 251 | }, |
| 252 | }; |
| 253 | |
Sascha Hauer | a493820 | 2005-05-03 22:57:56 +0100 | [diff] [blame] | 254 | static u64 fb_dma_mask = ~(u64)0; |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | static struct platform_device imxfb_device = { |
| 257 | .name = "imx-fb", |
| 258 | .id = 0, |
Sascha Hauer | a493820 | 2005-05-03 22:57:56 +0100 | [diff] [blame] | 259 | .dev = { |
| 260 | .platform_data = &imx_fb_info, |
| 261 | .dma_mask = &fb_dma_mask, |
| 262 | .coherent_dma_mask = 0xffffffff, |
| 263 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | .num_resources = ARRAY_SIZE(imxfb_resources), |
| 265 | .resource = imxfb_resources, |
| 266 | }; |
| 267 | |
| 268 | static struct platform_device *devices[] __initdata = { |
| 269 | &imx_mmc_device, |
| 270 | &imxfb_device, |
| 271 | &imx_uart1_device, |
| 272 | &imx_uart2_device, |
| 273 | }; |
| 274 | |
| 275 | static struct map_desc imx_io_desc[] __initdata = { |
Deepak Saxena | adecef7 | 2005-10-28 15:19:10 +0100 | [diff] [blame] | 276 | { |
| 277 | .virtual = IMX_IO_BASE, |
| 278 | .pfn = __phys_to_pfn(IMX_IO_PHYS), |
| 279 | .length = IMX_IO_SIZE, |
| 280 | .type = MT_DEVICE |
| 281 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | }; |
| 283 | |
| 284 | void __init |
| 285 | imx_map_io(void) |
| 286 | { |
| 287 | iotable_init(imx_io_desc, ARRAY_SIZE(imx_io_desc)); |
| 288 | } |
| 289 | |
| 290 | static int __init imx_init(void) |
| 291 | { |
| 292 | return platform_add_devices(devices, ARRAY_SIZE(devices)); |
| 293 | } |
| 294 | |
| 295 | subsys_initcall(imx_init); |