blob: 643dfbcc43f992fb064833f5f9451bde2fd47443 [file] [log] [blame]
Greg Kroah-Hartmane3b3d0f2017-11-06 18:11:51 +01001// SPDX-License-Identifier: GPL-2.0+
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3** mux.c:
4** serial driver for the Mux console found in some PA-RISC servers.
5**
6** (c) Copyright 2002 Ryan Bradetich
7** (c) Copyright 2002 Hewlett-Packard Company
8**
Linus Torvalds1da177e2005-04-16 15:20:36 -07009** This Driver currently only supports the console (port 0) on the MUX.
10** Additional work will be needed on this driver to enable the full
11** functionality of the MUX.
12**
13*/
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/ioport.h>
17#include <linux/init.h>
18#include <linux/serial.h>
Jiri Slabyee160a32011-09-01 16:20:57 +020019#include <linux/tty.h>
20#include <linux/tty_flip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/console.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/delay.h> /* for udelay */
23#include <linux/device.h>
Zihao Tangb1c92c12021-05-13 11:01:37 +080024#include <linux/io.h>
Matthew Wilcoxae8c75c2005-10-21 22:58:03 -040025#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/parisc-device.h>
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/sysrq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/serial_core.h>
30
31#define MUX_OFFSET 0x800
32#define MUX_LINE_OFFSET 0x80
33
34#define MUX_FIFO_SIZE 255
35#define MUX_POLL_DELAY (30 * HZ / 1000)
36
37#define IO_DATA_REG_OFFSET 0x3c
38#define IO_DCOUNT_REG_OFFSET 0x40
39
40#define MUX_EOFIFO(status) ((status & 0xF000) == 0xF000)
41#define MUX_STATUS(status) ((status & 0xF000) == 0x8000)
42#define MUX_BREAK(status) ((status & 0xF000) == 0x2000)
43
44#define MUX_NR 256
Helge Deller5076c152006-03-27 12:52:15 -070045static unsigned int port_cnt __read_mostly;
Ryan Bradetich4bd5d822006-11-03 05:38:39 +000046struct mux_port {
47 struct uart_port port;
48 int enabled;
49};
50static struct mux_port mux_ports[MUX_NR];
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52static struct uart_driver mux_driver = {
53 .owner = THIS_MODULE,
54 .driver_name = "ttyB",
55 .dev_name = "ttyB",
56 .major = MUX_MAJOR,
57 .minor = 0,
58 .nr = MUX_NR,
59};
60
61static struct timer_list mux_timer;
62
Ryan Bradetich92495c02005-11-17 16:36:52 -050063#define UART_PUT_CHAR(p, c) __raw_writel((c), (p)->membase + IO_DATA_REG_OFFSET)
64#define UART_GET_FIFO_CNT(p) __raw_readl((p)->membase + IO_DCOUNT_REG_OFFSET)
Ryan Bradetich61425442006-11-10 03:08:45 +000065
66/**
67 * get_mux_port_count - Get the number of available ports on the Mux.
68 * @dev: The parisc device.
69 *
70 * This function is used to determine the number of ports the Mux
71 * supports. The IODC data reports the number of ports the Mux
72 * can support, but there are cases where not all the Mux ports
73 * are connected. This function can override the IODC and
74 * return the true port count.
75 */
76static int __init get_mux_port_count(struct parisc_device *dev)
77{
Ryan Bradetich514fb842006-11-10 04:06:14 +000078 int status;
Ryan Bradetich61425442006-11-10 03:08:45 +000079 u8 iodc_data[32];
80 unsigned long bytecnt;
81
Ryan Bradetich61425442006-11-10 03:08:45 +000082 /* If this is the built-in Mux for the K-Class (Eole CAP/MUX),
83 * we only need to allocate resources for 1 port since the
84 * other 7 ports are not connected.
85 */
Ryan Bradetich514fb842006-11-10 04:06:14 +000086 if(dev->id.hversion == 0x15)
Ryan Bradetich61425442006-11-10 03:08:45 +000087 return 1;
88
Ryan Bradetich514fb842006-11-10 04:06:14 +000089 status = pdc_iodc_read(&bytecnt, dev->hpa.start, 0, iodc_data, 32);
90 BUG_ON(status != PDC_OK);
91
Ryan Bradetich61425442006-11-10 03:08:45 +000092 /* Return the number of ports specified in the iodc data. */
93 return ((((iodc_data)[4] & 0xf0) >> 4) * 8) + 8;
94}
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/**
97 * mux_tx_empty - Check if the transmitter fifo is empty.
98 * @port: Ptr to the uart_port.
99 *
100 * This function test if the transmitter fifo for the port
101 * described by 'port' is empty. If it is empty, this function
102 * should return TIOCSER_TEMT, otherwise return 0.
103 */
104static unsigned int mux_tx_empty(struct uart_port *port)
105{
Ryan Bradetich92495c02005-11-17 16:36:52 -0500106 return UART_GET_FIFO_CNT(port) ? 0 : TIOCSER_TEMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107}
108
109/**
110 * mux_set_mctrl - Set the current state of the modem control inputs.
111 * @ports: Ptr to the uart_port.
112 * @mctrl: Modem control bits.
113 *
114 * The Serial MUX does not support CTS, DCD or DSR so this function
115 * is ignored.
116 */
117static void mux_set_mctrl(struct uart_port *port, unsigned int mctrl)
118{
119}
120
121/**
122 * mux_get_mctrl - Returns the current state of modem control inputs.
123 * @port: Ptr to the uart_port.
124 *
125 * The Serial MUX does not support CTS, DCD or DSR so these lines are
126 * treated as permanently active.
127 */
128static unsigned int mux_get_mctrl(struct uart_port *port)
129{
130 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
131}
132
133/**
134 * mux_stop_tx - Stop transmitting characters.
135 * @port: Ptr to the uart_port.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 *
137 * The Serial MUX does not support this function.
138 */
Russell Kingb129a8c2005-08-31 10:12:14 +0100139static void mux_stop_tx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
141}
142
143/**
144 * mux_start_tx - Start transmitting characters.
145 * @port: Ptr to the uart_port.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 *
147 * The Serial Mux does not support this function.
148 */
Russell Kingb129a8c2005-08-31 10:12:14 +0100149static void mux_start_tx(struct uart_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
151}
152
153/**
154 * mux_stop_rx - Stop receiving characters.
155 * @port: Ptr to the uart_port.
156 *
157 * The Serial Mux does not support this function.
158 */
159static void mux_stop_rx(struct uart_port *port)
160{
161}
162
163/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 * mux_break_ctl - Control the transmitssion of a break signal.
165 * @port: Ptr to the uart_port.
166 * @break_state: Raise/Lower the break signal.
167 *
168 * The Serial Mux does not support this function.
169 */
170static void mux_break_ctl(struct uart_port *port, int break_state)
171{
172}
173
174/**
175 * mux_write - Write chars to the mux fifo.
176 * @port: Ptr to the uart_port.
177 *
178 * This function writes all the data from the uart buffer to
179 * the mux fifo.
180 */
181static void mux_write(struct uart_port *port)
182{
183 int count;
Alan Coxebd2c8f2009-09-19 13:13:28 -0700184 struct circ_buf *xmit = &port->state->xmit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 if(port->x_char) {
187 UART_PUT_CHAR(port, port->x_char);
188 port->icount.tx++;
189 port->x_char = 0;
190 return;
191 }
192
193 if(uart_circ_empty(xmit) || uart_tx_stopped(port)) {
Russell Kingb129a8c2005-08-31 10:12:14 +0100194 mux_stop_tx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 return;
196 }
197
198 count = (port->fifosize) - UART_GET_FIFO_CNT(port);
199 do {
200 UART_PUT_CHAR(port, xmit->buf[xmit->tail]);
201 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
202 port->icount.tx++;
203 if(uart_circ_empty(xmit))
204 break;
205
206 } while(--count > 0);
207
208 while(UART_GET_FIFO_CNT(port))
209 udelay(1);
210
211 if(uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
212 uart_write_wakeup(port);
213
214 if (uart_circ_empty(xmit))
Russell Kingb129a8c2005-08-31 10:12:14 +0100215 mux_stop_tx(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
218/**
219 * mux_read - Read chars from the mux fifo.
220 * @port: Ptr to the uart_port.
221 *
222 * This reads all available data from the mux's fifo and pushes
223 * the data to the tty layer.
224 */
225static void mux_read(struct uart_port *port)
226{
Jiri Slaby92a19f92013-01-03 15:53:03 +0100227 struct tty_port *tport = &port->state->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 int data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 __u32 start_count = port->icount.rx;
230
231 while(1) {
Ryan Bradetich92495c02005-11-17 16:36:52 -0500232 data = __raw_readl(port->membase + IO_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 if (MUX_STATUS(data))
235 continue;
236
237 if (MUX_EOFIFO(data))
238 break;
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 port->icount.rx++;
241
242 if (MUX_BREAK(data)) {
243 port->icount.brk++;
244 if(uart_handle_break(port))
245 continue;
246 }
247
Matthew Wilcoxbe577a52006-10-06 20:47:23 -0600248 if (uart_handle_sysrq_char(port, data & 0xffu))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 continue;
250
Jiri Slaby92a19f92013-01-03 15:53:03 +0100251 tty_insert_flip_char(tport, data & 0xFF, TTY_NORMAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 }
253
Jiri Slaby2e124b42013-01-03 15:53:06 +0100254 if (start_count != port->icount.rx)
255 tty_flip_buffer_push(tport);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256}
257
258/**
259 * mux_startup - Initialize the port.
260 * @port: Ptr to the uart_port.
261 *
262 * Grab any resources needed for this port and start the
263 * mux timer.
264 */
265static int mux_startup(struct uart_port *port)
266{
Ryan Bradetich4bd5d822006-11-03 05:38:39 +0000267 mux_ports[port->line].enabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 return 0;
269}
270
271/**
272 * mux_shutdown - Disable the port.
273 * @port: Ptr to the uart_port.
274 *
275 * Release any resources needed for the port.
276 */
277static void mux_shutdown(struct uart_port *port)
278{
Ryan Bradetich4bd5d822006-11-03 05:38:39 +0000279 mux_ports[port->line].enabled = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
282/**
283 * mux_set_termios - Chane port parameters.
284 * @port: Ptr to the uart_port.
285 * @termios: new termios settings.
286 * @old: old termios settings.
287 *
288 * The Serial Mux does not support this function.
289 */
290static void
Alan Cox606d0992006-12-08 02:38:45 -0800291mux_set_termios(struct uart_port *port, struct ktermios *termios,
292 struct ktermios *old)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
294}
295
296/**
297 * mux_type - Describe the port.
298 * @port: Ptr to the uart_port.
299 *
300 * Return a pointer to a string constant describing the
301 * specified port.
302 */
303static const char *mux_type(struct uart_port *port)
304{
305 return "Mux";
306}
307
308/**
309 * mux_release_port - Release memory and IO regions.
310 * @port: Ptr to the uart_port.
311 *
312 * Release any memory and IO region resources currently in use by
313 * the port.
314 */
315static void mux_release_port(struct uart_port *port)
316{
317}
318
319/**
320 * mux_request_port - Request memory and IO regions.
321 * @port: Ptr to the uart_port.
322 *
323 * Request any memory and IO region resources required by the port.
324 * If any fail, no resources should be registered when this function
325 * returns, and it should return -EBUSY on failure.
326 */
327static int mux_request_port(struct uart_port *port)
328{
329 return 0;
330}
331
332/**
333 * mux_config_port - Perform port autoconfiguration.
334 * @port: Ptr to the uart_port.
335 * @type: Bitmask of required configurations.
336 *
Ryan Bradetich4bd5d822006-11-03 05:38:39 +0000337 * Perform any autoconfiguration steps for the port. This function is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 * called if the UPF_BOOT_AUTOCONF flag is specified for the port.
339 * [Note: This is required for now because of a bug in the Serial core.
340 * rmk has already submitted a patch to linus, should be available for
341 * 2.5.47.]
342 */
343static void mux_config_port(struct uart_port *port, int type)
344{
345 port->type = PORT_MUX;
346}
347
348/**
349 * mux_verify_port - Verify the port information.
350 * @port: Ptr to the uart_port.
351 * @ser: Ptr to the serial information.
352 *
353 * Verify the new serial port information contained within serinfo is
354 * suitable for this port type.
355 */
356static int mux_verify_port(struct uart_port *port, struct serial_struct *ser)
357{
358 if(port->membase == NULL)
359 return -EINVAL;
360
361 return 0;
362}
363
364/**
365 * mux_drv_poll - Mux poll function.
366 * @unused: Unused variable
367 *
368 * This function periodically polls the Serial MUX to check for new data.
369 */
Kees Cooke99e88a2017-10-16 14:43:17 -0700370static void mux_poll(struct timer_list *unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
372 int i;
373
374 for(i = 0; i < port_cnt; ++i) {
Ryan Bradetich4bd5d822006-11-03 05:38:39 +0000375 if(!mux_ports[i].enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 continue;
377
Ryan Bradetich4bd5d822006-11-03 05:38:39 +0000378 mux_read(&mux_ports[i].port);
379 mux_write(&mux_ports[i].port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 }
381
382 mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
383}
384
385
386#ifdef CONFIG_SERIAL_MUX_CONSOLE
387static void mux_console_write(struct console *co, const char *s, unsigned count)
388{
Ryan Bradetich3de7b642006-11-03 05:52:41 +0000389 /* Wait until the FIFO drains. */
390 while(UART_GET_FIFO_CNT(&mux_ports[0].port))
391 udelay(1);
392
393 while(count--) {
394 if(*s == '\n') {
395 UART_PUT_CHAR(&mux_ports[0].port, '\r');
396 }
397 UART_PUT_CHAR(&mux_ports[0].port, *s++);
398 }
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
401
402static int mux_console_setup(struct console *co, char *options)
403{
404 return 0;
405}
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407static struct console mux_console = {
408 .name = "ttyB",
409 .write = mux_console_write,
Axel Linaa0bdd22015-09-19 11:43:07 +0800410 .device = uart_console_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 .setup = mux_console_setup,
412 .flags = CON_ENABLED | CON_PRINTBUFFER,
413 .index = 0,
Axel Linaa0bdd22015-09-19 11:43:07 +0800414 .data = &mux_driver,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415};
416
417#define MUX_CONSOLE &mux_console
418#else
419#define MUX_CONSOLE NULL
420#endif
421
Julia Lawall454d2372017-08-13 08:21:50 +0200422static const struct uart_ops mux_pops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 .tx_empty = mux_tx_empty,
424 .set_mctrl = mux_set_mctrl,
425 .get_mctrl = mux_get_mctrl,
426 .stop_tx = mux_stop_tx,
427 .start_tx = mux_start_tx,
428 .stop_rx = mux_stop_rx,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 .break_ctl = mux_break_ctl,
430 .startup = mux_startup,
431 .shutdown = mux_shutdown,
432 .set_termios = mux_set_termios,
433 .type = mux_type,
434 .release_port = mux_release_port,
435 .request_port = mux_request_port,
436 .config_port = mux_config_port,
437 .verify_port = mux_verify_port,
438};
439
440/**
441 * mux_probe - Determine if the Serial Mux should claim this device.
442 * @dev: The parisc device.
443 *
444 * Deterimine if the Serial Mux should claim this chip (return 0)
445 * or not (return 1).
446 */
447static int __init mux_probe(struct parisc_device *dev)
448{
Ryan Bradetich61425442006-11-10 03:08:45 +0000449 int i, status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Ryan Bradetich61425442006-11-10 03:08:45 +0000451 int port_count = get_mux_port_count(dev);
Ryan Bradetich752b9402006-11-09 04:45:08 +0000452 printk(KERN_INFO "Serial mux driver (%d ports) Revision: 0.6\n", port_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Ryan Bradetichc380f052006-11-05 01:21:44 +0000454 dev_set_drvdata(&dev->dev, (void *)(long)port_count);
455 request_mem_region(dev->hpa.start + MUX_OFFSET,
456 port_count * MUX_LINE_OFFSET, "Mux");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 if(!port_cnt) {
459 mux_driver.cons = MUX_CONSOLE;
460
461 status = uart_register_driver(&mux_driver);
462 if(status) {
463 printk(KERN_ERR "Serial mux: Unable to register driver.\n");
464 return 1;
465 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 }
467
Ryan Bradetichc380f052006-11-05 01:21:44 +0000468 for(i = 0; i < port_count; ++i, ++port_cnt) {
469 struct uart_port *port = &mux_ports[port_cnt].port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 port->iobase = 0;
Matthew Wilcoxae8c75c2005-10-21 22:58:03 -0400471 port->mapbase = dev->hpa.start + MUX_OFFSET +
472 (i * MUX_LINE_OFFSET);
Christoph Hellwig4bdc0d62020-01-06 09:43:50 +0100473 port->membase = ioremap(port->mapbase, MUX_LINE_OFFSET);
Russell King9b4a1612006-02-05 10:48:10 +0000474 port->iotype = UPIO_MEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 port->type = PORT_MUX;
Alan Coxd4e33fa2012-01-26 17:44:09 +0000476 port->irq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 port->uartclk = 0;
478 port->fifosize = MUX_FIFO_SIZE;
479 port->ops = &mux_pops;
480 port->flags = UPF_BOOT_AUTOCONF;
481 port->line = port_cnt;
Dmitry Safonovb4088e82019-12-13 00:06:25 +0000482 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MUX_CONSOLE);
Ryan Bradeticha137ce852005-11-17 16:38:28 -0500483
484 /* The port->timeout needs to match what is present in
485 * uart_wait_until_sent in serial_core.c. Otherwise
486 * the time spent in msleep_interruptable will be very
487 * long, causing the appearance of a console hang.
488 */
489 port->timeout = HZ / 50;
Matthew Wilcoxae8c75c2005-10-21 22:58:03 -0400490 spin_lock_init(&port->lock);
Ryan Bradetich752b9402006-11-09 04:45:08 +0000491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 status = uart_add_one_port(&mux_driver, port);
493 BUG_ON(status);
494 }
495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 return 0;
497}
498
Uwe Kleine-König87875c12021-08-07 11:19:27 +0200499static void __exit mux_remove(struct parisc_device *dev)
Ryan Bradetichc380f052006-11-05 01:21:44 +0000500{
Ryan Bradetich752b9402006-11-09 04:45:08 +0000501 int i, j;
Ryan Bradetichc380f052006-11-05 01:21:44 +0000502 int port_count = (long)dev_get_drvdata(&dev->dev);
503
Ryan Bradetichc380f052006-11-05 01:21:44 +0000504 /* Find Port 0 for this card in the mux_ports list. */
505 for(i = 0; i < port_cnt; ++i) {
506 if(mux_ports[i].port.mapbase == dev->hpa.start + MUX_OFFSET)
507 break;
508 }
509 BUG_ON(i + port_count > port_cnt);
510
511 /* Release the resources associated with each port on the device. */
Ryan Bradetich752b9402006-11-09 04:45:08 +0000512 for(j = 0; j < port_count; ++j, ++i) {
Ryan Bradetichc380f052006-11-05 01:21:44 +0000513 struct uart_port *port = &mux_ports[i].port;
514
515 uart_remove_one_port(&mux_driver, port);
516 if(port->membase)
517 iounmap(port->membase);
518 }
519
520 release_mem_region(dev->hpa.start + MUX_OFFSET, port_count * MUX_LINE_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521}
522
Ryan Bradetich752b9402006-11-09 04:45:08 +0000523/* Hack. This idea was taken from the 8250_gsc.c on how to properly order
524 * the serial port detection in the proper order. The idea is we always
525 * want the builtin mux to be detected before addin mux cards, so we
526 * specifically probe for the builtin mux cards first.
527 *
528 * This table only contains the parisc_device_id of known builtin mux
529 * devices. All other mux cards will be detected by the generic mux_tbl.
530 */
Helge Dellerfc72b7a2017-08-21 21:55:11 +0200531static const struct parisc_device_id builtin_mux_tbl[] __initconst = {
Ryan Bradetich752b9402006-11-09 04:45:08 +0000532 { HPHW_A_DIRECT, HVERSION_REV_ANY_ID, 0x15, 0x0000D }, /* All K-class */
533 { HPHW_A_DIRECT, HVERSION_REV_ANY_ID, 0x44, 0x0000D }, /* E35, E45, and E55 */
534 { 0, }
535};
536
Helge Dellerfc72b7a2017-08-21 21:55:11 +0200537static const struct parisc_device_id mux_tbl[] __initconst = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 { HPHW_A_DIRECT, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0000D },
539 { 0, }
540};
541
Ryan Bradetich752b9402006-11-09 04:45:08 +0000542MODULE_DEVICE_TABLE(parisc, builtin_mux_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543MODULE_DEVICE_TABLE(parisc, mux_tbl);
544
Helge Dellerfc72b7a2017-08-21 21:55:11 +0200545static struct parisc_driver builtin_serial_mux_driver __refdata = {
Ryan Bradetich752b9402006-11-09 04:45:08 +0000546 .name = "builtin_serial_mux",
547 .id_table = builtin_mux_tbl,
548 .probe = mux_probe,
Helge Dellerfc72b7a2017-08-21 21:55:11 +0200549 .remove = __exit_p(mux_remove),
Ryan Bradetich752b9402006-11-09 04:45:08 +0000550};
551
Helge Dellerfc72b7a2017-08-21 21:55:11 +0200552static struct parisc_driver serial_mux_driver __refdata = {
Matthew Wilcoxbdad1f82005-10-21 22:36:23 -0400553 .name = "serial_mux",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 .id_table = mux_tbl,
555 .probe = mux_probe,
Helge Dellerfc72b7a2017-08-21 21:55:11 +0200556 .remove = __exit_p(mux_remove),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557};
558
559/**
Joe Perches8f4aafe2008-02-03 17:29:25 +0200560 * mux_init - Serial MUX initialization procedure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 *
562 * Register the Serial MUX driver.
563 */
564static int __init mux_init(void)
565{
Ryan Bradetich752b9402006-11-09 04:45:08 +0000566 register_parisc_driver(&builtin_serial_mux_driver);
567 register_parisc_driver(&serial_mux_driver);
Ryan Bradetichc380f052006-11-05 01:21:44 +0000568
569 if(port_cnt > 0) {
570 /* Start the Mux timer */
Kees Cooke99e88a2017-10-16 14:43:17 -0700571 timer_setup(&mux_timer, mux_poll, 0);
Ryan Bradetichc380f052006-11-05 01:21:44 +0000572 mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
573
574#ifdef CONFIG_SERIAL_MUX_CONSOLE
575 register_console(&mux_console);
576#endif
577 }
578
Ryan Bradetich752b9402006-11-09 04:45:08 +0000579 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580}
581
582/**
583 * mux_exit - Serial MUX cleanup procedure.
584 *
585 * Unregister the Serial MUX driver from the tty layer.
586 */
587static void __exit mux_exit(void)
588{
Ryan Bradetichc380f052006-11-05 01:21:44 +0000589 /* Delete the Mux timer. */
590 if(port_cnt > 0) {
Julia Lawall0f1e1262014-03-26 22:33:42 +0100591 del_timer_sync(&mux_timer);
Ryan Bradetichc380f052006-11-05 01:21:44 +0000592#ifdef CONFIG_SERIAL_MUX_CONSOLE
593 unregister_console(&mux_console);
594#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 }
596
Ryan Bradetich752b9402006-11-09 04:45:08 +0000597 unregister_parisc_driver(&builtin_serial_mux_driver);
Ryan Bradetichc380f052006-11-05 01:21:44 +0000598 unregister_parisc_driver(&serial_mux_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 uart_unregister_driver(&mux_driver);
600}
601
602module_init(mux_init);
603module_exit(mux_exit);
604
605MODULE_AUTHOR("Ryan Bradetich");
606MODULE_DESCRIPTION("Serial MUX driver");
607MODULE_LICENSE("GPL");
608MODULE_ALIAS_CHARDEV_MAJOR(MUX_MAJOR);