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 | |
| 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> |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Patrick Delaunay | e7e69a5 | 2021-11-15 16:32:19 +0100 | [diff] [blame] | 18 | static int fdt_simplefb_configure_node(void *blob, int off) |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 19 | { |
Simon Glass | d2ed433 | 2017-04-05 16:23:42 -0600 | [diff] [blame] | 20 | int xsize, ysize; |
| 21 | int bpix; /* log2 of bits per pixel */ |
| 22 | const char *name; |
| 23 | ulong fb_base; |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 24 | struct video_uc_plat *plat; |
Simon Glass | 55a6307 | 2017-04-05 16:23:43 -0600 | [diff] [blame] | 25 | struct video_priv *uc_priv; |
| 26 | struct udevice *dev; |
| 27 | int ret; |
Simon Glass | d2ed433 | 2017-04-05 16:23:42 -0600 | [diff] [blame] | 28 | |
Simon Glass | 55a6307 | 2017-04-05 16:23:43 -0600 | [diff] [blame] | 29 | ret = uclass_first_device_err(UCLASS_VIDEO, &dev); |
| 30 | if (ret) |
| 31 | return ret; |
| 32 | uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 33 | plat = dev_get_uclass_plat(dev); |
Simon Glass | 55a6307 | 2017-04-05 16:23:43 -0600 | [diff] [blame] | 34 | xsize = uc_priv->xsize; |
| 35 | ysize = uc_priv->ysize; |
| 36 | bpix = uc_priv->bpix; |
| 37 | fb_base = plat->base; |
Simon Glass | d2ed433 | 2017-04-05 16:23:42 -0600 | [diff] [blame] | 38 | switch (bpix) { |
| 39 | case 4: /* VIDEO_BPP16 */ |
| 40 | name = "r5g6b5"; |
| 41 | break; |
| 42 | case 5: /* VIDEO_BPP32 */ |
| 43 | name = "a8r8g8b8"; |
| 44 | break; |
| 45 | default: |
| 46 | return -EINVAL; |
| 47 | } |
| 48 | |
| 49 | return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize, |
| 50 | xsize * (1 << bpix) / 8, name); |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 51 | } |
| 52 | |
Patrick Delaunay | e7e69a5 | 2021-11-15 16:32:19 +0100 | [diff] [blame] | 53 | int fdt_simplefb_add_node(void *blob) |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 54 | { |
| 55 | static const char compat[] = "simple-framebuffer"; |
| 56 | static const char disabled[] = "disabled"; |
| 57 | int off, ret; |
| 58 | |
| 59 | off = fdt_add_subnode(blob, 0, "framebuffer"); |
| 60 | if (off < 0) |
| 61 | return -1; |
| 62 | |
| 63 | ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled)); |
| 64 | if (ret < 0) |
| 65 | return -1; |
| 66 | |
| 67 | ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat)); |
| 68 | if (ret < 0) |
| 69 | return -1; |
| 70 | |
Patrick Delaunay | e7e69a5 | 2021-11-15 16:32:19 +0100 | [diff] [blame] | 71 | return fdt_simplefb_configure_node(blob, off); |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Heinrich Schuchardt | adcd00a | 2023-04-03 20:46:50 +0200 | [diff] [blame] | 74 | /** |
| 75 | * fdt_simplefb_enable_existing_node() - enable simple-framebuffer DT node |
| 76 | * |
| 77 | * @blob: device-tree |
| 78 | * Return: 0 on success, non-zero otherwise |
| 79 | */ |
| 80 | static int fdt_simplefb_enable_existing_node(void *blob) |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 81 | { |
| 82 | int off; |
| 83 | |
| 84 | off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer"); |
| 85 | if (off < 0) |
| 86 | return -1; |
| 87 | |
Patrick Delaunay | e7e69a5 | 2021-11-15 16:32:19 +0100 | [diff] [blame] | 88 | return fdt_simplefb_configure_node(blob, off); |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 89 | } |
Patrick Delaunay | 774aecc | 2021-11-15 16:32:21 +0100 | [diff] [blame] | 90 | |
Simon Glass | 13c79d2 | 2023-02-05 15:44:27 -0700 | [diff] [blame] | 91 | #if IS_ENABLED(CONFIG_VIDEO) |
Patrick Delaunay | 774aecc | 2021-11-15 16:32:21 +0100 | [diff] [blame] | 92 | int fdt_simplefb_enable_and_mem_rsv(void *blob) |
| 93 | { |
| 94 | struct fdt_memory mem; |
| 95 | int ret; |
| 96 | |
| 97 | /* nothing to do when video is not active */ |
| 98 | if (!video_is_active()) |
| 99 | return 0; |
| 100 | |
| 101 | ret = fdt_simplefb_enable_existing_node(blob); |
| 102 | if (ret) |
| 103 | return ret; |
| 104 | |
| 105 | /* nothing to do when the frame buffer is not defined */ |
| 106 | if (gd->video_bottom == gd->video_top) |
| 107 | return 0; |
| 108 | |
| 109 | /* reserved with no-map tag the video buffer */ |
| 110 | mem.start = gd->video_bottom; |
| 111 | mem.end = gd->video_top - 1; |
| 112 | |
| 113 | return fdtdec_add_reserved_memory(blob, "framebuffer", &mem, NULL, 0, NULL, |
| 114 | FDTDEC_RESERVED_MEMORY_NO_MAP); |
| 115 | } |
| 116 | #endif |