xref: /openbmc/u-boot/drivers/video/simplefb.c (revision ecab65e4)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2017 Rob Clark
4  */
5 
6 #include <common.h>
7 #include <dm.h>
8 #include <fdtdec.h>
9 #include <fdt_support.h>
10 #include <video.h>
11 
12 static int simple_video_probe(struct udevice *dev)
13 {
14 	struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
15 	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
16 	const void *blob = gd->fdt_blob;
17 	const int node = dev_of_offset(dev);
18 	const char *format;
19 	fdt_addr_t base;
20 	fdt_size_t size;
21 
22 	base = fdtdec_get_addr_size_auto_parent(blob, dev_of_offset(dev->parent),
23 			node, "reg", 0, &size, false);
24 	if (base == FDT_ADDR_T_NONE) {
25 		debug("%s: Failed to decode memory region\n", __func__);
26 		return -EINVAL;
27 	}
28 
29 	debug("%s: base=%llx, size=%llu\n", __func__, base, size);
30 
31 	/*
32 	 * TODO is there some way to reserve the framebuffer
33 	 * region so it isn't clobbered?
34 	 */
35 	plat->base = base;
36 	plat->size = size;
37 
38 	video_set_flush_dcache(dev, true);
39 
40 	debug("%s: Query resolution...\n", __func__);
41 
42 	uc_priv->xsize = fdtdec_get_uint(blob, node, "width", 0);
43 	uc_priv->ysize = fdtdec_get_uint(blob, node, "height", 0);
44 	uc_priv->rot = 0;
45 
46 	format = fdt_getprop(blob, node, "format", NULL);
47 	debug("%s: %dx%d@%s\n", __func__, uc_priv->xsize, uc_priv->ysize, format);
48 
49 	if (strcmp(format, "r5g6b5") == 0) {
50 		uc_priv->bpix = VIDEO_BPP16;
51 	} else if (strcmp(format, "a8b8g8r8") == 0) {
52 		uc_priv->bpix = VIDEO_BPP32;
53 	} else {
54 		printf("%s: invalid format: %s\n", __func__, format);
55 		return -EINVAL;
56 	}
57 
58 	return 0;
59 }
60 
61 static const struct udevice_id simple_video_ids[] = {
62 	{ .compatible = "simple-framebuffer" },
63 	{ }
64 };
65 
66 U_BOOT_DRIVER(simple_video) = {
67 	.name	= "simple_video",
68 	.id	= UCLASS_VIDEO,
69 	.of_match = simple_video_ids,
70 	.probe	= simple_video_probe,
71 };
72