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