blob: 239b006744d8deed758da95f9c41c0d59dbb48d1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rob Clarkcf7ab0c2017-08-03 12:47:00 -04002/*
3 * (C) Copyright 2017 Rob Clark
Rob Clarkcf7ab0c2017-08-03 12:47:00 -04004 */
5
Rob Clarkcf7ab0c2017-08-03 12:47:00 -04006#include <dm.h>
7#include <fdtdec.h>
8#include <fdt_support.h>
Simon Glass0f2af882020-05-10 11:40:05 -06009#include <log.h>
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040010#include <video.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040012
13static int simple_video_probe(struct udevice *dev)
14{
Simon Glassb75b15b2020-12-03 16:55:23 -070015 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040016 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Caleb Connollyca106b92024-02-16 18:38:06 +000017 ofnode node = dev_ofnode(dev);
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040018 const char *format;
Caleb Connollyca106b92024-02-16 18:38:06 +000019 int ret;
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040020 fdt_addr_t base;
21 fdt_size_t size;
Caleb Connollyca106b92024-02-16 18:38:06 +000022 u32 width, height, rot;
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040023
Caleb Connollyca106b92024-02-16 18:38:06 +000024 base = dev_read_addr_size(dev, &size);
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040025 if (base == FDT_ADDR_T_NONE) {
26 debug("%s: Failed to decode memory region\n", __func__);
27 return -EINVAL;
28 }
29
Eva Kurchatova5a08efd2024-10-09 16:48:28 +080030 debug("%s: base=%llx, size=%llu\n",
31 __func__, (unsigned long long)base, (unsigned long long)size);
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040032
33 /*
34 * TODO is there some way to reserve the framebuffer
35 * region so it isn't clobbered?
36 */
37 plat->base = base;
38 plat->size = size;
39
40 video_set_flush_dcache(dev, true);
41
42 debug("%s: Query resolution...\n", __func__);
43
Caleb Connollyca106b92024-02-16 18:38:06 +000044 ret = ofnode_read_u32(node, "width", &width);
45 ret = ret ?: ofnode_read_u32(node, "height", &height);
46 if (ret || !width || !height) {
47 log_err("%s: invalid width or height: %d\n", __func__, ret);
48 return ret ?: -EINVAL;
Takumi Suedacb029002022-09-13 18:32:42 +090049 }
Caleb Connollyca106b92024-02-16 18:38:06 +000050 ofnode_read_u32(node, "rot", &rot);
51 uc_priv->rot = rot;
52 uc_priv->xsize = width;
53 uc_priv->ysize = height;
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040054
Caleb Connollyca106b92024-02-16 18:38:06 +000055 format = ofnode_read_string(node, "format");
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040056 debug("%s: %dx%d@%s\n", __func__, uc_priv->xsize, uc_priv->ysize, format);
57
Caleb Connollyca106b92024-02-16 18:38:06 +000058 if (!format) {
59 log_err("%s: please add required property \"format\"\n", __func__);
60 return -EINVAL;
61 }
62
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040063 if (strcmp(format, "r5g6b5") == 0) {
64 uc_priv->bpix = VIDEO_BPP16;
Mark Kettenis31e9f792021-09-25 22:47:38 +020065 } else if (strcmp(format, "a8b8g8r8") == 0 ||
66 strcmp(format, "x8b8g8r8") == 0) {
67 uc_priv->bpix = VIDEO_BPP32;
68 uc_priv->format = VIDEO_X8B8G8R8;
69 } else if (strcmp(format, "a8r8g8b8") == 0 ||
70 strcmp(format, "x8r8g8b8") == 0) {
71 uc_priv->bpix = VIDEO_BPP32;
72 uc_priv->format = VIDEO_X8R8G8B8;
73 } else if (strcmp(format, "a2r10g10b10") == 0 ||
74 strcmp(format, "x2r10g10b10") == 0) {
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040075 uc_priv->bpix = VIDEO_BPP32;
Mark Kettenis31e9f792021-09-25 22:47:38 +020076 uc_priv->format = VIDEO_X2R10G10B10;
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040077 } else {
Caleb Connollyca106b92024-02-16 18:38:06 +000078 log_err("%s: invalid format: %s\n", __func__, format);
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040079 return -EINVAL;
80 }
81
82 return 0;
83}
84
85static const struct udevice_id simple_video_ids[] = {
86 { .compatible = "simple-framebuffer" },
87 { }
88};
89
90U_BOOT_DRIVER(simple_video) = {
91 .name = "simple_video",
92 .id = UCLASS_VIDEO,
93 .of_match = simple_video_ids,
94 .probe = simple_video_probe,
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040095};