generic.c 9.0 KB

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