debug.c 8.9 KB

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