common.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. * linux/arch/arm/plat-omap/common.c
  3. *
  4. * Code common to all OMAP machines.
  5. * The file is created by Tony Lindgren <tony@atomide.com>
  6. *
  7. * Copyright (C) 2009 Texas Instruments
  8. * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
  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. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/delay.h>
  18. #include <linux/console.h>
  19. #include <linux/serial.h>
  20. #include <linux/tty.h>
  21. #include <linux/serial_8250.h>
  22. #include <linux/serial_reg.h>
  23. #include <linux/clk.h>
  24. #include <linux/io.h>
  25. #include <mach/hardware.h>
  26. #include <asm/system.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/mach/map.h>
  29. #include <asm/setup.h>
  30. #include <plat/common.h>
  31. #include <plat/board.h>
  32. #include <plat/control.h>
  33. #include <plat/mux.h>
  34. #include <plat/fpga.h>
  35. #include <plat/serial.h>
  36. #include <plat/clock.h>
  37. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  38. # include "../mach-omap2/sdrc.h"
  39. #endif
  40. #define NO_LENGTH_CHECK 0xffffffff
  41. struct omap_board_config_kernel *omap_board_config;
  42. int omap_board_config_size;
  43. static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
  44. {
  45. struct omap_board_config_kernel *kinfo = NULL;
  46. int i;
  47. /* Try to find the config from the board-specific structures
  48. * in the kernel. */
  49. for (i = 0; i < omap_board_config_size; i++) {
  50. if (omap_board_config[i].tag == tag) {
  51. if (skip == 0) {
  52. kinfo = &omap_board_config[i];
  53. break;
  54. } else {
  55. skip--;
  56. }
  57. }
  58. }
  59. if (kinfo == NULL)
  60. return NULL;
  61. return kinfo->data;
  62. }
  63. const void *__omap_get_config(u16 tag, size_t len, int nr)
  64. {
  65. return get_config(tag, len, nr, NULL);
  66. }
  67. EXPORT_SYMBOL(__omap_get_config);
  68. const void *omap_get_var_config(u16 tag, size_t *len)
  69. {
  70. return get_config(tag, NO_LENGTH_CHECK, 0, len);
  71. }
  72. EXPORT_SYMBOL(omap_get_var_config);
  73. /*
  74. * 32KHz clocksource ... always available, on pretty most chips except
  75. * OMAP 730 and 1510. Other timers could be used as clocksources, with
  76. * higher resolution in free-running counter modes (e.g. 12 MHz xtal),
  77. * but systems won't necessarily want to spend resources that way.
  78. */
  79. #define OMAP16XX_TIMER_32K_SYNCHRONIZED 0xfffbc410
  80. #if !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX))
  81. #include <linux/clocksource.h>
  82. /*
  83. * offset_32k holds the init time counter value. It is then subtracted
  84. * from every counter read to achieve a counter that counts time from the
  85. * kernel boot (needed for sched_clock()).
  86. */
  87. static u32 offset_32k __read_mostly;
  88. #ifdef CONFIG_ARCH_OMAP16XX
  89. static cycle_t omap16xx_32k_read(struct clocksource *cs)
  90. {
  91. return omap_readl(OMAP16XX_TIMER_32K_SYNCHRONIZED) - offset_32k;
  92. }
  93. #else
  94. #define omap16xx_32k_read NULL
  95. #endif
  96. #ifdef CONFIG_ARCH_OMAP2420
  97. static cycle_t omap2420_32k_read(struct clocksource *cs)
  98. {
  99. return omap_readl(OMAP2420_32KSYNCT_BASE + 0x10) - offset_32k;
  100. }
  101. #else
  102. #define omap2420_32k_read NULL
  103. #endif
  104. #ifdef CONFIG_ARCH_OMAP2430
  105. static cycle_t omap2430_32k_read(struct clocksource *cs)
  106. {
  107. return omap_readl(OMAP2430_32KSYNCT_BASE + 0x10) - offset_32k;
  108. }
  109. #else
  110. #define omap2430_32k_read NULL
  111. #endif
  112. #ifdef CONFIG_ARCH_OMAP3
  113. static cycle_t omap34xx_32k_read(struct clocksource *cs)
  114. {
  115. return omap_readl(OMAP3430_32KSYNCT_BASE + 0x10) - offset_32k;
  116. }
  117. #else
  118. #define omap34xx_32k_read NULL
  119. #endif
  120. #ifdef CONFIG_ARCH_OMAP4
  121. static cycle_t omap44xx_32k_read(struct clocksource *cs)
  122. {
  123. return omap_readl(OMAP4430_32KSYNCT_BASE + 0x10) - offset_32k;
  124. }
  125. #else
  126. #define omap44xx_32k_read NULL
  127. #endif
  128. /*
  129. * Kernel assumes that sched_clock can be called early but may not have
  130. * things ready yet.
  131. */
  132. static cycle_t omap_32k_read_dummy(struct clocksource *cs)
  133. {
  134. return 0;
  135. }
  136. static struct clocksource clocksource_32k = {
  137. .name = "32k_counter",
  138. .rating = 250,
  139. .read = omap_32k_read_dummy,
  140. .mask = CLOCKSOURCE_MASK(32),
  141. .shift = 10,
  142. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  143. };
  144. /*
  145. * Returns current time from boot in nsecs. It's OK for this to wrap
  146. * around for now, as it's just a relative time stamp.
  147. */
  148. unsigned long long sched_clock(void)
  149. {
  150. return clocksource_cyc2ns(clocksource_32k.read(&clocksource_32k),
  151. clocksource_32k.mult, clocksource_32k.shift);
  152. }
  153. /**
  154. * read_persistent_clock - Return time from a persistent clock.
  155. *
  156. * Reads the time from a source which isn't disabled during PM, the
  157. * 32k sync timer. Convert the cycles elapsed since last read into
  158. * nsecs and adds to a monotonically increasing timespec.
  159. */
  160. static struct timespec persistent_ts;
  161. static cycles_t cycles, last_cycles;
  162. void read_persistent_clock(struct timespec *ts)
  163. {
  164. unsigned long long nsecs;
  165. cycles_t delta;
  166. struct timespec *tsp = &persistent_ts;
  167. last_cycles = cycles;
  168. cycles = clocksource_32k.read(&clocksource_32k);
  169. delta = cycles - last_cycles;
  170. nsecs = clocksource_cyc2ns(delta,
  171. clocksource_32k.mult, clocksource_32k.shift);
  172. timespec_add_ns(tsp, nsecs);
  173. *ts = *tsp;
  174. }
  175. static int __init omap_init_clocksource_32k(void)
  176. {
  177. static char err[] __initdata = KERN_ERR
  178. "%s: can't register clocksource!\n";
  179. if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
  180. struct clk *sync_32k_ick;
  181. if (cpu_is_omap16xx())
  182. clocksource_32k.read = omap16xx_32k_read;
  183. else if (cpu_is_omap2420())
  184. clocksource_32k.read = omap2420_32k_read;
  185. else if (cpu_is_omap2430())
  186. clocksource_32k.read = omap2430_32k_read;
  187. else if (cpu_is_omap34xx())
  188. clocksource_32k.read = omap34xx_32k_read;
  189. else if (cpu_is_omap44xx())
  190. clocksource_32k.read = omap44xx_32k_read;
  191. else
  192. return -ENODEV;
  193. sync_32k_ick = clk_get(NULL, "omap_32ksync_ick");
  194. if (sync_32k_ick)
  195. clk_enable(sync_32k_ick);
  196. clocksource_32k.mult = clocksource_hz2mult(32768,
  197. clocksource_32k.shift);
  198. offset_32k = clocksource_32k.read(&clocksource_32k);
  199. if (clocksource_register(&clocksource_32k))
  200. printk(err, clocksource_32k.name);
  201. }
  202. return 0;
  203. }
  204. arch_initcall(omap_init_clocksource_32k);
  205. #endif /* !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX)) */
  206. /* Global address base setup code */
  207. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  208. static void __init __omap2_set_globals(struct omap_globals *omap2_globals)
  209. {
  210. omap2_set_globals_tap(omap2_globals);
  211. omap2_set_globals_sdrc(omap2_globals);
  212. omap2_set_globals_control(omap2_globals);
  213. omap2_set_globals_prcm(omap2_globals);
  214. omap2_set_globals_uart(omap2_globals);
  215. }
  216. #endif
  217. #if defined(CONFIG_ARCH_OMAP2420)
  218. static struct omap_globals omap242x_globals = {
  219. .class = OMAP242X_CLASS,
  220. .tap = OMAP2_L4_IO_ADDRESS(0x48014000),
  221. .sdrc = OMAP2420_SDRC_BASE,
  222. .sms = OMAP2420_SMS_BASE,
  223. .ctrl = OMAP2420_CTRL_BASE,
  224. .prm = OMAP2420_PRM_BASE,
  225. .cm = OMAP2420_CM_BASE,
  226. .uart1_phys = OMAP2_UART1_BASE,
  227. .uart2_phys = OMAP2_UART2_BASE,
  228. .uart3_phys = OMAP2_UART3_BASE,
  229. };
  230. void __init omap2_set_globals_242x(void)
  231. {
  232. __omap2_set_globals(&omap242x_globals);
  233. }
  234. #endif
  235. #if defined(CONFIG_ARCH_OMAP2430)
  236. static struct omap_globals omap243x_globals = {
  237. .class = OMAP243X_CLASS,
  238. .tap = OMAP2_L4_IO_ADDRESS(0x4900a000),
  239. .sdrc = OMAP243X_SDRC_BASE,
  240. .sms = OMAP243X_SMS_BASE,
  241. .ctrl = OMAP243X_CTRL_BASE,
  242. .prm = OMAP2430_PRM_BASE,
  243. .cm = OMAP2430_CM_BASE,
  244. .uart1_phys = OMAP2_UART1_BASE,
  245. .uart2_phys = OMAP2_UART2_BASE,
  246. .uart3_phys = OMAP2_UART3_BASE,
  247. };
  248. void __init omap2_set_globals_243x(void)
  249. {
  250. __omap2_set_globals(&omap243x_globals);
  251. }
  252. #endif
  253. #if defined(CONFIG_ARCH_OMAP3)
  254. static struct omap_globals omap3_globals = {
  255. .class = OMAP343X_CLASS,
  256. .tap = OMAP2_L4_IO_ADDRESS(0x4830A000),
  257. .sdrc = OMAP343X_SDRC_BASE,
  258. .sms = OMAP343X_SMS_BASE,
  259. .ctrl = OMAP343X_CTRL_BASE,
  260. .prm = OMAP3430_PRM_BASE,
  261. .cm = OMAP3430_CM_BASE,
  262. .uart1_phys = OMAP3_UART1_BASE,
  263. .uart2_phys = OMAP3_UART2_BASE,
  264. .uart3_phys = OMAP3_UART3_BASE,
  265. };
  266. void __init omap2_set_globals_343x(void)
  267. {
  268. __omap2_set_globals(&omap3_globals);
  269. }
  270. void __init omap2_set_globals_36xx(void)
  271. {
  272. omap3_globals.uart4_phys = OMAP3_UART4_BASE;
  273. __omap2_set_globals(&omap3_globals);
  274. }
  275. #endif
  276. #if defined(CONFIG_ARCH_OMAP4)
  277. static struct omap_globals omap4_globals = {
  278. .class = OMAP443X_CLASS,
  279. .tap = OMAP2_L4_IO_ADDRESS(OMAP443X_SCM_BASE),
  280. .ctrl = OMAP443X_CTRL_BASE,
  281. .prm = OMAP4430_PRM_BASE,
  282. .cm = OMAP4430_CM_BASE,
  283. .cm2 = OMAP4430_CM2_BASE,
  284. .uart1_phys = OMAP4_UART1_BASE,
  285. .uart2_phys = OMAP4_UART2_BASE,
  286. .uart3_phys = OMAP4_UART3_BASE,
  287. .uart4_phys = OMAP4_UART4_BASE,
  288. };
  289. void __init omap2_set_globals_443x(void)
  290. {
  291. omap2_set_globals_tap(&omap4_globals);
  292. omap2_set_globals_control(&omap4_globals);
  293. omap2_set_globals_prcm(&omap4_globals);
  294. omap2_set_globals_uart(&omap4_globals);
  295. }
  296. #endif