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/console.h>
107 #include <linux/init.h>
108 #include <linux/major.h>
109 #include <linux/delay.h>
110 #include <linux/tty.h>
111 #include <asm/system.h>
112 #include <asm/arch/svinto.h>
113 #include <asm/io.h> /* Get SIMCOUT. */
118 const volatile unsigned* read;
119 volatile char* write;
120 volatile unsigned* xoff;
122 volatile char* tr_ctrl;
123 volatile char* rec_ctrl;
125 unsigned int started;
126 unsigned long baudrate;
127 unsigned char parity;
131 struct dbg_port ports[]=
141 IO_STATE(R_IRQ_MASK1_SET, ser0_data, set),
155 IO_STATE(R_IRQ_MASK1_SET, ser1_data, set),
169 IO_STATE(R_IRQ_MASK1_SET, ser2_data, set),
183 IO_STATE(R_IRQ_MASK1_SET, ser3_data, set),
191 extern struct tty_driver *serial_driver;
193 struct dbg_port* port =
194 #if defined(CONFIG_ETRAX_DEBUG_PORT0)
196 #elif defined(CONFIG_ETRAX_DEBUG_PORT1)
198 #elif defined(CONFIG_ETRAX_DEBUG_PORT2)
200 #elif defined(CONFIG_ETRAX_DEBUG_PORT3)
206 static struct dbg_port* kgdb_port =
207 #if defined(CONFIG_ETRAX_KGDB_PORT0)
209 #elif defined(CONFIG_ETRAX_KGDB_PORT1)
211 #elif defined(CONFIG_ETRAX_KGDB_PORT2)
213 #elif defined(CONFIG_ETRAX_KGDB_PORT3)
220 start_port(struct dbg_port* p)
222 unsigned long rec_ctrl = 0;
223 unsigned long tr_ctrl = 0;
234 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma6);
235 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma6, unused);
237 else if (p->index == 1)
239 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma8);
240 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma8, usb);
242 else if (p->index == 2)
244 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma2);
245 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma2, par0);
246 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma3);
247 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma3, par0);
248 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, ser2, select);
252 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma4);
253 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma4, par1);
254 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma5);
255 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma5, par1);
256 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, ser3, select);
259 *R_GEN_CONFIG = genconfig_shadow;
262 IO_STATE(R_SERIAL0_XOFF, tx_stop, enable) |
263 IO_STATE(R_SERIAL0_XOFF, auto_xoff, disable) |
264 IO_FIELD(R_SERIAL0_XOFF, xoff_char, 0);
271 IO_STATE(R_SERIAL0_BAUD, tr_baud, c115k2Hz) |
272 IO_STATE(R_SERIAL0_BAUD, rec_baud, c115k2Hz);
276 IO_STATE(R_SERIAL0_BAUD, tr_baud, c1200Hz) |
277 IO_STATE(R_SERIAL0_BAUD, rec_baud, c1200Hz);
281 IO_STATE(R_SERIAL0_BAUD, tr_baud, c2400Hz) |
282 IO_STATE(R_SERIAL0_BAUD, rec_baud, c2400Hz);
286 IO_STATE(R_SERIAL0_BAUD, tr_baud, c4800Hz) |
287 IO_STATE(R_SERIAL0_BAUD, rec_baud, c4800Hz);
291 IO_STATE(R_SERIAL0_BAUD, tr_baud, c9600Hz) |
292 IO_STATE(R_SERIAL0_BAUD, rec_baud, c9600Hz);
296 IO_STATE(R_SERIAL0_BAUD, tr_baud, c19k2Hz) |
297 IO_STATE(R_SERIAL0_BAUD, rec_baud, c19k2Hz);
301 IO_STATE(R_SERIAL0_BAUD, tr_baud, c38k4Hz) |
302 IO_STATE(R_SERIAL0_BAUD, rec_baud, c38k4Hz);
306 IO_STATE(R_SERIAL0_BAUD, tr_baud, c57k6Hz) |
307 IO_STATE(R_SERIAL0_BAUD, rec_baud, c57k6Hz);
311 IO_STATE(R_SERIAL0_BAUD, tr_baud, c115k2Hz) |
312 IO_STATE(R_SERIAL0_BAUD, rec_baud, c115k2Hz);
316 if (p->parity == 'E') {
318 IO_STATE(R_SERIAL0_REC_CTRL, rec_par, even) |
319 IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, enable);
321 IO_STATE(R_SERIAL0_TR_CTRL, tr_par, even) |
322 IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, enable);
323 } else if (p->parity == 'O') {
325 IO_STATE(R_SERIAL0_REC_CTRL, rec_par, odd) |
326 IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, enable);
328 IO_STATE(R_SERIAL0_TR_CTRL, tr_par, odd) |
329 IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, enable);
332 IO_STATE(R_SERIAL0_REC_CTRL, rec_par, even) |
333 IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, disable);
335 IO_STATE(R_SERIAL0_TR_CTRL, tr_par, even) |
336 IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, disable);
340 rec_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_bitnr, rec_7bit);
341 tr_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_bitnr, tr_7bit);
345 rec_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_bitnr, rec_8bit);
346 tr_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_bitnr, tr_8bit);
350 IO_STATE(R_SERIAL0_REC_CTRL, dma_err, stop) |
351 IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable) |
352 IO_STATE(R_SERIAL0_REC_CTRL, rts_, active) |
353 IO_STATE(R_SERIAL0_REC_CTRL, sampling, middle) |
354 IO_STATE(R_SERIAL0_REC_CTRL, rec_stick_par, normal) |
358 IO_FIELD(R_SERIAL0_TR_CTRL, txd, 0) |
359 IO_STATE(R_SERIAL0_TR_CTRL, tr_enable, enable) |
360 IO_STATE(R_SERIAL0_TR_CTRL, auto_cts, disabled) |
361 IO_STATE(R_SERIAL0_TR_CTRL, stop_bits, one_bit) |
362 IO_STATE(R_SERIAL0_TR_CTRL, tr_stick_par, normal) |
367 console_write_direct(struct console *co, const char *buf, unsigned int len)
371 local_irq_save(flags);
377 for (i = 0; i < len; i++) {
379 if (buf[i] == '\n') {
380 while (!(*port->read & IO_MASK(R_SERIAL0_READ, tr_ready)))
384 /* Wait until transmitter is ready and send.*/
385 while (!(*port->read & IO_MASK(R_SERIAL0_READ, tr_ready)))
387 *port->write = buf[i];
389 local_irq_restore(flags);
392 int raw_printk(const char *fmt, ...)
394 static char buf[1024];
396 static int first = 1;
398 /* Force reinitialization of the port to get manual mode. */
405 printed_len = vsnprintf(buf, sizeof(buf), fmt, args);
407 console_write_direct(NULL, buf, strlen(buf));
412 console_write(struct console *co, const char *buf, unsigned int len)
417 #ifdef CONFIG_SVINTO_SIM
418 /* no use to simulate the serial debug output */
423 console_write_direct(co, buf, len);
426 /* legacy function */
429 console_print_etrax(const char *buf)
431 console_write(NULL, buf, strlen(buf));
434 /* Use polling to get a single character FROM the debug port */
439 unsigned long readval;
445 readval = *kgdb_port->read;
446 } while (!(readval & IO_MASK(R_SERIAL0_READ, data_avail)));
448 return (readval & IO_MASK(R_SERIAL0_READ, data_in));
451 /* Use polling to put a single character to the debug port */
454 putDebugChar(int val)
459 while (!(*kgdb_port->read & IO_MASK(R_SERIAL0_READ, tr_ready)))
461 *kgdb_port->write = val;
464 /* Enable irq for receiving chars on the debug port, used by kgdb */
472 *R_IRQ_MASK1_SET = kgdb_port->irq;
473 /* use R_VECT_MASK directly, since we really bypass Linux normal
474 * IRQ handling in kgdb anyway, we don't need to use enable_irq
476 *R_VECT_MASK_SET = IO_STATE(R_VECT_MASK_SET, serial, set);
478 *kgdb_port->rec_ctrl = IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable);
482 console_setup(struct console *co, char *options)
487 port = &ports[co->index];
488 port->baudrate = 115200;
491 port->baudrate = simple_strtoul(options, NULL, 10);
493 while(*s >= '0' && *s <= '9')
495 if (*s) port->parity = *s++;
496 if (*s) port->bits = *s++ - '0';
503 /* This is a dummy serial device that throws away anything written to it.
504 * This is used when no debug output is wanted.
506 static struct tty_driver dummy_driver;
508 static int dummy_open(struct tty_struct *tty, struct file * filp)
513 static void dummy_close(struct tty_struct *tty, struct file * filp)
517 static int dummy_write(struct tty_struct * tty,
518 const unsigned char *buf, int count)
524 dummy_write_room(struct tty_struct *tty)
530 init_dummy_console(void)
532 memset(&dummy_driver, 0, sizeof(struct tty_driver));
533 dummy_driver.driver_name = "serial";
534 dummy_driver.name = "ttyS";
535 dummy_driver.major = TTY_MAJOR;
536 dummy_driver.minor_start = 68;
537 dummy_driver.num = 1; /* etrax100 has 4 serial ports */
538 dummy_driver.type = TTY_DRIVER_TYPE_SERIAL;
539 dummy_driver.subtype = SERIAL_TYPE_NORMAL;
540 dummy_driver.init_termios = tty_std_termios;
541 dummy_driver.init_termios.c_cflag =
542 B115200 | CS8 | CREAD | HUPCL | CLOCAL; /* is normally B9600 default... */
543 dummy_driver.flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
545 dummy_driver.open = dummy_open;
546 dummy_driver.close = dummy_close;
547 dummy_driver.write = dummy_write;
548 dummy_driver.write_room = dummy_write_room;
549 if (tty_register_driver(&dummy_driver))
550 panic("Couldn't register dummy serial driver\n");
553 static struct tty_driver*
554 etrax_console_device(struct console* co, int *index)
557 *index = port->index;
558 return port ? serial_driver : &dummy_driver;
561 static struct console sercons = {
563 write: console_write,
565 device : etrax_console_device,
567 setup : console_setup,
568 flags : CON_PRINTBUFFER,
573 static struct console sercons0 = {
575 write: console_write,
577 device : etrax_console_device,
579 setup : console_setup,
580 flags : CON_PRINTBUFFER,
586 static struct console sercons1 = {
588 write: console_write,
590 device : etrax_console_device,
592 setup : console_setup,
593 flags : CON_PRINTBUFFER,
598 static struct console sercons2 = {
600 write: console_write,
602 device : etrax_console_device,
604 setup : console_setup,
605 flags : CON_PRINTBUFFER,
610 static struct console sercons3 = {
612 write: console_write,
614 device : etrax_console_device,
616 setup : console_setup,
617 flags : CON_PRINTBUFFER,
623 * Register console (for printk's etc)
627 init_etrax_debug(void)
629 static int first = 1;
632 unregister_console(&sercons);
633 register_console(&sercons0);
634 register_console(&sercons1);
635 register_console(&sercons2);
636 register_console(&sercons3);
637 init_dummy_console();
642 register_console(&sercons);
644 #ifdef CONFIG_ETRAX_KGDB
645 start_port(kgdb_port);
649 __initcall(init_etrax_debug);