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.19 2004/10/21 07:26:16 starvik
16 * Made it possible to specify console settings on kernel command line.
18 * Revision 1.18 2004/10/19 13:07:37 starvik
19 * Merge of Linux 2.6.9
21 * Revision 1.17 2004/09/29 10:33:46 starvik
22 * Resolved a dealock when printing debug from kernel.
24 * Revision 1.16 2004/08/24 06:12:19 starvik
27 * Revision 1.15 2004/08/16 12:37:19 starvik
28 * Merge of Linux 2.6.8
30 * Revision 1.14 2004/05/17 13:11:29 starvik
31 * Disable DMA until real serial driver is up
33 * Revision 1.13 2004/05/14 07:58:01 starvik
34 * Merge of changes from 2.4
36 * Revision 1.12 2003/09/11 07:29:49 starvik
37 * Merge of Linux 2.6.0-test5
39 * Revision 1.11 2003/07/07 09:53:36 starvik
40 * Revert all the 2.5.74 merge changes to make the console work again
42 * Revision 1.9 2003/02/17 17:07:23 starvik
43 * Solved the problem with corrupted debug output (from Linux 2.4)
44 * * Wait until DMA, FIFO and pipe is empty before and after transmissions
45 * * Buffer data until a FIFO flush can be triggered.
47 * Revision 1.8 2003/01/22 06:48:36 starvik
48 * Fixed warnings issued by GCC 3.2.1
50 * Revision 1.7 2002/12/12 08:26:32 starvik
51 * Don't use C-comments inside CVS comments
53 * Revision 1.6 2002/12/11 15:42:02 starvik
54 * Extracted v10 (ETRAX 100LX) specific stuff from arch/cris/kernel/
56 * Revision 1.5 2002/11/20 06:58:03 starvik
59 * Revision 1.4 2002/11/19 14:35:24 starvik
60 * Changes from linux 2.4
61 * Changed struct initializer syntax to the currently prefered notation
63 * Revision 1.3 2002/11/06 09:47:03 starvik
64 * Modified for new interrupt macros
66 * Revision 1.2 2002/01/21 15:21:50 bjornw
67 * Update for kdev_t changes
69 * Revision 1.6 2001/04/17 13:58:39 orjanf
70 * * Renamed CONFIG_KGDB to CONFIG_ETRAX_KGDB.
72 * Revision 1.5 2001/03/26 14:22:05 bjornw
73 * Namechange of some config options
75 * Revision 1.4 2000/10/06 12:37:26 bjornw
76 * Use physical addresses when talking to DMA
81 #include <linux/config.h>
82 #include <linux/console.h>
83 #include <linux/init.h>
84 #include <linux/major.h>
85 #include <linux/delay.h>
86 #include <linux/tty.h>
87 #include <asm/system.h>
88 #include <asm/arch/svinto.h>
89 #include <asm/io.h> /* Get SIMCOUT. */
94 const volatile unsigned* read;
96 volatile unsigned* xoff;
98 volatile char* tr_ctrl;
99 volatile char* rec_ctrl;
101 unsigned int started;
102 unsigned long baudrate;
103 unsigned char parity;
107 struct dbg_port ports[]=
117 IO_STATE(R_IRQ_MASK1_SET, ser0_data, set)
127 IO_STATE(R_IRQ_MASK1_SET, ser1_data, set)
137 IO_STATE(R_IRQ_MASK1_SET, ser2_data, set)
147 IO_STATE(R_IRQ_MASK1_SET, ser3_data, set)
151 static struct tty_driver *serial_driver;
153 struct dbg_port* port =
154 #if defined(CONFIG_ETRAX_DEBUG_PORT0)
156 #elif defined(CONFIG_ETRAX_DEBUG_PORT1)
158 #elif defined(CONFIG_ETRAX_DEBUG_PORT2)
160 #elif defined(CONFIG_ETRAX_DEBUG_PORT3)
165 /* Used by serial.c to register a debug_write_function so that the normal
166 * serial driver is used for kernel debug output
168 typedef int (*debugport_write_function)(int i, const char *buf, unsigned int len);
170 debugport_write_function debug_write_function = NULL;
175 unsigned long rec_ctrl = 0;
176 unsigned long tr_ctrl = 0;
185 if (port->index == 0)
187 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma6);
188 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma6, unused);
190 else if (port->index == 1)
192 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma8);
193 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma8, usb);
195 else if (port->index == 2)
197 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma2);
198 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma2, par0);
199 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma3);
200 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma3, par0);
201 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, ser2, select);
205 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma4);
206 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma4, par1);
207 genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma5);
208 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma5, par1);
209 genconfig_shadow |= IO_STATE(R_GEN_CONFIG, ser3, select);
212 *R_GEN_CONFIG = genconfig_shadow;
215 IO_STATE(R_SERIAL0_XOFF, tx_stop, enable) |
216 IO_STATE(R_SERIAL0_XOFF, auto_xoff, disable) |
217 IO_FIELD(R_SERIAL0_XOFF, xoff_char, 0);
219 switch (port->baudrate)
224 IO_STATE(R_SERIAL0_BAUD, tr_baud, c115k2Hz) |
225 IO_STATE(R_SERIAL0_BAUD, rec_baud, c115k2Hz);
229 IO_STATE(R_SERIAL0_BAUD, tr_baud, c1200Hz) |
230 IO_STATE(R_SERIAL0_BAUD, rec_baud, c1200Hz);
234 IO_STATE(R_SERIAL0_BAUD, tr_baud, c2400Hz) |
235 IO_STATE(R_SERIAL0_BAUD, rec_baud, c2400Hz);
239 IO_STATE(R_SERIAL0_BAUD, tr_baud, c4800Hz) |
240 IO_STATE(R_SERIAL0_BAUD, rec_baud, c4800Hz);
244 IO_STATE(R_SERIAL0_BAUD, tr_baud, c9600Hz) |
245 IO_STATE(R_SERIAL0_BAUD, rec_baud, c9600Hz);
249 IO_STATE(R_SERIAL0_BAUD, tr_baud, c19k2Hz) |
250 IO_STATE(R_SERIAL0_BAUD, rec_baud, c19k2Hz);
254 IO_STATE(R_SERIAL0_BAUD, tr_baud, c38k4Hz) |
255 IO_STATE(R_SERIAL0_BAUD, rec_baud, c38k4Hz);
259 IO_STATE(R_SERIAL0_BAUD, tr_baud, c57k6Hz) |
260 IO_STATE(R_SERIAL0_BAUD, rec_baud, c57k6Hz);
264 IO_STATE(R_SERIAL0_BAUD, tr_baud, c115k2Hz) |
265 IO_STATE(R_SERIAL0_BAUD, rec_baud, c115k2Hz);
269 if (port->parity == 'E') {
271 IO_STATE(R_SERIAL0_REC_CTRL, rec_par, even) |
272 IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, enable);
274 IO_STATE(R_SERIAL0_TR_CTRL, tr_par, even) |
275 IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, enable);
276 } else if (port->parity == 'O') {
278 IO_STATE(R_SERIAL0_REC_CTRL, rec_par, odd) |
279 IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, enable);
281 IO_STATE(R_SERIAL0_TR_CTRL, tr_par, odd) |
282 IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, enable);
285 IO_STATE(R_SERIAL0_REC_CTRL, rec_par, even) |
286 IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, disable);
288 IO_STATE(R_SERIAL0_TR_CTRL, tr_par, even) |
289 IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, disable);
294 rec_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_bitnr, rec_7bit);
295 tr_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_bitnr, tr_7bit);
299 rec_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_bitnr, rec_8bit);
300 tr_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_bitnr, tr_8bit);
304 IO_STATE(R_SERIAL0_REC_CTRL, dma_err, stop) |
305 IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable) |
306 IO_STATE(R_SERIAL0_REC_CTRL, rts_, active) |
307 IO_STATE(R_SERIAL0_REC_CTRL, sampling, middle) |
308 IO_STATE(R_SERIAL0_REC_CTRL, rec_stick_par, normal) |
312 IO_FIELD(R_SERIAL0_TR_CTRL, txd, 0) |
313 IO_STATE(R_SERIAL0_TR_CTRL, tr_enable, enable) |
314 IO_STATE(R_SERIAL0_TR_CTRL, auto_cts, disabled) |
315 IO_STATE(R_SERIAL0_TR_CTRL, stop_bits, one_bit) |
316 IO_STATE(R_SERIAL0_TR_CTRL, tr_stick_par, normal) |
321 console_write_direct(struct console *co, const char *buf, unsigned int len)
325 local_irq_save(flags);
327 for (i = 0; i < len; i++) {
328 /* Wait until transmitter is ready and send.*/
329 while (!(*port->read & IO_MASK(R_SERIAL0_READ, tr_ready)))
331 *port->write = buf[i];
333 local_irq_restore(flags);
337 console_write(struct console *co, const char *buf, unsigned int len)
342 #ifdef CONFIG_SVINTO_SIM
343 /* no use to simulate the serial debug output */
350 #ifdef CONFIG_ETRAX_KGDB
351 /* kgdb needs to output debug info using the gdb protocol */
352 putDebugString(buf, len);
356 if (debug_write_function)
357 debug_write_function(co->index, buf, len);
359 console_write_direct(co, buf, len);
362 /* legacy function */
365 console_print_etrax(const char *buf)
367 console_write(NULL, buf, strlen(buf));
370 /* Use polling to get a single character FROM the debug port */
375 unsigned long readval;
378 readval = *port->read;
379 } while (!(readval & IO_MASK(R_SERIAL0_READ, data_avail)));
381 return (readval & IO_MASK(R_SERIAL0_READ, data_in));
384 /* Use polling to put a single character to the debug port */
387 putDebugChar(int val)
389 while (!(*port->read & IO_MASK(R_SERIAL0_READ, tr_ready)))
394 /* Enable irq for receiving chars on the debug port, used by kgdb */
399 *R_IRQ_MASK1_SET = port->irq;
400 /* use R_VECT_MASK directly, since we really bypass Linux normal
401 * IRQ handling in kgdb anyway, we don't need to use enable_irq
403 *R_VECT_MASK_SET = IO_STATE(R_VECT_MASK_SET, serial, set);
405 *port->rec_ctrl = IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable);
408 static struct tty_driver*
409 etrax_console_device(struct console* co, int *index)
411 return serial_driver;
415 console_setup(struct console *co, char *options)
420 port = &ports[co->index];
421 port->baudrate = 115200;
424 port->baudrate = simple_strtoul(options, NULL, 10);
426 while(*s >= '0' && *s <= '9')
428 if (*s) port->parity = *s++;
429 if (*s) port->bits = *s++ - '0';
436 static struct console sercons = {
438 write: console_write,
440 device : etrax_console_device,
442 setup : console_setup,
443 flags : CON_PRINTBUFFER,
448 static struct console sercons0 = {
450 write: console_write,
452 device : etrax_console_device,
454 setup : console_setup,
455 flags : CON_PRINTBUFFER,
461 static struct console sercons1 = {
463 write: console_write,
465 device : etrax_console_device,
467 setup : console_setup,
468 flags : CON_PRINTBUFFER,
473 static struct console sercons2 = {
475 write: console_write,
477 device : etrax_console_device,
479 setup : console_setup,
480 flags : CON_PRINTBUFFER,
485 static struct console sercons3 = {
487 write: console_write,
489 device : etrax_console_device,
491 setup : console_setup,
492 flags : CON_PRINTBUFFER,
498 * Register console (for printk's etc)
502 init_etrax_debug(void)
504 static int first = 1;
508 register_console(&sercons0);
509 register_console(&sercons1);
510 register_console(&sercons2);
511 register_console(&sercons3);
512 unregister_console(&sercons);
518 register_console(&sercons);
525 serial_driver = alloc_tty_driver(1);
531 __initcall(init_etrax_debug);