early_printk.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. #ifdef CONFIG_BFIN_JTAG_COMM
  37. extern struct console *bfin_jc_early_init(void);
  38. #endif
  39. static struct console *early_console;
  40. /* Default console */
  41. #define DEFAULT_PORT 0
  42. #define DEFAULT_CFLAG CS8|B57600
  43. /* Default console for early crashes */
  44. #define DEFAULT_EARLY_PORT "serial,uart0,57600"
  45. #ifdef CONFIG_SERIAL_CORE
  46. /* What should get here is "0,57600" */
  47. static struct console * __init earlyserial_init(char *buf)
  48. {
  49. int baud, bit;
  50. char parity;
  51. unsigned int serial_port = DEFAULT_PORT;
  52. unsigned int cflag = DEFAULT_CFLAG;
  53. serial_port = simple_strtoul(buf, &buf, 10);
  54. buf++;
  55. cflag = 0;
  56. baud = simple_strtoul(buf, &buf, 10);
  57. switch (baud) {
  58. case 1200:
  59. cflag |= B1200;
  60. break;
  61. case 2400:
  62. cflag |= B2400;
  63. break;
  64. case 4800:
  65. cflag |= B4800;
  66. break;
  67. case 9600:
  68. cflag |= B9600;
  69. break;
  70. case 19200:
  71. cflag |= B19200;
  72. break;
  73. case 38400:
  74. cflag |= B38400;
  75. break;
  76. case 115200:
  77. cflag |= B115200;
  78. break;
  79. default:
  80. cflag |= B57600;
  81. }
  82. parity = buf[0];
  83. buf++;
  84. switch (parity) {
  85. case 'e':
  86. cflag |= PARENB;
  87. break;
  88. case 'o':
  89. cflag |= PARODD;
  90. break;
  91. }
  92. bit = simple_strtoul(buf, &buf, 10);
  93. switch (bit) {
  94. case 5:
  95. cflag |= CS5;
  96. break;
  97. case 6:
  98. cflag |= CS6;
  99. break;
  100. case 7:
  101. cflag |= CS7;
  102. break;
  103. default:
  104. cflag |= CS8;
  105. }
  106. #ifdef CONFIG_SERIAL_BFIN
  107. return bfin_earlyserial_init(serial_port, cflag);
  108. #else
  109. return NULL;
  110. #endif
  111. }
  112. #endif
  113. int __init setup_early_printk(char *buf)
  114. {
  115. /* Crashing in here would be really bad, so check both the var
  116. and the pointer before we start using it
  117. */
  118. if (!buf)
  119. return 0;
  120. if (!*buf)
  121. return 0;
  122. if (early_console != NULL)
  123. return 0;
  124. #ifdef CONFIG_SERIAL_BFIN
  125. /* Check for Blackfin Serial */
  126. if (!strncmp(buf, "serial,uart", 11)) {
  127. buf += 11;
  128. early_console = earlyserial_init(buf);
  129. }
  130. #endif
  131. #ifdef CONFIG_BFIN_JTAG_COMM
  132. /* Check for Blackfin JTAG */
  133. if (!strncmp(buf, "jtag", 4)) {
  134. buf += 4;
  135. early_console = bfin_jc_early_init();
  136. }
  137. #endif
  138. #ifdef CONFIG_FB
  139. /* TODO: add framebuffer console support */
  140. #endif
  141. if (likely(early_console)) {
  142. early_console->flags |= CON_BOOT;
  143. register_console(early_console);
  144. printk(KERN_INFO "early printk enabled on %s%d\n",
  145. early_console->name,
  146. early_console->index);
  147. }
  148. return 0;
  149. }
  150. /*
  151. * Set up a temporary Event Vector Table, so if something bad happens before
  152. * the kernel is fully started, it doesn't vector off into somewhere we don't
  153. * know
  154. */
  155. asmlinkage void __init init_early_exception_vectors(void)
  156. {
  157. SSYNC();
  158. /* cannot program in software:
  159. * evt0 - emulation (jtag)
  160. * evt1 - reset
  161. */
  162. bfin_write_EVT2(early_trap);
  163. bfin_write_EVT3(early_trap);
  164. bfin_write_EVT5(early_trap);
  165. bfin_write_EVT6(early_trap);
  166. bfin_write_EVT7(early_trap);
  167. bfin_write_EVT8(early_trap);
  168. bfin_write_EVT9(early_trap);
  169. bfin_write_EVT10(early_trap);
  170. bfin_write_EVT11(early_trap);
  171. bfin_write_EVT12(early_trap);
  172. bfin_write_EVT13(early_trap);
  173. bfin_write_EVT14(early_trap);
  174. bfin_write_EVT15(early_trap);
  175. CSYNC();
  176. /* Set all the return from interrupt, exception, NMI to a known place
  177. * so if we do a RETI, RETX or RETN by mistake - we go somewhere known
  178. * Note - don't change RETS - we are in a subroutine, or
  179. * RETE - since it might screw up if emulator is attached
  180. */
  181. asm("\tRETI = %0; RETX = %0; RETN = %0;\n"
  182. : : "p"(early_trap));
  183. }
  184. asmlinkage void __init early_trap_c(struct pt_regs *fp, void *retaddr)
  185. {
  186. /* This can happen before the uart is initialized, so initialize
  187. * the UART now
  188. */
  189. if (likely(early_console == NULL))
  190. setup_early_printk(DEFAULT_EARLY_PORT);
  191. dump_bfin_mem(fp);
  192. show_regs(fp);
  193. dump_bfin_trace_buffer();
  194. panic("Died early");
  195. }
  196. early_param("earlyprintk", setup_early_printk);