1 /* Serialport functions for debugging
3 * Copyright (c) 2000-2007 Axis Communications AB
8 * console_print_etrax(char *buf)
16 #include <linux/console.h>
17 #include <linux/init.h>
18 #include <linux/major.h>
19 #include <linux/delay.h>
20 #include <linux/tty.h>
21 #include <asm/system.h>
22 #include <arch/svinto.h>
23 #include <asm/io.h> /* Get SIMCOUT. */
25 extern void reset_watchdog(void);
30 const volatile unsigned* read
;
32 volatile unsigned* xoff
;
34 volatile char* tr_ctrl
;
35 volatile char* rec_ctrl
;
38 unsigned long baudrate
;
43 struct dbg_port ports
[]=
53 IO_STATE(R_IRQ_MASK1_SET
, ser0_data
, set
),
67 IO_STATE(R_IRQ_MASK1_SET
, ser1_data
, set
),
81 IO_STATE(R_IRQ_MASK1_SET
, ser2_data
, set
),
95 IO_STATE(R_IRQ_MASK1_SET
, ser3_data
, set
),
103 #ifdef CONFIG_ETRAX_SERIAL
104 extern struct tty_driver
*serial_driver
;
107 struct dbg_port
* port
=
108 #if defined(CONFIG_ETRAX_DEBUG_PORT0)
110 #elif defined(CONFIG_ETRAX_DEBUG_PORT1)
112 #elif defined(CONFIG_ETRAX_DEBUG_PORT2)
114 #elif defined(CONFIG_ETRAX_DEBUG_PORT3)
120 static struct dbg_port
* kgdb_port
=
121 #if defined(CONFIG_ETRAX_KGDB_PORT0)
123 #elif defined(CONFIG_ETRAX_KGDB_PORT1)
125 #elif defined(CONFIG_ETRAX_KGDB_PORT2)
127 #elif defined(CONFIG_ETRAX_KGDB_PORT3)
134 start_port(struct dbg_port
* p
)
136 unsigned long rec_ctrl
= 0;
137 unsigned long tr_ctrl
= 0;
148 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma6
);
149 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma6
, unused
);
151 else if (p
->index
== 1)
153 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma8
);
154 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma8
, usb
);
156 else if (p
->index
== 2)
158 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma2
);
159 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma2
, par0
);
160 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma3
);
161 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma3
, par0
);
162 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, ser2
, select
);
166 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma4
);
167 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma4
, par1
);
168 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma5
);
169 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma5
, par1
);
170 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, ser3
, select
);
173 *R_GEN_CONFIG
= genconfig_shadow
;
176 IO_STATE(R_SERIAL0_XOFF
, tx_stop
, enable
) |
177 IO_STATE(R_SERIAL0_XOFF
, auto_xoff
, disable
) |
178 IO_FIELD(R_SERIAL0_XOFF
, xoff_char
, 0);
185 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c115k2Hz
) |
186 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c115k2Hz
);
190 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c1200Hz
) |
191 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c1200Hz
);
195 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c2400Hz
) |
196 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c2400Hz
);
200 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c4800Hz
) |
201 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c4800Hz
);
205 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c9600Hz
) |
206 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c9600Hz
);
210 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c19k2Hz
) |
211 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c19k2Hz
);
215 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c38k4Hz
) |
216 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c38k4Hz
);
220 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c57k6Hz
) |
221 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c57k6Hz
);
225 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c115k2Hz
) |
226 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c115k2Hz
);
230 if (p
->parity
== 'E') {
232 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par
, even
) |
233 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par_en
, enable
);
235 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par
, even
) |
236 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par_en
, enable
);
237 } else if (p
->parity
== 'O') {
239 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par
, odd
) |
240 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par_en
, enable
);
242 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par
, odd
) |
243 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par_en
, enable
);
246 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par
, even
) |
247 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par_en
, disable
);
249 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par
, even
) |
250 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par_en
, disable
);
254 rec_ctrl
|= IO_STATE(R_SERIAL0_REC_CTRL
, rec_bitnr
, rec_7bit
);
255 tr_ctrl
|= IO_STATE(R_SERIAL0_TR_CTRL
, tr_bitnr
, tr_7bit
);
259 rec_ctrl
|= IO_STATE(R_SERIAL0_REC_CTRL
, rec_bitnr
, rec_8bit
);
260 tr_ctrl
|= IO_STATE(R_SERIAL0_TR_CTRL
, tr_bitnr
, tr_8bit
);
264 IO_STATE(R_SERIAL0_REC_CTRL
, dma_err
, stop
) |
265 IO_STATE(R_SERIAL0_REC_CTRL
, rec_enable
, enable
) |
266 IO_STATE(R_SERIAL0_REC_CTRL
, rts_
, active
) |
267 IO_STATE(R_SERIAL0_REC_CTRL
, sampling
, middle
) |
268 IO_STATE(R_SERIAL0_REC_CTRL
, rec_stick_par
, normal
) |
272 IO_FIELD(R_SERIAL0_TR_CTRL
, txd
, 0) |
273 IO_STATE(R_SERIAL0_TR_CTRL
, tr_enable
, enable
) |
274 IO_STATE(R_SERIAL0_TR_CTRL
, auto_cts
, disabled
) |
275 IO_STATE(R_SERIAL0_TR_CTRL
, stop_bits
, one_bit
) |
276 IO_STATE(R_SERIAL0_TR_CTRL
, tr_stick_par
, normal
) |
281 console_write_direct(struct console
*co
, const char *buf
, unsigned int len
)
289 local_irq_save(flags
);
292 for (i
= 0; i
< len
; i
++) {
294 if (buf
[i
] == '\n') {
295 while (!(*port
->read
& IO_MASK(R_SERIAL0_READ
, tr_ready
)))
299 /* Wait until transmitter is ready and send.*/
300 while (!(*port
->read
& IO_MASK(R_SERIAL0_READ
, tr_ready
)))
302 *port
->write
= buf
[i
];
306 * Feed the watchdog, otherwise it will reset the chip during boot.
307 * The time to send an ordinary boot message line (10-90 chars)
308 * varies between 1-8ms at 115200. What makes up for the additional
309 * 90ms that allows the watchdog to bite?
313 local_irq_restore(flags
);
317 console_write(struct console
*co
, const char *buf
, unsigned int len
)
322 #ifdef CONFIG_SVINTO_SIM
323 /* no use to simulate the serial debug output */
328 console_write_direct(co
, buf
, len
);
331 /* legacy function */
334 console_print_etrax(const char *buf
)
336 console_write(NULL
, buf
, strlen(buf
));
339 /* Use polling to get a single character FROM the debug port */
344 unsigned long readval
;
350 readval
= *kgdb_port
->read
;
351 } while (!(readval
& IO_MASK(R_SERIAL0_READ
, data_avail
)));
353 return (readval
& IO_MASK(R_SERIAL0_READ
, data_in
));
356 /* Use polling to put a single character to the debug port */
359 putDebugChar(int val
)
364 while (!(*kgdb_port
->read
& IO_MASK(R_SERIAL0_READ
, tr_ready
)))
366 *kgdb_port
->write
= val
;
369 /* Enable irq for receiving chars on the debug port, used by kgdb */
377 *R_IRQ_MASK1_SET
= kgdb_port
->irq
;
378 /* use R_VECT_MASK directly, since we really bypass Linux normal
379 * IRQ handling in kgdb anyway, we don't need to use enable_irq
381 *R_VECT_MASK_SET
= IO_STATE(R_VECT_MASK_SET
, serial
, set
);
383 *kgdb_port
->rec_ctrl
= IO_STATE(R_SERIAL0_REC_CTRL
, rec_enable
, enable
);
387 console_setup(struct console
*co
, char *options
)
392 port
= &ports
[co
->index
];
393 port
->baudrate
= 115200;
396 port
->baudrate
= simple_strtoul(options
, NULL
, 10);
398 while(*s
>= '0' && *s
<= '9')
400 if (*s
) port
->parity
= *s
++;
401 if (*s
) port
->bits
= *s
++ - '0';
409 /* This is a dummy serial device that throws away anything written to it.
410 * This is used when no debug output is wanted.
412 static struct tty_driver dummy_driver
;
414 static int dummy_open(struct tty_struct
*tty
, struct file
* filp
)
419 static void dummy_close(struct tty_struct
*tty
, struct file
* filp
)
423 static int dummy_write(struct tty_struct
* tty
,
424 const unsigned char *buf
, int count
)
429 static int dummy_write_room(struct tty_struct
*tty
)
434 static const struct tty_operations dummy_ops
= {
436 .close
= dummy_close
,
437 .write
= dummy_write
,
438 .write_room
= dummy_write_room
,
442 init_dummy_console(void)
444 memset(&dummy_driver
, 0, sizeof(struct tty_driver
));
445 dummy_driver
.driver_name
= "serial";
446 dummy_driver
.name
= "ttyS";
447 dummy_driver
.major
= TTY_MAJOR
;
448 dummy_driver
.minor_start
= 68;
449 dummy_driver
.num
= 1; /* etrax100 has 4 serial ports */
450 dummy_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
451 dummy_driver
.subtype
= SERIAL_TYPE_NORMAL
;
452 dummy_driver
.init_termios
= tty_std_termios
;
453 /* Normally B9600 default... */
454 dummy_driver
.init_termios
.c_cflag
=
455 B115200
| CS8
| CREAD
| HUPCL
| CLOCAL
;
456 dummy_driver
.flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
;
457 dummy_driver
.init_termios
.c_ispeed
= 115200;
458 dummy_driver
.init_termios
.c_ospeed
= 115200;
460 dummy_driver
.ops
= &dummy_ops
;
461 if (tty_register_driver(&dummy_driver
))
462 panic("Couldn't register dummy serial driver\n");
465 static struct tty_driver
*
466 etrax_console_device(struct console
* co
, int *index
)
469 *index
= port
->index
;
472 #ifdef CONFIG_ETRAX_SERIAL
473 return port
? serial_driver
: &dummy_driver
;
475 return &dummy_driver
;
479 static struct console sercons
= {
481 write
: console_write
,
483 device
: etrax_console_device
,
485 setup
: console_setup
,
486 flags
: CON_PRINTBUFFER
,
491 static struct console sercons0
= {
493 write
: console_write
,
495 device
: etrax_console_device
,
497 setup
: console_setup
,
498 flags
: CON_PRINTBUFFER
,
504 static struct console sercons1
= {
506 write
: console_write
,
508 device
: etrax_console_device
,
510 setup
: console_setup
,
511 flags
: CON_PRINTBUFFER
,
516 static struct console sercons2
= {
518 write
: console_write
,
520 device
: etrax_console_device
,
522 setup
: console_setup
,
523 flags
: CON_PRINTBUFFER
,
528 static struct console sercons3
= {
530 write
: console_write
,
532 device
: etrax_console_device
,
534 setup
: console_setup
,
535 flags
: CON_PRINTBUFFER
,
541 * Register console (for printk's etc)
545 init_etrax_debug(void)
547 static int first
= 1;
550 unregister_console(&sercons
);
551 register_console(&sercons0
);
552 register_console(&sercons1
);
553 register_console(&sercons2
);
554 register_console(&sercons3
);
555 init_dummy_console();
560 register_console(&sercons
);
562 #ifdef CONFIG_ETRAX_KGDB
563 start_port(kgdb_port
);
567 __initcall(init_etrax_debug
);