Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Rockchip SoC DP (Display Port) interface driver. |
| 4 | * |
| 5 | * Copyright (C) Fuzhou Rockchip Electronics Co., Ltd. |
| 6 | * Author: Andy Yan <andy.yan@rock-chips.com> |
| 7 | * Yakir Yang <ykk@rock-chips.com> |
| 8 | * Jeff Chen <jeff.chen@rock-chips.com> |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/component.h> |
| 12 | #include <linux/mfd/syscon.h> |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 13 | #include <linux/of_device.h> |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 14 | #include <linux/of_graph.h> |
| 15 | #include <linux/regmap.h> |
| 16 | #include <linux/reset.h> |
| 17 | #include <linux/clk.h> |
| 18 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 19 | #include <video/of_videomode.h> |
| 20 | #include <video/videomode.h> |
| 21 | |
Sean Paul | 6c836d9 | 2019-06-11 12:08:22 -0400 | [diff] [blame] | 22 | #include <drm/drm_atomic.h> |
| 23 | #include <drm/drm_atomic_helper.h> |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 24 | #include <drm/bridge/analogix_dp.h> |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 25 | #include <drm/drm_dp_helper.h> |
| 26 | #include <drm/drm_of.h> |
| 27 | #include <drm/drm_panel.h> |
| 28 | #include <drm/drm_probe_helper.h> |
Thomas Zimmermann | 0dbd735 | 2020-03-05 16:59:40 +0100 | [diff] [blame] | 29 | #include <drm/drm_simple_kms_helper.h> |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 30 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 31 | #include "rockchip_drm_drv.h" |
| 32 | #include "rockchip_drm_vop.h" |
| 33 | |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 34 | #define RK3288_GRF_SOC_CON6 0x25c |
| 35 | #define RK3288_EDP_LCDC_SEL BIT(5) |
Yakir Yang | 82872e4 | 2016-06-29 17:15:26 +0800 | [diff] [blame] | 36 | #define RK3399_GRF_SOC_CON20 0x6250 |
| 37 | #define RK3399_EDP_LCDC_SEL BIT(5) |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 38 | |
| 39 | #define HIWORD_UPDATE(val, mask) (val | (mask) << 16) |
| 40 | |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 41 | #define PSR_WAIT_LINE_FLAG_TIMEOUT_MS 100 |
| 42 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 43 | #define to_dp(nm) container_of(nm, struct rockchip_dp_device, nm) |
| 44 | |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 45 | /** |
| 46 | * struct rockchip_dp_chip_data - splite the grf setting of kind of chips |
| 47 | * @lcdsel_grf_reg: grf register offset of lcdc select |
| 48 | * @lcdsel_big: reg value of selecting vop big for eDP |
| 49 | * @lcdsel_lit: reg value of selecting vop little for eDP |
| 50 | * @chip_type: specific chip type |
| 51 | */ |
| 52 | struct rockchip_dp_chip_data { |
| 53 | u32 lcdsel_grf_reg; |
| 54 | u32 lcdsel_big; |
| 55 | u32 lcdsel_lit; |
| 56 | u32 chip_type; |
| 57 | }; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 58 | |
| 59 | struct rockchip_dp_device { |
| 60 | struct drm_device *drm_dev; |
| 61 | struct device *dev; |
| 62 | struct drm_encoder encoder; |
| 63 | struct drm_display_mode mode; |
| 64 | |
| 65 | struct clk *pclk; |
Yakir Yang | dc1c93b | 2016-06-29 17:16:05 +0800 | [diff] [blame] | 66 | struct clk *grfclk; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 67 | struct regmap *grf; |
| 68 | struct reset_control *rst; |
| 69 | |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 70 | const struct rockchip_dp_chip_data *data; |
| 71 | |
Jeffy Chen | 6b2d8fd | 2018-01-10 17:23:41 +0100 | [diff] [blame] | 72 | struct analogix_dp_device *adp; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 73 | struct analogix_dp_plat_data plat_data; |
| 74 | }; |
| 75 | |
| 76 | static int rockchip_dp_pre_init(struct rockchip_dp_device *dp) |
| 77 | { |
| 78 | reset_control_assert(dp->rst); |
| 79 | usleep_range(10, 20); |
| 80 | reset_control_deassert(dp->rst); |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
Douglas Anderson | 7bb3bb4 | 2018-04-23 12:49:58 +0200 | [diff] [blame] | 85 | static int rockchip_dp_poweron_start(struct analogix_dp_plat_data *plat_data) |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 86 | { |
| 87 | struct rockchip_dp_device *dp = to_dp(plat_data); |
| 88 | int ret; |
| 89 | |
| 90 | ret = clk_prepare_enable(dp->pclk); |
| 91 | if (ret < 0) { |
Haneen Mohammed | d8dd680 | 2017-09-15 02:36:03 -0600 | [diff] [blame] | 92 | DRM_DEV_ERROR(dp->dev, "failed to enable pclk %d\n", ret); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | ret = rockchip_dp_pre_init(dp); |
| 97 | if (ret < 0) { |
Haneen Mohammed | d8dd680 | 2017-09-15 02:36:03 -0600 | [diff] [blame] | 98 | DRM_DEV_ERROR(dp->dev, "failed to dp pre init %d\n", ret); |
Wei Yongjun | 3694c5c | 2016-07-19 11:32:43 +0000 | [diff] [blame] | 99 | clk_disable_unprepare(dp->pclk); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 100 | return ret; |
| 101 | } |
| 102 | |
Douglas Anderson | 7bb3bb4 | 2018-04-23 12:49:58 +0200 | [diff] [blame] | 103 | return ret; |
| 104 | } |
| 105 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 106 | static int rockchip_dp_powerdown(struct analogix_dp_plat_data *plat_data) |
| 107 | { |
| 108 | struct rockchip_dp_device *dp = to_dp(plat_data); |
| 109 | |
| 110 | clk_disable_unprepare(dp->pclk); |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
Yakir Yang | db8a9ae | 2016-06-29 17:15:39 +0800 | [diff] [blame] | 115 | static int rockchip_dp_get_modes(struct analogix_dp_plat_data *plat_data, |
| 116 | struct drm_connector *connector) |
| 117 | { |
| 118 | struct drm_display_info *di = &connector->display_info; |
| 119 | /* VOP couldn't output YUV video format for eDP rightly */ |
| 120 | u32 mask = DRM_COLOR_FORMAT_YCRCB444 | DRM_COLOR_FORMAT_YCRCB422; |
| 121 | |
| 122 | if ((di->color_formats & mask)) { |
| 123 | DRM_DEBUG_KMS("Swapping display color format from YUV to RGB\n"); |
| 124 | di->color_formats &= ~mask; |
| 125 | di->color_formats |= DRM_COLOR_FORMAT_RGB444; |
| 126 | di->bpc = 8; |
| 127 | } |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 132 | static bool |
| 133 | rockchip_dp_drm_encoder_mode_fixup(struct drm_encoder *encoder, |
| 134 | const struct drm_display_mode *mode, |
| 135 | struct drm_display_mode *adjusted_mode) |
| 136 | { |
| 137 | /* do nothing */ |
| 138 | return true; |
| 139 | } |
| 140 | |
| 141 | static void rockchip_dp_drm_encoder_mode_set(struct drm_encoder *encoder, |
| 142 | struct drm_display_mode *mode, |
| 143 | struct drm_display_mode *adjusted) |
| 144 | { |
| 145 | /* do nothing */ |
| 146 | } |
| 147 | |
Sean Paul | 6c836d9 | 2019-06-11 12:08:22 -0400 | [diff] [blame] | 148 | static |
| 149 | struct drm_crtc *rockchip_dp_drm_get_new_crtc(struct drm_encoder *encoder, |
| 150 | struct drm_atomic_state *state) |
| 151 | { |
| 152 | struct drm_connector *connector; |
| 153 | struct drm_connector_state *conn_state; |
| 154 | |
| 155 | connector = drm_atomic_get_new_connector_for_encoder(state, encoder); |
| 156 | if (!connector) |
| 157 | return NULL; |
| 158 | |
| 159 | conn_state = drm_atomic_get_new_connector_state(state, connector); |
| 160 | if (!conn_state) |
| 161 | return NULL; |
| 162 | |
| 163 | return conn_state->crtc; |
| 164 | } |
| 165 | |
| 166 | static void rockchip_dp_drm_encoder_enable(struct drm_encoder *encoder, |
| 167 | struct drm_atomic_state *state) |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 168 | { |
| 169 | struct rockchip_dp_device *dp = to_dp(encoder); |
Sean Paul | 6c836d9 | 2019-06-11 12:08:22 -0400 | [diff] [blame] | 170 | struct drm_crtc *crtc; |
| 171 | struct drm_crtc_state *old_crtc_state; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 172 | int ret; |
| 173 | u32 val; |
| 174 | |
Sean Paul | 6c836d9 | 2019-06-11 12:08:22 -0400 | [diff] [blame] | 175 | crtc = rockchip_dp_drm_get_new_crtc(encoder, state); |
| 176 | if (!crtc) |
| 177 | return; |
| 178 | |
| 179 | old_crtc_state = drm_atomic_get_old_crtc_state(state, crtc); |
| 180 | /* Coming back from self refresh, nothing to do */ |
| 181 | if (old_crtc_state && old_crtc_state->self_refresh_active) |
| 182 | return; |
| 183 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 184 | ret = drm_of_encoder_active_endpoint_id(dp->dev->of_node, encoder); |
| 185 | if (ret < 0) |
| 186 | return; |
| 187 | |
| 188 | if (ret) |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 189 | val = dp->data->lcdsel_lit; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 190 | else |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 191 | val = dp->data->lcdsel_big; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 192 | |
Haneen Mohammed | d8dd680 | 2017-09-15 02:36:03 -0600 | [diff] [blame] | 193 | DRM_DEV_DEBUG(dp->dev, "vop %s output to dp\n", (ret) ? "LIT" : "BIG"); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 194 | |
Yakir Yang | dc1c93b | 2016-06-29 17:16:05 +0800 | [diff] [blame] | 195 | ret = clk_prepare_enable(dp->grfclk); |
| 196 | if (ret < 0) { |
Haneen Mohammed | d8dd680 | 2017-09-15 02:36:03 -0600 | [diff] [blame] | 197 | DRM_DEV_ERROR(dp->dev, "failed to enable grfclk %d\n", ret); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 198 | return; |
| 199 | } |
Yakir Yang | dc1c93b | 2016-06-29 17:16:05 +0800 | [diff] [blame] | 200 | |
| 201 | ret = regmap_write(dp->grf, dp->data->lcdsel_grf_reg, val); |
| 202 | if (ret != 0) |
Haneen Mohammed | d8dd680 | 2017-09-15 02:36:03 -0600 | [diff] [blame] | 203 | DRM_DEV_ERROR(dp->dev, "Could not write to GRF: %d\n", ret); |
Yakir Yang | dc1c93b | 2016-06-29 17:16:05 +0800 | [diff] [blame] | 204 | |
| 205 | clk_disable_unprepare(dp->grfclk); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 206 | } |
| 207 | |
Sean Paul | 6c836d9 | 2019-06-11 12:08:22 -0400 | [diff] [blame] | 208 | static void rockchip_dp_drm_encoder_disable(struct drm_encoder *encoder, |
| 209 | struct drm_atomic_state *state) |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 210 | { |
Sean Paul | 6c836d9 | 2019-06-11 12:08:22 -0400 | [diff] [blame] | 211 | struct rockchip_dp_device *dp = to_dp(encoder); |
| 212 | struct drm_crtc *crtc; |
| 213 | struct drm_crtc_state *new_crtc_state = NULL; |
| 214 | int ret; |
| 215 | |
| 216 | crtc = rockchip_dp_drm_get_new_crtc(encoder, state); |
| 217 | /* No crtc means we're doing a full shutdown */ |
| 218 | if (!crtc) |
| 219 | return; |
| 220 | |
| 221 | new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc); |
| 222 | /* If we're not entering self-refresh, no need to wait for vact */ |
| 223 | if (!new_crtc_state || !new_crtc_state->self_refresh_active) |
| 224 | return; |
| 225 | |
| 226 | ret = rockchip_drm_wait_vact_end(crtc, PSR_WAIT_LINE_FLAG_TIMEOUT_MS); |
| 227 | if (ret) |
| 228 | DRM_DEV_ERROR(dp->dev, "line flag irq timed out\n"); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 229 | } |
| 230 | |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 231 | static int |
| 232 | rockchip_dp_drm_encoder_atomic_check(struct drm_encoder *encoder, |
| 233 | struct drm_crtc_state *crtc_state, |
| 234 | struct drm_connector_state *conn_state) |
| 235 | { |
| 236 | struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state); |
Mark Yao | 6bda811 | 2018-04-23 12:49:57 +0200 | [diff] [blame] | 237 | struct drm_display_info *di = &conn_state->connector->display_info; |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 238 | |
| 239 | /* |
Yakir Yang | d698f0e | 2016-06-29 17:15:44 +0800 | [diff] [blame] | 240 | * The hardware IC designed that VOP must output the RGB10 video |
| 241 | * format to eDP controller, and if eDP panel only support RGB8, |
| 242 | * then eDP controller should cut down the video data, not via VOP |
| 243 | * controller, that's why we need to hardcode the VOP output mode |
| 244 | * to RGA10 here. |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 245 | */ |
Yakir Yang | 82872e4 | 2016-06-29 17:15:26 +0800 | [diff] [blame] | 246 | |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 247 | s->output_mode = ROCKCHIP_OUT_MODE_AAAA; |
| 248 | s->output_type = DRM_MODE_CONNECTOR_eDP; |
Mark Yao | 6bda811 | 2018-04-23 12:49:57 +0200 | [diff] [blame] | 249 | s->output_bpc = di->bpc; |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 254 | static struct drm_encoder_helper_funcs rockchip_dp_encoder_helper_funcs = { |
| 255 | .mode_fixup = rockchip_dp_drm_encoder_mode_fixup, |
| 256 | .mode_set = rockchip_dp_drm_encoder_mode_set, |
Sean Paul | 6c836d9 | 2019-06-11 12:08:22 -0400 | [diff] [blame] | 257 | .atomic_enable = rockchip_dp_drm_encoder_enable, |
| 258 | .atomic_disable = rockchip_dp_drm_encoder_disable, |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 259 | .atomic_check = rockchip_dp_drm_encoder_atomic_check, |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 260 | }; |
| 261 | |
Jeffy Chen | 102712a | 2017-10-19 11:48:04 +0800 | [diff] [blame] | 262 | static int rockchip_dp_of_probe(struct rockchip_dp_device *dp) |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 263 | { |
| 264 | struct device *dev = dp->dev; |
| 265 | struct device_node *np = dev->of_node; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 266 | |
| 267 | dp->grf = syscon_regmap_lookup_by_phandle(np, "rockchip,grf"); |
| 268 | if (IS_ERR(dp->grf)) { |
Haneen Mohammed | d8dd680 | 2017-09-15 02:36:03 -0600 | [diff] [blame] | 269 | DRM_DEV_ERROR(dev, "failed to get rockchip,grf property\n"); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 270 | return PTR_ERR(dp->grf); |
| 271 | } |
| 272 | |
Yakir Yang | dc1c93b | 2016-06-29 17:16:05 +0800 | [diff] [blame] | 273 | dp->grfclk = devm_clk_get(dev, "grf"); |
| 274 | if (PTR_ERR(dp->grfclk) == -ENOENT) { |
| 275 | dp->grfclk = NULL; |
| 276 | } else if (PTR_ERR(dp->grfclk) == -EPROBE_DEFER) { |
| 277 | return -EPROBE_DEFER; |
| 278 | } else if (IS_ERR(dp->grfclk)) { |
Haneen Mohammed | d8dd680 | 2017-09-15 02:36:03 -0600 | [diff] [blame] | 279 | DRM_DEV_ERROR(dev, "failed to get grf clock\n"); |
Yakir Yang | dc1c93b | 2016-06-29 17:16:05 +0800 | [diff] [blame] | 280 | return PTR_ERR(dp->grfclk); |
| 281 | } |
| 282 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 283 | dp->pclk = devm_clk_get(dev, "pclk"); |
| 284 | if (IS_ERR(dp->pclk)) { |
Haneen Mohammed | d8dd680 | 2017-09-15 02:36:03 -0600 | [diff] [blame] | 285 | DRM_DEV_ERROR(dev, "failed to get pclk property\n"); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 286 | return PTR_ERR(dp->pclk); |
| 287 | } |
| 288 | |
| 289 | dp->rst = devm_reset_control_get(dev, "dp"); |
| 290 | if (IS_ERR(dp->rst)) { |
Haneen Mohammed | d8dd680 | 2017-09-15 02:36:03 -0600 | [diff] [blame] | 291 | DRM_DEV_ERROR(dev, "failed to get dp reset control\n"); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 292 | return PTR_ERR(dp->rst); |
| 293 | } |
| 294 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static int rockchip_dp_drm_create_encoder(struct rockchip_dp_device *dp) |
| 299 | { |
| 300 | struct drm_encoder *encoder = &dp->encoder; |
| 301 | struct drm_device *drm_dev = dp->drm_dev; |
| 302 | struct device *dev = dp->dev; |
| 303 | int ret; |
| 304 | |
| 305 | encoder->possible_crtcs = drm_of_find_possible_crtcs(drm_dev, |
| 306 | dev->of_node); |
| 307 | DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs); |
| 308 | |
Thomas Zimmermann | 0dbd735 | 2020-03-05 16:59:40 +0100 | [diff] [blame] | 309 | ret = drm_simple_encoder_init(drm_dev, encoder, |
| 310 | DRM_MODE_ENCODER_TMDS); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 311 | if (ret) { |
| 312 | DRM_ERROR("failed to initialize encoder with drm\n"); |
| 313 | return ret; |
| 314 | } |
| 315 | |
| 316 | drm_encoder_helper_add(encoder, &rockchip_dp_encoder_helper_funcs); |
| 317 | |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | static int rockchip_dp_bind(struct device *dev, struct device *master, |
| 322 | void *data) |
| 323 | { |
| 324 | struct rockchip_dp_device *dp = dev_get_drvdata(dev); |
| 325 | struct drm_device *drm_dev = data; |
| 326 | int ret; |
| 327 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 328 | dp->drm_dev = drm_dev; |
| 329 | |
| 330 | ret = rockchip_dp_drm_create_encoder(dp); |
| 331 | if (ret) { |
| 332 | DRM_ERROR("failed to create drm encoder\n"); |
| 333 | return ret; |
| 334 | } |
| 335 | |
| 336 | dp->plat_data.encoder = &dp->encoder; |
| 337 | |
Marek Szyprowski | 152cce0 | 2020-03-10 11:34:27 +0100 | [diff] [blame] | 338 | ret = analogix_dp_bind(dp->adp, drm_dev); |
| 339 | if (ret) |
Sean Paul | 6c836d9 | 2019-06-11 12:08:22 -0400 | [diff] [blame] | 340 | goto err_cleanup_encoder; |
Jeffy Chen | 6b2d8fd | 2018-01-10 17:23:41 +0100 | [diff] [blame] | 341 | |
| 342 | return 0; |
Jeffy Chen | c8c0451 | 2018-01-10 17:23:43 +0100 | [diff] [blame] | 343 | err_cleanup_encoder: |
| 344 | dp->encoder.funcs->destroy(&dp->encoder); |
| 345 | return ret; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | static void rockchip_dp_unbind(struct device *dev, struct device *master, |
| 349 | void *data) |
| 350 | { |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 351 | struct rockchip_dp_device *dp = dev_get_drvdata(dev); |
| 352 | |
Jeffy Chen | 6b2d8fd | 2018-01-10 17:23:41 +0100 | [diff] [blame] | 353 | analogix_dp_unbind(dp->adp); |
Jeffy Chen | 7fe201c | 2018-01-10 17:23:42 +0100 | [diff] [blame] | 354 | dp->encoder.funcs->destroy(&dp->encoder); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static const struct component_ops rockchip_dp_component_ops = { |
| 358 | .bind = rockchip_dp_bind, |
| 359 | .unbind = rockchip_dp_unbind, |
| 360 | }; |
| 361 | |
| 362 | static int rockchip_dp_probe(struct platform_device *pdev) |
| 363 | { |
| 364 | struct device *dev = &pdev->dev; |
Marek Szyprowski | 152cce0 | 2020-03-10 11:34:27 +0100 | [diff] [blame] | 365 | const struct rockchip_dp_chip_data *dp_data; |
Yakir Yang | eb87c91 | 2016-06-29 17:15:30 +0800 | [diff] [blame] | 366 | struct drm_panel *panel = NULL; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 367 | struct rockchip_dp_device *dp; |
Rob Herring | ebc9446 | 2017-03-29 13:55:46 -0500 | [diff] [blame] | 368 | int ret; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 369 | |
Marek Szyprowski | 152cce0 | 2020-03-10 11:34:27 +0100 | [diff] [blame] | 370 | dp_data = of_device_get_match_data(dev); |
| 371 | if (!dp_data) |
| 372 | return -ENODEV; |
| 373 | |
Rob Herring | ebc9446 | 2017-03-29 13:55:46 -0500 | [diff] [blame] | 374 | ret = drm_of_find_panel_or_bridge(dev->of_node, 1, 0, &panel, NULL); |
Jeffy Chen | 102712a | 2017-10-19 11:48:04 +0800 | [diff] [blame] | 375 | if (ret < 0) |
Rob Herring | ebc9446 | 2017-03-29 13:55:46 -0500 | [diff] [blame] | 376 | return ret; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 377 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 378 | dp = devm_kzalloc(dev, sizeof(*dp), GFP_KERNEL); |
| 379 | if (!dp) |
| 380 | return -ENOMEM; |
| 381 | |
| 382 | dp->dev = dev; |
Tomasz Figa | a416960 | 2018-04-23 12:49:59 +0200 | [diff] [blame] | 383 | dp->adp = ERR_PTR(-ENODEV); |
Marek Szyprowski | 152cce0 | 2020-03-10 11:34:27 +0100 | [diff] [blame] | 384 | dp->data = dp_data; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 385 | dp->plat_data.panel = panel; |
Marek Szyprowski | 152cce0 | 2020-03-10 11:34:27 +0100 | [diff] [blame] | 386 | dp->plat_data.dev_type = dp->data->chip_type; |
| 387 | dp->plat_data.power_on_start = rockchip_dp_poweron_start; |
| 388 | dp->plat_data.power_off = rockchip_dp_powerdown; |
| 389 | dp->plat_data.get_modes = rockchip_dp_get_modes; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 390 | |
Jeffy Chen | 102712a | 2017-10-19 11:48:04 +0800 | [diff] [blame] | 391 | ret = rockchip_dp_of_probe(dp); |
| 392 | if (ret < 0) |
| 393 | return ret; |
| 394 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 395 | platform_set_drvdata(pdev, dp); |
| 396 | |
Marek Szyprowski | 152cce0 | 2020-03-10 11:34:27 +0100 | [diff] [blame] | 397 | dp->adp = analogix_dp_probe(dev, &dp->plat_data); |
| 398 | if (IS_ERR(dp->adp)) |
| 399 | return PTR_ERR(dp->adp); |
| 400 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 401 | return component_add(dev, &rockchip_dp_component_ops); |
| 402 | } |
| 403 | |
| 404 | static int rockchip_dp_remove(struct platform_device *pdev) |
| 405 | { |
Marek Szyprowski | 152cce0 | 2020-03-10 11:34:27 +0100 | [diff] [blame] | 406 | struct rockchip_dp_device *dp = platform_get_drvdata(pdev); |
| 407 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 408 | component_del(&pdev->dev, &rockchip_dp_component_ops); |
Marek Szyprowski | 152cce0 | 2020-03-10 11:34:27 +0100 | [diff] [blame] | 409 | analogix_dp_remove(dp->adp); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 410 | |
| 411 | return 0; |
| 412 | } |
| 413 | |
Jeffy Chen | 6b2d8fd | 2018-01-10 17:23:41 +0100 | [diff] [blame] | 414 | #ifdef CONFIG_PM_SLEEP |
| 415 | static int rockchip_dp_suspend(struct device *dev) |
| 416 | { |
| 417 | struct rockchip_dp_device *dp = dev_get_drvdata(dev); |
| 418 | |
Tomasz Figa | a416960 | 2018-04-23 12:49:59 +0200 | [diff] [blame] | 419 | if (IS_ERR(dp->adp)) |
| 420 | return 0; |
| 421 | |
Jeffy Chen | 6b2d8fd | 2018-01-10 17:23:41 +0100 | [diff] [blame] | 422 | return analogix_dp_suspend(dp->adp); |
| 423 | } |
| 424 | |
| 425 | static int rockchip_dp_resume(struct device *dev) |
| 426 | { |
| 427 | struct rockchip_dp_device *dp = dev_get_drvdata(dev); |
| 428 | |
Tomasz Figa | a416960 | 2018-04-23 12:49:59 +0200 | [diff] [blame] | 429 | if (IS_ERR(dp->adp)) |
| 430 | return 0; |
| 431 | |
Jeffy Chen | 6b2d8fd | 2018-01-10 17:23:41 +0100 | [diff] [blame] | 432 | return analogix_dp_resume(dp->adp); |
| 433 | } |
| 434 | #endif |
| 435 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 436 | static const struct dev_pm_ops rockchip_dp_pm_ops = { |
Tomeu Vizoso | fe64ba5 | 2016-06-06 16:53:33 +0200 | [diff] [blame] | 437 | #ifdef CONFIG_PM_SLEEP |
Douglas Anderson | f7ccbed | 2019-08-02 11:46:16 -0700 | [diff] [blame] | 438 | .suspend_late = rockchip_dp_suspend, |
Jeffy Chen | 6b2d8fd | 2018-01-10 17:23:41 +0100 | [diff] [blame] | 439 | .resume_early = rockchip_dp_resume, |
Tomeu Vizoso | fe64ba5 | 2016-06-06 16:53:33 +0200 | [diff] [blame] | 440 | #endif |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 441 | }; |
| 442 | |
Yakir Yang | 82872e4 | 2016-06-29 17:15:26 +0800 | [diff] [blame] | 443 | static const struct rockchip_dp_chip_data rk3399_edp = { |
| 444 | .lcdsel_grf_reg = RK3399_GRF_SOC_CON20, |
| 445 | .lcdsel_big = HIWORD_UPDATE(0, RK3399_EDP_LCDC_SEL), |
| 446 | .lcdsel_lit = HIWORD_UPDATE(RK3399_EDP_LCDC_SEL, RK3399_EDP_LCDC_SEL), |
| 447 | .chip_type = RK3399_EDP, |
| 448 | }; |
| 449 | |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 450 | static const struct rockchip_dp_chip_data rk3288_dp = { |
| 451 | .lcdsel_grf_reg = RK3288_GRF_SOC_CON6, |
| 452 | .lcdsel_big = HIWORD_UPDATE(0, RK3288_EDP_LCDC_SEL), |
| 453 | .lcdsel_lit = HIWORD_UPDATE(RK3288_EDP_LCDC_SEL, RK3288_EDP_LCDC_SEL), |
| 454 | .chip_type = RK3288_DP, |
| 455 | }; |
| 456 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 457 | static const struct of_device_id rockchip_dp_dt_ids[] = { |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 458 | {.compatible = "rockchip,rk3288-dp", .data = &rk3288_dp }, |
Yakir Yang | 82872e4 | 2016-06-29 17:15:26 +0800 | [diff] [blame] | 459 | {.compatible = "rockchip,rk3399-edp", .data = &rk3399_edp }, |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 460 | {} |
| 461 | }; |
| 462 | MODULE_DEVICE_TABLE(of, rockchip_dp_dt_ids); |
| 463 | |
Jeffy Chen | 8820b68 | 2017-03-22 11:21:20 +0800 | [diff] [blame] | 464 | struct platform_driver rockchip_dp_driver = { |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 465 | .probe = rockchip_dp_probe, |
| 466 | .remove = rockchip_dp_remove, |
| 467 | .driver = { |
| 468 | .name = "rockchip-dp", |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 469 | .pm = &rockchip_dp_pm_ops, |
Souptick Joarder | f7fc7a7 | 2021-06-08 00:18:36 +0530 | [diff] [blame] | 470 | .of_match_table = rockchip_dp_dt_ids, |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 471 | }, |
| 472 | }; |