16 #include <linux/kernel.h>
19 #include <linux/module.h>
22 #include <linux/tty.h>
24 #include <linux/serial.h>
25 #include <linux/serial_core.h>
30 #define DRV_NAME "altera_jtaguart"
37 #define ALTERA_JTAGUART_SIZE 8
39 #define ALTERA_JTAGUART_DATA_REG 0
41 #define ALTERA_JTAGUART_DATA_DATA_MSK 0x000000FF
42 #define ALTERA_JTAGUART_DATA_RVALID_MSK 0x00008000
43 #define ALTERA_JTAGUART_DATA_RAVAIL_MSK 0xFFFF0000
44 #define ALTERA_JTAGUART_DATA_RAVAIL_OFF 16
46 #define ALTERA_JTAGUART_CONTROL_REG 4
48 #define ALTERA_JTAGUART_CONTROL_RE_MSK 0x00000001
49 #define ALTERA_JTAGUART_CONTROL_WE_MSK 0x00000002
50 #define ALTERA_JTAGUART_CONTROL_RI_MSK 0x00000100
51 #define ALTERA_JTAGUART_CONTROL_RI_OFF 8
52 #define ALTERA_JTAGUART_CONTROL_WI_MSK 0x00000200
53 #define ALTERA_JTAGUART_CONTROL_AC_MSK 0x00000400
54 #define ALTERA_JTAGUART_CONTROL_WSPACE_MSK 0xFFFF0000
55 #define ALTERA_JTAGUART_CONTROL_WSPACE_OFF 16
66 static unsigned int altera_jtaguart_tx_empty(
struct uart_port *
port)
72 static unsigned int altera_jtaguart_get_mctrl(
struct uart_port *
port)
77 static void altera_jtaguart_set_mctrl(
struct uart_port *
port,
unsigned int sigs)
108 static void altera_jtaguart_break_ctl(
struct uart_port *
port,
int break_state)
112 static void altera_jtaguart_enable_ms(
struct uart_port *
port)
116 static void altera_jtaguart_set_termios(
struct uart_port *
port,
128 unsigned char ch,
flag;
149 unsigned int pending,
count;
195 spin_lock(&port->
lock);
198 altera_jtaguart_rx_chars(pp);
200 altera_jtaguart_tx_chars(pp);
202 spin_unlock(&port->
lock);
207 static void altera_jtaguart_config_port(
struct uart_port *port,
int flags)
215 static int altera_jtaguart_startup(
struct uart_port *port)
226 "interrupt vector=%d\n", port->
line, port->
irq);
236 spin_unlock_irqrestore(&port->
lock, flags);
241 static void altera_jtaguart_shutdown(
struct uart_port *port)
253 spin_unlock_irqrestore(&port->
lock, flags);
258 static const char *altera_jtaguart_type(
struct uart_port *port)
263 static int altera_jtaguart_request_port(
struct uart_port *port)
269 static void altera_jtaguart_release_port(
struct uart_port *port)
274 static int altera_jtaguart_verify_port(
struct uart_port *port,
285 static struct uart_ops altera_jtaguart_ops = {
286 .tx_empty = altera_jtaguart_tx_empty,
287 .get_mctrl = altera_jtaguart_get_mctrl,
288 .set_mctrl = altera_jtaguart_set_mctrl,
289 .start_tx = altera_jtaguart_start_tx,
290 .stop_tx = altera_jtaguart_stop_tx,
291 .stop_rx = altera_jtaguart_stop_rx,
292 .enable_ms = altera_jtaguart_enable_ms,
293 .break_ctl = altera_jtaguart_break_ctl,
294 .startup = altera_jtaguart_startup,
295 .shutdown = altera_jtaguart_shutdown,
296 .set_termios = altera_jtaguart_set_termios,
297 .type = altera_jtaguart_type,
298 .request_port = altera_jtaguart_request_port,
299 .release_port = altera_jtaguart_release_port,
300 .config_port = altera_jtaguart_config_port,
301 .verify_port = altera_jtaguart_verify_port,
304 #define ALTERA_JTAGUART_MAXPORTS 1
307 #if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE)
309 #if defined(CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE_BYPASS)
310 static void altera_jtaguart_console_putc(
struct console *co,
const char c)
312 struct uart_port *port = &(altera_jtaguart_ports + co->
index)->port;
320 spin_unlock_irqrestore(&port->
lock, flags);
323 spin_unlock_irqrestore(&port->
lock, flags);
328 spin_unlock_irqrestore(&port->
lock, flags);
331 static void altera_jtaguart_console_putc(
struct console *co,
const char c)
333 struct uart_port *port = &(altera_jtaguart_ports + co->
index)->port;
338 ALTERA_JTAGUART_CONTROL_WSPACE_MSK) == 0) {
339 spin_unlock_irqrestore(&port->
lock, flags);
344 spin_unlock_irqrestore(&port->
lock, flags);
348 static void altera_jtaguart_console_write(
struct console *co,
const char *
s,
351 for (;
count; count--, s++) {
352 altera_jtaguart_console_putc(co, *s);
354 altera_jtaguart_console_putc(co,
'\r');
358 static int __init altera_jtaguart_console_setup(
struct console *co,
365 port = &altera_jtaguart_ports[co->
index].port;
373 static struct console altera_jtaguart_console = {
375 .write = altera_jtaguart_console_write,
377 .setup = altera_jtaguart_console_setup,
380 .data = &altera_jtaguart_driver,
383 static int __init altera_jtaguart_console_init(
void)
391 #define ALTERA_JTAGUART_CONSOLE (&altera_jtaguart_console)
395 #define ALTERA_JTAGUART_CONSOLE NULL
399 static struct uart_driver altera_jtaguart_driver = {
401 .driver_name =
"altera_jtaguart",
423 port = &altera_jtaguart_ports[
i].port;
448 port->
ops = &altera_jtaguart_ops;
464 port = &altera_jtaguart_ports[
i].port;
479 .probe = altera_jtaguart_probe,
488 static int __init altera_jtaguart_init(
void)
503 static void __exit altera_jtaguart_exit(
void)