generic.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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/gpio.h>
  34. #include <asm/arch/udc.h>
  35. #include <asm/arch/pxafb.h>
  36. #include <asm/arch/mmc.h>
  37. #include <asm/arch/irda.h>
  38. #include <asm/arch/i2c.h>
  39. #include "devices.h"
  40. #include "generic.h"
  41. /*
  42. * Handy function to set GPIO alternate functions
  43. */
  44. int pxa_gpio_mode(int gpio_mode)
  45. {
  46. unsigned long flags;
  47. int gpio = gpio_mode & GPIO_MD_MASK_NR;
  48. int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
  49. int gafr;
  50. if (gpio > PXA_LAST_GPIO)
  51. return -EINVAL;
  52. local_irq_save(flags);
  53. if (gpio_mode & GPIO_DFLT_LOW)
  54. GPCR(gpio) = GPIO_bit(gpio);
  55. else if (gpio_mode & GPIO_DFLT_HIGH)
  56. GPSR(gpio) = GPIO_bit(gpio);
  57. if (gpio_mode & GPIO_MD_MASK_DIR)
  58. GPDR(gpio) |= GPIO_bit(gpio);
  59. else
  60. GPDR(gpio) &= ~GPIO_bit(gpio);
  61. gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
  62. GAFR(gpio) = gafr | (fn << (((gpio) & 0xf)*2));
  63. local_irq_restore(flags);
  64. return 0;
  65. }
  66. EXPORT_SYMBOL(pxa_gpio_mode);
  67. /*
  68. * Return GPIO level
  69. */
  70. int pxa_gpio_get_value(unsigned gpio)
  71. {
  72. return __gpio_get_value(gpio);
  73. }
  74. EXPORT_SYMBOL(pxa_gpio_get_value);
  75. /*
  76. * Set output GPIO level
  77. */
  78. void pxa_gpio_set_value(unsigned gpio, int value)
  79. {
  80. __gpio_set_value(gpio, value);
  81. }
  82. EXPORT_SYMBOL(pxa_gpio_set_value);
  83. /*
  84. * Routine to safely enable or disable a clock in the CKEN
  85. */
  86. void pxa_set_cken(int clock, int enable)
  87. {
  88. unsigned long flags;
  89. local_irq_save(flags);
  90. if (enable)
  91. CKEN |= (1 << clock);
  92. else
  93. CKEN &= ~(1 << clock);
  94. local_irq_restore(flags);
  95. }
  96. EXPORT_SYMBOL(pxa_set_cken);
  97. /*
  98. * Intel PXA2xx internal register mapping.
  99. *
  100. * Note 1: not all PXA2xx variants implement all those addresses.
  101. *
  102. * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
  103. * and cache flush area.
  104. */
  105. static struct map_desc standard_io_desc[] __initdata = {
  106. { /* Devs */
  107. .virtual = 0xf2000000,
  108. .pfn = __phys_to_pfn(0x40000000),
  109. .length = 0x02000000,
  110. .type = MT_DEVICE
  111. }, { /* LCD */
  112. .virtual = 0xf4000000,
  113. .pfn = __phys_to_pfn(0x44000000),
  114. .length = 0x00100000,
  115. .type = MT_DEVICE
  116. }, { /* Mem Ctl */
  117. .virtual = 0xf6000000,
  118. .pfn = __phys_to_pfn(0x48000000),
  119. .length = 0x00100000,
  120. .type = MT_DEVICE
  121. }, { /* USB host */
  122. .virtual = 0xf8000000,
  123. .pfn = __phys_to_pfn(0x4c000000),
  124. .length = 0x00100000,
  125. .type = MT_DEVICE
  126. }, { /* Camera */
  127. .virtual = 0xfa000000,
  128. .pfn = __phys_to_pfn(0x50000000),
  129. .length = 0x00100000,
  130. .type = MT_DEVICE
  131. }, { /* IMem ctl */
  132. .virtual = 0xfe000000,
  133. .pfn = __phys_to_pfn(0x58000000),
  134. .length = 0x00100000,
  135. .type = MT_DEVICE
  136. }, { /* UNCACHED_PHYS_0 */
  137. .virtual = 0xff000000,
  138. .pfn = __phys_to_pfn(0x00000000),
  139. .length = 0x00100000,
  140. .type = MT_DEVICE
  141. }
  142. };
  143. void __init pxa_map_io(void)
  144. {
  145. iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
  146. get_clk_frequency_khz(1);
  147. }
  148. static struct resource pxamci_resources[] = {
  149. [0] = {
  150. .start = 0x41100000,
  151. .end = 0x41100fff,
  152. .flags = IORESOURCE_MEM,
  153. },
  154. [1] = {
  155. .start = IRQ_MMC,
  156. .end = IRQ_MMC,
  157. .flags = IORESOURCE_IRQ,
  158. },
  159. };
  160. static u64 pxamci_dmamask = 0xffffffffUL;
  161. struct platform_device pxa_device_mci = {
  162. .name = "pxa2xx-mci",
  163. .id = -1,
  164. .dev = {
  165. .dma_mask = &pxamci_dmamask,
  166. .coherent_dma_mask = 0xffffffff,
  167. },
  168. .num_resources = ARRAY_SIZE(pxamci_resources),
  169. .resource = pxamci_resources,
  170. };
  171. void __init pxa_set_mci_info(struct pxamci_platform_data *info)
  172. {
  173. pxa_device_mci.dev.platform_data = info;
  174. }
  175. static struct pxa2xx_udc_mach_info pxa_udc_info;
  176. void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
  177. {
  178. memcpy(&pxa_udc_info, info, sizeof *info);
  179. }
  180. static struct resource pxa2xx_udc_resources[] = {
  181. [0] = {
  182. .start = 0x40600000,
  183. .end = 0x4060ffff,
  184. .flags = IORESOURCE_MEM,
  185. },
  186. [1] = {
  187. .start = IRQ_USB,
  188. .end = IRQ_USB,
  189. .flags = IORESOURCE_IRQ,
  190. },
  191. };
  192. static u64 udc_dma_mask = ~(u32)0;
  193. struct platform_device pxa_device_udc = {
  194. .name = "pxa2xx-udc",
  195. .id = -1,
  196. .resource = pxa2xx_udc_resources,
  197. .num_resources = ARRAY_SIZE(pxa2xx_udc_resources),
  198. .dev = {
  199. .platform_data = &pxa_udc_info,
  200. .dma_mask = &udc_dma_mask,
  201. }
  202. };
  203. static struct resource pxafb_resources[] = {
  204. [0] = {
  205. .start = 0x44000000,
  206. .end = 0x4400ffff,
  207. .flags = IORESOURCE_MEM,
  208. },
  209. [1] = {
  210. .start = IRQ_LCD,
  211. .end = IRQ_LCD,
  212. .flags = IORESOURCE_IRQ,
  213. },
  214. };
  215. static u64 fb_dma_mask = ~(u64)0;
  216. struct platform_device pxa_device_fb = {
  217. .name = "pxa2xx-fb",
  218. .id = -1,
  219. .dev = {
  220. .dma_mask = &fb_dma_mask,
  221. .coherent_dma_mask = 0xffffffff,
  222. },
  223. .num_resources = ARRAY_SIZE(pxafb_resources),
  224. .resource = pxafb_resources,
  225. };
  226. void __init set_pxa_fb_info(struct pxafb_mach_info *info)
  227. {
  228. pxa_device_fb.dev.platform_data = info;
  229. }
  230. void __init set_pxa_fb_parent(struct device *parent_dev)
  231. {
  232. pxa_device_fb.dev.parent = parent_dev;
  233. }
  234. static struct resource pxa_resource_ffuart[] = {
  235. {
  236. .start = __PREG(FFUART),
  237. .end = __PREG(FFUART) + 35,
  238. .flags = IORESOURCE_MEM,
  239. }, {
  240. .start = IRQ_FFUART,
  241. .end = IRQ_FFUART,
  242. .flags = IORESOURCE_IRQ,
  243. }
  244. };
  245. struct platform_device pxa_device_ffuart= {
  246. .name = "pxa2xx-uart",
  247. .id = 0,
  248. .resource = pxa_resource_ffuart,
  249. .num_resources = ARRAY_SIZE(pxa_resource_ffuart),
  250. };
  251. static struct resource pxa_resource_btuart[] = {
  252. {
  253. .start = __PREG(BTUART),
  254. .end = __PREG(BTUART) + 35,
  255. .flags = IORESOURCE_MEM,
  256. }, {
  257. .start = IRQ_BTUART,
  258. .end = IRQ_BTUART,
  259. .flags = IORESOURCE_IRQ,
  260. }
  261. };
  262. struct platform_device pxa_device_btuart = {
  263. .name = "pxa2xx-uart",
  264. .id = 1,
  265. .resource = pxa_resource_btuart,
  266. .num_resources = ARRAY_SIZE(pxa_resource_btuart),
  267. };
  268. static struct resource pxa_resource_stuart[] = {
  269. {
  270. .start = __PREG(STUART),
  271. .end = __PREG(STUART) + 35,
  272. .flags = IORESOURCE_MEM,
  273. }, {
  274. .start = IRQ_STUART,
  275. .end = IRQ_STUART,
  276. .flags = IORESOURCE_IRQ,
  277. }
  278. };
  279. struct platform_device pxa_device_stuart = {
  280. .name = "pxa2xx-uart",
  281. .id = 2,
  282. .resource = pxa_resource_stuart,
  283. .num_resources = ARRAY_SIZE(pxa_resource_stuart),
  284. };
  285. static struct resource pxa_resource_hwuart[] = {
  286. {
  287. .start = __PREG(HWUART),
  288. .end = __PREG(HWUART) + 47,
  289. .flags = IORESOURCE_MEM,
  290. }, {
  291. .start = IRQ_HWUART,
  292. .end = IRQ_HWUART,
  293. .flags = IORESOURCE_IRQ,
  294. }
  295. };
  296. struct platform_device pxa_device_hwuart = {
  297. .name = "pxa2xx-uart",
  298. .id = 3,
  299. .resource = pxa_resource_hwuart,
  300. .num_resources = ARRAY_SIZE(pxa_resource_hwuart),
  301. };
  302. static struct resource pxai2c_resources[] = {
  303. {
  304. .start = 0x40301680,
  305. .end = 0x403016a3,
  306. .flags = IORESOURCE_MEM,
  307. }, {
  308. .start = IRQ_I2C,
  309. .end = IRQ_I2C,
  310. .flags = IORESOURCE_IRQ,
  311. },
  312. };
  313. struct platform_device pxa_device_i2c = {
  314. .name = "pxa2xx-i2c",
  315. .id = 0,
  316. .resource = pxai2c_resources,
  317. .num_resources = ARRAY_SIZE(pxai2c_resources),
  318. };
  319. void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
  320. {
  321. pxa_device_i2c.dev.platform_data = info;
  322. }
  323. static struct resource pxai2s_resources[] = {
  324. {
  325. .start = 0x40400000,
  326. .end = 0x40400083,
  327. .flags = IORESOURCE_MEM,
  328. }, {
  329. .start = IRQ_I2S,
  330. .end = IRQ_I2S,
  331. .flags = IORESOURCE_IRQ,
  332. },
  333. };
  334. struct platform_device pxa_device_i2s = {
  335. .name = "pxa2xx-i2s",
  336. .id = -1,
  337. .resource = pxai2s_resources,
  338. .num_resources = ARRAY_SIZE(pxai2s_resources),
  339. };
  340. static u64 pxaficp_dmamask = ~(u32)0;
  341. struct platform_device pxa_device_ficp = {
  342. .name = "pxa2xx-ir",
  343. .id = -1,
  344. .dev = {
  345. .dma_mask = &pxaficp_dmamask,
  346. .coherent_dma_mask = 0xffffffff,
  347. },
  348. };
  349. void __init pxa_set_ficp_info(struct pxaficp_platform_data *info)
  350. {
  351. pxa_device_ficp.dev.platform_data = info;
  352. }
  353. struct platform_device pxa_device_rtc = {
  354. .name = "sa1100-rtc",
  355. .id = -1,
  356. };