diff options
Diffstat (limited to 'drivers/serial')
29 files changed, 417 insertions, 564 deletions
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index 6fda32d44c..60b0e5f1dc 100644 --- a/drivers/serial/Kconfig +++ b/drivers/serial/Kconfig @@ -31,7 +31,7 @@ config DRIVER_SERIAL_AR933X config DRIVER_SERIAL_EFI bool "EFI serial" - depends on EFI_BOOTUP + depends on EFI_PAYLOAD config DRIVER_SERIAL_IMX depends on ARCH_IMX @@ -58,7 +58,7 @@ config DRIVER_SERIAL_LINUX_CONSOLE bool "linux console driver" config DRIVER_SERIAL_EFI_STDIO - depends on EFI_BOOTUP + depends on EFI_PAYLOAD bool "EFI stdio driver" config DRIVER_SERIAL_MPC5XXX @@ -71,16 +71,6 @@ config DRIVER_SERIAL_CLPS711X default y bool "CLPS711X serial driver" -config DRIVER_SERIAL_ALTERA - depends on NIOS2 - default y - bool "Altera serial driver" - -config DRIVER_SERIAL_ALTERA_JTAG - depends on NIOS2 - default n - bool "Altera JTAG serial driver" - config DRIVER_SERIAL_NS16550 default n bool "NS16550 serial driver" @@ -107,24 +97,6 @@ config DRIVER_SERIAL_PL010 help Enable this to get support for AMBA PL010 based serial devices -config DRIVER_SERIAL_S3C_IMPROVED - bool - -config DRIVER_SERIAL_S3C - bool "Samsung S3C serial driver" - depends on ARCH_SAMSUNG - select DRIVER_SERIAL_S3C_IMPROVED if (CPU_S5PC110 || CPU_S5PV210 || CPU_S3C6410) - default y - help - Say Y here if you want to use the CONS on a Samsung S3C CPU - -config DRIVER_SERIAL_S3C_AUTOSYNC - bool "Enable auto flow" - depends on DRIVER_SERIAL_S3C - help - Say Y here if you want to use the auto flow feature of this - UART. RTS and CTS will be handled by the hardware when enabled. - config DRIVER_SERIAL_PXA bool "PXA serial driver" depends on ARCH_PXA @@ -150,6 +122,10 @@ config DRIVER_SERIAL_LPUART default y bool "LPUART serial driver" +config DRIVER_SERIAL_LPUART32 + depends on ARCH_IMX + bool "LPUART32 serial driver" + config VIRTIO_CONSOLE tristate "Virtio console" depends on VIRTIO diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile index 4b2bfb0537..4887e24ee1 100644 --- a/drivers/serial/Makefile +++ b/drivers/serial/Makefile @@ -12,10 +12,7 @@ obj-$(CONFIG_DRIVER_SERIAL_CLPS711X) += serial_clps711x.o obj-$(CONFIG_DRIVER_SERIAL_NS16550) += serial_ns16550.o obj-$(CONFIG_DRIVER_SERIAL_NS16550_PCI) += serial_ns16550_pci.o obj-$(CONFIG_DRIVER_SERIAL_PL010) += serial_pl010.o -obj-$(CONFIG_DRIVER_SERIAL_S3C) += serial_s3c.o obj-$(CONFIG_DRIVER_SERIAL_STM32) += serial_stm32.o -obj-$(CONFIG_DRIVER_SERIAL_ALTERA) += serial_altera.o -obj-$(CONFIG_DRIVER_SERIAL_ALTERA_JTAG) += serial_altera_jtag.o obj-$(CONFIG_DRIVER_SERIAL_PXA) += serial_pxa.o obj-$(CONFIG_DRIVER_SERIAL_OMAP4_USBBOOT) += serial_omap4_usbboot.o obj-$(CONFIG_DRIVER_SERIAL_AUART) += serial_auart.o @@ -23,6 +20,7 @@ obj-$(CONFIG_DRIVER_SERIAL_CADENCE) += serial_cadence.o obj-$(CONFIG_DRIVER_SERIAL_EFI_STDIO) += efi-stdio.o obj-$(CONFIG_DRIVER_SERIAL_DIGIC) += serial_digic.o obj-$(CONFIG_DRIVER_SERIAL_LPUART) += serial_lpuart.o +obj-$(CONFIG_DRIVER_SERIAL_LPUART32) += serial_lpuart32.o obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o obj-$(CONFIG_SERIAL_SIFIVE) += serial_sifive.o obj-$(CONFIG_SERIAL_SBI) += serial_sbi.o diff --git a/drivers/serial/arm_dcc.c b/drivers/serial/arm_dcc.c index db0ee7fe09..1e2b4e425c 100644 --- a/drivers/serial/arm_dcc.c +++ b/drivers/serial/arm_dcc.c @@ -108,7 +108,7 @@ static int arm_dcc_tstc(struct console_device *cdev) static struct console_device arm_dcc_dev; -static int arm_dcc_probe(struct device_d *dev) +static int arm_dcc_probe(struct device *dev) { struct console_device *cdev; @@ -125,13 +125,13 @@ static int arm_dcc_probe(struct device_d *dev) return 0; } -static struct driver_d arm_dcc_driver = { +static struct driver arm_dcc_driver = { .name = "arm_dcc", .probe = arm_dcc_probe, }; console_platform_driver(arm_dcc_driver); -static struct device_d arm_dcc_device = { +static struct device arm_dcc_device = { .id = DEVICE_ID_DYNAMIC, .name = "arm_dcc", }; diff --git a/drivers/serial/atmel.c b/drivers/serial/atmel.c index 9e20754998..b957b75284 100644 --- a/drivers/serial/atmel.c +++ b/drivers/serial/atmel.c @@ -384,7 +384,7 @@ static int atmel_serial_set_mode(struct console_device *cdev, enum console_mode */ static int atmel_serial_init_port(struct console_device *cdev) { - struct device_d *dev = cdev->dev; + struct device *dev = cdev->dev; struct atmel_uart_port *uart = to_atmel_uart_port(cdev); uart->base = dev_request_mem_region_err_null(dev, 0); @@ -412,7 +412,7 @@ static int atmel_serial_init_port(struct console_device *cdev) return 0; } -static int atmel_serial_probe(struct device_d *dev) +static int atmel_serial_probe(struct device *dev) { struct atmel_uart_port *uart; struct console_device *cdev; @@ -447,8 +447,9 @@ static const struct of_device_id __maybe_unused atmel_serial_dt_ids[] = { { .compatible = "atmel,at91sam9260-usart" }, { /* sentinel */ } }; +MODULE_DEVICE_TABLE(of, atmel_serial_dt_ids); -static struct driver_d atmel_serial_driver = { +static struct driver atmel_serial_driver = { .name = "atmel_usart", .probe = atmel_serial_probe, .of_compatible = DRV_OF_COMPAT(atmel_serial_dt_ids), diff --git a/drivers/serial/efi-stdio.c b/drivers/serial/efi-stdio.c index 2e2aa57227..92133f8378 100644 --- a/drivers/serial/efi-stdio.c +++ b/drivers/serial/efi-stdio.c @@ -20,7 +20,7 @@ struct efi_console_priv { struct efi_simple_text_output_protocol *out; - struct efi_simple_input_interface *in; + struct efi_simple_text_input_protocol *in; struct efi_simple_text_input_ex_protocol *inex; struct console_device cdev; u16 efi_console_buffer[CONFIG_CBSIZE + 1]; @@ -79,17 +79,23 @@ static int xlate_keypress(struct efi_input_key *k) return k->unicode_char & 0xff; } +static void efi_wait_single_event(struct efi_event *event) +{ + size_t index; + + /* wait until key is pressed */ + BS->wait_for_event(1, &event, &index); +} + static int efi_read_key(struct efi_console_priv *priv, bool wait) { - unsigned long index; efi_status_t efiret; struct efi_key_data kd; - /* wait until key is pressed */ - if (wait) - BS->wait_for_event(1, priv->in->wait_for_key, &index); - if (priv->inex) { + if (wait) + efi_wait_single_event(priv->inex->wait_for_key_ex); + efiret = priv->inex->read_key_stroke_ex(priv->inex, &kd); if (efiret == EFI_NOT_READY) @@ -118,6 +124,9 @@ static int efi_read_key(struct efi_console_priv *priv, bool wait) } } + if (wait) + efi_wait_single_event(priv->in->wait_for_key); + efiret = priv->in->read_key_stroke(priv->in, &kd.key); if (EFI_ERROR(efiret)) @@ -412,7 +421,7 @@ static void efi_set_mode(struct efi_console_priv *priv) priv->mode_names, n, priv); } -static int efi_console_probe(struct device_d *dev) +static int efi_console_probe(struct device *dev) { efi_guid_t inex_guid = EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID; struct efi_simple_text_input_ex_protocol *inex; @@ -430,7 +439,7 @@ static int efi_console_probe(struct device_d *dev) if (!priv->inputbuffer) return -ENOMEM; - efiret = BS->open_protocol((void *)efi_sys_table->con_in_handle, + efiret = BS->open_protocol(efi_sys_table->con_in_handle, &inex_guid, (void **)&inex, efi_parent_image, @@ -467,7 +476,7 @@ static int efi_console_probe(struct device_d *dev) return 0; } -static struct driver_d efi_console_driver = { +static struct driver efi_console_driver = { .name = "efi-stdio", .probe = efi_console_probe, }; diff --git a/drivers/serial/linux_console.c b/drivers/serial/linux_console.c index a8e9c52125..b8303dfd12 100644 --- a/drivers/serial/linux_console.c +++ b/drivers/serial/linux_console.c @@ -15,7 +15,7 @@ static void linux_console_putc(struct console_device *cdev, char c) { - struct device_d *dev = cdev->dev; + struct device *dev = cdev->dev; struct linux_console_data *d = dev->platform_data; linux_write(d->stdoutfd, &c, 1); @@ -23,7 +23,7 @@ static void linux_console_putc(struct console_device *cdev, char c) static int linux_console_tstc(struct console_device *cdev) { - struct device_d *dev = cdev->dev; + struct device *dev = cdev->dev; struct linux_console_data *d = dev->platform_data; return linux_tstc(d->stdinfd); @@ -31,7 +31,7 @@ static int linux_console_tstc(struct console_device *cdev) static int linux_console_getc(struct console_device *cdev) { - struct device_d *dev = cdev->dev; + struct device *dev = cdev->dev; struct linux_console_data *d = dev->platform_data; static char old_c; char c; @@ -45,7 +45,7 @@ static int linux_console_getc(struct console_device *cdev) return c; } -static int linux_console_probe(struct device_d *dev) +static int linux_console_probe(struct device *dev) { struct console_device *cdev; struct linux_console_data *data = dev->platform_data; @@ -67,7 +67,7 @@ static int linux_console_probe(struct device_d *dev) return 0; } -static struct driver_d linux_console_driver = { +static struct driver linux_console_driver = { .name = "console", .probe = linux_console_probe, }; diff --git a/drivers/serial/serial_altera.c b/drivers/serial/serial_altera.c deleted file mode 100644 index 55f4443862..0000000000 --- a/drivers/serial/serial_altera.c +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * (C) Copyright 2011, Franck JULLIEN, <elec4fun@gmail.com> - */ - -#include <common.h> -#include <driver.h> -#include <init.h> -#include <malloc.h> -#include <io.h> -#include <asm/nios2-io.h> - -struct altera_serial_priv { - struct console_device cdev; - void __iomem *regs; -}; - -static int altera_serial_setbaudrate(struct console_device *cdev, int baudrate) -{ - struct altera_serial_priv *priv = container_of(cdev, - struct altera_serial_priv, cdev); - - struct nios_uart *uart = priv->regs; - uint16_t div; - - div = (CPU_FREQ / baudrate) - 1; - writew(div, &uart->divisor); - - return 0; -} - -static void altera_serial_putc(struct console_device *cdev, char c) -{ - struct altera_serial_priv *priv = container_of(cdev, - struct altera_serial_priv, cdev); - - struct nios_uart *uart = priv->regs; - - while ((readw(&uart->status) & NIOS_UART_TRDY) == 0); - - writew(c, &uart->txdata); -} - -static int altera_serial_tstc(struct console_device *cdev) -{ - struct altera_serial_priv *priv = container_of(cdev, - struct altera_serial_priv, cdev); - - struct nios_uart *uart = priv->regs; - - return readw(&uart->status) & NIOS_UART_RRDY; -} - -static int altera_serial_getc(struct console_device *cdev) -{ - struct altera_serial_priv *priv = container_of(cdev, - struct altera_serial_priv, cdev); - - struct nios_uart *uart = priv->regs; - - while (altera_serial_tstc(cdev) == 0); - - return readw(&uart->rxdata) & 0x000000FF; -} - -static int altera_serial_probe(struct device_d *dev) -{ - struct resource *iores; - struct console_device *cdev; - struct altera_serial_priv *priv; - - priv = xzalloc(sizeof(*priv)); - cdev = &priv->cdev; - - iores = dev_request_mem_resource(dev, 0); - if (IS_ERR(iores)) - return PTR_ERR(iores); - priv->regs = IOMEM(iores->start); - cdev->dev = dev; - cdev->tstc = altera_serial_tstc; - cdev->putc = altera_serial_putc; - cdev->getc = altera_serial_getc; - cdev->setbrg = altera_serial_setbaudrate; - - console_register(cdev); - - return 0; -} - -static struct driver_d altera_serial_driver = { - .name = "altera_serial", - .probe = altera_serial_probe, -}; -console_platform_driver(altera_serial_driver); diff --git a/drivers/serial/serial_altera_jtag.c b/drivers/serial/serial_altera_jtag.c deleted file mode 100644 index b6720545ce..0000000000 --- a/drivers/serial/serial_altera_jtag.c +++ /dev/null @@ -1,99 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * (C) Copyright 2004, Psyent Corporation <www.psyent.com> - * Scott McNutt <smcnutt@psyent.com> - * - * (C) Copyright 2011 - Franck JULLIEN <elec4fun@gmail.com> - */ - -#include <common.h> -#include <driver.h> -#include <init.h> -#include <malloc.h> -#include <io.h> -#include <asm/nios2-io.h> - -struct altera_serial_jtag_priv { - struct console_device cdev; - void __iomem *regs; -}; - - -static int altera_serial_jtag_setbaudrate(struct console_device *cdev, int baudrate) -{ - return 0; -} - -static void altera_serial_jtag_putc(struct console_device *cdev, char c) -{ - struct altera_serial_jtag_priv *priv = container_of(cdev, - struct altera_serial_jtag_priv, cdev); - - struct nios_jtag *jtag = priv->regs; - uint32_t st; - - while (1) { - st = readl(&jtag->control); - if (NIOS_JTAG_WSPACE(st)) - break; - } - - writel(c, &jtag->data); -} - -static int altera_serial_jtag_tstc(struct console_device *cdev) -{ - struct altera_serial_jtag_priv *priv = container_of(cdev, - struct altera_serial_jtag_priv, cdev); - - struct nios_jtag *jtag = priv->regs; - - return readl(&jtag->control) & NIOS_JTAG_RRDY; -} - -static int altera_serial_jtag_getc(struct console_device *cdev) -{ - struct altera_serial_jtag_priv *priv = container_of(cdev, - struct altera_serial_jtag_priv, cdev); - - struct nios_jtag *jtag = priv->regs; - uint32_t val; - - while (1) { - val = readl(&jtag->data); - if (val & NIOS_JTAG_RVALID) - break; - } - - return val & 0xFF; -} - -static int altera_serial_jtag_probe(struct device_d *dev) { - struct resource *iores; - - struct console_device *cdev; - struct altera_serial_jtag_priv *priv; - - priv = xzalloc(sizeof(*priv)); - cdev = &priv->cdev; - - iores = dev_request_mem_resource(dev, 0); - if (IS_ERR(iores)) - return PTR_ERR(iores); - priv->regs = IOMEM(iores->start); - cdev->dev = dev; - cdev->tstc = altera_serial_jtag_tstc; - cdev->putc = altera_serial_jtag_putc; - cdev->getc = altera_serial_jtag_getc; - cdev->setbrg = altera_serial_jtag_setbaudrate; - - console_register(cdev); - - return 0; -} - -static struct driver_d altera_serial_jtag_driver = { - .name = "altera_serial_jtag", - .probe = altera_serial_jtag_probe, -}; -console_platform_driver(altera_serial_jtag_driver); diff --git a/drivers/serial/serial_ar933x.c b/drivers/serial/serial_ar933x.c index 29e1151db3..f5595ec1ee 100644 --- a/drivers/serial/serial_ar933x.c +++ b/drivers/serial/serial_ar933x.c @@ -141,7 +141,7 @@ static int ar933x_serial_getc(struct console_device *cdev) return rdata & AR933X_UART_DATA_TX_RX_MASK; } -static int ar933x_serial_probe(struct device_d *dev) +static int ar933x_serial_probe(struct device *dev) { struct resource *iores; struct console_device *cdev; @@ -188,8 +188,9 @@ static struct of_device_id ar933x_serial_dt_ids[] = { /* sentinel */ }, }; +MODULE_DEVICE_TABLE(of, ar933x_serial_dt_ids); -static struct driver_d ar933x_serial_driver = { +static struct driver ar933x_serial_driver = { .name = "ar933x_serial", .probe = ar933x_serial_probe, .of_compatible = DRV_OF_COMPAT(ar933x_serial_dt_ids), diff --git a/drivers/serial/serial_auart.c b/drivers/serial/serial_auart.c index d8e31fae30..217ac5c891 100644 --- a/drivers/serial/serial_auart.c +++ b/drivers/serial/serial_auart.c @@ -36,8 +36,6 @@ #include <linux/clk.h> #include <linux/err.h> -#include <mach/clock.h> - #define HW_UARTAPP_CTRL0 (0x00000000) #define HW_UARTAPP_CTRL2 (0x00000020) @@ -168,7 +166,7 @@ static void auart_serial_init_port(struct auart_priv *priv) writel(0x0, priv->base + HW_UARTAPP_INTR); } -static int auart_serial_probe(struct device_d *dev) +static int auart_serial_probe(struct device *dev) { struct resource *iores; struct auart_priv *priv; @@ -218,8 +216,9 @@ static const __maybe_unused struct of_device_id auart_serial_dt_ids[] = { /* sentinel */ } }; +MODULE_DEVICE_TABLE(of, auart_serial_dt_ids); -static struct driver_d auart_serial_driver = { +static struct driver auart_serial_driver = { .name = "auart_serial", .probe = auart_serial_probe, .of_compatible = DRV_OF_COMPAT(auart_serial_dt_ids), diff --git a/drivers/serial/serial_cadence.c b/drivers/serial/serial_cadence.c index 84dcd1b76b..ee162e541a 100644 --- a/drivers/serial/serial_cadence.c +++ b/drivers/serial/serial_cadence.c @@ -173,7 +173,7 @@ static int cadence_clocksource_clock_change(struct notifier_block *nb, return 0; } -static int cadence_serial_probe(struct device_d *dev) +static int cadence_serial_probe(struct device *dev) { struct resource *iores; struct console_device *cdev; @@ -240,6 +240,7 @@ static __maybe_unused struct of_device_id cadence_serial_dt_ids[] = { /* sentinel */ } }; +MODULE_DEVICE_TABLE(of, cadence_serial_dt_ids); static struct platform_device_id cadence_serial_ids[] = { { @@ -250,7 +251,7 @@ static struct platform_device_id cadence_serial_ids[] = { }, }; -static struct driver_d cadence_serial_driver = { +static struct driver cadence_serial_driver = { .name = "cadence_serial", .probe = cadence_serial_probe, .of_compatible = DRV_OF_COMPAT(cadence_serial_dt_ids), diff --git a/drivers/serial/serial_clps711x.c b/drivers/serial/serial_clps711x.c index 81eb85429e..2a284909bf 100644 --- a/drivers/serial/serial_clps711x.c +++ b/drivers/serial/serial_clps711x.c @@ -8,6 +8,7 @@ #include <linux/clk.h> #include <linux/err.h> #include <mfd/syscon.h> +#include <linux/regmap.h> #define UARTDR 0x00 # define UARTDR_FRMERR (1 << 8) @@ -127,7 +128,7 @@ static void clps711x_flush(struct console_device *cdev) } while (tmp & SYSFLG_UBUSY); } -static int clps711x_probe(struct device_d *dev) +static int clps711x_probe(struct device *dev) { struct device_node *syscon; struct clps711x_uart *s; @@ -148,7 +149,7 @@ static int clps711x_probe(struct device_d *dev) goto out_err; } - syscon = of_parse_phandle(dev->device_node, "syscon", 0); + syscon = of_parse_phandle(dev->of_node, "syscon", 0); s->regmap = syscon_node_to_regmap(syscon); if (IS_ERR(s->regmap)) { err = PTR_ERR(s->regmap); @@ -164,7 +165,7 @@ static int clps711x_probe(struct device_d *dev) s->cdev.setbrg = clps711x_setbaudrate; s->cdev.linux_console_name = "ttyCL"; - devname = of_alias_get(dev->device_node); + devname = of_alias_get(dev->of_node); if (devname) { s->cdev.devname = xstrdup(devname); s->cdev.devid = DEVICE_ID_SINGLE; @@ -185,8 +186,9 @@ static const struct of_device_id __maybe_unused clps711x_uart_dt_ids[] = { { .compatible = "cirrus,ep7209-uart", }, { /* sentinel */ } }; +MODULE_DEVICE_TABLE(of, clps711x_uart_dt_ids); -static struct driver_d clps711x_driver = { +static struct driver clps711x_driver = { .name = "clps711x-uart", .probe = clps711x_probe, .of_compatible = DRV_OF_COMPAT(clps711x_uart_dt_ids), diff --git a/drivers/serial/serial_digic.c b/drivers/serial/serial_digic.c index 74c9c9c7e2..48e9cd3248 100644 --- a/drivers/serial/serial_digic.c +++ b/drivers/serial/serial_digic.c @@ -10,7 +10,7 @@ #include <malloc.h> #include <io.h> -#include <mach/uart.h> +#include <mach/digic/uart.h> /* * This driver is based on the "Serial terminal" docs here: @@ -89,7 +89,7 @@ static int digic_serial_tstc(struct console_device *cdev) */ } -static int digic_serial_probe(struct device_d *dev) +static int digic_serial_probe(struct device *dev) { struct resource *iores; struct console_device *cdev; @@ -117,8 +117,9 @@ static __maybe_unused struct of_device_id digic_serial_dt_ids[] = { /* sentinel */ } }; +MODULE_DEVICE_TABLE(of, digic_serial_dt_ids); -static struct driver_d digic_serial_driver = { +static struct driver digic_serial_driver = { .name = "digic-uart", .probe = digic_serial_probe, .of_compatible = DRV_OF_COMPAT(digic_serial_dt_ids), diff --git a/drivers/serial/serial_imx.c b/drivers/serial/serial_imx.c index cf9c3f02a7..0f91028605 100644 --- a/drivers/serial/serial_imx.c +++ b/drivers/serial/serial_imx.c @@ -197,7 +197,7 @@ static int imx_clocksource_clock_change(struct notifier_block *nb, return 0; } -static int imx_serial_probe(struct device_d *dev) +static int imx_serial_probe(struct device *dev) { struct resource *iores; struct console_device *cdev; @@ -236,19 +236,19 @@ static int imx_serial_probe(struct device_d *dev) cdev->linux_console_name = "ttymxc"; cdev->linux_earlycon_name = "ec_imx6q"; cdev->phys_base = priv->regs; - if (dev->device_node) { - devname = of_alias_get(dev->device_node); + if (dev->of_node) { + devname = of_alias_get(dev->of_node); if (devname) { cdev->devname = xstrdup(devname); cdev->devid = DEVICE_ID_SINGLE; } } - if (of_property_read_bool(dev->device_node, "fsl,dte-mode")) + if (of_property_read_bool(dev->of_node, "fsl,dte-mode")) priv->dte_mode = 1; - if (of_property_read_bool(dev->device_node, "linux,rs485-enabled-at-boot-time") && - !of_property_read_bool(dev->device_node, "rs485-rts-active-low")) + if (of_property_read_bool(dev->of_node, "linux,rs485-enabled-at-boot-time") && + !of_property_read_bool(dev->of_node, "rs485-rts-active-low")) priv->rs485_mode = 1; imx_serial_init_port(cdev); @@ -299,6 +299,7 @@ static __maybe_unused struct of_device_id imx_serial_dt_ids[] = { /* sentinel */ } }; +MODULE_DEVICE_TABLE(of, imx_serial_dt_ids); static struct platform_device_id imx_serial_ids[] = { { @@ -312,7 +313,7 @@ static struct platform_device_id imx_serial_ids[] = { }, }; -static struct driver_d imx_serial_driver = { +static struct driver imx_serial_driver = { .name = "imx_serial", .probe = imx_serial_probe, .of_compatible = DRV_OF_COMPAT(imx_serial_dt_ids), diff --git a/drivers/serial/serial_litex.c b/drivers/serial/serial_litex.c index 554fee71a3..04da556f6a 100644 --- a/drivers/serial/serial_litex.c +++ b/drivers/serial/serial_litex.c @@ -58,7 +58,7 @@ static int litex_serial_tstc(struct console_device *cdev) return !litex_serial_readb(cdev, UART_RXEMPTY); } -static int litex_serial_probe(struct device_d *dev) +static int litex_serial_probe(struct device *dev) { struct resource *iores; struct console_device *cdev; @@ -90,8 +90,9 @@ static __maybe_unused struct of_device_id litex_serial_dt_ids[] = { /* sentinel */ } }; +MODULE_DEVICE_TABLE(of, litex_serial_dt_ids); -static struct driver_d litex_serial_driver = { +static struct driver litex_serial_driver = { .name = "litex-uart", .probe = litex_serial_probe, .of_compatible = DRV_OF_COMPAT(litex_serial_dt_ids), diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c index 720018c9ac..828a0dd0bb 100644 --- a/drivers/serial/serial_lpuart.c +++ b/drivers/serial/serial_lpuart.c @@ -113,7 +113,7 @@ static int lpuart_clocksource_clock_change(struct notifier_block *nb, return lpuart_serial_setbaudrate(&lpuart->cdev, lpuart->baudrate); } -static int lpuart_serial_probe(struct device_d *dev) +static int lpuart_serial_probe(struct device *dev) { int ret; struct console_device *cdev; @@ -151,8 +151,8 @@ static int lpuart_serial_probe(struct device_d *dev) cdev->flush = lpuart_serial_flush; cdev->setbrg = lpuart_serial_setbaudrate; - if (dev->device_node) { - devname = of_alias_get(dev->device_node); + if (dev->of_node) { + devname = of_alias_get(dev->of_node); if (devname) { cdev->devname = xstrdup(devname); cdev->devid = DEVICE_ID_SINGLE; @@ -186,8 +186,9 @@ static struct of_device_id lpuart_serial_dt_ids[] = { { .compatible = "fsl,vf610-lpuart" }, {} }; +MODULE_DEVICE_TABLE(of, lpuart_serial_dt_ids); -static struct driver_d lpuart_serial_driver = { +static struct driver lpuart_serial_driver = { .name = "lpuart-serial", .probe = lpuart_serial_probe, .of_compatible = DRV_OF_COMPAT(lpuart_serial_dt_ids), diff --git a/drivers/serial/serial_lpuart32.c b/drivers/serial/serial_lpuart32.c new file mode 100644 index 0000000000..09d4b620be --- /dev/null +++ b/drivers/serial/serial_lpuart32.c @@ -0,0 +1,188 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023 Pengutronix + */ + +#include <common.h> +#include <driver.h> +#include <init.h> +#include <malloc.h> +#include <notifier.h> +#include <io.h> +#include <of.h> +#include <linux/err.h> +#include <linux/clk.h> +#include <serial/lpuart32.h> + +struct lpuart32_devtype_data { + unsigned int reg_offs; +}; + +struct lpuart32 { + struct console_device cdev; + int baudrate; + int dte_mode; + struct notifier_block notify; + struct resource *io; + void __iomem *base; + struct clk *clk; +}; + +static struct lpuart32 *cdev_to_lpuart32(struct console_device *cdev) +{ + return container_of(cdev, struct lpuart32, cdev); +} + +static void lpuart32_enable(struct lpuart32 *lpuart32) +{ + writel(LPUART32_UARTCTRL_TE | LPUART32_UARTCTRL_RE, + lpuart32->base + LPUART32_UARTCTRL); +} + +static void lpuart32_disable(struct lpuart32 *lpuart32) +{ + writel(0, lpuart32->base + LPUART32_UARTCTRL); +} + +/* Test whether a character is in the RX buffer */ +static int lpuart32_serial_tstc(struct console_device *cdev) +{ + struct lpuart32 *lpuart32 = cdev_to_lpuart32(cdev); + + if (readl(lpuart32->base + LPUART32_UARTSTAT) & LPUART32_UARTSTAT_OR) + writel(LPUART32_UARTSTAT_OR, lpuart32->base + LPUART32_UARTSTAT); + + return readl(lpuart32->base + LPUART32_UARTSTAT) & LPUART32_UARTSTAT_RDRF; +} + +static int lpuart32_serial_setbaudrate(struct console_device *cdev, + int baudrate) +{ + struct lpuart32 *lpuart32 = cdev_to_lpuart32(cdev); + + lpuart32_disable(lpuart32); + + /* + * We treat baudrate of 0 as a request to disable UART + */ + if (baudrate) { + lpuart32_setbrg(lpuart32->base, clk_get_rate(lpuart32->clk), + baudrate); + lpuart32_enable(lpuart32); + } + + lpuart32->baudrate = baudrate; + + return 0; +} + +static int lpuart32_serial_getc(struct console_device *cdev) +{ + struct lpuart32 *lpuart32 = cdev_to_lpuart32(cdev); + + while (!lpuart32_serial_tstc(cdev)); + + return readl(lpuart32->base + LPUART32_UARTDATA) & 0xff; +} + +static void lpuart32_serial_putc(struct console_device *cdev, char c) +{ + struct lpuart32 *lpuart32 = cdev_to_lpuart32(cdev); + + lpuart32_putc(lpuart32->base, c); +} + +static void lpuart32_serial_flush(struct console_device *cdev) +{ +} + +static int lpuart32_serial_probe(struct device *dev) +{ + int ret; + struct console_device *cdev; + struct lpuart32 *lpuart32; + const char *devname; + struct lpuart32_devtype_data *devtype; + + ret = dev_get_drvdata(dev, (const void **)&devtype); + if (ret) + return ret; + + lpuart32 = xzalloc(sizeof(*lpuart32)); + cdev = &lpuart32->cdev; + dev->priv = lpuart32; + + lpuart32->io = dev_request_mem_resource(dev, 0); + if (IS_ERR(lpuart32->io)) { + ret = PTR_ERR(lpuart32->io); + goto err_free; + } + lpuart32->base = IOMEM(lpuart32->io->start) + devtype->reg_offs; + + lpuart32->clk = clk_get(dev, NULL); + if (IS_ERR(lpuart32->clk)) { + ret = PTR_ERR(lpuart32->clk); + dev_err(dev, "Failed to get UART clock %d\n", ret); + goto io_release; + } + + ret = clk_enable(lpuart32->clk); + if (ret) { + dev_err(dev, "Failed to enable UART clock %d\n", ret); + goto io_release; + } + + cdev->dev = dev; + cdev->tstc = lpuart32_serial_tstc; + cdev->putc = lpuart32_serial_putc; + cdev->getc = lpuart32_serial_getc; + cdev->flush = lpuart32_serial_flush; + cdev->setbrg = lpuart32_serial_setbaudrate; + + if (dev->of_node) { + devname = of_alias_get(dev->of_node); + if (devname) { + cdev->devname = xstrdup(devname); + cdev->devid = DEVICE_ID_SINGLE; + } + } + + cdev->linux_console_name = "ttyLP"; + cdev->linux_earlycon_name = "lpuart"; + cdev->phys_base = lpuart32->base; + + lpuart32_setup(lpuart32->base, clk_get_rate(lpuart32->clk)); + + ret = console_register(cdev); + if (!ret) + return 0; + + clk_put(lpuart32->clk); +io_release: + release_region(lpuart32->io); +err_free: + free(lpuart32); + + return ret; +} + +static struct lpuart32_devtype_data imx7ulp_data = { + .reg_offs = 0x10, +}; + +static struct of_device_id lpuart32_serial_dt_ids[] = { + { + .compatible = "fsl,imx7ulp-lpuart", + .data = &imx7ulp_data, + }, { + /* sentinel */ + } +}; +MODULE_DEVICE_TABLE(of, lpuart32_serial_dt_ids); + +static struct driver lpuart32_serial_driver = { + .name = "lpuart32-serial", + .probe = lpuart32_serial_probe, + .of_compatible = DRV_OF_COMPAT(lpuart32_serial_dt_ids), +}; +console_platform_driver(lpuart32_serial_driver); diff --git a/drivers/serial/serial_mpc5xxx.c b/drivers/serial/serial_mpc5xxx.c index 38248dfd82..4408de9e91 100644 --- a/drivers/serial/serial_mpc5xxx.c +++ b/drivers/serial/serial_mpc5xxx.c @@ -46,7 +46,7 @@ static int __mpc5xxx_serial_setbaudrate(struct mpc5xxx_psc *psc, int baudrate) static int mpc5xxx_serial_setbaudrate(struct console_device *cdev, int baudrate) { - struct device_d *dev = cdev->dev; + struct device *dev = cdev->dev; struct mpc5xxx_psc *psc = dev->priv; __mpc5xxx_serial_setbaudrate(psc, baudrate); @@ -90,7 +90,7 @@ static int __mpc5xxx_serial_init(struct mpc5xxx_psc *psc) static int mpc5xxx_serial_init(struct console_device *cdev) { - struct device_d *dev = cdev->dev; + struct device *dev = cdev->dev; struct mpc5xxx_psc *psc = dev->priv; __mpc5xxx_serial_init(psc); @@ -100,7 +100,7 @@ static int mpc5xxx_serial_init(struct console_device *cdev) static void mpc5xxx_serial_putc (struct console_device *cdev, const char c) { - struct device_d *dev = cdev->dev; + struct device *dev = cdev->dev; struct mpc5xxx_psc *psc = dev->priv; /* Wait for last character to go. */ @@ -112,7 +112,7 @@ static void mpc5xxx_serial_putc (struct console_device *cdev, const char c) static int mpc5xxx_serial_getc (struct console_device *cdev) { - struct device_d *dev = cdev->dev; + struct device *dev = cdev->dev; struct mpc5xxx_psc *psc = dev->priv; /* Wait for a character to arrive. */ @@ -124,13 +124,13 @@ static int mpc5xxx_serial_getc (struct console_device *cdev) static int mpc5xxx_serial_tstc (struct console_device *cdev) { - struct device_d *dev = cdev->dev; + struct device *dev = cdev->dev; struct mpc5xxx_psc *psc = dev->priv; return (psc->psc_status & PSC_SR_RXRDY); } -static int mpc5xxx_serial_probe(struct device_d *dev) +static int mpc5xxx_serial_probe(struct device *dev) { struct resource *iores; struct console_device *cdev; @@ -153,7 +153,7 @@ static int mpc5xxx_serial_probe(struct device_d *dev) return 0; } -static struct driver_d mpc5xxx_serial_driver = { +static struct driver mpc5xxx_serial_driver = { .name = "mpc5xxx_serial", .probe = mpc5xxx_serial_probe, }; diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c index e5cbc3624e..1b1692658f 100644 --- a/drivers/serial/serial_ns16550.c +++ b/drivers/serial/serial_ns16550.c @@ -40,6 +40,10 @@ struct ns16550_priv { void (*write_reg)(struct ns16550_priv *, uint8_t val, unsigned offset); uint8_t (*read_reg)(struct ns16550_priv *, unsigned offset); const char *access_type; + + bool rs485_mode; + bool rs485_rts_active_low; + bool rs485_rx_during_tx; }; struct ns16550_drvdata { @@ -265,9 +269,37 @@ static void rpi_init_port(struct console_device *cdev) */ static void ns16550_putc(struct console_device *cdev, char c) { - /* Loop Doing Nothing */ - while ((ns16550_read(cdev, lsr) & LSR_THRE) == 0) ; + struct ns16550_priv *priv = to_ns16550_priv(cdev); + + /* wait until FIFO can accept at least one byte */ + while ((ns16550_read(cdev, lsr) & (LSR_THRE)) != (LSR_THRE)) + ; + + if (priv->rs485_mode) { + if (priv->rs485_rts_active_low) + ns16550_write(cdev, MCR_RTS, mcr); + else + ns16550_write(cdev, 0, mcr); + + if (!priv->rs485_rx_during_tx) + ns16550_write(cdev, CNTL_TXEN, cntl); + } + ns16550_write(cdev, c, thr); + + if (priv->rs485_mode) { + /* wait until FIFO is cleared*/ + while ((ns16550_read(cdev, lsr) & (LSR_EMPTY)) != (LSR_EMPTY)) + ; + + if (priv->rs485_rts_active_low) + ns16550_write(cdev, 0, mcr); + else + ns16550_write(cdev, MCR_RTS, mcr); + + if (!priv->rs485_rx_during_tx) + ns16550_write(cdev, CNTL_TXEN | CNTL_RXEN, cntl); + } } /** @@ -307,7 +339,7 @@ static void ns16550_flush(struct console_device *cdev) while ((ns16550_read(cdev, lsr) & LSR_TEMT) == 0) ; } -static void ns16550_probe_dt(struct device_d *dev, struct ns16550_priv *priv) +static void ns16550_probe_dt(struct device *dev, struct ns16550_priv *priv) { struct device_node *np = dev_of_node(dev); u32 offset; @@ -321,6 +353,12 @@ static void ns16550_probe_dt(struct device_d *dev, struct ns16550_priv *priv) priv->mmiobase += offset; of_property_read_u32(np, "reg-shift", &priv->plat.shift); of_property_read_u32(np, "reg-io-width", &width); + priv->rs485_rts_active_low = + of_property_read_bool(np, "rs485-rts-active-low"); + priv->rs485_mode = + of_property_read_bool(np, "linux,rs485-enabled-at-boot-time"); + priv->rs485_rx_during_tx = + of_property_read_bool(np, "rs485-rx-during-tx"); switch (width) { case 1: @@ -385,23 +423,51 @@ static __maybe_unused struct ns16550_drvdata rpi_drvdata = { .linux_earlycon_name = "bcm2835aux", }; -static int ns16550_init_iomem(struct device_d *dev, struct ns16550_priv *priv) +/** + * @return the requested resource to be properly released in case probe fail + */ +static struct resource *ns16550_init_iores(struct device *dev, struct ns16550_priv *priv) { - struct resource *iores; struct resource *res; - int width; + struct resource *iores; + unsigned long flags; res = dev_get_resource(dev, IORESOURCE_MEM, 0); if (IS_ERR(res)) - return PTR_ERR(res); + res = dev_get_resource(dev, IORESOURCE_IO, 0); + if (IS_ERR(res)) + return res; - iores = dev_request_mem_resource(dev, 0); + flags = res->flags & (IORESOURCE_MEM_TYPE_MASK | IORESOURCE_IO); + + if (flags & IORESOURCE_IO) + iores = request_ioport_region(dev_name(dev), res->start, res->end); + else + iores = request_iomem_region(dev_name(dev), res->start, res->end); if (IS_ERR(iores)) - return PTR_ERR(iores); - priv->mmiobase = IOMEM(iores->start); + return iores; - width = res->flags & IORESOURCE_MEM_TYPE_MASK; - switch (width) { + if (flags & IORESOURCE_IO) + priv->iobase = iores->start; + else + priv->mmiobase = IOMEM(iores->start); + + switch (flags) { + case IORESOURCE_IO | IORESOURCE_MEM_8BIT: + priv->read_reg = ns16550_read_reg_ioport_8; + priv->write_reg = ns16550_write_reg_ioport_8; + priv->access_type = "io"; + break; + case IORESOURCE_IO | IORESOURCE_MEM_16BIT: + priv->read_reg = ns16550_read_reg_ioport_16; + priv->write_reg = ns16550_write_reg_ioport_16; + priv->access_type = "io"; + break; + case IORESOURCE_IO | IORESOURCE_MEM_32BIT: + priv->read_reg = ns16550_read_reg_ioport_32; + priv->write_reg = ns16550_write_reg_ioport_32; + priv->access_type = "io"; + break; case IORESOURCE_MEM_8BIT: priv->read_reg = ns16550_read_reg_mmio_8; priv->write_reg = ns16550_write_reg_mmio_8; @@ -419,43 +485,7 @@ static int ns16550_init_iomem(struct device_d *dev, struct ns16550_priv *priv) break; } - return 0; -} - -static int ns16550_init_ioport(struct device_d *dev, struct ns16550_priv *priv) -{ - struct resource *res; - int width; - - res = dev_get_resource(dev, IORESOURCE_IO, 0); - if (IS_ERR(res)) - return PTR_ERR(res); - - res = request_ioport_region(dev_name(dev), res->start, res->end); - if (IS_ERR(res)) - return PTR_ERR(res); - - priv->iobase = res->start; - - width = res->flags & IORESOURCE_MEM_TYPE_MASK; - switch (width) { - case IORESOURCE_MEM_8BIT: - priv->read_reg = ns16550_read_reg_ioport_8; - priv->write_reg = ns16550_write_reg_ioport_8; - break; - case IORESOURCE_MEM_16BIT: - priv->read_reg = ns16550_read_reg_ioport_16; - priv->write_reg = ns16550_write_reg_ioport_16; - break; - case IORESOURCE_MEM_32BIT: - priv->read_reg = ns16550_read_reg_ioport_32; - priv->write_reg = ns16550_write_reg_ioport_32; - break; - } - - priv->access_type = "io"; - - return 0; + return iores; } /** @@ -467,24 +497,24 @@ static int ns16550_init_ioport(struct device_d *dev, struct ns16550_priv *priv) * ENOMEM if calloc failed * else return result of console_register */ -static int ns16550_probe(struct device_d *dev) +static int ns16550_probe(struct device *dev) { struct ns16550_priv *priv; struct console_device *cdev; struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data; const struct ns16550_drvdata *devtype; + struct resource *iores; int ret; devtype = device_get_match_data(dev) ?: &ns16550_drvdata; priv = xzalloc(sizeof(*priv)); - ret = ns16550_init_iomem(dev, priv); - if (ret) - ret = ns16550_init_ioport(dev, priv); - - if (ret) - return ret; + iores = ns16550_init_iores(dev, priv); + if (IS_ERR(iores)) { + ret = PTR_ERR(iores); + goto err; + } if (plat) priv->plat = *plat; @@ -499,16 +529,18 @@ static int ns16550_probe(struct device_d *dev) if (IS_ERR(priv->clk)) { ret = PTR_ERR(priv->clk); dev_err(dev, "failed to get clk (%d)\n", ret); - goto err; + goto release_region; } - clk_enable(priv->clk); + ret = clk_enable(priv->clk); + if (ret) + goto clk_put; priv->plat.clock = clk_get_rate(priv->clk); } if (priv->plat.clock == 0) { dev_err(dev, "no valid clockrate\n"); ret = -EINVAL; - goto err; + goto clk_disable; } cdev = &priv->cdev; @@ -528,8 +560,18 @@ static int ns16550_probe(struct device_d *dev) devtype->init_port(cdev); - return console_register(cdev); + ret = console_register(cdev); + if (ret) + goto clk_disable; + + return 0; +clk_disable: + clk_disable(priv->clk); +clk_put: + clk_put(priv->clk); +release_region: + release_region(iores); err: free(priv); @@ -549,6 +591,12 @@ static struct of_device_id ns16550_serial_dt_ids[] = { }, { .compatible = "nvidia,tegra20-uart", }, +#if IS_ENABLED(CONFIG_ARCH_K3) + { + .compatible = "ti,am654-uart", + .data = &omap_clk48m_drvdata, + }, +#endif #if IS_ENABLED(CONFIG_ARCH_OMAP) { .compatible = "ti,omap2-uart", @@ -580,6 +628,7 @@ static struct of_device_id ns16550_serial_dt_ids[] = { /* sentinel */ }, }; +MODULE_DEVICE_TABLE(of, ns16550_serial_dt_ids); static __maybe_unused struct platform_device_id ns16550_serial_ids[] = { { @@ -593,7 +642,7 @@ static __maybe_unused struct platform_device_id ns16550_serial_ids[] = { /** * @brief Driver registration structure */ -static struct driver_d ns16550_serial_driver = { +static struct driver ns16550_serial_driver = { .name = "ns16550_serial", .probe = ns16550_probe, .of_compatible = DRV_OF_COMPAT(ns16550_serial_dt_ids), diff --git a/drivers/serial/serial_ns16550.h b/drivers/serial/serial_ns16550.h index 56c639a134..2d941cb8d1 100644 --- a/drivers/serial/serial_ns16550.h +++ b/drivers/serial/serial_ns16550.h @@ -36,6 +36,7 @@ #define lsr 5 #define msr 6 #define scr 7 +#define cntl 8 #define thr rbr #define iir fcr @@ -73,6 +74,12 @@ #define LSR_TEMT 0x40 /* Xmitter empty */ #define LSR_ERR 0x80 /* Error */ +/* Transmitter FIFO completely empty */ +#define LSR_EMPTY (LSR_THRE | LSR_TEMT) + +#define CNTL_RXEN 0x01 +#define CNTL_TXEN 0x02 + /* useful defaults for LCR */ #define LCR_8N1 0x03 diff --git a/drivers/serial/serial_ns16550_pci.c b/drivers/serial/serial_ns16550_pci.c index fde8f718dd..f82b5797ce 100644 --- a/drivers/serial/serial_ns16550_pci.c +++ b/drivers/serial/serial_ns16550_pci.c @@ -1203,7 +1203,7 @@ static int pci_quatech_init(struct pci_dev *dev) outl(inl(base + 0x38) | 0x00002000, base + 0x38); tmp = inl(base + 0x3c); outl(tmp | 0x01000000, base + 0x3c); - outl(tmp &= ~0x01000000, base + 0x3c); + outl(tmp & ~0x01000000, base + 0x3c); } } return 0; @@ -3656,7 +3656,7 @@ pciserial_init_ports(struct pci_dev *dev, const struct pciserial_board *board) uart.pdata->clock = board->base_baud * 16; for (i = 0; i < nr_ports; i++) { - struct device_d *ns16550_dev; + struct device *ns16550_dev; struct resource *res; rc = quirk->setup(priv, board, &uart, i); diff --git a/drivers/serial/serial_omap4_usbboot.c b/drivers/serial/serial_omap4_usbboot.c index d0d01d585f..6592be4f35 100644 --- a/drivers/serial/serial_omap4_usbboot.c +++ b/drivers/serial/serial_omap4_usbboot.c @@ -4,7 +4,7 @@ #include <init.h> #include <malloc.h> #include <errno.h> -#include <mach/omap4_rom_usb.h> +#include <mach/omap/omap4_rom_usb.h> struct serial_omap4_usbboot_priv { struct console_device cdev; @@ -46,9 +46,15 @@ static int serial_omap4_usbboot_getc(struct console_device *cdev) return priv->val; } -static int serial_omap4_usbboot_probe(struct device_d *dev) +static int serial_omap4_usbboot_probe(struct device *dev) { struct serial_omap4_usbboot_priv *priv; + int ret; + + ret = omap4_usbboot_open(); + if (ret) + return ret; + priv = xzalloc(sizeof(*priv)); priv->cdev.dev = dev; @@ -60,7 +66,7 @@ static int serial_omap4_usbboot_probe(struct device_d *dev) return console_register(&priv->cdev); } -static struct driver_d serial_omap4_usbboot_driver = { +static struct driver serial_omap4_usbboot_driver = { .name = "serial_omap4_usbboot", .probe = serial_omap4_usbboot_probe, }; diff --git a/drivers/serial/serial_pl010.c b/drivers/serial/serial_pl010.c index f2cf944e8f..56b9e67610 100644 --- a/drivers/serial/serial_pl010.c +++ b/drivers/serial/serial_pl010.c @@ -115,7 +115,7 @@ static int pl010_tstc(struct console_device *cdev) return !(readl(&pl010->flag) & UART_PL010_FR_RXFE); } -static int pl010_probe(struct device_d *dev) +static int pl010_probe(struct device *dev) { struct resource *iores; struct console_device *cdev; @@ -138,7 +138,7 @@ static int pl010_probe(struct device_d *dev) return 0; } -static struct driver_d pl010_driver = { +static struct driver pl010_driver = { .name = "pl010_serial", .probe = pl010_probe, }; diff --git a/drivers/serial/serial_pxa.c b/drivers/serial/serial_pxa.c index c9f612dbeb..97342f923e 100644 --- a/drivers/serial/serial_pxa.c +++ b/drivers/serial/serial_pxa.c @@ -9,7 +9,7 @@ #include <init.h> #include <malloc.h> -#include <mach/clock.h> +#include <mach/pxa/clock.h> #include <asm/io.h> #define RBR 0x00 /* Receive Buffer Register (read only) */ @@ -149,7 +149,7 @@ static int pxa_serial_setbaudrate(struct console_device *cdev, int baudrate) return 0; } -static int pxa_serial_probe(struct device_d *dev) +static int pxa_serial_probe(struct device *dev) { struct resource *iores; struct console_device *cdev; @@ -175,7 +175,7 @@ static int pxa_serial_probe(struct device_d *dev) return 0; } -static struct driver_d pxa_serial_driver = { +static struct driver pxa_serial_driver = { .name = "pxa_serial", .probe = pxa_serial_probe, }; diff --git a/drivers/serial/serial_s3c.c b/drivers/serial/serial_s3c.c deleted file mode 100644 index 4080079d42..0000000000 --- a/drivers/serial/serial_s3c.c +++ /dev/null @@ -1,198 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * (c) 2009...2011 Juergen Beisert <j.beisert@pengutronix.de> - * - * Based on code from: - * (c) 2004 Sascha Hauer <sascha@saschahauer.de> - */ - -#include <common.h> -#include <driver.h> -#include <init.h> -#include <malloc.h> -#include <io.h> -#include <mach/s3c-generic.h> -#include <mach/s3c-iomap.h> - -/* Note: Offsets are for little endian access */ -#define ULCON 0x00 /* line control */ -#define UCON 0x04 /* UART control */ -# define UCON_SET_CLK_SRC(x) (((x) & 0x03) << 10) -# define UCON_GET_CLK_SRC(x) (((x) >> 10) & 0x03) -#define UFCON 0x08 /* FIFO control */ -#define UMCON 0x0c /* modem control */ -#define UTRSTAT 0x10 /* Rx/Tx status */ -#define UERSTAT 0x14 /* error status */ -#define UFSTAT 0x18 /* FIFO status */ -#define UMSTAT 0x1c /* modem status */ -#define UTXH 0x20 /* transmitt */ -#define URXH 0x24 /* receive */ -#define UBRDIV 0x28 /* baudrate generator */ -#define UBRDIVSLOT 0x2c /* baudrate slot generator */ -#define UINTM 0x38 /* interrupt mask register */ - -struct s3c_uart { - void __iomem *regs; - struct console_device cdev; -}; - -#define to_s3c_uart(c) container_of(c, struct s3c_uart, cdev) - -/* each architecture has a preferred reference clock for its UARTs */ -static unsigned s3c_select_arch_input_clock(void) -{ - /* S3C24xx: 0=2=PCLK, 1=UEXTCLK, 3=FCLK/n */ - if (IS_ENABLED(CONFIG_ARCH_S3C24xx)) - return 0; /* use the internal PCLK */ - /* S3C64xx: 0=2=PCLK, 1=UCLK0, 3=UCLK1 */ - if (IS_ENABLED(CONFIG_ARCH_S3C64xx)) - return 3; /* use the internal UCLK1 */ - /* S5PCxx: 0=PCLK, 1=SCLK_UART */ - if (IS_ENABLED(CONFIG_ARCH_S5PCxx)) - return 0; /* use the internal PCLK */ -} - -static unsigned s3c_get_arch_uart_input_clock(void __iomem *base) -{ - unsigned reg = readw(base + UCON); - return s3c_get_uart_clk(UCON_GET_CLK_SRC(reg)); -} - -/* - * This table takes the fractional value of the baud divisor and gives - * the recommended setting for the UDIVSLOT register. Refer the datasheet - * for further details - */ -static const uint16_t udivslot_table[] __maybe_unused = { - 0x0000, 0x0080, 0x0808, 0x0888, 0x2222, 0x4924, 0x4A52, 0x54AA, - 0x5555, 0xD555, 0xD5D5, 0xDDD5, 0xDDDD, 0xDFDD, 0xDFDF, 0xFFDF, -}; - -static int s3c_serial_setbaudrate(struct console_device *cdev, int baudrate) -{ - struct s3c_uart *priv = to_s3c_uart(cdev); - void __iomem *base = priv->regs; - unsigned val; - - if (IS_ENABLED(CONFIG_DRIVER_SERIAL_S3C_IMPROVED)) { - val = s3c_get_arch_uart_input_clock(base) / baudrate; - writew(udivslot_table[val & 15], base + UBRDIVSLOT); - } - - val = s3c_get_arch_uart_input_clock(base) / (16 * baudrate) - 1; - writew(val, base + UBRDIV); - - return 0; -} - -static int s3c_serial_init_port(struct console_device *cdev) -{ - struct s3c_uart *priv = to_s3c_uart(cdev); - void __iomem *base = priv->regs; - - /* FIFO enable, Tx/Rx FIFO clear */ - writeb(0x07, base + UFCON); - writeb(0x00, base + UMCON); - - /* Normal,No parity,1 stop,8 bit */ - writeb(0x03, base + ULCON); - - /* - * S3C2440 SoC: - * - no clock divider - * all SoCs: - * - enable receive and transmit mode - */ - writew(0x0005 | UCON_SET_CLK_SRC(s3c_select_arch_input_clock()), - base + UCON); - - if (IS_ENABLED(CONFIG_DRIVER_SERIAL_S3C_IMPROVED)) - /* 'interrupt or polling mode' for both directions */ - writeb(0xf, base + UINTM); - - if (IS_ENABLED(CONFIG_DRIVER_SERIAL_S3C_AUTOSYNC)) - writeb(0x10, base + UMCON); /* enable auto flow control */ - else - writeb(0x01, base + UMCON); /* RTS up */ - - return 0; -} - -static void s3c_serial_putc(struct console_device *cdev, char c) -{ - struct s3c_uart *priv = to_s3c_uart(cdev); - void __iomem *base = priv->regs; - - /* Wait for Tx FIFO not full */ - while (!(readb(base + UTRSTAT) & 0x2)) - ; - - writeb(c, base + UTXH); -} - -static int s3c_serial_tstc(struct console_device *cdev) -{ - struct s3c_uart *priv = to_s3c_uart(cdev); - void __iomem *base = priv->regs; - - /* If receive fifo is empty, return false */ - if (readb(base + UTRSTAT) & 0x1) - return 1; - - return 0; -} - -static int s3c_serial_getc(struct console_device *cdev) -{ - struct s3c_uart *priv = to_s3c_uart(cdev); - void __iomem *base = priv->regs; - - /* wait for a character */ - while (!(readb(base + UTRSTAT) & 0x1)) - ; - - return readb(base + URXH); -} - -static void s3c_serial_flush(struct console_device *cdev) -{ - struct s3c_uart *priv = to_s3c_uart(cdev); - void __iomem *base = priv->regs; - - while (!(readb(base + UTRSTAT) & 0x4)) - ; -} - -static int s3c_serial_probe(struct device_d *dev) -{ - struct resource *iores; - struct s3c_uart *priv; - struct console_device *cdev; - - priv = xzalloc(sizeof(struct s3c_uart)); - cdev = &priv->cdev; - iores = dev_request_mem_resource(dev, 0); - if (IS_ERR(iores)) - return PTR_ERR(iores); - priv->regs = IOMEM(iores->start); - dev->priv = priv; - cdev->dev = dev; - cdev->tstc = s3c_serial_tstc; - cdev->putc = s3c_serial_putc; - cdev->getc = s3c_serial_getc; - cdev->flush = s3c_serial_flush; - cdev->setbrg = s3c_serial_setbaudrate; - - s3c_serial_init_port(cdev); - - /* Enable UART */ - console_register(cdev); - - return 0; -} - -static struct driver_d s3c_serial_driver = { - .name = "s3c_serial", - .probe = s3c_serial_probe, -}; -console_platform_driver(s3c_serial_driver); diff --git a/drivers/serial/serial_sbi.c b/drivers/serial/serial_sbi.c index 343fcda4dc..dd3eef41d1 100644 --- a/drivers/serial/serial_sbi.c +++ b/drivers/serial/serial_sbi.c @@ -36,7 +36,7 @@ static int sbi_serial_tstc(struct console_device *cdev) return priv->head != priv->tail; } -static int sbi_serial_probe(struct device_d *dev) +static int sbi_serial_probe(struct device *dev) { struct sbi_serial_priv *priv; @@ -51,7 +51,7 @@ static int sbi_serial_probe(struct device_d *dev) return console_register(&priv->cdev); } -static struct driver_d serial_sbi_driver = { +static struct driver serial_sbi_driver = { .name = "riscv-serial-sbi", .probe = sbi_serial_probe, }; diff --git a/drivers/serial/serial_sifive.c b/drivers/serial/serial_sifive.c index 931269f2e3..f056233b4e 100644 --- a/drivers/serial/serial_sifive.c +++ b/drivers/serial/serial_sifive.c @@ -116,7 +116,7 @@ static void sifive_serial_flush(struct console_device *cdev) ; } -static int sifive_serial_probe(struct device_d *dev) +static int sifive_serial_probe(struct device *dev) { struct sifive_serial_priv *priv; struct resource *iores; @@ -130,7 +130,8 @@ static int sifive_serial_probe(struct device_d *dev) } else { dev_dbg(dev, "failed to get clock. Fallback to device tree.\n"); - ret = of_property_read_u32(dev->device_node, "clock-frequency", &freq); + ret = of_property_read_u32(dev->of_node, "clock-frequency", + &freq); if (ret) { dev_warn(dev, "unknown clock frequency\n"); return ret; @@ -162,8 +163,9 @@ static __maybe_unused struct of_device_id sifive_serial_dt_ids[] = { { .compatible = "sifive,uart0" }, { /* sentinel */ } }; +MODULE_DEVICE_TABLE(of, sifive_serial_dt_ids); -static struct driver_d serial_sifive_driver = { +static struct driver serial_sifive_driver = { .name = "serial_sifive", .probe = sifive_serial_probe, .of_compatible = sifive_serial_dt_ids, diff --git a/drivers/serial/serial_stm32.c b/drivers/serial/serial_stm32.c index f1d4c6de90..3e18a2c152 100644 --- a/drivers/serial/serial_stm32.c +++ b/drivers/serial/serial_stm32.c @@ -138,7 +138,7 @@ static void stm32_serial_init(struct console_device *cdev) writel(cr1, base + CR1_OFFSET(stm32f4)); } -static int stm32_serial_probe(struct device_d *dev) +static int stm32_serial_probe(struct device *dev) { int ret; struct console_device *cdev; @@ -165,7 +165,7 @@ static int stm32_serial_probe(struct device_d *dev) stm32->stm32f4 = info->stm32f4; stm32->uart_enable_bit = info->uart_enable_bit; - stm32->clk = clk_get(dev, NULL); + stm32->clk = clk_get_for_console(dev, NULL); if (IS_ERR(stm32->clk)) { ret = PTR_ERR(stm32->clk); dev_err(dev, "Failed to get UART clock %d\n", ret); @@ -183,11 +183,11 @@ static int stm32_serial_probe(struct device_d *dev) cdev->putc = stm32_serial_putc; cdev->getc = stm32_serial_getc; cdev->flush = stm32_serial_flush; - cdev->setbrg = stm32_serial_setbaudrate; + cdev->setbrg = stm32->clk ? stm32_serial_setbaudrate : NULL; cdev->linux_console_name = "ttySTM"; - if (dev->device_node) { - devname = of_alias_get(dev->device_node); + if (dev->of_node) { + devname = of_alias_get(dev->of_node); if (devname) { cdev->devname = xstrdup(devname); cdev->devid = DEVICE_ID_SINGLE; @@ -240,8 +240,9 @@ static struct of_device_id stm32_serial_dt_ids[] = { }, { } }; +MODULE_DEVICE_TABLE(of, stm32_serial_dt_ids); -static struct driver_d stm32_serial_driver = { +static struct driver stm32_serial_driver = { .name = "stm32-serial", .probe = stm32_serial_probe, .of_compatible = DRV_OF_COMPAT(stm32_serial_dt_ids), diff --git a/drivers/serial/stm-serial.c b/drivers/serial/stm-serial.c index b4b2c4cc8f..af30bfa71d 100644 --- a/drivers/serial/stm-serial.c +++ b/drivers/serial/stm-serial.c @@ -20,7 +20,6 @@ #include <malloc.h> #include <linux/clk.h> #include <linux/err.h> -#include <mach/clock.h> #define UARTDBGDR 0x00 #define UARTDBGFR 0x18 @@ -132,7 +131,7 @@ static int stm_serial_init_port(struct stm_priv *priv) return 0; } -static int stm_serial_probe(struct device_d *dev) +static int stm_serial_probe(struct device *dev) { struct resource *iores; struct stm_priv *priv; @@ -181,8 +180,9 @@ static __maybe_unused struct of_device_id stm_serial_dt_ids[] = { /* sentinel */ } }; +MODULE_DEVICE_TABLE(of, stm_serial_dt_ids); -static struct driver_d stm_serial_driver = { +static struct driver stm_serial_driver = { .name = "stm_serial", .probe = stm_serial_probe, .of_compatible = DRV_OF_COMPAT(stm_serial_dt_ids), |