common.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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/config.h>
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/delay.h>
  15. #include <linux/pm.h>
  16. #include <linux/console.h>
  17. #include <linux/serial.h>
  18. #include <linux/tty.h>
  19. #include <linux/serial_8250.h>
  20. #include <linux/serial_reg.h>
  21. #include <linux/clk.h>
  22. #include <asm/hardware.h>
  23. #include <asm/system.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/mach/map.h>
  26. #include <asm/io.h>
  27. #include <asm/setup.h>
  28. #include <asm/arch/board.h>
  29. #include <asm/arch/mux.h>
  30. #include <asm/arch/fpga.h>
  31. #include <asm/arch/clock.h>
  32. #define NO_LENGTH_CHECK 0xffffffff
  33. unsigned char omap_bootloader_tag[512];
  34. int omap_bootloader_tag_len;
  35. struct omap_board_config_kernel *omap_board_config;
  36. int omap_board_config_size;
  37. static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
  38. {
  39. struct omap_board_config_kernel *kinfo = NULL;
  40. int i;
  41. #ifdef CONFIG_OMAP_BOOT_TAG
  42. struct omap_board_config_entry *info = NULL;
  43. if (omap_bootloader_tag_len > 4)
  44. info = (struct omap_board_config_entry *) omap_bootloader_tag;
  45. while (info != NULL) {
  46. u8 *next;
  47. if (info->tag == tag) {
  48. if (skip == 0)
  49. break;
  50. skip--;
  51. }
  52. if ((info->len & 0x03) != 0) {
  53. /* We bail out to avoid an alignment fault */
  54. printk(KERN_ERR "OMAP peripheral config: Length (%d) not word-aligned (tag %04x)\n",
  55. info->len, info->tag);
  56. return NULL;
  57. }
  58. next = (u8 *) info + sizeof(*info) + info->len;
  59. if (next >= omap_bootloader_tag + omap_bootloader_tag_len)
  60. info = NULL;
  61. else
  62. info = (struct omap_board_config_entry *) next;
  63. }
  64. if (info != NULL) {
  65. /* Check the length as a lame attempt to check for
  66. * binary inconsistancy. */
  67. if (len != NO_LENGTH_CHECK) {
  68. /* Word-align len */
  69. if (len & 0x03)
  70. len = (len + 3) & ~0x03;
  71. if (info->len != len) {
  72. printk(KERN_ERR "OMAP peripheral config: Length mismatch with tag %x (want %d, got %d)\n",
  73. tag, len, info->len);
  74. return NULL;
  75. }
  76. }
  77. if (len_out != NULL)
  78. *len_out = info->len;
  79. return info->data;
  80. }
  81. #endif
  82. /* Try to find the config from the board-specific structures
  83. * in the kernel. */
  84. for (i = 0; i < omap_board_config_size; i++) {
  85. if (omap_board_config[i].tag == tag) {
  86. kinfo = &omap_board_config[i];
  87. break;
  88. }
  89. }
  90. if (kinfo == NULL)
  91. return NULL;
  92. return kinfo->data;
  93. }
  94. const void *__omap_get_config(u16 tag, size_t len, int nr)
  95. {
  96. return get_config(tag, len, nr, NULL);
  97. }
  98. EXPORT_SYMBOL(__omap_get_config);
  99. const void *omap_get_var_config(u16 tag, size_t *len)
  100. {
  101. return get_config(tag, NO_LENGTH_CHECK, 0, len);
  102. }
  103. EXPORT_SYMBOL(omap_get_var_config);
  104. static int __init omap_add_serial_console(void)
  105. {
  106. const struct omap_serial_console_config *con_info;
  107. const struct omap_uart_config *uart_info;
  108. static char speed[11], *opt = NULL;
  109. int line, i, uart_idx;
  110. uart_info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
  111. con_info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
  112. struct omap_serial_console_config);
  113. if (uart_info == NULL || con_info == NULL)
  114. return 0;
  115. if (con_info->console_uart == 0)
  116. return 0;
  117. if (con_info->console_speed) {
  118. snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
  119. opt = speed;
  120. }
  121. uart_idx = con_info->console_uart - 1;
  122. if (uart_idx >= OMAP_MAX_NR_PORTS) {
  123. printk(KERN_INFO "Console: external UART#%d. "
  124. "Not adding it as console this time.\n",
  125. uart_idx + 1);
  126. return 0;
  127. }
  128. if (!(uart_info->enabled_uarts & (1 << uart_idx))) {
  129. printk(KERN_ERR "Console: Selected UART#%d is "
  130. "not enabled for this platform\n",
  131. uart_idx + 1);
  132. return -1;
  133. }
  134. line = 0;
  135. for (i = 0; i < uart_idx; i++) {
  136. if (uart_info->enabled_uarts & (1 << i))
  137. line++;
  138. }
  139. return add_preferred_console("ttyS", line, opt);
  140. }
  141. console_initcall(omap_add_serial_console);