]> git.sur5r.net Git - u-boot/blob - common/lcd_simplefb.c
dm: video: Refactor lcd_simplefb to prepare for driver model
[u-boot] / common / lcd_simplefb.c
1 /*
2  * Simplefb device tree support
3  *
4  * (C) Copyright 2015
5  * Stephen Warren <swarren@wwwdotorg.org>
6  *
7  * SPDX-License-Identifier:     GPL-2.0+
8  */
9
10 #include <common.h>
11 #include <lcd.h>
12 #include <fdt_support.h>
13 #include <libfdt.h>
14
15 DECLARE_GLOBAL_DATA_PTR;
16
17 static int lcd_dt_simplefb_configure_node(void *blob, int off)
18 {
19         int xsize, ysize;
20         int bpix; /* log2 of bits per pixel */
21         const char *name;
22         ulong fb_base;
23
24         xsize = lcd_get_pixel_width();
25         ysize = lcd_get_pixel_height();
26         bpix = LCD_BPP;
27         fb_base = gd->fb_base;
28         switch (bpix) {
29         case 4: /* VIDEO_BPP16 */
30                 name = "r5g6b5";
31                 break;
32         case 5: /* VIDEO_BPP32 */
33                 name = "a8r8g8b8";
34                 break;
35         default:
36                 return -EINVAL;
37         }
38
39         return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize,
40                                        xsize * (1 << bpix) / 8, name);
41 }
42
43 int lcd_dt_simplefb_add_node(void *blob)
44 {
45         static const char compat[] = "simple-framebuffer";
46         static const char disabled[] = "disabled";
47         int off, ret;
48
49         off = fdt_add_subnode(blob, 0, "framebuffer");
50         if (off < 0)
51                 return -1;
52
53         ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
54         if (ret < 0)
55                 return -1;
56
57         ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
58         if (ret < 0)
59                 return -1;
60
61         return lcd_dt_simplefb_configure_node(blob, off);
62 }
63
64 int lcd_dt_simplefb_enable_existing_node(void *blob)
65 {
66         int off;
67
68         off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
69         if (off < 0)
70                 return -1;
71
72         return lcd_dt_simplefb_configure_node(blob, off);
73 }