early_printk.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * File: arch/blackfin/kernel/early_printk.c
  3. * Based on: arch/x86_64/kernel/early_printk.c
  4. * Author: Robin Getz <rgetz@blackfin.uclinux.org
  5. *
  6. * Created: 14Aug2007
  7. * Description: allow a console to be used for early printk
  8. *
  9. * Modified:
  10. * Copyright 2004-2007 Analog Devices Inc.
  11. *
  12. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/init.h>
  26. #include <linux/serial_core.h>
  27. #include <linux/console.h>
  28. #include <linux/string.h>
  29. #include <asm/blackfin.h>
  30. #include <asm/irq_handler.h>
  31. #include <asm/early_printk.h>
  32. #ifdef CONFIG_SERIAL_BFIN
  33. extern struct console *bfin_earlyserial_init(unsigned int port,
  34. unsigned int cflag);
  35. #endif
  36. static struct console *early_console;
  37. /* Default console */
  38. #define DEFAULT_PORT 0
  39. #define DEFAULT_CFLAG CS8|B57600
  40. /* Default console for early crashes */
  41. #define DEFAULT_EARLY_PORT "serial,uart0,57600"
  42. #ifdef CONFIG_SERIAL_CORE
  43. /* What should get here is "0,57600" */
  44. static struct console * __init earlyserial_init(char *buf)
  45. {
  46. int baud, bit;
  47. char parity;
  48. unsigned int serial_port = DEFAULT_PORT;
  49. unsigned int cflag = DEFAULT_CFLAG;
  50. serial_port = simple_strtoul(buf, &buf, 10);
  51. buf++;
  52. cflag = 0;
  53. baud = simple_strtoul(buf, &buf, 10);
  54. switch (baud) {
  55. case 1200:
  56. cflag |= B1200;
  57. break;
  58. case 2400:
  59. cflag |= B2400;
  60. break;
  61. case 4800:
  62. cflag |= B4800;
  63. break;
  64. case 9600:
  65. cflag |= B9600;
  66. break;
  67. case 19200:
  68. cflag |= B19200;
  69. break;
  70. case 38400:
  71. cflag |= B38400;
  72. break;
  73. case 115200:
  74. cflag |= B115200;
  75. break;
  76. default:
  77. cflag |= B57600;
  78. }
  79. parity = buf[0];
  80. buf++;
  81. switch (parity) {
  82. case 'e':
  83. cflag |= PARENB;
  84. break;
  85. case 'o':
  86. cflag |= PARODD;
  87. break;
  88. }
  89. bit = simple_strtoul(buf, &buf, 10);
  90. switch (bit) {
  91. case 5:
  92. cflag |= CS5;
  93. break;
  94. case 6:
  95. cflag |= CS5;
  96. break;
  97. case 7:
  98. cflag |= CS5;
  99. break;
  100. default:
  101. cflag |= CS8;
  102. }
  103. #ifdef CONFIG_SERIAL_BFIN
  104. return bfin_earlyserial_init(serial_port, cflag);
  105. #else
  106. return NULL;
  107. #endif
  108. }
  109. #endif
  110. int __init setup_early_printk(char *buf)
  111. {
  112. /* Crashing in here would be really bad, so check both the var
  113. and the pointer before we start using it
  114. */
  115. if (!buf)
  116. return 0;
  117. if (!*buf)
  118. return 0;
  119. if (early_console != NULL)
  120. return 0;
  121. #ifdef CONFIG_SERIAL_BFIN
  122. /* Check for Blackfin Serial */
  123. if (!strncmp(buf, "serial,uart", 11)) {
  124. buf += 11;
  125. early_console = earlyserial_init(buf);
  126. }
  127. #endif
  128. #ifdef CONFIG_FB
  129. /* TODO: add framebuffer console support */
  130. #endif
  131. if (likely(early_console)) {
  132. early_console->flags |= CON_BOOT;
  133. register_console(early_console);
  134. printk(KERN_INFO "early printk enabled on %s%d\n",
  135. early_console->name,
  136. early_console->index);
  137. }
  138. return 0;
  139. }
  140. /*
  141. * Set up a temporary Event Vector Table, so if something bad happens before
  142. * the kernel is fully started, it doesn't vector off into somewhere we don't
  143. * know
  144. */
  145. asmlinkage void __init init_early_exception_vectors(void)
  146. {
  147. SSYNC();
  148. /* cannot program in software:
  149. * evt0 - emulation (jtag)
  150. * evt1 - reset
  151. */
  152. bfin_write_EVT2(early_trap);
  153. bfin_write_EVT3(early_trap);
  154. bfin_write_EVT5(early_trap);
  155. bfin_write_EVT6(early_trap);
  156. bfin_write_EVT7(early_trap);
  157. bfin_write_EVT8(early_trap);
  158. bfin_write_EVT9(early_trap);
  159. bfin_write_EVT10(early_trap);
  160. bfin_write_EVT11(early_trap);
  161. bfin_write_EVT12(early_trap);
  162. bfin_write_EVT13(early_trap);
  163. bfin_write_EVT14(early_trap);
  164. bfin_write_EVT15(early_trap);
  165. CSYNC();
  166. /* Set all the return from interrupt, exception, NMI to a known place
  167. * so if we do a RETI, RETX or RETN by mistake - we go somewhere known
  168. * Note - don't change RETS - we are in a subroutine, or
  169. * RETE - since it might screw up if emulator is attached
  170. */
  171. asm("\tRETI = %0; RETX = %0; RETN = %0;\n"
  172. : : "p"(early_trap));
  173. }
  174. asmlinkage void __init early_trap_c(struct pt_regs *fp, void *retaddr)
  175. {
  176. /* This can happen before the uart is initialized, so initialize
  177. * the UART now
  178. */
  179. if (likely(early_console == NULL))
  180. setup_early_printk(DEFAULT_EARLY_PORT);
  181. dump_bfin_mem(fp);
  182. show_regs(fp);
  183. dump_bfin_trace_buffer();
  184. panic("Died early");
  185. }
  186. early_param("earlyprintk", setup_early_printk);