blob: 2ba00f6d34c040d81c192636ba8df26a4b5a30d8 [file] [log] [blame]
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +02001/*
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
15DECLARE_GLOBAL_DATA_PTR;
16
17static int lcd_dt_simplefb_configure_node(void *blob, int off)
18{
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020019 int vl_col = lcd_get_pixel_width();
20 int vl_row = lcd_get_pixel_height();
Hannes Petermaierfdf7f592015-04-25 00:30:21 +020021#if LCD_BPP == LCD_COLOR16
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020022 return fdt_setup_simplefb_node(blob, off, gd->fb_base, vl_col, vl_row,
23 vl_col * 2, "r5g6b5");
Hannes Petermaierfdf7f592015-04-25 00:30:21 +020024#elif LCD_BPP == LCD_COLOR32
25 return fdt_setup_simplefb_node(blob, off, gd->fb_base, vl_col, vl_row,
26 vl_col * 4, "a8r8g8b8");
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020027#else
28 return -1;
29#endif
30}
31
32int lcd_dt_simplefb_add_node(void *blob)
33{
34 static const char compat[] = "simple-framebuffer";
35 static const char disabled[] = "disabled";
36 int off, ret;
37
38 off = fdt_add_subnode(blob, 0, "framebuffer");
39 if (off < 0)
40 return -1;
41
42 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
43 if (ret < 0)
44 return -1;
45
46 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
47 if (ret < 0)
48 return -1;
49
50 return lcd_dt_simplefb_configure_node(blob, off);
51}
52
53int lcd_dt_simplefb_enable_existing_node(void *blob)
54{
55 int off;
56
57 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
58 if (off < 0)
59 return -1;
60
61 return lcd_dt_simplefb_configure_node(blob, off);
62}