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/pxa-regs.h> 34 #include <asm/arch/udc.h> 35 #include <asm/arch/pxafb.h> 36 #include <asm/arch/mmc.h> 37 #include <asm/arch/i2c.h> 38 39 #include "generic.h" 40 41 /* 42 * Handy function to set GPIO alternate functions 43 */ 44 45 void pxa_gpio_mode(int gpio_mode) 46 { 47 unsigned long flags; 48 int gpio = gpio_mode & GPIO_MD_MASK_NR; 49 int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8; 50 int gafr; 51 52 local_irq_save(flags); 53 if (gpio_mode & GPIO_DFLT_LOW) 54 GPCR(gpio) = GPIO_bit(gpio); 55 else if (gpio_mode & GPIO_DFLT_HIGH) 56 GPSR(gpio) = GPIO_bit(gpio); 57 if (gpio_mode & GPIO_MD_MASK_DIR) 58 GPDR(gpio) |= GPIO_bit(gpio); 59 else 60 GPDR(gpio) &= ~GPIO_bit(gpio); 61 gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2)); 62 GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2)); 63 local_irq_restore(flags); 64 } 65 66 EXPORT_SYMBOL(pxa_gpio_mode); 67 68 /* 69 * Routine to safely enable or disable a clock in the CKEN 70 */ 71 void pxa_set_cken(int clock, int enable) 72 { 73 unsigned long flags; 74 local_irq_save(flags); 75 76 if (enable) 77 CKEN |= clock; 78 else 79 CKEN &= ~clock; 80 81 local_irq_restore(flags); 82 } 83 84 EXPORT_SYMBOL(pxa_set_cken); 85 86 /* 87 * Intel PXA2xx internal register mapping. 88 * 89 * Note 1: not all PXA2xx variants implement all those addresses. 90 * 91 * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table 92 * and cache flush area. 93 */ 94 static struct map_desc standard_io_desc[] __initdata = { 95 /* virtual physical length type */ 96 { 0xf2000000, 0x40000000, 0x02000000, MT_DEVICE }, /* Devs */ 97 { 0xf4000000, 0x44000000, 0x00100000, MT_DEVICE }, /* LCD */ 98 { 0xf6000000, 0x48000000, 0x00100000, MT_DEVICE }, /* Mem Ctl */ 99 { 0xf8000000, 0x4c000000, 0x00100000, MT_DEVICE }, /* USB host */ 100 { 0xfa000000, 0x50000000, 0x00100000, MT_DEVICE }, /* Camera */ 101 { 0xfe000000, 0x58000000, 0x00100000, MT_DEVICE }, /* IMem ctl */ 102 { 0xff000000, 0x00000000, 0x00100000, MT_DEVICE } /* UNCACHED_PHYS_0 */ 103 }; 104 105 void __init pxa_map_io(void) 106 { 107 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc)); 108 get_clk_frequency_khz(1); 109 } 110 111 112 static struct resource pxamci_resources[] = { 113 [0] = { 114 .start = 0x41100000, 115 .end = 0x41100fff, 116 .flags = IORESOURCE_MEM, 117 }, 118 [1] = { 119 .start = IRQ_MMC, 120 .end = IRQ_MMC, 121 .flags = IORESOURCE_IRQ, 122 }, 123 }; 124 125 static u64 pxamci_dmamask = 0xffffffffUL; 126 127 static struct platform_device pxamci_device = { 128 .name = "pxa2xx-mci", 129 .id = -1, 130 .dev = { 131 .dma_mask = &pxamci_dmamask, 132 .coherent_dma_mask = 0xffffffff, 133 }, 134 .num_resources = ARRAY_SIZE(pxamci_resources), 135 .resource = pxamci_resources, 136 }; 137 138 void __init pxa_set_mci_info(struct pxamci_platform_data *info) 139 { 140 pxamci_device.dev.platform_data = info; 141 } 142 143 144 static struct pxa2xx_udc_mach_info pxa_udc_info; 145 146 void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info) 147 { 148 memcpy(&pxa_udc_info, info, sizeof *info); 149 } 150 151 static struct resource pxa2xx_udc_resources[] = { 152 [0] = { 153 .start = 0x40600000, 154 .end = 0x4060ffff, 155 .flags = IORESOURCE_MEM, 156 }, 157 [1] = { 158 .start = IRQ_USB, 159 .end = IRQ_USB, 160 .flags = IORESOURCE_IRQ, 161 }, 162 }; 163 164 static u64 udc_dma_mask = ~(u32)0; 165 166 static struct platform_device udc_device = { 167 .name = "pxa2xx-udc", 168 .id = -1, 169 .resource = pxa2xx_udc_resources, 170 .num_resources = ARRAY_SIZE(pxa2xx_udc_resources), 171 .dev = { 172 .platform_data = &pxa_udc_info, 173 .dma_mask = &udc_dma_mask, 174 } 175 }; 176 177 static struct pxafb_mach_info pxa_fb_info; 178 179 void __init set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info) 180 { 181 memcpy(&pxa_fb_info,hard_pxa_fb_info,sizeof(struct pxafb_mach_info)); 182 } 183 184 static struct resource pxafb_resources[] = { 185 [0] = { 186 .start = 0x44000000, 187 .end = 0x4400ffff, 188 .flags = IORESOURCE_MEM, 189 }, 190 [1] = { 191 .start = IRQ_LCD, 192 .end = IRQ_LCD, 193 .flags = IORESOURCE_IRQ, 194 }, 195 }; 196 197 static u64 fb_dma_mask = ~(u64)0; 198 199 static struct platform_device pxafb_device = { 200 .name = "pxa2xx-fb", 201 .id = -1, 202 .dev = { 203 .platform_data = &pxa_fb_info, 204 .dma_mask = &fb_dma_mask, 205 .coherent_dma_mask = 0xffffffff, 206 }, 207 .num_resources = ARRAY_SIZE(pxafb_resources), 208 .resource = pxafb_resources, 209 }; 210 211 static struct platform_device ffuart_device = { 212 .name = "pxa2xx-uart", 213 .id = 0, 214 }; 215 static struct platform_device btuart_device = { 216 .name = "pxa2xx-uart", 217 .id = 1, 218 }; 219 static struct platform_device stuart_device = { 220 .name = "pxa2xx-uart", 221 .id = 2, 222 }; 223 224 static struct resource i2c_resources[] = { 225 { 226 .start = 0x40301680, 227 .end = 0x403016a3, 228 .flags = IORESOURCE_MEM, 229 }, { 230 .start = IRQ_I2C, 231 .end = IRQ_I2C, 232 .flags = IORESOURCE_IRQ, 233 }, 234 }; 235 236 static struct platform_device i2c_device = { 237 .name = "pxa2xx-i2c", 238 .id = 0, 239 .resource = i2c_resources, 240 .num_resources = ARRAY_SIZE(i2c_resources), 241 }; 242 243 void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info) 244 { 245 i2c_device.dev.platform_data = info; 246 } 247 248 static struct platform_device *devices[] __initdata = { 249 &pxamci_device, 250 &udc_device, 251 &pxafb_device, 252 &ffuart_device, 253 &btuart_device, 254 &stuart_device, 255 &i2c_device, 256 }; 257 258 static int __init pxa_init(void) 259 { 260 return platform_add_devices(devices, ARRAY_SIZE(devices)); 261 } 262 263 subsys_initcall(pxa_init); 264