Alper Nebi Yasak | 53f2033 | 2020-10-22 22:43:13 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * Copyright 2014 Rockchip Inc. |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <clk.h> |
| 9 | #include <display.h> |
| 10 | #include <dm.h> |
Arnaud Patard (Rtp) | 3af97be | 2021-03-05 11:27:54 +0100 | [diff] [blame] | 11 | #include <dm/device_compat.h> |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 12 | #include <edid.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 14 | #include <regmap.h> |
Arnaud Patard (Rtp) | 3af97be | 2021-03-05 11:27:54 +0100 | [diff] [blame] | 15 | #include <reset.h> |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 16 | #include <syscon.h> |
| 17 | #include <video.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 18 | #include <asm/global_data.h> |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 19 | #include <asm/gpio.h> |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 20 | #include <asm/io.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 21 | #include <asm/arch-rockchip/clock.h> |
| 22 | #include <asm/arch-rockchip/edp_rk3288.h> |
| 23 | #include <asm/arch-rockchip/vop_rk3288.h> |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 24 | #include <dm/device-internal.h> |
| 25 | #include <dm/uclass-internal.h> |
Arnaud Patard (Rtp) | 1af703c | 2021-03-05 11:27:49 +0100 | [diff] [blame] | 26 | #include <efi.h> |
| 27 | #include <efi_loader.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 28 | #include <linux/bitops.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 29 | #include <linux/err.h> |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 30 | #include <power/regulator.h> |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 31 | #include "rk_vop.h" |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 35 | enum vop_pol { |
| 36 | HSYNC_POSITIVE = 0, |
| 37 | VSYNC_POSITIVE = 1, |
| 38 | DEN_NEGATIVE = 2, |
| 39 | DCLK_INVERT = 3 |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Jagan Teki | ff2e4e2 | 2024-01-17 13:21:43 +0530 | [diff] [blame] | 42 | static void rkvop_enable(struct udevice *dev, ulong fbbase, |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 43 | int fb_bits_per_pixel, |
Arnaud Patard (Rtp) | 3af97be | 2021-03-05 11:27:54 +0100 | [diff] [blame] | 44 | const struct display_timing *edid, |
| 45 | struct reset_ctl *dclk_rst) |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 46 | { |
Jagan Teki | ff2e4e2 | 2024-01-17 13:21:43 +0530 | [diff] [blame] | 47 | struct rk_vop_priv *priv = dev_get_priv(dev); |
| 48 | struct rk3288_vop *regs = priv->regs; |
Jagan Teki | 8b8e5b9 | 2024-01-17 13:21:44 +0530 | [diff] [blame] | 49 | struct rk3288_vop *win_regs = priv->regs + priv->win_offset; |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 50 | u32 lb_mode; |
| 51 | u32 rgb_mode; |
| 52 | u32 hactive = edid->hactive.typ; |
| 53 | u32 vactive = edid->vactive.typ; |
Arnaud Patard (Rtp) | 3af97be | 2021-03-05 11:27:54 +0100 | [diff] [blame] | 54 | int ret; |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 55 | |
| 56 | writel(V_ACT_WIDTH(hactive - 1) | V_ACT_HEIGHT(vactive - 1), |
Jagan Teki | 8b8e5b9 | 2024-01-17 13:21:44 +0530 | [diff] [blame] | 57 | &win_regs->win0_act_info); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 58 | |
| 59 | writel(V_DSP_XST(edid->hsync_len.typ + edid->hback_porch.typ) | |
| 60 | V_DSP_YST(edid->vsync_len.typ + edid->vback_porch.typ), |
Jagan Teki | 8b8e5b9 | 2024-01-17 13:21:44 +0530 | [diff] [blame] | 61 | &win_regs->win0_dsp_st); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 62 | |
| 63 | writel(V_DSP_WIDTH(hactive - 1) | |
| 64 | V_DSP_HEIGHT(vactive - 1), |
Jagan Teki | 8b8e5b9 | 2024-01-17 13:21:44 +0530 | [diff] [blame] | 65 | &win_regs->win0_dsp_info); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 66 | |
Jagan Teki | 8b8e5b9 | 2024-01-17 13:21:44 +0530 | [diff] [blame] | 67 | clrsetbits_le32(&win_regs->win0_color_key, M_WIN0_KEY_EN | M_WIN0_KEY_COLOR, |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 68 | V_WIN0_KEY_EN(0) | V_WIN0_KEY_COLOR(0)); |
| 69 | |
| 70 | switch (fb_bits_per_pixel) { |
| 71 | case 16: |
| 72 | rgb_mode = RGB565; |
Jagan Teki | 8b8e5b9 | 2024-01-17 13:21:44 +0530 | [diff] [blame] | 73 | writel(V_RGB565_VIRWIDTH(hactive), &win_regs->win0_vir); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 74 | break; |
| 75 | case 24: |
| 76 | rgb_mode = RGB888; |
Jagan Teki | 8b8e5b9 | 2024-01-17 13:21:44 +0530 | [diff] [blame] | 77 | writel(V_RGB888_VIRWIDTH(hactive), &win_regs->win0_vir); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 78 | break; |
| 79 | case 32: |
| 80 | default: |
| 81 | rgb_mode = ARGB8888; |
Jagan Teki | 8b8e5b9 | 2024-01-17 13:21:44 +0530 | [diff] [blame] | 82 | writel(V_ARGB888_VIRWIDTH(hactive), &win_regs->win0_vir); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 83 | break; |
| 84 | } |
| 85 | |
| 86 | if (hactive > 2560) |
| 87 | lb_mode = LB_RGB_3840X2; |
| 88 | else if (hactive > 1920) |
| 89 | lb_mode = LB_RGB_2560X4; |
| 90 | else if (hactive > 1280) |
| 91 | lb_mode = LB_RGB_1920X5; |
| 92 | else |
| 93 | lb_mode = LB_RGB_1280X8; |
| 94 | |
Jagan Teki | 8b8e5b9 | 2024-01-17 13:21:44 +0530 | [diff] [blame] | 95 | clrsetbits_le32(&win_regs->win0_ctrl0, |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 96 | M_WIN0_LB_MODE | M_WIN0_DATA_FMT | M_WIN0_EN, |
| 97 | V_WIN0_LB_MODE(lb_mode) | V_WIN0_DATA_FMT(rgb_mode) | |
| 98 | V_WIN0_EN(1)); |
| 99 | |
Jagan Teki | 8b8e5b9 | 2024-01-17 13:21:44 +0530 | [diff] [blame] | 100 | writel(fbbase, &win_regs->win0_yrgb_mst); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 101 | writel(0x01, ®s->reg_cfg_done); /* enable reg config */ |
Arnaud Patard (Rtp) | 3af97be | 2021-03-05 11:27:54 +0100 | [diff] [blame] | 102 | |
| 103 | ret = reset_assert(dclk_rst); |
| 104 | if (ret) { |
| 105 | dev_warn(dev, "failed to assert dclk reset (ret=%d)\n", ret); |
| 106 | return; |
| 107 | } |
| 108 | udelay(20); |
| 109 | |
| 110 | ret = reset_deassert(dclk_rst); |
| 111 | if (ret) |
| 112 | dev_warn(dev, "failed to deassert dclk reset (ret=%d)\n", ret); |
| 113 | |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 116 | static void rkvop_set_pin_polarity(struct udevice *dev, |
| 117 | enum vop_modes mode, u32 polarity) |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 118 | { |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 119 | struct rkvop_driverdata *ops = |
| 120 | (struct rkvop_driverdata *)dev_get_driver_data(dev); |
| 121 | |
| 122 | if (ops->set_pin_polarity) |
| 123 | ops->set_pin_polarity(dev, mode, polarity); |
| 124 | } |
| 125 | |
| 126 | static void rkvop_enable_output(struct udevice *dev, enum vop_modes mode) |
| 127 | { |
| 128 | struct rk_vop_priv *priv = dev_get_priv(dev); |
| 129 | struct rk3288_vop *regs = priv->regs; |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 130 | |
Simon Glass | d742950 | 2017-05-31 17:57:29 -0600 | [diff] [blame] | 131 | /* remove from standby */ |
| 132 | clrbits_le32(®s->sys_ctrl, V_STANDBY_EN(1)); |
| 133 | |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 134 | switch (mode) { |
| 135 | case VOP_MODE_HDMI: |
| 136 | clrsetbits_le32(®s->sys_ctrl, M_ALL_OUT_EN, |
| 137 | V_HDMI_OUT_EN(1)); |
| 138 | break; |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 139 | |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 140 | case VOP_MODE_EDP: |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 141 | clrsetbits_le32(®s->sys_ctrl, M_ALL_OUT_EN, |
| 142 | V_EDP_OUT_EN(1)); |
| 143 | break; |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 144 | |
Jagan Teki | 5023ade | 2020-04-02 17:11:22 +0530 | [diff] [blame] | 145 | #if defined(CONFIG_ROCKCHIP_RK3288) |
Jacob Chen | 0b6aee4 | 2016-03-14 11:20:18 +0800 | [diff] [blame] | 146 | case VOP_MODE_LVDS: |
| 147 | clrsetbits_le32(®s->sys_ctrl, M_ALL_OUT_EN, |
| 148 | V_RGB_OUT_EN(1)); |
| 149 | break; |
Jagan Teki | 5023ade | 2020-04-02 17:11:22 +0530 | [diff] [blame] | 150 | #endif |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 151 | |
Eric Gao | 0f49407 | 2017-05-02 18:23:52 +0800 | [diff] [blame] | 152 | case VOP_MODE_MIPI: |
| 153 | clrsetbits_le32(®s->sys_ctrl, M_ALL_OUT_EN, |
| 154 | V_MIPI_OUT_EN(1)); |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 155 | break; |
| 156 | |
| 157 | default: |
| 158 | debug("%s: unsupported output mode %x\n", __func__, mode); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 159 | } |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 160 | } |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 161 | |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 162 | static void rkvop_mode_set(struct udevice *dev, |
| 163 | const struct display_timing *edid, |
| 164 | enum vop_modes mode) |
| 165 | { |
| 166 | struct rk_vop_priv *priv = dev_get_priv(dev); |
| 167 | struct rk3288_vop *regs = priv->regs; |
Jagan Teki | 026c5db | 2024-01-17 13:21:45 +0530 | [diff] [blame^] | 168 | struct rk3288_vop *dsp_regs = priv->regs + priv->dsp_offset; |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 169 | struct rkvop_driverdata *data = |
| 170 | (struct rkvop_driverdata *)dev_get_driver_data(dev); |
Jacob Chen | 0b6aee4 | 2016-03-14 11:20:18 +0800 | [diff] [blame] | 171 | |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 172 | u32 hactive = edid->hactive.typ; |
| 173 | u32 vactive = edid->vactive.typ; |
| 174 | u32 hsync_len = edid->hsync_len.typ; |
| 175 | u32 hback_porch = edid->hback_porch.typ; |
| 176 | u32 vsync_len = edid->vsync_len.typ; |
| 177 | u32 vback_porch = edid->vback_porch.typ; |
| 178 | u32 hfront_porch = edid->hfront_porch.typ; |
| 179 | u32 vfront_porch = edid->vfront_porch.typ; |
| 180 | int mode_flags; |
| 181 | u32 pin_polarity; |
| 182 | |
| 183 | pin_polarity = BIT(DCLK_INVERT); |
| 184 | if (edid->flags & DISPLAY_FLAGS_HSYNC_HIGH) |
| 185 | pin_polarity |= BIT(HSYNC_POSITIVE); |
| 186 | if (edid->flags & DISPLAY_FLAGS_VSYNC_HIGH) |
| 187 | pin_polarity |= BIT(VSYNC_POSITIVE); |
| 188 | |
| 189 | rkvop_set_pin_polarity(dev, mode, pin_polarity); |
| 190 | rkvop_enable_output(dev, mode); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 191 | |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 192 | mode_flags = 0; /* RGB888 */ |
| 193 | if ((data->features & VOP_FEATURE_OUTPUT_10BIT) && |
| 194 | (mode == VOP_MODE_HDMI || mode == VOP_MODE_EDP)) |
| 195 | mode_flags = 15; /* RGBaaa */ |
| 196 | |
| 197 | clrsetbits_le32(®s->dsp_ctrl0, M_DSP_OUT_MODE, |
| 198 | V_DSP_OUT_MODE(mode_flags)); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 199 | |
| 200 | writel(V_HSYNC(hsync_len) | |
| 201 | V_HORPRD(hsync_len + hback_porch + hactive + hfront_porch), |
Jagan Teki | 026c5db | 2024-01-17 13:21:45 +0530 | [diff] [blame^] | 202 | &dsp_regs->dsp_htotal_hs_end); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 203 | |
| 204 | writel(V_HEAP(hsync_len + hback_porch + hactive) | |
| 205 | V_HASP(hsync_len + hback_porch), |
Jagan Teki | 026c5db | 2024-01-17 13:21:45 +0530 | [diff] [blame^] | 206 | &dsp_regs->dsp_hact_st_end); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 207 | |
| 208 | writel(V_VSYNC(vsync_len) | |
| 209 | V_VERPRD(vsync_len + vback_porch + vactive + vfront_porch), |
Jagan Teki | 026c5db | 2024-01-17 13:21:45 +0530 | [diff] [blame^] | 210 | &dsp_regs->dsp_vtotal_vs_end); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 211 | |
| 212 | writel(V_VAEP(vsync_len + vback_porch + vactive)| |
| 213 | V_VASP(vsync_len + vback_porch), |
Jagan Teki | 026c5db | 2024-01-17 13:21:45 +0530 | [diff] [blame^] | 214 | &dsp_regs->dsp_vact_st_end); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 215 | |
| 216 | writel(V_HEAP(hsync_len + hback_porch + hactive) | |
| 217 | V_HASP(hsync_len + hback_porch), |
Jagan Teki | 026c5db | 2024-01-17 13:21:45 +0530 | [diff] [blame^] | 218 | &dsp_regs->post_dsp_hact_info); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 219 | |
| 220 | writel(V_VAEP(vsync_len + vback_porch + vactive)| |
| 221 | V_VASP(vsync_len + vback_porch), |
Jagan Teki | 026c5db | 2024-01-17 13:21:45 +0530 | [diff] [blame^] | 222 | &dsp_regs->post_dsp_vact_info); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 223 | |
| 224 | writel(0x01, ®s->reg_cfg_done); /* enable reg config */ |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * rk_display_init() - Try to enable the given display device |
| 229 | * |
| 230 | * This function performs many steps: |
| 231 | * - Finds the display device being referenced by @ep_node |
| 232 | * - Puts the VOP's ID into its uclass platform data |
| 233 | * - Probes the device to set it up |
| 234 | * - Reads the EDID timing information |
| 235 | * - Sets up the VOP clocks, etc. for the selected pixel clock and display mode |
| 236 | * - Enables the display (the display device handles this and will do different |
| 237 | * things depending on the display type) |
| 238 | * - Tells the uclass about the display resolution so that the console will |
| 239 | * appear correctly |
| 240 | * |
| 241 | * @dev: VOP device that we want to connect to the display |
| 242 | * @fbbase: Frame buffer address |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 243 | * @ep_node: Device tree node to process - this is the offset of an endpoint |
| 244 | * node within the VOP's 'port' list. |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 245 | * Return: 0 if OK, -ve if something went wrong |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 246 | */ |
Philipp Tomsich | 13b016d | 2018-02-23 17:38:52 +0100 | [diff] [blame] | 247 | static int rk_display_init(struct udevice *dev, ulong fbbase, ofnode ep_node) |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 248 | { |
| 249 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 250 | int vop_id, remote_vop_id; |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 251 | struct display_timing timing; |
| 252 | struct udevice *disp; |
Philipp Tomsich | 13b016d | 2018-02-23 17:38:52 +0100 | [diff] [blame] | 253 | int ret; |
| 254 | u32 remote_phandle; |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 255 | struct display_plat *disp_uc_plat; |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 256 | struct clk clk; |
Eric Gao | 58791c3 | 2017-05-02 18:23:53 +0800 | [diff] [blame] | 257 | enum video_log2_bpp l2bpp; |
Philipp Tomsich | 13b016d | 2018-02-23 17:38:52 +0100 | [diff] [blame] | 258 | ofnode remote; |
Arnaud Patard (Rtp) | 058ffd6 | 2021-03-05 11:27:46 +0100 | [diff] [blame] | 259 | const char *compat; |
Arnaud Patard (Rtp) | 3af97be | 2021-03-05 11:27:54 +0100 | [diff] [blame] | 260 | struct reset_ctl dclk_rst; |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 261 | |
Arnaud Patard (Rtp) | 6b81d6a | 2021-03-05 11:27:52 +0100 | [diff] [blame] | 262 | debug("%s(%s, 0x%lx, %s)\n", __func__, |
Philipp Tomsich | 13b016d | 2018-02-23 17:38:52 +0100 | [diff] [blame] | 263 | dev_read_name(dev), fbbase, ofnode_get_name(ep_node)); |
| 264 | |
Philipp Tomsich | 13b016d | 2018-02-23 17:38:52 +0100 | [diff] [blame] | 265 | ret = ofnode_read_u32(ep_node, "remote-endpoint", &remote_phandle); |
| 266 | if (ret) |
| 267 | return ret; |
| 268 | |
| 269 | remote = ofnode_get_by_phandle(remote_phandle); |
| 270 | if (!ofnode_valid(remote)) |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 271 | return -EINVAL; |
Philipp Tomsich | 13b016d | 2018-02-23 17:38:52 +0100 | [diff] [blame] | 272 | remote_vop_id = ofnode_read_u32_default(remote, "reg", -1); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 273 | debug("remote vop_id=%d\n", remote_vop_id); |
| 274 | |
Philipp Tomsich | 13b016d | 2018-02-23 17:38:52 +0100 | [diff] [blame] | 275 | /* |
| 276 | * The remote-endpoint references into a subnode of the encoder |
| 277 | * (i.e. HDMI, MIPI, etc.) with the DTS looking something like |
| 278 | * the following (assume 'hdmi_in_vopl' to be referenced): |
| 279 | * |
| 280 | * hdmi: hdmi@ff940000 { |
| 281 | * ports { |
| 282 | * hdmi_in: port { |
| 283 | * hdmi_in_vopb: endpoint@0 { ... }; |
| 284 | * hdmi_in_vopl: endpoint@1 { ... }; |
| 285 | * } |
| 286 | * } |
| 287 | * } |
| 288 | * |
| 289 | * The original code had 3 steps of "walking the parent", but |
| 290 | * a much better (as in: less likely to break if the DTS |
| 291 | * changes) way of doing this is to "find the enclosing device |
| 292 | * of UCLASS_DISPLAY". |
| 293 | */ |
| 294 | while (ofnode_valid(remote)) { |
| 295 | remote = ofnode_get_parent(remote); |
| 296 | if (!ofnode_valid(remote)) { |
| 297 | debug("%s(%s): no UCLASS_DISPLAY for remote-endpoint\n", |
| 298 | __func__, dev_read_name(dev)); |
| 299 | return -EINVAL; |
| 300 | } |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 301 | |
Philipp Tomsich | 13b016d | 2018-02-23 17:38:52 +0100 | [diff] [blame] | 302 | uclass_find_device_by_ofnode(UCLASS_DISPLAY, remote, &disp); |
| 303 | if (disp) |
| 304 | break; |
| 305 | }; |
Arnaud Patard (Rtp) | 058ffd6 | 2021-03-05 11:27:46 +0100 | [diff] [blame] | 306 | compat = ofnode_get_property(remote, "compatible", NULL); |
| 307 | if (!compat) { |
| 308 | debug("%s(%s): Failed to find compatible property\n", |
| 309 | __func__, dev_read_name(dev)); |
| 310 | return -EINVAL; |
| 311 | } |
Johan Jonker | ab446c5 | 2023-03-15 19:33:38 +0100 | [diff] [blame] | 312 | if (strstr(compat, "edp") || |
| 313 | strstr(compat, "rk3288-dp")) { |
Arnaud Patard (Rtp) | 058ffd6 | 2021-03-05 11:27:46 +0100 | [diff] [blame] | 314 | vop_id = VOP_MODE_EDP; |
| 315 | } else if (strstr(compat, "mipi")) { |
| 316 | vop_id = VOP_MODE_MIPI; |
| 317 | } else if (strstr(compat, "hdmi")) { |
| 318 | vop_id = VOP_MODE_HDMI; |
| 319 | } else if (strstr(compat, "cdn-dp")) { |
| 320 | vop_id = VOP_MODE_DP; |
| 321 | } else if (strstr(compat, "lvds")) { |
| 322 | vop_id = VOP_MODE_LVDS; |
| 323 | } else { |
| 324 | debug("%s(%s): Failed to find vop mode for %s\n", |
| 325 | __func__, dev_read_name(dev), compat); |
| 326 | return -EINVAL; |
| 327 | } |
| 328 | debug("vop_id=%d\n", vop_id); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 329 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 330 | disp_uc_plat = dev_get_uclass_plat(disp); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 331 | debug("Found device '%s', disp_uc_priv=%p\n", disp->name, disp_uc_plat); |
Simon Glass | 86ad1b6 | 2016-11-13 14:22:08 -0700 | [diff] [blame] | 332 | if (display_in_use(disp)) { |
| 333 | debug(" - device in use\n"); |
| 334 | return -EBUSY; |
| 335 | } |
| 336 | |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 337 | disp_uc_plat->source_id = remote_vop_id; |
| 338 | disp_uc_plat->src_dev = dev; |
| 339 | |
| 340 | ret = device_probe(disp); |
| 341 | if (ret) { |
| 342 | debug("%s: device '%s' display won't probe (ret=%d)\n", |
| 343 | __func__, dev->name, ret); |
| 344 | return ret; |
| 345 | } |
| 346 | |
| 347 | ret = display_read_timing(disp, &timing); |
| 348 | if (ret) { |
| 349 | debug("%s: Failed to read timings\n", __func__); |
| 350 | return ret; |
| 351 | } |
| 352 | |
Simon Glass | 25891bc | 2016-11-13 14:21:56 -0700 | [diff] [blame] | 353 | ret = clk_get_by_index(dev, 1, &clk); |
Stephen Warren | a962243 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 354 | if (!ret) |
| 355 | ret = clk_set_rate(&clk, timing.pixelclock.typ); |
Eric Gao | 9ada0e6 | 2017-05-02 18:23:51 +0800 | [diff] [blame] | 356 | if (IS_ERR_VALUE(ret)) { |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 357 | debug("%s: Failed to set pixel clock: ret=%d\n", __func__, ret); |
| 358 | return ret; |
| 359 | } |
| 360 | |
Eric Gao | 58791c3 | 2017-05-02 18:23:53 +0800 | [diff] [blame] | 361 | /* Set bitwidth for vop display according to vop mode */ |
| 362 | switch (vop_id) { |
| 363 | case VOP_MODE_EDP: |
Jagan Teki | 5023ade | 2020-04-02 17:11:22 +0530 | [diff] [blame] | 364 | #if defined(CONFIG_ROCKCHIP_RK3288) |
Eric Gao | 58791c3 | 2017-05-02 18:23:53 +0800 | [diff] [blame] | 365 | case VOP_MODE_LVDS: |
Jagan Teki | 5023ade | 2020-04-02 17:11:22 +0530 | [diff] [blame] | 366 | #endif |
Eric Gao | 58791c3 | 2017-05-02 18:23:53 +0800 | [diff] [blame] | 367 | l2bpp = VIDEO_BPP16; |
| 368 | break; |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 369 | case VOP_MODE_HDMI: |
Eric Gao | 58791c3 | 2017-05-02 18:23:53 +0800 | [diff] [blame] | 370 | case VOP_MODE_MIPI: |
| 371 | l2bpp = VIDEO_BPP32; |
| 372 | break; |
| 373 | default: |
| 374 | l2bpp = VIDEO_BPP16; |
| 375 | } |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 376 | |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 377 | rkvop_mode_set(dev, &timing, vop_id); |
Arnaud Patard (Rtp) | 3af97be | 2021-03-05 11:27:54 +0100 | [diff] [blame] | 378 | |
| 379 | ret = reset_get_by_name(dev, "dclk", &dclk_rst); |
| 380 | if (ret) { |
| 381 | dev_err(dev, "failed to get dclk reset (ret=%d)\n", ret); |
| 382 | return ret; |
| 383 | } |
| 384 | |
Jagan Teki | ff2e4e2 | 2024-01-17 13:21:43 +0530 | [diff] [blame] | 385 | rkvop_enable(dev, fbbase, 1 << l2bpp, &timing, &dclk_rst); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 386 | |
| 387 | ret = display_enable(disp, 1 << l2bpp, &timing); |
| 388 | if (ret) |
| 389 | return ret; |
| 390 | |
| 391 | uc_priv->xsize = timing.hactive.typ; |
| 392 | uc_priv->ysize = timing.vactive.typ; |
| 393 | uc_priv->bpix = l2bpp; |
| 394 | debug("fb=%lx, size=%d %d\n", fbbase, uc_priv->xsize, uc_priv->ysize); |
| 395 | |
| 396 | return 0; |
| 397 | } |
| 398 | |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 399 | void rk_vop_probe_regulators(struct udevice *dev, |
| 400 | const char * const *names, int cnt) |
| 401 | { |
| 402 | int i, ret; |
| 403 | const char *name; |
| 404 | struct udevice *reg; |
| 405 | |
| 406 | for (i = 0; i < cnt; ++i) { |
| 407 | name = names[i]; |
| 408 | debug("%s: probing regulator '%s'\n", dev->name, name); |
| 409 | |
| 410 | ret = regulator_autoset_by_name(name, ®); |
| 411 | if (!ret) |
| 412 | ret = regulator_set_enable(reg, true); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | int rk_vop_probe(struct udevice *dev) |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 417 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 418 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 419 | struct rk_vop_priv *priv = dev_get_priv(dev); |
Jagan Teki | 8b8e5b9 | 2024-01-17 13:21:44 +0530 | [diff] [blame] | 420 | struct rkvop_driverdata *ops = |
| 421 | (struct rkvop_driverdata *)dev_get_driver_data(dev); |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 422 | int ret = 0; |
Philipp Tomsich | 13b016d | 2018-02-23 17:38:52 +0100 | [diff] [blame] | 423 | ofnode port, node; |
Arnaud Patard (Rtp) | 3af97be | 2021-03-05 11:27:54 +0100 | [diff] [blame] | 424 | struct reset_ctl ahb_rst; |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 425 | |
| 426 | /* Before relocation we don't need to do anything */ |
| 427 | if (!(gd->flags & GD_FLG_RELOC)) |
| 428 | return 0; |
| 429 | |
Arnaud Patard (Rtp) | 3af97be | 2021-03-05 11:27:54 +0100 | [diff] [blame] | 430 | ret = reset_get_by_name(dev, "ahb", &ahb_rst); |
| 431 | if (ret) { |
| 432 | dev_err(dev, "failed to get ahb reset (ret=%d)\n", ret); |
| 433 | return ret; |
| 434 | } |
| 435 | |
| 436 | ret = reset_assert(&ahb_rst); |
| 437 | if (ret) { |
| 438 | dev_err(dev, "failed to assert ahb reset (ret=%d)\n", ret); |
Ondrej Jirman | 1dd75ef | 2023-05-22 23:47:01 +0200 | [diff] [blame] | 439 | return ret; |
Arnaud Patard (Rtp) | 3af97be | 2021-03-05 11:27:54 +0100 | [diff] [blame] | 440 | } |
| 441 | udelay(20); |
| 442 | |
| 443 | ret = reset_deassert(&ahb_rst); |
| 444 | if (ret) { |
| 445 | dev_err(dev, "failed to deassert ahb reset (ret=%d)\n", ret); |
| 446 | return ret; |
| 447 | } |
| 448 | |
Arnaud Patard (Rtp) | 1af703c | 2021-03-05 11:27:49 +0100 | [diff] [blame] | 449 | #if defined(CONFIG_EFI_LOADER) |
| 450 | debug("Adding to EFI map %d @ %lx\n", plat->size, plat->base); |
| 451 | efi_add_memory_map(plat->base, plat->size, EFI_RESERVED_MEMORY_TYPE); |
| 452 | #endif |
| 453 | |
Johan Jonker | 8d5d8e0 | 2023-03-13 01:32:04 +0100 | [diff] [blame] | 454 | priv->regs = dev_read_addr_ptr(dev); |
Jagan Teki | 8b8e5b9 | 2024-01-17 13:21:44 +0530 | [diff] [blame] | 455 | priv->win_offset = ops->win_offset; |
Jagan Teki | 026c5db | 2024-01-17 13:21:45 +0530 | [diff] [blame^] | 456 | priv->dsp_offset = ops->dsp_offset; |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 457 | |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 458 | /* |
| 459 | * Try all the ports until we find one that works. In practice this |
| 460 | * tries EDP first if available, then HDMI. |
Simon Glass | 86ad1b6 | 2016-11-13 14:22:08 -0700 | [diff] [blame] | 461 | * |
| 462 | * Note that rockchip_vop_set_clk() always uses NPLL as the source |
| 463 | * clock so it is currently not possible to use more than one display |
| 464 | * device simultaneously. |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 465 | */ |
Philipp Tomsich | 13b016d | 2018-02-23 17:38:52 +0100 | [diff] [blame] | 466 | port = dev_read_subnode(dev, "port"); |
| 467 | if (!ofnode_valid(port)) { |
| 468 | debug("%s(%s): 'port' subnode not found\n", |
| 469 | __func__, dev_read_name(dev)); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 470 | return -EINVAL; |
Philipp Tomsich | 13b016d | 2018-02-23 17:38:52 +0100 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | for (node = ofnode_first_subnode(port); |
| 474 | ofnode_valid(node); |
| 475 | node = dev_read_next_subnode(node)) { |
Eric Gao | 58791c3 | 2017-05-02 18:23:53 +0800 | [diff] [blame] | 476 | ret = rk_display_init(dev, plat->base, node); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 477 | if (ret) |
| 478 | debug("Device failed: ret=%d\n", ret); |
| 479 | if (!ret) |
| 480 | break; |
| 481 | } |
Simon Glass | 773ca82 | 2016-05-14 14:03:01 -0600 | [diff] [blame] | 482 | video_set_flush_dcache(dev, 1); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 483 | |
| 484 | return ret; |
| 485 | } |
| 486 | |
Philipp Tomsich | a354c2d | 2017-05-31 17:59:30 +0200 | [diff] [blame] | 487 | int rk_vop_bind(struct udevice *dev) |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 488 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 489 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 490 | |
Philipp Tomsich | d3a5826 | 2017-05-31 17:59:29 +0200 | [diff] [blame] | 491 | plat->size = 4 * (CONFIG_VIDEO_ROCKCHIP_MAX_XRES * |
| 492 | CONFIG_VIDEO_ROCKCHIP_MAX_YRES); |
Simon Glass | e421bb8 | 2016-01-21 19:45:05 -0700 | [diff] [blame] | 493 | |
| 494 | return 0; |
| 495 | } |