common.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/setup.h>
  28. #include <asm/arch/board.h>
  29. #include <asm/arch/mux.h>
  30. #include <asm/arch/fpga.h>
  31. #include "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 *info;
  107. info = omap_get_config(OMAP_TAG_SERIAL_CONSOLE,
  108. struct omap_serial_console_config);
  109. if (info != NULL && info->console_uart) {
  110. static char speed[11], *opt = NULL;
  111. if (info->console_speed) {
  112. snprintf(speed, sizeof(speed), "%u", info->console_speed);
  113. opt = speed;
  114. }
  115. return add_preferred_console("ttyS", info->console_uart - 1, opt);
  116. }
  117. return 0;
  118. }
  119. console_initcall(omap_add_serial_console);