generic.c 9.2 KB

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