common.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 inconsistancy. */
  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. kinfo = &omap_board_config[i];
  86. break;
  87. }
  88. }
  89. if (kinfo == NULL)
  90. return NULL;
  91. return kinfo->data;
  92. }
  93. const void *__omap_get_config(u16 tag, size_t len, int nr)
  94. {
  95. return get_config(tag, len, nr, NULL);
  96. }
  97. EXPORT_SYMBOL(__omap_get_config);
  98. const void *omap_get_var_config(u16 tag, size_t *len)
  99. {
  100. return get_config(tag, NO_LENGTH_CHECK, 0, len);
  101. }
  102. EXPORT_SYMBOL(omap_get_var_config);
  103. static int __init omap_add_serial_console(void)
  104. {
  105. const struct omap_serial_console_config *con_info;
  106. const struct omap_uart_config *uart_info;
  107. static char speed[11], *opt = NULL;
  108. int line, i, uart_idx;
  109. uart_info = omap_get_config(OMAP_TAG_UART, struct omap_uart_config);
  110. con_info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
  111. struct omap_serial_console_config);
  112. if (uart_info == NULL || con_info == NULL)
  113. return 0;
  114. if (con_info->console_uart == 0)
  115. return 0;
  116. if (con_info->console_speed) {
  117. snprintf(speed, sizeof(speed), "%u", con_info->console_speed);
  118. opt = speed;
  119. }
  120. uart_idx = con_info->console_uart - 1;
  121. if (uart_idx >= OMAP_MAX_NR_PORTS) {
  122. printk(KERN_INFO "Console: external UART#%d. "
  123. "Not adding it as console this time.\n",
  124. uart_idx + 1);
  125. return 0;
  126. }
  127. if (!(uart_info->enabled_uarts & (1 << uart_idx))) {
  128. printk(KERN_ERR "Console: Selected UART#%d is "
  129. "not enabled for this platform\n",
  130. uart_idx + 1);
  131. return -1;
  132. }
  133. line = 0;
  134. for (i = 0; i < uart_idx; i++) {
  135. if (uart_info->enabled_uarts & (1 << i))
  136. line++;
  137. }
  138. return add_preferred_console("ttyS", line, opt);
  139. }
  140. console_initcall(omap_add_serial_console);