blob: fbeed8c8ecbcfb3df43932f06a442729ddd42fab [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>
18
19#include <asm/atarihw.h>
20#include <asm/atariints.h>
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/* Flag that Modem1 port is already initialized and used */
23int atari_MFP_init_done;
24/* Flag that Modem1 port is already initialized and used */
25int atari_SCC_init_done;
26/* Can be set somewhere, if a SCC master reset has already be done and should
27 * not be repeated; used by kgdb */
28int atari_SCC_reset_done;
29
30static struct console atari_console_driver = {
Roman Zippel6ff58012007-05-01 22:32:43 +020031 .name = "debug",
32 .flags = CON_PRINTBUFFER,
33 .index = -1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070034};
35
36
Roman Zippel6ff58012007-05-01 22:32:43 +020037static inline void ata_mfp_out(char c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
Roman Zippel6ff58012007-05-01 22:32:43 +020039 while (!(mfp.trn_stat & 0x80)) /* wait for tx buf empty */
40 barrier();
41 mfp.usart_dta = c;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
Roman Zippel6ff58012007-05-01 22:32:43 +020044void atari_mfp_console_write(struct console *co, const char *str,
45 unsigned int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
Roman Zippel6ff58012007-05-01 22:32:43 +020047 while (count--) {
48 if (*str == '\n')
49 ata_mfp_out('\r');
50 ata_mfp_out(*str++);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 }
Roman Zippel6ff58012007-05-01 22:32:43 +020052}
53
54static inline void ata_scc_out(char c)
55{
56 do {
57 MFPDELAY();
58 } while (!(scc.cha_b_ctrl & 0x04)); /* wait for tx buf empty */
59 MFPDELAY();
60 scc.cha_b_data = c;
61}
62
63void atari_scc_console_write(struct console *co, const char *str,
64 unsigned int count)
65{
66 while (count--) {
67 if (*str == '\n')
68 ata_scc_out('\r');
69 ata_scc_out(*str++);
70 }
71}
72
73static inline void ata_midi_out(char c)
74{
75 while (!(acia.mid_ctrl & ACIA_TDRE)) /* wait for tx buf empty */
76 barrier();
77 acia.mid_data = c;
78}
79
80void atari_midi_console_write(struct console *co, const char *str,
81 unsigned int count)
82{
83 while (count--) {
84 if (*str == '\n')
85 ata_midi_out('\r');
86 ata_midi_out(*str++);
87 }
88}
89
90static int ata_par_out(char c)
91{
92 unsigned char tmp;
93 /* This a some-seconds timeout in case no printer is connected */
94 unsigned long i = loops_per_jiffy > 1 ? loops_per_jiffy : 10000000/HZ;
95
96 while ((mfp.par_dt_reg & 1) && --i) /* wait for BUSY == L */
97 ;
98 if (!i)
99 return 0;
100
101 sound_ym.rd_data_reg_sel = 15; /* select port B */
102 sound_ym.wd_data = c; /* put char onto port */
103 sound_ym.rd_data_reg_sel = 14; /* select port A */
104 tmp = sound_ym.rd_data_reg_sel;
105 sound_ym.wd_data = tmp & ~0x20; /* set strobe L */
106 MFPDELAY(); /* wait a bit */
107 sound_ym.wd_data = tmp | 0x20; /* set strobe H */
108 return 1;
109}
110
111static void atari_par_console_write(struct console *co, const char *str,
112 unsigned int count)
113{
114 static int printer_present = 1;
115
116 if (!printer_present)
117 return;
118
119 while (count--) {
120 if (*str == '\n') {
121 if (!ata_par_out('\r')) {
122 printer_present = 0;
123 return;
124 }
125 }
126 if (!ata_par_out(*str++)) {
127 printer_present = 0;
128 return;
129 }
130 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
133#ifdef CONFIG_SERIAL_CONSOLE
134int atari_mfp_console_wait_key(struct console *co)
135{
Roman Zippel6ff58012007-05-01 22:32:43 +0200136 while (!(mfp.rcv_stat & 0x80)) /* wait for rx buf filled */
137 barrier();
138 return mfp.usart_dta;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
141int atari_scc_console_wait_key(struct console *co)
142{
Roman Zippel6ff58012007-05-01 22:32:43 +0200143 do {
144 MFPDELAY();
145 } while (!(scc.cha_b_ctrl & 0x01)); /* wait for rx buf filled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 MFPDELAY();
Roman Zippel6ff58012007-05-01 22:32:43 +0200147 return scc.cha_b_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148}
149
150int atari_midi_console_wait_key(struct console *co)
151{
Roman Zippel6ff58012007-05-01 22:32:43 +0200152 while (!(acia.mid_ctrl & ACIA_RDRF)) /* wait for rx buf filled */
153 barrier();
154 return acia.mid_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
156#endif
157
Roman Zippel6ff58012007-05-01 22:32:43 +0200158/*
159 * The following two functions do a quick'n'dirty initialization of the MFP or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 * SCC serial ports. They're used by the debugging interface, kgdb, and the
Roman Zippel6ff58012007-05-01 22:32:43 +0200161 * serial console code.
162 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163#ifndef CONFIG_SERIAL_CONSOLE
Roman Zippel6ff58012007-05-01 22:32:43 +0200164static void __init atari_init_mfp_port(int cflag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#else
Roman Zippel6ff58012007-05-01 22:32:43 +0200166void atari_init_mfp_port(int cflag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#endif
168{
Roman Zippel6ff58012007-05-01 22:32:43 +0200169 /*
170 * timer values for 1200...115200 bps; > 38400 select 110, 134, or 150
171 * bps, resp., and work only correct if there's a RSVE or RSSPEED
172 */
173 static int baud_table[9] = { 16, 11, 8, 4, 2, 1, 175, 143, 128 };
174 int baud = cflag & CBAUD;
175 int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x04 : 0x06) : 0;
176 int csize = ((cflag & CSIZE) == CS7) ? 0x20 : 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Roman Zippel6ff58012007-05-01 22:32:43 +0200178 if (cflag & CBAUDEX)
179 baud += B38400;
180 if (baud < B1200 || baud > B38400+2)
181 baud = B9600; /* use default 9600bps for non-implemented rates */
182 baud -= B1200; /* baud_table[] starts at 1200bps */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Roman Zippel6ff58012007-05-01 22:32:43 +0200184 mfp.trn_stat &= ~0x01; /* disable TX */
185 mfp.usart_ctr = parity | csize | 0x88; /* 1:16 clk mode, 1 stop bit */
186 mfp.tim_ct_cd &= 0x70; /* stop timer D */
187 mfp.tim_dt_d = baud_table[baud];
188 mfp.tim_ct_cd |= 0x01; /* start timer D, 1:4 */
189 mfp.trn_stat |= 0x01; /* enable TX */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Roman Zippel6ff58012007-05-01 22:32:43 +0200191 atari_MFP_init_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192}
193
Roman Zippel6ff58012007-05-01 22:32:43 +0200194#define SCC_WRITE(reg, val) \
195 do { \
196 scc.cha_b_ctrl = (reg); \
197 MFPDELAY(); \
198 scc.cha_b_ctrl = (val); \
199 MFPDELAY(); \
200 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202/* loops_per_jiffy isn't initialized yet, so we can't use udelay(). This does a
203 * delay of ~ 60us. */
Roman Zippel6ff58012007-05-01 22:32:43 +0200204#define LONG_DELAY() \
205 do { \
206 int i; \
207 for (i = 100; i > 0; --i) \
208 MFPDELAY(); \
209 } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211#ifndef CONFIG_SERIAL_CONSOLE
Roman Zippel6ff58012007-05-01 22:32:43 +0200212static void __init atari_init_scc_port(int cflag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213#else
Roman Zippel6ff58012007-05-01 22:32:43 +0200214void atari_init_scc_port(int cflag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215#endif
216{
Roman Zippel6ff58012007-05-01 22:32:43 +0200217 extern int atari_SCC_reset_done;
218 static int clksrc_table[9] =
219 /* reg 11: 0x50 = BRG, 0x00 = RTxC, 0x28 = TRxC */
220 { 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x00, 0x00 };
221 static int brgsrc_table[9] =
222 /* reg 14: 0 = RTxC, 2 = PCLK */
223 { 2, 2, 2, 2, 2, 2, 0, 2, 2 };
224 static int clkmode_table[9] =
225 /* reg 4: 0x40 = x16, 0x80 = x32, 0xc0 = x64 */
226 { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x80 };
227 static int div_table[9] =
228 /* reg12 (BRG low) */
229 { 208, 138, 103, 50, 24, 11, 1, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Roman Zippel6ff58012007-05-01 22:32:43 +0200231 int baud = cflag & CBAUD;
232 int clksrc, clkmode, div, reg3, reg5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Roman Zippel6ff58012007-05-01 22:32:43 +0200234 if (cflag & CBAUDEX)
235 baud += B38400;
236 if (baud < B1200 || baud > B38400+2)
237 baud = B9600; /* use default 9600bps for non-implemented rates */
238 baud -= B1200; /* tables starts at 1200bps */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Roman Zippel6ff58012007-05-01 22:32:43 +0200240 clksrc = clksrc_table[baud];
241 clkmode = clkmode_table[baud];
242 div = div_table[baud];
243 if (ATARIHW_PRESENT(TT_MFP) && baud >= 6) {
244 /* special treatment for TT, where rates >= 38400 are done via TRxC */
245 clksrc = 0x28; /* TRxC */
246 clkmode = baud == 6 ? 0xc0 :
247 baud == 7 ? 0x80 : /* really 76800bps */
248 0x40; /* really 153600bps */
249 div = 0;
250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Roman Zippel6ff58012007-05-01 22:32:43 +0200252 reg3 = (cflag & CSIZE) == CS8 ? 0xc0 : 0x40;
253 reg5 = (cflag & CSIZE) == CS8 ? 0x60 : 0x20 | 0x82 /* assert DTR/RTS */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Roman Zippel6ff58012007-05-01 22:32:43 +0200255 (void)scc.cha_b_ctrl; /* reset reg pointer */
256 SCC_WRITE(9, 0xc0); /* reset */
257 LONG_DELAY(); /* extra delay after WR9 access */
258 SCC_WRITE(4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03)
259 : 0 | 0x04 /* 1 stopbit */ | clkmode);
260 SCC_WRITE(3, reg3);
261 SCC_WRITE(5, reg5);
262 SCC_WRITE(9, 0); /* no interrupts */
263 LONG_DELAY(); /* extra delay after WR9 access */
264 SCC_WRITE(10, 0); /* NRZ mode */
265 SCC_WRITE(11, clksrc); /* main clock source */
266 SCC_WRITE(12, div); /* BRG value */
267 SCC_WRITE(13, 0); /* BRG high byte */
268 SCC_WRITE(14, brgsrc_table[baud]);
269 SCC_WRITE(14, brgsrc_table[baud] | (div ? 1 : 0));
270 SCC_WRITE(3, reg3 | 1);
271 SCC_WRITE(5, reg5 | 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Roman Zippel6ff58012007-05-01 22:32:43 +0200273 atari_SCC_reset_done = 1;
274 atari_SCC_init_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
277#ifndef CONFIG_SERIAL_CONSOLE
Roman Zippel6ff58012007-05-01 22:32:43 +0200278static void __init atari_init_midi_port(int cflag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279#else
Roman Zippel6ff58012007-05-01 22:32:43 +0200280void atari_init_midi_port(int cflag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281#endif
282{
Roman Zippel6ff58012007-05-01 22:32:43 +0200283 int baud = cflag & CBAUD;
284 int csize = ((cflag & CSIZE) == CS8) ? 0x10 : 0x00;
285 /* warning 7N1 isn't possible! (instead 7O2 is used...) */
286 int parity = (cflag & PARENB) ? ((cflag & PARODD) ? 0x0c : 0x08) : 0x04;
287 int div;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Roman Zippel6ff58012007-05-01 22:32:43 +0200289 /* 4800 selects 7812.5, 115200 selects 500000, all other (incl. 9600 as
290 * default) the standard MIDI speed 31250. */
291 if (cflag & CBAUDEX)
292 baud += B38400;
293 if (baud == B4800)
294 div = ACIA_DIV64; /* really 7812.5 bps */
295 else if (baud == B38400+2 /* 115200 */)
296 div = ACIA_DIV1; /* really 500 kbps (does that work??) */
297 else
298 div = ACIA_DIV16; /* 31250 bps, standard for MIDI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Roman Zippel6ff58012007-05-01 22:32:43 +0200300 /* RTS low, ints disabled */
301 acia.mid_ctrl = div | csize | parity |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 ((atari_switches & ATARI_SWITCH_MIDI) ?
303 ACIA_RHTID : ACIA_RLTID);
304}
305
Roman Zippeld6713b42007-05-01 22:32:45 +0200306static int __init atari_debug_setup(char *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
Roman Zippeld6713b42007-05-01 22:32:45 +0200308 if (!MACH_IS_ATARI)
309 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Roman Zippeld6713b42007-05-01 22:32:45 +0200311 if (!strcmp(arg, "ser"))
312 /* defaults to ser2 for a Falcon and ser1 otherwise */
313 arg = MACH_IS_FALCON ? "ser2" : "ser1";
314
315 if (!strcmp(arg, "ser1")) {
Roman Zippel6ff58012007-05-01 22:32:43 +0200316 /* ST-MFP Modem1 serial port */
317 atari_init_mfp_port(B9600|CS8);
318 atari_console_driver.write = atari_mfp_console_write;
Roman Zippeld6713b42007-05-01 22:32:45 +0200319 } else if (!strcmp(arg, "ser2")) {
Roman Zippel6ff58012007-05-01 22:32:43 +0200320 /* SCC Modem2 serial port */
321 atari_init_scc_port(B9600|CS8);
322 atari_console_driver.write = atari_scc_console_write;
Roman Zippeld6713b42007-05-01 22:32:45 +0200323 } else if (!strcmp(arg, "midi")) {
Roman Zippel6ff58012007-05-01 22:32:43 +0200324 /* MIDI port */
325 atari_init_midi_port(B9600|CS8);
326 atari_console_driver.write = atari_midi_console_write;
Roman Zippeld6713b42007-05-01 22:32:45 +0200327 } else if (!strcmp(arg, "par")) {
Roman Zippel6ff58012007-05-01 22:32:43 +0200328 /* parallel printer */
329 atari_turnoff_irq(IRQ_MFP_BUSY); /* avoid ints */
330 sound_ym.rd_data_reg_sel = 7; /* select mixer control */
331 sound_ym.wd_data = 0xff; /* sound off, ports are output */
332 sound_ym.rd_data_reg_sel = 15; /* select port B */
333 sound_ym.wd_data = 0; /* no char */
334 sound_ym.rd_data_reg_sel = 14; /* select port A */
335 sound_ym.wd_data = sound_ym.rd_data_reg_sel | 0x20; /* strobe H */
336 atari_console_driver.write = atari_par_console_write;
337 }
338 if (atari_console_driver.write)
339 register_console(&atari_console_driver);
Roman Zippeld6713b42007-05-01 22:32:45 +0200340
341 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
Roman Zippeld6713b42007-05-01 22:32:45 +0200343
344early_param("debug", atari_debug_setup);