Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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