2 * linux/drivers/serial/t32.c
4 * serial port emulation driver for the TRACE32 Terminal.
6 * JTAG1 protocol version for ICD:
7 * Copyright (C) 2003, 2004 Hyok S. Choi (hyok.choi@samsung.com)
8 * SAMSUNG ELECTRONICS Co.,Ltd.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 * Oct-2003 Hyok S. Choi Created
16 * Feb-2004 Hyok S. Choi Updated for serial_core.c and 2.6 kernel
17 * Apr-2004 Hyok S. Choi xmit_string_CR added
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/tty.h>
24 #include <linux/ioport.h>
25 #include <linux/init.h>
26 #include <linux/serial.h>
27 #include <linux/console.h>
28 #include <linux/sysrq.h>
29 #include <linux/major.h>
34 #include <linux/serial_core.h>
37 /* real irq interrupt used */
40 /* scheduled work used */
45 static struct work_struct t32_poll_task
;
46 static void t32_poll(void *data
);
49 #define UART_NR 1 /* we have only one JTAG port */
51 #define SERIAL_T32_NAME "ttyJ"
52 #define SERIAL_T32_MAJOR 4
53 #define SERIAL_T32_MINOR 64
55 static int __inline__
__check_JTAG_RX_FLAG(void)
59 " mrc p14, 0, %0, c0, c0 @ read comms control reg\n"
60 " and %0, %0, #1 @ jtag read buffer status"
64 /* if __ret == 0 : no input yet
65 == 1 : a character pending */
69 static void __inline__
__get_JTAG_RX(volatile char *p
)
72 " mrc p14, 0, r3, c1, c0 @ read comms data reg to r5\n"
73 " strb r3, [%0] @ str a char"
80 static int __inline__
__check_JTAG_TX_FLAG(void)
84 " mrc p14, 0, %0, c0, c0 @ read comms control reg\n"
85 " and %0, %0, #2 @ the read buffer status"
89 /* if __ret == 0 : tx is available
94 void xmit_string(char *p
, int len
)
96 #ifndef CONFIG_JTAG_T32_OUTPUT_DISABLE
98 r0 = string ; string address
99 r1 = 2 ; state check bit (write)
100 r4 = *string ; character
103 __asm__
__volatile__(
105 "1: mrc p14, 0, r3, c0, c0 @ read comms control reg\n"
106 " and r3, r3, #2 @ the write buffer status\n"
107 " cmp r3, #2 @ is it available?\n"
108 " beq 1b @ is not, wait till then\n"
109 " ldrb r4, [%0] @ load a char\n"
110 " mcr p14, 0, r4, c1, c0 @ write it\n"
111 " add %0, %0, #1 @ str address increase one\n"
112 " add r7, r7, #1 @ count increase\n"
113 " cmp r7, %1 @ compare with str length\n"
114 " bne 1b @ if it is not yet, loop"
115 : /* no output register */
121 void xmit_string_CR(char *p
, int len
)
123 #ifndef CONFIG_JTAG_T32_OUTPUT_DISABLE
125 r0 = string ; string address
126 r1 = 2 ; state check bit (write)
127 r4 = *string ; character
130 __asm__
__volatile__(
132 " ldrb r4, [%0] @ load a char\n"
133 "1: mrc p14, 0, r3, c0, c0 @ read comms control reg\n"
134 " and r3, r3, #2 @ the write buffer status\n"
135 " cmp r3, #2 @ is it available?\n"
136 " beq 1b @ is not, wait till then\n"
137 " mcr p14, 0, r4, c1, c0 @ write it\n"
138 " cmp r4, #0x0a @ is it LF?\n"
139 " bne 2f @ if it is not, continue\n"
140 " mov r4, #0x0d @ set the CR\n"
141 " b 1b @ loop for writing CR\n"
142 "2: ldrb r4, [%0, #1]! @ load a char\n"
143 " add r7, r7, #1 @ count increase\n"
144 " cmp r7, %1 @ compare with str length\n"
145 " bne 1b @ if it is not yet, loop"
146 : /* no output register */
154 t32_stop_tx(struct uart_port
*port
, unsigned int tty_stop
)
159 t32_transmit_buffer(struct uart_port
*port
)
161 struct circ_buf
*xmit
= &port
->info
->xmit
;
163 int pendings
= uart_circ_chars_pending(xmit
);
165 if(pendings
+ xmit
->tail
> UART_XMIT_SIZE
)
167 xmit_string(&(xmit
->buf
[xmit
->tail
]), UART_XMIT_SIZE
- xmit
->tail
);
168 xmit_string(&(xmit
->buf
[0]), xmit
->head
);
170 xmit_string(&(xmit
->buf
[xmit
->tail
]), pendings
);
172 xmit
->tail
= (xmit
->tail
+ pendings
) & (UART_XMIT_SIZE
-1);
173 port
->icount
.tx
+= pendings
;
175 if (uart_circ_empty(xmit
))
176 t32_stop_tx(port
, 0);
180 t32_transmit_x_char(struct uart_port
*port
)
182 xmit_string(&port
->x_char
, 1);
188 t32_start_tx(struct uart_port
*port
, unsigned int tty_start
)
190 t32_transmit_buffer(port
);
194 t32_stop_rx(struct uart_port
*port
)
199 t32_enable_ms(struct uart_port
*port
)
204 t32_rx_chars(struct uart_port
*port
)
207 struct tty_struct
*tty
= port
->info
->tty
;
211 * checking JTAG flag is better to resolve the status test.
212 * incount is NOT used for JTAG1 protocol.
215 if (__check_JTAG_RX_FLAG())
216 /* if __ret == 0 : no input yet
217 == 1 : a character pending */
219 /* for JTAG 1 protocol, incount is always 1. */
221 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
222 *tty
->flip
.char_buf_ptr
++ = ch
;
223 *tty
->flip
.flag_buf_ptr
++ = TTY_NORMAL
;
227 tty_flip_buffer_push(tty
);
232 t32_overrun_chars(struct uart_port
*port
)
234 port
->icount
.overrun
++;
238 t32_tx_chars(struct uart_port
*port
)
240 struct circ_buf
*xmit
= &port
->info
->xmit
;
243 t32_transmit_x_char(port
);
247 if (uart_circ_empty(xmit
) || uart_tx_stopped(port
)) {
248 t32_stop_tx(port
, 0);
252 t32_transmit_buffer(port
);
254 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
255 uart_write_wakeup(port
);
258 #ifdef T32_IRQ_USED /* real IRQ used */
260 t32_int(int irq
, void *dev_id
, struct pt_regs
*regs
)
262 struct uart_port
*port
= dev_id
;
265 spin_lock(&port
->lock
);
271 spin_unlock(&port
->lock
);
273 return IRQ_RETVAL(handled
);
276 #else /* emulation by scheduled work */
280 struct uart_port
*port
= data
;
282 spin_lock(&port
->lock
);
287 schedule_delayed_work(&t32_poll_task
, 1);
289 spin_unlock(&port
->lock
);
292 #endif /* end of T32_IRQ_USED */
295 t32_tx_empty(struct uart_port
*port
)
301 t32_get_mctrl(struct uart_port
*port
)
307 t32_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
312 t32_break_ctl(struct uart_port
*port
, int break_state
)
316 static int t32_startup(struct uart_port
*port
)
318 #ifdef T32_IRQ_USED /* real IRQ used */
321 /* Allocate the IRQ */
322 retval
= request_irq(port
->irq
, t32_int
, SA_INTERRUPT
,
326 #else /* emulation */
327 /* Initialize the work, and shcedule it. */
328 INIT_WORK(&t32_poll_task
, t32_poll
, port
);
329 schedule_delayed_work(&t32_poll_task
, 1);
335 static void t32_shutdown(struct uart_port
*port
)
340 t32_set_termios(struct uart_port
*port
, struct termios
*termios
,
346 unsigned int baud
, quot
;
349 * We don't support parity, stop bits, or anything other
350 * than 8 bits, so clear these termios flags.
352 termios
->c_cflag
&= ~(CSIZE
| CSTOPB
| PARENB
| PARODD
| CREAD
);
353 termios
->c_cflag
|= CS8
;
356 * We don't appear to support any error conditions either.
358 termios
->c_iflag
&= ~(INPCK
| IGNPAR
| IGNBRK
| BRKINT
);
361 * Ask the core to calculate the divisor for us.
363 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16);
364 quot
= uart_get_divisor(port
, baud
);
367 spin_lock_irqsave(&port
->lock
, flags
);
370 uart_update_timeout(port
, termios
->c_cflag
, baud
);
373 spin_unlock_irqrestore(&port
->lock
, flags
);
377 static const char *t32_type(struct uart_port
*port
)
379 return port
->type
== PORT_T32_JTAG1
? "T32" : NULL
;
382 static void t32_release_port(struct uart_port
*port
)
386 static int t32_request_port(struct uart_port
*port
)
392 * Configure/autoconfigure the port.
394 static void t32_config_port(struct uart_port
*port
, int flags
)
396 if (flags
& UART_CONFIG_TYPE
) {
397 port
->type
= PORT_T32_JTAG1
;
398 t32_request_port(port
);
403 * verify the new serial_struct (for TIOCSSERIAL).
405 static int t32_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
408 if (ser
->type
!= PORT_UNKNOWN
&& ser
->type
!= PORT_T32_JTAG1
)
410 if (ser
->irq
< 0 || ser
->irq
>= NR_IRQS
)
412 if (ser
->baud_base
< 9600)
417 static struct uart_ops t32_pops
= {
418 .tx_empty
= t32_tx_empty
,
419 .set_mctrl
= t32_set_mctrl
,
420 .get_mctrl
= t32_get_mctrl
,
421 .stop_tx
= t32_stop_tx
,
422 .start_tx
= t32_start_tx
,
423 .stop_rx
= t32_stop_rx
,
424 .enable_ms
= t32_enable_ms
,
425 .break_ctl
= t32_break_ctl
,
426 .startup
= t32_startup
,
427 .shutdown
= t32_shutdown
,
428 .set_termios
= t32_set_termios
,
430 .release_port
= t32_release_port
,
431 .request_port
= t32_request_port
,
432 .config_port
= t32_config_port
,
433 .verify_port
= t32_verify_port
,
436 static struct uart_port t32_ports
[UART_NR
] = {
438 .membase
= (char*)0x12345678, /* we need these garbages */
439 .mapbase
= 0x12345678, /* for serial_core.c */
440 .iotype
= SERIAL_IO_MEM
,
449 .flags
= ASYNC_BOOT_AUTOCONF
,
455 #ifdef CONFIG_SERIAL_T32_CONSOLE
458 t32_console_write(struct console
*co
, const char *s
, unsigned int count
)
460 xmit_string_CR((char*)s
, count
);
464 * Read the current UART setup.
467 t32_console_get_options(struct uart_port
*port
, int *baud
, int *parity
, int *bits
)
475 t32_console_setup(struct console
*co
, char *options
)
477 struct uart_port
*port
;
483 if (co
->index
>= UART_NR
)
485 port
= &t32_ports
[co
->index
];
488 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
490 t32_console_get_options(port
, &baud
, &parity
, &bits
);
492 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
495 extern struct uart_driver t32_reg
;
496 static struct console t32_console
= {
497 .name
= SERIAL_T32_NAME
,
498 .write
= t32_console_write
,
499 .device
= uart_console_device
,
500 .setup
= t32_console_setup
,
501 .flags
= CON_PRINTBUFFER
,
506 static int __init
t32_console_init(void)
508 register_console(&t32_console
);
511 console_initcall(t32_console_init
);
513 #define T32_CONSOLE &t32_console
515 #define T32_CONSOLE NULL
518 static struct uart_driver t32_reg
= {
519 .owner
= THIS_MODULE
,
520 .driver_name
= SERIAL_T32_NAME
,
521 .dev_name
= SERIAL_T32_NAME
,
522 .major
= SERIAL_T32_MAJOR
,
523 .minor
= SERIAL_T32_MINOR
,
533 printk(KERN_INFO
"T32: JTAG1 Serial emulation driver driver $Revision: 1.1 $\n");
535 ret
= uart_register_driver(&t32_reg
);
539 for (i
= 0; i
< UART_NR
; i
++)
540 uart_add_one_port(&t32_reg
, &t32_ports
[i
]);
545 __initcall(t32_init
);
547 MODULE_DESCRIPTION("T32 JTAG1 serial and console emulation driver");
548 MODULE_AUTHOR("Hyok S. Choi <hyok.choi@samsung.com>");
549 MODULE_SUPPORTED_DEVICE("ttyJ");
550 MODULE_LICENSE("GPL");