generic.c 5.8 KB

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