[U-Boot] [PATCH v2 1/5] serial: Introduce ->getinfo() callback

Simon Glass sjg at chromium.org
Thu Nov 15 19:45:32 UTC 2018


Hi Andy,

On 15 November 2018 at 09:58, Andy Shevchenko
<andriy.shevchenko at linux.intel.com> wrote:
>
> New callback will give a necessary information to fill up ACPI SPCR table,
> for example. Maybe used later for other purposes.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
> ---
>  drivers/serial/serial-uclass.c | 21 +++++++++++++++++++++
>  include/common.h               |  3 +++
>  include/serial.h               | 17 +++++++++++++++++
>  3 files changed, 41 insertions(+)
>

Seems useful to me.

Please add a test to test/dm/serial.c

> diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
> index 665cca85cb..274734d059 100644
> --- a/drivers/serial/serial-uclass.c
> +++ b/drivers/serial/serial-uclass.c
> @@ -308,6 +308,25 @@ int serial_setconfig(uint config)
>         return 0;
>  }
>
> +int serial_getinfo(struct serial_device_info *info)

This should use driver model, so:

int serial_getinfo(struct udevice *dev, 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)
>  {
>  }
> @@ -425,6 +444,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 8b9f859c07..1f9c98e735 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);

See above - please don't add any more non-DM functions.

>
>  /* $(CPU)/speed.c */
>  int    get_clocks (void);
> diff --git a/include/serial.h b/include/serial.h
> index 020cd392e8..33531b7791 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 */

Please make this an enum

> +       u8      reg_width;
> +       u8      reg_offset;
> +       u8      reg_shift;
> +       u64     addr;

ulong

Needs a struct comment as I don't know what most of these do.

What about parity, number of bits, etc?

> +};
> +
>  /**
>   * struct struct dm_serial_ops - Driver model serial operations
>   *
> @@ -201,6 +211,13 @@ struct dm_serial_ops {
>          * @return 0 if OK, -ve on error
>          */
>         int (*setconfig)(struct udevice *dev, uint serial_config);
> +       /**
> +        * getinfo() - Get serial device information
> +        *
> +        * @dev: Device pointer
> +        * @info: struct serial_device_info to fill
> +        */
> +       int (*getinfo)(struct udevice *dev, struct serial_device_info *info);

This bit looks good

>  };
>
>  /**
> --
> 2.19.1
>

Regards,
SImon


More information about the U-Boot mailing list