11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/arch/m68k/atari/debug.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Atari debugging and serial console stuff 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Assembled of parts of former atari/config.c 97-12-18 by Roman Hodek 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * This file is subject to the terms and conditions of the GNU General Public 91da177e4SLinus Torvalds * License. See the file COPYING in the main directory of this archive 101da177e4SLinus Torvalds * for more details. 111da177e4SLinus Torvalds */ 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds #include <linux/types.h> 141da177e4SLinus Torvalds #include <linux/tty.h> 151da177e4SLinus Torvalds #include <linux/console.h> 161da177e4SLinus Torvalds #include <linux/init.h> 171da177e4SLinus Torvalds #include <linux/delay.h> 18a3b2004aSAdrian Bunk #include <linux/module.h> 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds #include <asm/atarihw.h> 211da177e4SLinus Torvalds #include <asm/atariints.h> 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds /* Can be set somewhere, if a SCC master reset has already be done and should 241da177e4SLinus Torvalds * not be repeated; used by kgdb */ 251da177e4SLinus Torvalds int atari_SCC_reset_done; 26a3b2004aSAdrian Bunk EXPORT_SYMBOL(atari_SCC_reset_done); 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds static struct console atari_console_driver = { 291da177e4SLinus Torvalds .name = "debug", 301da177e4SLinus Torvalds .flags = CON_PRINTBUFFER, 311da177e4SLinus Torvalds .index = -1, 321da177e4SLinus Torvalds }; 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds static inline void ata_mfp_out(char c) 361da177e4SLinus Torvalds { 373d92e8f3SGeert Uytterhoeven while (!(st_mfp.trn_stat & 0x80)) /* wait for tx buf empty */ 381da177e4SLinus Torvalds barrier(); 393d92e8f3SGeert Uytterhoeven st_mfp.usart_dta = c; 401da177e4SLinus Torvalds } 411da177e4SLinus Torvalds 425575d0a3SAdrian Bunk static void atari_mfp_console_write(struct console *co, const char *str, 431da177e4SLinus Torvalds unsigned int count) 441da177e4SLinus Torvalds { 451da177e4SLinus Torvalds while (count--) { 461da177e4SLinus Torvalds if (*str == '\n') 471da177e4SLinus Torvalds ata_mfp_out('\r'); 481da177e4SLinus Torvalds ata_mfp_out(*str++); 491da177e4SLinus Torvalds } 501da177e4SLinus Torvalds } 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds static inline void ata_scc_out(char c) 531da177e4SLinus Torvalds { 541da177e4SLinus Torvalds do { 551da177e4SLinus Torvalds MFPDELAY(); 56*de339e4bSGeert Uytterhoeven } while (!(atari_scc.cha_b_ctrl & 0x04)); /* wait for tx buf empty */ 571da177e4SLinus Torvalds MFPDELAY(); 58*de339e4bSGeert Uytterhoeven atari_scc.cha_b_data = c; 591da177e4SLinus Torvalds } 601da177e4SLinus Torvalds 615575d0a3SAdrian Bunk static void atari_scc_console_write(struct console *co, const char *str, 621da177e4SLinus Torvalds unsigned int count) 631da177e4SLinus Torvalds { 641da177e4SLinus Torvalds while (count--) { 651da177e4SLinus Torvalds if (*str == '\n') 661da177e4SLinus Torvalds ata_scc_out('\r'); 671da177e4SLinus Torvalds ata_scc_out(*str++); 681da177e4SLinus Torvalds } 691da177e4SLinus Torvalds } 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds static inline void ata_midi_out(char c) 721da177e4SLinus Torvalds { 731da177e4SLinus Torvalds while (!(acia.mid_ctrl & ACIA_TDRE)) /* wait for tx buf empty */ 741da177e4SLinus Torvalds barrier(); 751da177e4SLinus Torvalds acia.mid_data = c; 761da177e4SLinus Torvalds } 771da177e4SLinus Torvalds 785575d0a3SAdrian Bunk static void atari_midi_console_write(struct console *co, const char *str, 791da177e4SLinus Torvalds unsigned int count) 801da177e4SLinus Torvalds { 811da177e4SLinus Torvalds while (count--) { 821da177e4SLinus Torvalds if (*str == '\n') 831da177e4SLinus Torvalds ata_midi_out('\r'); 841da177e4SLinus Torvalds ata_midi_out(*str++); 851da177e4SLinus Torvalds } 861da177e4SLinus Torvalds } 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds static int ata_par_out(char c) 891da177e4SLinus Torvalds { 901da177e4SLinus Torvalds unsigned char tmp; 911da177e4SLinus Torvalds /* This a some-seconds timeout in case no printer is connected */ 921da177e4SLinus Torvalds unsigned long i = loops_per_jiffy > 1 ? loops_per_jiffy : 10000000/HZ; 931da177e4SLinus Torvalds 943d92e8f3SGeert Uytterhoeven while ((st_mfp.par_dt_reg & 1) && --i) /* wait for BUSY == L */ 951da177e4SLinus Torvalds ; 966ff5801aSRoman Zippel if (!i) 976ff5801aSRoman Zippel return 0; 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds sound_ym.rd_data_reg_sel = 15; /* select port B */ 1001da177e4SLinus Torvalds sound_ym.wd_data = c; /* put char onto port */ 1011da177e4SLinus Torvalds sound_ym.rd_data_reg_sel = 14; /* select port A */ 1021da177e4SLinus Torvalds tmp = sound_ym.rd_data_reg_sel; 1031da177e4SLinus Torvalds sound_ym.wd_data = tmp & ~0x20; /* set strobe L */ 1041da177e4SLinus Torvalds MFPDELAY(); /* wait a bit */ 1051da177e4SLinus Torvalds sound_ym.wd_data = tmp | 0x20; /* set strobe H */ 1066ff5801aSRoman Zippel return 1; 1071da177e4SLinus Torvalds } 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds static void atari_par_console_write(struct console *co, const char *str, 1101da177e4SLinus Torvalds unsigned int count) 1111da177e4SLinus Torvalds { 1121da177e4SLinus Torvalds static int printer_present = 1; 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds if (!printer_present) 1151da177e4SLinus Torvalds return; 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds while (count--) { 1186ff5801aSRoman Zippel if (*str == '\n') { 1191da177e4SLinus Torvalds if (!ata_par_out('\r')) { 1201da177e4SLinus Torvalds printer_present = 0; 1211da177e4SLinus Torvalds return; 1221da177e4SLinus Torvalds } 1236ff5801aSRoman Zippel } 1241da177e4SLinus Torvalds if (!ata_par_out(*str++)) { 1251da177e4SLinus Torvalds printer_present = 0; 1261da177e4SLinus Torvalds return; 1271da177e4SLinus Torvalds } 1281da177e4SLinus Torvalds } 1291da177e4SLinus Torvalds } 1301da177e4SLinus Torvalds 1315575d0a3SAdrian Bunk #if 0 1321da177e4SLinus Torvalds int atari_mfp_console_wait_key(struct console *co) 1331da177e4SLinus Torvalds { 1343d92e8f3SGeert Uytterhoeven while (!(st_mfp.rcv_stat & 0x80)) /* wait for rx buf filled */ 1351da177e4SLinus Torvalds barrier(); 1363d92e8f3SGeert Uytterhoeven return st_mfp.usart_dta; 1371da177e4SLinus Torvalds } 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds int atari_scc_console_wait_key(struct console *co) 1401da177e4SLinus Torvalds { 1411da177e4SLinus Torvalds do { 1421da177e4SLinus Torvalds MFPDELAY(); 143*de339e4bSGeert Uytterhoeven } while (!(atari_scc.cha_b_ctrl & 0x01)); /* wait for rx buf filled */ 1441da177e4SLinus Torvalds MFPDELAY(); 145*de339e4bSGeert Uytterhoeven return atari_scc.cha_b_data; 1461da177e4SLinus Torvalds } 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds int atari_midi_console_wait_key(struct console *co) 1491da177e4SLinus Torvalds { 1501da177e4SLinus Torvalds while (!(acia.mid_ctrl & ACIA_RDRF)) /* wait for rx buf filled */ 1511da177e4SLinus Torvalds barrier(); 1526ff5801aSRoman Zippel return acia.mid_data; 1531da177e4SLinus Torvalds } 1541da177e4SLinus Torvalds #endif 1551da177e4SLinus Torvalds 1566ff5801aSRoman Zippel /* 1576ff5801aSRoman Zippel * The following two functions do a quick'n'dirty initialization of the MFP or 1581da177e4SLinus Torvalds * SCC serial ports. They're used by the debugging interface, kgdb, and the 1596ff5801aSRoman Zippel * serial console code. 1606ff5801aSRoman Zippel */ 1611da177e4SLinus Torvalds static void __init atari_init_mfp_port(int cflag) 1621da177e4SLinus Torvalds { 1636ff5801aSRoman Zippel /* 1646ff5801aSRoman Zippel * timer values for 1200...115200 bps; > 38400 select 110, 134, or 150 1656ff5801aSRoman Zippel * bps, resp., and work only correct if there's a RSVE or RSSPEED 1666ff5801aSRoman Zippel */ 1671da177e4SLinus Torvalds static int baud_table[9] = { 16, 11, 8, 4, 2, 1, 175, 143, 128 }; 1681da177e4SLinus Torvalds int baud = cflag & CBAUD; 1691da177e4SLinus Torvalds int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x04 : 0x06) : 0; 1701da177e4SLinus Torvalds int csize = ((cflag & CSIZE) == CS7) ? 0x20 : 0x00; 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds if (cflag & CBAUDEX) 1731da177e4SLinus Torvalds baud += B38400; 1741da177e4SLinus Torvalds if (baud < B1200 || baud > B38400+2) 1751da177e4SLinus Torvalds baud = B9600; /* use default 9600bps for non-implemented rates */ 1761da177e4SLinus Torvalds baud -= B1200; /* baud_table[] starts at 1200bps */ 1771da177e4SLinus Torvalds 1783d92e8f3SGeert Uytterhoeven st_mfp.trn_stat &= ~0x01; /* disable TX */ 1793d92e8f3SGeert Uytterhoeven st_mfp.usart_ctr = parity | csize | 0x88; /* 1:16 clk mode, 1 stop bit */ 1803d92e8f3SGeert Uytterhoeven st_mfp.tim_ct_cd &= 0x70; /* stop timer D */ 1813d92e8f3SGeert Uytterhoeven st_mfp.tim_dt_d = baud_table[baud]; 1823d92e8f3SGeert Uytterhoeven st_mfp.tim_ct_cd |= 0x01; /* start timer D, 1:4 */ 1833d92e8f3SGeert Uytterhoeven st_mfp.trn_stat |= 0x01; /* enable TX */ 1841da177e4SLinus Torvalds } 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds #define SCC_WRITE(reg, val) \ 1871da177e4SLinus Torvalds do { \ 188*de339e4bSGeert Uytterhoeven atari_scc.cha_b_ctrl = (reg); \ 1891da177e4SLinus Torvalds MFPDELAY(); \ 190*de339e4bSGeert Uytterhoeven atari_scc.cha_b_ctrl = (val); \ 1911da177e4SLinus Torvalds MFPDELAY(); \ 1921da177e4SLinus Torvalds } while (0) 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds /* loops_per_jiffy isn't initialized yet, so we can't use udelay(). This does a 1951da177e4SLinus Torvalds * delay of ~ 60us. */ 1961da177e4SLinus Torvalds #define LONG_DELAY() \ 1971da177e4SLinus Torvalds do { \ 1981da177e4SLinus Torvalds int i; \ 1991da177e4SLinus Torvalds for (i = 100; i > 0; --i) \ 2001da177e4SLinus Torvalds MFPDELAY(); \ 2011da177e4SLinus Torvalds } while (0) 2021da177e4SLinus Torvalds 2031da177e4SLinus Torvalds static void __init atari_init_scc_port(int cflag) 2041da177e4SLinus Torvalds { 2051da177e4SLinus Torvalds extern int atari_SCC_reset_done; 2061da177e4SLinus Torvalds static int clksrc_table[9] = 2071da177e4SLinus Torvalds /* reg 11: 0x50 = BRG, 0x00 = RTxC, 0x28 = TRxC */ 2081da177e4SLinus Torvalds { 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x00, 0x00 }; 2091da177e4SLinus Torvalds static int brgsrc_table[9] = 2101da177e4SLinus Torvalds /* reg 14: 0 = RTxC, 2 = PCLK */ 2111da177e4SLinus Torvalds { 2, 2, 2, 2, 2, 2, 0, 2, 2 }; 2121da177e4SLinus Torvalds static int clkmode_table[9] = 2131da177e4SLinus Torvalds /* reg 4: 0x40 = x16, 0x80 = x32, 0xc0 = x64 */ 2141da177e4SLinus Torvalds { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x80 }; 2151da177e4SLinus Torvalds static int div_table[9] = 2161da177e4SLinus Torvalds /* reg12 (BRG low) */ 2171da177e4SLinus Torvalds { 208, 138, 103, 50, 24, 11, 1, 0, 0 }; 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds int baud = cflag & CBAUD; 2201da177e4SLinus Torvalds int clksrc, clkmode, div, reg3, reg5; 2211da177e4SLinus Torvalds 2221da177e4SLinus Torvalds if (cflag & CBAUDEX) 2231da177e4SLinus Torvalds baud += B38400; 2241da177e4SLinus Torvalds if (baud < B1200 || baud > B38400+2) 2251da177e4SLinus Torvalds baud = B9600; /* use default 9600bps for non-implemented rates */ 2261da177e4SLinus Torvalds baud -= B1200; /* tables starts at 1200bps */ 2271da177e4SLinus Torvalds 2281da177e4SLinus Torvalds clksrc = clksrc_table[baud]; 2291da177e4SLinus Torvalds clkmode = clkmode_table[baud]; 2301da177e4SLinus Torvalds div = div_table[baud]; 2311da177e4SLinus Torvalds if (ATARIHW_PRESENT(TT_MFP) && baud >= 6) { 2321da177e4SLinus Torvalds /* special treatment for TT, where rates >= 38400 are done via TRxC */ 2331da177e4SLinus Torvalds clksrc = 0x28; /* TRxC */ 2341da177e4SLinus Torvalds clkmode = baud == 6 ? 0xc0 : 2351da177e4SLinus Torvalds baud == 7 ? 0x80 : /* really 76800bps */ 2361da177e4SLinus Torvalds 0x40; /* really 153600bps */ 2371da177e4SLinus Torvalds div = 0; 2381da177e4SLinus Torvalds } 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds reg3 = (cflag & CSIZE) == CS8 ? 0xc0 : 0x40; 2411da177e4SLinus Torvalds reg5 = (cflag & CSIZE) == CS8 ? 0x60 : 0x20 | 0x82 /* assert DTR/RTS */; 2421da177e4SLinus Torvalds 243*de339e4bSGeert Uytterhoeven (void)atari_scc.cha_b_ctrl; /* reset reg pointer */ 2441da177e4SLinus Torvalds SCC_WRITE(9, 0xc0); /* reset */ 2451da177e4SLinus Torvalds LONG_DELAY(); /* extra delay after WR9 access */ 2466ff5801aSRoman Zippel SCC_WRITE(4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03) 2476ff5801aSRoman Zippel : 0 | 0x04 /* 1 stopbit */ | clkmode); 2481da177e4SLinus Torvalds SCC_WRITE(3, reg3); 2491da177e4SLinus Torvalds SCC_WRITE(5, reg5); 2501da177e4SLinus Torvalds SCC_WRITE(9, 0); /* no interrupts */ 2511da177e4SLinus Torvalds LONG_DELAY(); /* extra delay after WR9 access */ 2521da177e4SLinus Torvalds SCC_WRITE(10, 0); /* NRZ mode */ 2531da177e4SLinus Torvalds SCC_WRITE(11, clksrc); /* main clock source */ 2541da177e4SLinus Torvalds SCC_WRITE(12, div); /* BRG value */ 2551da177e4SLinus Torvalds SCC_WRITE(13, 0); /* BRG high byte */ 2561da177e4SLinus Torvalds SCC_WRITE(14, brgsrc_table[baud]); 2571da177e4SLinus Torvalds SCC_WRITE(14, brgsrc_table[baud] | (div ? 1 : 0)); 2581da177e4SLinus Torvalds SCC_WRITE(3, reg3 | 1); 2591da177e4SLinus Torvalds SCC_WRITE(5, reg5 | 8); 2601da177e4SLinus Torvalds 2611da177e4SLinus Torvalds atari_SCC_reset_done = 1; 2621da177e4SLinus Torvalds } 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds static void __init atari_init_midi_port(int cflag) 2651da177e4SLinus Torvalds { 2661da177e4SLinus Torvalds int baud = cflag & CBAUD; 2671da177e4SLinus Torvalds int csize = ((cflag & CSIZE) == CS8) ? 0x10 : 0x00; 2681da177e4SLinus Torvalds /* warning 7N1 isn't possible! (instead 7O2 is used...) */ 2691da177e4SLinus Torvalds int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x0c : 0x08) : 0x04; 2701da177e4SLinus Torvalds int div; 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds /* 4800 selects 7812.5, 115200 selects 500000, all other (incl. 9600 as 2731da177e4SLinus Torvalds * default) the standard MIDI speed 31250. */ 2741da177e4SLinus Torvalds if (cflag & CBAUDEX) 2751da177e4SLinus Torvalds baud += B38400; 2761da177e4SLinus Torvalds if (baud == B4800) 2771da177e4SLinus Torvalds div = ACIA_DIV64; /* really 7812.5 bps */ 2781da177e4SLinus Torvalds else if (baud == B38400+2 /* 115200 */) 2791da177e4SLinus Torvalds div = ACIA_DIV1; /* really 500 kbps (does that work??) */ 2801da177e4SLinus Torvalds else 2811da177e4SLinus Torvalds div = ACIA_DIV16; /* 31250 bps, standard for MIDI */ 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds /* RTS low, ints disabled */ 2841da177e4SLinus Torvalds acia.mid_ctrl = div | csize | parity | 2851da177e4SLinus Torvalds ((atari_switches & ATARI_SWITCH_MIDI) ? 2861da177e4SLinus Torvalds ACIA_RHTID : ACIA_RLTID); 2871da177e4SLinus Torvalds } 2881da177e4SLinus Torvalds 289d6713b40SRoman Zippel static int __init atari_debug_setup(char *arg) 2901da177e4SLinus Torvalds { 291d6713b40SRoman Zippel if (!MACH_IS_ATARI) 292d6713b40SRoman Zippel return 0; 2931da177e4SLinus Torvalds 294d6713b40SRoman Zippel if (!strcmp(arg, "ser")) 295d6713b40SRoman Zippel /* defaults to ser2 for a Falcon and ser1 otherwise */ 296d6713b40SRoman Zippel arg = MACH_IS_FALCON ? "ser2" : "ser1"; 297d6713b40SRoman Zippel 298d6713b40SRoman Zippel if (!strcmp(arg, "ser1")) { 2991da177e4SLinus Torvalds /* ST-MFP Modem1 serial port */ 3001da177e4SLinus Torvalds atari_init_mfp_port(B9600|CS8); 3011da177e4SLinus Torvalds atari_console_driver.write = atari_mfp_console_write; 302d6713b40SRoman Zippel } else if (!strcmp(arg, "ser2")) { 3031da177e4SLinus Torvalds /* SCC Modem2 serial port */ 3041da177e4SLinus Torvalds atari_init_scc_port(B9600|CS8); 3051da177e4SLinus Torvalds atari_console_driver.write = atari_scc_console_write; 306d6713b40SRoman Zippel } else if (!strcmp(arg, "midi")) { 3071da177e4SLinus Torvalds /* MIDI port */ 3081da177e4SLinus Torvalds atari_init_midi_port(B9600|CS8); 3091da177e4SLinus Torvalds atari_console_driver.write = atari_midi_console_write; 310d6713b40SRoman Zippel } else if (!strcmp(arg, "par")) { 3111da177e4SLinus Torvalds /* parallel printer */ 3121da177e4SLinus Torvalds atari_turnoff_irq(IRQ_MFP_BUSY); /* avoid ints */ 3131da177e4SLinus Torvalds sound_ym.rd_data_reg_sel = 7; /* select mixer control */ 3141da177e4SLinus Torvalds sound_ym.wd_data = 0xff; /* sound off, ports are output */ 3151da177e4SLinus Torvalds sound_ym.rd_data_reg_sel = 15; /* select port B */ 3161da177e4SLinus Torvalds sound_ym.wd_data = 0; /* no char */ 3171da177e4SLinus Torvalds sound_ym.rd_data_reg_sel = 14; /* select port A */ 3181da177e4SLinus Torvalds sound_ym.wd_data = sound_ym.rd_data_reg_sel | 0x20; /* strobe H */ 3191da177e4SLinus Torvalds atari_console_driver.write = atari_par_console_write; 3201da177e4SLinus Torvalds } 3211da177e4SLinus Torvalds if (atari_console_driver.write) 3221da177e4SLinus Torvalds register_console(&atari_console_driver); 323d6713b40SRoman Zippel 324d6713b40SRoman Zippel return 0; 3251da177e4SLinus Torvalds } 326d6713b40SRoman Zippel 327d6713b40SRoman Zippel early_param("debug", atari_debug_setup); 328