blob: 17dfe62c9dae72a0f45544a82718a8aeafb50f84 [file] [log] [blame]
Alper Nebi Yasak53f20332020-10-22 22:43:13 +03001// SPDX-License-Identifier: GPL-2.0
Simon Glasse421bb82016-01-21 19:45:05 -07002/*
3 * Copyright (c) 2015 Google, Inc
4 * Copyright 2014 Rockchip Inc.
Simon Glasse421bb82016-01-21 19:45:05 -07005 */
6
Simon Glasse421bb82016-01-21 19:45:05 -07007#include <clk.h>
8#include <display.h>
9#include <dm.h>
Arnaud Patard (Rtp)3af97be2021-03-05 11:27:54 +010010#include <dm/device_compat.h>
Simon Glasse421bb82016-01-21 19:45:05 -070011#include <edid.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glasse421bb82016-01-21 19:45:05 -070013#include <regmap.h>
Arnaud Patard (Rtp)3af97be2021-03-05 11:27:54 +010014#include <reset.h>
Simon Glasse421bb82016-01-21 19:45:05 -070015#include <syscon.h>
16#include <video.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Simon Glasse421bb82016-01-21 19:45:05 -070018#include <asm/gpio.h>
Simon Glasse421bb82016-01-21 19:45:05 -070019#include <asm/io.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080020#include <asm/arch-rockchip/clock.h>
21#include <asm/arch-rockchip/edp_rk3288.h>
22#include <asm/arch-rockchip/vop_rk3288.h>
Simon Glasse421bb82016-01-21 19:45:05 -070023#include <dm/device-internal.h>
24#include <dm/uclass-internal.h>
Arnaud Patard (Rtp)1af703c2021-03-05 11:27:49 +010025#include <efi.h>
26#include <efi_loader.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060027#include <linux/bitops.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070028#include <linux/err.h>
Simon Glasse421bb82016-01-21 19:45:05 -070029#include <power/regulator.h>
Philipp Tomsicha354c2d2017-05-31 17:59:30 +020030#include "rk_vop.h"
Simon Glasse421bb82016-01-21 19:45:05 -070031
32DECLARE_GLOBAL_DATA_PTR;
33
Philipp Tomsicha354c2d2017-05-31 17:59:30 +020034enum vop_pol {
35 HSYNC_POSITIVE = 0,
36 VSYNC_POSITIVE = 1,
37 DEN_NEGATIVE = 2,
38 DCLK_INVERT = 3
Simon Glasse421bb82016-01-21 19:45:05 -070039};
40
Jagan Tekiff2e4e22024-01-17 13:21:43 +053041static void rkvop_enable(struct udevice *dev, ulong fbbase,
Philipp Tomsicha354c2d2017-05-31 17:59:30 +020042 int fb_bits_per_pixel,
Arnaud Patard (Rtp)3af97be2021-03-05 11:27:54 +010043 const struct display_timing *edid,
44 struct reset_ctl *dclk_rst)
Simon Glasse421bb82016-01-21 19:45:05 -070045{
Jagan Tekiff2e4e22024-01-17 13:21:43 +053046 struct rk_vop_priv *priv = dev_get_priv(dev);
47 struct rk3288_vop *regs = priv->regs;
Jagan Teki8b8e5b92024-01-17 13:21:44 +053048 struct rk3288_vop *win_regs = priv->regs + priv->win_offset;
Simon Glasse421bb82016-01-21 19:45:05 -070049 u32 lb_mode;
50 u32 rgb_mode;
51 u32 hactive = edid->hactive.typ;
52 u32 vactive = edid->vactive.typ;
Arnaud Patard (Rtp)3af97be2021-03-05 11:27:54 +010053 int ret;
Simon Glasse421bb82016-01-21 19:45:05 -070054
55 writel(V_ACT_WIDTH(hactive - 1) | V_ACT_HEIGHT(vactive - 1),
Jagan Teki8b8e5b92024-01-17 13:21:44 +053056 &win_regs->win0_act_info);
Simon Glasse421bb82016-01-21 19:45:05 -070057
58 writel(V_DSP_XST(edid->hsync_len.typ + edid->hback_porch.typ) |
59 V_DSP_YST(edid->vsync_len.typ + edid->vback_porch.typ),
Jagan Teki8b8e5b92024-01-17 13:21:44 +053060 &win_regs->win0_dsp_st);
Simon Glasse421bb82016-01-21 19:45:05 -070061
62 writel(V_DSP_WIDTH(hactive - 1) |
63 V_DSP_HEIGHT(vactive - 1),
Jagan Teki8b8e5b92024-01-17 13:21:44 +053064 &win_regs->win0_dsp_info);
Simon Glasse421bb82016-01-21 19:45:05 -070065
Jagan Teki8b8e5b92024-01-17 13:21:44 +053066 clrsetbits_le32(&win_regs->win0_color_key, M_WIN0_KEY_EN | M_WIN0_KEY_COLOR,
Simon Glasse421bb82016-01-21 19:45:05 -070067 V_WIN0_KEY_EN(0) | V_WIN0_KEY_COLOR(0));
68
69 switch (fb_bits_per_pixel) {
70 case 16:
71 rgb_mode = RGB565;
Jagan Teki8b8e5b92024-01-17 13:21:44 +053072 writel(V_RGB565_VIRWIDTH(hactive), &win_regs->win0_vir);
Simon Glasse421bb82016-01-21 19:45:05 -070073 break;
74 case 24:
75 rgb_mode = RGB888;
Jagan Teki8b8e5b92024-01-17 13:21:44 +053076 writel(V_RGB888_VIRWIDTH(hactive), &win_regs->win0_vir);
Simon Glasse421bb82016-01-21 19:45:05 -070077 break;
78 case 32:
79 default:
80 rgb_mode = ARGB8888;
Jagan Teki8b8e5b92024-01-17 13:21:44 +053081 writel(V_ARGB888_VIRWIDTH(hactive), &win_regs->win0_vir);
Simon Glasse421bb82016-01-21 19:45:05 -070082 break;
83 }
84
85 if (hactive > 2560)
86 lb_mode = LB_RGB_3840X2;
87 else if (hactive > 1920)
88 lb_mode = LB_RGB_2560X4;
89 else if (hactive > 1280)
90 lb_mode = LB_RGB_1920X5;
91 else
92 lb_mode = LB_RGB_1280X8;
93
Jagan Teki8b8e5b92024-01-17 13:21:44 +053094 clrsetbits_le32(&win_regs->win0_ctrl0,
Simon Glasse421bb82016-01-21 19:45:05 -070095 M_WIN0_LB_MODE | M_WIN0_DATA_FMT | M_WIN0_EN,
96 V_WIN0_LB_MODE(lb_mode) | V_WIN0_DATA_FMT(rgb_mode) |
97 V_WIN0_EN(1));
98
Jagan Teki8b8e5b92024-01-17 13:21:44 +053099 writel(fbbase, &win_regs->win0_yrgb_mst);
Simon Glasse421bb82016-01-21 19:45:05 -0700100 writel(0x01, &regs->reg_cfg_done); /* enable reg config */
Arnaud Patard (Rtp)3af97be2021-03-05 11:27:54 +0100101
102 ret = reset_assert(dclk_rst);
103 if (ret) {
104 dev_warn(dev, "failed to assert dclk reset (ret=%d)\n", ret);
105 return;
106 }
107 udelay(20);
108
109 ret = reset_deassert(dclk_rst);
110 if (ret)
111 dev_warn(dev, "failed to deassert dclk reset (ret=%d)\n", ret);
112
Simon Glasse421bb82016-01-21 19:45:05 -0700113}
114
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200115static void rkvop_set_pin_polarity(struct udevice *dev,
116 enum vop_modes mode, u32 polarity)
Simon Glasse421bb82016-01-21 19:45:05 -0700117{
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200118 struct rkvop_driverdata *ops =
119 (struct rkvop_driverdata *)dev_get_driver_data(dev);
120
121 if (ops->set_pin_polarity)
122 ops->set_pin_polarity(dev, mode, polarity);
123}
124
125static void rkvop_enable_output(struct udevice *dev, enum vop_modes mode)
126{
127 struct rk_vop_priv *priv = dev_get_priv(dev);
128 struct rk3288_vop *regs = priv->regs;
Simon Glasse421bb82016-01-21 19:45:05 -0700129
Simon Glassd7429502017-05-31 17:57:29 -0600130 /* remove from standby */
131 clrbits_le32(&regs->sys_ctrl, V_STANDBY_EN(1));
132
Simon Glasse421bb82016-01-21 19:45:05 -0700133 switch (mode) {
134 case VOP_MODE_HDMI:
135 clrsetbits_le32(&regs->sys_ctrl, M_ALL_OUT_EN,
136 V_HDMI_OUT_EN(1));
137 break;
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200138
Simon Glasse421bb82016-01-21 19:45:05 -0700139 case VOP_MODE_EDP:
Simon Glasse421bb82016-01-21 19:45:05 -0700140 clrsetbits_le32(&regs->sys_ctrl, M_ALL_OUT_EN,
141 V_EDP_OUT_EN(1));
142 break;
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200143
Jagan Teki5023ade2020-04-02 17:11:22 +0530144#if defined(CONFIG_ROCKCHIP_RK3288)
Jacob Chen0b6aee42016-03-14 11:20:18 +0800145 case VOP_MODE_LVDS:
146 clrsetbits_le32(&regs->sys_ctrl, M_ALL_OUT_EN,
147 V_RGB_OUT_EN(1));
148 break;
Jagan Teki5023ade2020-04-02 17:11:22 +0530149#endif
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200150
Eric Gao0f494072017-05-02 18:23:52 +0800151 case VOP_MODE_MIPI:
152 clrsetbits_le32(&regs->sys_ctrl, M_ALL_OUT_EN,
153 V_MIPI_OUT_EN(1));
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200154 break;
155
156 default:
157 debug("%s: unsupported output mode %x\n", __func__, mode);
Simon Glasse421bb82016-01-21 19:45:05 -0700158 }
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200159}
Simon Glasse421bb82016-01-21 19:45:05 -0700160
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200161static void rkvop_mode_set(struct udevice *dev,
162 const struct display_timing *edid,
163 enum vop_modes mode)
164{
165 struct rk_vop_priv *priv = dev_get_priv(dev);
166 struct rk3288_vop *regs = priv->regs;
Jagan Teki026c5db2024-01-17 13:21:45 +0530167 struct rk3288_vop *dsp_regs = priv->regs + priv->dsp_offset;
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200168 struct rkvop_driverdata *data =
169 (struct rkvop_driverdata *)dev_get_driver_data(dev);
Jacob Chen0b6aee42016-03-14 11:20:18 +0800170
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200171 u32 hactive = edid->hactive.typ;
172 u32 vactive = edid->vactive.typ;
173 u32 hsync_len = edid->hsync_len.typ;
174 u32 hback_porch = edid->hback_porch.typ;
175 u32 vsync_len = edid->vsync_len.typ;
176 u32 vback_porch = edid->vback_porch.typ;
177 u32 hfront_porch = edid->hfront_porch.typ;
178 u32 vfront_porch = edid->vfront_porch.typ;
179 int mode_flags;
180 u32 pin_polarity;
181
182 pin_polarity = BIT(DCLK_INVERT);
183 if (edid->flags & DISPLAY_FLAGS_HSYNC_HIGH)
184 pin_polarity |= BIT(HSYNC_POSITIVE);
185 if (edid->flags & DISPLAY_FLAGS_VSYNC_HIGH)
186 pin_polarity |= BIT(VSYNC_POSITIVE);
187
188 rkvop_set_pin_polarity(dev, mode, pin_polarity);
189 rkvop_enable_output(dev, mode);
Simon Glasse421bb82016-01-21 19:45:05 -0700190
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200191 mode_flags = 0; /* RGB888 */
192 if ((data->features & VOP_FEATURE_OUTPUT_10BIT) &&
193 (mode == VOP_MODE_HDMI || mode == VOP_MODE_EDP))
194 mode_flags = 15; /* RGBaaa */
195
196 clrsetbits_le32(&regs->dsp_ctrl0, M_DSP_OUT_MODE,
197 V_DSP_OUT_MODE(mode_flags));
Simon Glasse421bb82016-01-21 19:45:05 -0700198
199 writel(V_HSYNC(hsync_len) |
200 V_HORPRD(hsync_len + hback_porch + hactive + hfront_porch),
Jagan Teki026c5db2024-01-17 13:21:45 +0530201 &dsp_regs->dsp_htotal_hs_end);
Simon Glasse421bb82016-01-21 19:45:05 -0700202
203 writel(V_HEAP(hsync_len + hback_porch + hactive) |
204 V_HASP(hsync_len + hback_porch),
Jagan Teki026c5db2024-01-17 13:21:45 +0530205 &dsp_regs->dsp_hact_st_end);
Simon Glasse421bb82016-01-21 19:45:05 -0700206
207 writel(V_VSYNC(vsync_len) |
208 V_VERPRD(vsync_len + vback_porch + vactive + vfront_porch),
Jagan Teki026c5db2024-01-17 13:21:45 +0530209 &dsp_regs->dsp_vtotal_vs_end);
Simon Glasse421bb82016-01-21 19:45:05 -0700210
211 writel(V_VAEP(vsync_len + vback_porch + vactive)|
212 V_VASP(vsync_len + vback_porch),
Jagan Teki026c5db2024-01-17 13:21:45 +0530213 &dsp_regs->dsp_vact_st_end);
Simon Glasse421bb82016-01-21 19:45:05 -0700214
215 writel(V_HEAP(hsync_len + hback_porch + hactive) |
216 V_HASP(hsync_len + hback_porch),
Jagan Teki026c5db2024-01-17 13:21:45 +0530217 &dsp_regs->post_dsp_hact_info);
Simon Glasse421bb82016-01-21 19:45:05 -0700218
219 writel(V_VAEP(vsync_len + vback_porch + vactive)|
220 V_VASP(vsync_len + vback_porch),
Jagan Teki026c5db2024-01-17 13:21:45 +0530221 &dsp_regs->post_dsp_vact_info);
Simon Glasse421bb82016-01-21 19:45:05 -0700222
223 writel(0x01, &regs->reg_cfg_done); /* enable reg config */
224}
225
226/**
227 * rk_display_init() - Try to enable the given display device
228 *
229 * This function performs many steps:
230 * - Finds the display device being referenced by @ep_node
231 * - Puts the VOP's ID into its uclass platform data
232 * - Probes the device to set it up
233 * - Reads the EDID timing information
234 * - Sets up the VOP clocks, etc. for the selected pixel clock and display mode
235 * - Enables the display (the display device handles this and will do different
236 * things depending on the display type)
237 * - Tells the uclass about the display resolution so that the console will
238 * appear correctly
239 *
240 * @dev: VOP device that we want to connect to the display
241 * @fbbase: Frame buffer address
Simon Glasse421bb82016-01-21 19:45:05 -0700242 * @ep_node: Device tree node to process - this is the offset of an endpoint
243 * node within the VOP's 'port' list.
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100244 * Return: 0 if OK, -ve if something went wrong
Simon Glasse421bb82016-01-21 19:45:05 -0700245 */
Philipp Tomsich13b016d2018-02-23 17:38:52 +0100246static int rk_display_init(struct udevice *dev, ulong fbbase, ofnode ep_node)
Simon Glasse421bb82016-01-21 19:45:05 -0700247{
248 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Simon Glasse421bb82016-01-21 19:45:05 -0700249 int vop_id, remote_vop_id;
Simon Glasse421bb82016-01-21 19:45:05 -0700250 struct display_timing timing;
251 struct udevice *disp;
Philipp Tomsich13b016d2018-02-23 17:38:52 +0100252 int ret;
253 u32 remote_phandle;
Simon Glasse421bb82016-01-21 19:45:05 -0700254 struct display_plat *disp_uc_plat;
Stephen Warrena9622432016-06-17 09:44:00 -0600255 struct clk clk;
Eric Gao58791c32017-05-02 18:23:53 +0800256 enum video_log2_bpp l2bpp;
Philipp Tomsich13b016d2018-02-23 17:38:52 +0100257 ofnode remote;
Arnaud Patard (Rtp)058ffd62021-03-05 11:27:46 +0100258 const char *compat;
Arnaud Patard (Rtp)3af97be2021-03-05 11:27:54 +0100259 struct reset_ctl dclk_rst;
Simon Glasse421bb82016-01-21 19:45:05 -0700260
Arnaud Patard (Rtp)6b81d6a2021-03-05 11:27:52 +0100261 debug("%s(%s, 0x%lx, %s)\n", __func__,
Philipp Tomsich13b016d2018-02-23 17:38:52 +0100262 dev_read_name(dev), fbbase, ofnode_get_name(ep_node));
263
Philipp Tomsich13b016d2018-02-23 17:38:52 +0100264 ret = ofnode_read_u32(ep_node, "remote-endpoint", &remote_phandle);
265 if (ret)
266 return ret;
267
268 remote = ofnode_get_by_phandle(remote_phandle);
269 if (!ofnode_valid(remote))
Simon Glasse421bb82016-01-21 19:45:05 -0700270 return -EINVAL;
Philipp Tomsich13b016d2018-02-23 17:38:52 +0100271 remote_vop_id = ofnode_read_u32_default(remote, "reg", -1);
Simon Glasse421bb82016-01-21 19:45:05 -0700272 debug("remote vop_id=%d\n", remote_vop_id);
273
Philipp Tomsich13b016d2018-02-23 17:38:52 +0100274 /*
275 * The remote-endpoint references into a subnode of the encoder
276 * (i.e. HDMI, MIPI, etc.) with the DTS looking something like
277 * the following (assume 'hdmi_in_vopl' to be referenced):
278 *
279 * hdmi: hdmi@ff940000 {
280 * ports {
281 * hdmi_in: port {
282 * hdmi_in_vopb: endpoint@0 { ... };
283 * hdmi_in_vopl: endpoint@1 { ... };
284 * }
285 * }
286 * }
287 *
288 * The original code had 3 steps of "walking the parent", but
289 * a much better (as in: less likely to break if the DTS
290 * changes) way of doing this is to "find the enclosing device
291 * of UCLASS_DISPLAY".
292 */
293 while (ofnode_valid(remote)) {
294 remote = ofnode_get_parent(remote);
295 if (!ofnode_valid(remote)) {
296 debug("%s(%s): no UCLASS_DISPLAY for remote-endpoint\n",
297 __func__, dev_read_name(dev));
298 return -EINVAL;
299 }
Simon Glasse421bb82016-01-21 19:45:05 -0700300
Philipp Tomsich13b016d2018-02-23 17:38:52 +0100301 uclass_find_device_by_ofnode(UCLASS_DISPLAY, remote, &disp);
302 if (disp)
303 break;
304 };
Arnaud Patard (Rtp)058ffd62021-03-05 11:27:46 +0100305 compat = ofnode_get_property(remote, "compatible", NULL);
306 if (!compat) {
307 debug("%s(%s): Failed to find compatible property\n",
308 __func__, dev_read_name(dev));
309 return -EINVAL;
310 }
Johan Jonkerab446c52023-03-15 19:33:38 +0100311 if (strstr(compat, "edp") ||
312 strstr(compat, "rk3288-dp")) {
Arnaud Patard (Rtp)058ffd62021-03-05 11:27:46 +0100313 vop_id = VOP_MODE_EDP;
314 } else if (strstr(compat, "mipi")) {
315 vop_id = VOP_MODE_MIPI;
316 } else if (strstr(compat, "hdmi")) {
317 vop_id = VOP_MODE_HDMI;
318 } else if (strstr(compat, "cdn-dp")) {
319 vop_id = VOP_MODE_DP;
320 } else if (strstr(compat, "lvds")) {
321 vop_id = VOP_MODE_LVDS;
322 } else {
323 debug("%s(%s): Failed to find vop mode for %s\n",
324 __func__, dev_read_name(dev), compat);
325 return -EINVAL;
326 }
327 debug("vop_id=%d\n", vop_id);
Simon Glasse421bb82016-01-21 19:45:05 -0700328
Simon Glass71fa5b42020-12-03 16:55:18 -0700329 disp_uc_plat = dev_get_uclass_plat(disp);
Simon Glasse421bb82016-01-21 19:45:05 -0700330 debug("Found device '%s', disp_uc_priv=%p\n", disp->name, disp_uc_plat);
Simon Glass86ad1b62016-11-13 14:22:08 -0700331 if (display_in_use(disp)) {
332 debug(" - device in use\n");
333 return -EBUSY;
334 }
335
Simon Glasse421bb82016-01-21 19:45:05 -0700336 disp_uc_plat->source_id = remote_vop_id;
337 disp_uc_plat->src_dev = dev;
338
339 ret = device_probe(disp);
340 if (ret) {
341 debug("%s: device '%s' display won't probe (ret=%d)\n",
342 __func__, dev->name, ret);
343 return ret;
344 }
345
346 ret = display_read_timing(disp, &timing);
347 if (ret) {
348 debug("%s: Failed to read timings\n", __func__);
349 return ret;
350 }
351
Simon Glass25891bc2016-11-13 14:21:56 -0700352 ret = clk_get_by_index(dev, 1, &clk);
Stephen Warrena9622432016-06-17 09:44:00 -0600353 if (!ret)
354 ret = clk_set_rate(&clk, timing.pixelclock.typ);
Eric Gao9ada0e62017-05-02 18:23:51 +0800355 if (IS_ERR_VALUE(ret)) {
Simon Glasse421bb82016-01-21 19:45:05 -0700356 debug("%s: Failed to set pixel clock: ret=%d\n", __func__, ret);
357 return ret;
358 }
359
Eric Gao58791c32017-05-02 18:23:53 +0800360 /* Set bitwidth for vop display according to vop mode */
361 switch (vop_id) {
362 case VOP_MODE_EDP:
Jagan Teki5023ade2020-04-02 17:11:22 +0530363#if defined(CONFIG_ROCKCHIP_RK3288)
Eric Gao58791c32017-05-02 18:23:53 +0800364 case VOP_MODE_LVDS:
Jagan Teki5023ade2020-04-02 17:11:22 +0530365#endif
Eric Gao58791c32017-05-02 18:23:53 +0800366 l2bpp = VIDEO_BPP16;
367 break;
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200368 case VOP_MODE_HDMI:
Eric Gao58791c32017-05-02 18:23:53 +0800369 case VOP_MODE_MIPI:
370 l2bpp = VIDEO_BPP32;
371 break;
372 default:
373 l2bpp = VIDEO_BPP16;
374 }
Simon Glasse421bb82016-01-21 19:45:05 -0700375
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200376 rkvop_mode_set(dev, &timing, vop_id);
Arnaud Patard (Rtp)3af97be2021-03-05 11:27:54 +0100377
378 ret = reset_get_by_name(dev, "dclk", &dclk_rst);
379 if (ret) {
380 dev_err(dev, "failed to get dclk reset (ret=%d)\n", ret);
381 return ret;
382 }
383
Jagan Tekiff2e4e22024-01-17 13:21:43 +0530384 rkvop_enable(dev, fbbase, 1 << l2bpp, &timing, &dclk_rst);
Simon Glasse421bb82016-01-21 19:45:05 -0700385
386 ret = display_enable(disp, 1 << l2bpp, &timing);
387 if (ret)
388 return ret;
389
390 uc_priv->xsize = timing.hactive.typ;
391 uc_priv->ysize = timing.vactive.typ;
392 uc_priv->bpix = l2bpp;
393 debug("fb=%lx, size=%d %d\n", fbbase, uc_priv->xsize, uc_priv->ysize);
394
395 return 0;
396}
397
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200398void rk_vop_probe_regulators(struct udevice *dev,
399 const char * const *names, int cnt)
400{
401 int i, ret;
402 const char *name;
403 struct udevice *reg;
404
405 for (i = 0; i < cnt; ++i) {
406 name = names[i];
407 debug("%s: probing regulator '%s'\n", dev->name, name);
408
409 ret = regulator_autoset_by_name(name, &reg);
410 if (!ret)
411 ret = regulator_set_enable(reg, true);
412 }
413}
414
415int rk_vop_probe(struct udevice *dev)
Simon Glasse421bb82016-01-21 19:45:05 -0700416{
Simon Glassb75b15b2020-12-03 16:55:23 -0700417 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Simon Glasse421bb82016-01-21 19:45:05 -0700418 struct rk_vop_priv *priv = dev_get_priv(dev);
Jagan Teki8b8e5b92024-01-17 13:21:44 +0530419 struct rkvop_driverdata *ops =
420 (struct rkvop_driverdata *)dev_get_driver_data(dev);
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200421 int ret = 0;
Philipp Tomsich13b016d2018-02-23 17:38:52 +0100422 ofnode port, node;
Arnaud Patard (Rtp)3af97be2021-03-05 11:27:54 +0100423 struct reset_ctl ahb_rst;
Simon Glasse421bb82016-01-21 19:45:05 -0700424
425 /* Before relocation we don't need to do anything */
426 if (!(gd->flags & GD_FLG_RELOC))
427 return 0;
428
Arnaud Patard (Rtp)3af97be2021-03-05 11:27:54 +0100429 ret = reset_get_by_name(dev, "ahb", &ahb_rst);
430 if (ret) {
431 dev_err(dev, "failed to get ahb reset (ret=%d)\n", ret);
432 return ret;
433 }
434
435 ret = reset_assert(&ahb_rst);
436 if (ret) {
437 dev_err(dev, "failed to assert ahb reset (ret=%d)\n", ret);
Ondrej Jirman1dd75ef2023-05-22 23:47:01 +0200438 return ret;
Arnaud Patard (Rtp)3af97be2021-03-05 11:27:54 +0100439 }
440 udelay(20);
441
442 ret = reset_deassert(&ahb_rst);
443 if (ret) {
444 dev_err(dev, "failed to deassert ahb reset (ret=%d)\n", ret);
445 return ret;
446 }
447
Arnaud Patard (Rtp)1af703c2021-03-05 11:27:49 +0100448#if defined(CONFIG_EFI_LOADER)
449 debug("Adding to EFI map %d @ %lx\n", plat->size, plat->base);
450 efi_add_memory_map(plat->base, plat->size, EFI_RESERVED_MEMORY_TYPE);
451#endif
452
Johan Jonker8d5d8e02023-03-13 01:32:04 +0100453 priv->regs = dev_read_addr_ptr(dev);
Jagan Teki8b8e5b92024-01-17 13:21:44 +0530454 priv->win_offset = ops->win_offset;
Jagan Teki026c5db2024-01-17 13:21:45 +0530455 priv->dsp_offset = ops->dsp_offset;
Simon Glasse421bb82016-01-21 19:45:05 -0700456
Simon Glasse421bb82016-01-21 19:45:05 -0700457 /*
458 * Try all the ports until we find one that works. In practice this
459 * tries EDP first if available, then HDMI.
Simon Glass86ad1b62016-11-13 14:22:08 -0700460 *
461 * Note that rockchip_vop_set_clk() always uses NPLL as the source
462 * clock so it is currently not possible to use more than one display
463 * device simultaneously.
Simon Glasse421bb82016-01-21 19:45:05 -0700464 */
Philipp Tomsich13b016d2018-02-23 17:38:52 +0100465 port = dev_read_subnode(dev, "port");
466 if (!ofnode_valid(port)) {
467 debug("%s(%s): 'port' subnode not found\n",
468 __func__, dev_read_name(dev));
Simon Glasse421bb82016-01-21 19:45:05 -0700469 return -EINVAL;
Philipp Tomsich13b016d2018-02-23 17:38:52 +0100470 }
471
472 for (node = ofnode_first_subnode(port);
473 ofnode_valid(node);
474 node = dev_read_next_subnode(node)) {
Eric Gao58791c32017-05-02 18:23:53 +0800475 ret = rk_display_init(dev, plat->base, node);
Simon Glasse421bb82016-01-21 19:45:05 -0700476 if (ret)
477 debug("Device failed: ret=%d\n", ret);
478 if (!ret)
479 break;
480 }
Simon Glass773ca822016-05-14 14:03:01 -0600481 video_set_flush_dcache(dev, 1);
Simon Glasse421bb82016-01-21 19:45:05 -0700482
483 return ret;
484}
485
Philipp Tomsicha354c2d2017-05-31 17:59:30 +0200486int rk_vop_bind(struct udevice *dev)
Simon Glasse421bb82016-01-21 19:45:05 -0700487{
Simon Glassb75b15b2020-12-03 16:55:23 -0700488 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Simon Glasse421bb82016-01-21 19:45:05 -0700489
Philipp Tomsichd3a58262017-05-31 17:59:29 +0200490 plat->size = 4 * (CONFIG_VIDEO_ROCKCHIP_MAX_XRES *
491 CONFIG_VIDEO_ROCKCHIP_MAX_YRES);
Simon Glasse421bb82016-01-21 19:45:05 -0700492
493 return 0;
494}