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>
40*29e5c442SRob Herring #include <linux/of.h>
41*29e5c442SRob Herring #include <linux/platform_device.h>
42ab4382d2SGreg Kroah-Hartman
434f1c6581SZihao Tang #include <linux/io.h>
44ab4382d2SGreg Kroah-Hartman #include <asm/irq.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
serial_in(struct uart_sunsu_port * up,int offset)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
serial_out(struct uart_sunsu_port * up,int offset,int value)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 */
serial_icr_write(struct uart_sunsu_port * up,int offset,int value)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 */
__enable_rsa(struct uart_sunsu_port * up)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
enable_rsa(struct uart_sunsu_port * up)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 */
disable_rsa(struct uart_sunsu_port * up)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
__stop_tx(struct uart_sunsu_port * p)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
sunsu_stop_tx(struct uart_port * port)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
sunsu_start_tx(struct uart_port * port)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
sunsu_stop_rx(struct uart_port * port)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
sunsu_enable_ms(struct uart_port * port)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
receive_chars(struct uart_sunsu_port * up,unsigned char * status)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
transmit_chars(struct uart_sunsu_port * up)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]);
4207f20ab70SIlpo Järvinen uart_xmit_advance(&up->port, 1);
421ab4382d2SGreg Kroah-Hartman if (uart_circ_empty(xmit))
422ab4382d2SGreg Kroah-Hartman break;
423ab4382d2SGreg Kroah-Hartman } while (--count > 0);
424ab4382d2SGreg Kroah-Hartman
425ab4382d2SGreg Kroah-Hartman if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
426ab4382d2SGreg Kroah-Hartman uart_write_wakeup(&up->port);
427ab4382d2SGreg Kroah-Hartman
428ab4382d2SGreg Kroah-Hartman if (uart_circ_empty(xmit))
429ab4382d2SGreg Kroah-Hartman __stop_tx(up);
430ab4382d2SGreg Kroah-Hartman }
431ab4382d2SGreg Kroah-Hartman
check_modem_status(struct uart_sunsu_port * up)432ab4382d2SGreg Kroah-Hartman static void check_modem_status(struct uart_sunsu_port *up)
433ab4382d2SGreg Kroah-Hartman {
434ab4382d2SGreg Kroah-Hartman int status;
435ab4382d2SGreg Kroah-Hartman
436ab4382d2SGreg Kroah-Hartman status = serial_in(up, UART_MSR);
437ab4382d2SGreg Kroah-Hartman
438ab4382d2SGreg Kroah-Hartman if ((status & UART_MSR_ANY_DELTA) == 0)
439ab4382d2SGreg Kroah-Hartman return;
440ab4382d2SGreg Kroah-Hartman
441ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_TERI)
442ab4382d2SGreg Kroah-Hartman up->port.icount.rng++;
443ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_DDSR)
444ab4382d2SGreg Kroah-Hartman up->port.icount.dsr++;
445ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_DDCD)
446ab4382d2SGreg Kroah-Hartman uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
447ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_DCTS)
448ab4382d2SGreg Kroah-Hartman uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
449ab4382d2SGreg Kroah-Hartman
450ab4382d2SGreg Kroah-Hartman wake_up_interruptible(&up->port.state->port.delta_msr_wait);
451ab4382d2SGreg Kroah-Hartman }
452ab4382d2SGreg Kroah-Hartman
sunsu_serial_interrupt(int irq,void * dev_id)453ab4382d2SGreg Kroah-Hartman static irqreturn_t sunsu_serial_interrupt(int irq, void *dev_id)
454ab4382d2SGreg Kroah-Hartman {
455ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up = dev_id;
456ab4382d2SGreg Kroah-Hartman unsigned long flags;
457ab4382d2SGreg Kroah-Hartman unsigned char status;
458ab4382d2SGreg Kroah-Hartman
459ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags);
460ab4382d2SGreg Kroah-Hartman
461ab4382d2SGreg Kroah-Hartman do {
462ab4382d2SGreg Kroah-Hartman status = serial_inp(up, UART_LSR);
463ab4382d2SGreg Kroah-Hartman if (status & UART_LSR_DR)
4642e124b4aSJiri Slaby receive_chars(up, &status);
465ab4382d2SGreg Kroah-Hartman check_modem_status(up);
466ab4382d2SGreg Kroah-Hartman if (status & UART_LSR_THRE)
467ab4382d2SGreg Kroah-Hartman transmit_chars(up);
468ab4382d2SGreg Kroah-Hartman
4692e124b4aSJiri Slaby tty_flip_buffer_push(&up->port.state->port);
470ab4382d2SGreg Kroah-Hartman
471ab4382d2SGreg Kroah-Hartman } while (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT));
472ab4382d2SGreg Kroah-Hartman
473ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags);
474ab4382d2SGreg Kroah-Hartman
475ab4382d2SGreg Kroah-Hartman return IRQ_HANDLED;
476ab4382d2SGreg Kroah-Hartman }
477ab4382d2SGreg Kroah-Hartman
478ab4382d2SGreg Kroah-Hartman /* Separate interrupt handling path for keyboard/mouse ports. */
479ab4382d2SGreg Kroah-Hartman
480ab4382d2SGreg Kroah-Hartman static void
481ab4382d2SGreg Kroah-Hartman sunsu_change_speed(struct uart_port *port, unsigned int cflag,
482ab4382d2SGreg Kroah-Hartman unsigned int iflag, unsigned int quot);
483ab4382d2SGreg Kroah-Hartman
sunsu_change_mouse_baud(struct uart_sunsu_port * up)484ab4382d2SGreg Kroah-Hartman static void sunsu_change_mouse_baud(struct uart_sunsu_port *up)
485ab4382d2SGreg Kroah-Hartman {
486ab4382d2SGreg Kroah-Hartman unsigned int cur_cflag = up->cflag;
487ab4382d2SGreg Kroah-Hartman int quot, new_baud;
488ab4382d2SGreg Kroah-Hartman
489ab4382d2SGreg Kroah-Hartman up->cflag &= ~CBAUD;
490ab4382d2SGreg Kroah-Hartman up->cflag |= suncore_mouse_baud_cflag_next(cur_cflag, &new_baud);
491ab4382d2SGreg Kroah-Hartman
492ab4382d2SGreg Kroah-Hartman quot = up->port.uartclk / (16 * new_baud);
493ab4382d2SGreg Kroah-Hartman
494ab4382d2SGreg Kroah-Hartman sunsu_change_speed(&up->port, up->cflag, 0, quot);
495ab4382d2SGreg Kroah-Hartman }
496ab4382d2SGreg Kroah-Hartman
receive_kbd_ms_chars(struct uart_sunsu_port * up,int is_break)497ab4382d2SGreg Kroah-Hartman static void receive_kbd_ms_chars(struct uart_sunsu_port *up, int is_break)
498ab4382d2SGreg Kroah-Hartman {
499ab4382d2SGreg Kroah-Hartman do {
500ab4382d2SGreg Kroah-Hartman unsigned char ch = serial_inp(up, UART_RX);
501ab4382d2SGreg Kroah-Hartman
502ab4382d2SGreg Kroah-Hartman /* Stop-A is handled by drivers/char/keyboard.c now. */
503ab4382d2SGreg Kroah-Hartman if (up->su_type == SU_PORT_KBD) {
504ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO
505ab4382d2SGreg Kroah-Hartman serio_interrupt(&up->serio, ch, 0);
506ab4382d2SGreg Kroah-Hartman #endif
507ab4382d2SGreg Kroah-Hartman } else if (up->su_type == SU_PORT_MS) {
508ab4382d2SGreg Kroah-Hartman int ret = suncore_mouse_baud_detection(ch, is_break);
509ab4382d2SGreg Kroah-Hartman
510ab4382d2SGreg Kroah-Hartman switch (ret) {
511ab4382d2SGreg Kroah-Hartman case 2:
512ab4382d2SGreg Kroah-Hartman sunsu_change_mouse_baud(up);
513df561f66SGustavo A. R. Silva fallthrough;
514ab4382d2SGreg Kroah-Hartman case 1:
515ab4382d2SGreg Kroah-Hartman break;
516ab4382d2SGreg Kroah-Hartman
517ab4382d2SGreg Kroah-Hartman case 0:
518ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO
519ab4382d2SGreg Kroah-Hartman serio_interrupt(&up->serio, ch, 0);
520ab4382d2SGreg Kroah-Hartman #endif
521ab4382d2SGreg Kroah-Hartman break;
522fc811472SJoe Perches }
523ab4382d2SGreg Kroah-Hartman }
524ab4382d2SGreg Kroah-Hartman } while (serial_in(up, UART_LSR) & UART_LSR_DR);
525ab4382d2SGreg Kroah-Hartman }
526ab4382d2SGreg Kroah-Hartman
sunsu_kbd_ms_interrupt(int irq,void * dev_id)527ab4382d2SGreg Kroah-Hartman static irqreturn_t sunsu_kbd_ms_interrupt(int irq, void *dev_id)
528ab4382d2SGreg Kroah-Hartman {
529ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up = dev_id;
530ab4382d2SGreg Kroah-Hartman
531ab4382d2SGreg Kroah-Hartman if (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT)) {
532ab4382d2SGreg Kroah-Hartman unsigned char status = serial_inp(up, UART_LSR);
533ab4382d2SGreg Kroah-Hartman
534ab4382d2SGreg Kroah-Hartman if ((status & UART_LSR_DR) || (status & UART_LSR_BI))
535ab4382d2SGreg Kroah-Hartman receive_kbd_ms_chars(up, (status & UART_LSR_BI) != 0);
536ab4382d2SGreg Kroah-Hartman }
537ab4382d2SGreg Kroah-Hartman
538ab4382d2SGreg Kroah-Hartman return IRQ_HANDLED;
539ab4382d2SGreg Kroah-Hartman }
540ab4382d2SGreg Kroah-Hartman
sunsu_tx_empty(struct uart_port * port)541ab4382d2SGreg Kroah-Hartman static unsigned int sunsu_tx_empty(struct uart_port *port)
542ab4382d2SGreg Kroah-Hartman {
5439a6962c5SFabian Frederick struct uart_sunsu_port *up =
5449a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port);
545ab4382d2SGreg Kroah-Hartman unsigned long flags;
546ab4382d2SGreg Kroah-Hartman unsigned int ret;
547ab4382d2SGreg Kroah-Hartman
548ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags);
549ab4382d2SGreg Kroah-Hartman ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
550ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags);
551ab4382d2SGreg Kroah-Hartman
552ab4382d2SGreg Kroah-Hartman return ret;
553ab4382d2SGreg Kroah-Hartman }
554ab4382d2SGreg Kroah-Hartman
sunsu_get_mctrl(struct uart_port * port)555ab4382d2SGreg Kroah-Hartman static unsigned int sunsu_get_mctrl(struct uart_port *port)
556ab4382d2SGreg Kroah-Hartman {
5579a6962c5SFabian Frederick struct uart_sunsu_port *up =
5589a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port);
559ab4382d2SGreg Kroah-Hartman unsigned char status;
560ab4382d2SGreg Kroah-Hartman unsigned int ret;
561ab4382d2SGreg Kroah-Hartman
562ab4382d2SGreg Kroah-Hartman status = serial_in(up, UART_MSR);
563ab4382d2SGreg Kroah-Hartman
564ab4382d2SGreg Kroah-Hartman ret = 0;
565ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_DCD)
566ab4382d2SGreg Kroah-Hartman ret |= TIOCM_CAR;
567ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_RI)
568ab4382d2SGreg Kroah-Hartman ret |= TIOCM_RNG;
569ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_DSR)
570ab4382d2SGreg Kroah-Hartman ret |= TIOCM_DSR;
571ab4382d2SGreg Kroah-Hartman if (status & UART_MSR_CTS)
572ab4382d2SGreg Kroah-Hartman ret |= TIOCM_CTS;
573ab4382d2SGreg Kroah-Hartman return ret;
574ab4382d2SGreg Kroah-Hartman }
575ab4382d2SGreg Kroah-Hartman
sunsu_set_mctrl(struct uart_port * port,unsigned int mctrl)576ab4382d2SGreg Kroah-Hartman static void sunsu_set_mctrl(struct uart_port *port, unsigned int mctrl)
577ab4382d2SGreg Kroah-Hartman {
5789a6962c5SFabian Frederick struct uart_sunsu_port *up =
5799a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port);
580ab4382d2SGreg Kroah-Hartman unsigned char mcr = 0;
581ab4382d2SGreg Kroah-Hartman
582ab4382d2SGreg Kroah-Hartman if (mctrl & TIOCM_RTS)
583ab4382d2SGreg Kroah-Hartman mcr |= UART_MCR_RTS;
584ab4382d2SGreg Kroah-Hartman if (mctrl & TIOCM_DTR)
585ab4382d2SGreg Kroah-Hartman mcr |= UART_MCR_DTR;
586ab4382d2SGreg Kroah-Hartman if (mctrl & TIOCM_OUT1)
587ab4382d2SGreg Kroah-Hartman mcr |= UART_MCR_OUT1;
588ab4382d2SGreg Kroah-Hartman if (mctrl & TIOCM_OUT2)
589ab4382d2SGreg Kroah-Hartman mcr |= UART_MCR_OUT2;
590ab4382d2SGreg Kroah-Hartman if (mctrl & TIOCM_LOOP)
591ab4382d2SGreg Kroah-Hartman mcr |= UART_MCR_LOOP;
592ab4382d2SGreg Kroah-Hartman
593ab4382d2SGreg Kroah-Hartman serial_out(up, UART_MCR, mcr);
594ab4382d2SGreg Kroah-Hartman }
595ab4382d2SGreg Kroah-Hartman
sunsu_break_ctl(struct uart_port * port,int break_state)596ab4382d2SGreg Kroah-Hartman static void sunsu_break_ctl(struct uart_port *port, int break_state)
597ab4382d2SGreg Kroah-Hartman {
5989a6962c5SFabian Frederick struct uart_sunsu_port *up =
5999a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port);
600ab4382d2SGreg Kroah-Hartman unsigned long flags;
601ab4382d2SGreg Kroah-Hartman
602ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags);
603ab4382d2SGreg Kroah-Hartman if (break_state == -1)
604ab4382d2SGreg Kroah-Hartman up->lcr |= UART_LCR_SBC;
605ab4382d2SGreg Kroah-Hartman else
606ab4382d2SGreg Kroah-Hartman up->lcr &= ~UART_LCR_SBC;
607ab4382d2SGreg Kroah-Hartman serial_out(up, UART_LCR, up->lcr);
608ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags);
609ab4382d2SGreg Kroah-Hartman }
610ab4382d2SGreg Kroah-Hartman
sunsu_startup(struct uart_port * port)611ab4382d2SGreg Kroah-Hartman static int sunsu_startup(struct uart_port *port)
612ab4382d2SGreg Kroah-Hartman {
6139a6962c5SFabian Frederick struct uart_sunsu_port *up =
6149a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port);
615ab4382d2SGreg Kroah-Hartman unsigned long flags;
616ab4382d2SGreg Kroah-Hartman int retval;
617ab4382d2SGreg Kroah-Hartman
618ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16C950) {
619ab4382d2SGreg Kroah-Hartman /* Wake up and initialize UART */
620ab4382d2SGreg Kroah-Hartman up->acr = 0;
621ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0xBF);
622ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_EFR, UART_EFR_ECB);
623ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, 0);
624ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0);
625ab4382d2SGreg Kroah-Hartman serial_icr_write(up, UART_CSR, 0); /* Reset the UART */
626ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0xBF);
627ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_EFR, UART_EFR_ECB);
628ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0);
629ab4382d2SGreg Kroah-Hartman }
630ab4382d2SGreg Kroah-Hartman
631ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIAL_8250_RSA
632ab4382d2SGreg Kroah-Hartman /*
633ab4382d2SGreg Kroah-Hartman * If this is an RSA port, see if we can kick it up to the
634ab4382d2SGreg Kroah-Hartman * higher speed clock.
635ab4382d2SGreg Kroah-Hartman */
636ab4382d2SGreg Kroah-Hartman enable_rsa(up);
637ab4382d2SGreg Kroah-Hartman #endif
638ab4382d2SGreg Kroah-Hartman
639ab4382d2SGreg Kroah-Hartman /*
640ab4382d2SGreg Kroah-Hartman * Clear the FIFO buffers and disable them.
641ab4382d2SGreg Kroah-Hartman * (they will be reenabled in set_termios())
642ab4382d2SGreg Kroah-Hartman */
643ab4382d2SGreg Kroah-Hartman if (uart_config[up->port.type].flags & UART_CLEAR_FIFO) {
644ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
645ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
646ab4382d2SGreg Kroah-Hartman UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
647ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, 0);
648ab4382d2SGreg Kroah-Hartman }
649ab4382d2SGreg Kroah-Hartman
650ab4382d2SGreg Kroah-Hartman /*
651ab4382d2SGreg Kroah-Hartman * Clear the interrupt registers.
652ab4382d2SGreg Kroah-Hartman */
653ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_LSR);
654ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_RX);
655ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_IIR);
656ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_MSR);
657ab4382d2SGreg Kroah-Hartman
658ab4382d2SGreg Kroah-Hartman /*
659ab4382d2SGreg Kroah-Hartman * At this point, there's no way the LSR could still be 0xff;
660ab4382d2SGreg Kroah-Hartman * if it is, then bail out, because there's likely no UART
661ab4382d2SGreg Kroah-Hartman * here.
662ab4382d2SGreg Kroah-Hartman */
663ab4382d2SGreg Kroah-Hartman if (!(up->port.flags & UPF_BUGGY_UART) &&
664ab4382d2SGreg Kroah-Hartman (serial_inp(up, UART_LSR) == 0xff)) {
665ab4382d2SGreg Kroah-Hartman printk("ttyS%d: LSR safety check engaged!\n", up->port.line);
666ab4382d2SGreg Kroah-Hartman return -ENODEV;
667ab4382d2SGreg Kroah-Hartman }
668ab4382d2SGreg Kroah-Hartman
669ab4382d2SGreg Kroah-Hartman if (up->su_type != SU_PORT_PORT) {
670ab4382d2SGreg Kroah-Hartman retval = request_irq(up->port.irq, sunsu_kbd_ms_interrupt,
671ab4382d2SGreg Kroah-Hartman IRQF_SHARED, su_typev[up->su_type], up);
672ab4382d2SGreg Kroah-Hartman } else {
673ab4382d2SGreg Kroah-Hartman retval = request_irq(up->port.irq, sunsu_serial_interrupt,
674ab4382d2SGreg Kroah-Hartman IRQF_SHARED, su_typev[up->su_type], up);
675ab4382d2SGreg Kroah-Hartman }
676ab4382d2SGreg Kroah-Hartman if (retval) {
677ab4382d2SGreg Kroah-Hartman printk("su: Cannot register IRQ %d\n", up->port.irq);
678ab4382d2SGreg Kroah-Hartman return retval;
679ab4382d2SGreg Kroah-Hartman }
680ab4382d2SGreg Kroah-Hartman
681ab4382d2SGreg Kroah-Hartman /*
682ab4382d2SGreg Kroah-Hartman * Now, initialize the UART
683ab4382d2SGreg Kroah-Hartman */
684ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, UART_LCR_WLEN8);
685ab4382d2SGreg Kroah-Hartman
686ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags);
687ab4382d2SGreg Kroah-Hartman
688ab4382d2SGreg Kroah-Hartman up->port.mctrl |= TIOCM_OUT2;
689ab4382d2SGreg Kroah-Hartman
690ab4382d2SGreg Kroah-Hartman sunsu_set_mctrl(&up->port, up->port.mctrl);
691ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags);
692ab4382d2SGreg Kroah-Hartman
693ab4382d2SGreg Kroah-Hartman /*
694ab4382d2SGreg Kroah-Hartman * Finally, enable interrupts. Note: Modem status interrupts
695ab4382d2SGreg Kroah-Hartman * are set via set_termios(), which will be occurring imminently
696ab4382d2SGreg Kroah-Hartman * anyway, so we don't enable them here.
697ab4382d2SGreg Kroah-Hartman */
698ab4382d2SGreg Kroah-Hartman up->ier = UART_IER_RLSI | UART_IER_RDI;
699ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, up->ier);
700ab4382d2SGreg Kroah-Hartman
701ab4382d2SGreg Kroah-Hartman if (up->port.flags & UPF_FOURPORT) {
702ab4382d2SGreg Kroah-Hartman unsigned int icp;
703ab4382d2SGreg Kroah-Hartman /*
704ab4382d2SGreg Kroah-Hartman * Enable interrupts on the AST Fourport board
705ab4382d2SGreg Kroah-Hartman */
706ab4382d2SGreg Kroah-Hartman icp = (up->port.iobase & 0xfe0) | 0x01f;
707ab4382d2SGreg Kroah-Hartman outb_p(0x80, icp);
708ab4382d2SGreg Kroah-Hartman (void) inb_p(icp);
709ab4382d2SGreg Kroah-Hartman }
710ab4382d2SGreg Kroah-Hartman
711ab4382d2SGreg Kroah-Hartman /*
712ab4382d2SGreg Kroah-Hartman * And clear the interrupt registers again for luck.
713ab4382d2SGreg Kroah-Hartman */
714ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_LSR);
715ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_RX);
716ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_IIR);
717ab4382d2SGreg Kroah-Hartman (void) serial_inp(up, UART_MSR);
718ab4382d2SGreg Kroah-Hartman
719ab4382d2SGreg Kroah-Hartman return 0;
720ab4382d2SGreg Kroah-Hartman }
721ab4382d2SGreg Kroah-Hartman
sunsu_shutdown(struct uart_port * port)722ab4382d2SGreg Kroah-Hartman static void sunsu_shutdown(struct uart_port *port)
723ab4382d2SGreg Kroah-Hartman {
7249a6962c5SFabian Frederick struct uart_sunsu_port *up =
7259a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port);
726ab4382d2SGreg Kroah-Hartman unsigned long flags;
727ab4382d2SGreg Kroah-Hartman
728ab4382d2SGreg Kroah-Hartman /*
729ab4382d2SGreg Kroah-Hartman * Disable interrupts from this port
730ab4382d2SGreg Kroah-Hartman */
731ab4382d2SGreg Kroah-Hartman up->ier = 0;
732ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, 0);
733ab4382d2SGreg Kroah-Hartman
734ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags);
735ab4382d2SGreg Kroah-Hartman if (up->port.flags & UPF_FOURPORT) {
736ab4382d2SGreg Kroah-Hartman /* reset interrupts on the AST Fourport board */
737ab4382d2SGreg Kroah-Hartman inb((up->port.iobase & 0xfe0) | 0x1f);
738ab4382d2SGreg Kroah-Hartman up->port.mctrl |= TIOCM_OUT1;
739ab4382d2SGreg Kroah-Hartman } else
740ab4382d2SGreg Kroah-Hartman up->port.mctrl &= ~TIOCM_OUT2;
741ab4382d2SGreg Kroah-Hartman
742ab4382d2SGreg Kroah-Hartman sunsu_set_mctrl(&up->port, up->port.mctrl);
743ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags);
744ab4382d2SGreg Kroah-Hartman
745ab4382d2SGreg Kroah-Hartman /*
746ab4382d2SGreg Kroah-Hartman * Disable break condition and FIFOs
747ab4382d2SGreg Kroah-Hartman */
748ab4382d2SGreg Kroah-Hartman serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC);
749ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
750ab4382d2SGreg Kroah-Hartman UART_FCR_CLEAR_RCVR |
751ab4382d2SGreg Kroah-Hartman UART_FCR_CLEAR_XMIT);
752ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, 0);
753ab4382d2SGreg Kroah-Hartman
754ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIAL_8250_RSA
755ab4382d2SGreg Kroah-Hartman /*
756ab4382d2SGreg Kroah-Hartman * Reset the RSA board back to 115kbps compat mode.
757ab4382d2SGreg Kroah-Hartman */
758ab4382d2SGreg Kroah-Hartman disable_rsa(up);
759ab4382d2SGreg Kroah-Hartman #endif
760ab4382d2SGreg Kroah-Hartman
761ab4382d2SGreg Kroah-Hartman /*
762ab4382d2SGreg Kroah-Hartman * Read data port to reset things.
763ab4382d2SGreg Kroah-Hartman */
764ab4382d2SGreg Kroah-Hartman (void) serial_in(up, UART_RX);
765ab4382d2SGreg Kroah-Hartman
766ab4382d2SGreg Kroah-Hartman free_irq(up->port.irq, up);
767ab4382d2SGreg Kroah-Hartman }
768ab4382d2SGreg Kroah-Hartman
769ab4382d2SGreg Kroah-Hartman static void
sunsu_change_speed(struct uart_port * port,unsigned int cflag,unsigned int iflag,unsigned int quot)770ab4382d2SGreg Kroah-Hartman sunsu_change_speed(struct uart_port *port, unsigned int cflag,
771ab4382d2SGreg Kroah-Hartman unsigned int iflag, unsigned int quot)
772ab4382d2SGreg Kroah-Hartman {
7739a6962c5SFabian Frederick struct uart_sunsu_port *up =
7749a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port);
775ab4382d2SGreg Kroah-Hartman unsigned char cval, fcr = 0;
776ab4382d2SGreg Kroah-Hartman unsigned long flags;
777ab4382d2SGreg Kroah-Hartman
778ab4382d2SGreg Kroah-Hartman switch (cflag & CSIZE) {
779ab4382d2SGreg Kroah-Hartman case CS5:
780ab4382d2SGreg Kroah-Hartman cval = 0x00;
781ab4382d2SGreg Kroah-Hartman break;
782ab4382d2SGreg Kroah-Hartman case CS6:
783ab4382d2SGreg Kroah-Hartman cval = 0x01;
784ab4382d2SGreg Kroah-Hartman break;
785ab4382d2SGreg Kroah-Hartman case CS7:
786ab4382d2SGreg Kroah-Hartman cval = 0x02;
787ab4382d2SGreg Kroah-Hartman break;
788ab4382d2SGreg Kroah-Hartman default:
789ab4382d2SGreg Kroah-Hartman case CS8:
790ab4382d2SGreg Kroah-Hartman cval = 0x03;
791ab4382d2SGreg Kroah-Hartman break;
792ab4382d2SGreg Kroah-Hartman }
793ab4382d2SGreg Kroah-Hartman
794ab4382d2SGreg Kroah-Hartman if (cflag & CSTOPB)
795ab4382d2SGreg Kroah-Hartman cval |= 0x04;
796ab4382d2SGreg Kroah-Hartman if (cflag & PARENB)
797ab4382d2SGreg Kroah-Hartman cval |= UART_LCR_PARITY;
798ab4382d2SGreg Kroah-Hartman if (!(cflag & PARODD))
799ab4382d2SGreg Kroah-Hartman cval |= UART_LCR_EPAR;
800ab4382d2SGreg Kroah-Hartman if (cflag & CMSPAR)
801ab4382d2SGreg Kroah-Hartman cval |= UART_LCR_SPAR;
802ab4382d2SGreg Kroah-Hartman
803ab4382d2SGreg Kroah-Hartman /*
804ab4382d2SGreg Kroah-Hartman * Work around a bug in the Oxford Semiconductor 952 rev B
805ab4382d2SGreg Kroah-Hartman * chip which causes it to seriously miscalculate baud rates
806ab4382d2SGreg Kroah-Hartman * when DLL is 0.
807ab4382d2SGreg Kroah-Hartman */
808ab4382d2SGreg Kroah-Hartman if ((quot & 0xff) == 0 && up->port.type == PORT_16C950 &&
809ab4382d2SGreg Kroah-Hartman up->rev == 0x5201)
810ab4382d2SGreg Kroah-Hartman quot ++;
811ab4382d2SGreg Kroah-Hartman
812ab4382d2SGreg Kroah-Hartman if (uart_config[up->port.type].flags & UART_USE_FIFO) {
813ab4382d2SGreg Kroah-Hartman if ((up->port.uartclk / quot) < (2400 * 16))
814ab4382d2SGreg Kroah-Hartman fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
815ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIAL_8250_RSA
816ab4382d2SGreg Kroah-Hartman else if (up->port.type == PORT_RSA)
817ab4382d2SGreg Kroah-Hartman fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_14;
818ab4382d2SGreg Kroah-Hartman #endif
819ab4382d2SGreg Kroah-Hartman else
820ab4382d2SGreg Kroah-Hartman fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_8;
821ab4382d2SGreg Kroah-Hartman }
822ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16750)
823ab4382d2SGreg Kroah-Hartman fcr |= UART_FCR7_64BYTE;
824ab4382d2SGreg Kroah-Hartman
825ab4382d2SGreg Kroah-Hartman /*
826ab4382d2SGreg Kroah-Hartman * Ok, we're now changing the port state. Do it with
827ab4382d2SGreg Kroah-Hartman * interrupts disabled.
828ab4382d2SGreg Kroah-Hartman */
829ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags);
830ab4382d2SGreg Kroah-Hartman
831ab4382d2SGreg Kroah-Hartman /*
832ab4382d2SGreg Kroah-Hartman * Update the per-port timeout.
833ab4382d2SGreg Kroah-Hartman */
834ab4382d2SGreg Kroah-Hartman uart_update_timeout(port, cflag, (port->uartclk / (16 * quot)));
835ab4382d2SGreg Kroah-Hartman
836ab4382d2SGreg Kroah-Hartman up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
837ab4382d2SGreg Kroah-Hartman if (iflag & INPCK)
838ab4382d2SGreg Kroah-Hartman up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
839ef8b9ddcSPeter Hurley if (iflag & (IGNBRK | BRKINT | PARMRK))
840ab4382d2SGreg Kroah-Hartman up->port.read_status_mask |= UART_LSR_BI;
841ab4382d2SGreg Kroah-Hartman
842ab4382d2SGreg Kroah-Hartman /*
843ab4382d2SGreg Kroah-Hartman * Characteres to ignore
844ab4382d2SGreg Kroah-Hartman */
845ab4382d2SGreg Kroah-Hartman up->port.ignore_status_mask = 0;
846ab4382d2SGreg Kroah-Hartman if (iflag & IGNPAR)
847ab4382d2SGreg Kroah-Hartman up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
848ab4382d2SGreg Kroah-Hartman if (iflag & IGNBRK) {
849ab4382d2SGreg Kroah-Hartman up->port.ignore_status_mask |= UART_LSR_BI;
850ab4382d2SGreg Kroah-Hartman /*
851ab4382d2SGreg Kroah-Hartman * If we're ignoring parity and break indicators,
852ab4382d2SGreg Kroah-Hartman * ignore overruns too (for real raw support).
853ab4382d2SGreg Kroah-Hartman */
854ab4382d2SGreg Kroah-Hartman if (iflag & IGNPAR)
855ab4382d2SGreg Kroah-Hartman up->port.ignore_status_mask |= UART_LSR_OE;
856ab4382d2SGreg Kroah-Hartman }
857ab4382d2SGreg Kroah-Hartman
858ab4382d2SGreg Kroah-Hartman /*
859ab4382d2SGreg Kroah-Hartman * ignore all characters if CREAD is not set
860ab4382d2SGreg Kroah-Hartman */
861ab4382d2SGreg Kroah-Hartman if ((cflag & CREAD) == 0)
862ab4382d2SGreg Kroah-Hartman up->port.ignore_status_mask |= UART_LSR_DR;
863ab4382d2SGreg Kroah-Hartman
864ab4382d2SGreg Kroah-Hartman /*
865ab4382d2SGreg Kroah-Hartman * CTS flow control flag and modem status interrupts
866ab4382d2SGreg Kroah-Hartman */
867ab4382d2SGreg Kroah-Hartman up->ier &= ~UART_IER_MSI;
868ab4382d2SGreg Kroah-Hartman if (UART_ENABLE_MS(&up->port, cflag))
869ab4382d2SGreg Kroah-Hartman up->ier |= UART_IER_MSI;
870ab4382d2SGreg Kroah-Hartman
871ab4382d2SGreg Kroah-Hartman serial_out(up, UART_IER, up->ier);
872ab4382d2SGreg Kroah-Hartman
873ab4382d2SGreg Kroah-Hartman if (uart_config[up->port.type].flags & UART_STARTECH) {
874ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0xBF);
875ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_EFR, cflag & CRTSCTS ? UART_EFR_CTS :0);
876ab4382d2SGreg Kroah-Hartman }
877ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
878ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_DLL, quot & 0xff); /* LS of divisor */
879ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_DLM, quot >> 8); /* MS of divisor */
880ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16750)
881ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, fcr); /* set fcr */
882ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, cval); /* reset DLAB */
883ab4382d2SGreg Kroah-Hartman up->lcr = cval; /* Save LCR */
884ab4382d2SGreg Kroah-Hartman if (up->port.type != PORT_16750) {
885ab4382d2SGreg Kroah-Hartman if (fcr & UART_FCR_ENABLE_FIFO) {
886ab4382d2SGreg Kroah-Hartman /* emulated UARTs (Lucent Venus 167x) need two steps */
887ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
888ab4382d2SGreg Kroah-Hartman }
889ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, fcr); /* set fcr */
890ab4382d2SGreg Kroah-Hartman }
891ab4382d2SGreg Kroah-Hartman
892ab4382d2SGreg Kroah-Hartman up->cflag = cflag;
893ab4382d2SGreg Kroah-Hartman
894ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags);
895ab4382d2SGreg Kroah-Hartman }
896ab4382d2SGreg Kroah-Hartman
897ab4382d2SGreg Kroah-Hartman static void
sunsu_set_termios(struct uart_port * port,struct ktermios * termios,const struct ktermios * old)898ab4382d2SGreg Kroah-Hartman sunsu_set_termios(struct uart_port *port, struct ktermios *termios,
899bec5b814SIlpo Järvinen const struct ktermios *old)
900ab4382d2SGreg Kroah-Hartman {
901ab4382d2SGreg Kroah-Hartman unsigned int baud, quot;
902ab4382d2SGreg Kroah-Hartman
903ab4382d2SGreg Kroah-Hartman /*
904ab4382d2SGreg Kroah-Hartman * Ask the core to calculate the divisor for us.
905ab4382d2SGreg Kroah-Hartman */
906ab4382d2SGreg Kroah-Hartman baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
907ab4382d2SGreg Kroah-Hartman quot = uart_get_divisor(port, baud);
908ab4382d2SGreg Kroah-Hartman
909ab4382d2SGreg Kroah-Hartman sunsu_change_speed(port, termios->c_cflag, termios->c_iflag, quot);
910ab4382d2SGreg Kroah-Hartman }
911ab4382d2SGreg Kroah-Hartman
sunsu_release_port(struct uart_port * port)912ab4382d2SGreg Kroah-Hartman static void sunsu_release_port(struct uart_port *port)
913ab4382d2SGreg Kroah-Hartman {
914ab4382d2SGreg Kroah-Hartman }
915ab4382d2SGreg Kroah-Hartman
sunsu_request_port(struct uart_port * port)916ab4382d2SGreg Kroah-Hartman static int sunsu_request_port(struct uart_port *port)
917ab4382d2SGreg Kroah-Hartman {
918ab4382d2SGreg Kroah-Hartman return 0;
919ab4382d2SGreg Kroah-Hartman }
920ab4382d2SGreg Kroah-Hartman
sunsu_config_port(struct uart_port * port,int flags)921ab4382d2SGreg Kroah-Hartman static void sunsu_config_port(struct uart_port *port, int flags)
922ab4382d2SGreg Kroah-Hartman {
9239a6962c5SFabian Frederick struct uart_sunsu_port *up =
9249a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port);
925ab4382d2SGreg Kroah-Hartman
926ab4382d2SGreg Kroah-Hartman if (flags & UART_CONFIG_TYPE) {
927ab4382d2SGreg Kroah-Hartman /*
928ab4382d2SGreg Kroah-Hartman * We are supposed to call autoconfig here, but this requires
929ab4382d2SGreg Kroah-Hartman * splitting all the OBP probing crap from the UART probing.
930ab4382d2SGreg Kroah-Hartman * We'll do it when we kill sunsu.c altogether.
931ab4382d2SGreg Kroah-Hartman */
932ab4382d2SGreg Kroah-Hartman port->type = up->type_probed; /* XXX */
933ab4382d2SGreg Kroah-Hartman }
934ab4382d2SGreg Kroah-Hartman }
935ab4382d2SGreg Kroah-Hartman
936ab4382d2SGreg Kroah-Hartman static int
sunsu_verify_port(struct uart_port * port,struct serial_struct * ser)937ab4382d2SGreg Kroah-Hartman sunsu_verify_port(struct uart_port *port, struct serial_struct *ser)
938ab4382d2SGreg Kroah-Hartman {
939ab4382d2SGreg Kroah-Hartman return -EINVAL;
940ab4382d2SGreg Kroah-Hartman }
941ab4382d2SGreg Kroah-Hartman
942ab4382d2SGreg Kroah-Hartman static const char *
sunsu_type(struct uart_port * port)943ab4382d2SGreg Kroah-Hartman sunsu_type(struct uart_port *port)
944ab4382d2SGreg Kroah-Hartman {
945ab4382d2SGreg Kroah-Hartman int type = port->type;
946ab4382d2SGreg Kroah-Hartman
947ab4382d2SGreg Kroah-Hartman if (type >= ARRAY_SIZE(uart_config))
948ab4382d2SGreg Kroah-Hartman type = 0;
949ab4382d2SGreg Kroah-Hartman return uart_config[type].name;
950ab4382d2SGreg Kroah-Hartman }
951ab4382d2SGreg Kroah-Hartman
9520bfdbe07SJulia Lawall static const struct uart_ops sunsu_pops = {
953ab4382d2SGreg Kroah-Hartman .tx_empty = sunsu_tx_empty,
954ab4382d2SGreg Kroah-Hartman .set_mctrl = sunsu_set_mctrl,
955ab4382d2SGreg Kroah-Hartman .get_mctrl = sunsu_get_mctrl,
956ab4382d2SGreg Kroah-Hartman .stop_tx = sunsu_stop_tx,
957ab4382d2SGreg Kroah-Hartman .start_tx = sunsu_start_tx,
958ab4382d2SGreg Kroah-Hartman .stop_rx = sunsu_stop_rx,
959ab4382d2SGreg Kroah-Hartman .enable_ms = sunsu_enable_ms,
960ab4382d2SGreg Kroah-Hartman .break_ctl = sunsu_break_ctl,
961ab4382d2SGreg Kroah-Hartman .startup = sunsu_startup,
962ab4382d2SGreg Kroah-Hartman .shutdown = sunsu_shutdown,
963ab4382d2SGreg Kroah-Hartman .set_termios = sunsu_set_termios,
964ab4382d2SGreg Kroah-Hartman .type = sunsu_type,
965ab4382d2SGreg Kroah-Hartman .release_port = sunsu_release_port,
966ab4382d2SGreg Kroah-Hartman .request_port = sunsu_request_port,
967ab4382d2SGreg Kroah-Hartman .config_port = sunsu_config_port,
968ab4382d2SGreg Kroah-Hartman .verify_port = sunsu_verify_port,
969ab4382d2SGreg Kroah-Hartman };
970ab4382d2SGreg Kroah-Hartman
971ab4382d2SGreg Kroah-Hartman #define UART_NR 4
972ab4382d2SGreg Kroah-Hartman
973ab4382d2SGreg Kroah-Hartman static struct uart_sunsu_port sunsu_ports[UART_NR];
974cb29529eSTkhai Kirill static int nr_inst; /* Number of already registered ports */
975ab4382d2SGreg Kroah-Hartman
976ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO
977ab4382d2SGreg Kroah-Hartman
978ab4382d2SGreg Kroah-Hartman static DEFINE_SPINLOCK(sunsu_serio_lock);
979ab4382d2SGreg Kroah-Hartman
sunsu_serio_write(struct serio * serio,unsigned char ch)980ab4382d2SGreg Kroah-Hartman static int sunsu_serio_write(struct serio *serio, unsigned char ch)
981ab4382d2SGreg Kroah-Hartman {
982ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up = serio->port_data;
983ab4382d2SGreg Kroah-Hartman unsigned long flags;
984ab4382d2SGreg Kroah-Hartman int lsr;
985ab4382d2SGreg Kroah-Hartman
986ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&sunsu_serio_lock, flags);
987ab4382d2SGreg Kroah-Hartman
988ab4382d2SGreg Kroah-Hartman do {
989ab4382d2SGreg Kroah-Hartman lsr = serial_in(up, UART_LSR);
990ab4382d2SGreg Kroah-Hartman } while (!(lsr & UART_LSR_THRE));
991ab4382d2SGreg Kroah-Hartman
992ab4382d2SGreg Kroah-Hartman /* Send the character out. */
993ab4382d2SGreg Kroah-Hartman serial_out(up, UART_TX, ch);
994ab4382d2SGreg Kroah-Hartman
995ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&sunsu_serio_lock, flags);
996ab4382d2SGreg Kroah-Hartman
997ab4382d2SGreg Kroah-Hartman return 0;
998ab4382d2SGreg Kroah-Hartman }
999ab4382d2SGreg Kroah-Hartman
sunsu_serio_open(struct serio * serio)1000ab4382d2SGreg Kroah-Hartman static int sunsu_serio_open(struct serio *serio)
1001ab4382d2SGreg Kroah-Hartman {
1002ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up = serio->port_data;
1003ab4382d2SGreg Kroah-Hartman unsigned long flags;
1004ab4382d2SGreg Kroah-Hartman int ret;
1005ab4382d2SGreg Kroah-Hartman
1006ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&sunsu_serio_lock, flags);
1007ab4382d2SGreg Kroah-Hartman if (!up->serio_open) {
1008ab4382d2SGreg Kroah-Hartman up->serio_open = 1;
1009ab4382d2SGreg Kroah-Hartman ret = 0;
1010ab4382d2SGreg Kroah-Hartman } else
1011ab4382d2SGreg Kroah-Hartman ret = -EBUSY;
1012ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&sunsu_serio_lock, flags);
1013ab4382d2SGreg Kroah-Hartman
1014ab4382d2SGreg Kroah-Hartman return ret;
1015ab4382d2SGreg Kroah-Hartman }
1016ab4382d2SGreg Kroah-Hartman
sunsu_serio_close(struct serio * serio)1017ab4382d2SGreg Kroah-Hartman static void sunsu_serio_close(struct serio *serio)
1018ab4382d2SGreg Kroah-Hartman {
1019ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up = serio->port_data;
1020ab4382d2SGreg Kroah-Hartman unsigned long flags;
1021ab4382d2SGreg Kroah-Hartman
1022ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&sunsu_serio_lock, flags);
1023ab4382d2SGreg Kroah-Hartman up->serio_open = 0;
1024ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&sunsu_serio_lock, flags);
1025ab4382d2SGreg Kroah-Hartman }
1026ab4382d2SGreg Kroah-Hartman
1027ab4382d2SGreg Kroah-Hartman #endif /* CONFIG_SERIO */
1028ab4382d2SGreg Kroah-Hartman
sunsu_autoconfig(struct uart_sunsu_port * up)1029ab4382d2SGreg Kroah-Hartman static void sunsu_autoconfig(struct uart_sunsu_port *up)
1030ab4382d2SGreg Kroah-Hartman {
1031ab4382d2SGreg Kroah-Hartman unsigned char status1, status2, scratch, scratch2, scratch3;
1032ab4382d2SGreg Kroah-Hartman unsigned char save_lcr, save_mcr;
1033ab4382d2SGreg Kroah-Hartman unsigned long flags;
1034ab4382d2SGreg Kroah-Hartman
1035ab4382d2SGreg Kroah-Hartman if (up->su_type == SU_PORT_NONE)
1036ab4382d2SGreg Kroah-Hartman return;
1037ab4382d2SGreg Kroah-Hartman
1038ab4382d2SGreg Kroah-Hartman up->type_probed = PORT_UNKNOWN;
1039ab4382d2SGreg Kroah-Hartman up->port.iotype = UPIO_MEM;
1040ab4382d2SGreg Kroah-Hartman
1041ab4382d2SGreg Kroah-Hartman spin_lock_irqsave(&up->port.lock, flags);
1042ab4382d2SGreg Kroah-Hartman
1043ab4382d2SGreg Kroah-Hartman if (!(up->port.flags & UPF_BUGGY_UART)) {
1044ab4382d2SGreg Kroah-Hartman /*
1045ab4382d2SGreg Kroah-Hartman * Do a simple existence test first; if we fail this, there's
1046ab4382d2SGreg Kroah-Hartman * no point trying anything else.
1047ab4382d2SGreg Kroah-Hartman *
1048ab4382d2SGreg Kroah-Hartman * 0x80 is used as a nonsense port to prevent against false
1049ab4382d2SGreg Kroah-Hartman * positives due to ISA bus float. The assumption is that
1050ab4382d2SGreg Kroah-Hartman * 0x80 is a non-existent port; which should be safe since
1051ab4382d2SGreg Kroah-Hartman * include/asm/io.h also makes this assumption.
1052ab4382d2SGreg Kroah-Hartman */
1053ab4382d2SGreg Kroah-Hartman scratch = serial_inp(up, UART_IER);
1054ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, 0);
1055ab4382d2SGreg Kroah-Hartman #ifdef __i386__
1056ab4382d2SGreg Kroah-Hartman outb(0xff, 0x080);
1057ab4382d2SGreg Kroah-Hartman #endif
1058ab4382d2SGreg Kroah-Hartman scratch2 = serial_inp(up, UART_IER);
1059ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, 0x0f);
1060ab4382d2SGreg Kroah-Hartman #ifdef __i386__
1061ab4382d2SGreg Kroah-Hartman outb(0, 0x080);
1062ab4382d2SGreg Kroah-Hartman #endif
1063ab4382d2SGreg Kroah-Hartman scratch3 = serial_inp(up, UART_IER);
1064ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, scratch);
1065ab4382d2SGreg Kroah-Hartman if (scratch2 != 0 || scratch3 != 0x0F)
1066ab4382d2SGreg Kroah-Hartman goto out; /* We failed; there's nothing here */
1067ab4382d2SGreg Kroah-Hartman }
1068ab4382d2SGreg Kroah-Hartman
1069ab4382d2SGreg Kroah-Hartman save_mcr = serial_in(up, UART_MCR);
1070ab4382d2SGreg Kroah-Hartman save_lcr = serial_in(up, UART_LCR);
1071ab4382d2SGreg Kroah-Hartman
1072ab4382d2SGreg Kroah-Hartman /*
1073ab4382d2SGreg Kroah-Hartman * Check to see if a UART is really there. Certain broken
1074ab4382d2SGreg Kroah-Hartman * internal modems based on the Rockwell chipset fail this
1075ab4382d2SGreg Kroah-Hartman * test, because they apparently don't implement the loopback
1076ab4382d2SGreg Kroah-Hartman * test mode. So this test is skipped on the COM 1 through
1077ab4382d2SGreg Kroah-Hartman * COM 4 ports. This *should* be safe, since no board
1078ab4382d2SGreg Kroah-Hartman * manufacturer would be stupid enough to design a board
1079ab4382d2SGreg Kroah-Hartman * that conflicts with COM 1-4 --- we hope!
1080ab4382d2SGreg Kroah-Hartman */
1081ab4382d2SGreg Kroah-Hartman if (!(up->port.flags & UPF_SKIP_TEST)) {
1082ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A);
1083ab4382d2SGreg Kroah-Hartman status1 = serial_inp(up, UART_MSR) & 0xF0;
1084ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_MCR, save_mcr);
1085ab4382d2SGreg Kroah-Hartman if (status1 != 0x90)
1086ab4382d2SGreg Kroah-Hartman goto out; /* We failed loopback test */
1087ab4382d2SGreg Kroah-Hartman }
1088ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0xBF); /* set up for StarTech test */
1089ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_EFR, 0); /* EFR is the same as FCR */
1090ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0);
1091ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
1092ab4382d2SGreg Kroah-Hartman scratch = serial_in(up, UART_IIR) >> 6;
1093ab4382d2SGreg Kroah-Hartman switch (scratch) {
1094ab4382d2SGreg Kroah-Hartman case 0:
1095ab4382d2SGreg Kroah-Hartman up->port.type = PORT_16450;
1096ab4382d2SGreg Kroah-Hartman break;
1097ab4382d2SGreg Kroah-Hartman case 1:
1098ab4382d2SGreg Kroah-Hartman up->port.type = PORT_UNKNOWN;
1099ab4382d2SGreg Kroah-Hartman break;
1100ab4382d2SGreg Kroah-Hartman case 2:
1101ab4382d2SGreg Kroah-Hartman up->port.type = PORT_16550;
1102ab4382d2SGreg Kroah-Hartman break;
1103ab4382d2SGreg Kroah-Hartman case 3:
1104ab4382d2SGreg Kroah-Hartman up->port.type = PORT_16550A;
1105ab4382d2SGreg Kroah-Hartman break;
1106ab4382d2SGreg Kroah-Hartman }
1107ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16550A) {
1108ab4382d2SGreg Kroah-Hartman /* Check for Startech UART's */
1109ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, UART_LCR_DLAB);
1110ab4382d2SGreg Kroah-Hartman if (serial_in(up, UART_EFR) == 0) {
1111ab4382d2SGreg Kroah-Hartman up->port.type = PORT_16650;
1112ab4382d2SGreg Kroah-Hartman } else {
1113ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0xBF);
1114ab4382d2SGreg Kroah-Hartman if (serial_in(up, UART_EFR) == 0)
1115ab4382d2SGreg Kroah-Hartman up->port.type = PORT_16650V2;
1116ab4382d2SGreg Kroah-Hartman }
1117ab4382d2SGreg Kroah-Hartman }
1118ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16550A) {
1119ab4382d2SGreg Kroah-Hartman /* Check for TI 16750 */
1120ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, save_lcr | UART_LCR_DLAB);
1121ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR,
1122ab4382d2SGreg Kroah-Hartman UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
1123ab4382d2SGreg Kroah-Hartman scratch = serial_in(up, UART_IIR) >> 5;
1124ab4382d2SGreg Kroah-Hartman if (scratch == 7) {
1125ab4382d2SGreg Kroah-Hartman /*
1126ab4382d2SGreg Kroah-Hartman * If this is a 16750, and not a cheap UART
1127ab4382d2SGreg Kroah-Hartman * clone, then it should only go into 64 byte
1128ab4382d2SGreg Kroah-Hartman * mode if the UART_FCR7_64BYTE bit was set
1129ab4382d2SGreg Kroah-Hartman * while UART_LCR_DLAB was latched.
1130ab4382d2SGreg Kroah-Hartman */
1131ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
1132ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, 0);
1133ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR,
1134ab4382d2SGreg Kroah-Hartman UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
1135ab4382d2SGreg Kroah-Hartman scratch = serial_in(up, UART_IIR) >> 5;
1136ab4382d2SGreg Kroah-Hartman if (scratch == 6)
1137ab4382d2SGreg Kroah-Hartman up->port.type = PORT_16750;
1138ab4382d2SGreg Kroah-Hartman }
1139ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
1140ab4382d2SGreg Kroah-Hartman }
1141ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_LCR, save_lcr);
1142ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_16450) {
1143ab4382d2SGreg Kroah-Hartman scratch = serial_in(up, UART_SCR);
1144ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_SCR, 0xa5);
1145ab4382d2SGreg Kroah-Hartman status1 = serial_in(up, UART_SCR);
1146ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_SCR, 0x5a);
1147ab4382d2SGreg Kroah-Hartman status2 = serial_in(up, UART_SCR);
1148ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_SCR, scratch);
1149ab4382d2SGreg Kroah-Hartman
1150ab4382d2SGreg Kroah-Hartman if ((status1 != 0xa5) || (status2 != 0x5a))
1151ab4382d2SGreg Kroah-Hartman up->port.type = PORT_8250;
1152ab4382d2SGreg Kroah-Hartman }
1153ab4382d2SGreg Kroah-Hartman
1154ab4382d2SGreg Kroah-Hartman up->port.fifosize = uart_config[up->port.type].dfl_xmit_fifo_size;
1155ab4382d2SGreg Kroah-Hartman
1156ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_UNKNOWN)
1157ab4382d2SGreg Kroah-Hartman goto out;
1158ab4382d2SGreg Kroah-Hartman up->type_probed = up->port.type; /* XXX */
1159ab4382d2SGreg Kroah-Hartman
1160ab4382d2SGreg Kroah-Hartman /*
1161ab4382d2SGreg Kroah-Hartman * Reset the UART.
1162ab4382d2SGreg Kroah-Hartman */
1163ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIAL_8250_RSA
1164ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_RSA)
1165ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_RSA_FRR, 0);
1166ab4382d2SGreg Kroah-Hartman #endif
1167ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_MCR, save_mcr);
1168ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, (UART_FCR_ENABLE_FIFO |
1169ab4382d2SGreg Kroah-Hartman UART_FCR_CLEAR_RCVR |
1170ab4382d2SGreg Kroah-Hartman UART_FCR_CLEAR_XMIT));
1171ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_FCR, 0);
1172ab4382d2SGreg Kroah-Hartman (void)serial_in(up, UART_RX);
1173ab4382d2SGreg Kroah-Hartman serial_outp(up, UART_IER, 0);
1174ab4382d2SGreg Kroah-Hartman
1175ab4382d2SGreg Kroah-Hartman out:
1176ab4382d2SGreg Kroah-Hartman spin_unlock_irqrestore(&up->port.lock, flags);
1177ab4382d2SGreg Kroah-Hartman }
1178ab4382d2SGreg Kroah-Hartman
1179ab4382d2SGreg Kroah-Hartman static struct uart_driver sunsu_reg = {
1180ab4382d2SGreg Kroah-Hartman .owner = THIS_MODULE,
1181ab4382d2SGreg Kroah-Hartman .driver_name = "sunsu",
1182ab4382d2SGreg Kroah-Hartman .dev_name = "ttyS",
1183ab4382d2SGreg Kroah-Hartman .major = TTY_MAJOR,
1184ab4382d2SGreg Kroah-Hartman };
1185ab4382d2SGreg Kroah-Hartman
sunsu_kbd_ms_init(struct uart_sunsu_port * up)11869671f099SBill Pemberton static int sunsu_kbd_ms_init(struct uart_sunsu_port *up)
1187ab4382d2SGreg Kroah-Hartman {
1188ab4382d2SGreg Kroah-Hartman int quot, baud;
1189ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO
1190ab4382d2SGreg Kroah-Hartman struct serio *serio;
1191ab4382d2SGreg Kroah-Hartman #endif
1192ab4382d2SGreg Kroah-Hartman
1193ab4382d2SGreg Kroah-Hartman if (up->su_type == SU_PORT_KBD) {
1194ab4382d2SGreg Kroah-Hartman up->cflag = B1200 | CS8 | CLOCAL | CREAD;
1195ab4382d2SGreg Kroah-Hartman baud = 1200;
1196ab4382d2SGreg Kroah-Hartman } else {
1197ab4382d2SGreg Kroah-Hartman up->cflag = B4800 | CS8 | CLOCAL | CREAD;
1198ab4382d2SGreg Kroah-Hartman baud = 4800;
1199ab4382d2SGreg Kroah-Hartman }
1200ab4382d2SGreg Kroah-Hartman quot = up->port.uartclk / (16 * baud);
1201ab4382d2SGreg Kroah-Hartman
1202ab4382d2SGreg Kroah-Hartman sunsu_autoconfig(up);
1203ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_UNKNOWN)
1204ab4382d2SGreg Kroah-Hartman return -ENODEV;
1205ab4382d2SGreg Kroah-Hartman
1206a73ee843SRob Herring printk("%pOF: %s port at %llx, irq %u\n",
1207a73ee843SRob Herring up->port.dev->of_node,
1208ab4382d2SGreg Kroah-Hartman (up->su_type == SU_PORT_KBD) ? "Keyboard" : "Mouse",
1209ab4382d2SGreg Kroah-Hartman (unsigned long long) up->port.mapbase,
1210ab4382d2SGreg Kroah-Hartman up->port.irq);
1211ab4382d2SGreg Kroah-Hartman
1212ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO
1213ab4382d2SGreg Kroah-Hartman serio = &up->serio;
1214ab4382d2SGreg Kroah-Hartman serio->port_data = up;
1215ab4382d2SGreg Kroah-Hartman
1216ab4382d2SGreg Kroah-Hartman serio->id.type = SERIO_RS232;
1217ab4382d2SGreg Kroah-Hartman if (up->su_type == SU_PORT_KBD) {
1218ab4382d2SGreg Kroah-Hartman serio->id.proto = SERIO_SUNKBD;
1219eb9e109dSWolfram Sang strscpy(serio->name, "sukbd", sizeof(serio->name));
1220ab4382d2SGreg Kroah-Hartman } else {
1221ab4382d2SGreg Kroah-Hartman serio->id.proto = SERIO_SUN;
1222ab4382d2SGreg Kroah-Hartman serio->id.extra = 1;
1223eb9e109dSWolfram Sang strscpy(serio->name, "sums", sizeof(serio->name));
1224ab4382d2SGreg Kroah-Hartman }
1225eb9e109dSWolfram Sang strscpy(serio->phys,
1226ab4382d2SGreg Kroah-Hartman (!(up->port.line & 1) ? "su/serio0" : "su/serio1"),
1227ab4382d2SGreg Kroah-Hartman sizeof(serio->phys));
1228ab4382d2SGreg Kroah-Hartman
1229ab4382d2SGreg Kroah-Hartman serio->write = sunsu_serio_write;
1230ab4382d2SGreg Kroah-Hartman serio->open = sunsu_serio_open;
1231ab4382d2SGreg Kroah-Hartman serio->close = sunsu_serio_close;
1232ab4382d2SGreg Kroah-Hartman serio->dev.parent = up->port.dev;
1233ab4382d2SGreg Kroah-Hartman
1234ab4382d2SGreg Kroah-Hartman serio_register_port(serio);
1235ab4382d2SGreg Kroah-Hartman #endif
1236ab4382d2SGreg Kroah-Hartman
1237ab4382d2SGreg Kroah-Hartman sunsu_change_speed(&up->port, up->cflag, 0, quot);
1238ab4382d2SGreg Kroah-Hartman
1239ab4382d2SGreg Kroah-Hartman sunsu_startup(&up->port);
1240ab4382d2SGreg Kroah-Hartman return 0;
1241ab4382d2SGreg Kroah-Hartman }
1242ab4382d2SGreg Kroah-Hartman
1243ab4382d2SGreg Kroah-Hartman /*
1244ab4382d2SGreg Kroah-Hartman * ------------------------------------------------------------
1245ab4382d2SGreg Kroah-Hartman * Serial console driver
1246ab4382d2SGreg Kroah-Hartman * ------------------------------------------------------------
1247ab4382d2SGreg Kroah-Hartman */
1248ab4382d2SGreg Kroah-Hartman
1249ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIAL_SUNSU_CONSOLE
1250ab4382d2SGreg Kroah-Hartman
1251ab4382d2SGreg Kroah-Hartman /*
1252ab4382d2SGreg Kroah-Hartman * Wait for transmitter & holding register to empty
1253ab4382d2SGreg Kroah-Hartman */
wait_for_xmitr(struct uart_sunsu_port * up)12540d5547caSDenys Vlasenko static void wait_for_xmitr(struct uart_sunsu_port *up)
1255ab4382d2SGreg Kroah-Hartman {
1256ab4382d2SGreg Kroah-Hartman unsigned int status, tmout = 10000;
1257ab4382d2SGreg Kroah-Hartman
1258ab4382d2SGreg Kroah-Hartman /* Wait up to 10ms for the character(s) to be sent. */
1259ab4382d2SGreg Kroah-Hartman do {
1260ab4382d2SGreg Kroah-Hartman status = serial_in(up, UART_LSR);
1261ab4382d2SGreg Kroah-Hartman
1262ab4382d2SGreg Kroah-Hartman if (status & UART_LSR_BI)
1263ab4382d2SGreg Kroah-Hartman up->lsr_break_flag = UART_LSR_BI;
1264ab4382d2SGreg Kroah-Hartman
1265ab4382d2SGreg Kroah-Hartman if (--tmout == 0)
1266ab4382d2SGreg Kroah-Hartman break;
1267ab4382d2SGreg Kroah-Hartman udelay(1);
126834619de1SIlpo Järvinen } while (!uart_lsr_tx_empty(status));
1269ab4382d2SGreg Kroah-Hartman
1270ab4382d2SGreg Kroah-Hartman /* Wait up to 1s for flow control if necessary */
1271ab4382d2SGreg Kroah-Hartman if (up->port.flags & UPF_CONS_FLOW) {
1272ab4382d2SGreg Kroah-Hartman tmout = 1000000;
1273ab4382d2SGreg Kroah-Hartman while (--tmout &&
1274ab4382d2SGreg Kroah-Hartman ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0))
1275ab4382d2SGreg Kroah-Hartman udelay(1);
1276ab4382d2SGreg Kroah-Hartman }
1277ab4382d2SGreg Kroah-Hartman }
1278ab4382d2SGreg Kroah-Hartman
sunsu_console_putchar(struct uart_port * port,unsigned char ch)12793f8bab17SJiri Slaby static void sunsu_console_putchar(struct uart_port *port, unsigned char ch)
1280ab4382d2SGreg Kroah-Hartman {
12819a6962c5SFabian Frederick struct uart_sunsu_port *up =
12829a6962c5SFabian Frederick container_of(port, struct uart_sunsu_port, port);
1283ab4382d2SGreg Kroah-Hartman
1284ab4382d2SGreg Kroah-Hartman wait_for_xmitr(up);
1285ab4382d2SGreg Kroah-Hartman serial_out(up, UART_TX, ch);
1286ab4382d2SGreg Kroah-Hartman }
1287ab4382d2SGreg Kroah-Hartman
1288ab4382d2SGreg Kroah-Hartman /*
1289ab4382d2SGreg Kroah-Hartman * Print a string to the serial port trying not to disturb
1290ab4382d2SGreg Kroah-Hartman * any possible real use of the port...
1291ab4382d2SGreg Kroah-Hartman */
sunsu_console_write(struct console * co,const char * s,unsigned int count)1292ab4382d2SGreg Kroah-Hartman static void sunsu_console_write(struct console *co, const char *s,
1293ab4382d2SGreg Kroah-Hartman unsigned int count)
1294ab4382d2SGreg Kroah-Hartman {
1295ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up = &sunsu_ports[co->index];
1296ab4382d2SGreg Kroah-Hartman unsigned long flags;
1297ab4382d2SGreg Kroah-Hartman unsigned int ier;
1298ab4382d2SGreg Kroah-Hartman int locked = 1;
1299ab4382d2SGreg Kroah-Hartman
1300e58e241cSDavid Miller if (up->port.sysrq || oops_in_progress)
1301e58e241cSDavid Miller locked = spin_trylock_irqsave(&up->port.lock, flags);
1302e58e241cSDavid Miller else
1303e58e241cSDavid Miller spin_lock_irqsave(&up->port.lock, flags);
1304ab4382d2SGreg Kroah-Hartman
1305ab4382d2SGreg Kroah-Hartman /*
1306ab4382d2SGreg Kroah-Hartman * First save the UER then disable the interrupts
1307ab4382d2SGreg Kroah-Hartman */
1308ab4382d2SGreg Kroah-Hartman ier = serial_in(up, UART_IER);
1309ab4382d2SGreg Kroah-Hartman serial_out(up, UART_IER, 0);
1310ab4382d2SGreg Kroah-Hartman
1311ab4382d2SGreg Kroah-Hartman uart_console_write(&up->port, s, count, sunsu_console_putchar);
1312ab4382d2SGreg Kroah-Hartman
1313ab4382d2SGreg Kroah-Hartman /*
1314ab4382d2SGreg Kroah-Hartman * Finally, wait for transmitter to become empty
1315ab4382d2SGreg Kroah-Hartman * and restore the IER
1316ab4382d2SGreg Kroah-Hartman */
1317ab4382d2SGreg Kroah-Hartman wait_for_xmitr(up);
1318ab4382d2SGreg Kroah-Hartman serial_out(up, UART_IER, ier);
1319ab4382d2SGreg Kroah-Hartman
1320ab4382d2SGreg Kroah-Hartman if (locked)
1321e58e241cSDavid Miller spin_unlock_irqrestore(&up->port.lock, flags);
1322ab4382d2SGreg Kroah-Hartman }
1323ab4382d2SGreg Kroah-Hartman
1324ab4382d2SGreg Kroah-Hartman /*
1325ab4382d2SGreg Kroah-Hartman * Setup initial baud/bits/parity. We do two things here:
1326ab4382d2SGreg Kroah-Hartman * - construct a cflag setting for the first su_open()
1327ab4382d2SGreg Kroah-Hartman * - initialize the serial port
1328ab4382d2SGreg Kroah-Hartman * Return non-zero if we didn't find a serial port.
1329ab4382d2SGreg Kroah-Hartman */
sunsu_console_setup(struct console * co,char * options)1330ab4382d2SGreg Kroah-Hartman static int __init sunsu_console_setup(struct console *co, char *options)
1331ab4382d2SGreg Kroah-Hartman {
1332ab4382d2SGreg Kroah-Hartman static struct ktermios dummy;
1333ab4382d2SGreg Kroah-Hartman struct ktermios termios;
1334ab4382d2SGreg Kroah-Hartman struct uart_port *port;
1335ab4382d2SGreg Kroah-Hartman
1336ab4382d2SGreg Kroah-Hartman printk("Console: ttyS%d (SU)\n",
1337ab4382d2SGreg Kroah-Hartman (sunsu_reg.minor - 64) + co->index);
1338ab4382d2SGreg Kroah-Hartman
1339cb29529eSTkhai Kirill if (co->index > nr_inst)
1340cb29529eSTkhai Kirill return -ENODEV;
1341ab4382d2SGreg Kroah-Hartman port = &sunsu_ports[co->index].port;
1342ab4382d2SGreg Kroah-Hartman
1343ab4382d2SGreg Kroah-Hartman /*
1344ab4382d2SGreg Kroah-Hartman * Temporary fix.
1345ab4382d2SGreg Kroah-Hartman */
1346ab4382d2SGreg Kroah-Hartman spin_lock_init(&port->lock);
1347ab4382d2SGreg Kroah-Hartman
1348ab4382d2SGreg Kroah-Hartman /* Get firmware console settings. */
1349ab4382d2SGreg Kroah-Hartman sunserial_console_termios(co, port->dev->of_node);
1350ab4382d2SGreg Kroah-Hartman
1351ab4382d2SGreg Kroah-Hartman memset(&termios, 0, sizeof(struct ktermios));
1352ab4382d2SGreg Kroah-Hartman termios.c_cflag = co->cflag;
1353ab4382d2SGreg Kroah-Hartman port->mctrl |= TIOCM_DTR;
1354ab4382d2SGreg Kroah-Hartman port->ops->set_termios(port, &termios, &dummy);
1355ab4382d2SGreg Kroah-Hartman
1356ab4382d2SGreg Kroah-Hartman return 0;
1357ab4382d2SGreg Kroah-Hartman }
1358ab4382d2SGreg Kroah-Hartman
1359ab4382d2SGreg Kroah-Hartman static struct console sunsu_console = {
1360ab4382d2SGreg Kroah-Hartman .name = "ttyS",
1361ab4382d2SGreg Kroah-Hartman .write = sunsu_console_write,
1362ab4382d2SGreg Kroah-Hartman .device = uart_console_device,
1363ab4382d2SGreg Kroah-Hartman .setup = sunsu_console_setup,
1364ab4382d2SGreg Kroah-Hartman .flags = CON_PRINTBUFFER,
1365ab4382d2SGreg Kroah-Hartman .index = -1,
1366ab4382d2SGreg Kroah-Hartman .data = &sunsu_reg,
1367ab4382d2SGreg Kroah-Hartman };
1368ab4382d2SGreg Kroah-Hartman
1369ab4382d2SGreg Kroah-Hartman /*
1370ab4382d2SGreg Kroah-Hartman * Register console.
1371ab4382d2SGreg Kroah-Hartman */
1372ab4382d2SGreg Kroah-Hartman
SUNSU_CONSOLE(void)1373ab4382d2SGreg Kroah-Hartman static inline struct console *SUNSU_CONSOLE(void)
1374ab4382d2SGreg Kroah-Hartman {
1375ab4382d2SGreg Kroah-Hartman return &sunsu_console;
1376ab4382d2SGreg Kroah-Hartman }
1377ab4382d2SGreg Kroah-Hartman #else
1378ab4382d2SGreg Kroah-Hartman #define SUNSU_CONSOLE() (NULL)
1379ab4382d2SGreg Kroah-Hartman #define sunsu_serial_console_init() do { } while (0)
1380ab4382d2SGreg Kroah-Hartman #endif
1381ab4382d2SGreg Kroah-Hartman
su_get_type(struct device_node * dp)13829671f099SBill Pemberton static enum su_type su_get_type(struct device_node *dp)
1383ab4382d2SGreg Kroah-Hartman {
1384ab4382d2SGreg Kroah-Hartman struct device_node *ap = of_find_node_by_path("/aliases");
1385d430aff8SYangtao Li enum su_type rc = SU_PORT_PORT;
1386ab4382d2SGreg Kroah-Hartman
1387ab4382d2SGreg Kroah-Hartman if (ap) {
1388ab4382d2SGreg Kroah-Hartman const char *keyb = of_get_property(ap, "keyboard", NULL);
1389ab4382d2SGreg Kroah-Hartman const char *ms = of_get_property(ap, "mouse", NULL);
1390d430aff8SYangtao Li struct device_node *match;
1391ab4382d2SGreg Kroah-Hartman
1392ab4382d2SGreg Kroah-Hartman if (keyb) {
1393d430aff8SYangtao Li match = of_find_node_by_path(keyb);
1394d430aff8SYangtao Li
1395d430aff8SYangtao Li /*
1396d430aff8SYangtao Li * The pointer is used as an identifier not
1397d430aff8SYangtao Li * as a pointer, we can drop the refcount on
1398d430aff8SYangtao Li * the of__node immediately after getting it.
1399d430aff8SYangtao Li */
1400d430aff8SYangtao Li of_node_put(match);
1401d430aff8SYangtao Li
1402d430aff8SYangtao Li if (dp == match) {
1403d430aff8SYangtao Li rc = SU_PORT_KBD;
1404d430aff8SYangtao Li goto out;
1405d430aff8SYangtao Li }
1406ab4382d2SGreg Kroah-Hartman }
1407ab4382d2SGreg Kroah-Hartman if (ms) {
1408d430aff8SYangtao Li match = of_find_node_by_path(ms);
1409d430aff8SYangtao Li
1410d430aff8SYangtao Li of_node_put(match);
1411d430aff8SYangtao Li
1412d430aff8SYangtao Li if (dp == match) {
1413d430aff8SYangtao Li rc = SU_PORT_MS;
1414d430aff8SYangtao Li goto out;
1415d430aff8SYangtao Li }
1416ab4382d2SGreg Kroah-Hartman }
1417ab4382d2SGreg Kroah-Hartman }
1418ab4382d2SGreg Kroah-Hartman
1419d430aff8SYangtao Li out:
1420d430aff8SYangtao Li of_node_put(ap);
1421d430aff8SYangtao Li return rc;
1422ab4382d2SGreg Kroah-Hartman }
1423ab4382d2SGreg Kroah-Hartman
su_probe(struct platform_device * op)14249671f099SBill Pemberton static int su_probe(struct platform_device *op)
1425ab4382d2SGreg Kroah-Hartman {
1426ab4382d2SGreg Kroah-Hartman struct device_node *dp = op->dev.of_node;
1427ab4382d2SGreg Kroah-Hartman struct uart_sunsu_port *up;
1428ab4382d2SGreg Kroah-Hartman struct resource *rp;
1429ab4382d2SGreg Kroah-Hartman enum su_type type;
1430ab4382d2SGreg Kroah-Hartman bool ignore_line;
1431ab4382d2SGreg Kroah-Hartman int err;
1432ab4382d2SGreg Kroah-Hartman
1433ab4382d2SGreg Kroah-Hartman type = su_get_type(dp);
1434ab4382d2SGreg Kroah-Hartman if (type == SU_PORT_PORT) {
1435cb29529eSTkhai Kirill if (nr_inst >= UART_NR)
1436ab4382d2SGreg Kroah-Hartman return -EINVAL;
1437cb29529eSTkhai Kirill up = &sunsu_ports[nr_inst];
1438ab4382d2SGreg Kroah-Hartman } else {
1439ab4382d2SGreg Kroah-Hartman up = kzalloc(sizeof(*up), GFP_KERNEL);
1440ab4382d2SGreg Kroah-Hartman if (!up)
1441ab4382d2SGreg Kroah-Hartman return -ENOMEM;
1442ab4382d2SGreg Kroah-Hartman }
1443ab4382d2SGreg Kroah-Hartman
1444cb29529eSTkhai Kirill up->port.line = nr_inst;
1445ab4382d2SGreg Kroah-Hartman
1446ab4382d2SGreg Kroah-Hartman spin_lock_init(&up->port.lock);
1447ab4382d2SGreg Kroah-Hartman
1448ab4382d2SGreg Kroah-Hartman up->su_type = type;
1449ab4382d2SGreg Kroah-Hartman
1450ab4382d2SGreg Kroah-Hartman rp = &op->resource[0];
1451ab4382d2SGreg Kroah-Hartman up->port.mapbase = rp->start;
145228f65c11SJoe Perches up->reg_size = resource_size(rp);
1453ab4382d2SGreg Kroah-Hartman up->port.membase = of_ioremap(rp, 0, up->reg_size, "su");
1454ab4382d2SGreg Kroah-Hartman if (!up->port.membase) {
1455ab4382d2SGreg Kroah-Hartman if (type != SU_PORT_PORT)
1456ab4382d2SGreg Kroah-Hartman kfree(up);
1457ab4382d2SGreg Kroah-Hartman return -ENOMEM;
1458ab4382d2SGreg Kroah-Hartman }
1459ab4382d2SGreg Kroah-Hartman
1460ab4382d2SGreg Kroah-Hartman up->port.irq = op->archdata.irqs[0];
1461ab4382d2SGreg Kroah-Hartman
1462ab4382d2SGreg Kroah-Hartman up->port.dev = &op->dev;
1463ab4382d2SGreg Kroah-Hartman
1464ab4382d2SGreg Kroah-Hartman up->port.type = PORT_UNKNOWN;
1465ab4382d2SGreg Kroah-Hartman up->port.uartclk = (SU_BASE_BAUD * 16);
14665e637d2bSDmitry Safonov up->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SUNSU_CONSOLE);
1467ab4382d2SGreg Kroah-Hartman
1468ab4382d2SGreg Kroah-Hartman err = 0;
1469ab4382d2SGreg Kroah-Hartman if (up->su_type == SU_PORT_KBD || up->su_type == SU_PORT_MS) {
1470ab4382d2SGreg Kroah-Hartman err = sunsu_kbd_ms_init(up);
1471ab4382d2SGreg Kroah-Hartman if (err) {
1472ab4382d2SGreg Kroah-Hartman of_iounmap(&op->resource[0],
1473ab4382d2SGreg Kroah-Hartman up->port.membase, up->reg_size);
1474ab4382d2SGreg Kroah-Hartman kfree(up);
1475ab4382d2SGreg Kroah-Hartman return err;
1476ab4382d2SGreg Kroah-Hartman }
1477696faeddSJingoo Han platform_set_drvdata(op, up);
1478ab4382d2SGreg Kroah-Hartman
1479cb29529eSTkhai Kirill nr_inst++;
1480cb29529eSTkhai Kirill
1481ab4382d2SGreg Kroah-Hartman return 0;
1482ab4382d2SGreg Kroah-Hartman }
1483ab4382d2SGreg Kroah-Hartman
1484ab4382d2SGreg Kroah-Hartman up->port.flags |= UPF_BOOT_AUTOCONF;
1485ab4382d2SGreg Kroah-Hartman
1486ab4382d2SGreg Kroah-Hartman sunsu_autoconfig(up);
1487ab4382d2SGreg Kroah-Hartman
1488ab4382d2SGreg Kroah-Hartman err = -ENODEV;
1489ab4382d2SGreg Kroah-Hartman if (up->port.type == PORT_UNKNOWN)
1490ab4382d2SGreg Kroah-Hartman goto out_unmap;
1491ab4382d2SGreg Kroah-Hartman
1492ab4382d2SGreg Kroah-Hartman up->port.ops = &sunsu_pops;
1493ab4382d2SGreg Kroah-Hartman
1494ab4382d2SGreg Kroah-Hartman ignore_line = false;
1495778ec49cSRob Herring if (of_node_name_eq(dp, "rsc-console") ||
1496778ec49cSRob Herring of_node_name_eq(dp, "lom-console"))
1497ab4382d2SGreg Kroah-Hartman ignore_line = true;
1498ab4382d2SGreg Kroah-Hartman
1499ab4382d2SGreg Kroah-Hartman sunserial_console_match(SUNSU_CONSOLE(), dp,
1500ab4382d2SGreg Kroah-Hartman &sunsu_reg, up->port.line,
1501ab4382d2SGreg Kroah-Hartman ignore_line);
1502ab4382d2SGreg Kroah-Hartman err = uart_add_one_port(&sunsu_reg, &up->port);
1503ab4382d2SGreg Kroah-Hartman if (err)
1504ab4382d2SGreg Kroah-Hartman goto out_unmap;
1505ab4382d2SGreg Kroah-Hartman
1506696faeddSJingoo Han platform_set_drvdata(op, up);
1507ab4382d2SGreg Kroah-Hartman
1508cb29529eSTkhai Kirill nr_inst++;
1509ab4382d2SGreg Kroah-Hartman
1510ab4382d2SGreg Kroah-Hartman return 0;
1511ab4382d2SGreg Kroah-Hartman
1512ab4382d2SGreg Kroah-Hartman out_unmap:
1513ab4382d2SGreg Kroah-Hartman of_iounmap(&op->resource[0], up->port.membase, up->reg_size);
1514af6f9d68SSouptick Joarder kfree(up);
1515ab4382d2SGreg Kroah-Hartman return err;
1516ab4382d2SGreg Kroah-Hartman }
1517ab4382d2SGreg Kroah-Hartman
su_remove(struct platform_device * op)1518ae8d8a14SBill Pemberton static int su_remove(struct platform_device *op)
1519ab4382d2SGreg Kroah-Hartman {
1520696faeddSJingoo Han struct uart_sunsu_port *up = platform_get_drvdata(op);
1521ab4382d2SGreg Kroah-Hartman bool kbdms = false;
1522ab4382d2SGreg Kroah-Hartman
1523ab4382d2SGreg Kroah-Hartman if (up->su_type == SU_PORT_MS ||
1524ab4382d2SGreg Kroah-Hartman up->su_type == SU_PORT_KBD)
1525ab4382d2SGreg Kroah-Hartman kbdms = true;
1526ab4382d2SGreg Kroah-Hartman
1527ab4382d2SGreg Kroah-Hartman if (kbdms) {
1528ab4382d2SGreg Kroah-Hartman #ifdef CONFIG_SERIO
1529ab4382d2SGreg Kroah-Hartman serio_unregister_port(&up->serio);
1530ab4382d2SGreg Kroah-Hartman #endif
1531ab4382d2SGreg Kroah-Hartman } else if (up->port.type != PORT_UNKNOWN)
1532ab4382d2SGreg Kroah-Hartman uart_remove_one_port(&sunsu_reg, &up->port);
1533ab4382d2SGreg Kroah-Hartman
1534ab4382d2SGreg Kroah-Hartman if (up->port.membase)
1535ab4382d2SGreg Kroah-Hartman of_iounmap(&op->resource[0], up->port.membase, up->reg_size);
1536ab4382d2SGreg Kroah-Hartman
1537ab4382d2SGreg Kroah-Hartman if (kbdms)
1538ab4382d2SGreg Kroah-Hartman kfree(up);
1539ab4382d2SGreg Kroah-Hartman
1540ab4382d2SGreg Kroah-Hartman return 0;
1541ab4382d2SGreg Kroah-Hartman }
1542ab4382d2SGreg Kroah-Hartman
1543ab4382d2SGreg Kroah-Hartman static const struct of_device_id su_match[] = {
1544ab4382d2SGreg Kroah-Hartman {
1545ab4382d2SGreg Kroah-Hartman .name = "su",
1546ab4382d2SGreg Kroah-Hartman },
1547ab4382d2SGreg Kroah-Hartman {
1548ab4382d2SGreg Kroah-Hartman .name = "su_pnp",
1549ab4382d2SGreg Kroah-Hartman },
1550ab4382d2SGreg Kroah-Hartman {
1551ab4382d2SGreg Kroah-Hartman .name = "serial",
1552ab4382d2SGreg Kroah-Hartman .compatible = "su",
1553ab4382d2SGreg Kroah-Hartman },
1554ab4382d2SGreg Kroah-Hartman {
1555ab4382d2SGreg Kroah-Hartman .type = "serial",
1556ab4382d2SGreg Kroah-Hartman .compatible = "su",
1557ab4382d2SGreg Kroah-Hartman },
1558ab4382d2SGreg Kroah-Hartman {},
1559ab4382d2SGreg Kroah-Hartman };
1560ab4382d2SGreg Kroah-Hartman MODULE_DEVICE_TABLE(of, su_match);
1561ab4382d2SGreg Kroah-Hartman
1562793218dfSGrant Likely static struct platform_driver su_driver = {
1563ab4382d2SGreg Kroah-Hartman .driver = {
1564ab4382d2SGreg Kroah-Hartman .name = "su",
1565ab4382d2SGreg Kroah-Hartman .of_match_table = su_match,
1566ab4382d2SGreg Kroah-Hartman },
1567ab4382d2SGreg Kroah-Hartman .probe = su_probe,
15682d47b716SBill Pemberton .remove = su_remove,
1569ab4382d2SGreg Kroah-Hartman };
1570ab4382d2SGreg Kroah-Hartman
sunsu_init(void)1571ab4382d2SGreg Kroah-Hartman static int __init sunsu_init(void)
1572ab4382d2SGreg Kroah-Hartman {
1573ab4382d2SGreg Kroah-Hartman struct device_node *dp;
1574ab4382d2SGreg Kroah-Hartman int err;
1575ab4382d2SGreg Kroah-Hartman int num_uart = 0;
1576ab4382d2SGreg Kroah-Hartman
1577ab4382d2SGreg Kroah-Hartman for_each_node_by_name(dp, "su") {
1578ab4382d2SGreg Kroah-Hartman if (su_get_type(dp) == SU_PORT_PORT)
1579ab4382d2SGreg Kroah-Hartman num_uart++;
1580ab4382d2SGreg Kroah-Hartman }
1581ab4382d2SGreg Kroah-Hartman for_each_node_by_name(dp, "su_pnp") {
1582ab4382d2SGreg Kroah-Hartman if (su_get_type(dp) == SU_PORT_PORT)
1583ab4382d2SGreg Kroah-Hartman num_uart++;
1584ab4382d2SGreg Kroah-Hartman }
1585ab4382d2SGreg Kroah-Hartman for_each_node_by_name(dp, "serial") {
1586ab4382d2SGreg Kroah-Hartman if (of_device_is_compatible(dp, "su")) {
1587ab4382d2SGreg Kroah-Hartman if (su_get_type(dp) == SU_PORT_PORT)
1588ab4382d2SGreg Kroah-Hartman num_uart++;
1589ab4382d2SGreg Kroah-Hartman }
1590ab4382d2SGreg Kroah-Hartman }
1591ab4382d2SGreg Kroah-Hartman for_each_node_by_type(dp, "serial") {
1592ab4382d2SGreg Kroah-Hartman if (of_device_is_compatible(dp, "su")) {
1593ab4382d2SGreg Kroah-Hartman if (su_get_type(dp) == SU_PORT_PORT)
1594ab4382d2SGreg Kroah-Hartman num_uart++;
1595ab4382d2SGreg Kroah-Hartman }
1596ab4382d2SGreg Kroah-Hartman }
1597ab4382d2SGreg Kroah-Hartman
1598ab4382d2SGreg Kroah-Hartman if (num_uart) {
1599ab4382d2SGreg Kroah-Hartman err = sunserial_register_minors(&sunsu_reg, num_uart);
1600ab4382d2SGreg Kroah-Hartman if (err)
1601ab4382d2SGreg Kroah-Hartman return err;
1602ab4382d2SGreg Kroah-Hartman }
1603ab4382d2SGreg Kroah-Hartman
1604793218dfSGrant Likely err = platform_driver_register(&su_driver);
1605ab4382d2SGreg Kroah-Hartman if (err && num_uart)
1606ab4382d2SGreg Kroah-Hartman sunserial_unregister_minors(&sunsu_reg, num_uart);
1607ab4382d2SGreg Kroah-Hartman
1608ab4382d2SGreg Kroah-Hartman return err;
1609ab4382d2SGreg Kroah-Hartman }
1610ab4382d2SGreg Kroah-Hartman
sunsu_exit(void)1611ab4382d2SGreg Kroah-Hartman static void __exit sunsu_exit(void)
1612ab4382d2SGreg Kroah-Hartman {
1613ad348cc5SWei Yongjun platform_driver_unregister(&su_driver);
1614ab4382d2SGreg Kroah-Hartman if (sunsu_reg.nr)
1615ab4382d2SGreg Kroah-Hartman sunserial_unregister_minors(&sunsu_reg, sunsu_reg.nr);
1616ab4382d2SGreg Kroah-Hartman }
1617ab4382d2SGreg Kroah-Hartman
1618ab4382d2SGreg Kroah-Hartman module_init(sunsu_init);
1619ab4382d2SGreg Kroah-Hartman module_exit(sunsu_exit);
1620ab4382d2SGreg Kroah-Hartman
1621ab4382d2SGreg Kroah-Hartman MODULE_AUTHOR("Eddie C. Dost, Peter Zaitcev, and David S. Miller");
1622ab4382d2SGreg Kroah-Hartman MODULE_DESCRIPTION("Sun SU serial port driver");
1623ab4382d2SGreg Kroah-Hartman MODULE_VERSION("2.0");
1624ab4382d2SGreg Kroah-Hartman MODULE_LICENSE("GPL");
1625