]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
033167c4 NK |
2 | /* |
3 | * Simplefb device tree support | |
4 | * | |
5 | * (C) Copyright 2015 | |
6 | * Stephen Warren <[email protected]> | |
033167c4 NK |
7 | */ |
8 | ||
9 | #include <common.h> | |
d08e42a8 | 10 | #include <dm.h> |
033167c4 NK |
11 | #include <lcd.h> |
12 | #include <fdt_support.h> | |
b08c8c48 | 13 | #include <linux/libfdt.h> |
d08e42a8 | 14 | #include <video.h> |
033167c4 NK |
15 | |
16 | DECLARE_GLOBAL_DATA_PTR; | |
17 | ||
18 | static int lcd_dt_simplefb_configure_node(void *blob, int off) | |
19 | { | |
45261455 SG |
20 | int xsize, ysize; |
21 | int bpix; /* log2 of bits per pixel */ | |
22 | const char *name; | |
23 | ulong fb_base; | |
d08e42a8 SG |
24 | #ifdef CONFIG_DM_VIDEO |
25 | struct video_uc_platdata *plat; | |
26 | struct video_priv *uc_priv; | |
27 | struct udevice *dev; | |
28 | int ret; | |
45261455 | 29 | |
d08e42a8 SG |
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 | |
45261455 SG |
40 | xsize = lcd_get_pixel_width(); |
41 | ysize = lcd_get_pixel_height(); | |
42 | bpix = LCD_BPP; | |
43 | fb_base = gd->fb_base; | |
d08e42a8 | 44 | #endif |
45261455 SG |
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); | |
033167c4 NK |
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 | } |