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>
23 extern void reset_watchdog(void);
28 const volatile unsigned* read
;
30 volatile unsigned* xoff
;
32 volatile char* tr_ctrl
;
33 volatile char* rec_ctrl
;
36 unsigned long baudrate
;
41 struct dbg_port ports
[]=
51 IO_STATE(R_IRQ_MASK1_SET
, ser0_data
, set
),
65 IO_STATE(R_IRQ_MASK1_SET
, ser1_data
, set
),
79 IO_STATE(R_IRQ_MASK1_SET
, ser2_data
, set
),
93 IO_STATE(R_IRQ_MASK1_SET
, ser3_data
, set
),
101 #ifdef CONFIG_ETRAX_SERIAL
102 extern struct tty_driver
*serial_driver
;
105 struct dbg_port
* port
=
106 #if defined(CONFIG_ETRAX_DEBUG_PORT0)
108 #elif defined(CONFIG_ETRAX_DEBUG_PORT1)
110 #elif defined(CONFIG_ETRAX_DEBUG_PORT2)
112 #elif defined(CONFIG_ETRAX_DEBUG_PORT3)
118 static struct dbg_port
* kgdb_port
=
119 #if defined(CONFIG_ETRAX_KGDB_PORT0)
121 #elif defined(CONFIG_ETRAX_KGDB_PORT1)
123 #elif defined(CONFIG_ETRAX_KGDB_PORT2)
125 #elif defined(CONFIG_ETRAX_KGDB_PORT3)
132 start_port(struct dbg_port
* p
)
134 unsigned long rec_ctrl
= 0;
135 unsigned long tr_ctrl
= 0;
146 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma6
);
147 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma6
, unused
);
149 else if (p
->index
== 1)
151 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma8
);
152 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma8
, usb
);
154 else if (p
->index
== 2)
156 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma2
);
157 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma2
, par0
);
158 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma3
);
159 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma3
, par0
);
160 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, ser2
, select
);
164 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma4
);
165 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma4
, par1
);
166 genconfig_shadow
&= ~IO_MASK(R_GEN_CONFIG
, dma5
);
167 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, dma5
, par1
);
168 genconfig_shadow
|= IO_STATE(R_GEN_CONFIG
, ser3
, select
);
171 *R_GEN_CONFIG
= genconfig_shadow
;
174 IO_STATE(R_SERIAL0_XOFF
, tx_stop
, enable
) |
175 IO_STATE(R_SERIAL0_XOFF
, auto_xoff
, disable
) |
176 IO_FIELD(R_SERIAL0_XOFF
, xoff_char
, 0);
183 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c115k2Hz
) |
184 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c115k2Hz
);
188 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c1200Hz
) |
189 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c1200Hz
);
193 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c2400Hz
) |
194 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c2400Hz
);
198 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c4800Hz
) |
199 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c4800Hz
);
203 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c9600Hz
) |
204 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c9600Hz
);
208 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c19k2Hz
) |
209 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c19k2Hz
);
213 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c38k4Hz
) |
214 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c38k4Hz
);
218 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c57k6Hz
) |
219 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c57k6Hz
);
223 IO_STATE(R_SERIAL0_BAUD
, tr_baud
, c115k2Hz
) |
224 IO_STATE(R_SERIAL0_BAUD
, rec_baud
, c115k2Hz
);
228 if (p
->parity
== 'E') {
230 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par
, even
) |
231 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par_en
, enable
);
233 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par
, even
) |
234 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par_en
, enable
);
235 } else if (p
->parity
== 'O') {
237 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par
, odd
) |
238 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par_en
, enable
);
240 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par
, odd
) |
241 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par_en
, enable
);
244 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par
, even
) |
245 IO_STATE(R_SERIAL0_REC_CTRL
, rec_par_en
, disable
);
247 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par
, even
) |
248 IO_STATE(R_SERIAL0_TR_CTRL
, tr_par_en
, disable
);
252 rec_ctrl
|= IO_STATE(R_SERIAL0_REC_CTRL
, rec_bitnr
, rec_7bit
);
253 tr_ctrl
|= IO_STATE(R_SERIAL0_TR_CTRL
, tr_bitnr
, tr_7bit
);
257 rec_ctrl
|= IO_STATE(R_SERIAL0_REC_CTRL
, rec_bitnr
, rec_8bit
);
258 tr_ctrl
|= IO_STATE(R_SERIAL0_TR_CTRL
, tr_bitnr
, tr_8bit
);
262 IO_STATE(R_SERIAL0_REC_CTRL
, dma_err
, stop
) |
263 IO_STATE(R_SERIAL0_REC_CTRL
, rec_enable
, enable
) |
264 IO_STATE(R_SERIAL0_REC_CTRL
, rts_
, active
) |
265 IO_STATE(R_SERIAL0_REC_CTRL
, sampling
, middle
) |
266 IO_STATE(R_SERIAL0_REC_CTRL
, rec_stick_par
, normal
) |
270 IO_FIELD(R_SERIAL0_TR_CTRL
, txd
, 0) |
271 IO_STATE(R_SERIAL0_TR_CTRL
, tr_enable
, enable
) |
272 IO_STATE(R_SERIAL0_TR_CTRL
, auto_cts
, disabled
) |
273 IO_STATE(R_SERIAL0_TR_CTRL
, stop_bits
, one_bit
) |
274 IO_STATE(R_SERIAL0_TR_CTRL
, tr_stick_par
, normal
) |
279 console_write_direct(struct console
*co
, const char *buf
, unsigned int len
)
287 local_irq_save(flags
);
290 for (i
= 0; i
< len
; i
++) {
292 if (buf
[i
] == '\n') {
293 while (!(*port
->read
& IO_MASK(R_SERIAL0_READ
, tr_ready
)))
297 /* Wait until transmitter is ready and send.*/
298 while (!(*port
->read
& IO_MASK(R_SERIAL0_READ
, tr_ready
)))
300 *port
->write
= buf
[i
];
304 * Feed the watchdog, otherwise it will reset the chip during boot.
305 * The time to send an ordinary boot message line (10-90 chars)
306 * varies between 1-8ms at 115200. What makes up for the additional
307 * 90ms that allows the watchdog to bite?
311 local_irq_restore(flags
);
315 console_write(struct console
*co
, const char *buf
, unsigned int len
)
320 console_write_direct(co
, buf
, len
);
323 /* legacy function */
326 console_print_etrax(const char *buf
)
328 console_write(NULL
, buf
, strlen(buf
));
331 /* Use polling to get a single character FROM the debug port */
336 unsigned long readval
;
342 readval
= *kgdb_port
->read
;
343 } while (!(readval
& IO_MASK(R_SERIAL0_READ
, data_avail
)));
345 return (readval
& IO_MASK(R_SERIAL0_READ
, data_in
));
348 /* Use polling to put a single character to the debug port */
351 putDebugChar(int val
)
356 while (!(*kgdb_port
->read
& IO_MASK(R_SERIAL0_READ
, tr_ready
)))
358 *kgdb_port
->write
= val
;
361 /* Enable irq for receiving chars on the debug port, used by kgdb */
369 *R_IRQ_MASK1_SET
= kgdb_port
->irq
;
370 /* use R_VECT_MASK directly, since we really bypass Linux normal
371 * IRQ handling in kgdb anyway, we don't need to use enable_irq
373 *R_VECT_MASK_SET
= IO_STATE(R_VECT_MASK_SET
, serial
, set
);
375 *kgdb_port
->rec_ctrl
= IO_STATE(R_SERIAL0_REC_CTRL
, rec_enable
, enable
);
379 console_setup(struct console
*co
, char *options
)
384 port
= &ports
[co
->index
];
385 port
->baudrate
= 115200;
388 port
->baudrate
= simple_strtoul(options
, NULL
, 10);
390 while(*s
>= '0' && *s
<= '9')
392 if (*s
) port
->parity
= *s
++;
393 if (*s
) port
->bits
= *s
++ - '0';
401 /* This is a dummy serial device that throws away anything written to it.
402 * This is used when no debug output is wanted.
404 static struct tty_driver dummy_driver
;
406 static int dummy_open(struct tty_struct
*tty
, struct file
* filp
)
411 static void dummy_close(struct tty_struct
*tty
, struct file
* filp
)
415 static int dummy_write(struct tty_struct
* tty
,
416 const unsigned char *buf
, int count
)
421 static int dummy_write_room(struct tty_struct
*tty
)
426 static const struct tty_operations dummy_ops
= {
428 .close
= dummy_close
,
429 .write
= dummy_write
,
430 .write_room
= dummy_write_room
,
434 init_dummy_console(void)
436 memset(&dummy_driver
, 0, sizeof(struct tty_driver
));
437 dummy_driver
.driver_name
= "serial";
438 dummy_driver
.name
= "ttyS";
439 dummy_driver
.major
= TTY_MAJOR
;
440 dummy_driver
.minor_start
= 68;
441 dummy_driver
.num
= 1; /* etrax100 has 4 serial ports */
442 dummy_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
443 dummy_driver
.subtype
= SERIAL_TYPE_NORMAL
;
444 dummy_driver
.init_termios
= tty_std_termios
;
445 /* Normally B9600 default... */
446 dummy_driver
.init_termios
.c_cflag
=
447 B115200
| CS8
| CREAD
| HUPCL
| CLOCAL
;
448 dummy_driver
.flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
;
449 dummy_driver
.init_termios
.c_ispeed
= 115200;
450 dummy_driver
.init_termios
.c_ospeed
= 115200;
452 dummy_driver
.ops
= &dummy_ops
;
453 if (tty_register_driver(&dummy_driver
))
454 panic("Couldn't register dummy serial driver\n");
457 static struct tty_driver
*
458 etrax_console_device(struct console
* co
, int *index
)
461 *index
= port
->index
;
464 #ifdef CONFIG_ETRAX_SERIAL
465 return port
? serial_driver
: &dummy_driver
;
467 return &dummy_driver
;
471 static struct console sercons
= {
473 write
: console_write
,
475 device
: etrax_console_device
,
477 setup
: console_setup
,
478 flags
: CON_PRINTBUFFER
,
483 static struct console sercons0
= {
485 write
: console_write
,
487 device
: etrax_console_device
,
489 setup
: console_setup
,
490 flags
: CON_PRINTBUFFER
,
496 static struct console sercons1
= {
498 write
: console_write
,
500 device
: etrax_console_device
,
502 setup
: console_setup
,
503 flags
: CON_PRINTBUFFER
,
508 static struct console sercons2
= {
510 write
: console_write
,
512 device
: etrax_console_device
,
514 setup
: console_setup
,
515 flags
: CON_PRINTBUFFER
,
520 static struct console sercons3
= {
522 write
: console_write
,
524 device
: etrax_console_device
,
526 setup
: console_setup
,
527 flags
: CON_PRINTBUFFER
,
533 * Register console (for printk's etc)
537 init_etrax_debug(void)
539 static int first
= 1;
542 unregister_console(&sercons
);
543 register_console(&sercons0
);
544 register_console(&sercons1
);
545 register_console(&sercons2
);
546 register_console(&sercons3
);
547 init_dummy_console();
552 register_console(&sercons
);
554 #ifdef CONFIG_ETRAX_KGDB
555 start_port(kgdb_port
);
559 __initcall(init_etrax_debug
);