1 /* Serialport functions for debugging
3 * Copyright (c) 2000 Axis Communications AB
8 * console_print_etrax(char *buf)
14 * $Log: debugport.c,v $
15 * Revision 1.27 2005/06/10 10:34:14 starvik
16 * Real console support
18 * Revision 1.26 2005/06/07 07:06:07 starvik
19 * Added LF->CR translation to make ETRAX customers happy.
21 * Revision 1.25 2005/03/08 08:56:47 mikaelam
22 * Do only set index as port->index if port is defined, otherwise use the index from the command line
24 * Revision 1.24 2005/01/19 10:26:33 mikaelam
25 * Return the cris serial driver in console device driver callback function
27 * Revision 1.23 2005/01/14 10:12:17 starvik
28 * KGDB on separate port.
29 * Console fixes from 2.4.
31 * Revision 1.22 2005/01/11 16:06:13 starvik
34 * Revision 1.21 2005/01/11 13:49:14 starvik
35 * Added raw_printk to be used where we don't trust the console.
37 * Revision 1.20 2004/12/27 11:18:32 starvik
38 * Merge of Linux 2.6.10 (not functional yet).
40 * Revision 1.19 2004/10/21 07:26:16 starvik
41 * Made it possible to specify console settings on kernel command line.
43 * Revision 1.18 2004/10/19 13:07:37 starvik
44 * Merge of Linux 2.6.9
46 * Revision 1.17 2004/09/29 10:33:46 starvik
47 * Resolved a dealock when printing debug from kernel.
49 * Revision 1.16 2004/08/24 06:12:19 starvik
52 * Revision 1.15 2004/08/16 12:37:19 starvik
53 * Merge of Linux 2.6.8
55 * Revision 1.14 2004/05/17 13:11:29 starvik
56 * Disable DMA until real serial driver is up
58 * Revision 1.13 2004/05/14 07:58:01 starvik
59 * Merge of changes from 2.4
61 * Revision 1.12 2003/09/11 07:29:49 starvik
62 * Merge of Linux 2.6.0-test5
64 * Revision 1.11 2003/07/07 09:53:36 starvik
65 * Revert all the 2.5.74 merge changes to make the console work again
67 * Revision 1.9 2003/02/17 17:07:23 starvik
68 * Solved the problem with corrupted debug output (from Linux 2.4)
69 * * Wait until DMA, FIFO and pipe is empty before and after transmissions
70 * * Buffer data until a FIFO flush can be triggered.
72 * Revision 1.8 2003/01/22 06:48:36 starvik
73 * Fixed warnings issued by GCC 3.2.1
75 * Revision 1.7 2002/12/12 08:26:32 starvik
76 * Don't use C-comments inside CVS comments
78 * Revision 1.6 2002/12/11 15:42:02 starvik
79 * Extracted v10 (ETRAX 100LX) specific stuff from arch/cris/kernel/
81 * Revision 1.5 2002/11/20 06:58:03 starvik
84 * Revision 1.4 2002/11/19 14:35:24 starvik
85 * Changes from linux 2.4
86 * Changed struct initializer syntax to the currently prefered notation
88 * Revision 1.3 2002/11/06 09:47:03 starvik
89 * Modified for new interrupt macros
91 * Revision 1.2 2002/01/21 15:21:50 bjornw
92 * Update for kdev_t changes
94 * Revision 1.6 2001/04/17 13:58:39 orjanf
95 * * Renamed CONFIG_KGDB to CONFIG_ETRAX_KGDB.
97 * Revision 1.5 2001/03/26 14:22:05 bjornw
98 * Namechange of some config options
100 * Revision 1.4 2000/10/06 12:37:26 bjornw
101 * Use physical addresses when talking to DMA
106 #include <linux/config.h>
107 #include <linux/console.h>
108 #include <linux/init.h>
109 #include <linux/major.h>
110 #include <linux/delay.h>
111 #include <linux/tty.h>
112 #include <asm/system.h>
113 #include <asm/arch/svinto.h>
114 #include <asm/io.h> /* Get SIMCOUT. */
119 const volatile unsigned* read;
120 volatile char* write;
121 volatile unsigned* xoff;
123 volatile char* tr_ctrl;
124 volatile char* rec_ctrl;
126 unsigned int started;
127 unsigned long baudrate;
128 unsigned char parity;
132 struct dbg_port ports[]=
142 IO_STATE(R_IRQ_MASK1_SET, ser0_data, set),
156 IO_STATE(R_IRQ_MASK1_SET, ser1_data, set),
170 IO_STATE(R_IRQ_MASK1_SET, ser2_data, set),
184 IO_STATE(R_IRQ_MASK1_SET, ser3_data, set),
192 extern struct tty_driver *serial_driver;
194 struct dbg_port* port =
195 #if defined(CONFIG_ETRAX_DEBUG_PORT0)
197 #elif defined(CONFIG_ETRAX_DEBUG_PORT1)
199 #elif defined(CONFIG_ETRAX_DEBUG_PORT2)
201 #elif defined(CONFIG_ETRAX_DEBUG_PORT3)
207 static struct dbg_port* kgdb_port =
208 #if defined(CONFIG_ETRAX_KGDB_PORT0)
210 #elif defined(CONFIG_ETRAX_KGDB_PORT1)
212 #elif defined(CONFIG_ETRAX_KGDB_PORT2)
214 #elif defined(CONFIG_ETRAX_KGDB_PORT3)
221 start_port(struct dbg_port* p)
223 unsigned long rec_ctrl = 0;
224 unsigned long tr_ctrl = 0;
235 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma6);
236 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma6, unused);
238 else if (p->index == 1)
240 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma8);
241 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma8, usb);
243 else if (p->index == 2)
245 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma2);
246 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma2, par0);
247 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma3);
248 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma3, par0);
249 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, ser2, select);
253 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma4);
254 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma4, par1);
255 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma5);
256 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma5, par1);
257 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, ser3, select);
260 *R_GEN_CONFIG = genconfig_shadow;
263 IO_STATE(R_SERIAL0_XOFF, tx_stop, enable) |
264 IO_STATE(R_SERIAL0_XOFF, auto_xoff, disable) |
265 IO_FIELD(R_SERIAL0_XOFF, xoff_char, 0);
272 IO_STATE(R_SERIAL0_BAUD, tr_baud, c115k2Hz) |
273 IO_STATE(R_SERIAL0_BAUD, rec_baud, c115k2Hz);
277 IO_STATE(R_SERIAL0_BAUD, tr_baud, c1200Hz) |
278 IO_STATE(R_SERIAL0_BAUD, rec_baud, c1200Hz);
282 IO_STATE(R_SERIAL0_BAUD, tr_baud, c2400Hz) |
283 IO_STATE(R_SERIAL0_BAUD, rec_baud, c2400Hz);
287 IO_STATE(R_SERIAL0_BAUD, tr_baud, c4800Hz) |
288 IO_STATE(R_SERIAL0_BAUD, rec_baud, c4800Hz);
292 IO_STATE(R_SERIAL0_BAUD, tr_baud, c9600Hz) |
293 IO_STATE(R_SERIAL0_BAUD, rec_baud, c9600Hz);
297 IO_STATE(R_SERIAL0_BAUD, tr_baud, c19k2Hz) |
298 IO_STATE(R_SERIAL0_BAUD, rec_baud, c19k2Hz);
302 IO_STATE(R_SERIAL0_BAUD, tr_baud, c38k4Hz) |
303 IO_STATE(R_SERIAL0_BAUD, rec_baud, c38k4Hz);
307 IO_STATE(R_SERIAL0_BAUD, tr_baud, c57k6Hz) |
308 IO_STATE(R_SERIAL0_BAUD, rec_baud, c57k6Hz);
312 IO_STATE(R_SERIAL0_BAUD, tr_baud, c115k2Hz) |
313 IO_STATE(R_SERIAL0_BAUD, rec_baud, c115k2Hz);
317 if (p->parity == 'E') {
319 IO_STATE(R_SERIAL0_REC_CTRL, rec_par, even) |
320 IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, enable);
322 IO_STATE(R_SERIAL0_TR_CTRL, tr_par, even) |
323 IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, enable);
324 } else if (p->parity == 'O') {
326 IO_STATE(R_SERIAL0_REC_CTRL, rec_par, odd) |
327 IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, enable);
329 IO_STATE(R_SERIAL0_TR_CTRL, tr_par, odd) |
330 IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, enable);
333 IO_STATE(R_SERIAL0_REC_CTRL, rec_par, even) |
334 IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, disable);
336 IO_STATE(R_SERIAL0_TR_CTRL, tr_par, even) |
337 IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, disable);
341 rec_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_bitnr, rec_7bit);
342 tr_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_bitnr, tr_7bit);
346 rec_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_bitnr, rec_8bit);
347 tr_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_bitnr, tr_8bit);
351 IO_STATE(R_SERIAL0_REC_CTRL, dma_err, stop) |
352 IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable) |
353 IO_STATE(R_SERIAL0_REC_CTRL, rts_, active) |
354 IO_STATE(R_SERIAL0_REC_CTRL, sampling, middle) |
355 IO_STATE(R_SERIAL0_REC_CTRL, rec_stick_par, normal) |
359 IO_FIELD(R_SERIAL0_TR_CTRL, txd, 0) |
360 IO_STATE(R_SERIAL0_TR_CTRL, tr_enable, enable) |
361 IO_STATE(R_SERIAL0_TR_CTRL, auto_cts, disabled) |
362 IO_STATE(R_SERIAL0_TR_CTRL, stop_bits, one_bit) |
363 IO_STATE(R_SERIAL0_TR_CTRL, tr_stick_par, normal) |
368 console_write_direct(struct console *co, const char *buf, unsigned int len)
372 local_irq_save(flags);
378 for (i = 0; i < len; i++) {
380 if (buf[i] == '\n') {
381 while (!(*port->read & IO_MASK(R_SERIAL0_READ, tr_ready)))
385 /* Wait until transmitter is ready and send.*/
386 while (!(*port->read & IO_MASK(R_SERIAL0_READ, tr_ready)))
388 *port->write = buf[i];
390 local_irq_restore(flags);
393 int raw_printk(const char *fmt, ...)
395 static char buf[1024];
397 static int first = 1;
399 /* Force reinitialization of the port to get manual mode. */
406 printed_len = vsnprintf(buf, sizeof(buf), fmt, args);
408 console_write_direct(NULL, buf, strlen(buf));
413 console_write(struct console *co, const char *buf, unsigned int len)
418 #ifdef CONFIG_SVINTO_SIM
419 /* no use to simulate the serial debug output */
424 console_write_direct(co, buf, len);
427 /* legacy function */
430 console_print_etrax(const char *buf)
432 console_write(NULL, buf, strlen(buf));
435 /* Use polling to get a single character FROM the debug port */
440 unsigned long readval;
446 readval = *kgdb_port->read;
447 } while (!(readval & IO_MASK(R_SERIAL0_READ, data_avail)));
449 return (readval & IO_MASK(R_SERIAL0_READ, data_in));
452 /* Use polling to put a single character to the debug port */
455 putDebugChar(int val)
460 while (!(*kgdb_port->read & IO_MASK(R_SERIAL0_READ, tr_ready)))
462 *kgdb_port->write = val;
465 /* Enable irq for receiving chars on the debug port, used by kgdb */
473 *R_IRQ_MASK1_SET = kgdb_port->irq;
474 /* use R_VECT_MASK directly, since we really bypass Linux normal
475 * IRQ handling in kgdb anyway, we don't need to use enable_irq
477 *R_VECT_MASK_SET = IO_STATE(R_VECT_MASK_SET, serial, set);
479 *kgdb_port->rec_ctrl = IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable);
483 console_setup(struct console *co, char *options)
488 port = &ports[co->index];
489 port->baudrate = 115200;
492 port->baudrate = simple_strtoul(options, NULL, 10);
494 while(*s >= '0' && *s <= '9')
496 if (*s) port->parity = *s++;
497 if (*s) port->bits = *s++ - '0';
504 /* This is a dummy serial device that throws away anything written to it.
505 * This is used when no debug output is wanted.
507 static struct tty_driver dummy_driver;
509 static int dummy_open(struct tty_struct *tty, struct file * filp)
514 static void dummy_close(struct tty_struct *tty, struct file * filp)
518 static int dummy_write(struct tty_struct * tty,
519 const unsigned char *buf, int count)
525 dummy_write_room(struct tty_struct *tty)
531 init_dummy_console(void)
533 memset(&dummy_driver, 0, sizeof(struct tty_driver));
534 dummy_driver.driver_name = "serial";
535 dummy_driver.name = "ttyS";
536 dummy_driver.major = TTY_MAJOR;
537 dummy_driver.minor_start = 68;
538 dummy_driver.num = 1; /* etrax100 has 4 serial ports */
539 dummy_driver.type = TTY_DRIVER_TYPE_SERIAL;
540 dummy_driver.subtype = SERIAL_TYPE_NORMAL;
541 dummy_driver.init_termios = tty_std_termios;
542 dummy_driver.init_termios.c_cflag =
543 B115200 | CS8 | CREAD | HUPCL | CLOCAL; /* is normally B9600 default... */
544 dummy_driver.flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
546 dummy_driver.open = dummy_open;
547 dummy_driver.close = dummy_close;
548 dummy_driver.write = dummy_write;
549 dummy_driver.write_room = dummy_write_room;
550 if (tty_register_driver(&dummy_driver))
551 panic("Couldn't register dummy serial driver\n");
554 static struct tty_driver*
555 etrax_console_device(struct console* co, int *index)
558 *index = port->index;
559 return port ? serial_driver : &dummy_driver;
562 static struct console sercons = {
564 write: console_write,
566 device : etrax_console_device,
568 setup : console_setup,
569 flags : CON_PRINTBUFFER,
574 static struct console sercons0 = {
576 write: console_write,
578 device : etrax_console_device,
580 setup : console_setup,
581 flags : CON_PRINTBUFFER,
587 static struct console sercons1 = {
589 write: console_write,
591 device : etrax_console_device,
593 setup : console_setup,
594 flags : CON_PRINTBUFFER,
599 static struct console sercons2 = {
601 write: console_write,
603 device : etrax_console_device,
605 setup : console_setup,
606 flags : CON_PRINTBUFFER,
611 static struct console sercons3 = {
613 write: console_write,
615 device : etrax_console_device,
617 setup : console_setup,
618 flags : CON_PRINTBUFFER,
624 * Register console (for printk's etc)
628 init_etrax_debug(void)
630 static int first = 1;
633 unregister_console(&sercons);
634 register_console(&sercons0);
635 register_console(&sercons1);
636 register_console(&sercons2);
637 register_console(&sercons3);
638 init_dummy_console();
643 register_console(&sercons);
645 #ifdef CONFIG_ETRAX_KGDB
646 start_port(kgdb_port);
650 __initcall(init_etrax_debug);