This will be useful in U-Boot proper, so move the code from spl_upl to the generic spl_common file.
Tweak the compatible string for serial and make sure to use the UPL values for I/O / memory, even though they currently happen to be the same as is used by U-Boot. Signed-off-by: Simon Glass <s...@chromium.org> --- boot/upl_common.c | 78 ++++++++++++++++++++++++++++++++++++++++++ common/spl/spl_upl.c | 80 ++------------------------------------------ include/upl.h | 18 ++++++++++ 3 files changed, 98 insertions(+), 78 deletions(-) diff --git a/boot/upl_common.c b/boot/upl_common.c index 69a6673a9bf..a0ed5568854 100644 --- a/boot/upl_common.c +++ b/boot/upl_common.c @@ -8,8 +8,15 @@ #define LOG_CATEGORY UCLASS_BOOTSTD +#include <dm.h> +#include <serial.h> #include <string.h> #include <upl.h> +#include <video.h> +#include <asm/global_data.h> +#include <dm/uclass-internal.h> + +DECLARE_GLOBAL_DATA_PTR; /* Names of bootmodes */ const char *const bootmode_names[UPLBM_COUNT] = { @@ -50,6 +57,77 @@ const char *const graphics_formats[UPLUS_COUNT] = { [UPLGF_ABGR64] = "a16b16g16r16", }; +int upl_add_serial(struct upl_serial *ser) +{ + struct udevice *dev = gd->cur_serial_dev; + struct serial_device_info info; + struct memregion region; + int ret; + + if (!dev) + return log_msg_ret("ser", -ENOENT); + ret = serial_getinfo(dev, &info); + if (ret) + return log_msg_ret("inf", ret); + + ser->compatible = ofnode_read_string(dev_ofnode(dev), "compatible"); + ser->clock_frequency = info.clock; + ser->current_speed = info.baudrate; + region.base = info.addr; + region.size = info.size; + if (!alist_add(&ser->reg, region)) + return -ENOMEM; + ser->reg_io_shift = info.reg_shift; + ser->reg_offset = info.reg_offset; + ser->reg_io_width = info.reg_width; + ser->virtual_reg = 0; + ser->access_type = info.addr_space == SERIAL_ADDRESS_SPACE_IO ? + UPLAT_IO : UPLAT_MMIO; + + return 0; +} + +int upl_add_graphics(struct upl_graphics *gra) +{ + struct video_uc_plat *plat; + struct video_priv *priv; + struct memregion region; + struct udevice *dev; + + uclass_find_first_device(UCLASS_VIDEO, &dev); + if (!dev || !device_active(dev)) + return log_msg_ret("vid", -ENOENT); + + plat = dev_get_uclass_plat(dev); + region.base = plat->base; + region.size = plat->size; + if (!alist_add(&gra->reg, region)) + return log_msg_ret("reg", -ENOMEM); + + priv = dev_get_uclass_priv(dev); + gra->width = priv->xsize; + gra->height = priv->ysize; + gra->stride = priv->line_length; /* private field */ + switch (priv->format) { + case VIDEO_RGBA8888: + case VIDEO_X8R8G8B8: + gra->format = UPLGF_ARGB32; + break; + case VIDEO_X8B8G8R8: + gra->format = UPLGF_ABGR32; + break; + case VIDEO_X2R10G10B10: + log_debug("device '%s': VIDEO_X2R10G10B10 not supported\n", + dev->name); + return log_msg_ret("for", -EPROTO); + case VIDEO_UNKNOWN: + log_debug("device '%s': Unknown video format\n", dev->name); + return log_msg_ret("for", -EPROTO); + } + + return 0; +} + void upl_init(struct upl *upl) { memset(upl, '\0', sizeof(struct upl)); diff --git a/common/spl/spl_upl.c b/common/spl/spl_upl.c index 81a106570b8..5c68e4ab283 100644 --- a/common/spl/spl_upl.c +++ b/common/spl/spl_upl.c @@ -12,14 +12,8 @@ #include <bloblist.h> #include <dm.h> #include <image.h> -#include <mapmem.h> -#include <serial.h> #include <spl.h> #include <upl.h> -#include <video.h> -#include <asm/global_data.h> -#include <dm/read.h> -#include <dm/uclass-internal.h> DECLARE_GLOBAL_DATA_PTR; @@ -57,76 +51,6 @@ int _upl_add_image(int node, ulong load_addr, ulong size, const char *desc) return 0; } -static int write_serial(struct upl_serial *ser) -{ - struct udevice *dev = gd->cur_serial_dev; - struct serial_device_info info; - struct memregion region; - int ret; - - if (!dev) - return log_msg_ret("ser", -ENOENT); - ret = serial_getinfo(dev, &info); - if (ret) - return log_msg_ret("inf", ret); - - ser->compatible = ofnode_read_string(dev_ofnode(dev), "compatible"); - ser->clock_frequency = info.clock; - ser->current_speed = gd->baudrate; - region.base = info.addr; - region.size = info.size; - if (!alist_add(&ser->reg, region)) - return -ENOMEM; - ser->reg_io_shift = info.reg_shift; - ser->reg_offset = info.reg_offset; - ser->reg_io_width = info.reg_width; - ser->virtual_reg = 0; - ser->access_type = info.addr_space; - - return 0; -} - -static int write_graphics(struct upl_graphics *gra) -{ - struct video_uc_plat *plat; - struct video_priv *priv; - struct memregion region; - struct udevice *dev; - - uclass_find_first_device(UCLASS_VIDEO, &dev); - if (!dev || !device_active(dev)) - return log_msg_ret("vid", -ENOENT); - - plat = dev_get_uclass_plat(dev); - region.base = plat->base; - region.size = plat->size; - if (!alist_add(&gra->reg, region)) - return log_msg_ret("reg", -ENOMEM); - - priv = dev_get_uclass_priv(dev); - gra->width = priv->xsize; - gra->height = priv->ysize; - gra->stride = priv->line_length; /* private field */ - switch (priv->format) { - case VIDEO_RGBA8888: - case VIDEO_X8R8G8B8: - gra->format = UPLGF_ARGB32; - break; - case VIDEO_X8B8G8R8: - gra->format = UPLGF_ABGR32; - break; - case VIDEO_X2R10G10B10: - log_debug("device '%s': VIDEO_X2R10G10B10 not supported\n", - dev->name); - return log_msg_ret("for", -EPROTO); - case VIDEO_UNKNOWN: - log_debug("device '%s': Unknown video format\n", dev->name); - return log_msg_ret("for", -EPROTO); - } - - return 0; -} - int spl_write_upl_handoff(struct spl_image_info *spl_image) { struct upl *upl = &s_upl; @@ -139,10 +63,10 @@ int spl_write_upl_handoff(struct spl_image_info *spl_image) upl->addr_cells = IS_ENABLED(CONFIG_PHYS_64BIT) ? 2 : 1; upl->size_cells = IS_ENABLED(CONFIG_PHYS_64BIT) ? 2 : 1; upl->bootmode = UPLBM_DEFAULT; - ret = write_serial(&upl->serial); + ret = upl_add_serial(&upl->serial); if (ret) return log_msg_ret("ser", ret); - ret = write_graphics(&upl->graphics); + ret = upl_add_graphics(&upl->graphics); if (ret && ret != -ENOENT) return log_msg_ret("gra", ret); diff --git a/include/upl.h b/include/upl.h index 9f2a6e7842d..e415130d44f 100644 --- a/include/upl.h +++ b/include/upl.h @@ -371,6 +371,24 @@ static inline int upl_add_image(const void *fit, int node, ulong load_addr, return 0; } +/** + * upl_add_serial() - Add serial information to the UPL struct + * + * Writes details about the current serial port to the UPL struct + * + * Return: 0 if OK, -ve on error + */ +int upl_add_serial(struct upl_serial *ser); + +/** + * upl_add_graphics() - Add video information to the UPL struct + * + * Writes details about the current video device to the UPL struct + * + * Return: 0 if OK, -ve on error + */ +int upl_add_graphics(struct upl_graphics *gra); + /** upl_init() - Set up a UPL struct */ void upl_init(struct upl *upl); -- 2.43.0