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 | |
Sean Paul | d761b2d | 2016-08-16 17:12:45 -0700 | [diff] [blame] | 74 | struct work_struct psr_work; |
| 75 | spinlock_t psr_lock; |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 76 | unsigned int psr_state; |
| 77 | |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 78 | const struct rockchip_dp_chip_data *data; |
| 79 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 80 | struct analogix_dp_plat_data plat_data; |
| 81 | }; |
| 82 | |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 83 | static void analogix_dp_psr_set(struct drm_encoder *encoder, bool enabled) |
| 84 | { |
| 85 | struct rockchip_dp_device *dp = to_dp(encoder); |
Sean Paul | d761b2d | 2016-08-16 17:12:45 -0700 | [diff] [blame] | 86 | unsigned long flags; |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 87 | |
Tomeu Vizoso | 0546d68 | 2016-09-23 16:06:40 +0200 | [diff] [blame] | 88 | if (!analogix_dp_psr_supported(dp->dev)) |
| 89 | return; |
| 90 | |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 91 | dev_dbg(dp->dev, "%s PSR...\n", enabled ? "Entry" : "Exit"); |
| 92 | |
Sean Paul | d761b2d | 2016-08-16 17:12:45 -0700 | [diff] [blame] | 93 | spin_lock_irqsave(&dp->psr_lock, flags); |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 94 | if (enabled) |
| 95 | dp->psr_state = EDP_VSC_PSR_STATE_ACTIVE; |
| 96 | else |
| 97 | dp->psr_state = ~EDP_VSC_PSR_STATE_ACTIVE; |
| 98 | |
Sean Paul | d761b2d | 2016-08-16 17:12:45 -0700 | [diff] [blame] | 99 | schedule_work(&dp->psr_work); |
| 100 | spin_unlock_irqrestore(&dp->psr_lock, flags); |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static void analogix_dp_psr_work(struct work_struct *work) |
| 104 | { |
| 105 | struct rockchip_dp_device *dp = |
Sean Paul | d761b2d | 2016-08-16 17:12:45 -0700 | [diff] [blame] | 106 | container_of(work, typeof(*dp), psr_work); |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 107 | int ret; |
Sean Paul | d761b2d | 2016-08-16 17:12:45 -0700 | [diff] [blame] | 108 | unsigned long flags; |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 109 | |
Jeffy Chen | 459b086 | 2017-04-27 14:54:17 +0800 | [diff] [blame] | 110 | ret = rockchip_drm_wait_vact_end(dp->encoder.crtc, |
| 111 | PSR_WAIT_LINE_FLAG_TIMEOUT_MS); |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 112 | if (ret) { |
| 113 | dev_err(dp->dev, "line flag interrupt did not arrive\n"); |
| 114 | return; |
| 115 | } |
| 116 | |
Sean Paul | d761b2d | 2016-08-16 17:12:45 -0700 | [diff] [blame] | 117 | spin_lock_irqsave(&dp->psr_lock, flags); |
Jeffy Chen | aa5bfa4 | 2017-04-29 20:39:07 +0800 | [diff] [blame] | 118 | if (dp->psr_state == EDP_VSC_PSR_STATE_ACTIVE) |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 119 | analogix_dp_enable_psr(dp->dev); |
| 120 | else |
| 121 | analogix_dp_disable_psr(dp->dev); |
Sean Paul | d761b2d | 2016-08-16 17:12:45 -0700 | [diff] [blame] | 122 | spin_unlock_irqrestore(&dp->psr_lock, flags); |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 123 | } |
| 124 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 125 | static int rockchip_dp_pre_init(struct rockchip_dp_device *dp) |
| 126 | { |
| 127 | reset_control_assert(dp->rst); |
| 128 | usleep_range(10, 20); |
| 129 | reset_control_deassert(dp->rst); |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static int rockchip_dp_poweron(struct analogix_dp_plat_data *plat_data) |
| 135 | { |
| 136 | struct rockchip_dp_device *dp = to_dp(plat_data); |
| 137 | int ret; |
| 138 | |
Sean Paul | d761b2d | 2016-08-16 17:12:45 -0700 | [diff] [blame] | 139 | cancel_work_sync(&dp->psr_work); |
| 140 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 141 | ret = clk_prepare_enable(dp->pclk); |
| 142 | if (ret < 0) { |
| 143 | dev_err(dp->dev, "failed to enable pclk %d\n", ret); |
| 144 | return ret; |
| 145 | } |
| 146 | |
| 147 | ret = rockchip_dp_pre_init(dp); |
| 148 | if (ret < 0) { |
| 149 | dev_err(dp->dev, "failed to dp pre init %d\n", ret); |
Wei Yongjun | 3694c5c | 2016-07-19 11:32:43 +0000 | [diff] [blame] | 150 | clk_disable_unprepare(dp->pclk); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 151 | return ret; |
| 152 | } |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | static int rockchip_dp_powerdown(struct analogix_dp_plat_data *plat_data) |
| 158 | { |
| 159 | struct rockchip_dp_device *dp = to_dp(plat_data); |
| 160 | |
| 161 | clk_disable_unprepare(dp->pclk); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
Yakir Yang | db8a9ae | 2016-06-29 17:15:39 +0800 | [diff] [blame] | 166 | static int rockchip_dp_get_modes(struct analogix_dp_plat_data *plat_data, |
| 167 | struct drm_connector *connector) |
| 168 | { |
| 169 | struct drm_display_info *di = &connector->display_info; |
| 170 | /* VOP couldn't output YUV video format for eDP rightly */ |
| 171 | u32 mask = DRM_COLOR_FORMAT_YCRCB444 | DRM_COLOR_FORMAT_YCRCB422; |
| 172 | |
| 173 | if ((di->color_formats & mask)) { |
| 174 | DRM_DEBUG_KMS("Swapping display color format from YUV to RGB\n"); |
| 175 | di->color_formats &= ~mask; |
| 176 | di->color_formats |= DRM_COLOR_FORMAT_RGB444; |
| 177 | di->bpc = 8; |
| 178 | } |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 183 | static bool |
| 184 | rockchip_dp_drm_encoder_mode_fixup(struct drm_encoder *encoder, |
| 185 | const struct drm_display_mode *mode, |
| 186 | struct drm_display_mode *adjusted_mode) |
| 187 | { |
| 188 | /* do nothing */ |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | static void rockchip_dp_drm_encoder_mode_set(struct drm_encoder *encoder, |
| 193 | struct drm_display_mode *mode, |
| 194 | struct drm_display_mode *adjusted) |
| 195 | { |
| 196 | /* do nothing */ |
| 197 | } |
| 198 | |
| 199 | static void rockchip_dp_drm_encoder_enable(struct drm_encoder *encoder) |
| 200 | { |
| 201 | struct rockchip_dp_device *dp = to_dp(encoder); |
| 202 | int ret; |
| 203 | u32 val; |
| 204 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 205 | ret = drm_of_encoder_active_endpoint_id(dp->dev->of_node, encoder); |
| 206 | if (ret < 0) |
| 207 | return; |
| 208 | |
| 209 | if (ret) |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 210 | val = dp->data->lcdsel_lit; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 211 | else |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 212 | val = dp->data->lcdsel_big; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 213 | |
| 214 | dev_dbg(dp->dev, "vop %s output to dp\n", (ret) ? "LIT" : "BIG"); |
| 215 | |
Yakir Yang | dc1c93b | 2016-06-29 17:16:05 +0800 | [diff] [blame] | 216 | ret = clk_prepare_enable(dp->grfclk); |
| 217 | if (ret < 0) { |
| 218 | dev_err(dp->dev, "failed to enable grfclk %d\n", ret); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 219 | return; |
| 220 | } |
Yakir Yang | dc1c93b | 2016-06-29 17:16:05 +0800 | [diff] [blame] | 221 | |
| 222 | ret = regmap_write(dp->grf, dp->data->lcdsel_grf_reg, val); |
| 223 | if (ret != 0) |
| 224 | dev_err(dp->dev, "Could not write to GRF: %d\n", ret); |
| 225 | |
| 226 | clk_disable_unprepare(dp->grfclk); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | static void rockchip_dp_drm_encoder_nop(struct drm_encoder *encoder) |
| 230 | { |
| 231 | /* do nothing */ |
| 232 | } |
| 233 | |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 234 | static int |
| 235 | rockchip_dp_drm_encoder_atomic_check(struct drm_encoder *encoder, |
| 236 | struct drm_crtc_state *crtc_state, |
| 237 | struct drm_connector_state *conn_state) |
| 238 | { |
| 239 | struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state); |
| 240 | |
| 241 | /* |
Yakir Yang | d698f0e | 2016-06-29 17:15:44 +0800 | [diff] [blame] | 242 | * The hardware IC designed that VOP must output the RGB10 video |
| 243 | * format to eDP controller, and if eDP panel only support RGB8, |
| 244 | * then eDP controller should cut down the video data, not via VOP |
| 245 | * controller, that's why we need to hardcode the VOP output mode |
| 246 | * to RGA10 here. |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 247 | */ |
Yakir Yang | 82872e4 | 2016-06-29 17:15:26 +0800 | [diff] [blame] | 248 | |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 249 | s->output_mode = ROCKCHIP_OUT_MODE_AAAA; |
| 250 | s->output_type = DRM_MODE_CONNECTOR_eDP; |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 255 | static struct drm_encoder_helper_funcs rockchip_dp_encoder_helper_funcs = { |
| 256 | .mode_fixup = rockchip_dp_drm_encoder_mode_fixup, |
| 257 | .mode_set = rockchip_dp_drm_encoder_mode_set, |
| 258 | .enable = rockchip_dp_drm_encoder_enable, |
| 259 | .disable = rockchip_dp_drm_encoder_nop, |
Mark Yao | 4e257d9 | 2016-04-20 10:41:42 +0800 | [diff] [blame] | 260 | .atomic_check = rockchip_dp_drm_encoder_atomic_check, |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | static void rockchip_dp_drm_encoder_destroy(struct drm_encoder *encoder) |
| 264 | { |
| 265 | drm_encoder_cleanup(encoder); |
| 266 | } |
| 267 | |
| 268 | static struct drm_encoder_funcs rockchip_dp_encoder_funcs = { |
| 269 | .destroy = rockchip_dp_drm_encoder_destroy, |
| 270 | }; |
| 271 | |
| 272 | static int rockchip_dp_init(struct rockchip_dp_device *dp) |
| 273 | { |
| 274 | struct device *dev = dp->dev; |
| 275 | struct device_node *np = dev->of_node; |
| 276 | int ret; |
| 277 | |
| 278 | dp->grf = syscon_regmap_lookup_by_phandle(np, "rockchip,grf"); |
| 279 | if (IS_ERR(dp->grf)) { |
| 280 | dev_err(dev, "failed to get rockchip,grf property\n"); |
| 281 | return PTR_ERR(dp->grf); |
| 282 | } |
| 283 | |
Yakir Yang | dc1c93b | 2016-06-29 17:16:05 +0800 | [diff] [blame] | 284 | dp->grfclk = devm_clk_get(dev, "grf"); |
| 285 | if (PTR_ERR(dp->grfclk) == -ENOENT) { |
| 286 | dp->grfclk = NULL; |
| 287 | } else if (PTR_ERR(dp->grfclk) == -EPROBE_DEFER) { |
| 288 | return -EPROBE_DEFER; |
| 289 | } else if (IS_ERR(dp->grfclk)) { |
| 290 | dev_err(dev, "failed to get grf clock\n"); |
| 291 | return PTR_ERR(dp->grfclk); |
| 292 | } |
| 293 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 294 | dp->pclk = devm_clk_get(dev, "pclk"); |
| 295 | if (IS_ERR(dp->pclk)) { |
| 296 | dev_err(dev, "failed to get pclk property\n"); |
| 297 | return PTR_ERR(dp->pclk); |
| 298 | } |
| 299 | |
| 300 | dp->rst = devm_reset_control_get(dev, "dp"); |
| 301 | if (IS_ERR(dp->rst)) { |
| 302 | dev_err(dev, "failed to get dp reset control\n"); |
| 303 | return PTR_ERR(dp->rst); |
| 304 | } |
| 305 | |
| 306 | ret = clk_prepare_enable(dp->pclk); |
| 307 | if (ret < 0) { |
| 308 | dev_err(dp->dev, "failed to enable pclk %d\n", ret); |
| 309 | return ret; |
| 310 | } |
| 311 | |
| 312 | ret = rockchip_dp_pre_init(dp); |
| 313 | if (ret < 0) { |
| 314 | dev_err(dp->dev, "failed to pre init %d\n", ret); |
Wei Yongjun | 3694c5c | 2016-07-19 11:32:43 +0000 | [diff] [blame] | 315 | clk_disable_unprepare(dp->pclk); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 316 | return ret; |
| 317 | } |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | static int rockchip_dp_drm_create_encoder(struct rockchip_dp_device *dp) |
| 323 | { |
| 324 | struct drm_encoder *encoder = &dp->encoder; |
| 325 | struct drm_device *drm_dev = dp->drm_dev; |
| 326 | struct device *dev = dp->dev; |
| 327 | int ret; |
| 328 | |
| 329 | encoder->possible_crtcs = drm_of_find_possible_crtcs(drm_dev, |
| 330 | dev->of_node); |
| 331 | DRM_DEBUG_KMS("possible_crtcs = 0x%x\n", encoder->possible_crtcs); |
| 332 | |
| 333 | ret = drm_encoder_init(drm_dev, encoder, &rockchip_dp_encoder_funcs, |
| 334 | DRM_MODE_ENCODER_TMDS, NULL); |
| 335 | if (ret) { |
| 336 | DRM_ERROR("failed to initialize encoder with drm\n"); |
| 337 | return ret; |
| 338 | } |
| 339 | |
| 340 | drm_encoder_helper_add(encoder, &rockchip_dp_encoder_helper_funcs); |
| 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | static int rockchip_dp_bind(struct device *dev, struct device *master, |
| 346 | void *data) |
| 347 | { |
| 348 | struct rockchip_dp_device *dp = dev_get_drvdata(dev); |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 349 | const struct rockchip_dp_chip_data *dp_data; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 350 | struct drm_device *drm_dev = data; |
| 351 | int ret; |
| 352 | |
| 353 | /* |
| 354 | * Just like the probe function said, we don't need the |
| 355 | * device drvrate anymore, we should leave the charge to |
| 356 | * analogix dp driver, set the device drvdata to NULL. |
| 357 | */ |
| 358 | dev_set_drvdata(dev, NULL); |
| 359 | |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 360 | dp_data = of_device_get_match_data(dev); |
| 361 | if (!dp_data) |
| 362 | return -ENODEV; |
| 363 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 364 | ret = rockchip_dp_init(dp); |
| 365 | if (ret < 0) |
| 366 | return ret; |
| 367 | |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 368 | dp->data = dp_data; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 369 | dp->drm_dev = drm_dev; |
| 370 | |
| 371 | ret = rockchip_dp_drm_create_encoder(dp); |
| 372 | if (ret) { |
| 373 | DRM_ERROR("failed to create drm encoder\n"); |
| 374 | return ret; |
| 375 | } |
| 376 | |
| 377 | dp->plat_data.encoder = &dp->encoder; |
| 378 | |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 379 | dp->plat_data.dev_type = dp->data->chip_type; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 380 | dp->plat_data.power_on = rockchip_dp_poweron; |
| 381 | dp->plat_data.power_off = rockchip_dp_powerdown; |
Yakir Yang | db8a9ae | 2016-06-29 17:15:39 +0800 | [diff] [blame] | 382 | dp->plat_data.get_modes = rockchip_dp_get_modes; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 383 | |
Sean Paul | d761b2d | 2016-08-16 17:12:45 -0700 | [diff] [blame] | 384 | spin_lock_init(&dp->psr_lock); |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 385 | dp->psr_state = ~EDP_VSC_PSR_STATE_ACTIVE; |
Sean Paul | d761b2d | 2016-08-16 17:12:45 -0700 | [diff] [blame] | 386 | INIT_WORK(&dp->psr_work, analogix_dp_psr_work); |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 387 | |
| 388 | rockchip_drm_psr_register(&dp->encoder, analogix_dp_psr_set); |
| 389 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 390 | return analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data); |
| 391 | } |
| 392 | |
| 393 | static void rockchip_dp_unbind(struct device *dev, struct device *master, |
| 394 | void *data) |
| 395 | { |
Yakir Yang | 8f0ac5c | 2016-07-24 14:57:52 +0800 | [diff] [blame] | 396 | struct rockchip_dp_device *dp = dev_get_drvdata(dev); |
| 397 | |
| 398 | rockchip_drm_psr_unregister(&dp->encoder); |
| 399 | |
Jeffy Chen | b7ac7b5 | 2017-04-06 20:31:22 +0800 | [diff] [blame] | 400 | analogix_dp_unbind(dev, master, data); |
| 401 | clk_disable_unprepare(dp->pclk); |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static const struct component_ops rockchip_dp_component_ops = { |
| 405 | .bind = rockchip_dp_bind, |
| 406 | .unbind = rockchip_dp_unbind, |
| 407 | }; |
| 408 | |
| 409 | static int rockchip_dp_probe(struct platform_device *pdev) |
| 410 | { |
| 411 | struct device *dev = &pdev->dev; |
Yakir Yang | eb87c91 | 2016-06-29 17:15:30 +0800 | [diff] [blame] | 412 | struct drm_panel *panel = NULL; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 413 | struct rockchip_dp_device *dp; |
Rob Herring | ebc9446 | 2017-03-29 13:55:46 -0500 | [diff] [blame] | 414 | int ret; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 415 | |
Rob Herring | ebc9446 | 2017-03-29 13:55:46 -0500 | [diff] [blame] | 416 | ret = drm_of_find_panel_or_bridge(dev->of_node, 1, 0, &panel, NULL); |
| 417 | if (ret) |
| 418 | return ret; |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 419 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 420 | dp = devm_kzalloc(dev, sizeof(*dp), GFP_KERNEL); |
| 421 | if (!dp) |
| 422 | return -ENOMEM; |
| 423 | |
| 424 | dp->dev = dev; |
| 425 | |
| 426 | dp->plat_data.panel = panel; |
| 427 | |
| 428 | /* |
| 429 | * We just use the drvdata until driver run into component |
| 430 | * add function, and then we would set drvdata to null, so |
| 431 | * that analogix dp driver could take charge of the drvdata. |
| 432 | */ |
| 433 | platform_set_drvdata(pdev, dp); |
| 434 | |
| 435 | return component_add(dev, &rockchip_dp_component_ops); |
| 436 | } |
| 437 | |
| 438 | static int rockchip_dp_remove(struct platform_device *pdev) |
| 439 | { |
| 440 | component_del(&pdev->dev, &rockchip_dp_component_ops); |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 445 | static const struct dev_pm_ops rockchip_dp_pm_ops = { |
Tomeu Vizoso | fe64ba5 | 2016-06-06 16:53:33 +0200 | [diff] [blame] | 446 | #ifdef CONFIG_PM_SLEEP |
| 447 | .suspend = analogix_dp_suspend, |
| 448 | .resume_early = analogix_dp_resume, |
| 449 | #endif |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 450 | }; |
| 451 | |
Yakir Yang | 82872e4 | 2016-06-29 17:15:26 +0800 | [diff] [blame] | 452 | static const struct rockchip_dp_chip_data rk3399_edp = { |
| 453 | .lcdsel_grf_reg = RK3399_GRF_SOC_CON20, |
| 454 | .lcdsel_big = HIWORD_UPDATE(0, RK3399_EDP_LCDC_SEL), |
| 455 | .lcdsel_lit = HIWORD_UPDATE(RK3399_EDP_LCDC_SEL, RK3399_EDP_LCDC_SEL), |
| 456 | .chip_type = RK3399_EDP, |
| 457 | }; |
| 458 | |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 459 | static const struct rockchip_dp_chip_data rk3288_dp = { |
| 460 | .lcdsel_grf_reg = RK3288_GRF_SOC_CON6, |
| 461 | .lcdsel_big = HIWORD_UPDATE(0, RK3288_EDP_LCDC_SEL), |
| 462 | .lcdsel_lit = HIWORD_UPDATE(RK3288_EDP_LCDC_SEL, RK3288_EDP_LCDC_SEL), |
| 463 | .chip_type = RK3288_DP, |
| 464 | }; |
| 465 | |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 466 | static const struct of_device_id rockchip_dp_dt_ids[] = { |
Yakir Yang | d9c900b | 2016-06-29 17:15:01 +0800 | [diff] [blame] | 467 | {.compatible = "rockchip,rk3288-dp", .data = &rk3288_dp }, |
Yakir Yang | 82872e4 | 2016-06-29 17:15:26 +0800 | [diff] [blame] | 468 | {.compatible = "rockchip,rk3399-edp", .data = &rk3399_edp }, |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 469 | {} |
| 470 | }; |
| 471 | MODULE_DEVICE_TABLE(of, rockchip_dp_dt_ids); |
| 472 | |
Jeffy Chen | 8820b68 | 2017-03-22 11:21:20 +0800 | [diff] [blame] | 473 | struct platform_driver rockchip_dp_driver = { |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 474 | .probe = rockchip_dp_probe, |
| 475 | .remove = rockchip_dp_remove, |
| 476 | .driver = { |
| 477 | .name = "rockchip-dp", |
Yakir Yang | 9e32e16 | 2016-03-29 09:57:30 +0800 | [diff] [blame] | 478 | .pm = &rockchip_dp_pm_ops, |
| 479 | .of_match_table = of_match_ptr(rockchip_dp_dt_ids), |
| 480 | }, |
| 481 | }; |