2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-01-19 02:52:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Google, Inc
|
|
|
|
*/
|
|
|
|
|
2021-04-27 09:02:19 +00:00
|
|
|
#define LOG_CATEGORY UCLASS_VIDEO
|
|
|
|
|
2016-01-19 02:52:15 +00:00
|
|
|
#include <common.h>
|
2020-07-03 03:12:20 +00:00
|
|
|
#include <console.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <cpu_func.h>
|
2016-01-19 02:52:15 +00:00
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2016-01-19 02:52:15 +00:00
|
|
|
#include <mapmem.h>
|
|
|
|
#include <stdio_dev.h>
|
|
|
|
#include <video.h>
|
|
|
|
#include <video_console.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2016-01-19 02:52:15 +00:00
|
|
|
#include <dm/lists.h>
|
2020-12-14 07:47:52 +00:00
|
|
|
#include <dm/device_compat.h>
|
2016-01-19 02:52:15 +00:00
|
|
|
#include <dm/device-internal.h>
|
|
|
|
#include <dm/uclass-internal.h>
|
|
|
|
#ifdef CONFIG_SANDBOX
|
|
|
|
#include <asm/sdl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Theory of operation:
|
|
|
|
*
|
|
|
|
* Before relocation each device is bound. The driver for each device must
|
2020-12-03 23:55:23 +00:00
|
|
|
* set the @align and @size values in struct video_uc_plat. This
|
2016-01-19 02:52:15 +00:00
|
|
|
* information represents the requires size and alignment of the frame buffer
|
|
|
|
* for the device. The values can be an over-estimate but cannot be too
|
|
|
|
* small. The actual values will be suppled (in the same manner) by the bind()
|
2022-03-09 19:46:00 +00:00
|
|
|
* method after relocation. Additionally driver can allocate frame buffer
|
|
|
|
* itself by setting plat->base.
|
2016-01-19 02:52:15 +00:00
|
|
|
*
|
|
|
|
* This information is then picked up by video_reserve() which works out how
|
|
|
|
* much memory is needed for all devices. This is allocated between
|
|
|
|
* gd->video_bottom and gd->video_top.
|
|
|
|
*
|
|
|
|
* After relocation the same process occurs. The driver supplies the same
|
|
|
|
* @size and @align information and this time video_post_bind() checks that
|
|
|
|
* the drivers does not overflow the allocated memory.
|
|
|
|
*
|
|
|
|
* The frame buffer address is actually set (to plat->base) in
|
|
|
|
* video_post_probe(). This function also clears the frame buffer and
|
|
|
|
* allocates a suitable text console device. This can then be used to write
|
|
|
|
* text to the video device.
|
|
|
|
*/
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2020-07-03 03:12:32 +00:00
|
|
|
/**
|
|
|
|
* struct video_uc_priv - Information for the video uclass
|
|
|
|
*
|
|
|
|
* @video_ptr: Current allocation position of the video framebuffer pointer.
|
|
|
|
* While binding devices after relocation, this points to the next
|
|
|
|
* available address to use for a device's framebuffer. It starts at
|
|
|
|
* gd->video_top and works downwards, running out of space when it hits
|
|
|
|
* gd->video_bottom.
|
|
|
|
*/
|
|
|
|
struct video_uc_priv {
|
|
|
|
ulong video_ptr;
|
|
|
|
};
|
|
|
|
|
2022-10-06 14:36:03 +00:00
|
|
|
/** struct vid_rgb - Describes a video colour */
|
|
|
|
struct vid_rgb {
|
|
|
|
u32 r;
|
|
|
|
u32 g;
|
|
|
|
u32 b;
|
|
|
|
};
|
|
|
|
|
2016-01-22 02:44:52 +00:00
|
|
|
void video_set_flush_dcache(struct udevice *dev, bool flush)
|
|
|
|
{
|
|
|
|
struct video_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
|
|
|
|
priv->flush_dcache = flush;
|
|
|
|
}
|
|
|
|
|
2023-03-10 20:47:17 +00:00
|
|
|
static ulong alloc_fb_(ulong align, ulong size, ulong *addrp)
|
|
|
|
{
|
|
|
|
ulong base;
|
|
|
|
|
|
|
|
align = align ? align : 1 << 20;
|
|
|
|
base = *addrp - size;
|
|
|
|
base &= ~(align - 1);
|
|
|
|
size = *addrp - base;
|
|
|
|
*addrp = base;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2016-01-19 02:52:15 +00:00
|
|
|
static ulong alloc_fb(struct udevice *dev, ulong *addrp)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct video_uc_plat *plat = dev_get_uclass_plat(dev);
|
2023-03-10 20:47:17 +00:00
|
|
|
ulong size;
|
|
|
|
|
|
|
|
if (!plat->size) {
|
|
|
|
if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->copy_size) {
|
|
|
|
size = alloc_fb_(plat->align, plat->copy_size, addrp);
|
|
|
|
plat->copy_base = *addrp;
|
|
|
|
return size;
|
|
|
|
}
|
2016-01-19 02:52:15 +00:00
|
|
|
|
2016-10-09 11:14:17 +00:00
|
|
|
return 0;
|
2023-03-10 20:47:17 +00:00
|
|
|
}
|
2016-10-09 11:14:17 +00:00
|
|
|
|
2022-03-09 19:46:00 +00:00
|
|
|
/* Allow drivers to allocate the frame buffer themselves */
|
|
|
|
if (plat->base)
|
|
|
|
return 0;
|
|
|
|
|
2023-03-10 20:47:17 +00:00
|
|
|
size = alloc_fb_(plat->align, plat->size, addrp);
|
|
|
|
plat->base = *addrp;
|
2016-01-19 02:52:15 +00:00
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
int video_reserve(ulong *addrp)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
ulong size;
|
|
|
|
|
|
|
|
gd->video_top = *addrp;
|
|
|
|
for (uclass_find_first_device(UCLASS_VIDEO, &dev);
|
|
|
|
dev;
|
|
|
|
uclass_find_next_device(&dev)) {
|
|
|
|
size = alloc_fb(dev, addrp);
|
|
|
|
debug("%s: Reserving %lx bytes at %lx for video device '%s'\n",
|
|
|
|
__func__, size, *addrp, dev->name);
|
|
|
|
}
|
2020-07-03 03:12:33 +00:00
|
|
|
|
|
|
|
/* Allocate space for PCI video devices in case there were not bound */
|
|
|
|
if (*addrp == gd->video_top)
|
|
|
|
*addrp -= CONFIG_VIDEO_PCI_DEFAULT_FB_SIZE;
|
|
|
|
|
2016-01-19 02:52:15 +00:00
|
|
|
gd->video_bottom = *addrp;
|
2020-05-10 20:17:01 +00:00
|
|
|
gd->fb_base = *addrp;
|
2016-01-19 02:52:15 +00:00
|
|
|
debug("Video frame buffers from %lx to %lx\n", gd->video_bottom,
|
|
|
|
gd->video_top);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-06 14:36:08 +00:00
|
|
|
int video_fill(struct udevice *dev, u32 colour)
|
2016-01-19 02:52:15 +00:00
|
|
|
{
|
|
|
|
struct video_priv *priv = dev_get_uclass_priv(dev);
|
2020-07-03 03:12:22 +00:00
|
|
|
int ret;
|
2016-01-19 02:52:15 +00:00
|
|
|
|
2018-02-08 20:47:10 +00:00
|
|
|
switch (priv->bpix) {
|
2019-12-21 01:10:37 +00:00
|
|
|
case VIDEO_BPP16:
|
|
|
|
if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
|
|
|
|
u16 *ppix = priv->fb;
|
|
|
|
u16 *end = priv->fb + priv->fb_size;
|
|
|
|
|
|
|
|
while (ppix < end)
|
2022-10-06 14:36:08 +00:00
|
|
|
*ppix++ = colour;
|
2019-12-21 01:10:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case VIDEO_BPP32:
|
|
|
|
if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
|
|
|
|
u32 *ppix = priv->fb;
|
|
|
|
u32 *end = priv->fb + priv->fb_size;
|
|
|
|
|
|
|
|
while (ppix < end)
|
2022-10-06 14:36:08 +00:00
|
|
|
*ppix++ = colour;
|
2019-12-21 01:10:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-02-08 20:47:10 +00:00
|
|
|
default:
|
2022-10-06 14:36:08 +00:00
|
|
|
memset(priv->fb, colour, priv->fb_size);
|
2018-02-08 20:47:10 +00:00
|
|
|
break;
|
2016-01-19 02:52:15 +00:00
|
|
|
}
|
2020-07-03 03:12:22 +00:00
|
|
|
ret = video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-10-01 18:22:26 +00:00
|
|
|
|
2020-12-15 14:12:09 +00:00
|
|
|
return video_sync(dev, false);
|
2016-01-19 02:52:15 +00:00
|
|
|
}
|
|
|
|
|
2022-10-06 14:36:08 +00:00
|
|
|
int video_clear(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct video_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = video_fill(dev, priv->colour_bg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-06 14:36:03 +00:00
|
|
|
static const struct vid_rgb colours[VID_COLOUR_COUNT] = {
|
|
|
|
{ 0x00, 0x00, 0x00 }, /* black */
|
|
|
|
{ 0xc0, 0x00, 0x00 }, /* red */
|
|
|
|
{ 0x00, 0xc0, 0x00 }, /* green */
|
|
|
|
{ 0xc0, 0x60, 0x00 }, /* brown */
|
|
|
|
{ 0x00, 0x00, 0xc0 }, /* blue */
|
|
|
|
{ 0xc0, 0x00, 0xc0 }, /* magenta */
|
|
|
|
{ 0x00, 0xc0, 0xc0 }, /* cyan */
|
|
|
|
{ 0xc0, 0xc0, 0xc0 }, /* light gray */
|
|
|
|
{ 0x80, 0x80, 0x80 }, /* gray */
|
|
|
|
{ 0xff, 0x00, 0x00 }, /* bright red */
|
|
|
|
{ 0x00, 0xff, 0x00 }, /* bright green */
|
|
|
|
{ 0xff, 0xff, 0x00 }, /* yellow */
|
|
|
|
{ 0x00, 0x00, 0xff }, /* bright blue */
|
|
|
|
{ 0xff, 0x00, 0xff }, /* bright magenta */
|
|
|
|
{ 0x00, 0xff, 0xff }, /* bright cyan */
|
|
|
|
{ 0xff, 0xff, 0xff }, /* white */
|
|
|
|
};
|
|
|
|
|
|
|
|
u32 video_index_to_colour(struct video_priv *priv, unsigned int idx)
|
|
|
|
{
|
|
|
|
switch (priv->bpix) {
|
|
|
|
case VIDEO_BPP16:
|
2023-02-06 00:55:32 +00:00
|
|
|
if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
|
2022-10-06 14:36:03 +00:00
|
|
|
return ((colours[idx].r >> 3) << 11) |
|
|
|
|
((colours[idx].g >> 2) << 5) |
|
|
|
|
((colours[idx].b >> 3) << 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VIDEO_BPP32:
|
2023-02-05 22:44:30 +00:00
|
|
|
if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
|
2022-10-06 14:36:03 +00:00
|
|
|
if (priv->format == VIDEO_X2R10G10B10)
|
|
|
|
return (colours[idx].r << 22) |
|
|
|
|
(colours[idx].g << 12) |
|
|
|
|
(colours[idx].b << 2);
|
|
|
|
else
|
|
|
|
return (colours[idx].r << 16) |
|
|
|
|
(colours[idx].g << 8) |
|
|
|
|
(colours[idx].b << 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For unknown bit arrangements just support
|
|
|
|
* black and white.
|
|
|
|
*/
|
|
|
|
if (idx)
|
|
|
|
return 0xffffff; /* white */
|
|
|
|
|
|
|
|
return 0x000000; /* black */
|
|
|
|
}
|
|
|
|
|
2018-11-06 22:21:36 +00:00
|
|
|
void video_set_default_colors(struct udevice *dev, bool invert)
|
2018-02-08 20:47:11 +00:00
|
|
|
{
|
2018-11-06 22:21:36 +00:00
|
|
|
struct video_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
int fore, back;
|
|
|
|
|
2019-12-21 01:10:37 +00:00
|
|
|
if (CONFIG_IS_ENABLED(SYS_WHITE_ON_BLACK)) {
|
|
|
|
/* White is used when switching to bold, use light gray here */
|
|
|
|
fore = VID_LIGHT_GRAY;
|
|
|
|
back = VID_BLACK;
|
|
|
|
} else {
|
|
|
|
fore = VID_BLACK;
|
|
|
|
back = VID_WHITE;
|
|
|
|
}
|
2018-11-06 22:21:36 +00:00
|
|
|
if (invert) {
|
|
|
|
int temp;
|
|
|
|
|
|
|
|
temp = fore;
|
|
|
|
fore = back;
|
|
|
|
back = temp;
|
|
|
|
}
|
|
|
|
priv->fg_col_idx = fore;
|
2019-03-23 01:29:56 +00:00
|
|
|
priv->bg_col_idx = back;
|
2022-10-06 14:36:03 +00:00
|
|
|
priv->colour_fg = video_index_to_colour(priv, fore);
|
|
|
|
priv->colour_bg = video_index_to_colour(priv, back);
|
2018-02-08 20:47:11 +00:00
|
|
|
}
|
|
|
|
|
2016-01-19 02:52:15 +00:00
|
|
|
/* Flush video activity to the caches */
|
2020-12-14 07:47:52 +00:00
|
|
|
int video_sync(struct udevice *vid, bool force)
|
2016-01-19 02:52:15 +00:00
|
|
|
{
|
2020-12-03 08:30:00 +00:00
|
|
|
struct video_ops *ops = video_get_ops(vid);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (ops && ops->video_sync) {
|
|
|
|
ret = ops->video_sync(vid);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-01-19 02:52:15 +00:00
|
|
|
/*
|
|
|
|
* flush_dcache_range() is declared in common.h but it seems that some
|
|
|
|
* architectures do not actually implement it. Is there a way to find
|
|
|
|
* out whether it exists? For now, ARM is safe.
|
|
|
|
*/
|
2019-05-03 13:41:00 +00:00
|
|
|
#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
|
2016-01-19 02:52:15 +00:00
|
|
|
struct video_priv *priv = dev_get_uclass_priv(vid);
|
|
|
|
|
|
|
|
if (priv->flush_dcache) {
|
|
|
|
flush_dcache_range((ulong)priv->fb,
|
2016-11-13 21:22:06 +00:00
|
|
|
ALIGN((ulong)priv->fb + priv->fb_size,
|
|
|
|
CONFIG_SYS_CACHELINE_SIZE));
|
2016-01-19 02:52:15 +00:00
|
|
|
}
|
|
|
|
#elif defined(CONFIG_VIDEO_SANDBOX_SDL)
|
|
|
|
struct video_priv *priv = dev_get_uclass_priv(vid);
|
|
|
|
static ulong last_sync;
|
|
|
|
|
2022-02-28 22:13:48 +00:00
|
|
|
if (force || get_timer(last_sync) > 100) {
|
2016-01-19 02:52:15 +00:00
|
|
|
sandbox_sdl_sync(priv->fb);
|
|
|
|
last_sync = get_timer(0);
|
|
|
|
}
|
|
|
|
#endif
|
2020-12-14 07:47:52 +00:00
|
|
|
return 0;
|
2016-01-19 02:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void video_sync_all(void)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
2020-12-14 07:47:52 +00:00
|
|
|
int ret;
|
2016-01-19 02:52:15 +00:00
|
|
|
|
|
|
|
for (uclass_find_first_device(UCLASS_VIDEO, &dev);
|
|
|
|
dev;
|
|
|
|
uclass_find_next_device(&dev)) {
|
2020-12-14 07:47:52 +00:00
|
|
|
if (device_active(dev)) {
|
|
|
|
ret = video_sync(dev, true);
|
|
|
|
if (ret)
|
|
|
|
dev_dbg(dev, "Video sync failed\n");
|
|
|
|
}
|
2016-01-19 02:52:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-15 15:32:20 +00:00
|
|
|
bool video_is_active(void)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
for (uclass_find_first_device(UCLASS_VIDEO, &dev);
|
|
|
|
dev;
|
|
|
|
uclass_find_next_device(&dev)) {
|
|
|
|
if (device_active(dev))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-19 02:52:15 +00:00
|
|
|
int video_get_xsize(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct video_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
|
|
|
|
return priv->xsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
int video_get_ysize(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct video_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
|
|
|
|
return priv->ysize;
|
|
|
|
}
|
|
|
|
|
2020-07-03 03:12:20 +00:00
|
|
|
#ifdef CONFIG_VIDEO_COPY
|
|
|
|
int video_sync_copy(struct udevice *dev, void *from, void *to)
|
|
|
|
{
|
|
|
|
struct video_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
|
|
|
|
if (priv->copy_fb) {
|
|
|
|
long offset, size;
|
|
|
|
|
|
|
|
/* Find the offset of the first byte to copy */
|
|
|
|
if ((ulong)to > (ulong)from) {
|
|
|
|
size = to - from;
|
|
|
|
offset = from - priv->fb;
|
|
|
|
} else {
|
|
|
|
size = from - to;
|
|
|
|
offset = to - priv->fb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow a bit of leeway for valid requests somewhere near the
|
|
|
|
* frame buffer
|
|
|
|
*/
|
|
|
|
if (offset < -priv->fb_size || offset > 2 * priv->fb_size) {
|
|
|
|
#ifdef DEBUG
|
2021-11-19 20:23:51 +00:00
|
|
|
char str[120];
|
2020-07-03 03:12:20 +00:00
|
|
|
|
|
|
|
snprintf(str, sizeof(str),
|
2021-11-19 20:23:51 +00:00
|
|
|
"[** FAULT sync_copy fb=%p, from=%p, to=%p, offset=%lx]",
|
2020-07-03 03:12:20 +00:00
|
|
|
priv->fb, from, to, offset);
|
|
|
|
console_puts_select_stderr(true, str);
|
|
|
|
#endif
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Silently crop the memcpy. This allows callers to avoid doing
|
|
|
|
* this themselves. It is common for the end pointer to go a
|
|
|
|
* few lines after the end of the frame buffer, since most of
|
|
|
|
* the update algorithms terminate a line after their last write
|
|
|
|
*/
|
|
|
|
if (offset + size > priv->fb_size) {
|
|
|
|
size = priv->fb_size - offset;
|
|
|
|
} else if (offset < 0) {
|
|
|
|
size += offset;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(priv->copy_fb + offset, priv->fb + offset, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-01-14 03:29:46 +00:00
|
|
|
|
|
|
|
int video_sync_copy_all(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct video_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
|
|
|
|
video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-03 03:12:20 +00:00
|
|
|
#endif
|
|
|
|
|
2021-11-19 20:24:03 +00:00
|
|
|
#define SPLASH_DECL(_name) \
|
|
|
|
extern u8 __splash_ ## _name ## _begin[]; \
|
|
|
|
extern u8 __splash_ ## _name ## _end[]
|
|
|
|
|
|
|
|
#define SPLASH_START(_name) __splash_ ## _name ## _begin
|
|
|
|
|
|
|
|
SPLASH_DECL(u_boot_logo);
|
|
|
|
|
2022-10-06 14:36:09 +00:00
|
|
|
void *video_get_u_boot_logo(void)
|
|
|
|
{
|
|
|
|
return SPLASH_START(u_boot_logo);
|
|
|
|
}
|
|
|
|
|
2021-11-19 20:24:03 +00:00
|
|
|
static int show_splash(struct udevice *dev)
|
|
|
|
{
|
|
|
|
u8 *data = SPLASH_START(u_boot_logo);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = video_bmp_display(dev, map_to_sysmem(data), -4, 4, true);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-06 14:36:18 +00:00
|
|
|
int video_default_font_height(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE))
|
|
|
|
return IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE,
|
|
|
|
CONFIG_CONSOLE_TRUETYPE_SIZE);
|
|
|
|
|
|
|
|
return vc_priv->y_charsize;
|
|
|
|
}
|
|
|
|
|
2016-01-19 02:52:15 +00:00
|
|
|
/* Set up the display ready for use */
|
|
|
|
static int video_post_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct video_uc_plat *plat = dev_get_uclass_plat(dev);
|
2016-01-19 02:52:15 +00:00
|
|
|
struct video_priv *priv = dev_get_uclass_priv(dev);
|
|
|
|
char name[30], drv[15], *str;
|
2016-01-15 01:10:48 +00:00
|
|
|
const char *drv_name = drv;
|
2016-01-19 02:52:15 +00:00
|
|
|
struct udevice *cons;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Set up the line and display size */
|
|
|
|
priv->fb = map_sysmem(plat->base, plat->size);
|
2018-11-29 22:08:52 +00:00
|
|
|
if (!priv->line_length)
|
|
|
|
priv->line_length = priv->xsize * VNBYTES(priv->bpix);
|
|
|
|
|
2016-01-19 02:52:15 +00:00
|
|
|
priv->fb_size = priv->line_length * priv->ysize;
|
|
|
|
|
2020-07-03 03:12:21 +00:00
|
|
|
if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->copy_base)
|
|
|
|
priv->copy_fb = map_sysmem(plat->copy_base, plat->size);
|
|
|
|
|
2018-02-08 20:47:11 +00:00
|
|
|
/* Set up colors */
|
2018-11-06 22:21:36 +00:00
|
|
|
video_set_default_colors(dev, false);
|
2017-08-03 16:47:01 +00:00
|
|
|
|
|
|
|
if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
|
|
|
|
video_clear(dev);
|
2016-01-19 02:52:15 +00:00
|
|
|
|
2016-01-19 02:52:17 +00:00
|
|
|
/*
|
2016-01-15 01:10:48 +00:00
|
|
|
* Create a text console device. For now we always do this, although
|
2016-01-19 02:52:17 +00:00
|
|
|
* it might be useful to support only bitmap drawing on the device
|
2016-01-15 01:10:48 +00:00
|
|
|
* for boards that don't need to display text. We create a TrueType
|
|
|
|
* console if enabled, a rotated console if the video driver requests
|
|
|
|
* it, otherwise a normal console.
|
|
|
|
*
|
|
|
|
* The console can be override by setting vidconsole_drv_name before
|
|
|
|
* probing this video driver, or in the probe() method.
|
|
|
|
*
|
|
|
|
* TrueType does not support rotation at present so fall back to the
|
|
|
|
* rotated console in that case.
|
2016-01-19 02:52:17 +00:00
|
|
|
*/
|
2016-01-15 01:10:48 +00:00
|
|
|
if (!priv->rot && IS_ENABLED(CONFIG_CONSOLE_TRUETYPE)) {
|
2016-01-15 01:10:42 +00:00
|
|
|
snprintf(name, sizeof(name), "%s.vidconsole_tt", dev->name);
|
|
|
|
strcpy(drv, "vidconsole_tt");
|
|
|
|
} else {
|
|
|
|
snprintf(name, sizeof(name), "%s.vidconsole%d", dev->name,
|
|
|
|
priv->rot);
|
|
|
|
snprintf(drv, sizeof(drv), "vidconsole%d", priv->rot);
|
|
|
|
}
|
|
|
|
|
2016-01-19 02:52:17 +00:00
|
|
|
str = strdup(name);
|
|
|
|
if (!str)
|
|
|
|
return -ENOMEM;
|
2016-01-15 01:10:48 +00:00
|
|
|
if (priv->vidconsole_drv_name)
|
|
|
|
drv_name = priv->vidconsole_drv_name;
|
|
|
|
ret = device_bind_driver(dev, drv_name, str, &cons);
|
2016-01-19 02:52:17 +00:00
|
|
|
if (ret) {
|
|
|
|
debug("%s: Cannot bind console driver\n", __func__);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-01-15 01:10:48 +00:00
|
|
|
|
2016-01-19 02:52:17 +00:00
|
|
|
ret = device_probe(cons);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: Cannot probe console driver\n", __func__);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-03-28 19:40:36 +00:00
|
|
|
if (IS_ENABLED(CONFIG_VIDEO_LOGO) &&
|
|
|
|
!IS_ENABLED(CONFIG_SPLASH_SCREEN) && !plat->hide_logo) {
|
2021-11-19 20:24:03 +00:00
|
|
|
ret = show_splash(dev);
|
|
|
|
if (ret) {
|
|
|
|
log_debug("Cannot show splash screen\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 02:52:15 +00:00
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Post-relocation, allocate memory for the frame buffer */
|
|
|
|
static int video_post_bind(struct udevice *dev)
|
|
|
|
{
|
2020-07-03 03:12:32 +00:00
|
|
|
struct video_uc_priv *uc_priv;
|
|
|
|
ulong addr;
|
2016-01-19 02:52:15 +00:00
|
|
|
ulong size;
|
|
|
|
|
|
|
|
/* Before relocation there is nothing to do here */
|
2018-04-22 13:47:48 +00:00
|
|
|
if (!(gd->flags & GD_FLG_RELOC))
|
2016-01-19 02:52:15 +00:00
|
|
|
return 0;
|
2020-07-03 03:12:32 +00:00
|
|
|
|
|
|
|
/* Set up the video pointer, if this is the first device */
|
2020-12-23 02:30:28 +00:00
|
|
|
uc_priv = uclass_get_priv(dev->uclass);
|
2020-07-03 03:12:32 +00:00
|
|
|
if (!uc_priv->video_ptr)
|
|
|
|
uc_priv->video_ptr = gd->video_top;
|
|
|
|
|
|
|
|
/* Allocate framebuffer space for this device */
|
|
|
|
addr = uc_priv->video_ptr;
|
2016-01-19 02:52:15 +00:00
|
|
|
size = alloc_fb(dev, &addr);
|
|
|
|
if (addr < gd->video_bottom) {
|
2023-02-13 15:56:34 +00:00
|
|
|
/* Device tree node may need the 'bootph-all' or
|
|
|
|
* 'bootph-some-ram' tag
|
2019-05-21 17:19:12 +00:00
|
|
|
*/
|
2016-01-19 02:52:15 +00:00
|
|
|
printf("Video device '%s' cannot allocate frame buffer memory -ensure the device is set up before relocation\n",
|
|
|
|
dev->name);
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
debug("%s: Claiming %lx bytes at %lx for video device '%s'\n",
|
|
|
|
__func__, size, addr, dev->name);
|
2020-07-03 03:12:32 +00:00
|
|
|
uc_priv->video_ptr = addr;
|
2016-01-19 02:52:15 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UCLASS_DRIVER(video) = {
|
|
|
|
.id = UCLASS_VIDEO,
|
|
|
|
.name = "video",
|
|
|
|
.flags = DM_UC_FLAG_SEQ_ALIAS,
|
|
|
|
.post_bind = video_post_bind,
|
|
|
|
.post_probe = video_post_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct video_uc_priv),
|
|
|
|
.per_device_auto = sizeof(struct video_priv),
|
2020-12-03 23:55:23 +00:00
|
|
|
.per_device_plat_auto = sizeof(struct video_uc_plat),
|
2016-01-19 02:52:15 +00:00
|
|
|
};
|