22 #if defined(CONFIG_SERIAL_SB1250_DUART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
26 #include <linux/compiler.h>
29 #include <linux/errno.h>
33 #include <linux/kernel.h>
34 #include <linux/module.h>
36 #include <linux/serial.h>
37 #include <linux/serial_core.h>
40 #include <linux/tty.h>
42 #include <linux/types.h>
53 #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
57 #define SBD_CHANREGS(line) A_BCM1480_DUART_CHANREG((line), 0)
58 #define SBD_CTRLREGS(line) A_BCM1480_DUART_CTRLREG((line), 0)
59 #define SBD_INT(line) (K_BCM1480_INT_UART_0 + (line))
61 #define DUART_CHANREG_SPACING BCM1480_DUART_CHANREG_SPACING
63 #define R_DUART_IMRREG(line) R_BCM1480_DUART_IMRREG(line)
64 #define R_DUART_INCHREG(line) R_BCM1480_DUART_INCHREG(line)
65 #define R_DUART_ISRREG(line) R_BCM1480_DUART_ISRREG(line)
67 #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X)
71 #define SBD_CHANREGS(line) A_DUART_CHANREG((line), 0)
72 #define SBD_CTRLREGS(line) A_DUART_CTRLREG(0)
73 #define SBD_INT(line) (K_INT_UART_0 + (line))
76 #error invalid SB1250 UART configuration
86 #define DUART_MAX_CHIP 2
87 #define DUART_MAX_SIDE 2
109 #define to_sport(uport) container_of(uport, struct sbd_port, port)
167 retval = __read_sbdchn(sport, reg);
169 __war_sbd1956(sport);
173 static unsigned char read_sbdshr(
struct sbd_port *sport,
int reg)
177 retval = __read_sbdshr(sport, reg);
179 __war_sbd1956(sport);
183 static void write_sbdchn(
struct sbd_port *sport,
int reg,
unsigned int value)
185 __write_sbdchn(sport, reg, value);
187 __war_sbd1956(sport);
190 static void write_sbdshr(
struct sbd_port *sport,
int reg,
unsigned int value)
192 __write_sbdshr(sport, reg, value);
194 __war_sbd1956(sport);
198 static int sbd_receive_ready(
struct sbd_port *sport)
203 static int sbd_receive_drain(
struct sbd_port *sport)
207 while (sbd_receive_ready(sport) && --loops)
221 while (!sbd_transmit_ready(sport) && --loops)
226 static int sbd_transmit_empty(
struct sbd_port *sport)
231 static int sbd_line_drain(
struct sbd_port *sport)
235 while (!sbd_transmit_empty(sport) && --loops)
241 static unsigned int sbd_tx_empty(
struct uart_port *uport)
248 static unsigned int sbd_get_mctrl(
struct uart_port *uport)
251 unsigned int mctrl,
status;
254 status >>= (uport->
line) % 2;
262 static void sbd_set_mctrl(
struct uart_port *uport,
unsigned int mctrl)
265 unsigned int clr = 0,
set = 0, mode2;
275 clr <<= (uport->
line) % 2;
276 set <<= (uport->
line) % 2;
290 static void sbd_stop_tx(
struct uart_port *uport)
298 static void sbd_start_tx(
struct uart_port *uport)
304 mask = read_sbdshr(sport, R_DUART_IMRREG((uport->
line) % 2));
306 write_sbdshr(sport, R_DUART_IMRREG((uport->
line) % 2), mask);
313 static void sbd_stop_rx(
struct uart_port *uport)
317 write_sbdshr(sport, R_DUART_IMRREG((uport->
line) % 2), 0);
320 static void sbd_enable_ms(
struct uart_port *uport)
324 write_sbdchn(sport, R_DUART_AUXCTL_X,
328 static void sbd_break_ctl(
struct uart_port *uport,
int break_state)
332 if (break_state == -1)
339 static void sbd_receive_chars(
struct sbd_port *sport)
346 for (count = 16;
count; count--) {
363 if (uart_handle_break(uport))
373 if (status & M_DUART_RCVD_BRK)
375 else if (status & M_DUART_FRM_ERR)
377 else if (status & M_DUART_PARITY_ERR)
390 static void sbd_transmit_chars(
struct sbd_port *sport)
398 if (sport->
port.x_char) {
400 sport->
port.icount.tx++;
401 sport->
port.x_char = 0;
412 sport->
port.icount.tx++;
421 mask = read_sbdshr(sport, R_DUART_IMRREG((uport->
line) % 2));
423 write_sbdshr(sport, R_DUART_IMRREG((uport->
line) % 2), mask);
427 static void sbd_status_handle(
struct sbd_port *sport)
432 delta = read_sbdshr(sport, R_DUART_INCHREG((uport->
line) % 2));
433 delta >>= (uport->
line) % 2;
451 unsigned int intstat;
454 for (count = 16;
count; count--) {
455 intstat = read_sbdshr(sport,
456 R_DUART_ISRREG((uport->
line) % 2));
457 intstat &= read_sbdshr(sport,
458 R_DUART_IMRREG((uport->
line) % 2));
464 sbd_receive_chars(sport);
466 sbd_status_handle(sport);
468 sbd_transmit_chars(sport);
477 static int sbd_startup(
struct uart_port *uport)
489 sbd_receive_drain(sport);
493 read_sbdshr(sport, R_DUART_INCHREG((uport->
line) % 2));
505 write_sbdshr(sport, R_DUART_IMRREG((uport->
line) % 2),
511 static void sbd_shutdown(
struct uart_port *uport)
521 static void sbd_init_port(
struct sbd_port *sport)
533 write_sbdchn(sport, R_DUART_FULL_CTL,
534 V_DUART_INT_TIME(0) | V_DUART_SIG_FULL(15));
535 write_sbdchn(sport, R_DUART_OPCR_X, 0);
536 write_sbdchn(sport, R_DUART_AUXCTL_X, 0);
537 write_sbdshr(sport, R_DUART_IMRREG((uport->
line) % 2), 0);
546 unsigned int mode1 = 0, mode2 = 0,
aux = 0;
547 unsigned int mode1mask = 0, mode2mask = 0, auxmask = 0;
548 unsigned int oldmode1, oldmode2, oldaux;
549 unsigned int baud, brg;
622 spin_lock(&uport->
lock);
631 oldaux = read_sbdchn(sport, R_DUART_AUXCTL_X) & auxmask;
634 sbd_line_drain(sport);
640 write_sbdchn(sport, R_DUART_AUXCTL_X,
aux | oldaux);
644 spin_unlock(&uport->
lock);
648 static const char *sbd_type(
struct uart_port *uport)
650 return "SB1250 DUART";
653 static void sbd_release_port(
struct uart_port *uport)
670 static int sbd_map_port(
struct uart_port *uport)
672 const char *
err =
KERN_ERR "sbd: Cannot map MMIO\n";
678 DUART_CHANREG_SPACING);
686 DUART_CHANREG_SPACING);
697 static int sbd_request_port(
struct uart_port *uport)
699 const char *err =
KERN_ERR "sbd: Unable to reserve MMIO resource\n";
710 if (map_guard == 1) {
719 ret = sbd_map_port(uport);
724 DUART_CHANREG_SPACING);
739 if (sbd_request_port(uport))
744 sbd_init_port(sport);
754 if (ser->
irq != uport->
irq)
762 static const struct uart_ops sbd_ops = {
763 .tx_empty = sbd_tx_empty,
764 .set_mctrl = sbd_set_mctrl,
765 .get_mctrl = sbd_get_mctrl,
766 .stop_tx = sbd_stop_tx,
767 .start_tx = sbd_start_tx,
768 .stop_rx = sbd_stop_rx,
769 .enable_ms = sbd_enable_ms,
770 .break_ctl = sbd_break_ctl,
771 .startup = sbd_startup,
772 .shutdown = sbd_shutdown,
773 .set_termios = sbd_set_termios,
775 .release_port = sbd_release_port,
776 .request_port = sbd_request_port,
777 .config_port = sbd_config_port,
778 .verify_port = sbd_verify_port,
782 static void __init sbd_probe_duarts(
void)
805 for (chip = 0, line = 0; chip <
DUART_MAX_CHIP && line < max_lines;
807 sbd_duarts[
chip].mapctrl = SBD_CTRLREGS(line);
816 uport->
irq = SBD_INT(line);
817 uport->
uartclk = 100000000 / 20 * 16;
821 uport->
ops = &sbd_ops;
823 uport->
mapbase = SBD_CHANREGS(line);
829 #ifdef CONFIG_SERIAL_SB1250_DUART_CONSOLE
835 static void sbd_console_putchar(
struct uart_port *uport,
int ch)
839 sbd_transmit_drain(sport);
843 static void sbd_console_write(
struct console *co,
const char *
s,
855 mask = read_sbdshr(sport, R_DUART_IMRREG((uport->
line) % 2));
856 write_sbdshr(sport, R_DUART_IMRREG((uport->
line) % 2),
859 spin_unlock_irqrestore(&uport->
lock, flags);
865 sbd_line_drain(sport);
868 write_sbdshr(sport, R_DUART_IMRREG((uport->
line) % 2), mask);
869 spin_unlock_irqrestore(&uport->
lock, flags);
887 ret = sbd_map_port(uport);
891 sbd_init_port(sport);
899 static struct console sbd_console = {
901 .write = sbd_console_write,
903 .setup = sbd_console_setup,
909 static int __init sbd_serial_console_init(
void)
919 #define SERIAL_SB1250_DUART_CONSOLE &sbd_console
921 #define SERIAL_SB1250_DUART_CONSOLE NULL
927 .driver_name =
"sb1250_duart",
936 static int __init sbd_init(
void)
959 static void __exit sbd_exit(
void)