common.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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 <mach/common.h>
  31. #include <mach/board.h>
  32. #include <mach/control.h>
  33. #include <mach/mux.h>
  34. #include <mach/fpga.h>
  35. #include <mach/clock.h>
  36. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  37. # include "../mach-omap2/sdrc.h"
  38. #endif
  39. #define NO_LENGTH_CHECK 0xffffffff
  40. unsigned char omap_bootloader_tag[512];
  41. int omap_bootloader_tag_len;
  42. struct omap_board_config_kernel *omap_board_config;
  43. int omap_board_config_size;
  44. static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
  45. {
  46. struct omap_board_config_kernel *kinfo = NULL;
  47. int i;
  48. /* Try to find the config from the board-specific structures
  49. * in the kernel. */
  50. for (i = 0; i < omap_board_config_size; i++) {
  51. if (omap_board_config[i].tag == tag) {
  52. if (skip == 0) {
  53. kinfo = &omap_board_config[i];
  54. break;
  55. } else {
  56. skip--;
  57. }
  58. }
  59. }
  60. if (kinfo == NULL)
  61. return NULL;
  62. return kinfo->data;
  63. }
  64. const void *__omap_get_config(u16 tag, size_t len, int nr)
  65. {
  66. return get_config(tag, len, nr, NULL);
  67. }
  68. EXPORT_SYMBOL(__omap_get_config);
  69. const void *omap_get_var_config(u16 tag, size_t *len)
  70. {
  71. return get_config(tag, NO_LENGTH_CHECK, 0, len);
  72. }
  73. EXPORT_SYMBOL(omap_get_var_config);
  74. /*
  75. * 32KHz clocksource ... always available, on pretty most chips except
  76. * OMAP 730 and 1510. Other timers could be used as clocksources, with
  77. * higher resolution in free-running counter modes (e.g. 12 MHz xtal),
  78. * but systems won't necessarily want to spend resources that way.
  79. */
  80. #define OMAP16XX_TIMER_32K_SYNCHRONIZED 0xfffbc410
  81. #if !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX))
  82. #include <linux/clocksource.h>
  83. #ifdef CONFIG_ARCH_OMAP16XX
  84. static cycle_t omap16xx_32k_read(struct clocksource *cs)
  85. {
  86. return omap_readl(OMAP16XX_TIMER_32K_SYNCHRONIZED);
  87. }
  88. #else
  89. #define omap16xx_32k_read NULL
  90. #endif
  91. #ifdef CONFIG_ARCH_OMAP2420
  92. static cycle_t omap2420_32k_read(struct clocksource *cs)
  93. {
  94. return omap_readl(OMAP2420_32KSYNCT_BASE + 0x10);
  95. }
  96. #else
  97. #define omap2420_32k_read NULL
  98. #endif
  99. #ifdef CONFIG_ARCH_OMAP2430
  100. static cycle_t omap2430_32k_read(struct clocksource *cs)
  101. {
  102. return omap_readl(OMAP2430_32KSYNCT_BASE + 0x10);
  103. }
  104. #else
  105. #define omap2430_32k_read NULL
  106. #endif
  107. #ifdef CONFIG_ARCH_OMAP34XX
  108. static cycle_t omap34xx_32k_read(struct clocksource *cs)
  109. {
  110. return omap_readl(OMAP3430_32KSYNCT_BASE + 0x10);
  111. }
  112. #else
  113. #define omap34xx_32k_read NULL
  114. #endif
  115. #ifdef CONFIG_ARCH_OMAP4
  116. static cycle_t omap44xx_32k_read(struct clocksource *cs)
  117. {
  118. return omap_readl(OMAP4430_32KSYNCT_BASE + 0x10);
  119. }
  120. #else
  121. #define omap44xx_32k_read NULL
  122. #endif
  123. /*
  124. * Kernel assumes that sched_clock can be called early but may not have
  125. * things ready yet.
  126. */
  127. static cycle_t omap_32k_read_dummy(struct clocksource *cs)
  128. {
  129. return 0;
  130. }
  131. static struct clocksource clocksource_32k = {
  132. .name = "32k_counter",
  133. .rating = 250,
  134. .read = omap_32k_read_dummy,
  135. .mask = CLOCKSOURCE_MASK(32),
  136. .shift = 10,
  137. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  138. };
  139. /*
  140. * Returns current time from boot in nsecs. It's OK for this to wrap
  141. * around for now, as it's just a relative time stamp.
  142. */
  143. unsigned long long sched_clock(void)
  144. {
  145. return clocksource_cyc2ns(clocksource_32k.read(&clocksource_32k),
  146. clocksource_32k.mult, clocksource_32k.shift);
  147. }
  148. static int __init omap_init_clocksource_32k(void)
  149. {
  150. static char err[] __initdata = KERN_ERR
  151. "%s: can't register clocksource!\n";
  152. if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
  153. struct clk *sync_32k_ick;
  154. if (cpu_is_omap16xx())
  155. clocksource_32k.read = omap16xx_32k_read;
  156. else if (cpu_is_omap2420())
  157. clocksource_32k.read = omap2420_32k_read;
  158. else if (cpu_is_omap2430())
  159. clocksource_32k.read = omap2430_32k_read;
  160. else if (cpu_is_omap34xx())
  161. clocksource_32k.read = omap34xx_32k_read;
  162. else if (cpu_is_omap44xx())
  163. clocksource_32k.read = omap44xx_32k_read;
  164. else
  165. return -ENODEV;
  166. sync_32k_ick = clk_get(NULL, "omap_32ksync_ick");
  167. if (sync_32k_ick)
  168. clk_enable(sync_32k_ick);
  169. clocksource_32k.mult = clocksource_hz2mult(32768,
  170. clocksource_32k.shift);
  171. if (clocksource_register(&clocksource_32k))
  172. printk(err, clocksource_32k.name);
  173. }
  174. return 0;
  175. }
  176. arch_initcall(omap_init_clocksource_32k);
  177. #endif /* !(defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP15XX)) */
  178. /* Global address base setup code */
  179. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  180. static void __init __omap2_set_globals(struct omap_globals *omap2_globals)
  181. {
  182. omap2_set_globals_tap(omap2_globals);
  183. omap2_set_globals_sdrc(omap2_globals);
  184. omap2_set_globals_control(omap2_globals);
  185. omap2_set_globals_prcm(omap2_globals);
  186. }
  187. #endif
  188. #if defined(CONFIG_ARCH_OMAP2420)
  189. static struct omap_globals omap242x_globals = {
  190. .class = OMAP242X_CLASS,
  191. .tap = OMAP2_IO_ADDRESS(0x48014000),
  192. .sdrc = OMAP2_IO_ADDRESS(OMAP2420_SDRC_BASE),
  193. .sms = OMAP2_IO_ADDRESS(OMAP2420_SMS_BASE),
  194. .ctrl = OMAP2_IO_ADDRESS(OMAP2420_CTRL_BASE),
  195. .prm = OMAP2_IO_ADDRESS(OMAP2420_PRM_BASE),
  196. .cm = OMAP2_IO_ADDRESS(OMAP2420_CM_BASE),
  197. };
  198. void __init omap2_set_globals_242x(void)
  199. {
  200. __omap2_set_globals(&omap242x_globals);
  201. }
  202. #endif
  203. #if defined(CONFIG_ARCH_OMAP2430)
  204. static struct omap_globals omap243x_globals = {
  205. .class = OMAP243X_CLASS,
  206. .tap = OMAP2_IO_ADDRESS(0x4900a000),
  207. .sdrc = OMAP2_IO_ADDRESS(OMAP243X_SDRC_BASE),
  208. .sms = OMAP2_IO_ADDRESS(OMAP243X_SMS_BASE),
  209. .ctrl = OMAP2_IO_ADDRESS(OMAP243X_CTRL_BASE),
  210. .prm = OMAP2_IO_ADDRESS(OMAP2430_PRM_BASE),
  211. .cm = OMAP2_IO_ADDRESS(OMAP2430_CM_BASE),
  212. };
  213. void __init omap2_set_globals_243x(void)
  214. {
  215. __omap2_set_globals(&omap243x_globals);
  216. }
  217. #endif
  218. #if defined(CONFIG_ARCH_OMAP3430)
  219. static struct omap_globals omap343x_globals = {
  220. .class = OMAP343X_CLASS,
  221. .tap = OMAP2_IO_ADDRESS(0x4830A000),
  222. .sdrc = OMAP2_IO_ADDRESS(OMAP343X_SDRC_BASE),
  223. .sms = OMAP2_IO_ADDRESS(OMAP343X_SMS_BASE),
  224. .ctrl = OMAP2_IO_ADDRESS(OMAP343X_CTRL_BASE),
  225. .prm = OMAP2_IO_ADDRESS(OMAP3430_PRM_BASE),
  226. .cm = OMAP2_IO_ADDRESS(OMAP3430_CM_BASE),
  227. };
  228. void __init omap2_set_globals_343x(void)
  229. {
  230. __omap2_set_globals(&omap343x_globals);
  231. }
  232. #endif
  233. #if defined(CONFIG_ARCH_OMAP4)
  234. static struct omap_globals omap4_globals = {
  235. .class = OMAP443X_CLASS,
  236. .tap = OMAP2_IO_ADDRESS(0x4830a000),
  237. .ctrl = OMAP2_IO_ADDRESS(OMAP443X_CTRL_BASE),
  238. .prm = OMAP2_IO_ADDRESS(OMAP4430_PRM_BASE),
  239. .cm = OMAP2_IO_ADDRESS(OMAP4430_CM_BASE),
  240. };
  241. void __init omap2_set_globals_443x(void)
  242. {
  243. omap2_set_globals_tap(&omap4_globals);
  244. omap2_set_globals_control(&omap4_globals);
  245. }
  246. #endif