Blame view

drivers/serial/mux.c 15.1 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  /*
  ** mux.c:
  **	serial driver for the Mux console found in some PA-RISC servers.
  **
  **	(c) Copyright 2002 Ryan Bradetich
  **	(c) Copyright 2002 Hewlett-Packard Company
  **
  ** This program is free software; you can redistribute it and/or modify
  ** it under the terms of the GNU General Public License as published by
  ** the Free Software Foundation; either version 2 of the License, or
  ** (at your option) any later version.
  **
  ** This Driver currently only supports the console (port 0) on the MUX.
  ** Additional work will be needed on this driver to enable the full
  ** functionality of the MUX.
  **
  */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
19
20
21
22
23
24
25
26
27
  #include <linux/module.h>
  #include <linux/tty.h>
  #include <linux/ioport.h>
  #include <linux/init.h>
  #include <linux/serial.h>
  #include <linux/console.h>
  #include <linux/slab.h>
  #include <linux/delay.h> /* for udelay */
  #include <linux/device.h>
  #include <asm/io.h>
ae8c75c1c   Matthew Wilcox   [PARISC] Fix mux....
28
  #include <asm/irq.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  #include <asm/parisc-device.h>
  
  #ifdef CONFIG_MAGIC_SYSRQ
  #include <linux/sysrq.h>
  #define SUPPORT_SYSRQ
  #endif
  
  #include <linux/serial_core.h>
  
  #define MUX_OFFSET 0x800
  #define MUX_LINE_OFFSET 0x80
  
  #define MUX_FIFO_SIZE 255
  #define MUX_POLL_DELAY (30 * HZ / 1000)
  
  #define IO_DATA_REG_OFFSET 0x3c
  #define IO_DCOUNT_REG_OFFSET 0x40
  
  #define MUX_EOFIFO(status) ((status & 0xF000) == 0xF000)
  #define MUX_STATUS(status) ((status & 0xF000) == 0x8000)
  #define MUX_BREAK(status) ((status & 0xF000) == 0x2000)
  
  #define MUX_NR 256
5076c1586   Helge Deller   [PARISC] I/O-Spac...
52
  static unsigned int port_cnt __read_mostly;
4bd5d8277   Ryan Bradetich   [PARISC] [MUX] Mu...
53
54
55
56
57
  struct mux_port {
  	struct uart_port port;
  	int enabled;
  };
  static struct mux_port mux_ports[MUX_NR];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
58
59
60
61
62
63
64
65
66
67
68
  
  static struct uart_driver mux_driver = {
  	.owner = THIS_MODULE,
  	.driver_name = "ttyB",
  	.dev_name = "ttyB",
  	.major = MUX_MAJOR,
  	.minor = 0,
  	.nr = MUX_NR,
  };
  
  static struct timer_list mux_timer;
92495c0eb   Ryan Bradetich   [PARISC] Compile ...
69
70
  #define UART_PUT_CHAR(p, c) __raw_writel((c), (p)->membase + IO_DATA_REG_OFFSET)
  #define UART_GET_FIFO_CNT(p) __raw_readl((p)->membase + IO_DCOUNT_REG_OFFSET)
614254458   Ryan Bradetich   [PARISC] [MUX] Co...
71
72
73
74
75
76
77
78
79
80
81
82
83
  
  /**
   * get_mux_port_count - Get the number of available ports on the Mux.
   * @dev: The parisc device.
   *
   * This function is used to determine the number of ports the Mux
   * supports.  The IODC data reports the number of ports the Mux
   * can support, but there are cases where not all the Mux ports
   * are connected.  This function can override the IODC and
   * return the true port count.
   */
  static int __init get_mux_port_count(struct parisc_device *dev)
  {
514fb84e1   Ryan Bradetich   [PARISC] [MUX] Ge...
84
  	int status;
614254458   Ryan Bradetich   [PARISC] [MUX] Co...
85
86
  	u8 iodc_data[32];
  	unsigned long bytecnt;
614254458   Ryan Bradetich   [PARISC] [MUX] Co...
87
88
89
90
  	/* If this is the built-in Mux for the K-Class (Eole CAP/MUX),
  	 * we only need to allocate resources for 1 port since the
  	 * other 7 ports are not connected.
  	 */
514fb84e1   Ryan Bradetich   [PARISC] [MUX] Ge...
91
  	if(dev->id.hversion == 0x15)
614254458   Ryan Bradetich   [PARISC] [MUX] Co...
92
  		return 1;
514fb84e1   Ryan Bradetich   [PARISC] [MUX] Ge...
93
94
  	status = pdc_iodc_read(&bytecnt, dev->hpa.start, 0, iodc_data, 32);
  	BUG_ON(status != PDC_OK);
614254458   Ryan Bradetich   [PARISC] [MUX] Co...
95
96
97
  	/* Return the number of ports specified in the iodc data. */
  	return ((((iodc_data)[4] & 0xf0) >> 4) * 8) + 8;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
99
100
101
102
103
104
105
106
107
108
  
  /**
   * mux_tx_empty - Check if the transmitter fifo is empty.
   * @port: Ptr to the uart_port.
   *
   * This function test if the transmitter fifo for the port
   * described by 'port' is empty.  If it is empty, this function
   * should return TIOCSER_TEMT, otherwise return 0.
   */
  static unsigned int mux_tx_empty(struct uart_port *port)
  {
92495c0eb   Ryan Bradetich   [PARISC] Compile ...
109
  	return UART_GET_FIFO_CNT(port) ? 0 : TIOCSER_TEMT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
  } 
  
  /**
   * mux_set_mctrl - Set the current state of the modem control inputs.
   * @ports: Ptr to the uart_port.
   * @mctrl: Modem control bits.
   *
   * The Serial MUX does not support CTS, DCD or DSR so this function
   * is ignored.
   */
  static void mux_set_mctrl(struct uart_port *port, unsigned int mctrl)
  {
  }
  
  /**
   * mux_get_mctrl - Returns the current state of modem control inputs.
   * @port: Ptr to the uart_port.
   *
   * The Serial MUX does not support CTS, DCD or DSR so these lines are
   * treated as permanently active.
   */
  static unsigned int mux_get_mctrl(struct uart_port *port)
  { 
  	return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
  }
  
  /**
   * mux_stop_tx - Stop transmitting characters.
   * @port: Ptr to the uart_port.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
139
140
141
   *
   * The Serial MUX does not support this function.
   */
b129a8ccd   Russell King   [SERIAL] Clean up...
142
  static void mux_stop_tx(struct uart_port *port)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
143
144
145
146
147
148
  {
  }
  
  /**
   * mux_start_tx - Start transmitting characters.
   * @port: Ptr to the uart_port.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
149
150
151
   *
   * The Serial Mux does not support this function.
   */
b129a8ccd   Russell King   [SERIAL] Clean up...
152
  static void mux_start_tx(struct uart_port *port)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
  {
  }
  
  /**
   * mux_stop_rx - Stop receiving characters.
   * @port: Ptr to the uart_port.
   *
   * The Serial Mux does not support this function.
   */
  static void mux_stop_rx(struct uart_port *port)
  {
  }
  
  /**
   * mux_enable_ms - Enable modum status interrupts.
   * @port: Ptr to the uart_port.
   *
   * The Serial Mux does not support this function.
   */
  static void mux_enable_ms(struct uart_port *port)
  {
  }
  
  /**
   * mux_break_ctl - Control the transmitssion of a break signal.
   * @port: Ptr to the uart_port.
   * @break_state: Raise/Lower the break signal.
   *
   * The Serial Mux does not support this function.
   */
  static void mux_break_ctl(struct uart_port *port, int break_state)
  {
  }
  
  /**
   * mux_write - Write chars to the mux fifo.
   * @port: Ptr to the uart_port.
   *
   * This function writes all the data from the uart buffer to
   * the mux fifo.
   */
  static void mux_write(struct uart_port *port)
  {
  	int count;
  	struct circ_buf *xmit = &port->info->xmit;
  
  	if(port->x_char) {
  		UART_PUT_CHAR(port, port->x_char);
  		port->icount.tx++;
  		port->x_char = 0;
  		return;
  	}
  
  	if(uart_circ_empty(xmit) || uart_tx_stopped(port)) {
b129a8ccd   Russell King   [SERIAL] Clean up...
207
  		mux_stop_tx(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
  		return;
  	}
  
  	count = (port->fifosize) - UART_GET_FIFO_CNT(port);
  	do {
  		UART_PUT_CHAR(port, xmit->buf[xmit->tail]);
  		xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
  		port->icount.tx++;
  		if(uart_circ_empty(xmit))
  			break;
  
  	} while(--count > 0);
  
  	while(UART_GET_FIFO_CNT(port)) 
  		udelay(1);
  
  	if(uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
  		uart_write_wakeup(port);
  
  	if (uart_circ_empty(xmit))
b129a8ccd   Russell King   [SERIAL] Clean up...
228
  		mux_stop_tx(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
229
230
231
232
233
234
235
236
237
238
239
240
  }
  
  /**
   * mux_read - Read chars from the mux fifo.
   * @port: Ptr to the uart_port.
   *
   * This reads all available data from the mux's fifo and pushes
   * the data to the tty layer.
   */
  static void mux_read(struct uart_port *port)
  {
  	int data;
a88487c79   Takashi Iwai   Fix compile error...
241
  	struct tty_struct *tty = port->info->port.tty;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
242
243
244
  	__u32 start_count = port->icount.rx;
  
  	while(1) {
92495c0eb   Ryan Bradetich   [PARISC] Compile ...
245
  		data = __raw_readl(port->membase + IO_DATA_REG_OFFSET);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
246
247
248
249
250
251
  
  		if (MUX_STATUS(data))
  			continue;
  
  		if (MUX_EOFIFO(data))
  			break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
252
253
254
255
256
257
258
  		port->icount.rx++;
  
  		if (MUX_BREAK(data)) {
  			port->icount.brk++;
  			if(uart_handle_break(port))
  				continue;
  		}
be577a522   Matthew Wilcox   Build fixes for s...
259
  		if (uart_handle_sysrq_char(port, data & 0xffu))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
260
  			continue;
33f0f88f1   Alan Cox   [PATCH] TTY layer...
261
  		tty_insert_flip_char(tty, data & 0xFF, TTY_NORMAL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
  	}
  	
  	if (start_count != port->icount.rx) {
  		tty_flip_buffer_push(tty);
  	}
  }
  
  /**
   * mux_startup - Initialize the port.
   * @port: Ptr to the uart_port.
   *
   * Grab any resources needed for this port and start the
   * mux timer.
   */
  static int mux_startup(struct uart_port *port)
  {
4bd5d8277   Ryan Bradetich   [PARISC] [MUX] Mu...
278
  	mux_ports[port->line].enabled = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
279
280
281
282
283
284
285
286
287
288
289
  	return 0;
  }
  
  /**
   * mux_shutdown - Disable the port.
   * @port: Ptr to the uart_port.
   *
   * Release any resources needed for the port.
   */
  static void mux_shutdown(struct uart_port *port)
  {
4bd5d8277   Ryan Bradetich   [PARISC] [MUX] Mu...
290
  	mux_ports[port->line].enabled = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
291
292
293
294
295
296
297
298
299
300
301
  }
  
  /**
   * mux_set_termios - Chane port parameters.
   * @port: Ptr to the uart_port.
   * @termios: new termios settings.
   * @old: old termios settings.
   *
   * The Serial Mux does not support this function.
   */
  static void
606d099cd   Alan Cox   [PATCH] tty: swit...
302
303
  mux_set_termios(struct uart_port *port, struct ktermios *termios,
  	        struct ktermios *old)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
  {
  }
  
  /**
   * mux_type - Describe the port.
   * @port: Ptr to the uart_port.
   *
   * Return a pointer to a string constant describing the
   * specified port.
   */
  static const char *mux_type(struct uart_port *port)
  {
  	return "Mux";
  }
  
  /**
   * mux_release_port - Release memory and IO regions.
   * @port: Ptr to the uart_port.
   * 
   * Release any memory and IO region resources currently in use by
   * the port.
   */
  static void mux_release_port(struct uart_port *port)
  {
  }
  
  /**
   * mux_request_port - Request memory and IO regions.
   * @port: Ptr to the uart_port.
   *
   * Request any memory and IO region resources required by the port.
   * If any fail, no resources should be registered when this function
   * returns, and it should return -EBUSY on failure.
   */
  static int mux_request_port(struct uart_port *port)
  {
  	return 0;
  }
  
  /**
   * mux_config_port - Perform port autoconfiguration.
   * @port: Ptr to the uart_port.
   * @type: Bitmask of required configurations.
   *
4bd5d8277   Ryan Bradetich   [PARISC] [MUX] Mu...
348
   * Perform any autoconfiguration steps for the port.  This function is
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
   * called if the UPF_BOOT_AUTOCONF flag is specified for the port.
   * [Note: This is required for now because of a bug in the Serial core.
   *  rmk has already submitted a patch to linus, should be available for
   *  2.5.47.]
   */
  static void mux_config_port(struct uart_port *port, int type)
  {
  	port->type = PORT_MUX;
  }
  
  /**
   * mux_verify_port - Verify the port information.
   * @port: Ptr to the uart_port.
   * @ser: Ptr to the serial information.
   *
   * Verify the new serial port information contained within serinfo is
   * suitable for this port type.
   */
  static int mux_verify_port(struct uart_port *port, struct serial_struct *ser)
  {
  	if(port->membase == NULL)
  		return -EINVAL;
  
  	return 0;
  }
  
  /**
   * mux_drv_poll - Mux poll function.
   * @unused: Unused variable
   *
   * This function periodically polls the Serial MUX to check for new data.
   */
  static void mux_poll(unsigned long unused)
  {  
  	int i;
  
  	for(i = 0; i < port_cnt; ++i) {
4bd5d8277   Ryan Bradetich   [PARISC] [MUX] Mu...
386
  		if(!mux_ports[i].enabled)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
387
  			continue;
4bd5d8277   Ryan Bradetich   [PARISC] [MUX] Mu...
388
389
  		mux_read(&mux_ports[i].port);
  		mux_write(&mux_ports[i].port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
390
391
392
393
394
395
396
397
398
  	}
  
  	mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
  }
  
  
  #ifdef CONFIG_SERIAL_MUX_CONSOLE
  static void mux_console_write(struct console *co, const char *s, unsigned count)
  {
3de7b6482   Ryan Bradetich   [PARISC] [MUX] Mu...
399
400
401
402
403
404
405
406
407
408
409
  	/* Wait until the FIFO drains. */
  	while(UART_GET_FIFO_CNT(&mux_ports[0].port))
  		udelay(1);
  
  	while(count--) {
  		if(*s == '
  ') {
  			UART_PUT_CHAR(&mux_ports[0].port, '\r');
  		}
  		UART_PUT_CHAR(&mux_ports[0].port, *s++);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
  }
  
  static int mux_console_setup(struct console *co, char *options)
  {
          return 0;
  }
  
  struct tty_driver *mux_console_device(struct console *co, int *index)
  {
          *index = co->index;
  	return mux_driver.tty_driver;
  }
  
  static struct console mux_console = {
  	.name =		"ttyB",
  	.write =	mux_console_write,
  	.device =	mux_console_device,
  	.setup =	mux_console_setup,
  	.flags =	CON_ENABLED | CON_PRINTBUFFER,
  	.index =	0,
  };
  
  #define MUX_CONSOLE	&mux_console
  #else
  #define MUX_CONSOLE	NULL
  #endif
  
  static struct uart_ops mux_pops = {
  	.tx_empty =		mux_tx_empty,
  	.set_mctrl =		mux_set_mctrl,
  	.get_mctrl =		mux_get_mctrl,
  	.stop_tx =		mux_stop_tx,
  	.start_tx =		mux_start_tx,
  	.stop_rx =		mux_stop_rx,
  	.enable_ms =		mux_enable_ms,
  	.break_ctl =		mux_break_ctl,
  	.startup =		mux_startup,
  	.shutdown =		mux_shutdown,
  	.set_termios =		mux_set_termios,
  	.type =			mux_type,
  	.release_port =		mux_release_port,
  	.request_port =		mux_request_port,
  	.config_port =		mux_config_port,
  	.verify_port =		mux_verify_port,
  };
  
  /**
   * mux_probe - Determine if the Serial Mux should claim this device.
   * @dev: The parisc device.
   *
   * Deterimine if the Serial Mux should claim this chip (return 0)
   * or not (return 1).
   */
  static int __init mux_probe(struct parisc_device *dev)
  {
614254458   Ryan Bradetich   [PARISC] [MUX] Co...
465
  	int i, status;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
466

614254458   Ryan Bradetich   [PARISC] [MUX] Co...
467
  	int port_count = get_mux_port_count(dev);
752b94035   Ryan Bradetich   [PARISC] [MUX] De...
468
469
  	printk(KERN_INFO "Serial mux driver (%d ports) Revision: 0.6
  ", port_count);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
470

c380f0572   Ryan Bradetich   [PARISC] [MUX] Ma...
471
472
473
  	dev_set_drvdata(&dev->dev, (void *)(long)port_count);
  	request_mem_region(dev->hpa.start + MUX_OFFSET,
                             port_count * MUX_LINE_OFFSET, "Mux");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
474
475
476
477
478
479
480
481
482
483
  
  	if(!port_cnt) {
  		mux_driver.cons = MUX_CONSOLE;
  
  		status = uart_register_driver(&mux_driver);
  		if(status) {
  			printk(KERN_ERR "Serial mux: Unable to register driver.
  ");
  			return 1;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
484
  	}
c380f0572   Ryan Bradetich   [PARISC] [MUX] Ma...
485
486
  	for(i = 0; i < port_count; ++i, ++port_cnt) {
  		struct uart_port *port = &mux_ports[port_cnt].port;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
487
  		port->iobase	= 0;
ae8c75c1c   Matthew Wilcox   [PARISC] Fix mux....
488
489
  		port->mapbase	= dev->hpa.start + MUX_OFFSET +
  						(i * MUX_LINE_OFFSET);
5076c1586   Helge Deller   [PARISC] I/O-Spac...
490
  		port->membase	= ioremap_nocache(port->mapbase, MUX_LINE_OFFSET);
9b4a16177   Russell King   [SERIAL] uart_por...
491
  		port->iotype	= UPIO_MEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
492
  		port->type	= PORT_MUX;
ae8c75c1c   Matthew Wilcox   [PARISC] Fix mux....
493
  		port->irq	= NO_IRQ;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
494
495
496
497
498
  		port->uartclk	= 0;
  		port->fifosize	= MUX_FIFO_SIZE;
  		port->ops	= &mux_pops;
  		port->flags	= UPF_BOOT_AUTOCONF;
  		port->line	= port_cnt;
a137ce853   Ryan Bradetich   [PARISC] Define p...
499
500
501
502
503
504
505
  
  		/* The port->timeout needs to match what is present in
  		 * uart_wait_until_sent in serial_core.c.  Otherwise
  		 * the time spent in msleep_interruptable will be very
  		 * long, causing the appearance of a console hang.
  		 */
  		port->timeout   = HZ / 50;
ae8c75c1c   Matthew Wilcox   [PARISC] Fix mux....
506
  		spin_lock_init(&port->lock);
752b94035   Ryan Bradetich   [PARISC] [MUX] De...
507

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
508
509
510
  		status = uart_add_one_port(&mux_driver, port);
  		BUG_ON(status);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
511
512
  	return 0;
  }
c380f0572   Ryan Bradetich   [PARISC] [MUX] Ma...
513
514
  static int __devexit mux_remove(struct parisc_device *dev)
  {
752b94035   Ryan Bradetich   [PARISC] [MUX] De...
515
  	int i, j;
c380f0572   Ryan Bradetich   [PARISC] [MUX] Ma...
516
  	int port_count = (long)dev_get_drvdata(&dev->dev);
c380f0572   Ryan Bradetich   [PARISC] [MUX] Ma...
517
518
519
520
521
522
523
524
  	/* Find Port 0 for this card in the mux_ports list. */
  	for(i = 0; i < port_cnt; ++i) {
  		if(mux_ports[i].port.mapbase == dev->hpa.start + MUX_OFFSET)
  			break;
  	}
  	BUG_ON(i + port_count > port_cnt);
  
  	/* Release the resources associated with each port on the device. */
752b94035   Ryan Bradetich   [PARISC] [MUX] De...
525
  	for(j = 0; j < port_count; ++j, ++i) {
c380f0572   Ryan Bradetich   [PARISC] [MUX] Ma...
526
527
528
529
530
531
532
533
  		struct uart_port *port = &mux_ports[i].port;
  
  		uart_remove_one_port(&mux_driver, port);
  		if(port->membase)
  			iounmap(port->membase);
  	}
  
  	release_mem_region(dev->hpa.start + MUX_OFFSET, port_count * MUX_LINE_OFFSET);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
534
535
  	return 0;
  }
752b94035   Ryan Bradetich   [PARISC] [MUX] De...
536
537
538
539
540
541
542
543
544
545
546
547
548
  /* Hack.  This idea was taken from the 8250_gsc.c on how to properly order
   * the serial port detection in the proper order.   The idea is we always
   * want the builtin mux to be detected before addin mux cards, so we
   * specifically probe for the builtin mux cards first.
   *
   * This table only contains the parisc_device_id of known builtin mux
   * devices.  All other mux cards will be detected by the generic mux_tbl.
   */
  static struct parisc_device_id builtin_mux_tbl[] = {
  	{ HPHW_A_DIRECT, HVERSION_REV_ANY_ID, 0x15, 0x0000D }, /* All K-class */
  	{ HPHW_A_DIRECT, HVERSION_REV_ANY_ID, 0x44, 0x0000D }, /* E35, E45, and E55 */
  	{ 0, }
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
549
550
551
552
  static struct parisc_device_id mux_tbl[] = {
  	{ HPHW_A_DIRECT, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0000D },
  	{ 0, }
  };
752b94035   Ryan Bradetich   [PARISC] [MUX] De...
553
  MODULE_DEVICE_TABLE(parisc, builtin_mux_tbl);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
554
  MODULE_DEVICE_TABLE(parisc, mux_tbl);
752b94035   Ryan Bradetich   [PARISC] [MUX] De...
555
556
557
558
559
560
  static struct parisc_driver builtin_serial_mux_driver = {
  	.name =		"builtin_serial_mux",
  	.id_table =	builtin_mux_tbl,
  	.probe =	mux_probe,
  	.remove =       __devexit_p(mux_remove),
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
561
  static struct parisc_driver serial_mux_driver = {
bdad1f836   Matthew Wilcox   [PARISC] Change t...
562
  	.name =		"serial_mux",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
563
564
  	.id_table =	mux_tbl,
  	.probe =	mux_probe,
c380f0572   Ryan Bradetich   [PARISC] [MUX] Ma...
565
  	.remove =       __devexit_p(mux_remove),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
566
567
568
  };
  
  /**
8f4aafec6   Joe Perches   drivers/serial/: ...
569
   * mux_init - Serial MUX initialization procedure.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
570
571
572
573
574
   *
   * Register the Serial MUX driver.
   */
  static int __init mux_init(void)
  {
752b94035   Ryan Bradetich   [PARISC] [MUX] De...
575
576
  	register_parisc_driver(&builtin_serial_mux_driver);
  	register_parisc_driver(&serial_mux_driver);
c380f0572   Ryan Bradetich   [PARISC] [MUX] Ma...
577
578
579
580
581
582
583
584
585
586
587
  
  	if(port_cnt > 0) {
  		/* Start the Mux timer */
  		init_timer(&mux_timer);
  		mux_timer.function = mux_poll;
  		mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
  
  #ifdef CONFIG_SERIAL_MUX_CONSOLE
  	        register_console(&mux_console);
  #endif
  	}
752b94035   Ryan Bradetich   [PARISC] [MUX] De...
588
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
589
590
591
592
593
594
595
596
597
  }
  
  /**
   * mux_exit - Serial MUX cleanup procedure.
   *
   * Unregister the Serial MUX driver from the tty layer.
   */
  static void __exit mux_exit(void)
  {
c380f0572   Ryan Bradetich   [PARISC] [MUX] Ma...
598
599
600
601
602
603
  	/* Delete the Mux timer. */
  	if(port_cnt > 0) {
  		del_timer(&mux_timer);
  #ifdef CONFIG_SERIAL_MUX_CONSOLE
  		unregister_console(&mux_console);
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
604
  	}
752b94035   Ryan Bradetich   [PARISC] [MUX] De...
605
  	unregister_parisc_driver(&builtin_serial_mux_driver);
c380f0572   Ryan Bradetich   [PARISC] [MUX] Ma...
606
  	unregister_parisc_driver(&serial_mux_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
607
608
609
610
611
612
613
614
615
616
  	uart_unregister_driver(&mux_driver);
  }
  
  module_init(mux_init);
  module_exit(mux_exit);
  
  MODULE_AUTHOR("Ryan Bradetich");
  MODULE_DESCRIPTION("Serial MUX driver");
  MODULE_LICENSE("GPL");
  MODULE_ALIAS_CHARDEV_MAJOR(MUX_MAJOR);