Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

serial: 8250: Extract platform driver

Extract platform driver to a separate module for better maintenance
and to reduce churn on 8250_core part changes when it's solely related
to the former. No functional changes intended.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Sunil V L <sunilvl@ventanamicro.com>
Tested-by: Sunil V L <sunilvl@ventanamicro.com>
Link: https://lore.kernel.org/r/20240506140308.4040735-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Andy Shevchenko and committed by
Greg Kroah-Hartman
ffd8e8bd c0e1aa60

+369 -339
+21 -1
drivers/tty/serial/8250/8250.h
··· 9 9 10 10 #include <linux/bits.h> 11 11 #include <linux/serial_8250.h> 12 - #include <linux/serial_reg.h> 12 + #include <linux/serial_core.h> 13 13 #include <linux/dmaengine.h> 14 14 15 15 #include "../serial_mctrl_gpio.h" ··· 93 93 #define UART_BUG_THRE BIT(3) /* UART has buggy THRE reassertion */ 94 94 #define UART_BUG_TXRACE BIT(5) /* UART Tx fails to set remote DR */ 95 95 96 + /* Module parameters */ 97 + #define UART_NR CONFIG_SERIAL_8250_NR_UARTS 98 + 99 + extern unsigned int nr_uarts; 96 100 97 101 #ifdef CONFIG_SERIAL_8250_SHARE_IRQ 98 102 #define SERIAL8250_SHARE_IRQS 1 99 103 #else 100 104 #define SERIAL8250_SHARE_IRQS 0 101 105 #endif 106 + 107 + extern unsigned int share_irqs; 108 + extern unsigned int skip_txen_test; 102 109 103 110 #define SERIAL8250_PORT_FLAGS(_base, _irq, _flags) \ 104 111 { \ ··· 118 111 119 112 #define SERIAL8250_PORT(_base, _irq) SERIAL8250_PORT_FLAGS(_base, _irq, 0) 120 113 114 + extern struct uart_driver serial8250_reg; 115 + void serial8250_register_ports(struct uart_driver *drv, struct device *dev); 116 + 117 + /* Legacy ISA bus related APIs */ 118 + typedef void (*serial8250_isa_config_fn)(int, struct uart_port *, u32 *); 119 + extern serial8250_isa_config_fn serial8250_isa_config; 120 + 121 + void serial8250_isa_init_ports(void); 122 + 123 + extern struct platform_device *serial8250_isa_devs; 124 + 121 125 extern const struct uart_ops *univ8250_port_base_ops; 126 + extern struct uart_ops univ8250_port_ops; 122 127 123 128 static inline int serial_in(struct uart_8250_port *up, int offset) 124 129 { ··· 220 201 return true; 221 202 } 222 203 204 + struct uart_8250_port *serial8250_setup_port(int index); 223 205 struct uart_8250_port *serial8250_get_port(int line); 224 206 225 207 void serial8250_rpm_get(struct uart_8250_port *p);
+5 -337
drivers/tty/serial/8250/8250_core.c
··· 6 6 * 7 7 * Copyright (C) 2001 Russell King. 8 8 * 9 - * Supports: ISA-compatible 8250/16550 ports 10 - * PNP 8250/16550 ports 9 + * Supports: 11 10 * early_serial_setup() ports 12 11 * userspace-configurable "phantom" ports 13 - * "serial8250" platform devices 14 12 * serial8250_register_8250_port() ports 15 13 */ 16 14 ··· 34 36 #include <linux/string_helpers.h> 35 37 #include <linux/uaccess.h> 36 38 #include <linux/io.h> 37 - #ifdef CONFIG_SPARC 38 - #include <linux/sunserialcore.h> 39 - #endif 40 39 41 40 #include <asm/irq.h> 42 41 43 - #include "../serial_base.h" /* For serial_base_add_isa_preferred_console() */ 44 - 45 42 #include "8250.h" 46 43 47 - /* 48 - * Configuration: 49 - * share_irqs - whether we pass IRQF_SHARED to request_irq(). This option 50 - * is unsafe when used on edge-triggered interrupts. 51 - */ 52 - static unsigned int share_irqs = SERIAL8250_SHARE_IRQS; 53 - 54 - static unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS; 55 - 56 - static struct uart_driver serial8250_reg; 57 - 58 - static unsigned int skip_txen_test; /* force skip of txen test at init time */ 59 - 60 44 #define PASS_LIMIT 512 61 - 62 - #include <asm/serial.h> 63 - /* 64 - * SERIAL_PORT_DFNS tells us about built-in ports that have no 65 - * standard enumeration mechanism. Platforms that can find all 66 - * serial ports via mechanisms like ACPI or PCI need not supply it. 67 - */ 68 - #ifndef SERIAL_PORT_DFNS 69 - #define SERIAL_PORT_DFNS 70 - #endif 71 - 72 - static const struct old_serial_port old_serial_port[] = { 73 - SERIAL_PORT_DFNS /* defined in asm/serial.h */ 74 - }; 75 - 76 - #define UART_NR CONFIG_SERIAL_8250_NR_UARTS 77 45 78 46 struct irq_info { 79 47 struct hlist_node node; ··· 306 342 } 307 343 308 344 const struct uart_ops *univ8250_port_base_ops = NULL; 309 - static struct uart_ops univ8250_port_ops; 345 + struct uart_ops univ8250_port_ops; 310 346 311 347 static const struct uart_8250_ops univ8250_driver_ops = { 312 348 .setup_irq = univ8250_setup_irq, ··· 334 370 } 335 371 EXPORT_SYMBOL_GPL(serial8250_get_port); 336 372 337 - static void (*serial8250_isa_config)(int port, struct uart_port *up, 338 - u32 *capabilities); 339 - 340 - void serial8250_set_isa_configurator( 341 - void (*v)(int port, struct uart_port *up, u32 *capabilities)) 342 - { 343 - serial8250_isa_config = v; 344 - } 345 - EXPORT_SYMBOL(serial8250_set_isa_configurator); 346 - 347 373 static inline void serial8250_apply_quirks(struct uart_8250_port *up) 348 374 { 349 375 up->port.quirks |= skip_txen_test ? UPQ_NO_TXEN_TEST : 0; 350 376 } 351 377 352 - static struct uart_8250_port *serial8250_setup_port(int index) 378 + struct uart_8250_port *serial8250_setup_port(int index) 353 379 { 354 380 struct uart_8250_port *up; 355 381 ··· 364 410 return up; 365 411 } 366 412 367 - static void __init serial8250_isa_init_ports(void) 368 - { 369 - struct uart_8250_port *up; 370 - static int first = 1; 371 - int i, irqflag = 0; 372 - 373 - if (!first) 374 - return; 375 - first = 0; 376 - 377 - if (nr_uarts > UART_NR) 378 - nr_uarts = UART_NR; 379 - 380 - /* 381 - * Set up initial isa ports based on nr_uart module param, or else 382 - * default to CONFIG_SERIAL_8250_RUNTIME_UARTS. Note that we do not 383 - * need to increase nr_uarts when setting up the initial isa ports. 384 - */ 385 - for (i = 0; i < nr_uarts; i++) 386 - serial8250_setup_port(i); 387 - 388 - /* chain base port ops to support Remote Supervisor Adapter */ 389 - univ8250_port_ops = *univ8250_port_base_ops; 390 - univ8250_rsa_support(&univ8250_port_ops); 391 - 392 - if (share_irqs) 393 - irqflag = IRQF_SHARED; 394 - 395 - for (i = 0, up = serial8250_ports; 396 - i < ARRAY_SIZE(old_serial_port) && i < nr_uarts; 397 - i++, up++) { 398 - struct uart_port *port = &up->port; 399 - 400 - port->iobase = old_serial_port[i].port; 401 - port->irq = irq_canonicalize(old_serial_port[i].irq); 402 - port->irqflags = 0; 403 - port->uartclk = old_serial_port[i].baud_base * 16; 404 - port->flags = old_serial_port[i].flags; 405 - port->hub6 = 0; 406 - port->membase = old_serial_port[i].iomem_base; 407 - port->iotype = old_serial_port[i].io_type; 408 - port->regshift = old_serial_port[i].iomem_reg_shift; 409 - 410 - port->irqflags |= irqflag; 411 - if (serial8250_isa_config != NULL) 412 - serial8250_isa_config(i, &up->port, &up->capabilities); 413 - 414 - serial_base_add_isa_preferred_console(serial8250_reg.dev_name, i); 415 - } 416 - } 417 - 418 - static void __init 419 - serial8250_register_ports(struct uart_driver *drv, struct device *dev) 413 + void __init serial8250_register_ports(struct uart_driver *drv, struct device *dev) 420 414 { 421 415 int i; 422 416 ··· 521 619 #define SERIAL8250_CONSOLE NULL 522 620 #endif 523 621 524 - static struct uart_driver serial8250_reg = { 622 + struct uart_driver serial8250_reg = { 525 623 .owner = THIS_MODULE, 526 624 .driver_name = "serial", 527 625 .dev_name = "ttyS", ··· 621 719 uart_resume_port(&serial8250_reg, port); 622 720 } 623 721 EXPORT_SYMBOL(serial8250_resume_port); 624 - 625 - /* 626 - * Register a set of serial devices attached to a platform device. The 627 - * list is terminated with a zero flags entry, which means we expect 628 - * all entries to have at least UPF_BOOT_AUTOCONF set. 629 - */ 630 - static int serial8250_probe(struct platform_device *dev) 631 - { 632 - struct plat_serial8250_port *p = dev_get_platdata(&dev->dev); 633 - struct uart_8250_port uart; 634 - int ret, i, irqflag = 0; 635 - 636 - memset(&uart, 0, sizeof(uart)); 637 - 638 - if (share_irqs) 639 - irqflag = IRQF_SHARED; 640 - 641 - for (i = 0; p && p->flags != 0; p++, i++) { 642 - uart.port.iobase = p->iobase; 643 - uart.port.membase = p->membase; 644 - uart.port.irq = p->irq; 645 - uart.port.irqflags = p->irqflags; 646 - uart.port.uartclk = p->uartclk; 647 - uart.port.regshift = p->regshift; 648 - uart.port.iotype = p->iotype; 649 - uart.port.flags = p->flags; 650 - uart.port.mapbase = p->mapbase; 651 - uart.port.mapsize = p->mapsize; 652 - uart.port.hub6 = p->hub6; 653 - uart.port.has_sysrq = p->has_sysrq; 654 - uart.port.private_data = p->private_data; 655 - uart.port.type = p->type; 656 - uart.bugs = p->bugs; 657 - uart.port.serial_in = p->serial_in; 658 - uart.port.serial_out = p->serial_out; 659 - uart.dl_read = p->dl_read; 660 - uart.dl_write = p->dl_write; 661 - uart.port.handle_irq = p->handle_irq; 662 - uart.port.handle_break = p->handle_break; 663 - uart.port.set_termios = p->set_termios; 664 - uart.port.set_ldisc = p->set_ldisc; 665 - uart.port.get_mctrl = p->get_mctrl; 666 - uart.port.pm = p->pm; 667 - uart.port.dev = &dev->dev; 668 - uart.port.irqflags |= irqflag; 669 - ret = serial8250_register_8250_port(&uart); 670 - if (ret < 0) { 671 - dev_err(&dev->dev, "unable to register port at index %d " 672 - "(IO%lx MEM%llx IRQ%d): %d\n", i, 673 - p->iobase, (unsigned long long)p->mapbase, 674 - p->irq, ret); 675 - } 676 - } 677 - return 0; 678 - } 679 - 680 - /* 681 - * Remove serial ports registered against a platform device. 682 - */ 683 - static void serial8250_remove(struct platform_device *dev) 684 - { 685 - int i; 686 - 687 - for (i = 0; i < nr_uarts; i++) { 688 - struct uart_8250_port *up = &serial8250_ports[i]; 689 - 690 - if (up->port.dev == &dev->dev) 691 - serial8250_unregister_port(i); 692 - } 693 - } 694 - 695 - static int serial8250_suspend(struct platform_device *dev, pm_message_t state) 696 - { 697 - int i; 698 - 699 - for (i = 0; i < UART_NR; i++) { 700 - struct uart_8250_port *up = &serial8250_ports[i]; 701 - 702 - if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev) 703 - uart_suspend_port(&serial8250_reg, &up->port); 704 - } 705 - 706 - return 0; 707 - } 708 - 709 - static int serial8250_resume(struct platform_device *dev) 710 - { 711 - int i; 712 - 713 - for (i = 0; i < UART_NR; i++) { 714 - struct uart_8250_port *up = &serial8250_ports[i]; 715 - 716 - if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev) 717 - serial8250_resume_port(i); 718 - } 719 - 720 - return 0; 721 - } 722 - 723 - static struct platform_driver serial8250_isa_driver = { 724 - .probe = serial8250_probe, 725 - .remove_new = serial8250_remove, 726 - .suspend = serial8250_suspend, 727 - .resume = serial8250_resume, 728 - .driver = { 729 - .name = "serial8250", 730 - }, 731 - }; 732 - 733 - /* 734 - * This "device" covers _all_ ISA 8250-compatible serial devices listed 735 - * in the table in include/asm/serial.h 736 - */ 737 - static struct platform_device *serial8250_isa_devs; 738 722 739 723 /* 740 724 * serial8250_register_8250_port and serial8250_unregister_port allows for ··· 898 1110 } 899 1111 EXPORT_SYMBOL(serial8250_unregister_port); 900 1112 901 - static int __init serial8250_init(void) 902 - { 903 - int ret; 904 - 905 - if (nr_uarts == 0) 906 - return -ENODEV; 907 - 908 - serial8250_isa_init_ports(); 909 - 910 - pr_info("Serial: 8250/16550 driver, %d ports, IRQ sharing %s\n", 911 - nr_uarts, str_enabled_disabled(share_irqs)); 912 - 913 - #ifdef CONFIG_SPARC 914 - ret = sunserial_register_minors(&serial8250_reg, UART_NR); 915 - #else 916 - serial8250_reg.nr = UART_NR; 917 - ret = uart_register_driver(&serial8250_reg); 918 - #endif 919 - if (ret) 920 - goto out; 921 - 922 - ret = serial8250_pnp_init(); 923 - if (ret) 924 - goto unreg_uart_drv; 925 - 926 - serial8250_isa_devs = platform_device_alloc("serial8250", 927 - PLAT8250_DEV_LEGACY); 928 - if (!serial8250_isa_devs) { 929 - ret = -ENOMEM; 930 - goto unreg_pnp; 931 - } 932 - 933 - ret = platform_device_add(serial8250_isa_devs); 934 - if (ret) 935 - goto put_dev; 936 - 937 - serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev); 938 - 939 - ret = platform_driver_register(&serial8250_isa_driver); 940 - if (ret == 0) 941 - goto out; 942 - 943 - platform_device_del(serial8250_isa_devs); 944 - put_dev: 945 - platform_device_put(serial8250_isa_devs); 946 - unreg_pnp: 947 - serial8250_pnp_exit(); 948 - unreg_uart_drv: 949 - #ifdef CONFIG_SPARC 950 - sunserial_unregister_minors(&serial8250_reg, UART_NR); 951 - #else 952 - uart_unregister_driver(&serial8250_reg); 953 - #endif 954 - out: 955 - return ret; 956 - } 957 - 958 - static void __exit serial8250_exit(void) 959 - { 960 - struct platform_device *isa_dev = serial8250_isa_devs; 961 - 962 - /* 963 - * This tells serial8250_unregister_port() not to re-register 964 - * the ports (thereby making serial8250_isa_driver permanently 965 - * in use.) 966 - */ 967 - serial8250_isa_devs = NULL; 968 - 969 - platform_driver_unregister(&serial8250_isa_driver); 970 - platform_device_unregister(isa_dev); 971 - 972 - serial8250_pnp_exit(); 973 - 974 - #ifdef CONFIG_SPARC 975 - sunserial_unregister_minors(&serial8250_reg, UART_NR); 976 - #else 977 - uart_unregister_driver(&serial8250_reg); 978 - #endif 979 - } 980 - 981 - module_init(serial8250_init); 982 - module_exit(serial8250_exit); 983 - 984 1113 MODULE_LICENSE("GPL"); 985 1114 MODULE_DESCRIPTION("Generic 8250/16x50 serial driver"); 986 - 987 - module_param_hw(share_irqs, uint, other, 0644); 988 - MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices (unsafe)"); 989 - 990 - module_param(nr_uarts, uint, 0644); 991 - MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")"); 992 - 993 - module_param(skip_txen_test, uint, 0644); 994 - MODULE_PARM_DESC(skip_txen_test, "Skip checking for the TXEN bug at init time"); 995 - 996 - MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR); 997 - 998 - #ifdef CONFIG_SERIAL_8250_DEPRECATED_OPTIONS 999 - #ifndef MODULE 1000 - /* This module was renamed to 8250_core in 3.7. Keep the old "8250" name 1001 - * working as well for the module options so we don't break people. We 1002 - * need to keep the names identical and the convenient macros will happily 1003 - * refuse to let us do that by failing the build with redefinition errors 1004 - * of global variables. So we stick them inside a dummy function to avoid 1005 - * those conflicts. The options still get parsed, and the redefined 1006 - * MODULE_PARAM_PREFIX lets us keep the "8250." syntax alive. 1007 - * 1008 - * This is hacky. I'm sorry. 1009 - */ 1010 - static void __used s8250_options(void) 1011 - { 1012 - #undef MODULE_PARAM_PREFIX 1013 - #define MODULE_PARAM_PREFIX "8250_core." 1014 - 1015 - module_param_cb(share_irqs, &param_ops_uint, &share_irqs, 0644); 1016 - module_param_cb(nr_uarts, &param_ops_uint, &nr_uarts, 0644); 1017 - module_param_cb(skip_txen_test, &param_ops_uint, &skip_txen_test, 0644); 1018 - } 1019 - #else 1020 - MODULE_ALIAS("8250_core"); 1021 - #endif 1022 - #endif
+339
drivers/tty/serial/8250/8250_platform.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Universal/legacy platform driver for 8250/16550-type serial ports 4 + * 5 + * Supports: ISA-compatible 8250/16550 ports 6 + * PNP 8250/16550 ports 7 + * "serial8250" platform devices 8 + */ 9 + #include <linux/array_size.h> 10 + #include <linux/module.h> 11 + #include <linux/moduleparam.h> 12 + #include <linux/platform_device.h> 13 + 14 + #include <linux/serial_8250.h> 15 + 16 + #ifdef CONFIG_SPARC 17 + #include <linux/sunserialcore.h> 18 + #endif 19 + 20 + #include "../serial_base.h" /* For serial_base_add_isa_preferred_console() */ 21 + #include "8250.h" 22 + 23 + /* 24 + * Configuration: 25 + * share_irqs Whether we pass IRQF_SHARED to request_irq(). 26 + * This option is unsafe when used on edge-triggered interrupts. 27 + * skip_txen_test Force skip of txen test at init time. 28 + */ 29 + unsigned int share_irqs = SERIAL8250_SHARE_IRQS; 30 + unsigned int skip_txen_test; 31 + 32 + unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS; 33 + 34 + #include <asm/serial.h> 35 + 36 + /* 37 + * SERIAL_PORT_DFNS tells us about built-in ports that have no 38 + * standard enumeration mechanism. Platforms that can find all 39 + * serial ports via mechanisms like ACPI or PCI need not supply it. 40 + */ 41 + #ifndef SERIAL_PORT_DFNS 42 + #define SERIAL_PORT_DFNS 43 + #endif 44 + 45 + static const struct old_serial_port old_serial_port[] = { 46 + SERIAL_PORT_DFNS /* defined in asm/serial.h */ 47 + }; 48 + 49 + serial8250_isa_config_fn serial8250_isa_config; 50 + void serial8250_set_isa_configurator(serial8250_isa_config_fn v) 51 + { 52 + serial8250_isa_config = v; 53 + } 54 + EXPORT_SYMBOL(serial8250_set_isa_configurator); 55 + 56 + void __init serial8250_isa_init_ports(void) 57 + { 58 + static int first = 1; 59 + int i, irqflag = 0; 60 + 61 + if (!first) 62 + return; 63 + first = 0; 64 + 65 + if (nr_uarts > UART_NR) 66 + nr_uarts = UART_NR; 67 + 68 + /* 69 + * Set up initial isa ports based on nr_uart module param, or else 70 + * default to CONFIG_SERIAL_8250_RUNTIME_UARTS. Note that we do not 71 + * need to increase nr_uarts when setting up the initial isa ports. 72 + */ 73 + for (i = 0; i < nr_uarts; i++) 74 + serial8250_setup_port(i); 75 + 76 + /* chain base port ops to support Remote Supervisor Adapter */ 77 + univ8250_port_ops = *univ8250_port_base_ops; 78 + univ8250_rsa_support(&univ8250_port_ops); 79 + 80 + if (share_irqs) 81 + irqflag = IRQF_SHARED; 82 + 83 + for (i = 0; i < ARRAY_SIZE(old_serial_port) && i < nr_uarts; i++) { 84 + struct uart_8250_port *up = serial8250_get_port(i); 85 + struct uart_port *port = &up->port; 86 + 87 + port->iobase = old_serial_port[i].port; 88 + port->irq = irq_canonicalize(old_serial_port[i].irq); 89 + port->irqflags = 0; 90 + port->uartclk = old_serial_port[i].baud_base * 16; 91 + port->flags = old_serial_port[i].flags; 92 + port->hub6 = 0; 93 + port->membase = old_serial_port[i].iomem_base; 94 + port->iotype = old_serial_port[i].io_type; 95 + port->regshift = old_serial_port[i].iomem_reg_shift; 96 + 97 + port->irqflags |= irqflag; 98 + if (serial8250_isa_config != NULL) 99 + serial8250_isa_config(i, &up->port, &up->capabilities); 100 + 101 + serial_base_add_isa_preferred_console(serial8250_reg.dev_name, i); 102 + } 103 + } 104 + 105 + /* 106 + * Register a set of serial devices attached to a platform device. The 107 + * list is terminated with a zero flags entry, which means we expect 108 + * all entries to have at least UPF_BOOT_AUTOCONF set. 109 + */ 110 + static int serial8250_probe(struct platform_device *dev) 111 + { 112 + struct plat_serial8250_port *p = dev_get_platdata(&dev->dev); 113 + struct uart_8250_port uart; 114 + int ret, i, irqflag = 0; 115 + 116 + memset(&uart, 0, sizeof(uart)); 117 + 118 + if (share_irqs) 119 + irqflag = IRQF_SHARED; 120 + 121 + for (i = 0; p && p->flags != 0; p++, i++) { 122 + uart.port.iobase = p->iobase; 123 + uart.port.membase = p->membase; 124 + uart.port.irq = p->irq; 125 + uart.port.irqflags = p->irqflags; 126 + uart.port.uartclk = p->uartclk; 127 + uart.port.regshift = p->regshift; 128 + uart.port.iotype = p->iotype; 129 + uart.port.flags = p->flags; 130 + uart.port.mapbase = p->mapbase; 131 + uart.port.mapsize = p->mapsize; 132 + uart.port.hub6 = p->hub6; 133 + uart.port.has_sysrq = p->has_sysrq; 134 + uart.port.private_data = p->private_data; 135 + uart.port.type = p->type; 136 + uart.bugs = p->bugs; 137 + uart.port.serial_in = p->serial_in; 138 + uart.port.serial_out = p->serial_out; 139 + uart.dl_read = p->dl_read; 140 + uart.dl_write = p->dl_write; 141 + uart.port.handle_irq = p->handle_irq; 142 + uart.port.handle_break = p->handle_break; 143 + uart.port.set_termios = p->set_termios; 144 + uart.port.set_ldisc = p->set_ldisc; 145 + uart.port.get_mctrl = p->get_mctrl; 146 + uart.port.pm = p->pm; 147 + uart.port.dev = &dev->dev; 148 + uart.port.irqflags |= irqflag; 149 + ret = serial8250_register_8250_port(&uart); 150 + if (ret < 0) { 151 + dev_err(&dev->dev, "unable to register port at index %d " 152 + "(IO%lx MEM%llx IRQ%d): %d\n", i, 153 + p->iobase, (unsigned long long)p->mapbase, 154 + p->irq, ret); 155 + } 156 + } 157 + return 0; 158 + } 159 + 160 + /* 161 + * Remove serial ports registered against a platform device. 162 + */ 163 + static void serial8250_remove(struct platform_device *dev) 164 + { 165 + int i; 166 + 167 + for (i = 0; i < nr_uarts; i++) { 168 + struct uart_8250_port *up = serial8250_get_port(i); 169 + 170 + if (up->port.dev == &dev->dev) 171 + serial8250_unregister_port(i); 172 + } 173 + } 174 + 175 + static int serial8250_suspend(struct platform_device *dev, pm_message_t state) 176 + { 177 + int i; 178 + 179 + for (i = 0; i < UART_NR; i++) { 180 + struct uart_8250_port *up = serial8250_get_port(i); 181 + 182 + if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev) 183 + uart_suspend_port(&serial8250_reg, &up->port); 184 + } 185 + 186 + return 0; 187 + } 188 + 189 + static int serial8250_resume(struct platform_device *dev) 190 + { 191 + int i; 192 + 193 + for (i = 0; i < UART_NR; i++) { 194 + struct uart_8250_port *up = serial8250_get_port(i); 195 + 196 + if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev) 197 + serial8250_resume_port(i); 198 + } 199 + 200 + return 0; 201 + } 202 + 203 + static struct platform_driver serial8250_isa_driver = { 204 + .probe = serial8250_probe, 205 + .remove_new = serial8250_remove, 206 + .suspend = serial8250_suspend, 207 + .resume = serial8250_resume, 208 + .driver = { 209 + .name = "serial8250", 210 + }, 211 + }; 212 + 213 + /* 214 + * This "device" covers _all_ ISA 8250-compatible serial devices listed 215 + * in the table in include/asm/serial.h 216 + */ 217 + struct platform_device *serial8250_isa_devs; 218 + 219 + static int __init serial8250_init(void) 220 + { 221 + int ret; 222 + 223 + if (nr_uarts == 0) 224 + return -ENODEV; 225 + 226 + serial8250_isa_init_ports(); 227 + 228 + pr_info("Serial: 8250/16550 driver, %d ports, IRQ sharing %s\n", 229 + nr_uarts, str_enabled_disabled(share_irqs)); 230 + 231 + #ifdef CONFIG_SPARC 232 + ret = sunserial_register_minors(&serial8250_reg, UART_NR); 233 + #else 234 + serial8250_reg.nr = UART_NR; 235 + ret = uart_register_driver(&serial8250_reg); 236 + #endif 237 + if (ret) 238 + goto out; 239 + 240 + ret = serial8250_pnp_init(); 241 + if (ret) 242 + goto unreg_uart_drv; 243 + 244 + serial8250_isa_devs = platform_device_alloc("serial8250", 245 + PLAT8250_DEV_LEGACY); 246 + if (!serial8250_isa_devs) { 247 + ret = -ENOMEM; 248 + goto unreg_pnp; 249 + } 250 + 251 + ret = platform_device_add(serial8250_isa_devs); 252 + if (ret) 253 + goto put_dev; 254 + 255 + serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev); 256 + 257 + ret = platform_driver_register(&serial8250_isa_driver); 258 + if (ret == 0) 259 + goto out; 260 + 261 + platform_device_del(serial8250_isa_devs); 262 + put_dev: 263 + platform_device_put(serial8250_isa_devs); 264 + unreg_pnp: 265 + serial8250_pnp_exit(); 266 + unreg_uart_drv: 267 + #ifdef CONFIG_SPARC 268 + sunserial_unregister_minors(&serial8250_reg, UART_NR); 269 + #else 270 + uart_unregister_driver(&serial8250_reg); 271 + #endif 272 + out: 273 + return ret; 274 + } 275 + module_init(serial8250_init); 276 + 277 + static void __exit serial8250_exit(void) 278 + { 279 + struct platform_device *isa_dev = serial8250_isa_devs; 280 + 281 + /* 282 + * This tells serial8250_unregister_port() not to re-register 283 + * the ports (thereby making serial8250_isa_driver permanently 284 + * in use.) 285 + */ 286 + serial8250_isa_devs = NULL; 287 + 288 + platform_driver_unregister(&serial8250_isa_driver); 289 + platform_device_unregister(isa_dev); 290 + 291 + serial8250_pnp_exit(); 292 + 293 + #ifdef CONFIG_SPARC 294 + sunserial_unregister_minors(&serial8250_reg, UART_NR); 295 + #else 296 + uart_unregister_driver(&serial8250_reg); 297 + #endif 298 + } 299 + module_exit(serial8250_exit); 300 + 301 + MODULE_LICENSE("GPL"); 302 + MODULE_DESCRIPTION("Generic 8250/16x50 serial platform driver"); 303 + 304 + module_param_hw(share_irqs, uint, other, 0644); 305 + MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices (unsafe)"); 306 + 307 + module_param(nr_uarts, uint, 0644); 308 + MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")"); 309 + 310 + module_param(skip_txen_test, uint, 0644); 311 + MODULE_PARM_DESC(skip_txen_test, "Skip checking for the TXEN bug at init time"); 312 + 313 + MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR); 314 + 315 + #ifdef CONFIG_SERIAL_8250_DEPRECATED_OPTIONS 316 + #ifndef MODULE 317 + /* This module was renamed to 8250_core in 3.7. Keep the old "8250" name 318 + * working as well for the module options so we don't break people. We 319 + * need to keep the names identical and the convenient macros will happily 320 + * refuse to let us do that by failing the build with redefinition errors 321 + * of global variables. So we stick them inside a dummy function to avoid 322 + * those conflicts. The options still get parsed, and the redefined 323 + * MODULE_PARAM_PREFIX lets us keep the "8250." syntax alive. 324 + * 325 + * This is hacky. I'm sorry. 326 + */ 327 + static void __used s8250_options(void) 328 + { 329 + #undef MODULE_PARAM_PREFIX 330 + #define MODULE_PARAM_PREFIX "8250_core." 331 + 332 + module_param_cb(share_irqs, &param_ops_uint, &share_irqs, 0644); 333 + module_param_cb(nr_uarts, &param_ops_uint, &nr_uarts, 0644); 334 + module_param_cb(skip_txen_test, &param_ops_uint, &skip_txen_test, 0644); 335 + } 336 + #else 337 + MODULE_ALIAS("8250_core"); 338 + #endif 339 + #endif
+4 -1
drivers/tty/serial/8250/Makefile
··· 3 3 # Makefile for the 8250 serial device drivers. 4 4 # 5 5 6 - obj-$(CONFIG_SERIAL_8250) += 8250.o 8250_base.o 6 + obj-$(CONFIG_SERIAL_8250) += 8250.o 7 7 8250-y := 8250_core.o 8 + 8250-y += 8250_platform.o 8 9 8250-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o 9 10 8250-$(CONFIG_SERIAL_8250_RSA) += 8250_rsa.o 11 + 12 + obj-$(CONFIG_SERIAL_8250) += 8250_base.o 10 13 8250_base-y := 8250_port.o 11 14 8250_base-$(CONFIG_SERIAL_8250_DMA) += 8250_dma.o 12 15 8250_base-$(CONFIG_SERIAL_8250_DWLIB) += 8250_dwlib.o