blob: c8d742500aef1ff143f1c75271885249f64c0858 [file] [log] [blame]
Sachin Bhayareeeb88892018-01-02 16:36:01 +05301/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/interrupt.h>
16#include <linux/spinlock.h>
17#include <linux/delay.h>
18#include <linux/io.h>
19#include <linux/of_device.h>
20#include <linux/of_gpio.h>
21#include <linux/gpio.h>
22#include <linux/err.h>
23#include <linux/regulator/consumer.h>
24#include <linux/leds-qpnp-wled.h>
25#include <linux/clk.h>
26#include <linux/uaccess.h>
27#include <linux/msm-bus.h>
28#include <linux/pm_qos.h>
Sachin Bhayare3d3767e2018-01-02 21:10:57 +053029#include <linux/mdss_io_util.h>
Sachin Bhayareeeb88892018-01-02 16:36:01 +053030
31#include "mdss.h"
32#include "mdss_panel.h"
33#include "mdss_dsi.h"
34#include "mdss_debug.h"
35#include "mdss_dsi_phy.h"
36#include "mdss_dba_utils.h"
37
38#define XO_CLK_RATE 19200000
39#define CMDLINE_DSI_CTL_NUM_STRING_LEN 2
40
41/* Master structure to hold all the information about the DSI/panel */
42static struct mdss_dsi_data *mdss_dsi_res;
43
44#define DSI_DISABLE_PC_LATENCY 100
45#define DSI_ENABLE_PC_LATENCY PM_QOS_DEFAULT_VALUE
46
47static struct pm_qos_request mdss_dsi_pm_qos_request;
48
49static void mdss_dsi_pm_qos_add_request(struct mdss_dsi_ctrl_pdata *ctrl_pdata)
50{
51 struct irq_info *irq_info;
52
53 if (!ctrl_pdata || !ctrl_pdata->shared_data)
54 return;
55
56 irq_info = ctrl_pdata->dsi_hw->irq_info;
57
58 if (!irq_info)
59 return;
60
61 mutex_lock(&ctrl_pdata->shared_data->pm_qos_lock);
62 if (!ctrl_pdata->shared_data->pm_qos_req_cnt) {
63 pr_debug("%s: add request irq\n", __func__);
64
65 mdss_dsi_pm_qos_request.type = PM_QOS_REQ_AFFINE_IRQ;
66 mdss_dsi_pm_qos_request.irq = irq_info->irq;
67 pm_qos_add_request(&mdss_dsi_pm_qos_request,
68 PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
69 }
70 ctrl_pdata->shared_data->pm_qos_req_cnt++;
71 mutex_unlock(&ctrl_pdata->shared_data->pm_qos_lock);
72}
73
74static void mdss_dsi_pm_qos_remove_request(struct dsi_shared_data *sdata)
75{
76 if (!sdata)
77 return;
78
79 mutex_lock(&sdata->pm_qos_lock);
80 if (sdata->pm_qos_req_cnt) {
81 sdata->pm_qos_req_cnt--;
82 if (!sdata->pm_qos_req_cnt) {
83 pr_debug("%s: remove request", __func__);
84 pm_qos_remove_request(&mdss_dsi_pm_qos_request);
85 }
86 } else {
87 pr_warn("%s: unbalanced pm_qos ref count\n", __func__);
88 }
89 mutex_unlock(&sdata->pm_qos_lock);
90}
91
92static void mdss_dsi_pm_qos_update_request(int val)
93{
94 pr_debug("%s: update request %d", __func__, val);
95 pm_qos_update_request(&mdss_dsi_pm_qos_request, val);
96}
97
98static int mdss_dsi_pinctrl_set_state(struct mdss_dsi_ctrl_pdata *ctrl_pdata,
99 bool active);
100
101static struct mdss_dsi_ctrl_pdata *mdss_dsi_get_ctrl(u32 ctrl_id)
102{
103 if (ctrl_id >= DSI_CTRL_MAX || !mdss_dsi_res)
104 return NULL;
105
106 return mdss_dsi_res->ctrl_pdata[ctrl_id];
107}
108
109static void mdss_dsi_config_clk_src(struct platform_device *pdev)
110{
111 struct mdss_dsi_data *dsi_res = platform_get_drvdata(pdev);
112 struct dsi_shared_data *sdata = dsi_res->shared_data;
113
114 if (!sdata->ext_byte0_clk || !sdata->ext_pixel0_clk) {
115 pr_debug("%s: DSI-0 ext. clocks not present\n", __func__);
116 return;
117 }
118
119 if (mdss_dsi_is_pll_src_default(sdata)) {
120 /*
121 * Default Mapping:
122 * 1. dual-dsi/single-dsi:
123 * DSI0 <--> PLL0
124 * DSI1 <--> PLL1
125 * 2. split-dsi:
126 * DSI0 <--> PLL0
127 * DSI1 <--> PLL0
128 */
129 sdata->byte0_parent = sdata->ext_byte0_clk;
130 sdata->pixel0_parent = sdata->ext_pixel0_clk;
131
132 if (mdss_dsi_is_hw_config_split(sdata)) {
133 sdata->byte1_parent = sdata->byte0_parent;
134 sdata->pixel1_parent = sdata->pixel0_parent;
135 } else if (sdata->ext_byte1_clk && sdata->ext_pixel1_clk) {
136 sdata->byte1_parent = sdata->ext_byte1_clk;
137 sdata->pixel1_parent = sdata->ext_pixel1_clk;
138 } else {
139 pr_debug("%s: DSI-1 external clocks not present\n",
140 __func__);
141 return;
142 }
143
144 pr_debug("%s: default: DSI0 <--> PLL0, DSI1 <--> %s", __func__,
145 mdss_dsi_is_hw_config_split(sdata) ? "PLL0" : "PLL1");
146 } else {
147 /*
148 * For split-dsi and single-dsi use cases, map the PLL source
149 * based on the pll source configuration. It is possible that
150 * for split-dsi case, the only supported config is to source
151 * the clocks from PLL0. This is not explicitly checked here as
152 * it should have been already enforced when validating the
153 * board configuration.
154 */
155 if (mdss_dsi_is_pll_src_pll0(sdata)) {
156 pr_debug("%s: single source: PLL0", __func__);
157 sdata->byte0_parent = sdata->ext_byte0_clk;
158 sdata->pixel0_parent = sdata->ext_pixel0_clk;
159 } else if (mdss_dsi_is_pll_src_pll1(sdata)) {
160 if (sdata->ext_byte1_clk && sdata->ext_pixel1_clk) {
161 pr_debug("%s: single source: PLL1", __func__);
162 sdata->byte0_parent = sdata->ext_byte1_clk;
163 sdata->pixel0_parent = sdata->ext_pixel1_clk;
164 } else {
165 pr_err("%s: DSI-1 external clocks not present\n",
166 __func__);
167 return;
168 }
169 }
170 sdata->byte1_parent = sdata->byte0_parent;
171 sdata->pixel1_parent = sdata->pixel0_parent;
172 }
173}
174
175static char const *mdss_dsi_get_clk_src(struct mdss_dsi_ctrl_pdata *ctrl)
176{
177 struct dsi_shared_data *sdata;
178
179 if (!ctrl) {
180 pr_err("%s: Invalid input data\n", __func__);
181 return "????";
182 }
183
184 sdata = ctrl->shared_data;
185
186 if (mdss_dsi_is_left_ctrl(ctrl)) {
187 if (sdata->byte0_parent == sdata->ext_byte0_clk)
188 return "PLL0";
189 else
190 return "PLL1";
191 } else {
192 if (sdata->byte1_parent == sdata->ext_byte0_clk)
193 return "PLL0";
194 else
195 return "PLL1";
196 }
197}
198
199static int mdss_dsi_set_clk_src(struct mdss_dsi_ctrl_pdata *ctrl)
200{
201 int rc;
202 struct dsi_shared_data *sdata;
203 struct clk *byte_parent, *pixel_parent;
204
205 if (!ctrl) {
206 pr_err("%s: Invalid input data\n", __func__);
207 return -EINVAL;
208 }
209
210 sdata = ctrl->shared_data;
211
212 if (!ctrl->byte_clk_rcg || !ctrl->pixel_clk_rcg) {
213 pr_debug("%s: set_clk_src not needed\n", __func__);
214 return 0;
215 }
216
217 if (mdss_dsi_is_left_ctrl(ctrl)) {
218 byte_parent = sdata->byte0_parent;
219 pixel_parent = sdata->pixel0_parent;
220 } else {
221 byte_parent = sdata->byte1_parent;
222 pixel_parent = sdata->pixel1_parent;
223 }
224
225 rc = clk_set_parent(ctrl->byte_clk_rcg, byte_parent);
226 if (rc) {
227 pr_err("%s: failed to set parent for byte clk for ctrl%d. rc=%d\n",
228 __func__, ctrl->ndx, rc);
229 goto error;
230 }
231
232 rc = clk_set_parent(ctrl->pixel_clk_rcg, pixel_parent);
233 if (rc) {
234 pr_err("%s: failed to set parent for pixel clk for ctrl%d. rc=%d\n",
235 __func__, ctrl->ndx, rc);
236 goto error;
237 }
238
239 pr_debug("%s: ctrl%d clock source set to %s", __func__, ctrl->ndx,
240 mdss_dsi_get_clk_src(ctrl));
241
242error:
243 return rc;
244}
245
246static int mdss_dsi_regulator_init(struct platform_device *pdev,
247 struct dsi_shared_data *sdata)
248{
249 int rc = 0, i = 0, j = 0;
250
251 if (!pdev || !sdata) {
252 pr_err("%s: invalid input\n", __func__);
253 return -EINVAL;
254 }
255
256 for (i = DSI_CORE_PM; !rc && (i < DSI_MAX_PM); i++) {
257 rc = msm_dss_config_vreg(&pdev->dev,
258 sdata->power_data[i].vreg_config,
259 sdata->power_data[i].num_vreg, 1);
260 if (rc) {
261 pr_err("%s: failed to init vregs for %s\n",
262 __func__, __mdss_dsi_pm_name(i));
263 for (j = i-1; j >= DSI_CORE_PM; j--) {
264 msm_dss_config_vreg(&pdev->dev,
265 sdata->power_data[j].vreg_config,
266 sdata->power_data[j].num_vreg, 0);
267 }
268 }
269 }
270
271 return rc;
272}
273
274static int mdss_dsi_panel_power_off(struct mdss_panel_data *pdata)
275{
276 int ret = 0;
277 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
278
279 if (pdata == NULL) {
280 pr_err("%s: Invalid input data\n", __func__);
281 ret = -EINVAL;
282 goto end;
283 }
284
285 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
286 panel_data);
287
288 ret = mdss_dsi_panel_reset(pdata, 0);
289 if (ret) {
290 pr_warn("%s: Panel reset failed. rc=%d\n", __func__, ret);
291 ret = 0;
292 }
293
294 if (mdss_dsi_pinctrl_set_state(ctrl_pdata, false))
295 pr_debug("reset disable: pinctrl not enabled\n");
296
297 ret = msm_dss_enable_vreg(
298 ctrl_pdata->panel_power_data.vreg_config,
299 ctrl_pdata->panel_power_data.num_vreg, 0);
300 if (ret)
301 pr_err("%s: failed to disable vregs for %s\n",
302 __func__, __mdss_dsi_pm_name(DSI_PANEL_PM));
303
304end:
305 return ret;
306}
307
308static int mdss_dsi_panel_power_on(struct mdss_panel_data *pdata)
309{
310 int ret = 0;
311 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
312
313 if (pdata == NULL) {
314 pr_err("%s: Invalid input data\n", __func__);
315 return -EINVAL;
316 }
317
318 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
319 panel_data);
320
321 ret = msm_dss_enable_vreg(
322 ctrl_pdata->panel_power_data.vreg_config,
323 ctrl_pdata->panel_power_data.num_vreg, 1);
324 if (ret) {
325 pr_err("%s: failed to enable vregs for %s\n",
326 __func__, __mdss_dsi_pm_name(DSI_PANEL_PM));
327 return ret;
328 }
329
330 /*
331 * If continuous splash screen feature is enabled, then we need to
332 * request all the GPIOs that have already been configured in the
333 * bootloader. This needs to be done irresepective of whether
334 * the lp11_init flag is set or not.
335 */
336 if (pdata->panel_info.cont_splash_enabled ||
337 !pdata->panel_info.mipi.lp11_init) {
338 if (mdss_dsi_pinctrl_set_state(ctrl_pdata, true))
339 pr_debug("reset enable: pinctrl not enabled\n");
340
341 ret = mdss_dsi_panel_reset(pdata, 1);
342 if (ret)
343 pr_err("%s: Panel reset failed. rc=%d\n",
344 __func__, ret);
345 }
346
347 return ret;
348}
349
350static int mdss_dsi_panel_power_lp(struct mdss_panel_data *pdata, int enable)
351{
352 /* Panel power control when entering/exiting lp mode */
353 return 0;
354}
355
Sachin Bhayare3d3767e2018-01-02 21:10:57 +0530356int msm_dss_config_vreg_opt_mode(struct dss_vreg *in_vreg,
357 int num_vreg, enum dss_vreg_mode mode)
358{
359/* stub: FIX ME.Should be sourced from mdss_io_util.c */
360 return 0;
361}
362
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530363static int mdss_dsi_panel_power_ulp(struct mdss_panel_data *pdata,
364 int enable)
365{
366 int ret = 0, i;
367 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
368 u32 mode = enable ? DSS_REG_MODE_ULP : DSS_REG_MODE_ENABLE;
369 struct dsi_shared_data *sdata;
370
371 pr_debug("%s: +\n", __func__);
372 if (pdata == NULL) {
373 pr_err("%s: Invalid input data\n", __func__);
374 return -EINVAL;
375 }
376
377 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
378 panel_data);
379 sdata = ctrl_pdata->shared_data;
380
381 for (i = 0; i < DSI_MAX_PM; i++) {
382 /*
383 * Core power module need to be controlled along with
384 * DSI core clocks.
385 */
386 if (i == DSI_CORE_PM)
387 continue;
388 if (i == DSI_PANEL_PM)
389 ret = msm_dss_config_vreg_opt_mode(
390 ctrl_pdata->panel_power_data.vreg_config,
391 ctrl_pdata->panel_power_data.num_vreg, mode);
392 else
393 ret = msm_dss_config_vreg_opt_mode(
394 sdata->power_data[i].vreg_config,
395 sdata->power_data[i].num_vreg, mode);
396 if (ret) {
397 pr_err("%s: failed to config ulp opt mode for %s.rc=%d\n",
398 __func__, __mdss_dsi_pm_name(i), ret);
399 break;
400 }
401 }
402
403 if (ret) {
404 mode = enable ? DSS_REG_MODE_ENABLE : DSS_REG_MODE_ULP;
405 for (; i >= 0; i--)
406 msm_dss_config_vreg_opt_mode(
407 ctrl_pdata->power_data[i].vreg_config,
408 ctrl_pdata->power_data[i].num_vreg, mode);
409 }
410 return ret;
411}
412
413int mdss_dsi_panel_power_ctrl(struct mdss_panel_data *pdata,
414 int power_state)
415{
Sachin Bhayare3d3767e2018-01-02 21:10:57 +0530416 int ret = 0;
Sachin Bhayareeeb88892018-01-02 16:36:01 +0530417 struct mdss_panel_info *pinfo;
418 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
419
420 if (pdata == NULL) {
421 pr_err("%s: Invalid input data\n", __func__);
422 return -EINVAL;
423 }
424
425 pinfo = &pdata->panel_info;
426 pr_debug("%pS-->%s: cur_power_state=%d req_power_state=%d\n",
427 __builtin_return_address(0), __func__,
428 pinfo->panel_power_state, power_state);
429
430 if (pinfo->panel_power_state == power_state) {
431 pr_debug("%s: no change needed\n", __func__);
432 return 0;
433 }
434
435 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
436 panel_data);
437
438 /*
439 * If a dynamic mode switch is pending, the regulators should not
440 * be turned off or on.
441 */
442 if (pdata->panel_info.dynamic_switch_pending)
443 return 0;
444
445 switch (power_state) {
446 case MDSS_PANEL_POWER_OFF:
447 ret = mdss_dsi_panel_power_off(pdata);
448 break;
449 case MDSS_PANEL_POWER_ON:
450 if (mdss_dsi_is_panel_on_ulp(pdata)) {
451 ret = mdss_dsi_panel_power_ulp(pdata, false);
452 goto end;
453 } else if (mdss_dsi_is_panel_on_lp(pdata)) {
454 ret = mdss_dsi_panel_power_lp(pdata, false);
455 goto end;
456 } else {
457 ret = mdss_dsi_panel_power_on(pdata);
458 }
459 break;
460 case MDSS_PANEL_POWER_LP1:
461 if (mdss_dsi_is_panel_on_ulp(pdata))
462 ret = mdss_dsi_panel_power_ulp(pdata, false);
463 else
464 ret = mdss_dsi_panel_power_lp(pdata, true);
465 /*
466 * temp workaround until framework issues pertaining to LP2
467 * power state transitions are fixed. For now, we internally
468 * transition to LP2 state whenever core power is turned off
469 * in LP1 state
470 */
471 break;
472 case MDSS_PANEL_POWER_LP2:
473 if (!ctrl_pdata->core_power)
474 ret = mdss_dsi_panel_power_ulp(pdata, true);
475 break;
476 default:
477 pr_err("%s: unknown panel power state requested (%d)\n",
478 __func__, power_state);
479 ret = -EINVAL;
480 }
481
482 if (!ret)
483 pinfo->panel_power_state = power_state;
484end:
485 return ret;
486}
487
488static void mdss_dsi_put_dt_vreg_data(struct device *dev,
489 struct dss_module_power *module_power)
490{
491 if (!module_power) {
492 pr_err("%s: invalid input\n", __func__);
493 return;
494 }
495
496 if (module_power->vreg_config) {
497 devm_kfree(dev, module_power->vreg_config);
498 module_power->vreg_config = NULL;
499 }
500 module_power->num_vreg = 0;
501}
502
503static int mdss_dsi_get_dt_vreg_data(struct device *dev,
504 struct device_node *of_node, struct dss_module_power *mp,
505 enum dsi_pm_type module)
506{
507 int i = 0, rc = 0;
508 u32 tmp = 0;
509 struct device_node *supply_node = NULL;
510 const char *pm_supply_name = NULL;
511 struct device_node *supply_root_node = NULL;
512
513 if (!dev || !mp) {
514 pr_err("%s: invalid input\n", __func__);
515 rc = -EINVAL;
516 return rc;
517 }
518
519 mp->num_vreg = 0;
520 pm_supply_name = __mdss_dsi_pm_supply_node_name(module);
521 supply_root_node = of_get_child_by_name(of_node, pm_supply_name);
522 if (!supply_root_node) {
523 /*
524 * Try to get the root node for panel power supply using
525 * of_parse_phandle() API if of_get_child_by_name() API fails.
526 */
527 supply_root_node = of_parse_phandle(of_node, pm_supply_name, 0);
528 if (!supply_root_node) {
529 pr_err("no supply entry present: %s\n", pm_supply_name);
530 goto novreg;
531 }
532 }
533
534
535 for_each_child_of_node(supply_root_node, supply_node) {
536 mp->num_vreg++;
537 }
538
539 if (mp->num_vreg == 0) {
540 pr_debug("%s: no vreg\n", __func__);
541 goto novreg;
542 } else {
543 pr_debug("%s: vreg found. count=%d\n", __func__, mp->num_vreg);
544 }
545
546 mp->vreg_config = devm_kzalloc(dev, sizeof(struct dss_vreg) *
547 mp->num_vreg, GFP_KERNEL);
548 if (!mp->vreg_config) {
549 rc = -ENOMEM;
550 goto error;
551 }
552
553 for_each_child_of_node(supply_root_node, supply_node) {
554 const char *st = NULL;
555 /* vreg-name */
556 rc = of_property_read_string(supply_node,
557 "qcom,supply-name", &st);
558 if (rc) {
559 pr_err("%s: error reading name. rc=%d\n",
560 __func__, rc);
561 goto error;
562 }
563 snprintf(mp->vreg_config[i].vreg_name,
564 ARRAY_SIZE((mp->vreg_config[i].vreg_name)), "%s", st);
565 /* vreg-min-voltage */
566 rc = of_property_read_u32(supply_node,
567 "qcom,supply-min-voltage", &tmp);
568 if (rc) {
569 pr_err("%s: error reading min volt. rc=%d\n",
570 __func__, rc);
571 goto error;
572 }
573 mp->vreg_config[i].min_voltage = tmp;
574
575 /* vreg-max-voltage */
576 rc = of_property_read_u32(supply_node,
577 "qcom,supply-max-voltage", &tmp);
578 if (rc) {
579 pr_err("%s: error reading max volt. rc=%d\n",
580 __func__, rc);
581 goto error;
582 }
583 mp->vreg_config[i].max_voltage = tmp;
584
585 /* enable-load */
586 rc = of_property_read_u32(supply_node,
587 "qcom,supply-enable-load", &tmp);
588 if (rc) {
589 pr_err("%s: error reading enable load. rc=%d\n",
590 __func__, rc);
591 goto error;
592 }
593 mp->vreg_config[i].load[DSS_REG_MODE_ENABLE] = tmp;
594
595 /* disable-load */
596 rc = of_property_read_u32(supply_node,
597 "qcom,supply-disable-load", &tmp);
598 if (rc) {
599 pr_err("%s: error reading disable load. rc=%d\n",
600 __func__, rc);
601 goto error;
602 }
603 mp->vreg_config[i].load[DSS_REG_MODE_DISABLE] = tmp;
604
605 /* ulp-load */
606 rc = of_property_read_u32(supply_node,
607 "qcom,supply-ulp-load", &tmp);
608 if (rc) {
609 pr_warn("%s: error reading ulp load. rc=%d\n",
610 __func__, rc);
611 rc = 0;
612 }
613 mp->vreg_config[i].load[DSS_REG_MODE_ULP] = (!rc ? tmp :
614 mp->vreg_config[i].load[DSS_REG_MODE_ENABLE]);
615
616 /* pre-sleep */
617 rc = of_property_read_u32(supply_node,
618 "qcom,supply-pre-on-sleep", &tmp);
619 if (rc) {
620 pr_debug("%s: error reading supply pre sleep value. rc=%d\n",
621 __func__, rc);
622 rc = 0;
623 } else {
624 mp->vreg_config[i].pre_on_sleep = tmp;
625 }
626
627 rc = of_property_read_u32(supply_node,
628 "qcom,supply-pre-off-sleep", &tmp);
629 if (rc) {
630 pr_debug("%s: error reading supply pre sleep value. rc=%d\n",
631 __func__, rc);
632 rc = 0;
633 } else {
634 mp->vreg_config[i].pre_off_sleep = tmp;
635 }
636
637 /* post-sleep */
638 rc = of_property_read_u32(supply_node,
639 "qcom,supply-post-on-sleep", &tmp);
640 if (rc) {
641 pr_debug("%s: error reading supply post sleep value. rc=%d\n",
642 __func__, rc);
643 rc = 0;
644 } else {
645 mp->vreg_config[i].post_on_sleep = tmp;
646 }
647
648 rc = of_property_read_u32(supply_node,
649 "qcom,supply-post-off-sleep", &tmp);
650 if (rc) {
651 pr_debug("%s: error reading supply post sleep value. rc=%d\n",
652 __func__, rc);
653 rc = 0;
654 } else {
655 mp->vreg_config[i].post_off_sleep = tmp;
656 }
657
658 pr_debug("%s: %s min=%d, max=%d, enable=%d, disable=%d, ulp_load=%d preonsleep=%d, postonsleep=%d, preoffsleep=%d, postoffsleep=%d\n",
659 __func__,
660 mp->vreg_config[i].vreg_name,
661 mp->vreg_config[i].min_voltage,
662 mp->vreg_config[i].max_voltage,
663 mp->vreg_config[i].load[DSS_REG_MODE_ENABLE],
664 mp->vreg_config[i].load[DSS_REG_MODE_DISABLE],
665 mp->vreg_config[i].load[DSS_REG_MODE_ULP],
666 mp->vreg_config[i].pre_on_sleep,
667 mp->vreg_config[i].post_on_sleep,
668 mp->vreg_config[i].pre_off_sleep,
669 mp->vreg_config[i].post_off_sleep
670 );
671 ++i;
672 }
673
674 return rc;
675
676error:
677 if (mp->vreg_config) {
678 devm_kfree(dev, mp->vreg_config);
679 mp->vreg_config = NULL;
680 }
681novreg:
682 mp->num_vreg = 0;
683
684 return rc;
685}
686
687static int mdss_dsi_get_panel_cfg(char *panel_cfg,
688 struct mdss_dsi_ctrl_pdata *ctrl)
689{
690 int rc;
691 struct mdss_panel_cfg *pan_cfg = NULL;
692
693 if (!panel_cfg)
694 return MDSS_PANEL_INTF_INVALID;
695
696 pan_cfg = ctrl->mdss_util->panel_intf_type(MDSS_PANEL_INTF_DSI);
697 if (IS_ERR(pan_cfg)) {
698 return PTR_ERR(pan_cfg);
699 } else if (!pan_cfg) {
700 panel_cfg[0] = 0;
701 return 0;
702 }
703
704 pr_debug("%s:%d: cfg:[%s]\n", __func__, __LINE__,
705 pan_cfg->arg_cfg);
706 rc = strlcpy(panel_cfg, pan_cfg->arg_cfg,
707 sizeof(pan_cfg->arg_cfg));
708 return rc;
709}
710
711struct buf_data {
712 char *buf; /* cmd buf */
713 int blen; /* cmd buf length */
714 char *string_buf; /* cmd buf as string, 3 bytes per number */
715 int sblen; /* string buffer length */
716 int sync_flag;
717 struct mutex dbg_mutex; /* mutex to synchronize read/write/flush */
718};
719
720struct mdss_dsi_debugfs_info {
721 struct dentry *root;
722 struct mdss_dsi_ctrl_pdata ctrl_pdata;
723 struct buf_data on_cmd;
724 struct buf_data off_cmd;
725 u32 override_flag;
726};
727
728static int mdss_dsi_cmd_state_open(struct inode *inode, struct file *file)
729{
730 /* non-seekable */
731 file->private_data = inode->i_private;
732 return nonseekable_open(inode, file);
733}
734
735static ssize_t mdss_dsi_cmd_state_read(struct file *file, char __user *buf,
736 size_t count, loff_t *ppos)
737{
738 int *link_state = file->private_data;
739 char buffer[32];
740 int blen = 0;
741
742 if (*ppos)
743 return 0;
744
745 if ((*link_state) == DSI_HS_MODE)
746 blen = snprintf(buffer, sizeof(buffer), "dsi_hs_mode\n");
747 else
748 blen = snprintf(buffer, sizeof(buffer), "dsi_lp_mode\n");
749
750 if (blen < 0)
751 return 0;
752
753 if (copy_to_user(buf, buffer, blen))
754 return -EFAULT;
755
756 *ppos += blen;
757 return blen;
758}
759
760static ssize_t mdss_dsi_cmd_state_write(struct file *file,
761 const char __user *p, size_t count, loff_t *ppos)
762{
763 int *link_state = file->private_data;
764 char *input;
765
766 if (!count) {
767 pr_err("%s: Zero bytes to be written\n", __func__);
768 return -EINVAL;
769 }
770
771 input = kmalloc(count, GFP_KERNEL);
772 if (!input)
773 return -ENOMEM;
774
775 if (copy_from_user(input, p, count)) {
776 kfree(input);
777 return -EFAULT;
778 }
779 input[count-1] = '\0';
780
781 if (strnstr(input, "dsi_hs_mode", strlen("dsi_hs_mode")))
782 *link_state = DSI_HS_MODE;
783 else
784 *link_state = DSI_LP_MODE;
785
786 kfree(input);
787 return count;
788}
789
790static const struct file_operations mdss_dsi_cmd_state_fop = {
791 .open = mdss_dsi_cmd_state_open,
792 .read = mdss_dsi_cmd_state_read,
793 .write = mdss_dsi_cmd_state_write,
794};
795
796static int mdss_dsi_cmd_open(struct inode *inode, struct file *file)
797{
798 /* non-seekable */
799 file->private_data = inode->i_private;
800 return nonseekable_open(inode, file);
801}
802
803static ssize_t mdss_dsi_cmd_read(struct file *file, char __user *buf,
804 size_t count, loff_t *ppos)
805{
806 struct buf_data *pcmds = file->private_data;
807 char *bp;
808 ssize_t ret = 0;
809
810 mutex_lock(&pcmds->dbg_mutex);
811 if (*ppos == 0) {
812 kfree(pcmds->string_buf);
813 pcmds->string_buf = NULL;
814 pcmds->sblen = 0;
815 }
816
817 if (!pcmds->string_buf) {
818 /*
819 * Buffer size is the sum of cmd length (3 bytes per number)
820 * with NULL terminater
821 */
822 int bsize = ((pcmds->blen)*3 + 1);
823 int blen = 0;
824 char *buffer;
825
826 buffer = kmalloc(bsize, GFP_KERNEL);
827 if (!buffer) {
828 mutex_unlock(&pcmds->dbg_mutex);
829 return -ENOMEM;
830 }
831
832 bp = pcmds->buf;
833 while ((blen < (bsize-1)) &&
834 (bp < ((pcmds->buf) + (pcmds->blen)))) {
835 struct dsi_ctrl_hdr dchdr =
836 *((struct dsi_ctrl_hdr *)bp);
837 int dhrlen = sizeof(dchdr), dlen;
838 char *tmp = (char *)(&dchdr);
839
840 dlen = dchdr.dlen;
841 dchdr.dlen = htons(dchdr.dlen);
842 while (dhrlen--)
843 blen += snprintf(buffer+blen, bsize-blen,
844 "%02x ", (*tmp++));
845
846 bp += sizeof(dchdr);
847 while (dlen--)
848 blen += snprintf(buffer+blen, bsize-blen,
849 "%02x ", (*bp++));
850 buffer[blen-1] = '\n';
851 }
852 buffer[blen] = '\0';
853 pcmds->string_buf = buffer;
854 pcmds->sblen = blen;
855 }
856
857 /*
858 * The max value of count is PAGE_SIZE(4096).
859 * It may need multiple times of reading if string buf is too large
860 */
861 if (*ppos >= (pcmds->sblen)) {
862 kfree(pcmds->string_buf);
863 pcmds->string_buf = NULL;
864 pcmds->sblen = 0;
865 mutex_unlock(&pcmds->dbg_mutex);
866 return 0; /* the end */
867 }
868 ret = simple_read_from_buffer(buf, count, ppos, pcmds->string_buf,
869 pcmds->sblen);
870 mutex_unlock(&pcmds->dbg_mutex);
871 return ret;
872}
873
874static ssize_t mdss_dsi_cmd_write(struct file *file, const char __user *p,
875 size_t count, loff_t *ppos)
876{
877 struct buf_data *pcmds = file->private_data;
878 ssize_t ret = 0;
879 int blen = 0;
880 char *string_buf;
881
882 mutex_lock(&pcmds->dbg_mutex);
883 if (*ppos == 0) {
884 kfree(pcmds->string_buf);
885 pcmds->string_buf = NULL;
886 pcmds->sblen = 0;
887 }
888
889 /* Allocate memory for the received string */
890 blen = count + (pcmds->sblen);
891 string_buf = krealloc(pcmds->string_buf, blen + 1, GFP_KERNEL);
892 if (!string_buf) {
893 pr_err("%s: Failed to allocate memory\n", __func__);
894 mutex_unlock(&pcmds->dbg_mutex);
895 return -ENOMEM;
896 }
897
898 /* Writing in batches is possible */
899 ret = simple_write_to_buffer(string_buf, blen, ppos, p, count);
900 if (ret < 0) {
901 pr_err("%s: Failed to copy data\n", __func__);
902 mutex_unlock(&pcmds->dbg_mutex);
903 return -EINVAL;
904 }
905
906 string_buf[ret] = '\0';
907 pcmds->string_buf = string_buf;
908 pcmds->sblen = count;
909 mutex_unlock(&pcmds->dbg_mutex);
910 return ret;
911}
912
913static int mdss_dsi_cmd_flush(struct file *file, fl_owner_t id)
914{
915 struct buf_data *pcmds = file->private_data;
916 int blen, len, i;
917 char *buf, *bufp, *bp;
918 struct dsi_ctrl_hdr *dchdr;
919
920 mutex_lock(&pcmds->dbg_mutex);
921
922 if (!pcmds->string_buf) {
923 mutex_unlock(&pcmds->dbg_mutex);
924 return 0;
925 }
926
927 /*
928 * Allocate memory for command buffer
929 * 3 bytes per number, and 2 bytes for the last one
930 */
931 blen = ((pcmds->sblen) + 2) / 3;
932 buf = kcalloc(1, blen, GFP_KERNEL);
933 if (!buf) {
934 pr_err("%s: Failed to allocate memory\n", __func__);
935 kfree(pcmds->string_buf);
936 pcmds->string_buf = NULL;
937 pcmds->sblen = 0;
938 mutex_unlock(&pcmds->dbg_mutex);
939 return -ENOMEM;
940 }
941
942 /* Translate the input string to command array */
943 bufp = pcmds->string_buf;
944 for (i = 0; i < blen; i++) {
945 uint32_t value = 0;
946 int step = 0;
947
948 if (sscanf(bufp, "%02x%n", &value, &step) > 0) {
949 *(buf+i) = (char)value;
950 bufp += step;
951 }
952 }
953
954 /* Scan dcs commands */
955 bp = buf;
956 len = blen;
957 while (len >= sizeof(*dchdr)) {
958 dchdr = (struct dsi_ctrl_hdr *)bp;
959 dchdr->dlen = ntohs(dchdr->dlen);
960 if (dchdr->dlen > len || dchdr->dlen < 0) {
961 pr_err("%s: dtsi cmd=%x error, len=%d\n",
962 __func__, dchdr->dtype, dchdr->dlen);
963 kfree(buf);
964 mutex_unlock(&pcmds->dbg_mutex);
965 return -EINVAL;
966 }
967 bp += sizeof(*dchdr);
968 len -= sizeof(*dchdr);
969 bp += dchdr->dlen;
970 len -= dchdr->dlen;
971 }
972 if (len != 0) {
973 pr_err("%s: dcs_cmd=%x len=%d error!\n", __func__,
974 bp[0], len);
975 kfree(buf);
976 mutex_unlock(&pcmds->dbg_mutex);
977 return -EINVAL;
978 }
979
980 if (pcmds->sync_flag) {
981 pcmds->buf = buf;
982 pcmds->blen = blen;
983 pcmds->sync_flag = 0;
984 } else {
985 kfree(pcmds->buf);
986 pcmds->buf = buf;
987 pcmds->blen = blen;
988 }
989 mutex_unlock(&pcmds->dbg_mutex);
990 return 0;
991}
992
993static const struct file_operations mdss_dsi_cmd_fop = {
994 .open = mdss_dsi_cmd_open,
995 .read = mdss_dsi_cmd_read,
996 .write = mdss_dsi_cmd_write,
997 .flush = mdss_dsi_cmd_flush,
998};
999
1000struct dentry *dsi_debugfs_create_dcs_cmd(const char *name, umode_t mode,
1001 struct dentry *parent, struct buf_data *cmd,
1002 struct dsi_panel_cmds ctrl_cmds)
1003{
1004 mutex_init(&cmd->dbg_mutex);
1005 cmd->buf = ctrl_cmds.buf;
1006 cmd->blen = ctrl_cmds.blen;
1007 cmd->string_buf = NULL;
1008 cmd->sblen = 0;
1009 cmd->sync_flag = 1;
1010
1011 return debugfs_create_file(name, mode, parent,
1012 cmd, &mdss_dsi_cmd_fop);
1013}
1014
1015#define DEBUGFS_CREATE_DCS_CMD(name, node, cmd, ctrl_cmd) \
1016 dsi_debugfs_create_dcs_cmd(name, 0644, node, cmd, ctrl_cmd)
1017
1018static int mdss_dsi_debugfs_setup(struct mdss_panel_data *pdata,
1019 struct dentry *parent)
1020{
1021 struct mdss_dsi_ctrl_pdata *ctrl_pdata, *dfs_ctrl;
1022 struct mdss_dsi_debugfs_info *dfs;
1023
1024 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
1025 panel_data);
1026
1027 dfs = kcalloc(1, sizeof(*dfs), GFP_KERNEL);
1028 if (!dfs)
1029 return -ENOMEM;
1030
1031 dfs->root = debugfs_create_dir("dsi_ctrl_pdata", parent);
1032 if (IS_ERR_OR_NULL(dfs->root)) {
1033 pr_err("%s: debugfs_create_dir dsi fail, error %ld\n",
1034 __func__, PTR_ERR(dfs->root));
1035 kfree(dfs);
1036 return -ENODEV;
1037 }
1038
1039 dfs_ctrl = &dfs->ctrl_pdata;
1040 debugfs_create_u32("override_flag", 0644, dfs->root,
1041 &dfs->override_flag);
1042
1043 debugfs_create_bool("cmd_sync_wait_broadcast", 0644, dfs->root,
Sachin Bhayare3d3767e2018-01-02 21:10:57 +05301044 &dfs_ctrl->cmd_sync_wait_broadcast);
Sachin Bhayareeeb88892018-01-02 16:36:01 +05301045 debugfs_create_bool("cmd_sync_wait_trigger", 0644, dfs->root,
Sachin Bhayare3d3767e2018-01-02 21:10:57 +05301046 &dfs_ctrl->cmd_sync_wait_trigger);
Sachin Bhayareeeb88892018-01-02 16:36:01 +05301047
1048 debugfs_create_file("dsi_on_cmd_state", 0644, dfs->root,
1049 &dfs_ctrl->on_cmds.link_state, &mdss_dsi_cmd_state_fop);
1050 debugfs_create_file("dsi_off_cmd_state", 0644, dfs->root,
1051 &dfs_ctrl->off_cmds.link_state, &mdss_dsi_cmd_state_fop);
1052
1053 DEBUGFS_CREATE_DCS_CMD("dsi_on_cmd", dfs->root, &dfs->on_cmd,
1054 ctrl_pdata->on_cmds);
1055 DEBUGFS_CREATE_DCS_CMD("dsi_off_cmd", dfs->root, &dfs->off_cmd,
1056 ctrl_pdata->off_cmds);
1057
1058 debugfs_create_u32("dsi_err_counter", 0644, dfs->root,
1059 &dfs_ctrl->err_cont.max_err_index);
1060 debugfs_create_u32("dsi_err_time_delta", 0644, dfs->root,
1061 &dfs_ctrl->err_cont.err_time_delta);
1062
1063 dfs->override_flag = 0;
1064 dfs->ctrl_pdata = *ctrl_pdata;
1065 ctrl_pdata->debugfs_info = dfs;
1066 return 0;
1067}
1068
1069static int mdss_dsi_debugfs_init(struct mdss_dsi_ctrl_pdata *ctrl_pdata)
1070{
1071 int rc;
1072 struct mdss_panel_data *pdata;
1073 struct mdss_panel_info panel_info;
1074
1075 if (!ctrl_pdata) {
1076 pr_warn_once("%s: Invalid pdata!\n", __func__);
1077 return -EINVAL;
1078 }
1079
1080 pdata = &ctrl_pdata->panel_data;
1081 if (!pdata)
1082 return -EINVAL;
1083
1084 panel_info = pdata->panel_info;
1085 rc = mdss_dsi_debugfs_setup(pdata, panel_info.debugfs_info->root);
1086 if (rc) {
1087 pr_err("%s: Error in initilizing dsi ctrl debugfs\n",
1088 __func__);
1089 return rc;
1090 }
1091
1092 pr_debug("%s: Initialized mdss_dsi_debugfs_init\n", __func__);
1093 return 0;
1094}
1095
1096static void mdss_dsi_debugfs_cleanup(struct mdss_dsi_ctrl_pdata *ctrl_pdata)
1097{
1098 struct mdss_panel_data *pdata = &ctrl_pdata->panel_data;
1099
1100 do {
1101 struct mdss_dsi_ctrl_pdata *ctrl = container_of(pdata,
1102 struct mdss_dsi_ctrl_pdata, panel_data);
1103 struct mdss_dsi_debugfs_info *dfs = ctrl->debugfs_info;
1104
1105 if (dfs && dfs->root)
1106 debugfs_remove_recursive(dfs->root);
1107 kfree(dfs);
1108 pdata = pdata->next;
1109 } while (pdata);
1110 pr_debug("%s: Cleaned up mdss_dsi_debugfs_info\n", __func__);
1111}
1112
1113static int _mdss_dsi_refresh_cmd(struct buf_data *new_cmds,
1114 struct dsi_panel_cmds *original_pcmds)
1115{
1116 char *bp;
1117 int len, cnt, i;
1118 struct dsi_ctrl_hdr *dchdr;
1119 struct dsi_cmd_desc *cmds;
1120
1121 if (new_cmds->sync_flag)
1122 return 0;
1123
1124 bp = new_cmds->buf;
1125 len = new_cmds->blen;
1126 cnt = 0;
1127 /* Scan dcs commands and get dcs command count */
1128 while (len >= sizeof(*dchdr)) {
1129 dchdr = (struct dsi_ctrl_hdr *)bp;
1130 if (dchdr->dlen > len) {
1131 pr_err("%s: dtsi cmd=%x error, len=%d\n",
1132 __func__, dchdr->dtype, dchdr->dlen);
1133 return -EINVAL;
1134 }
1135 bp += sizeof(*dchdr) + dchdr->dlen;
1136 len -= sizeof(*dchdr) + dchdr->dlen;
1137 cnt++;
1138 }
1139
1140 if (len != 0) {
1141 pr_err("%s: dcs_cmd=%x len=%d error!\n", __func__,
1142 bp[0], len);
1143 return -EINVAL;
1144 }
1145
1146 /* Reallocate space for dcs commands */
1147 cmds = kcalloc(cnt, sizeof(struct dsi_cmd_desc), GFP_KERNEL);
1148 if (!cmds)
1149 return -ENOMEM;
1150
1151 kfree(original_pcmds->buf);
1152 kfree(original_pcmds->cmds);
1153 original_pcmds->cmd_cnt = cnt;
1154 original_pcmds->cmds = cmds;
1155 original_pcmds->buf = new_cmds->buf;
1156 original_pcmds->blen = new_cmds->blen;
1157
1158 bp = original_pcmds->buf;
1159 len = original_pcmds->blen;
1160 for (i = 0; i < cnt; i++) {
1161 dchdr = (struct dsi_ctrl_hdr *)bp;
1162 len -= sizeof(*dchdr);
1163 bp += sizeof(*dchdr);
1164 original_pcmds->cmds[i].dchdr = *dchdr;
1165 original_pcmds->cmds[i].payload = bp;
1166 bp += dchdr->dlen;
1167 len -= dchdr->dlen;
1168 }
1169
1170 new_cmds->sync_flag = 1;
1171 return 0;
1172}
1173
1174static void mdss_dsi_debugfsinfo_to_dsictrl_info(
1175 struct mdss_dsi_ctrl_pdata *ctrl_pdata)
1176{
1177 struct mdss_dsi_debugfs_info *dfs = ctrl_pdata->debugfs_info;
1178 struct dsi_err_container *dfs_err_cont = &dfs->ctrl_pdata.err_cont;
1179 struct dsi_err_container *err_cont = &ctrl_pdata->err_cont;
1180
1181 ctrl_pdata->cmd_sync_wait_broadcast =
1182 dfs->ctrl_pdata.cmd_sync_wait_broadcast;
1183 ctrl_pdata->cmd_sync_wait_trigger =
1184 dfs->ctrl_pdata.cmd_sync_wait_trigger;
1185
1186 _mdss_dsi_refresh_cmd(&dfs->on_cmd, &ctrl_pdata->on_cmds);
1187 _mdss_dsi_refresh_cmd(&dfs->off_cmd, &ctrl_pdata->off_cmds);
1188
1189 ctrl_pdata->on_cmds.link_state =
1190 dfs->ctrl_pdata.on_cmds.link_state;
1191 ctrl_pdata->off_cmds.link_state =
1192 dfs->ctrl_pdata.off_cmds.link_state;
1193
1194 /* keep error counter between 2 to 10 */
1195 if (dfs_err_cont->max_err_index >= 2 &&
1196 dfs_err_cont->max_err_index <= MAX_ERR_INDEX) {
1197 err_cont->max_err_index = dfs_err_cont->max_err_index;
1198 } else {
1199 dfs_err_cont->max_err_index = err_cont->max_err_index;
1200 pr_warn("resetting the dsi error counter to %d\n",
1201 err_cont->max_err_index);
1202 }
1203
1204 /* keep error duration between 16 ms to 100 seconds */
1205 if (dfs_err_cont->err_time_delta >= 16 &&
1206 dfs_err_cont->err_time_delta <= 100000) {
1207 err_cont->err_time_delta = dfs_err_cont->err_time_delta;
1208 } else {
1209 dfs_err_cont->err_time_delta = err_cont->err_time_delta;
1210 pr_warn("resetting the dsi error time delta to %d ms\n",
1211 err_cont->err_time_delta);
1212 }
1213}
1214
1215static void mdss_dsi_validate_debugfs_info(
1216 struct mdss_dsi_ctrl_pdata *ctrl_pdata)
1217{
1218 struct mdss_dsi_debugfs_info *dfs = ctrl_pdata->debugfs_info;
1219
1220 if (dfs->override_flag) {
1221 pr_debug("%s: Overriding dsi ctrl_pdata with debugfs data\n",
1222 __func__);
1223 dfs->override_flag = 0;
1224 mdss_dsi_debugfsinfo_to_dsictrl_info(ctrl_pdata);
1225 }
1226}
1227
1228static int mdss_dsi_off(struct mdss_panel_data *pdata, int power_state)
1229{
1230 int ret = 0;
1231 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
1232 struct mdss_panel_info *panel_info = NULL;
1233
1234 if (pdata == NULL) {
1235 pr_err("%s: Invalid input data\n", __func__);
1236 return -EINVAL;
1237 }
1238
1239 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
1240 panel_data);
1241
1242 panel_info = &ctrl_pdata->panel_data.panel_info;
1243
1244 pr_debug("%s+: ctrl=%pK ndx=%d power_state=%d\n",
1245 __func__, ctrl_pdata, ctrl_pdata->ndx, power_state);
1246
1247 if (power_state == panel_info->panel_power_state) {
1248 pr_debug("%s: No change in power state %d -> %d\n", __func__,
1249 panel_info->panel_power_state, power_state);
1250 goto end;
1251 }
1252
1253 if (mdss_panel_is_power_on(power_state)) {
1254 pr_debug("%s: dsi_off with panel always on\n", __func__);
1255 goto panel_power_ctrl;
1256 }
1257
1258 /*
1259 * Link clocks should be turned off before PHY can be disabled.
1260 * For command mode panels, all clocks are turned off prior to reaching
1261 * here, so core clocks should be turned on before accessing hardware
1262 * registers. For video mode panel, turn off link clocks and then
1263 * disable PHY
1264 */
1265 if (pdata->panel_info.type == MIPI_CMD_PANEL)
1266 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1267 MDSS_DSI_CORE_CLK, MDSS_DSI_CLK_ON);
1268 else
1269 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1270 MDSS_DSI_LINK_CLK, MDSS_DSI_CLK_OFF);
1271
1272 if (!pdata->panel_info.ulps_suspend_enabled) {
1273 /* disable DSI controller */
1274 mdss_dsi_controller_cfg(0, pdata);
1275
1276 /* disable DSI phy */
1277 mdss_dsi_phy_disable(ctrl_pdata);
1278 }
1279 ctrl_pdata->ctrl_state &= ~CTRL_STATE_DSI_ACTIVE;
1280
1281 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1282 MDSS_DSI_CORE_CLK, MDSS_DSI_CLK_OFF);
1283
1284panel_power_ctrl:
1285 ret = mdss_dsi_panel_power_ctrl(pdata, power_state);
1286 if (ret) {
1287 pr_err("%s: Panel power off failed\n", __func__);
1288 goto end;
1289 }
1290
1291 if (panel_info->dynamic_fps
1292 && (panel_info->dfps_update == DFPS_SUSPEND_RESUME_MODE)
1293 && (panel_info->new_fps != panel_info->mipi.frame_rate))
1294 panel_info->mipi.frame_rate = panel_info->new_fps;
1295
1296 /* Initialize Max Packet size for DCS reads */
1297 ctrl_pdata->cur_max_pkt_size = 0;
1298end:
1299 pr_debug("%s-:\n", __func__);
1300
1301 return ret;
1302}
1303
1304int mdss_dsi_switch_mode(struct mdss_panel_data *pdata, int mode)
1305{
1306 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
1307 struct mipi_panel_info *pinfo;
1308 bool dsi_ctrl_setup_needed = false;
1309
1310 if (!pdata) {
1311 pr_err("%s: Invalid input data\n", __func__);
1312 return -EINVAL;
1313 }
1314 pr_debug("%s, start\n", __func__);
1315
1316 pinfo = &pdata->panel_info.mipi;
1317 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
1318 panel_data);
1319
1320 if ((pinfo->dms_mode != DYNAMIC_MODE_RESOLUTION_SWITCH_IMMEDIATE) &&
1321 (pinfo->dms_mode != DYNAMIC_MODE_SWITCH_IMMEDIATE)) {
1322 pr_debug("%s: Dynamic mode switch not enabled.\n", __func__);
1323 return -EPERM;
1324 }
1325
1326 if (mode == MIPI_VIDEO_PANEL) {
1327 mode = SWITCH_TO_VIDEO_MODE;
1328 } else if (mode == MIPI_CMD_PANEL) {
1329 mode = SWITCH_TO_CMD_MODE;
1330 } else if (mode == SWITCH_RESOLUTION) {
1331 dsi_ctrl_setup_needed = true;
1332 pr_debug("Resolution switch mode selected\n");
1333 } else {
1334 pr_err("Invalid mode selected, mode=%d\n", mode);
1335 return -EINVAL;
1336 }
1337
1338 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1339 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON);
1340 if (dsi_ctrl_setup_needed)
1341 mdss_dsi_ctrl_setup(ctrl_pdata);
1342 ctrl_pdata->switch_mode(pdata, mode);
1343 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1344 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF);
1345
1346 pr_debug("%s, end\n", __func__);
1347 return 0;
1348}
1349
1350static int mdss_dsi_reconfig(struct mdss_panel_data *pdata, int mode)
1351{
1352 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
1353 struct mipi_panel_info *pinfo;
1354
1355 if (!pdata) {
1356 pr_err("%s: Invalid input data\n", __func__);
1357 return -EINVAL;
1358 }
1359 pr_debug("%s, start\n", __func__);
1360
1361 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
1362 panel_data);
1363 pinfo = &pdata->panel_info.mipi;
1364
1365 if (pinfo->dms_mode == DYNAMIC_MODE_SWITCH_IMMEDIATE) {
1366 /* reset DSI */
1367 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1368 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON);
1369 mdss_dsi_sw_reset(ctrl_pdata, true);
1370 mdss_dsi_ctrl_setup(ctrl_pdata);
1371 mdss_dsi_controller_cfg(true, pdata);
1372 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1373 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF);
1374 }
1375
1376 pr_debug("%s, end\n", __func__);
1377 return 0;
1378}
1379static int mdss_dsi_update_panel_config(struct mdss_dsi_ctrl_pdata *ctrl_pdata,
1380 int mode)
1381{
1382 int ret = 0;
1383 struct mdss_panel_info *pinfo = &(ctrl_pdata->panel_data.panel_info);
1384
1385 if (mode == DSI_CMD_MODE) {
1386 pinfo->mipi.mode = DSI_CMD_MODE;
1387 pinfo->type = MIPI_CMD_PANEL;
1388 pinfo->mipi.vsync_enable = 1;
1389 pinfo->mipi.hw_vsync_mode = 1;
1390 pinfo->partial_update_enabled = pinfo->partial_update_supported;
1391 } else { /*video mode*/
1392 pinfo->mipi.mode = DSI_VIDEO_MODE;
1393 pinfo->type = MIPI_VIDEO_PANEL;
1394 pinfo->mipi.vsync_enable = 0;
1395 pinfo->mipi.hw_vsync_mode = 0;
1396 pinfo->partial_update_enabled = 0;
1397 }
1398
1399 ctrl_pdata->panel_mode = pinfo->mipi.mode;
1400 mdss_panel_get_dst_fmt(pinfo->bpp, pinfo->mipi.mode,
1401 pinfo->mipi.pixel_packing, &(pinfo->mipi.dst_format));
1402 return ret;
1403}
1404
1405int mdss_dsi_on(struct mdss_panel_data *pdata)
1406{
1407 int ret = 0;
1408 struct mdss_panel_info *pinfo;
1409 struct mipi_panel_info *mipi;
1410 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
1411 int cur_power_state;
1412
1413 if (pdata == NULL) {
1414 pr_err("%s: Invalid input data\n", __func__);
1415 return -EINVAL;
1416 }
1417
1418 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
1419 panel_data);
1420
1421 if (ctrl_pdata->debugfs_info)
1422 mdss_dsi_validate_debugfs_info(ctrl_pdata);
1423
1424 cur_power_state = pdata->panel_info.panel_power_state;
1425 pr_debug("%s+: ctrl=%pK ndx=%d cur_power_state=%d\n", __func__,
1426 ctrl_pdata, ctrl_pdata->ndx, cur_power_state);
1427
1428 pinfo = &pdata->panel_info;
1429 mipi = &pdata->panel_info.mipi;
1430
1431 if (mdss_dsi_is_panel_on_interactive(pdata)) {
1432 /*
1433 * all interrupts are disabled at LK
1434 * for cont_splash case, intr mask bits need
1435 * to be restored to allow dcs command be
1436 * sent to panel
1437 */
1438 mdss_dsi_restore_intr_mask(ctrl_pdata);
1439 pr_debug("%s: panel already on\n", __func__);
1440 goto end;
1441 }
1442
1443 ret = mdss_dsi_panel_power_ctrl(pdata, MDSS_PANEL_POWER_ON);
1444 if (ret) {
1445 pr_err("%s:Panel power on failed. rc=%d\n", __func__, ret);
1446 goto end;
1447 }
1448
1449 if (mdss_panel_is_power_on(cur_power_state)) {
1450 pr_debug("%s: dsi_on from panel low power state\n", __func__);
1451 goto end;
1452 }
1453
1454 ret = mdss_dsi_set_clk_src(ctrl_pdata);
1455 if (ret) {
1456 pr_err("%s: failed to set clk src. rc=%d\n", __func__, ret);
1457 goto end;
1458 }
1459
1460 /*
1461 * Enable DSI core clocks prior to resetting and initializing DSI
1462 * Phy. Phy and ctrl setup need to be done before enabling the link
1463 * clocks.
1464 */
1465 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1466 MDSS_DSI_CORE_CLK, MDSS_DSI_CLK_ON);
1467
1468 /*
1469 * If ULPS during suspend feature is enabled, then DSI PHY was
1470 * left on during suspend. In this case, we do not need to reset/init
1471 * PHY. This would have already been done when the CORE clocks are
1472 * turned on. However, if cont splash is disabled, the first time DSI
1473 * is powered on, phy init needs to be done unconditionally.
1474 */
1475 if (!pdata->panel_info.ulps_suspend_enabled || !ctrl_pdata->ulps) {
1476 mdss_dsi_phy_sw_reset(ctrl_pdata);
1477 mdss_dsi_phy_init(ctrl_pdata);
1478 mdss_dsi_ctrl_setup(ctrl_pdata);
1479 }
1480 ctrl_pdata->ctrl_state |= CTRL_STATE_DSI_ACTIVE;
1481
1482 /* DSI link clocks need to be on prior to ctrl sw reset */
1483 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1484 MDSS_DSI_LINK_CLK, MDSS_DSI_CLK_ON);
1485 mdss_dsi_sw_reset(ctrl_pdata, true);
1486
1487 /*
1488 * Issue hardware reset line after enabling the DSI clocks and data
1489 * data lanes for LP11 init
1490 */
1491 if (mipi->lp11_init) {
1492 if (mdss_dsi_pinctrl_set_state(ctrl_pdata, true))
1493 pr_debug("reset enable: pinctrl not enabled\n");
1494 mdss_dsi_panel_reset(pdata, 1);
1495 }
1496
1497 if (mipi->init_delay)
1498 usleep_range(mipi->init_delay, mipi->init_delay + 10);
1499
1500 if (mipi->force_clk_lane_hs) {
1501 u32 tmp;
1502
1503 tmp = MIPI_INP((ctrl_pdata->ctrl_base) + 0xac);
1504 tmp |= (1<<28);
1505 MIPI_OUTP((ctrl_pdata->ctrl_base) + 0xac, tmp);
1506 wmb(); /* ensure write is finished before progressing */
1507 }
1508
1509 if (pdata->panel_info.type == MIPI_CMD_PANEL)
1510 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1511 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF);
1512
1513end:
1514 pr_debug("%s-:\n", __func__);
1515 return ret;
1516}
1517
1518static int mdss_dsi_pinctrl_set_state(
1519 struct mdss_dsi_ctrl_pdata *ctrl_pdata,
1520 bool active)
1521{
1522 struct pinctrl_state *pin_state;
1523 struct mdss_panel_info *pinfo = NULL;
1524 int rc = -EFAULT;
1525
1526 if (IS_ERR_OR_NULL(ctrl_pdata->pin_res.pinctrl))
1527 return PTR_ERR(ctrl_pdata->pin_res.pinctrl);
1528
1529 pinfo = &ctrl_pdata->panel_data.panel_info;
1530 if ((mdss_dsi_is_right_ctrl(ctrl_pdata) &&
1531 mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data)) ||
1532 pinfo->is_dba_panel) {
1533 pr_debug("%s:%d, right ctrl pinctrl config not needed\n",
1534 __func__, __LINE__);
1535 return 0;
1536 }
1537
1538 pin_state = active ? ctrl_pdata->pin_res.gpio_state_active
1539 : ctrl_pdata->pin_res.gpio_state_suspend;
1540 if (!IS_ERR_OR_NULL(pin_state)) {
1541 rc = pinctrl_select_state(ctrl_pdata->pin_res.pinctrl,
1542 pin_state);
1543 if (rc)
1544 pr_err("%s: can not set %s pins\n", __func__,
1545 active ? MDSS_PINCTRL_STATE_DEFAULT
1546 : MDSS_PINCTRL_STATE_SLEEP);
1547 } else {
1548 pr_err("%s: invalid '%s' pinstate\n", __func__,
1549 active ? MDSS_PINCTRL_STATE_DEFAULT
1550 : MDSS_PINCTRL_STATE_SLEEP);
1551 }
1552 return rc;
1553}
1554
1555static int mdss_dsi_pinctrl_init(struct platform_device *pdev)
1556{
1557 struct mdss_dsi_ctrl_pdata *ctrl_pdata;
1558
1559 ctrl_pdata = platform_get_drvdata(pdev);
1560 ctrl_pdata->pin_res.pinctrl = devm_pinctrl_get(&pdev->dev);
1561 if (IS_ERR_OR_NULL(ctrl_pdata->pin_res.pinctrl)) {
1562 pr_err("%s: failed to get pinctrl\n", __func__);
1563 return PTR_ERR(ctrl_pdata->pin_res.pinctrl);
1564 }
1565
1566 ctrl_pdata->pin_res.gpio_state_active
1567 = pinctrl_lookup_state(ctrl_pdata->pin_res.pinctrl,
1568 MDSS_PINCTRL_STATE_DEFAULT);
1569 if (IS_ERR_OR_NULL(ctrl_pdata->pin_res.gpio_state_active))
1570 pr_warn("%s: can not get default pinstate\n", __func__);
1571
1572 ctrl_pdata->pin_res.gpio_state_suspend
1573 = pinctrl_lookup_state(ctrl_pdata->pin_res.pinctrl,
1574 MDSS_PINCTRL_STATE_SLEEP);
1575 if (IS_ERR_OR_NULL(ctrl_pdata->pin_res.gpio_state_suspend))
1576 pr_warn("%s: can not get sleep pinstate\n", __func__);
1577
1578 return 0;
1579}
1580
1581static int mdss_dsi_unblank(struct mdss_panel_data *pdata)
1582{
1583 int ret = 0;
1584 struct mipi_panel_info *mipi;
1585 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
1586 struct mdss_dsi_ctrl_pdata *sctrl = NULL;
1587
1588 if (pdata == NULL) {
1589 pr_err("%s: Invalid input data\n", __func__);
1590 return -EINVAL;
1591 }
1592
1593 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
1594 panel_data);
1595 mipi = &pdata->panel_info.mipi;
1596
1597 pr_debug("%s+: ctrl=%pK ndx=%d cur_power_state=%d ctrl_state=%x\n",
1598 __func__, ctrl_pdata, ctrl_pdata->ndx,
1599 pdata->panel_info.panel_power_state, ctrl_pdata->ctrl_state);
1600
1601 mdss_dsi_pm_qos_update_request(DSI_DISABLE_PC_LATENCY);
1602
1603 if (mdss_dsi_is_ctrl_clk_master(ctrl_pdata))
1604 sctrl = mdss_dsi_get_ctrl_clk_slave();
1605
1606 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1607 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON);
1608 if (sctrl)
1609 mdss_dsi_clk_ctrl(sctrl, sctrl->dsi_clk_handle,
1610 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON);
1611
1612 if (ctrl_pdata->ctrl_state & CTRL_STATE_PANEL_LP) {
1613 pr_debug("%s: dsi_unblank with panel always on\n", __func__);
1614 if (ctrl_pdata->low_power_config)
1615 ret = ctrl_pdata->low_power_config(pdata, false);
1616 if (!ret)
1617 ctrl_pdata->ctrl_state &= ~CTRL_STATE_PANEL_LP;
1618 goto error;
1619 }
1620
1621 if (!(ctrl_pdata->ctrl_state & CTRL_STATE_PANEL_INIT)) {
1622 if (!pdata->panel_info.dynamic_switch_pending) {
1623 ATRACE_BEGIN("dsi_panel_on");
1624 ret = ctrl_pdata->on(pdata);
1625 if (ret) {
1626 pr_err("%s: unable to initialize the panel\n",
1627 __func__);
1628 goto error;
1629 }
1630 ATRACE_END("dsi_panel_on");
1631 }
1632 }
1633
1634 if ((pdata->panel_info.type == MIPI_CMD_PANEL) &&
1635 mipi->vsync_enable && mipi->hw_vsync_mode) {
1636 mdss_dsi_set_tear_on(ctrl_pdata);
1637 }
1638
1639 ctrl_pdata->ctrl_state |= CTRL_STATE_PANEL_INIT;
1640
1641error:
1642 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1643 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF);
1644 if (sctrl)
1645 mdss_dsi_clk_ctrl(sctrl, sctrl->dsi_clk_handle,
1646 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF);
1647
1648 mdss_dsi_pm_qos_update_request(DSI_ENABLE_PC_LATENCY);
1649
1650 pr_debug("%s-:\n", __func__);
1651
1652 return ret;
1653}
1654
1655static int mdss_dsi_blank(struct mdss_panel_data *pdata, int power_state)
1656{
1657 int ret = 0;
1658 struct mipi_panel_info *mipi;
1659 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
1660
1661 if (pdata == NULL) {
1662 pr_err("%s: Invalid input data\n", __func__);
1663 return -EINVAL;
1664 }
1665
1666 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
1667 panel_data);
1668 mipi = &pdata->panel_info.mipi;
1669
1670 pr_debug("%s+: ctrl=%pK ndx=%d power_state=%d\n",
1671 __func__, ctrl_pdata, ctrl_pdata->ndx, power_state);
1672
1673 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1674 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON);
1675
1676 if (mdss_panel_is_power_on_lp(power_state)) {
1677 pr_debug("%s: low power state requested\n", __func__);
1678 if (ctrl_pdata->low_power_config)
1679 ret = ctrl_pdata->low_power_config(pdata, true);
1680 if (!ret)
1681 ctrl_pdata->ctrl_state |= CTRL_STATE_PANEL_LP;
1682 goto error;
1683 }
1684
1685 if (pdata->panel_info.type == MIPI_VIDEO_PANEL &&
1686 ctrl_pdata->off_cmds.link_state == DSI_LP_MODE) {
1687 mdss_dsi_sw_reset(ctrl_pdata, false);
1688 mdss_dsi_host_init(pdata);
1689 }
1690
1691 mdss_dsi_op_mode_config(DSI_CMD_MODE, pdata);
1692
1693 if (pdata->panel_info.dynamic_switch_pending) {
1694 pr_info("%s: switching to %s mode\n", __func__,
1695 (pdata->panel_info.mipi.mode ? "video" : "command"));
1696 if (pdata->panel_info.type == MIPI_CMD_PANEL) {
1697 ctrl_pdata->switch_mode(pdata, SWITCH_TO_VIDEO_MODE);
1698 } else if (pdata->panel_info.type == MIPI_VIDEO_PANEL) {
1699 ctrl_pdata->switch_mode(pdata, SWITCH_TO_CMD_MODE);
1700 mdss_dsi_set_tear_off(ctrl_pdata);
1701 }
1702 }
1703
1704 if ((pdata->panel_info.type == MIPI_CMD_PANEL) &&
1705 mipi->vsync_enable && mipi->hw_vsync_mode) {
1706 mdss_dsi_set_tear_off(ctrl_pdata);
1707 }
1708
1709 if (ctrl_pdata->ctrl_state & CTRL_STATE_PANEL_INIT) {
1710 if (!pdata->panel_info.dynamic_switch_pending) {
1711 ATRACE_BEGIN("dsi_panel_off");
1712 ret = ctrl_pdata->off(pdata);
1713 if (ret) {
1714 pr_err("%s: Panel OFF failed\n", __func__);
1715 goto error;
1716 }
1717 ATRACE_END("dsi_panel_off");
1718 }
1719 ctrl_pdata->ctrl_state &= ~(CTRL_STATE_PANEL_INIT |
1720 CTRL_STATE_PANEL_LP);
1721 }
1722
1723error:
1724 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1725 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF);
1726 pr_debug("%s-:End\n", __func__);
1727 return ret;
1728}
1729
1730static int mdss_dsi_post_panel_on(struct mdss_panel_data *pdata)
1731{
1732 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
1733
1734 if (pdata == NULL) {
1735 pr_err("%s: Invalid input data\n", __func__);
1736 return -EINVAL;
1737 }
1738
1739 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
1740 panel_data);
1741
1742 pr_debug("%s+: ctrl=%pK ndx=%d\n", __func__,
1743 ctrl_pdata, ctrl_pdata->ndx);
1744
1745 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1746 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON);
1747
1748 if (ctrl_pdata->post_panel_on)
1749 ctrl_pdata->post_panel_on(pdata);
1750
1751 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
1752 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF);
1753 pr_debug("%s-:\n", __func__);
1754
1755 return 0;
1756}
1757
1758static irqreturn_t test_hw_vsync_handler(int irq, void *data)
1759{
1760 struct mdss_panel_data *pdata = (struct mdss_panel_data *)data;
1761
1762 pr_debug("HW VSYNC\n");
1763 MDSS_XLOG(0xaaa, irq);
1764 complete_all(&pdata->te_done);
1765 if (pdata->next)
1766 complete_all(&pdata->next->te_done);
1767 return IRQ_HANDLED;
1768}
1769
1770int mdss_dsi_cont_splash_on(struct mdss_panel_data *pdata)
1771{
1772 int ret = 0;
1773 struct mipi_panel_info *mipi;
1774 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
1775
1776 pr_info("%s:%d DSI on for continuous splash.\n", __func__, __LINE__);
1777
1778 if (pdata == NULL) {
1779 pr_err("%s: Invalid input data\n", __func__);
1780 return -EINVAL;
1781 }
1782
1783 mipi = &pdata->panel_info.mipi;
1784
1785 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
1786 panel_data);
1787
1788 pr_debug("%s+: ctrl=%pK ndx=%d\n", __func__,
1789 ctrl_pdata, ctrl_pdata->ndx);
1790
1791 WARN((ctrl_pdata->ctrl_state & CTRL_STATE_PANEL_INIT),
1792 "Incorrect Ctrl state=0x%x\n", ctrl_pdata->ctrl_state);
1793
1794 mdss_dsi_ctrl_setup(ctrl_pdata);
1795 mdss_dsi_sw_reset(ctrl_pdata, true);
1796 pr_debug("%s-:End\n", __func__);
1797 return ret;
1798}
1799
1800static void __mdss_dsi_mask_dfps_errors(struct mdss_dsi_ctrl_pdata *ctrl,
1801 bool mask)
1802{
1803 u32 data = 0;
1804
1805 /*
1806 * Assumption is that the DSI clocks will be enabled
1807 * when this API is called from dfps thread
1808 */
1809 if (mask) {
1810 /* mask FIFO underflow and PLL unlock bits */
1811 mdss_dsi_set_reg(ctrl, 0x10c, 0x7c000000, 0x7c000000);
1812 } else {
1813 data = MIPI_INP((ctrl->ctrl_base) + 0x0120);
1814 if (data & BIT(16)) {
1815 pr_debug("pll unlocked: 0x%x\n", data);
1816 /* clear PLL unlock bit */
1817 MIPI_OUTP((ctrl->ctrl_base) + 0x120, BIT(16));
1818 }
1819
1820 data = MIPI_INP((ctrl->ctrl_base) + 0x00c);
1821 if (data & 0x88880000) {
1822 pr_debug("dsi fifo underflow: 0x%x\n", data);
1823 /* clear DSI FIFO underflow and empty */
1824 MIPI_OUTP((ctrl->ctrl_base) + 0x00c, 0x99990000);
1825 }
1826
1827 /* restore FIFO underflow and PLL unlock bits */
1828 mdss_dsi_set_reg(ctrl, 0x10c, 0x7c000000, 0x0);
1829 }
1830}
1831
1832static void __mdss_dsi_update_video_mode_total(struct mdss_panel_data *pdata,
1833 int new_fps)
1834{
1835 u32 hsync_period, vsync_period;
1836 u32 new_dsi_v_total, current_dsi_v_total;
1837 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
1838
1839 if (pdata == NULL) {
1840 pr_err("%s Invalid pdata\n", __func__);
1841 return;
1842 }
1843
1844 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
1845 panel_data);
1846 if (ctrl_pdata == NULL) {
1847 pr_err("%s Invalid ctrl_pdata\n", __func__);
1848 return;
1849 }
1850
1851 vsync_period =
1852 mdss_panel_get_vtotal(&pdata->panel_info);
1853 hsync_period =
1854 mdss_panel_get_htotal(&pdata->panel_info, true);
1855 current_dsi_v_total =
1856 MIPI_INP((ctrl_pdata->ctrl_base) + 0x2C);
1857 new_dsi_v_total =
1858 ((vsync_period - 1) << 16) | (hsync_period - 1);
1859
1860 MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x2C,
1861 (current_dsi_v_total | 0x8000000));
1862 if (new_dsi_v_total & 0x8000000) {
1863 MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x2C,
1864 new_dsi_v_total);
1865 } else {
1866 MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x2C,
1867 (new_dsi_v_total | 0x8000000));
1868 MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x2C,
1869 (new_dsi_v_total & 0x7ffffff));
1870 }
1871
1872 if (ctrl_pdata->timing_db_mode)
1873 MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x1e4, 0x1);
1874
1875 pr_debug("%s new_fps:%d vsync:%d hsync:%d frame_rate:%d\n",
1876 __func__, new_fps, vsync_period, hsync_period,
1877 ctrl_pdata->panel_data.panel_info.mipi.frame_rate);
1878
1879 ctrl_pdata->panel_data.panel_info.current_fps = new_fps;
1880 MDSS_XLOG(current_dsi_v_total, new_dsi_v_total, new_fps,
1881 ctrl_pdata->timing_db_mode);
1882
1883}
1884
1885static void __mdss_dsi_dyn_refresh_config(
1886 struct mdss_dsi_ctrl_pdata *ctrl_pdata)
1887{
1888 int reg_data = 0;
1889 u32 phy_rev = ctrl_pdata->shared_data->phy_rev;
1890
1891 /* configure only for master control in split display */
1892 if (mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) &&
1893 mdss_dsi_is_ctrl_clk_slave(ctrl_pdata))
1894 return;
1895
1896 switch (phy_rev) {
1897 case DSI_PHY_REV_10:
1898 reg_data = MIPI_INP((ctrl_pdata->ctrl_base) +
1899 DSI_DYNAMIC_REFRESH_CTRL);
1900 reg_data &= ~BIT(12);
1901 MIPI_OUTP((ctrl_pdata->ctrl_base)
1902 + DSI_DYNAMIC_REFRESH_CTRL, reg_data);
1903 break;
1904 case DSI_PHY_REV_20:
1905 reg_data = BIT(13);
1906 MIPI_OUTP((ctrl_pdata->ctrl_base)
1907 + DSI_DYNAMIC_REFRESH_CTRL, reg_data);
1908 break;
1909 default:
1910 pr_err("Phy rev %d unsupported\n", phy_rev);
1911 break;
1912 }
1913
1914 pr_debug("Dynamic fps ctrl = 0x%x\n", reg_data);
1915}
1916
1917static void __mdss_dsi_calc_dfps_delay(struct mdss_panel_data *pdata)
1918{
1919 u32 esc_clk_rate = XO_CLK_RATE;
1920 u32 pipe_delay, pipe_delay2 = 0, pll_delay;
1921 u32 hsync_period = 0;
1922 u32 pclk_to_esc_ratio, byte_to_esc_ratio, hr_bit_to_esc_ratio;
1923 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
1924 struct mdss_panel_info *pinfo = NULL;
1925 struct mdss_dsi_phy_ctrl *pd = NULL;
1926
1927 if (pdata == NULL) {
1928 pr_err("%s Invalid pdata\n", __func__);
1929 return;
1930 }
1931
1932 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
1933 panel_data);
1934 if (ctrl_pdata == NULL) {
1935 pr_err("%s Invalid ctrl_pdata\n", __func__);
1936 return;
1937 }
1938
1939 if (mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) &&
1940 mdss_dsi_is_ctrl_clk_slave(ctrl_pdata))
1941 return;
1942
1943 pinfo = &pdata->panel_info;
1944 pd = &(pinfo->mipi.dsi_phy_db);
1945
1946 pclk_to_esc_ratio = (ctrl_pdata->pclk_rate / esc_clk_rate);
1947 byte_to_esc_ratio = (ctrl_pdata->byte_clk_rate / esc_clk_rate);
1948 hr_bit_to_esc_ratio = ((ctrl_pdata->byte_clk_rate * 4) / esc_clk_rate);
1949
1950 hsync_period = mdss_panel_get_htotal(pinfo, true);
1951 pipe_delay = (hsync_period + 1) / pclk_to_esc_ratio;
1952 if (pinfo->mipi.eof_bllp_power_stop == 0)
1953 pipe_delay += (17 / pclk_to_esc_ratio) +
1954 ((21 + (pinfo->mipi.t_clk_pre + 1) +
1955 (pinfo->mipi.t_clk_post + 1)) /
1956 byte_to_esc_ratio) +
1957 ((((pd->timing[8] >> 1) + 1) +
1958 ((pd->timing[6] >> 1) + 1) +
1959 ((pd->timing[3] * 4) + (pd->timing[5] >> 1) + 1) +
1960 ((pd->timing[7] >> 1) + 1) +
1961 ((pd->timing[1] >> 1) + 1) +
1962 ((pd->timing[4] >> 1) + 1)) / hr_bit_to_esc_ratio);
1963
1964 if (pinfo->mipi.force_clk_lane_hs)
1965 pipe_delay2 = (6 / byte_to_esc_ratio) +
1966 ((((pd->timing[1] >> 1) + 1) +
1967 ((pd->timing[4] >> 1) + 1)) / hr_bit_to_esc_ratio);
1968
1969 /* 130 us pll delay recommended by h/w doc */
1970 pll_delay = ((130 * esc_clk_rate) / 1000000) * 2;
1971
1972 MIPI_OUTP((ctrl_pdata->ctrl_base) + DSI_DYNAMIC_REFRESH_PIPE_DELAY,
1973 pipe_delay);
1974 MIPI_OUTP((ctrl_pdata->ctrl_base) + DSI_DYNAMIC_REFRESH_PIPE_DELAY2,
1975 pipe_delay2);
1976 MIPI_OUTP((ctrl_pdata->ctrl_base) + DSI_DYNAMIC_REFRESH_PLL_DELAY,
1977 pll_delay);
1978}
1979
1980static int __mdss_dsi_dfps_calc_clks(struct mdss_panel_data *pdata,
1981 int new_fps)
1982{
1983 int rc = 0;
1984 u64 clk_rate;
1985 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
1986 struct mdss_panel_info *pinfo;
1987 u32 phy_rev;
1988
1989 if (pdata == NULL) {
1990 pr_err("%s Invalid pdata\n", __func__);
1991 return -EINVAL;
1992 }
1993
1994 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
1995 panel_data);
1996 if (ctrl_pdata == NULL) {
1997 pr_err("%s Invalid ctrl_pdata\n", __func__);
1998 return -EINVAL;
1999 }
2000
2001 pinfo = &pdata->panel_info;
2002 phy_rev = ctrl_pdata->shared_data->phy_rev;
2003
2004 rc = mdss_dsi_clk_div_config
2005 (&ctrl_pdata->panel_data.panel_info, new_fps);
2006 if (rc) {
2007 pr_err("%s: unable to initialize the clk dividers\n",
2008 __func__);
2009 return rc;
2010 }
2011
2012 __mdss_dsi_dyn_refresh_config(ctrl_pdata);
2013
2014 if (phy_rev == DSI_PHY_REV_20)
2015 mdss_dsi_dfps_config_8996(ctrl_pdata);
2016
2017 __mdss_dsi_calc_dfps_delay(pdata);
2018
2019 /* take a backup of current clk rates */
2020 ctrl_pdata->pclk_rate_bkp = ctrl_pdata->pclk_rate;
2021 ctrl_pdata->byte_clk_rate_bkp = ctrl_pdata->byte_clk_rate;
2022
2023 ctrl_pdata->pclk_rate = pinfo->mipi.dsi_pclk_rate;
2024 clk_rate = pinfo->clk_rate;
2025 do_div(clk_rate, 8U);
2026 ctrl_pdata->byte_clk_rate = (u32) clk_rate;
2027
2028 pr_debug("byte_rate=%i\n", ctrl_pdata->byte_clk_rate);
2029 pr_debug("pclk_rate=%i\n", ctrl_pdata->pclk_rate);
2030
2031 return rc;
2032}
2033
2034static int __mdss_dsi_dfps_update_clks(struct mdss_panel_data *pdata,
2035 int new_fps)
2036{
2037 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
2038 struct mdss_dsi_ctrl_pdata *sctrl_pdata = NULL;
Sachin Bhayare3d3767e2018-01-02 21:10:57 +05302039 struct mdss_panel_info *pinfo, *spinfo = NULL;
Sachin Bhayareeeb88892018-01-02 16:36:01 +05302040 int rc = 0;
2041
2042 if (pdata == NULL) {
2043 pr_err("%s Invalid pdata\n", __func__);
2044 return -EINVAL;
2045 }
2046
2047 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
2048 panel_data);
2049 if (IS_ERR_OR_NULL(ctrl_pdata)) {
2050 pr_err("Invalid sctrl_pdata = %lu\n", PTR_ERR(ctrl_pdata));
2051 return PTR_ERR(ctrl_pdata);
2052 }
2053
2054 pinfo = &ctrl_pdata->panel_data.panel_info;
2055
2056 /*
2057 * In split display case, configure and enable dynamic refresh
2058 * register only after both the ctrl data is programmed. So,
2059 * ignore enabling dynamic refresh for the master control and
2060 * configure only when it is slave control.
2061 */
2062 if (mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) &&
2063 mdss_dsi_is_ctrl_clk_master(ctrl_pdata))
2064 return 0;
2065
2066 if (mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) &&
2067 mdss_dsi_is_ctrl_clk_slave(ctrl_pdata)) {
2068 sctrl_pdata = ctrl_pdata;
2069 spinfo = pinfo;
2070 ctrl_pdata = mdss_dsi_get_ctrl_clk_master();
2071 if (IS_ERR_OR_NULL(ctrl_pdata)) {
2072 pr_err("Invalid ctrl_pdata = %lu\n",
2073 PTR_ERR(ctrl_pdata));
2074 return PTR_ERR(ctrl_pdata);
2075 }
2076
2077 pinfo = &ctrl_pdata->panel_data.panel_info;
2078 }
2079
2080 /*
2081 * For programming dynamic refresh registers, we need to change
2082 * the parent to shadow clocks for the software byte and pixel mux.
2083 * After switching to shadow clocks, if there is no ref count on
2084 * main byte and pixel clocks, clock driver may shutdown those
2085 * unreferenced byte and pixel clocks. Hence add an extra reference
2086 * count to avoid shutting down the main byte and pixel clocks.
2087 */
2088 rc = clk_prepare_enable(ctrl_pdata->pll_byte_clk);
2089 if (rc) {
2090 pr_err("Unable to add extra refcnt for byte clock\n");
2091 goto error_byte;
2092 }
2093
2094 rc = clk_prepare_enable(ctrl_pdata->pll_pixel_clk);
2095 if (rc) {
2096 pr_err("Unable to add extra refcnt for pixel clock\n");
2097 goto error_pixel;
2098 }
2099
2100 /* change the parent to shadow clocks*/
2101 rc = clk_set_parent(ctrl_pdata->mux_byte_clk,
2102 ctrl_pdata->shadow_byte_clk);
2103 if (rc) {
2104 pr_err("Unable to set parent to shadow byte clock\n");
2105 goto error_shadow_byte;
2106 }
2107
2108 rc = clk_set_parent(ctrl_pdata->mux_pixel_clk,
2109 ctrl_pdata->shadow_pixel_clk);
2110 if (rc) {
2111 pr_err("Unable to set parent to shadow pixel clock\n");
2112 goto error_shadow_pixel;
2113 }
2114
2115 rc = mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle,
2116 MDSS_DSI_LINK_BYTE_CLK, ctrl_pdata->byte_clk_rate, 0);
2117 if (rc) {
2118 pr_err("%s: dsi_byte_clk - clk_set_rate failed\n",
2119 __func__);
2120 goto error_byte_link;
2121 }
2122
2123 rc = mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle,
2124 MDSS_DSI_LINK_PIX_CLK, ctrl_pdata->pclk_rate, 0);
2125 if (rc) {
2126 pr_err("%s: dsi_pixel_clk - clk_set_rate failed\n",
2127 __func__);
2128 goto error_pixel_link;
2129 }
2130
2131 if (sctrl_pdata) {
2132 rc = mdss_dsi_clk_set_link_rate(sctrl_pdata->dsi_clk_handle,
2133 MDSS_DSI_LINK_BYTE_CLK, sctrl_pdata->byte_clk_rate, 0);
2134 if (rc) {
2135 pr_err("%s: slv dsi_byte_clk - clk_set_rate failed\n",
2136 __func__);
2137 goto error_sbyte_link;
2138 }
2139
2140 rc = mdss_dsi_clk_set_link_rate(sctrl_pdata->dsi_clk_handle,
2141 MDSS_DSI_LINK_PIX_CLK, sctrl_pdata->pclk_rate, 0);
2142 if (rc) {
2143 pr_err("%s: slv dsi_pixel_clk - clk_set_rate failed\n",
2144 __func__);
2145 goto error_spixel_link;
2146 }
2147 }
2148
2149 rc = mdss_dsi_en_wait4dynamic_done(ctrl_pdata);
2150 if (rc < 0) {
2151 pr_err("Unsuccessful dynamic fps change");
2152 goto dfps_timeout;
2153 }
2154
2155 MIPI_OUTP((ctrl_pdata->ctrl_base) + DSI_DYNAMIC_REFRESH_CTRL, 0x00);
2156 if (sctrl_pdata)
2157 MIPI_OUTP((sctrl_pdata->ctrl_base) + DSI_DYNAMIC_REFRESH_CTRL,
2158 0x00);
2159
2160 rc = mdss_dsi_phy_pll_reset_status(ctrl_pdata);
2161 if (rc) {
2162 pr_err("%s: pll cannot be locked reset core ready failed %d\n",
2163 __func__, rc);
2164 goto dfps_timeout;
2165 }
2166
2167 __mdss_dsi_mask_dfps_errors(ctrl_pdata, false);
2168 if (sctrl_pdata)
2169 __mdss_dsi_mask_dfps_errors(sctrl_pdata, false);
2170
2171 /* Move the mux clocks to main byte and pixel clocks */
2172 rc = clk_set_parent(ctrl_pdata->mux_byte_clk,
2173 ctrl_pdata->pll_byte_clk);
2174 if (rc)
2175 pr_err("Unable to set parent back to main byte clock\n");
2176
2177 rc = clk_set_parent(ctrl_pdata->mux_pixel_clk,
2178 ctrl_pdata->pll_pixel_clk);
2179 if (rc)
2180 pr_err("Unable to set parent back to main pixel clock\n");
2181
2182 /* Remove extra ref count on parent clocks */
2183 clk_disable_unprepare(ctrl_pdata->pll_byte_clk);
2184 clk_disable_unprepare(ctrl_pdata->pll_pixel_clk);
2185
2186 /* update new fps that at this point is already updated in hw */
2187 pinfo->current_fps = new_fps;
2188 if (sctrl_pdata)
2189 spinfo->current_fps = new_fps;
2190
2191 return rc;
2192
2193dfps_timeout:
2194 if (sctrl_pdata)
2195 mdss_dsi_clk_set_link_rate(sctrl_pdata->dsi_clk_handle,
2196 MDSS_DSI_LINK_PIX_CLK,
2197 sctrl_pdata->pclk_rate_bkp, 0);
2198error_spixel_link:
2199 if (sctrl_pdata)
2200 mdss_dsi_clk_set_link_rate(sctrl_pdata->dsi_clk_handle,
2201 MDSS_DSI_LINK_BYTE_CLK,
2202 sctrl_pdata->byte_clk_rate_bkp, 0);
2203error_sbyte_link:
2204 mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle,
2205 MDSS_DSI_LINK_PIX_CLK, ctrl_pdata->pclk_rate_bkp, 0);
2206error_pixel_link:
2207 mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle,
2208 MDSS_DSI_LINK_BYTE_CLK, ctrl_pdata->byte_clk_rate_bkp, 0);
2209error_byte_link:
2210 clk_set_parent(ctrl_pdata->mux_pixel_clk, ctrl_pdata->pll_pixel_clk);
2211error_shadow_pixel:
2212 clk_set_parent(ctrl_pdata->mux_byte_clk, ctrl_pdata->pll_byte_clk);
2213error_shadow_byte:
2214 clk_disable_unprepare(ctrl_pdata->pll_pixel_clk);
2215error_pixel:
2216 clk_disable_unprepare(ctrl_pdata->pll_byte_clk);
2217error_byte:
2218 return rc;
2219}
2220
2221static int mdss_dsi_check_params(struct mdss_dsi_ctrl_pdata *ctrl, void *arg)
2222{
2223 struct mdss_panel_info *var_pinfo, *pinfo;
2224 int rc = 0;
2225
2226 if (!ctrl || !arg)
2227 return 0;
2228
2229 pinfo = &ctrl->panel_data.panel_info;
2230 if (!pinfo->is_pluggable)
2231 return 0;
2232
2233 var_pinfo = (struct mdss_panel_info *)arg;
2234
2235 pr_debug("%s: reconfig xres: %d yres: %d, current xres: %d yres: %d\n",
2236 __func__, var_pinfo->xres, var_pinfo->yres,
2237 pinfo->xres, pinfo->yres);
2238 if ((var_pinfo->xres != pinfo->xres) ||
2239 (var_pinfo->yres != pinfo->yres) ||
2240 (var_pinfo->lcdc.h_back_porch != pinfo->lcdc.h_back_porch) ||
2241 (var_pinfo->lcdc.h_front_porch != pinfo->lcdc.h_front_porch) ||
2242 (var_pinfo->lcdc.h_pulse_width != pinfo->lcdc.h_pulse_width) ||
2243 (var_pinfo->lcdc.v_back_porch != pinfo->lcdc.v_back_porch) ||
2244 (var_pinfo->lcdc.v_front_porch != pinfo->lcdc.v_front_porch) ||
2245 (var_pinfo->lcdc.v_pulse_width != pinfo->lcdc.v_pulse_width)
2246 )
2247 rc = 1;
2248
2249 return rc;
2250}
2251
2252#ifdef TARGET_HW_MDSS_HDMI
2253static void mdss_dsi_update_params(struct mdss_dsi_ctrl_pdata *ctrl, void *arg)
2254{
2255 struct mdss_panel_info *pinfo;
2256
2257 if (!ctrl || !arg)
2258 return;
2259
2260 pinfo = &ctrl->panel_data.panel_info;
2261 mdss_dba_update_lane_cfg(pinfo);
2262}
2263#else
2264static void mdss_dsi_update_params(struct mdss_dsi_ctrl_pdata *ctrl, void *arg)
2265{
2266}
2267#endif
2268
2269static int mdss_dsi_dfps_config(struct mdss_panel_data *pdata, int new_fps)
2270{
2271 int rc = 0;
2272 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
2273 struct mdss_panel_info *pinfo;
2274 u32 phy_rev;
2275 u32 frame_rate_bkp;
2276
2277 pr_debug("%s+:\n", __func__);
2278
2279 if (pdata == NULL) {
2280 pr_err("%s: Invalid input data\n", __func__);
2281 return -EINVAL;
2282 }
2283
2284 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
2285 panel_data);
2286
2287 if (!ctrl_pdata->panel_data.panel_info.dynamic_fps) {
2288 pr_err("Dynamic fps not enabled for this panel\n");
2289 return -EINVAL;
2290 }
2291
2292 phy_rev = ctrl_pdata->shared_data->phy_rev;
2293 pinfo = &pdata->panel_info;
2294
2295 /* get the fps configured in HW */
2296 frame_rate_bkp = pinfo->current_fps;
2297
2298 if (new_fps == pinfo->current_fps) {
2299 /*
2300 * This is unlikely as mdss driver checks for previously
2301 * configured frame rate.
2302 */
2303 pr_debug("Panel is already at this FPS\n");
2304 goto end_update;
2305 }
2306
2307 if (pinfo->dfps_update == DFPS_IMMEDIATE_PORCH_UPDATE_MODE_HFP ||
2308 pinfo->dfps_update == DFPS_IMMEDIATE_PORCH_UPDATE_MODE_VFP) {
2309 /* Porch method */
2310 __mdss_dsi_update_video_mode_total(pdata, new_fps);
2311 } else if (pinfo->dfps_update == DFPS_IMMEDIATE_CLK_UPDATE_MODE) {
2312 /* Clock update method */
2313
2314 __mdss_dsi_mask_dfps_errors(ctrl_pdata, true);
2315
2316 if (phy_rev == DSI_PHY_REV_20) {
2317 rc = mdss_dsi_phy_calc_timing_param(pinfo, phy_rev,
2318 new_fps);
2319 if (rc) {
2320 pr_err("PHY calculations failed-%d\n", new_fps);
2321 goto end_update;
2322 }
2323 }
2324
2325 rc = __mdss_dsi_dfps_calc_clks(pdata, new_fps);
2326 if (rc) {
2327 pr_err("error calculating clocks for %d\n", new_fps);
2328 goto error_clks;
2329 }
2330
2331 rc = __mdss_dsi_dfps_update_clks(pdata, new_fps);
2332 if (rc) {
2333 pr_err("Dynamic refresh failed-%d\n", new_fps);
2334 goto error_dfps;
2335 }
2336 }
2337
2338 return rc;
2339error_dfps:
2340 if (__mdss_dsi_dfps_calc_clks(pdata, frame_rate_bkp))
2341 pr_err("error reverting clock calculations for %d\n",
2342 frame_rate_bkp);
2343error_clks:
2344 if (mdss_dsi_phy_calc_timing_param(pinfo, phy_rev, frame_rate_bkp))
2345 pr_err("Unable to revert phy timing-%d\n", frame_rate_bkp);
2346end_update:
2347 return rc;
2348}
2349
2350static int mdss_dsi_ctl_partial_roi(struct mdss_panel_data *pdata)
2351{
2352 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
2353 int rc = -EINVAL;
2354
2355 if (pdata == NULL) {
2356 pr_err("%s: Invalid input data\n", __func__);
2357 return -EINVAL;
2358 }
2359
2360 if (!pdata->panel_info.partial_update_enabled)
2361 return 0;
2362
2363 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
2364 panel_data);
2365
2366 if (ctrl_pdata->set_col_page_addr)
2367 rc = ctrl_pdata->set_col_page_addr(pdata, false);
2368
2369 return rc;
2370}
2371
2372static int mdss_dsi_set_stream_size(struct mdss_panel_data *pdata)
2373{
2374 u32 stream_ctrl, stream_total, idle;
2375 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
2376 struct mdss_panel_info *pinfo;
2377 struct dsc_desc *dsc = NULL;
2378 struct mdss_rect *roi;
2379 struct panel_horizontal_idle *pidle;
2380 int i;
2381
2382 if (pdata == NULL) {
2383 pr_err("%s: Invalid input data\n", __func__);
2384 return -EINVAL;
2385 }
2386
2387 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
2388 panel_data);
2389
2390 pinfo = &pdata->panel_info;
2391
2392 if (!pinfo->partial_update_supported)
2393 return -EINVAL;
2394
2395 if (pinfo->compression_mode == COMPRESSION_DSC)
2396 dsc = &pinfo->dsc;
2397
2398 roi = &pinfo->roi;
2399
2400 /* DSI_COMMAND_MODE_MDP_STREAM_CTRL */
2401 if (dsc) {
2402 u16 byte_num = dsc->bytes_per_pkt;
2403
2404 if (pinfo->mipi.insert_dcs_cmd)
2405 byte_num++;
2406
2407 stream_ctrl = (byte_num << 16) | (pinfo->mipi.vc << 8) |
2408 DTYPE_DCS_LWRITE;
2409 stream_total = dsc->pic_height << 16 | dsc->pclk_per_line;
2410 } else {
2411
2412 stream_ctrl = (((roi->w * 3) + 1) << 16) |
2413 (pdata->panel_info.mipi.vc << 8) | DTYPE_DCS_LWRITE;
2414 stream_total = roi->h << 16 | roi->w;
2415 }
2416 MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x60, stream_ctrl);
2417 MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x58, stream_ctrl);
2418
2419 /* DSI_COMMAND_MODE_MDP_STREAM_TOTAL */
2420 MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x64, stream_total);
2421 MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x5C, stream_total);
2422
2423 /* set idle control -- dsi clk cycle */
2424 idle = 0;
2425 pidle = ctrl_pdata->line_idle;
2426 for (i = 0; i < ctrl_pdata->horizontal_idle_cnt; i++) {
2427 if (roi->w > pidle->min && roi->w <= pidle->max) {
2428 idle = pidle->idle;
2429 pr_debug("%s: ndx=%d w=%d range=%d-%d idle=%d\n",
2430 __func__, ctrl_pdata->ndx, roi->w,
2431 pidle->min, pidle->max, pidle->idle);
2432 break;
2433 }
2434 pidle++;
2435 }
2436
2437 if (idle)
2438 idle |= BIT(12); /* enable */
2439
2440 MIPI_OUTP((ctrl_pdata->ctrl_base) + 0x194, idle);
2441
2442 if (dsc)
2443 mdss_dsi_dsc_config(ctrl_pdata, dsc);
2444
2445 return 0;
2446}
2447
2448#ifdef TARGET_HW_MDSS_HDMI
2449static void mdss_dsi_dba_work(struct work_struct *work)
2450{
2451 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
2452 struct delayed_work *dw = to_delayed_work(work);
2453 struct mdss_dba_utils_init_data utils_init_data;
2454 struct mdss_panel_info *pinfo;
2455
2456 ctrl_pdata = container_of(dw, struct mdss_dsi_ctrl_pdata, dba_work);
2457 if (!ctrl_pdata) {
2458 pr_err("%s: invalid ctrl data\n", __func__);
2459 return;
2460 }
2461
2462 pinfo = &ctrl_pdata->panel_data.panel_info;
2463 if (!pinfo) {
2464 pr_err("%s: invalid ctrl data\n", __func__);
2465 return;
2466 }
2467
2468 memset(&utils_init_data, 0, sizeof(utils_init_data));
2469
2470 utils_init_data.chip_name = ctrl_pdata->bridge_name;
2471 utils_init_data.client_name = "dsi";
2472 utils_init_data.instance_id = ctrl_pdata->bridge_index;
2473 utils_init_data.fb_node = ctrl_pdata->fb_node;
2474 utils_init_data.kobj = ctrl_pdata->kobj;
2475 utils_init_data.pinfo = pinfo;
2476 if (ctrl_pdata->mdss_util)
2477 utils_init_data.cont_splash_enabled =
2478 ctrl_pdata->mdss_util->panel_intf_status(
2479 ctrl_pdata->panel_data.panel_info.pdest,
2480 MDSS_PANEL_INTF_DSI) ? true : false;
2481 else
2482 utils_init_data.cont_splash_enabled = false;
2483
2484 pinfo->dba_data = mdss_dba_utils_init(&utils_init_data);
2485
2486 if (!IS_ERR_OR_NULL(pinfo->dba_data)) {
2487 ctrl_pdata->ds_registered = true;
2488 } else {
2489 pr_debug("%s: dba device not ready, queue again\n", __func__);
2490 queue_delayed_work(ctrl_pdata->workq,
2491 &ctrl_pdata->dba_work, HZ);
2492 }
2493}
2494#else
2495static void mdss_dsi_dba_work(struct work_struct *work)
2496{
2497 (void)(*work);
2498}
2499#endif
2500static int mdss_dsi_reset_write_ptr(struct mdss_panel_data *pdata)
2501{
2502
2503 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
2504 struct mdss_panel_info *pinfo;
2505 int rc = 0;
2506
2507 if (pdata == NULL) {
2508 pr_err("%s: Invalid input data\n", __func__);
2509 return -EINVAL;
2510 }
2511
2512 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
2513 panel_data);
2514
2515 pinfo = &ctrl_pdata->panel_data.panel_info;
2516 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
2517 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON);
2518 /* Need to reset the DSI core since the pixel stream was stopped. */
2519 mdss_dsi_sw_reset(ctrl_pdata, true);
2520
2521 /*
2522 * Reset the partial update co-ordinates to the panel height and
2523 * width
2524 */
2525 if (pinfo->dcs_cmd_by_left && (ctrl_pdata->ndx == 1))
2526 goto skip_cmd_send;
2527
2528 pinfo->roi.x = 0;
2529 pinfo->roi.y = 0;
2530 pinfo->roi.w = pinfo->xres;
2531 if (pinfo->dcs_cmd_by_left)
2532 pinfo->roi.w = pinfo->xres;
2533 if (pdata->next)
2534 pinfo->roi.w += pdata->next->panel_info.xres;
2535 pinfo->roi.h = pinfo->yres;
2536
2537 mdss_dsi_set_stream_size(pdata);
2538
2539 if (ctrl_pdata->set_col_page_addr)
2540 rc = ctrl_pdata->set_col_page_addr(pdata, true);
2541
2542skip_cmd_send:
2543 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
2544 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_OFF);
2545
2546 pr_debug("%s: DSI%d write ptr reset finished\n", __func__,
2547 ctrl_pdata->ndx);
2548
2549 return rc;
2550}
2551
2552int mdss_dsi_register_recovery_handler(struct mdss_dsi_ctrl_pdata *ctrl,
2553 struct mdss_intf_recovery *recovery)
2554{
2555 mutex_lock(&ctrl->mutex);
2556 ctrl->recovery = recovery;
2557 mutex_unlock(&ctrl->mutex);
2558 return 0;
2559}
2560
2561static int mdss_dsi_register_mdp_callback(struct mdss_dsi_ctrl_pdata *ctrl,
2562 struct mdss_intf_recovery *mdp_callback)
2563{
2564 mutex_lock(&ctrl->mutex);
2565 ctrl->mdp_callback = mdp_callback;
2566 mutex_unlock(&ctrl->mutex);
2567 return 0;
2568}
2569
2570static struct device_node *mdss_dsi_get_fb_node_cb(struct platform_device *pdev)
2571{
2572 struct device_node *fb_node;
2573 struct platform_device *dsi_dev;
2574 struct mdss_dsi_ctrl_pdata *ctrl_pdata;
2575
2576 if (pdev == NULL) {
2577 pr_err("%s: Invalid input data\n", __func__);
2578 return NULL;
2579 }
2580
2581 ctrl_pdata = platform_get_drvdata(pdev);
2582 dsi_dev = of_find_device_by_node(pdev->dev.of_node->parent);
2583 if (!dsi_dev) {
2584 pr_err("Unable to find dsi master device: %s\n",
2585 pdev->dev.of_node->full_name);
2586 return NULL;
2587 }
2588
2589 fb_node = of_parse_phandle(dsi_dev->dev.of_node,
2590 mdss_dsi_get_fb_name(ctrl_pdata), 0);
2591 if (!fb_node) {
2592 pr_err("Unable to find fb node for device: %s\n", pdev->name);
2593 return NULL;
2594 }
2595
2596 return fb_node;
2597}
2598
2599static int mdss_dsi_event_handler(struct mdss_panel_data *pdata,
2600 int event, void *arg)
2601{
2602 int rc = 0;
2603 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
2604 struct fb_info *fbi;
2605 int power_state;
2606 u32 mode;
2607 struct mdss_panel_info *pinfo;
2608
2609 if (pdata == NULL) {
2610 pr_err("%s: Invalid input data\n", __func__);
2611 return -EINVAL;
2612 }
2613 pinfo = &pdata->panel_info;
2614 ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
2615 panel_data);
2616 pr_debug("%s+: ctrl=%d event=%d\n", __func__, ctrl_pdata->ndx, event);
2617
2618 MDSS_XLOG(event, arg, ctrl_pdata->ndx, 0x3333);
2619
2620 switch (event) {
2621 case MDSS_EVENT_UPDATE_PARAMS:
2622 pr_debug("%s:Entered Case MDSS_EVENT_UPDATE_PARAMS\n",
2623 __func__);
2624 mdss_dsi_update_params(ctrl_pdata, arg);
2625 break;
2626 case MDSS_EVENT_CHECK_PARAMS:
2627 pr_debug("%s:Entered Case MDSS_EVENT_CHECK_PARAMS\n", __func__);
2628 if (mdss_dsi_check_params(ctrl_pdata, arg)) {
2629 ctrl_pdata->update_phy_timing = true;
2630 /*
2631 * Call to MDSS_EVENT_CHECK_PARAMS expects
2632 * the return value of 1, if there is a change
2633 * in panel timing parameters.
2634 */
2635 rc = 1;
2636 }
2637 ctrl_pdata->refresh_clk_rate = true;
2638 break;
2639 case MDSS_EVENT_LINK_READY:
2640 if (ctrl_pdata->refresh_clk_rate)
2641 rc = mdss_dsi_clk_refresh(pdata,
2642 ctrl_pdata->update_phy_timing);
2643
2644 rc = mdss_dsi_on(pdata);
2645 mdss_dsi_op_mode_config(pdata->panel_info.mipi.mode,
2646 pdata);
2647 break;
2648 case MDSS_EVENT_UNBLANK:
2649 if (ctrl_pdata->on_cmds.link_state == DSI_LP_MODE)
2650 rc = mdss_dsi_unblank(pdata);
2651 break;
2652 case MDSS_EVENT_POST_PANEL_ON:
2653 rc = mdss_dsi_post_panel_on(pdata);
2654 break;
2655 case MDSS_EVENT_PANEL_ON:
2656 ctrl_pdata->ctrl_state |= CTRL_STATE_MDP_ACTIVE;
2657 if (ctrl_pdata->on_cmds.link_state == DSI_HS_MODE)
2658 rc = mdss_dsi_unblank(pdata);
2659 pdata->panel_info.esd_rdy = true;
2660 break;
2661 case MDSS_EVENT_BLANK:
2662 power_state = (int) (unsigned long) arg;
2663 if (ctrl_pdata->off_cmds.link_state == DSI_HS_MODE)
2664 rc = mdss_dsi_blank(pdata, power_state);
2665 break;
2666 case MDSS_EVENT_PANEL_OFF:
2667 power_state = (int) (unsigned long) arg;
2668 disable_esd_thread();
2669 ctrl_pdata->ctrl_state &= ~CTRL_STATE_MDP_ACTIVE;
2670 if (ctrl_pdata->off_cmds.link_state == DSI_LP_MODE)
2671 rc = mdss_dsi_blank(pdata, power_state);
2672 rc = mdss_dsi_off(pdata, power_state);
2673 break;
2674 case MDSS_EVENT_CONT_SPLASH_FINISH:
2675 if (ctrl_pdata->off_cmds.link_state == DSI_LP_MODE)
2676 rc = mdss_dsi_blank(pdata, MDSS_PANEL_POWER_OFF);
2677 ctrl_pdata->ctrl_state &= ~CTRL_STATE_MDP_ACTIVE;
2678 rc = mdss_dsi_cont_splash_on(pdata);
2679 break;
2680 case MDSS_EVENT_PANEL_CLK_CTRL:
2681 mdss_dsi_clk_req(ctrl_pdata,
2682 (struct dsi_panel_clk_ctrl *) arg);
2683 break;
2684 case MDSS_EVENT_DSI_CMDLIST_KOFF:
2685 mdss_dsi_cmdlist_commit(ctrl_pdata, 1);
2686 break;
2687 case MDSS_EVENT_PANEL_UPDATE_FPS:
2688 if (arg != NULL) {
2689 rc = mdss_dsi_dfps_config(pdata,
2690 (int) (unsigned long) arg);
2691 if (rc)
2692 pr_err("unable to change fps-%d, error-%d\n",
2693 (int) (unsigned long) arg, rc);
2694 else
2695 pr_debug("panel frame rate changed to %d\n",
2696 (int) (unsigned long) arg);
2697 }
2698 break;
2699 case MDSS_EVENT_CONT_SPLASH_BEGIN:
2700 if (ctrl_pdata->off_cmds.link_state == DSI_HS_MODE) {
2701 /* Panel is Enabled in Bootloader */
2702 rc = mdss_dsi_blank(pdata, MDSS_PANEL_POWER_OFF);
2703 }
2704 break;
2705 case MDSS_EVENT_DSC_PPS_SEND:
2706 if (pinfo->compression_mode == COMPRESSION_DSC)
2707 mdss_dsi_panel_dsc_pps_send(ctrl_pdata, pinfo);
2708 break;
2709 case MDSS_EVENT_ENABLE_PARTIAL_ROI:
2710 rc = mdss_dsi_ctl_partial_roi(pdata);
2711 break;
2712 case MDSS_EVENT_DSI_RESET_WRITE_PTR:
2713 rc = mdss_dsi_reset_write_ptr(pdata);
2714 break;
2715 case MDSS_EVENT_DSI_STREAM_SIZE:
2716 rc = mdss_dsi_set_stream_size(pdata);
2717 break;
2718 case MDSS_EVENT_DSI_UPDATE_PANEL_DATA:
2719 rc = mdss_dsi_update_panel_config(ctrl_pdata,
2720 (int)(unsigned long) arg);
2721 break;
2722 case MDSS_EVENT_REGISTER_RECOVERY_HANDLER:
2723 rc = mdss_dsi_register_recovery_handler(ctrl_pdata,
2724 (struct mdss_intf_recovery *)arg);
2725 break;
2726 case MDSS_EVENT_REGISTER_MDP_CALLBACK:
2727 rc = mdss_dsi_register_mdp_callback(ctrl_pdata,
2728 (struct mdss_intf_recovery *)arg);
2729 break;
2730 case MDSS_EVENT_DSI_DYNAMIC_SWITCH:
2731 mode = (u32)(unsigned long) arg;
2732 mdss_dsi_switch_mode(pdata, mode);
2733 break;
2734 case MDSS_EVENT_DSI_RECONFIG_CMD:
2735 mode = (u32)(unsigned long) arg;
2736 rc = mdss_dsi_reconfig(pdata, mode);
2737 break;
2738 case MDSS_EVENT_DSI_PANEL_STATUS:
2739 if (ctrl_pdata->check_status)
2740 rc = ctrl_pdata->check_status(ctrl_pdata);
2741 else
2742 rc = true;
2743 break;
2744 case MDSS_EVENT_PANEL_TIMING_SWITCH:
2745 rc = mdss_dsi_panel_timing_switch(ctrl_pdata, arg);
2746 break;
2747 case MDSS_EVENT_FB_REGISTERED:
2748 mdss_dsi_debugfs_init(ctrl_pdata);
2749
2750 fbi = (struct fb_info *)arg;
2751 if (!fbi || !fbi->dev)
2752 break;
2753
2754 ctrl_pdata->kobj = &fbi->dev->kobj;
2755 ctrl_pdata->fb_node = fbi->node;
2756
2757 if (IS_ENABLED(CONFIG_MSM_DBA) &&
2758 pdata->panel_info.is_dba_panel) {
2759 queue_delayed_work(ctrl_pdata->workq,
2760 &ctrl_pdata->dba_work, HZ);
2761 }
2762 break;
2763 default:
2764 pr_debug("%s: unhandled event=%d\n", __func__, event);
2765 break;
2766 }
2767 pr_debug("%s-:event=%d, rc=%d\n", __func__, event, rc);
2768 return rc;
2769}
2770
2771static int mdss_dsi_set_override_cfg(char *override_cfg,
2772 struct mdss_dsi_ctrl_pdata *ctrl_pdata, char *panel_cfg)
2773{
2774 struct mdss_panel_info *pinfo = &ctrl_pdata->panel_data.panel_info;
2775 char *token = NULL;
2776
2777 pr_debug("%s: override config:%s\n", __func__, override_cfg);
2778 while ((token = strsep(&override_cfg, ":"))) {
2779 if (!strcmp(token, OVERRIDE_CFG)) {
2780 continue;
2781 } else if (!strcmp(token, SIM_HW_TE_PANEL)) {
2782 pinfo->sim_panel_mode = SIM_HW_TE_MODE;
2783 } else if (!strcmp(token, SIM_SW_TE_PANEL)) {
2784 pinfo->sim_panel_mode = SIM_SW_TE_MODE;
2785 } else if (!strcmp(token, SIM_PANEL)) {
2786 pinfo->sim_panel_mode = SIM_MODE;
2787 } else {
2788 pr_err("%s: invalid override_cfg token: %s\n",
2789 __func__, token);
2790 return -EINVAL;
2791 }
2792 }
2793 pr_debug("%s:sim_panel_mode:%d\n", __func__, pinfo->sim_panel_mode);
2794
2795 return 0;
2796}
2797
2798static struct device_node *mdss_dsi_pref_prim_panel(
2799 struct platform_device *pdev)
2800{
2801 struct device_node *dsi_pan_node = NULL;
2802
2803 pr_debug("%s:%d: Select primary panel from dt\n",
2804 __func__, __LINE__);
2805 dsi_pan_node = of_parse_phandle(pdev->dev.of_node,
2806 "qcom,dsi-pref-prim-pan", 0);
2807 if (!dsi_pan_node)
2808 pr_err("%s:can't find panel phandle\n", __func__);
2809
2810 return dsi_pan_node;
2811}
2812
2813/**
2814 * mdss_dsi_find_panel_of_node(): find device node of dsi panel
2815 * @pdev: platform_device of the dsi ctrl node
2816 * @panel_cfg: string containing intf specific config data
2817 *
2818 * Function finds the panel device node using the interface
2819 * specific configuration data. This configuration data is
2820 * could be derived from the result of bootloader's GCDB
2821 * panel detection mechanism. If such config data doesn't
2822 * exist then this panel returns the default panel configured
2823 * in the device tree.
2824 *
2825 * returns pointer to panel node on success, NULL on error.
2826 */
2827static struct device_node *mdss_dsi_find_panel_of_node(
2828 struct platform_device *pdev, char *panel_cfg)
2829{
2830 int len, i = 0;
2831 int ctrl_id = pdev->id - 1;
2832 char panel_name[MDSS_MAX_PANEL_LEN] = "";
2833 char ctrl_id_stream[3] = "0:";
2834 char *str1 = NULL, *str2 = NULL, *override_cfg = NULL;
2835 char cfg_np_name[MDSS_MAX_PANEL_LEN] = "";
2836 struct device_node *dsi_pan_node = NULL, *mdss_node = NULL;
2837 struct mdss_dsi_ctrl_pdata *ctrl_pdata = platform_get_drvdata(pdev);
2838 struct mdss_panel_info *pinfo = &ctrl_pdata->panel_data.panel_info;
2839
2840 len = strlen(panel_cfg);
2841 ctrl_pdata->panel_data.dsc_cfg_np_name[0] = '\0';
2842 if (!len) {
2843 /* no panel cfg chg, parse dt */
2844 pr_debug("%s:%d: no cmd line cfg present\n",
2845 __func__, __LINE__);
2846 goto end;
2847 } else {
2848 /* check if any override parameters are set */
2849 pinfo->sim_panel_mode = 0;
2850 override_cfg = strnstr(panel_cfg, "#" OVERRIDE_CFG, len);
2851 if (override_cfg) {
2852 *override_cfg = '\0';
2853 if (mdss_dsi_set_override_cfg(override_cfg + 1,
2854 ctrl_pdata, panel_cfg))
2855 return NULL;
2856 len = strlen(panel_cfg);
2857 }
2858
2859 if (ctrl_id == 1)
2860 strlcpy(ctrl_id_stream, "1:", 3);
2861
2862 /* get controller number */
2863 str1 = strnstr(panel_cfg, ctrl_id_stream, len);
2864 if (!str1) {
2865 pr_err("%s: controller %s is not present in %s\n",
2866 __func__, ctrl_id_stream, panel_cfg);
2867 goto end;
2868 }
2869 if ((str1 != panel_cfg) && (*(str1-1) != ':')) {
2870 str1 += CMDLINE_DSI_CTL_NUM_STRING_LEN;
2871 pr_debug("false match with config node name in \"%s\". search again in \"%s\"\n",
2872 panel_cfg, str1);
2873 str1 = strnstr(str1, ctrl_id_stream, len);
2874 if (!str1) {
2875 pr_err("%s: 2. controller %s is not present in %s\n",
2876 __func__, ctrl_id_stream, str1);
2877 goto end;
2878 }
2879 }
2880 str1 += CMDLINE_DSI_CTL_NUM_STRING_LEN;
2881
2882 /* get panel name */
2883 str2 = strnchr(str1, strlen(str1), ':');
2884 if (!str2) {
2885 strlcpy(panel_name, str1, MDSS_MAX_PANEL_LEN);
2886 } else {
2887 for (i = 0; (str1 + i) < str2; i++)
2888 panel_name[i] = *(str1 + i);
2889 panel_name[i] = 0;
2890 }
2891 pr_info("%s: cmdline:%s panel_name:%s\n",
2892 __func__, panel_cfg, panel_name);
2893 if (!strcmp(panel_name, NONE_PANEL))
2894 goto exit;
2895
2896 mdss_node = of_parse_phandle(pdev->dev.of_node,
2897 "qcom,mdss-mdp", 0);
2898 if (!mdss_node) {
2899 pr_err("%s: %d: mdss_node null\n",
2900 __func__, __LINE__);
2901 return NULL;
2902 }
2903 dsi_pan_node = of_find_node_by_name(mdss_node, panel_name);
2904 if (!dsi_pan_node) {
2905 pr_err("%s: invalid pan node \"%s\"\n",
2906 __func__, panel_name);
2907 goto end;
2908 } else {
2909 /* extract config node name if present */
2910 str1 += i;
2911 str2 = strnstr(str1, "config", strlen(str1));
2912 if (str2) {
2913 str1 = strnchr(str2, strlen(str2), ':');
2914 if (str1) {
2915 for (i = 0; ((str2 + i) < str1) &&
2916 i < (MDSS_MAX_PANEL_LEN - 1); i++)
2917 cfg_np_name[i] = *(str2 + i);
2918 if ((i >= 0)
2919 && (i < MDSS_MAX_PANEL_LEN))
2920 cfg_np_name[i] = 0;
2921 } else {
2922 strlcpy(cfg_np_name, str2,
2923 MDSS_MAX_PANEL_LEN);
2924 }
2925 strlcpy(ctrl_pdata->panel_data.dsc_cfg_np_name,
2926 cfg_np_name, MDSS_MAX_PANEL_LEN);
2927 }
2928 }
2929
2930 return dsi_pan_node;
2931 }
2932end:
2933 if (strcmp(panel_name, NONE_PANEL))
2934 dsi_pan_node = mdss_dsi_pref_prim_panel(pdev);
2935exit:
2936 return dsi_pan_node;
2937}
2938
2939static struct device_node *mdss_dsi_config_panel(struct platform_device *pdev,
2940 int ndx)
2941{
2942 struct mdss_dsi_ctrl_pdata *ctrl_pdata = platform_get_drvdata(pdev);
2943 char panel_cfg[MDSS_MAX_PANEL_LEN];
2944 struct device_node *dsi_pan_node = NULL;
2945 int rc = 0;
2946
2947 if (!ctrl_pdata) {
2948 pr_err("%s: Unable to get the ctrl_pdata\n", __func__);
2949 return NULL;
2950 }
2951
2952 /* DSI panels can be different between controllers */
2953 rc = mdss_dsi_get_panel_cfg(panel_cfg, ctrl_pdata);
2954 if (!rc)
2955 /* dsi panel cfg not present */
2956 pr_warn("%s:%d:dsi specific cfg not present\n",
2957 __func__, __LINE__);
2958
2959 /* find panel device node */
2960 dsi_pan_node = mdss_dsi_find_panel_of_node(pdev, panel_cfg);
2961 if (!dsi_pan_node) {
2962 pr_err("%s: can't find panel node %s\n", __func__, panel_cfg);
2963 of_node_put(dsi_pan_node);
2964 return NULL;
2965 }
2966
2967 rc = mdss_dsi_panel_init(dsi_pan_node, ctrl_pdata, ndx);
2968 if (rc) {
2969 pr_err("%s: dsi panel init failed\n", __func__);
2970 of_node_put(dsi_pan_node);
2971 return NULL;
2972 }
2973
2974 return dsi_pan_node;
2975}
2976
2977static int mdss_dsi_ctrl_clock_init(struct platform_device *ctrl_pdev,
2978 struct mdss_dsi_ctrl_pdata *ctrl_pdata)
2979{
2980 int rc = 0;
2981 struct mdss_dsi_clk_info info;
2982 struct mdss_dsi_clk_client client1 = {"dsi_clk_client"};
2983 struct mdss_dsi_clk_client client2 = {"mdp_event_client"};
2984 void *handle;
2985
2986 if (mdss_dsi_link_clk_init(ctrl_pdev, ctrl_pdata)) {
2987 pr_err("%s: unable to initialize Dsi ctrl clks\n", __func__);
2988 return -EPERM;
2989 }
2990
2991 memset(&info, 0x0, sizeof(info));
2992
2993 info.core_clks.mdp_core_clk = ctrl_pdata->shared_data->mdp_core_clk;
2994 info.core_clks.ahb_clk = ctrl_pdata->shared_data->ahb_clk;
2995 info.core_clks.axi_clk = ctrl_pdata->shared_data->axi_clk;
2996 info.core_clks.mmss_misc_ahb_clk =
2997 ctrl_pdata->shared_data->mmss_misc_ahb_clk;
2998
2999 info.link_clks.esc_clk = ctrl_pdata->esc_clk;
3000 info.link_clks.byte_clk = ctrl_pdata->byte_clk;
3001 info.link_clks.pixel_clk = ctrl_pdata->pixel_clk;
3002
3003 info.pre_clkoff_cb = mdss_dsi_pre_clkoff_cb;
3004 info.post_clkon_cb = mdss_dsi_post_clkon_cb;
3005 info.pre_clkon_cb = mdss_dsi_pre_clkon_cb;
3006 info.post_clkoff_cb = mdss_dsi_post_clkoff_cb;
3007 info.priv_data = ctrl_pdata;
3008 snprintf(info.name, DSI_CLK_NAME_LEN, "DSI%d", ctrl_pdata->ndx);
3009 ctrl_pdata->clk_mngr = mdss_dsi_clk_init(&info);
3010 if (IS_ERR_OR_NULL(ctrl_pdata->clk_mngr)) {
3011 rc = PTR_ERR(ctrl_pdata->clk_mngr);
3012 ctrl_pdata->clk_mngr = NULL;
3013 pr_err("dsi clock registration failed, rc = %d\n", rc);
3014 goto error_link_clk_deinit;
3015 }
3016
3017 /*
3018 * There are two clients that control dsi clocks. MDP driver controls
3019 * the clock through MDSS_PANEL_EVENT_CLK_CTRL event and dsi driver
3020 * through clock interface. To differentiate between the votes from the
3021 * two clients, dsi driver will use two different handles to vote for
3022 * clock states from dsi and mdp driver.
3023 */
3024 handle = mdss_dsi_clk_register(ctrl_pdata->clk_mngr, &client1);
3025 if (IS_ERR_OR_NULL(handle)) {
3026 rc = PTR_ERR(handle);
3027 pr_err("failed to register %s client, rc = %d\n",
3028 client1.client_name, rc);
3029 goto error_clk_deinit;
3030 } else {
3031 ctrl_pdata->dsi_clk_handle = handle;
3032 }
3033
3034 handle = mdss_dsi_clk_register(ctrl_pdata->clk_mngr, &client2);
3035 if (IS_ERR_OR_NULL(handle)) {
3036 rc = PTR_ERR(handle);
3037 pr_err("failed to register %s client, rc = %d\n",
3038 client2.client_name, rc);
3039 goto error_clk_client_deregister;
3040 } else {
3041 ctrl_pdata->mdp_clk_handle = handle;
3042 }
3043
3044 return rc;
3045error_clk_client_deregister:
3046 mdss_dsi_clk_deregister(ctrl_pdata->dsi_clk_handle);
3047error_clk_deinit:
3048 mdss_dsi_clk_deinit(ctrl_pdata->clk_mngr);
3049error_link_clk_deinit:
3050 mdss_dsi_link_clk_deinit(&ctrl_pdev->dev, ctrl_pdata);
3051 return rc;
3052}
3053
3054static int mdss_dsi_set_clk_rates(struct mdss_dsi_ctrl_pdata *ctrl_pdata)
3055{
3056 int rc = 0;
3057
3058 rc = mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle,
3059 MDSS_DSI_LINK_BYTE_CLK,
3060 ctrl_pdata->byte_clk_rate,
3061 MDSS_DSI_CLK_UPDATE_CLK_RATE_AT_ON);
3062 if (rc) {
3063 pr_err("%s: dsi_byte_clk - clk_set_rate failed\n",
3064 __func__);
3065 return rc;
3066 }
3067
3068 rc = mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle,
3069 MDSS_DSI_LINK_PIX_CLK,
3070 ctrl_pdata->pclk_rate,
3071 MDSS_DSI_CLK_UPDATE_CLK_RATE_AT_ON);
3072 if (rc) {
3073 pr_err("%s: dsi_pixel_clk - clk_set_rate failed\n",
3074 __func__);
3075 return rc;
3076 }
3077
3078 rc = mdss_dsi_clk_set_link_rate(ctrl_pdata->dsi_clk_handle,
3079 MDSS_DSI_LINK_ESC_CLK,
3080 19200000,
3081 MDSS_DSI_CLK_UPDATE_CLK_RATE_AT_ON);
3082 if (rc) {
3083 pr_err("%s: dsi_esc_clk - clk_set_rate failed\n",
3084 __func__);
3085 return rc;
3086 }
3087
3088 return rc;
3089}
3090
3091static int mdss_dsi_cont_splash_config(struct mdss_panel_info *pinfo,
3092 struct mdss_dsi_ctrl_pdata *ctrl_pdata)
3093{
3094 void *clk_handle;
3095 int rc = 0;
3096
3097 if (pinfo->cont_splash_enabled) {
3098 rc = mdss_dsi_panel_power_ctrl(&(ctrl_pdata->panel_data),
3099 MDSS_PANEL_POWER_ON);
3100 if (rc) {
3101 pr_err("%s: Panel power on failed\n", __func__);
3102 return rc;
3103 }
3104 if (ctrl_pdata->bklt_ctrl == BL_PWM)
3105 mdss_dsi_panel_pwm_enable(ctrl_pdata);
3106 ctrl_pdata->ctrl_state |= (CTRL_STATE_PANEL_INIT |
3107 CTRL_STATE_MDP_ACTIVE | CTRL_STATE_DSI_ACTIVE);
3108
3109 /*
3110 * MDP client removes this extra vote during splash reconfigure
3111 * for command mode panel from interface. DSI removes the vote
3112 * during suspend-resume for video mode panel.
3113 */
3114 if (ctrl_pdata->panel_data.panel_info.type == MIPI_CMD_PANEL)
3115 clk_handle = ctrl_pdata->mdp_clk_handle;
3116 else
3117 clk_handle = ctrl_pdata->dsi_clk_handle;
3118
3119 mdss_dsi_clk_ctrl(ctrl_pdata, clk_handle,
3120 MDSS_DSI_ALL_CLKS, MDSS_DSI_CLK_ON);
3121 mdss_dsi_read_hw_revision(ctrl_pdata);
3122 mdss_dsi_read_phy_revision(ctrl_pdata);
3123 ctrl_pdata->is_phyreg_enabled = 1;
3124 if (pinfo->type == MIPI_CMD_PANEL)
3125 mdss_dsi_set_burst_mode(ctrl_pdata);
3126 } else {
3127 /* Turn on the clocks to read the DSI and PHY revision */
3128 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
3129 MDSS_DSI_CORE_CLK, MDSS_DSI_CLK_ON);
3130 mdss_dsi_read_hw_revision(ctrl_pdata);
3131 mdss_dsi_read_phy_revision(ctrl_pdata);
3132 mdss_dsi_clk_ctrl(ctrl_pdata, ctrl_pdata->dsi_clk_handle,
3133 MDSS_DSI_CORE_CLK, MDSS_DSI_CLK_OFF);
3134 pinfo->panel_power_state = MDSS_PANEL_POWER_OFF;
3135 }
3136
3137 return rc;
3138}
3139
3140static int mdss_dsi_get_bridge_chip_params(struct mdss_panel_info *pinfo,
3141 struct mdss_dsi_ctrl_pdata *ctrl_pdata,
3142 struct platform_device *pdev)
3143{
3144 int rc = 0;
3145 u32 temp_val = 0;
3146
3147 if (!ctrl_pdata || !pdev || !pinfo) {
3148 pr_err("%s: Invalid Params ctrl_pdata=%pK, pdev=%pK\n",
3149 __func__, ctrl_pdata, pdev);
3150 rc = -EINVAL;
3151 goto end;
3152 }
3153
3154 if (pinfo->is_dba_panel) {
3155 rc = of_property_read_u32(pdev->dev.of_node,
3156 "qcom,bridge-index", &temp_val);
3157 if (rc) {
3158 pr_err("%s:%d Unable to read qcom,bridge-index, ret=%d\n",
3159 __func__, __LINE__, rc);
3160 goto end;
3161 }
3162 pr_debug("%s: DT property %s is %X\n", __func__,
3163 "qcom,bridge-index", temp_val);
3164 ctrl_pdata->bridge_index = temp_val;
3165 }
3166end:
3167 return rc;
3168}
3169
3170static int mdss_dsi_ctrl_probe(struct platform_device *pdev)
3171{
3172 int rc = 0;
3173 u32 index;
3174 struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
3175 struct mdss_panel_info *pinfo = NULL;
3176 struct device_node *dsi_pan_node = NULL;
3177 const char *ctrl_name;
3178 struct mdss_util_intf *util;
3179 static int te_irq_registered;
3180 struct mdss_panel_data *pdata;
3181
3182 if (!pdev || !pdev->dev.of_node) {
3183 pr_err("%s: pdev not found for DSI controller\n", __func__);
3184 return -ENODEV;
3185 }
3186 rc = of_property_read_u32(pdev->dev.of_node,
3187 "cell-index", &index);
3188 if (rc) {
3189 dev_err(&pdev->dev, "%s: Cell-index not specified, rc=%d\n",
3190 __func__, rc);
3191 return rc;
3192 }
3193
3194 if (index == 0)
3195 pdev->id = 1;
3196 else
3197 pdev->id = 2;
3198
3199 ctrl_pdata = mdss_dsi_get_ctrl(index);
3200 if (!ctrl_pdata) {
3201 pr_err("%s: Unable to get the ctrl_pdata\n", __func__);
3202 return -EINVAL;
3203 }
3204
3205 platform_set_drvdata(pdev, ctrl_pdata);
3206
3207 util = mdss_get_util_intf();
3208 if (util == NULL) {
3209 pr_err("Failed to get mdss utility functions\n");
3210 return -ENODEV;
3211 }
3212
3213 ctrl_pdata->mdss_util = util;
3214 atomic_set(&ctrl_pdata->te_irq_ready, 0);
3215
3216 ctrl_name = of_get_property(pdev->dev.of_node, "label", NULL);
3217 if (!ctrl_name)
3218 pr_info("%s:%d, DSI Ctrl name not specified\n",
3219 __func__, __LINE__);
3220 else
3221 pr_info("%s: DSI Ctrl name = %s\n",
3222 __func__, ctrl_name);
3223
3224 rc = mdss_dsi_pinctrl_init(pdev);
3225 if (rc)
3226 pr_warn("%s: failed to get pin resources\n", __func__);
3227
3228 if (index == 0) {
3229 ctrl_pdata->panel_data.panel_info.pdest = DISPLAY_1;
3230 ctrl_pdata->ndx = DSI_CTRL_0;
3231 } else {
3232 ctrl_pdata->panel_data.panel_info.pdest = DISPLAY_2;
3233 ctrl_pdata->ndx = DSI_CTRL_1;
3234 }
3235
3236 if (mdss_dsi_ctrl_clock_init(pdev, ctrl_pdata)) {
3237 pr_err("%s: unable to initialize dsi clk manager\n", __func__);
3238 return -EPERM;
3239 }
3240
3241 dsi_pan_node = mdss_dsi_config_panel(pdev, index);
3242 if (!dsi_pan_node) {
3243 pr_err("%s: panel configuration failed\n", __func__);
3244 return -EINVAL;
3245 }
3246
3247 if (!mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) ||
3248 (mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) &&
3249 (ctrl_pdata->panel_data.panel_info.pdest == DISPLAY_1))) {
3250 rc = mdss_panel_parse_bl_settings(dsi_pan_node, ctrl_pdata);
3251 if (rc) {
3252 pr_warn("%s: dsi bl settings parse failed\n", __func__);
3253 /* Panels like AMOLED and dsi2hdmi chip
3254 * does not need backlight control.
3255 * So we should not fail probe here.
3256 */
3257 ctrl_pdata->bklt_ctrl = UNKNOWN_CTRL;
3258 }
3259 } else {
3260 ctrl_pdata->bklt_ctrl = UNKNOWN_CTRL;
3261 }
3262
3263 rc = dsi_panel_device_register(pdev, dsi_pan_node, ctrl_pdata);
3264 if (rc) {
3265 pr_err("%s: dsi panel dev reg failed\n", __func__);
3266 goto error_pan_node;
3267 }
3268
3269 pinfo = &(ctrl_pdata->panel_data.panel_info);
3270 if (!(mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) &&
3271 mdss_dsi_is_ctrl_clk_slave(ctrl_pdata)) &&
3272 pinfo->dynamic_fps) {
3273 rc = mdss_dsi_shadow_clk_init(pdev, ctrl_pdata);
3274
3275 if (rc) {
3276 pr_err("%s: unable to initialize shadow ctrl clks\n",
3277 __func__);
3278 rc = -EPERM;
3279 }
3280 }
3281
3282 rc = mdss_dsi_set_clk_rates(ctrl_pdata);
3283 if (rc) {
3284 pr_err("%s: Failed to set dsi clk rates\n", __func__);
3285 return rc;
3286 }
3287
3288 rc = mdss_dsi_cont_splash_config(pinfo, ctrl_pdata);
3289 if (rc) {
3290 pr_err("%s: Failed to set dsi splash config\n", __func__);
3291 return rc;
3292 }
3293
3294 if (mdss_dsi_is_te_based_esd(ctrl_pdata)) {
3295 init_completion(&ctrl_pdata->te_irq_comp);
3296 rc = devm_request_irq(&pdev->dev,
3297 gpio_to_irq(ctrl_pdata->disp_te_gpio),
3298 hw_vsync_handler, IRQF_TRIGGER_FALLING,
3299 "VSYNC_GPIO", ctrl_pdata);
3300 if (rc) {
3301 pr_err("%s: TE request_irq failed for ESD\n", __func__);
3302 goto error_shadow_clk_deinit;
3303 }
3304 te_irq_registered = 1;
3305 disable_irq(gpio_to_irq(ctrl_pdata->disp_te_gpio));
3306 }
3307
3308 pdata = &ctrl_pdata->panel_data;
3309 init_completion(&pdata->te_done);
3310 if (pdata->panel_info.type == MIPI_CMD_PANEL) {
3311 if (!te_irq_registered) {
3312 rc = devm_request_irq(&pdev->dev,
3313 gpio_to_irq(pdata->panel_te_gpio),
3314 test_hw_vsync_handler, IRQF_TRIGGER_FALLING,
3315 "VSYNC_GPIO", &ctrl_pdata->panel_data);
3316 if (rc) {
3317 pr_err("%s: TE request_irq failed\n", __func__);
3318 goto error_shadow_clk_deinit;
3319 }
3320 te_irq_registered = 1;
3321 disable_irq_nosync(gpio_to_irq(pdata->panel_te_gpio));
3322 }
3323 }
3324
3325 rc = mdss_dsi_get_bridge_chip_params(pinfo, ctrl_pdata, pdev);
3326 if (rc) {
3327 pr_err("%s: Failed to get bridge params\n", __func__);
3328 goto error_shadow_clk_deinit;
3329 }
3330
3331 ctrl_pdata->workq = create_workqueue("mdss_dsi_dba");
3332 if (!ctrl_pdata->workq) {
3333 pr_err("%s: Error creating workqueue\n", __func__);
3334 rc = -EPERM;
3335 goto error_pan_node;
3336 }
3337
3338 INIT_DELAYED_WORK(&ctrl_pdata->dba_work, mdss_dsi_dba_work);
3339
3340 pr_info("%s: Dsi Ctrl->%d initialized, DSI rev:0x%x, PHY rev:0x%x\n",
3341 __func__, index, ctrl_pdata->shared_data->hw_rev,
3342 ctrl_pdata->shared_data->phy_rev);
3343 mdss_dsi_pm_qos_add_request(ctrl_pdata);
3344
3345 if (index == 0)
3346 ctrl_pdata->shared_data->dsi0_active = true;
3347 else
3348 ctrl_pdata->shared_data->dsi1_active = true;
3349
3350 return 0;
3351
3352error_shadow_clk_deinit:
3353 mdss_dsi_shadow_clk_deinit(&pdev->dev, ctrl_pdata);
3354error_pan_node:
3355 mdss_dsi_unregister_bl_settings(ctrl_pdata);
3356 of_node_put(dsi_pan_node);
3357 return rc;
3358}
3359
3360static int mdss_dsi_bus_scale_init(struct platform_device *pdev,
3361 struct dsi_shared_data *sdata)
3362{
3363 int rc = 0;
3364
3365 sdata->bus_scale_table = msm_bus_cl_get_pdata(pdev);
3366 if (IS_ERR_OR_NULL(sdata->bus_scale_table)) {
3367 rc = PTR_ERR(sdata->bus_scale_table);
3368 pr_err("%s: msm_bus_cl_get_pdata() failed, rc=%d\n", __func__,
3369 rc);
3370 return rc;
3371 sdata->bus_scale_table = NULL;
3372 }
3373
3374 sdata->bus_handle =
3375 msm_bus_scale_register_client(sdata->bus_scale_table);
3376
3377 if (!sdata->bus_handle) {
3378 rc = -EINVAL;
3379 pr_err("%sbus_client register failed\n", __func__);
3380 }
3381
3382 return rc;
3383}
3384
3385static void mdss_dsi_bus_scale_deinit(struct dsi_shared_data *sdata)
3386{
3387 if (sdata->bus_handle) {
3388 if (sdata->bus_refcount)
3389 msm_bus_scale_client_update_request(sdata->bus_handle,
3390 0);
3391
3392 sdata->bus_refcount = 0;
3393 msm_bus_scale_unregister_client(sdata->bus_handle);
3394 sdata->bus_handle = 0;
3395 }
3396}
3397
3398static int mdss_dsi_parse_dt_params(struct platform_device *pdev,
3399 struct dsi_shared_data *sdata)
3400{
3401 int rc = 0;
3402
3403 rc = of_property_read_u32(pdev->dev.of_node,
3404 "qcom,mmss-ulp-clamp-ctrl-offset",
3405 &sdata->ulps_clamp_ctrl_off);
3406 if (!rc) {
3407 rc = of_property_read_u32(pdev->dev.of_node,
3408 "qcom,mmss-phyreset-ctrl-offset",
3409 &sdata->ulps_phyrst_ctrl_off);
3410 }
3411
3412 sdata->cmd_clk_ln_recovery_en =
3413 of_property_read_bool(pdev->dev.of_node,
3414 "qcom,dsi-clk-ln-recovery");
3415
3416 return 0;
3417}
3418
3419#ifdef TARGET_HW_MDSS_HDMI
3420static void mdss_dsi_res_deinit_hdmi(struct platform_device *pdev, int val)
3421{
3422 struct mdss_dsi_data *dsi_res = platform_get_drvdata(pdev);
3423
3424 if (dsi_res->ctrl_pdata[val]->ds_registered) {
3425 struct mdss_panel_info *pinfo =
3426 &dsi_res->ctrl_pdata[val]->
3427 panel_data.panel_info;
3428 if (pinfo)
3429 mdss_dba_utils_deinit(pinfo->dba_data);
3430 }
3431}
3432#else
3433static void mdss_dsi_res_deinit_hdmi(struct platform_device *pdev, int val)
3434{
3435 (void)(*pdev);
3436 (void)(val);
3437}
3438#endif
3439
3440static void mdss_dsi_res_deinit(struct platform_device *pdev)
3441{
3442 int i;
3443 struct mdss_dsi_data *dsi_res = platform_get_drvdata(pdev);
3444 struct dsi_shared_data *sdata;
3445
3446 if (!dsi_res) {
3447 pr_err("%s: DSI root device drvdata not found\n", __func__);
3448 return;
3449 }
3450
3451 for (i = 0; i < DSI_CTRL_MAX; i++) {
3452 if (dsi_res->ctrl_pdata[i]) {
3453 mdss_dsi_res_deinit_hdmi(pdev, i);
3454 devm_kfree(&pdev->dev, dsi_res->ctrl_pdata[i]);
3455 }
3456 }
3457
3458 sdata = dsi_res->shared_data;
3459 if (!sdata)
3460 goto res_release;
3461
3462 for (i = (DSI_MAX_PM - 1); i >= DSI_CORE_PM; i--) {
3463 if (msm_dss_config_vreg(&pdev->dev,
3464 sdata->power_data[i].vreg_config,
3465 sdata->power_data[i].num_vreg, 1) < 0)
3466 pr_err("%s: failed to de-init vregs for %s\n",
3467 __func__, __mdss_dsi_pm_name(i));
3468 mdss_dsi_put_dt_vreg_data(&pdev->dev,
3469 &sdata->power_data[i]);
3470 }
3471
3472 mdss_dsi_bus_scale_deinit(sdata);
3473 mdss_dsi_core_clk_deinit(&pdev->dev, sdata);
3474
3475 if (sdata)
3476 devm_kfree(&pdev->dev, sdata);
3477
3478res_release:
3479 if (dsi_res)
3480 devm_kfree(&pdev->dev, dsi_res);
3481
3482}
3483
3484static int mdss_dsi_res_init(struct platform_device *pdev)
3485{
3486 int rc = 0, i;
3487 struct dsi_shared_data *sdata;
3488
3489 mdss_dsi_res = platform_get_drvdata(pdev);
3490 if (!mdss_dsi_res) {
3491 mdss_dsi_res = devm_kzalloc(&pdev->dev,
3492 sizeof(struct mdss_dsi_data),
3493 GFP_KERNEL);
3494 if (!mdss_dsi_res) {
3495 pr_err("%s: FAILED: cannot alloc dsi data\n",
3496 __func__);
3497 rc = -ENOMEM;
3498 goto mem_fail;
3499 }
3500
3501 mdss_dsi_res->shared_data = devm_kzalloc(&pdev->dev,
3502 sizeof(struct dsi_shared_data),
3503 GFP_KERNEL);
3504 pr_debug("%s Allocated shared_data=%pK\n", __func__,
3505 mdss_dsi_res->shared_data);
3506 if (!mdss_dsi_res->shared_data) {
3507 pr_err("%s Unable to alloc mem for shared_data\n",
3508 __func__);
3509 rc = -ENOMEM;
3510 goto mem_fail;
3511 }
3512
3513 sdata = mdss_dsi_res->shared_data;
3514
3515 rc = mdss_dsi_parse_dt_params(pdev, sdata);
3516 if (rc) {
3517 pr_err("%s: failed to parse mdss dsi DT params\n",
3518 __func__);
3519 goto mem_fail;
3520 }
3521
3522 rc = mdss_dsi_core_clk_init(pdev, sdata);
3523 if (rc) {
3524 pr_err("%s: failed to initialize DSI core clocks\n",
3525 __func__);
3526 goto mem_fail;
3527 }
3528
3529 /* Parse the regulator information */
3530 for (i = DSI_CORE_PM; i < DSI_MAX_PM; i++) {
3531 rc = mdss_dsi_get_dt_vreg_data(&pdev->dev,
3532 pdev->dev.of_node, &sdata->power_data[i], i);
3533 if (rc) {
3534 pr_err("%s: '%s' get_dt_vreg_data failed.rc=%d\n",
3535 __func__, __mdss_dsi_pm_name(i), rc);
3536 i--;
3537 for (; i >= DSI_CORE_PM; i--)
3538 mdss_dsi_put_dt_vreg_data(&pdev->dev,
3539 &sdata->power_data[i]);
3540 goto mem_fail;
3541 }
3542 }
3543 rc = mdss_dsi_regulator_init(pdev, sdata);
3544 if (rc) {
3545 pr_err("%s: failed to init regulator, rc=%d\n",
3546 __func__, rc);
3547 goto mem_fail;
3548 }
3549
3550 rc = mdss_dsi_bus_scale_init(pdev, sdata);
3551 if (rc) {
3552 pr_err("%s: failed to init bus scale settings, rc=%d\n",
3553 __func__, rc);
3554 goto mem_fail;
3555 }
3556
3557 mutex_init(&sdata->phy_reg_lock);
3558 mutex_init(&sdata->pm_qos_lock);
3559
3560 for (i = 0; i < DSI_CTRL_MAX; i++) {
3561 mdss_dsi_res->ctrl_pdata[i] = devm_kzalloc(&pdev->dev,
3562 sizeof(struct mdss_dsi_ctrl_pdata),
3563 GFP_KERNEL);
3564 if (!mdss_dsi_res->ctrl_pdata[i]) {
3565 pr_err("%s Unable to alloc mem for ctrl=%d\n",
3566 __func__, i);
3567 rc = -ENOMEM;
3568 goto mem_fail;
3569 }
3570 pr_debug("%s Allocated ctrl_pdata[%d]=%pK\n",
3571 __func__, i, mdss_dsi_res->ctrl_pdata[i]);
3572 mdss_dsi_res->ctrl_pdata[i]->shared_data =
3573 mdss_dsi_res->shared_data;
3574 }
3575
3576 platform_set_drvdata(pdev, mdss_dsi_res);
3577 }
3578
3579 mdss_dsi_res->pdev = pdev;
3580 pr_debug("%s: Setting up mdss_dsi_res=%pK\n", __func__, mdss_dsi_res);
3581
3582 return 0;
3583
3584mem_fail:
3585 mdss_dsi_res_deinit(pdev);
3586 return rc;
3587}
3588
3589static int mdss_dsi_parse_hw_cfg(struct platform_device *pdev, char *pan_cfg)
3590{
3591 const char *data;
3592 struct mdss_dsi_data *dsi_res = platform_get_drvdata(pdev);
3593 struct dsi_shared_data *sdata;
3594 char dsi_cfg[20];
3595 char *cfg_prim = NULL, *cfg_sec = NULL, *ch = NULL;
3596 int i = 0;
3597
3598 if (!dsi_res) {
3599 pr_err("%s: DSI root device drvdata not found\n", __func__);
3600 return -EINVAL;
3601 }
3602
3603 sdata = mdss_dsi_res->shared_data;
3604 if (!sdata) {
3605 pr_err("%s: DSI shared data not found\n", __func__);
3606 return -EINVAL;
3607 }
3608
3609 sdata->hw_config = SINGLE_DSI;
3610
3611 if (pan_cfg)
3612 cfg_prim = strnstr(pan_cfg, "cfg:", strlen(pan_cfg));
3613 if (cfg_prim) {
3614 cfg_prim += 4;
3615
3616 cfg_sec = strnchr(cfg_prim, strlen(cfg_prim), ':');
3617 if (!cfg_sec)
3618 cfg_sec = cfg_prim + strlen(cfg_prim);
3619
3620 for (i = 0; ((cfg_prim + i) < cfg_sec) &&
3621 (*(cfg_prim+i) != '#'); i++)
3622 dsi_cfg[i] = *(cfg_prim + i);
3623
3624 dsi_cfg[i] = '\0';
3625 data = dsi_cfg;
3626 } else {
3627 data = of_get_property(pdev->dev.of_node,
3628 "hw-config", NULL);
3629 }
3630
3631 if (data) {
3632 /*
3633 * To handle the override parameter (#override:sim)
3634 * passed for simulator panels
3635 */
3636 ch = strnstr(data, "#", strlen(data));
3637 ch ? *ch = '\0' : false;
3638
3639 if (!strcmp(data, "dual_dsi"))
3640 sdata->hw_config = DUAL_DSI;
3641 else if (!strcmp(data, "split_dsi"))
3642 sdata->hw_config = SPLIT_DSI;
3643 else if (!strcmp(data, "single_dsi"))
3644 sdata->hw_config = SINGLE_DSI;
3645 else
3646 pr_err("%s: Incorrect string for DSI config:%s. Setting default as SINGLE_DSI\n",
3647 __func__, data);
3648 } else {
3649 pr_err("%s: Error: No DSI HW config found\n",
3650 __func__);
3651 return -EINVAL;
3652 }
3653
3654 pr_debug("%s: DSI h/w configuration is %d\n", __func__,
3655 sdata->hw_config);
3656
3657 return 0;
3658}
3659
3660static void mdss_dsi_parse_pll_src_cfg(struct platform_device *pdev,
3661 char *pan_cfg)
3662{
3663 const char *data;
3664 char *pll_ptr, pll_cfg[10] = {'\0'};
3665 struct dsi_shared_data *sdata = mdss_dsi_res->shared_data;
3666
3667 sdata->pll_src_config = PLL_SRC_DEFAULT;
3668
3669 if (pan_cfg) {
3670 pll_ptr = strnstr(pan_cfg, ":pll0", strlen(pan_cfg));
3671 if (!pll_ptr) {
3672 pll_ptr = strnstr(pan_cfg, ":pll1", strlen(pan_cfg));
3673 if (pll_ptr)
3674 strlcpy(pll_cfg, "PLL1", strlen(pll_cfg));
3675 } else {
3676 strlcpy(pll_cfg, "PLL0", strlen(pll_cfg));
3677 }
3678 }
3679 data = pll_cfg;
3680
3681 if (!data || !strcmp(data, ""))
3682 data = of_get_property(pdev->dev.of_node,
3683 "pll-src-config", NULL);
3684 if (data) {
3685 if (!strcmp(data, "PLL0"))
3686 sdata->pll_src_config = PLL_SRC_0;
3687 else if (!strcmp(data, "PLL1"))
3688 sdata->pll_src_config = PLL_SRC_1;
3689 else
3690 pr_err("%s: invalid pll src config %s\n",
3691 __func__, data);
3692 } else {
3693 pr_debug("%s: PLL src config not specified\n", __func__);
3694 }
3695
3696 pr_debug("%s: pll_src_config = %d", __func__, sdata->pll_src_config);
3697}
3698
3699static int mdss_dsi_validate_pll_src_config(struct dsi_shared_data *sdata)
3700{
3701 int rc = 0;
3702
3703 /*
3704 * DSI PLL1 can only drive DSI PHY1. As such:
3705 * - For split dsi config, only PLL0 is supported
3706 * - For dual dsi config, DSI0-PLL0 and DSI1-PLL1 is the only
3707 * possible configuration
3708 */
3709 if (mdss_dsi_is_hw_config_split(sdata) &&
3710 mdss_dsi_is_pll_src_pll1(sdata)) {
3711 pr_err("%s: unsupported PLL config: using PLL1 for split-dsi\n",
3712 __func__);
3713 rc = -EINVAL;
3714 goto error;
3715 }
3716
3717 if (mdss_dsi_is_hw_config_dual(sdata) &&
3718 !mdss_dsi_is_pll_src_default(sdata)) {
3719 pr_debug("%s: pll src config not applicable for dual-dsi\n",
3720 __func__);
3721 sdata->pll_src_config = PLL_SRC_DEFAULT;
3722 }
3723
3724error:
3725 return rc;
3726}
3727
3728static int mdss_dsi_validate_config(struct platform_device *pdev)
3729{
3730 struct dsi_shared_data *sdata = mdss_dsi_res->shared_data;
3731
3732 return mdss_dsi_validate_pll_src_config(sdata);
3733}
3734
3735static const struct of_device_id mdss_dsi_ctrl_dt_match[] = {
3736 {.compatible = "qcom,mdss-dsi-ctrl"},
3737 {}
3738};
3739MODULE_DEVICE_TABLE(of, mdss_dsi_ctrl_dt_match);
3740
3741static int mdss_dsi_probe(struct platform_device *pdev)
3742{
3743 struct mdss_panel_cfg *pan_cfg = NULL;
3744 struct mdss_util_intf *util;
3745 char *panel_cfg;
3746 int rc = 0;
3747
3748 util = mdss_get_util_intf();
3749 if (util == NULL) {
3750 pr_err("%s: Failed to get mdss utility functions\n", __func__);
3751 return -ENODEV;
3752 }
3753
3754 if (!util->mdp_probe_done) {
3755 pr_err("%s: MDP not probed yet!\n", __func__);
3756 return -EPROBE_DEFER;
3757 }
3758
Sachin Bhayareeeb88892018-01-02 16:36:01 +05303759 if (!pdev || !pdev->dev.of_node) {
3760 pr_err("%s: DSI driver only supports device tree probe\n",
3761 __func__);
3762 return -ENOTSUPP;
3763 }
3764
3765 pan_cfg = util->panel_intf_type(MDSS_PANEL_INTF_HDMI);
3766 if (IS_ERR(pan_cfg)) {
3767 return PTR_ERR(pan_cfg);
3768 } else if (pan_cfg) {
3769 pr_debug("%s: HDMI is primary\n", __func__);
3770 return -ENODEV;
3771 }
3772
3773 pan_cfg = util->panel_intf_type(MDSS_PANEL_INTF_DSI);
3774 if (IS_ERR_OR_NULL(pan_cfg)) {
3775 rc = PTR_ERR(pan_cfg);
3776 goto error;
3777 } else {
3778 panel_cfg = pan_cfg->arg_cfg;
3779 }
3780
3781 rc = mdss_dsi_res_init(pdev);
3782 if (rc) {
3783 pr_err("%s Unable to set dsi res\n", __func__);
3784 return rc;
3785 }
3786
3787 rc = mdss_dsi_parse_hw_cfg(pdev, panel_cfg);
3788 if (rc) {
3789 pr_err("%s Unable to parse dsi h/w config\n", __func__);
3790 mdss_dsi_res_deinit(pdev);
3791 return rc;
3792 }
3793
3794 mdss_dsi_parse_pll_src_cfg(pdev, panel_cfg);
3795
3796 of_platform_populate(pdev->dev.of_node, mdss_dsi_ctrl_dt_match,
3797 NULL, &pdev->dev);
3798
3799 rc = mdss_dsi_validate_config(pdev);
3800 if (rc) {
3801 pr_err("%s: Invalid DSI hw configuration\n", __func__);
3802 goto error;
3803 }
3804
3805 mdss_dsi_config_clk_src(pdev);
3806
3807error:
3808 return rc;
3809}
3810
3811static int mdss_dsi_remove(struct platform_device *pdev)
3812{
3813 mdss_dsi_res_deinit(pdev);
3814 return 0;
3815}
3816
3817static int mdss_dsi_ctrl_remove(struct platform_device *pdev)
3818{
3819 struct msm_fb_data_type *mfd;
3820 struct mdss_dsi_ctrl_pdata *ctrl_pdata = platform_get_drvdata(pdev);
3821
3822 if (!ctrl_pdata) {
3823 pr_err("%s: no driver data\n", __func__);
3824 return -ENODEV;
3825 }
3826
3827 mdss_dsi_pm_qos_remove_request(ctrl_pdata->shared_data);
3828
3829 if (msm_dss_config_vreg(&pdev->dev,
3830 ctrl_pdata->panel_power_data.vreg_config,
3831 ctrl_pdata->panel_power_data.num_vreg, 1) < 0)
3832 pr_err("%s: failed to de-init vregs for %s\n",
3833 __func__, __mdss_dsi_pm_name(DSI_PANEL_PM));
3834 mdss_dsi_put_dt_vreg_data(&pdev->dev, &ctrl_pdata->panel_power_data);
3835
3836 mfd = platform_get_drvdata(pdev);
3837 msm_dss_iounmap(&ctrl_pdata->mmss_misc_io);
3838 msm_dss_iounmap(&ctrl_pdata->phy_io);
3839 msm_dss_iounmap(&ctrl_pdata->ctrl_io);
3840 mdss_dsi_debugfs_cleanup(ctrl_pdata);
3841
3842 if (ctrl_pdata->workq)
3843 destroy_workqueue(ctrl_pdata->workq);
3844
3845 return 0;
3846}
3847
3848struct device dsi_dev;
3849
3850int mdss_dsi_retrieve_ctrl_resources(struct platform_device *pdev, int mode,
3851 struct mdss_dsi_ctrl_pdata *ctrl)
3852{
3853 int rc = 0;
3854 u32 index;
3855
3856 rc = of_property_read_u32(pdev->dev.of_node, "cell-index", &index);
3857 if (rc) {
3858 dev_err(&pdev->dev,
3859 "%s: Cell-index not specified, rc=%d\n",
3860 __func__, rc);
3861 return rc;
3862 }
3863
3864 if (index == 0) {
3865 if (mode != DISPLAY_1) {
3866 pr_err("%s:%d Panel->Ctrl mapping is wrong\n",
3867 __func__, __LINE__);
3868 return -EPERM;
3869 }
3870 } else if (index == 1) {
3871 if (mode != DISPLAY_2) {
3872 pr_err("%s:%d Panel->Ctrl mapping is wrong\n",
3873 __func__, __LINE__);
3874 return -EPERM;
3875 }
3876 } else {
3877 pr_err("%s:%d Unknown Ctrl mapped to panel\n",
3878 __func__, __LINE__);
3879 return -EPERM;
3880 }
3881
3882 rc = msm_dss_ioremap_byname(pdev, &ctrl->ctrl_io, "dsi_ctrl");
3883 if (rc) {
3884 pr_err("%s:%d unable to remap dsi ctrl resources\n",
3885 __func__, __LINE__);
3886 return rc;
3887 }
3888
3889 ctrl->ctrl_base = ctrl->ctrl_io.base;
3890 ctrl->reg_size = ctrl->ctrl_io.len;
3891
3892 rc = msm_dss_ioremap_byname(pdev, &ctrl->phy_io, "dsi_phy");
3893 if (rc) {
3894 pr_err("%s:%d unable to remap dsi phy resources\n",
3895 __func__, __LINE__);
3896 return rc;
3897 }
3898
3899 rc = msm_dss_ioremap_byname(pdev, &ctrl->phy_regulator_io,
3900 "dsi_phy_regulator");
3901 if (rc)
3902 pr_debug("%s:%d unable to remap dsi phy regulator resources\n",
3903 __func__, __LINE__);
3904 else
3905 pr_info("%s: phy_regulator_base=%pK phy_regulator_size=%x\n",
3906 __func__, ctrl->phy_regulator_io.base,
3907 ctrl->phy_regulator_io.len);
3908
3909 pr_info("%s: ctrl_base=%pK ctrl_size=%x phy_base=%pK phy_size=%x\n",
3910 __func__, ctrl->ctrl_base, ctrl->reg_size, ctrl->phy_io.base,
3911 ctrl->phy_io.len);
3912
3913 rc = msm_dss_ioremap_byname(pdev, &ctrl->mmss_misc_io,
3914 "mmss_misc_phys");
3915 if (rc) {
3916 pr_debug("%s:%d mmss_misc IO remap failed\n",
3917 __func__, __LINE__);
3918 }
3919
3920 return 0;
3921}
3922
3923static int mdss_dsi_irq_init(struct device *dev, int irq_no,
3924 struct mdss_dsi_ctrl_pdata *ctrl)
3925{
3926 int ret;
3927
3928 ret = devm_request_irq(dev, irq_no, mdss_dsi_isr,
Sachin Bhayare3d3767e2018-01-02 21:10:57 +05303929 0, "DSI", ctrl);
Sachin Bhayareeeb88892018-01-02 16:36:01 +05303930 if (ret) {
3931 pr_err("msm_dsi_irq_init request_irq() failed!\n");
3932 return ret;
3933 }
3934
3935 disable_irq(irq_no);
3936 ctrl->dsi_hw->irq_info = kcalloc(1, sizeof(struct irq_info),
3937 GFP_KERNEL);
3938 if (!ctrl->dsi_hw->irq_info)
3939 return -ENOMEM;
3940
3941 ctrl->dsi_hw->irq_info->irq = irq_no;
3942 ctrl->dsi_hw->irq_info->irq_ena = false;
3943
3944 return ret;
3945}
3946
3947static void mdss_dsi_parse_lane_swap(struct device_node *np, char *dlane_swap)
3948{
3949 const char *data;
3950
3951 *dlane_swap = DSI_LANE_MAP_0123;
3952 data = of_get_property(np, "qcom,lane-map", NULL);
3953 if (data) {
3954 if (!strcmp(data, "lane_map_3012"))
3955 *dlane_swap = DSI_LANE_MAP_3012;
3956 else if (!strcmp(data, "lane_map_2301"))
3957 *dlane_swap = DSI_LANE_MAP_2301;
3958 else if (!strcmp(data, "lane_map_1230"))
3959 *dlane_swap = DSI_LANE_MAP_1230;
3960 else if (!strcmp(data, "lane_map_0321"))
3961 *dlane_swap = DSI_LANE_MAP_0321;
3962 else if (!strcmp(data, "lane_map_1032"))
3963 *dlane_swap = DSI_LANE_MAP_1032;
3964 else if (!strcmp(data, "lane_map_2103"))
3965 *dlane_swap = DSI_LANE_MAP_2103;
3966 else if (!strcmp(data, "lane_map_3210"))
3967 *dlane_swap = DSI_LANE_MAP_3210;
3968 }
3969}
3970
3971static int mdss_dsi_parse_ctrl_params(struct platform_device *ctrl_pdev,
3972 struct device_node *pan_node, struct mdss_dsi_ctrl_pdata *ctrl_pdata)
3973{
3974 int i, len;
3975 struct mdss_panel_info *pinfo = &(ctrl_pdata->panel_data.panel_info);
3976 const char *data;
3977
3978 ctrl_pdata->null_insert_enabled = of_property_read_bool(
3979 ctrl_pdev->dev.of_node, "qcom,null-insertion-enabled");
3980
3981 data = of_get_property(ctrl_pdev->dev.of_node,
3982 "qcom,platform-strength-ctrl", &len);
3983 if (!data) {
3984 pr_err("%s:%d, Unable to read Phy Strength ctrl settings\n",
3985 __func__, __LINE__);
3986 return -EINVAL;
3987 }
3988
3989 pinfo->mipi.dsi_phy_db.strength_len = len;
3990 for (i = 0; i < len; i++)
3991 pinfo->mipi.dsi_phy_db.strength[i] = data[i];
3992
3993 pinfo->mipi.dsi_phy_db.reg_ldo_mode = of_property_read_bool(
3994 ctrl_pdev->dev.of_node, "qcom,regulator-ldo-mode");
3995
3996 data = of_get_property(ctrl_pdev->dev.of_node,
3997 "qcom,platform-regulator-settings", &len);
3998 if (!data) {
3999 pr_err("%s:%d, Unable to read Phy regulator settings\n",
4000 __func__, __LINE__);
4001 return -EINVAL;
4002 }
4003
4004 pinfo->mipi.dsi_phy_db.regulator_len = len;
4005 for (i = 0; i < len; i++)
4006 pinfo->mipi.dsi_phy_db.regulator[i] = data[i];
4007
4008 data = of_get_property(ctrl_pdev->dev.of_node,
4009 "qcom,platform-bist-ctrl", &len);
4010 if ((!data) || (len != 6))
4011 pr_debug("%s:%d, Unable to read Phy Bist Ctrl settings\n",
4012 __func__, __LINE__);
4013 else
4014 for (i = 0; i < len; i++)
4015 pinfo->mipi.dsi_phy_db.bistctrl[i] = data[i];
4016
4017 data = of_get_property(ctrl_pdev->dev.of_node,
4018 "qcom,platform-lane-config", &len);
4019 if (!data) {
4020 pr_err("%s:%d, Unable to read Phy lane configure settings\n",
4021 __func__, __LINE__);
4022 return -EINVAL;
4023 }
4024
4025 pinfo->mipi.dsi_phy_db.lanecfg_len = len;
4026 for (i = 0; i < len; i++)
4027 pinfo->mipi.dsi_phy_db.lanecfg[i] = data[i];
4028
4029 ctrl_pdata->timing_db_mode = of_property_read_bool(
4030 ctrl_pdev->dev.of_node, "qcom,timing-db-mode");
4031
4032 ctrl_pdata->cmd_sync_wait_broadcast = of_property_read_bool(
4033 pan_node, "qcom,cmd-sync-wait-broadcast");
4034
4035 if (ctrl_pdata->cmd_sync_wait_broadcast &&
4036 mdss_dsi_is_hw_config_split(ctrl_pdata->shared_data) &&
4037 (pinfo->pdest == DISPLAY_2))
4038 ctrl_pdata->cmd_sync_wait_trigger = true;
4039
4040 pr_debug("%s: cmd_sync_wait_enable=%d trigger=%d\n", __func__,
4041 ctrl_pdata->cmd_sync_wait_broadcast,
4042 ctrl_pdata->cmd_sync_wait_trigger);
4043
4044 mdss_dsi_parse_lane_swap(ctrl_pdev->dev.of_node,
4045 &(ctrl_pdata->dlane_swap));
4046
4047 pinfo->is_pluggable = of_property_read_bool(ctrl_pdev->dev.of_node,
4048 "qcom,pluggable");
4049
4050 data = of_get_property(ctrl_pdev->dev.of_node,
4051 "qcom,display-id", &len);
4052 if (!data || len <= 0)
4053 pr_err("%s:%d Unable to read qcom,display-id, data=%pK,len=%d\n",
4054 __func__, __LINE__, data, len);
4055 else
4056 snprintf(ctrl_pdata->panel_data.panel_info.display_id,
4057 MDSS_DISPLAY_ID_MAX_LEN, "%s", data);
4058
4059 return 0;
4060
4061
4062}
4063
4064static int mdss_dsi_parse_gpio_params(struct platform_device *ctrl_pdev,
4065 struct mdss_dsi_ctrl_pdata *ctrl_pdata)
4066{
4067 struct mdss_panel_info *pinfo = &(ctrl_pdata->panel_data.panel_info);
4068 struct mdss_panel_data *pdata = &ctrl_pdata->panel_data;
4069
4070 /*
4071 * If disp_en_gpio has been set previously (disp_en_gpio > 0)
4072 * while parsing the panel node, then do not override it
4073 */
4074 if (ctrl_pdata->disp_en_gpio <= 0) {
4075 ctrl_pdata->disp_en_gpio = of_get_named_gpio(
4076 ctrl_pdev->dev.of_node,
4077 "qcom,platform-enable-gpio", 0);
4078
4079 if (!gpio_is_valid(ctrl_pdata->disp_en_gpio))
4080 pr_debug("%s:%d, Disp_en gpio not specified\n",
4081 __func__, __LINE__);
4082 }
4083
4084 ctrl_pdata->disp_te_gpio = of_get_named_gpio(ctrl_pdev->dev.of_node,
4085 "qcom,platform-te-gpio", 0);
4086
4087 if (!gpio_is_valid(ctrl_pdata->disp_te_gpio))
4088 pr_err("%s:%d, TE gpio not specified\n",
4089 __func__, __LINE__);
4090 pdata->panel_te_gpio = ctrl_pdata->disp_te_gpio;
4091
4092 ctrl_pdata->bklt_en_gpio = of_get_named_gpio(ctrl_pdev->dev.of_node,
4093 "qcom,platform-bklight-en-gpio", 0);
4094 if (!gpio_is_valid(ctrl_pdata->bklt_en_gpio))
4095 pr_info("%s: bklt_en gpio not specified\n", __func__);
4096
4097 ctrl_pdata->rst_gpio = of_get_named_gpio(ctrl_pdev->dev.of_node,
4098 "qcom,platform-reset-gpio", 0);
4099 if (!gpio_is_valid(ctrl_pdata->rst_gpio))
4100 pr_err("%s:%d, reset gpio not specified\n",
4101 __func__, __LINE__);
4102
4103 if (pinfo->mode_gpio_state != MODE_GPIO_NOT_VALID) {
4104
4105 ctrl_pdata->mode_gpio = of_get_named_gpio(
4106 ctrl_pdev->dev.of_node,
4107 "qcom,platform-mode-gpio", 0);
4108 if (!gpio_is_valid(ctrl_pdata->mode_gpio))
4109 pr_info("%s:%d, mode gpio not specified\n",
4110 __func__, __LINE__);
4111 } else {
4112 ctrl_pdata->mode_gpio = -EINVAL;
4113 }
4114
4115 ctrl_pdata->intf_mux_gpio = of_get_named_gpio(ctrl_pdev->dev.of_node,
4116 "qcom,platform-intf-mux-gpio", 0);
4117 if (!gpio_is_valid(ctrl_pdata->intf_mux_gpio))
4118 pr_debug("%s:%d, intf mux gpio not specified\n",
4119 __func__, __LINE__);
4120
4121 return 0;
4122}
4123
4124static void mdss_dsi_set_prim_panel(struct mdss_dsi_ctrl_pdata *ctrl_pdata)
4125{
4126 struct mdss_dsi_ctrl_pdata *octrl = NULL;
4127 struct mdss_panel_info *pinfo;
4128
4129 pinfo = &ctrl_pdata->panel_data.panel_info;
4130
4131 /*
4132 * for Split and Single DSI case default is always primary
4133 * and for Dual dsi case below assumptions are made.
4134 * 1. DSI controller with bridge chip is always secondary
4135 * 2. When there is no brigde chip, DSI1 is secondary
4136 */
4137 pinfo->is_prim_panel = true;
4138 if (mdss_dsi_is_hw_config_dual(ctrl_pdata->shared_data)) {
4139 if (mdss_dsi_is_right_ctrl(ctrl_pdata)) {
4140 octrl = mdss_dsi_get_other_ctrl(ctrl_pdata);
4141 if (octrl && octrl->panel_data.panel_info.is_prim_panel)
4142 pinfo->is_prim_panel = false;
4143 else
4144 pinfo->is_prim_panel = true;
4145 }
4146 }
4147}
4148
4149int dsi_panel_device_register(struct platform_device *ctrl_pdev,
4150 struct device_node *pan_node, struct mdss_dsi_ctrl_pdata *ctrl_pdata)
4151{
4152 struct mipi_panel_info *mipi;
4153 int rc;
4154 struct dsi_shared_data *sdata;
4155 struct mdss_panel_info *pinfo = &(ctrl_pdata->panel_data.panel_info);
4156 struct resource *res;
4157 u64 clk_rate;
4158
4159 mipi = &(pinfo->mipi);
4160
4161 pinfo->type =
4162 ((mipi->mode == DSI_VIDEO_MODE)
4163 ? MIPI_VIDEO_PANEL : MIPI_CMD_PANEL);
4164
4165 rc = mdss_dsi_clk_div_config(pinfo, mipi->frame_rate);
4166 if (rc) {
4167 pr_err("%s: unable to initialize the clk dividers\n", __func__);
4168 return rc;
4169 }
4170 ctrl_pdata->pclk_rate = mipi->dsi_pclk_rate;
4171 clk_rate = pinfo->clk_rate;
4172 do_div(clk_rate, 8U);
4173 ctrl_pdata->byte_clk_rate = (u32)clk_rate;
4174 pr_debug("%s: pclk=%d, bclk=%d\n", __func__,
4175 ctrl_pdata->pclk_rate, ctrl_pdata->byte_clk_rate);
4176
4177
4178 rc = mdss_dsi_get_dt_vreg_data(&ctrl_pdev->dev, pan_node,
4179 &ctrl_pdata->panel_power_data, DSI_PANEL_PM);
4180 if (rc) {
4181 DEV_ERR("%s: '%s' get_dt_vreg_data failed.rc=%d\n",
4182 __func__, __mdss_dsi_pm_name(DSI_PANEL_PM), rc);
4183 return rc;
4184 }
4185
4186 rc = msm_dss_config_vreg(&ctrl_pdev->dev,
4187 ctrl_pdata->panel_power_data.vreg_config,
4188 ctrl_pdata->panel_power_data.num_vreg, 1);
4189 if (rc) {
4190 pr_err("%s: failed to init regulator, rc=%d\n",
4191 __func__, rc);
4192 return rc;
4193 }
4194
4195 rc = mdss_dsi_parse_ctrl_params(ctrl_pdev, pan_node, ctrl_pdata);
4196 if (rc) {
4197 pr_err("%s: failed to parse ctrl settings, rc=%d\n",
4198 __func__, rc);
4199 return rc;
4200 }
4201
4202 pinfo->panel_max_fps = mdss_panel_get_framerate(pinfo,
4203 FPS_RESOLUTION_HZ);
4204 pinfo->panel_max_vtotal = mdss_panel_get_vtotal(pinfo);
4205
4206 rc = mdss_dsi_parse_gpio_params(ctrl_pdev, ctrl_pdata);
4207 if (rc) {
4208 pr_err("%s: failed to parse gpio params, rc=%d\n",
4209 __func__, rc);
4210 return rc;
4211 }
4212
4213 if (mdss_dsi_retrieve_ctrl_resources(ctrl_pdev,
4214 pinfo->pdest,
4215 ctrl_pdata)) {
4216 pr_err("%s: unable to get Dsi controller res\n", __func__);
4217 return -EPERM;
4218 }
4219
4220 ctrl_pdata->panel_data.event_handler = mdss_dsi_event_handler;
4221 ctrl_pdata->panel_data.get_fb_node = mdss_dsi_get_fb_node_cb;
4222
4223 if (ctrl_pdata->status_mode == ESD_REG ||
4224 ctrl_pdata->status_mode == ESD_REG_NT35596)
4225 ctrl_pdata->check_status = mdss_dsi_reg_status_check;
4226 else if (ctrl_pdata->status_mode == ESD_BTA)
4227 ctrl_pdata->check_status = mdss_dsi_bta_status_check;
4228
4229 if (ctrl_pdata->status_mode == ESD_MAX) {
4230 pr_err("%s: Using default BTA for ESD check\n", __func__);
4231 ctrl_pdata->check_status = mdss_dsi_bta_status_check;
4232 }
4233 if (ctrl_pdata->bklt_ctrl == BL_PWM)
4234 mdss_dsi_panel_pwm_cfg(ctrl_pdata);
4235
4236 mdss_dsi_ctrl_init(&ctrl_pdev->dev, ctrl_pdata);
4237 mdss_dsi_set_prim_panel(ctrl_pdata);
4238
4239 ctrl_pdata->dsi_irq_line = of_property_read_bool(
4240 ctrl_pdev->dev.of_node, "qcom,dsi-irq-line");
4241
4242 if (ctrl_pdata->dsi_irq_line) {
4243 /* DSI has it's own irq line */
4244 res = platform_get_resource(ctrl_pdev, IORESOURCE_IRQ, 0);
4245 if (!res || res->start == 0) {
4246 pr_err("%s:%d unable to get the MDSS irq resources\n",
4247 __func__, __LINE__);
4248 return -ENODEV;
4249 }
4250 rc = mdss_dsi_irq_init(&ctrl_pdev->dev, res->start, ctrl_pdata);
4251 if (rc) {
4252 dev_err(&ctrl_pdev->dev, "%s: failed to init irq\n",
4253 __func__);
4254 return rc;
4255 }
4256 }
4257 ctrl_pdata->ctrl_state = CTRL_STATE_UNKNOWN;
4258
4259 /*
4260 * If ULPS during suspend is enabled, add an extra vote for the
4261 * DSI CTRL power module. This keeps the regulator always enabled.
4262 * This is needed for the DSI PHY to maintain ULPS state during
4263 * suspend also.
4264 */
4265 sdata = ctrl_pdata->shared_data;
4266
4267 if (pinfo->ulps_suspend_enabled) {
4268 rc = msm_dss_enable_vreg(
4269 sdata->power_data[DSI_PHY_PM].vreg_config,
4270 sdata->power_data[DSI_PHY_PM].num_vreg, 1);
4271 if (rc) {
4272 pr_err("%s: failed to enable vregs for DSI_CTRL_PM\n",
4273 __func__);
4274 return rc;
4275 }
4276 }
4277
4278 pinfo->cont_splash_enabled =
4279 ctrl_pdata->mdss_util->panel_intf_status(pinfo->pdest,
4280 MDSS_PANEL_INTF_DSI) ? true : false;
4281
4282 pr_info("%s: Continuous splash %s\n", __func__,
4283 pinfo->cont_splash_enabled ? "enabled" : "disabled");
4284
4285 rc = mdss_register_panel(ctrl_pdev, &(ctrl_pdata->panel_data));
4286 if (rc) {
4287 pr_err("%s: unable to register MIPI DSI panel\n", __func__);
4288 return rc;
4289 }
4290
4291 if (pinfo->pdest == DISPLAY_1) {
4292 mdss_debug_register_io("dsi0_ctrl", &ctrl_pdata->ctrl_io, NULL);
4293 mdss_debug_register_io("dsi0_phy", &ctrl_pdata->phy_io, NULL);
4294 if (ctrl_pdata->phy_regulator_io.len)
4295 mdss_debug_register_io("dsi0_phy_regulator",
4296 &ctrl_pdata->phy_regulator_io, NULL);
4297 } else {
4298 mdss_debug_register_io("dsi1_ctrl", &ctrl_pdata->ctrl_io, NULL);
4299 mdss_debug_register_io("dsi1_phy", &ctrl_pdata->phy_io, NULL);
4300 if (ctrl_pdata->phy_regulator_io.len)
4301 mdss_debug_register_io("dsi1_phy_regulator",
4302 &ctrl_pdata->phy_regulator_io, NULL);
4303 }
4304
4305 panel_debug_register_base("panel",
4306 ctrl_pdata->ctrl_base, ctrl_pdata->reg_size);
4307
4308 pr_debug("%s: Panel data initialized\n", __func__);
4309 return 0;
4310}
4311
4312static const struct of_device_id mdss_dsi_dt_match[] = {
4313 {.compatible = "qcom,mdss-dsi"},
4314 {}
4315};
4316MODULE_DEVICE_TABLE(of, mdss_dsi_dt_match);
4317
4318static struct platform_driver mdss_dsi_driver = {
4319 .probe = mdss_dsi_probe,
4320 .remove = mdss_dsi_remove,
4321 .shutdown = NULL,
4322 .driver = {
4323 .name = "mdss_dsi",
4324 .of_match_table = mdss_dsi_dt_match,
4325 },
4326};
4327
4328static struct platform_driver mdss_dsi_ctrl_driver = {
4329 .probe = mdss_dsi_ctrl_probe,
4330 .remove = mdss_dsi_ctrl_remove,
4331 .shutdown = NULL,
4332 .driver = {
4333 .name = "mdss_dsi_ctrl",
4334 .of_match_table = mdss_dsi_ctrl_dt_match,
4335 },
4336};
4337
4338static int mdss_dsi_register_driver(void)
4339{
4340 return platform_driver_register(&mdss_dsi_driver);
4341}
4342
4343static int __init mdss_dsi_driver_init(void)
4344{
4345 int ret;
4346
4347 ret = mdss_dsi_register_driver();
4348 if (ret) {
4349 pr_err("mdss_dsi_register_driver() failed!\n");
4350 return ret;
4351 }
4352
4353 return ret;
4354}
4355module_init(mdss_dsi_driver_init);
4356
4357
4358static int mdss_dsi_ctrl_register_driver(void)
4359{
4360 return platform_driver_register(&mdss_dsi_ctrl_driver);
4361}
4362
4363static int __init mdss_dsi_ctrl_driver_init(void)
4364{
4365 int ret;
4366
4367 ret = mdss_dsi_ctrl_register_driver();
4368 if (ret) {
4369 pr_err("mdss_dsi_ctrl_register_driver() failed!\n");
4370 return ret;
4371 }
4372
4373 return ret;
4374}
4375module_init(mdss_dsi_ctrl_driver_init);
4376
4377static void __exit mdss_dsi_driver_cleanup(void)
4378{
4379 platform_driver_unregister(&mdss_dsi_ctrl_driver);
4380}
4381module_exit(mdss_dsi_driver_cleanup);
4382
4383MODULE_LICENSE("GPL v2");
4384MODULE_DESCRIPTION("DSI controller driver");