2 * linux/arch/m68k/mac/debug.c
4 * Shamelessly stolen (SCC code and general framework) from:
6 * linux/arch/m68k/atari/debug.c
8 * Atari debugging and serial console stuff
10 * Assembled of parts of former atari/config.c 97-12-18 by Roman Hodek
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
17 #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>
24 #define BOOTINFO_COMPAT_1_0
25 #include <asm/setup.h>
26 #include <asm/bootinfo.h>
27 #include <asm/macints.h>
29 extern unsigned long mac_videobase;
30 extern unsigned long mac_videodepth;
31 extern unsigned long mac_rowbytes;
33 extern void mac_serial_print(const char *);
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 ...
46 * The 'pos' argument now simply means 'linefeed after print' ...
50 static int peng, line;
55 void mac_debugging_short(int pos, short num)
58 unsigned char *pengoffset;
64 printk("debug: %d !\n", num);
69 /* printk("debug: %d !\n", num); */
73 /* calculate current offset */
74 pengoffset = (unsigned char *)mac_videobase +
75 (150+line*2) * mac_rowbytes + 80 * peng;
79 for (i = 0; i < 8 * sizeof(short); i++) { /* # of bits */
80 /* value mask for bit i, reverse order */
81 *pptr++ = (num & (1 << (8*sizeof(short)-i-1)) ? 0xFF : 0x00);
93 void mac_debugging_long(int pos, long addr)
96 unsigned char *pengoffset;
102 printk("debug: #%ld !\n", addr);
107 /* printk("debug: #%ld !\n", addr); */
111 pengoffset=(unsigned char *)(mac_videobase+(150+line*2)*mac_rowbytes)
116 for (i = 0; i < 8 * sizeof(long); i++) { /* # of bits */
117 *pptr++ = (addr & (1 << (8*sizeof(long)-i-1)) ? 0xFF : 0x00);
133 * TODO: serial debug code
146 # define scc (*((volatile struct mac_SCC*)mac_bi_data.sccbase))
148 static int scc_port = -1;
150 static struct console mac_console_driver = {
152 .flags = CON_PRINTBUFFER,
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)
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.
171 static void mac_debug_console_write(struct console *co, const char *str,
174 mac_serial_print(str);
179 /* Mac: loops_per_jiffy min. 19000 ^= .5 us; MFPDELAY was 0.6 us*/
183 static inline void mac_sccb_out(char c)
188 for (i = uSEC; i > 0; --i)
190 } while (!(scc.cha_b_ctrl & 0x04)); /* wait for tx buf empty */
191 for (i = uSEC; i > 0; --i)
196 static inline void mac_scca_out(char c)
201 for (i = uSEC; i > 0; --i)
203 } while (!(scc.cha_a_ctrl & 0x04)); /* wait for tx buf empty */
204 for (i = uSEC; i > 0; --i)
209 static void mac_sccb_console_write(struct console *co, const char *str,
215 mac_sccb_out(*str++);
219 static void mac_scca_console_write(struct console *co, const char *str,
225 mac_scca_out(*str++);
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) \
236 scc.cha_b_ctrl = (reg); \
237 for (i = uSEC; i > 0; --i) \
239 scc.cha_b_ctrl = (val); \
240 for (i = uSEC; i > 0; --i) \
244 #define SCCA_WRITE(reg,val) \
247 scc.cha_a_ctrl = (reg); \
248 for (i = uSEC; i > 0; --i) \
250 scc.cha_a_ctrl = (val); \
251 for (i = uSEC; i > 0; --i) \
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*/
258 #define LONG_DELAY() \
261 for (i = 60*uSEC; i > 0; --i) \
265 static void __init mac_init_scc_port(int cflag, int port)
268 * baud rates: 1200, 1800, 2400, 4800, 9600, 19.2k, 38.4k, 57.6k, 115.2k
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 };
281 int baud = cflag & CBAUD;
282 int clksrc, clkmode, div, reg3, reg5;
286 if (baud < B1200 || baud > B38400+2)
287 baud = B9600; /* use default 9600bps for non-implemented rates */
288 baud -= B1200; /* tables starts at 1200bps */
290 clksrc = clksrc_table[baud];
291 clkmode = clkmode_table[baud];
292 div = div_table[baud];
294 reg3 = (((cflag & CSIZE) == CS8) ? 0xc0 : 0x40);
295 reg5 = (((cflag & CSIZE) == CS8) ? 0x60 : 0x20) | 0x82 /* assert DTR/RTS */;
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 */ |
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 */
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 |
320 0x04 /* 1 stopbit */ |
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 */
331 SCCA_WRITE(3, reg3 | 1);
332 SCCA_WRITE(5, reg5 | 8);
335 #endif /* DEBUG_SERIAL */
337 static int __init mac_debug_setup(char *arg)
343 if (!strcmp(arg, "ser") || !strcmp(arg, "ser1")) {
345 mac_init_scc_port(B9600|CS8, 0);
346 mac_console_driver.write = mac_scca_console_write;
348 } else if (!strcmp(arg, "ser2")) {
349 /* Mac printer port */
350 mac_init_scc_port(B9600|CS8, 1);
351 mac_console_driver.write = mac_sccb_console_write;
356 if (!strcmp(arg, "scn") || !strcmp(arg, "con")) {
357 /* display, using head.S console routines */
358 mac_console_driver.write = mac_debug_console_write;
361 if (mac_console_driver.write)
362 register_console(&mac_console_driver);
366 early_param("debug", mac_debug_setup);