[U-Boot] [PATCH v3] serial: omap: Introduce DM specific omap serial

Derald D. Woods woods.technical at gmail.com
Tue Aug 28 03:28:11 UTC 2018


On Mon, Aug 27, 2018 at 03:55:24PM +0530, Lokesh Vutla wrote:
> Add driver model support for OMAP_SERIAL while reusing
> the functions in ns16550.c
> 
> Signed-off-by: Lokesh Vutla <lokeshvutla at ti.com>

Works for omap3-evm, omap3-beagle-xm, and am3517-evm. I captured
'dm tree' output below:

OMAP3_EVM #  dm tree
 Class      Probed  Driver      Name
----------------------------------------
 root       [ + ]   root_drive  root_driver
 gpio       [ + ]   gpio_omap   |-- gpio_omap
 gpio       [   ]   gpio_omap   |-- gpio_omap
 gpio       [   ]   gpio_omap   |-- gpio_omap
 gpio       [   ]   gpio_omap   |-- gpio_omap
 gpio       [   ]   gpio_omap   |-- gpio_omap
 gpio       [   ]   gpio_omap   |-- gpio_omap
 serial     [   ]   ns16550_se  |-- ns16550_serial
 simple_bus [ + ]   generic_si  `-- ocp at 68000000
 simple_bus [   ]   generic_si      |-- l4 at 48000000
 simple_bus [   ]   generic_si      |   `-- scm at 2000
 simple_bus [   ]   generic_si      |       `-- scm_conf at 270
 gpio       [   ]   gpio_omap       |-- gpio at 48310000
 gpio       [   ]   gpio_omap       |-- gpio at 49050000
 gpio       [   ]   gpio_omap       |-- gpio at 49052000
 gpio       [   ]   gpio_omap       |-- gpio at 49054000
 gpio       [   ]   gpio_omap       |-- gpio at 49056000
 gpio       [   ]   gpio_omap       |-- gpio at 49058000
 serial     [ + ]   omap_seria      |-- serial at 4806a000
 serial     [   ]   omap_seria      |-- serial at 4806c000
 serial     [   ]   omap_seria      |-- serial at 49020000
 spi        [   ]   omap3_spi       |-- spi at 48098000
 spi        [   ]   omap3_spi       |-- spi at 4809a000
 spi        [   ]   omap3_spi       |-- spi at 480b8000
 spi        [   ]   omap3_spi       |-- spi at 480ba000
 mmc        [ + ]   omap_hsmmc      |-- mmc at 4809c000
 blk        [   ]   mmc_blk         |   `-- mmc at 4809c000.blk
 mmc        [ + ]   omap_hsmmc      `-- mmc at 480b4000
 blk        [   ]   mmc_blk             `-- mmc at 480b4000.blk


BeagleBoard # dm tree
 Class      Probed  Driver      Name
----------------------------------------
 root       [ + ]   root_drive  root_driver
 serial     [   ]   ns16550_se  |-- ns16550_serial
 gpio       [ + ]   gpio_omap   |-- gpio_omap
 gpio       [ + ]   gpio_omap   |-- gpio_omap
 gpio       [ + ]   gpio_omap   |-- gpio_omap
 gpio       [ + ]   gpio_omap   |-- gpio_omap
 gpio       [ + ]   gpio_omap   |-- gpio_omap
 gpio       [ + ]   gpio_omap   |-- gpio_omap
 simple_bus [ + ]   generic_si  `-- ocp at 68000000
 simple_bus [   ]   generic_si      |-- l4 at 48000000
 simple_bus [   ]   generic_si      |   `-- scm at 2000
 simple_bus [   ]   generic_si      |       `-- scm_conf at 270
 gpio       [ + ]   gpio_omap       |-- gpio at 48310000
 gpio       [ + ]   gpio_omap       |-- gpio at 49050000
 gpio       [ + ]   gpio_omap       |-- gpio at 49052000
 gpio       [ + ]   gpio_omap       |-- gpio at 49054000
 gpio       [ + ]   gpio_omap       |-- gpio at 49056000
 gpio       [ + ]   gpio_omap       |-- gpio at 49058000
 serial     [   ]   omap_seria      |-- serial at 4806a000
 serial     [   ]   omap_seria      |-- serial at 4806c000
 serial     [ + ]   omap_seria      `-- serial at 49020000


AM3517_EVM # dm tree
 Class      Probed  Driver      Name
----------------------------------------
 root       [ + ]   root_drive  root_driver
 gpio       [ + ]   gpio_omap   |-- gpio_omap
 gpio       [   ]   gpio_omap   |-- gpio_omap
 gpio       [   ]   gpio_omap   |-- gpio_omap
 gpio       [   ]   gpio_omap   |-- gpio_omap
 gpio       [   ]   gpio_omap   |-- gpio_omap
 gpio       [   ]   gpio_omap   |-- gpio_omap
 simple_bus [ + ]   generic_si  `-- ocp at 68000000
 simple_bus [   ]   generic_si      |-- l4 at 48000000
 simple_bus [   ]   generic_si      |   `-- scm at 2000
 simple_bus [   ]   generic_si      |       `-- scm_conf at 270
 gpio       [   ]   gpio_omap       |-- gpio at 48310000
 gpio       [   ]   gpio_omap       |-- gpio at 49050000
 gpio       [   ]   gpio_omap       |-- gpio at 49052000
 gpio       [ + ]   gpio_omap       |-- gpio at 49054000
 gpio       [   ]   gpio_omap       |-- gpio at 49056000
 gpio       [   ]   gpio_omap       |-- gpio at 49058000
 serial     [   ]   omap_seria      |-- serial at 4806a000
 serial     [   ]   omap_seria      |-- serial at 4806c000
 serial     [ + ]   omap_seria      |-- serial at 49020000
 i2c        [   ]   i2c_omap        |-- i2c at 48070000
 i2c        [   ]   i2c_omap        |-- i2c at 48072000
 i2c        [   ]   i2c_omap        |-- i2c at 48060000
 mmc        [ + ]   omap_hsmmc      `-- mmc at 4809c000
 blk        [   ]   mmc_blk             `-- mmc at 4809c000.blk


In addition to this patch, I also applied these OMAP3 related patches:

https://patchwork.ozlabs.org/project/uboot/list/?submitter=67132

A WIP branch is here:

https://github.com/woodsts/u-boot/commits/omap3-adam-queue

Tested-by: Derald D. Woods <woods.technical at gmail.com>

> ---
> Based on the conclusion on the thread[1], added a separate driver for
> omap uart.
> 
> [1] https://patchwork.ozlabs.org/patch/944756/
> 
> Changes since v2:
> - Dropped enabling OMAP_SERIAL by default for SOC_DA8XX. 
> 
>  drivers/serial/Kconfig       |   9 +++
>  drivers/serial/Makefile      |   1 +
>  drivers/serial/ns16550.c     |  47 +------------
>  drivers/serial/serial_omap.c | 126 +++++++++++++++++++++++++++++++++++
>  4 files changed, 139 insertions(+), 44 deletions(-)
>  create mode 100644 drivers/serial/serial_omap.c
> 
> diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
> index 766e5ced03..41f43af01f 100644
> --- a/drivers/serial/Kconfig
> +++ b/drivers/serial/Kconfig
> @@ -625,6 +625,15 @@ config MSM_SERIAL
>  	  for example APQ8016 and MSM8916.
>  	  Single baudrate is supported in current implementation (115200).
>  
> +config OMAP_SERIAL
> +	bool "Support for OMAP specific UART"
> +	depends on DM_SERIAL
> +	default y if ARCH_OMAP2PLUS
> +	select SYS_NS16550
> +	help
> +	  If you have an TI based SoC and want to use the on-chip serial
> +	  port, say Y to this option. If unsure say N.
> +
>  config OWL_SERIAL
>  	bool "Actions Semi OWL UART"
>  	depends on DM_SERIAL && ARCH_OWL
> diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
> index 9fa81d855d..03dc29ee2e 100644
> --- a/drivers/serial/Makefile
> +++ b/drivers/serial/Makefile
> @@ -65,6 +65,7 @@ obj-$(CONFIG_MVEBU_A3700_UART) += serial_mvebu_a3700.o
>  obj-$(CONFIG_MPC8XX_CONS) += serial_mpc8xx.o
>  obj-$(CONFIG_NULLDEV_SERIAL) += serial_nulldev.o
>  obj-$(CONFIG_OWL_SERIAL) += serial_owl.o
> +obj-$(CONFIG_OMAP_SERIAL) += serial_omap.o
>  
>  ifndef CONFIG_SPL_BUILD
>  obj-$(CONFIG_USB_TTY) += usbtty.o
> diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
> index 9c80090aa7..f9041aa626 100644
> --- a/drivers/serial/ns16550.c
> +++ b/drivers/serial/ns16550.c
> @@ -175,7 +175,7 @@ void NS16550_init(NS16550_t com_port, int baud_divisor)
>  		;
>  
>  	serial_out(CONFIG_SYS_NS16550_IER, &com_port->ier);
> -#if defined(CONFIG_ARCH_OMAP2PLUS)
> +#if defined(CONFIG_ARCH_OMAP2PLUS) || defined(CONFIG_OMAP_SERIAL)
>  	serial_out(0x7, &com_port->mdr1);	/* mode select reset TL16C750*/
>  #endif
>  
> @@ -183,7 +183,8 @@ void NS16550_init(NS16550_t com_port, int baud_divisor)
>  	serial_out(ns16550_getfcr(com_port), &com_port->fcr);
>  	if (baud_divisor != -1)
>  		NS16550_setbrg(com_port, baud_divisor);
> -#if defined(CONFIG_ARCH_OMAP2PLUS) || defined(CONFIG_SOC_DA8XX)
> +#if defined(CONFIG_ARCH_OMAP2PLUS) || defined(CONFIG_SOC_DA8XX) || \
> +	defined(CONFIG_OMAP_SERIAL)
>  	/* /16 is proper to hit 115200 with 48MHz */
>  	serial_out(0, &com_port->mdr1);
>  #endif
> @@ -279,42 +280,6 @@ DEBUG_UART_FUNCS
>  
>  #endif
>  
> -#ifdef CONFIG_DEBUG_UART_OMAP
> -
> -#include <debug_uart.h>
> -
> -static inline void _debug_uart_init(void)
> -{
> -	struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
> -	int baud_divisor;
> -
> -	baud_divisor = ns16550_calc_divisor(com_port, CONFIG_DEBUG_UART_CLOCK,
> -					    CONFIG_BAUDRATE);
> -	serial_dout(&com_port->ier, CONFIG_SYS_NS16550_IER);
> -	serial_dout(&com_port->mdr1, 0x7);
> -	serial_dout(&com_port->mcr, UART_MCRVAL);
> -	serial_dout(&com_port->fcr, UART_FCR_DEFVAL);
> -
> -	serial_dout(&com_port->lcr, UART_LCR_BKSE | UART_LCRVAL);
> -	serial_dout(&com_port->dll, baud_divisor & 0xff);
> -	serial_dout(&com_port->dlm, (baud_divisor >> 8) & 0xff);
> -	serial_dout(&com_port->lcr, UART_LCRVAL);
> -	serial_dout(&com_port->mdr1, 0x0);
> -}
> -
> -static inline void _debug_uart_putc(int ch)
> -{
> -	struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
> -
> -	while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
> -		;
> -	serial_dout(&com_port->thr, ch);
> -}
> -
> -DEBUG_UART_FUNCS
> -
> -#endif
> -
>  #ifdef CONFIG_DM_SERIAL
>  static int ns16550_serial_putc(struct udevice *dev, const char ch)
>  {
> @@ -489,12 +454,6 @@ static const struct udevice_id ns16550_serial_ids[] = {
>  	{ .compatible = "ingenic,jz4780-uart",	.data = PORT_JZ4780  },
>  	{ .compatible = "nvidia,tegra20-uart",	.data = PORT_NS16550 },
>  	{ .compatible = "snps,dw-apb-uart",	.data = PORT_NS16550 },
> -	{ .compatible = "ti,omap2-uart",	.data = PORT_NS16550 },
> -	{ .compatible = "ti,omap3-uart",	.data = PORT_NS16550 },
> -	{ .compatible = "ti,omap4-uart",	.data = PORT_NS16550 },
> -	{ .compatible = "ti,am3352-uart",	.data = PORT_NS16550 },
> -	{ .compatible = "ti,am4372-uart",	.data = PORT_NS16550 },
> -	{ .compatible = "ti,dra742-uart",	.data = PORT_NS16550 },
>  	{}
>  };
>  #endif /* OF_CONTROL && !OF_PLATDATA */
> diff --git a/drivers/serial/serial_omap.c b/drivers/serial/serial_omap.c
> new file mode 100644
> index 0000000000..d8a047bb71
> --- /dev/null
> +++ b/drivers/serial/serial_omap.c
> @@ -0,0 +1,126 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Texas Instruments' OMAP serial driver
> + *
> + * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
> + *	Lokesh Vutla <lokeshvutla at ti.com>
> + */
> +
> +#include <common.h>
> +#include <debug_uart.h>
> +#include <dm.h>
> +#include <dt-structs.h>
> +#include <ns16550.h>
> +#include <serial.h>
> +#include <clk.h>
> +
> +#ifndef CONFIG_SYS_NS16550_CLK
> +#define CONFIG_SYS_NS16550_CLK  0
> +#endif
> +
> +#ifdef CONFIG_DEBUG_UART_OMAP
> +
> +#include <debug_uart.h>
> +
> +static inline void _debug_uart_init(void)
> +{
> +	struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
> +	int baud_divisor;
> +
> +	baud_divisor = ns16550_calc_divisor(com_port, CONFIG_DEBUG_UART_CLOCK,
> +					    CONFIG_BAUDRATE);
> +	serial_dout(&com_port->ier, CONFIG_SYS_NS16550_IER);
> +	serial_dout(&com_port->mdr1, 0x7);
> +	serial_dout(&com_port->mcr, UART_MCRVAL);
> +	serial_dout(&com_port->fcr, UART_FCR_DEFVAL);
> +
> +	serial_dout(&com_port->lcr, UART_LCR_BKSE | UART_LCRVAL);
> +	serial_dout(&com_port->dll, baud_divisor & 0xff);
> +	serial_dout(&com_port->dlm, (baud_divisor >> 8) & 0xff);
> +	serial_dout(&com_port->lcr, UART_LCRVAL);
> +	serial_dout(&com_port->mdr1, 0x0);
> +}
> +
> +static inline void _debug_uart_putc(int ch)
> +{
> +	struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
> +
> +	while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
> +		;
> +	serial_dout(&com_port->thr, ch);
> +}
> +
> +DEBUG_UART_FUNCS
> +
> +#endif
> +
> +#if CONFIG_IS_ENABLED(DM_SERIAL)
> +
> +#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
> +static int omap_serial_ofdata_to_platdata(struct udevice *dev)
> +{
> +	struct ns16550_platdata *plat = dev->platdata;
> +	fdt_addr_t addr;
> +	struct clk clk;
> +	int err;
> +
> +	/* try Processor Local Bus device first */
> +	addr = dev_read_addr(dev);
> +	if (addr == FDT_ADDR_T_NONE)
> +		return -EINVAL;
> +
> +	plat->base = (unsigned long)map_physmem(addr, 0, MAP_NOCACHE);
> +
> +	plat->reg_offset = dev_read_u32_default(dev, "reg-offset", 0);
> +	plat->reg_shift = 2;
> +
> +	err = clk_get_by_index(dev, 0, &clk);
> +	if (!err) {
> +		err = clk_get_rate(&clk);
> +		if (!IS_ERR_VALUE(err))
> +			plat->clock = err;
> +	} else if (err != -ENOENT && err != -ENODEV && err != -ENOSYS) {
> +		debug("omap serial failed to get clock\n");
> +		return err;
> +	}
> +
> +	if (!plat->clock)
> +		plat->clock = dev_read_u32_default(dev, "clock-frequency",
> +						   CONFIG_SYS_NS16550_CLK);
> +	if (!plat->clock) {
> +		debug("omap serial clock not defined\n");
> +		return -EINVAL;
> +	}
> +
> +	plat->fcr = UART_FCR_DEFVAL;
> +
> +	return 0;
> +}
> +
> +static const struct udevice_id omap_serial_ids[] = {
> +	{ .compatible = "ti,omap2-uart", },
> +	{ .compatible = "ti,omap3-uart", },
> +	{ .compatible = "ti,omap4-uart", },
> +	{ .compatible = "ti,am3352-uart", },
> +	{ .compatible = "ti,am4372-uart", },
> +	{ .compatible = "ti,dra742-uart", },
> +	{}
> +};
> +#endif /* OF_CONTROL && !OF_PLATDATA */
> +
> +#if CONFIG_IS_ENABLED(SERIAL_PRESENT)
> +U_BOOT_DRIVER(omap_serial) = {
> +	.name	= "omap_serial",
> +	.id	= UCLASS_SERIAL,
> +#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
> +	.of_match = omap_serial_ids,
> +	.ofdata_to_platdata = omap_serial_ofdata_to_platdata,
> +	.platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
> +#endif
> +	.priv_auto_alloc_size = sizeof(struct NS16550),
> +	.probe = ns16550_serial_probe,
> +	.ops	= &ns16550_serial_ops,
> +	.flags	= DM_FLAG_PRE_RELOC,
> +};
> +#endif
> +#endif /* DM_SERIAL */
> -- 
> 2.18.0
> 
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot


More information about the U-Boot mailing list