diff options
Diffstat (limited to 'drivers/tty')
59 files changed, 619 insertions, 513 deletions
diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 226adeec2aed..e50665425902 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -115,8 +115,8 @@ int serdev_device_add(struct serdev_device *serdev) err = device_add(&serdev->dev); if (err < 0) { - dev_err(&serdev->dev, "Can't add %s, status %d\n", - dev_name(&serdev->dev), err); + dev_err(&serdev->dev, "Can't add %s, status %pe\n", + dev_name(&serdev->dev), ERR_PTR(err)); goto err_clear_serdev; } @@ -540,7 +540,8 @@ static int of_serdev_register_devices(struct serdev_controller *ctrl) err = serdev_device_add(serdev); if (err) { dev_err(&serdev->dev, - "failure adding device. status %d\n", err); + "failure adding device. status %pe\n", + ERR_PTR(err)); serdev_device_put(serdev); } else found = true; @@ -656,7 +657,8 @@ static acpi_status acpi_serdev_register_device(struct serdev_controller *ctrl, err = serdev_device_add(serdev); if (err) { dev_err(&serdev->dev, - "failure adding ACPI serdev device. status %d\n", err); + "failure adding ACPI serdev device. status %pe\n", + ERR_PTR(err)); serdev_device_put(serdev); } @@ -731,8 +733,8 @@ int serdev_controller_add(struct serdev_controller *ctrl) ret_of = of_serdev_register_devices(ctrl); ret_acpi = acpi_serdev_register_devices(ctrl); if (ret_of && ret_acpi) { - dev_dbg(&ctrl->dev, "no devices registered: of:%d acpi:%d\n", - ret_of, ret_acpi); + dev_dbg(&ctrl->dev, "no devices registered: of:%pe acpi:%pe\n", + ERR_PTR(ret_of), ERR_PTR(ret_acpi)); ret = -ENODEV; goto err_rpm_disable; } diff --git a/drivers/tty/serial/21285.c b/drivers/tty/serial/21285.c index 32b3acf8150a..718e010fcb04 100644 --- a/drivers/tty/serial/21285.c +++ b/drivers/tty/serial/21285.c @@ -41,8 +41,43 @@ static const char serial21285_name[] = "Footbridge UART"; -#define tx_enabled(port) ((port)->unused[0]) -#define rx_enabled(port) ((port)->unused[1]) +/* + * We only need 2 bits of data, so instead of creating a whole structure for + * this, use bits of the private_data pointer of the uart port structure. + */ +#define tx_enabled_bit 0 +#define rx_enabled_bit 1 + +static bool is_enabled(struct uart_port *port, int bit) +{ + unsigned long private_data = (unsigned long)port->private_data; + + if (test_bit(bit, &private_data)) + return true; + return false; +} + +static void enable(struct uart_port *port, int bit) +{ + unsigned long private_data = (unsigned long)port->private_data; + + set_bit(bit, &private_data); +} + +static void disable(struct uart_port *port, int bit) +{ + unsigned long private_data = (unsigned long)port->private_data; + + clear_bit(bit, &private_data); +} + +#define is_tx_enabled(port) is_enabled(port, tx_enabled_bit) +#define tx_enable(port) enable(port, tx_enabled_bit) +#define tx_disable(port) disable(port, tx_enabled_bit) + +#define is_rx_enabled(port) is_enabled(port, rx_enabled_bit) +#define rx_enable(port) enable(port, rx_enabled_bit) +#define rx_disable(port) disable(port, rx_enabled_bit) /* * The documented expression for selecting the divisor is: @@ -57,25 +92,25 @@ static const char serial21285_name[] = "Footbridge UART"; static void serial21285_stop_tx(struct uart_port *port) { - if (tx_enabled(port)) { + if (is_tx_enabled(port)) { disable_irq_nosync(IRQ_CONTX); - tx_enabled(port) = 0; + tx_disable(port); } } static void serial21285_start_tx(struct uart_port *port) { - if (!tx_enabled(port)) { + if (!is_tx_enabled(port)) { enable_irq(IRQ_CONTX); - tx_enabled(port) = 1; + tx_enable(port); } } static void serial21285_stop_rx(struct uart_port *port) { - if (rx_enabled(port)) { + if (is_rx_enabled(port)) { disable_irq_nosync(IRQ_CONRX); - rx_enabled(port) = 0; + rx_disable(port); } } @@ -185,8 +220,8 @@ static int serial21285_startup(struct uart_port *port) { int ret; - tx_enabled(port) = 1; - rx_enabled(port) = 1; + tx_enable(port); + rx_enable(port); ret = request_irq(IRQ_CONRX, serial21285_rx_chars, 0, serial21285_name, port); diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/serial/8250/8250_aspeed_vuart.c index 6e67fd89445a..d657aa14c3e4 100644 --- a/drivers/tty/serial/8250/8250_aspeed_vuart.c +++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c @@ -5,10 +5,6 @@ * Copyright (C) 2016 Jeremy Kerr <jk@ozlabs.org>, IBM Corp. * Copyright (C) 2006 Arnd Bergmann <arnd@arndb.de>, IBM Corp. */ -#if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/device.h> #include <linux/module.h> #include <linux/of_address.h> @@ -406,6 +402,7 @@ static int aspeed_vuart_probe(struct platform_device *pdev) port.port.unthrottle = aspeed_vuart_unthrottle; port.port.status = UPSTAT_SYNC_FIFO; port.port.dev = &pdev->dev; + port.port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE); rc = sysfs_create_group(&vuart->dev->kobj, &aspeed_vuart_attr_group); if (rc < 0) diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c index e682390ce0de..0894a22fd702 100644 --- a/drivers/tty/serial/8250/8250_core.c +++ b/drivers/tty/serial/8250/8250_core.c @@ -816,6 +816,7 @@ static int serial8250_probe(struct platform_device *dev) uart.port.flags = p->flags; uart.port.mapbase = p->mapbase; uart.port.hub6 = p->hub6; + uart.port.has_sysrq = p->has_sysrq; uart.port.private_data = p->private_data; uart.port.type = p->type; uart.port.serial_in = p->serial_in; diff --git a/drivers/tty/serial/8250/8250_fsl.c b/drivers/tty/serial/8250/8250_fsl.c index aa0e216d5ead..0d0c80905c58 100644 --- a/drivers/tty/serial/8250/8250_fsl.c +++ b/drivers/tty/serial/8250/8250_fsl.c @@ -1,8 +1,4 @@ // SPDX-License-Identifier: GPL-2.0 -#if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/serial_reg.h> #include <linux/serial_8250.h> diff --git a/drivers/tty/serial/8250/8250_of.c b/drivers/tty/serial/8250/8250_of.c index 92fbf46ce3bd..531ad67395e0 100644 --- a/drivers/tty/serial/8250/8250_of.c +++ b/drivers/tty/serial/8250/8250_of.c @@ -222,8 +222,10 @@ static int of_platform_serial_setup(struct platform_device *ofdev, if (IS_ENABLED(CONFIG_SERIAL_8250_FSL) && (of_device_is_compatible(np, "fsl,ns16550") || - of_device_is_compatible(np, "fsl,16550-FIFO64"))) + of_device_is_compatible(np, "fsl,16550-FIFO64"))) { port->handle_irq = fsl8250_handle_irq; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE); + } return 0; err_unprepare: diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c index 836e736ae188..1ee7b89817dd 100644 --- a/drivers/tty/serial/8250/8250_omap.c +++ b/drivers/tty/serial/8250/8250_omap.c @@ -8,10 +8,6 @@ * */ -#if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/clk.h> #include <linux/device.h> #include <linux/io.h> @@ -1192,6 +1188,7 @@ static int omap8250_probe(struct platform_device *pdev) up.port.throttle = omap_8250_throttle; up.port.unthrottle = omap_8250_unthrottle; up.port.rs485_config = omap_8250_rs485_config; + up.port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE); ret = of_alias_get_id(np, "serial"); if (ret < 0) { diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 90655910b0c7..8243f280a2ec 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -11,10 +11,6 @@ * membase is an 'ioremapped' cookie. */ -#if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/ioport.h> @@ -3055,6 +3051,7 @@ void serial8250_init_port(struct uart_8250_port *up) spin_lock_init(&port->lock); port->ops = &serial8250_pops; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_8250_CONSOLE); up->cur_iotype = 0xFF; } diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index 99f5da3bf913..c835e10bd97e 100644 --- a/drivers/tty/serial/Kconfig +++ b/drivers/tty/serial/Kconfig @@ -237,7 +237,7 @@ config SERIAL_CLPS711X_CONSOLE config SERIAL_SAMSUNG tristate "Samsung SoC serial support" - depends on PLAT_SAMSUNG || ARCH_EXYNOS + depends on PLAT_SAMSUNG || ARCH_EXYNOS || COMPILE_TEST select SERIAL_CORE help Support for the on-chip UARTs on the Samsung S3C24XX series CPUs, diff --git a/drivers/tty/serial/amba-pl010.c b/drivers/tty/serial/amba-pl010.c index 2c37d11726ab..3284f34e9dfe 100644 --- a/drivers/tty/serial/amba-pl010.c +++ b/drivers/tty/serial/amba-pl010.c @@ -15,10 +15,6 @@ * and hooked into this driver. */ -#if defined(CONFIG_SERIAL_AMBA_PL010_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/module.h> #include <linux/ioport.h> #include <linux/init.h> @@ -728,6 +724,7 @@ static int pl010_probe(struct amba_device *dev, const struct amba_id *id) uap->port.iotype = UPIO_MEM; uap->port.irq = dev->irq[0]; uap->port.fifosize = 16; + uap->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_AMBA_PL010_CONSOLE); uap->port.ops = &amba_pl010_pops; uap->port.flags = UPF_BOOT_AUTOCONF; uap->port.line = i; diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index 4b28134d596a..2296bb0f9578 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -16,11 +16,6 @@ * and hooked into this driver. */ - -#if defined(CONFIG_SERIAL_AMBA_PL011_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/module.h> #include <linux/ioport.h> #include <linux/init.h> @@ -1452,8 +1447,6 @@ static void pl011_modem_status(struct uart_amba_port *uap) static void check_apply_cts_event_workaround(struct uart_amba_port *uap) { - unsigned int dummy_read; - if (!uap->vendor->cts_event_workaround) return; @@ -1465,8 +1458,8 @@ static void check_apply_cts_event_workaround(struct uart_amba_port *uap) * single apb access will incur 2 pclk(133.12Mhz) delay, * so add 2 dummy reads */ - dummy_read = pl011_read(uap, REG_ICR); - dummy_read = pl011_read(uap, REG_ICR); + pl011_read(uap, REG_ICR); + pl011_read(uap, REG_ICR); } static irqreturn_t pl011_int(int irq, void *dev_id) @@ -2579,6 +2572,7 @@ static int pl011_setup_port(struct device *dev, struct uart_amba_port *uap, uap->port.mapbase = mmiobase->start; uap->port.membase = base; uap->port.fifosize = uap->fifosize; + uap->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_AMBA_PL011_CONSOLE); uap->port.flags = UPF_BOOT_AUTOCONF; uap->port.line = index; @@ -2769,6 +2763,7 @@ static struct platform_driver arm_sbsa_uart_platform_driver = { .remove = sbsa_uart_remove, .driver = { .name = "sbsa-uart", + .pm = &pl011_dev_pm_ops, .of_match_table = of_match_ptr(sbsa_uart_of_match), .acpi_match_table = ACPI_PTR(sbsa_uart_acpi_match), .suppress_bind_attrs = IS_BUILTIN(CONFIG_SERIAL_AMBA_PL011), diff --git a/drivers/tty/serial/apbuart.c b/drivers/tty/serial/apbuart.c index 60cd133ffbbc..e8d56e899ec7 100644 --- a/drivers/tty/serial/apbuart.c +++ b/drivers/tty/serial/apbuart.c @@ -11,10 +11,6 @@ * Copyright (C) 2009 Kristoffer Glembo <kristoffer@gaisler.com>, Aeroflex Gaisler AB */ -#if defined(CONFIG_SERIAL_GRLIB_GAISLER_APBUART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/module.h> #include <linux/tty.h> #include <linux/tty_flip.h> @@ -626,6 +622,7 @@ static int __init grlib_apbuart_configure(void) port->irq = 0; port->iotype = UPIO_MEM; port->ops = &grlib_apbuart_ops; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_GRLIB_GAISLER_APBUART_CONSOLE); port->flags = UPF_BOOT_AUTOCONF; port->line = line; port->uartclk = *freq_hz; diff --git a/drivers/tty/serial/arc_uart.c b/drivers/tty/serial/arc_uart.c index d904a3a345e7..17c3fc398fc6 100644 --- a/drivers/tty/serial/arc_uart.c +++ b/drivers/tty/serial/arc_uart.c @@ -21,10 +21,6 @@ * -check if sysreq works */ -#if defined(CONFIG_SERIAL_ARC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/module.h> #include <linux/serial.h> #include <linux/console.h> @@ -625,6 +621,7 @@ static int arc_serial_probe(struct platform_device *pdev) port->flags = UPF_BOOT_AUTOCONF; port->line = dev_id; port->ops = &arc_serial_pops; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ARC_CONSOLE); port->fifosize = ARC_UART_TX_FIFO_SIZE; diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 1ba9bc667e13..fa19eb360ed8 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -51,10 +51,6 @@ #define ATMEL_RTS_HIGH_OFFSET 16 #define ATMEL_RTS_LOW_OFFSET 20 -#if defined(CONFIG_SERIAL_ATMEL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/serial_core.h> #include "serial_mctrl_gpio.h" @@ -196,10 +192,6 @@ struct atmel_uart_port { static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART]; static DECLARE_BITMAP(atmel_ports_in_use, ATMEL_MAX_UART); -#ifdef SUPPORT_SYSRQ -static struct console atmel_console; -#endif - #if defined(CONFIG_OF) static const struct of_device_id atmel_serial_dt_ids[] = { { .compatible = "atmel,at91rm9200-usart-serial" }, @@ -2878,6 +2870,7 @@ static int atmel_serial_probe(struct platform_device *pdev) atmel_port = &atmel_ports[ret]; atmel_port->backup_imr = 0; atmel_port->uart.line = ret; + atmel_port->uart.has_sysrq = IS_ENABLED(CONFIG_SERIAL_ATMEL_CONSOLE); atmel_serial_probe_fifos(atmel_port, pdev); atomic_set(&atmel_port->tasklet_shutdown, 0); diff --git a/drivers/tty/serial/bcm63xx_uart.c b/drivers/tty/serial/bcm63xx_uart.c index b7adc6127b3d..5674da2b76f0 100644 --- a/drivers/tty/serial/bcm63xx_uart.c +++ b/drivers/tty/serial/bcm63xx_uart.c @@ -10,10 +10,6 @@ * my board. */ -#if defined(CONFIG_SERIAL_BCM63XX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/kernel.h> #include <linux/platform_device.h> #include <linux/init.h> @@ -858,6 +854,7 @@ static int bcm_uart_probe(struct platform_device *pdev) port->fifosize = 16; port->uartclk = clk_get_rate(clk) / 2; port->line = pdev->id; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_BCM63XX_CONSOLE); clk_put(clk); ret = uart_add_one_port(&bcm_uart_driver, port); diff --git a/drivers/tty/serial/clps711x.c b/drivers/tty/serial/clps711x.c index 061590795680..95abc6faa3d5 100644 --- a/drivers/tty/serial/clps711x.c +++ b/drivers/tty/serial/clps711x.c @@ -8,10 +8,6 @@ * Copyright (C) 2000 Deep Blue Solutions Ltd. */ -#if defined(CONFIG_SERIAL_CLPS711X_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/module.h> #include <linux/device.h> #include <linux/console.h> @@ -479,6 +475,7 @@ static int uart_clps711x_probe(struct platform_device *pdev) s->port.mapbase = res->start; s->port.type = PORT_CLPS711X; s->port.fifosize = 16; + s->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_CLPS711X_CONSOLE); s->port.flags = UPF_SKIP_TEST | UPF_FIXED_TYPE; s->port.uartclk = clk_get_rate(uart_clk); s->port.ops = &uart_clps711x_ops; diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c index de6d02f7abe2..19d5a4cf29a6 100644 --- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c +++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c @@ -40,10 +40,6 @@ #include <asm/fs_pd.h> #include <asm/udbg.h> -#if defined(CONFIG_SERIAL_CPM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/serial_core.h> #include <linux/kernel.h> @@ -347,9 +343,7 @@ static void cpm_uart_int_rx(struct uart_port *port) /* ASSUMPTION: it contains nothing valid */ i = 0; } -#ifdef SUPPORT_SYSRQ port->sysrq = 0; -#endif goto error_return; } @@ -1204,7 +1198,8 @@ static int cpm_uart_init_port(struct device_node *np, pinfo->port.uartclk = ppc_proc_freq; pinfo->port.mapbase = (unsigned long)mem; pinfo->port.type = PORT_CPM; - pinfo->port.ops = &cpm_uart_pops, + pinfo->port.ops = &cpm_uart_pops; + pinfo->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_CPM_CONSOLE); pinfo->port.iotype = UPIO_MEM; pinfo->port.fifosize = pinfo->tx_nrfifos * pinfo->tx_fifosize; spin_lock_init(&pinfo->port.lock); diff --git a/drivers/tty/serial/dz.c b/drivers/tty/serial/dz.c index 7b57e840e255..6192ed011bc3 100644 --- a/drivers/tty/serial/dz.c +++ b/drivers/tty/serial/dz.c @@ -29,10 +29,6 @@ #undef DEBUG_DZ -#if defined(CONFIG_SERIAL_DZ_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/bitops.h> #include <linux/compiler.h> #include <linux/console.h> @@ -787,6 +783,7 @@ static void __init dz_init_ports(void) uport->ops = &dz_ops; uport->line = line; uport->mapbase = base; + uport->has_sysrq = IS_ENABLED(CONFIG_SERIAL_DZ_CONSOLE); } } diff --git a/drivers/tty/serial/efm32-uart.c b/drivers/tty/serial/efm32-uart.c index d6b5e5463746..2ac87128d7fd 100644 --- a/drivers/tty/serial/efm32-uart.c +++ b/drivers/tty/serial/efm32-uart.c @@ -1,8 +1,4 @@ // SPDX-License-Identifier: GPL-2.0 -#if defined(CONFIG_SERIAL_EFM32_UART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/kernel.h> #include <linux/module.h> #include <linux/io.h> @@ -748,6 +744,7 @@ static int efm32_uart_probe(struct platform_device *pdev) efm_port->port.type = PORT_EFMUART; efm_port->port.iotype = UPIO_MEM32; efm_port->port.fifosize = 2; + efm_port->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_EFM32_UART_CONSOLE); efm_port->port.ops = &efm32_uart_pops; efm_port->port.flags = UPF_BOOT_AUTOCONF; diff --git a/drivers/tty/serial/fsl_linflexuart.c b/drivers/tty/serial/fsl_linflexuart.c index 205c31a61684..3e28be402aef 100644 --- a/drivers/tty/serial/fsl_linflexuart.c +++ b/drivers/tty/serial/fsl_linflexuart.c @@ -6,11 +6,6 @@ * Copyright 2017-2019 NXP */ -#if defined(CONFIG_SERIAL_FSL_LINFLEXUART_CONSOLE) && \ - defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/console.h> #include <linux/io.h> #include <linux/irq.h> @@ -279,10 +274,8 @@ static irqreturn_t linflex_rxint(int irq, void *dev_id) if (brk) { uart_handle_break(sport); } else { -#ifdef SUPPORT_SYSRQ if (uart_handle_sysrq_char(sport, (unsigned char)rx)) continue; -#endif tty_insert_flip_char(port, rx, flg); } } @@ -863,6 +856,7 @@ static int linflex_probe(struct platform_device *pdev) sport->irq = platform_get_irq(pdev, 0); sport->ops = &linflex_pops; sport->flags = UPF_BOOT_AUTOCONF; + sport->has_sysrq = IS_ENABLED(CONFIG_SERIAL_FSL_LINFLEXUART_CONSOLE); linflex_ports[sport->line] = sport; diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c index 4e128d19e0ad..76c69d255d92 100644 --- a/drivers/tty/serial/fsl_lpuart.c +++ b/drivers/tty/serial/fsl_lpuart.c @@ -5,10 +5,6 @@ * Copyright 2012-2014 Freescale Semiconductor, Inc. */ -#if defined(CONFIG_SERIAL_FSL_LPUART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/clk.h> #include <linux/console.h> #include <linux/dma-mapping.h> @@ -864,9 +860,7 @@ static void lpuart_rxint(struct lpuart_port *sport) if (sr & UARTSR1_OR) flg = TTY_OVERRUN; -#ifdef SUPPORT_SYSRQ sport->port.sysrq = 0; -#endif } tty_insert_flip_char(port, rx, flg); @@ -946,9 +940,7 @@ static void lpuart32_rxint(struct lpuart_port *sport) if (sr & UARTSTAT_OR) flg = TTY_OVERRUN; -#ifdef SUPPORT_SYSRQ sport->port.sysrq = 0; -#endif } tty_insert_flip_char(port, rx, flg); @@ -2461,6 +2453,7 @@ static int lpuart_probe(struct platform_device *pdev) sport->port.ops = &lpuart32_pops; else sport->port.ops = &lpuart_pops; + sport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_FSL_LPUART_CONSOLE); sport->port.flags = UPF_BOOT_AUTOCONF; if (lpuart_is_32(sport)) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index a9e20e6c63ad..83c6e2ac0e8d 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -8,10 +8,6 @@ * Copyright (C) 2004 Pengutronix */ -#if defined(CONFIG_SERIAL_IMX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/module.h> #include <linux/ioport.h> #include <linux/init.h> @@ -779,9 +775,7 @@ static irqreturn_t imx_uart_rxint(int irq, void *dev_id) if (rx & URXD_OVRRUN) flg = TTY_OVERRUN; -#ifdef SUPPORT_SYSRQ sport->port.sysrq = 0; -#endif } if (sport->port.ignore_status_mask & URXD_DUMMY_READ) @@ -2231,6 +2225,7 @@ static int imx_uart_probe(struct platform_device *pdev) sport->port.iotype = UPIO_MEM; sport->port.irq = rxirq; sport->port.fifosize = 32; + sport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_IMX_CONSOLE); sport->port.ops = &imx_uart_pops; sport->port.rs485_config = imx_uart_rs485_config; sport->port.flags = UPF_BOOT_AUTOCONF; diff --git a/drivers/tty/serial/ip22zilog.c b/drivers/tty/serial/ip22zilog.c index 8c810733df3d..86fff69d7e7c 100644 --- a/drivers/tty/serial/ip22zilog.c +++ b/drivers/tty/serial/ip22zilog.c @@ -38,10 +38,6 @@ #include <asm/sgi/hpc3.h> #include <asm/sgi/ip22.h> -#if defined(CONFIG_SERIAL_IP22_ZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/serial_core.h> #include "ip22zilog.h" @@ -1080,6 +1076,7 @@ static struct uart_driver ip22zilog_reg = { static void __init ip22zilog_prepare(void) { + unsigned char sysrq_on = IS_ENABLED(CONFIG_SERIAL_IP22_ZILOG_CONSOLE); struct uart_ip22zilog_port *up; struct zilog_layout *rp; int channel, chip; @@ -1115,6 +1112,7 @@ static void __init ip22zilog_prepare(void) up[(chip * 2) + 0].port.irq = zilog_irq; up[(chip * 2) + 0].port.uartclk = ZS_CLOCK; up[(chip * 2) + 0].port.fifosize = 1; + up[(chip * 2) + 0].port.has_sysrq = sysrq_on; up[(chip * 2) + 0].port.ops = &ip22zilog_pops; up[(chip * 2) + 0].port.type = PORT_IP22ZILOG; up[(chip * 2) + 0].port.flags = 0; @@ -1126,6 +1124,7 @@ static void __init ip22zilog_prepare(void) up[(chip * 2) + 1].port.irq = zilog_irq; up[(chip * 2) + 1].port.uartclk = ZS_CLOCK; up[(chip * 2) + 1].port.fifosize = 1; + up[(chip * 2) + 1].port.has_sysrq = sysrq_on; up[(chip * 2) + 1].port.ops = &ip22zilog_pops; up[(chip * 2) + 1].port.type = PORT_IP22ZILOG; up[(chip * 2) + 1].port.line = (chip * 2) + 1; diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c index fbc5bc022a39..12e15358554c 100644 --- a/drivers/tty/serial/meson_uart.c +++ b/drivers/tty/serial/meson_uart.c @@ -5,10 +5,6 @@ * Copyright (C) 2014 Carlo Caione <carlo@caione.org> */ -#if defined(CONFIG_SERIAL_MESON_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/clk.h> #include <linux/console.h> #include <linux/delay.h> @@ -703,6 +699,7 @@ static int meson_uart_probe(struct platform_device *pdev) port->mapsize = resource_size(res_mem); port->irq = res_irq->start; port->flags = UPF_BOOT_AUTOCONF | UPF_LOW_LATENCY; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MESON_CONSOLE); port->dev = &pdev->dev; port->line = pdev->id; port->type = PORT_MESON; diff --git a/drivers/tty/serial/milbeaut_usio.c b/drivers/tty/serial/milbeaut_usio.c index 949ab7efc4fc..8f2cab7f66ad 100644 --- a/drivers/tty/serial/milbeaut_usio.c +++ b/drivers/tty/serial/milbeaut_usio.c @@ -3,10 +3,6 @@ * Copyright (C) 2018 Socionext Inc. */ -#if defined(CONFIG_SERIAL_MILBEAUT_USIO_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/clk.h> #include <linux/console.h> #include <linux/module.h> @@ -537,6 +533,7 @@ static int mlb_usio_probe(struct platform_device *pdev) port->irq = mlb_usio_irq[index][RX]; port->uartclk = clk_get_rate(clk); port->fifosize = 128; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MILBEAUT_USIO_CONSOLE); port->iotype = UPIO_MEM32; port->flags = UPF_BOOT_AUTOCONF | UPF_SPD_VHI; port->line = index; diff --git a/drivers/tty/serial/mpc52xx_uart.c b/drivers/tty/serial/mpc52xx_uart.c index 3a75ee08d619..af1700445251 100644 --- a/drivers/tty/serial/mpc52xx_uart.c +++ b/drivers/tty/serial/mpc52xx_uart.c @@ -44,10 +44,6 @@ #include <asm/mpc52xx.h> #include <asm/mpc52xx_psc.h> -#if defined(CONFIG_SERIAL_MPC52xx_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/serial_core.h> @@ -1382,12 +1378,8 @@ mpc52xx_uart_int_rx_chars(struct uart_port *port) ch = psc_ops->read_char(port); /* Handle sysreq char */ -#ifdef SUPPORT_SYSRQ - if (uart_handle_sysrq_char(port, ch)) { - port->sysrq = 0; + if (uart_handle_sysrq_char(port, ch)) continue; - } -#endif /* Store it */ @@ -1770,6 +1762,7 @@ static int mpc52xx_uart_of_probe(struct platform_device *op) spin_lock_init(&port->lock); port->uartclk = uartclk; port->fifosize = 512; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MPC52xx_CONSOLE); port->iotype = UPIO_MEM; port->flags = UPF_BOOT_AUTOCONF | (uart_console(port) ? 0 : UPF_IOREMAP); diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c index f6c45a796433..19e897dad5fe 100644 --- a/drivers/tty/serial/msm_serial.c +++ b/drivers/tty/serial/msm_serial.c @@ -7,10 +7,6 @@ * Copyright (c) 2011, Code Aurora Forum. All rights reserved. */ -#if defined(CONFIG_SERIAL_MSM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -# define SUPPORT_SYSRQ -#endif - #include <linux/kernel.h> #include <linux/atomic.h> #include <linux/dma-mapping.h> @@ -1810,6 +1806,7 @@ static int msm_serial_probe(struct platform_device *pdev) if (unlikely(irq < 0)) return -ENXIO; port->irq = irq; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MSM_CONSOLE); platform_set_drvdata(pdev, port); diff --git a/drivers/tty/serial/mux.c b/drivers/tty/serial/mux.c index 00ce31e8d19a..2a9953211a2a 100644 --- a/drivers/tty/serial/mux.c +++ b/drivers/tty/serial/mux.c @@ -25,11 +25,7 @@ #include <asm/irq.h> #include <asm/parisc-device.h> -#if defined(CONFIG_SERIAL_MUX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) #include <linux/sysrq.h> -#define SUPPORT_SYSRQ -#endif - #include <linux/serial_core.h> #define MUX_OFFSET 0x800 @@ -483,6 +479,7 @@ static int __init mux_probe(struct parisc_device *dev) port->ops = &mux_pops; port->flags = UPF_BOOT_AUTOCONF; port->line = port_cnt; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MUX_CONSOLE); /* The port->timeout needs to match what is present in * uart_wait_until_sent in serial_core.c. Otherwise diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c index e34525970682..b4f835e7de23 100644 --- a/drivers/tty/serial/mxs-auart.c +++ b/drivers/tty/serial/mxs-auart.c @@ -12,10 +12,6 @@ * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved. */ -#if defined(CONFIG_SERIAL_MXS_AUART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/kernel.h> #include <linux/errno.h> #include <linux/init.h> @@ -1693,6 +1689,7 @@ static int mxs_auart_probe(struct platform_device *pdev) s->port.fifosize = MXS_AUART_FIFO_SIZE; s->port.uartclk = clk_get_rate(s->clk); s->port.type = PORT_IMX; + s->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_MXS_AUART_CONSOLE); mxs_init_regs(s); diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c index 6420ae581a80..48017cec7f2f 100644 --- a/drivers/tty/serial/omap-serial.c +++ b/drivers/tty/serial/omap-serial.c @@ -16,10 +16,6 @@ * this driver as required for the omap-platform. */ -#if defined(CONFIG_SERIAL_OMAP_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/module.h> #include <linux/init.h> #include <linux/console.h> @@ -493,10 +489,13 @@ static unsigned int check_modem_status(struct uart_omap_port *up) static void serial_omap_rlsi(struct uart_omap_port *up, unsigned int lsr) { unsigned int flag; - unsigned char ch = 0; + /* + * Read one data character out to avoid stalling the receiver according + * to the table 23-246 of the omap4 TRM. + */ if (likely(lsr & UART_LSR_DR)) - ch = serial_in(up, UART_RX); + serial_in(up, UART_RX); up->port.icount.rx++; flag = TTY_NORMAL; @@ -1680,6 +1679,7 @@ static int serial_omap_probe(struct platform_device *pdev) up->port.regshift = 2; up->port.fifosize = 64; up->port.ops = &serial_omap_pops; + up->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_OMAP_CONSOLE); if (pdev->dev.of_node) ret = of_alias_get_id(pdev->dev.of_node, "serial"); diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c index c16234bca78f..0a96217dba67 100644 --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -2,9 +2,6 @@ /* *Copyright (C) 2011 LAPIS Semiconductor Co., Ltd. */ -#if defined(CONFIG_SERIAL_PCH_UART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif #include <linux/kernel.h> #include <linux/serial_reg.h> #include <linux/slab.h> @@ -587,12 +584,8 @@ static int pch_uart_hal_read(struct eg20t_port *priv, unsigned char *buf, if (uart_handle_break(port)) continue; } -#ifdef SUPPORT_SYSRQ - if (port->sysrq) { - if (uart_handle_sysrq_char(port, rbr)) - continue; - } -#endif + if (uart_handle_sysrq_char(port, rbr)) + continue; buf[i++] = rbr; } @@ -1796,6 +1789,7 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev, priv->port.flags = UPF_BOOT_AUTOCONF; priv->port.fifosize = fifosize; priv->port.line = board->line_no; + priv->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_PCH_UART_CONSOLE); priv->trigger = PCH_UART_HAL_TRIGGER_M; snprintf(priv->irq_name, IRQ_NAME_SIZE, diff --git a/drivers/tty/serial/pmac_zilog.c b/drivers/tty/serial/pmac_zilog.c index bcb5bf70534e..ba65a3bbd72a 100644 --- a/drivers/tty/serial/pmac_zilog.c +++ b/drivers/tty/serial/pmac_zilog.c @@ -61,10 +61,6 @@ #define of_machine_is_compatible(x) (0) #endif -#if defined (CONFIG_SERIAL_PMACZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/serial.h> #include <linux/serial_core.h> @@ -1721,6 +1717,7 @@ static int __init pmz_init_port(struct uart_pmac_port *uap) uap->control_reg = uap->port.membase; uap->data_reg = uap->control_reg + 4; uap->port_type = 0; + uap->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_PMACZILOG_CONSOLE); pmz_convert_to_zs(uap, CS8, 0, 9600); diff --git a/drivers/tty/serial/pnx8xxx_uart.c b/drivers/tty/serial/pnx8xxx_uart.c index 223a9499104e..972d94e8d32b 100644 --- a/drivers/tty/serial/pnx8xxx_uart.c +++ b/drivers/tty/serial/pnx8xxx_uart.c @@ -10,10 +10,6 @@ * Copyright (C) 2000 Deep Blue Solutions Ltd. */ -#if defined(CONFIG_SERIAL_PNX8XXX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/module.h> #include <linux/ioport.h> #include <linux/init.h> @@ -220,9 +216,7 @@ static void pnx8xxx_rx_chars(struct pnx8xxx_port *sport) else if (status & FIFO_TO_SM(PNX8XXX_UART_FIFO_RXFE)) flg = TTY_FRAME; -#ifdef SUPPORT_SYSRQ sport->port.sysrq = 0; -#endif } if (uart_handle_sysrq_char(&sport->port, ch)) @@ -800,6 +794,7 @@ static int pnx8xxx_serial_probe(struct platform_device *pdev) if (pnx8xxx_ports[i].port.mapbase != res->start) continue; + pnx8xxx_ports[i].port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_PNX8XXX_CONSOLE); pnx8xxx_ports[i].port.dev = &pdev->dev; uart_add_one_port(&pnx8xxx_reg, &pnx8xxx_ports[i].port); platform_set_drvdata(pdev, &pnx8xxx_ports[i]); diff --git a/drivers/tty/serial/pxa.c b/drivers/tty/serial/pxa.c index 4932b674f7ef..41319ef96fa6 100644 --- a/drivers/tty/serial/pxa.c +++ b/drivers/tty/serial/pxa.c @@ -19,10 +19,6 @@ */ -#if defined(CONFIG_SERIAL_PXA_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/ioport.h> #include <linux/init.h> #include <linux/console.h> @@ -879,6 +875,7 @@ static int serial_pxa_probe(struct platform_device *dev) sport->port.dev = &dev->dev; sport->port.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; sport->port.uartclk = clk_get_rate(sport->clk); + sport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_PXA_CONSOLE); ret = serial_pxa_probe_dt(dev, sport); if (ret > 0) diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c index ff63728a95f4..c41c766d6c7c 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -1,10 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2017-2018, The Linux foundation. All rights reserved. -#if defined(CONFIG_SERIAL_QCOM_GENI_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -# define SUPPORT_SYSRQ -#endif - #include <linux/clk.h> #include <linux/console.h> #include <linux/io.h> @@ -1308,6 +1304,7 @@ static int qcom_geni_serial_probe(struct platform_device *pdev) if (irq < 0) return irq; uport->irq = irq; + uport->has_sysrq = IS_ENABLED(CONFIG_SERIAL_QCOM_GENI_CONSOLE); irq_set_status_flags(uport->irq, IRQ_NOAUTOEN); ret = devm_request_irq(uport->dev, uport->irq, qcom_geni_serial_isr, diff --git a/drivers/tty/serial/sa1100.c b/drivers/tty/serial/sa1100.c index 8e618129e65c..75c2a22895f9 100644 --- a/drivers/tty/serial/sa1100.c +++ b/drivers/tty/serial/sa1100.c @@ -7,10 +7,6 @@ * Copyright (C) 2000 Deep Blue Solutions Ltd. */ -#if defined(CONFIG_SERIAL_SA1100_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/module.h> #include <linux/ioport.h> #include <linux/init.h> @@ -214,9 +210,7 @@ sa1100_rx_chars(struct sa1100_port *sport) else if (status & UTSR1_TO_SM(UTSR1_FRE)) flg = TTY_FRAME; -#ifdef SUPPORT_SYSRQ sport->port.sysrq = 0; -#endif } if (uart_handle_sysrq_char(&sport->port, ch)) @@ -860,6 +854,7 @@ static int sa1100_serial_resume(struct platform_device *dev) static int sa1100_serial_add_one_port(struct sa1100_port *sport, struct platform_device *dev) { sport->port.dev = &dev->dev; + sport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SA1100_CONSOLE); // mctrl_gpio_init() requires that the GPIO driver supports interrupts, // but we need to support GPIO drivers for hardware that has no such diff --git a/drivers/tty/serial/samsung.h b/drivers/tty/serial/samsung.h deleted file mode 100644 index f93022113f59..000000000000 --- a/drivers/tty/serial/samsung.h +++ /dev/null @@ -1,147 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#ifndef __SAMSUNG_H -#define __SAMSUNG_H - -/* - * Driver for Samsung SoC onboard UARTs. - * - * Ben Dooks, Copyright (c) 2003-2008 Simtec Electronics - * http://armlinux.simtec.co.uk/ -*/ - -#include <linux/dmaengine.h> - -struct s3c24xx_uart_info { - char *name; - unsigned int type; - unsigned int fifosize; - unsigned long rx_fifomask; - unsigned long rx_fifoshift; - unsigned long rx_fifofull; - unsigned long tx_fifomask; - unsigned long tx_fifoshift; - unsigned long tx_fifofull; - unsigned int def_clk_sel; - unsigned long num_clks; - unsigned long clksel_mask; - unsigned long clksel_shift; - - /* uart port features */ - - unsigned int has_divslot:1; - - /* uart controls */ - int (*reset_port)(struct uart_port *, struct s3c2410_uartcfg *); -}; - -struct s3c24xx_serial_drv_data { - struct s3c24xx_uart_info *info; - struct s3c2410_uartcfg *def_cfg; - unsigned int fifosize[CONFIG_SERIAL_SAMSUNG_UARTS]; -}; - -struct s3c24xx_uart_dma { - unsigned int rx_chan_id; - unsigned int tx_chan_id; - - struct dma_slave_config rx_conf; - struct dma_slave_config tx_conf; - - struct dma_chan *rx_chan; - struct dma_chan *tx_chan; - - dma_addr_t rx_addr; - dma_addr_t tx_addr; - - dma_cookie_t rx_cookie; - dma_cookie_t tx_cookie; - - char *rx_buf; - - dma_addr_t tx_transfer_addr; - - size_t rx_size; - size_t tx_size; - - struct dma_async_tx_descriptor *tx_desc; - struct dma_async_tx_descriptor *rx_desc; - - int tx_bytes_requested; - int rx_bytes_requested; -}; - -struct s3c24xx_uart_port { - unsigned char rx_claimed; - unsigned char tx_claimed; - unsigned int pm_level; - unsigned long baudclk_rate; - unsigned int min_dma_size; - - unsigned int rx_irq; - unsigned int tx_irq; - - unsigned int tx_in_progress; - unsigned int tx_mode; - unsigned int rx_mode; - - struct s3c24xx_uart_info *info; - struct clk *clk; - struct clk *baudclk; - struct uart_port port; - struct s3c24xx_serial_drv_data *drv_data; - - /* reference to platform data */ - struct s3c2410_uartcfg *cfg; - - struct s3c24xx_uart_dma *dma; - -#ifdef CONFIG_ARM_S3C24XX_CPUFREQ - struct notifier_block freq_transition; -#endif -}; - -/* conversion functions */ - -#define s3c24xx_dev_to_port(__dev) dev_get_drvdata(__dev) - -/* register access controls */ - -#define portaddr(port, reg) ((port)->membase + (reg)) -#define portaddrl(port, reg) \ - ((unsigned long *)(unsigned long)((port)->membase + (reg))) - -#define rd_regb(port, reg) (readb_relaxed(portaddr(port, reg))) -#define rd_regl(port, reg) (readl_relaxed(portaddr(port, reg))) - -#define wr_regb(port, reg, val) writeb_relaxed(val, portaddr(port, reg)) -#define wr_regl(port, reg, val) writel_relaxed(val, portaddr(port, reg)) - -/* Byte-order aware bit setting/clearing functions. */ - -static inline void s3c24xx_set_bit(struct uart_port *port, int idx, - unsigned int reg) -{ - unsigned long flags; - u32 val; - - local_irq_save(flags); - val = rd_regl(port, reg); - val |= (1 << idx); - wr_regl(port, reg, val); - local_irq_restore(flags); -} - -static inline void s3c24xx_clear_bit(struct uart_port *port, int idx, - unsigned int reg) -{ - unsigned long flags; - u32 val; - - local_irq_save(flags); - val = rd_regl(port, reg); - val &= ~(1 << idx); - wr_regl(port, reg, val); - local_irq_restore(flags); -} - -#endif diff --git a/drivers/tty/serial/samsung_tty.c b/drivers/tty/serial/samsung_tty.c index 83fd51607741..4762c74dbc35 100644 --- a/drivers/tty/serial/samsung_tty.c +++ b/drivers/tty/serial/samsung_tty.c @@ -4,7 +4,7 @@ * * Ben Dooks, Copyright (c) 2003-2008 Simtec Electronics * http://armlinux.simtec.co.uk/ -*/ + */ /* Hote on 2410 error handling * @@ -19,11 +19,7 @@ * and change the policy on BREAK * * BJD, 04-Nov-2004 -*/ - -#if defined(CONFIG_SERIAL_SAMSUNG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif + */ #include <linux/dmaengine.h> #include <linux/dma-mapping.h> @@ -44,33 +40,8 @@ #include <linux/clk.h> #include <linux/cpufreq.h> #include <linux/of.h> - #include <asm/irq.h> -#include "samsung.h" - -#if defined(CONFIG_SERIAL_SAMSUNG_DEBUG) && \ - !defined(MODULE) - -extern void printascii(const char *); - -__printf(1, 2) -static void dbg(const char *fmt, ...) -{ - va_list va; - char buff[256]; - - va_start(va, fmt); - vscnprintf(buff, sizeof(buff), fmt, va); - va_end(va); - - printascii(buff); -} - -#else -#define dbg(fmt, ...) do { if (0) no_printk(fmt, ##__VA_ARGS__); } while (0) -#endif - /* UART name and device definitions */ #define S3C24XX_SERIAL_NAME "ttySAC" @@ -81,14 +52,142 @@ static void dbg(const char *fmt, ...) #define S3C24XX_TX_DMA 2 #define S3C24XX_RX_PIO 1 #define S3C24XX_RX_DMA 2 -/* macros to change one thing to another */ - -#define tx_enabled(port) ((port)->unused[0]) -#define rx_enabled(port) ((port)->unused[1]) /* flag to ignore all characters coming in */ #define RXSTAT_DUMMY_READ (0x10000000) +struct s3c24xx_uart_info { + char *name; + unsigned int type; + unsigned int fifosize; + unsigned long rx_fifomask; + unsigned long rx_fifoshift; + unsigned long rx_fifofull; + unsigned long tx_fifomask; + unsigned long tx_fifoshift; + unsigned long tx_fifofull; + unsigned int def_clk_sel; + unsigned long num_clks; + unsigned long clksel_mask; + unsigned long clksel_shift; + + /* uart port features */ + + unsigned int has_divslot:1; +}; + +struct s3c24xx_serial_drv_data { + struct s3c24xx_uart_info *info; + struct s3c2410_uartcfg *def_cfg; + unsigned int fifosize[CONFIG_SERIAL_SAMSUNG_UARTS]; +}; + +struct s3c24xx_uart_dma { + unsigned int rx_chan_id; + unsigned int tx_chan_id; + + struct dma_slave_config rx_conf; + struct dma_slave_config tx_conf; + + struct dma_chan *rx_chan; + struct dma_chan *tx_chan; + + dma_addr_t rx_addr; + dma_addr_t tx_addr; + + dma_cookie_t rx_cookie; + dma_cookie_t tx_cookie; + + char *rx_buf; + + dma_addr_t tx_transfer_addr; + + size_t rx_size; + size_t tx_size; + + struct dma_async_tx_descriptor *tx_desc; + struct dma_async_tx_descriptor *rx_desc; + + int tx_bytes_requested; + int rx_bytes_requested; +}; + +struct s3c24xx_uart_port { + unsigned char rx_claimed; + unsigned char tx_claimed; + unsigned char rx_enabled; + unsigned char tx_enabled; + unsigned int pm_level; + unsigned long baudclk_rate; + unsigned int min_dma_size; + + unsigned int rx_irq; + unsigned int tx_irq; + + unsigned int tx_in_progress; + unsigned int tx_mode; + unsigned int rx_mode; + + struct s3c24xx_uart_info *info; + struct clk *clk; + struct clk *baudclk; + struct uart_port port; + struct s3c24xx_serial_drv_data *drv_data; + + /* reference to platform data */ + struct s3c2410_uartcfg *cfg; + + struct s3c24xx_uart_dma *dma; + +#ifdef CONFIG_ARM_S3C24XX_CPUFREQ + struct notifier_block freq_transition; +#endif +}; + +/* conversion functions */ + +#define s3c24xx_dev_to_port(__dev) dev_get_drvdata(__dev) + +/* register access controls */ + +#define portaddr(port, reg) ((port)->membase + (reg)) +#define portaddrl(port, reg) \ + ((unsigned long *)(unsigned long)((port)->membase + (reg))) + +#define rd_regb(port, reg) (readb_relaxed(portaddr(port, reg))) +#define rd_regl(port, reg) (readl_relaxed(portaddr(port, reg))) + +#define wr_regb(port, reg, val) writeb_relaxed(val, portaddr(port, reg)) +#define wr_regl(port, reg, val) writel_relaxed(val, portaddr(port, reg)) + +/* Byte-order aware bit setting/clearing functions. */ + +static inline void s3c24xx_set_bit(struct uart_port *port, int idx, + unsigned int reg) +{ + unsigned long flags; + u32 val; + + local_irq_save(flags); + val = rd_regl(port, reg); + val |= (1 << idx); + wr_regl(port, reg, val); + local_irq_restore(flags); +} + +static inline void s3c24xx_clear_bit(struct uart_port *port, int idx, + unsigned int reg) +{ + unsigned long flags; + u32 val; + + local_irq_save(flags); + val = rd_regl(port, reg); + val &= ~(1 << idx); + wr_regl(port, reg, val); + local_irq_restore(flags); +} + static inline struct s3c24xx_uart_port *to_ourport(struct uart_port *port) { return container_of(port, struct s3c24xx_uart_port, port); @@ -118,6 +217,7 @@ static int s3c24xx_serial_has_interrupt_mask(struct uart_port *port) static void s3c24xx_serial_rx_enable(struct uart_port *port) { + struct s3c24xx_uart_port *ourport = to_ourport(port); unsigned long flags; unsigned int ucon, ufcon; int count = 10000; @@ -135,12 +235,13 @@ static void s3c24xx_serial_rx_enable(struct uart_port *port) ucon |= S3C2410_UCON_RXIRQMODE; wr_regl(port, S3C2410_UCON, ucon); - rx_enabled(port) = 1; + ourport->rx_enabled = 1; spin_unlock_irqrestore(&port->lock, flags); } static void s3c24xx_serial_rx_disable(struct uart_port *port) { + struct s3c24xx_uart_port *ourport = to_ourport(port); unsigned long flags; unsigned int ucon; @@ -150,7 +251,7 @@ static void s3c24xx_serial_rx_disable(struct uart_port *port) ucon &= ~S3C2410_UCON_RXIRQMODE; wr_regl(port, S3C2410_UCON, ucon); - rx_enabled(port) = 0; + ourport->rx_enabled = 0; spin_unlock_irqrestore(&port->lock, flags); } @@ -162,7 +263,7 @@ static void s3c24xx_serial_stop_tx(struct uart_port *port) struct dma_tx_state state; int count; - if (!tx_enabled(port)) + if (!ourport->tx_enabled) return; if (s3c24xx_serial_has_interrupt_mask(port)) @@ -182,7 +283,7 @@ static void s3c24xx_serial_stop_tx(struct uart_port *port) port->icount.tx += count; } - tx_enabled(port) = 0; + ourport->tx_enabled = 0; ourport->tx_in_progress = 0; if (port->flags & UPF_CONS_FLOW) @@ -340,11 +441,11 @@ static void s3c24xx_serial_start_tx(struct uart_port *port) struct s3c24xx_uart_port *ourport = to_ourport(port); struct circ_buf *xmit = &port->state->xmit; - if (!tx_enabled(port)) { + if (!ourport->tx_enabled) { if (port->flags & UPF_CONS_FLOW) s3c24xx_serial_rx_disable(port); - tx_enabled(port) = 1; + ourport->tx_enabled = 1; if (!ourport->dma || !ourport->dma->tx_chan) s3c24xx_serial_start_tx_pio(ourport); } @@ -389,14 +490,14 @@ static void s3c24xx_serial_stop_rx(struct uart_port *port) enum dma_status dma_status; unsigned int received; - if (rx_enabled(port)) { - dbg("s3c24xx_serial_stop_rx: port=%p\n", port); + if (ourport->rx_enabled) { + dev_dbg(port->dev, "stopping rx\n"); if (s3c24xx_serial_has_interrupt_mask(port)) s3c24xx_set_bit(port, S3C64XX_UINTM_RXD, S3C64XX_UINTM); else disable_irq_nosync(ourport->rx_irq); - rx_enabled(port) = 0; + ourport->rx_enabled = 0; } if (dma && dma->rx_chan) { dmaengine_pause(dma->tx_chan); @@ -546,7 +647,7 @@ static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport); static irqreturn_t s3c24xx_serial_rx_chars_dma(void *dev_id) { - unsigned int utrstat, ufstat, received; + unsigned int utrstat, received; struct s3c24xx_uart_port *ourport = dev_id; struct uart_port *port = &ourport->port; struct s3c24xx_uart_dma *dma = ourport->dma; @@ -556,7 +657,7 @@ static irqreturn_t s3c24xx_serial_rx_chars_dma(void *dev_id) struct dma_tx_state state; utrstat = rd_regl(port, S3C2410_UTRSTAT); - ufstat = rd_regl(port, S3C2410_UFSTAT); + rd_regl(port, S3C2410_UFSTAT); spin_lock_irqsave(&port->lock, flags); @@ -618,9 +719,9 @@ static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport) if (port->flags & UPF_CONS_FLOW) { int txe = s3c24xx_serial_txempty_nofifo(port); - if (rx_enabled(port)) { + if (ourport->rx_enabled) { if (!txe) { - rx_enabled(port) = 0; + ourport->rx_enabled = 0; continue; } } else { @@ -628,7 +729,7 @@ static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport) ufcon = rd_regl(port, S3C2410_UFCON); ufcon |= S3C2410_UFCON_RESETRX; wr_regl(port, S3C2410_UFCON, ufcon); - rx_enabled(port) = 1; + ourport->rx_enabled = 1; return; } continue; @@ -641,12 +742,13 @@ static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport) port->icount.rx++; if (unlikely(uerstat & S3C2410_UERSTAT_ANY)) { - dbg("rxerr: port ch=0x%02x, rxs=0x%08x\n", - ch, uerstat); + dev_dbg(port->dev, + "rxerr: port ch=0x%02x, rxs=0x%08x\n", + ch, uerstat); /* check for break */ if (uerstat & S3C2410_UERSTAT_BREAK) { - dbg("break!\n"); + dev_dbg(port->dev, "break!\n"); port->icount.brk++; if (uart_handle_break(port)) continue; /* Ignore character */ @@ -732,7 +834,7 @@ static irqreturn_t s3c24xx_serial_tx_chars(int irq, void *id) /* if there isn't anything more to transmit, or the uart is now * stopped, disable the uart and exit - */ + */ if (uart_circ_empty(xmit) || uart_tx_stopped(port)) { s3c24xx_serial_stop_tx(port); @@ -978,7 +1080,7 @@ static void s3c24xx_serial_shutdown(struct uart_port *port) if (ourport->tx_claimed) { if (!s3c24xx_serial_has_interrupt_mask(port)) free_irq(ourport->tx_irq, ourport); - tx_enabled(port) = 0; + ourport->tx_enabled = 0; ourport->tx_claimed = 0; ourport->tx_mode = 0; } @@ -987,7 +1089,7 @@ static void s3c24xx_serial_shutdown(struct uart_port *port) if (!s3c24xx_serial_has_interrupt_mask(port)) free_irq(ourport->rx_irq, ourport); ourport->rx_claimed = 0; - rx_enabled(port) = 0; + ourport->rx_enabled = 0; } /* Clear pending interrupts and mask all interrupts */ @@ -1009,10 +1111,7 @@ static int s3c24xx_serial_startup(struct uart_port *port) struct s3c24xx_uart_port *ourport = to_ourport(port); int ret; - dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n", - port, (unsigned long long)port->mapbase, port->membase); - - rx_enabled(port) = 1; + ourport->rx_enabled = 1; ret = request_irq(ourport->rx_irq, s3c24xx_serial_rx_chars, 0, s3c24xx_serial_portname(port), ourport); @@ -1024,9 +1123,9 @@ static int s3c24xx_serial_startup(struct uart_port *port) ourport->rx_claimed = 1; - dbg("requesting tx irq...\n"); + dev_dbg(port->dev, "requesting tx irq...\n"); - tx_enabled(port) = 1; + ourport->tx_enabled = 1; ret = request_irq(ourport->tx_irq, s3c24xx_serial_tx_chars, 0, s3c24xx_serial_portname(port), ourport); @@ -1038,10 +1137,9 @@ static int s3c24xx_serial_startup(struct uart_port *port) ourport->tx_claimed = 1; - dbg("s3c24xx_serial_startup ok\n"); - /* the port reset code should have done the correct - * register setup for the port controls */ + * register setup for the port controls + */ return ret; @@ -1057,9 +1155,6 @@ static int s3c64xx_serial_startup(struct uart_port *port) unsigned int ufcon; int ret; - dbg("s3c64xx_serial_startup: port=%p (%08llx,%p)\n", - port, (unsigned long long)port->mapbase, port->membase); - wr_regl(port, S3C64XX_UINTM, 0xf); if (ourport->dma) { ret = s3c24xx_serial_request_dma(ourport); @@ -1077,9 +1172,9 @@ static int s3c64xx_serial_startup(struct uart_port *port) } /* For compatibility with s3c24xx Soc's */ - rx_enabled(port) = 1; + ourport->rx_enabled = 1; ourport->rx_claimed = 1; - tx_enabled(port) = 0; + ourport->tx_enabled = 0; ourport->tx_claimed = 1; spin_lock_irqsave(&port->lock, flags); @@ -1097,7 +1192,6 @@ static int s3c64xx_serial_startup(struct uart_port *port) /* Enable Rx Interrupt */ s3c24xx_clear_bit(port, S3C64XX_UINTM_RXD, S3C64XX_UINTM); - dbg("s3c64xx_serial_startup ok\n"); return ret; } @@ -1145,7 +1239,7 @@ static void s3c24xx_serial_pm(struct uart_port *port, unsigned int level, * baud clocks (and the resultant actual baud rates) and then tries to * pick the closest one and select that. * -*/ + */ #define MAX_CLK_NAME_LENGTH 15 @@ -1315,29 +1409,30 @@ static void s3c24xx_serial_set_termios(struct uart_port *port, if (cfg->has_fracval) { udivslot = (div & 15); - dbg("fracval = %04x\n", udivslot); + dev_dbg(port->dev, "fracval = %04x\n", udivslot); } else { udivslot = udivslot_table[div & 15]; - dbg("udivslot = %04x (div %d)\n", udivslot, div & 15); + dev_dbg(port->dev, "udivslot = %04x (div %d)\n", + udivslot, div & 15); } } switch (termios->c_cflag & CSIZE) { case CS5: - dbg("config: 5bits/char\n"); + dev_dbg(port->dev, "config: 5bits/char\n"); ulcon = S3C2410_LCON_CS5; break; case CS6: - dbg("config: 6bits/char\n"); + dev_dbg(port->dev, "config: 6bits/char\n"); ulcon = S3C2410_LCON_CS6; break; case CS7: - dbg("config: 7bits/char\n"); + dev_dbg(port->dev, "config: 7bits/char\n"); ulcon = S3C2410_LCON_CS7; break; case CS8: default: - dbg("config: 8bits/char\n"); + dev_dbg(port->dev, "config: 8bits/char\n"); ulcon = S3C2410_LCON_CS8; break; } @@ -1359,8 +1454,9 @@ static void s3c24xx_serial_set_termios(struct uart_port *port, spin_lock_irqsave(&port->lock, flags); - dbg("setting ulcon to %08x, brddiv to %d, udivslot %08x\n", - ulcon, quot, udivslot); + dev_dbg(port->dev, + "setting ulcon to %08x, brddiv to %d, udivslot %08x\n", + ulcon, quot, udivslot); wr_regl(port, S3C2410_ULCON, ulcon); wr_regl(port, S3C2410_UBRDIV, quot); @@ -1381,10 +1477,11 @@ static void s3c24xx_serial_set_termios(struct uart_port *port, if (ourport->info->has_divslot) wr_regl(port, S3C2443_DIVSLOT, udivslot); - dbg("uart: ulcon = 0x%08x, ucon = 0x%08x, ufcon = 0x%08x\n", - rd_regl(port, S3C2410_ULCON), - rd_regl(port, S3C2410_UCON), - rd_regl(port, S3C2410_UFCON)); + dev_dbg(port->dev, + "uart: ulcon = 0x%08x, ucon = 0x%08x, ufcon = 0x%08x\n", + rd_regl(port, S3C2410_ULCON), + rd_regl(port, S3C2410_UCON), + rd_regl(port, S3C2410_UFCON)); /* * Update the per-port timeout. @@ -1442,6 +1539,7 @@ static void s3c24xx_serial_release_port(struct uart_port *port) static int s3c24xx_serial_request_port(struct uart_port *port) { const char *name = s3c24xx_serial_portname(port); + return request_mem_region(port->mapbase, MAP_SIZE, name) ? 0 : -EBUSY; } @@ -1583,7 +1681,7 @@ s3c24xx_serial_ports[CONFIG_SERIAL_SAMSUNG_UARTS] = { /* s3c24xx_serial_resetport * * reset the fifos and other the settings. -*/ + */ static void s3c24xx_serial_resetport(struct uart_port *port, struct s3c2410_uartcfg *cfg) @@ -1637,7 +1735,8 @@ static int s3c24xx_serial_cpufreq_transition(struct notifier_block *nb, if (val == CPUFREQ_PRECHANGE) { /* we should really shut the port down whilst the - * frequency change is in progress. */ + * frequency change is in progress. + */ } else if (val == CPUFREQ_POSTCHANGE) { struct ktermios *termios; @@ -1743,8 +1842,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport, struct resource *res; int ret; - dbg("s3c24xx_serial_init_port: port=%p, platdev=%p\n", port, platdev); - if (platdev == NULL) return -ENODEV; @@ -1761,7 +1858,7 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport, port->uartclk = 1; if (cfg->uart_flags & UPF_CONS_FLOW) { - dbg("s3c24xx_serial_init_port: enabling flow control\n"); + dev_dbg(port->dev, "enabling flow control\n"); port->flags |= UPF_CONS_FLOW; } @@ -1773,7 +1870,7 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport, return -EINVAL; } - dbg("resource %pR)\n", res); + dev_dbg(port->dev, "resource %pR)\n", res); port->membase = devm_ioremap(port->dev, res->start, resource_size(res)); if (!port->membase) { @@ -1835,9 +1932,9 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport, wr_regl(port, S3C64XX_UINTSP, 0xf); } - dbg("port: map=%pa, mem=%p, irq=%d (%d,%d), clock=%u\n", - &port->mapbase, port->membase, port->irq, - ourport->rx_irq, ourport->tx_irq, port->uartclk); + dev_dbg(port->dev, "port: map=%pa, mem=%p, irq=%d (%d,%d), clock=%u\n", + &port->mapbase, port->membase, port->irq, + ourport->rx_irq, ourport->tx_irq, port->uartclk); /* reset the fifos (and setup the uart) */ s3c24xx_serial_resetport(port, cfg); @@ -1851,7 +1948,10 @@ err: /* Device driver serial port probe */ +#ifdef CONFIG_OF static const struct of_device_id s3c24xx_uart_dt_match[]; +#endif + static int probe_index; static inline struct s3c24xx_serial_drv_data *s3c24xx_get_driver_data( @@ -1860,6 +1960,7 @@ static inline struct s3c24xx_serial_drv_data *s3c24xx_get_driver_data( #ifdef CONFIG_OF if (pdev->dev.of_node) { const struct of_device_id *match; + match = of_match_node(s3c24xx_uart_dt_match, pdev->dev.of_node); return (struct s3c24xx_serial_drv_data *)match->data; } @@ -1881,8 +1982,6 @@ static int s3c24xx_serial_probe(struct platform_device *pdev) index = ret; } - dbg("s3c24xx_serial_probe(%p) %d\n", pdev, index); - if (index >= ARRAY_SIZE(s3c24xx_serial_ports)) { dev_err(&pdev->dev, "serial%d out of range\n", index); return -EINVAL; @@ -1909,6 +2008,7 @@ static int s3c24xx_serial_probe(struct platform_device *pdev) ourport->port.fifosize = ourport->drv_data->fifosize[index]; else if (ourport->info->fifosize) ourport->port.fifosize = ourport->info->fifosize; + ourport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SAMSUNG_CONSOLE); /* * DMA transfers must be aligned at least to cache line size, @@ -1917,7 +2017,7 @@ static int s3c24xx_serial_probe(struct platform_device *pdev) ourport->min_dma_size = max_t(int, ourport->port.fifosize, dma_get_cache_alignment()); - dbg("%s: initialising port %p...\n", __func__, ourport); + dev_dbg(&pdev->dev, "%s: initialising port %p...\n", __func__, ourport); ret = s3c24xx_serial_init_port(ourport, pdev); if (ret < 0) @@ -1931,7 +2031,7 @@ static int s3c24xx_serial_probe(struct platform_device *pdev) } } - dbg("%s: adding port\n", __func__); + dev_dbg(&pdev->dev, "%s: adding port\n", __func__); uart_add_one_port(&s3c24xx_uart_drv, &ourport->port); platform_set_drvdata(pdev, &ourport->port); @@ -2008,9 +2108,10 @@ static int s3c24xx_serial_resume_noirq(struct device *dev) /* restore IRQ mask */ if (s3c24xx_serial_has_interrupt_mask(port)) { unsigned int uintm = 0xf; - if (tx_enabled(port)) + + if (ourport->tx_enabled) uintm &= ~S3C64XX_UINTM_TXD_MSK; - if (rx_enabled(port)) + if (ourport->rx_enabled) uintm &= ~S3C64XX_UINTM_RXD_MSK; clk_prepare_enable(ourport->clk); if (!IS_ERR(ourport->baudclk)) @@ -2143,10 +2244,6 @@ s3c24xx_serial_get_options(struct uart_port *port, int *baud, ucon = rd_regl(port, S3C2410_UCON); ubrdiv = rd_regl(port, S3C2410_UBRDIV); - dbg("s3c24xx_serial_get_options: port=%p\n" - "registers: ulcon=%08x, ucon=%08x, ubdriv=%08x\n", - port, ulcon, ucon, ubrdiv); - if (s3c24xx_port_configured(ucon)) { switch (ulcon & S3C2410_LCON_CSMASK) { case S3C2410_LCON_CS5: @@ -2190,7 +2287,7 @@ s3c24xx_serial_get_options(struct uart_port *port, int *baud, rate = 1; *baud = rate / (16 * (ubrdiv + 1)); - dbg("calculated baud %d\n", *baud); + dev_dbg(port->dev, "calculated baud %d\n", *baud); } } @@ -2204,9 +2301,6 @@ s3c24xx_serial_console_setup(struct console *co, char *options) int parity = 'n'; int flow = 'n'; - dbg("s3c24xx_serial_console_setup: co=%p (%d), %s\n", - co, co->index, options); - /* is this a valid port */ if (co->index == -1 || co->index >= CONFIG_SERIAL_SAMSUNG_UARTS) @@ -2221,8 +2315,6 @@ s3c24xx_serial_console_setup(struct console *co, char *options) cons_uart = port; - dbg("s3c24xx_serial_console_setup: port=%p (%d)\n", port, co->index); - /* * Check whether an invalid uart number has been specified, and * if so, search for the first available port that does have @@ -2233,7 +2325,7 @@ s3c24xx_serial_console_setup(struct console *co, char *options) else s3c24xx_serial_get_options(port, &baud, &parity, &bits); - dbg("s3c24xx_serial_console_setup: baud %d\n", baud); + dev_dbg(port->dev, "baud %d\n", baud); return uart_set_options(port, co, baud, parity, bits, flow); } @@ -2523,7 +2615,8 @@ static void samsung_early_putc(struct uart_port *port, int c) writeb(c, port->membase + S3C2410_UTXH); } -static void samsung_early_write(struct console *con, const char *s, unsigned n) +static void samsung_early_write(struct console *con, const char *s, + unsigned int n) { struct earlycon_device *dev = con->data; diff --git a/drivers/tty/serial/sb1250-duart.c b/drivers/tty/serial/sb1250-duart.c index 329aced26bd8..cb8185bffe42 100644 --- a/drivers/tty/serial/sb1250-duart.c +++ b/drivers/tty/serial/sb1250-duart.c @@ -15,10 +15,6 @@ * "BCM1250/BCM1125/BCM1125H User Manual", Broadcom Corporation */ -#if defined(CONFIG_SERIAL_SB1250_DUART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/compiler.h> #include <linux/console.h> #include <linux/delay.h> @@ -813,6 +809,7 @@ static void __init sbd_probe_duarts(void) uport->ops = &sbd_ops; uport->line = line; uport->mapbase = SBD_CHANREGS(line); + uport->has_sysrq = IS_ENABLED(CONFIG_SERIAL_SB1250_DUART_CONSOLE); } } } diff --git a/drivers/tty/serial/sccnxp.c b/drivers/tty/serial/sccnxp.c index d2b77aae42ae..10cc16a71f26 100644 --- a/drivers/tty/serial/sccnxp.c +++ b/drivers/tty/serial/sccnxp.c @@ -7,10 +7,6 @@ * Based on sc26xx.c, by Thomas Bogendörfer (tsbogend@alpha.franken.de) */ -#if defined(CONFIG_SERIAL_SCCNXP_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/clk.h> #include <linux/delay.h> #include <linux/err.h> @@ -1000,6 +996,7 @@ static int sccnxp_probe(struct platform_device *pdev) s->port[i].regshift = s->pdata.reg_shift; s->port[i].uartclk = uartclk; s->port[i].ops = &sccnxp_ops; + s->port[i].has_sysrq = IS_ENABLED(CONFIG_SERIAL_SCCNXP_CONSOLE); uart_add_one_port(&s->uart, &s->port[i]); /* Set direction to input */ if (s->chip->flags & SCCNXP_HAVE_IO) diff --git a/drivers/tty/serial/serial_txx9.c b/drivers/tty/serial/serial_txx9.c index d22ccb32aa9b..b4d89e31730e 100644 --- a/drivers/tty/serial/serial_txx9.c +++ b/drivers/tty/serial/serial_txx9.c @@ -12,10 +12,6 @@ * Serial driver for TX3927/TX4927/TX4925/TX4938 internal SIO controller */ -#if defined(CONFIG_SERIAL_TXX9_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/module.h> #include <linux/ioport.h> #include <linux/init.h> @@ -1095,6 +1091,7 @@ static int serial_txx9_probe(struct platform_device *dev) port.flags = p->flags; port.mapbase = p->mapbase; port.dev = &dev->dev; + port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_TXX9_CONSOLE); ret = serial_txx9_register_port(&port); if (ret < 0) { dev_err(&dev->dev, "unable to register port at index %d " diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 58bf9d496ba5..9b4ff872e297 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -15,10 +15,6 @@ * Modified to support SH7300 SCIF. Takashi Kusuda (Jun 2003). * Removed SH7300 support (Jul 2007). */ -#if defined(CONFIG_SERIAL_SH_SCI_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #undef DEBUG #include <linux/clk.h> @@ -2887,6 +2883,7 @@ static int sci_init_single(struct platform_device *dev, port->ops = &sci_uart_ops; port->iotype = UPIO_MEM; port->line = index; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_SH_SCI_CONSOLE); res = platform_get_resource(dev, IORESOURCE_MEM, 0); if (res == NULL) @@ -3015,12 +3012,9 @@ static void serial_console_write(struct console *co, const char *s, unsigned long flags; int locked = 1; -#if defined(SUPPORT_SYSRQ) if (port->sysrq) locked = 0; - else -#endif - if (oops_in_progress) + else if (oops_in_progress) locked = spin_trylock_irqsave(&port->lock, flags); else spin_lock_irqsave(&port->lock, flags); diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c index f60a59d9bf27..3d3c70634589 100644 --- a/drivers/tty/serial/sprd_serial.c +++ b/drivers/tty/serial/sprd_serial.c @@ -3,10 +3,6 @@ * Copyright (C) 2012-2015 Spreadtrum Communications Inc. */ -#if defined(CONFIG_SERIAL_SPRD_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/clk.h> #include <linux/console.h> #include <linux/delay.h> @@ -1230,6 +1226,7 @@ static int sprd_probe(struct platform_device *pdev) up->fifosize = SPRD_FIFO_SIZE; up->ops = &serial_sprd_ops; up->flags = UPF_BOOT_AUTOCONF; + up->has_sysrq = IS_ENABLED(CONFIG_SERIAL_SPRD_CONSOLE); ret = sprd_clk_init(up); if (ret) diff --git a/drivers/tty/serial/st-asc.c b/drivers/tty/serial/st-asc.c index 7971997cdead..fb6bbb5e2234 100644 --- a/drivers/tty/serial/st-asc.c +++ b/drivers/tty/serial/st-asc.c @@ -5,10 +5,6 @@ * Copyright (C) 2003-2013 STMicroelectronics (R&D) Limited */ -#if defined(CONFIG_SERIAL_ST_ASC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/module.h> #include <linux/serial.h> #include <linux/console.h> @@ -730,6 +726,7 @@ static int asc_init_port(struct asc_port *ascport, port->fifosize = ASC_FIFO_SIZE; port->dev = &pdev->dev; port->irq = platform_get_irq(pdev, 0); + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ST_ASC_CONSOLE); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); port->membase = devm_ioremap_resource(&pdev->dev, res); diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index 2f72514d63ed..5e93e8d40f59 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -8,10 +8,6 @@ * Inspired by st-asc.c from STMicroelectronics (c) */ -#if defined(CONFIG_SERIAL_STM32_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/clk.h> #include <linux/console.h> #include <linux/delay.h> @@ -926,6 +922,7 @@ static int stm32_init_port(struct stm32_port *stm32port, port->ops = &stm32_uart_ops; port->dev = &pdev->dev; port->fifosize = stm32port->info->cfg.fifosize; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_STM32_CONSOLE); ret = platform_get_irq(pdev, 0); if (ret <= 0) diff --git a/drivers/tty/serial/sunhv.c b/drivers/tty/serial/sunhv.c index f8503f8fc44e..eafada8fb6fa 100644 --- a/drivers/tty/serial/sunhv.c +++ b/drivers/tty/serial/sunhv.c @@ -25,10 +25,6 @@ #include <asm/irq.h> #include <asm/setup.h> -#if defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/serial_core.h> #include <linux/sunserialcore.h> @@ -552,6 +548,7 @@ static int hv_probe(struct platform_device *op) sunhv_port = port; + port->has_sysrq = 1; port->line = 0; port->ops = &sunhv_pops; port->type = PORT_SUNHV; diff --git a/drivers/tty/serial/sunsab.c b/drivers/tty/serial/sunsab.c index 72131b5e132e..1eb703c980e0 100644 --- a/drivers/tty/serial/sunsab.c +++ b/drivers/tty/serial/sunsab.c @@ -40,10 +40,6 @@ #include <asm/prom.h> #include <asm/setup.h> -#if defined(CONFIG_SERIAL_SUNSAB_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/serial_core.h> #include <linux/sunserialcore.h> @@ -985,6 +981,7 @@ static int sunsab_init_one(struct uart_sunsab_port *up, up->port.fifosize = SAB82532_XMIT_FIFO_SIZE; up->port.iotype = UPIO_MEM; + up->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SUNSAB_CONSOLE); writeb(SAB82532_IPC_IC_ACT_LOW, &up->regs->w.ipc); diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c index 4db6aaa330b2..8ce9a7a256e5 100644 --- a/drivers/tty/serial/sunsu.c +++ b/drivers/tty/serial/sunsu.c @@ -44,10 +44,6 @@ #include <asm/prom.h> #include <asm/setup.h> -#if defined(CONFIG_SERIAL_SUNSU_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/serial_core.h> #include <linux/sunserialcore.h> @@ -1475,6 +1471,7 @@ static int su_probe(struct platform_device *op) up->port.type = PORT_UNKNOWN; up->port.uartclk = (SU_BASE_BAUD * 16); + up->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SUNSU_CONSOLE); err = 0; if (up->su_type == SU_PORT_KBD || up->su_type == SU_PORT_MS) { diff --git a/drivers/tty/serial/sunzilog.c b/drivers/tty/serial/sunzilog.c index bc7af8b08a72..103ab8c556e7 100644 --- a/drivers/tty/serial/sunzilog.c +++ b/drivers/tty/serial/sunzilog.c @@ -40,10 +40,6 @@ #include <asm/prom.h> #include <asm/setup.h> -#if defined(CONFIG_SERIAL_SUNZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/serial_core.h> #include <linux/sunserialcore.h> @@ -1444,6 +1440,7 @@ static int zs_probe(struct platform_device *op) up[0].port.line = (inst * 2) + 0; up[0].port.dev = &op->dev; up[0].flags |= SUNZILOG_FLAG_IS_CHANNEL_A; + up[0].port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SUNZILOG_CONSOLE); if (keyboard_mouse) up[0].flags |= SUNZILOG_FLAG_CONS_KEYB; sunzilog_init_hw(&up[0]); @@ -1461,6 +1458,7 @@ static int zs_probe(struct platform_device *op) up[1].port.line = (inst * 2) + 1; up[1].port.dev = &op->dev; up[1].flags |= 0; + up[1].port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_SUNZILOG_CONSOLE); if (keyboard_mouse) up[1].flags |= SUNZILOG_FLAG_CONS_MOUSE; sunzilog_init_hw(&up[1]); diff --git a/drivers/tty/serial/ucc_uart.c b/drivers/tty/serial/ucc_uart.c index a0555ae2b1ef..ff7784047156 100644 --- a/drivers/tty/serial/ucc_uart.c +++ b/drivers/tty/serial/ucc_uart.c @@ -551,9 +551,7 @@ handle_error: /* Overrun does not affect the current character ! */ if (status & BD_SC_OV) tty_insert_flip_char(tport, 0, TTY_OVERRUN); -#ifdef SUPPORT_SYSRQ port->sysrq = 0; -#endif goto error_return; } diff --git a/drivers/tty/serial/vr41xx_siu.c b/drivers/tty/serial/vr41xx_siu.c index 6d106e33f842..eeb4b6568776 100644 --- a/drivers/tty/serial/vr41xx_siu.c +++ b/drivers/tty/serial/vr41xx_siu.c @@ -7,10 +7,6 @@ * Based on drivers/serial/8250.c, by Russell King. */ -#if defined(CONFIG_SERIAL_VR41XX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/console.h> #include <linux/errno.h> #include <linux/init.h> @@ -869,6 +865,7 @@ static int siu_probe(struct platform_device *dev) port = &siu_uart_ports[i]; port->ops = &siu_uart_ops; port->dev = &dev->dev; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_VR41XX_CONSOLE); retval = uart_add_one_port(&siu_uart_driver, port); if (retval < 0) { diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c index 3d58e9b34553..764e992438b2 100644 --- a/drivers/tty/serial/vt8500_serial.c +++ b/drivers/tty/serial/vt8500_serial.c @@ -7,10 +7,6 @@ * Author: Robert Love <rlove@google.com> */ -#if defined(CONFIG_SERIAL_VT8500_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -# define SUPPORT_SYSRQ -#endif - #include <linux/hrtimer.h> #include <linux/delay.h> #include <linux/io.h> @@ -703,6 +699,7 @@ static int vt8500_serial_probe(struct platform_device *pdev) vt8500_port->uart.line = port; vt8500_port->uart.dev = &pdev->dev; vt8500_port->uart.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; + vt8500_port->uart.has_sysrq = IS_ENABLED(CONFIG_SERIAL_VT8500_CONSOLE); /* Serial core uses the magic "16" everywhere - adjust for it */ vt8500_port->uart.uartclk = 16 * clk_get_rate(vt8500_port->clk) / diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c index 4e55bc327a54..2b5606469bed 100644 --- a/drivers/tty/serial/xilinx_uartps.c +++ b/drivers/tty/serial/xilinx_uartps.c @@ -9,10 +9,6 @@ * in the code. */ -#if defined(CONFIG_SERIAL_XILINX_PS_UART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/platform_device.h> #include <linux/serial.h> #include <linux/console.h> @@ -1634,6 +1630,7 @@ static int cdns_uart_probe(struct platform_device *pdev) port->flags = UPF_BOOT_AUTOCONF; port->ops = &cdns_uart_ops; port->fifosize = CDNS_UART_FIFO_SIZE; + port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_XILINX_PS_UART_CONSOLE); /* * Register the port. diff --git a/drivers/tty/serial/zs.c b/drivers/tty/serial/zs.c index b03d3e458ea2..1467952da3f6 100644 --- a/drivers/tty/serial/zs.c +++ b/drivers/tty/serial/zs.c @@ -44,10 +44,6 @@ * complicated and prevents the use of some automatic modes of operation. */ -#if defined(CONFIG_SERIAL_ZS_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) -#define SUPPORT_SYSRQ -#endif - #include <linux/bug.h> #include <linux/console.h> #include <linux/delay.h> @@ -1106,6 +1102,7 @@ static int __init zs_probe_sccs(void) zport->scc = &zs_sccs[chip]; zport->clk_mode = 16; + uport->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ZS_CONSOLE); uport->irq = zs_parms.irq[chip]; uport->uartclk = ZS_CLOCK; uport->fifosize = 1; diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c index 573b2055173c..1d4f317a0e42 100644 --- a/drivers/tty/sysrq.c +++ b/drivers/tty/sysrq.c @@ -967,8 +967,6 @@ static struct input_handler sysrq_handler = { .id_table = sysrq_ids, }; -static bool sysrq_handler_registered; - static inline void sysrq_register_handler(void) { int error; @@ -978,16 +976,11 @@ static inline void sysrq_register_handler(void) error = input_register_handler(&sysrq_handler); if (error) pr_err("Failed to register input handler, error %d", error); - else - sysrq_handler_registered = true; } static inline void sysrq_unregister_handler(void) { - if (sysrq_handler_registered) { - input_unregister_handler(&sysrq_handler); - sysrq_handler_registered = false; - } + input_unregister_handler(&sysrq_handler); } static int sysrq_reset_seq_param_set(const char *buffer, diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index d9f54c7d94f2..a1453fe10862 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -1893,7 +1893,7 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp, struct tty_struct *tty_kopen(dev_t device) { struct tty_struct *tty; - struct tty_driver *driver = NULL; + struct tty_driver *driver; int index = -1; mutex_lock(&tty_mutex); diff --git a/drivers/tty/vt/.gitignore b/drivers/tty/vt/.gitignore index 9b38b85f9d9a..3ecf42234d89 100644 --- a/drivers/tty/vt/.gitignore +++ b/drivers/tty/vt/.gitignore @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 +conmakehash consolemap_deftbl.c defkeymap.c diff --git a/drivers/tty/vt/Makefile b/drivers/tty/vt/Makefile index edbbe0ccdb83..329ca336b8ee 100644 --- a/drivers/tty/vt/Makefile +++ b/drivers/tty/vt/Makefile @@ -12,10 +12,12 @@ obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o # Files generated that shall be removed upon make clean clean-files := consolemap_deftbl.c defkeymap.c +hostprogs-y += conmakehash + quiet_cmd_conmk = CONMK $@ - cmd_conmk = scripts/conmakehash $< > $@ + cmd_conmk = $(obj)/conmakehash $< > $@ -$(obj)/consolemap_deftbl.c: $(src)/$(FONTMAPFILE) +$(obj)/consolemap_deftbl.c: $(src)/$(FONTMAPFILE) $(obj)/conmakehash $(call cmd,conmk) $(obj)/defkeymap.o: $(obj)/defkeymap.c diff --git a/drivers/tty/vt/conmakehash.c b/drivers/tty/vt/conmakehash.c new file mode 100644 index 000000000000..cddd789fe46e --- /dev/null +++ b/drivers/tty/vt/conmakehash.c @@ -0,0 +1,290 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * conmakehash.c + * + * Create arrays for initializing the kernel folded tables (using a hash + * table turned out to be to limiting...) Unfortunately we can't simply + * preinitialize the tables at compile time since kfree() cannot accept + * memory not allocated by kmalloc(), and doing our own memory management + * just for this seems like massive overkill. + * + * Copyright (C) 1995-1997 H. Peter Anvin + */ + +#include <stdio.h> +#include <stdlib.h> +#include <sysexits.h> +#include <string.h> +#include <ctype.h> + +#define MAX_FONTLEN 256 + +typedef unsigned short unicode; + +static void usage(char *argv0) +{ + fprintf(stderr, "Usage: \n" + " %s chartable [hashsize] [hashstep] [maxhashlevel]\n", argv0); + exit(EX_USAGE); +} + +static int getunicode(char **p0) +{ + char *p = *p0; + + while (*p == ' ' || *p == '\t') + p++; + if (*p != 'U' || p[1] != '+' || + !isxdigit(p[2]) || !isxdigit(p[3]) || !isxdigit(p[4]) || + !isxdigit(p[5]) || isxdigit(p[6])) + return -1; + *p0 = p+6; + return strtol(p+2,0,16); +} + +unicode unitable[MAX_FONTLEN][255]; + /* Massive overkill, but who cares? */ +int unicount[MAX_FONTLEN]; + +static void addpair(int fp, int un) +{ + int i; + + if ( un <= 0xfffe ) + { + /* Check it isn't a duplicate */ + + for ( i = 0 ; i < unicount[fp] ; i++ ) + if ( unitable[fp][i] == un ) + return; + + /* Add to list */ + + if ( unicount[fp] > 254 ) + { + fprintf(stderr, "ERROR: Only 255 unicodes/glyph permitted!\n"); + exit(EX_DATAERR); + } + + unitable[fp][unicount[fp]] = un; + unicount[fp]++; + } + + /* otherwise: ignore */ +} + +int main(int argc, char *argv[]) +{ + FILE *ctbl; + char *tblname; + char buffer[65536]; + int fontlen; + int i, nuni, nent; + int fp0, fp1, un0, un1; + char *p, *p1; + + if ( argc < 2 || argc > 5 ) + usage(argv[0]); + + if ( !strcmp(argv[1],"-") ) + { + ctbl = stdin; + tblname = "stdin"; + } + else + { + ctbl = fopen(tblname = argv[1], "r"); + if ( !ctbl ) + { + perror(tblname); + exit(EX_NOINPUT); + } + } + + /* For now we assume the default font is always 256 characters. */ + fontlen = 256; + + /* Initialize table */ + + for ( i = 0 ; i < fontlen ; i++ ) + unicount[i] = 0; + + /* Now we come to the tricky part. Parse the input table. */ + + while ( fgets(buffer, sizeof(buffer), ctbl) != NULL ) + { + if ( (p = strchr(buffer, '\n')) != NULL ) + *p = '\0'; + else + fprintf(stderr, "%s: Warning: line too long\n", tblname); + + p = buffer; + +/* + * Syntax accepted: + * <fontpos> <unicode> <unicode> ... + * <range> idem + * <range> <unicode range> + * + * where <range> ::= <fontpos>-<fontpos> + * and <unicode> ::= U+<h><h><h><h> + * and <h> ::= <hexadecimal digit> + */ + + while (*p == ' ' || *p == '\t') + p++; + if (!*p || *p == '#') + continue; /* skip comment or blank line */ + + fp0 = strtol(p, &p1, 0); + if (p1 == p) + { + fprintf(stderr, "Bad input line: %s\n", buffer); + exit(EX_DATAERR); + } + p = p1; + + while (*p == ' ' || *p == '\t') + p++; + if (*p == '-') + { + p++; + fp1 = strtol(p, &p1, 0); + if (p1 == p) + { + fprintf(stderr, "Bad input line: %s\n", buffer); + exit(EX_DATAERR); + } + p = p1; + } + else + fp1 = 0; + + if ( fp0 < 0 || fp0 >= fontlen ) + { + fprintf(stderr, + "%s: Glyph number (0x%x) larger than font length\n", + tblname, fp0); + exit(EX_DATAERR); + } + if ( fp1 && (fp1 < fp0 || fp1 >= fontlen) ) + { + fprintf(stderr, + "%s: Bad end of range (0x%x)\n", + tblname, fp1); + exit(EX_DATAERR); + } + + if (fp1) + { + /* we have a range; expect the word "idem" or a Unicode range of the + same length */ + while (*p == ' ' || *p == '\t') + p++; + if (!strncmp(p, "idem", 4)) + { + for (i=fp0; i<=fp1; i++) + addpair(i,i); + p += 4; + } + else + { + un0 = getunicode(&p); + while (*p == ' ' || *p == '\t') + p++; + if (*p != '-') + { + fprintf(stderr, +"%s: Corresponding to a range of font positions, there should be a Unicode range\n", + tblname); + exit(EX_DATAERR); + } + p++; + un1 = getunicode(&p); + if (un0 < 0 || un1 < 0) + { + fprintf(stderr, +"%s: Bad Unicode range corresponding to font position range 0x%x-0x%x\n", + tblname, fp0, fp1); + exit(EX_DATAERR); + } + if (un1 - un0 != fp1 - fp0) + { + fprintf(stderr, +"%s: Unicode range U+%x-U+%x not of the same length as font position range 0x%x-0x%x\n", + tblname, un0, un1, fp0, fp1); + exit(EX_DATAERR); + } + for(i=fp0; i<=fp1; i++) + addpair(i,un0-fp0+i); + } + } + else + { + /* no range; expect a list of unicode values for a single font position */ + + while ( (un0 = getunicode(&p)) >= 0 ) + addpair(fp0, un0); + } + while (*p == ' ' || *p == '\t') + p++; + if (*p && *p != '#') + fprintf(stderr, "%s: trailing junk (%s) ignored\n", tblname, p); + } + + /* Okay, we hit EOF, now output hash table */ + + fclose(ctbl); + + + /* Compute total size of Unicode list */ + nuni = 0; + for ( i = 0 ; i < fontlen ; i++ ) + nuni += unicount[i]; + + printf("\ +/*\n\ + * Do not edit this file; it was automatically generated by\n\ + *\n\ + * conmakehash %s > [this file]\n\ + *\n\ + */\n\ +\n\ +#include <linux/types.h>\n\ +\n\ +u8 dfont_unicount[%d] = \n\ +{\n\t", argv[1], fontlen); + + for ( i = 0 ; i < fontlen ; i++ ) + { + printf("%3d", unicount[i]); + if ( i == fontlen-1 ) + printf("\n};\n"); + else if ( i % 8 == 7 ) + printf(",\n\t"); + else + printf(", "); + } + + printf("\nu16 dfont_unitable[%d] = \n{\n\t", nuni); + + fp0 = 0; + nent = 0; + for ( i = 0 ; i < nuni ; i++ ) + { + while ( nent >= unicount[fp0] ) + { + fp0++; + nent = 0; + } + printf("0x%04x", unitable[fp0][nent++]); + if ( i == nuni-1 ) + printf("\n};\n"); + else if ( i % 8 == 7 ) + printf(",\n\t"); + else + printf(", "); + } + + exit(EX_OK); +} |