generic.c 6.6 KB

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