Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #define pr_fmt(fmt) "[drm-dp] %s: " fmt, __func__ |
| 16 | |
| 17 | #include "dp_panel.h" |
| 18 | |
Ajay Singh Parmar | f63dbc7ab | 2017-07-02 22:45:28 -0700 | [diff] [blame] | 19 | #define DP_PANEL_DEFAULT_BPP 24 |
Padmanabhan Komanduru | 5871728 | 2017-08-28 17:01:49 +0530 | [diff] [blame] | 20 | #define DP_MAX_DS_PORT_COUNT 1 |
Ajay Singh Parmar | f63dbc7ab | 2017-07-02 22:45:28 -0700 | [diff] [blame] | 21 | |
Padmanabhan Komanduru | d84b38b | 2017-05-24 04:24:57 -0700 | [diff] [blame] | 22 | enum { |
| 23 | DP_LINK_RATE_MULTIPLIER = 27000000, |
| 24 | }; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 25 | |
| 26 | struct dp_panel_private { |
| 27 | struct device *dev; |
| 28 | struct dp_panel dp_panel; |
| 29 | struct dp_aux *aux; |
Padmanabhan Komanduru | fdafc41 | 2017-09-11 13:13:38 +0530 | [diff] [blame] | 30 | struct dp_link *link; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 31 | struct dp_catalog_panel *catalog; |
Padmanabhan Komanduru | 2e9914b | 2017-08-04 20:51:31 +0530 | [diff] [blame] | 32 | bool aux_cfg_update_done; |
Ajay Singh Parmar | 4c92d39 | 2017-08-30 22:51:10 -0700 | [diff] [blame^] | 33 | bool custom_edid; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Padmanabhan Komanduru | ef656fa | 2017-09-19 20:33:27 +0530 | [diff] [blame] | 36 | static const struct dp_panel_info fail_safe = { |
| 37 | .h_active = 640, |
| 38 | .v_active = 480, |
| 39 | .h_back_porch = 48, |
| 40 | .h_front_porch = 16, |
| 41 | .h_sync_width = 96, |
| 42 | .h_active_low = 0, |
| 43 | .v_back_porch = 33, |
| 44 | .v_front_porch = 10, |
| 45 | .v_sync_width = 2, |
| 46 | .v_active_low = 0, |
| 47 | .h_skew = 0, |
| 48 | .refresh_rate = 60, |
| 49 | .pixel_clk_khz = 25200, |
| 50 | .bpp = 24, |
| 51 | }; |
| 52 | |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 53 | static int dp_panel_read_dpcd(struct dp_panel *dp_panel) |
| 54 | { |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 55 | int rlen, rc = 0; |
| 56 | struct dp_panel_private *panel; |
Ajay Singh Parmar | a4b0606 | 2017-06-23 17:10:36 -0700 | [diff] [blame] | 57 | struct drm_dp_link *link_info; |
Padmanabhan Komanduru | 5871728 | 2017-08-28 17:01:49 +0530 | [diff] [blame] | 58 | u8 *dpcd, major = 0, minor = 0; |
| 59 | u32 dfp_count = 0; |
Ajay Singh Parmar | a4b0606 | 2017-06-23 17:10:36 -0700 | [diff] [blame] | 60 | unsigned long caps = DP_LINK_CAP_ENHANCED_FRAMING; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 61 | |
| 62 | if (!dp_panel) { |
| 63 | pr_err("invalid input\n"); |
| 64 | rc = -EINVAL; |
| 65 | goto end; |
| 66 | } |
| 67 | |
Padmanabhan Komanduru | 5871728 | 2017-08-28 17:01:49 +0530 | [diff] [blame] | 68 | dpcd = dp_panel->dpcd; |
| 69 | |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 70 | panel = container_of(dp_panel, struct dp_panel_private, dp_panel); |
Ajay Singh Parmar | a4b0606 | 2017-06-23 17:10:36 -0700 | [diff] [blame] | 71 | link_info = &dp_panel->link_info; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 72 | |
Padmanabhan Komanduru | d84b38b | 2017-05-24 04:24:57 -0700 | [diff] [blame] | 73 | rlen = drm_dp_dpcd_read(panel->aux->drm_aux, DP_DPCD_REV, |
Padmanabhan Komanduru | 5871728 | 2017-08-28 17:01:49 +0530 | [diff] [blame] | 74 | dpcd, (DP_RECEIVER_CAP_SIZE + 1)); |
Padmanabhan Komanduru | d84b38b | 2017-05-24 04:24:57 -0700 | [diff] [blame] | 75 | if (rlen < (DP_RECEIVER_CAP_SIZE + 1)) { |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 76 | pr_err("dpcd read failed, rlen=%d\n", rlen); |
| 77 | rc = -EINVAL; |
| 78 | goto end; |
| 79 | } |
| 80 | |
Ajay Singh Parmar | a4b0606 | 2017-06-23 17:10:36 -0700 | [diff] [blame] | 81 | link_info->revision = dp_panel->dpcd[DP_DPCD_REV]; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 82 | |
Ajay Singh Parmar | a4b0606 | 2017-06-23 17:10:36 -0700 | [diff] [blame] | 83 | major = (link_info->revision >> 4) & 0x0f; |
| 84 | minor = link_info->revision & 0x0f; |
Padmanabhan Komanduru | d84b38b | 2017-05-24 04:24:57 -0700 | [diff] [blame] | 85 | pr_debug("version: %d.%d\n", major, minor); |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 86 | |
Ajay Singh Parmar | a4b0606 | 2017-06-23 17:10:36 -0700 | [diff] [blame] | 87 | link_info->rate = |
Padmanabhan Komanduru | d84b38b | 2017-05-24 04:24:57 -0700 | [diff] [blame] | 88 | drm_dp_bw_code_to_link_rate(dp_panel->dpcd[DP_MAX_LINK_RATE]); |
Ajay Singh Parmar | a4b0606 | 2017-06-23 17:10:36 -0700 | [diff] [blame] | 89 | pr_debug("link_rate=%d\n", link_info->rate); |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 90 | |
Ajay Singh Parmar | dd30789 | 2017-08-15 16:08:59 -0700 | [diff] [blame] | 91 | link_info->num_lanes = dp_panel->dpcd[DP_MAX_LANE_COUNT] & |
| 92 | DP_MAX_LANE_COUNT_MASK; |
Ajay Singh Parmar | f63dbc7ab | 2017-07-02 22:45:28 -0700 | [diff] [blame] | 93 | |
Ajay Singh Parmar | a4b0606 | 2017-06-23 17:10:36 -0700 | [diff] [blame] | 94 | pr_debug("lane_count=%d\n", link_info->num_lanes); |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 95 | |
Padmanabhan Komanduru | 5871728 | 2017-08-28 17:01:49 +0530 | [diff] [blame] | 96 | if (drm_dp_enhanced_frame_cap(dpcd)) |
Ajay Singh Parmar | a4b0606 | 2017-06-23 17:10:36 -0700 | [diff] [blame] | 97 | link_info->capabilities |= caps; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 98 | |
Padmanabhan Komanduru | 5871728 | 2017-08-28 17:01:49 +0530 | [diff] [blame] | 99 | dfp_count = dpcd[DP_DOWN_STREAM_PORT_COUNT] & |
| 100 | DP_DOWN_STREAM_PORT_COUNT; |
| 101 | |
| 102 | if ((dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT) |
| 103 | && (dpcd[DP_DPCD_REV] > 0x10)) { |
| 104 | rlen = drm_dp_dpcd_read(panel->aux->drm_aux, |
| 105 | DP_DOWNSTREAM_PORT_0, dp_panel->ds_ports, |
| 106 | DP_MAX_DOWNSTREAM_PORTS); |
| 107 | if (rlen < DP_MAX_DOWNSTREAM_PORTS) { |
| 108 | pr_err("ds port status failed, rlen=%d\n", rlen); |
| 109 | rc = -EINVAL; |
| 110 | goto end; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | if (dfp_count > DP_MAX_DS_PORT_COUNT) |
| 115 | pr_debug("DS port count %d greater that max (%d) supported\n", |
| 116 | dfp_count, DP_MAX_DS_PORT_COUNT); |
| 117 | |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 118 | end: |
| 119 | return rc; |
| 120 | } |
| 121 | |
Padmanabhan Komanduru | ef656fa | 2017-09-19 20:33:27 +0530 | [diff] [blame] | 122 | static int dp_panel_set_default_link_params(struct dp_panel *dp_panel) |
| 123 | { |
| 124 | struct drm_dp_link *link_info; |
| 125 | const int default_bw_code = 162000; |
| 126 | const int default_num_lanes = 1; |
| 127 | |
| 128 | if (!dp_panel) { |
| 129 | pr_err("invalid input\n"); |
| 130 | return -EINVAL; |
| 131 | } |
| 132 | link_info = &dp_panel->link_info; |
| 133 | link_info->rate = default_bw_code; |
| 134 | link_info->num_lanes = default_num_lanes; |
| 135 | pr_debug("link_rate=%d num_lanes=%d\n", |
| 136 | link_info->rate, link_info->num_lanes); |
Ajay Singh Parmar | 4c92d39 | 2017-08-30 22:51:10 -0700 | [diff] [blame^] | 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static int dp_panel_set_edid(struct dp_panel *dp_panel, u8 *edid) |
| 142 | { |
| 143 | struct dp_panel_private *panel; |
| 144 | |
| 145 | if (!dp_panel) { |
| 146 | pr_err("invalid input\n"); |
| 147 | return -EINVAL; |
| 148 | } |
| 149 | |
| 150 | panel = container_of(dp_panel, struct dp_panel_private, dp_panel); |
| 151 | |
| 152 | if (edid) { |
| 153 | dp_panel->edid_ctrl->edid = (struct edid *)edid; |
| 154 | panel->custom_edid = true; |
| 155 | } else { |
| 156 | panel->custom_edid = false; |
| 157 | } |
| 158 | |
Padmanabhan Komanduru | ef656fa | 2017-09-19 20:33:27 +0530 | [diff] [blame] | 159 | return 0; |
| 160 | } |
Padmanabhan Komanduru | 2e9914b | 2017-08-04 20:51:31 +0530 | [diff] [blame] | 161 | |
| 162 | static int dp_panel_read_edid(struct dp_panel *dp_panel, |
| 163 | struct drm_connector *connector) |
| 164 | { |
| 165 | int retry_cnt = 0; |
| 166 | const int max_retry = 10; |
| 167 | struct dp_panel_private *panel; |
| 168 | |
| 169 | if (!dp_panel) { |
| 170 | pr_err("invalid input\n"); |
| 171 | return -EINVAL; |
| 172 | } |
| 173 | |
| 174 | panel = container_of(dp_panel, struct dp_panel_private, dp_panel); |
| 175 | |
Ajay Singh Parmar | 4c92d39 | 2017-08-30 22:51:10 -0700 | [diff] [blame^] | 176 | if (panel->custom_edid) { |
| 177 | pr_debug("skip edid read in debug mode\n"); |
| 178 | return 0; |
| 179 | } |
| 180 | |
Padmanabhan Komanduru | 2e9914b | 2017-08-04 20:51:31 +0530 | [diff] [blame] | 181 | do { |
| 182 | sde_get_edid(connector, &panel->aux->drm_aux->ddc, |
| 183 | (void **)&dp_panel->edid_ctrl); |
| 184 | if (!dp_panel->edid_ctrl->edid) { |
| 185 | pr_err("EDID read failed\n"); |
| 186 | retry_cnt++; |
| 187 | panel->aux->reconfig(panel->aux); |
| 188 | panel->aux_cfg_update_done = true; |
| 189 | } else { |
| 190 | return 0; |
| 191 | } |
| 192 | } while (retry_cnt < max_retry); |
| 193 | |
| 194 | return -EINVAL; |
| 195 | } |
| 196 | |
| 197 | static int dp_panel_read_sink_caps(struct dp_panel *dp_panel, |
| 198 | struct drm_connector *connector) |
| 199 | { |
| 200 | int rc = 0; |
| 201 | struct dp_panel_private *panel; |
| 202 | |
| 203 | if (!dp_panel || !connector) { |
| 204 | pr_err("invalid input\n"); |
| 205 | return -EINVAL; |
| 206 | } |
| 207 | |
| 208 | panel = container_of(dp_panel, struct dp_panel_private, dp_panel); |
| 209 | |
| 210 | rc = dp_panel_read_dpcd(dp_panel); |
Padmanabhan Komanduru | ef656fa | 2017-09-19 20:33:27 +0530 | [diff] [blame] | 211 | if (rc || !is_link_rate_valid(drm_dp_link_rate_to_bw_code( |
| 212 | dp_panel->link_info.rate)) || !is_lane_count_valid( |
Padmanabhan Komanduru | 87222e7 | 2017-09-21 18:27:25 +0530 | [diff] [blame] | 213 | dp_panel->link_info.num_lanes) || |
| 214 | ((drm_dp_link_rate_to_bw_code(dp_panel->link_info.rate)) > |
| 215 | dp_panel->max_bw_code)) { |
Padmanabhan Komanduru | ef656fa | 2017-09-19 20:33:27 +0530 | [diff] [blame] | 216 | pr_err("panel dpcd read failed/incorrect, set default params\n"); |
| 217 | dp_panel_set_default_link_params(dp_panel); |
Padmanabhan Komanduru | 2e9914b | 2017-08-04 20:51:31 +0530 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | rc = dp_panel_read_edid(dp_panel, connector); |
| 221 | if (rc) { |
Padmanabhan Komanduru | ef656fa | 2017-09-19 20:33:27 +0530 | [diff] [blame] | 222 | pr_err("panel edid read failed, set failsafe mode\n"); |
Padmanabhan Komanduru | 2e9914b | 2017-08-04 20:51:31 +0530 | [diff] [blame] | 223 | return rc; |
| 224 | } |
| 225 | |
| 226 | if (panel->aux_cfg_update_done) { |
| 227 | pr_debug("read DPCD with updated AUX config\n"); |
| 228 | dp_panel_read_dpcd(dp_panel); |
| 229 | panel->aux_cfg_update_done = false; |
| 230 | } |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
Tatenda Chipeperekwa | 8a44bd9 | 2017-10-05 16:32:06 -0700 | [diff] [blame] | 235 | static u32 dp_panel_get_supported_bpp(struct dp_panel *dp_panel, |
| 236 | u32 mode_edid_bpp, u32 mode_pclk_khz) |
Padmanabhan Komanduru | d5eae9d | 2017-06-22 19:23:36 +0530 | [diff] [blame] | 237 | { |
Ajay Singh Parmar | a4b0606 | 2017-06-23 17:10:36 -0700 | [diff] [blame] | 238 | struct drm_dp_link *link_info; |
Tatenda Chipeperekwa | 8a44bd9 | 2017-10-05 16:32:06 -0700 | [diff] [blame] | 239 | const u32 max_supported_bpp = 30, min_supported_bpp = 18; |
| 240 | u32 bpp = 0, data_rate_khz = 0; |
Padmanabhan Komanduru | d5eae9d | 2017-06-22 19:23:36 +0530 | [diff] [blame] | 241 | |
Tatenda Chipeperekwa | 8a44bd9 | 2017-10-05 16:32:06 -0700 | [diff] [blame] | 242 | bpp = min_t(u32, mode_edid_bpp, max_supported_bpp); |
| 243 | |
| 244 | link_info = &dp_panel->link_info; |
| 245 | data_rate_khz = link_info->num_lanes * link_info->rate * 8; |
| 246 | |
| 247 | while (bpp > min_supported_bpp) { |
| 248 | if (mode_pclk_khz * bpp <= data_rate_khz) |
| 249 | break; |
| 250 | bpp -= 6; |
| 251 | } |
| 252 | |
| 253 | return bpp; |
| 254 | } |
| 255 | |
| 256 | static u32 dp_panel_get_mode_bpp(struct dp_panel *dp_panel, |
| 257 | u32 mode_edid_bpp, u32 mode_pclk_khz) |
| 258 | { |
| 259 | struct dp_panel_private *panel; |
| 260 | u32 bpp = mode_edid_bpp; |
| 261 | |
| 262 | if (!dp_panel || !mode_edid_bpp || !mode_pclk_khz) { |
Padmanabhan Komanduru | d5eae9d | 2017-06-22 19:23:36 +0530 | [diff] [blame] | 263 | pr_err("invalid input\n"); |
| 264 | return 0; |
| 265 | } |
| 266 | |
Tatenda Chipeperekwa | 8a44bd9 | 2017-10-05 16:32:06 -0700 | [diff] [blame] | 267 | panel = container_of(dp_panel, struct dp_panel_private, dp_panel); |
Padmanabhan Komanduru | d5eae9d | 2017-06-22 19:23:36 +0530 | [diff] [blame] | 268 | |
Tatenda Chipeperekwa | 8a44bd9 | 2017-10-05 16:32:06 -0700 | [diff] [blame] | 269 | if (dp_panel->video_test) |
| 270 | bpp = dp_link_bit_depth_to_bpp( |
| 271 | panel->link->test_video.test_bit_depth); |
| 272 | else |
| 273 | bpp = dp_panel_get_supported_bpp(dp_panel, mode_edid_bpp, |
| 274 | mode_pclk_khz); |
Padmanabhan Komanduru | d5eae9d | 2017-06-22 19:23:36 +0530 | [diff] [blame] | 275 | |
Tatenda Chipeperekwa | 8a44bd9 | 2017-10-05 16:32:06 -0700 | [diff] [blame] | 276 | return bpp; |
Padmanabhan Komanduru | d5eae9d | 2017-06-22 19:23:36 +0530 | [diff] [blame] | 277 | } |
| 278 | |
Padmanabhan Komanduru | fdafc41 | 2017-09-11 13:13:38 +0530 | [diff] [blame] | 279 | static void dp_panel_set_test_mode(struct dp_panel_private *panel, |
| 280 | struct dp_display_mode *mode) |
| 281 | { |
| 282 | struct dp_panel_info *pinfo = NULL; |
| 283 | struct dp_link_test_video *test_info = NULL; |
| 284 | |
| 285 | if (!panel) { |
| 286 | pr_err("invalid params\n"); |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | pinfo = &mode->timing; |
| 291 | test_info = &panel->link->test_video; |
| 292 | |
| 293 | pinfo->h_active = test_info->test_h_width; |
| 294 | pinfo->h_sync_width = test_info->test_hsync_width; |
| 295 | pinfo->h_back_porch = test_info->test_h_start - |
| 296 | test_info->test_hsync_width; |
| 297 | pinfo->h_front_porch = test_info->test_h_total - |
| 298 | (test_info->test_h_start + test_info->test_h_width); |
| 299 | |
| 300 | pinfo->v_active = test_info->test_v_height; |
| 301 | pinfo->v_sync_width = test_info->test_vsync_width; |
| 302 | pinfo->v_back_porch = test_info->test_v_start - |
| 303 | test_info->test_vsync_width; |
| 304 | pinfo->v_front_porch = test_info->test_v_total - |
| 305 | (test_info->test_v_start + test_info->test_v_height); |
| 306 | |
| 307 | pinfo->bpp = dp_link_bit_depth_to_bpp(test_info->test_bit_depth); |
| 308 | pinfo->h_active_low = test_info->test_hsync_pol; |
| 309 | pinfo->v_active_low = test_info->test_vsync_pol; |
| 310 | |
| 311 | pinfo->refresh_rate = test_info->test_rr_n; |
| 312 | pinfo->pixel_clk_khz = test_info->test_h_total * |
| 313 | test_info->test_v_total * pinfo->refresh_rate; |
| 314 | |
| 315 | if (test_info->test_rr_d == 0) |
| 316 | pinfo->pixel_clk_khz /= 1000; |
| 317 | else |
| 318 | pinfo->pixel_clk_khz /= 1001; |
| 319 | |
| 320 | if (test_info->test_h_width == 640) |
| 321 | pinfo->pixel_clk_khz = 25170; |
| 322 | } |
| 323 | |
| 324 | static int dp_panel_get_modes(struct dp_panel *dp_panel, |
| 325 | struct drm_connector *connector, struct dp_display_mode *mode) |
| 326 | { |
| 327 | struct dp_panel_private *panel; |
| 328 | |
| 329 | if (!dp_panel) { |
| 330 | pr_err("invalid input\n"); |
| 331 | return -EINVAL; |
| 332 | } |
| 333 | |
| 334 | panel = container_of(dp_panel, struct dp_panel_private, dp_panel); |
| 335 | |
| 336 | if (dp_panel->video_test) { |
| 337 | dp_panel_set_test_mode(panel, mode); |
| 338 | return 1; |
| 339 | } else if (dp_panel->edid_ctrl->edid) { |
| 340 | return _sde_edid_update_modes(connector, dp_panel->edid_ctrl); |
Padmanabhan Komanduru | ef656fa | 2017-09-19 20:33:27 +0530 | [diff] [blame] | 341 | } else { /* fail-safe mode */ |
| 342 | memcpy(&mode->timing, &fail_safe, |
| 343 | sizeof(fail_safe)); |
| 344 | return 1; |
Padmanabhan Komanduru | fdafc41 | 2017-09-11 13:13:38 +0530 | [diff] [blame] | 345 | } |
Padmanabhan Komanduru | fdafc41 | 2017-09-11 13:13:38 +0530 | [diff] [blame] | 346 | } |
| 347 | |
Padmanabhan Komanduru | 504e289 | 2017-09-19 20:38:31 +0530 | [diff] [blame] | 348 | static void dp_panel_handle_sink_request(struct dp_panel *dp_panel) |
| 349 | { |
| 350 | struct dp_panel_private *panel; |
| 351 | |
| 352 | if (!dp_panel) { |
| 353 | pr_err("invalid input\n"); |
| 354 | return; |
| 355 | } |
| 356 | |
| 357 | panel = container_of(dp_panel, struct dp_panel_private, dp_panel); |
| 358 | |
| 359 | if (panel->link->sink_request & DP_TEST_LINK_EDID_READ) { |
| 360 | u8 checksum = sde_get_edid_checksum(dp_panel->edid_ctrl); |
| 361 | |
| 362 | panel->link->send_edid_checksum(panel->link, checksum); |
| 363 | panel->link->send_test_response(panel->link); |
| 364 | } |
| 365 | } |
| 366 | |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 367 | static int dp_panel_timing_cfg(struct dp_panel *dp_panel) |
| 368 | { |
| 369 | int rc = 0; |
| 370 | u32 data, total_ver, total_hor; |
| 371 | struct dp_catalog_panel *catalog; |
| 372 | struct dp_panel_private *panel; |
| 373 | struct dp_panel_info *pinfo; |
| 374 | |
| 375 | if (!dp_panel) { |
| 376 | pr_err("invalid input\n"); |
| 377 | rc = -EINVAL; |
| 378 | goto end; |
| 379 | } |
| 380 | |
| 381 | panel = container_of(dp_panel, struct dp_panel_private, dp_panel); |
| 382 | catalog = panel->catalog; |
| 383 | pinfo = &panel->dp_panel.pinfo; |
| 384 | |
| 385 | pr_debug("width=%d hporch= %d %d %d\n", |
| 386 | pinfo->h_active, pinfo->h_back_porch, |
| 387 | pinfo->h_front_porch, pinfo->h_sync_width); |
| 388 | |
| 389 | pr_debug("height=%d vporch= %d %d %d\n", |
| 390 | pinfo->v_active, pinfo->v_back_porch, |
| 391 | pinfo->v_front_porch, pinfo->v_sync_width); |
| 392 | |
| 393 | total_hor = pinfo->h_active + pinfo->h_back_porch + |
| 394 | pinfo->h_front_porch + pinfo->h_sync_width; |
| 395 | |
| 396 | total_ver = pinfo->v_active + pinfo->v_back_porch + |
| 397 | pinfo->v_front_porch + pinfo->v_sync_width; |
| 398 | |
| 399 | data = total_ver; |
| 400 | data <<= 16; |
| 401 | data |= total_hor; |
| 402 | |
| 403 | catalog->total = data; |
| 404 | |
| 405 | data = (pinfo->v_back_porch + pinfo->v_sync_width); |
| 406 | data <<= 16; |
| 407 | data |= (pinfo->h_back_porch + pinfo->h_sync_width); |
| 408 | |
| 409 | catalog->sync_start = data; |
| 410 | |
| 411 | data = pinfo->v_sync_width; |
| 412 | data <<= 16; |
| 413 | data |= (pinfo->v_active_low << 31); |
| 414 | data |= pinfo->h_sync_width; |
| 415 | data |= (pinfo->h_active_low << 15); |
| 416 | |
| 417 | catalog->width_blanking = data; |
| 418 | |
| 419 | data = pinfo->v_active; |
| 420 | data <<= 16; |
| 421 | data |= pinfo->h_active; |
| 422 | |
| 423 | catalog->dp_active = data; |
| 424 | |
| 425 | panel->catalog->timing_cfg(catalog); |
| 426 | end: |
| 427 | return rc; |
| 428 | } |
| 429 | |
Padmanabhan Komanduru | d84b38b | 2017-05-24 04:24:57 -0700 | [diff] [blame] | 430 | static int dp_panel_edid_register(struct dp_panel *dp_panel) |
| 431 | { |
| 432 | int rc = 0; |
| 433 | |
| 434 | if (!dp_panel) { |
| 435 | pr_err("invalid input\n"); |
| 436 | rc = -EINVAL; |
| 437 | goto end; |
| 438 | } |
| 439 | |
| 440 | dp_panel->edid_ctrl = sde_edid_init(); |
| 441 | if (!dp_panel->edid_ctrl) { |
| 442 | pr_err("sde edid init for DP failed\n"); |
| 443 | rc = -ENOMEM; |
| 444 | goto end; |
| 445 | } |
| 446 | end: |
| 447 | return rc; |
| 448 | } |
| 449 | |
| 450 | static void dp_panel_edid_deregister(struct dp_panel *dp_panel) |
| 451 | { |
| 452 | if (!dp_panel) { |
| 453 | pr_err("invalid input\n"); |
| 454 | return; |
| 455 | } |
| 456 | |
| 457 | sde_edid_deinit((void **)&dp_panel->edid_ctrl); |
| 458 | } |
| 459 | |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 460 | static int dp_panel_init_panel_info(struct dp_panel *dp_panel) |
| 461 | { |
| 462 | int rc = 0; |
Ajay Singh Parmar | f63dbc7ab | 2017-07-02 22:45:28 -0700 | [diff] [blame] | 463 | struct dp_panel_info *pinfo; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 464 | |
| 465 | if (!dp_panel) { |
| 466 | pr_err("invalid input\n"); |
| 467 | rc = -EINVAL; |
| 468 | goto end; |
| 469 | } |
| 470 | |
Ajay Singh Parmar | f63dbc7ab | 2017-07-02 22:45:28 -0700 | [diff] [blame] | 471 | pinfo = &dp_panel->pinfo; |
| 472 | |
| 473 | /* |
| 474 | * print resolution info as this is a result |
| 475 | * of user initiated action of cable connection |
| 476 | */ |
| 477 | pr_info("SET NEW RESOLUTION:\n"); |
| 478 | pr_info("%dx%d@%dfps\n", pinfo->h_active, |
| 479 | pinfo->v_active, pinfo->refresh_rate); |
| 480 | pr_info("h_porches(back|front|width) = (%d|%d|%d)\n", |
| 481 | pinfo->h_back_porch, |
| 482 | pinfo->h_front_porch, |
| 483 | pinfo->h_sync_width); |
| 484 | pr_info("v_porches(back|front|width) = (%d|%d|%d)\n", |
| 485 | pinfo->v_back_porch, |
| 486 | pinfo->v_front_porch, |
| 487 | pinfo->v_sync_width); |
| 488 | pr_info("pixel clock (KHz)=(%d)\n", pinfo->pixel_clk_khz); |
| 489 | pr_info("bpp = %d\n", pinfo->bpp); |
| 490 | pr_info("active low (h|v)=(%d|%d)\n", pinfo->h_active_low, |
| 491 | pinfo->v_active_low); |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 492 | end: |
| 493 | return rc; |
| 494 | } |
| 495 | |
Ajay Singh Parmar | 88617ba | 2017-07-03 00:12:26 -0700 | [diff] [blame] | 496 | static u32 dp_panel_get_min_req_link_rate(struct dp_panel *dp_panel) |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 497 | { |
| 498 | const u32 encoding_factx10 = 8; |
Ajay Singh Parmar | 88617ba | 2017-07-03 00:12:26 -0700 | [diff] [blame] | 499 | u32 min_link_rate_khz = 0, lane_cnt; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 500 | struct dp_panel_info *pinfo; |
| 501 | |
| 502 | if (!dp_panel) { |
| 503 | pr_err("invalid input\n"); |
| 504 | goto end; |
| 505 | } |
| 506 | |
Ajay Singh Parmar | a4b0606 | 2017-06-23 17:10:36 -0700 | [diff] [blame] | 507 | lane_cnt = dp_panel->link_info.num_lanes; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 508 | pinfo = &dp_panel->pinfo; |
| 509 | |
Ajay Singh Parmar | 88617ba | 2017-07-03 00:12:26 -0700 | [diff] [blame] | 510 | /* num_lanes * lane_count * 8 >= pclk * bpp * 10 */ |
| 511 | min_link_rate_khz = pinfo->pixel_clk_khz / |
| 512 | (lane_cnt * encoding_factx10); |
| 513 | min_link_rate_khz *= pinfo->bpp; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 514 | |
Ajay Singh Parmar | 88617ba | 2017-07-03 00:12:26 -0700 | [diff] [blame] | 515 | pr_debug("min lclk req=%d khz for pclk=%d khz, lanes=%d, bpp=%d\n", |
| 516 | min_link_rate_khz, pinfo->pixel_clk_khz, lane_cnt, |
| 517 | pinfo->bpp); |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 518 | end: |
Ajay Singh Parmar | 88617ba | 2017-07-03 00:12:26 -0700 | [diff] [blame] | 519 | return min_link_rate_khz; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Padmanabhan Komanduru | fdafc41 | 2017-09-11 13:13:38 +0530 | [diff] [blame] | 522 | struct dp_panel *dp_panel_get(struct dp_panel_in *in) |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 523 | { |
| 524 | int rc = 0; |
| 525 | struct dp_panel_private *panel; |
| 526 | struct dp_panel *dp_panel; |
| 527 | |
Padmanabhan Komanduru | fdafc41 | 2017-09-11 13:13:38 +0530 | [diff] [blame] | 528 | if (!in->dev || !in->catalog || !in->aux || !in->link) { |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 529 | pr_err("invalid input\n"); |
| 530 | rc = -EINVAL; |
| 531 | goto error; |
| 532 | } |
| 533 | |
Padmanabhan Komanduru | fdafc41 | 2017-09-11 13:13:38 +0530 | [diff] [blame] | 534 | panel = devm_kzalloc(in->dev, sizeof(*panel), GFP_KERNEL); |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 535 | if (!panel) { |
| 536 | rc = -ENOMEM; |
| 537 | goto error; |
| 538 | } |
| 539 | |
Padmanabhan Komanduru | fdafc41 | 2017-09-11 13:13:38 +0530 | [diff] [blame] | 540 | panel->dev = in->dev; |
| 541 | panel->aux = in->aux; |
| 542 | panel->catalog = in->catalog; |
| 543 | panel->link = in->link; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 544 | |
| 545 | dp_panel = &panel->dp_panel; |
Padmanabhan Komanduru | 2e9914b | 2017-08-04 20:51:31 +0530 | [diff] [blame] | 546 | panel->aux_cfg_update_done = false; |
Padmanabhan Komanduru | 87222e7 | 2017-09-21 18:27:25 +0530 | [diff] [blame] | 547 | dp_panel->max_bw_code = DP_LINK_BW_8_1; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 548 | |
Padmanabhan Komanduru | d84b38b | 2017-05-24 04:24:57 -0700 | [diff] [blame] | 549 | dp_panel->sde_edid_register = dp_panel_edid_register; |
| 550 | dp_panel->sde_edid_deregister = dp_panel_edid_deregister; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 551 | dp_panel->init_info = dp_panel_init_panel_info; |
| 552 | dp_panel->timing_cfg = dp_panel_timing_cfg; |
Padmanabhan Komanduru | 2e9914b | 2017-08-04 20:51:31 +0530 | [diff] [blame] | 553 | dp_panel->read_sink_caps = dp_panel_read_sink_caps; |
Ajay Singh Parmar | 88617ba | 2017-07-03 00:12:26 -0700 | [diff] [blame] | 554 | dp_panel->get_min_req_link_rate = dp_panel_get_min_req_link_rate; |
Tatenda Chipeperekwa | 8a44bd9 | 2017-10-05 16:32:06 -0700 | [diff] [blame] | 555 | dp_panel->get_mode_bpp = dp_panel_get_mode_bpp; |
Padmanabhan Komanduru | fdafc41 | 2017-09-11 13:13:38 +0530 | [diff] [blame] | 556 | dp_panel->get_modes = dp_panel_get_modes; |
Padmanabhan Komanduru | 504e289 | 2017-09-19 20:38:31 +0530 | [diff] [blame] | 557 | dp_panel->handle_sink_request = dp_panel_handle_sink_request; |
Ajay Singh Parmar | 4c92d39 | 2017-08-30 22:51:10 -0700 | [diff] [blame^] | 558 | dp_panel->set_edid = dp_panel_set_edid; |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 559 | |
| 560 | return dp_panel; |
| 561 | error: |
| 562 | return ERR_PTR(rc); |
| 563 | } |
| 564 | |
| 565 | void dp_panel_put(struct dp_panel *dp_panel) |
| 566 | { |
| 567 | struct dp_panel_private *panel; |
| 568 | |
| 569 | if (!dp_panel) |
| 570 | return; |
| 571 | |
| 572 | panel = container_of(dp_panel, struct dp_panel_private, dp_panel); |
| 573 | |
Ajay Singh Parmar | 72d5765 | 2017-03-25 17:24:07 -0700 | [diff] [blame] | 574 | devm_kfree(panel->dev, panel); |
| 575 | } |