generic.c 9.9 KB

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