debugport.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Copyright (C) 2003, Axis Communications AB.
  3. */
  4. #include <linux/console.h>
  5. #include <linux/kernel.h>
  6. #include <linux/init.h>
  7. #include <linux/string.h>
  8. #include <hwregs/reg_rdwr.h>
  9. #include <hwregs/reg_map.h>
  10. #include <hwregs/ser_defs.h>
  11. #include <hwregs/dma_defs.h>
  12. #include <mach/pinmux.h>
  13. struct dbg_port
  14. {
  15. unsigned char nbr;
  16. unsigned long instance;
  17. unsigned int started;
  18. unsigned long baudrate;
  19. unsigned char parity;
  20. unsigned int bits;
  21. };
  22. struct dbg_port ports[] =
  23. {
  24. {
  25. 0,
  26. regi_ser0,
  27. 0,
  28. 115200,
  29. 'N',
  30. 8
  31. },
  32. {
  33. 1,
  34. regi_ser1,
  35. 0,
  36. 115200,
  37. 'N',
  38. 8
  39. },
  40. {
  41. 2,
  42. regi_ser2,
  43. 0,
  44. 115200,
  45. 'N',
  46. 8
  47. },
  48. {
  49. 3,
  50. regi_ser3,
  51. 0,
  52. 115200,
  53. 'N',
  54. 8
  55. },
  56. #if CONFIG_ETRAX_SERIAL_PORTS == 5
  57. {
  58. 4,
  59. regi_ser4,
  60. 0,
  61. 115200,
  62. 'N',
  63. 8
  64. },
  65. #endif
  66. };
  67. static struct dbg_port *port =
  68. #if defined(CONFIG_ETRAX_DEBUG_PORT0)
  69. &ports[0];
  70. #elif defined(CONFIG_ETRAX_DEBUG_PORT1)
  71. &ports[1];
  72. #elif defined(CONFIG_ETRAX_DEBUG_PORT2)
  73. &ports[2];
  74. #elif defined(CONFIG_ETRAX_DEBUG_PORT3)
  75. &ports[3];
  76. #else
  77. NULL;
  78. #endif
  79. #ifdef CONFIG_ETRAX_KGDB
  80. static struct dbg_port *kgdb_port =
  81. #if defined(CONFIG_ETRAX_KGDB_PORT0)
  82. &ports[0];
  83. #elif defined(CONFIG_ETRAX_KGDB_PORT1)
  84. &ports[1];
  85. #elif defined(CONFIG_ETRAX_KGDB_PORT2)
  86. &ports[2];
  87. #elif defined(CONFIG_ETRAX_KGDB_PORT3)
  88. &ports[3];
  89. #elif defined(CONFIG_ETRAX_KGDB_PORT4)
  90. &ports[4];
  91. #else
  92. NULL;
  93. #endif
  94. #endif
  95. static void start_port(struct dbg_port *p)
  96. {
  97. /* Set up serial port registers */
  98. reg_ser_rw_tr_ctrl tr_ctrl = {0};
  99. reg_ser_rw_tr_dma_en tr_dma_en = {0};
  100. reg_ser_rw_rec_ctrl rec_ctrl = {0};
  101. reg_ser_rw_tr_baud_div tr_baud_div = {0};
  102. reg_ser_rw_rec_baud_div rec_baud_div = {0};
  103. if (!p || p->started)
  104. return;
  105. p->started = 1;
  106. if (p->nbr == 1)
  107. crisv32_pinmux_alloc_fixed(pinmux_ser1);
  108. else if (p->nbr == 2)
  109. crisv32_pinmux_alloc_fixed(pinmux_ser2);
  110. else if (p->nbr == 3)
  111. crisv32_pinmux_alloc_fixed(pinmux_ser3);
  112. #if CONFIG_ETRAX_SERIAL_PORTS == 5
  113. else if (p->nbr == 4)
  114. crisv32_pinmux_alloc_fixed(pinmux_ser4);
  115. #endif
  116. tr_ctrl.base_freq = rec_ctrl.base_freq = regk_ser_f29_493;
  117. tr_dma_en.en = rec_ctrl.dma_mode = regk_ser_no;
  118. tr_baud_div.div = rec_baud_div.div = 29493000 / p->baudrate / 8;
  119. tr_ctrl.en = rec_ctrl.en = 1;
  120. if (p->parity == 'O') {
  121. tr_ctrl.par_en = regk_ser_yes;
  122. tr_ctrl.par = regk_ser_odd;
  123. rec_ctrl.par_en = regk_ser_yes;
  124. rec_ctrl.par = regk_ser_odd;
  125. } else if (p->parity == 'E') {
  126. tr_ctrl.par_en = regk_ser_yes;
  127. tr_ctrl.par = regk_ser_even;
  128. rec_ctrl.par_en = regk_ser_yes;
  129. rec_ctrl.par = regk_ser_odd;
  130. }
  131. if (p->bits == 7) {
  132. tr_ctrl.data_bits = regk_ser_bits7;
  133. rec_ctrl.data_bits = regk_ser_bits7;
  134. }
  135. REG_WR (ser, p->instance, rw_tr_baud_div, tr_baud_div);
  136. REG_WR (ser, p->instance, rw_rec_baud_div, rec_baud_div);
  137. REG_WR (ser, p->instance, rw_tr_dma_en, tr_dma_en);
  138. REG_WR (ser, p->instance, rw_tr_ctrl, tr_ctrl);
  139. REG_WR (ser, p->instance, rw_rec_ctrl, rec_ctrl);
  140. }
  141. #ifdef CONFIG_ETRAX_KGDB
  142. /* Use polling to get a single character from the kernel debug port */
  143. int getDebugChar(void)
  144. {
  145. reg_ser_rs_stat_din stat;
  146. reg_ser_rw_ack_intr ack_intr = { 0 };
  147. do {
  148. stat = REG_RD(ser, kgdb_port->instance, rs_stat_din);
  149. } while (!stat.dav);
  150. /* Ack the data_avail interrupt. */
  151. ack_intr.dav = 1;
  152. REG_WR(ser, kgdb_port->instance, rw_ack_intr, ack_intr);
  153. return stat.data;
  154. }
  155. /* Use polling to put a single character to the kernel debug port */
  156. void putDebugChar(int val)
  157. {
  158. reg_ser_r_stat_din stat;
  159. do {
  160. stat = REG_RD(ser, kgdb_port->instance, r_stat_din);
  161. } while (!stat.tr_rdy);
  162. REG_WR_INT(ser, kgdb_port->instance, rw_dout, val);
  163. }
  164. #endif /* CONFIG_ETRAX_KGDB */
  165. static void __init early_putch(int c)
  166. {
  167. reg_ser_r_stat_din stat;
  168. /* Wait until transmitter is ready and send. */
  169. do
  170. stat = REG_RD(ser, port->instance, r_stat_din);
  171. while (!stat.tr_rdy);
  172. REG_WR_INT(ser, port->instance, rw_dout, c);
  173. }
  174. static void __init
  175. early_console_write(struct console *con, const char *s, unsigned n)
  176. {
  177. extern void reset_watchdog(void);
  178. int i;
  179. /* Send data. */
  180. for (i = 0; i < n; i++) {
  181. /* TODO: the '\n' -> '\n\r' translation should be done at the
  182. receiver. Remove it when the serial driver removes it. */
  183. if (s[i] == '\n')
  184. early_putch('\r');
  185. early_putch(s[i]);
  186. reset_watchdog();
  187. }
  188. }
  189. static struct console early_console_dev __initdata = {
  190. .name = "early",
  191. .write = early_console_write,
  192. .flags = CON_PRINTBUFFER | CON_BOOT,
  193. .index = -1
  194. };
  195. /* Register console for printk's, etc. */
  196. int __init init_etrax_debug(void)
  197. {
  198. start_port(port);
  199. /* Register an early console if a debug port was chosen. */
  200. register_console(&early_console_dev);
  201. #ifdef CONFIG_ETRAX_KGDB
  202. start_port(kgdb_port);
  203. #endif /* CONFIG_ETRAX_KGDB */
  204. return 0;
  205. }