blob: bb92cc3acc770e8d3b0972d2bdd0b2d3aedd0207 [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 {
190 return 0;
191 }
192 } while (retry_cnt < max_retry);
193
194 return -EINVAL;
195}
196
197static 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 Komanduruef656fa2017-09-19 20:33:27 +0530211 if (rc || !is_link_rate_valid(drm_dp_link_rate_to_bw_code(
212 dp_panel->link_info.rate)) || !is_lane_count_valid(
Padmanabhan Komanduru87222e72017-09-21 18:27:25 +0530213 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 Komanduruef656fa2017-09-19 20:33:27 +0530216 pr_err("panel dpcd read failed/incorrect, set default params\n");
217 dp_panel_set_default_link_params(dp_panel);
Padmanabhan Komanduru2e9914b2017-08-04 20:51:31 +0530218 }
219
220 rc = dp_panel_read_edid(dp_panel, connector);
221 if (rc) {
Padmanabhan Komanduruef656fa2017-09-19 20:33:27 +0530222 pr_err("panel edid read failed, set failsafe mode\n");
Padmanabhan Komanduru2e9914b2017-08-04 20:51:31 +0530223 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 Chipeperekwa8a44bd92017-10-05 16:32:06 -0700235static u32 dp_panel_get_supported_bpp(struct dp_panel *dp_panel,
236 u32 mode_edid_bpp, u32 mode_pclk_khz)
Padmanabhan Komandurud5eae9d2017-06-22 19:23:36 +0530237{
Ajay Singh Parmara4b06062017-06-23 17:10:36 -0700238 struct drm_dp_link *link_info;
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700239 const u32 max_supported_bpp = 30, min_supported_bpp = 18;
240 u32 bpp = 0, data_rate_khz = 0;
Padmanabhan Komandurud5eae9d2017-06-22 19:23:36 +0530241
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700242 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
256static 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 Komandurud5eae9d2017-06-22 19:23:36 +0530263 pr_err("invalid input\n");
264 return 0;
265 }
266
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700267 panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
Padmanabhan Komandurud5eae9d2017-06-22 19:23:36 +0530268
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700269 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 Komandurud5eae9d2017-06-22 19:23:36 +0530275
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700276 return bpp;
Padmanabhan Komandurud5eae9d2017-06-22 19:23:36 +0530277}
278
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530279static 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
324static 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 Komanduruef656fa2017-09-19 20:33:27 +0530341 } else { /* fail-safe mode */
342 memcpy(&mode->timing, &fail_safe,
343 sizeof(fail_safe));
344 return 1;
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530345 }
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530346}
347
Padmanabhan Komanduru504e2892017-09-19 20:38:31 +0530348static 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 Parmar72d57652017-03-25 17:24:07 -0700367static 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);
426end:
427 return rc;
428}
429
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -0700430static 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 }
446end:
447 return rc;
448}
449
450static 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 Parmar72d57652017-03-25 17:24:07 -0700460static int dp_panel_init_panel_info(struct dp_panel *dp_panel)
461{
462 int rc = 0;
Ajay Singh Parmarf63dbc7ab2017-07-02 22:45:28 -0700463 struct dp_panel_info *pinfo;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700464
465 if (!dp_panel) {
466 pr_err("invalid input\n");
467 rc = -EINVAL;
468 goto end;
469 }
470
Ajay Singh Parmarf63dbc7ab2017-07-02 22:45:28 -0700471 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 Parmar72d57652017-03-25 17:24:07 -0700492end:
493 return rc;
494}
495
Ajay Singh Parmar88617ba2017-07-03 00:12:26 -0700496static u32 dp_panel_get_min_req_link_rate(struct dp_panel *dp_panel)
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700497{
498 const u32 encoding_factx10 = 8;
Ajay Singh Parmar88617ba2017-07-03 00:12:26 -0700499 u32 min_link_rate_khz = 0, lane_cnt;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700500 struct dp_panel_info *pinfo;
501
502 if (!dp_panel) {
503 pr_err("invalid input\n");
504 goto end;
505 }
506
Ajay Singh Parmara4b06062017-06-23 17:10:36 -0700507 lane_cnt = dp_panel->link_info.num_lanes;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700508 pinfo = &dp_panel->pinfo;
509
Ajay Singh Parmar88617ba2017-07-03 00:12:26 -0700510 /* 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 Parmar72d57652017-03-25 17:24:07 -0700514
Ajay Singh Parmar88617ba2017-07-03 00:12:26 -0700515 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 Parmar72d57652017-03-25 17:24:07 -0700518end:
Ajay Singh Parmar88617ba2017-07-03 00:12:26 -0700519 return min_link_rate_khz;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700520}
521
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530522struct dp_panel *dp_panel_get(struct dp_panel_in *in)
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700523{
524 int rc = 0;
525 struct dp_panel_private *panel;
526 struct dp_panel *dp_panel;
527
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530528 if (!in->dev || !in->catalog || !in->aux || !in->link) {
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700529 pr_err("invalid input\n");
530 rc = -EINVAL;
531 goto error;
532 }
533
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530534 panel = devm_kzalloc(in->dev, sizeof(*panel), GFP_KERNEL);
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700535 if (!panel) {
536 rc = -ENOMEM;
537 goto error;
538 }
539
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530540 panel->dev = in->dev;
541 panel->aux = in->aux;
542 panel->catalog = in->catalog;
543 panel->link = in->link;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700544
545 dp_panel = &panel->dp_panel;
Padmanabhan Komanduru2e9914b2017-08-04 20:51:31 +0530546 panel->aux_cfg_update_done = false;
Padmanabhan Komanduru87222e72017-09-21 18:27:25 +0530547 dp_panel->max_bw_code = DP_LINK_BW_8_1;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700548
Padmanabhan Komandurud84b38b2017-05-24 04:24:57 -0700549 dp_panel->sde_edid_register = dp_panel_edid_register;
550 dp_panel->sde_edid_deregister = dp_panel_edid_deregister;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700551 dp_panel->init_info = dp_panel_init_panel_info;
552 dp_panel->timing_cfg = dp_panel_timing_cfg;
Padmanabhan Komanduru2e9914b2017-08-04 20:51:31 +0530553 dp_panel->read_sink_caps = dp_panel_read_sink_caps;
Ajay Singh Parmar88617ba2017-07-03 00:12:26 -0700554 dp_panel->get_min_req_link_rate = dp_panel_get_min_req_link_rate;
Tatenda Chipeperekwa8a44bd92017-10-05 16:32:06 -0700555 dp_panel->get_mode_bpp = dp_panel_get_mode_bpp;
Padmanabhan Komandurufdafc412017-09-11 13:13:38 +0530556 dp_panel->get_modes = dp_panel_get_modes;
Padmanabhan Komanduru504e2892017-09-19 20:38:31 +0530557 dp_panel->handle_sink_request = dp_panel_handle_sink_request;
Ajay Singh Parmar4c92d392017-08-30 22:51:10 -0700558 dp_panel->set_edid = dp_panel_set_edid;
Ajay Singh Parmar72d57652017-03-25 17:24:07 -0700559
560 return dp_panel;
561error:
562 return ERR_PTR(rc);
563}
564
565void 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 Parmar72d57652017-03-25 17:24:07 -0700574 devm_kfree(panel->dev, panel);
575}