Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rob Clark | 971d7e6 | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2017 Rob Clark |
Rob Clark | 971d7e6 | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <fdtdec.h> |
| 9 | #include <fdt_support.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Rob Clark | 971d7e6 | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 11 | #include <video.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Rob Clark | 971d7e6 | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 13 | |
| 14 | static int simple_video_probe(struct udevice *dev) |
| 15 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 16 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Rob Clark | 971d7e6 | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 17 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
| 18 | const void *blob = gd->fdt_blob; |
| 19 | const int node = dev_of_offset(dev); |
| 20 | const char *format; |
| 21 | fdt_addr_t base; |
| 22 | fdt_size_t size; |
| 23 | |
| 24 | base = fdtdec_get_addr_size_auto_parent(blob, dev_of_offset(dev->parent), |
| 25 | node, "reg", 0, &size, false); |
| 26 | if (base == FDT_ADDR_T_NONE) { |
| 27 | debug("%s: Failed to decode memory region\n", __func__); |
| 28 | return -EINVAL; |
| 29 | } |
| 30 | |
| 31 | debug("%s: base=%llx, size=%llu\n", __func__, base, size); |
| 32 | |
| 33 | /* |
| 34 | * TODO is there some way to reserve the framebuffer |
| 35 | * region so it isn't clobbered? |
| 36 | */ |
| 37 | plat->base = base; |
| 38 | plat->size = size; |
| 39 | |
| 40 | video_set_flush_dcache(dev, true); |
| 41 | |
| 42 | debug("%s: Query resolution...\n", __func__); |
| 43 | |
| 44 | uc_priv->xsize = fdtdec_get_uint(blob, node, "width", 0); |
| 45 | uc_priv->ysize = fdtdec_get_uint(blob, node, "height", 0); |
Takumi Sueda | db2c8ed | 2022-09-13 18:32:42 +0900 | [diff] [blame] | 46 | uc_priv->rot = fdtdec_get_uint(blob, node, "rot", 0); |
| 47 | if (uc_priv->rot > 3) { |
| 48 | log_debug("%s: invalid rot\n", __func__); |
| 49 | return log_msg_ret("rot", -EINVAL); |
| 50 | } |
Rob Clark | 971d7e6 | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 51 | |
| 52 | format = fdt_getprop(blob, node, "format", NULL); |
| 53 | debug("%s: %dx%d@%s\n", __func__, uc_priv->xsize, uc_priv->ysize, format); |
| 54 | |
| 55 | if (strcmp(format, "r5g6b5") == 0) { |
| 56 | uc_priv->bpix = VIDEO_BPP16; |
Mark Kettenis | 2c2653d | 2021-09-25 22:47:38 +0200 | [diff] [blame] | 57 | } else if (strcmp(format, "a8b8g8r8") == 0 || |
| 58 | strcmp(format, "x8b8g8r8") == 0) { |
Rob Clark | 971d7e6 | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 59 | uc_priv->bpix = VIDEO_BPP32; |
Mark Kettenis | 2c2653d | 2021-09-25 22:47:38 +0200 | [diff] [blame] | 60 | uc_priv->format = VIDEO_X8B8G8R8; |
| 61 | } else if (strcmp(format, "a8r8g8b8") == 0 || |
| 62 | strcmp(format, "x8r8g8b8") == 0) { |
| 63 | uc_priv->bpix = VIDEO_BPP32; |
| 64 | uc_priv->format = VIDEO_X8R8G8B8; |
| 65 | } else if (strcmp(format, "a2r10g10b10") == 0 || |
| 66 | strcmp(format, "x2r10g10b10") == 0) { |
| 67 | uc_priv->bpix = VIDEO_BPP32; |
| 68 | uc_priv->format = VIDEO_X2R10G10B10; |
Rob Clark | 971d7e6 | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 69 | } else { |
| 70 | printf("%s: invalid format: %s\n", __func__, format); |
| 71 | return -EINVAL; |
| 72 | } |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static const struct udevice_id simple_video_ids[] = { |
| 78 | { .compatible = "simple-framebuffer" }, |
| 79 | { } |
| 80 | }; |
| 81 | |
| 82 | U_BOOT_DRIVER(simple_video) = { |
| 83 | .name = "simple_video", |
| 84 | .id = UCLASS_VIDEO, |
| 85 | .of_match = simple_video_ids, |
| 86 | .probe = simple_video_probe, |
Rob Clark | 971d7e6 | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 87 | }; |