blob: 32173030ab74602bb5739fa121fb6c32251871b4 [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090014#include <linux/libfdt.h>
Simon Glass55a63072017-04-05 16:23:43 -060015#include <video.h>
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020016
17DECLARE_GLOBAL_DATA_PTR;
18
Patrick Delaunaye7e69a52021-11-15 16:32:19 +010019static int fdt_simplefb_configure_node(void *blob, int off)
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020020{
Simon Glassd2ed4332017-04-05 16:23:42 -060021 int xsize, ysize;
22 int bpix; /* log2 of bits per pixel */
23 const char *name;
24 ulong fb_base;
Simon Glass55a63072017-04-05 16:23:43 -060025#ifdef CONFIG_DM_VIDEO
Simon Glassb75b15b2020-12-03 16:55:23 -070026 struct video_uc_plat *plat;
Simon Glass55a63072017-04-05 16:23:43 -060027 struct video_priv *uc_priv;
28 struct udevice *dev;
29 int ret;
Simon Glassd2ed4332017-04-05 16:23:42 -060030
Simon Glass55a63072017-04-05 16:23:43 -060031 ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
32 if (ret)
33 return ret;
34 uc_priv = dev_get_uclass_priv(dev);
Simon Glass71fa5b42020-12-03 16:55:18 -070035 plat = dev_get_uclass_plat(dev);
Simon Glass55a63072017-04-05 16:23:43 -060036 xsize = uc_priv->xsize;
37 ysize = uc_priv->ysize;
38 bpix = uc_priv->bpix;
39 fb_base = plat->base;
40#else
Simon Glassd2ed4332017-04-05 16:23:42 -060041 xsize = lcd_get_pixel_width();
42 ysize = lcd_get_pixel_height();
43 bpix = LCD_BPP;
44 fb_base = gd->fb_base;
Simon Glass55a63072017-04-05 16:23:43 -060045#endif
Simon Glassd2ed4332017-04-05 16:23:42 -060046 switch (bpix) {
47 case 4: /* VIDEO_BPP16 */
48 name = "r5g6b5";
49 break;
50 case 5: /* VIDEO_BPP32 */
51 name = "a8r8g8b8";
52 break;
53 default:
54 return -EINVAL;
55 }
56
57 return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize,
58 xsize * (1 << bpix) / 8, name);
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020059}
60
Patrick Delaunaye7e69a52021-11-15 16:32:19 +010061int fdt_simplefb_add_node(void *blob)
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020062{
63 static const char compat[] = "simple-framebuffer";
64 static const char disabled[] = "disabled";
65 int off, ret;
66
67 off = fdt_add_subnode(blob, 0, "framebuffer");
68 if (off < 0)
69 return -1;
70
71 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
72 if (ret < 0)
73 return -1;
74
75 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
76 if (ret < 0)
77 return -1;
78
Patrick Delaunaye7e69a52021-11-15 16:32:19 +010079 return fdt_simplefb_configure_node(blob, off);
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020080}
81
Patrick Delaunaye7e69a52021-11-15 16:32:19 +010082int fdt_simplefb_enable_existing_node(void *blob)
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020083{
84 int off;
85
86 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
87 if (off < 0)
88 return -1;
89
Patrick Delaunaye7e69a52021-11-15 16:32:19 +010090 return fdt_simplefb_configure_node(blob, off);
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020091}