Prepare v2019.07
[project/bcm63xx/u-boot.git] / common / lcd_simplefb.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Simplefb device tree support
4 *
5 * (C) Copyright 2015
6 * Stephen Warren <swarren@wwwdotorg.org>
7 */
8
9 #include <common.h>
10 #include <dm.h>
11 #include <lcd.h>
12 #include <fdt_support.h>
13 #include <linux/libfdt.h>
14 #include <video.h>
15
16 DECLARE_GLOBAL_DATA_PTR;
17
18 static int lcd_dt_simplefb_configure_node(void *blob, int off)
19 {
20 int xsize, ysize;
21 int bpix; /* log2 of bits per pixel */
22 const char *name;
23 ulong fb_base;
24 #ifdef CONFIG_DM_VIDEO
25 struct video_uc_platdata *plat;
26 struct video_priv *uc_priv;
27 struct udevice *dev;
28 int ret;
29
30 ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
31 if (ret)
32 return ret;
33 uc_priv = dev_get_uclass_priv(dev);
34 plat = dev_get_uclass_platdata(dev);
35 xsize = uc_priv->xsize;
36 ysize = uc_priv->ysize;
37 bpix = uc_priv->bpix;
38 fb_base = plat->base;
39 #else
40 xsize = lcd_get_pixel_width();
41 ysize = lcd_get_pixel_height();
42 bpix = LCD_BPP;
43 fb_base = gd->fb_base;
44 #endif
45 switch (bpix) {
46 case 4: /* VIDEO_BPP16 */
47 name = "r5g6b5";
48 break;
49 case 5: /* VIDEO_BPP32 */
50 name = "a8r8g8b8";
51 break;
52 default:
53 return -EINVAL;
54 }
55
56 return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize,
57 xsize * (1 << bpix) / 8, name);
58 }
59
60 int lcd_dt_simplefb_add_node(void *blob)
61 {
62 static const char compat[] = "simple-framebuffer";
63 static const char disabled[] = "disabled";
64 int off, ret;
65
66 off = fdt_add_subnode(blob, 0, "framebuffer");
67 if (off < 0)
68 return -1;
69
70 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
71 if (ret < 0)
72 return -1;
73
74 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
75 if (ret < 0)
76 return -1;
77
78 return lcd_dt_simplefb_configure_node(blob, off);
79 }
80
81 int lcd_dt_simplefb_enable_existing_node(void *blob)
82 {
83 int off;
84
85 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
86 if (off < 0)
87 return -1;
88
89 return lcd_dt_simplefb_configure_node(blob, off);
90 }