[U-Boot] [PATCH v1 1/2] WIP: serial: Introduce ->getinfo() callback

Patrice CHOTARD patrice.chotard at st.com
Mon Sep 24 07:43:53 UTC 2018


Hi Andy

On 09/22/2018 03:05 PM, Andy Shevchenko wrote:
> TBD

You forgot to add a commit message ;-)

> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
> ---
>  drivers/serial/ns16550.c       | 14 ++++++++++++++
>  drivers/serial/serial-uclass.c | 21 +++++++++++++++++++++
>  include/common.h               |  3 +++
>  include/serial.h               | 14 ++++++++++++++
>  4 files changed, 52 insertions(+)
> 
> diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
> index f9041aa626..a996446936 100644
> --- a/drivers/serial/ns16550.c
> +++ b/drivers/serial/ns16550.c
> @@ -334,6 +334,19 @@ static int ns16550_serial_setbrg(struct udevice *dev, int baudrate)
>  	return 0;
>  }
>  
> +static int ns16550_serial_getinfo(struct udevice *dev, struct serial_device_info *info)
> +{
> +	struct NS16550 *const com_port = dev_get_priv(dev);
> +	struct ns16550_platdata *plat = com_port->plat;
> +
> +	info->addr_space = 0;
> +	info->reg_width = 8;
> +	info->reg_shift = plat->reg_shift;
> +	info->reg_offset = plat->reg_offset;
> +	info->addr = plat->base;
> +	return 0;
> +}
> +
>  int ns16550_serial_probe(struct udevice *dev)
>  {
>  	struct NS16550 *const com_port = dev_get_priv(dev);
> @@ -440,6 +453,7 @@ const struct dm_serial_ops ns16550_serial_ops = {
>  	.pending = ns16550_serial_pending,
>  	.getc = ns16550_serial_getc,
>  	.setbrg = ns16550_serial_setbrg,
> +	.getinfo = ns16550_serial_getinfo,
>  };
>  
>  #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
> diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
> index ffdcae0931..4778302e8f 100644
> --- a/drivers/serial/serial-uclass.c
> +++ b/drivers/serial/serial-uclass.c
> @@ -304,6 +304,25 @@ int serial_setconfig(uint config)
>  	return 0;
>  }
>  
> +int serial_getinfo(struct serial_device_info *info)
> +{
> +	struct dm_serial_ops *ops;
> +
> +	if (!gd->cur_serial_dev)
> +		return -ENODEV;
> +
> +	if (!info)
> +		return -EINVAL;
> +
> +	info->baudrate = gd->baudrate;
> +
> +	ops = serial_get_ops(gd->cur_serial_dev);
> +	if (ops->getinfo)
> +		return ops->getinfo(gd->cur_serial_dev, info);
> +
> +	return -EINVAL;
> +}
> +
>  void serial_stdio_init(void)
>  {
>  }
> @@ -421,6 +440,8 @@ static int serial_post_probe(struct udevice *dev)
>  	if (ops->loop)
>  		ops->loop += gd->reloc_off
>  #endif
> +	if (ops->getinfo)
> +		ops->getinfo += gd->reloc_off;
>  #endif
>  	/* Set the baud rate */
>  	if (ops->setbrg) {
> diff --git a/include/common.h b/include/common.h
> index 83b3bdc58d..0479f3eac1 100644
> --- a/include/common.h
> +++ b/include/common.h
> @@ -349,6 +349,8 @@ void smp_set_core_boot_addr(unsigned long addr, int corenr);
>  void smp_kick_all_cpus(void);
>  
>  /* $(CPU)/serial.c */
> +struct serial_device_info;
> +
>  int	serial_init   (void);
>  void	serial_setbrg (void);
>  void	serial_putc   (const char);
> @@ -357,6 +359,7 @@ void	serial_puts   (const char *);
>  int	serial_getc   (void);
>  int	serial_tstc   (void);
>  int	serial_setconfig(uint config);
> +int	serial_getinfo(struct serial_device_info *info);
>  
>  /* $(CPU)/speed.c */
>  int	get_clocks (void);
> diff --git a/include/serial.h b/include/serial.h
> index 020cd392e8..c73477b079 100644
> --- a/include/serial.h
> +++ b/include/serial.h
> @@ -111,6 +111,16 @@ enum serial_stop {
>  				SERIAL_8_BITS << SERIAL_BITS_SHIFT | \
>  				SERIAL_ONE_STOP << SERIAL_STOP_SHIFT
>  
> +/* REVISIT: ACPI GAS specification implied */
> +struct serial_device_info {
> +	unsigned int baudrate;
> +	u8	addr_space; /* 0 - MMIO, 1 - IO */
> +	u8	reg_width;
> +	u8	reg_offset;
> +	u8	reg_shift;
> +	u64	addr;
> +};
> +
>  /**
>   * struct struct dm_serial_ops - Driver model serial operations
>   *
> @@ -201,6 +211,10 @@ struct dm_serial_ops {
>  	 * @return 0 if OK, -ve on error
>  	 */
>  	int (*setconfig)(struct udevice *dev, uint serial_config);
> +	/**
> +	 * getinfo() - Get serial device information
> +	 */
> +	int (*getinfo)(struct udevice *dev, struct serial_device_info *info);
>  };
>  
>  /**
> 


More information about the U-Boot mailing list