common.c 8.7 KB

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