blob: b3cdd2acc8d02ec7b7d61eff65a70b3271112695 [file] [log] [blame]
Ajay Singh Parmar72d57652017-03-25 17:24:07 -07001/*
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 Parmarf63dbc7ab2017-07-02 22:45:28 -070019#define DP_PANEL_DEFAULT_BPP 24
Padmanabhan Komanduru58717282017-08-28 17:01:49 +053020#define DP_MAX_DS_PORT_COUNT 1
Ajay Singh Parmarf63dbc7ab2017-07-02 22:45:28 -070021
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -070022enum {
23 DP_LINK_RATE_MULTIPLIER = 27000000,
24};
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070025
26struct dp_panel_private {
27 struct device *dev;
28 struct dp_panel dp_panel;
29 struct dp_aux *aux;
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +053030 struct dp_link *link;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070031 struct dp_catalog_panel *catalog;
Padmanabhan Komanduru2e9914b2017-08-04 20:51:31 +053032 bool aux_cfg_update_done;
Ajay Singh Parmar4c92d392017-08-30 22:51:10 -070033 bool custom_edid;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070034};
35
Padmanabhan Komanduruef656fa2017-09-19 20:33:27 +053036static 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 Parmar72d57652017-03-25 17:24:07 -070053static int dp_panel_read_dpcd(struct dp_panel *dp_panel)
54{
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070055 int rlen, rc = 0;
56 struct dp_panel_private *panel;
Ajay Singh Parmara4b06062017-06-23 17:10:36 -070057 struct drm_dp_link *link_info;
Padmanabhan Komanduru58717282017-08-28 17:01:49 +053058 u8 *dpcd, major = 0, minor = 0;
59 u32 dfp_count = 0;
Ajay Singh Parmara4b06062017-06-23 17:10:36 -070060 unsigned long caps = DP_LINK_CAP_ENHANCED_FRAMING;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070061
62 if (!dp_panel) {
63 pr_err("invalid input\n");
64 rc = -EINVAL;
65 goto end;
66 }
67
Padmanabhan Komanduru58717282017-08-28 17:01:49 +053068 dpcd = dp_panel->dpcd;
69
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070070 panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
Ajay Singh Parmara4b06062017-06-23 17:10:36 -070071 link_info = &dp_panel->link_info;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070072
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -070073 rlen = drm_dp_dpcd_read(panel->aux->drm_aux, DP_DPCD_REV,
Padmanabhan Komanduru58717282017-08-28 17:01:49 +053074 dpcd, (DP_RECEIVER_CAP_SIZE + 1));
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -070075 if (rlen < (DP_RECEIVER_CAP_SIZE + 1)) {
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070076 pr_err("dpcd read failed, rlen=%d\n", rlen);
77 rc = -EINVAL;
78 goto end;
79 }
80
Ajay Singh Parmara4b06062017-06-23 17:10:36 -070081 link_info->revision = dp_panel->dpcd[DP_DPCD_REV];
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070082
Ajay Singh Parmara4b06062017-06-23 17:10:36 -070083 major = (link_info->revision >> 4) & 0x0f;
84 minor = link_info->revision & 0x0f;
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -070085 pr_debug("version: %d.%d\n", major, minor);
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070086
Ajay Singh Parmara4b06062017-06-23 17:10:36 -070087 link_info->rate =
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -070088 drm_dp_bw_code_to_link_rate(dp_panel->dpcd[DP_MAX_LINK_RATE]);
Ajay Singh Parmara4b06062017-06-23 17:10:36 -070089 pr_debug("link_rate=%d\n", link_info->rate);
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070090
Ajay Singh Parmardd307892017-08-15 16:08:59 -070091 link_info->num_lanes = dp_panel->dpcd[DP_MAX_LANE_COUNT] &
92 DP_MAX_LANE_COUNT_MASK;
Ajay Singh Parmarf63dbc7ab2017-07-02 22:45:28 -070093
Ajay Singh Parmara4b06062017-06-23 17:10:36 -070094 pr_debug("lane_count=%d\n", link_info->num_lanes);
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070095
Padmanabhan Komanduru58717282017-08-28 17:01:49 +053096 if (drm_dp_enhanced_frame_cap(dpcd))
Ajay Singh Parmara4b06062017-06-23 17:10:36 -070097 link_info->capabilities |= caps;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -070098
Padmanabhan Komanduru58717282017-08-28 17:01:49 +053099 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 Parmar72d57652017-03-25 17:24:07 -0700118end:
119 return rc;
120}
121
Padmanabhan Komanduruef656fa2017-09-19 20:33:27 +0530122static 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 Parmar4c92d392017-08-30 22:51:10 -0700137
138 return 0;
139}
140
141static 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 Komanduruef656fa2017-09-19 20:33:27 +0530159 return 0;
160}
Padmanabhan Komanduru2e9914b2017-08-04 20:51:31 +0530161
162static 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 Parmar4c92d392017-08-30 22:51:10 -0700176 if (panel->custom_edid) {
177 pr_debug("skip edid read in debug mode\n");
178 return 0;
179 }
180
Padmanabhan Komanduru2e9914b2017-08-04 20:51:31 +0530181 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 {
Ajay Singh Parmarfae11672017-09-01 19:49:30 -0700190 u8 *buf = (u8 *)dp_panel->edid_ctrl->edid;
191 u32 size = buf[0x7F] ? 256 : 128;
192
193 print_hex_dump(KERN_DEBUG, "[drm-dp] SINK EDID: ",
194 DUMP_PREFIX_NONE, 16, 1, buf, size, false);
195
Padmanabhan Komanduru2e9914b2017-08-04 20:51:31 +0530196 return 0;
197 }
198 } while (retry_cnt < max_retry);
199
200 return -EINVAL;
201}
202
203static int dp_panel_read_sink_caps(struct dp_panel *dp_panel,
204 struct drm_connector *connector)
205{
206 int rc = 0;
207 struct dp_panel_private *panel;
208
209 if (!dp_panel || !connector) {
210 pr_err("invalid input\n");
211 return -EINVAL;
212 }
213
214 panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
215
216 rc = dp_panel_read_dpcd(dp_panel);
Padmanabhan Komanduruef656fa2017-09-19 20:33:27 +0530217 if (rc || !is_link_rate_valid(drm_dp_link_rate_to_bw_code(
218 dp_panel->link_info.rate)) || !is_lane_count_valid(
Padmanabhan Komanduru87222e72017-09-21 18:27:25 +0530219 dp_panel->link_info.num_lanes) ||
220 ((drm_dp_link_rate_to_bw_code(dp_panel->link_info.rate)) >
221 dp_panel->max_bw_code)) {
Padmanabhan Komanduruef656fa2017-09-19 20:33:27 +0530222 pr_err("panel dpcd read failed/incorrect, set default params\n");
223 dp_panel_set_default_link_params(dp_panel);
Padmanabhan Komanduru2e9914b2017-08-04 20:51:31 +0530224 }
225
226 rc = dp_panel_read_edid(dp_panel, connector);
227 if (rc) {
Padmanabhan Komanduruef656fa2017-09-19 20:33:27 +0530228 pr_err("panel edid read failed, set failsafe mode\n");
Padmanabhan Komanduru2e9914b2017-08-04 20:51:31 +0530229 return rc;
230 }
231
232 if (panel->aux_cfg_update_done) {
233 pr_debug("read DPCD with updated AUX config\n");
234 dp_panel_read_dpcd(dp_panel);
235 panel->aux_cfg_update_done = false;
236 }
237
238 return 0;
239}
240
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700241static u32 dp_panel_get_supported_bpp(struct dp_panel *dp_panel,
242 u32 mode_edid_bpp, u32 mode_pclk_khz)
Padmanabhan Komandurud5eae9d2017-06-22 19:23:36 +0530243{
Ajay Singh Parmara4b06062017-06-23 17:10:36 -0700244 struct drm_dp_link *link_info;
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700245 const u32 max_supported_bpp = 30, min_supported_bpp = 18;
246 u32 bpp = 0, data_rate_khz = 0;
Padmanabhan Komandurud5eae9d2017-06-22 19:23:36 +0530247
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700248 bpp = min_t(u32, mode_edid_bpp, max_supported_bpp);
249
250 link_info = &dp_panel->link_info;
251 data_rate_khz = link_info->num_lanes * link_info->rate * 8;
252
253 while (bpp > min_supported_bpp) {
254 if (mode_pclk_khz * bpp <= data_rate_khz)
255 break;
256 bpp -= 6;
257 }
258
259 return bpp;
260}
261
262static u32 dp_panel_get_mode_bpp(struct dp_panel *dp_panel,
263 u32 mode_edid_bpp, u32 mode_pclk_khz)
264{
265 struct dp_panel_private *panel;
266 u32 bpp = mode_edid_bpp;
267
268 if (!dp_panel || !mode_edid_bpp || !mode_pclk_khz) {
Padmanabhan Komandurud5eae9d2017-06-22 19:23:36 +0530269 pr_err("invalid input\n");
270 return 0;
271 }
272
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700273 panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
Padmanabhan Komandurud5eae9d2017-06-22 19:23:36 +0530274
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700275 if (dp_panel->video_test)
276 bpp = dp_link_bit_depth_to_bpp(
277 panel->link->test_video.test_bit_depth);
278 else
279 bpp = dp_panel_get_supported_bpp(dp_panel, mode_edid_bpp,
280 mode_pclk_khz);
Padmanabhan Komandurud5eae9d2017-06-22 19:23:36 +0530281
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700282 return bpp;
Padmanabhan Komandurud5eae9d2017-06-22 19:23:36 +0530283}
284
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530285static void dp_panel_set_test_mode(struct dp_panel_private *panel,
286 struct dp_display_mode *mode)
287{
288 struct dp_panel_info *pinfo = NULL;
289 struct dp_link_test_video *test_info = NULL;
290
291 if (!panel) {
292 pr_err("invalid params\n");
293 return;
294 }
295
296 pinfo = &mode->timing;
297 test_info = &panel->link->test_video;
298
299 pinfo->h_active = test_info->test_h_width;
300 pinfo->h_sync_width = test_info->test_hsync_width;
301 pinfo->h_back_porch = test_info->test_h_start -
302 test_info->test_hsync_width;
303 pinfo->h_front_porch = test_info->test_h_total -
304 (test_info->test_h_start + test_info->test_h_width);
305
306 pinfo->v_active = test_info->test_v_height;
307 pinfo->v_sync_width = test_info->test_vsync_width;
308 pinfo->v_back_porch = test_info->test_v_start -
309 test_info->test_vsync_width;
310 pinfo->v_front_porch = test_info->test_v_total -
311 (test_info->test_v_start + test_info->test_v_height);
312
313 pinfo->bpp = dp_link_bit_depth_to_bpp(test_info->test_bit_depth);
314 pinfo->h_active_low = test_info->test_hsync_pol;
315 pinfo->v_active_low = test_info->test_vsync_pol;
316
317 pinfo->refresh_rate = test_info->test_rr_n;
318 pinfo->pixel_clk_khz = test_info->test_h_total *
319 test_info->test_v_total * pinfo->refresh_rate;
320
321 if (test_info->test_rr_d == 0)
322 pinfo->pixel_clk_khz /= 1000;
323 else
324 pinfo->pixel_clk_khz /= 1001;
325
326 if (test_info->test_h_width == 640)
327 pinfo->pixel_clk_khz = 25170;
328}
329
330static int dp_panel_get_modes(struct dp_panel *dp_panel,
331 struct drm_connector *connector, struct dp_display_mode *mode)
332{
333 struct dp_panel_private *panel;
334
335 if (!dp_panel) {
336 pr_err("invalid input\n");
337 return -EINVAL;
338 }
339
340 panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
341
342 if (dp_panel->video_test) {
343 dp_panel_set_test_mode(panel, mode);
344 return 1;
345 } else if (dp_panel->edid_ctrl->edid) {
346 return _sde_edid_update_modes(connector, dp_panel->edid_ctrl);
Padmanabhan Komanduruef656fa2017-09-19 20:33:27 +0530347 } else { /* fail-safe mode */
348 memcpy(&mode->timing, &fail_safe,
349 sizeof(fail_safe));
350 return 1;
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530351 }
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530352}
353
Padmanabhan Komanduru504e2892017-09-19 20:38:31 +0530354static void dp_panel_handle_sink_request(struct dp_panel *dp_panel)
355{
356 struct dp_panel_private *panel;
357
358 if (!dp_panel) {
359 pr_err("invalid input\n");
360 return;
361 }
362
363 panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
364
365 if (panel->link->sink_request & DP_TEST_LINK_EDID_READ) {
366 u8 checksum = sde_get_edid_checksum(dp_panel->edid_ctrl);
367
368 panel->link->send_edid_checksum(panel->link, checksum);
369 panel->link->send_test_response(panel->link);
370 }
371}
372
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700373static int dp_panel_timing_cfg(struct dp_panel *dp_panel)
374{
375 int rc = 0;
376 u32 data, total_ver, total_hor;
377 struct dp_catalog_panel *catalog;
378 struct dp_panel_private *panel;
379 struct dp_panel_info *pinfo;
380
381 if (!dp_panel) {
382 pr_err("invalid input\n");
383 rc = -EINVAL;
384 goto end;
385 }
386
387 panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
388 catalog = panel->catalog;
389 pinfo = &panel->dp_panel.pinfo;
390
391 pr_debug("width=%d hporch= %d %d %d\n",
392 pinfo->h_active, pinfo->h_back_porch,
393 pinfo->h_front_porch, pinfo->h_sync_width);
394
395 pr_debug("height=%d vporch= %d %d %d\n",
396 pinfo->v_active, pinfo->v_back_porch,
397 pinfo->v_front_porch, pinfo->v_sync_width);
398
399 total_hor = pinfo->h_active + pinfo->h_back_porch +
400 pinfo->h_front_porch + pinfo->h_sync_width;
401
402 total_ver = pinfo->v_active + pinfo->v_back_porch +
403 pinfo->v_front_porch + pinfo->v_sync_width;
404
405 data = total_ver;
406 data <<= 16;
407 data |= total_hor;
408
409 catalog->total = data;
410
411 data = (pinfo->v_back_porch + pinfo->v_sync_width);
412 data <<= 16;
413 data |= (pinfo->h_back_porch + pinfo->h_sync_width);
414
415 catalog->sync_start = data;
416
417 data = pinfo->v_sync_width;
418 data <<= 16;
419 data |= (pinfo->v_active_low << 31);
420 data |= pinfo->h_sync_width;
421 data |= (pinfo->h_active_low << 15);
422
423 catalog->width_blanking = data;
424
425 data = pinfo->v_active;
426 data <<= 16;
427 data |= pinfo->h_active;
428
429 catalog->dp_active = data;
430
431 panel->catalog->timing_cfg(catalog);
432end:
433 return rc;
434}
435
Ajay Singh Parmarfae11672017-09-01 19:49:30 -0700436static int dp_panel_edid_register(struct dp_panel_private *panel)
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -0700437{
438 int rc = 0;
439
Ajay Singh Parmarfae11672017-09-01 19:49:30 -0700440 panel->dp_panel.edid_ctrl = sde_edid_init();
441 if (!panel->dp_panel.edid_ctrl) {
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -0700442 pr_err("sde edid init for DP failed\n");
443 rc = -ENOMEM;
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -0700444 }
Ajay Singh Parmarfae11672017-09-01 19:49:30 -0700445
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -0700446 return rc;
447}
448
Ajay Singh Parmarfae11672017-09-01 19:49:30 -0700449static void dp_panel_edid_deregister(struct dp_panel_private *panel)
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -0700450{
Ajay Singh Parmarfae11672017-09-01 19:49:30 -0700451 sde_edid_deinit((void **)&panel->dp_panel.edid_ctrl);
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -0700452}
453
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700454static int dp_panel_init_panel_info(struct dp_panel *dp_panel)
455{
456 int rc = 0;
Ajay Singh Parmarf63dbc7ab2017-07-02 22:45:28 -0700457 struct dp_panel_info *pinfo;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700458
459 if (!dp_panel) {
460 pr_err("invalid input\n");
461 rc = -EINVAL;
462 goto end;
463 }
464
Ajay Singh Parmarf63dbc7ab2017-07-02 22:45:28 -0700465 pinfo = &dp_panel->pinfo;
466
467 /*
468 * print resolution info as this is a result
469 * of user initiated action of cable connection
470 */
471 pr_info("SET NEW RESOLUTION:\n");
472 pr_info("%dx%d@%dfps\n", pinfo->h_active,
473 pinfo->v_active, pinfo->refresh_rate);
474 pr_info("h_porches(back|front|width) = (%d|%d|%d)\n",
475 pinfo->h_back_porch,
476 pinfo->h_front_porch,
477 pinfo->h_sync_width);
478 pr_info("v_porches(back|front|width) = (%d|%d|%d)\n",
479 pinfo->v_back_porch,
480 pinfo->v_front_porch,
481 pinfo->v_sync_width);
482 pr_info("pixel clock (KHz)=(%d)\n", pinfo->pixel_clk_khz);
483 pr_info("bpp = %d\n", pinfo->bpp);
484 pr_info("active low (h|v)=(%d|%d)\n", pinfo->h_active_low,
485 pinfo->v_active_low);
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700486end:
487 return rc;
488}
489
Ajay Singh Parmarfae11672017-09-01 19:49:30 -0700490static int dp_panel_deinit_panel_info(struct dp_panel *dp_panel)
491{
492 int rc = 0;
493 struct dp_panel_private *panel;
494
495 if (!dp_panel) {
496 pr_err("invalid input\n");
497 return -EINVAL;
498 }
499
500 panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
501
502 if (!panel->custom_edid)
503 sde_free_edid((void **)&dp_panel->edid_ctrl);
504
505 memset(&dp_panel->pinfo, 0, sizeof(dp_panel->pinfo));
506
507 return rc;
508}
509
Ajay Singh Parmar88617ba2017-07-03 00:12:26 -0700510static u32 dp_panel_get_min_req_link_rate(struct dp_panel *dp_panel)
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700511{
512 const u32 encoding_factx10 = 8;
Ajay Singh Parmar88617ba2017-07-03 00:12:26 -0700513 u32 min_link_rate_khz = 0, lane_cnt;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700514 struct dp_panel_info *pinfo;
515
516 if (!dp_panel) {
517 pr_err("invalid input\n");
518 goto end;
519 }
520
Ajay Singh Parmara4b06062017-06-23 17:10:36 -0700521 lane_cnt = dp_panel->link_info.num_lanes;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700522 pinfo = &dp_panel->pinfo;
523
Ajay Singh Parmar88617ba2017-07-03 00:12:26 -0700524 /* num_lanes * lane_count * 8 >= pclk * bpp * 10 */
525 min_link_rate_khz = pinfo->pixel_clk_khz /
526 (lane_cnt * encoding_factx10);
527 min_link_rate_khz *= pinfo->bpp;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700528
Ajay Singh Parmar88617ba2017-07-03 00:12:26 -0700529 pr_debug("min lclk req=%d khz for pclk=%d khz, lanes=%d, bpp=%d\n",
530 min_link_rate_khz, pinfo->pixel_clk_khz, lane_cnt,
531 pinfo->bpp);
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700532end:
Ajay Singh Parmar88617ba2017-07-03 00:12:26 -0700533 return min_link_rate_khz;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700534}
535
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530536struct dp_panel *dp_panel_get(struct dp_panel_in *in)
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700537{
538 int rc = 0;
539 struct dp_panel_private *panel;
540 struct dp_panel *dp_panel;
541
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530542 if (!in->dev || !in->catalog || !in->aux || !in->link) {
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700543 pr_err("invalid input\n");
544 rc = -EINVAL;
545 goto error;
546 }
547
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530548 panel = devm_kzalloc(in->dev, sizeof(*panel), GFP_KERNEL);
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700549 if (!panel) {
550 rc = -ENOMEM;
551 goto error;
552 }
553
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530554 panel->dev = in->dev;
555 panel->aux = in->aux;
556 panel->catalog = in->catalog;
557 panel->link = in->link;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700558
559 dp_panel = &panel->dp_panel;
Padmanabhan Komanduru2e9914b2017-08-04 20:51:31 +0530560 panel->aux_cfg_update_done = false;
Padmanabhan Komanduru87222e72017-09-21 18:27:25 +0530561 dp_panel->max_bw_code = DP_LINK_BW_8_1;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700562
Ajay Singh Parmarfae11672017-09-01 19:49:30 -0700563 dp_panel->init = dp_panel_init_panel_info;
564 dp_panel->deinit = dp_panel_deinit_panel_info;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700565 dp_panel->timing_cfg = dp_panel_timing_cfg;
Padmanabhan Komanduru2e9914b2017-08-04 20:51:31 +0530566 dp_panel->read_sink_caps = dp_panel_read_sink_caps;
Ajay Singh Parmar88617ba2017-07-03 00:12:26 -0700567 dp_panel->get_min_req_link_rate = dp_panel_get_min_req_link_rate;
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700568 dp_panel->get_mode_bpp = dp_panel_get_mode_bpp;
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530569 dp_panel->get_modes = dp_panel_get_modes;
Padmanabhan Komanduru504e2892017-09-19 20:38:31 +0530570 dp_panel->handle_sink_request = dp_panel_handle_sink_request;
Ajay Singh Parmar4c92d392017-08-30 22:51:10 -0700571 dp_panel->set_edid = dp_panel_set_edid;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700572
Ajay Singh Parmarfae11672017-09-01 19:49:30 -0700573 dp_panel_edid_register(panel);
574
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700575 return dp_panel;
576error:
577 return ERR_PTR(rc);
578}
579
580void dp_panel_put(struct dp_panel *dp_panel)
581{
582 struct dp_panel_private *panel;
583
584 if (!dp_panel)
585 return;
586
587 panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
588
Ajay Singh Parmarfae11672017-09-01 19:49:30 -0700589 dp_panel_edid_deregister(panel);
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700590 devm_kfree(panel->dev, panel);
591}