debug.c 9.7 KB

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