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