8250_core.c 32.8 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0+
L
Linus Torvalds 已提交
2
/*
3
 *  Universal/legacy driver for 8250/16550-type serial ports
L
Linus Torvalds 已提交
4 5 6 7 8
 *
 *  Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
 *
 *  Copyright (C) 2001 Russell King.
 *
9 10 11 12 13 14
 *  Supports: ISA-compatible 8250/16550 ports
 *	      PNP 8250/16550 ports
 *	      early_serial_setup() ports
 *	      userspace-configurable "phantom" ports
 *	      "serial8250" platform devices
 *	      serial8250_register_8250_port() ports
L
Linus Torvalds 已提交
15 16
 */

17
#include <linux/acpi.h>
L
Linus Torvalds 已提交
18 19 20 21 22 23 24
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/ioport.h>
#include <linux/init.h>
#include <linux/console.h>
#include <linux/sysrq.h>
#include <linux/delay.h>
25
#include <linux/platform_device.h>
L
Linus Torvalds 已提交
26
#include <linux/tty.h>
27
#include <linux/ratelimit.h>
L
Linus Torvalds 已提交
28 29 30
#include <linux/tty_flip.h>
#include <linux/serial.h>
#include <linux/serial_8250.h>
31
#include <linux/nmi.h>
32
#include <linux/mutex.h>
33
#include <linux/slab.h>
34
#include <linux/uaccess.h>
35
#include <linux/io.h>
36 37 38
#ifdef CONFIG_SPARC
#include <linux/sunserialcore.h>
#endif
L
Linus Torvalds 已提交
39 40 41 42 43 44 45

#include <asm/irq.h>

#include "8250.h"

/*
 * Configuration:
46
 *   share_irqs - whether we pass IRQF_SHARED to request_irq().  This option
L
Linus Torvalds 已提交
47 48
 *                is unsafe when used on edge-triggered interrupts.
 */
A
Adrian Bunk 已提交
49
static unsigned int share_irqs = SERIAL8250_SHARE_IRQS;
L
Linus Torvalds 已提交
50

51 52
static unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS;

53 54
static struct uart_driver serial8250_reg;

55 56
static unsigned int skip_txen_test; /* force skip of txen test at init time */

J
Jiri Slaby 已提交
57
#define PASS_LIMIT	512
L
Linus Torvalds 已提交
58

59
#include <asm/serial.h>
L
Linus Torvalds 已提交
60 61 62 63 64 65 66 67 68
/*
 * SERIAL_PORT_DFNS tells us about built-in ports that have no
 * standard enumeration mechanism.   Platforms that can find all
 * serial ports via mechanisms like ACPI or PCI need not supply it.
 */
#ifndef SERIAL_PORT_DFNS
#define SERIAL_PORT_DFNS
#endif

69
static const struct old_serial_port old_serial_port[] = {
L
Linus Torvalds 已提交
70 71 72
	SERIAL_PORT_DFNS /* defined in asm/serial.h */
};

73
#define UART_NR	CONFIG_SERIAL_8250_NR_UARTS
L
Linus Torvalds 已提交
74 75 76 77 78 79 80 81 82

#ifdef CONFIG_SERIAL_8250_RSA

#define PORT_RSA_MAX 4
static unsigned long probe_rsa[PORT_RSA_MAX];
static unsigned int probe_rsa_count;
#endif /* CONFIG_SERIAL_8250_RSA  */

struct irq_info {
A
Alan Cox 已提交
83 84 85
	struct			hlist_node node;
	int			irq;
	spinlock_t		lock;	/* Protects list not the hash */
L
Linus Torvalds 已提交
86 87 88
	struct list_head	*head;
};

A
Alan Cox 已提交
89 90 91
#define NR_IRQ_HASH		32	/* Can be adjusted later */
static struct hlist_head irq_lists[NR_IRQ_HASH];
static DEFINE_MUTEX(hash_mutex);	/* Used to walk the hash */
L
Linus Torvalds 已提交
92 93

/*
94 95 96 97 98 99 100 101 102 103 104 105
 * This is the serial driver's interrupt routine.
 *
 * Arjan thinks the old way was overly complex, so it got simplified.
 * Alan disagrees, saying that need the complexity to handle the weird
 * nature of ISA shared interrupts.  (This is a special exception.)
 *
 * In order to handle ISA shared interrupts properly, we need to check
 * that all ports have been serviced, and therefore the ISA interrupt
 * line has been de-asserted.
 *
 * This means we need to loop through all ports. checking that they
 * don't have an interrupt pending.
L
Linus Torvalds 已提交
106
 */
107
static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
108
{
109 110 111
	struct irq_info *i = dev_id;
	struct list_head *l, *end = NULL;
	int pass_counter = 0, handled = 0;
112

J
Jiri Slaby 已提交
113
	pr_debug("%s(%d): start\n", __func__, irq);
114

115
	spin_lock(&i->lock);
116

117 118 119 120
	l = i->head;
	do {
		struct uart_8250_port *up;
		struct uart_port *port;
121

122 123
		up = list_entry(l, struct uart_8250_port, list);
		port = &up->port;
L
Linus Torvalds 已提交
124

125 126 127 128 129
		if (port->handle_irq(port)) {
			handled = 1;
			end = NULL;
		} else if (end == NULL)
			end = l;
L
Linus Torvalds 已提交
130

131
		l = l->next;
L
Linus Torvalds 已提交
132

133
		if (l == i->head && pass_counter++ > PASS_LIMIT)
134 135
			break;
	} while (l != end);
136

137
	spin_unlock(&i->lock);
138

J
Jiri Slaby 已提交
139
	pr_debug("%s(%d): end\n", __func__, irq);
L
Linus Torvalds 已提交
140

141
	return IRQ_RETVAL(handled);
A
Alex Williamson 已提交
142 143
}

L
Linus Torvalds 已提交
144
/*
145 146 147 148 149
 * To support ISA shared interrupts, we need to have one interrupt
 * handler that ensures that the IRQ line has been deasserted
 * before returning.  Failing to do this will result in the IRQ
 * line being stuck active, and, since ISA irqs are edge triggered,
 * no more IRQs will be seen.
L
Linus Torvalds 已提交
150
 */
151
static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
L
Linus Torvalds 已提交
152
{
153
	spin_lock_irq(&i->lock);
L
Linus Torvalds 已提交
154

155 156 157 158 159 160 161 162 163 164 165 166 167
	if (!list_empty(i->head)) {
		if (i->head == &up->list)
			i->head = i->head->next;
		list_del(&up->list);
	} else {
		BUG_ON(i->head != &up->list);
		i->head = NULL;
	}
	spin_unlock_irq(&i->lock);
	/* List empty so throw away the hash node */
	if (i->head == NULL) {
		hlist_del(&i->node);
		kfree(i);
L
Linus Torvalds 已提交
168 169 170
	}
}

171
static int serial_link_irq_chain(struct uart_8250_port *up)
172
{
173 174
	struct hlist_head *h;
	struct irq_info *i;
175
	int ret;
176

177
	mutex_lock(&hash_mutex);
178

179
	h = &irq_lists[up->port.irq % NR_IRQ_HASH];
180

181
	hlist_for_each_entry(i, h, node)
182 183
		if (i->irq == up->port.irq)
			break;
184

185
	if (i == NULL) {
186 187 188 189 190 191 192 193 194 195
		i = kzalloc(sizeof(struct irq_info), GFP_KERNEL);
		if (i == NULL) {
			mutex_unlock(&hash_mutex);
			return -ENOMEM;
		}
		spin_lock_init(&i->lock);
		i->irq = up->port.irq;
		hlist_add_head(&i->node, h);
	}
	mutex_unlock(&hash_mutex);
196

197
	spin_lock_irq(&i->lock);
198

199 200 201
	if (i->head) {
		list_add(&up->list, i->head);
		spin_unlock_irq(&i->lock);
202

203 204 205 206 207 208
		ret = 0;
	} else {
		INIT_LIST_HEAD(&up->list);
		i->head = &up->list;
		spin_unlock_irq(&i->lock);
		ret = request_irq(up->port.irq, serial8250_interrupt,
209
				  up->port.irqflags, up->port.name, i);
210 211 212
		if (ret < 0)
			serial_do_unlink(i, up);
	}
213

214
	return ret;
215 216
}

217
static void serial_unlink_irq_chain(struct uart_8250_port *up)
L
Linus Torvalds 已提交
218
{
219 220
	struct irq_info *i;
	struct hlist_head *h;
L
Linus Torvalds 已提交
221

222
	mutex_lock(&hash_mutex);
L
Linus Torvalds 已提交
223

224
	h = &irq_lists[up->port.irq % NR_IRQ_HASH];
L
Linus Torvalds 已提交
225

226
	hlist_for_each_entry(i, h, node)
227 228
		if (i->irq == up->port.irq)
			break;
L
Linus Torvalds 已提交
229

230
	BUG_ON(i == NULL);
231
	BUG_ON(i->head == NULL);
L
Linus Torvalds 已提交
232

233 234
	if (list_empty(i->head))
		free_irq(up->port.irq, i);
L
Linus Torvalds 已提交
235

236 237
	serial_do_unlink(i, up);
	mutex_unlock(&hash_mutex);
L
Linus Torvalds 已提交
238 239 240
}

/*
241 242 243 244
 * This function is used to handle ports that do not have an
 * interrupt.  This doesn't work very well for 16450's, but gives
 * barely passable results for a 16550A.  (Although at the expense
 * of much CPU overhead).
L
Linus Torvalds 已提交
245
 */
246
static void serial8250_timeout(struct timer_list *t)
L
Linus Torvalds 已提交
247
{
248
	struct uart_8250_port *up = from_timer(up, t, timer);
L
Linus Torvalds 已提交
249

250 251 252
	up->port.handle_irq(&up->port);
	mod_timer(&up->timer, jiffies + uart_poll_timeout(&up->port));
}
L
Linus Torvalds 已提交
253

254
static void serial8250_backup_timeout(struct timer_list *t)
255
{
256
	struct uart_8250_port *up = from_timer(up, t, timer);
257
	unsigned int iir, ier = 0, lsr;
258
	unsigned long flags;
L
Linus Torvalds 已提交
259

260
	spin_lock_irqsave(&up->port.lock, flags);
261

L
Linus Torvalds 已提交
262
	/*
263 264
	 * Must disable interrupts or else we risk racing with the interrupt
	 * based handler.
L
Linus Torvalds 已提交
265
	 */
266 267 268
	if (up->port.irq) {
		ier = serial_in(up, UART_IER);
		serial_out(up, UART_IER, 0);
L
Linus Torvalds 已提交
269
	}
270

271
	iir = serial_in(up, UART_IIR);
L
Linus Torvalds 已提交
272

273 274 275 276 277 278
	/*
	 * This should be a safe test for anyone who doesn't trust the
	 * IIR bits on their UART, but it's specifically designed for
	 * the "Diva" UART used on the management processor on many HP
	 * ia64 and parisc boxes.
	 */
279
	lsr = serial_lsr_in(up);
280 281 282 283 284
	if ((iir & UART_IIR_NO_INT) && (up->ier & UART_IER_THRI) &&
	    (!uart_circ_empty(&up->port.state->xmit) || up->port.x_char) &&
	    (lsr & UART_LSR_THRE)) {
		iir &= ~(UART_IIR_ID | UART_IIR_NO_INT);
		iir |= UART_IIR_THRI;
285
	}
286

287 288
	if (!(iir & UART_IIR_NO_INT))
		serial8250_tx_chars(up);
L
Linus Torvalds 已提交
289

290 291
	if (up->port.irq)
		serial_out(up, UART_IER, ier);
L
Linus Torvalds 已提交
292

293
	spin_unlock_irqrestore(&up->port.lock, flags);
294

295 296 297
	/* Standard timer interval plus 0.2s to keep the port running */
	mod_timer(&up->timer,
		jiffies + uart_poll_timeout(&up->port) + HZ / 5);
298 299
}

300
static int univ8250_setup_irq(struct uart_8250_port *up)
L
Linus Torvalds 已提交
301
{
302
	struct uart_port *port = &up->port;
303
	int retval = 0;
L
Linus Torvalds 已提交
304

305 306 307 308 309
	/*
	 * The above check will only give an accurate result the first time
	 * the port is opened so this value needs to be preserved.
	 */
	if (up->bugs & UART_BUG_THRE) {
310
		pr_debug("%s - using backup timer\n", port->name);
L
Linus Torvalds 已提交
311

312
		up->timer.function = serial8250_backup_timeout;
313 314 315
		mod_timer(&up->timer, jiffies +
			  uart_poll_timeout(port) + HZ / 5);
	}
L
Linus Torvalds 已提交
316

317 318 319 320 321
	/*
	 * If the "interrupt" for this port doesn't correspond with any
	 * hardware interrupt, we use a timer-based system.  The original
	 * driver used to do this with IRQ0.
	 */
322
	if (!port->irq)
323
		mod_timer(&up->timer, jiffies + uart_poll_timeout(port));
324
	else
325
		retval = serial_link_irq_chain(up);
L
Linus Torvalds 已提交
326

327
	return retval;
L
Linus Torvalds 已提交
328 329
}

330
static void univ8250_release_irq(struct uart_8250_port *up)
L
Linus Torvalds 已提交
331
{
332
	struct uart_port *port = &up->port;
L
Linus Torvalds 已提交
333

334
	del_timer_sync(&up->timer);
335
	up->timer.function = serial8250_timeout;
336 337
	if (port->irq)
		serial_unlink_irq_chain(up);
L
Linus Torvalds 已提交
338 339
}

340
#ifdef CONFIG_SERIAL_8250_RSA
L
Linus Torvalds 已提交
341 342 343 344
static int serial8250_request_rsa_resource(struct uart_8250_port *up)
{
	unsigned long start = UART_RSA_BASE << up->port.regshift;
	unsigned int size = 8 << up->port.regshift;
345
	struct uart_port *port = &up->port;
346
	int ret = -EINVAL;
L
Linus Torvalds 已提交
347

348
	switch (port->iotype) {
L
Linus Torvalds 已提交
349 350
	case UPIO_HUB6:
	case UPIO_PORT:
351
		start += port->iobase;
352 353 354
		if (request_region(start, size, "serial-rsa"))
			ret = 0;
		else
L
Linus Torvalds 已提交
355 356 357 358 359 360 361 362 363 364 365
			ret = -EBUSY;
		break;
	}

	return ret;
}

static void serial8250_release_rsa_resource(struct uart_8250_port *up)
{
	unsigned long offset = UART_RSA_BASE << up->port.regshift;
	unsigned int size = 8 << up->port.regshift;
366
	struct uart_port *port = &up->port;
L
Linus Torvalds 已提交
367

368
	switch (port->iotype) {
L
Linus Torvalds 已提交
369 370
	case UPIO_HUB6:
	case UPIO_PORT:
371
		release_region(port->iobase + offset, size);
L
Linus Torvalds 已提交
372 373 374
		break;
	}
}
375
#endif
L
Linus Torvalds 已提交
376

P
Peter Hurley 已提交
377 378 379
static const struct uart_ops *base_ops;
static struct uart_ops univ8250_port_ops;

380 381 382 383 384
static const struct uart_8250_ops univ8250_driver_ops = {
	.setup_irq	= univ8250_setup_irq,
	.release_irq	= univ8250_release_irq,
};

L
Linus Torvalds 已提交
385 386
static struct uart_8250_port serial8250_ports[UART_NR];

387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
/**
 * serial8250_get_port - retrieve struct uart_8250_port
 * @line: serial line number
 *
 * This function retrieves struct uart_8250_port for the specific line.
 * This struct *must* *not* be used to perform a 8250 or serial core operation
 * which is not accessible otherwise. Its only purpose is to make the struct
 * accessible to the runtime-pm callbacks for context suspend/restore.
 * The lock assumption made here is none because runtime-pm suspend/resume
 * callbacks should not be invoked if there is any operation performed on the
 * port.
 */
struct uart_8250_port *serial8250_get_port(int line)
{
	return &serial8250_ports[line];
}
EXPORT_SYMBOL_GPL(serial8250_get_port);

405
static void (*serial8250_isa_config)(int port, struct uart_port *up,
406
	u32 *capabilities);
407 408

void serial8250_set_isa_configurator(
409
	void (*v)(int port, struct uart_port *up, u32 *capabilities))
410 411 412 413 414
{
	serial8250_isa_config = v;
}
EXPORT_SYMBOL(serial8250_set_isa_configurator);

P
Peter Hurley 已提交
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 465 466 467 468 469 470 471 472 473 474 475 476 477
#ifdef CONFIG_SERIAL_8250_RSA

static void univ8250_config_port(struct uart_port *port, int flags)
{
	struct uart_8250_port *up = up_to_u8250p(port);

	up->probe &= ~UART_PROBE_RSA;
	if (port->type == PORT_RSA) {
		if (serial8250_request_rsa_resource(up) == 0)
			up->probe |= UART_PROBE_RSA;
	} else if (flags & UART_CONFIG_TYPE) {
		int i;

		for (i = 0; i < probe_rsa_count; i++) {
			if (probe_rsa[i] == up->port.iobase) {
				if (serial8250_request_rsa_resource(up) == 0)
					up->probe |= UART_PROBE_RSA;
				break;
			}
		}
	}

	base_ops->config_port(port, flags);

	if (port->type != PORT_RSA && up->probe & UART_PROBE_RSA)
		serial8250_release_rsa_resource(up);
}

static int univ8250_request_port(struct uart_port *port)
{
	struct uart_8250_port *up = up_to_u8250p(port);
	int ret;

	ret = base_ops->request_port(port);
	if (ret == 0 && port->type == PORT_RSA) {
		ret = serial8250_request_rsa_resource(up);
		if (ret < 0)
			base_ops->release_port(port);
	}

	return ret;
}

static void univ8250_release_port(struct uart_port *port)
{
	struct uart_8250_port *up = up_to_u8250p(port);

	if (port->type == PORT_RSA)
		serial8250_release_rsa_resource(up);
	base_ops->release_port(port);
}

static void univ8250_rsa_support(struct uart_ops *ops)
{
	ops->config_port  = univ8250_config_port;
	ops->request_port = univ8250_request_port;
	ops->release_port = univ8250_release_port;
}

#else
#define univ8250_rsa_support(x)		do { } while (0)
#endif /* CONFIG_SERIAL_8250_RSA */

478 479 480 481 482
static inline void serial8250_apply_quirks(struct uart_8250_port *up)
{
	up->port.quirks |= skip_txen_test ? UPQ_NO_TXEN_TEST : 0;
}

L
Linus Torvalds 已提交
483 484 485 486
static void __init serial8250_isa_init_ports(void)
{
	struct uart_8250_port *up;
	static int first = 1;
487
	int i, irqflag = 0;
L
Linus Torvalds 已提交
488 489 490 491 492

	if (!first)
		return;
	first = 0;

493 494 495
	if (nr_uarts > UART_NR)
		nr_uarts = UART_NR;

496
	for (i = 0; i < nr_uarts; i++) {
L
Linus Torvalds 已提交
497
		struct uart_8250_port *up = &serial8250_ports[i];
498
		struct uart_port *port = &up->port;
L
Linus Torvalds 已提交
499

500
		port->line = i;
501
		serial8250_init_port(up);
P
Peter Hurley 已提交
502 503 504
		if (!base_ops)
			base_ops = port->ops;
		port->ops = &univ8250_port_ops;
L
Linus Torvalds 已提交
505

506
		timer_setup(&up->timer, serial8250_timeout, 0);
L
Linus Torvalds 已提交
507

508 509
		up->ops = &univ8250_driver_ops;

510 511 512 513
		if (IS_ENABLED(CONFIG_ALPHA_JENSEN) ||
		    (IS_ENABLED(CONFIG_ALPHA_GENERIC) && alpha_jensen()))
			port->set_mctrl = alpha_jensen_set_mctrl;

514
		serial8250_set_defaults(up);
L
Linus Torvalds 已提交
515 516
	}

P
Peter Hurley 已提交
517 518 519 520
	/* chain base port ops to support Remote Supervisor Adapter */
	univ8250_port_ops = *base_ops;
	univ8250_rsa_support(&univ8250_port_ops);

521 522 523
	if (share_irqs)
		irqflag = IRQF_SHARED;

524
	for (i = 0, up = serial8250_ports;
525
	     i < ARRAY_SIZE(old_serial_port) && i < nr_uarts;
L
Linus Torvalds 已提交
526
	     i++, up++) {
527 528 529 530
		struct uart_port *port = &up->port;

		port->iobase   = old_serial_port[i].port;
		port->irq      = irq_canonicalize(old_serial_port[i].irq);
531
		port->irqflags = 0;
532 533
		port->uartclk  = old_serial_port[i].baud_base * 16;
		port->flags    = old_serial_port[i].flags;
534
		port->hub6     = 0;
535 536 537
		port->membase  = old_serial_port[i].iomem_base;
		port->iotype   = old_serial_port[i].io_type;
		port->regshift = old_serial_port[i].iomem_reg_shift;
538

539
		port->irqflags |= irqflag;
540 541
		if (serial8250_isa_config != NULL)
			serial8250_isa_config(i, &up->port, &up->capabilities);
L
Linus Torvalds 已提交
542 543 544 545 546 547 548 549
	}
}

static void __init
serial8250_register_ports(struct uart_driver *drv, struct device *dev)
{
	int i;

A
Alan Cox 已提交
550 551 552
	for (i = 0; i < nr_uarts; i++) {
		struct uart_8250_port *up = &serial8250_ports[i];

553 554 555
		if (up->port.type == PORT_8250_CIR)
			continue;

556 557
		if (up->port.dev)
			continue;
L
Linus Torvalds 已提交
558 559

		up->port.dev = dev;
560

561
		serial8250_apply_quirks(up);
L
Linus Torvalds 已提交
562 563 564 565 566 567
		uart_add_one_port(drv, &up->port);
	}
}

#ifdef CONFIG_SERIAL_8250_CONSOLE

568 569 570 571 572 573 574 575 576 577
static void univ8250_console_write(struct console *co, const char *s,
				   unsigned int count)
{
	struct uart_8250_port *up = &serial8250_ports[co->index];

	serial8250_console_write(up, s, count);
}

static int univ8250_console_setup(struct console *co, char *options)
{
578
	struct uart_port *port;
579
	int retval;
580

L
Linus Torvalds 已提交
581 582 583 584 585
	/*
	 * Check whether an invalid uart number has been specified, and
	 * if so, search for the first available port that does have
	 * console support.
	 */
586
	if (co->index >= nr_uarts)
L
Linus Torvalds 已提交
587
		co->index = 0;
588
	port = &serial8250_ports[co->index].port;
589
	/* link port to console */
590
	port->cons = co;
L
Linus Torvalds 已提交
591

592 593 594 595
	retval = serial8250_console_setup(port, options, false);
	if (retval != 0)
		port->cons = NULL;
	return retval;
L
Linus Torvalds 已提交
596 597
}

598 599 600 601 602 603 604 605
static int univ8250_console_exit(struct console *co)
{
	struct uart_port *port;

	port = &serial8250_ports[co->index].port;
	return serial8250_console_exit(port);
}

606
/**
607
 *	univ8250_console_match - non-standard console matching
608 609 610 611 612 613
 *	@co:	  registering console
 *	@name:	  name from console command line
 *	@idx:	  index from console command line
 *	@options: ptr to option string from console command line
 *
 *	Only attempts to match console command lines of the form:
614
 *	    console=uart[8250],io|mmio|mmio16|mmio32,<addr>[,<options>]
615
 *	    console=uart[8250],0x<addr>[,<options>]
616 617 618 619
 *	This form is used to register an initial earlycon boot console and
 *	replace it with the serial8250_console at 8250 driver init.
 *
 *	Performs console setup for a match (as required by interface)
620
 *	If no <options> are specified, then assume the h/w is already setup.
621 622 623
 *
 *	Returns 0 if console matches; otherwise non-zero to use default matching
 */
624 625
static int univ8250_console_match(struct console *co, char *name, int idx,
				  char *options)
626
{
627 628
	char match[] = "uart";	/* 8250-specific earlycon name */
	unsigned char iotype;
629
	resource_size_t addr;
630 631 632 633 634 635 636 637 638 639 640 641 642 643
	int i;

	if (strncmp(name, match, 4) != 0)
		return -ENODEV;

	if (uart_parse_earlycon(options, &iotype, &addr, &options))
		return -ENODEV;

	/* try to match the port specified on the command line */
	for (i = 0; i < nr_uarts; i++) {
		struct uart_port *port = &serial8250_ports[i].port;

		if (port->iotype != iotype)
			continue;
644 645 646
		if ((iotype == UPIO_MEM || iotype == UPIO_MEM16 ||
		     iotype == UPIO_MEM32 || iotype == UPIO_MEM32BE)
		    && (port->mapbase != addr))
647 648 649 650 651
			continue;
		if (iotype == UPIO_PORT && port->iobase != addr)
			continue;

		co->index = i;
652 653
		port->cons = co;
		return serial8250_console_setup(port, options, true);
654 655 656
	}

	return -ENODEV;
657 658
}

659
static struct console univ8250_console = {
L
Linus Torvalds 已提交
660
	.name		= "ttyS",
661
	.write		= univ8250_console_write,
L
Linus Torvalds 已提交
662
	.device		= uart_console_device,
663
	.setup		= univ8250_console_setup,
664
	.exit		= univ8250_console_exit,
665
	.match		= univ8250_console_match,
666
	.flags		= CON_PRINTBUFFER | CON_ANYTIME,
L
Linus Torvalds 已提交
667 668 669 670
	.index		= -1,
	.data		= &serial8250_reg,
};

671
static int __init univ8250_console_init(void)
L
Linus Torvalds 已提交
672
{
673 674 675
	if (nr_uarts == 0)
		return -ENODEV;

L
Linus Torvalds 已提交
676
	serial8250_isa_init_ports();
677
	register_console(&univ8250_console);
L
Linus Torvalds 已提交
678 679
	return 0;
}
680
console_initcall(univ8250_console_init);
L
Linus Torvalds 已提交
681

682
#define SERIAL8250_CONSOLE	(&univ8250_console)
L
Linus Torvalds 已提交
683 684 685 686 687 688 689 690 691 692 693 694 695
#else
#define SERIAL8250_CONSOLE	NULL
#endif

static struct uart_driver serial8250_reg = {
	.owner			= THIS_MODULE,
	.driver_name		= "serial",
	.dev_name		= "ttyS",
	.major			= TTY_MAJOR,
	.minor			= 64,
	.cons			= SERIAL8250_CONSOLE,
};

696 697 698 699 700 701
/*
 * early_serial_setup - early registration for 8250 ports
 *
 * Setup an 8250 port structure prior to console initialisation.  Use
 * after console initialisation will cause undefined behaviour.
 */
L
Linus Torvalds 已提交
702 703
int __init early_serial_setup(struct uart_port *port)
{
D
David Daney 已提交
704 705
	struct uart_port *p;

706
	if (port->line >= ARRAY_SIZE(serial8250_ports) || nr_uarts == 0)
L
Linus Torvalds 已提交
707 708 709
		return -ENODEV;

	serial8250_isa_init_ports();
D
David Daney 已提交
710 711 712 713
	p = &serial8250_ports[port->line].port;
	p->iobase       = port->iobase;
	p->membase      = port->membase;
	p->irq          = port->irq;
714
	p->irqflags     = port->irqflags;
D
David Daney 已提交
715 716 717 718 719 720
	p->uartclk      = port->uartclk;
	p->fifosize     = port->fifosize;
	p->regshift     = port->regshift;
	p->iotype       = port->iotype;
	p->flags        = port->flags;
	p->mapbase      = port->mapbase;
721
	p->mapsize      = port->mapsize;
D
David Daney 已提交
722
	p->private_data = port->private_data;
723 724
	p->type		= port->type;
	p->line		= port->line;
725

726 727
	serial8250_set_defaults(up_to_u8250p(p));

728 729 730 731
	if (port->serial_in)
		p->serial_in = port->serial_in;
	if (port->serial_out)
		p->serial_out = port->serial_out;
732 733
	if (port->handle_irq)
		p->handle_irq = port->handle_irq;
734

L
Linus Torvalds 已提交
735 736 737 738 739 740 741 742 743 744 745
	return 0;
}

/**
 *	serial8250_suspend_port - suspend one serial port
 *	@line:  serial line number
 *
 *	Suspend one serial port.
 */
void serial8250_suspend_port(int line)
{
746 747 748 749 750 751
	struct uart_8250_port *up = &serial8250_ports[line];
	struct uart_port *port = &up->port;

	if (!console_suspend_enabled && uart_console(port) &&
	    port->type != PORT_8250) {
		unsigned char canary = 0xa5;
752

753
		serial_out(up, UART_SCR, canary);
754 755
		if (serial_in(up, UART_SCR) == canary)
			up->canary = canary;
756 757 758
	}

	uart_suspend_port(&serial8250_reg, port);
L
Linus Torvalds 已提交
759
}
760
EXPORT_SYMBOL(serial8250_suspend_port);
L
Linus Torvalds 已提交
761 762 763 764 765 766 767 768 769

/**
 *	serial8250_resume_port - resume one serial port
 *	@line:  serial line number
 *
 *	Resume one serial port.
 */
void serial8250_resume_port(int line)
{
770
	struct uart_8250_port *up = &serial8250_ports[line];
771
	struct uart_port *port = &up->port;
772

773 774
	up->canary = 0;

775 776
	if (up->capabilities & UART_NATSEMI) {
		/* Ensure it's still in high speed mode */
777
		serial_port_out(port, UART_LCR, 0xE0);
778

779
		ns16550a_goto_highspeed(up);
780

781
		serial_port_out(port, UART_LCR, 0);
782
		port->uartclk = 921600*16;
783
	}
784
	uart_resume_port(&serial8250_reg, port);
L
Linus Torvalds 已提交
785
}
786
EXPORT_SYMBOL(serial8250_resume_port);
L
Linus Torvalds 已提交
787 788 789 790 791 792

/*
 * Register a set of serial devices attached to a platform device.  The
 * list is terminated with a zero flags entry, which means we expect
 * all entries to have at least UPF_BOOT_AUTOCONF set.
 */
B
Bill Pemberton 已提交
793
static int serial8250_probe(struct platform_device *dev)
L
Linus Torvalds 已提交
794
{
J
Jingoo Han 已提交
795
	struct plat_serial8250_port *p = dev_get_platdata(&dev->dev);
796
	struct uart_8250_port uart;
797
	int ret, i, irqflag = 0;
L
Linus Torvalds 已提交
798

799
	memset(&uart, 0, sizeof(uart));
L
Linus Torvalds 已提交
800

801 802 803
	if (share_irqs)
		irqflag = IRQF_SHARED;

804
	for (i = 0; p && p->flags != 0; p++, i++) {
805 806 807 808 809 810 811 812 813 814
		uart.port.iobase	= p->iobase;
		uart.port.membase	= p->membase;
		uart.port.irq		= p->irq;
		uart.port.irqflags	= p->irqflags;
		uart.port.uartclk	= p->uartclk;
		uart.port.regshift	= p->regshift;
		uart.port.iotype	= p->iotype;
		uart.port.flags		= p->flags;
		uart.port.mapbase	= p->mapbase;
		uart.port.hub6		= p->hub6;
815
		uart.port.has_sysrq	= p->has_sysrq;
816 817 818 819 820 821 822
		uart.port.private_data	= p->private_data;
		uart.port.type		= p->type;
		uart.port.serial_in	= p->serial_in;
		uart.port.serial_out	= p->serial_out;
		uart.port.handle_irq	= p->handle_irq;
		uart.port.handle_break	= p->handle_break;
		uart.port.set_termios	= p->set_termios;
E
Ed Blake 已提交
823
		uart.port.set_ldisc	= p->set_ldisc;
824
		uart.port.get_mctrl	= p->get_mctrl;
825 826 827 828
		uart.port.pm		= p->pm;
		uart.port.dev		= &dev->dev;
		uart.port.irqflags	|= irqflag;
		ret = serial8250_register_8250_port(&uart);
829
		if (ret < 0) {
830
			dev_err(&dev->dev, "unable to register port at index %d "
831 832 833
				"(IO%lx MEM%llx IRQ%d): %d\n", i,
				p->iobase, (unsigned long long)p->mapbase,
				p->irq, ret);
834
		}
L
Linus Torvalds 已提交
835 836 837 838 839 840 841
	}
	return 0;
}

/*
 * Remove serial ports registered against a platform device.
 */
B
Bill Pemberton 已提交
842
static int serial8250_remove(struct platform_device *dev)
L
Linus Torvalds 已提交
843 844 845
{
	int i;

846
	for (i = 0; i < nr_uarts; i++) {
L
Linus Torvalds 已提交
847 848
		struct uart_8250_port *up = &serial8250_ports[i];

849
		if (up->port.dev == &dev->dev)
L
Linus Torvalds 已提交
850 851 852 853 854
			serial8250_unregister_port(i);
	}
	return 0;
}

855
static int serial8250_suspend(struct platform_device *dev, pm_message_t state)
L
Linus Torvalds 已提交
856 857 858 859 860 861
{
	int i;

	for (i = 0; i < UART_NR; i++) {
		struct uart_8250_port *up = &serial8250_ports[i];

862
		if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
L
Linus Torvalds 已提交
863 864 865 866 867 868
			uart_suspend_port(&serial8250_reg, &up->port);
	}

	return 0;
}

869
static int serial8250_resume(struct platform_device *dev)
L
Linus Torvalds 已提交
870 871 872 873 874 875
{
	int i;

	for (i = 0; i < UART_NR; i++) {
		struct uart_8250_port *up = &serial8250_ports[i];

876
		if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
877
			serial8250_resume_port(i);
L
Linus Torvalds 已提交
878 879 880 881 882
	}

	return 0;
}

883
static struct platform_driver serial8250_isa_driver = {
L
Linus Torvalds 已提交
884
	.probe		= serial8250_probe,
885
	.remove		= serial8250_remove,
L
Linus Torvalds 已提交
886 887
	.suspend	= serial8250_suspend,
	.resume		= serial8250_resume,
888 889 890
	.driver		= {
		.name	= "serial8250",
	},
L
Linus Torvalds 已提交
891 892 893 894 895 896 897 898 899
};

/*
 * This "device" covers _all_ ISA 8250-compatible serial devices listed
 * in the table in include/asm/serial.h
 */
static struct platform_device *serial8250_isa_devs;

/*
900
 * serial8250_register_8250_port and serial8250_unregister_port allows for
L
Linus Torvalds 已提交
901 902 903
 * 16x50 serial ports to be configured at run-time, to support PCMCIA
 * modems and PCI multiport cards.
 */
904
static DEFINE_MUTEX(serial_mutex);
L
Linus Torvalds 已提交
905

906
static struct uart_8250_port *serial8250_find_match_or_unused(const struct uart_port *port)
L
Linus Torvalds 已提交
907 908 909 910 911 912
{
	int i;

	/*
	 * First, find a port entry which matches.
	 */
913
	for (i = 0; i < nr_uarts; i++)
L
Linus Torvalds 已提交
914 915 916
		if (uart_match_port(&serial8250_ports[i].port, port))
			return &serial8250_ports[i];

917 918 919 920 921
	/* try line number first if still available */
	i = port->line;
	if (i < nr_uarts && serial8250_ports[i].port.type == PORT_UNKNOWN &&
			serial8250_ports[i].port.iobase == 0)
		return &serial8250_ports[i];
L
Linus Torvalds 已提交
922 923 924 925 926
	/*
	 * We didn't find a matching entry, so look for the first
	 * free entry.  We look for one which hasn't been previously
	 * used (indicated by zero iobase).
	 */
927
	for (i = 0; i < nr_uarts; i++)
L
Linus Torvalds 已提交
928 929 930 931 932 933 934 935
		if (serial8250_ports[i].port.type == PORT_UNKNOWN &&
		    serial8250_ports[i].port.iobase == 0)
			return &serial8250_ports[i];

	/*
	 * That also failed.  Last resort is to find any entry which
	 * doesn't have a real port associated with it.
	 */
936
	for (i = 0; i < nr_uarts; i++)
L
Linus Torvalds 已提交
937 938 939 940 941 942
		if (serial8250_ports[i].port.type == PORT_UNKNOWN)
			return &serial8250_ports[i];

	return NULL;
}

943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
static void serial_8250_overrun_backoff_work(struct work_struct *work)
{
	struct uart_8250_port *up =
	    container_of(to_delayed_work(work), struct uart_8250_port,
			 overrun_backoff);
	struct uart_port *port = &up->port;
	unsigned long flags;

	spin_lock_irqsave(&port->lock, flags);
	up->ier |= UART_IER_RLSI | UART_IER_RDI;
	up->port.read_status_mask |= UART_LSR_DR;
	serial_out(up, UART_IER, up->ier);
	spin_unlock_irqrestore(&port->lock, flags);
}

L
Linus Torvalds 已提交
958
/**
959
 *	serial8250_register_8250_port - register a serial port
960
 *	@up: serial port template
L
Linus Torvalds 已提交
961 962 963 964 965 966 967 968 969 970
 *
 *	Configure the serial port specified by the request. If the
 *	port exists and is in use, it is hung up and unregistered
 *	first.
 *
 *	The port is then probed and if necessary the IRQ is autodetected
 *	If this fails an error is returned.
 *
 *	On success the port is ready to use and the line number is returned.
 */
971
int serial8250_register_8250_port(const struct uart_8250_port *up)
L
Linus Torvalds 已提交
972 973 974 975
{
	struct uart_8250_port *uart;
	int ret = -ENOSPC;

976
	if (up->port.uartclk == 0)
L
Linus Torvalds 已提交
977 978
		return -EINVAL;

979
	mutex_lock(&serial_mutex);
L
Linus Torvalds 已提交
980

981
	uart = serial8250_find_match_or_unused(&up->port);
S
Sean Young 已提交
982
	if (uart && uart->port.type != PORT_8250_CIR) {
983 984
		struct mctrl_gpios *gpios;

985 986
		if (uart->port.dev)
			uart_remove_one_port(&serial8250_reg, &uart->port);
L
Linus Torvalds 已提交
987

988 989 990 991 992 993 994 995 996
		uart->port.iobase       = up->port.iobase;
		uart->port.membase      = up->port.membase;
		uart->port.irq          = up->port.irq;
		uart->port.irqflags     = up->port.irqflags;
		uart->port.uartclk      = up->port.uartclk;
		uart->port.fifosize     = up->port.fifosize;
		uart->port.regshift     = up->port.regshift;
		uart->port.iotype       = up->port.iotype;
		uart->port.flags        = up->port.flags | UPF_BOOT_AUTOCONF;
A
Alan Cox 已提交
997
		uart->bugs		= up->bugs;
998
		uart->port.mapbase      = up->port.mapbase;
999
		uart->port.mapsize      = up->port.mapsize;
1000
		uart->port.private_data = up->port.private_data;
1001 1002
		uart->tx_loadsz		= up->tx_loadsz;
		uart->capabilities	= up->capabilities;
1003 1004
		uart->port.throttle	= up->port.throttle;
		uart->port.unthrottle	= up->port.unthrottle;
1005
		uart->port.rs485_config	= up->port.rs485_config;
1006
		uart->port.rs485_supported = up->port.rs485_supported;
1007
		uart->port.rs485	= up->port.rs485;
1008 1009
		uart->rs485_start_tx	= up->rs485_start_tx;
		uart->rs485_stop_tx	= up->rs485_stop_tx;
1010
		uart->lsr_save_mask	= up->lsr_save_mask;
1011
		uart->dma		= up->dma;
1012

1013 1014 1015 1016
		/* Take tx_loadsz from fifosize if it wasn't set separately */
		if (uart->port.fifosize && !uart->tx_loadsz)
			uart->tx_loadsz = uart->port.fifosize;

1017
		if (up->port.dev) {
1018
			uart->port.dev = up->port.dev;
1019 1020 1021
			ret = uart_get_rs485_mode(&uart->port);
			if (ret)
				goto err;
1022
		}
1023 1024

		if (up->port.flags & UPF_FIXED_TYPE)
1025
			uart->port.type = up->port.type;
1026

1027 1028 1029 1030 1031 1032 1033
		/*
		 * Only call mctrl_gpio_init(), if the device has no ACPI
		 * companion device
		 */
		if (!has_acpi_companion(uart->port.dev)) {
			gpios = mctrl_gpio_init(&uart->port, 0);
			if (IS_ERR(gpios)) {
1034
				ret = PTR_ERR(gpios);
1035
				goto err;
1036 1037 1038 1039 1040
			} else {
				uart->gpios = gpios;
			}
		}

1041 1042
		serial8250_set_defaults(uart);

1043
		/* Possibly override default I/O functions.  */
1044 1045 1046 1047 1048 1049
		if (up->port.serial_in)
			uart->port.serial_in = up->port.serial_in;
		if (up->port.serial_out)
			uart->port.serial_out = up->port.serial_out;
		if (up->port.handle_irq)
			uart->port.handle_irq = up->port.handle_irq;
1050
		/*  Possibly override set_termios call */
1051 1052
		if (up->port.set_termios)
			uart->port.set_termios = up->port.set_termios;
E
Ed Blake 已提交
1053 1054
		if (up->port.set_ldisc)
			uart->port.set_ldisc = up->port.set_ldisc;
1055 1056
		if (up->port.get_mctrl)
			uart->port.get_mctrl = up->port.get_mctrl;
1057 1058
		if (up->port.set_mctrl)
			uart->port.set_mctrl = up->port.set_mctrl;
1059 1060 1061 1062
		if (up->port.get_divisor)
			uart->port.get_divisor = up->port.get_divisor;
		if (up->port.set_divisor)
			uart->port.set_divisor = up->port.set_divisor;
1063 1064 1065 1066
		if (up->port.startup)
			uart->port.startup = up->port.startup;
		if (up->port.shutdown)
			uart->port.shutdown = up->port.shutdown;
1067 1068 1069 1070 1071 1072 1073 1074
		if (up->port.pm)
			uart->port.pm = up->port.pm;
		if (up->port.handle_break)
			uart->port.handle_break = up->port.handle_break;
		if (up->dl_read)
			uart->dl_read = up->dl_read;
		if (up->dl_write)
			uart->dl_write = up->dl_write;
L
Linus Torvalds 已提交
1075

1076 1077 1078 1079 1080
		if (uart->port.type != PORT_8250_CIR) {
			if (serial8250_isa_config != NULL)
				serial8250_isa_config(0, &uart->port,
						&uart->capabilities);

1081
			serial8250_apply_quirks(uart);
1082 1083
			ret = uart_add_one_port(&serial8250_reg,
						&uart->port);
1084 1085 1086 1087
			if (ret)
				goto err;

			ret = uart->port.line;
1088 1089 1090 1091 1092 1093
		} else {
			dev_info(uart->port.dev,
				"skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n",
				uart->port.iobase,
				(unsigned long long)uart->port.mapbase,
				uart->port.irq);
1094

1095 1096
			ret = 0;
		}
1097

1098 1099 1100
		if (!uart->lsr_save_mask)
			uart->lsr_save_mask = LSR_SAVE_FLAGS;	/* Use default LSR mask */

1101 1102 1103 1104 1105 1106 1107 1108 1109
		/* Initialise interrupt backoff work if required */
		if (up->overrun_backoff_time_ms > 0) {
			uart->overrun_backoff_time_ms =
				up->overrun_backoff_time_ms;
			INIT_DELAYED_WORK(&uart->overrun_backoff,
					serial_8250_overrun_backoff_work);
		} else {
			uart->overrun_backoff_time_ms = 0;
		}
1110 1111
	}

1112
	mutex_unlock(&serial_mutex);
L
Linus Torvalds 已提交
1113 1114

	return ret;
1115 1116 1117 1118 1119

err:
	uart->port.dev = NULL;
	mutex_unlock(&serial_mutex);
	return ret;
L
Linus Torvalds 已提交
1120
}
1121 1122
EXPORT_SYMBOL(serial8250_register_8250_port);

L
Linus Torvalds 已提交
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
/**
 *	serial8250_unregister_port - remove a 16x50 serial port at runtime
 *	@line: serial line number
 *
 *	Remove one serial port.  This may not be called from interrupt
 *	context.  We hand the port back to the our control.
 */
void serial8250_unregister_port(int line)
{
	struct uart_8250_port *uart = &serial8250_ports[line];

1134
	mutex_lock(&serial_mutex);
1135 1136 1137 1138 1139 1140 1141 1142 1143

	if (uart->em485) {
		unsigned long flags;

		spin_lock_irqsave(&uart->port.lock, flags);
		serial8250_em485_destroy(uart);
		spin_unlock_irqrestore(&uart->port.lock, flags);
	}

L
Linus Torvalds 已提交
1144 1145 1146 1147 1148
	uart_remove_one_port(&serial8250_reg, &uart->port);
	if (serial8250_isa_devs) {
		uart->port.flags &= ~UPF_BOOT_AUTOCONF;
		uart->port.type = PORT_UNKNOWN;
		uart->port.dev = &serial8250_isa_devs->dev;
1149
		uart->capabilities = 0;
1150
		serial8250_apply_quirks(uart);
L
Linus Torvalds 已提交
1151 1152 1153 1154
		uart_add_one_port(&serial8250_reg, &uart->port);
	} else {
		uart->port.dev = NULL;
	}
1155
	mutex_unlock(&serial_mutex);
L
Linus Torvalds 已提交
1156 1157 1158 1159 1160
}
EXPORT_SYMBOL(serial8250_unregister_port);

static int __init serial8250_init(void)
{
A
Alan Cox 已提交
1161
	int ret;
L
Linus Torvalds 已提交
1162

1163 1164 1165
	if (nr_uarts == 0)
		return -ENODEV;

1166
	serial8250_isa_init_ports();
1167

1168 1169
	pr_info("Serial: 8250/16550 driver, %d ports, IRQ sharing %sabled\n",
		nr_uarts, share_irqs ? "en" : "dis");
L
Linus Torvalds 已提交
1170

1171 1172 1173 1174
#ifdef CONFIG_SPARC
	ret = sunserial_register_minors(&serial8250_reg, UART_NR);
#else
	serial8250_reg.nr = UART_NR;
L
Linus Torvalds 已提交
1175
	ret = uart_register_driver(&serial8250_reg);
1176
#endif
L
Linus Torvalds 已提交
1177 1178 1179
	if (ret)
		goto out;

1180 1181 1182 1183
	ret = serial8250_pnp_init();
	if (ret)
		goto unreg_uart_drv;

1184 1185 1186 1187
	serial8250_isa_devs = platform_device_alloc("serial8250",
						    PLAT8250_DEV_LEGACY);
	if (!serial8250_isa_devs) {
		ret = -ENOMEM;
1188
		goto unreg_pnp;
L
Linus Torvalds 已提交
1189 1190
	}

1191 1192 1193 1194
	ret = platform_device_add(serial8250_isa_devs);
	if (ret)
		goto put_dev;

L
Linus Torvalds 已提交
1195 1196
	serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev);

1197 1198 1199
	ret = platform_driver_register(&serial8250_isa_driver);
	if (ret == 0)
		goto out;
L
Linus Torvalds 已提交
1200

1201
	platform_device_del(serial8250_isa_devs);
A
Alan Cox 已提交
1202
put_dev:
1203
	platform_device_put(serial8250_isa_devs);
1204 1205
unreg_pnp:
	serial8250_pnp_exit();
A
Alan Cox 已提交
1206
unreg_uart_drv:
1207 1208 1209
#ifdef CONFIG_SPARC
	sunserial_unregister_minors(&serial8250_reg, UART_NR);
#else
L
Linus Torvalds 已提交
1210
	uart_unregister_driver(&serial8250_reg);
1211
#endif
A
Alan Cox 已提交
1212
out:
L
Linus Torvalds 已提交
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226
	return ret;
}

static void __exit serial8250_exit(void)
{
	struct platform_device *isa_dev = serial8250_isa_devs;

	/*
	 * This tells serial8250_unregister_port() not to re-register
	 * the ports (thereby making serial8250_isa_driver permanently
	 * in use.)
	 */
	serial8250_isa_devs = NULL;

1227
	platform_driver_unregister(&serial8250_isa_driver);
L
Linus Torvalds 已提交
1228 1229
	platform_device_unregister(isa_dev);

1230 1231
	serial8250_pnp_exit();

1232 1233 1234
#ifdef CONFIG_SPARC
	sunserial_unregister_minors(&serial8250_reg, UART_NR);
#else
L
Linus Torvalds 已提交
1235
	uart_unregister_driver(&serial8250_reg);
1236
#endif
L
Linus Torvalds 已提交
1237 1238 1239 1240 1241 1242
}

module_init(serial8250_init);
module_exit(serial8250_exit);

MODULE_LICENSE("GPL");
1243
MODULE_DESCRIPTION("Generic 8250/16x50 serial driver");
L
Linus Torvalds 已提交
1244

1245
module_param_hw(share_irqs, uint, other, 0644);
1246
MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices (unsafe)");
L
Linus Torvalds 已提交
1247

1248 1249 1250
module_param(nr_uarts, uint, 0644);
MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")");

1251 1252 1253
module_param(skip_txen_test, uint, 0644);
MODULE_PARM_DESC(skip_txen_test, "Skip checking for the TXEN bug at init time");

L
Linus Torvalds 已提交
1254
#ifdef CONFIG_SERIAL_8250_RSA
1255
module_param_hw_array(probe_rsa, ulong, ioport, &probe_rsa_count, 0444);
L
Linus Torvalds 已提交
1256 1257 1258
MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
#endif
MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);
1259

1260
#ifdef CONFIG_SERIAL_8250_DEPRECATED_OPTIONS
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
#ifndef MODULE
/* This module was renamed to 8250_core in 3.7.  Keep the old "8250" name
 * working as well for the module options so we don't break people.  We
 * need to keep the names identical and the convenient macros will happily
 * refuse to let us do that by failing the build with redefinition errors
 * of global variables.  So we stick them inside a dummy function to avoid
 * those conflicts.  The options still get parsed, and the redefined
 * MODULE_PARAM_PREFIX lets us keep the "8250." syntax alive.
 *
 * This is hacky.  I'm sorry.
 */
static void __used s8250_options(void)
{
#undef MODULE_PARAM_PREFIX
1275
#define MODULE_PARAM_PREFIX "8250_core."
1276 1277 1278 1279 1280 1281 1282

	module_param_cb(share_irqs, &param_ops_uint, &share_irqs, 0644);
	module_param_cb(nr_uarts, &param_ops_uint, &nr_uarts, 0644);
	module_param_cb(skip_txen_test, &param_ops_uint, &skip_txen_test, 0644);
#ifdef CONFIG_SERIAL_8250_RSA
	__module_param_call(MODULE_PARAM_PREFIX, probe_rsa,
		&param_array_ops, .arr = &__param_arr_probe_rsa,
1283
		0444, -1, 0);
1284 1285 1286
#endif
}
#else
1287
MODULE_ALIAS("8250_core");
1288 1289
#endif
#endif