2 * linux/drivers/char/21285.c
4 * Driver for the serial port on the 21285 StrongArm-110 core logic chip.
6 * Based on drivers/char/serial.c
8 * $Id: 21285.c,v 1.37 2002/07/28 10:03:27 rmk Exp $
10 #include <linux/config.h>
11 #include <linux/module.h>
12 #include <linux/tty.h>
13 #include <linux/ioport.h>
14 #include <linux/init.h>
15 #include <linux/console.h>
16 #include <linux/serial_core.h>
17 #include <linux/serial.h>
21 #include <asm/hardware/dec21285.h>
22 #include <asm/hardware.h>
24 #define BAUD_BASE (mem_fclk_21285/64)
26 #define SERIAL_21285_NAME "ttyFB"
27 #define SERIAL_21285_MAJOR 204
28 #define SERIAL_21285_MINOR 4
30 #define RXSTAT_DUMMY_READ 0x80000000
31 #define RXSTAT_FRAME (1 << 0)
32 #define RXSTAT_PARITY (1 << 1)
33 #define RXSTAT_OVERRUN (1 << 2)
34 #define RXSTAT_ANYERR (RXSTAT_FRAME|RXSTAT_PARITY|RXSTAT_OVERRUN)
36 #define H_UBRLCR_BREAK (1 << 0)
37 #define H_UBRLCR_PARENB (1 << 1)
38 #define H_UBRLCR_PAREVN (1 << 2)
39 #define H_UBRLCR_STOPB (1 << 3)
40 #define H_UBRLCR_FIFO (1 << 4)
42 static const char serial21285_name
[] = "Footbridge UART";
44 #define tx_enabled(port) ((port)->unused[0])
45 #define rx_enabled(port) ((port)->unused[1])
48 * The documented expression for selecting the divisor is:
49 * BAUD_BASE / baud - 1
50 * However, typically BAUD_BASE is not divisible by baud, so
51 * we want to select the divisor that gives us the minimum
52 * error. Therefore, we want:
53 * int(BAUD_BASE / baud - 0.5) ->
54 * int(BAUD_BASE / baud - (baud >> 1) / baud) ->
55 * int((BAUD_BASE - (baud >> 1)) / baud)
59 serial21285_stop_tx(struct uart_port
*port
, unsigned int tty_stop
)
61 if (tx_enabled(port
)) {
62 disable_irq(IRQ_CONTX
);
68 serial21285_start_tx(struct uart_port
*port
, unsigned int tty_start
)
70 if (!tx_enabled(port
)) {
71 enable_irq(IRQ_CONTX
);
76 static void serial21285_stop_rx(struct uart_port
*port
)
78 if (rx_enabled(port
)) {
79 disable_irq(IRQ_CONRX
);
84 static void serial21285_enable_ms(struct uart_port
*port
)
88 static irqreturn_t
serial21285_rx_chars(int irq
, void *dev_id
, struct pt_regs
*regs
)
90 struct uart_port
*port
= dev_id
;
91 struct tty_struct
*tty
= port
->info
->tty
;
92 unsigned int status
, ch
, rxs
, max_count
= 256;
94 status
= *CSR_UARTFLG
;
95 while (!(status
& 0x10) && max_count
--) {
96 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
97 tty
->flip
.work
.func((void *)tty
);
98 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
) {
99 printk(KERN_WARNING
"TTY_DONT_FLIP set\n");
106 *tty
->flip
.char_buf_ptr
= ch
;
107 *tty
->flip
.flag_buf_ptr
= TTY_NORMAL
;
110 rxs
= *CSR_RXSTAT
| RXSTAT_DUMMY_READ
;
111 if (rxs
& RXSTAT_ANYERR
) {
112 if (rxs
& RXSTAT_PARITY
)
113 port
->icount
.parity
++;
114 else if (rxs
& RXSTAT_FRAME
)
115 port
->icount
.frame
++;
116 if (rxs
& RXSTAT_OVERRUN
)
117 port
->icount
.overrun
++;
119 rxs
&= port
->read_status_mask
;
121 if (rxs
& RXSTAT_PARITY
)
122 *tty
->flip
.flag_buf_ptr
= TTY_PARITY
;
123 else if (rxs
& RXSTAT_FRAME
)
124 *tty
->flip
.flag_buf_ptr
= TTY_FRAME
;
127 if ((rxs
& port
->ignore_status_mask
) == 0) {
128 tty
->flip
.flag_buf_ptr
++;
129 tty
->flip
.char_buf_ptr
++;
132 if ((rxs
& RXSTAT_OVERRUN
) &&
133 tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
135 * Overrun is special, since it's reported
136 * immediately, and doesn't affect the current
139 *tty
->flip
.char_buf_ptr
++ = 0;
140 *tty
->flip
.flag_buf_ptr
++ = TTY_OVERRUN
;
143 status
= *CSR_UARTFLG
;
145 tty_flip_buffer_push(tty
);
151 static irqreturn_t
serial21285_tx_chars(int irq
, void *dev_id
, struct pt_regs
*regs
)
153 struct uart_port
*port
= dev_id
;
154 struct circ_buf
*xmit
= &port
->info
->xmit
;
158 *CSR_UARTDR
= port
->x_char
;
163 if (uart_circ_empty(xmit
) || uart_tx_stopped(port
)) {
164 serial21285_stop_tx(port
, 0);
169 *CSR_UARTDR
= xmit
->buf
[xmit
->tail
];
170 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
172 if (uart_circ_empty(xmit
))
174 } while (--count
> 0 && !(*CSR_UARTFLG
& 0x20));
176 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
177 uart_write_wakeup(port
);
179 if (uart_circ_empty(xmit
))
180 serial21285_stop_tx(port
, 0);
186 static unsigned int serial21285_tx_empty(struct uart_port
*port
)
188 return (*CSR_UARTFLG
& 8) ? 0 : TIOCSER_TEMT
;
191 /* no modem control lines */
192 static unsigned int serial21285_get_mctrl(struct uart_port
*port
)
194 return TIOCM_CAR
| TIOCM_DSR
| TIOCM_CTS
;
197 static void serial21285_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
201 static void serial21285_break_ctl(struct uart_port
*port
, int break_state
)
206 spin_lock_irqsave(&port
->lock
, flags
);
207 h_lcr
= *CSR_H_UBRLCR
;
209 h_lcr
|= H_UBRLCR_BREAK
;
211 h_lcr
&= ~H_UBRLCR_BREAK
;
212 *CSR_H_UBRLCR
= h_lcr
;
213 spin_unlock_irqrestore(&port
->lock
, flags
);
216 static int serial21285_startup(struct uart_port
*port
)
220 tx_enabled(port
) = 1;
221 rx_enabled(port
) = 1;
223 ret
= request_irq(IRQ_CONRX
, serial21285_rx_chars
, 0,
224 serial21285_name
, port
);
226 ret
= request_irq(IRQ_CONTX
, serial21285_tx_chars
, 0,
227 serial21285_name
, port
);
229 free_irq(IRQ_CONRX
, port
);
235 static void serial21285_shutdown(struct uart_port
*port
)
237 free_irq(IRQ_CONTX
, port
);
238 free_irq(IRQ_CONRX
, port
);
242 serial21285_set_termios(struct uart_port
*port
, struct termios
*termios
,
246 unsigned int baud
, quot
, h_lcr
;
249 * We don't support modem control lines.
251 termios
->c_cflag
&= ~(HUPCL
| CRTSCTS
| CMSPAR
);
252 termios
->c_cflag
|= CLOCAL
;
255 * We don't support BREAK character recognition.
257 termios
->c_iflag
&= ~(IGNBRK
| BRKINT
);
260 * Ask the core to calculate the divisor for us.
262 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16);
263 quot
= uart_get_divisor(port
, baud
);
265 switch (termios
->c_cflag
& CSIZE
) {
280 if (termios
->c_cflag
& CSTOPB
)
281 h_lcr
|= H_UBRLCR_STOPB
;
282 if (termios
->c_cflag
& PARENB
) {
283 h_lcr
|= H_UBRLCR_PARENB
;
284 if (!(termios
->c_cflag
& PARODD
))
285 h_lcr
|= H_UBRLCR_PAREVN
;
289 h_lcr
|= H_UBRLCR_FIFO
;
291 spin_lock_irqsave(&port
->lock
, flags
);
294 * Update the per-port timeout.
296 uart_update_timeout(port
, termios
->c_cflag
, baud
);
299 * Which character status flags are we interested in?
301 port
->read_status_mask
= RXSTAT_OVERRUN
;
302 if (termios
->c_iflag
& INPCK
)
303 port
->read_status_mask
|= RXSTAT_FRAME
| RXSTAT_PARITY
;
306 * Which character status flags should we ignore?
308 port
->ignore_status_mask
= 0;
309 if (termios
->c_iflag
& IGNPAR
)
310 port
->ignore_status_mask
|= RXSTAT_FRAME
| RXSTAT_PARITY
;
311 if (termios
->c_iflag
& IGNBRK
&& termios
->c_iflag
& IGNPAR
)
312 port
->ignore_status_mask
|= RXSTAT_OVERRUN
;
315 * Ignore all characters if CREAD is not set.
317 if ((termios
->c_cflag
& CREAD
) == 0)
318 port
->ignore_status_mask
|= RXSTAT_DUMMY_READ
;
323 *CSR_L_UBRLCR
= quot
& 0xff;
324 *CSR_M_UBRLCR
= (quot
>> 8) & 0x0f;
325 *CSR_H_UBRLCR
= h_lcr
;
328 spin_unlock_irqrestore(&port
->lock
, flags
);
331 static const char *serial21285_type(struct uart_port
*port
)
333 return port
->type
== PORT_21285
? "DC21285" : NULL
;
336 static void serial21285_release_port(struct uart_port
*port
)
338 release_mem_region(port
->mapbase
, 32);
341 static int serial21285_request_port(struct uart_port
*port
)
343 return request_mem_region(port
->mapbase
, 32, serial21285_name
)
344 != NULL
? 0 : -EBUSY
;
347 static void serial21285_config_port(struct uart_port
*port
, int flags
)
349 if (flags
& UART_CONFIG_TYPE
&& serial21285_request_port(port
) == 0)
350 port
->type
= PORT_21285
;
354 * verify the new serial_struct (for TIOCSSERIAL).
356 static int serial21285_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
359 if (ser
->type
!= PORT_UNKNOWN
&& ser
->type
!= PORT_21285
)
361 if (ser
->irq
!= NO_IRQ
)
363 if (ser
->baud_base
!= port
->uartclk
/ 16)
368 static struct uart_ops serial21285_ops
= {
369 .tx_empty
= serial21285_tx_empty
,
370 .get_mctrl
= serial21285_get_mctrl
,
371 .set_mctrl
= serial21285_set_mctrl
,
372 .stop_tx
= serial21285_stop_tx
,
373 .start_tx
= serial21285_start_tx
,
374 .stop_rx
= serial21285_stop_rx
,
375 .enable_ms
= serial21285_enable_ms
,
376 .break_ctl
= serial21285_break_ctl
,
377 .startup
= serial21285_startup
,
378 .shutdown
= serial21285_shutdown
,
379 .set_termios
= serial21285_set_termios
,
380 .type
= serial21285_type
,
381 .release_port
= serial21285_release_port
,
382 .request_port
= serial21285_request_port
,
383 .config_port
= serial21285_config_port
,
384 .verify_port
= serial21285_verify_port
,
387 static struct uart_port serial21285_port
= {
389 .mapbase
= 0x42000160,
390 .iotype
= SERIAL_IO_MEM
,
394 .ops
= &serial21285_ops
,
395 .flags
= ASYNC_BOOT_AUTOCONF
,
398 static void serial21285_setup_ports(void)
400 serial21285_port
.uartclk
= mem_fclk_21285
/ 4;
403 #ifdef CONFIG_SERIAL_21285_CONSOLE
406 serial21285_console_write(struct console
*co
, const char *s
,
411 for (i
= 0; i
< count
; i
++) {
412 while (*CSR_UARTFLG
& 0x20)
416 while (*CSR_UARTFLG
& 0x20)
424 serial21285_get_options(struct uart_port
*port
, int *baud
,
425 int *parity
, int *bits
)
427 if (*CSR_UARTCON
== 1) {
431 switch (tmp
& 0x60) {
447 if (tmp
& H_UBRLCR_PARENB
) {
449 if (tmp
& H_UBRLCR_PAREVN
)
453 tmp
= *CSR_L_UBRLCR
| (*CSR_M_UBRLCR
<< 8);
455 *baud
= port
->uartclk
/ (16 * (tmp
+ 1));
459 static int __init
serial21285_console_setup(struct console
*co
, char *options
)
461 struct uart_port
*port
= &serial21285_port
;
467 if (machine_is_personal_server())
471 * Check whether an invalid uart number has been specified, and
472 * if so, search for the first available port that does have
476 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
478 serial21285_get_options(port
, &baud
, &parity
, &bits
);
480 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
483 extern struct uart_driver serial21285_reg
;
484 #ifdef CONFIG_SERIAL_21285_OLD
485 static struct console serial21285_old_cons
=
487 .name
= SERIAL_21285_OLD_NAME
,
488 .write
= serial21285_console_write
,
489 .device
= uart_console_device
,
490 .setup
= serial21285_console_setup
,
491 .flags
= CON_PRINTBUFFER
,
493 .data
= &serial21285_reg
,
497 static struct console serial21285_console
=
499 .name
= SERIAL_21285_NAME
,
500 .write
= serial21285_console_write
,
501 .device
= uart_console_device
,
502 .setup
= serial21285_console_setup
,
503 .flags
= CON_PRINTBUFFER
,
505 .data
= &serial21285_reg
,
508 static int __init
rs285_console_init(void)
510 serial21285_setup_ports();
511 register_console(&serial21285_console
);
514 console_initcall(rs285_console_init
);
516 #define SERIAL_21285_CONSOLE &serial21285_console
518 #define SERIAL_21285_CONSOLE NULL
521 static struct uart_driver serial21285_reg
= {
522 .owner
= THIS_MODULE
,
523 .driver_name
= "ttyFB",
525 .major
= SERIAL_21285_MAJOR
,
526 .minor
= SERIAL_21285_MINOR
,
528 .cons
= SERIAL_21285_CONSOLE
,
531 static int __init
serial21285_init(void)
535 printk(KERN_INFO
"Serial: 21285 driver $Revision: 1.37 $\n");
537 serial21285_setup_ports();
539 ret
= uart_register_driver(&serial21285_reg
);
541 uart_add_one_port(&serial21285_reg
, &serial21285_port
);
546 static void __exit
serial21285_exit(void)
548 uart_remove_one_port(&serial21285_reg
, &serial21285_port
);
549 uart_unregister_driver(&serial21285_reg
);
552 module_init(serial21285_init
);
553 module_exit(serial21285_exit
);
555 MODULE_LICENSE("GPL");
556 MODULE_DESCRIPTION("Intel Footbridge (21285) serial driver $Revision: 1.37 $");