blob: 28efdc33c1aeab89afde05ff5249ba5bdf2f20ac [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/types.h>
14#include <linux/tty.h>
15#include <linux/console.h>
16#include <linux/init.h>
17#include <linux/delay.h>
Adrian Bunka3b20042008-02-04 22:30:26 -080018#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include <asm/atarihw.h>
21#include <asm/atariints.h>
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/* Can be set somewhere, if a SCC master reset has already be done and should
24 * not be repeated; used by kgdb */
25int atari_SCC_reset_done;
Adrian Bunka3b20042008-02-04 22:30:26 -080026EXPORT_SYMBOL(atari_SCC_reset_done);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28static struct console atari_console_driver = {
Roman Zippel6ff58012007-05-01 22:32:43 +020029 .name = "debug",
30 .flags = CON_PRINTBUFFER,
31 .index = -1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070032};
33
34
Roman Zippel6ff58012007-05-01 22:32:43 +020035static inline void ata_mfp_out(char c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
Geert Uytterhoeven3d92e8f2009-02-22 09:38:47 +010037 while (!(st_mfp.trn_stat & 0x80)) /* wait for tx buf empty */
Roman Zippel6ff58012007-05-01 22:32:43 +020038 barrier();
Geert Uytterhoeven3d92e8f2009-02-22 09:38:47 +010039 st_mfp.usart_dta = c;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
Adrian Bunk5575d0a2008-07-17 21:16:24 +020042static void atari_mfp_console_write(struct console *co, const char *str,
43 unsigned int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
Roman Zippel6ff58012007-05-01 22:32:43 +020045 while (count--) {
46 if (*str == '\n')
47 ata_mfp_out('\r');
48 ata_mfp_out(*str++);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 }
Roman Zippel6ff58012007-05-01 22:32:43 +020050}
51
52static inline void ata_scc_out(char c)
53{
54 do {
55 MFPDELAY();
56 } while (!(scc.cha_b_ctrl & 0x04)); /* wait for tx buf empty */
57 MFPDELAY();
58 scc.cha_b_data = c;
59}
60
Adrian Bunk5575d0a2008-07-17 21:16:24 +020061static void atari_scc_console_write(struct console *co, const char *str,
62 unsigned int count)
Roman Zippel6ff58012007-05-01 22:32:43 +020063{
64 while (count--) {
65 if (*str == '\n')
66 ata_scc_out('\r');
67 ata_scc_out(*str++);
68 }
69}
70
71static inline void ata_midi_out(char c)
72{
73 while (!(acia.mid_ctrl & ACIA_TDRE)) /* wait for tx buf empty */
74 barrier();
75 acia.mid_data = c;
76}
77
Adrian Bunk5575d0a2008-07-17 21:16:24 +020078static void atari_midi_console_write(struct console *co, const char *str,
79 unsigned int count)
Roman Zippel6ff58012007-05-01 22:32:43 +020080{
81 while (count--) {
82 if (*str == '\n')
83 ata_midi_out('\r');
84 ata_midi_out(*str++);
85 }
86}
87
88static int ata_par_out(char c)
89{
90 unsigned char tmp;
91 /* This a some-seconds timeout in case no printer is connected */
92 unsigned long i = loops_per_jiffy > 1 ? loops_per_jiffy : 10000000/HZ;
93
Geert Uytterhoeven3d92e8f2009-02-22 09:38:47 +010094 while ((st_mfp.par_dt_reg & 1) && --i) /* wait for BUSY == L */
Roman Zippel6ff58012007-05-01 22:32:43 +020095 ;
96 if (!i)
97 return 0;
98
99 sound_ym.rd_data_reg_sel = 15; /* select port B */
100 sound_ym.wd_data = c; /* put char onto port */
101 sound_ym.rd_data_reg_sel = 14; /* select port A */
102 tmp = sound_ym.rd_data_reg_sel;
103 sound_ym.wd_data = tmp & ~0x20; /* set strobe L */
104 MFPDELAY(); /* wait a bit */
105 sound_ym.wd_data = tmp | 0x20; /* set strobe H */
106 return 1;
107}
108
109static void atari_par_console_write(struct console *co, const char *str,
110 unsigned int count)
111{
112 static int printer_present = 1;
113
114 if (!printer_present)
115 return;
116
117 while (count--) {
118 if (*str == '\n') {
119 if (!ata_par_out('\r')) {
120 printer_present = 0;
121 return;
122 }
123 }
124 if (!ata_par_out(*str++)) {
125 printer_present = 0;
126 return;
127 }
128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Adrian Bunk5575d0a2008-07-17 21:16:24 +0200131#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132int atari_mfp_console_wait_key(struct console *co)
133{
Geert Uytterhoeven3d92e8f2009-02-22 09:38:47 +0100134 while (!(st_mfp.rcv_stat & 0x80)) /* wait for rx buf filled */
Roman Zippel6ff58012007-05-01 22:32:43 +0200135 barrier();
Geert Uytterhoeven3d92e8f2009-02-22 09:38:47 +0100136 return st_mfp.usart_dta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
139int atari_scc_console_wait_key(struct console *co)
140{
Roman Zippel6ff58012007-05-01 22:32:43 +0200141 do {
142 MFPDELAY();
143 } while (!(scc.cha_b_ctrl & 0x01)); /* wait for rx buf filled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 MFPDELAY();
Roman Zippel6ff58012007-05-01 22:32:43 +0200145 return scc.cha_b_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
148int atari_midi_console_wait_key(struct console *co)
149{
Roman Zippel6ff58012007-05-01 22:32:43 +0200150 while (!(acia.mid_ctrl & ACIA_RDRF)) /* wait for rx buf filled */
151 barrier();
152 return acia.mid_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
154#endif
155
Roman Zippel6ff58012007-05-01 22:32:43 +0200156/*
157 * The following two functions do a quick'n'dirty initialization of the MFP or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 * SCC serial ports. They're used by the debugging interface, kgdb, and the
Roman Zippel6ff58012007-05-01 22:32:43 +0200159 * serial console code.
160 */
Roman Zippel6ff58012007-05-01 22:32:43 +0200161static void __init atari_init_mfp_port(int cflag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
Roman Zippel6ff58012007-05-01 22:32:43 +0200163 /*
164 * timer values for 1200...115200 bps; > 38400 select 110, 134, or 150
165 * bps, resp., and work only correct if there's a RSVE or RSSPEED
166 */
167 static int baud_table[9] = { 16, 11, 8, 4, 2, 1, 175, 143, 128 };
168 int baud = cflag & CBAUD;
169 int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x04 : 0x06) : 0;
170 int csize = ((cflag & CSIZE) == CS7) ? 0x20 : 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Roman Zippel6ff58012007-05-01 22:32:43 +0200172 if (cflag & CBAUDEX)
173 baud += B38400;
174 if (baud < B1200 || baud > B38400+2)
175 baud = B9600; /* use default 9600bps for non-implemented rates */
176 baud -= B1200; /* baud_table[] starts at 1200bps */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Geert Uytterhoeven3d92e8f2009-02-22 09:38:47 +0100178 st_mfp.trn_stat &= ~0x01; /* disable TX */
179 st_mfp.usart_ctr = parity | csize | 0x88; /* 1:16 clk mode, 1 stop bit */
180 st_mfp.tim_ct_cd &= 0x70; /* stop timer D */
181 st_mfp.tim_dt_d = baud_table[baud];
182 st_mfp.tim_ct_cd |= 0x01; /* start timer D, 1:4 */
183 st_mfp.trn_stat |= 0x01; /* enable TX */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
185
Roman Zippel6ff58012007-05-01 22:32:43 +0200186#define SCC_WRITE(reg, val) \
187 do { \
188 scc.cha_b_ctrl = (reg); \
189 MFPDELAY(); \
190 scc.cha_b_ctrl = (val); \
191 MFPDELAY(); \
192 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194/* loops_per_jiffy isn't initialized yet, so we can't use udelay(). This does a
195 * delay of ~ 60us. */
Roman Zippel6ff58012007-05-01 22:32:43 +0200196#define LONG_DELAY() \
197 do { \
198 int i; \
199 for (i = 100; i > 0; --i) \
200 MFPDELAY(); \
201 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Roman Zippel6ff58012007-05-01 22:32:43 +0200203static void __init atari_init_scc_port(int cflag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Roman Zippel6ff58012007-05-01 22:32:43 +0200205 extern int atari_SCC_reset_done;
206 static int clksrc_table[9] =
207 /* reg 11: 0x50 = BRG, 0x00 = RTxC, 0x28 = TRxC */
208 { 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x00, 0x00 };
209 static int brgsrc_table[9] =
210 /* reg 14: 0 = RTxC, 2 = PCLK */
211 { 2, 2, 2, 2, 2, 2, 0, 2, 2 };
212 static int clkmode_table[9] =
213 /* reg 4: 0x40 = x16, 0x80 = x32, 0xc0 = x64 */
214 { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x80 };
215 static int div_table[9] =
216 /* reg12 (BRG low) */
217 { 208, 138, 103, 50, 24, 11, 1, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Roman Zippel6ff58012007-05-01 22:32:43 +0200219 int baud = cflag & CBAUD;
220 int clksrc, clkmode, div, reg3, reg5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Roman Zippel6ff58012007-05-01 22:32:43 +0200222 if (cflag & CBAUDEX)
223 baud += B38400;
224 if (baud < B1200 || baud > B38400+2)
225 baud = B9600; /* use default 9600bps for non-implemented rates */
226 baud -= B1200; /* tables starts at 1200bps */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Roman Zippel6ff58012007-05-01 22:32:43 +0200228 clksrc = clksrc_table[baud];
229 clkmode = clkmode_table[baud];
230 div = div_table[baud];
231 if (ATARIHW_PRESENT(TT_MFP) && baud >= 6) {
232 /* special treatment for TT, where rates >= 38400 are done via TRxC */
233 clksrc = 0x28; /* TRxC */
234 clkmode = baud == 6 ? 0xc0 :
235 baud == 7 ? 0x80 : /* really 76800bps */
236 0x40; /* really 153600bps */
237 div = 0;
238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Roman Zippel6ff58012007-05-01 22:32:43 +0200240 reg3 = (cflag & CSIZE) == CS8 ? 0xc0 : 0x40;
241 reg5 = (cflag & CSIZE) == CS8 ? 0x60 : 0x20 | 0x82 /* assert DTR/RTS */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Roman Zippel6ff58012007-05-01 22:32:43 +0200243 (void)scc.cha_b_ctrl; /* reset reg pointer */
244 SCC_WRITE(9, 0xc0); /* reset */
245 LONG_DELAY(); /* extra delay after WR9 access */
246 SCC_WRITE(4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03)
247 : 0 | 0x04 /* 1 stopbit */ | clkmode);
248 SCC_WRITE(3, reg3);
249 SCC_WRITE(5, reg5);
250 SCC_WRITE(9, 0); /* no interrupts */
251 LONG_DELAY(); /* extra delay after WR9 access */
252 SCC_WRITE(10, 0); /* NRZ mode */
253 SCC_WRITE(11, clksrc); /* main clock source */
254 SCC_WRITE(12, div); /* BRG value */
255 SCC_WRITE(13, 0); /* BRG high byte */
256 SCC_WRITE(14, brgsrc_table[baud]);
257 SCC_WRITE(14, brgsrc_table[baud] | (div ? 1 : 0));
258 SCC_WRITE(3, reg3 | 1);
259 SCC_WRITE(5, reg5 | 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Roman Zippel6ff58012007-05-01 22:32:43 +0200261 atari_SCC_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
263
Roman Zippel6ff58012007-05-01 22:32:43 +0200264static void __init atari_init_midi_port(int cflag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Roman Zippel6ff58012007-05-01 22:32:43 +0200266 int baud = cflag & CBAUD;
267 int csize = ((cflag & CSIZE) == CS8) ? 0x10 : 0x00;
268 /* warning 7N1 isn't possible! (instead 7O2 is used...) */
269 int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x0c : 0x08) : 0x04;
270 int div;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Roman Zippel6ff58012007-05-01 22:32:43 +0200272 /* 4800 selects 7812.5, 115200 selects 500000, all other (incl. 9600 as
273 * default) the standard MIDI speed 31250. */
274 if (cflag & CBAUDEX)
275 baud += B38400;
276 if (baud == B4800)
277 div = ACIA_DIV64; /* really 7812.5 bps */
278 else if (baud == B38400+2 /* 115200 */)
279 div = ACIA_DIV1; /* really 500 kbps (does that work??) */
280 else
281 div = ACIA_DIV16; /* 31250 bps, standard for MIDI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Roman Zippel6ff58012007-05-01 22:32:43 +0200283 /* RTS low, ints disabled */
284 acia.mid_ctrl = div | csize | parity |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 ((atari_switches & ATARI_SWITCH_MIDI) ?
286 ACIA_RHTID : ACIA_RLTID);
287}
288
Roman Zippeld6713b42007-05-01 22:32:45 +0200289static int __init atari_debug_setup(char *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
Roman Zippeld6713b42007-05-01 22:32:45 +0200291 if (!MACH_IS_ATARI)
292 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Roman Zippeld6713b42007-05-01 22:32:45 +0200294 if (!strcmp(arg, "ser"))
295 /* defaults to ser2 for a Falcon and ser1 otherwise */
296 arg = MACH_IS_FALCON ? "ser2" : "ser1";
297
298 if (!strcmp(arg, "ser1")) {
Roman Zippel6ff58012007-05-01 22:32:43 +0200299 /* ST-MFP Modem1 serial port */
300 atari_init_mfp_port(B9600|CS8);
301 atari_console_driver.write = atari_mfp_console_write;
Roman Zippeld6713b42007-05-01 22:32:45 +0200302 } else if (!strcmp(arg, "ser2")) {
Roman Zippel6ff58012007-05-01 22:32:43 +0200303 /* SCC Modem2 serial port */
304 atari_init_scc_port(B9600|CS8);
305 atari_console_driver.write = atari_scc_console_write;
Roman Zippeld6713b42007-05-01 22:32:45 +0200306 } else if (!strcmp(arg, "midi")) {
Roman Zippel6ff58012007-05-01 22:32:43 +0200307 /* MIDI port */
308 atari_init_midi_port(B9600|CS8);
309 atari_console_driver.write = atari_midi_console_write;
Roman Zippeld6713b42007-05-01 22:32:45 +0200310 } else if (!strcmp(arg, "par")) {
Roman Zippel6ff58012007-05-01 22:32:43 +0200311 /* parallel printer */
312 atari_turnoff_irq(IRQ_MFP_BUSY); /* avoid ints */
313 sound_ym.rd_data_reg_sel = 7; /* select mixer control */
314 sound_ym.wd_data = 0xff; /* sound off, ports are output */
315 sound_ym.rd_data_reg_sel = 15; /* select port B */
316 sound_ym.wd_data = 0; /* no char */
317 sound_ym.rd_data_reg_sel = 14; /* select port A */
318 sound_ym.wd_data = sound_ym.rd_data_reg_sel | 0x20; /* strobe H */
319 atari_console_driver.write = atari_par_console_write;
320 }
321 if (atari_console_driver.write)
322 register_console(&atari_console_driver);
Roman Zippeld6713b42007-05-01 22:32:45 +0200323
324 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
Roman Zippeld6713b42007-05-01 22:32:45 +0200326
327early_param("debug", atari_debug_setup);