generic.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. #include <asm/hardware.h>
  27. #include <asm/irq.h>
  28. #include <asm/system.h>
  29. #include <asm/pgtable.h>
  30. #include <asm/mach/map.h>
  31. #include <asm/arch/pxa-regs.h>
  32. #include <asm/arch/udc.h>
  33. #include <asm/arch/pxafb.h>
  34. #include <asm/arch/mmc.h>
  35. #include <asm/arch/irda.h>
  36. #include <asm/arch/i2c.h>
  37. #include "generic.h"
  38. /*
  39. * Handy function to set GPIO alternate functions
  40. */
  41. void pxa_gpio_mode(int gpio_mode)
  42. {
  43. unsigned long flags;
  44. int gpio = gpio_mode & GPIO_MD_MASK_NR;
  45. int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
  46. int gafr;
  47. local_irq_save(flags);
  48. if (gpio_mode & GPIO_DFLT_LOW)
  49. GPCR(gpio) = GPIO_bit(gpio);
  50. else if (gpio_mode & GPIO_DFLT_HIGH)
  51. GPSR(gpio) = GPIO_bit(gpio);
  52. if (gpio_mode & GPIO_MD_MASK_DIR)
  53. GPDR(gpio) |= GPIO_bit(gpio);
  54. else
  55. GPDR(gpio) &= ~GPIO_bit(gpio);
  56. gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
  57. GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
  58. local_irq_restore(flags);
  59. }
  60. EXPORT_SYMBOL(pxa_gpio_mode);
  61. /*
  62. * Routine to safely enable or disable a clock in the CKEN
  63. */
  64. void pxa_set_cken(int clock, int enable)
  65. {
  66. unsigned long flags;
  67. local_irq_save(flags);
  68. if (enable)
  69. CKEN |= clock;
  70. else
  71. CKEN &= ~clock;
  72. local_irq_restore(flags);
  73. }
  74. EXPORT_SYMBOL(pxa_set_cken);
  75. /*
  76. * Intel PXA2xx internal register mapping.
  77. *
  78. * Note 1: not all PXA2xx variants implement all those addresses.
  79. *
  80. * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
  81. * and cache flush area.
  82. */
  83. static struct map_desc standard_io_desc[] __initdata = {
  84. { /* Devs */
  85. .virtual = 0xf2000000,
  86. .pfn = __phys_to_pfn(0x40000000),
  87. .length = 0x02000000,
  88. .type = MT_DEVICE
  89. }, { /* LCD */
  90. .virtual = 0xf4000000,
  91. .pfn = __phys_to_pfn(0x44000000),
  92. .length = 0x00100000,
  93. .type = MT_DEVICE
  94. }, { /* Mem Ctl */
  95. .virtual = 0xf6000000,
  96. .pfn = __phys_to_pfn(0x48000000),
  97. .length = 0x00100000,
  98. .type = MT_DEVICE
  99. }, { /* USB host */
  100. .virtual = 0xf8000000,
  101. .pfn = __phys_to_pfn(0x4c000000),
  102. .length = 0x00100000,
  103. .type = MT_DEVICE
  104. }, { /* Camera */
  105. .virtual = 0xfa000000,
  106. .pfn = __phys_to_pfn(0x50000000),
  107. .length = 0x00100000,
  108. .type = MT_DEVICE
  109. }, { /* IMem ctl */
  110. .virtual = 0xfe000000,
  111. .pfn = __phys_to_pfn(0x58000000),
  112. .length = 0x00100000,
  113. .type = MT_DEVICE
  114. }, { /* UNCACHED_PHYS_0 */
  115. .virtual = 0xff000000,
  116. .pfn = __phys_to_pfn(0x00000000),
  117. .length = 0x00100000,
  118. .type = MT_DEVICE
  119. }
  120. };
  121. void __init pxa_map_io(void)
  122. {
  123. iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
  124. get_clk_frequency_khz(1);
  125. }
  126. static struct resource pxamci_resources[] = {
  127. [0] = {
  128. .start = 0x41100000,
  129. .end = 0x41100fff,
  130. .flags = IORESOURCE_MEM,
  131. },
  132. [1] = {
  133. .start = IRQ_MMC,
  134. .end = IRQ_MMC,
  135. .flags = IORESOURCE_IRQ,
  136. },
  137. };
  138. static u64 pxamci_dmamask = 0xffffffffUL;
  139. static struct platform_device pxamci_device = {
  140. .name = "pxa2xx-mci",
  141. .id = -1,
  142. .dev = {
  143. .dma_mask = &pxamci_dmamask,
  144. .coherent_dma_mask = 0xffffffff,
  145. },
  146. .num_resources = ARRAY_SIZE(pxamci_resources),
  147. .resource = pxamci_resources,
  148. };
  149. void __init pxa_set_mci_info(struct pxamci_platform_data *info)
  150. {
  151. pxamci_device.dev.platform_data = info;
  152. }
  153. static struct pxa2xx_udc_mach_info pxa_udc_info;
  154. void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
  155. {
  156. memcpy(&pxa_udc_info, info, sizeof *info);
  157. }
  158. static struct resource pxa2xx_udc_resources[] = {
  159. [0] = {
  160. .start = 0x40600000,
  161. .end = 0x4060ffff,
  162. .flags = IORESOURCE_MEM,
  163. },
  164. [1] = {
  165. .start = IRQ_USB,
  166. .end = IRQ_USB,
  167. .flags = IORESOURCE_IRQ,
  168. },
  169. };
  170. static u64 udc_dma_mask = ~(u32)0;
  171. static struct platform_device udc_device = {
  172. .name = "pxa2xx-udc",
  173. .id = -1,
  174. .resource = pxa2xx_udc_resources,
  175. .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
  176. .dev = {
  177. .platform_data = &pxa_udc_info,
  178. .dma_mask = &udc_dma_mask,
  179. }
  180. };
  181. static struct pxafb_mach_info pxa_fb_info;
  182. void __init set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info)
  183. {
  184. memcpy(&pxa_fb_info,hard_pxa_fb_info,sizeof(struct pxafb_mach_info));
  185. }
  186. static struct resource pxafb_resources[] = {
  187. [0] = {
  188. .start = 0x44000000,
  189. .end = 0x4400ffff,
  190. .flags = IORESOURCE_MEM,
  191. },
  192. [1] = {
  193. .start = IRQ_LCD,
  194. .end = IRQ_LCD,
  195. .flags = IORESOURCE_IRQ,
  196. },
  197. };
  198. static u64 fb_dma_mask = ~(u64)0;
  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. void __init set_pxa_fb_parent(struct device *parent_dev)
  211. {
  212. pxafb_device.dev.parent = parent_dev;
  213. }
  214. static struct platform_device ffuart_device = {
  215. .name = "pxa2xx-uart",
  216. .id = 0,
  217. };
  218. static struct platform_device btuart_device = {
  219. .name = "pxa2xx-uart",
  220. .id = 1,
  221. };
  222. static struct platform_device stuart_device = {
  223. .name = "pxa2xx-uart",
  224. .id = 2,
  225. };
  226. static struct platform_device hwuart_device = {
  227. .name = "pxa2xx-uart",
  228. .id = 3,
  229. };
  230. static struct resource i2c_resources[] = {
  231. {
  232. .start = 0x40301680,
  233. .end = 0x403016a3,
  234. .flags = IORESOURCE_MEM,
  235. }, {
  236. .start = IRQ_I2C,
  237. .end = IRQ_I2C,
  238. .flags = IORESOURCE_IRQ,
  239. },
  240. };
  241. static struct platform_device i2c_device = {
  242. .name = "pxa2xx-i2c",
  243. .id = 0,
  244. .resource = i2c_resources,
  245. .num_resources = ARRAY_SIZE(i2c_resources),
  246. };
  247. void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
  248. {
  249. i2c_device.dev.platform_data = info;
  250. }
  251. static struct resource i2s_resources[] = {
  252. {
  253. .start = 0x40400000,
  254. .end = 0x40400083,
  255. .flags = IORESOURCE_MEM,
  256. }, {
  257. .start = IRQ_I2S,
  258. .end = IRQ_I2S,
  259. .flags = IORESOURCE_IRQ,
  260. },
  261. };
  262. static struct platform_device i2s_device = {
  263. .name = "pxa2xx-i2s",
  264. .id = -1,
  265. .resource = i2s_resources,
  266. .num_resources = ARRAY_SIZE(i2s_resources),
  267. };
  268. static u64 pxaficp_dmamask = ~(u32)0;
  269. static struct platform_device pxaficp_device = {
  270. .name = "pxa2xx-ir",
  271. .id = -1,
  272. .dev = {
  273. .dma_mask = &pxaficp_dmamask,
  274. .coherent_dma_mask = 0xffffffff,
  275. },
  276. };
  277. void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
  278. {
  279. pxaficp_device.dev.platform_data = info;
  280. }
  281. static struct platform_device *devices[] __initdata = {
  282. &pxamci_device,
  283. &udc_device,
  284. &pxafb_device,
  285. &ffuart_device,
  286. &btuart_device,
  287. &stuart_device,
  288. &pxaficp_device,
  289. &i2c_device,
  290. &i2s_device,
  291. };
  292. static int __init pxa_init(void)
  293. {
  294. int cpuid, ret;
  295. ret = platform_add_devices(devices, ARRAY_SIZE(devices));
  296. if (ret)
  297. return ret;
  298. /* Only add HWUART for PXA255/26x; PXA210/250/27x do not have it. */
  299. cpuid = read_cpuid(CPUID_ID);
  300. if (((cpuid >> 4) & 0xfff) == 0x2d0 ||
  301. ((cpuid >> 4) & 0xfff) == 0x290)
  302. ret = platform_device_register(&hwuart_device);
  303. return ret;
  304. }
  305. subsys_initcall(pxa_init);