2 * linux/drivers/char/sa1100.c
4 * Driver for SA11x0 serial ports
6 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
8 * Copyright (C) 2000 Deep Blue Solutions 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 as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * $Id: sa1100.c,v 1.50 2002/07/29 14:41:04 rmk Exp $
27 #include <linux/config.h>
28 #include <linux/module.h>
29 #include <linux/tty.h>
30 #include <linux/ioport.h>
31 #include <linux/init.h>
32 #include <linux/serial.h>
33 #include <linux/console.h>
34 #include <linux/sysrq.h>
35 #include <linux/device.h>
39 #include <asm/hardware.h>
40 #include <asm/mach/serial_sa1100.h>
42 #if defined(CONFIG_SERIAL_SA1100_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
46 #include <linux/serial_core.h>
48 /* We've been assigned a range on the "Low-density serial ports" major */
49 #define SERIAL_SA1100_MAJOR 204
54 #define SA1100_ISR_PASS_LIMIT 256
57 * Convert from ignore_status_mask or read_status_mask to UTSR[01]
59 #define SM_TO_UTSR0(x) ((x) & 0xff)
60 #define SM_TO_UTSR1(x) ((x) >> 8)
61 #define UTSR0_TO_SM(x) ((x))
62 #define UTSR1_TO_SM(x) ((x) << 8)
64 #define UART_GET_UTCR0(sport) __raw_readl((sport)->port.membase + UTCR0)
65 #define UART_GET_UTCR1(sport) __raw_readl((sport)->port.membase + UTCR1)
66 #define UART_GET_UTCR2(sport) __raw_readl((sport)->port.membase + UTCR2)
67 #define UART_GET_UTCR3(sport) __raw_readl((sport)->port.membase + UTCR3)
68 #define UART_GET_UTSR0(sport) __raw_readl((sport)->port.membase + UTSR0)
69 #define UART_GET_UTSR1(sport) __raw_readl((sport)->port.membase + UTSR1)
70 #define UART_GET_CHAR(sport) __raw_readl((sport)->port.membase + UTDR)
72 #define UART_PUT_UTCR0(sport,v) __raw_writel((v),(sport)->port.membase + UTCR0)
73 #define UART_PUT_UTCR1(sport,v) __raw_writel((v),(sport)->port.membase + UTCR1)
74 #define UART_PUT_UTCR2(sport,v) __raw_writel((v),(sport)->port.membase + UTCR2)
75 #define UART_PUT_UTCR3(sport,v) __raw_writel((v),(sport)->port.membase + UTCR3)
76 #define UART_PUT_UTSR0(sport,v) __raw_writel((v),(sport)->port.membase + UTSR0)
77 #define UART_PUT_UTSR1(sport,v) __raw_writel((v),(sport)->port.membase + UTSR1)
78 #define UART_PUT_CHAR(sport,v) __raw_writel((v),(sport)->port.membase + UTDR)
81 * This is the size of our serial port register set.
83 #define UART_PORT_SIZE 0x24
86 * This determines how often we check the modem status signals
87 * for any change. They generally aren't connected to an IRQ
88 * so we have to poll them. We also check immediately before
89 * filling the TX fifo incase CTS has been dropped.
91 #define MCTRL_TIMEOUT (250*HZ/1000)
94 struct uart_port port
;
95 struct timer_list timer
;
96 unsigned int old_status
;
100 * Handle any change of modem status signal since we were last called.
102 static void sa1100_mctrl_check(struct sa1100_port
*sport
)
104 unsigned int status
, changed
;
106 status
= sport
->port
.ops
->get_mctrl(&sport
->port
);
107 changed
= status
^ sport
->old_status
;
112 sport
->old_status
= status
;
114 if (changed
& TIOCM_RI
)
115 sport
->port
.icount
.rng
++;
116 if (changed
& TIOCM_DSR
)
117 sport
->port
.icount
.dsr
++;
118 if (changed
& TIOCM_CAR
)
119 uart_handle_dcd_change(&sport
->port
, status
& TIOCM_CAR
);
120 if (changed
& TIOCM_CTS
)
121 uart_handle_cts_change(&sport
->port
, status
& TIOCM_CTS
);
123 wake_up_interruptible(&sport
->port
.info
->delta_msr_wait
);
127 * This is our per-port timeout handler, for checking the
128 * modem status signals.
130 static void sa1100_timeout(unsigned long data
)
132 struct sa1100_port
*sport
= (struct sa1100_port
*)data
;
135 if (sport
->port
.info
) {
136 spin_lock_irqsave(&sport
->port
.lock
, flags
);
137 sa1100_mctrl_check(sport
);
138 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
140 mod_timer(&sport
->timer
, jiffies
+ MCTRL_TIMEOUT
);
145 * interrupts disabled on entry
147 static void sa1100_stop_tx(struct uart_port
*port
, unsigned int tty_stop
)
149 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
152 utcr3
= UART_GET_UTCR3(sport
);
153 UART_PUT_UTCR3(sport
, utcr3
& ~UTCR3_TIE
);
154 sport
->port
.read_status_mask
&= ~UTSR0_TO_SM(UTSR0_TFS
);
158 * interrupts may not be disabled on entry
160 static void sa1100_start_tx(struct uart_port
*port
, unsigned int tty_start
)
162 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
166 spin_lock_irqsave(&sport
->port
.lock
, flags
);
167 utcr3
= UART_GET_UTCR3(sport
);
168 sport
->port
.read_status_mask
|= UTSR0_TO_SM(UTSR0_TFS
);
169 UART_PUT_UTCR3(sport
, utcr3
| UTCR3_TIE
);
170 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
176 static void sa1100_stop_rx(struct uart_port
*port
)
178 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
181 utcr3
= UART_GET_UTCR3(sport
);
182 UART_PUT_UTCR3(sport
, utcr3
& ~UTCR3_RIE
);
186 * Set the modem control timer to fire immediately.
188 static void sa1100_enable_ms(struct uart_port
*port
)
190 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
192 mod_timer(&sport
->timer
, jiffies
);
196 sa1100_rx_chars(struct sa1100_port
*sport
, struct pt_regs
*regs
)
198 struct tty_struct
*tty
= sport
->port
.info
->tty
;
199 unsigned int status
, ch
, flg
, ignored
= 0;
201 status
= UTSR1_TO_SM(UART_GET_UTSR1(sport
)) |
202 UTSR0_TO_SM(UART_GET_UTSR0(sport
));
203 while (status
& UTSR1_TO_SM(UTSR1_RNE
)) {
204 ch
= UART_GET_CHAR(sport
);
206 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
208 sport
->port
.icount
.rx
++;
213 * note that the error handling code is
214 * out of the main execution path
216 if (status
& UTSR1_TO_SM(UTSR1_PRE
| UTSR1_FRE
| UTSR1_ROR
))
219 if (uart_handle_sysrq_char(&sport
->port
, ch
, regs
))
223 *tty
->flip
.flag_buf_ptr
++ = flg
;
224 *tty
->flip
.char_buf_ptr
++ = ch
;
227 status
= UTSR1_TO_SM(UART_GET_UTSR1(sport
)) |
228 UTSR0_TO_SM(UART_GET_UTSR0(sport
));
231 tty_flip_buffer_push(tty
);
235 if (status
& UTSR1_TO_SM(UTSR1_PRE
))
236 sport
->port
.icount
.parity
++;
237 else if (status
& UTSR1_TO_SM(UTSR1_FRE
))
238 sport
->port
.icount
.frame
++;
239 if (status
& UTSR1_TO_SM(UTSR1_ROR
))
240 sport
->port
.icount
.overrun
++;
242 if (status
& sport
->port
.ignore_status_mask
) {
248 status
&= sport
->port
.read_status_mask
;
250 if (status
& UTSR1_TO_SM(UTSR1_PRE
))
252 else if (status
& UTSR1_TO_SM(UTSR1_FRE
))
255 if (status
& UTSR1_TO_SM(UTSR1_ROR
)) {
257 * overrun does *not* affect the character
258 * we read from the FIFO
260 *tty
->flip
.flag_buf_ptr
++ = flg
;
261 *tty
->flip
.char_buf_ptr
++ = ch
;
263 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
269 sport
->port
.sysrq
= 0;
274 static void sa1100_tx_chars(struct sa1100_port
*sport
)
276 struct circ_buf
*xmit
= &sport
->port
.info
->xmit
;
278 if (sport
->port
.x_char
) {
279 UART_PUT_CHAR(sport
, sport
->port
.x_char
);
280 sport
->port
.icount
.tx
++;
281 sport
->port
.x_char
= 0;
286 * Check the modem control lines before
287 * transmitting anything.
289 sa1100_mctrl_check(sport
);
291 if (uart_circ_empty(xmit
) || uart_tx_stopped(&sport
->port
)) {
292 sa1100_stop_tx(&sport
->port
, 0);
297 * Tried using FIFO (not checking TNF) for fifo fill:
298 * still had the '4 bytes repeated' problem.
300 while (UART_GET_UTSR1(sport
) & UTSR1_TNF
) {
301 UART_PUT_CHAR(sport
, xmit
->buf
[xmit
->tail
]);
302 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
303 sport
->port
.icount
.tx
++;
304 if (uart_circ_empty(xmit
))
308 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
309 uart_write_wakeup(&sport
->port
);
311 if (uart_circ_empty(xmit
))
312 sa1100_stop_tx(&sport
->port
, 0);
315 static irqreturn_t
sa1100_int(int irq
, void *dev_id
, struct pt_regs
*regs
)
317 struct sa1100_port
*sport
= dev_id
;
318 unsigned int status
, pass_counter
= 0;
320 spin_lock(&sport
->port
.lock
);
321 status
= UART_GET_UTSR0(sport
);
322 status
&= SM_TO_UTSR0(sport
->port
.read_status_mask
) | ~UTSR0_TFS
;
324 if (status
& (UTSR0_RFS
| UTSR0_RID
)) {
325 /* Clear the receiver idle bit, if set */
326 if (status
& UTSR0_RID
)
327 UART_PUT_UTSR0(sport
, UTSR0_RID
);
328 sa1100_rx_chars(sport
, regs
);
331 /* Clear the relevant break bits */
332 if (status
& (UTSR0_RBB
| UTSR0_REB
))
333 UART_PUT_UTSR0(sport
, status
& (UTSR0_RBB
| UTSR0_REB
));
335 if (status
& UTSR0_RBB
)
336 sport
->port
.icount
.brk
++;
338 if (status
& UTSR0_REB
)
339 uart_handle_break(&sport
->port
);
341 if (status
& UTSR0_TFS
)
342 sa1100_tx_chars(sport
);
343 if (pass_counter
++ > SA1100_ISR_PASS_LIMIT
)
345 status
= UART_GET_UTSR0(sport
);
346 status
&= SM_TO_UTSR0(sport
->port
.read_status_mask
) |
348 } while (status
& (UTSR0_TFS
| UTSR0_RFS
| UTSR0_RID
));
349 spin_unlock(&sport
->port
.lock
);
355 * Return TIOCSER_TEMT when transmitter is not busy.
357 static unsigned int sa1100_tx_empty(struct uart_port
*port
)
359 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
361 return UART_GET_UTSR1(sport
) & UTSR1_TBY
? 0 : TIOCSER_TEMT
;
364 static unsigned int sa1100_get_mctrl(struct uart_port
*port
)
366 return TIOCM_CTS
| TIOCM_DSR
| TIOCM_CAR
;
369 static void sa1100_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
374 * Interrupts always disabled.
376 static void sa1100_break_ctl(struct uart_port
*port
, int break_state
)
378 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
382 spin_lock_irqsave(&sport
->port
.lock
, flags
);
383 utcr3
= UART_GET_UTCR3(sport
);
384 if (break_state
== -1)
388 UART_PUT_UTCR3(sport
, utcr3
);
389 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
392 static int sa1100_startup(struct uart_port
*port
)
394 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
400 retval
= request_irq(sport
->port
.irq
, sa1100_int
, 0,
401 "sa11x0-uart", sport
);
406 * Finally, clear and enable interrupts
408 UART_PUT_UTSR0(sport
, -1);
409 UART_PUT_UTCR3(sport
, UTCR3_RXE
| UTCR3_TXE
| UTCR3_RIE
);
412 * Enable modem status interrupts
414 spin_lock_irq(&sport
->port
.lock
);
415 sa1100_enable_ms(&sport
->port
);
416 spin_unlock_irq(&sport
->port
.lock
);
421 static void sa1100_shutdown(struct uart_port
*port
)
423 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
428 del_timer_sync(&sport
->timer
);
433 free_irq(sport
->port
.irq
, sport
);
436 * Disable all interrupts, port and break condition.
438 UART_PUT_UTCR3(sport
, 0);
442 sa1100_set_termios(struct uart_port
*port
, struct termios
*termios
,
445 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
447 unsigned int utcr0
, old_utcr3
, baud
, quot
;
448 unsigned int old_csize
= old
? old
->c_cflag
& CSIZE
: CS8
;
451 * We only support CS7 and CS8.
453 while ((termios
->c_cflag
& CSIZE
) != CS7
&&
454 (termios
->c_cflag
& CSIZE
) != CS8
) {
455 termios
->c_cflag
&= ~CSIZE
;
456 termios
->c_cflag
|= old_csize
;
460 if ((termios
->c_cflag
& CSIZE
) == CS8
)
465 if (termios
->c_cflag
& CSTOPB
)
467 if (termios
->c_cflag
& PARENB
) {
469 if (!(termios
->c_cflag
& PARODD
))
474 * Ask the core to calculate the divisor for us.
476 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16);
477 quot
= uart_get_divisor(port
, baud
);
479 spin_lock_irqsave(&sport
->port
.lock
, flags
);
481 sport
->port
.read_status_mask
&= UTSR0_TO_SM(UTSR0_TFS
);
482 sport
->port
.read_status_mask
|= UTSR1_TO_SM(UTSR1_ROR
);
483 if (termios
->c_iflag
& INPCK
)
484 sport
->port
.read_status_mask
|=
485 UTSR1_TO_SM(UTSR1_FRE
| UTSR1_PRE
);
486 if (termios
->c_iflag
& (BRKINT
| PARMRK
))
487 sport
->port
.read_status_mask
|=
488 UTSR0_TO_SM(UTSR0_RBB
| UTSR0_REB
);
491 * Characters to ignore
493 sport
->port
.ignore_status_mask
= 0;
494 if (termios
->c_iflag
& IGNPAR
)
495 sport
->port
.ignore_status_mask
|=
496 UTSR1_TO_SM(UTSR1_FRE
| UTSR1_PRE
);
497 if (termios
->c_iflag
& IGNBRK
) {
498 sport
->port
.ignore_status_mask
|=
499 UTSR0_TO_SM(UTSR0_RBB
| UTSR0_REB
);
501 * If we're ignoring parity and break indicators,
502 * ignore overruns too (for real raw support).
504 if (termios
->c_iflag
& IGNPAR
)
505 sport
->port
.ignore_status_mask
|=
506 UTSR1_TO_SM(UTSR1_ROR
);
509 del_timer_sync(&sport
->timer
);
512 * Update the per-port timeout.
514 uart_update_timeout(port
, termios
->c_cflag
, baud
);
517 * disable interrupts and drain transmitter
519 old_utcr3
= UART_GET_UTCR3(sport
);
520 UART_PUT_UTCR3(sport
, old_utcr3
& ~(UTCR3_RIE
| UTCR3_TIE
));
522 while (UART_GET_UTSR1(sport
) & UTSR1_TBY
)
525 /* then, disable everything */
526 UART_PUT_UTCR3(sport
, 0);
528 /* set the parity, stop bits and data size */
529 UART_PUT_UTCR0(sport
, utcr0
);
531 /* set the baud rate */
533 UART_PUT_UTCR1(sport
, ((quot
& 0xf00) >> 8));
534 UART_PUT_UTCR2(sport
, (quot
& 0xff));
536 UART_PUT_UTSR0(sport
, -1);
538 UART_PUT_UTCR3(sport
, old_utcr3
);
540 if (UART_ENABLE_MS(&sport
->port
, termios
->c_cflag
))
541 sa1100_enable_ms(&sport
->port
);
543 spin_unlock_irqrestore(&sport
->port
.lock
, flags
);
546 static const char *sa1100_type(struct uart_port
*port
)
548 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
550 return sport
->port
.type
== PORT_SA1100
? "SA1100" : NULL
;
554 * Release the memory region(s) being used by 'port'.
556 static void sa1100_release_port(struct uart_port
*port
)
558 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
560 release_mem_region(sport
->port
.mapbase
, UART_PORT_SIZE
);
564 * Request the memory region(s) being used by 'port'.
566 static int sa1100_request_port(struct uart_port
*port
)
568 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
570 return request_mem_region(sport
->port
.mapbase
, UART_PORT_SIZE
,
571 "sa11x0-uart") != NULL
? 0 : -EBUSY
;
575 * Configure/autoconfigure the port.
577 static void sa1100_config_port(struct uart_port
*port
, int flags
)
579 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
581 if (flags
& UART_CONFIG_TYPE
&&
582 sa1100_request_port(&sport
->port
) == 0)
583 sport
->port
.type
= PORT_SA1100
;
587 * Verify the new serial_struct (for TIOCSSERIAL).
588 * The only change we allow are to the flags and type, and
589 * even then only between PORT_SA1100 and PORT_UNKNOWN
592 sa1100_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
594 struct sa1100_port
*sport
= (struct sa1100_port
*)port
;
597 if (ser
->type
!= PORT_UNKNOWN
&& ser
->type
!= PORT_SA1100
)
599 if (sport
->port
.irq
!= ser
->irq
)
601 if (ser
->io_type
!= SERIAL_IO_MEM
)
603 if (sport
->port
.uartclk
/ 16 != ser
->baud_base
)
605 if ((void *)sport
->port
.mapbase
!= ser
->iomem_base
)
607 if (sport
->port
.iobase
!= ser
->port
)
614 static struct uart_ops sa1100_pops
= {
615 .tx_empty
= sa1100_tx_empty
,
616 .set_mctrl
= sa1100_set_mctrl
,
617 .get_mctrl
= sa1100_get_mctrl
,
618 .stop_tx
= sa1100_stop_tx
,
619 .start_tx
= sa1100_start_tx
,
620 .stop_rx
= sa1100_stop_rx
,
621 .enable_ms
= sa1100_enable_ms
,
622 .break_ctl
= sa1100_break_ctl
,
623 .startup
= sa1100_startup
,
624 .shutdown
= sa1100_shutdown
,
625 .set_termios
= sa1100_set_termios
,
627 .release_port
= sa1100_release_port
,
628 .request_port
= sa1100_request_port
,
629 .config_port
= sa1100_config_port
,
630 .verify_port
= sa1100_verify_port
,
633 static struct sa1100_port sa1100_ports
[NR_PORTS
];
636 * Setup the SA1100 serial ports. Note that we don't include the IrDA
637 * port here since we have our own SIR/FIR driver (see drivers/net/irda)
639 * Note also that we support "console=ttySAx" where "x" is either 0 or 1.
640 * Which serial port this ends up being depends on the machine you're
641 * running this kernel on. I'm not convinced that this is a good idea,
642 * but that's the way it traditionally works.
644 * Note that NanoEngine UART3 becomes UART2, and UART2 is no longer
647 static void __init
sa1100_init_ports(void)
649 static int first
= 1;
656 for (i
= 0; i
< NR_PORTS
; i
++) {
657 sa1100_ports
[i
].port
.uartclk
= 3686400;
658 sa1100_ports
[i
].port
.ops
= &sa1100_pops
;
659 sa1100_ports
[i
].port
.fifosize
= 8;
660 sa1100_ports
[i
].port
.line
= i
;
661 sa1100_ports
[i
].port
.iotype
= SERIAL_IO_MEM
;
662 init_timer(&sa1100_ports
[i
].timer
);
663 sa1100_ports
[i
].timer
.function
= sa1100_timeout
;
664 sa1100_ports
[i
].timer
.data
= (unsigned long)&sa1100_ports
[i
];
668 * make transmit lines outputs, so that when the port
669 * is closed, the output is in the MARK state.
671 PPDR
|= PPC_TXD1
| PPC_TXD3
;
672 PPSR
|= PPC_TXD1
| PPC_TXD3
;
675 void __init
sa1100_register_uart_fns(struct sa1100_port_fns
*fns
)
678 sa1100_pops
.get_mctrl
= fns
->get_mctrl
;
680 sa1100_pops
.set_mctrl
= fns
->set_mctrl
;
682 sa1100_pops
.pm
= fns
->pm
;
683 sa1100_pops
.set_wake
= fns
->set_wake
;
686 void __init
sa1100_register_uart(int idx
, int port
)
688 if (idx
>= NR_PORTS
) {
689 printk(KERN_ERR
"%s: bad index number %d\n", __FUNCTION__
, idx
);
695 sa1100_ports
[idx
].port
.membase
= (void *)&Ser1UTCR0
;
696 sa1100_ports
[idx
].port
.mapbase
= _Ser1UTCR0
;
697 sa1100_ports
[idx
].port
.irq
= IRQ_Ser1UART
;
698 sa1100_ports
[idx
].port
.flags
= ASYNC_BOOT_AUTOCONF
;
702 sa1100_ports
[idx
].port
.membase
= (void *)&Ser2UTCR0
;
703 sa1100_ports
[idx
].port
.mapbase
= _Ser2UTCR0
;
704 sa1100_ports
[idx
].port
.irq
= IRQ_Ser2ICP
;
705 sa1100_ports
[idx
].port
.flags
= ASYNC_BOOT_AUTOCONF
;
709 sa1100_ports
[idx
].port
.membase
= (void *)&Ser3UTCR0
;
710 sa1100_ports
[idx
].port
.mapbase
= _Ser3UTCR0
;
711 sa1100_ports
[idx
].port
.irq
= IRQ_Ser3UART
;
712 sa1100_ports
[idx
].port
.flags
= ASYNC_BOOT_AUTOCONF
;
716 printk(KERN_ERR
"%s: bad port number %d\n", __FUNCTION__
, port
);
721 #ifdef CONFIG_SERIAL_SA1100_CONSOLE
724 * Interrupts are disabled on entering
727 sa1100_console_write(struct console
*co
, const char *s
, unsigned int count
)
729 struct sa1100_port
*sport
= &sa1100_ports
[co
->index
];
730 unsigned int old_utcr3
, status
, i
;
733 * First, save UTCR3 and then disable interrupts
735 old_utcr3
= UART_GET_UTCR3(sport
);
736 UART_PUT_UTCR3(sport
, (old_utcr3
& ~(UTCR3_RIE
| UTCR3_TIE
)) |
740 * Now, do each character
742 for (i
= 0; i
< count
; i
++) {
744 status
= UART_GET_UTSR1(sport
);
745 } while (!(status
& UTSR1_TNF
));
746 UART_PUT_CHAR(sport
, s
[i
]);
749 status
= UART_GET_UTSR1(sport
);
750 } while (!(status
& UTSR1_TNF
));
751 UART_PUT_CHAR(sport
, '\r');
756 * Finally, wait for transmitter to become empty
760 status
= UART_GET_UTSR1(sport
);
761 } while (status
& UTSR1_TBY
);
762 UART_PUT_UTCR3(sport
, old_utcr3
);
766 * If the port was already initialised (eg, by a boot loader),
767 * try to determine the current setup.
770 sa1100_console_get_options(struct sa1100_port
*sport
, int *baud
,
771 int *parity
, int *bits
)
775 utcr3
= UART_GET_UTCR3(sport
) & (UTCR3_RXE
| UTCR3_TXE
);
776 if (utcr3
== (UTCR3_RXE
| UTCR3_TXE
)) {
777 /* ok, the port was enabled */
778 unsigned int utcr0
, quot
;
780 utcr0
= UART_GET_UTCR0(sport
);
783 if (utcr0
& UTCR0_PE
) {
784 if (utcr0
& UTCR0_OES
)
790 if (utcr0
& UTCR0_DSS
)
795 quot
= UART_GET_UTCR2(sport
) | UART_GET_UTCR1(sport
) << 8;
797 *baud
= sport
->port
.uartclk
/ (16 * (quot
+ 1));
802 sa1100_console_setup(struct console
*co
, char *options
)
804 struct sa1100_port
*sport
;
811 * Check whether an invalid uart number has been specified, and
812 * if so, search for the first available port that does have
815 if (co
->index
== -1 || co
->index
>= NR_PORTS
)
817 sport
= &sa1100_ports
[co
->index
];
820 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
822 sa1100_console_get_options(sport
, &baud
, &parity
, &bits
);
824 return uart_set_options(&sport
->port
, co
, baud
, parity
, bits
, flow
);
827 extern struct uart_driver sa1100_reg
;
828 static struct console sa1100_console
= {
830 .write
= sa1100_console_write
,
831 .device
= uart_console_device
,
832 .setup
= sa1100_console_setup
,
833 .flags
= CON_PRINTBUFFER
,
838 static int __init
sa1100_rs_console_init(void)
841 register_console(&sa1100_console
);
844 console_initcall(sa1100_rs_console_init
);
846 #define SA1100_CONSOLE &sa1100_console
848 #define SA1100_CONSOLE NULL
851 static struct uart_driver sa1100_reg
= {
852 .owner
= THIS_MODULE
,
853 .driver_name
= "ttySA",
855 .devfs_name
= "ttySA",
856 .major
= SERIAL_SA1100_MAJOR
,
857 .minor
= MINOR_START
,
859 .cons
= SA1100_CONSOLE
,
862 static int sa1100_serial_suspend(struct device
*_dev
, u32 state
, u32 level
)
864 struct sa1100_port
*sport
= dev_get_drvdata(_dev
);
866 if (sport
&& level
== SUSPEND_DISABLE
)
867 uart_suspend_port(&sa1100_reg
, &sport
->port
);
872 static int sa1100_serial_resume(struct device
*_dev
, u32 level
)
874 struct sa1100_port
*sport
= dev_get_drvdata(_dev
);
876 if (sport
&& level
== RESUME_ENABLE
)
877 uart_resume_port(&sa1100_reg
, &sport
->port
);
882 static int sa1100_serial_probe(struct device
*_dev
)
884 struct platform_device
*dev
= to_platform_device(_dev
);
885 struct resource
*res
= dev
->resource
;
888 for (i
= 0; i
< dev
->num_resources
; i
++, res
++)
889 if (res
->flags
& IORESOURCE_MEM
)
892 if (i
< dev
->num_resources
) {
893 for (i
= 0; i
< NR_PORTS
; i
++) {
894 if (sa1100_ports
[i
].port
.mapbase
!= res
->start
)
897 sa1100_ports
[i
].port
.dev
= _dev
;
898 uart_add_one_port(&sa1100_reg
, &sa1100_ports
[i
].port
);
899 dev_set_drvdata(_dev
, &sa1100_ports
[i
]);
907 static int sa1100_serial_remove(struct device
*_dev
)
909 struct sa1100_port
*sport
= dev_get_drvdata(_dev
);
911 dev_set_drvdata(_dev
, NULL
);
914 uart_remove_one_port(&sa1100_reg
, &sport
->port
);
919 static struct device_driver sa11x0_serial_driver
= {
920 .name
= "sa11x0-uart",
921 .bus
= &platform_bus_type
,
922 .probe
= sa1100_serial_probe
,
923 .remove
= sa1100_serial_remove
,
924 .suspend
= sa1100_serial_suspend
,
925 .resume
= sa1100_serial_resume
,
928 static int __init
sa1100_serial_init(void)
932 printk(KERN_INFO
"Serial: SA11x0 driver $Revision: 1.50 $\n");
936 ret
= uart_register_driver(&sa1100_reg
);
938 ret
= driver_register(&sa11x0_serial_driver
);
940 uart_unregister_driver(&sa1100_reg
);
945 static void __exit
sa1100_serial_exit(void)
947 driver_unregister(&sa11x0_serial_driver
);
948 uart_unregister_driver(&sa1100_reg
);
951 module_init(sa1100_serial_init
);
952 module_exit(sa1100_serial_exit
);
954 MODULE_AUTHOR("Deep Blue Solutions Ltd");
955 MODULE_DESCRIPTION("SA1100 generic serial port driver $Revision: 1.50 $");
956 MODULE_LICENSE("GPL");
957 MODULE_ALIAS_CHARDEV_MAJOR(SERIAL_SA1100_MAJOR
);