common.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * linux/arch/arm/plat-omap/common.c
  3. *
  4. * Code common to all OMAP machines.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/delay.h>
  14. #include <linux/pm.h>
  15. #include <linux/console.h>
  16. #include <linux/serial.h>
  17. #include <linux/tty.h>
  18. #include <linux/serial_8250.h>
  19. #include <linux/serial_reg.h>
  20. #include <linux/clk.h>
  21. #include <linux/io.h>
  22. #include <mach/hardware.h>
  23. #include <asm/system.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/mach/map.h>
  26. #include <asm/setup.h>
  27. #include <mach/common.h>
  28. #include <mach/board.h>
  29. #include <mach/control.h>
  30. #include <mach/mux.h>
  31. #include <mach/fpga.h>
  32. #include <mach/clock.h>
  33. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  34. # include "../mach-omap2/sdrc.h"
  35. #endif
  36. #define NO_LENGTH_CHECK 0xffffffff
  37. unsigned char omap_bootloader_tag[512];
  38. int omap_bootloader_tag_len;
  39. struct omap_board_config_kernel *omap_board_config;
  40. int omap_board_config_size;
  41. static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
  42. {
  43. struct omap_board_config_kernel *kinfo = NULL;
  44. int i;
  45. #ifdef CONFIG_OMAP_BOOT_TAG
  46. struct omap_board_config_entry *info = NULL;
  47. if (omap_bootloader_tag_len > 4)
  48. info = (struct omap_board_config_entry *) omap_bootloader_tag;
  49. while (info != NULL) {
  50. u8 *next;
  51. if (info->tag == tag) {
  52. if (skip == 0)
  53. break;
  54. skip--;
  55. }
  56. if ((info->len & 0x03) != 0) {
  57. /* We bail out to avoid an alignment fault */
  58. printk(KERN_ERR "OMAP peripheral config: Length (%d) not word-aligned (tag %04x)\n",
  59. info->len, info->tag);
  60. return NULL;
  61. }
  62. next = (u8 *) info + sizeof(*info) + info->len;
  63. if (next >= omap_bootloader_tag + omap_bootloader_tag_len)
  64. info = NULL;
  65. else
  66. info = (struct omap_board_config_entry *) next;
  67. }
  68. if (info != NULL) {
  69. /* Check the length as a lame attempt to check for
  70. * binary inconsistency. */
  71. if (len != NO_LENGTH_CHECK) {
  72. /* Word-align len */
  73. if (len & 0x03)
  74. len = (len + 3) & ~0x03;
  75. if (info->len != len) {
  76. printk(KERN_ERR "OMAP peripheral config: Length mismatch with tag %x (want %d, got %d)\n",
  77. tag, len, info->len);
  78. return NULL;
  79. }
  80. }
  81. if (len_out != NULL)
  82. *len_out = info->len;
  83. return info->data;
  84. }
  85. #endif
  86. /* Try to find the config from the board-specific structures
  87. * in the kernel. */
  88. for (i = 0; i < omap_board_config_size; i++) {
  89. if (omap_board_config[i].tag == tag) {
  90. if (skip == 0) {
  91. kinfo = &omap_board_config[i];
  92. break;
  93. } else {
  94. skip--;
  95. }
  96. }
  97. }
  98. if (kinfo == NULL)
  99. return NULL;
  100. return kinfo->data;
  101. }
  102. const void *__omap_get_config(u16 tag, size_t len, int nr)
  103. {
  104. return get_config(tag, len, nr, NULL);
  105. }
  106. EXPORT_SYMBOL(__omap_get_config);
  107. const void *omap_get_var_config(u16 tag, size_t *len)
  108. {
  109. return get_config(tag, NO_LENGTH_CHECK, 0, len);
  110. }
  111. EXPORT_SYMBOL(omap_get_var_config);
  112. static int __init omap_add_serial_console(void)
  113. {
  114. const struct omap_serial_console_config *con_info;
  115. const struct omap_uart_config *uart_info;
  116. static char speed[11], *opt = NULL;
  117. int line, i, uart_idx;
  118. uart_info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
  119. con_info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
  120. struct omap_serial_console_config);
  121. if (uart_info == NULL || con_info == NULL)
  122. return 0;
  123. if (con_info->console_uart == 0)
  124. return 0;
  125. if (con_info->console_speed) {
  126. snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
  127. opt = speed;
  128. }
  129. uart_idx = con_info->console_uart - 1;
  130. if (uart_idx >= OMAP_MAX_NR_PORTS) {
  131. printk(KERN_INFO "Console: external UART#%d. "
  132. "Not adding it as console this time.\n",
  133. uart_idx + 1);
  134. return 0;
  135. }
  136. if (!(uart_info->enabled_uarts & (1 << uart_idx))) {
  137. printk(KERN_ERR "Console: Selected UART#%d is "
  138. "not enabled for this platform\n",
  139. uart_idx + 1);
  140. return -1;
  141. }
  142. line = 0;
  143. for (i = 0; i < uart_idx; i++) {
  144. if (uart_info->enabled_uarts & (1 << i))
  145. line++;
  146. }
  147. return add_preferred_console("ttyS", line, opt);
  148. }
  149. console_initcall(omap_add_serial_console);
  150. /*
  151. * 32KHz clocksource ... always available, on pretty most chips except
  152. * OMAP 730 and 1510. Other timers could be used as clocksources, with
  153. * higher resolution in free-running counter modes (e.g. 12 MHz xtal),
  154. * but systems won't necessarily want to spend resources that way.
  155. */
  156. #if defined(CONFIG_ARCH_OMAP16XX)
  157. #define TIMER_32K_SYNCHRONIZED 0xfffbc410
  158. #elif defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
  159. #define TIMER_32K_SYNCHRONIZED (OMAP2_32KSYNCT_BASE + 0x10)
  160. #endif
  161. #ifdef TIMER_32K_SYNCHRONIZED
  162. #include <linux/clocksource.h>
  163. static cycle_t omap_32k_read(void)
  164. {
  165. return omap_readl(TIMER_32K_SYNCHRONIZED);
  166. }
  167. static struct clocksource clocksource_32k = {
  168. .name = "32k_counter",
  169. .rating = 250,
  170. .read = omap_32k_read,
  171. .mask = CLOCKSOURCE_MASK(32),
  172. .shift = 10,
  173. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  174. };
  175. /*
  176. * Rounds down to nearest nsec.
  177. */
  178. unsigned long long omap_32k_ticks_to_nsecs(unsigned long ticks_32k)
  179. {
  180. return cyc2ns(&clocksource_32k, ticks_32k);
  181. }
  182. /*
  183. * Returns current time from boot in nsecs. It's OK for this to wrap
  184. * around for now, as it's just a relative time stamp.
  185. */
  186. unsigned long long sched_clock(void)
  187. {
  188. return omap_32k_ticks_to_nsecs(omap_32k_read());
  189. }
  190. static int __init omap_init_clocksource_32k(void)
  191. {
  192. static char err[] __initdata = KERN_ERR
  193. "%s: can't register clocksource!\n";
  194. if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
  195. struct clk *sync_32k_ick;
  196. sync_32k_ick = clk_get(NULL, "omap_32ksync_ick");
  197. if (sync_32k_ick)
  198. clk_enable(sync_32k_ick);
  199. clocksource_32k.mult = clocksource_hz2mult(32768,
  200. clocksource_32k.shift);
  201. if (clocksource_register(&clocksource_32k))
  202. printk(err, clocksource_32k.name);
  203. }
  204. return 0;
  205. }
  206. arch_initcall(omap_init_clocksource_32k);
  207. #endif /* TIMER_32K_SYNCHRONIZED */
  208. /* Global address base setup code */
  209. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  210. static struct omap_globals *omap2_globals;
  211. static void __init __omap2_set_globals(void)
  212. {
  213. omap2_set_globals_tap(omap2_globals);
  214. omap2_set_globals_memory(omap2_globals);
  215. omap2_set_globals_control(omap2_globals);
  216. omap2_set_globals_prcm(omap2_globals);
  217. }
  218. #endif
  219. #if defined(CONFIG_ARCH_OMAP2420)
  220. static struct omap_globals omap242x_globals = {
  221. .class = OMAP242X_CLASS,
  222. .tap = OMAP2_IO_ADDRESS(0x48014000),
  223. .sdrc = OMAP2_IO_ADDRESS(OMAP2420_SDRC_BASE),
  224. .sms = OMAP2_IO_ADDRESS(OMAP2420_SMS_BASE),
  225. .ctrl = OMAP2_IO_ADDRESS(OMAP2420_CTRL_BASE),
  226. .prm = OMAP2_IO_ADDRESS(OMAP2420_PRM_BASE),
  227. .cm = OMAP2_IO_ADDRESS(OMAP2420_CM_BASE),
  228. };
  229. void __init omap2_set_globals_242x(void)
  230. {
  231. omap2_globals = &omap242x_globals;
  232. __omap2_set_globals();
  233. }
  234. #endif
  235. #if defined(CONFIG_ARCH_OMAP2430)
  236. static struct omap_globals omap243x_globals = {
  237. .class = OMAP243X_CLASS,
  238. .tap = OMAP2_IO_ADDRESS(0x4900a000),
  239. .sdrc = OMAP2_IO_ADDRESS(OMAP243X_SDRC_BASE),
  240. .sms = OMAP2_IO_ADDRESS(OMAP243X_SMS_BASE),
  241. .ctrl = OMAP2_IO_ADDRESS(OMAP243X_CTRL_BASE),
  242. .prm = OMAP2_IO_ADDRESS(OMAP2430_PRM_BASE),
  243. .cm = OMAP2_IO_ADDRESS(OMAP2430_CM_BASE),
  244. };
  245. void __init omap2_set_globals_243x(void)
  246. {
  247. omap2_globals = &omap243x_globals;
  248. __omap2_set_globals();
  249. }
  250. #endif
  251. #if defined(CONFIG_ARCH_OMAP3430)
  252. static struct omap_globals omap343x_globals = {
  253. .class = OMAP343X_CLASS,
  254. .tap = OMAP2_IO_ADDRESS(0x4830A000),
  255. .sdrc = OMAP2_IO_ADDRESS(OMAP343X_SDRC_BASE),
  256. .sms = OMAP2_IO_ADDRESS(OMAP343X_SMS_BASE),
  257. .ctrl = OMAP2_IO_ADDRESS(OMAP343X_CTRL_BASE),
  258. .prm = OMAP2_IO_ADDRESS(OMAP3430_PRM_BASE),
  259. .cm = OMAP2_IO_ADDRESS(OMAP3430_CM_BASE),
  260. };
  261. void __init omap2_set_globals_343x(void)
  262. {
  263. omap2_globals = &omap343x_globals;
  264. __omap2_set_globals();
  265. }
  266. #endif