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