blob: 5cff4509c1e0034b5ca12b1a901048b0780aac7f [file] [log] [blame]
Raghavendra Ambadas70867fe2020-03-19 13:24:54 +05301/* Copyright (c) 2017-2018, 2020, The Linux Foundation. All rights reserved.
Arun kumardb962812018-05-30 16:31:52 +05302 *
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#include <linux/module.h>
14#include <linux/of_gpio.h>
15#include <linux/gpio.h>
16#include <linux/qpnp/pin.h>
17#include <linux/delay.h>
18#include <linux/interrupt.h>
19#include <linux/leds.h>
20#include <linux/qpnp/pwm.h>
21#include <linux/of_device.h>
22
23#include "mdss.h"
24#include "mdss_panel.h"
25#include "mdss_spi_panel.h"
26#include "mdss_spi_client.h"
27#include "mdp3.h"
28
29DEFINE_LED_TRIGGER(bl_led_trigger);
30static int mdss_spi_panel_reset(struct mdss_panel_data *pdata, int enable)
31{
32 struct spi_panel_data *ctrl_pdata = NULL;
33 struct mdss_panel_info *pinfo = NULL;
34 int i, rc = 0;
35
36 if (pdata == NULL) {
37 pr_err("%s: Invalid input data\n", __func__);
38 return -EINVAL;
39 }
40
41 ctrl_pdata = container_of(pdata, struct spi_panel_data,
42 panel_data);
43
44 if (!gpio_is_valid(ctrl_pdata->rst_gpio)) {
45 pr_debug("%s:%d, reset line not configured\n",
46 __func__, __LINE__);
47 return rc;
48 }
49
50 if (!gpio_is_valid(ctrl_pdata->disp_dc_gpio)) {
51 pr_debug("%s:%d, dc line not configured\n",
52 __func__, __LINE__);
53 return rc;
54 }
55
56 pr_debug("%s: enable = %d\n", __func__, enable);
57 pinfo = &(ctrl_pdata->panel_data.panel_info);
58
59 if (enable) {
60 rc = gpio_request(ctrl_pdata->rst_gpio, "disp_rst_n");
61 if (rc) {
62 pr_err("display reset gpio request failed\n");
63 return rc;
64 }
65
66 rc = gpio_request(ctrl_pdata->disp_dc_gpio, "disp_dc");
67 if (rc) {
68 pr_err("display dc gpio request failed\n");
69 return rc;
70 }
71
72 if (!pinfo->cont_splash_enabled) {
73 for (i = 0; i < pdata->panel_info.rst_seq_len; ++i) {
74 gpio_direction_output((ctrl_pdata->rst_gpio),
75 pdata->panel_info.rst_seq[i]);
76 if (pdata->panel_info.rst_seq[++i])
77 usleep_range(pinfo->rst_seq[i] * 1000,
78 pinfo->rst_seq[i] * 1000);
79 }
80 }
81
82 if (ctrl_pdata->ctrl_state & CTRL_STATE_PANEL_INIT) {
83 pr_debug("%s: Panel Not properly turned OFF\n",
84 __func__);
85 ctrl_pdata->ctrl_state &= ~CTRL_STATE_PANEL_INIT;
86 pr_err("%s: Reset panel done\n", __func__);
87 }
88 } else {
89 gpio_direction_output((ctrl_pdata->rst_gpio), 0);
90 gpio_free(ctrl_pdata->rst_gpio);
91
92 gpio_direction_output(ctrl_pdata->disp_dc_gpio, 0);
93 gpio_free(ctrl_pdata->disp_dc_gpio);
94 }
95 return rc;
96}
97
98
99static int mdss_spi_panel_pinctrl_set_state(
100 struct spi_panel_data *ctrl_pdata,
101 bool active)
102{
103 struct pinctrl_state *pin_state;
104 int rc = -EFAULT;
105
106 if (IS_ERR_OR_NULL(ctrl_pdata->pin_res.pinctrl))
107 return PTR_ERR(ctrl_pdata->pin_res.pinctrl);
108
109 pin_state = active ? ctrl_pdata->pin_res.gpio_state_active
110 : ctrl_pdata->pin_res.gpio_state_suspend;
111 if (!IS_ERR_OR_NULL(pin_state)) {
112 rc = pinctrl_select_state(ctrl_pdata->pin_res.pinctrl,
113 pin_state);
114 if (rc)
115 pr_err("%s: can not set %s pins\n", __func__,
116 active ? MDSS_PINCTRL_STATE_DEFAULT
117 : MDSS_PINCTRL_STATE_SLEEP);
118 } else {
119 pr_err("%s: invalid '%s' pinstate\n", __func__,
120 active ? MDSS_PINCTRL_STATE_DEFAULT
121 : MDSS_PINCTRL_STATE_SLEEP);
122 }
123 return rc;
124}
125
126
127static int mdss_spi_panel_pinctrl_init(struct platform_device *pdev)
128{
129 struct spi_panel_data *ctrl_pdata;
130
131 ctrl_pdata = platform_get_drvdata(pdev);
132 ctrl_pdata->pin_res.pinctrl = devm_pinctrl_get(&pdev->dev);
133 if (IS_ERR_OR_NULL(ctrl_pdata->pin_res.pinctrl)) {
134 pr_err("%s: failed to get pinctrl\n", __func__);
135 return PTR_ERR(ctrl_pdata->pin_res.pinctrl);
136 }
137
138 ctrl_pdata->pin_res.gpio_state_active
139 = pinctrl_lookup_state(ctrl_pdata->pin_res.pinctrl,
140 MDSS_PINCTRL_STATE_DEFAULT);
141 if (IS_ERR_OR_NULL(ctrl_pdata->pin_res.gpio_state_active))
142 pr_warn("%s: can not get default pinstate\n", __func__);
143
144 ctrl_pdata->pin_res.gpio_state_suspend
145 = pinctrl_lookup_state(ctrl_pdata->pin_res.pinctrl,
146 MDSS_PINCTRL_STATE_SLEEP);
147 if (IS_ERR_OR_NULL(ctrl_pdata->pin_res.gpio_state_suspend))
148 pr_warn("%s: can not get sleep pinstate\n", __func__);
149
150 return 0;
151}
152
153
154static int mdss_spi_panel_power_on(struct mdss_panel_data *pdata)
155{
156 int ret = 0;
157 struct spi_panel_data *ctrl_pdata = NULL;
158
159 if (pdata == NULL) {
160 pr_err("%s: Invalid input data\n", __func__);
161 return -EINVAL;
162 }
163
164 ctrl_pdata = container_of(pdata, struct spi_panel_data,
165 panel_data);
Krishna Manikandan695632e2020-03-04 20:50:28 +0530166 if (!mdp3_res->secure_reg_on) {
167 ret = msm_mdss_enable_vreg(
168 ctrl_pdata->panel_power_data.vreg_config,
169 ctrl_pdata->panel_power_data.num_vreg, 1);
170 if (ret) {
171 pr_err("%s: failed to enable vregs for %s\n",
172 __func__, "PANEL_PM");
173 }
Arun kumardb962812018-05-30 16:31:52 +0530174 }
175
176 /*
177 * If continuous splash screen feature is enabled, then we need to
178 * request all the GPIOs that have already been configured in the
179 * bootloader. This needs to be done irresepective of whether
180 * the lp11_init flag is set or not.
181 */
182 if (pdata->panel_info.cont_splash_enabled) {
183 if (mdss_spi_panel_pinctrl_set_state(ctrl_pdata, true))
184 pr_debug("reset enable: pinctrl not enabled\n");
185
186 ret = mdss_spi_panel_reset(pdata, 1);
187 if (ret)
188 pr_err("%s: Panel reset failed. rc=%d\n",
189 __func__, ret);
190 }
191
192 return ret;
193}
194
195
196static int mdss_spi_panel_power_off(struct mdss_panel_data *pdata)
197{
198 int ret = 0;
199 struct spi_panel_data *ctrl_pdata = NULL;
200
201 if (pdata == NULL) {
202 pr_err("%s: Invalid input data\n", __func__);
203 ret = -EINVAL;
204 goto end;
205 }
206 ctrl_pdata = container_of(pdata, struct spi_panel_data,
207 panel_data);
208
209 ret = mdss_spi_panel_reset(pdata, 0);
210 if (ret) {
211 pr_warn("%s: Panel reset failed. rc=%d\n", __func__, ret);
212 ret = 0;
213 }
214
215 if (mdss_spi_panel_pinctrl_set_state(ctrl_pdata, false))
216 pr_warn("reset disable: pinctrl not enabled\n");
217
Krishna Manikandan695632e2020-03-04 20:50:28 +0530218 if (!mdp3_res->secure_reg_on) {
219 ret = msm_mdss_enable_vreg(
220 ctrl_pdata->panel_power_data.vreg_config,
221 ctrl_pdata->panel_power_data.num_vreg, 0);
222 if (ret)
223 pr_err("%s: failed to disable vregs for %s\n",
224 __func__, "PANEL_PM");
225 }
Arun kumardb962812018-05-30 16:31:52 +0530226
227end:
228 return ret;
229}
230
231
232static int mdss_spi_panel_power_ctrl(struct mdss_panel_data *pdata,
233 int power_state)
234{
235 int ret;
236 struct mdss_panel_info *pinfo;
237
238 if (pdata == NULL) {
239 pr_err("%s: Invalid input data\n", __func__);
240 return -EINVAL;
241 }
242
243 pinfo = &pdata->panel_info;
244 pr_debug("%s: cur_power_state=%d req_power_state=%d\n", __func__,
245 pinfo->panel_power_state, power_state);
246
247 if (pinfo->panel_power_state == power_state) {
248 pr_debug("%s: no change needed\n", __func__);
249 return 0;
250 }
251
252 switch (power_state) {
253 case MDSS_PANEL_POWER_OFF:
254 ret = mdss_spi_panel_power_off(pdata);
255 break;
256 case MDSS_PANEL_POWER_ON:
257 ret = mdss_spi_panel_power_on(pdata);
258 break;
259 default:
260 pr_err("%s: unknown panel power state requested (%d)\n",
261 __func__, power_state);
262 ret = -EINVAL;
263 }
264
265 if (!ret)
266 pinfo->panel_power_state = power_state;
267
268 return ret;
269}
270
271static int mdss_spi_panel_unblank(struct mdss_panel_data *pdata)
272{
273 int ret = 0;
274 struct spi_panel_data *ctrl_pdata = NULL;
275
276 if (pdata == NULL) {
277 pr_err("%s: Invalid input data\n", __func__);
278 return -EINVAL;
279 }
280
281 ctrl_pdata = container_of(pdata, struct spi_panel_data,
282 panel_data);
283
284 if (!(ctrl_pdata->ctrl_state & CTRL_STATE_PANEL_INIT)) {
285 ret = ctrl_pdata->on(pdata);
286 if (ret) {
287 pr_err("%s: unable to initialize the panel\n",
288 __func__);
289 return ret;
290 }
291 ctrl_pdata->ctrl_state |= CTRL_STATE_PANEL_INIT;
292 }
293
294 return ret;
295}
296
297static int mdss_spi_panel_blank(struct mdss_panel_data *pdata, int power_state)
298{
299 int ret = 0;
300 struct spi_panel_data *ctrl_pdata = NULL;
301
302 if (pdata == NULL) {
303 pr_err("%s: Invalid input data\n", __func__);
304 return -EINVAL;
305 }
306
307 ctrl_pdata = container_of(pdata, struct spi_panel_data,
308 panel_data);
309
310 if (ctrl_pdata->ctrl_state & CTRL_STATE_PANEL_INIT) {
311 ret = ctrl_pdata->off(pdata);
312 if (ret) {
313 pr_err("%s: Panel OFF failed\n", __func__);
314 return ret;
315 }
316 ctrl_pdata->ctrl_state &= ~CTRL_STATE_PANEL_INIT;
317 }
318
319 return ret;
320}
321
322
323static int mdss_spi_panel_event_handler(struct mdss_panel_data *pdata,
324 int event, void *arg)
325{
326 int rc = 0;
327 struct spi_panel_data *ctrl_pdata = NULL;
328 int power_state;
329
330 if (pdata == NULL) {
331 pr_err("%s: Invalid input data\n", __func__);
332 return -EINVAL;
333 }
334 ctrl_pdata = container_of(pdata, struct spi_panel_data,
335 panel_data);
336
337 switch (event) {
338 case MDSS_EVENT_LINK_READY:
339 rc = mdss_spi_panel_power_ctrl(pdata, MDSS_PANEL_POWER_ON);
340 if (rc) {
341 pr_err("%s:Panel power on failed. rc=%d\n",
342 __func__, rc);
343 return rc;
344 }
345 mdss_spi_panel_pinctrl_set_state(ctrl_pdata, true);
346 mdss_spi_panel_reset(pdata, 1);
347 break;
348 case MDSS_EVENT_UNBLANK:
349 rc = mdss_spi_panel_unblank(pdata);
350 break;
351 case MDSS_EVENT_PANEL_ON:
352 ctrl_pdata->ctrl_state |= CTRL_STATE_MDP_ACTIVE;
353 break;
354 case MDSS_EVENT_BLANK:
355 power_state = (int) (unsigned long) arg;
356 break;
357 case MDSS_EVENT_PANEL_OFF:
358 power_state = (int) (unsigned long) arg;
359 ctrl_pdata->ctrl_state &= ~CTRL_STATE_MDP_ACTIVE;
360 rc = mdss_spi_panel_blank(pdata, power_state);
361 rc = mdss_spi_panel_power_ctrl(pdata, power_state);
362 break;
363 default:
364 pr_debug("%s: unhandled event=%d\n", __func__, event);
365 break;
366 }
367 pr_debug("%s-:event=%d, rc=%d\n", __func__, event, rc);
368 return rc;
369}
370
371int is_spi_panel_continuous_splash_on(struct mdss_panel_data *pdata)
372{
373 int i = 0, voltage = 0;
374 struct mdss_vreg *vreg;
375 int num_vreg;
376 struct spi_panel_data *ctrl_pdata = NULL;
377
378 ctrl_pdata = container_of(pdata, struct spi_panel_data,
379 panel_data);
380 vreg = ctrl_pdata->panel_power_data.vreg_config;
381 num_vreg = ctrl_pdata->panel_power_data.num_vreg;
382
383 for (i = 0; i < num_vreg; i++) {
384 if (regulator_is_enabled(vreg[i].vreg) <= 0)
385 return false;
386 voltage = regulator_get_voltage(vreg[i].vreg);
387 if (!(voltage >= vreg[i].min_voltage &&
388 voltage <= vreg[i].max_voltage))
389 return false;
390 }
391
392 return true;
393}
394
395static void enable_spi_panel_te_irq(struct spi_panel_data *ctrl_pdata,
396 bool enable)
397{
398 static bool is_enabled = true;
399
400 if (is_enabled == enable)
401 return;
402
403 if (!gpio_is_valid(ctrl_pdata->disp_te_gpio)) {
404 pr_err("%s:%d,SPI panel TE GPIO not configured\n",
405 __func__, __LINE__);
406 return;
407 }
408
409 if (enable)
410 enable_irq(gpio_to_irq(ctrl_pdata->disp_te_gpio));
411 else
412 disable_irq(gpio_to_irq(ctrl_pdata->disp_te_gpio));
413
414 is_enabled = enable;
415}
416
417int mdss_spi_panel_kickoff(struct mdss_panel_data *pdata,
418 char *buf, int len, int dma_stride)
419{
420 struct spi_panel_data *ctrl_pdata = NULL;
421 char *tx_buf;
422 int rc = 0;
423 int panel_yres;
424 int panel_xres;
425 int padding_length = 0;
426 int actual_stride = 0;
427 int byte_per_pixel = 0;
428 int scan_count = 0;
429
430 if (pdata == NULL) {
431 pr_err("%s: Invalid input data\n", __func__);
432 return -EINVAL;
433 }
434
435 ctrl_pdata = container_of(pdata, struct spi_panel_data,
436 panel_data);
437
438 tx_buf = ctrl_pdata->tx_buf;
439 panel_xres = ctrl_pdata->panel_data.panel_info.xres;
440 panel_yres = ctrl_pdata->panel_data.panel_info.yres;
441
442 byte_per_pixel = ctrl_pdata->panel_data.panel_info.bpp / 8;
443 actual_stride = panel_xres * byte_per_pixel;
444 padding_length = dma_stride - actual_stride;
445
446 /* remove the padding and copy to continuous buffer */
447 while (scan_count < panel_yres) {
448 memcpy((tx_buf + scan_count * actual_stride),
449 (buf + scan_count * (actual_stride + padding_length)),
450 actual_stride);
451 scan_count++;
452 }
453
454 enable_spi_panel_te_irq(ctrl_pdata, true);
455
456 mutex_lock(&ctrl_pdata->spi_tx_mutex);
457 reinit_completion(&ctrl_pdata->spi_panel_te);
458
459 rc = wait_for_completion_timeout(&ctrl_pdata->spi_panel_te,
460 msecs_to_jiffies(SPI_PANEL_TE_TIMEOUT));
461
462 if (rc == 0)
463 pr_err("wait panel TE time out\n");
464
465 rc = mdss_spi_tx_pixel(tx_buf, ctrl_pdata->byte_pre_frame);
466 mutex_unlock(&ctrl_pdata->spi_tx_mutex);
467
468 return rc;
469}
470
471static int mdss_spi_read_panel_data(struct mdss_panel_data *pdata,
472 u8 reg_addr, u8 *data, u8 len)
473{
474 int rc = 0;
475 struct spi_panel_data *ctrl_pdata = NULL;
476
477 ctrl_pdata = container_of(pdata, struct spi_panel_data,
478 panel_data);
479
480 mutex_lock(&ctrl_pdata->spi_tx_mutex);
481 gpio_direction_output(ctrl_pdata->disp_dc_gpio, 0);
482 rc = mdss_spi_read_data(reg_addr, data, len);
483 gpio_direction_output(ctrl_pdata->disp_dc_gpio, 1);
484 mutex_unlock(&ctrl_pdata->spi_tx_mutex);
485
486 return rc;
487}
488
489static int mdss_spi_panel_on(struct mdss_panel_data *pdata)
490{
491 struct spi_panel_data *ctrl = NULL;
492 struct mdss_panel_info *pinfo;
493 int i;
494
495 if (pdata == NULL) {
496 pr_err("%s: Invalid input data\n", __func__);
497 return -EINVAL;
498 }
499 pinfo = &pdata->panel_info;
500 ctrl = container_of(pdata, struct spi_panel_data,
501 panel_data);
502
503 for (i = 0; i < ctrl->on_cmds.cmd_cnt; i++) {
504 /* pull down dc gpio indicate this is command */
505 gpio_direction_output(ctrl->disp_dc_gpio, 0);
506 mdss_spi_tx_command(ctrl->on_cmds.cmds[i].command);
507 gpio_direction_output((ctrl->disp_dc_gpio), 1);
508
509 if (ctrl->on_cmds.cmds[i].dchdr.dlen > 1) {
510 mdss_spi_tx_parameter(ctrl->on_cmds.cmds[i].parameter,
511 ctrl->on_cmds.cmds[i].dchdr.dlen-1);
512 }
513 if (ctrl->on_cmds.cmds[i].dchdr.wait != 0)
514 msleep(ctrl->on_cmds.cmds[i].dchdr.wait);
515 }
516
517 pinfo->blank_state = MDSS_PANEL_BLANK_UNBLANK;
518
519 pr_debug("%s:-\n", __func__);
520
521 return 0;
522}
523
524
525static int mdss_spi_panel_off(struct mdss_panel_data *pdata)
526{
527 struct spi_panel_data *ctrl = NULL;
528 struct mdss_panel_info *pinfo;
529 int i;
530
531 if (pdata == NULL) {
532 pr_err("%s: Invalid input data\n", __func__);
533 return -EINVAL;
534 }
535
536 pinfo = &pdata->panel_info;
537 ctrl = container_of(pdata, struct spi_panel_data,
538 panel_data);
539
540 for (i = 0; i < ctrl->off_cmds.cmd_cnt; i++) {
541 /* pull down dc gpio indicate this is command */
542 gpio_direction_output(ctrl->disp_dc_gpio, 0);
543 mdss_spi_tx_command(ctrl->off_cmds.cmds[i].command);
544 gpio_direction_output((ctrl->disp_dc_gpio), 1);
545
546 if (ctrl->off_cmds.cmds[i].dchdr.dlen > 1) {
547 mdss_spi_tx_parameter(ctrl->off_cmds.cmds[i].parameter,
548 ctrl->off_cmds.cmds[i].dchdr.dlen-1);
549 }
550
551 if (ctrl->off_cmds.cmds[i].dchdr.wait != 0)
552 msleep(ctrl->off_cmds.cmds[i].dchdr.wait);
553 }
554
555 pinfo->blank_state = MDSS_PANEL_BLANK_BLANK;
556
557 pr_debug("%s:-\n", __func__);
558 return 0;
559}
560
561static void mdss_spi_put_dt_vreg_data(struct device *dev,
562 struct mdss_module_power *module_power)
563{
564 if (!module_power) {
565 pr_err("%s: invalid input\n", __func__);
566 return;
567 }
568
569 if (module_power->vreg_config) {
570 devm_kfree(dev, module_power->vreg_config);
571 module_power->vreg_config = NULL;
572 }
573 module_power->num_vreg = 0;
574}
575
576
577static int mdss_spi_get_panel_vreg_data(struct device *dev,
578 struct mdss_module_power *mp)
579{
580 int i = 0, rc = 0;
581 u32 tmp = 0;
582 struct device_node *of_node = NULL, *supply_node = NULL;
583 struct device_node *supply_root_node = NULL;
584
585 if (!dev || !mp) {
586 pr_err("%s: invalid input\n", __func__);
587 rc = -EINVAL;
588 return rc;
589 }
590
591 of_node = dev->of_node;
592
593 mp->num_vreg = 0;
594
595 supply_root_node = of_get_child_by_name(of_node,
596 "qcom,panel-supply-entries");
597
598 for_each_available_child_of_node(supply_root_node, supply_node) {
599 mp->num_vreg++;
600 }
601 if (mp->num_vreg == 0) {
602 pr_debug("%s: no vreg\n", __func__);
603 goto novreg;
604 } else {
605 pr_debug("%s: vreg found. count=%d\n", __func__, mp->num_vreg);
606 }
607
608 mp->vreg_config = kcalloc(mp->num_vreg, sizeof(struct mdss_vreg),
609 GFP_KERNEL);
610
611 if (mp->vreg_config != NULL) {
612 for_each_available_child_of_node(supply_root_node,
613 supply_node) {
614 const char *st = NULL;
615 /* vreg-name */
616 rc = of_property_read_string(supply_node,
617 "qcom,supply-name", &st);
618 if (rc) {
619 pr_err("%s: error reading name. rc=%d\n",
620 __func__, rc);
621 goto error;
622 }
623 snprintf(mp->vreg_config[i].vreg_name,
624 ARRAY_SIZE((mp->vreg_config[i].vreg_name)),
625 "%s", st);
626 /* vreg-min-voltage */
627 rc = of_property_read_u32(supply_node,
628 "qcom,supply-min-voltage", &tmp);
629 if (rc) {
630 pr_err("%s: error reading min volt. rc=%d\n",
631 __func__, rc);
632 goto error;
633 }
634 mp->vreg_config[i].min_voltage = tmp;
635
636 /* vreg-max-voltage */
637 rc = of_property_read_u32(supply_node,
638 "qcom,supply-max-voltage", &tmp);
639 if (rc) {
640 pr_err("%s: error reading max volt. rc=%d\n",
641 __func__, rc);
642 goto error;
643 }
644 mp->vreg_config[i].max_voltage = tmp;
645
646 /* enable-load */
647 rc = of_property_read_u32(supply_node,
648 "qcom,supply-enable-load", &tmp);
649 if (rc) {
650 pr_err("%s: error read enable load. rc=%d\n",
651 __func__, rc);
652 goto error;
653 }
654 mp->vreg_config[i].load[DSS_REG_MODE_ENABLE] = tmp;
655
656 /* disable-load */
657 rc = of_property_read_u32(supply_node,
658 "qcom,supply-disable-load", &tmp);
659 if (rc) {
660 pr_err("%s: error read disable load. rc=%d\n",
661 __func__, rc);
662 goto error;
663 }
664 mp->vreg_config[i].load[DSS_REG_MODE_DISABLE] = tmp;
665
666 /* pre-sleep */
667 rc = of_property_read_u32(supply_node,
668 "qcom,supply-pre-on-sleep", &tmp);
669 if (rc) {
670 pr_debug("%s: error read pre on value\n",
671 __func__);
672 rc = 0;
673 } else {
674 mp->vreg_config[i].pre_on_sleep = tmp;
675 }
676
677 rc = of_property_read_u32(supply_node,
678 "qcom,supply-pre-off-sleep", &tmp);
679 if (rc) {
680 pr_debug("%s: error read pre off value\n",
681 __func__);
682 rc = 0;
683 } else {
684 mp->vreg_config[i].pre_off_sleep = tmp;
685 }
686
687 /* post-sleep */
688 rc = of_property_read_u32(supply_node,
689 "qcom,supply-post-on-sleep", &tmp);
690 if (rc) {
691 pr_debug("%s: error read post on value\n",
692 __func__);
693 rc = 0;
694 } else {
695 mp->vreg_config[i].post_on_sleep = tmp;
696 }
697
698 rc = of_property_read_u32(supply_node,
699 "qcom,supply-post-off-sleep", &tmp);
700 if (rc) {
701 pr_debug("%s: error read post off value\n",
702 __func__);
703 rc = 0;
704 } else {
705 mp->vreg_config[i].post_off_sleep = tmp;
706 }
707
708 ++i;
709 }
710 }
711 return rc;
712error:
713 kfree(mp->vreg_config);
714 mp->vreg_config = NULL;
715
716novreg:
717 mp->num_vreg = 0;
718
719 return rc;
720
721}
722
723static int mdss_spi_panel_parse_cmds(struct device_node *np,
724 struct spi_panel_cmds *pcmds, char *cmd_key)
725{
726 const char *data;
727 int blen = 0, len;
728 char *buf, *bp;
729 struct spi_ctrl_hdr *dchdr;
730 int i, cnt;
731
732 data = of_get_property(np, cmd_key, &blen);
733 if (!data) {
734 pr_err("%s: failed, key=%s\n", __func__, cmd_key);
735 return -ENOMEM;
736 }
737
738 buf = kcalloc(blen, sizeof(char), GFP_KERNEL);
739 if (!buf)
740 return -ENOMEM;
741
742 memcpy(buf, data, blen);
743
744 /* scan dcs commands */
745 bp = buf;
746 len = blen;
747 cnt = 0;
748 while (len >= sizeof(*dchdr)) {
749 dchdr = (struct spi_ctrl_hdr *)bp;
750 if (dchdr->dlen > len) {
751 pr_err("%s: dtsi parse error, len=%d",
752 __func__, dchdr->dlen);
753 goto exit_free;
754 }
755 bp += sizeof(*dchdr);
756 len -= sizeof(*dchdr);
757 bp += dchdr->dlen;
758 len -= dchdr->dlen;
759 cnt++;
760 }
761
762 if (len != 0) {
763 pr_err("%s: dcs_cmd=%x len=%d error",
764 __func__, buf[0], len);
765 goto exit_free;
766 }
767
768 pcmds->cmds = kcalloc(cnt, sizeof(struct spi_cmd_desc),
769 GFP_KERNEL);
770 if (!pcmds->cmds)
771 goto exit_free;
772
773 pcmds->cmd_cnt = cnt;
774 pcmds->buf = buf;
775 pcmds->blen = blen;
776
777 bp = buf;
778 len = blen;
779 for (i = 0; i < cnt; i++) {
780 dchdr = (struct spi_ctrl_hdr *)bp;
781 len -= sizeof(*dchdr);
782 bp += sizeof(*dchdr);
783 pcmds->cmds[i].dchdr = *dchdr;
784 pcmds->cmds[i].command = bp;
785 pcmds->cmds[i].parameter = bp + sizeof(char);
786 bp += dchdr->dlen;
787 len -= dchdr->dlen;
788 }
789
790 pr_debug("%s: dcs_cmd=%x, len=%d, cmd_cnt=%d\n", __func__,
791 pcmds->buf[0], pcmds->blen, pcmds->cmd_cnt);
792
793 return 0;
794
795exit_free:
796 kfree(buf);
797 return -ENOMEM;
798}
799static int mdss_spi_panel_parse_reset_seq(struct device_node *np,
800 u32 rst_seq[MDSS_SPI_RST_SEQ_LEN], u32 *rst_len,
801 const char *name)
802{
803 int num = 0, i;
804 int rc;
805 struct property *data;
806 u32 tmp[MDSS_SPI_RST_SEQ_LEN];
807
808 *rst_len = 0;
809 data = of_find_property(np, name, &num);
810 num /= sizeof(u32);
811 if (!data || !num || num > MDSS_SPI_RST_SEQ_LEN || num % 2) {
812 pr_err("%s:%d, error reading %s, length found = %d\n",
813 __func__, __LINE__, name, num);
814 } else {
815 rc = of_property_read_u32_array(np, name, tmp, num);
816 if (rc)
817 pr_err("%s:%d, error reading %s, rc = %d\n",
818 __func__, __LINE__, name, rc);
819 else {
820 for (i = 0; i < num; ++i)
821 rst_seq[i] = tmp[i];
822 *rst_len = num;
823 }
824 }
825 return 0;
826}
827
828static bool mdss_send_panel_cmd_for_esd(struct spi_panel_data *ctrl_pdata)
829{
830
831 if (ctrl_pdata == NULL) {
832 pr_err("%s: Invalid input data\n", __func__);
833 return false;
834 }
835
836 mutex_lock(&ctrl_pdata->spi_tx_mutex);
837 mdss_spi_panel_on(&ctrl_pdata->panel_data);
838 mutex_unlock(&ctrl_pdata->spi_tx_mutex);
839
840 return true;
841}
842
843static bool mdss_spi_reg_status_check(struct spi_panel_data *ctrl_pdata)
844{
845 int ret = 0;
846 int i = 0;
847
848 if (ctrl_pdata == NULL) {
849 pr_err("%s: Invalid input data\n", __func__);
850 return false;
851 }
852
853 pr_debug("%s: Checking Register status\n", __func__);
854
855 ret = mdss_spi_read_panel_data(&ctrl_pdata->panel_data,
856 ctrl_pdata->panel_status_reg,
857 ctrl_pdata->act_status_value,
858 ctrl_pdata->status_cmds_rlen);
859 if (ret < 0) {
860 pr_err("%s: Read status register returned error\n", __func__);
861 } else {
862 for (i = 0; i < ctrl_pdata->status_cmds_rlen; i++) {
863 pr_debug("act_value[%d] = %x, exp_value[%d] = %x\n",
864 i, ctrl_pdata->act_status_value[i],
865 i, ctrl_pdata->exp_status_value[i]);
866 if (ctrl_pdata->act_status_value[i] !=
867 ctrl_pdata->exp_status_value[i])
868 return false;
869 }
870 }
871
872 return true;
873}
874
875static void mdss_spi_parse_esd_params(struct device_node *np,
876 struct spi_panel_data *ctrl)
877{
878 u32 tmp;
879 int rc;
880 struct property *data;
881 const char *string;
882 struct mdss_panel_info *pinfo = &ctrl->panel_data.panel_info;
883
884 pinfo->esd_check_enabled = of_property_read_bool(np,
885 "qcom,esd-check-enabled");
886
887 if (!pinfo->esd_check_enabled)
888 return;
889
890 ctrl->status_mode = SPI_ESD_MAX;
891
892 rc = of_property_read_string(np,
893 "qcom,mdss-spi-panel-status-check-mode", &string);
894 if (!rc) {
895 if (!strcmp(string, "reg_read")) {
896 ctrl->status_mode = SPI_ESD_REG;
897 ctrl->check_status =
898 mdss_spi_reg_status_check;
899 } else if (!strcmp(string, "send_init_command")) {
900 ctrl->status_mode = SPI_SEND_PANEL_COMMAND;
901 ctrl->check_status =
902 mdss_send_panel_cmd_for_esd;
903 return;
904 } else {
905 pr_err("No valid panel-status-check-mode string\n");
906 pinfo->esd_check_enabled = false;
907 return;
908 }
909 }
910
911 rc = of_property_read_u8(np, "qcom,mdss-spi-panel-status-reg",
912 &ctrl->panel_status_reg);
913 if (rc) {
914 pr_warn("%s:%d, Read status reg failed, disable ESD check\n",
915 __func__, __LINE__);
916 pinfo->esd_check_enabled = false;
917 return;
918 }
919
920 rc = of_property_read_u32(np, "qcom,mdss-spi-panel-status-read-length",
921 &tmp);
922 if (rc) {
923 pr_warn("%s:%d, Read reg length failed, disable ESD check\n",
924 __func__, __LINE__);
925 pinfo->esd_check_enabled = false;
926 return;
927 }
928
929 ctrl->status_cmds_rlen = (!rc ? tmp : 1);
930
931 ctrl->exp_status_value = kzalloc(sizeof(u8) *
932 (ctrl->status_cmds_rlen + 1), GFP_KERNEL);
933 ctrl->act_status_value = kzalloc(sizeof(u8) *
934 (ctrl->status_cmds_rlen + 1), GFP_KERNEL);
935
936 if (!ctrl->exp_status_value || !ctrl->act_status_value) {
937 pr_err("%s: Error allocating memory for status buffer\n",
938 __func__);
939 pinfo->esd_check_enabled = false;
940 return;
941 }
942
943 data = of_find_property(np, "qcom,mdss-spi-panel-status-value", &tmp);
944 tmp /= sizeof(u8);
945 if (!data || (tmp != ctrl->status_cmds_rlen)) {
946 pr_err("%s: Panel status values not found\n", __func__);
947 pinfo->esd_check_enabled = false;
948 memset(ctrl->exp_status_value, 0, ctrl->status_cmds_rlen);
949 } else {
950 rc = of_property_read_u8_array(np,
951 "qcom,mdss-spi-panel-status-value",
952 ctrl->exp_status_value, tmp);
953 if (rc) {
954 pr_err("%s: Error reading panel status values\n",
955 __func__);
956 pinfo->esd_check_enabled = false;
957 memset(ctrl->exp_status_value, 0,
958 ctrl->status_cmds_rlen);
959 }
960 }
961}
962
963static int mdss_spi_panel_parse_dt(struct device_node *np,
964 struct spi_panel_data *ctrl_pdata)
965{
966 u32 tmp;
967 int rc;
968 const char *data;
969 struct mdss_panel_info *pinfo = &(ctrl_pdata->panel_data.panel_info);
970
971 pinfo->cont_splash_enabled = of_property_read_bool(np,
972 "qcom,cont-splash-enabled");
973
974 rc = of_property_read_u32(np, "qcom,mdss-spi-panel-width", &tmp);
975 if (rc) {
976 pr_err("%s: panel width not specified\n", __func__);
977 return -EINVAL;
978 }
979 pinfo->xres = (!rc ? tmp : 240);
980
981 rc = of_property_read_u32(np, "qcom,mdss-spi-panel-height", &tmp);
982 if (rc) {
983 pr_err("%s:panel height not specified\n", __func__);
984 return -EINVAL;
985 }
986 pinfo->yres = (!rc ? tmp : 320);
987
988 rc = of_property_read_u32(np,
989 "qcom,mdss-pan-physical-width-dimension", &tmp);
990 pinfo->physical_width = (!rc ? tmp : 0);
991 rc = of_property_read_u32(np,
992 "qcom,mdss-pan-physical-height-dimension", &tmp);
993 pinfo->physical_height = (!rc ? tmp : 0);
994 rc = of_property_read_u32(np, "qcom,mdss-spi-panel-framerate", &tmp);
995 pinfo->spi.frame_rate = (!rc ? tmp : 30);
996 rc = of_property_read_u32(np, "qcom,mdss-spi-h-front-porch", &tmp);
997 pinfo->lcdc.h_front_porch = (!rc ? tmp : 6);
998 rc = of_property_read_u32(np, "qcom,mdss-spi-h-back-porch", &tmp);
999 pinfo->lcdc.h_back_porch = (!rc ? tmp : 6);
1000 rc = of_property_read_u32(np, "qcom,mdss-spi-h-pulse-width", &tmp);
1001 pinfo->lcdc.h_pulse_width = (!rc ? tmp : 2);
1002 rc = of_property_read_u32(np, "qcom,mdss-spi-h-sync-skew", &tmp);
1003 pinfo->lcdc.hsync_skew = (!rc ? tmp : 0);
1004 rc = of_property_read_u32(np, "qcom,mdss-spi-v-back-porch", &tmp);
1005 pinfo->lcdc.v_back_porch = (!rc ? tmp : 6);
1006 rc = of_property_read_u32(np, "qcom,mdss-spi-v-front-porch", &tmp);
1007 pinfo->lcdc.v_front_porch = (!rc ? tmp : 6);
1008 rc = of_property_read_u32(np, "qcom,mdss-spi-v-pulse-width", &tmp);
1009 pinfo->lcdc.v_pulse_width = (!rc ? tmp : 2);
1010
1011
1012 rc = of_property_read_u32(np, "qcom,mdss-spi-bpp", &tmp);
1013 if (rc) {
1014 pr_err("%s: bpp not specified\n", __func__);
1015 return -EINVAL;
1016 }
1017 pinfo->bpp = (!rc ? tmp : 16);
1018
1019 pinfo->pdest = DISPLAY_1;
1020
1021 ctrl_pdata->bklt_ctrl = SPI_UNKNOWN_CTRL;
1022 data = of_get_property(np, "qcom,mdss-spi-bl-pmic-control-type", NULL);
1023 if (data) {
1024 if (!strcmp(data, "bl_ctrl_wled")) {
1025 led_trigger_register_simple("bkl-trigger",
1026 &bl_led_trigger);
1027 pr_debug("%s: SUCCESS-> WLED TRIGGER register\n",
1028 __func__);
1029 ctrl_pdata->bklt_ctrl = SPI_BL_WLED;
1030 } else if (!strcmp(data, "bl_gpio_pulse")) {
1031 led_trigger_register_simple("gpio-bklt-trigger",
1032 &bl_led_trigger);
1033 pr_debug("%s: SUCCESS-> GPIO PULSE TRIGGER register\n",
1034 __func__);
1035 ctrl_pdata->bklt_ctrl = SPI_BL_WLED;
1036 } else if (!strcmp(data, "bl_ctrl_pwm")) {
1037 ctrl_pdata->bklt_ctrl = SPI_BL_PWM;
1038 ctrl_pdata->pwm_pmi = of_property_read_bool(np,
1039 "qcom,mdss-spi-bl-pwm-pmi");
1040 rc = of_property_read_u32(np,
1041 "qcom,mdss-spi-bl-pmic-pwm-frequency", &tmp);
1042 if (rc) {
1043 pr_err("%s: Error, panel pwm_period\n",
1044 __func__);
1045 return -EINVAL;
1046 }
1047 ctrl_pdata->pwm_period = tmp;
1048 if (ctrl_pdata->pwm_pmi) {
1049 ctrl_pdata->pwm_bl = of_pwm_get(np, NULL);
1050 if (IS_ERR(ctrl_pdata->pwm_bl)) {
1051 pr_err("%s: Error, pwm device\n",
1052 __func__);
1053 ctrl_pdata->pwm_bl = NULL;
1054 return -EINVAL;
1055 }
1056 } else {
1057 rc = of_property_read_u32(np,
1058 "qcom,mdss-spi-bl-pmic-bank-select",
1059 &tmp);
1060 if (rc) {
1061 pr_err("%s: Error, lpg channel\n",
1062 __func__);
1063 return -EINVAL;
1064 }
1065 ctrl_pdata->pwm_lpg_chan = tmp;
1066 tmp = of_get_named_gpio(np,
1067 "qcom,mdss-spi-pwm-gpio", 0);
1068 ctrl_pdata->pwm_pmic_gpio = tmp;
1069 pr_debug("%s: Configured PWM bklt ctrl\n",
1070 __func__);
1071 }
1072 }
1073 }
1074 rc = of_property_read_u32(np, "qcom,mdss-brightness-max-level", &tmp);
1075 pinfo->brightness_max = (!rc ? tmp : MDSS_MAX_BL_BRIGHTNESS);
1076 rc = of_property_read_u32(np, "qcom,mdss-spi-bl-min-level", &tmp);
1077 pinfo->bl_min = (!rc ? tmp : 0);
1078 rc = of_property_read_u32(np, "qcom,mdss-spi-bl-max-level", &tmp);
1079 pinfo->bl_max = (!rc ? tmp : 255);
1080 ctrl_pdata->bklt_max = pinfo->bl_max;
1081
1082
1083 mdss_spi_panel_parse_reset_seq(np, pinfo->rst_seq,
1084 &(pinfo->rst_seq_len),
1085 "qcom,mdss-spi-reset-sequence");
1086
1087 mdss_spi_panel_parse_cmds(np, &ctrl_pdata->on_cmds,
1088 "qcom,mdss-spi-on-command");
1089
1090 mdss_spi_panel_parse_cmds(np, &ctrl_pdata->off_cmds,
1091 "qcom,mdss-spi-off-command");
1092
1093 mdss_spi_parse_esd_params(np, ctrl_pdata);
1094
1095
1096 return 0;
1097}
1098
1099static void mdss_spi_panel_pwm_cfg(struct spi_panel_data *ctrl)
1100{
1101 if (ctrl->pwm_pmi)
1102 return;
1103
1104 ctrl->pwm_bl = pwm_request(ctrl->pwm_lpg_chan, "lcd-bklt");
1105 if (ctrl->pwm_bl == NULL || IS_ERR(ctrl->pwm_bl)) {
1106 pr_err("%s: Error: lpg_chan=%d pwm request failed",
1107 __func__, ctrl->pwm_lpg_chan);
1108 }
1109 ctrl->pwm_enabled = 0;
1110}
1111
1112static void mdss_spi_panel_bklt_pwm(struct spi_panel_data *ctrl, int level)
1113{
1114 int ret;
1115 u32 duty;
1116 u32 period_ns;
1117
1118 if (ctrl->pwm_bl == NULL) {
1119 pr_err("%s: no PWM\n", __func__);
1120 return;
1121 }
1122
1123 if (level == 0) {
1124 if (ctrl->pwm_enabled) {
Raghavendra Ambadas70867fe2020-03-19 13:24:54 +05301125 ret = pwm_config(ctrl->pwm_bl, 0,
1126 ctrl->pwm_period * NSEC_PER_USEC);
Arun kumardb962812018-05-30 16:31:52 +05301127 if (ret)
Raghavendra Ambadas70867fe2020-03-19 13:24:54 +05301128 pr_err("%s: pwm_config() failed err=%d.\n",
Arun kumardb962812018-05-30 16:31:52 +05301129 __func__, ret);
1130 pwm_disable(ctrl->pwm_bl);
1131 }
1132 ctrl->pwm_enabled = 0;
1133 return;
1134 }
1135
1136 duty = level * ctrl->pwm_period;
1137 duty /= ctrl->bklt_max;
1138
1139 pr_debug("%s: bklt_ctrl=%d pwm_period=%d pwm_gpio=%d pwm_lpg_chan=%d\n",
1140 __func__, ctrl->bklt_ctrl, ctrl->pwm_period,
1141 ctrl->pwm_pmic_gpio, ctrl->pwm_lpg_chan);
1142
1143 if (ctrl->pwm_period >= USEC_PER_SEC) {
1144 ret = pwm_config_us(ctrl->pwm_bl, duty, ctrl->pwm_period);
1145 if (ret) {
1146 pr_err("%s: pwm_config_us() failed err=%d\n",
1147 __func__, ret);
1148 return;
1149 }
1150 } else {
1151 period_ns = ctrl->pwm_period * NSEC_PER_USEC;
1152 ret = pwm_config(ctrl->pwm_bl,
1153 level * period_ns / ctrl->bklt_max,
1154 period_ns);
1155 if (ret) {
1156 pr_err("%s: pwm_config() failed err=%d\n",
1157 __func__, ret);
1158 return;
1159 }
1160 }
1161
1162 if (!ctrl->pwm_enabled) {
1163 ret = pwm_enable(ctrl->pwm_bl);
1164 if (ret)
1165 pr_err("%s: pwm_enable() failed err=%d\n", __func__,
1166 ret);
1167 ctrl->pwm_enabled = 1;
1168 }
1169}
1170
1171static void mdss_spi_panel_bl_ctrl(struct mdss_panel_data *pdata,
1172 u32 bl_level)
1173{
Krishna Manikandan695632e2020-03-04 20:50:28 +05301174 /* Allow panel backlight update if secure UI is enabled */
1175 if (bl_level && !mdp3_res->secure_update_bl) {
Arun kumardb962812018-05-30 16:31:52 +05301176 mdp3_res->bklt_level = bl_level;
1177 mdp3_res->bklt_update = true;
1178 } else {
1179 mdss_spi_panel_bl_ctrl_update(pdata, bl_level);
1180 }
1181}
1182
1183#if defined(CONFIG_FB_MSM_MDSS_SPI_PANEL) && defined(CONFIG_SPI_QUP)
1184void mdss_spi_panel_bl_ctrl_update(struct mdss_panel_data *pdata,
1185 u32 bl_level)
1186{
1187 struct spi_panel_data *ctrl_pdata = NULL;
1188
1189 if (pdata == NULL) {
1190 pr_err("%s: Invalid input data\n", __func__);
1191 return;
1192 }
1193
1194 ctrl_pdata = container_of(pdata, struct spi_panel_data,
1195 panel_data);
1196
1197 if ((bl_level < pdata->panel_info.bl_min) && (bl_level != 0))
1198 bl_level = pdata->panel_info.bl_min;
1199
1200 switch (ctrl_pdata->bklt_ctrl) {
1201 case SPI_BL_WLED:
1202 led_trigger_event(bl_led_trigger, bl_level);
1203 break;
1204 case SPI_BL_PWM:
1205 mdss_spi_panel_bklt_pwm(ctrl_pdata, bl_level);
1206 break;
1207 default:
1208 pr_err("%s: Unknown bl_ctrl configuration %d\n",
1209 __func__, ctrl_pdata->bklt_ctrl);
1210 break;
1211 }
1212}
1213#endif
1214
1215static int mdss_spi_panel_init(struct device_node *node,
1216 struct spi_panel_data *ctrl_pdata,
1217 bool cmd_cfg_cont_splash)
1218{
1219 int rc = 0;
1220 static const char *panel_name;
1221 struct mdss_panel_info *pinfo;
1222
1223 if (!node || !ctrl_pdata) {
1224 pr_err("%s: Invalid arguments\n", __func__);
1225 return -ENODEV;
1226 }
1227
1228 pinfo = &ctrl_pdata->panel_data.panel_info;
1229
1230 pr_debug("%s:%d\n", __func__, __LINE__);
1231 pinfo->panel_name[0] = '\0';
1232 panel_name = of_get_property(node, "qcom,mdss-spi-panel-name", NULL);
1233 if (!panel_name) {
1234 pr_info("%s:%d, Panel name not specified\n",
1235 __func__, __LINE__);
1236 } else {
1237 pr_debug("%s: Panel Name = %s\n", __func__, panel_name);
1238 strlcpy(&pinfo->panel_name[0], panel_name, MDSS_MAX_PANEL_LEN);
1239 }
1240 rc = mdss_spi_panel_parse_dt(node, ctrl_pdata);
1241 if (rc) {
1242 pr_err("%s:%d panel dt parse failed\n", __func__, __LINE__);
1243 return rc;
1244 }
1245
1246 ctrl_pdata->byte_pre_frame = pinfo->xres * pinfo->yres * pinfo->bpp/8;
1247
1248 ctrl_pdata->tx_buf = kmalloc(ctrl_pdata->byte_pre_frame, GFP_KERNEL);
1249
1250 if (!cmd_cfg_cont_splash)
1251 pinfo->cont_splash_enabled = false;
1252
1253 pr_info("%s: Continuous splash %s\n", __func__,
1254 pinfo->cont_splash_enabled ? "enabled" : "disabled");
1255
1256 pinfo->dynamic_switch_pending = false;
1257 pinfo->is_lpm_mode = false;
1258 pinfo->esd_rdy = false;
1259
1260 ctrl_pdata->on = mdss_spi_panel_on;
1261 ctrl_pdata->off = mdss_spi_panel_off;
1262 ctrl_pdata->panel_data.set_backlight = mdss_spi_panel_bl_ctrl;
1263
1264 return 0;
1265}
1266
1267static int mdss_spi_get_panel_cfg(char *panel_cfg,
1268 struct spi_panel_data *ctrl_pdata)
1269{
1270 int rc;
1271 struct mdss_panel_cfg *pan_cfg = NULL;
1272
1273 if (!ctrl_pdata)
1274 return MDSS_PANEL_INTF_INVALID;
1275
1276 pan_cfg = ctrl_pdata->mdss_util->panel_intf_type(MDSS_PANEL_INTF_SPI);
1277 if (IS_ERR(pan_cfg)) {
1278 return PTR_ERR(pan_cfg);
1279 } else if (!pan_cfg) {
1280 panel_cfg[0] = 0;
1281 return 0;
1282 }
1283
1284 pr_debug("%s:%d: cfg:[%s]\n", __func__, __LINE__,
1285 pan_cfg->arg_cfg);
1286 ctrl_pdata->panel_data.panel_info.is_prim_panel = true;
1287 rc = strlcpy(panel_cfg, pan_cfg->arg_cfg,
1288 sizeof(pan_cfg->arg_cfg));
1289 return rc;
1290}
1291
1292static int mdss_spi_panel_regulator_init(struct platform_device *pdev)
1293{
1294 int rc = 0;
1295
1296 struct spi_panel_data *ctrl_pdata = NULL;
1297
1298 if (!pdev) {
1299 pr_err("%s: invalid input\n", __func__);
1300 return -EINVAL;
1301 }
1302
1303 ctrl_pdata = platform_get_drvdata(pdev);
1304 if (!ctrl_pdata) {
1305 pr_err("%s: invalid driver data\n", __func__);
1306 return -EINVAL;
1307 }
1308
1309 rc = msm_mdss_config_vreg(&pdev->dev,
1310 ctrl_pdata->panel_power_data.vreg_config,
1311 ctrl_pdata->panel_power_data.num_vreg, 1);
1312 if (rc)
1313 pr_err("%s: failed to init vregs for %s\n",
1314 __func__, "PANEL_PM");
1315
1316 return rc;
1317
1318}
1319
1320static irqreturn_t spi_panel_te_handler(int irq, void *data)
1321{
1322 struct spi_panel_data *ctrl_pdata = (struct spi_panel_data *)data;
1323 static int count = 2;
1324
1325 if (!ctrl_pdata) {
1326 pr_err("%s: SPI display not available\n", __func__);
1327 return IRQ_HANDLED;
1328 }
1329 complete(&ctrl_pdata->spi_panel_te);
1330
1331 if (ctrl_pdata->vsync_client.handler && !(--count)) {
1332 ctrl_pdata->vsync_client.handler(ctrl_pdata->vsync_client.arg);
1333 count = 2;
1334 }
1335
1336 return IRQ_HANDLED;
1337}
1338
1339void mdp3_spi_vsync_enable(struct mdss_panel_data *pdata,
1340 struct mdp3_notification *vsync_client)
1341{
1342 int updated = 0;
1343 struct spi_panel_data *ctrl_pdata = NULL;
1344
1345 if (pdata == NULL) {
1346 pr_err("%s: Invalid input data\n", __func__);
1347 return;
1348 }
1349
1350 ctrl_pdata = container_of(pdata, struct spi_panel_data,
1351 panel_data);
1352
1353 if (vsync_client) {
1354 if (ctrl_pdata->vsync_client.handler != vsync_client->handler) {
1355 ctrl_pdata->vsync_client = *vsync_client;
1356 updated = 1;
1357 }
1358 } else {
1359 if (ctrl_pdata->vsync_client.handler) {
1360 ctrl_pdata->vsync_client.handler = NULL;
1361 ctrl_pdata->vsync_client.arg = NULL;
1362 updated = 1;
1363 }
1364 }
1365
1366 if (updated) {
1367 if (vsync_client && vsync_client->handler)
1368 enable_spi_panel_te_irq(ctrl_pdata, true);
1369 else
1370 enable_spi_panel_te_irq(ctrl_pdata, false);
1371 }
1372}
1373
1374static struct device_node *mdss_spi_pref_prim_panel(
1375 struct platform_device *pdev)
1376{
1377 struct device_node *spi_pan_node = NULL;
1378
1379 pr_debug("%s:%d: Select primary panel from dt\n",
1380 __func__, __LINE__);
1381 spi_pan_node = of_parse_phandle(pdev->dev.of_node,
1382 "qcom,spi-pref-prim-pan", 0);
1383 if (!spi_pan_node)
1384 pr_err("%s:can't find panel phandle\n", __func__);
1385
1386 return spi_pan_node;
1387}
1388
1389static int spi_panel_device_register(struct device_node *pan_node,
1390 struct spi_panel_data *ctrl_pdata)
1391{
1392 int rc;
1393 struct mdss_panel_info *pinfo = &(ctrl_pdata->panel_data.panel_info);
1394 struct device_node *spi_ctrl_np = NULL;
1395 struct platform_device *ctrl_pdev = NULL;
1396
1397 pinfo->type = SPI_PANEL;
1398
1399 spi_ctrl_np = of_parse_phandle(pan_node,
1400 "qcom,mdss-spi-panel-controller", 0);
1401 if (!spi_ctrl_np) {
1402 pr_err("%s: SPI controller node not initialized\n", __func__);
1403 return -EPROBE_DEFER;
1404 }
1405
1406 ctrl_pdev = of_find_device_by_node(spi_ctrl_np);
1407 if (!ctrl_pdev) {
1408 of_node_put(spi_ctrl_np);
1409 pr_err("%s: SPI controller node not find\n", __func__);
1410 return -EPROBE_DEFER;
1411 }
1412
1413 rc = mdss_spi_panel_regulator_init(ctrl_pdev);
1414 if (rc) {
1415 pr_err("%s: failed to init regulator, rc=%d\n",
1416 __func__, rc);
1417 return rc;
1418 }
1419
1420 pinfo->panel_max_fps = mdss_panel_get_framerate(pinfo,
1421 FPS_RESOLUTION_HZ);
1422 pinfo->panel_max_vtotal = mdss_panel_get_vtotal(pinfo);
1423
1424 ctrl_pdata->disp_te_gpio = of_get_named_gpio(ctrl_pdev->dev.of_node,
1425 "qcom,platform-te-gpio", 0);
1426 if (!gpio_is_valid(ctrl_pdata->disp_te_gpio))
1427 pr_err("%s:%d, TE gpio not specified\n",
1428 __func__, __LINE__);
1429
1430 ctrl_pdata->disp_dc_gpio = of_get_named_gpio(ctrl_pdev->dev.of_node,
1431 "qcom,platform-spi-dc-gpio", 0);
1432 if (!gpio_is_valid(ctrl_pdata->disp_dc_gpio))
1433 pr_err("%s:%d, SPI DC gpio not specified\n",
1434 __func__, __LINE__);
1435
1436 ctrl_pdata->rst_gpio = of_get_named_gpio(ctrl_pdev->dev.of_node,
1437 "qcom,platform-reset-gpio", 0);
1438 if (!gpio_is_valid(ctrl_pdata->rst_gpio))
1439 pr_err("%s:%d, reset gpio not specified\n",
1440 __func__, __LINE__);
1441
1442 ctrl_pdata->panel_data.event_handler = mdss_spi_panel_event_handler;
1443
1444 if (ctrl_pdata->bklt_ctrl == SPI_BL_PWM)
1445 mdss_spi_panel_pwm_cfg(ctrl_pdata);
1446
1447 ctrl_pdata->ctrl_state = CTRL_STATE_UNKNOWN;
1448
1449 if (pinfo->cont_splash_enabled) {
1450 rc = mdss_spi_panel_power_ctrl(&(ctrl_pdata->panel_data),
1451 MDSS_PANEL_POWER_ON);
1452 if (rc) {
1453 pr_err("%s: Panel power on failed\n", __func__);
1454 return rc;
1455 }
1456 if (ctrl_pdata->bklt_ctrl == SPI_BL_PWM)
1457 ctrl_pdata->pwm_enabled = 1;
1458 pinfo->blank_state = MDSS_PANEL_BLANK_UNBLANK;
1459 ctrl_pdata->ctrl_state |=
1460 (CTRL_STATE_PANEL_INIT | CTRL_STATE_MDP_ACTIVE);
1461 } else {
1462 pinfo->panel_power_state = MDSS_PANEL_POWER_OFF;
1463 }
1464
1465 rc = mdss_register_panel(ctrl_pdev, &(ctrl_pdata->panel_data));
1466 if (rc) {
1467 pr_err("%s: unable to register SPI panel\n", __func__);
1468 return rc;
1469 }
1470
1471 pr_debug("%s: Panel data initialized\n", __func__);
1472 return 0;
1473}
1474
1475
1476/**
1477 * mdss_spi_find_panel_of_node(): find device node of spi panel
1478 * @pdev: platform_device of the spi ctrl node
1479 * @panel_cfg: string containing intf specific config data
1480 *
1481 * Function finds the panel device node using the interface
1482 * specific configuration data. This configuration data is
1483 * could be derived from the result of bootloader's GCDB
1484 * panel detection mechanism. If such config data doesn't
1485 * exist then this panel returns the default panel configured
1486 * in the device tree.
1487 *
1488 * returns pointer to panel node on success, NULL on error.
1489 */
1490static struct device_node *mdss_spi_find_panel_of_node(
1491 struct platform_device *pdev, char *panel_cfg)
1492{
1493 int len, i;
1494 int ctrl_id = pdev->id - 1;
1495 char panel_name[MDSS_MAX_PANEL_LEN] = "";
1496 char ctrl_id_stream[3] = "0:";
1497 char *stream = NULL, *pan = NULL;
1498 struct device_node *spi_pan_node = NULL, *mdss_node = NULL;
1499
1500 len = strlen(panel_cfg);
1501 if (!len) {
1502 /* no panel cfg chg, parse dt */
1503 pr_err("%s:%d: no cmd line cfg present\n",
1504 __func__, __LINE__);
1505 goto end;
1506 } else {
1507 if (ctrl_id == 1)
1508 strlcpy(ctrl_id_stream, "1:", 3);
1509
1510 stream = strnstr(panel_cfg, ctrl_id_stream, len);
1511 if (!stream) {
1512 pr_err("controller config is not present\n");
1513 goto end;
1514 }
1515 stream += 2;
1516
1517 pan = strnchr(stream, strlen(stream), ':');
1518 if (!pan) {
1519 strlcpy(panel_name, stream, MDSS_MAX_PANEL_LEN);
1520 } else {
1521 for (i = 0; (stream + i) < pan; i++)
1522 panel_name[i] = *(stream + i);
1523 panel_name[i] = 0;
1524 }
1525
1526 pr_debug("%s:%d:%s:%s\n", __func__, __LINE__,
1527 panel_cfg, panel_name);
1528
1529 mdss_node = of_parse_phandle(pdev->dev.of_node,
1530 "qcom,mdss-mdp", 0);
1531 if (!mdss_node) {
1532 pr_err("%s: %d: mdss_node null\n",
1533 __func__, __LINE__);
1534 return NULL;
1535 }
1536
1537 spi_pan_node = of_find_node_by_name(mdss_node,
1538 panel_name);
1539 if (!spi_pan_node) {
1540 pr_err("%s: invalid pan node, selecting prim panel\n",
1541 __func__);
1542 goto end;
1543 }
1544 return spi_pan_node;
1545 }
1546end:
1547 if (strcmp(panel_name, NONE_PANEL))
1548 spi_pan_node = mdss_spi_pref_prim_panel(pdev);
1549 of_node_put(mdss_node);
1550 return spi_pan_node;
1551}
1552
1553
1554static int mdss_spi_panel_probe(struct platform_device *pdev)
1555{
1556 int rc = 0;
1557 struct spi_panel_data *ctrl_pdata;
1558 struct mdss_panel_cfg *pan_cfg = NULL;
1559 struct device_node *spi_pan_node = NULL;
1560 bool cmd_cfg_cont_splash = true;
1561 char panel_cfg[MDSS_MAX_PANEL_LEN];
1562 struct mdss_util_intf *util;
1563 const char *ctrl_name;
1564
1565 util = mdss_get_util_intf();
1566 if (util == NULL) {
1567 pr_err("Failed to get mdss utility functions\n");
1568 return -ENODEV;
1569 }
1570
1571 if (!util->mdp_probe_done) {
1572 pr_err("%s: MDP not probed yet\n", __func__);
1573 return -EPROBE_DEFER;
1574 }
1575
1576 if (!pdev->dev.of_node) {
1577 pr_err("SPI driver only supports device tree probe\n");
1578 return -ENOTSUPP;
1579 }
1580
1581 pan_cfg = util->panel_intf_type(MDSS_PANEL_INTF_DSI);
1582 if (IS_ERR(pan_cfg)) {
1583 pr_err("%s: return MDSS_PANEL_INTF_DSI\n", __func__);
1584 return PTR_ERR(pan_cfg);
1585 } else if (pan_cfg) {
1586 pr_err("%s: DSI is primary\n", __func__);
1587 return -ENODEV;
1588 }
1589
1590 ctrl_pdata = platform_get_drvdata(pdev);
1591 if (!ctrl_pdata) {
1592 ctrl_pdata = devm_kzalloc(&pdev->dev,
1593 sizeof(struct spi_panel_data),
1594 GFP_KERNEL);
1595 if (!ctrl_pdata) {
1596 pr_err("%s: FAILED: cannot alloc spi panel\n",
1597 __func__);
1598 rc = -ENOMEM;
1599 goto error_no_mem;
1600 }
1601 platform_set_drvdata(pdev, ctrl_pdata);
1602 }
1603
1604 ctrl_pdata->mdss_util = util;
1605
1606 ctrl_name = of_get_property(pdev->dev.of_node, "label", NULL);
1607 if (!ctrl_name)
1608 pr_info("%s:%d, Ctrl name not specified\n",
1609 __func__, __LINE__);
1610 else
1611 pr_debug("%s: Ctrl name = %s\n",
1612 __func__, ctrl_name);
1613
1614
1615 rc = of_platform_populate(pdev->dev.of_node,
1616 NULL, NULL, &pdev->dev);
1617 if (rc) {
1618 dev_err(&pdev->dev,
1619 "%s: failed to add child nodes, rc=%d\n",
1620 __func__, rc);
1621 goto error_no_mem;
1622 }
1623
1624 rc = mdss_spi_panel_pinctrl_init(pdev);
1625 if (rc)
1626 pr_warn("%s: failed to get pin resources\n", __func__);
1627
1628 rc = mdss_spi_get_panel_vreg_data(&pdev->dev,
1629 &ctrl_pdata->panel_power_data);
1630 if (rc) {
1631 dev_err(&pdev->dev,
1632 "%s: failed to get panel vreg data, rc=%d\n",
1633 __func__, rc);
1634 goto error_vreg;
1635 }
1636
1637 /* SPI panels can be different between controllers */
1638 rc = mdss_spi_get_panel_cfg(panel_cfg, ctrl_pdata);
1639 if (!rc)
1640 /* spi panel cfg not present */
1641 pr_warn("%s:%d:spi specific cfg not present\n",
1642 __func__, __LINE__);
1643
1644 /* find panel device node */
1645 spi_pan_node = mdss_spi_find_panel_of_node(pdev, panel_cfg);
1646 if (!spi_pan_node) {
1647 pr_err("%s: can't find panel node %s\n", __func__, panel_cfg);
1648 goto error_pan_node;
1649 }
1650
1651 cmd_cfg_cont_splash = true;
1652
1653 rc = mdss_spi_panel_init(spi_pan_node, ctrl_pdata, cmd_cfg_cont_splash);
1654 if (rc) {
1655 pr_err("%s: spi panel init failed\n", __func__);
1656 goto error_pan_node;
1657 }
1658
1659 rc = spi_panel_device_register(spi_pan_node, ctrl_pdata);
1660 if (rc) {
1661 pr_err("%s: spi panel dev reg failed\n", __func__);
1662 goto error_pan_node;
1663 }
1664
1665 ctrl_pdata->panel_data.event_handler = mdss_spi_panel_event_handler;
1666
1667
1668 init_completion(&ctrl_pdata->spi_panel_te);
1669 mutex_init(&ctrl_pdata->spi_tx_mutex);
1670
1671 rc = devm_request_irq(&pdev->dev,
1672 gpio_to_irq(ctrl_pdata->disp_te_gpio),
1673 spi_panel_te_handler, IRQF_TRIGGER_RISING,
1674 "TE_GPIO", ctrl_pdata);
1675 if (rc) {
1676 pr_err("TE request_irq failed.\n");
1677 return rc;
1678 }
1679
1680 pr_debug("%s: spi panel initialized\n", __func__);
1681 return 0;
1682
1683error_pan_node:
1684 of_node_put(spi_pan_node);
1685error_vreg:
1686 mdss_spi_put_dt_vreg_data(&pdev->dev,
1687 &ctrl_pdata->panel_power_data);
1688error_no_mem:
1689 devm_kfree(&pdev->dev, ctrl_pdata);
1690 return rc;
1691}
1692
1693
1694static const struct of_device_id mdss_spi_panel_match[] = {
1695 { .compatible = "qcom,mdss-spi-display" },
1696 {},
1697};
1698
1699static struct platform_driver this_driver = {
1700 .probe = mdss_spi_panel_probe,
1701 .driver = {
1702 .name = "spi_panel",
1703 .owner = THIS_MODULE,
1704 .of_match_table = mdss_spi_panel_match,
1705 },
1706};
1707
1708static int __init mdss_spi_display_init(void)
1709{
1710 int ret;
1711
1712 ret = platform_driver_register(&this_driver);
1713 return 0;
1714}
1715module_init(mdss_spi_display_init);
1716
1717MODULE_DEVICE_TABLE(of, mdss_spi_panel_match);
1718MODULE_LICENSE("GPL v2");