generic.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 pxafb_mach_info pxa_fb_info;
  183. void __init set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info)
  184. {
  185. memcpy(&pxa_fb_info,hard_pxa_fb_info,sizeof(struct pxafb_mach_info));
  186. }
  187. static struct resource pxafb_resources[] = {
  188. [0] = {
  189. .start = 0x44000000,
  190. .end = 0x4400ffff,
  191. .flags = IORESOURCE_MEM,
  192. },
  193. [1] = {
  194. .start = IRQ_LCD,
  195. .end = IRQ_LCD,
  196. .flags = IORESOURCE_IRQ,
  197. },
  198. };
  199. static u64 fb_dma_mask = ~(u64)0;
  200. static struct platform_device pxafb_device = {
  201. .name = "pxa2xx-fb",
  202. .id = -1,
  203. .dev = {
  204. .platform_data = &pxa_fb_info,
  205. .dma_mask = &fb_dma_mask,
  206. .coherent_dma_mask = 0xffffffff,
  207. },
  208. .num_resources = ARRAY_SIZE(pxafb_resources),
  209. .resource = pxafb_resources,
  210. };
  211. void __init set_pxa_fb_parent(struct device *parent_dev)
  212. {
  213. pxafb_device.dev.parent = parent_dev;
  214. }
  215. static struct platform_device ffuart_device = {
  216. .name = "pxa2xx-uart",
  217. .id = 0,
  218. };
  219. static struct platform_device btuart_device = {
  220. .name = "pxa2xx-uart",
  221. .id = 1,
  222. };
  223. static struct platform_device stuart_device = {
  224. .name = "pxa2xx-uart",
  225. .id = 2,
  226. };
  227. static struct platform_device hwuart_device = {
  228. .name = "pxa2xx-uart",
  229. .id = 3,
  230. };
  231. static struct resource i2c_resources[] = {
  232. {
  233. .start = 0x40301680,
  234. .end = 0x403016a3,
  235. .flags = IORESOURCE_MEM,
  236. }, {
  237. .start = IRQ_I2C,
  238. .end = IRQ_I2C,
  239. .flags = IORESOURCE_IRQ,
  240. },
  241. };
  242. static struct platform_device i2c_device = {
  243. .name = "pxa2xx-i2c",
  244. .id = 0,
  245. .resource = i2c_resources,
  246. .num_resources = ARRAY_SIZE(i2c_resources),
  247. };
  248. void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
  249. {
  250. i2c_device.dev.platform_data = info;
  251. }
  252. static struct resource i2s_resources[] = {
  253. {
  254. .start = 0x40400000,
  255. .end = 0x40400083,
  256. .flags = IORESOURCE_MEM,
  257. }, {
  258. .start = IRQ_I2S,
  259. .end = IRQ_I2S,
  260. .flags = IORESOURCE_IRQ,
  261. },
  262. };
  263. static struct platform_device i2s_device = {
  264. .name = "pxa2xx-i2s",
  265. .id = -1,
  266. .resource = i2s_resources,
  267. .num_resources = ARRAY_SIZE(i2s_resources),
  268. };
  269. static u64 pxaficp_dmamask = ~(u32)0;
  270. static struct platform_device pxaficp_device = {
  271. .name = "pxa2xx-ir",
  272. .id = -1,
  273. .dev = {
  274. .dma_mask = &pxaficp_dmamask,
  275. .coherent_dma_mask = 0xffffffff,
  276. },
  277. };
  278. void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
  279. {
  280. pxaficp_device.dev.platform_data = info;
  281. }
  282. static struct platform_device pxartc_device = {
  283. .name = "sa1100-rtc",
  284. .id = -1,
  285. };
  286. static struct platform_device *devices[] __initdata = {
  287. &pxamci_device,
  288. &udc_device,
  289. &pxafb_device,
  290. &ffuart_device,
  291. &btuart_device,
  292. &stuart_device,
  293. &pxaficp_device,
  294. &i2c_device,
  295. &i2s_device,
  296. &pxartc_device,
  297. };
  298. static int __init pxa_init(void)
  299. {
  300. int cpuid, ret;
  301. ret = platform_add_devices(devices, ARRAY_SIZE(devices));
  302. if (ret)
  303. return ret;
  304. /* Only add HWUART for PXA255/26x; PXA210/250/27x do not have it. */
  305. cpuid = read_cpuid(CPUID_ID);
  306. if (((cpuid >> 4) & 0xfff) == 0x2d0 ||
  307. ((cpuid >> 4) & 0xfff) == 0x290)
  308. ret = platform_device_register(&hwuart_device);
  309. return ret;
  310. }
  311. subsys_initcall(pxa_init);