blob: 0c5b40c30b8d015d0f58fa27f8165e16fc5142e0 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rob Clark971d7e62017-08-03 12:47:00 -04002/*
3 * (C) Copyright 2017 Rob Clark
Rob Clark971d7e62017-08-03 12:47:00 -04004 */
5
6#include <common.h>
7#include <dm.h>
8#include <fdtdec.h>
9#include <fdt_support.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Rob Clark971d7e62017-08-03 12:47:00 -040011#include <video.h>
12
13static int simple_video_probe(struct udevice *dev)
14{
15 struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
16 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
17 const void *blob = gd->fdt_blob;
18 const int node = dev_of_offset(dev);
19 const char *format;
20 fdt_addr_t base;
21 fdt_size_t size;
22
23 base = fdtdec_get_addr_size_auto_parent(blob, dev_of_offset(dev->parent),
24 node, "reg", 0, &size, false);
25 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
43 uc_priv->xsize = fdtdec_get_uint(blob, node, "width", 0);
44 uc_priv->ysize = fdtdec_get_uint(blob, node, "height", 0);
45 uc_priv->rot = 0;
46
47 format = fdt_getprop(blob, node, "format", NULL);
48 debug("%s: %dx%d@%s\n", __func__, uc_priv->xsize, uc_priv->ysize, format);
49
50 if (strcmp(format, "r5g6b5") == 0) {
51 uc_priv->bpix = VIDEO_BPP16;
52 } else if (strcmp(format, "a8b8g8r8") == 0) {
53 uc_priv->bpix = VIDEO_BPP32;
54 } else {
55 printf("%s: invalid format: %s\n", __func__, format);
56 return -EINVAL;
57 }
58
59 return 0;
60}
61
62static const struct udevice_id simple_video_ids[] = {
63 { .compatible = "simple-framebuffer" },
64 { }
65};
66
67U_BOOT_DRIVER(simple_video) = {
68 .name = "simple_video",
69 .id = UCLASS_VIDEO,
70 .of_match = simple_video_ids,
71 .probe = simple_video_probe,
Rob Clark971d7e62017-08-03 12:47:00 -040072};