2 * linux/arch/m68k/atari/debug.c
4 * Atari debugging and serial console stuff
6 * Assembled of parts of former atari/config.c 97-12-18 by Roman Hodek
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
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>
19 #include <asm/atarihw.h>
20 #include <asm/atariints.h>
22 extern char m68k_debug_device[];
24 /* Flag that Modem1 port is already initialized and used */
25 int atari_MFP_init_done;
26 /* Flag that Modem1 port is already initialized and used */
27 int atari_SCC_init_done;
28 /* Can be set somewhere, if a SCC master reset has already be done and should
29 * not be repeated; used by kgdb */
30 int atari_SCC_reset_done;
32 static struct console atari_console_driver = {
34 .flags = CON_PRINTBUFFER,
39 static inline void ata_mfp_out (char c)
41 while (!(mfp.trn_stat & 0x80)) /* wait for tx buf empty */
46 void atari_mfp_console_write (struct console *co, const char *str,
52 ata_mfp_out( *str++ );
56 static inline void ata_scc_out (char c)
60 } while (!(scc.cha_b_ctrl & 0x04)); /* wait for tx buf empty */
65 void atari_scc_console_write (struct console *co, const char *str,
71 ata_scc_out( *str++ );
75 static inline void ata_midi_out (char c)
77 while (!(acia.mid_ctrl & ACIA_TDRE)) /* wait for tx buf empty */
82 void atari_midi_console_write (struct console *co, const char *str,
88 ata_midi_out( *str++ );
92 static int ata_par_out (char c)
95 /* This a some-seconds timeout in case no printer is connected */
96 unsigned long i = loops_per_jiffy > 1 ? loops_per_jiffy : 10000000/HZ;
98 while( (mfp.par_dt_reg & 1) && --i ) /* wait for BUSY == L */
102 sound_ym.rd_data_reg_sel = 15; /* select port B */
103 sound_ym.wd_data = c; /* put char onto port */
104 sound_ym.rd_data_reg_sel = 14; /* select port A */
105 tmp = sound_ym.rd_data_reg_sel;
106 sound_ym.wd_data = tmp & ~0x20; /* set strobe L */
107 MFPDELAY(); /* wait a bit */
108 sound_ym.wd_data = tmp | 0x20; /* set strobe H */
112 static void atari_par_console_write (struct console *co, const char *str,
115 static int printer_present = 1;
117 if (!printer_present)
122 if (!ata_par_out( '\r' )) {
126 if (!ata_par_out( *str++ )) {
133 #ifdef CONFIG_SERIAL_CONSOLE
134 int atari_mfp_console_wait_key(struct console *co)
136 while( !(mfp.rcv_stat & 0x80) ) /* wait for rx buf filled */
138 return( mfp.usart_dta );
141 int atari_scc_console_wait_key(struct console *co)
145 } while( !(scc.cha_b_ctrl & 0x01) ); /* wait for rx buf filled */
147 return( scc.cha_b_data );
150 int atari_midi_console_wait_key(struct console *co)
152 while( !(acia.mid_ctrl & ACIA_RDRF) ) /* wait for rx buf filled */
154 return( acia.mid_data );
158 /* The following two functions do a quick'n'dirty initialization of the MFP or
159 * SCC serial ports. They're used by the debugging interface, kgdb, and the
160 * serial console code. */
161 #ifndef CONFIG_SERIAL_CONSOLE
162 static void __init atari_init_mfp_port( int cflag )
164 void atari_init_mfp_port( int cflag )
167 /* timer values for 1200...115200 bps; > 38400 select 110, 134, or 150
168 * bps, resp., and work only correct if there's a RSVE or RSSPEED */
169 static int baud_table[9] = { 16, 11, 8, 4, 2, 1, 175, 143, 128 };
170 int baud = cflag & CBAUD;
171 int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x04 : 0x06) : 0;
172 int csize = ((cflag & CSIZE) == CS7) ? 0x20 : 0x00;
176 if (baud < B1200 || baud > B38400+2)
177 baud = B9600; /* use default 9600bps for non-implemented rates */
178 baud -= B1200; /* baud_table[] starts at 1200bps */
180 mfp.trn_stat &= ~0x01; /* disable TX */
181 mfp.usart_ctr = parity | csize | 0x88; /* 1:16 clk mode, 1 stop bit */
182 mfp.tim_ct_cd &= 0x70; /* stop timer D */
183 mfp.tim_dt_d = baud_table[baud];
184 mfp.tim_ct_cd |= 0x01; /* start timer D, 1:4 */
185 mfp.trn_stat |= 0x01; /* enable TX */
187 atari_MFP_init_done = 1;
190 #define SCC_WRITE(reg,val) \
192 scc.cha_b_ctrl = (reg); \
194 scc.cha_b_ctrl = (val); \
198 /* loops_per_jiffy isn't initialized yet, so we can't use udelay(). This does a
199 * delay of ~ 60us. */
200 #define LONG_DELAY() \
203 for( i = 100; i > 0; --i ) \
207 #ifndef CONFIG_SERIAL_CONSOLE
208 static void __init atari_init_scc_port( int cflag )
210 void atari_init_scc_port( int cflag )
213 extern int atari_SCC_reset_done;
214 static int clksrc_table[9] =
215 /* reg 11: 0x50 = BRG, 0x00 = RTxC, 0x28 = TRxC */
216 { 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x00, 0x00 };
217 static int brgsrc_table[9] =
218 /* reg 14: 0 = RTxC, 2 = PCLK */
219 { 2, 2, 2, 2, 2, 2, 0, 2, 2 };
220 static int clkmode_table[9] =
221 /* reg 4: 0x40 = x16, 0x80 = x32, 0xc0 = x64 */
222 { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x80 };
223 static int div_table[9] =
224 /* reg12 (BRG low) */
225 { 208, 138, 103, 50, 24, 11, 1, 0, 0 };
227 int baud = cflag & CBAUD;
228 int clksrc, clkmode, div, reg3, reg5;
232 if (baud < B1200 || baud > B38400+2)
233 baud = B9600; /* use default 9600bps for non-implemented rates */
234 baud -= B1200; /* tables starts at 1200bps */
236 clksrc = clksrc_table[baud];
237 clkmode = clkmode_table[baud];
238 div = div_table[baud];
239 if (ATARIHW_PRESENT(TT_MFP) && baud >= 6) {
240 /* special treatment for TT, where rates >= 38400 are done via TRxC */
241 clksrc = 0x28; /* TRxC */
242 clkmode = baud == 6 ? 0xc0 :
243 baud == 7 ? 0x80 : /* really 76800bps */
244 0x40; /* really 153600bps */
248 reg3 = (cflag & CSIZE) == CS8 ? 0xc0 : 0x40;
249 reg5 = (cflag & CSIZE) == CS8 ? 0x60 : 0x20 | 0x82 /* assert DTR/RTS */;
251 (void)scc.cha_b_ctrl; /* reset reg pointer */
252 SCC_WRITE( 9, 0xc0 ); /* reset */
253 LONG_DELAY(); /* extra delay after WR9 access */
254 SCC_WRITE( 4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03) : 0 |
255 0x04 /* 1 stopbit */ |
257 SCC_WRITE( 3, reg3 );
258 SCC_WRITE( 5, reg5 );
259 SCC_WRITE( 9, 0 ); /* no interrupts */
260 LONG_DELAY(); /* extra delay after WR9 access */
261 SCC_WRITE( 10, 0 ); /* NRZ mode */
262 SCC_WRITE( 11, clksrc ); /* main clock source */
263 SCC_WRITE( 12, div ); /* BRG value */
264 SCC_WRITE( 13, 0 ); /* BRG high byte */
265 SCC_WRITE( 14, brgsrc_table[baud] );
266 SCC_WRITE( 14, brgsrc_table[baud] | (div ? 1 : 0) );
267 SCC_WRITE( 3, reg3 | 1 );
268 SCC_WRITE( 5, reg5 | 8 );
270 atari_SCC_reset_done = 1;
271 atari_SCC_init_done = 1;
274 #ifndef CONFIG_SERIAL_CONSOLE
275 static void __init atari_init_midi_port( int cflag )
277 void atari_init_midi_port( int cflag )
280 int baud = cflag & CBAUD;
281 int csize = ((cflag & CSIZE) == CS8) ? 0x10 : 0x00;
282 /* warning 7N1 isn't possible! (instead 7O2 is used...) */
283 int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x0c : 0x08) : 0x04;
286 /* 4800 selects 7812.5, 115200 selects 500000, all other (incl. 9600 as
287 * default) the standard MIDI speed 31250. */
291 div = ACIA_DIV64; /* really 7812.5 bps */
292 else if (baud == B38400+2 /* 115200 */)
293 div = ACIA_DIV1; /* really 500 kbps (does that work??) */
295 div = ACIA_DIV16; /* 31250 bps, standard for MIDI */
297 /* RTS low, ints disabled */
298 acia.mid_ctrl = div | csize | parity |
299 ((atari_switches & ATARI_SWITCH_MIDI) ?
300 ACIA_RHTID : ACIA_RLTID);
303 void __init atari_debug_init(void)
305 if (!strcmp( m68k_debug_device, "ser" )) {
306 /* defaults to ser2 for a Falcon and ser1 otherwise */
307 strcpy( m68k_debug_device, MACH_IS_FALCON ? "ser2" : "ser1" );
311 if (!strcmp( m68k_debug_device, "ser1" )) {
312 /* ST-MFP Modem1 serial port */
313 atari_init_mfp_port( B9600|CS8 );
314 atari_console_driver.write = atari_mfp_console_write;
316 else if (!strcmp( m68k_debug_device, "ser2" )) {
317 /* SCC Modem2 serial port */
318 atari_init_scc_port( B9600|CS8 );
319 atari_console_driver.write = atari_scc_console_write;
321 else if (!strcmp( m68k_debug_device, "midi" )) {
323 atari_init_midi_port( B9600|CS8 );
324 atari_console_driver.write = atari_midi_console_write;
326 else if (!strcmp( m68k_debug_device, "par" )) {
327 /* parallel printer */
328 atari_turnoff_irq( IRQ_MFP_BUSY ); /* avoid ints */
329 sound_ym.rd_data_reg_sel = 7; /* select mixer control */
330 sound_ym.wd_data = 0xff; /* sound off, ports are output */
331 sound_ym.rd_data_reg_sel = 15; /* select port B */
332 sound_ym.wd_data = 0; /* no char */
333 sound_ym.rd_data_reg_sel = 14; /* select port A */
334 sound_ym.wd_data = sound_ym.rd_data_reg_sel | 0x20; /* strobe H */
335 atari_console_driver.write = atari_par_console_write;
337 if (atari_console_driver.write)
338 register_console(&atari_console_driver);