blob: fca600691e9aa7a9dba1fe8887f99f0e73a61351 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +02002/*
3 * Simplefb device tree support
4 *
5 * (C) Copyright 2015
6 * Stephen Warren <swarren@wwwdotorg.org>
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +02007 */
8
9#include <common.h>
Simon Glass55a63072017-04-05 16:23:43 -060010#include <dm.h>
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020011#include <lcd.h>
12#include <fdt_support.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090013#include <linux/libfdt.h>
Simon Glass55a63072017-04-05 16:23:43 -060014#include <video.h>
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020015
16DECLARE_GLOBAL_DATA_PTR;
17
18static int lcd_dt_simplefb_configure_node(void *blob, int off)
19{
Simon Glassd2ed4332017-04-05 16:23:42 -060020 int xsize, ysize;
21 int bpix; /* log2 of bits per pixel */
22 const char *name;
23 ulong fb_base;
Simon Glass55a63072017-04-05 16:23:43 -060024#ifdef CONFIG_DM_VIDEO
25 struct video_uc_platdata *plat;
26 struct video_priv *uc_priv;
27 struct udevice *dev;
28 int ret;
Simon Glassd2ed4332017-04-05 16:23:42 -060029
Simon Glass55a63072017-04-05 16:23:43 -060030 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
Simon Glassd2ed4332017-04-05 16:23:42 -060040 xsize = lcd_get_pixel_width();
41 ysize = lcd_get_pixel_height();
42 bpix = LCD_BPP;
43 fb_base = gd->fb_base;
Simon Glass55a63072017-04-05 16:23:43 -060044#endif
Simon Glassd2ed4332017-04-05 16:23:42 -060045 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);
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020058}
59
60int 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
81int 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}