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 | |
| 30 | debug("%s: base=%llx, size=%llu\n", __func__, base, size); |
| 31 | |
| 32 | /* |
| 33 | * TODO is there some way to reserve the framebuffer |
| 34 | * region so it isn't clobbered? |
| 35 | */ |
| 36 | plat->base = base; |
| 37 | plat->size = size; |
| 38 | |
| 39 | video_set_flush_dcache(dev, true); |
| 40 | |
| 41 | debug("%s: Query resolution...\n", __func__); |
| 42 | |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 43 | ret = ofnode_read_u32(node, "width", &width); |
| 44 | ret = ret ?: ofnode_read_u32(node, "height", &height); |
| 45 | if (ret || !width || !height) { |
| 46 | log_err("%s: invalid width or height: %d\n", __func__, ret); |
| 47 | return ret ?: -EINVAL; |
Takumi Sueda | cb02900 | 2022-09-13 18:32:42 +0900 | [diff] [blame] | 48 | } |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 49 | ofnode_read_u32(node, "rot", &rot); |
| 50 | uc_priv->rot = rot; |
| 51 | uc_priv->xsize = width; |
| 52 | uc_priv->ysize = height; |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 53 | |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 54 | format = ofnode_read_string(node, "format"); |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 55 | debug("%s: %dx%d@%s\n", __func__, uc_priv->xsize, uc_priv->ysize, format); |
| 56 | |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 57 | if (!format) { |
| 58 | log_err("%s: please add required property \"format\"\n", __func__); |
| 59 | return -EINVAL; |
| 60 | } |
| 61 | |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 62 | if (strcmp(format, "r5g6b5") == 0) { |
| 63 | uc_priv->bpix = VIDEO_BPP16; |
Mark Kettenis | 31e9f79 | 2021-09-25 22:47:38 +0200 | [diff] [blame] | 64 | } else if (strcmp(format, "a8b8g8r8") == 0 || |
| 65 | strcmp(format, "x8b8g8r8") == 0) { |
| 66 | uc_priv->bpix = VIDEO_BPP32; |
| 67 | uc_priv->format = VIDEO_X8B8G8R8; |
| 68 | } else if (strcmp(format, "a8r8g8b8") == 0 || |
| 69 | strcmp(format, "x8r8g8b8") == 0) { |
| 70 | uc_priv->bpix = VIDEO_BPP32; |
| 71 | uc_priv->format = VIDEO_X8R8G8B8; |
| 72 | } else if (strcmp(format, "a2r10g10b10") == 0 || |
| 73 | strcmp(format, "x2r10g10b10") == 0) { |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 74 | uc_priv->bpix = VIDEO_BPP32; |
Mark Kettenis | 31e9f79 | 2021-09-25 22:47:38 +0200 | [diff] [blame] | 75 | uc_priv->format = VIDEO_X2R10G10B10; |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 76 | } else { |
Caleb Connolly | ca106b9 | 2024-02-16 18:38:06 +0000 | [diff] [blame] | 77 | log_err("%s: invalid format: %s\n", __func__, format); |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 78 | return -EINVAL; |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static const struct udevice_id simple_video_ids[] = { |
| 85 | { .compatible = "simple-framebuffer" }, |
| 86 | { } |
| 87 | }; |
| 88 | |
| 89 | U_BOOT_DRIVER(simple_video) = { |
| 90 | .name = "simple_video", |
| 91 | .id = UCLASS_VIDEO, |
| 92 | .of_match = simple_video_ids, |
| 93 | .probe = simple_video_probe, |
Rob Clark | cf7ab0c | 2017-08-03 12:47:00 -0400 | [diff] [blame] | 94 | }; |