Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Simplefb device tree support |
| 4 | * |
| 5 | * (C) Copyright 2015 |
| 6 | * Stephen Warren <swarren@wwwdotorg.org> |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
Simon Glass | 55a6307 | 2017-04-05 16:23:43 -0600 | [diff] [blame] | 9 | #include <dm.h> |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 10 | #include <fdt_support.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 12 | #include <linux/libfdt.h> |
Simon Glass | 55a6307 | 2017-04-05 16:23:43 -0600 | [diff] [blame] | 13 | #include <video.h> |
Devarsh Thakkar | 0fbb81b | 2024-02-22 18:38:08 +0530 | [diff] [blame] | 14 | #include <spl.h> |
| 15 | #include <bloblist.h> |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Patrick Delaunay | e7e69a5 | 2021-11-15 16:32:19 +0100 | [diff] [blame] | 19 | static int fdt_simplefb_configure_node(void *blob, int off) |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 20 | { |
Simon Glass | d2ed433 | 2017-04-05 16:23:42 -0600 | [diff] [blame] | 21 | int xsize, ysize; |
| 22 | int bpix; /* log2 of bits per pixel */ |
| 23 | const char *name; |
| 24 | ulong fb_base; |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 25 | struct video_uc_plat *plat; |
Simon Glass | 55a6307 | 2017-04-05 16:23:43 -0600 | [diff] [blame] | 26 | struct video_priv *uc_priv; |
| 27 | struct udevice *dev; |
| 28 | int ret; |
Simon Glass | d2ed433 | 2017-04-05 16:23:42 -0600 | [diff] [blame] | 29 | |
Devarsh Thakkar | 0fbb81b | 2024-02-22 18:38:08 +0530 | [diff] [blame] | 30 | if (IS_ENABLED(CONFIG_SPL_VIDEO_HANDOFF) && spl_phase() > PHASE_SPL) { |
| 31 | struct video_handoff *ho; |
| 32 | |
| 33 | ho = bloblist_find(BLOBLISTT_U_BOOT_VIDEO, sizeof(*ho)); |
| 34 | if (!ho) |
| 35 | return log_msg_ret("Missing video bloblist", -ENOENT); |
| 36 | |
| 37 | xsize = ho->xsize; |
| 38 | ysize = ho->ysize; |
| 39 | bpix = ho->bpix; |
| 40 | fb_base = ho->fb; |
| 41 | } else { |
| 42 | ret = uclass_first_device_err(UCLASS_VIDEO, &dev); |
| 43 | if (ret) |
| 44 | return ret; |
| 45 | uc_priv = dev_get_uclass_priv(dev); |
| 46 | plat = dev_get_uclass_plat(dev); |
| 47 | xsize = uc_priv->xsize; |
| 48 | ysize = uc_priv->ysize; |
| 49 | bpix = uc_priv->bpix; |
| 50 | fb_base = plat->base; |
| 51 | } |
| 52 | |
Simon Glass | d2ed433 | 2017-04-05 16:23:42 -0600 | [diff] [blame] | 53 | switch (bpix) { |
| 54 | case 4: /* VIDEO_BPP16 */ |
| 55 | name = "r5g6b5"; |
| 56 | break; |
| 57 | case 5: /* VIDEO_BPP32 */ |
| 58 | name = "a8r8g8b8"; |
| 59 | break; |
| 60 | default: |
| 61 | return -EINVAL; |
| 62 | } |
| 63 | |
| 64 | return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize, |
| 65 | xsize * (1 << bpix) / 8, name); |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 66 | } |
| 67 | |
Patrick Delaunay | e7e69a5 | 2021-11-15 16:32:19 +0100 | [diff] [blame] | 68 | int fdt_simplefb_add_node(void *blob) |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 69 | { |
| 70 | static const char compat[] = "simple-framebuffer"; |
| 71 | static const char disabled[] = "disabled"; |
| 72 | int off, ret; |
| 73 | |
| 74 | off = fdt_add_subnode(blob, 0, "framebuffer"); |
| 75 | if (off < 0) |
| 76 | return -1; |
| 77 | |
| 78 | ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled)); |
| 79 | if (ret < 0) |
| 80 | return -1; |
| 81 | |
| 82 | ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat)); |
| 83 | if (ret < 0) |
| 84 | return -1; |
| 85 | |
Patrick Delaunay | e7e69a5 | 2021-11-15 16:32:19 +0100 | [diff] [blame] | 86 | return fdt_simplefb_configure_node(blob, off); |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Heinrich Schuchardt | adcd00a | 2023-04-03 20:46:50 +0200 | [diff] [blame] | 89 | /** |
| 90 | * fdt_simplefb_enable_existing_node() - enable simple-framebuffer DT node |
| 91 | * |
| 92 | * @blob: device-tree |
| 93 | * Return: 0 on success, non-zero otherwise |
| 94 | */ |
| 95 | static int fdt_simplefb_enable_existing_node(void *blob) |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 96 | { |
| 97 | int off; |
| 98 | |
| 99 | off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer"); |
| 100 | if (off < 0) |
| 101 | return -1; |
| 102 | |
Patrick Delaunay | e7e69a5 | 2021-11-15 16:32:19 +0100 | [diff] [blame] | 103 | return fdt_simplefb_configure_node(blob, off); |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 104 | } |
Patrick Delaunay | 774aecc | 2021-11-15 16:32:21 +0100 | [diff] [blame] | 105 | |
Simon Glass | 13c79d2 | 2023-02-05 15:44:27 -0700 | [diff] [blame] | 106 | #if IS_ENABLED(CONFIG_VIDEO) |
Patrick Delaunay | 774aecc | 2021-11-15 16:32:21 +0100 | [diff] [blame] | 107 | int fdt_simplefb_enable_and_mem_rsv(void *blob) |
| 108 | { |
Patrick Delaunay | 774aecc | 2021-11-15 16:32:21 +0100 | [diff] [blame] | 109 | int ret; |
| 110 | |
| 111 | /* nothing to do when video is not active */ |
| 112 | if (!video_is_active()) |
| 113 | return 0; |
| 114 | |
| 115 | ret = fdt_simplefb_enable_existing_node(blob); |
| 116 | if (ret) |
| 117 | return ret; |
| 118 | |
Devarsh Thakkar | 3119989 | 2024-02-22 18:38:10 +0530 | [diff] [blame] | 119 | return fdt_add_fb_mem_rsv(blob); |
Patrick Delaunay | 774aecc | 2021-11-15 16:32:21 +0100 | [diff] [blame] | 120 | } |
| 121 | #endif |