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