1e3b3d0f5SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 2ab4382d2SGreg Kroah-Hartman /* 3ab4382d2SGreg Kroah-Hartman * su.c: Small serial driver for keyboard/mouse interface on sparc32/PCI 4ab4382d2SGreg Kroah-Hartman * 5ab4382d2SGreg Kroah-Hartman * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be) 6ab4382d2SGreg Kroah-Hartman * Copyright (C) 1998-1999 Pete Zaitcev (zaitcev@yahoo.com) 7ab4382d2SGreg Kroah-Hartman * 8ab4382d2SGreg Kroah-Hartman * This is mainly a variation of 8250.c, credits go to authors mentioned 9ab4382d2SGreg Kroah-Hartman * therein. In fact this driver should be merged into the generic 8250.c 10ab4382d2SGreg Kroah-Hartman * infrastructure perhaps using a 8250_sparc.c module. 11ab4382d2SGreg Kroah-Hartman * 12ab4382d2SGreg Kroah-Hartman * Fixed to use tty_get_baud_rate(). 13ab4382d2SGreg Kroah-Hartman * Theodore Ts'o <tytso@mit.edu>, 2001-Oct-12 14ab4382d2SGreg Kroah-Hartman * 15ab4382d2SGreg Kroah-Hartman * Converted to new 2.5.x UART layer. 16ab4382d2SGreg Kroah-Hartman * David S. Miller (davem@davemloft.net), 2002-Jul-29 17ab4382d2SGreg Kroah-Hartman */ 18ab4382d2SGreg Kroah-Hartman 19ab4382d2SGreg Kroah-Hartman #include <linux/module.h> 20ab4382d2SGreg Kroah-Hartman #include <linux/kernel.h> 21ab4382d2SGreg Kroah-Hartman #include <linux/spinlock.h> 22ab4382d2SGreg Kroah-Hartman #include <linux/errno.h> 23ab4382d2SGreg Kroah-Hartman #include <linux/tty.h> 24ab4382d2SGreg Kroah-Hartman #include <linux/tty_flip.h> 25ab4382d2SGreg Kroah-Hartman #include <linux/major.h> 26ab4382d2SGreg Kroah-Hartman #include <linux/string.h> 27ab4382d2SGreg Kroah-Hartman #include <linux/ptrace.h> 28ab4382d2SGreg Kroah-Hartman #include <linux/ioport.h> 29ab4382d2SGreg Kroah-Hartman #include <linux/circ_buf.h> 30ab4382d2SGreg Kroah-Hartman #include <linux/serial.h> 31ab4382d2SGreg Kroah-Hartman #include <linux/sysrq.h> 32ab4382d2SGreg Kroah-Hartman #include <linux/console.h> 33ab4382d2SGreg Kroah-Hartman #include <linux/slab.h> 34ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO 35ab4382d2SGreg Kroah-Hartman #include <linux/serio.h> 36ab4382d2SGreg Kroah-Hartman #endif 37ab4382d2SGreg Kroah-Hartman #include <linux/serial_reg.h> 38ab4382d2SGreg Kroah-Hartman #include <linux/init.h> 39ab4382d2SGreg Kroah-Hartman #include <linux/delay.h> 40ab4382d2SGreg Kroah-Hartman #include <linux/of_device.h> 41ab4382d2SGreg Kroah-Hartman 424f1c6581SZihao Tang #include <linux/io.h> 43ab4382d2SGreg Kroah-Hartman #include <asm/irq.h> 44ab4382d2SGreg Kroah-Hartman #include <asm/prom.h> 45d550bbd4SDavid Howells #include <asm/setup.h> 46ab4382d2SGreg Kroah-Hartman 47ab4382d2SGreg Kroah-Hartman #include <linux/serial_core.h> 486816383aSPaul Gortmaker #include <linux/sunserialcore.h> 49ab4382d2SGreg Kroah-Hartman 50ab4382d2SGreg Kroah-Hartman /* We are on a NS PC87303 clocked with 24.0 MHz, which results 51ab4382d2SGreg Kroah-Hartman * in a UART clock of 1.8462 MHz. 52ab4382d2SGreg Kroah-Hartman */ 53ab4382d2SGreg Kroah-Hartman #define SU_BASE_BAUD (1846200 / 16) 54ab4382d2SGreg Kroah-Hartman 55ab4382d2SGreg Kroah-Hartman enum su_type { SU_PORT_NONE, SU_PORT_MS, SU_PORT_KBD, SU_PORT_PORT }; 56ab4382d2SGreg Kroah-Hartman static char *su_typev[] = { "su(???)", "su(mouse)", "su(kbd)", "su(serial)" }; 57ab4382d2SGreg Kroah-Hartman 584b71598bSPaul Gortmaker struct serial_uart_config { 594b71598bSPaul Gortmaker char *name; 604b71598bSPaul Gortmaker int dfl_xmit_fifo_size; 614b71598bSPaul Gortmaker int flags; 624b71598bSPaul Gortmaker }; 634b71598bSPaul Gortmaker 64ab4382d2SGreg Kroah-Hartman /* 65ab4382d2SGreg Kroah-Hartman * Here we define the default xmit fifo size used for each type of UART. 66ab4382d2SGreg Kroah-Hartman */ 67e2c65425SPaul Gortmaker static const struct serial_uart_config uart_config[] = { 68ab4382d2SGreg Kroah-Hartman { "unknown", 1, 0 }, 69ab4382d2SGreg Kroah-Hartman { "8250", 1, 0 }, 70ab4382d2SGreg Kroah-Hartman { "16450", 1, 0 }, 71ab4382d2SGreg Kroah-Hartman { "16550", 1, 0 }, 72ab4382d2SGreg Kroah-Hartman { "16550A", 16, UART_CLEAR_FIFO | UART_USE_FIFO }, 73ab4382d2SGreg Kroah-Hartman { "Cirrus", 1, 0 }, 74ab4382d2SGreg Kroah-Hartman { "ST16650", 1, UART_CLEAR_FIFO | UART_STARTECH }, 75ab4382d2SGreg Kroah-Hartman { "ST16650V2", 32, UART_CLEAR_FIFO | UART_USE_FIFO | UART_STARTECH }, 76ab4382d2SGreg Kroah-Hartman { "TI16750", 64, UART_CLEAR_FIFO | UART_USE_FIFO }, 77ab4382d2SGreg Kroah-Hartman { "Startech", 1, 0 }, 78ab4382d2SGreg Kroah-Hartman { "16C950/954", 128, UART_CLEAR_FIFO | UART_USE_FIFO }, 79ab4382d2SGreg Kroah-Hartman { "ST16654", 64, UART_CLEAR_FIFO | UART_USE_FIFO | UART_STARTECH }, 80ab4382d2SGreg Kroah-Hartman { "XR16850", 128, UART_CLEAR_FIFO | UART_USE_FIFO | UART_STARTECH }, 81ab4382d2SGreg Kroah-Hartman { "RSA", 2048, UART_CLEAR_FIFO | UART_USE_FIFO } 82ab4382d2SGreg Kroah-Hartman }; 83ab4382d2SGreg Kroah-Hartman 84ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port { 85ab4382d2SGreg Kroah-Hartman struct uart_port port; 86ab4382d2SGreg Kroah-Hartman unsigned char acr; 87ab4382d2SGreg Kroah-Hartman unsigned char ier; 88ab4382d2SGreg Kroah-Hartman unsigned short rev; 89ab4382d2SGreg Kroah-Hartman unsigned char lcr; 90ab4382d2SGreg Kroah-Hartman unsigned int lsr_break_flag; 91ab4382d2SGreg Kroah-Hartman unsigned int cflag; 92ab4382d2SGreg Kroah-Hartman 93ab4382d2SGreg Kroah-Hartman /* Probing information. */ 94ab4382d2SGreg Kroah-Hartman enum su_type su_type; 95ab4382d2SGreg Kroah-Hartman unsigned int type_probed; /* XXX Stupid */ 96ab4382d2SGreg Kroah-Hartman unsigned long reg_size; 97ab4382d2SGreg Kroah-Hartman 98ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO 99ab4382d2SGreg Kroah-Hartman struct serio serio; 100ab4382d2SGreg Kroah-Hartman int serio_open; 101ab4382d2SGreg Kroah-Hartman #endif 102ab4382d2SGreg Kroah-Hartman }; 103ab4382d2SGreg Kroah-Hartman 104ab4382d2SGreg Kroah-Hartman static unsigned int serial_in(struct uart_sunsu_port *up, int offset) 105ab4382d2SGreg Kroah-Hartman { 106ab4382d2SGreg Kroah-Hartman offset <<= up->port.regshift; 107ab4382d2SGreg Kroah-Hartman 108ab4382d2SGreg Kroah-Hartman switch (up->port.iotype) { 109ab4382d2SGreg Kroah-Hartman case UPIO_HUB6: 110ab4382d2SGreg Kroah-Hartman outb(up->port.hub6 - 1 + offset, up->port.iobase); 111ab4382d2SGreg Kroah-Hartman return inb(up->port.iobase + 1); 112ab4382d2SGreg Kroah-Hartman 113ab4382d2SGreg Kroah-Hartman case UPIO_MEM: 114ab4382d2SGreg Kroah-Hartman return readb(up->port.membase + offset); 115ab4382d2SGreg Kroah-Hartman 116ab4382d2SGreg Kroah-Hartman default: 117ab4382d2SGreg Kroah-Hartman return inb(up->port.iobase + offset); 118ab4382d2SGreg Kroah-Hartman } 119ab4382d2SGreg Kroah-Hartman } 120ab4382d2SGreg Kroah-Hartman 121ab4382d2SGreg Kroah-Hartman static void serial_out(struct uart_sunsu_port *up, int offset, int value) 122ab4382d2SGreg Kroah-Hartman { 123ab4382d2SGreg Kroah-Hartman #ifndef CONFIG_SPARC64 124ab4382d2SGreg Kroah-Hartman /* 125ab4382d2SGreg Kroah-Hartman * MrCoffee has weird schematics: IRQ4 & P10(?) pins of SuperIO are 126ab4382d2SGreg Kroah-Hartman * connected with a gate then go to SlavIO. When IRQ4 goes tristated 127ab4382d2SGreg Kroah-Hartman * gate outputs a logical one. Since we use level triggered interrupts 128ab4382d2SGreg Kroah-Hartman * we have lockup and watchdog reset. We cannot mask IRQ because 129ab4382d2SGreg Kroah-Hartman * keyboard shares IRQ with us (Word has it as Bob Smelik's design). 130b4a29b94SLukas Wunner * This problem is similar to what Alpha people suffer, see 131b4a29b94SLukas Wunner * 8250_alpha.c. 132ab4382d2SGreg Kroah-Hartman */ 133ab4382d2SGreg Kroah-Hartman if (offset == UART_MCR) 134ab4382d2SGreg Kroah-Hartman value |= UART_MCR_OUT2; 135ab4382d2SGreg Kroah-Hartman #endif 136ab4382d2SGreg Kroah-Hartman offset <<= up->port.regshift; 137ab4382d2SGreg Kroah-Hartman 138ab4382d2SGreg Kroah-Hartman switch (up->port.iotype) { 139ab4382d2SGreg Kroah-Hartman case UPIO_HUB6: 140ab4382d2SGreg Kroah-Hartman outb(up->port.hub6 - 1 + offset, up->port.iobase); 141ab4382d2SGreg Kroah-Hartman outb(value, up->port.iobase + 1); 142ab4382d2SGreg Kroah-Hartman break; 143ab4382d2SGreg Kroah-Hartman 144ab4382d2SGreg Kroah-Hartman case UPIO_MEM: 145ab4382d2SGreg Kroah-Hartman writeb(value, up->port.membase + offset); 146ab4382d2SGreg Kroah-Hartman break; 147ab4382d2SGreg Kroah-Hartman 148ab4382d2SGreg Kroah-Hartman default: 149ab4382d2SGreg Kroah-Hartman outb(value, up->port.iobase + offset); 150ab4382d2SGreg Kroah-Hartman } 151ab4382d2SGreg Kroah-Hartman } 152ab4382d2SGreg Kroah-Hartman 153ab4382d2SGreg Kroah-Hartman /* 154ab4382d2SGreg Kroah-Hartman * We used to support using pause I/O for certain machines. We 155ab4382d2SGreg Kroah-Hartman * haven't supported this for a while, but just in case it's badly 156ab4382d2SGreg Kroah-Hartman * needed for certain old 386 machines, I've left these #define's 157ab4382d2SGreg Kroah-Hartman * in.... 158ab4382d2SGreg Kroah-Hartman */ 159ab4382d2SGreg Kroah-Hartman #define serial_inp(up, offset) serial_in(up, offset) 160ab4382d2SGreg Kroah-Hartman #define serial_outp(up, offset, value) serial_out(up, offset, value) 161ab4382d2SGreg Kroah-Hartman 162ab4382d2SGreg Kroah-Hartman 163ab4382d2SGreg Kroah-Hartman /* 164ab4382d2SGreg Kroah-Hartman * For the 16C950 165ab4382d2SGreg Kroah-Hartman */ 166ab4382d2SGreg Kroah-Hartman static void serial_icr_write(struct uart_sunsu_port *up, int offset, int value) 167ab4382d2SGreg Kroah-Hartman { 168ab4382d2SGreg Kroah-Hartman serial_out(up, UART_SCR, offset); 169ab4382d2SGreg Kroah-Hartman serial_out(up, UART_ICR, value); 170ab4382d2SGreg Kroah-Hartman } 171ab4382d2SGreg Kroah-Hartman 172ab4382d2SGreg Kroah-Hartman #if 0 /* Unused currently */ 173ab4382d2SGreg Kroah-Hartman static unsigned int serial_icr_read(struct uart_sunsu_port *up, int offset) 174ab4382d2SGreg Kroah-Hartman { 175ab4382d2SGreg Kroah-Hartman unsigned int value; 176ab4382d2SGreg Kroah-Hartman 177ab4382d2SGreg Kroah-Hartman serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD); 178ab4382d2SGreg Kroah-Hartman serial_out(up, UART_SCR, offset); 179ab4382d2SGreg Kroah-Hartman value = serial_in(up, UART_ICR); 180ab4382d2SGreg Kroah-Hartman serial_icr_write(up, UART_ACR, up->acr); 181ab4382d2SGreg Kroah-Hartman 182ab4382d2SGreg Kroah-Hartman return value; 183ab4382d2SGreg Kroah-Hartman } 184ab4382d2SGreg Kroah-Hartman #endif 185ab4382d2SGreg Kroah-Hartman 186ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIAL_8250_RSA 187ab4382d2SGreg Kroah-Hartman /* 188ab4382d2SGreg Kroah-Hartman * Attempts to turn on the RSA FIFO. Returns zero on failure. 189ab4382d2SGreg Kroah-Hartman * We set the port uart clock rate if we succeed. 190ab4382d2SGreg Kroah-Hartman */ 191ab4382d2SGreg Kroah-Hartman static int __enable_rsa(struct uart_sunsu_port *up) 192ab4382d2SGreg Kroah-Hartman { 193ab4382d2SGreg Kroah-Hartman unsigned char mode; 194ab4382d2SGreg Kroah-Hartman int result; 195ab4382d2SGreg Kroah-Hartman 196ab4382d2SGreg Kroah-Hartman mode = serial_inp(up, UART_RSA_MSR); 197ab4382d2SGreg Kroah-Hartman result = mode & UART_RSA_MSR_FIFO; 198ab4382d2SGreg Kroah-Hartman 199ab4382d2SGreg Kroah-Hartman if (!result) { 200ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO); 201ab4382d2SGreg Kroah-Hartman mode = serial_inp(up, UART_RSA_MSR); 202ab4382d2SGreg Kroah-Hartman result = mode & UART_RSA_MSR_FIFO; 203ab4382d2SGreg Kroah-Hartman } 204ab4382d2SGreg Kroah-Hartman 205ab4382d2SGreg Kroah-Hartman if (result) 206ab4382d2SGreg Kroah-Hartman up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16; 207ab4382d2SGreg Kroah-Hartman 208ab4382d2SGreg Kroah-Hartman return result; 209ab4382d2SGreg Kroah-Hartman } 210ab4382d2SGreg Kroah-Hartman 211ab4382d2SGreg Kroah-Hartman static void enable_rsa(struct uart_sunsu_port *up) 212ab4382d2SGreg Kroah-Hartman { 213ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_RSA) { 214ab4382d2SGreg Kroah-Hartman if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) { 215ab4382d2SGreg Kroah-Hartman spin_lock_irq(&up->port.lock); 216ab4382d2SGreg Kroah-Hartman __enable_rsa(up); 217ab4382d2SGreg Kroah-Hartman spin_unlock_irq(&up->port.lock); 218ab4382d2SGreg Kroah-Hartman } 219ab4382d2SGreg Kroah-Hartman if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) 220ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_RSA_FRR, 0); 221ab4382d2SGreg Kroah-Hartman } 222ab4382d2SGreg Kroah-Hartman } 223ab4382d2SGreg Kroah-Hartman 224ab4382d2SGreg Kroah-Hartman /* 225ab4382d2SGreg Kroah-Hartman * Attempts to turn off the RSA FIFO. Returns zero on failure. 226ab4382d2SGreg Kroah-Hartman * It is unknown why interrupts were disabled in here. However, 227ab4382d2SGreg Kroah-Hartman * the caller is expected to preserve this behaviour by grabbing 228ab4382d2SGreg Kroah-Hartman * the spinlock before calling this function. 229ab4382d2SGreg Kroah-Hartman */ 230ab4382d2SGreg Kroah-Hartman static void disable_rsa(struct uart_sunsu_port *up) 231ab4382d2SGreg Kroah-Hartman { 232ab4382d2SGreg Kroah-Hartman unsigned char mode; 233ab4382d2SGreg Kroah-Hartman int result; 234ab4382d2SGreg Kroah-Hartman 235ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_RSA && 236ab4382d2SGreg Kroah-Hartman up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) { 237ab4382d2SGreg Kroah-Hartman spin_lock_irq(&up->port.lock); 238ab4382d2SGreg Kroah-Hartman 239ab4382d2SGreg Kroah-Hartman mode = serial_inp(up, UART_RSA_MSR); 240ab4382d2SGreg Kroah-Hartman result = !(mode & UART_RSA_MSR_FIFO); 241ab4382d2SGreg Kroah-Hartman 242ab4382d2SGreg Kroah-Hartman if (!result) { 243ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO); 244ab4382d2SGreg Kroah-Hartman mode = serial_inp(up, UART_RSA_MSR); 245ab4382d2SGreg Kroah-Hartman result = !(mode & UART_RSA_MSR_FIFO); 246ab4382d2SGreg Kroah-Hartman } 247ab4382d2SGreg Kroah-Hartman 248ab4382d2SGreg Kroah-Hartman if (result) 249ab4382d2SGreg Kroah-Hartman up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16; 250ab4382d2SGreg Kroah-Hartman spin_unlock_irq(&up->port.lock); 251ab4382d2SGreg Kroah-Hartman } 252ab4382d2SGreg Kroah-Hartman } 253ab4382d2SGreg Kroah-Hartman #endif /* CONFIG_SERIAL_8250_RSA */ 254ab4382d2SGreg Kroah-Hartman 255ab4382d2SGreg Kroah-Hartman static inline void __stop_tx(struct uart_sunsu_port *p) 256ab4382d2SGreg Kroah-Hartman { 257ab4382d2SGreg Kroah-Hartman if (p->ier & UART_IER_THRI) { 258ab4382d2SGreg Kroah-Hartman p->ier &= ~UART_IER_THRI; 259ab4382d2SGreg Kroah-Hartman serial_out(p, UART_IER, p->ier); 260ab4382d2SGreg Kroah-Hartman } 261ab4382d2SGreg Kroah-Hartman } 262ab4382d2SGreg Kroah-Hartman 263ab4382d2SGreg Kroah-Hartman static void sunsu_stop_tx(struct uart_port *port) 264ab4382d2SGreg Kroah-Hartman { 2659a6962c5SFabian Frederick struct uart_sunsu_port *up = 2669a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 267ab4382d2SGreg Kroah-Hartman 268ab4382d2SGreg Kroah-Hartman __stop_tx(up); 269ab4382d2SGreg Kroah-Hartman 270ab4382d2SGreg Kroah-Hartman /* 271ab4382d2SGreg Kroah-Hartman * We really want to stop the transmitter from sending. 272ab4382d2SGreg Kroah-Hartman */ 273ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16C950) { 274ab4382d2SGreg Kroah-Hartman up->acr |= UART_ACR_TXDIS; 275ab4382d2SGreg Kroah-Hartman serial_icr_write(up, UART_ACR, up->acr); 276ab4382d2SGreg Kroah-Hartman } 277ab4382d2SGreg Kroah-Hartman } 278ab4382d2SGreg Kroah-Hartman 279ab4382d2SGreg Kroah-Hartman static void sunsu_start_tx(struct uart_port *port) 280ab4382d2SGreg Kroah-Hartman { 2819a6962c5SFabian Frederick struct uart_sunsu_port *up = 2829a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 283ab4382d2SGreg Kroah-Hartman 284ab4382d2SGreg Kroah-Hartman if (!(up->ier & UART_IER_THRI)) { 285ab4382d2SGreg Kroah-Hartman up->ier |= UART_IER_THRI; 286ab4382d2SGreg Kroah-Hartman serial_out(up, UART_IER, up->ier); 287ab4382d2SGreg Kroah-Hartman } 288ab4382d2SGreg Kroah-Hartman 289ab4382d2SGreg Kroah-Hartman /* 290ab4382d2SGreg Kroah-Hartman * Re-enable the transmitter if we disabled it. 291ab4382d2SGreg Kroah-Hartman */ 292ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) { 293ab4382d2SGreg Kroah-Hartman up->acr &= ~UART_ACR_TXDIS; 294ab4382d2SGreg Kroah-Hartman serial_icr_write(up, UART_ACR, up->acr); 295ab4382d2SGreg Kroah-Hartman } 296ab4382d2SGreg Kroah-Hartman } 297ab4382d2SGreg Kroah-Hartman 298ab4382d2SGreg Kroah-Hartman static void sunsu_stop_rx(struct uart_port *port) 299ab4382d2SGreg Kroah-Hartman { 3009a6962c5SFabian Frederick struct uart_sunsu_port *up = 3019a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 302ab4382d2SGreg Kroah-Hartman 303ab4382d2SGreg Kroah-Hartman up->ier &= ~UART_IER_RLSI; 304ab4382d2SGreg Kroah-Hartman up->port.read_status_mask &= ~UART_LSR_DR; 305ab4382d2SGreg Kroah-Hartman serial_out(up, UART_IER, up->ier); 306ab4382d2SGreg Kroah-Hartman } 307ab4382d2SGreg Kroah-Hartman 308ab4382d2SGreg Kroah-Hartman static void sunsu_enable_ms(struct uart_port *port) 309ab4382d2SGreg Kroah-Hartman { 3109a6962c5SFabian Frederick struct uart_sunsu_port *up = 3119a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 312ab4382d2SGreg Kroah-Hartman unsigned long flags; 313ab4382d2SGreg Kroah-Hartman 314ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags); 315ab4382d2SGreg Kroah-Hartman up->ier |= UART_IER_MSI; 316ab4382d2SGreg Kroah-Hartman serial_out(up, UART_IER, up->ier); 317ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags); 318ab4382d2SGreg Kroah-Hartman } 319ab4382d2SGreg Kroah-Hartman 3202e124b4aSJiri Slaby static void 321ab4382d2SGreg Kroah-Hartman receive_chars(struct uart_sunsu_port *up, unsigned char *status) 322ab4382d2SGreg Kroah-Hartman { 32392a19f9cSJiri Slaby struct tty_port *port = &up->port.state->port; 324ab4382d2SGreg Kroah-Hartman unsigned char ch, flag; 325ab4382d2SGreg Kroah-Hartman int max_count = 256; 326ab4382d2SGreg Kroah-Hartman int saw_console_brk = 0; 327ab4382d2SGreg Kroah-Hartman 328ab4382d2SGreg Kroah-Hartman do { 329ab4382d2SGreg Kroah-Hartman ch = serial_inp(up, UART_RX); 330ab4382d2SGreg Kroah-Hartman flag = TTY_NORMAL; 331ab4382d2SGreg Kroah-Hartman up->port.icount.rx++; 332ab4382d2SGreg Kroah-Hartman 333ab4382d2SGreg Kroah-Hartman if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE | 334ab4382d2SGreg Kroah-Hartman UART_LSR_FE | UART_LSR_OE))) { 335ab4382d2SGreg Kroah-Hartman /* 336ab4382d2SGreg Kroah-Hartman * For statistics only 337ab4382d2SGreg Kroah-Hartman */ 338ab4382d2SGreg Kroah-Hartman if (*status & UART_LSR_BI) { 339ab4382d2SGreg Kroah-Hartman *status &= ~(UART_LSR_FE | UART_LSR_PE); 340ab4382d2SGreg Kroah-Hartman up->port.icount.brk++; 341ab4382d2SGreg Kroah-Hartman if (up->port.cons != NULL && 342ab4382d2SGreg Kroah-Hartman up->port.line == up->port.cons->index) 343ab4382d2SGreg Kroah-Hartman saw_console_brk = 1; 344ab4382d2SGreg Kroah-Hartman /* 345ab4382d2SGreg Kroah-Hartman * We do the SysRQ and SAK checking 346ab4382d2SGreg Kroah-Hartman * here because otherwise the break 347ab4382d2SGreg Kroah-Hartman * may get masked by ignore_status_mask 348ab4382d2SGreg Kroah-Hartman * or read_status_mask. 349ab4382d2SGreg Kroah-Hartman */ 350ab4382d2SGreg Kroah-Hartman if (uart_handle_break(&up->port)) 351ab4382d2SGreg Kroah-Hartman goto ignore_char; 352ab4382d2SGreg Kroah-Hartman } else if (*status & UART_LSR_PE) 353ab4382d2SGreg Kroah-Hartman up->port.icount.parity++; 354ab4382d2SGreg Kroah-Hartman else if (*status & UART_LSR_FE) 355ab4382d2SGreg Kroah-Hartman up->port.icount.frame++; 356ab4382d2SGreg Kroah-Hartman if (*status & UART_LSR_OE) 357ab4382d2SGreg Kroah-Hartman up->port.icount.overrun++; 358ab4382d2SGreg Kroah-Hartman 359ab4382d2SGreg Kroah-Hartman /* 360ab4382d2SGreg Kroah-Hartman * Mask off conditions which should be ingored. 361ab4382d2SGreg Kroah-Hartman */ 362ab4382d2SGreg Kroah-Hartman *status &= up->port.read_status_mask; 363ab4382d2SGreg Kroah-Hartman 364ab4382d2SGreg Kroah-Hartman if (up->port.cons != NULL && 365ab4382d2SGreg Kroah-Hartman up->port.line == up->port.cons->index) { 366ab4382d2SGreg Kroah-Hartman /* Recover the break flag from console xmit */ 367ab4382d2SGreg Kroah-Hartman *status |= up->lsr_break_flag; 368ab4382d2SGreg Kroah-Hartman up->lsr_break_flag = 0; 369ab4382d2SGreg Kroah-Hartman } 370ab4382d2SGreg Kroah-Hartman 371ab4382d2SGreg Kroah-Hartman if (*status & UART_LSR_BI) { 372ab4382d2SGreg Kroah-Hartman flag = TTY_BREAK; 373ab4382d2SGreg Kroah-Hartman } else if (*status & UART_LSR_PE) 374ab4382d2SGreg Kroah-Hartman flag = TTY_PARITY; 375ab4382d2SGreg Kroah-Hartman else if (*status & UART_LSR_FE) 376ab4382d2SGreg Kroah-Hartman flag = TTY_FRAME; 377ab4382d2SGreg Kroah-Hartman } 378ab4382d2SGreg Kroah-Hartman if (uart_handle_sysrq_char(&up->port, ch)) 379ab4382d2SGreg Kroah-Hartman goto ignore_char; 380ab4382d2SGreg Kroah-Hartman if ((*status & up->port.ignore_status_mask) == 0) 38192a19f9cSJiri Slaby tty_insert_flip_char(port, ch, flag); 382ab4382d2SGreg Kroah-Hartman if (*status & UART_LSR_OE) 383ab4382d2SGreg Kroah-Hartman /* 384ab4382d2SGreg Kroah-Hartman * Overrun is special, since it's reported 385ab4382d2SGreg Kroah-Hartman * immediately, and doesn't affect the current 386ab4382d2SGreg Kroah-Hartman * character. 387ab4382d2SGreg Kroah-Hartman */ 38892a19f9cSJiri Slaby tty_insert_flip_char(port, 0, TTY_OVERRUN); 389ab4382d2SGreg Kroah-Hartman ignore_char: 390ab4382d2SGreg Kroah-Hartman *status = serial_inp(up, UART_LSR); 391ab4382d2SGreg Kroah-Hartman } while ((*status & UART_LSR_DR) && (max_count-- > 0)); 392ab4382d2SGreg Kroah-Hartman 393ab4382d2SGreg Kroah-Hartman if (saw_console_brk) 394ab4382d2SGreg Kroah-Hartman sun_do_break(); 395ab4382d2SGreg Kroah-Hartman } 396ab4382d2SGreg Kroah-Hartman 397ab4382d2SGreg Kroah-Hartman static void transmit_chars(struct uart_sunsu_port *up) 398ab4382d2SGreg Kroah-Hartman { 399ab4382d2SGreg Kroah-Hartman struct circ_buf *xmit = &up->port.state->xmit; 400ab4382d2SGreg Kroah-Hartman int count; 401ab4382d2SGreg Kroah-Hartman 402ab4382d2SGreg Kroah-Hartman if (up->port.x_char) { 403ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_TX, up->port.x_char); 404ab4382d2SGreg Kroah-Hartman up->port.icount.tx++; 405ab4382d2SGreg Kroah-Hartman up->port.x_char = 0; 406ab4382d2SGreg Kroah-Hartman return; 407ab4382d2SGreg Kroah-Hartman } 408ab4382d2SGreg Kroah-Hartman if (uart_tx_stopped(&up->port)) { 409ab4382d2SGreg Kroah-Hartman sunsu_stop_tx(&up->port); 410ab4382d2SGreg Kroah-Hartman return; 411ab4382d2SGreg Kroah-Hartman } 412ab4382d2SGreg Kroah-Hartman if (uart_circ_empty(xmit)) { 413ab4382d2SGreg Kroah-Hartman __stop_tx(up); 414ab4382d2SGreg Kroah-Hartman return; 415ab4382d2SGreg Kroah-Hartman } 416ab4382d2SGreg Kroah-Hartman 417ab4382d2SGreg Kroah-Hartman count = up->port.fifosize; 418ab4382d2SGreg Kroah-Hartman do { 419ab4382d2SGreg Kroah-Hartman serial_out(up, UART_TX, xmit->buf[xmit->tail]); 420ab4382d2SGreg Kroah-Hartman xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); 421ab4382d2SGreg Kroah-Hartman up->port.icount.tx++; 422ab4382d2SGreg Kroah-Hartman if (uart_circ_empty(xmit)) 423ab4382d2SGreg Kroah-Hartman break; 424ab4382d2SGreg Kroah-Hartman } while (--count > 0); 425ab4382d2SGreg Kroah-Hartman 426ab4382d2SGreg Kroah-Hartman if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 427ab4382d2SGreg Kroah-Hartman uart_write_wakeup(&up->port); 428ab4382d2SGreg Kroah-Hartman 429ab4382d2SGreg Kroah-Hartman if (uart_circ_empty(xmit)) 430ab4382d2SGreg Kroah-Hartman __stop_tx(up); 431ab4382d2SGreg Kroah-Hartman } 432ab4382d2SGreg Kroah-Hartman 433ab4382d2SGreg Kroah-Hartman static void check_modem_status(struct uart_sunsu_port *up) 434ab4382d2SGreg Kroah-Hartman { 435ab4382d2SGreg Kroah-Hartman int status; 436ab4382d2SGreg Kroah-Hartman 437ab4382d2SGreg Kroah-Hartman status = serial_in(up, UART_MSR); 438ab4382d2SGreg Kroah-Hartman 439ab4382d2SGreg Kroah-Hartman if ((status & UART_MSR_ANY_DELTA) == 0) 440ab4382d2SGreg Kroah-Hartman return; 441ab4382d2SGreg Kroah-Hartman 442ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_TERI) 443ab4382d2SGreg Kroah-Hartman up->port.icount.rng++; 444ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_DDSR) 445ab4382d2SGreg Kroah-Hartman up->port.icount.dsr++; 446ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_DDCD) 447ab4382d2SGreg Kroah-Hartman uart_handle_dcd_change(&up->port, status & UART_MSR_DCD); 448ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_DCTS) 449ab4382d2SGreg Kroah-Hartman uart_handle_cts_change(&up->port, status & UART_MSR_CTS); 450ab4382d2SGreg Kroah-Hartman 451ab4382d2SGreg Kroah-Hartman wake_up_interruptible(&up->port.state->port.delta_msr_wait); 452ab4382d2SGreg Kroah-Hartman } 453ab4382d2SGreg Kroah-Hartman 454ab4382d2SGreg Kroah-Hartman static irqreturn_t sunsu_serial_interrupt(int irq, void *dev_id) 455ab4382d2SGreg Kroah-Hartman { 456ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up = dev_id; 457ab4382d2SGreg Kroah-Hartman unsigned long flags; 458ab4382d2SGreg Kroah-Hartman unsigned char status; 459ab4382d2SGreg Kroah-Hartman 460ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags); 461ab4382d2SGreg Kroah-Hartman 462ab4382d2SGreg Kroah-Hartman do { 463ab4382d2SGreg Kroah-Hartman status = serial_inp(up, UART_LSR); 464ab4382d2SGreg Kroah-Hartman if (status & UART_LSR_DR) 4652e124b4aSJiri Slaby receive_chars(up, &status); 466ab4382d2SGreg Kroah-Hartman check_modem_status(up); 467ab4382d2SGreg Kroah-Hartman if (status & UART_LSR_THRE) 468ab4382d2SGreg Kroah-Hartman transmit_chars(up); 469ab4382d2SGreg Kroah-Hartman 4702e124b4aSJiri Slaby tty_flip_buffer_push(&up->port.state->port); 471ab4382d2SGreg Kroah-Hartman 472ab4382d2SGreg Kroah-Hartman } while (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT)); 473ab4382d2SGreg Kroah-Hartman 474ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags); 475ab4382d2SGreg Kroah-Hartman 476ab4382d2SGreg Kroah-Hartman return IRQ_HANDLED; 477ab4382d2SGreg Kroah-Hartman } 478ab4382d2SGreg Kroah-Hartman 479ab4382d2SGreg Kroah-Hartman /* Separate interrupt handling path for keyboard/mouse ports. */ 480ab4382d2SGreg Kroah-Hartman 481ab4382d2SGreg Kroah-Hartman static void 482ab4382d2SGreg Kroah-Hartman sunsu_change_speed(struct uart_port *port, unsigned int cflag, 483ab4382d2SGreg Kroah-Hartman unsigned int iflag, unsigned int quot); 484ab4382d2SGreg Kroah-Hartman 485ab4382d2SGreg Kroah-Hartman static void sunsu_change_mouse_baud(struct uart_sunsu_port *up) 486ab4382d2SGreg Kroah-Hartman { 487ab4382d2SGreg Kroah-Hartman unsigned int cur_cflag = up->cflag; 488ab4382d2SGreg Kroah-Hartman int quot, new_baud; 489ab4382d2SGreg Kroah-Hartman 490ab4382d2SGreg Kroah-Hartman up->cflag &= ~CBAUD; 491ab4382d2SGreg Kroah-Hartman up->cflag |= suncore_mouse_baud_cflag_next(cur_cflag, &new_baud); 492ab4382d2SGreg Kroah-Hartman 493ab4382d2SGreg Kroah-Hartman quot = up->port.uartclk / (16 * new_baud); 494ab4382d2SGreg Kroah-Hartman 495ab4382d2SGreg Kroah-Hartman sunsu_change_speed(&up->port, up->cflag, 0, quot); 496ab4382d2SGreg Kroah-Hartman } 497ab4382d2SGreg Kroah-Hartman 498ab4382d2SGreg Kroah-Hartman static void receive_kbd_ms_chars(struct uart_sunsu_port *up, int is_break) 499ab4382d2SGreg Kroah-Hartman { 500ab4382d2SGreg Kroah-Hartman do { 501ab4382d2SGreg Kroah-Hartman unsigned char ch = serial_inp(up, UART_RX); 502ab4382d2SGreg Kroah-Hartman 503ab4382d2SGreg Kroah-Hartman /* Stop-A is handled by drivers/char/keyboard.c now. */ 504ab4382d2SGreg Kroah-Hartman if (up->su_type == SU_PORT_KBD) { 505ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO 506ab4382d2SGreg Kroah-Hartman serio_interrupt(&up->serio, ch, 0); 507ab4382d2SGreg Kroah-Hartman #endif 508ab4382d2SGreg Kroah-Hartman } else if (up->su_type == SU_PORT_MS) { 509ab4382d2SGreg Kroah-Hartman int ret = suncore_mouse_baud_detection(ch, is_break); 510ab4382d2SGreg Kroah-Hartman 511ab4382d2SGreg Kroah-Hartman switch (ret) { 512ab4382d2SGreg Kroah-Hartman case 2: 513ab4382d2SGreg Kroah-Hartman sunsu_change_mouse_baud(up); 514df561f66SGustavo A. R. Silva fallthrough; 515ab4382d2SGreg Kroah-Hartman case 1: 516ab4382d2SGreg Kroah-Hartman break; 517ab4382d2SGreg Kroah-Hartman 518ab4382d2SGreg Kroah-Hartman case 0: 519ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO 520ab4382d2SGreg Kroah-Hartman serio_interrupt(&up->serio, ch, 0); 521ab4382d2SGreg Kroah-Hartman #endif 522ab4382d2SGreg Kroah-Hartman break; 523fc811472SJoe Perches } 524ab4382d2SGreg Kroah-Hartman } 525ab4382d2SGreg Kroah-Hartman } while (serial_in(up, UART_LSR) & UART_LSR_DR); 526ab4382d2SGreg Kroah-Hartman } 527ab4382d2SGreg Kroah-Hartman 528ab4382d2SGreg Kroah-Hartman static irqreturn_t sunsu_kbd_ms_interrupt(int irq, void *dev_id) 529ab4382d2SGreg Kroah-Hartman { 530ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up = dev_id; 531ab4382d2SGreg Kroah-Hartman 532ab4382d2SGreg Kroah-Hartman if (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT)) { 533ab4382d2SGreg Kroah-Hartman unsigned char status = serial_inp(up, UART_LSR); 534ab4382d2SGreg Kroah-Hartman 535ab4382d2SGreg Kroah-Hartman if ((status & UART_LSR_DR) || (status & UART_LSR_BI)) 536ab4382d2SGreg Kroah-Hartman receive_kbd_ms_chars(up, (status & UART_LSR_BI) != 0); 537ab4382d2SGreg Kroah-Hartman } 538ab4382d2SGreg Kroah-Hartman 539ab4382d2SGreg Kroah-Hartman return IRQ_HANDLED; 540ab4382d2SGreg Kroah-Hartman } 541ab4382d2SGreg Kroah-Hartman 542ab4382d2SGreg Kroah-Hartman static unsigned int sunsu_tx_empty(struct uart_port *port) 543ab4382d2SGreg Kroah-Hartman { 5449a6962c5SFabian Frederick struct uart_sunsu_port *up = 5459a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 546ab4382d2SGreg Kroah-Hartman unsigned long flags; 547ab4382d2SGreg Kroah-Hartman unsigned int ret; 548ab4382d2SGreg Kroah-Hartman 549ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags); 550ab4382d2SGreg Kroah-Hartman ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; 551ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags); 552ab4382d2SGreg Kroah-Hartman 553ab4382d2SGreg Kroah-Hartman return ret; 554ab4382d2SGreg Kroah-Hartman } 555ab4382d2SGreg Kroah-Hartman 556ab4382d2SGreg Kroah-Hartman static unsigned int sunsu_get_mctrl(struct uart_port *port) 557ab4382d2SGreg Kroah-Hartman { 5589a6962c5SFabian Frederick struct uart_sunsu_port *up = 5599a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 560ab4382d2SGreg Kroah-Hartman unsigned char status; 561ab4382d2SGreg Kroah-Hartman unsigned int ret; 562ab4382d2SGreg Kroah-Hartman 563ab4382d2SGreg Kroah-Hartman status = serial_in(up, UART_MSR); 564ab4382d2SGreg Kroah-Hartman 565ab4382d2SGreg Kroah-Hartman ret = 0; 566ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_DCD) 567ab4382d2SGreg Kroah-Hartman ret |= TIOCM_CAR; 568ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_RI) 569ab4382d2SGreg Kroah-Hartman ret |= TIOCM_RNG; 570ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_DSR) 571ab4382d2SGreg Kroah-Hartman ret |= TIOCM_DSR; 572ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_CTS) 573ab4382d2SGreg Kroah-Hartman ret |= TIOCM_CTS; 574ab4382d2SGreg Kroah-Hartman return ret; 575ab4382d2SGreg Kroah-Hartman } 576ab4382d2SGreg Kroah-Hartman 577ab4382d2SGreg Kroah-Hartman static void sunsu_set_mctrl(struct uart_port *port, unsigned int mctrl) 578ab4382d2SGreg Kroah-Hartman { 5799a6962c5SFabian Frederick struct uart_sunsu_port *up = 5809a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 581ab4382d2SGreg Kroah-Hartman unsigned char mcr = 0; 582ab4382d2SGreg Kroah-Hartman 583ab4382d2SGreg Kroah-Hartman if (mctrl & TIOCM_RTS) 584ab4382d2SGreg Kroah-Hartman mcr |= UART_MCR_RTS; 585ab4382d2SGreg Kroah-Hartman if (mctrl & TIOCM_DTR) 586ab4382d2SGreg Kroah-Hartman mcr |= UART_MCR_DTR; 587ab4382d2SGreg Kroah-Hartman if (mctrl & TIOCM_OUT1) 588ab4382d2SGreg Kroah-Hartman mcr |= UART_MCR_OUT1; 589ab4382d2SGreg Kroah-Hartman if (mctrl & TIOCM_OUT2) 590ab4382d2SGreg Kroah-Hartman mcr |= UART_MCR_OUT2; 591ab4382d2SGreg Kroah-Hartman if (mctrl & TIOCM_LOOP) 592ab4382d2SGreg Kroah-Hartman mcr |= UART_MCR_LOOP; 593ab4382d2SGreg Kroah-Hartman 594ab4382d2SGreg Kroah-Hartman serial_out(up, UART_MCR, mcr); 595ab4382d2SGreg Kroah-Hartman } 596ab4382d2SGreg Kroah-Hartman 597ab4382d2SGreg Kroah-Hartman static void sunsu_break_ctl(struct uart_port *port, int break_state) 598ab4382d2SGreg Kroah-Hartman { 5999a6962c5SFabian Frederick struct uart_sunsu_port *up = 6009a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 601ab4382d2SGreg Kroah-Hartman unsigned long flags; 602ab4382d2SGreg Kroah-Hartman 603ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags); 604ab4382d2SGreg Kroah-Hartman if (break_state == -1) 605ab4382d2SGreg Kroah-Hartman up->lcr |= UART_LCR_SBC; 606ab4382d2SGreg Kroah-Hartman else 607ab4382d2SGreg Kroah-Hartman up->lcr &= ~UART_LCR_SBC; 608ab4382d2SGreg Kroah-Hartman serial_out(up, UART_LCR, up->lcr); 609ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags); 610ab4382d2SGreg Kroah-Hartman } 611ab4382d2SGreg Kroah-Hartman 612ab4382d2SGreg Kroah-Hartman static int sunsu_startup(struct uart_port *port) 613ab4382d2SGreg Kroah-Hartman { 6149a6962c5SFabian Frederick struct uart_sunsu_port *up = 6159a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 616ab4382d2SGreg Kroah-Hartman unsigned long flags; 617ab4382d2SGreg Kroah-Hartman int retval; 618ab4382d2SGreg Kroah-Hartman 619ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16C950) { 620ab4382d2SGreg Kroah-Hartman /* Wake up and initialize UART */ 621ab4382d2SGreg Kroah-Hartman up->acr = 0; 622ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0xBF); 623ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_EFR, UART_EFR_ECB); 624ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, 0); 625ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0); 626ab4382d2SGreg Kroah-Hartman serial_icr_write(up, UART_CSR, 0); /* Reset the UART */ 627ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0xBF); 628ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_EFR, UART_EFR_ECB); 629ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0); 630ab4382d2SGreg Kroah-Hartman } 631ab4382d2SGreg Kroah-Hartman 632ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIAL_8250_RSA 633ab4382d2SGreg Kroah-Hartman /* 634ab4382d2SGreg Kroah-Hartman * If this is an RSA port, see if we can kick it up to the 635ab4382d2SGreg Kroah-Hartman * higher speed clock. 636ab4382d2SGreg Kroah-Hartman */ 637ab4382d2SGreg Kroah-Hartman enable_rsa(up); 638ab4382d2SGreg Kroah-Hartman #endif 639ab4382d2SGreg Kroah-Hartman 640ab4382d2SGreg Kroah-Hartman /* 641ab4382d2SGreg Kroah-Hartman * Clear the FIFO buffers and disable them. 642ab4382d2SGreg Kroah-Hartman * (they will be reenabled in set_termios()) 643ab4382d2SGreg Kroah-Hartman */ 644ab4382d2SGreg Kroah-Hartman if (uart_config[up->port.type].flags & UART_CLEAR_FIFO) { 645ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 646ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | 647ab4382d2SGreg Kroah-Hartman UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 648ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, 0); 649ab4382d2SGreg Kroah-Hartman } 650ab4382d2SGreg Kroah-Hartman 651ab4382d2SGreg Kroah-Hartman /* 652ab4382d2SGreg Kroah-Hartman * Clear the interrupt registers. 653ab4382d2SGreg Kroah-Hartman */ 654ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_LSR); 655ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_RX); 656ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_IIR); 657ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_MSR); 658ab4382d2SGreg Kroah-Hartman 659ab4382d2SGreg Kroah-Hartman /* 660ab4382d2SGreg Kroah-Hartman * At this point, there's no way the LSR could still be 0xff; 661ab4382d2SGreg Kroah-Hartman * if it is, then bail out, because there's likely no UART 662ab4382d2SGreg Kroah-Hartman * here. 663ab4382d2SGreg Kroah-Hartman */ 664ab4382d2SGreg Kroah-Hartman if (!(up->port.flags & UPF_BUGGY_UART) && 665ab4382d2SGreg Kroah-Hartman (serial_inp(up, UART_LSR) == 0xff)) { 666ab4382d2SGreg Kroah-Hartman printk("ttyS%d: LSR safety check engaged!\n", up->port.line); 667ab4382d2SGreg Kroah-Hartman return -ENODEV; 668ab4382d2SGreg Kroah-Hartman } 669ab4382d2SGreg Kroah-Hartman 670ab4382d2SGreg Kroah-Hartman if (up->su_type != SU_PORT_PORT) { 671ab4382d2SGreg Kroah-Hartman retval = request_irq(up->port.irq, sunsu_kbd_ms_interrupt, 672ab4382d2SGreg Kroah-Hartman IRQF_SHARED, su_typev[up->su_type], up); 673ab4382d2SGreg Kroah-Hartman } else { 674ab4382d2SGreg Kroah-Hartman retval = request_irq(up->port.irq, sunsu_serial_interrupt, 675ab4382d2SGreg Kroah-Hartman IRQF_SHARED, su_typev[up->su_type], up); 676ab4382d2SGreg Kroah-Hartman } 677ab4382d2SGreg Kroah-Hartman if (retval) { 678ab4382d2SGreg Kroah-Hartman printk("su: Cannot register IRQ %d\n", up->port.irq); 679ab4382d2SGreg Kroah-Hartman return retval; 680ab4382d2SGreg Kroah-Hartman } 681ab4382d2SGreg Kroah-Hartman 682ab4382d2SGreg Kroah-Hartman /* 683ab4382d2SGreg Kroah-Hartman * Now, initialize the UART 684ab4382d2SGreg Kroah-Hartman */ 685ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, UART_LCR_WLEN8); 686ab4382d2SGreg Kroah-Hartman 687ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags); 688ab4382d2SGreg Kroah-Hartman 689ab4382d2SGreg Kroah-Hartman up->port.mctrl |= TIOCM_OUT2; 690ab4382d2SGreg Kroah-Hartman 691ab4382d2SGreg Kroah-Hartman sunsu_set_mctrl(&up->port, up->port.mctrl); 692ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags); 693ab4382d2SGreg Kroah-Hartman 694ab4382d2SGreg Kroah-Hartman /* 695ab4382d2SGreg Kroah-Hartman * Finally, enable interrupts. Note: Modem status interrupts 696ab4382d2SGreg Kroah-Hartman * are set via set_termios(), which will be occurring imminently 697ab4382d2SGreg Kroah-Hartman * anyway, so we don't enable them here. 698ab4382d2SGreg Kroah-Hartman */ 699ab4382d2SGreg Kroah-Hartman up->ier = UART_IER_RLSI | UART_IER_RDI; 700ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, up->ier); 701ab4382d2SGreg Kroah-Hartman 702ab4382d2SGreg Kroah-Hartman if (up->port.flags & UPF_FOURPORT) { 703ab4382d2SGreg Kroah-Hartman unsigned int icp; 704ab4382d2SGreg Kroah-Hartman /* 705ab4382d2SGreg Kroah-Hartman * Enable interrupts on the AST Fourport board 706ab4382d2SGreg Kroah-Hartman */ 707ab4382d2SGreg Kroah-Hartman icp = (up->port.iobase & 0xfe0) | 0x01f; 708ab4382d2SGreg Kroah-Hartman outb_p(0x80, icp); 709ab4382d2SGreg Kroah-Hartman (void) inb_p(icp); 710ab4382d2SGreg Kroah-Hartman } 711ab4382d2SGreg Kroah-Hartman 712ab4382d2SGreg Kroah-Hartman /* 713ab4382d2SGreg Kroah-Hartman * And clear the interrupt registers again for luck. 714ab4382d2SGreg Kroah-Hartman */ 715ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_LSR); 716ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_RX); 717ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_IIR); 718ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_MSR); 719ab4382d2SGreg Kroah-Hartman 720ab4382d2SGreg Kroah-Hartman return 0; 721ab4382d2SGreg Kroah-Hartman } 722ab4382d2SGreg Kroah-Hartman 723ab4382d2SGreg Kroah-Hartman static void sunsu_shutdown(struct uart_port *port) 724ab4382d2SGreg Kroah-Hartman { 7259a6962c5SFabian Frederick struct uart_sunsu_port *up = 7269a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 727ab4382d2SGreg Kroah-Hartman unsigned long flags; 728ab4382d2SGreg Kroah-Hartman 729ab4382d2SGreg Kroah-Hartman /* 730ab4382d2SGreg Kroah-Hartman * Disable interrupts from this port 731ab4382d2SGreg Kroah-Hartman */ 732ab4382d2SGreg Kroah-Hartman up->ier = 0; 733ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, 0); 734ab4382d2SGreg Kroah-Hartman 735ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags); 736ab4382d2SGreg Kroah-Hartman if (up->port.flags & UPF_FOURPORT) { 737ab4382d2SGreg Kroah-Hartman /* reset interrupts on the AST Fourport board */ 738ab4382d2SGreg Kroah-Hartman inb((up->port.iobase & 0xfe0) | 0x1f); 739ab4382d2SGreg Kroah-Hartman up->port.mctrl |= TIOCM_OUT1; 740ab4382d2SGreg Kroah-Hartman } else 741ab4382d2SGreg Kroah-Hartman up->port.mctrl &= ~TIOCM_OUT2; 742ab4382d2SGreg Kroah-Hartman 743ab4382d2SGreg Kroah-Hartman sunsu_set_mctrl(&up->port, up->port.mctrl); 744ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags); 745ab4382d2SGreg Kroah-Hartman 746ab4382d2SGreg Kroah-Hartman /* 747ab4382d2SGreg Kroah-Hartman * Disable break condition and FIFOs 748ab4382d2SGreg Kroah-Hartman */ 749ab4382d2SGreg Kroah-Hartman serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC); 750ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | 751ab4382d2SGreg Kroah-Hartman UART_FCR_CLEAR_RCVR | 752ab4382d2SGreg Kroah-Hartman UART_FCR_CLEAR_XMIT); 753ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, 0); 754ab4382d2SGreg Kroah-Hartman 755ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIAL_8250_RSA 756ab4382d2SGreg Kroah-Hartman /* 757ab4382d2SGreg Kroah-Hartman * Reset the RSA board back to 115kbps compat mode. 758ab4382d2SGreg Kroah-Hartman */ 759ab4382d2SGreg Kroah-Hartman disable_rsa(up); 760ab4382d2SGreg Kroah-Hartman #endif 761ab4382d2SGreg Kroah-Hartman 762ab4382d2SGreg Kroah-Hartman /* 763ab4382d2SGreg Kroah-Hartman * Read data port to reset things. 764ab4382d2SGreg Kroah-Hartman */ 765ab4382d2SGreg Kroah-Hartman (void) serial_in(up, UART_RX); 766ab4382d2SGreg Kroah-Hartman 767ab4382d2SGreg Kroah-Hartman free_irq(up->port.irq, up); 768ab4382d2SGreg Kroah-Hartman } 769ab4382d2SGreg Kroah-Hartman 770ab4382d2SGreg Kroah-Hartman static void 771ab4382d2SGreg Kroah-Hartman sunsu_change_speed(struct uart_port *port, unsigned int cflag, 772ab4382d2SGreg Kroah-Hartman unsigned int iflag, unsigned int quot) 773ab4382d2SGreg Kroah-Hartman { 7749a6962c5SFabian Frederick struct uart_sunsu_port *up = 7759a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 776ab4382d2SGreg Kroah-Hartman unsigned char cval, fcr = 0; 777ab4382d2SGreg Kroah-Hartman unsigned long flags; 778ab4382d2SGreg Kroah-Hartman 779ab4382d2SGreg Kroah-Hartman switch (cflag & CSIZE) { 780ab4382d2SGreg Kroah-Hartman case CS5: 781ab4382d2SGreg Kroah-Hartman cval = 0x00; 782ab4382d2SGreg Kroah-Hartman break; 783ab4382d2SGreg Kroah-Hartman case CS6: 784ab4382d2SGreg Kroah-Hartman cval = 0x01; 785ab4382d2SGreg Kroah-Hartman break; 786ab4382d2SGreg Kroah-Hartman case CS7: 787ab4382d2SGreg Kroah-Hartman cval = 0x02; 788ab4382d2SGreg Kroah-Hartman break; 789ab4382d2SGreg Kroah-Hartman default: 790ab4382d2SGreg Kroah-Hartman case CS8: 791ab4382d2SGreg Kroah-Hartman cval = 0x03; 792ab4382d2SGreg Kroah-Hartman break; 793ab4382d2SGreg Kroah-Hartman } 794ab4382d2SGreg Kroah-Hartman 795ab4382d2SGreg Kroah-Hartman if (cflag & CSTOPB) 796ab4382d2SGreg Kroah-Hartman cval |= 0x04; 797ab4382d2SGreg Kroah-Hartman if (cflag & PARENB) 798ab4382d2SGreg Kroah-Hartman cval |= UART_LCR_PARITY; 799ab4382d2SGreg Kroah-Hartman if (!(cflag & PARODD)) 800ab4382d2SGreg Kroah-Hartman cval |= UART_LCR_EPAR; 801ab4382d2SGreg Kroah-Hartman #ifdef CMSPAR 802ab4382d2SGreg Kroah-Hartman if (cflag & CMSPAR) 803ab4382d2SGreg Kroah-Hartman cval |= UART_LCR_SPAR; 804ab4382d2SGreg Kroah-Hartman #endif 805ab4382d2SGreg Kroah-Hartman 806ab4382d2SGreg Kroah-Hartman /* 807ab4382d2SGreg Kroah-Hartman * Work around a bug in the Oxford Semiconductor 952 rev B 808ab4382d2SGreg Kroah-Hartman * chip which causes it to seriously miscalculate baud rates 809ab4382d2SGreg Kroah-Hartman * when DLL is 0. 810ab4382d2SGreg Kroah-Hartman */ 811ab4382d2SGreg Kroah-Hartman if ((quot & 0xff) == 0 && up->port.type == PORT_16C950 && 812ab4382d2SGreg Kroah-Hartman up->rev == 0x5201) 813ab4382d2SGreg Kroah-Hartman quot ++; 814ab4382d2SGreg Kroah-Hartman 815ab4382d2SGreg Kroah-Hartman if (uart_config[up->port.type].flags & UART_USE_FIFO) { 816ab4382d2SGreg Kroah-Hartman if ((up->port.uartclk / quot) < (2400 * 16)) 817ab4382d2SGreg Kroah-Hartman fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1; 818ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIAL_8250_RSA 819ab4382d2SGreg Kroah-Hartman else if (up->port.type == PORT_RSA) 820ab4382d2SGreg Kroah-Hartman fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_14; 821ab4382d2SGreg Kroah-Hartman #endif 822ab4382d2SGreg Kroah-Hartman else 823ab4382d2SGreg Kroah-Hartman fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_8; 824ab4382d2SGreg Kroah-Hartman } 825ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16750) 826ab4382d2SGreg Kroah-Hartman fcr |= UART_FCR7_64BYTE; 827ab4382d2SGreg Kroah-Hartman 828ab4382d2SGreg Kroah-Hartman /* 829ab4382d2SGreg Kroah-Hartman * Ok, we're now changing the port state. Do it with 830ab4382d2SGreg Kroah-Hartman * interrupts disabled. 831ab4382d2SGreg Kroah-Hartman */ 832ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags); 833ab4382d2SGreg Kroah-Hartman 834ab4382d2SGreg Kroah-Hartman /* 835ab4382d2SGreg Kroah-Hartman * Update the per-port timeout. 836ab4382d2SGreg Kroah-Hartman */ 837ab4382d2SGreg Kroah-Hartman uart_update_timeout(port, cflag, (port->uartclk / (16 * quot))); 838ab4382d2SGreg Kroah-Hartman 839ab4382d2SGreg Kroah-Hartman up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; 840ab4382d2SGreg Kroah-Hartman if (iflag & INPCK) 841ab4382d2SGreg Kroah-Hartman up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE; 842ef8b9ddcSPeter Hurley if (iflag & (IGNBRK | BRKINT | PARMRK)) 843ab4382d2SGreg Kroah-Hartman up->port.read_status_mask |= UART_LSR_BI; 844ab4382d2SGreg Kroah-Hartman 845ab4382d2SGreg Kroah-Hartman /* 846ab4382d2SGreg Kroah-Hartman * Characteres to ignore 847ab4382d2SGreg Kroah-Hartman */ 848ab4382d2SGreg Kroah-Hartman up->port.ignore_status_mask = 0; 849ab4382d2SGreg Kroah-Hartman if (iflag & IGNPAR) 850ab4382d2SGreg Kroah-Hartman up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE; 851ab4382d2SGreg Kroah-Hartman if (iflag & IGNBRK) { 852ab4382d2SGreg Kroah-Hartman up->port.ignore_status_mask |= UART_LSR_BI; 853ab4382d2SGreg Kroah-Hartman /* 854ab4382d2SGreg Kroah-Hartman * If we're ignoring parity and break indicators, 855ab4382d2SGreg Kroah-Hartman * ignore overruns too (for real raw support). 856ab4382d2SGreg Kroah-Hartman */ 857ab4382d2SGreg Kroah-Hartman if (iflag & IGNPAR) 858ab4382d2SGreg Kroah-Hartman up->port.ignore_status_mask |= UART_LSR_OE; 859ab4382d2SGreg Kroah-Hartman } 860ab4382d2SGreg Kroah-Hartman 861ab4382d2SGreg Kroah-Hartman /* 862ab4382d2SGreg Kroah-Hartman * ignore all characters if CREAD is not set 863ab4382d2SGreg Kroah-Hartman */ 864ab4382d2SGreg Kroah-Hartman if ((cflag & CREAD) == 0) 865ab4382d2SGreg Kroah-Hartman up->port.ignore_status_mask |= UART_LSR_DR; 866ab4382d2SGreg Kroah-Hartman 867ab4382d2SGreg Kroah-Hartman /* 868ab4382d2SGreg Kroah-Hartman * CTS flow control flag and modem status interrupts 869ab4382d2SGreg Kroah-Hartman */ 870ab4382d2SGreg Kroah-Hartman up->ier &= ~UART_IER_MSI; 871ab4382d2SGreg Kroah-Hartman if (UART_ENABLE_MS(&up->port, cflag)) 872ab4382d2SGreg Kroah-Hartman up->ier |= UART_IER_MSI; 873ab4382d2SGreg Kroah-Hartman 874ab4382d2SGreg Kroah-Hartman serial_out(up, UART_IER, up->ier); 875ab4382d2SGreg Kroah-Hartman 876ab4382d2SGreg Kroah-Hartman if (uart_config[up->port.type].flags & UART_STARTECH) { 877ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0xBF); 878ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_EFR, cflag & CRTSCTS ? UART_EFR_CTS :0); 879ab4382d2SGreg Kroah-Hartman } 880ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */ 881ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_DLL, quot & 0xff); /* LS of divisor */ 882ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_DLM, quot >> 8); /* MS of divisor */ 883ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16750) 884ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, fcr); /* set fcr */ 885ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, cval); /* reset DLAB */ 886ab4382d2SGreg Kroah-Hartman up->lcr = cval; /* Save LCR */ 887ab4382d2SGreg Kroah-Hartman if (up->port.type != PORT_16750) { 888ab4382d2SGreg Kroah-Hartman if (fcr & UART_FCR_ENABLE_FIFO) { 889ab4382d2SGreg Kroah-Hartman /* emulated UARTs (Lucent Venus 167x) need two steps */ 890ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 891ab4382d2SGreg Kroah-Hartman } 892ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, fcr); /* set fcr */ 893ab4382d2SGreg Kroah-Hartman } 894ab4382d2SGreg Kroah-Hartman 895ab4382d2SGreg Kroah-Hartman up->cflag = cflag; 896ab4382d2SGreg Kroah-Hartman 897ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags); 898ab4382d2SGreg Kroah-Hartman } 899ab4382d2SGreg Kroah-Hartman 900ab4382d2SGreg Kroah-Hartman static void 901ab4382d2SGreg Kroah-Hartman sunsu_set_termios(struct uart_port *port, struct ktermios *termios, 902ab4382d2SGreg Kroah-Hartman struct ktermios *old) 903ab4382d2SGreg Kroah-Hartman { 904ab4382d2SGreg Kroah-Hartman unsigned int baud, quot; 905ab4382d2SGreg Kroah-Hartman 906ab4382d2SGreg Kroah-Hartman /* 907ab4382d2SGreg Kroah-Hartman * Ask the core to calculate the divisor for us. 908ab4382d2SGreg Kroah-Hartman */ 909ab4382d2SGreg Kroah-Hartman baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); 910ab4382d2SGreg Kroah-Hartman quot = uart_get_divisor(port, baud); 911ab4382d2SGreg Kroah-Hartman 912ab4382d2SGreg Kroah-Hartman sunsu_change_speed(port, termios->c_cflag, termios->c_iflag, quot); 913ab4382d2SGreg Kroah-Hartman } 914ab4382d2SGreg Kroah-Hartman 915ab4382d2SGreg Kroah-Hartman static void sunsu_release_port(struct uart_port *port) 916ab4382d2SGreg Kroah-Hartman { 917ab4382d2SGreg Kroah-Hartman } 918ab4382d2SGreg Kroah-Hartman 919ab4382d2SGreg Kroah-Hartman static int sunsu_request_port(struct uart_port *port) 920ab4382d2SGreg Kroah-Hartman { 921ab4382d2SGreg Kroah-Hartman return 0; 922ab4382d2SGreg Kroah-Hartman } 923ab4382d2SGreg Kroah-Hartman 924ab4382d2SGreg Kroah-Hartman static void sunsu_config_port(struct uart_port *port, int flags) 925ab4382d2SGreg Kroah-Hartman { 9269a6962c5SFabian Frederick struct uart_sunsu_port *up = 9279a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 928ab4382d2SGreg Kroah-Hartman 929ab4382d2SGreg Kroah-Hartman if (flags & UART_CONFIG_TYPE) { 930ab4382d2SGreg Kroah-Hartman /* 931ab4382d2SGreg Kroah-Hartman * We are supposed to call autoconfig here, but this requires 932ab4382d2SGreg Kroah-Hartman * splitting all the OBP probing crap from the UART probing. 933ab4382d2SGreg Kroah-Hartman * We'll do it when we kill sunsu.c altogether. 934ab4382d2SGreg Kroah-Hartman */ 935ab4382d2SGreg Kroah-Hartman port->type = up->type_probed; /* XXX */ 936ab4382d2SGreg Kroah-Hartman } 937ab4382d2SGreg Kroah-Hartman } 938ab4382d2SGreg Kroah-Hartman 939ab4382d2SGreg Kroah-Hartman static int 940ab4382d2SGreg Kroah-Hartman sunsu_verify_port(struct uart_port *port, struct serial_struct *ser) 941ab4382d2SGreg Kroah-Hartman { 942ab4382d2SGreg Kroah-Hartman return -EINVAL; 943ab4382d2SGreg Kroah-Hartman } 944ab4382d2SGreg Kroah-Hartman 945ab4382d2SGreg Kroah-Hartman static const char * 946ab4382d2SGreg Kroah-Hartman sunsu_type(struct uart_port *port) 947ab4382d2SGreg Kroah-Hartman { 948ab4382d2SGreg Kroah-Hartman int type = port->type; 949ab4382d2SGreg Kroah-Hartman 950ab4382d2SGreg Kroah-Hartman if (type >= ARRAY_SIZE(uart_config)) 951ab4382d2SGreg Kroah-Hartman type = 0; 952ab4382d2SGreg Kroah-Hartman return uart_config[type].name; 953ab4382d2SGreg Kroah-Hartman } 954ab4382d2SGreg Kroah-Hartman 9550bfdbe07SJulia Lawall static const struct uart_ops sunsu_pops = { 956ab4382d2SGreg Kroah-Hartman .tx_empty = sunsu_tx_empty, 957ab4382d2SGreg Kroah-Hartman .set_mctrl = sunsu_set_mctrl, 958ab4382d2SGreg Kroah-Hartman .get_mctrl = sunsu_get_mctrl, 959ab4382d2SGreg Kroah-Hartman .stop_tx = sunsu_stop_tx, 960ab4382d2SGreg Kroah-Hartman .start_tx = sunsu_start_tx, 961ab4382d2SGreg Kroah-Hartman .stop_rx = sunsu_stop_rx, 962ab4382d2SGreg Kroah-Hartman .enable_ms = sunsu_enable_ms, 963ab4382d2SGreg Kroah-Hartman .break_ctl = sunsu_break_ctl, 964ab4382d2SGreg Kroah-Hartman .startup = sunsu_startup, 965ab4382d2SGreg Kroah-Hartman .shutdown = sunsu_shutdown, 966ab4382d2SGreg Kroah-Hartman .set_termios = sunsu_set_termios, 967ab4382d2SGreg Kroah-Hartman .type = sunsu_type, 968ab4382d2SGreg Kroah-Hartman .release_port = sunsu_release_port, 969ab4382d2SGreg Kroah-Hartman .request_port = sunsu_request_port, 970ab4382d2SGreg Kroah-Hartman .config_port = sunsu_config_port, 971ab4382d2SGreg Kroah-Hartman .verify_port = sunsu_verify_port, 972ab4382d2SGreg Kroah-Hartman }; 973ab4382d2SGreg Kroah-Hartman 974ab4382d2SGreg Kroah-Hartman #define UART_NR 4 975ab4382d2SGreg Kroah-Hartman 976ab4382d2SGreg Kroah-Hartman static struct uart_sunsu_port sunsu_ports[UART_NR]; 977cb29529eSTkhai Kirill static int nr_inst; /* Number of already registered ports */ 978ab4382d2SGreg Kroah-Hartman 979ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO 980ab4382d2SGreg Kroah-Hartman 981ab4382d2SGreg Kroah-Hartman static DEFINE_SPINLOCK(sunsu_serio_lock); 982ab4382d2SGreg Kroah-Hartman 983ab4382d2SGreg Kroah-Hartman static int sunsu_serio_write(struct serio *serio, unsigned char ch) 984ab4382d2SGreg Kroah-Hartman { 985ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up = serio->port_data; 986ab4382d2SGreg Kroah-Hartman unsigned long flags; 987ab4382d2SGreg Kroah-Hartman int lsr; 988ab4382d2SGreg Kroah-Hartman 989ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&sunsu_serio_lock, flags); 990ab4382d2SGreg Kroah-Hartman 991ab4382d2SGreg Kroah-Hartman do { 992ab4382d2SGreg Kroah-Hartman lsr = serial_in(up, UART_LSR); 993ab4382d2SGreg Kroah-Hartman } while (!(lsr & UART_LSR_THRE)); 994ab4382d2SGreg Kroah-Hartman 995ab4382d2SGreg Kroah-Hartman /* Send the character out. */ 996ab4382d2SGreg Kroah-Hartman serial_out(up, UART_TX, ch); 997ab4382d2SGreg Kroah-Hartman 998ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&sunsu_serio_lock, flags); 999ab4382d2SGreg Kroah-Hartman 1000ab4382d2SGreg Kroah-Hartman return 0; 1001ab4382d2SGreg Kroah-Hartman } 1002ab4382d2SGreg Kroah-Hartman 1003ab4382d2SGreg Kroah-Hartman static int sunsu_serio_open(struct serio *serio) 1004ab4382d2SGreg Kroah-Hartman { 1005ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up = serio->port_data; 1006ab4382d2SGreg Kroah-Hartman unsigned long flags; 1007ab4382d2SGreg Kroah-Hartman int ret; 1008ab4382d2SGreg Kroah-Hartman 1009ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&sunsu_serio_lock, flags); 1010ab4382d2SGreg Kroah-Hartman if (!up->serio_open) { 1011ab4382d2SGreg Kroah-Hartman up->serio_open = 1; 1012ab4382d2SGreg Kroah-Hartman ret = 0; 1013ab4382d2SGreg Kroah-Hartman } else 1014ab4382d2SGreg Kroah-Hartman ret = -EBUSY; 1015ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&sunsu_serio_lock, flags); 1016ab4382d2SGreg Kroah-Hartman 1017ab4382d2SGreg Kroah-Hartman return ret; 1018ab4382d2SGreg Kroah-Hartman } 1019ab4382d2SGreg Kroah-Hartman 1020ab4382d2SGreg Kroah-Hartman static void sunsu_serio_close(struct serio *serio) 1021ab4382d2SGreg Kroah-Hartman { 1022ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up = serio->port_data; 1023ab4382d2SGreg Kroah-Hartman unsigned long flags; 1024ab4382d2SGreg Kroah-Hartman 1025ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&sunsu_serio_lock, flags); 1026ab4382d2SGreg Kroah-Hartman up->serio_open = 0; 1027ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&sunsu_serio_lock, flags); 1028ab4382d2SGreg Kroah-Hartman } 1029ab4382d2SGreg Kroah-Hartman 1030ab4382d2SGreg Kroah-Hartman #endif /* CONFIG_SERIO */ 1031ab4382d2SGreg Kroah-Hartman 1032ab4382d2SGreg Kroah-Hartman static void sunsu_autoconfig(struct uart_sunsu_port *up) 1033ab4382d2SGreg Kroah-Hartman { 1034ab4382d2SGreg Kroah-Hartman unsigned char status1, status2, scratch, scratch2, scratch3; 1035ab4382d2SGreg Kroah-Hartman unsigned char save_lcr, save_mcr; 1036ab4382d2SGreg Kroah-Hartman unsigned long flags; 1037ab4382d2SGreg Kroah-Hartman 1038ab4382d2SGreg Kroah-Hartman if (up->su_type == SU_PORT_NONE) 1039ab4382d2SGreg Kroah-Hartman return; 1040ab4382d2SGreg Kroah-Hartman 1041ab4382d2SGreg Kroah-Hartman up->type_probed = PORT_UNKNOWN; 1042ab4382d2SGreg Kroah-Hartman up->port.iotype = UPIO_MEM; 1043ab4382d2SGreg Kroah-Hartman 1044ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags); 1045ab4382d2SGreg Kroah-Hartman 1046ab4382d2SGreg Kroah-Hartman if (!(up->port.flags & UPF_BUGGY_UART)) { 1047ab4382d2SGreg Kroah-Hartman /* 1048ab4382d2SGreg Kroah-Hartman * Do a simple existence test first; if we fail this, there's 1049ab4382d2SGreg Kroah-Hartman * no point trying anything else. 1050ab4382d2SGreg Kroah-Hartman * 1051ab4382d2SGreg Kroah-Hartman * 0x80 is used as a nonsense port to prevent against false 1052ab4382d2SGreg Kroah-Hartman * positives due to ISA bus float. The assumption is that 1053ab4382d2SGreg Kroah-Hartman * 0x80 is a non-existent port; which should be safe since 1054ab4382d2SGreg Kroah-Hartman * include/asm/io.h also makes this assumption. 1055ab4382d2SGreg Kroah-Hartman */ 1056ab4382d2SGreg Kroah-Hartman scratch = serial_inp(up, UART_IER); 1057ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, 0); 1058ab4382d2SGreg Kroah-Hartman #ifdef __i386__ 1059ab4382d2SGreg Kroah-Hartman outb(0xff, 0x080); 1060ab4382d2SGreg Kroah-Hartman #endif 1061ab4382d2SGreg Kroah-Hartman scratch2 = serial_inp(up, UART_IER); 1062ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, 0x0f); 1063ab4382d2SGreg Kroah-Hartman #ifdef __i386__ 1064ab4382d2SGreg Kroah-Hartman outb(0, 0x080); 1065ab4382d2SGreg Kroah-Hartman #endif 1066ab4382d2SGreg Kroah-Hartman scratch3 = serial_inp(up, UART_IER); 1067ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, scratch); 1068ab4382d2SGreg Kroah-Hartman if (scratch2 != 0 || scratch3 != 0x0F) 1069ab4382d2SGreg Kroah-Hartman goto out; /* We failed; there's nothing here */ 1070ab4382d2SGreg Kroah-Hartman } 1071ab4382d2SGreg Kroah-Hartman 1072ab4382d2SGreg Kroah-Hartman save_mcr = serial_in(up, UART_MCR); 1073ab4382d2SGreg Kroah-Hartman save_lcr = serial_in(up, UART_LCR); 1074ab4382d2SGreg Kroah-Hartman 1075ab4382d2SGreg Kroah-Hartman /* 1076ab4382d2SGreg Kroah-Hartman * Check to see if a UART is really there. Certain broken 1077ab4382d2SGreg Kroah-Hartman * internal modems based on the Rockwell chipset fail this 1078ab4382d2SGreg Kroah-Hartman * test, because they apparently don't implement the loopback 1079ab4382d2SGreg Kroah-Hartman * test mode. So this test is skipped on the COM 1 through 1080ab4382d2SGreg Kroah-Hartman * COM 4 ports. This *should* be safe, since no board 1081ab4382d2SGreg Kroah-Hartman * manufacturer would be stupid enough to design a board 1082ab4382d2SGreg Kroah-Hartman * that conflicts with COM 1-4 --- we hope! 1083ab4382d2SGreg Kroah-Hartman */ 1084ab4382d2SGreg Kroah-Hartman if (!(up->port.flags & UPF_SKIP_TEST)) { 1085ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A); 1086ab4382d2SGreg Kroah-Hartman status1 = serial_inp(up, UART_MSR) & 0xF0; 1087ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_MCR, save_mcr); 1088ab4382d2SGreg Kroah-Hartman if (status1 != 0x90) 1089ab4382d2SGreg Kroah-Hartman goto out; /* We failed loopback test */ 1090ab4382d2SGreg Kroah-Hartman } 1091ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0xBF); /* set up for StarTech test */ 1092ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_EFR, 0); /* EFR is the same as FCR */ 1093ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0); 1094ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1095ab4382d2SGreg Kroah-Hartman scratch = serial_in(up, UART_IIR) >> 6; 1096ab4382d2SGreg Kroah-Hartman switch (scratch) { 1097ab4382d2SGreg Kroah-Hartman case 0: 1098ab4382d2SGreg Kroah-Hartman up->port.type = PORT_16450; 1099ab4382d2SGreg Kroah-Hartman break; 1100ab4382d2SGreg Kroah-Hartman case 1: 1101ab4382d2SGreg Kroah-Hartman up->port.type = PORT_UNKNOWN; 1102ab4382d2SGreg Kroah-Hartman break; 1103ab4382d2SGreg Kroah-Hartman case 2: 1104ab4382d2SGreg Kroah-Hartman up->port.type = PORT_16550; 1105ab4382d2SGreg Kroah-Hartman break; 1106ab4382d2SGreg Kroah-Hartman case 3: 1107ab4382d2SGreg Kroah-Hartman up->port.type = PORT_16550A; 1108ab4382d2SGreg Kroah-Hartman break; 1109ab4382d2SGreg Kroah-Hartman } 1110ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16550A) { 1111ab4382d2SGreg Kroah-Hartman /* Check for Startech UART's */ 1112ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, UART_LCR_DLAB); 1113ab4382d2SGreg Kroah-Hartman if (serial_in(up, UART_EFR) == 0) { 1114ab4382d2SGreg Kroah-Hartman up->port.type = PORT_16650; 1115ab4382d2SGreg Kroah-Hartman } else { 1116ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0xBF); 1117ab4382d2SGreg Kroah-Hartman if (serial_in(up, UART_EFR) == 0) 1118ab4382d2SGreg Kroah-Hartman up->port.type = PORT_16650V2; 1119ab4382d2SGreg Kroah-Hartman } 1120ab4382d2SGreg Kroah-Hartman } 1121ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16550A) { 1122ab4382d2SGreg Kroah-Hartman /* Check for TI 16750 */ 1123ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, save_lcr | UART_LCR_DLAB); 1124ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, 1125ab4382d2SGreg Kroah-Hartman UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 1126ab4382d2SGreg Kroah-Hartman scratch = serial_in(up, UART_IIR) >> 5; 1127ab4382d2SGreg Kroah-Hartman if (scratch == 7) { 1128ab4382d2SGreg Kroah-Hartman /* 1129ab4382d2SGreg Kroah-Hartman * If this is a 16750, and not a cheap UART 1130ab4382d2SGreg Kroah-Hartman * clone, then it should only go into 64 byte 1131ab4382d2SGreg Kroah-Hartman * mode if the UART_FCR7_64BYTE bit was set 1132ab4382d2SGreg Kroah-Hartman * while UART_LCR_DLAB was latched. 1133ab4382d2SGreg Kroah-Hartman */ 1134ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1135ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0); 1136ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, 1137ab4382d2SGreg Kroah-Hartman UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE); 1138ab4382d2SGreg Kroah-Hartman scratch = serial_in(up, UART_IIR) >> 5; 1139ab4382d2SGreg Kroah-Hartman if (scratch == 6) 1140ab4382d2SGreg Kroah-Hartman up->port.type = PORT_16750; 1141ab4382d2SGreg Kroah-Hartman } 1142ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO); 1143ab4382d2SGreg Kroah-Hartman } 1144ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, save_lcr); 1145ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16450) { 1146ab4382d2SGreg Kroah-Hartman scratch = serial_in(up, UART_SCR); 1147ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_SCR, 0xa5); 1148ab4382d2SGreg Kroah-Hartman status1 = serial_in(up, UART_SCR); 1149ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_SCR, 0x5a); 1150ab4382d2SGreg Kroah-Hartman status2 = serial_in(up, UART_SCR); 1151ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_SCR, scratch); 1152ab4382d2SGreg Kroah-Hartman 1153ab4382d2SGreg Kroah-Hartman if ((status1 != 0xa5) || (status2 != 0x5a)) 1154ab4382d2SGreg Kroah-Hartman up->port.type = PORT_8250; 1155ab4382d2SGreg Kroah-Hartman } 1156ab4382d2SGreg Kroah-Hartman 1157ab4382d2SGreg Kroah-Hartman up->port.fifosize = uart_config[up->port.type].dfl_xmit_fifo_size; 1158ab4382d2SGreg Kroah-Hartman 1159ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_UNKNOWN) 1160ab4382d2SGreg Kroah-Hartman goto out; 1161ab4382d2SGreg Kroah-Hartman up->type_probed = up->port.type; /* XXX */ 1162ab4382d2SGreg Kroah-Hartman 1163ab4382d2SGreg Kroah-Hartman /* 1164ab4382d2SGreg Kroah-Hartman * Reset the UART. 1165ab4382d2SGreg Kroah-Hartman */ 1166ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIAL_8250_RSA 1167ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_RSA) 1168ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_RSA_FRR, 0); 1169ab4382d2SGreg Kroah-Hartman #endif 1170ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_MCR, save_mcr); 1171ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, (UART_FCR_ENABLE_FIFO | 1172ab4382d2SGreg Kroah-Hartman UART_FCR_CLEAR_RCVR | 1173ab4382d2SGreg Kroah-Hartman UART_FCR_CLEAR_XMIT)); 1174ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, 0); 1175ab4382d2SGreg Kroah-Hartman (void)serial_in(up, UART_RX); 1176ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, 0); 1177ab4382d2SGreg Kroah-Hartman 1178ab4382d2SGreg Kroah-Hartman out: 1179ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags); 1180ab4382d2SGreg Kroah-Hartman } 1181ab4382d2SGreg Kroah-Hartman 1182ab4382d2SGreg Kroah-Hartman static struct uart_driver sunsu_reg = { 1183ab4382d2SGreg Kroah-Hartman .owner = THIS_MODULE, 1184ab4382d2SGreg Kroah-Hartman .driver_name = "sunsu", 1185ab4382d2SGreg Kroah-Hartman .dev_name = "ttyS", 1186ab4382d2SGreg Kroah-Hartman .major = TTY_MAJOR, 1187ab4382d2SGreg Kroah-Hartman }; 1188ab4382d2SGreg Kroah-Hartman 11899671f099SBill Pemberton static int sunsu_kbd_ms_init(struct uart_sunsu_port *up) 1190ab4382d2SGreg Kroah-Hartman { 1191ab4382d2SGreg Kroah-Hartman int quot, baud; 1192ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO 1193ab4382d2SGreg Kroah-Hartman struct serio *serio; 1194ab4382d2SGreg Kroah-Hartman #endif 1195ab4382d2SGreg Kroah-Hartman 1196ab4382d2SGreg Kroah-Hartman if (up->su_type == SU_PORT_KBD) { 1197ab4382d2SGreg Kroah-Hartman up->cflag = B1200 | CS8 | CLOCAL | CREAD; 1198ab4382d2SGreg Kroah-Hartman baud = 1200; 1199ab4382d2SGreg Kroah-Hartman } else { 1200ab4382d2SGreg Kroah-Hartman up->cflag = B4800 | CS8 | CLOCAL | CREAD; 1201ab4382d2SGreg Kroah-Hartman baud = 4800; 1202ab4382d2SGreg Kroah-Hartman } 1203ab4382d2SGreg Kroah-Hartman quot = up->port.uartclk / (16 * baud); 1204ab4382d2SGreg Kroah-Hartman 1205ab4382d2SGreg Kroah-Hartman sunsu_autoconfig(up); 1206ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_UNKNOWN) 1207ab4382d2SGreg Kroah-Hartman return -ENODEV; 1208ab4382d2SGreg Kroah-Hartman 1209a73ee843SRob Herring printk("%pOF: %s port at %llx, irq %u\n", 1210a73ee843SRob Herring up->port.dev->of_node, 1211ab4382d2SGreg Kroah-Hartman (up->su_type == SU_PORT_KBD) ? "Keyboard" : "Mouse", 1212ab4382d2SGreg Kroah-Hartman (unsigned long long) up->port.mapbase, 1213ab4382d2SGreg Kroah-Hartman up->port.irq); 1214ab4382d2SGreg Kroah-Hartman 1215ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO 1216ab4382d2SGreg Kroah-Hartman serio = &up->serio; 1217ab4382d2SGreg Kroah-Hartman serio->port_data = up; 1218ab4382d2SGreg Kroah-Hartman 1219ab4382d2SGreg Kroah-Hartman serio->id.type = SERIO_RS232; 1220ab4382d2SGreg Kroah-Hartman if (up->su_type == SU_PORT_KBD) { 1221ab4382d2SGreg Kroah-Hartman serio->id.proto = SERIO_SUNKBD; 1222ab4382d2SGreg Kroah-Hartman strlcpy(serio->name, "sukbd", sizeof(serio->name)); 1223ab4382d2SGreg Kroah-Hartman } else { 1224ab4382d2SGreg Kroah-Hartman serio->id.proto = SERIO_SUN; 1225ab4382d2SGreg Kroah-Hartman serio->id.extra = 1; 1226ab4382d2SGreg Kroah-Hartman strlcpy(serio->name, "sums", sizeof(serio->name)); 1227ab4382d2SGreg Kroah-Hartman } 1228ab4382d2SGreg Kroah-Hartman strlcpy(serio->phys, 1229ab4382d2SGreg Kroah-Hartman (!(up->port.line & 1) ? "su/serio0" : "su/serio1"), 1230ab4382d2SGreg Kroah-Hartman sizeof(serio->phys)); 1231ab4382d2SGreg Kroah-Hartman 1232ab4382d2SGreg Kroah-Hartman serio->write = sunsu_serio_write; 1233ab4382d2SGreg Kroah-Hartman serio->open = sunsu_serio_open; 1234ab4382d2SGreg Kroah-Hartman serio->close = sunsu_serio_close; 1235ab4382d2SGreg Kroah-Hartman serio->dev.parent = up->port.dev; 1236ab4382d2SGreg Kroah-Hartman 1237ab4382d2SGreg Kroah-Hartman serio_register_port(serio); 1238ab4382d2SGreg Kroah-Hartman #endif 1239ab4382d2SGreg Kroah-Hartman 1240ab4382d2SGreg Kroah-Hartman sunsu_change_speed(&up->port, up->cflag, 0, quot); 1241ab4382d2SGreg Kroah-Hartman 1242ab4382d2SGreg Kroah-Hartman sunsu_startup(&up->port); 1243ab4382d2SGreg Kroah-Hartman return 0; 1244ab4382d2SGreg Kroah-Hartman } 1245ab4382d2SGreg Kroah-Hartman 1246ab4382d2SGreg Kroah-Hartman /* 1247ab4382d2SGreg Kroah-Hartman * ------------------------------------------------------------ 1248ab4382d2SGreg Kroah-Hartman * Serial console driver 1249ab4382d2SGreg Kroah-Hartman * ------------------------------------------------------------ 1250ab4382d2SGreg Kroah-Hartman */ 1251ab4382d2SGreg Kroah-Hartman 1252ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIAL_SUNSU_CONSOLE 1253ab4382d2SGreg Kroah-Hartman 1254ab4382d2SGreg Kroah-Hartman #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) 1255ab4382d2SGreg Kroah-Hartman 1256ab4382d2SGreg Kroah-Hartman /* 1257ab4382d2SGreg Kroah-Hartman * Wait for transmitter & holding register to empty 1258ab4382d2SGreg Kroah-Hartman */ 12590d5547caSDenys Vlasenko static void wait_for_xmitr(struct uart_sunsu_port *up) 1260ab4382d2SGreg Kroah-Hartman { 1261ab4382d2SGreg Kroah-Hartman unsigned int status, tmout = 10000; 1262ab4382d2SGreg Kroah-Hartman 1263ab4382d2SGreg Kroah-Hartman /* Wait up to 10ms for the character(s) to be sent. */ 1264ab4382d2SGreg Kroah-Hartman do { 1265ab4382d2SGreg Kroah-Hartman status = serial_in(up, UART_LSR); 1266ab4382d2SGreg Kroah-Hartman 1267ab4382d2SGreg Kroah-Hartman if (status & UART_LSR_BI) 1268ab4382d2SGreg Kroah-Hartman up->lsr_break_flag = UART_LSR_BI; 1269ab4382d2SGreg Kroah-Hartman 1270ab4382d2SGreg Kroah-Hartman if (--tmout == 0) 1271ab4382d2SGreg Kroah-Hartman break; 1272ab4382d2SGreg Kroah-Hartman udelay(1); 1273ab4382d2SGreg Kroah-Hartman } while ((status & BOTH_EMPTY) != BOTH_EMPTY); 1274ab4382d2SGreg Kroah-Hartman 1275ab4382d2SGreg Kroah-Hartman /* Wait up to 1s for flow control if necessary */ 1276ab4382d2SGreg Kroah-Hartman if (up->port.flags & UPF_CONS_FLOW) { 1277ab4382d2SGreg Kroah-Hartman tmout = 1000000; 1278ab4382d2SGreg Kroah-Hartman while (--tmout && 1279ab4382d2SGreg Kroah-Hartman ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0)) 1280ab4382d2SGreg Kroah-Hartman udelay(1); 1281ab4382d2SGreg Kroah-Hartman } 1282ab4382d2SGreg Kroah-Hartman } 1283ab4382d2SGreg Kroah-Hartman 1284*3f8bab17SJiri Slaby static void sunsu_console_putchar(struct uart_port *port, unsigned char ch) 1285ab4382d2SGreg Kroah-Hartman { 12869a6962c5SFabian Frederick struct uart_sunsu_port *up = 12879a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port); 1288ab4382d2SGreg Kroah-Hartman 1289ab4382d2SGreg Kroah-Hartman wait_for_xmitr(up); 1290ab4382d2SGreg Kroah-Hartman serial_out(up, UART_TX, ch); 1291ab4382d2SGreg Kroah-Hartman } 1292ab4382d2SGreg Kroah-Hartman 1293ab4382d2SGreg Kroah-Hartman /* 1294ab4382d2SGreg Kroah-Hartman * Print a string to the serial port trying not to disturb 1295ab4382d2SGreg Kroah-Hartman * any possible real use of the port... 1296ab4382d2SGreg Kroah-Hartman */ 1297ab4382d2SGreg Kroah-Hartman static void sunsu_console_write(struct console *co, const char *s, 1298ab4382d2SGreg Kroah-Hartman unsigned int count) 1299ab4382d2SGreg Kroah-Hartman { 1300ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up = &sunsu_ports[co->index]; 1301ab4382d2SGreg Kroah-Hartman unsigned long flags; 1302ab4382d2SGreg Kroah-Hartman unsigned int ier; 1303ab4382d2SGreg Kroah-Hartman int locked = 1; 1304ab4382d2SGreg Kroah-Hartman 1305e58e241cSDavid Miller if (up->port.sysrq || oops_in_progress) 1306e58e241cSDavid Miller locked = spin_trylock_irqsave(&up->port.lock, flags); 1307e58e241cSDavid Miller else 1308e58e241cSDavid Miller spin_lock_irqsave(&up->port.lock, flags); 1309ab4382d2SGreg Kroah-Hartman 1310ab4382d2SGreg Kroah-Hartman /* 1311ab4382d2SGreg Kroah-Hartman * First save the UER then disable the interrupts 1312ab4382d2SGreg Kroah-Hartman */ 1313ab4382d2SGreg Kroah-Hartman ier = serial_in(up, UART_IER); 1314ab4382d2SGreg Kroah-Hartman serial_out(up, UART_IER, 0); 1315ab4382d2SGreg Kroah-Hartman 1316ab4382d2SGreg Kroah-Hartman uart_console_write(&up->port, s, count, sunsu_console_putchar); 1317ab4382d2SGreg Kroah-Hartman 1318ab4382d2SGreg Kroah-Hartman /* 1319ab4382d2SGreg Kroah-Hartman * Finally, wait for transmitter to become empty 1320ab4382d2SGreg Kroah-Hartman * and restore the IER 1321ab4382d2SGreg Kroah-Hartman */ 1322ab4382d2SGreg Kroah-Hartman wait_for_xmitr(up); 1323ab4382d2SGreg Kroah-Hartman serial_out(up, UART_IER, ier); 1324ab4382d2SGreg Kroah-Hartman 1325ab4382d2SGreg Kroah-Hartman if (locked) 1326e58e241cSDavid Miller spin_unlock_irqrestore(&up->port.lock, flags); 1327ab4382d2SGreg Kroah-Hartman } 1328ab4382d2SGreg Kroah-Hartman 1329ab4382d2SGreg Kroah-Hartman /* 1330ab4382d2SGreg Kroah-Hartman * Setup initial baud/bits/parity. We do two things here: 1331ab4382d2SGreg Kroah-Hartman * - construct a cflag setting for the first su_open() 1332ab4382d2SGreg Kroah-Hartman * - initialize the serial port 1333ab4382d2SGreg Kroah-Hartman * Return non-zero if we didn't find a serial port. 1334ab4382d2SGreg Kroah-Hartman */ 1335ab4382d2SGreg Kroah-Hartman static int __init sunsu_console_setup(struct console *co, char *options) 1336ab4382d2SGreg Kroah-Hartman { 1337ab4382d2SGreg Kroah-Hartman static struct ktermios dummy; 1338ab4382d2SGreg Kroah-Hartman struct ktermios termios; 1339ab4382d2SGreg Kroah-Hartman struct uart_port *port; 1340ab4382d2SGreg Kroah-Hartman 1341ab4382d2SGreg Kroah-Hartman printk("Console: ttyS%d (SU)\n", 1342ab4382d2SGreg Kroah-Hartman (sunsu_reg.minor - 64) + co->index); 1343ab4382d2SGreg Kroah-Hartman 1344cb29529eSTkhai Kirill if (co->index > nr_inst) 1345cb29529eSTkhai Kirill return -ENODEV; 1346ab4382d2SGreg Kroah-Hartman port = &sunsu_ports[co->index].port; 1347ab4382d2SGreg Kroah-Hartman 1348ab4382d2SGreg Kroah-Hartman /* 1349ab4382d2SGreg Kroah-Hartman * Temporary fix. 1350ab4382d2SGreg Kroah-Hartman */ 1351ab4382d2SGreg Kroah-Hartman spin_lock_init(&port->lock); 1352ab4382d2SGreg Kroah-Hartman 1353ab4382d2SGreg Kroah-Hartman /* Get firmware console settings. */ 1354ab4382d2SGreg Kroah-Hartman sunserial_console_termios(co, port->dev->of_node); 1355ab4382d2SGreg Kroah-Hartman 1356ab4382d2SGreg Kroah-Hartman memset(&termios, 0, sizeof(struct ktermios)); 1357ab4382d2SGreg Kroah-Hartman termios.c_cflag = co->cflag; 1358ab4382d2SGreg Kroah-Hartman port->mctrl |= TIOCM_DTR; 1359ab4382d2SGreg Kroah-Hartman port->ops->set_termios(port, &termios, &dummy); 1360ab4382d2SGreg Kroah-Hartman 1361ab4382d2SGreg Kroah-Hartman return 0; 1362ab4382d2SGreg Kroah-Hartman } 1363ab4382d2SGreg Kroah-Hartman 1364ab4382d2SGreg Kroah-Hartman static struct console sunsu_console = { 1365ab4382d2SGreg Kroah-Hartman .name = "ttyS", 1366ab4382d2SGreg Kroah-Hartman .write = sunsu_console_write, 1367ab4382d2SGreg Kroah-Hartman .device = uart_console_device, 1368ab4382d2SGreg Kroah-Hartman .setup = sunsu_console_setup, 1369ab4382d2SGreg Kroah-Hartman .flags = CON_PRINTBUFFER, 1370ab4382d2SGreg Kroah-Hartman .index = -1, 1371ab4382d2SGreg Kroah-Hartman .data = &sunsu_reg, 1372ab4382d2SGreg Kroah-Hartman }; 1373ab4382d2SGreg Kroah-Hartman 1374ab4382d2SGreg Kroah-Hartman /* 1375ab4382d2SGreg Kroah-Hartman * Register console. 1376ab4382d2SGreg Kroah-Hartman */ 1377ab4382d2SGreg Kroah-Hartman 1378ab4382d2SGreg Kroah-Hartman static inline struct console *SUNSU_CONSOLE(void) 1379ab4382d2SGreg Kroah-Hartman { 1380ab4382d2SGreg Kroah-Hartman return &sunsu_console; 1381ab4382d2SGreg Kroah-Hartman } 1382ab4382d2SGreg Kroah-Hartman #else 1383ab4382d2SGreg Kroah-Hartman #define SUNSU_CONSOLE() (NULL) 1384ab4382d2SGreg Kroah-Hartman #define sunsu_serial_console_init() do { } while (0) 1385ab4382d2SGreg Kroah-Hartman #endif 1386ab4382d2SGreg Kroah-Hartman 13879671f099SBill Pemberton static enum su_type su_get_type(struct device_node *dp) 1388ab4382d2SGreg Kroah-Hartman { 1389ab4382d2SGreg Kroah-Hartman struct device_node *ap = of_find_node_by_path("/aliases"); 1390d430aff8SYangtao Li enum su_type rc = SU_PORT_PORT; 1391ab4382d2SGreg Kroah-Hartman 1392ab4382d2SGreg Kroah-Hartman if (ap) { 1393ab4382d2SGreg Kroah-Hartman const char *keyb = of_get_property(ap, "keyboard", NULL); 1394ab4382d2SGreg Kroah-Hartman const char *ms = of_get_property(ap, "mouse", NULL); 1395d430aff8SYangtao Li struct device_node *match; 1396ab4382d2SGreg Kroah-Hartman 1397ab4382d2SGreg Kroah-Hartman if (keyb) { 1398d430aff8SYangtao Li match = of_find_node_by_path(keyb); 1399d430aff8SYangtao Li 1400d430aff8SYangtao Li /* 1401d430aff8SYangtao Li * The pointer is used as an identifier not 1402d430aff8SYangtao Li * as a pointer, we can drop the refcount on 1403d430aff8SYangtao Li * the of__node immediately after getting it. 1404d430aff8SYangtao Li */ 1405d430aff8SYangtao Li of_node_put(match); 1406d430aff8SYangtao Li 1407d430aff8SYangtao Li if (dp == match) { 1408d430aff8SYangtao Li rc = SU_PORT_KBD; 1409d430aff8SYangtao Li goto out; 1410d430aff8SYangtao Li } 1411ab4382d2SGreg Kroah-Hartman } 1412ab4382d2SGreg Kroah-Hartman if (ms) { 1413d430aff8SYangtao Li match = of_find_node_by_path(ms); 1414d430aff8SYangtao Li 1415d430aff8SYangtao Li of_node_put(match); 1416d430aff8SYangtao Li 1417d430aff8SYangtao Li if (dp == match) { 1418d430aff8SYangtao Li rc = SU_PORT_MS; 1419d430aff8SYangtao Li goto out; 1420d430aff8SYangtao Li } 1421ab4382d2SGreg Kroah-Hartman } 1422ab4382d2SGreg Kroah-Hartman } 1423ab4382d2SGreg Kroah-Hartman 1424d430aff8SYangtao Li out: 1425d430aff8SYangtao Li of_node_put(ap); 1426d430aff8SYangtao Li return rc; 1427ab4382d2SGreg Kroah-Hartman } 1428ab4382d2SGreg Kroah-Hartman 14299671f099SBill Pemberton static int su_probe(struct platform_device *op) 1430ab4382d2SGreg Kroah-Hartman { 1431ab4382d2SGreg Kroah-Hartman struct device_node *dp = op->dev.of_node; 1432ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up; 1433ab4382d2SGreg Kroah-Hartman struct resource *rp; 1434ab4382d2SGreg Kroah-Hartman enum su_type type; 1435ab4382d2SGreg Kroah-Hartman bool ignore_line; 1436ab4382d2SGreg Kroah-Hartman int err; 1437ab4382d2SGreg Kroah-Hartman 1438ab4382d2SGreg Kroah-Hartman type = su_get_type(dp); 1439ab4382d2SGreg Kroah-Hartman if (type == SU_PORT_PORT) { 1440cb29529eSTkhai Kirill if (nr_inst >= UART_NR) 1441ab4382d2SGreg Kroah-Hartman return -EINVAL; 1442cb29529eSTkhai Kirill up = &sunsu_ports[nr_inst]; 1443ab4382d2SGreg Kroah-Hartman } else { 1444ab4382d2SGreg Kroah-Hartman up = kzalloc(sizeof(*up), GFP_KERNEL); 1445ab4382d2SGreg Kroah-Hartman if (!up) 1446ab4382d2SGreg Kroah-Hartman return -ENOMEM; 1447ab4382d2SGreg Kroah-Hartman } 1448ab4382d2SGreg Kroah-Hartman 1449cb29529eSTkhai Kirill up->port.line = nr_inst; 1450ab4382d2SGreg Kroah-Hartman 1451ab4382d2SGreg Kroah-Hartman spin_lock_init(&up->port.lock); 1452ab4382d2SGreg Kroah-Hartman 1453ab4382d2SGreg Kroah-Hartman up->su_type = type; 1454ab4382d2SGreg Kroah-Hartman 1455ab4382d2SGreg Kroah-Hartman rp = &op->resource[0]; 1456ab4382d2SGreg Kroah-Hartman up->port.mapbase = rp->start; 145728f65c11SJoe Perches up->reg_size = resource_size(rp); 1458ab4382d2SGreg Kroah-Hartman up->port.membase = of_ioremap(rp, 0, up->reg_size, "su"); 1459ab4382d2SGreg Kroah-Hartman if (!up->port.membase) { 1460ab4382d2SGreg Kroah-Hartman if (type != SU_PORT_PORT) 1461ab4382d2SGreg Kroah-Hartman kfree(up); 1462ab4382d2SGreg Kroah-Hartman return -ENOMEM; 1463ab4382d2SGreg Kroah-Hartman } 1464ab4382d2SGreg Kroah-Hartman 1465ab4382d2SGreg Kroah-Hartman up->port.irq = op->archdata.irqs[0]; 1466ab4382d2SGreg Kroah-Hartman 1467ab4382d2SGreg Kroah-Hartman up->port.dev = &op->dev; 1468ab4382d2SGreg Kroah-Hartman 1469ab4382d2SGreg Kroah-Hartman up->port.type = PORT_UNKNOWN; 1470ab4382d2SGreg Kroah-Hartman up->port.uartclk = (SU_BASE_BAUD * 16); 14715e637d2bSDmitry Safonov up->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SUNSU_CONSOLE); 1472ab4382d2SGreg Kroah-Hartman 1473ab4382d2SGreg Kroah-Hartman err = 0; 1474ab4382d2SGreg Kroah-Hartman if (up->su_type == SU_PORT_KBD || up->su_type == SU_PORT_MS) { 1475ab4382d2SGreg Kroah-Hartman err = sunsu_kbd_ms_init(up); 1476ab4382d2SGreg Kroah-Hartman if (err) { 1477ab4382d2SGreg Kroah-Hartman of_iounmap(&op->resource[0], 1478ab4382d2SGreg Kroah-Hartman up->port.membase, up->reg_size); 1479ab4382d2SGreg Kroah-Hartman kfree(up); 1480ab4382d2SGreg Kroah-Hartman return err; 1481ab4382d2SGreg Kroah-Hartman } 1482696faeddSJingoo Han platform_set_drvdata(op, up); 1483ab4382d2SGreg Kroah-Hartman 1484cb29529eSTkhai Kirill nr_inst++; 1485cb29529eSTkhai Kirill 1486ab4382d2SGreg Kroah-Hartman return 0; 1487ab4382d2SGreg Kroah-Hartman } 1488ab4382d2SGreg Kroah-Hartman 1489ab4382d2SGreg Kroah-Hartman up->port.flags |= UPF_BOOT_AUTOCONF; 1490ab4382d2SGreg Kroah-Hartman 1491ab4382d2SGreg Kroah-Hartman sunsu_autoconfig(up); 1492ab4382d2SGreg Kroah-Hartman 1493ab4382d2SGreg Kroah-Hartman err = -ENODEV; 1494ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_UNKNOWN) 1495ab4382d2SGreg Kroah-Hartman goto out_unmap; 1496ab4382d2SGreg Kroah-Hartman 1497ab4382d2SGreg Kroah-Hartman up->port.ops = &sunsu_pops; 1498ab4382d2SGreg Kroah-Hartman 1499ab4382d2SGreg Kroah-Hartman ignore_line = false; 1500778ec49cSRob Herring if (of_node_name_eq(dp, "rsc-console") || 1501778ec49cSRob Herring of_node_name_eq(dp, "lom-console")) 1502ab4382d2SGreg Kroah-Hartman ignore_line = true; 1503ab4382d2SGreg Kroah-Hartman 1504ab4382d2SGreg Kroah-Hartman sunserial_console_match(SUNSU_CONSOLE(), dp, 1505ab4382d2SGreg Kroah-Hartman &sunsu_reg, up->port.line, 1506ab4382d2SGreg Kroah-Hartman ignore_line); 1507ab4382d2SGreg Kroah-Hartman err = uart_add_one_port(&sunsu_reg, &up->port); 1508ab4382d2SGreg Kroah-Hartman if (err) 1509ab4382d2SGreg Kroah-Hartman goto out_unmap; 1510ab4382d2SGreg Kroah-Hartman 1511696faeddSJingoo Han platform_set_drvdata(op, up); 1512ab4382d2SGreg Kroah-Hartman 1513cb29529eSTkhai Kirill nr_inst++; 1514ab4382d2SGreg Kroah-Hartman 1515ab4382d2SGreg Kroah-Hartman return 0; 1516ab4382d2SGreg Kroah-Hartman 1517ab4382d2SGreg Kroah-Hartman out_unmap: 1518ab4382d2SGreg Kroah-Hartman of_iounmap(&op->resource[0], up->port.membase, up->reg_size); 1519af6f9d68SSouptick Joarder kfree(up); 1520ab4382d2SGreg Kroah-Hartman return err; 1521ab4382d2SGreg Kroah-Hartman } 1522ab4382d2SGreg Kroah-Hartman 1523ae8d8a14SBill Pemberton static int su_remove(struct platform_device *op) 1524ab4382d2SGreg Kroah-Hartman { 1525696faeddSJingoo Han struct uart_sunsu_port *up = platform_get_drvdata(op); 1526ab4382d2SGreg Kroah-Hartman bool kbdms = false; 1527ab4382d2SGreg Kroah-Hartman 1528ab4382d2SGreg Kroah-Hartman if (up->su_type == SU_PORT_MS || 1529ab4382d2SGreg Kroah-Hartman up->su_type == SU_PORT_KBD) 1530ab4382d2SGreg Kroah-Hartman kbdms = true; 1531ab4382d2SGreg Kroah-Hartman 1532ab4382d2SGreg Kroah-Hartman if (kbdms) { 1533ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO 1534ab4382d2SGreg Kroah-Hartman serio_unregister_port(&up->serio); 1535ab4382d2SGreg Kroah-Hartman #endif 1536ab4382d2SGreg Kroah-Hartman } else if (up->port.type != PORT_UNKNOWN) 1537ab4382d2SGreg Kroah-Hartman uart_remove_one_port(&sunsu_reg, &up->port); 1538ab4382d2SGreg Kroah-Hartman 1539ab4382d2SGreg Kroah-Hartman if (up->port.membase) 1540ab4382d2SGreg Kroah-Hartman of_iounmap(&op->resource[0], up->port.membase, up->reg_size); 1541ab4382d2SGreg Kroah-Hartman 1542ab4382d2SGreg Kroah-Hartman if (kbdms) 1543ab4382d2SGreg Kroah-Hartman kfree(up); 1544ab4382d2SGreg Kroah-Hartman 1545ab4382d2SGreg Kroah-Hartman return 0; 1546ab4382d2SGreg Kroah-Hartman } 1547ab4382d2SGreg Kroah-Hartman 1548ab4382d2SGreg Kroah-Hartman static const struct of_device_id su_match[] = { 1549ab4382d2SGreg Kroah-Hartman { 1550ab4382d2SGreg Kroah-Hartman .name = "su", 1551ab4382d2SGreg Kroah-Hartman }, 1552ab4382d2SGreg Kroah-Hartman { 1553ab4382d2SGreg Kroah-Hartman .name = "su_pnp", 1554ab4382d2SGreg Kroah-Hartman }, 1555ab4382d2SGreg Kroah-Hartman { 1556ab4382d2SGreg Kroah-Hartman .name = "serial", 1557ab4382d2SGreg Kroah-Hartman .compatible = "su", 1558ab4382d2SGreg Kroah-Hartman }, 1559ab4382d2SGreg Kroah-Hartman { 1560ab4382d2SGreg Kroah-Hartman .type = "serial", 1561ab4382d2SGreg Kroah-Hartman .compatible = "su", 1562ab4382d2SGreg Kroah-Hartman }, 1563ab4382d2SGreg Kroah-Hartman {}, 1564ab4382d2SGreg Kroah-Hartman }; 1565ab4382d2SGreg Kroah-Hartman MODULE_DEVICE_TABLE(of, su_match); 1566ab4382d2SGreg Kroah-Hartman 1567793218dfSGrant Likely static struct platform_driver su_driver = { 1568ab4382d2SGreg Kroah-Hartman .driver = { 1569ab4382d2SGreg Kroah-Hartman .name = "su", 1570ab4382d2SGreg Kroah-Hartman .of_match_table = su_match, 1571ab4382d2SGreg Kroah-Hartman }, 1572ab4382d2SGreg Kroah-Hartman .probe = su_probe, 15732d47b716SBill Pemberton .remove = su_remove, 1574ab4382d2SGreg Kroah-Hartman }; 1575ab4382d2SGreg Kroah-Hartman 1576ab4382d2SGreg Kroah-Hartman static int __init sunsu_init(void) 1577ab4382d2SGreg Kroah-Hartman { 1578ab4382d2SGreg Kroah-Hartman struct device_node *dp; 1579ab4382d2SGreg Kroah-Hartman int err; 1580ab4382d2SGreg Kroah-Hartman int num_uart = 0; 1581ab4382d2SGreg Kroah-Hartman 1582ab4382d2SGreg Kroah-Hartman for_each_node_by_name(dp, "su") { 1583ab4382d2SGreg Kroah-Hartman if (su_get_type(dp) == SU_PORT_PORT) 1584ab4382d2SGreg Kroah-Hartman num_uart++; 1585ab4382d2SGreg Kroah-Hartman } 1586ab4382d2SGreg Kroah-Hartman for_each_node_by_name(dp, "su_pnp") { 1587ab4382d2SGreg Kroah-Hartman if (su_get_type(dp) == SU_PORT_PORT) 1588ab4382d2SGreg Kroah-Hartman num_uart++; 1589ab4382d2SGreg Kroah-Hartman } 1590ab4382d2SGreg Kroah-Hartman for_each_node_by_name(dp, "serial") { 1591ab4382d2SGreg Kroah-Hartman if (of_device_is_compatible(dp, "su")) { 1592ab4382d2SGreg Kroah-Hartman if (su_get_type(dp) == SU_PORT_PORT) 1593ab4382d2SGreg Kroah-Hartman num_uart++; 1594ab4382d2SGreg Kroah-Hartman } 1595ab4382d2SGreg Kroah-Hartman } 1596ab4382d2SGreg Kroah-Hartman for_each_node_by_type(dp, "serial") { 1597ab4382d2SGreg Kroah-Hartman if (of_device_is_compatible(dp, "su")) { 1598ab4382d2SGreg Kroah-Hartman if (su_get_type(dp) == SU_PORT_PORT) 1599ab4382d2SGreg Kroah-Hartman num_uart++; 1600ab4382d2SGreg Kroah-Hartman } 1601ab4382d2SGreg Kroah-Hartman } 1602ab4382d2SGreg Kroah-Hartman 1603ab4382d2SGreg Kroah-Hartman if (num_uart) { 1604ab4382d2SGreg Kroah-Hartman err = sunserial_register_minors(&sunsu_reg, num_uart); 1605ab4382d2SGreg Kroah-Hartman if (err) 1606ab4382d2SGreg Kroah-Hartman return err; 1607ab4382d2SGreg Kroah-Hartman } 1608ab4382d2SGreg Kroah-Hartman 1609793218dfSGrant Likely err = platform_driver_register(&su_driver); 1610ab4382d2SGreg Kroah-Hartman if (err && num_uart) 1611ab4382d2SGreg Kroah-Hartman sunserial_unregister_minors(&sunsu_reg, num_uart); 1612ab4382d2SGreg Kroah-Hartman 1613ab4382d2SGreg Kroah-Hartman return err; 1614ab4382d2SGreg Kroah-Hartman } 1615ab4382d2SGreg Kroah-Hartman 1616ab4382d2SGreg Kroah-Hartman static void __exit sunsu_exit(void) 1617ab4382d2SGreg Kroah-Hartman { 1618ad348cc5SWei Yongjun platform_driver_unregister(&su_driver); 1619ab4382d2SGreg Kroah-Hartman if (sunsu_reg.nr) 1620ab4382d2SGreg Kroah-Hartman sunserial_unregister_minors(&sunsu_reg, sunsu_reg.nr); 1621ab4382d2SGreg Kroah-Hartman } 1622ab4382d2SGreg Kroah-Hartman 1623ab4382d2SGreg Kroah-Hartman module_init(sunsu_init); 1624ab4382d2SGreg Kroah-Hartman module_exit(sunsu_exit); 1625ab4382d2SGreg Kroah-Hartman 1626ab4382d2SGreg Kroah-Hartman MODULE_AUTHOR("Eddie C. Dost, Peter Zaitcev, and David S. Miller"); 1627ab4382d2SGreg Kroah-Hartman MODULE_DESCRIPTION("Sun SU serial port driver"); 1628ab4382d2SGreg Kroah-Hartman MODULE_VERSION("2.0"); 1629ab4382d2SGreg Kroah-Hartman MODULE_LICENSE("GPL"); 1630