blob: cb518b149cb58b53a885882d475e20a2713878f3 [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
30 debug("%s: base=%llx, size=%llu\n", __func__, base, size);
31
32 /*
33 * TODO is there some way to reserve the framebuffer
34 * region so it isn't clobbered?
35 */
36 plat->base = base;
37 plat->size = size;
38
39 video_set_flush_dcache(dev, true);
40
41 debug("%s: Query resolution...\n", __func__);
42
Caleb Connollyca106b92024-02-16 18:38:06 +000043 ret = ofnode_read_u32(node, "width", &width);
44 ret = ret ?: ofnode_read_u32(node, "height", &height);
45 if (ret || !width || !height) {
46 log_err("%s: invalid width or height: %d\n", __func__, ret);
47 return ret ?: -EINVAL;
Takumi Suedacb029002022-09-13 18:32:42 +090048 }
Caleb Connollyca106b92024-02-16 18:38:06 +000049 ofnode_read_u32(node, "rot", &rot);
50 uc_priv->rot = rot;
51 uc_priv->xsize = width;
52 uc_priv->ysize = height;
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040053
Caleb Connollyca106b92024-02-16 18:38:06 +000054 format = ofnode_read_string(node, "format");
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040055 debug("%s: %dx%d@%s\n", __func__, uc_priv->xsize, uc_priv->ysize, format);
56
Caleb Connollyca106b92024-02-16 18:38:06 +000057 if (!format) {
58 log_err("%s: please add required property \"format\"\n", __func__);
59 return -EINVAL;
60 }
61
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040062 if (strcmp(format, "r5g6b5") == 0) {
63 uc_priv->bpix = VIDEO_BPP16;
Mark Kettenis31e9f792021-09-25 22:47:38 +020064 } else if (strcmp(format, "a8b8g8r8") == 0 ||
65 strcmp(format, "x8b8g8r8") == 0) {
66 uc_priv->bpix = VIDEO_BPP32;
67 uc_priv->format = VIDEO_X8B8G8R8;
68 } else if (strcmp(format, "a8r8g8b8") == 0 ||
69 strcmp(format, "x8r8g8b8") == 0) {
70 uc_priv->bpix = VIDEO_BPP32;
71 uc_priv->format = VIDEO_X8R8G8B8;
72 } else if (strcmp(format, "a2r10g10b10") == 0 ||
73 strcmp(format, "x2r10g10b10") == 0) {
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040074 uc_priv->bpix = VIDEO_BPP32;
Mark Kettenis31e9f792021-09-25 22:47:38 +020075 uc_priv->format = VIDEO_X2R10G10B10;
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040076 } else {
Caleb Connollyca106b92024-02-16 18:38:06 +000077 log_err("%s: invalid format: %s\n", __func__, format);
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040078 return -EINVAL;
79 }
80
81 return 0;
82}
83
84static const struct udevice_id simple_video_ids[] = {
85 { .compatible = "simple-framebuffer" },
86 { }
87};
88
89U_BOOT_DRIVER(simple_video) = {
90 .name = "simple_video",
91 .id = UCLASS_VIDEO,
92 .of_match = simple_video_ids,
93 .probe = simple_video_probe,
Rob Clarkcf7ab0c2017-08-03 12:47:00 -040094};