blob: 60fa263d743227c51cf7b80e0f2e7c407d7d8283 [file] [log] [blame]
Neil Armstrongadd986c2018-07-24 17:45:28 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Amlogic Meson Video Processing Unit driver
4 *
5 * Copyright (c) 2018 BayLibre, SAS.
6 * Author: Neil Armstrong <narmstrong@baylibre.com>
7 */
8
Simon Glassf74c7bd2019-10-27 09:54:03 -06009#include <common.h>
10#include <display.h>
11#include <dm.h>
Neil Armstrongadd986c2018-07-24 17:45:28 +020012#include <efi_loader.h>
Neil Armstrongadd986c2018-07-24 17:45:28 +020013#include <fdt_support.h>
Simon Glass655306c2020-05-10 11:39:58 -060014#include <part.h>
Neil Armstrongadd986c2018-07-24 17:45:28 +020015#include <linux/sizes.h>
16#include <asm/arch/mem.h>
Simon Glassf74c7bd2019-10-27 09:54:03 -060017#include <dm/device-internal.h>
18#include <dm/uclass-internal.h>
19
20#include "meson_vpu.h"
Neil Armstrongadd986c2018-07-24 17:45:28 +020021#include "meson_registers.h"
22#include "simplefb_common.h"
23
24#define MESON_VPU_OVERSCAN SZ_64K
25
26/* Static variable for use in meson_vpu_rsv_fb() */
27static struct meson_framebuffer {
28 u64 base;
29 u64 fb_size;
30 unsigned int xsize;
31 unsigned int ysize;
32 bool is_cvbs;
33} meson_fb = { 0 };
34
Simon Glassf74c7bd2019-10-27 09:54:03 -060035bool meson_vpu_is_compatible(struct meson_vpu_priv *priv,
36 enum vpu_compatible family)
37{
38 enum vpu_compatible compat = dev_get_driver_data(priv->dev);
39
40 return compat == family;
41}
42
Neil Armstrongadd986c2018-07-24 17:45:28 +020043static int meson_vpu_setup_mode(struct udevice *dev, struct udevice *disp)
44{
45 struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
46 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
47 struct display_timing timing;
48 bool is_cvbs = false;
49 int ret = 0;
50
51 if (disp) {
52 ret = display_read_timing(disp, &timing);
53 if (ret) {
54 debug("%s: Failed to read timings\n", __func__);
55 goto cvbs;
56 }
57
58 uc_priv->xsize = timing.hactive.typ;
59 uc_priv->ysize = timing.vactive.typ;
60
61 ret = display_enable(disp, 0, &timing);
62 if (ret)
63 goto cvbs;
64 } else {
65cvbs:
66 /* CVBS has a fixed 720x480i (NTSC) and 720x576i (PAL) */
67 is_cvbs = true;
68 timing.flags = DISPLAY_FLAGS_INTERLACED;
69 uc_priv->xsize = 720;
70 uc_priv->ysize = 576;
71 }
72
73 uc_priv->bpix = VPU_MAX_LOG2_BPP;
74
75 meson_fb.is_cvbs = is_cvbs;
76 meson_fb.xsize = uc_priv->xsize;
77 meson_fb.ysize = uc_priv->ysize;
78
79 /* Move the framebuffer to the end of addressable ram */
80 meson_fb.fb_size = ALIGN(meson_fb.xsize * meson_fb.ysize *
81 ((1 << VPU_MAX_LOG2_BPP) / 8) +
82 MESON_VPU_OVERSCAN, EFI_PAGE_SIZE);
83 meson_fb.base = gd->bd->bi_dram[0].start +
84 gd->bd->bi_dram[0].size - meson_fb.fb_size;
85
86 /* Override the framebuffer address */
87 uc_plat->base = meson_fb.base;
88
89 meson_vpu_setup_plane(dev, timing.flags & DISPLAY_FLAGS_INTERLACED);
90 meson_vpu_setup_venc(dev, &timing, is_cvbs);
91 meson_vpu_setup_vclk(dev, &timing, is_cvbs);
92
93 video_set_flush_dcache(dev, 1);
94
95 return 0;
96}
97
98static const struct udevice_id meson_vpu_ids[] = {
99 { .compatible = "amlogic,meson-gxbb-vpu", .data = VPU_COMPATIBLE_GXBB },
100 { .compatible = "amlogic,meson-gxl-vpu", .data = VPU_COMPATIBLE_GXL },
101 { .compatible = "amlogic,meson-gxm-vpu", .data = VPU_COMPATIBLE_GXM },
Neil Armstrongbb18f7e2019-08-30 14:09:25 +0200102 { .compatible = "amlogic,meson-g12a-vpu", .data = VPU_COMPATIBLE_G12A },
Neil Armstrongadd986c2018-07-24 17:45:28 +0200103 { }
104};
105
106static int meson_vpu_probe(struct udevice *dev)
107{
108 struct meson_vpu_priv *priv = dev_get_priv(dev);
Neil Armstrongadd986c2018-07-24 17:45:28 +0200109 struct udevice *disp;
110 int ret;
111
112 /* Before relocation we don't need to do anything */
113 if (!(gd->flags & GD_FLG_RELOC))
114 return 0;
115
116 priv->dev = dev;
117
118 priv->io_base = dev_remap_addr_index(dev, 0);
119 if (!priv->io_base)
120 return -EINVAL;
121
122 priv->hhi_base = dev_remap_addr_index(dev, 1);
123 if (!priv->hhi_base)
124 return -EINVAL;
125
126 priv->dmc_base = dev_remap_addr_index(dev, 2);
127 if (!priv->dmc_base)
128 return -EINVAL;
129
Neil Armstrongadd986c2018-07-24 17:45:28 +0200130 meson_vpu_init(dev);
131
132 /* probe the display */
133 ret = uclass_get_device(UCLASS_DISPLAY, 0, &disp);
134
135 return meson_vpu_setup_mode(dev, ret ? NULL : disp);
136}
137
138static int meson_vpu_bind(struct udevice *dev)
139{
140 struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
141
142 plat->size = VPU_MAX_WIDTH * VPU_MAX_HEIGHT *
143 (1 << VPU_MAX_LOG2_BPP) / 8;
144
145 return 0;
146}
147
148#if defined(CONFIG_VIDEO_DT_SIMPLEFB)
149static void meson_vpu_setup_simplefb(void *fdt)
150{
151 const char *pipeline = NULL;
152 u64 mem_start, mem_size;
153 int offset, ret;
154
155 if (meson_fb.is_cvbs)
156 pipeline = "vpu-cvbs";
157 else
158 pipeline = "vpu-hdmi";
159
160 offset = meson_simplefb_fdt_match(fdt, pipeline);
161 if (offset < 0) {
162 eprintf("Cannot setup simplefb: node not found\n");
163
164 /* If simplefb is missing, add it as reserved memory */
165 meson_board_add_reserved_memory(fdt, meson_fb.base,
166 meson_fb.fb_size);
167
168 return;
169 }
170
171 /*
172 * SimpleFB will try to iomap the framebuffer, so we can't use
173 * fdt_add_mem_rsv on the memory area. Instead, the FB is stored
174 * at the end of the RAM and we strip this portion from the kernel
175 * allowed region
176 */
177 mem_start = gd->bd->bi_dram[0].start;
178 mem_size = gd->bd->bi_dram[0].size - meson_fb.fb_size;
179 ret = fdt_fixup_memory_banks(fdt, &mem_start, &mem_size, 1);
180 if (ret) {
181 eprintf("Cannot setup simplefb: Error reserving memory\n");
182 return;
183 }
184
185 ret = fdt_setup_simplefb_node(fdt, offset, meson_fb.base,
186 meson_fb.xsize, meson_fb.ysize,
187 meson_fb.xsize * 4, "x8r8g8b8");
188 if (ret)
189 eprintf("Cannot setup simplefb: Error setting properties\n");
190}
191#endif
192
193void meson_vpu_rsv_fb(void *fdt)
194{
195 if (!meson_fb.base || !meson_fb.xsize || !meson_fb.ysize)
196 return;
197
198#if defined(CONFIG_EFI_LOADER)
Michael Walle282d3862020-05-17 12:29:19 +0200199 efi_add_memory_map(meson_fb.base, meson_fb.fb_size,
200 EFI_RESERVED_MEMORY_TYPE);
Neil Armstrongadd986c2018-07-24 17:45:28 +0200201#endif
202#if defined(CONFIG_VIDEO_DT_SIMPLEFB)
203 meson_vpu_setup_simplefb(fdt);
204#endif
205}
206
207U_BOOT_DRIVER(meson_vpu) = {
208 .name = "meson_vpu",
209 .id = UCLASS_VIDEO,
210 .of_match = meson_vpu_ids,
211 .probe = meson_vpu_probe,
212 .bind = meson_vpu_bind,
213 .priv_auto_alloc_size = sizeof(struct meson_vpu_priv),
Anatolij Gustschinb1e1f932020-02-17 12:36:44 +0100214 .flags = DM_FLAG_PRE_RELOC | DM_FLAG_REMOVE_WITH_PD_ON,
Neil Armstrongadd986c2018-07-24 17:45:28 +0200215};