Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2017 Rob Clark |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 4 | */ |
| 5 | |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <fdtdec.h> |
| 8 | #include <fdt_support.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 10 | #include <video.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 12 | |
| 13 | static int simple_video_probe(struct udevice *dev) |
| 14 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 15 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 16 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 17 | ofnode node = dev_ofnode(dev); |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 18 | const char *format; |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 19 | int ret; |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 20 | fdt_addr_t base; |
| 21 | fdt_size_t size; |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 22 | u32 width, height, rot; |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 23 | |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 24 | base = dev_read_addr_size(dev, &size); |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 25 | if (base == FDT_ADDR_T_NONE) { |
| 26 | debug("%s: Failed to decode memory region\n", __func__); |
| 27 | return -EINVAL; |
| 28 | } |
| 29 | |
Eva Kurchatova | 5a08efd | 2024-10-09 16:48:28 +0800 | [diff] [blame^] | 30 | debug("%s: base=%llx, size=%llu\n", |
| 31 | __func__, (unsigned long long)base, (unsigned long long)size); |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 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 | |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 44 | ret = ofnode_read_u32(node, "width", &width); |
| 45 | ret = ret ?: ofnode_read_u32(node, "height", &height); |
| 46 | if (ret || !width || !height) { |
| 47 | log_err("%s: invalid width or height: %d\n", __func__, ret); |
| 48 | return ret ?: -EINVAL; |
Takumi Sueda | cb02900 | 2022-09-13 18:32:42 +0900 | [diff] [blame] | 49 | } |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 50 | ofnode_read_u32(node, "rot", &rot); |
| 51 | uc_priv->rot = rot; |
| 52 | uc_priv->xsize = width; |
| 53 | uc_priv->ysize = height; |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 54 | |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 55 | format = ofnode_read_string(node, "format"); |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 56 | debug("%s: %dx%d@%s\n", __func__, uc_priv->xsize, uc_priv->ysize, format); |
| 57 | |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 58 | if (!format) { |
| 59 | log_err("%s: please add required property \"format\"\n", __func__); |
| 60 | return -EINVAL; |
| 61 | } |
| 62 | |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 63 | if (strcmp(format, "r5g6b5") == 0) { |
| 64 | uc_priv->bpix = VIDEO_BPP16; |
Mark Kettenis | 31e9f79 | 2021-09-25 22:47:38 +0200 | [diff] [blame] | 65 | } else if (strcmp(format, "a8b8g8r8") == 0 || |
| 66 | strcmp(format, "x8b8g8r8") == 0) { |
| 67 | uc_priv->bpix = VIDEO_BPP32; |
| 68 | uc_priv->format = VIDEO_X8B8G8R8; |
| 69 | } else if (strcmp(format, "a8r8g8b8") == 0 || |
| 70 | strcmp(format, "x8r8g8b8") == 0) { |
| 71 | uc_priv->bpix = VIDEO_BPP32; |
| 72 | uc_priv->format = VIDEO_X8R8G8B8; |
| 73 | } else if (strcmp(format, "a2r10g10b10") == 0 || |
| 74 | strcmp(format, "x2r10g10b10") == 0) { |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 75 | uc_priv->bpix = VIDEO_BPP32; |
Mark Kettenis | 31e9f79 | 2021-09-25 22:47:38 +0200 | [diff] [blame] | 76 | uc_priv->format = VIDEO_X2R10G10B10; |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 77 | } else { |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 78 | log_err("%s: invalid format: %s\n", __func__, format); |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 79 | return -EINVAL; |
| 80 | } |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | static const struct udevice_id simple_video_ids[] = { |
| 86 | { .compatible = "simple-framebuffer" }, |
| 87 | { } |
| 88 | }; |
| 89 | |
| 90 | U_BOOT_DRIVER(simple_video) = { |
| 91 | .name = "simple_video", |
| 92 | .id = UCLASS_VIDEO, |
| 93 | .of_match = simple_video_ids, |
| 94 | .probe = simple_video_probe, |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 95 | }; |