generic.c 7.4 KB

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