blob: 65dd77a742a341c493a64982b16a0ec5de60d445 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m68k/mac/debug.c
3 *
4 * Shamelessly stolen (SCC code and general framework) from:
5 *
6 * linux/arch/m68k/atari/debug.c
7 *
8 * Atari debugging and serial console stuff
9 *
10 * Assembled of parts of former atari/config.c 97-12-18 by Roman Hodek
11 *
12 * This file is subject to the terms and conditions of the GNU General Public
13 * License. See the file COPYING in the main directory of this archive
14 * for more details.
15 */
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/types.h>
18#include <linux/sched.h>
19#include <linux/tty.h>
20#include <linux/console.h>
21#include <linux/init.h>
22#include <linux/delay.h>
23
24#define BOOTINFO_COMPAT_1_0
25#include <asm/setup.h>
26#include <asm/bootinfo.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/macints.h>
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029extern unsigned long mac_videobase;
30extern unsigned long mac_videodepth;
31extern unsigned long mac_rowbytes;
32
33extern void mac_serial_print(const char *);
34
35#define DEBUG_HEADS
36#undef DEBUG_SCREEN
37#define DEBUG_SERIAL
38
39/*
40 * These two auxiliary debug functions should go away ASAP. Only usage:
41 * before the console output is up (after head.S come some other crucial
42 * setup routines :-) it permits writing 'data' to the screen as bit patterns
43 * (good luck reading those). Helped to figure that the bootinfo contained
44 * garbage data on the amount and size of memory chunks ...
45 *
46 * The 'pos' argument now simply means 'linefeed after print' ...
47 */
48
49#ifdef DEBUG_SCREEN
Roman Zippel6ff58012007-05-01 22:32:43 +020050static int peng, line;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#endif
52
Adrian Bunk8dfbdf42008-07-17 21:16:25 +020053#if 0
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055void mac_debugging_short(int pos, short num)
56{
57#ifdef DEBUG_SCREEN
58 unsigned char *pengoffset;
59 unsigned char *pptr;
60 int i;
61#endif
62
63#ifdef DEBUG_SERIAL
64 printk("debug: %d !\n", num);
65#endif
66
67#ifdef DEBUG_SCREEN
68 if (!MACH_IS_MAC) {
69 /* printk("debug: %d !\n", num); */
70 return;
71 }
72
73 /* calculate current offset */
Roman Zippel6ff58012007-05-01 22:32:43 +020074 pengoffset = (unsigned char *)mac_videobase +
Mariusz Kozlowski4eb527a2007-06-01 00:46:30 -070075 (150+line*2) * mac_rowbytes + 80 * peng;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Roman Zippel6ff58012007-05-01 22:32:43 +020077 pptr = pengoffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Roman Zippel6ff58012007-05-01 22:32:43 +020079 for (i = 0; i < 8 * sizeof(short); i++) { /* # of bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 /* value mask for bit i, reverse order */
Roman Zippel6ff58012007-05-01 22:32:43 +020081 *pptr++ = (num & (1 << (8*sizeof(short)-i-1)) ? 0xFF : 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 }
83
84 peng++;
85
86 if (pos) {
87 line++;
88 peng = 0;
89 }
90#endif
91}
92
93void mac_debugging_long(int pos, long addr)
94{
95#ifdef DEBUG_SCREEN
96 unsigned char *pengoffset;
97 unsigned char *pptr;
98 int i;
99#endif
100
101#ifdef DEBUG_SERIAL
102 printk("debug: #%ld !\n", addr);
103#endif
104
105#ifdef DEBUG_SCREEN
106 if (!MACH_IS_MAC) {
107 /* printk("debug: #%ld !\n", addr); */
108 return;
109 }
110
111 pengoffset=(unsigned char *)(mac_videobase+(150+line*2)*mac_rowbytes)
112 +80*peng;
113
Roman Zippel6ff58012007-05-01 22:32:43 +0200114 pptr = pengoffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Roman Zippel6ff58012007-05-01 22:32:43 +0200116 for (i = 0; i < 8 * sizeof(long); i++) { /* # of bits */
117 *pptr++ = (addr & (1 << (8*sizeof(long)-i-1)) ? 0xFF : 0x00);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119
120 peng++;
121
122 if (pos) {
123 line++;
124 peng = 0;
125 }
126#endif
127}
128
Adrian Bunk8dfbdf42008-07-17 21:16:25 +0200129#endif /* 0 */
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#ifdef DEBUG_SERIAL
132/*
133 * TODO: serial debug code
134 */
135
Roman Zippel6ff58012007-05-01 22:32:43 +0200136struct mac_SCC {
137 u_char cha_b_ctrl;
138 u_char char_dummy1;
139 u_char cha_a_ctrl;
140 u_char char_dummy2;
141 u_char cha_b_data;
142 u_char char_dummy3;
143 u_char cha_a_data;
144};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146# define scc (*((volatile struct mac_SCC*)mac_bi_data.sccbase))
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static int scc_port = -1;
149
150static struct console mac_console_driver = {
Roman Zippel6ff58012007-05-01 22:32:43 +0200151 .name = "debug",
152 .flags = CON_PRINTBUFFER,
153 .index = -1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154};
155
156/*
157 * Crude hack to get console output to the screen before the framebuffer
158 * is initialized (happens a lot later in 2.1!).
159 * We just use the console routines declared in head.S, this will interfere
160 * with regular framebuffer console output and should be used exclusively
161 * to debug kernel problems manifesting before framebuffer init (aka WSOD)
162 *
163 * To keep this hack from interfering with the regular console driver, either
164 * deregister this driver before/on framebuffer console init, or silence this
165 * function after the fbcon driver is running (will lose console messages!?).
166 * To debug real early bugs, need to write a 'mac_register_console_hack()'
167 * that is called from start_kernel() before setup_arch() and just registers
168 * this driver if Mac.
169 */
170
Adrian Bunk8dfbdf42008-07-17 21:16:25 +0200171static void mac_debug_console_write(struct console *co, const char *str,
172 unsigned int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 mac_serial_print(str);
175}
176
177
178
179/* Mac: loops_per_jiffy min. 19000 ^= .5 us; MFPDELAY was 0.6 us*/
180
181#define uSEC 1
182
Roman Zippel6ff58012007-05-01 22:32:43 +0200183static inline void mac_sccb_out(char c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
Roman Zippel6ff58012007-05-01 22:32:43 +0200185 int i;
186
187 do {
188 for (i = uSEC; i > 0; --i)
189 barrier();
190 } while (!(scc.cha_b_ctrl & 0x04)); /* wait for tx buf empty */
191 for (i = uSEC; i > 0; --i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 barrier();
Roman Zippel6ff58012007-05-01 22:32:43 +0200193 scc.cha_b_data = c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
Roman Zippel6ff58012007-05-01 22:32:43 +0200196static inline void mac_scca_out(char c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
Roman Zippel6ff58012007-05-01 22:32:43 +0200198 int i;
199
200 do {
201 for (i = uSEC; i > 0; --i)
202 barrier();
203 } while (!(scc.cha_a_ctrl & 0x04)); /* wait for tx buf empty */
204 for (i = uSEC; i > 0; --i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 barrier();
Roman Zippel6ff58012007-05-01 22:32:43 +0200206 scc.cha_a_data = c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208
Adrian Bunk8dfbdf42008-07-17 21:16:25 +0200209static void mac_sccb_console_write(struct console *co, const char *str,
210 unsigned int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
Roman Zippel6ff58012007-05-01 22:32:43 +0200212 while (count--) {
213 if (*str == '\n')
214 mac_sccb_out('\r');
215 mac_sccb_out(*str++);
216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}
218
Adrian Bunk8dfbdf42008-07-17 21:16:25 +0200219static void mac_scca_console_write(struct console *co, const char *str,
220 unsigned int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Roman Zippel6ff58012007-05-01 22:32:43 +0200222 while (count--) {
223 if (*str == '\n')
224 mac_scca_out('\r');
225 mac_scca_out(*str++);
226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
229
230/* The following two functions do a quick'n'dirty initialization of the MFP or
231 * SCC serial ports. They're used by the debugging interface, kgdb, and the
232 * serial console code. */
233#define SCCB_WRITE(reg,val) \
Roman Zippel6ff58012007-05-01 22:32:43 +0200234 do { \
235 int i; \
236 scc.cha_b_ctrl = (reg); \
237 for (i = uSEC; i > 0; --i) \
238 barrier(); \
239 scc.cha_b_ctrl = (val); \
240 for (i = uSEC; i > 0; --i) \
241 barrier(); \
242 } while(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244#define SCCA_WRITE(reg,val) \
Roman Zippel6ff58012007-05-01 22:32:43 +0200245 do { \
246 int i; \
247 scc.cha_a_ctrl = (reg); \
248 for (i = uSEC; i > 0; --i) \
249 barrier(); \
250 scc.cha_a_ctrl = (val); \
251 for (i = uSEC; i > 0; --i) \
252 barrier(); \
253 } while(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255/* loops_per_jiffy isn't initialized yet, so we can't use udelay(). This does a
256 * delay of ~ 60us. */
257/* Mac: loops_per_jiffy min. 19000 ^= .5 us; MFPDELAY was 0.6 us*/
Roman Zippel6ff58012007-05-01 22:32:43 +0200258#define LONG_DELAY() \
259 do { \
260 int i; \
261 for (i = 60*uSEC; i > 0; --i) \
262 barrier(); \
263 } while(0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Roman Zippel6ff58012007-05-01 22:32:43 +0200265static void __init mac_init_scc_port(int cflag, int port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 /*
268 * baud rates: 1200, 1800, 2400, 4800, 9600, 19.2k, 38.4k, 57.6k, 115.2k
269 */
270
271 static int clksrc_table[9] =
272 /* reg 11: 0x50 = BRG, 0x00 = RTxC, 0x28 = TRxC */
273 { 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x00, 0x00 };
274 static int clkmode_table[9] =
275 /* reg 4: 0x40 = x16, 0x80 = x32, 0xc0 = x64 */
276 { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x80 };
277 static int div_table[9] =
278 /* reg12 (BRG low) */
279 { 94, 62, 46, 22, 10, 4, 1, 0, 0 };
280
Roman Zippel6ff58012007-05-01 22:32:43 +0200281 int baud = cflag & CBAUD;
282 int clksrc, clkmode, div, reg3, reg5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Roman Zippel6ff58012007-05-01 22:32:43 +0200284 if (cflag & CBAUDEX)
285 baud += B38400;
286 if (baud < B1200 || baud > B38400+2)
287 baud = B9600; /* use default 9600bps for non-implemented rates */
288 baud -= B1200; /* tables starts at 1200bps */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Roman Zippel6ff58012007-05-01 22:32:43 +0200290 clksrc = clksrc_table[baud];
291 clkmode = clkmode_table[baud];
292 div = div_table[baud];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Roman Zippel6ff58012007-05-01 22:32:43 +0200294 reg3 = (((cflag & CSIZE) == CS8) ? 0xc0 : 0x40);
295 reg5 = (((cflag & CSIZE) == CS8) ? 0x60 : 0x20) | 0x82 /* assert DTR/RTS */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Roman Zippel6ff58012007-05-01 22:32:43 +0200297 if (port == 1) {
298 (void)scc.cha_b_ctrl; /* reset reg pointer */
299 SCCB_WRITE(9, 0xc0); /* reset */
300 LONG_DELAY(); /* extra delay after WR9 access */
301 SCCB_WRITE(4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03) : 0 |
302 0x04 /* 1 stopbit */ |
303 clkmode);
304 SCCB_WRITE(3, reg3);
305 SCCB_WRITE(5, reg5);
306 SCCB_WRITE(9, 0); /* no interrupts */
307 LONG_DELAY(); /* extra delay after WR9 access */
308 SCCB_WRITE(10, 0); /* NRZ mode */
309 SCCB_WRITE(11, clksrc); /* main clock source */
310 SCCB_WRITE(12, div); /* BRG value */
311 SCCB_WRITE(13, 0); /* BRG high byte */
312 SCCB_WRITE(14, 1);
313 SCCB_WRITE(3, reg3 | 1);
314 SCCB_WRITE(5, reg5 | 8);
315 } else if (port == 0) {
316 (void)scc.cha_a_ctrl; /* reset reg pointer */
317 SCCA_WRITE(9, 0xc0); /* reset */
318 LONG_DELAY(); /* extra delay after WR9 access */
319 SCCA_WRITE(4, (cflag & PARENB) ? ((cflag & PARODD) ? 0x01 : 0x03) : 0 |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 0x04 /* 1 stopbit */ |
Roman Zippel6ff58012007-05-01 22:32:43 +0200321 clkmode);
322 SCCA_WRITE(3, reg3);
323 SCCA_WRITE(5, reg5);
324 SCCA_WRITE(9, 0); /* no interrupts */
325 LONG_DELAY(); /* extra delay after WR9 access */
326 SCCA_WRITE(10, 0); /* NRZ mode */
327 SCCA_WRITE(11, clksrc); /* main clock source */
328 SCCA_WRITE(12, div); /* BRG value */
329 SCCA_WRITE(13, 0); /* BRG high byte */
330 SCCA_WRITE(14, 1);
331 SCCA_WRITE(3, reg3 | 1);
332 SCCA_WRITE(5, reg5 | 8);
333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334}
335#endif /* DEBUG_SERIAL */
336
Roman Zippeld6713b42007-05-01 22:32:45 +0200337static int __init mac_debug_setup(char *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Roman Zippeld6713b42007-05-01 22:32:45 +0200339 if (!MACH_IS_MAC)
340 return 0;
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#ifdef DEBUG_SERIAL
Roman Zippeld6713b42007-05-01 22:32:45 +0200343 if (!strcmp(arg, "ser") || !strcmp(arg, "ser1")) {
Roman Zippel6ff58012007-05-01 22:32:43 +0200344 /* Mac modem port */
345 mac_init_scc_port(B9600|CS8, 0);
346 mac_console_driver.write = mac_scca_console_write;
347 scc_port = 0;
Roman Zippeld6713b42007-05-01 22:32:45 +0200348 } else if (!strcmp(arg, "ser2")) {
Roman Zippel6ff58012007-05-01 22:32:43 +0200349 /* Mac printer port */
350 mac_init_scc_port(B9600|CS8, 1);
351 mac_console_driver.write = mac_sccb_console_write;
352 scc_port = 1;
353 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#endif
355#ifdef DEBUG_HEADS
Roman Zippeld6713b42007-05-01 22:32:45 +0200356 if (!strcmp(arg, "scn") || !strcmp(arg, "con")) {
Roman Zippel6ff58012007-05-01 22:32:43 +0200357 /* display, using head.S console routines */
358 mac_console_driver.write = mac_debug_console_write;
359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360#endif
Roman Zippel6ff58012007-05-01 22:32:43 +0200361 if (mac_console_driver.write)
362 register_console(&mac_console_driver);
Roman Zippeld6713b42007-05-01 22:32:45 +0200363 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
Roman Zippeld6713b42007-05-01 22:32:45 +0200365
366early_param("debug", mac_debug_setup);