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 <arch/svinto.h>
22 #include <asm/io.h> /* Get SIMCOUT. */
24 extern void reset_watchdog(void);
29 const volatile unsigned* read
;
31 volatile unsigned* xoff
;
33 volatile char* tr_ctrl
;
34 volatile char* rec_ctrl
;
37 unsigned long baudrate
;
42 struct dbg_port ports
[]=
52 IO_STATE(R_IRQ_MASK1_SET
, ser0_data
, set
),
66 IO_STATE(R_IRQ_MASK1_SET
, ser1_data
, set
),
80 IO_STATE(R_IRQ_MASK1_SET
, ser2_data
, set
),
94 IO_STATE(R_IRQ_MASK1_SET
, ser3_data
, set
),
102 #ifdef CONFIG_ETRAX_SERIAL
103 extern struct tty_driver
*serial_driver
;
106 struct dbg_port
* port
=
107 #if defined(CONFIG_ETRAX_DEBUG_PORT0)
109 #elif defined(CONFIG_ETRAX_DEBUG_PORT1)
111 #elif defined(CONFIG_ETRAX_DEBUG_PORT2)
113 #elif defined(CONFIG_ETRAX_DEBUG_PORT3)
119 static struct dbg_port
* kgdb_port
=
120 #if defined(CONFIG_ETRAX_KGDB_PORT0)
122 #elif defined(CONFIG_ETRAX_KGDB_PORT1)
124 #elif defined(CONFIG_ETRAX_KGDB_PORT2)
126 #elif defined(CONFIG_ETRAX_KGDB_PORT3)
133 start_port(struct dbg_port
* p
)
135 unsigned long rec_ctrl
= 0;
136 unsigned long tr_ctrl
= 0;
147 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma6
);
148 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma6
, unused
);
150 else if (p
->index
== 1)
152 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma8
);
153 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma8
, usb
);
155 else if (p
->index
== 2)
157 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma2
);
158 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma2
, par0
);
159 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma3
);
160 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma3
, par0
);
161 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, ser2
, select
);
165 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma4
);
166 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma4
, par1
);
167 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma5
);
168 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma5
, par1
);
169 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, ser3
, select
);
172 *R_GEN_CONFIG
= genconfig_shadow
;
175 IO_STATE(R_SERIAL0_XOFF
, tx_stop
, enable
) |
176 IO_STATE(R_SERIAL0_XOFF
, auto_xoff
, disable
) |
177 IO_FIELD(R_SERIAL0_XOFF
, xoff_char
, 0);
184 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c115k2Hz
) |
185 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c115k2Hz
);
189 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c1200Hz
) |
190 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c1200Hz
);
194 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c2400Hz
) |
195 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c2400Hz
);
199 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c4800Hz
) |
200 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c4800Hz
);
204 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c9600Hz
) |
205 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c9600Hz
);
209 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c19k2Hz
) |
210 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c19k2Hz
);
214 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c38k4Hz
) |
215 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c38k4Hz
);
219 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c57k6Hz
) |
220 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c57k6Hz
);
224 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c115k2Hz
) |
225 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c115k2Hz
);
229 if (p
->parity
== 'E') {
231 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par
, even
) |
232 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par_en
, enable
);
234 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par
, even
) |
235 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par_en
, enable
);
236 } else if (p
->parity
== 'O') {
238 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par
, odd
) |
239 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par_en
, enable
);
241 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par
, odd
) |
242 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par_en
, enable
);
245 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par
, even
) |
246 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par_en
, disable
);
248 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par
, even
) |
249 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par_en
, disable
);
253 rec_ctrl
|= IO_STATE(R_SERIAL0_REC_CTRL
, rec_bitnr
, rec_7bit
);
254 tr_ctrl
|= IO_STATE(R_SERIAL0_TR_CTRL
, tr_bitnr
, tr_7bit
);
258 rec_ctrl
|= IO_STATE(R_SERIAL0_REC_CTRL
, rec_bitnr
, rec_8bit
);
259 tr_ctrl
|= IO_STATE(R_SERIAL0_TR_CTRL
, tr_bitnr
, tr_8bit
);
263 IO_STATE(R_SERIAL0_REC_CTRL
, dma_err
, stop
) |
264 IO_STATE(R_SERIAL0_REC_CTRL
, rec_enable
, enable
) |
265 IO_STATE(R_SERIAL0_REC_CTRL
, rts_
, active
) |
266 IO_STATE(R_SERIAL0_REC_CTRL
, sampling
, middle
) |
267 IO_STATE(R_SERIAL0_REC_CTRL
, rec_stick_par
, normal
) |
271 IO_FIELD(R_SERIAL0_TR_CTRL
, txd
, 0) |
272 IO_STATE(R_SERIAL0_TR_CTRL
, tr_enable
, enable
) |
273 IO_STATE(R_SERIAL0_TR_CTRL
, auto_cts
, disabled
) |
274 IO_STATE(R_SERIAL0_TR_CTRL
, stop_bits
, one_bit
) |
275 IO_STATE(R_SERIAL0_TR_CTRL
, tr_stick_par
, normal
) |
280 console_write_direct(struct console
*co
, const char *buf
, unsigned int len
)
288 local_irq_save(flags
);
291 for (i
= 0; i
< len
; i
++) {
293 if (buf
[i
] == '\n') {
294 while (!(*port
->read
& IO_MASK(R_SERIAL0_READ
, tr_ready
)))
298 /* Wait until transmitter is ready and send.*/
299 while (!(*port
->read
& IO_MASK(R_SERIAL0_READ
, tr_ready
)))
301 *port
->write
= buf
[i
];
305 * Feed the watchdog, otherwise it will reset the chip during boot.
306 * The time to send an ordinary boot message line (10-90 chars)
307 * varies between 1-8ms at 115200. What makes up for the additional
308 * 90ms that allows the watchdog to bite?
312 local_irq_restore(flags
);
316 console_write(struct console
*co
, const char *buf
, unsigned int len
)
321 #ifdef CONFIG_SVINTO_SIM
322 /* no use to simulate the serial debug output */
327 console_write_direct(co
, buf
, len
);
330 /* legacy function */
333 console_print_etrax(const char *buf
)
335 console_write(NULL
, buf
, strlen(buf
));
338 /* Use polling to get a single character FROM the debug port */
343 unsigned long readval
;
349 readval
= *kgdb_port
->read
;
350 } while (!(readval
& IO_MASK(R_SERIAL0_READ
, data_avail
)));
352 return (readval
& IO_MASK(R_SERIAL0_READ
, data_in
));
355 /* Use polling to put a single character to the debug port */
358 putDebugChar(int val
)
363 while (!(*kgdb_port
->read
& IO_MASK(R_SERIAL0_READ
, tr_ready
)))
365 *kgdb_port
->write
= val
;
368 /* Enable irq for receiving chars on the debug port, used by kgdb */
376 *R_IRQ_MASK1_SET
= kgdb_port
->irq
;
377 /* use R_VECT_MASK directly, since we really bypass Linux normal
378 * IRQ handling in kgdb anyway, we don't need to use enable_irq
380 *R_VECT_MASK_SET
= IO_STATE(R_VECT_MASK_SET
, serial
, set
);
382 *kgdb_port
->rec_ctrl
= IO_STATE(R_SERIAL0_REC_CTRL
, rec_enable
, enable
);
386 console_setup(struct console
*co
, char *options
)
391 port
= &ports
[co
->index
];
392 port
->baudrate
= 115200;
395 port
->baudrate
= simple_strtoul(options
, NULL
, 10);
397 while(*s
>= '0' && *s
<= '9')
399 if (*s
) port
->parity
= *s
++;
400 if (*s
) port
->bits
= *s
++ - '0';
408 /* This is a dummy serial device that throws away anything written to it.
409 * This is used when no debug output is wanted.
411 static struct tty_driver dummy_driver
;
413 static int dummy_open(struct tty_struct
*tty
, struct file
* filp
)
418 static void dummy_close(struct tty_struct
*tty
, struct file
* filp
)
422 static int dummy_write(struct tty_struct
* tty
,
423 const unsigned char *buf
, int count
)
428 static int dummy_write_room(struct tty_struct
*tty
)
433 static const struct tty_operations dummy_ops
= {
435 .close
= dummy_close
,
436 .write
= dummy_write
,
437 .write_room
= dummy_write_room
,
441 init_dummy_console(void)
443 memset(&dummy_driver
, 0, sizeof(struct tty_driver
));
444 dummy_driver
.driver_name
= "serial";
445 dummy_driver
.name
= "ttyS";
446 dummy_driver
.major
= TTY_MAJOR
;
447 dummy_driver
.minor_start
= 68;
448 dummy_driver
.num
= 1; /* etrax100 has 4 serial ports */
449 dummy_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
450 dummy_driver
.subtype
= SERIAL_TYPE_NORMAL
;
451 dummy_driver
.init_termios
= tty_std_termios
;
452 /* Normally B9600 default... */
453 dummy_driver
.init_termios
.c_cflag
=
454 B115200
| CS8
| CREAD
| HUPCL
| CLOCAL
;
455 dummy_driver
.flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
;
456 dummy_driver
.init_termios
.c_ispeed
= 115200;
457 dummy_driver
.init_termios
.c_ospeed
= 115200;
459 dummy_driver
.ops
= &dummy_ops
;
460 if (tty_register_driver(&dummy_driver
))
461 panic("Couldn't register dummy serial driver\n");
464 static struct tty_driver
*
465 etrax_console_device(struct console
* co
, int *index
)
468 *index
= port
->index
;
471 #ifdef CONFIG_ETRAX_SERIAL
472 return port
? serial_driver
: &dummy_driver
;
474 return &dummy_driver
;
478 static struct console sercons
= {
480 write
: console_write
,
482 device
: etrax_console_device
,
484 setup
: console_setup
,
485 flags
: CON_PRINTBUFFER
,
490 static struct console sercons0
= {
492 write
: console_write
,
494 device
: etrax_console_device
,
496 setup
: console_setup
,
497 flags
: CON_PRINTBUFFER
,
503 static struct console sercons1
= {
505 write
: console_write
,
507 device
: etrax_console_device
,
509 setup
: console_setup
,
510 flags
: CON_PRINTBUFFER
,
515 static struct console sercons2
= {
517 write
: console_write
,
519 device
: etrax_console_device
,
521 setup
: console_setup
,
522 flags
: CON_PRINTBUFFER
,
527 static struct console sercons3
= {
529 write
: console_write
,
531 device
: etrax_console_device
,
533 setup
: console_setup
,
534 flags
: CON_PRINTBUFFER
,
540 * Register console (for printk's etc)
544 init_etrax_debug(void)
546 static int first
= 1;
549 unregister_console(&sercons
);
550 register_console(&sercons0
);
551 register_console(&sercons1
);
552 register_console(&sercons2
);
553 register_console(&sercons3
);
554 init_dummy_console();
559 register_console(&sercons
);
561 #ifdef CONFIG_ETRAX_KGDB
562 start_port(kgdb_port
);
566 __initcall(init_etrax_debug
);