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> 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds #include <asm/atarihw.h> 201da177e4SLinus Torvalds #include <asm/atariints.h> 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds extern char m68k_debug_device[]; 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds /* Flag that Modem1 port is already initialized and used */ 251da177e4SLinus Torvalds int atari_MFP_init_done; 261da177e4SLinus Torvalds /* Flag that Modem1 port is already initialized and used */ 271da177e4SLinus Torvalds int atari_SCC_init_done; 281da177e4SLinus Torvalds /* Can be set somewhere, if a SCC master reset has already be done and should 291da177e4SLinus Torvalds * not be repeated; used by kgdb */ 301da177e4SLinus Torvalds int atari_SCC_reset_done; 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds static struct console atari_console_driver = { 331da177e4SLinus Torvalds .name = "debug", 341da177e4SLinus Torvalds .flags = CON_PRINTBUFFER, 351da177e4SLinus Torvalds .index = -1, 361da177e4SLinus Torvalds }; 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds static inline void ata_mfp_out(char c) 401da177e4SLinus Torvalds { 411da177e4SLinus Torvalds while (!(mfp.trn_stat & 0x80)) /* wait for tx buf empty */ 421da177e4SLinus Torvalds barrier(); 431da177e4SLinus Torvalds mfp.usart_dta = c; 441da177e4SLinus Torvalds } 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds void atari_mfp_console_write(struct console *co, const char *str, 471da177e4SLinus Torvalds unsigned int count) 481da177e4SLinus Torvalds { 491da177e4SLinus Torvalds while (count--) { 501da177e4SLinus Torvalds if (*str == '\n') 511da177e4SLinus Torvalds ata_mfp_out('\r'); 521da177e4SLinus Torvalds ata_mfp_out(*str++); 531da177e4SLinus Torvalds } 541da177e4SLinus Torvalds } 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds static inline void ata_scc_out(char c) 571da177e4SLinus Torvalds { 581da177e4SLinus Torvalds do { 591da177e4SLinus Torvalds MFPDELAY(); 601da177e4SLinus Torvalds } while (!(scc.cha_b_ctrl & 0x04)); /* wait for tx buf empty */ 611da177e4SLinus Torvalds MFPDELAY(); 621da177e4SLinus Torvalds scc.cha_b_data = c; 631da177e4SLinus Torvalds } 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds void atari_scc_console_write(struct console *co, const char *str, 661da177e4SLinus Torvalds unsigned int count) 671da177e4SLinus Torvalds { 681da177e4SLinus Torvalds while (count--) { 691da177e4SLinus Torvalds if (*str == '\n') 701da177e4SLinus Torvalds ata_scc_out('\r'); 711da177e4SLinus Torvalds ata_scc_out(*str++); 721da177e4SLinus Torvalds } 731da177e4SLinus Torvalds } 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds static inline void ata_midi_out(char c) 761da177e4SLinus Torvalds { 771da177e4SLinus Torvalds while (!(acia.mid_ctrl & ACIA_TDRE)) /* wait for tx buf empty */ 781da177e4SLinus Torvalds barrier(); 791da177e4SLinus Torvalds acia.mid_data = c; 801da177e4SLinus Torvalds } 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds void atari_midi_console_write(struct console *co, const char *str, 831da177e4SLinus Torvalds unsigned int count) 841da177e4SLinus Torvalds { 851da177e4SLinus Torvalds while (count--) { 861da177e4SLinus Torvalds if (*str == '\n') 871da177e4SLinus Torvalds ata_midi_out('\r'); 881da177e4SLinus Torvalds ata_midi_out(*str++); 891da177e4SLinus Torvalds } 901da177e4SLinus Torvalds } 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds static int ata_par_out(char c) 931da177e4SLinus Torvalds { 941da177e4SLinus Torvalds unsigned char tmp; 951da177e4SLinus Torvalds /* This a some-seconds timeout in case no printer is connected */ 961da177e4SLinus Torvalds unsigned long i = loops_per_jiffy > 1 ? loops_per_jiffy : 10000000/HZ; 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds while ((mfp.par_dt_reg & 1) && --i) /* wait for BUSY == L */ 991da177e4SLinus Torvalds ; 100*6ff5801aSRoman Zippel if (!i) 101*6ff5801aSRoman Zippel return 0; 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds sound_ym.rd_data_reg_sel = 15; /* select port B */ 1041da177e4SLinus Torvalds sound_ym.wd_data = c; /* put char onto port */ 1051da177e4SLinus Torvalds sound_ym.rd_data_reg_sel = 14; /* select port A */ 1061da177e4SLinus Torvalds tmp = sound_ym.rd_data_reg_sel; 1071da177e4SLinus Torvalds sound_ym.wd_data = tmp & ~0x20; /* set strobe L */ 1081da177e4SLinus Torvalds MFPDELAY(); /* wait a bit */ 1091da177e4SLinus Torvalds sound_ym.wd_data = tmp | 0x20; /* set strobe H */ 110*6ff5801aSRoman Zippel return 1; 1111da177e4SLinus Torvalds } 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds static void atari_par_console_write(struct console *co, const char *str, 1141da177e4SLinus Torvalds unsigned int count) 1151da177e4SLinus Torvalds { 1161da177e4SLinus Torvalds static int printer_present = 1; 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds if (!printer_present) 1191da177e4SLinus Torvalds return; 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds while (count--) { 122*6ff5801aSRoman Zippel if (*str == '\n') { 1231da177e4SLinus Torvalds if (!ata_par_out('\r')) { 1241da177e4SLinus Torvalds printer_present = 0; 1251da177e4SLinus Torvalds return; 1261da177e4SLinus Torvalds } 127*6ff5801aSRoman Zippel } 1281da177e4SLinus Torvalds if (!ata_par_out(*str++)) { 1291da177e4SLinus Torvalds printer_present = 0; 1301da177e4SLinus Torvalds return; 1311da177e4SLinus Torvalds } 1321da177e4SLinus Torvalds } 1331da177e4SLinus Torvalds } 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds #ifdef CONFIG_SERIAL_CONSOLE 1361da177e4SLinus Torvalds int atari_mfp_console_wait_key(struct console *co) 1371da177e4SLinus Torvalds { 1381da177e4SLinus Torvalds while (!(mfp.rcv_stat & 0x80)) /* wait for rx buf filled */ 1391da177e4SLinus Torvalds barrier(); 140*6ff5801aSRoman Zippel return mfp.usart_dta; 1411da177e4SLinus Torvalds } 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds int atari_scc_console_wait_key(struct console *co) 1441da177e4SLinus Torvalds { 1451da177e4SLinus Torvalds do { 1461da177e4SLinus Torvalds MFPDELAY(); 1471da177e4SLinus Torvalds } while (!(scc.cha_b_ctrl & 0x01)); /* wait for rx buf filled */ 1481da177e4SLinus Torvalds MFPDELAY(); 149*6ff5801aSRoman Zippel return scc.cha_b_data; 1501da177e4SLinus Torvalds } 1511da177e4SLinus Torvalds 1521da177e4SLinus Torvalds int atari_midi_console_wait_key(struct console *co) 1531da177e4SLinus Torvalds { 1541da177e4SLinus Torvalds while (!(acia.mid_ctrl & ACIA_RDRF)) /* wait for rx buf filled */ 1551da177e4SLinus Torvalds barrier(); 156*6ff5801aSRoman Zippel return acia.mid_data; 1571da177e4SLinus Torvalds } 1581da177e4SLinus Torvalds #endif 1591da177e4SLinus Torvalds 160*6ff5801aSRoman Zippel /* 161*6ff5801aSRoman Zippel * The following two functions do a quick'n'dirty initialization of the MFP or 1621da177e4SLinus Torvalds * SCC serial ports. They're used by the debugging interface, kgdb, and the 163*6ff5801aSRoman Zippel * serial console code. 164*6ff5801aSRoman Zippel */ 1651da177e4SLinus Torvalds #ifndef CONFIG_SERIAL_CONSOLE 1661da177e4SLinus Torvalds static void __init atari_init_mfp_port(int cflag) 1671da177e4SLinus Torvalds #else 1681da177e4SLinus Torvalds void atari_init_mfp_port(int cflag) 1691da177e4SLinus Torvalds #endif 1701da177e4SLinus Torvalds { 171*6ff5801aSRoman Zippel /* 172*6ff5801aSRoman Zippel * timer values for 1200...115200 bps; > 38400 select 110, 134, or 150 173*6ff5801aSRoman Zippel * bps, resp., and work only correct if there's a RSVE or RSSPEED 174*6ff5801aSRoman Zippel */ 1751da177e4SLinus Torvalds static int baud_table[9] = { 16, 11, 8, 4, 2, 1, 175, 143, 128 }; 1761da177e4SLinus Torvalds int baud = cflag & CBAUD; 1771da177e4SLinus Torvalds int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x04 : 0x06) : 0; 1781da177e4SLinus Torvalds int csize = ((cflag & CSIZE) == CS7) ? 0x20 : 0x00; 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds if (cflag & CBAUDEX) 1811da177e4SLinus Torvalds baud += B38400; 1821da177e4SLinus Torvalds if (baud < B1200 || baud > B38400+2) 1831da177e4SLinus Torvalds baud = B9600; /* use default 9600bps for non-implemented rates */ 1841da177e4SLinus Torvalds baud -= B1200; /* baud_table[] starts at 1200bps */ 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds mfp.trn_stat &= ~0x01; /* disable TX */ 1871da177e4SLinus Torvalds mfp.usart_ctr = parity | csize | 0x88; /* 1:16 clk mode, 1 stop bit */ 1881da177e4SLinus Torvalds mfp.tim_ct_cd &= 0x70; /* stop timer D */ 1891da177e4SLinus Torvalds mfp.tim_dt_d = baud_table[baud]; 1901da177e4SLinus Torvalds mfp.tim_ct_cd |= 0x01; /* start timer D, 1:4 */ 1911da177e4SLinus Torvalds mfp.trn_stat |= 0x01; /* enable TX */ 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds atari_MFP_init_done = 1; 1941da177e4SLinus Torvalds } 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds #define SCC_WRITE(reg, val) \ 1971da177e4SLinus Torvalds do { \ 1981da177e4SLinus Torvalds scc.cha_b_ctrl = (reg); \ 1991da177e4SLinus Torvalds MFPDELAY(); \ 2001da177e4SLinus Torvalds scc.cha_b_ctrl = (val); \ 2011da177e4SLinus Torvalds MFPDELAY(); \ 2021da177e4SLinus Torvalds } while (0) 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds /* loops_per_jiffy isn't initialized yet, so we can't use udelay(). This does a 2051da177e4SLinus Torvalds * delay of ~ 60us. */ 2061da177e4SLinus Torvalds #define LONG_DELAY() \ 2071da177e4SLinus Torvalds do { \ 2081da177e4SLinus Torvalds int i; \ 2091da177e4SLinus Torvalds for (i = 100; i > 0; --i) \ 2101da177e4SLinus Torvalds MFPDELAY(); \ 2111da177e4SLinus Torvalds } while (0) 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds #ifndef CONFIG_SERIAL_CONSOLE 2141da177e4SLinus Torvalds static void __init atari_init_scc_port(int cflag) 2151da177e4SLinus Torvalds #else 2161da177e4SLinus Torvalds void atari_init_scc_port(int cflag) 2171da177e4SLinus Torvalds #endif 2181da177e4SLinus Torvalds { 2191da177e4SLinus Torvalds extern int atari_SCC_reset_done; 2201da177e4SLinus Torvalds static int clksrc_table[9] = 2211da177e4SLinus Torvalds /* reg 11: 0x50 = BRG, 0x00 = RTxC, 0x28 = TRxC */ 2221da177e4SLinus Torvalds { 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x00, 0x00 }; 2231da177e4SLinus Torvalds static int brgsrc_table[9] = 2241da177e4SLinus Torvalds /* reg 14: 0 = RTxC, 2 = PCLK */ 2251da177e4SLinus Torvalds { 2, 2, 2, 2, 2, 2, 0, 2, 2 }; 2261da177e4SLinus Torvalds static int clkmode_table[9] = 2271da177e4SLinus Torvalds /* reg 4: 0x40 = x16, 0x80 = x32, 0xc0 = x64 */ 2281da177e4SLinus Torvalds { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x80 }; 2291da177e4SLinus Torvalds static int div_table[9] = 2301da177e4SLinus Torvalds /* reg12 (BRG low) */ 2311da177e4SLinus Torvalds { 208, 138, 103, 50, 24, 11, 1, 0, 0 }; 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds int baud = cflag & CBAUD; 2341da177e4SLinus Torvalds int clksrc, clkmode, div, reg3, reg5; 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds if (cflag & CBAUDEX) 2371da177e4SLinus Torvalds baud += B38400; 2381da177e4SLinus Torvalds if (baud < B1200 || baud > B38400+2) 2391da177e4SLinus Torvalds baud = B9600; /* use default 9600bps for non-implemented rates */ 2401da177e4SLinus Torvalds baud -= B1200; /* tables starts at 1200bps */ 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds clksrc = clksrc_table[baud]; 2431da177e4SLinus Torvalds clkmode = clkmode_table[baud]; 2441da177e4SLinus Torvalds div = div_table[baud]; 2451da177e4SLinus Torvalds if (ATARIHW_PRESENT(TT_MFP) && baud >= 6) { 2461da177e4SLinus Torvalds /* special treatment for TT, where rates >= 38400 are done via TRxC */ 2471da177e4SLinus Torvalds clksrc = 0x28; /* TRxC */ 2481da177e4SLinus Torvalds clkmode = baud == 6 ? 0xc0 : 2491da177e4SLinus Torvalds baud == 7 ? 0x80 : /* really 76800bps */ 2501da177e4SLinus Torvalds 0x40; /* really 153600bps */ 2511da177e4SLinus Torvalds div = 0; 2521da177e4SLinus Torvalds } 2531da177e4SLinus Torvalds 2541da177e4SLinus Torvalds reg3 = (cflag & CSIZE) == CS8 ? 0xc0 : 0x40; 2551da177e4SLinus Torvalds reg5 = (cflag & CSIZE) == CS8 ? 0x60 : 0x20 | 0x82 /* assert DTR/RTS */; 2561da177e4SLinus Torvalds 2571da177e4SLinus Torvalds (void)scc.cha_b_ctrl; /* reset reg pointer */ 2581da177e4SLinus Torvalds SCC_WRITE(9, 0xc0); /* reset */ 2591da177e4SLinus Torvalds LONG_DELAY(); /* extra delay after WR9 access */ 260*6ff5801aSRoman Zippel SCC_WRITE(4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03) 261*6ff5801aSRoman Zippel : 0 | 0x04 /* 1 stopbit */ | clkmode); 2621da177e4SLinus Torvalds SCC_WRITE(3, reg3); 2631da177e4SLinus Torvalds SCC_WRITE(5, reg5); 2641da177e4SLinus Torvalds SCC_WRITE(9, 0); /* no interrupts */ 2651da177e4SLinus Torvalds LONG_DELAY(); /* extra delay after WR9 access */ 2661da177e4SLinus Torvalds SCC_WRITE(10, 0); /* NRZ mode */ 2671da177e4SLinus Torvalds SCC_WRITE(11, clksrc); /* main clock source */ 2681da177e4SLinus Torvalds SCC_WRITE(12, div); /* BRG value */ 2691da177e4SLinus Torvalds SCC_WRITE(13, 0); /* BRG high byte */ 2701da177e4SLinus Torvalds SCC_WRITE(14, brgsrc_table[baud]); 2711da177e4SLinus Torvalds SCC_WRITE(14, brgsrc_table[baud] | (div ? 1 : 0)); 2721da177e4SLinus Torvalds SCC_WRITE(3, reg3 | 1); 2731da177e4SLinus Torvalds SCC_WRITE(5, reg5 | 8); 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds atari_SCC_reset_done = 1; 2761da177e4SLinus Torvalds atari_SCC_init_done = 1; 2771da177e4SLinus Torvalds } 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds #ifndef CONFIG_SERIAL_CONSOLE 2801da177e4SLinus Torvalds static void __init atari_init_midi_port(int cflag) 2811da177e4SLinus Torvalds #else 2821da177e4SLinus Torvalds void atari_init_midi_port(int cflag) 2831da177e4SLinus Torvalds #endif 2841da177e4SLinus Torvalds { 2851da177e4SLinus Torvalds int baud = cflag & CBAUD; 2861da177e4SLinus Torvalds int csize = ((cflag & CSIZE) == CS8) ? 0x10 : 0x00; 2871da177e4SLinus Torvalds /* warning 7N1 isn't possible! (instead 7O2 is used...) */ 2881da177e4SLinus Torvalds int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x0c : 0x08) : 0x04; 2891da177e4SLinus Torvalds int div; 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvalds /* 4800 selects 7812.5, 115200 selects 500000, all other (incl. 9600 as 2921da177e4SLinus Torvalds * default) the standard MIDI speed 31250. */ 2931da177e4SLinus Torvalds if (cflag & CBAUDEX) 2941da177e4SLinus Torvalds baud += B38400; 2951da177e4SLinus Torvalds if (baud == B4800) 2961da177e4SLinus Torvalds div = ACIA_DIV64; /* really 7812.5 bps */ 2971da177e4SLinus Torvalds else if (baud == B38400+2 /* 115200 */) 2981da177e4SLinus Torvalds div = ACIA_DIV1; /* really 500 kbps (does that work??) */ 2991da177e4SLinus Torvalds else 3001da177e4SLinus Torvalds div = ACIA_DIV16; /* 31250 bps, standard for MIDI */ 3011da177e4SLinus Torvalds 3021da177e4SLinus Torvalds /* RTS low, ints disabled */ 3031da177e4SLinus Torvalds acia.mid_ctrl = div | csize | parity | 3041da177e4SLinus Torvalds ((atari_switches & ATARI_SWITCH_MIDI) ? 3051da177e4SLinus Torvalds ACIA_RHTID : ACIA_RLTID); 3061da177e4SLinus Torvalds } 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvalds void __init atari_debug_init(void) 3091da177e4SLinus Torvalds { 3101da177e4SLinus Torvalds if (!strcmp(m68k_debug_device, "ser")) { 3111da177e4SLinus Torvalds /* defaults to ser2 for a Falcon and ser1 otherwise */ 3121da177e4SLinus Torvalds strcpy(m68k_debug_device, MACH_IS_FALCON ? "ser2" : "ser1"); 3131da177e4SLinus Torvalds } 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvalds if (!strcmp(m68k_debug_device, "ser1")) { 3161da177e4SLinus Torvalds /* ST-MFP Modem1 serial port */ 3171da177e4SLinus Torvalds atari_init_mfp_port(B9600|CS8); 3181da177e4SLinus Torvalds atari_console_driver.write = atari_mfp_console_write; 319*6ff5801aSRoman Zippel } else if (!strcmp(m68k_debug_device, "ser2")) { 3201da177e4SLinus Torvalds /* SCC Modem2 serial port */ 3211da177e4SLinus Torvalds atari_init_scc_port(B9600|CS8); 3221da177e4SLinus Torvalds atari_console_driver.write = atari_scc_console_write; 323*6ff5801aSRoman Zippel } else if (!strcmp(m68k_debug_device, "midi")) { 3241da177e4SLinus Torvalds /* MIDI port */ 3251da177e4SLinus Torvalds atari_init_midi_port(B9600|CS8); 3261da177e4SLinus Torvalds atari_console_driver.write = atari_midi_console_write; 327*6ff5801aSRoman Zippel } else if (!strcmp(m68k_debug_device, "par")) { 3281da177e4SLinus Torvalds /* parallel printer */ 3291da177e4SLinus Torvalds atari_turnoff_irq(IRQ_MFP_BUSY); /* avoid ints */ 3301da177e4SLinus Torvalds sound_ym.rd_data_reg_sel = 7; /* select mixer control */ 3311da177e4SLinus Torvalds sound_ym.wd_data = 0xff; /* sound off, ports are output */ 3321da177e4SLinus Torvalds sound_ym.rd_data_reg_sel = 15; /* select port B */ 3331da177e4SLinus Torvalds sound_ym.wd_data = 0; /* no char */ 3341da177e4SLinus Torvalds sound_ym.rd_data_reg_sel = 14; /* select port A */ 3351da177e4SLinus Torvalds sound_ym.wd_data = sound_ym.rd_data_reg_sel | 0x20; /* strobe H */ 3361da177e4SLinus Torvalds atari_console_driver.write = atari_par_console_write; 3371da177e4SLinus Torvalds } 3381da177e4SLinus Torvalds if (atari_console_driver.write) 3391da177e4SLinus Torvalds register_console(&atari_console_driver); 3401da177e4SLinus Torvalds } 341