common.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <asm/hardware.h>
  22. #include <asm/system.h>
  23. #include <asm/pgtable.h>
  24. #include <asm/mach/map.h>
  25. #include <asm/hardware/clock.h>
  26. #include <asm/io.h>
  27. #include <asm/mach-types.h>
  28. #include <asm/setup.h>
  29. #include <asm/arch/board.h>
  30. #include <asm/arch/mux.h>
  31. #include <asm/arch/fpga.h>
  32. #include "clock.h"
  33. #define NO_LENGTH_CHECK 0xffffffff
  34. unsigned char omap_bootloader_tag[512];
  35. int omap_bootloader_tag_len;
  36. struct omap_board_config_kernel *omap_board_config;
  37. int omap_board_config_size;
  38. static const void *get_config(u16 tag, size_t len, int skip, size_t *len_out)
  39. {
  40. struct omap_board_config_kernel *kinfo = NULL;
  41. int i;
  42. #ifdef CONFIG_OMAP_BOOT_TAG
  43. struct omap_board_config_entry *info = NULL;
  44. if (omap_bootloader_tag_len > 4)
  45. info = (struct omap_board_config_entry *) omap_bootloader_tag;
  46. while (info != NULL) {
  47. u8 *next;
  48. if (info->tag == tag) {
  49. if (skip == 0)
  50. break;
  51. skip--;
  52. }
  53. if ((info->len & 0x03) != 0) {
  54. /* We bail out to avoid an alignment fault */
  55. printk(KERN_ERR "OMAP peripheral config: Length (%d) not word-aligned (tag %04x)\n",
  56. info->len, info->tag);
  57. return NULL;
  58. }
  59. next = (u8 *) info + sizeof(*info) + info->len;
  60. if (next >= omap_bootloader_tag + omap_bootloader_tag_len)
  61. info = NULL;
  62. else
  63. info = (struct omap_board_config_entry *) next;
  64. }
  65. if (info != NULL) {
  66. /* Check the length as a lame attempt to check for
  67. * binary inconsistancy. */
  68. if (len != NO_LENGTH_CHECK) {
  69. /* Word-align len */
  70. if (len & 0x03)
  71. len = (len + 3) & ~0x03;
  72. if (info->len != len) {
  73. printk(KERN_ERR "OMAP peripheral config: Length mismatch with tag %x (want %d, got %d)\n",
  74. tag, len, info->len);
  75. return NULL;
  76. }
  77. }
  78. if (len_out != NULL)
  79. *len_out = info->len;
  80. return info->data;
  81. }
  82. #endif
  83. /* Try to find the config from the board-specific structures
  84. * in the kernel. */
  85. for (i = 0; i < omap_board_config_size; i++) {
  86. if (omap_board_config[i].tag == tag) {
  87. kinfo = &omap_board_config[i];
  88. break;
  89. }
  90. }
  91. if (kinfo == NULL)
  92. return NULL;
  93. return kinfo->data;
  94. }
  95. const void *__omap_get_config(u16 tag, size_t len, int nr)
  96. {
  97. return get_config(tag, len, nr, NULL);
  98. }
  99. EXPORT_SYMBOL(__omap_get_config);
  100. const void *omap_get_var_config(u16 tag, size_t *len)
  101. {
  102. return get_config(tag, NO_LENGTH_CHECK, 0, len);
  103. }
  104. EXPORT_SYMBOL(omap_get_var_config);
  105. static int __init omap_add_serial_console(void)
  106. {
  107. const struct omap_serial_console_config *info;
  108. info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
  109. struct omap_serial_console_config);
  110. if (info != NULL && info->console_uart) {
  111. static char speed[11], *opt = NULL;
  112. if (info->console_speed) {
  113. snprintf(speed, sizeof(speed), "%u", info->console_speed);
  114. opt = speed;
  115. }
  116. return add_preferred_console("ttyS", info->console_uart - 1, opt);
  117. }
  118. return 0;
  119. }
  120. console_initcall(omap_add_serial_console);