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