debug.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. * linux/arch/m68k/atari/debug.c
  3. *
  4. * Atari debugging and serial console stuff
  5. *
  6. * Assembled of parts of former atari/config.c 97-12-18 by Roman Hodek
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file COPYING in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/types.h>
  13. #include <linux/tty.h>
  14. #include <linux/console.h>
  15. #include <linux/init.h>
  16. #include <linux/delay.h>
  17. #include <asm/atarihw.h>
  18. #include <asm/atariints.h>
  19. /* Flag that Modem1 port is already initialized and used */
  20. int atari_MFP_init_done;
  21. /* Flag that Modem1 port is already initialized and used */
  22. int atari_SCC_init_done;
  23. /* Can be set somewhere, if a SCC master reset has already be done and should
  24. * not be repeated; used by kgdb */
  25. int atari_SCC_reset_done;
  26. static struct console atari_console_driver = {
  27. .name = "debug",
  28. .flags = CON_PRINTBUFFER,
  29. .index = -1,
  30. };
  31. static inline void ata_mfp_out(char c)
  32. {
  33. while (!(mfp.trn_stat & 0x80)) /* wait for tx buf empty */
  34. barrier();
  35. mfp.usart_dta = c;
  36. }
  37. void atari_mfp_console_write(struct console *co, const char *str,
  38. unsigned int count)
  39. {
  40. while (count--) {
  41. if (*str == '\n')
  42. ata_mfp_out('\r');
  43. ata_mfp_out(*str++);
  44. }
  45. }
  46. static inline void ata_scc_out(char c)
  47. {
  48. do {
  49. MFPDELAY();
  50. } while (!(scc.cha_b_ctrl & 0x04)); /* wait for tx buf empty */
  51. MFPDELAY();
  52. scc.cha_b_data = c;
  53. }
  54. void atari_scc_console_write(struct console *co, const char *str,
  55. unsigned int count)
  56. {
  57. while (count--) {
  58. if (*str == '\n')
  59. ata_scc_out('\r');
  60. ata_scc_out(*str++);
  61. }
  62. }
  63. static inline void ata_midi_out(char c)
  64. {
  65. while (!(acia.mid_ctrl & ACIA_TDRE)) /* wait for tx buf empty */
  66. barrier();
  67. acia.mid_data = c;
  68. }
  69. void atari_midi_console_write(struct console *co, const char *str,
  70. unsigned int count)
  71. {
  72. while (count--) {
  73. if (*str == '\n')
  74. ata_midi_out('\r');
  75. ata_midi_out(*str++);
  76. }
  77. }
  78. static int ata_par_out(char c)
  79. {
  80. unsigned char tmp;
  81. /* This a some-seconds timeout in case no printer is connected */
  82. unsigned long i = loops_per_jiffy > 1 ? loops_per_jiffy : 10000000/HZ;
  83. while ((mfp.par_dt_reg & 1) && --i) /* wait for BUSY == L */
  84. ;
  85. if (!i)
  86. return 0;
  87. sound_ym.rd_data_reg_sel = 15; /* select port B */
  88. sound_ym.wd_data = c; /* put char onto port */
  89. sound_ym.rd_data_reg_sel = 14; /* select port A */
  90. tmp = sound_ym.rd_data_reg_sel;
  91. sound_ym.wd_data = tmp & ~0x20; /* set strobe L */
  92. MFPDELAY(); /* wait a bit */
  93. sound_ym.wd_data = tmp | 0x20; /* set strobe H */
  94. return 1;
  95. }
  96. static void atari_par_console_write(struct console *co, const char *str,
  97. unsigned int count)
  98. {
  99. static int printer_present = 1;
  100. if (!printer_present)
  101. return;
  102. while (count--) {
  103. if (*str == '\n') {
  104. if (!ata_par_out('\r')) {
  105. printer_present = 0;
  106. return;
  107. }
  108. }
  109. if (!ata_par_out(*str++)) {
  110. printer_present = 0;
  111. return;
  112. }
  113. }
  114. }
  115. #ifdef CONFIG_SERIAL_CONSOLE
  116. int atari_mfp_console_wait_key(struct console *co)
  117. {
  118. while (!(mfp.rcv_stat & 0x80)) /* wait for rx buf filled */
  119. barrier();
  120. return mfp.usart_dta;
  121. }
  122. int atari_scc_console_wait_key(struct console *co)
  123. {
  124. do {
  125. MFPDELAY();
  126. } while (!(scc.cha_b_ctrl & 0x01)); /* wait for rx buf filled */
  127. MFPDELAY();
  128. return scc.cha_b_data;
  129. }
  130. int atari_midi_console_wait_key(struct console *co)
  131. {
  132. while (!(acia.mid_ctrl & ACIA_RDRF)) /* wait for rx buf filled */
  133. barrier();
  134. return acia.mid_data;
  135. }
  136. #endif
  137. /*
  138. * The following two functions do a quick'n'dirty initialization of the MFP or
  139. * SCC serial ports. They're used by the debugging interface, kgdb, and the
  140. * serial console code.
  141. */
  142. #ifndef CONFIG_SERIAL_CONSOLE
  143. static void __init atari_init_mfp_port(int cflag)
  144. #else
  145. void atari_init_mfp_port(int cflag)
  146. #endif
  147. {
  148. /*
  149. * timer values for 1200...115200 bps; > 38400 select 110, 134, or 150
  150. * bps, resp., and work only correct if there's a RSVE or RSSPEED
  151. */
  152. static int baud_table[9] = { 16, 11, 8, 4, 2, 1, 175, 143, 128 };
  153. int baud = cflag & CBAUD;
  154. int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x04 : 0x06) : 0;
  155. int csize = ((cflag & CSIZE) == CS7) ? 0x20 : 0x00;
  156. if (cflag & CBAUDEX)
  157. baud += B38400;
  158. if (baud < B1200 || baud > B38400+2)
  159. baud = B9600; /* use default 9600bps for non-implemented rates */
  160. baud -= B1200; /* baud_table[] starts at 1200bps */
  161. mfp.trn_stat &= ~0x01; /* disable TX */
  162. mfp.usart_ctr = parity | csize | 0x88; /* 1:16 clk mode, 1 stop bit */
  163. mfp.tim_ct_cd &= 0x70; /* stop timer D */
  164. mfp.tim_dt_d = baud_table[baud];
  165. mfp.tim_ct_cd |= 0x01; /* start timer D, 1:4 */
  166. mfp.trn_stat |= 0x01; /* enable TX */
  167. atari_MFP_init_done = 1;
  168. }
  169. #define SCC_WRITE(reg, val) \
  170. do { \
  171. scc.cha_b_ctrl = (reg); \
  172. MFPDELAY(); \
  173. scc.cha_b_ctrl = (val); \
  174. MFPDELAY(); \
  175. } while (0)
  176. /* loops_per_jiffy isn't initialized yet, so we can't use udelay(). This does a
  177. * delay of ~ 60us. */
  178. #define LONG_DELAY() \
  179. do { \
  180. int i; \
  181. for (i = 100; i > 0; --i) \
  182. MFPDELAY(); \
  183. } while (0)
  184. #ifndef CONFIG_SERIAL_CONSOLE
  185. static void __init atari_init_scc_port(int cflag)
  186. #else
  187. void atari_init_scc_port(int cflag)
  188. #endif
  189. {
  190. extern int atari_SCC_reset_done;
  191. static int clksrc_table[9] =
  192. /* reg 11: 0x50 = BRG, 0x00 = RTxC, 0x28 = TRxC */
  193. { 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x00, 0x00 };
  194. static int brgsrc_table[9] =
  195. /* reg 14: 0 = RTxC, 2 = PCLK */
  196. { 2, 2, 2, 2, 2, 2, 0, 2, 2 };
  197. static int clkmode_table[9] =
  198. /* reg 4: 0x40 = x16, 0x80 = x32, 0xc0 = x64 */
  199. { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x80 };
  200. static int div_table[9] =
  201. /* reg12 (BRG low) */
  202. { 208, 138, 103, 50, 24, 11, 1, 0, 0 };
  203. int baud = cflag & CBAUD;
  204. int clksrc, clkmode, div, reg3, reg5;
  205. if (cflag & CBAUDEX)
  206. baud += B38400;
  207. if (baud < B1200 || baud > B38400+2)
  208. baud = B9600; /* use default 9600bps for non-implemented rates */
  209. baud -= B1200; /* tables starts at 1200bps */
  210. clksrc = clksrc_table[baud];
  211. clkmode = clkmode_table[baud];
  212. div = div_table[baud];
  213. if (ATARIHW_PRESENT(TT_MFP) && baud >= 6) {
  214. /* special treatment for TT, where rates >= 38400 are done via TRxC */
  215. clksrc = 0x28; /* TRxC */
  216. clkmode = baud == 6 ? 0xc0 :
  217. baud == 7 ? 0x80 : /* really 76800bps */
  218. 0x40; /* really 153600bps */
  219. div = 0;
  220. }
  221. reg3 = (cflag & CSIZE) == CS8 ? 0xc0 : 0x40;
  222. reg5 = (cflag & CSIZE) == CS8 ? 0x60 : 0x20 | 0x82 /* assert DTR/RTS */;
  223. (void)scc.cha_b_ctrl; /* reset reg pointer */
  224. SCC_WRITE(9, 0xc0); /* reset */
  225. LONG_DELAY(); /* extra delay after WR9 access */
  226. SCC_WRITE(4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03)
  227. : 0 | 0x04 /* 1 stopbit */ | clkmode);
  228. SCC_WRITE(3, reg3);
  229. SCC_WRITE(5, reg5);
  230. SCC_WRITE(9, 0); /* no interrupts */
  231. LONG_DELAY(); /* extra delay after WR9 access */
  232. SCC_WRITE(10, 0); /* NRZ mode */
  233. SCC_WRITE(11, clksrc); /* main clock source */
  234. SCC_WRITE(12, div); /* BRG value */
  235. SCC_WRITE(13, 0); /* BRG high byte */
  236. SCC_WRITE(14, brgsrc_table[baud]);
  237. SCC_WRITE(14, brgsrc_table[baud] | (div ? 1 : 0));
  238. SCC_WRITE(3, reg3 | 1);
  239. SCC_WRITE(5, reg5 | 8);
  240. atari_SCC_reset_done = 1;
  241. atari_SCC_init_done = 1;
  242. }
  243. #ifndef CONFIG_SERIAL_CONSOLE
  244. static void __init atari_init_midi_port(int cflag)
  245. #else
  246. void atari_init_midi_port(int cflag)
  247. #endif
  248. {
  249. int baud = cflag & CBAUD;
  250. int csize = ((cflag & CSIZE) == CS8) ? 0x10 : 0x00;
  251. /* warning 7N1 isn't possible! (instead 7O2 is used...) */
  252. int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x0c : 0x08) : 0x04;
  253. int div;
  254. /* 4800 selects 7812.5, 115200 selects 500000, all other (incl. 9600 as
  255. * default) the standard MIDI speed 31250. */
  256. if (cflag & CBAUDEX)
  257. baud += B38400;
  258. if (baud == B4800)
  259. div = ACIA_DIV64; /* really 7812.5 bps */
  260. else if (baud == B38400+2 /* 115200 */)
  261. div = ACIA_DIV1; /* really 500 kbps (does that work??) */
  262. else
  263. div = ACIA_DIV16; /* 31250 bps, standard for MIDI */
  264. /* RTS low, ints disabled */
  265. acia.mid_ctrl = div | csize | parity |
  266. ((atari_switches & ATARI_SWITCH_MIDI) ?
  267. ACIA_RHTID : ACIA_RLTID);
  268. }
  269. static int __init atari_debug_setup(char *arg)
  270. {
  271. if (!MACH_IS_ATARI)
  272. return 0;
  273. if (!strcmp(arg, "ser"))
  274. /* defaults to ser2 for a Falcon and ser1 otherwise */
  275. arg = MACH_IS_FALCON ? "ser2" : "ser1";
  276. if (!strcmp(arg, "ser1")) {
  277. /* ST-MFP Modem1 serial port */
  278. atari_init_mfp_port(B9600|CS8);
  279. atari_console_driver.write = atari_mfp_console_write;
  280. } else if (!strcmp(arg, "ser2")) {
  281. /* SCC Modem2 serial port */
  282. atari_init_scc_port(B9600|CS8);
  283. atari_console_driver.write = atari_scc_console_write;
  284. } else if (!strcmp(arg, "midi")) {
  285. /* MIDI port */
  286. atari_init_midi_port(B9600|CS8);
  287. atari_console_driver.write = atari_midi_console_write;
  288. } else if (!strcmp(arg, "par")) {
  289. /* parallel printer */
  290. atari_turnoff_irq(IRQ_MFP_BUSY); /* avoid ints */
  291. sound_ym.rd_data_reg_sel = 7; /* select mixer control */
  292. sound_ym.wd_data = 0xff; /* sound off, ports are output */
  293. sound_ym.rd_data_reg_sel = 15; /* select port B */
  294. sound_ym.wd_data = 0; /* no char */
  295. sound_ym.rd_data_reg_sel = 14; /* select port A */
  296. sound_ym.wd_data = sound_ym.rd_data_reg_sel | 0x20; /* strobe H */
  297. atari_console_driver.write = atari_par_console_write;
  298. }
  299. if (atari_console_driver.write)
  300. register_console(&atari_console_driver);
  301. return 0;
  302. }
  303. early_param("debug", atari_debug_setup);