debug.c 9.3 KB

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