debug.c 9.7 KB

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