common.c 6.5 KB

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