common.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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/mux.h>
  29. #include <asm/arch/fpga.h>
  30. #include <asm/arch/clock.h>
  31. #define NO_LENGTH_CHECK 0xffffffff
  32. unsigned char omap_bootloader_tag[512];
  33. int omap_bootloader_tag_len;
  34. struct omap_board_config_kernel *omap_board_config;
  35. int omap_board_config_size;
  36. static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
  37. {
  38. struct omap_board_config_kernel *kinfo = NULL;
  39. int i;
  40. #ifdef CONFIG_OMAP_BOOT_TAG
  41. struct omap_board_config_entry *info = NULL;
  42. if (omap_bootloader_tag_len > 4)
  43. info = (struct omap_board_config_entry *) omap_bootloader_tag;
  44. while (info != NULL) {
  45. u8 *next;
  46. if (info->tag == tag) {
  47. if (skip == 0)
  48. break;
  49. skip--;
  50. }
  51. if ((info->len & 0x03) != 0) {
  52. /* We bail out to avoid an alignment fault */
  53. printk(KERN_ERR "OMAP peripheral config: Length (%d) not word-aligned (tag %04x)\n",
  54. info->len, info->tag);
  55. return NULL;
  56. }
  57. next = (u8 *) info + sizeof(*info) + info->len;
  58. if (next >= omap_bootloader_tag + omap_bootloader_tag_len)
  59. info = NULL;
  60. else
  61. info = (struct omap_board_config_entry *) next;
  62. }
  63. if (info != NULL) {
  64. /* Check the length as a lame attempt to check for
  65. * binary inconsistency. */
  66. if (len != NO_LENGTH_CHECK) {
  67. /* Word-align len */
  68. if (len & 0x03)
  69. len = (len + 3) & ~0x03;
  70. if (info->len != len) {
  71. printk(KERN_ERR "OMAP peripheral config: Length mismatch with tag %x (want %d, got %d)\n",
  72. tag, len, info->len);
  73. return NULL;
  74. }
  75. }
  76. if (len_out != NULL)
  77. *len_out = info->len;
  78. return info->data;
  79. }
  80. #endif
  81. /* Try to find the config from the board-specific structures
  82. * in the kernel. */
  83. for (i = 0; i < omap_board_config_size; i++) {
  84. if (omap_board_config[i].tag == tag) {
  85. if (skip == 0) {
  86. kinfo = &omap_board_config[i];
  87. break;
  88. } else {
  89. skip--;
  90. }
  91. }
  92. }
  93. if (kinfo == NULL)
  94. return NULL;
  95. return kinfo->data;
  96. }
  97. const void *__omap_get_config(u16 tag, size_t len, int nr)
  98. {
  99. return get_config(tag, len, nr, NULL);
  100. }
  101. EXPORT_SYMBOL(__omap_get_config);
  102. const void *omap_get_var_config(u16 tag, size_t *len)
  103. {
  104. return get_config(tag, NO_LENGTH_CHECK, 0, len);
  105. }
  106. EXPORT_SYMBOL(omap_get_var_config);
  107. static int __init omap_add_serial_console(void)
  108. {
  109. const struct omap_serial_console_config *con_info;
  110. const struct omap_uart_config *uart_info;
  111. static char speed[11], *opt = NULL;
  112. int line, i, uart_idx;
  113. uart_info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
  114. con_info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
  115. struct omap_serial_console_config);
  116. if (uart_info == NULL || con_info == NULL)
  117. return 0;
  118. if (con_info->console_uart == 0)
  119. return 0;
  120. if (con_info->console_speed) {
  121. snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
  122. opt = speed;
  123. }
  124. uart_idx = con_info->console_uart - 1;
  125. if (uart_idx >= OMAP_MAX_NR_PORTS) {
  126. printk(KERN_INFO "Console: external UART#%d. "
  127. "Not adding it as console this time.\n",
  128. uart_idx + 1);
  129. return 0;
  130. }
  131. if (!(uart_info->enabled_uarts & (1 << uart_idx))) {
  132. printk(KERN_ERR "Console: Selected UART#%d is "
  133. "not enabled for this platform\n",
  134. uart_idx + 1);
  135. return -1;
  136. }
  137. line = 0;
  138. for (i = 0; i < uart_idx; i++) {
  139. if (uart_info->enabled_uarts & (1 << i))
  140. line++;
  141. }
  142. return add_preferred_console("ttyS", line, opt);
  143. }
  144. console_initcall(omap_add_serial_console);
  145. /*
  146. * 32KHz clocksource ... always available, on pretty most chips except
  147. * OMAP 730 and 1510. Other timers could be used as clocksources, with
  148. * higher resolution in free-running counter modes (e.g. 12 MHz xtal),
  149. * but systems won't necessarily want to spend resources that way.
  150. */
  151. #if defined(CONFIG_ARCH_OMAP16XX)
  152. #define TIMER_32K_SYNCHRONIZED 0xfffbc410
  153. #elif defined(CONFIG_ARCH_OMAP24XX)
  154. #define TIMER_32K_SYNCHRONIZED (OMAP24XX_32KSYNCT_BASE + 0x10)
  155. #endif
  156. #ifdef TIMER_32K_SYNCHRONIZED
  157. #include <linux/clocksource.h>
  158. static cycle_t omap_32k_read(void)
  159. {
  160. return omap_readl(TIMER_32K_SYNCHRONIZED);
  161. }
  162. static struct clocksource clocksource_32k = {
  163. .name = "32k_counter",
  164. .rating = 250,
  165. .read = omap_32k_read,
  166. .mask = CLOCKSOURCE_MASK(32),
  167. .shift = 10,
  168. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  169. };
  170. static int __init omap_init_clocksource_32k(void)
  171. {
  172. static char err[] __initdata = KERN_ERR
  173. "%s: can't register clocksource!\n";
  174. if (cpu_is_omap16xx() || cpu_is_omap24xx()) {
  175. clocksource_32k.mult = clocksource_hz2mult(32768,
  176. clocksource_32k.shift);
  177. if (clocksource_register(&clocksource_32k))
  178. printk(err, clocksource_32k.name);
  179. }
  180. return 0;
  181. }
  182. arch_initcall(omap_init_clocksource_32k);
  183. #endif /* TIMER_32K_SYNCHRONIZED */