generic.c 8.9 KB

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