generic.c 9.8 KB

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