generic.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. /* virtual physical length type */
  84. { 0xf2000000, 0x40000000, 0x02000000, MT_DEVICE }, /* Devs */
  85. { 0xf4000000, 0x44000000, 0x00100000, MT_DEVICE }, /* LCD */
  86. { 0xf6000000, 0x48000000, 0x00100000, MT_DEVICE }, /* Mem Ctl */
  87. { 0xf8000000, 0x4c000000, 0x00100000, MT_DEVICE }, /* USB host */
  88. { 0xfa000000, 0x50000000, 0x00100000, MT_DEVICE }, /* Camera */
  89. { 0xfe000000, 0x58000000, 0x00100000, MT_DEVICE }, /* IMem ctl */
  90. { 0xff000000, 0x00000000, 0x00100000, MT_DEVICE } /* UNCACHED_PHYS_0 */
  91. };
  92. void __init pxa_map_io(void)
  93. {
  94. iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
  95. get_clk_frequency_khz(1);
  96. }
  97. static struct resource pxamci_resources[] = {
  98. [0] = {
  99. .start = 0x41100000,
  100. .end = 0x41100fff,
  101. .flags = IORESOURCE_MEM,
  102. },
  103. [1] = {
  104. .start = IRQ_MMC,
  105. .end = IRQ_MMC,
  106. .flags = IORESOURCE_IRQ,
  107. },
  108. };
  109. static u64 pxamci_dmamask = 0xffffffffUL;
  110. static struct platform_device pxamci_device = {
  111. .name = "pxa2xx-mci",
  112. .id = -1,
  113. .dev = {
  114. .dma_mask = &pxamci_dmamask,
  115. .coherent_dma_mask = 0xffffffff,
  116. },
  117. .num_resources = ARRAY_SIZE(pxamci_resources),
  118. .resource = pxamci_resources,
  119. };
  120. void __init pxa_set_mci_info(struct pxamci_platform_data *info)
  121. {
  122. pxamci_device.dev.platform_data = info;
  123. }
  124. static struct pxa2xx_udc_mach_info pxa_udc_info;
  125. void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
  126. {
  127. memcpy(&pxa_udc_info, info, sizeof *info);
  128. }
  129. static struct resource pxa2xx_udc_resources[] = {
  130. [0] = {
  131. .start = 0x40600000,
  132. .end = 0x4060ffff,
  133. .flags = IORESOURCE_MEM,
  134. },
  135. [1] = {
  136. .start = IRQ_USB,
  137. .end = IRQ_USB,
  138. .flags = IORESOURCE_IRQ,
  139. },
  140. };
  141. static u64 udc_dma_mask = ~(u32)0;
  142. static struct platform_device udc_device = {
  143. .name = "pxa2xx-udc",
  144. .id = -1,
  145. .resource = pxa2xx_udc_resources,
  146. .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
  147. .dev = {
  148. .platform_data = &pxa_udc_info,
  149. .dma_mask = &udc_dma_mask,
  150. }
  151. };
  152. static struct pxafb_mach_info pxa_fb_info;
  153. void __init set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info)
  154. {
  155. memcpy(&pxa_fb_info,hard_pxa_fb_info,sizeof(struct pxafb_mach_info));
  156. }
  157. static struct resource pxafb_resources[] = {
  158. [0] = {
  159. .start = 0x44000000,
  160. .end = 0x4400ffff,
  161. .flags = IORESOURCE_MEM,
  162. },
  163. [1] = {
  164. .start = IRQ_LCD,
  165. .end = IRQ_LCD,
  166. .flags = IORESOURCE_IRQ,
  167. },
  168. };
  169. static u64 fb_dma_mask = ~(u64)0;
  170. static struct platform_device pxafb_device = {
  171. .name = "pxa2xx-fb",
  172. .id = -1,
  173. .dev = {
  174. .platform_data = &pxa_fb_info,
  175. .dma_mask = &fb_dma_mask,
  176. .coherent_dma_mask = 0xffffffff,
  177. },
  178. .num_resources = ARRAY_SIZE(pxafb_resources),
  179. .resource = pxafb_resources,
  180. };
  181. static struct platform_device ffuart_device = {
  182. .name = "pxa2xx-uart",
  183. .id = 0,
  184. };
  185. static struct platform_device btuart_device = {
  186. .name = "pxa2xx-uart",
  187. .id = 1,
  188. };
  189. static struct platform_device stuart_device = {
  190. .name = "pxa2xx-uart",
  191. .id = 2,
  192. };
  193. static struct resource i2c_resources[] = {
  194. {
  195. .start = 0x40301680,
  196. .end = 0x403016a3,
  197. .flags = IORESOURCE_MEM,
  198. }, {
  199. .start = IRQ_I2C,
  200. .end = IRQ_I2C,
  201. .flags = IORESOURCE_IRQ,
  202. },
  203. };
  204. static struct platform_device i2c_device = {
  205. .name = "pxa2xx-i2c",
  206. .id = 0,
  207. .resource = i2c_resources,
  208. .num_resources = ARRAY_SIZE(i2c_resources),
  209. };
  210. void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
  211. {
  212. i2c_device.dev.platform_data = info;
  213. }
  214. static struct platform_device *devices[] __initdata = {
  215. &pxamci_device,
  216. &udc_device,
  217. &pxafb_device,
  218. &ffuart_device,
  219. &btuart_device,
  220. &stuart_device,
  221. &i2c_device,
  222. };
  223. static int __init pxa_init(void)
  224. {
  225. return platform_add_devices(devices, ARRAY_SIZE(devices));
  226. }
  227. subsys_initcall(pxa_init);