2 * drivers/video/tegra/dc/dsi.c
4 * Copyright (c) 2011-2014, NVIDIA CORPORATION, All rights reserved.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/kernel.h>
18 #include <linux/clk.h>
19 #include <linux/delay.h>
20 #include <linux/err.h>
22 #include <linux/gpio.h>
23 #include <linux/interrupt.h>
24 #include <linux/slab.h>
25 #include <linux/spinlock.h>
26 #include <linux/workqueue.h>
27 #include <linux/moduleparam.h>
28 #include <linux/export.h>
29 #include <linux/debugfs.h>
30 #include <linux/seq_file.h>
31 #include <linux/nvhost.h>
32 #include <linux/lcm.h>
33 #include <linux/gcd.h>
34 #include <linux/regulator/consumer.h>
35 #include <linux/pm_runtime.h>
36 #include <linux/clk/tegra.h>
37 #include <linux/tegra-soc.h>
38 #include <linux/nvhost.h>
39 #include <linux/of_address.h>
52 /* HACK! This needs to come from DT */
53 #include "../../../../arch/arm/mach-tegra/iomap.h"
55 #define APB_MISC_GP_MIPI_PAD_CTRL_0 (TEGRA_APB_MISC_BASE + 0x820)
56 #define DSIB_MODE_ENABLE 0x2
58 /* Only enabling for T124 for now; causes issues for other chips */
59 #ifdef CONFIG_ARCH_TEGRA_12x_SOC
60 #define DSI_USE_SYNC_POINTS 1
62 #define DSI_USE_SYNC_POINTS 0
65 #define S_TO_MS(x) (1000 * (x))
66 #define MS_TO_US(x) (1000 * (x))
68 #define DSI_MODULE_NOT_INIT 0x0
69 #define DSI_MODULE_INIT 0x1
71 #define DSI_LPHS_NOT_INIT 0x0
72 #define DSI_LPHS_IN_LP_MODE 0x1
73 #define DSI_LPHS_IN_HS_MODE 0x2
75 #define DSI_VIDEO_TYPE_NOT_INIT 0x0
76 #define DSI_VIDEO_TYPE_VIDEO_MODE 0x1
77 #define DSI_VIDEO_TYPE_CMD_MODE 0x2
79 #define DSI_DRIVEN_MODE_NOT_INIT 0x0
80 #define DSI_DRIVEN_MODE_DC 0x1
81 #define DSI_DRIVEN_MODE_HOST 0x2
83 #define DSI_PHYCLK_OUT_DIS 0x0
84 #define DSI_PHYCLK_OUT_EN 0x1
86 #define DSI_PHYCLK_NOT_INIT 0x0
87 #define DSI_PHYCLK_CONTINUOUS 0x1
88 #define DSI_PHYCLK_TX_ONLY 0x2
90 #define DSI_CLK_BURST_NOT_INIT 0x0
91 #define DSI_CLK_BURST_NONE_BURST 0x1
92 #define DSI_CLK_BURST_BURST_MODE 0x2
94 #define DSI_DC_STREAM_DISABLE 0x0
95 #define DSI_DC_STREAM_ENABLE 0x1
97 #define DSI_LP_OP_NOT_INIT 0x0
98 #define DSI_LP_OP_WRITE 0x1
99 #define DSI_LP_OP_READ 0x2
101 #define DSI_HOST_IDLE_PERIOD 1000
102 static atomic_t dsi_syncpt_rst = ATOMIC_INIT(0);
104 static bool enable_read_debug;
105 module_param(enable_read_debug, bool, 0644);
106 MODULE_PARM_DESC(enable_read_debug,
107 "Enable to print read fifo and return packet type");
109 bool tegra_dsi_enable_read_debug(struct tegra_dc_dsi_data *dsi)
111 enable_read_debug = true;
112 return enable_read_debug;
115 bool tegra_dsi_disable_read_debug(struct tegra_dc_dsi_data *dsi)
117 enable_read_debug = false;
118 return enable_read_debug;
121 /* source of video data */
123 TEGRA_DSI_DRIVEN_BY_DC,
124 TEGRA_DSI_DRIVEN_BY_HOST,
127 const u32 dsi_pkt_seq_reg[NUMOF_PKT_SEQ] = {
142 const u32 dsi_pkt_seq_video_non_burst_syne[NUMOF_PKT_SEQ] = {
143 PKT_ID0(CMD_VS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
145 PKT_ID0(CMD_VE) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
147 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
149 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(1) |
150 PKT_ID2(CMD_HE) | PKT_LEN2(0),
151 PKT_ID3(CMD_BLNK) | PKT_LEN3(2) | PKT_ID4(CMD_RGB) | PKT_LEN4(3) |
152 PKT_ID5(CMD_BLNK) | PKT_LEN5(4),
153 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
155 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(1) |
156 PKT_ID2(CMD_HE) | PKT_LEN2(0),
157 PKT_ID3(CMD_BLNK) | PKT_LEN3(2) | PKT_ID4(CMD_RGB) | PKT_LEN4(3) |
158 PKT_ID5(CMD_BLNK) | PKT_LEN5(4),
161 const u32 dsi_pkt_seq_video_non_burst[NUMOF_PKT_SEQ] = {
162 PKT_ID0(CMD_VS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
164 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
166 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
168 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2) |
169 PKT_ID2(CMD_RGB) | PKT_LEN2(3),
170 PKT_ID3(CMD_BLNK) | PKT_LEN3(4),
171 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
173 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2) |
174 PKT_ID2(CMD_RGB) | PKT_LEN2(3),
175 PKT_ID3(CMD_BLNK) | PKT_LEN3(4),
178 const u32 dsi_pkt_seq_video_non_burst_no_eot_no_lp_no_hbp[NUMOF_PKT_SEQ] = {
179 PKT_ID0(CMD_VS) | PKT_LEN0(0),
181 PKT_ID0(CMD_HS) | PKT_LEN0(0),
183 PKT_ID0(CMD_HS) | PKT_LEN0(0),
185 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_RGB) | PKT_LEN1(3) |
186 PKT_ID2(CMD_BLNK) | PKT_LEN2(4),
188 PKT_ID0(CMD_HS) | PKT_LEN0(0),
190 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_RGB) | PKT_LEN1(3) |
191 PKT_ID2(CMD_BLNK) | PKT_LEN2(4),
195 static const u32 dsi_pkt_seq_video_burst[NUMOF_PKT_SEQ] = {
196 PKT_ID0(CMD_VS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
198 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
200 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
202 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2)|
203 PKT_ID2(CMD_RGB) | PKT_LEN2(3) | PKT_LP,
204 PKT_ID0(CMD_EOT) | PKT_LEN0(7),
205 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
207 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2)|
208 PKT_ID2(CMD_RGB) | PKT_LEN2(3) | PKT_LP,
209 PKT_ID0(CMD_EOT) | PKT_LEN0(7),
212 static const u32 dsi_pkt_seq_video_burst_no_eot[NUMOF_PKT_SEQ] = {
213 PKT_ID0(CMD_VS) | PKT_LEN0(0) | PKT_LP,
215 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_LP,
217 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_LP,
219 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2)|
220 PKT_ID2(CMD_RGB) | PKT_LEN2(3) | PKT_LP,
222 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_LP,
224 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2)|
225 PKT_ID2(CMD_RGB) | PKT_LEN2(3) | PKT_LP,
229 const u32 dsi_pkt_seq_video_non_burst_no_eot[NUMOF_PKT_SEQ] = {
230 PKT_ID0(CMD_VS) | PKT_LEN0(0) | PKT_LP,
232 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_LP,
234 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_LP,
236 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2) |
237 PKT_ID2(CMD_RGB) | PKT_LEN2(3),
238 PKT_ID3(CMD_BLNK) | PKT_LEN3(4),
239 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_LP,
241 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2) |
242 PKT_ID2(CMD_RGB) | PKT_LEN2(3),
243 PKT_ID3(CMD_BLNK) | PKT_LEN3(4),
246 const u32 dsi_pkt_seq_cmd_mode[NUMOF_PKT_SEQ] = {
253 PKT_ID0(CMD_LONGW) | PKT_LEN0(3) | PKT_ID1(CMD_EOT) |
254 PKT_LEN1(7) | PKT_LP,
258 PKT_ID0(CMD_LONGW) | PKT_LEN0(3) | PKT_ID1(CMD_EOT) |
259 PKT_LEN1(7) | PKT_LP,
263 const u32 init_reg[] = {
289 DSI_HOST_DSI_CONTROL,
296 DSI_INIT_SEQ_CONTROL,
303 const u32 init_reg_vs1_ext[] = {
304 DSI_PAD_CONTROL_0_VS1,
305 DSI_PAD_CONTROL_CD_VS1,
306 DSI_PAD_CD_STATUS_VS1,
307 DSI_PAD_CONTROL_1_VS1,
308 DSI_PAD_CONTROL_2_VS1,
309 DSI_PAD_CONTROL_3_VS1,
310 DSI_PAD_CONTROL_4_VS1,
311 DSI_GANGED_MODE_CONTROL,
312 DSI_GANGED_MODE_START,
313 DSI_GANGED_MODE_SIZE,
316 static int tegra_dsi_host_suspend(struct tegra_dc *dc);
317 static int tegra_dsi_host_resume(struct tegra_dc *dc);
318 static void tegra_dc_dsi_idle_work(struct work_struct *work);
319 static void tegra_dsi_send_dc_frames(struct tegra_dc *dc,
320 struct tegra_dc_dsi_data *dsi,
323 unsigned long tegra_dsi_controller_readl(struct tegra_dc_dsi_data *dsi,
328 BUG_ON(!nvhost_module_powered_ext(dsi->dc->ndev));
329 ret = readl(dsi->base[index] + reg * 4);
330 trace_display_readl(dsi->dc, ret, dsi->base[index] + reg * 4);
333 EXPORT_SYMBOL(tegra_dsi_controller_readl);
335 void tegra_dsi_controller_writel(struct tegra_dc_dsi_data *dsi,
336 u32 val, u32 reg, int index)
338 BUG_ON(!nvhost_module_powered_ext(dsi->dc->ndev));
339 trace_display_writel(dsi->dc, val, dsi->base[index] + reg * 4);
340 writel(val, dsi->base[index] + reg * 4);
342 EXPORT_SYMBOL(tegra_dsi_controller_writel);
344 unsigned long tegra_dsi_readl(struct tegra_dc_dsi_data *dsi, u32 reg)
347 BUG_ON(!nvhost_module_powered_ext(dsi->dc->ndev));
348 ret = readl(dsi->base[DSI_INSTANCE_0] + reg * 4);
349 trace_display_readl(dsi->dc, ret, dsi->base[DSI_INSTANCE_0] + reg * 4);
352 EXPORT_SYMBOL(tegra_dsi_readl);
354 void tegra_dsi_writel(struct tegra_dc_dsi_data *dsi, u32 val, u32 reg)
357 BUG_ON(!nvhost_module_powered_ext(dsi->dc->ndev));
358 for (i = 0; i < dsi->max_instances; i++) {
359 trace_display_writel(dsi->dc, val, dsi->base[i] + reg * 4);
360 writel(val, dsi->base[i] + reg * 4);
363 EXPORT_SYMBOL(tegra_dsi_writel);
365 inline void tegra_dsi_reset_deassert(struct tegra_dc_dsi_data *dsi)
368 for (i = 0; i < dsi->max_instances; i++)
369 tegra_periph_reset_deassert(dsi->dsi_clk[i]);
372 inline void tegra_dsi_reset_assert(struct tegra_dc_dsi_data *dsi)
375 for (i = 0; i < dsi->max_instances; i++)
376 tegra_periph_reset_assert(dsi->dsi_clk[i]);
379 static inline void tegra_dsi_lp_clk_enable(struct tegra_dc_dsi_data *dsi);
380 static inline void tegra_dsi_lp_clk_disable(struct tegra_dc_dsi_data *dsi);
382 void tegra_dsi_clk_enable(struct tegra_dc_dsi_data *dsi)
385 for (i = 0; i < dsi->max_instances; i++) {
386 clk_prepare_enable(dsi->dsi_clk[i]);
391 void tegra_dsi_clk_disable(struct tegra_dc_dsi_data *dsi)
394 for (i = 0; i < dsi->max_instances; i++) {
395 clk_disable_unprepare(dsi->dsi_clk[i]);
400 static inline void tegra_dsi_lp_clk_enable(struct tegra_dc_dsi_data *dsi)
403 for (i = 0; i < dsi->max_instances; i++) {
404 clk_prepare_enable(dsi->dsi_lp_clk[i]);
409 static inline void tegra_dsi_lp_clk_disable(struct tegra_dc_dsi_data *dsi)
412 for (i = 0; i < dsi->max_instances; i++) {
413 clk_disable_unprepare(dsi->dsi_lp_clk[i]);
418 static void tegra_dsi_setup_clk(struct tegra_dc *dc,
419 struct tegra_dc_dsi_data *dsi)
422 for (i = 0; i < dsi->max_instances; i++) {
423 tegra_dc_setup_clk(dc, dsi->dsi_clk[i]);
428 static void __maybe_unused tegra_dsi_syncpt_reset(
429 struct tegra_dc_dsi_data *dsi)
431 tegra_dsi_writel(dsi, 0x1, DSI_INCR_SYNCPT_CNTRL);
432 /* stabilization delay */
434 tegra_dsi_writel(dsi, 0x0, DSI_INCR_SYNCPT_CNTRL);
435 /* stabilization delay */
439 static int __maybe_unused tegra_dsi_syncpt
440 (struct tegra_dc_dsi_data *dsi, u8 link_id)
445 if (!nvhost_syncpt_read_ext_check(dsi->dc->ndev, dsi->syncpt_id, &val))
446 dsi->syncpt_val = val;
448 val = DSI_INCR_SYNCPT_COND(OP_DONE) |
449 DSI_INCR_SYNCPT_INDX(dsi->syncpt_id);
450 tegra_dsi_controller_writel(dsi, val, DSI_INCR_SYNCPT, link_id);
452 ret = nvhost_syncpt_wait_timeout_ext(dsi->dc->ndev, dsi->syncpt_id,
453 dsi->syncpt_val + 1, (u32)MAX_SCHEDULE_TIMEOUT, NULL, NULL);
455 dev_err(&dsi->dc->ndev->dev, "DSI sync point failure\n");
465 static u32 tegra_dsi_get_hs_clk_rate(struct tegra_dc_dsi_data *dsi)
467 u32 dsi_clock_rate_khz;
469 switch (dsi->info.video_burst_mode) {
470 case TEGRA_DSI_VIDEO_BURST_MODE_LOW_SPEED:
471 case TEGRA_DSI_VIDEO_BURST_MODE_MEDIUM_SPEED:
472 case TEGRA_DSI_VIDEO_BURST_MODE_FAST_SPEED:
473 case TEGRA_DSI_VIDEO_BURST_MODE_FASTEST_SPEED:
474 /* Calculate DSI HS clock rate for DSI burst mode */
475 dsi_clock_rate_khz = dsi->default_pixel_clk_khz *
476 dsi->shift_clk_div.mul /
477 dsi->shift_clk_div.div;
479 case TEGRA_DSI_VIDEO_NONE_BURST_MODE:
480 case TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END:
481 case TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED:
483 /* Clock rate is default DSI clock rate for non-burst mode */
484 dsi_clock_rate_khz = dsi->default_hs_clk_khz;
488 return dsi_clock_rate_khz;
491 static u32 tegra_dsi_get_lp_clk_rate(struct tegra_dc_dsi_data *dsi, u8 lp_op)
493 u32 dsi_clock_rate_khz;
495 if (dsi->info.enable_hs_clock_on_lp_cmd_mode)
496 if (dsi->info.hs_clk_in_lp_cmd_mode_freq_khz)
498 dsi->info.hs_clk_in_lp_cmd_mode_freq_khz;
500 dsi_clock_rate_khz = tegra_dsi_get_hs_clk_rate(dsi);
502 if (lp_op == DSI_LP_OP_READ)
504 dsi->info.lp_read_cmd_mode_freq_khz;
507 dsi->info.lp_cmd_mode_freq_khz;
509 return dsi_clock_rate_khz;
512 static struct tegra_dc_shift_clk_div tegra_dsi_get_shift_clk_div(
513 struct tegra_dc_dsi_data *dsi)
515 struct tegra_dc_shift_clk_div shift_clk_div;
516 struct tegra_dc_shift_clk_div max_shift_clk_div;
517 struct tegra_dc_shift_clk_div delta_shift_clk_div;
522 u32 default_hs_clk_mhz =
523 DIV_ROUND_CLOSEST(dsi->default_hs_clk_khz, 1000);
524 u32 max_panel_freq_mhz =
525 DIV_ROUND_CLOSEST(dsi->info.max_panel_freq_khz, 1000);
527 /* Get the real value of default shift_clk_div. default_shift_clk_div
528 * holds the real value of shift_clk_div.
530 shift_clk_div = dsi->default_shift_clk_div;
532 /* Calculate shift_clk_div which can match the video_burst_mode. */
533 if (dsi->info.video_burst_mode >=
534 TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED) {
535 if (max_panel_freq_mhz >= default_hs_clk_mhz) {
537 * dsi->info.max_panel_freq_khz * shift_clk_div /
538 * dsi->default_hs_clk_khz
540 max_shift_clk_div.mul = max_panel_freq_mhz *
542 max_shift_clk_div.div = default_hs_clk_mhz *
545 max_shift_clk_div = shift_clk_div;
548 burst_width = dsi->info.video_burst_mode
549 - TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED;
550 burst_width_max = TEGRA_DSI_VIDEO_BURST_MODE_FASTEST_SPEED
551 - TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED;
554 * (max_shift_clk_div - shift_clk_div) *
555 * burst_width / burst_width_max
557 temp_lcm = lcm(max_shift_clk_div.div, shift_clk_div.div);
558 delta_shift_clk_div.mul = (temp_lcm / max_shift_clk_div.div *
559 max_shift_clk_div.mul -
560 temp_lcm / shift_clk_div.div *
563 delta_shift_clk_div.div = temp_lcm * burst_width_max;
566 * shift_clk_div + delta_shift_clk_div
568 temp_lcm = lcm(shift_clk_div.div, delta_shift_clk_div.div);
569 shift_clk_div.mul = temp_lcm / shift_clk_div.div *
571 temp_lcm / delta_shift_clk_div.div *
572 delta_shift_clk_div.mul;
573 shift_clk_div.div = temp_lcm;
575 /* crunch shift clk numerator and denominator */
576 temp_gcd = gcd(shift_clk_div.mul, shift_clk_div.div);
577 shift_clk_div.mul /= temp_gcd;
578 shift_clk_div.div /= temp_gcd;
581 return shift_clk_div;
584 static void tegra_dsi_pix_correction(struct tegra_dc *dc,
585 struct tegra_dc_dsi_data *dsi)
592 h_width_pixels = dc->mode.h_back_porch + dc->mode.h_front_porch +
593 dc->mode.h_sync_width + dc->mode.h_active;
595 if (WARN(!dsi->info.n_data_lanes, "dsi n_data_lanes is 0\n"))
598 if (dsi->info.ganged_type == TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD) {
599 temp = dc->mode.h_active % dsi->info.n_data_lanes;
601 h_act_corr = dsi->info.n_data_lanes - temp;
602 h_width_pixels += h_act_corr;
606 temp = h_width_pixels % dsi->info.n_data_lanes;
608 hfp_corr = dsi->info.n_data_lanes - temp;
609 h_width_pixels += hfp_corr;
613 if (WARN(!dsi->pixel_scaler_div, "dsi pixel_scaler_div is 0"))
616 temp = (h_width_pixels * dsi->pixel_scaler_mul /
617 dsi->pixel_scaler_div) % dsi->info.n_data_lanes;
619 hfp_corr += dsi->info.n_data_lanes;
620 h_width_pixels += dsi->info.n_data_lanes;
626 dc->mode.h_front_porch += hfp_corr;
627 dc->mode.h_active += h_act_corr;
630 static void tegra_dsi_init_sw(struct tegra_dc *dc,
631 struct tegra_dc_dsi_data *dsi)
640 switch (dsi->info.pixel_format) {
641 case TEGRA_DSI_PIXEL_FORMAT_16BIT_P:
642 /* 2 bytes per pixel */
643 dsi->pixel_scaler_mul = 2;
644 dsi->pixel_scaler_div = 1;
646 case TEGRA_DSI_PIXEL_FORMAT_18BIT_P:
647 /* 2.25 bytes per pixel */
648 dsi->pixel_scaler_mul = 9;
649 dsi->pixel_scaler_div = 4;
651 case TEGRA_DSI_PIXEL_FORMAT_18BIT_NP:
652 case TEGRA_DSI_PIXEL_FORMAT_24BIT_P:
653 /* 3 bytes per pixel */
654 dsi->pixel_scaler_mul = 3;
655 dsi->pixel_scaler_div = 1;
662 dsi->enabled = false;
663 dsi->clk_ref = false;
665 n_data_lanes = dsi->info.n_data_lanes;
666 if (dsi->info.ganged_type == TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT ||
667 dsi->info.ganged_type == TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD)
670 dsi->dsi_control_val =
671 DSI_CONTROL_VIRTUAL_CHANNEL(dsi->info.virtual_channel) |
672 DSI_CONTROL_NUM_DATA_LANES(n_data_lanes - 1) |
673 DSI_CONTROL_VID_SOURCE(dc->ndev->id) |
674 DSI_CONTROL_DATA_FORMAT(dsi->info.pixel_format);
676 if (dsi->info.ganged_type)
677 tegra_dsi_pix_correction(dc, dsi);
679 /* Below we are going to calculate dsi and dc clock rate.
680 * Calcuate the horizontal and vertical width.
682 h_width_pixels = dc->mode.h_back_porch + dc->mode.h_front_porch +
683 dc->mode.h_sync_width + dc->mode.h_active;
685 v_width_lines = dc->mode.v_back_porch + dc->mode.v_front_porch +
686 dc->mode.v_sync_width + dc->mode.v_active;
688 /* Calculate minimum required pixel rate. */
689 pixel_clk_hz = h_width_pixels * v_width_lines * dsi->info.refresh_rate;
690 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_MODE) {
691 if (dsi->info.rated_refresh_rate >= dsi->info.refresh_rate)
692 dev_info(&dc->ndev->dev, "DSI: measured refresh rate "
693 "should be larger than rated refresh rate.\n");
694 dc->mode.rated_pclk = h_width_pixels * v_width_lines *
695 dsi->info.rated_refresh_rate;
698 /* Calculate minimum byte rate on DSI interface. */
699 byte_clk_hz = (pixel_clk_hz * dsi->pixel_scaler_mul) /
700 (dsi->pixel_scaler_div * dsi->info.n_data_lanes);
702 /* Round up to multiple of mega hz. */
703 plld_clk_mhz = DIV_ROUND_UP((byte_clk_hz * NUMOF_BIT_PER_BYTE),
706 /* Calculate default real shift_clk_div. */
707 dsi->default_shift_clk_div.mul = NUMOF_BIT_PER_BYTE *
708 dsi->pixel_scaler_mul;
709 dsi->default_shift_clk_div.div = 2 * dsi->pixel_scaler_div *
710 dsi->info.n_data_lanes;
712 /* Calculate default DSI hs clock. DSI interface is double data rate.
713 * Data is transferred on both rising and falling edge of clk, div by 2
714 * to get the actual clock rate.
716 dsi->default_hs_clk_khz = plld_clk_mhz * 1000 / 2;
718 dsi->default_pixel_clk_khz = (plld_clk_mhz * 1000 *
719 dsi->default_shift_clk_div.div) /
720 (2 * dsi->default_shift_clk_div.mul);
722 /* Get the actual shift_clk_div and clock rates. */
723 dsi->shift_clk_div = tegra_dsi_get_shift_clk_div(dsi);
724 dsi->target_lp_clk_khz =
725 tegra_dsi_get_lp_clk_rate(dsi, DSI_LP_OP_WRITE);
726 dsi->target_hs_clk_khz = tegra_dsi_get_hs_clk_rate(dsi);
728 dev_info(&dc->ndev->dev, "DSI: HS clock rate is %d\n",
729 dsi->target_hs_clk_khz);
731 #if DSI_USE_SYNC_POINTS
732 dsi->syncpt_id = NVSYNCPT_DSI;
736 * Force video clock to be continuous mode if
737 * enable_hs_clock_on_lp_cmd_mode is set
739 if (dsi->info.enable_hs_clock_on_lp_cmd_mode) {
740 if (dsi->info.video_clock_mode !=
741 TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS)
742 dev_warn(&dc->ndev->dev,
743 "Force clock continuous mode\n");
745 dsi->info.video_clock_mode = TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS;
748 atomic_set(&dsi->host_ref, 0);
749 dsi->host_suspended = false;
750 mutex_init(&dsi->host_lock);
751 init_completion(&dc->out->user_vblank_comp);
752 INIT_DELAYED_WORK(&dsi->idle_work, tegra_dc_dsi_idle_work);
753 dsi->idle_delay = msecs_to_jiffies(DSI_HOST_IDLE_PERIOD);
756 #define SELECT_T_PHY(platform_t_phy_ps, default_phy, clk_ps, hw_inc) ( \
757 (platform_t_phy_ps) ? ( \
758 ((DSI_CONVERT_T_PHY_PS_TO_T_PHY(platform_t_phy_ps, clk_ps, hw_inc)) < 0 ? 0 : \
759 (DSI_CONVERT_T_PHY_PS_TO_T_PHY(platform_t_phy_ps, clk_ps, hw_inc)))) : \
760 ((default_phy) < 0 ? 0 : (default_phy)))
762 static void tegra_dsi_get_clk_phy_timing(struct tegra_dc_dsi_data *dsi,
763 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
765 phy_timing_clk->t_tlpx = SELECT_T_PHY(
766 dsi->info.phy_timing.t_tlpx_ns * 1000,
767 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
769 phy_timing_clk->t_clktrail = SELECT_T_PHY(
770 dsi->info.phy_timing.t_clktrail_ns * 1000,
771 T_CLKTRAIL_DEFAULT(clk_ps), clk_ps, T_CLKTRAIL_HW_INC);
773 phy_timing_clk->t_clkpost = SELECT_T_PHY(
774 dsi->info.phy_timing.t_clkpost_ns * 1000,
775 T_CLKPOST_DEFAULT(clk_ps), clk_ps, T_CLKPOST_HW_INC);
777 phy_timing_clk->t_clkzero = SELECT_T_PHY(
778 dsi->info.phy_timing.t_clkzero_ns * 1000,
779 T_CLKZERO_DEFAULT(clk_ps), clk_ps, T_CLKZERO_HW_INC);
781 phy_timing_clk->t_clkprepare = SELECT_T_PHY(
782 dsi->info.phy_timing.t_clkprepare_ns * 1000,
783 T_CLKPREPARE_DEFAULT(clk_ps), clk_ps, T_CLKPREPARE_HW_INC);
785 phy_timing_clk->t_clkpre = SELECT_T_PHY(
786 dsi->info.phy_timing.t_clkpre_ns * 1000,
787 T_CLKPRE_DEFAULT, clk_ps, T_CLKPRE_HW_INC);
790 static void tegra_dsi_get_hs_phy_timing(struct tegra_dc_dsi_data *dsi,
791 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
793 phy_timing_clk->t_tlpx = SELECT_T_PHY(
794 dsi->info.phy_timing.t_tlpx_ns * 1000,
795 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
797 phy_timing_clk->t_hsdexit = SELECT_T_PHY(
798 dsi->info.phy_timing.t_hsdexit_ns * 1000,
799 T_HSEXIT_DEFAULT(clk_ps), clk_ps, T_HSEXIT_HW_INC);
801 phy_timing_clk->t_hstrail = SELECT_T_PHY(
802 dsi->info.phy_timing.t_hstrail_ns * 1000,
803 T_HSTRAIL_DEFAULT(clk_ps), clk_ps, T_HSTRAIL_HW_INC);
805 phy_timing_clk->t_datzero = SELECT_T_PHY(
806 dsi->info.phy_timing.t_datzero_ns * 1000,
807 T_DATZERO_DEFAULT(clk_ps), clk_ps, T_DATZERO_HW_INC);
809 phy_timing_clk->t_hsprepare = SELECT_T_PHY(
810 dsi->info.phy_timing.t_hsprepare_ns * 1000,
811 T_HSPREPARE_DEFAULT(clk_ps), clk_ps, T_HSPREPARE_HW_INC);
814 static void tegra_dsi_get_escape_phy_timing(struct tegra_dc_dsi_data *dsi,
815 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
817 phy_timing_clk->t_tlpx = SELECT_T_PHY(
818 dsi->info.phy_timing.t_tlpx_ns * 1000,
819 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
822 static void tegra_dsi_get_bta_phy_timing(struct tegra_dc_dsi_data *dsi,
823 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
825 phy_timing_clk->t_tlpx = SELECT_T_PHY(
826 dsi->info.phy_timing.t_tlpx_ns * 1000,
827 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
829 phy_timing_clk->t_taget = SELECT_T_PHY(
830 dsi->info.phy_timing.t_taget_ns * 1000,
831 T_TAGET_DEFAULT(clk_ps), clk_ps, T_TAGET_HW_INC);
833 phy_timing_clk->t_tasure = SELECT_T_PHY(
834 dsi->info.phy_timing.t_tasure_ns * 1000,
835 T_TASURE_DEFAULT(clk_ps), clk_ps, T_TASURE_HW_INC);
837 phy_timing_clk->t_tago = SELECT_T_PHY(
838 dsi->info.phy_timing.t_tago_ns * 1000,
839 T_TAGO_DEFAULT(clk_ps), clk_ps, T_TAGO_HW_INC);
842 static void tegra_dsi_get_ulps_phy_timing(struct tegra_dc_dsi_data *dsi,
843 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
845 phy_timing_clk->t_tlpx = SELECT_T_PHY(
846 dsi->info.phy_timing.t_tlpx_ns * 1000,
847 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
849 phy_timing_clk->t_wakeup = SELECT_T_PHY(
850 dsi->info.phy_timing.t_wakeup_ns * 1000,
851 T_WAKEUP_DEFAULT, clk_ps, T_WAKEUP_HW_INC);
856 static void tegra_dsi_get_phy_timing(struct tegra_dc_dsi_data *dsi,
857 struct dsi_phy_timing_inclk *phy_timing_clk,
860 if (tegra_platform_is_fpga() && !(dsi->info.ganged_type)) {
861 clk_ps = (1000 * 1000 * 1000) / (dsi->info.fpga_freq_khz ?
862 dsi->info.fpga_freq_khz : DEFAULT_FPGA_FREQ_KHZ);
865 if (lphs == DSI_LPHS_IN_HS_MODE) {
866 tegra_dsi_get_clk_phy_timing(dsi, phy_timing_clk, clk_ps);
867 tegra_dsi_get_hs_phy_timing(dsi, phy_timing_clk, clk_ps);
869 /* default is LP mode */
870 tegra_dsi_get_escape_phy_timing(dsi, phy_timing_clk, clk_ps);
871 tegra_dsi_get_bta_phy_timing(dsi, phy_timing_clk, clk_ps);
872 tegra_dsi_get_ulps_phy_timing(dsi, phy_timing_clk, clk_ps);
873 if (dsi->info.enable_hs_clock_on_lp_cmd_mode)
874 tegra_dsi_get_clk_phy_timing(dsi,
875 phy_timing_clk, clk_ps);
879 static int tegra_dsi_mipi_phy_timing_range(struct tegra_dc_dsi_data *dsi,
880 struct dsi_phy_timing_inclk *phy_timing,
885 #define CHECK_RANGE(val, min, max) ( \
886 ((min) == NOT_DEFINED ? 0 : (val) < (min)) || \
887 ((max) == NOT_DEFINED ? 0 : (val) > (max)) ? -EINVAL : 0)
889 if (tegra_platform_is_fpga())
890 clk_ps = dsi->info.fpga_freq_khz ?
891 ((1000 * 1000 * 1000) / dsi->info.fpga_freq_khz) :
892 DEFAULT_FPGA_FREQ_KHZ;
895 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
896 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC),
897 MIPI_T_TLPX_PS_MIN, MIPI_T_TLPX_PS_MAX);
899 dev_warn(&dsi->dc->ndev->dev,
900 "dsi: Tlpx mipi range violated\n");
904 if (lphs == DSI_LPHS_IN_HS_MODE) {
906 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
907 phy_timing->t_hsdexit, clk_ps, T_HSEXIT_HW_INC),
908 MIPI_T_HSEXIT_PS_MIN, MIPI_T_HSEXIT_PS_MAX);
910 dev_warn(&dsi->dc->ndev->dev,
911 "dsi: HsExit mipi range violated\n");
916 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
917 phy_timing->t_hstrail, clk_ps, T_HSTRAIL_HW_INC),
918 MIPI_T_HSTRAIL_PS_MIN(clk_ps), MIPI_T_HSTRAIL_PS_MAX);
920 dev_warn(&dsi->dc->ndev->dev,
921 "dsi: HsTrail mipi range violated\n");
926 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
927 phy_timing->t_datzero, clk_ps, T_DATZERO_HW_INC),
928 MIPI_T_HSZERO_PS_MIN, MIPI_T_HSZERO_PS_MAX);
930 dev_warn(&dsi->dc->ndev->dev,
931 "dsi: HsZero mipi range violated\n");
936 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
937 phy_timing->t_hsprepare, clk_ps, T_HSPREPARE_HW_INC),
938 MIPI_T_HSPREPARE_PS_MIN(clk_ps),
939 MIPI_T_HSPREPARE_PS_MAX(clk_ps));
941 dev_warn(&dsi->dc->ndev->dev,
942 "dsi: HsPrepare mipi range violated\n");
947 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
948 phy_timing->t_hsprepare, clk_ps, T_HSPREPARE_HW_INC) +
949 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
950 phy_timing->t_datzero, clk_ps, T_DATZERO_HW_INC),
951 MIPI_T_HSPREPARE_ADD_HSZERO_PS_MIN(clk_ps),
952 MIPI_T_HSPREPARE_ADD_HSZERO_PS_MAX);
954 dev_warn(&dsi->dc->ndev->dev,
955 "dsi: HsPrepare + HsZero mipi range violated\n");
959 /* default is LP mode */
961 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
962 phy_timing->t_wakeup, clk_ps, T_WAKEUP_HW_INC),
963 MIPI_T_WAKEUP_PS_MIN, MIPI_T_WAKEUP_PS_MAX);
965 dev_warn(&dsi->dc->ndev->dev,
966 "dsi: WakeUp mipi range violated\n");
971 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
972 phy_timing->t_tasure, clk_ps, T_TASURE_HW_INC),
973 MIPI_T_TASURE_PS_MIN(DSI_CONVERT_T_PHY_TO_T_PHY_PS(
974 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC)),
975 MIPI_T_TASURE_PS_MAX(DSI_CONVERT_T_PHY_TO_T_PHY_PS(
976 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC)));
978 dev_warn(&dsi->dc->ndev->dev,
979 "dsi: TaSure mipi range violated\n");
984 if (lphs == DSI_LPHS_IN_HS_MODE ||
985 dsi->info.enable_hs_clock_on_lp_cmd_mode) {
987 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
988 phy_timing->t_clktrail, clk_ps, T_CLKTRAIL_HW_INC),
989 MIPI_T_CLKTRAIL_PS_MIN, MIPI_T_CLKTRAIL_PS_MAX);
991 dev_warn(&dsi->dc->ndev->dev,
992 "dsi: ClkTrail mipi range violated\n");
997 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
998 phy_timing->t_clkpost, clk_ps, T_CLKPOST_HW_INC),
999 MIPI_T_CLKPOST_PS_MIN(clk_ps), MIPI_T_CLKPOST_PS_MAX);
1001 dev_warn(&dsi->dc->ndev->dev,
1002 "dsi: ClkPost mipi range violated\n");
1007 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1008 phy_timing->t_clkzero, clk_ps, T_CLKZERO_HW_INC),
1009 MIPI_T_CLKZERO_PS_MIN, MIPI_T_CLKZERO_PS_MAX);
1011 dev_warn(&dsi->dc->ndev->dev,
1012 "dsi: ClkZero mipi range violated\n");
1017 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1018 phy_timing->t_clkprepare, clk_ps, T_CLKPREPARE_HW_INC),
1019 MIPI_T_CLKPREPARE_PS_MIN, MIPI_T_CLKPREPARE_PS_MAX);
1021 dev_warn(&dsi->dc->ndev->dev,
1022 "dsi: ClkPrepare mipi range violated\n");
1027 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1028 phy_timing->t_clkpre, clk_ps, T_CLKPRE_HW_INC),
1029 MIPI_T_CLKPRE_PS_MIN, MIPI_T_CLKPRE_PS_MAX);
1031 dev_warn(&dsi->dc->ndev->dev,
1032 "dsi: ClkPre mipi range violated\n");
1037 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1038 phy_timing->t_clkprepare, clk_ps, T_CLKPREPARE_HW_INC) +
1039 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1040 phy_timing->t_clkzero, clk_ps, T_CLKZERO_HW_INC),
1041 MIPI_T_CLKPREPARE_ADD_CLKZERO_PS_MIN,
1042 MIPI_T_CLKPREPARE_ADD_CLKZERO_PS_MAX);
1044 dev_warn(&dsi->dc->ndev->dev,
1045 "dsi: ClkPrepare + ClkZero mipi range violated\n");
1054 static int tegra_dsi_hs_phy_len(struct tegra_dc_dsi_data *dsi,
1055 struct dsi_phy_timing_inclk *phy_timing,
1056 u32 clk_ps, u8 lphs)
1058 u32 hs_t_phy_ps = 0;
1059 u32 clk_t_phy_ps = 0;
1062 struct tegra_dc_mode *modes;
1066 if (!(lphs == DSI_LPHS_IN_HS_MODE))
1069 if (dsi->info.video_data_type ==
1070 TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE &&
1071 dsi->info.video_burst_mode <=
1072 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END)
1075 modes = dsi->dc->out->modes;
1076 t_pix_ps = clk_ps * BITS_PER_BYTE *
1077 dsi->pixel_scaler_mul / dsi->pixel_scaler_div;
1080 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1081 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC) +
1082 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1083 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC) +
1084 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1085 phy_timing->t_hsprepare, clk_ps, T_HSPREPARE_HW_INC) +
1086 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1087 phy_timing->t_datzero, clk_ps, T_DATZERO_HW_INC) +
1088 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1089 phy_timing->t_hstrail, clk_ps, T_HSTRAIL_HW_INC) +
1090 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1091 phy_timing->t_hsdexit, clk_ps, T_HSEXIT_HW_INC);
1093 if (dsi->info.video_clock_mode == TEGRA_DSI_VIDEO_CLOCK_TX_ONLY) {
1095 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1096 phy_timing->t_clkpost, clk_ps, T_CLKPOST_HW_INC) +
1097 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1098 phy_timing->t_clktrail, clk_ps, T_CLKTRAIL_HW_INC) +
1099 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1100 phy_timing->t_hsdexit, clk_ps, T_HSEXIT_HW_INC) +
1101 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1102 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC) +
1103 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1104 phy_timing->t_clkprepare, clk_ps, T_CLKPREPARE_HW_INC) +
1105 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1106 phy_timing->t_clkzero, clk_ps, T_CLKZERO_HW_INC) +
1107 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1108 phy_timing->t_clkpre, clk_ps, T_CLKPRE_HW_INC);
1110 /* clk_pre overlaps LP-11 hs mode start sequence */
1111 hs_t_phy_ps -= DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1112 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC);
1115 h_blank_ps = t_pix_ps * (modes->h_sync_width + modes->h_back_porch +
1116 modes->h_front_porch);
1118 /* Extra tlpx and byte cycle required by dsi HW */
1119 t_phy_ps = dsi->info.n_data_lanes * (hs_t_phy_ps + clk_t_phy_ps +
1120 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1121 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC) +
1122 clk_ps * BITS_PER_BYTE);
1124 if (h_blank_ps < t_phy_ps) {
1126 dev_WARN(&dsi->dc->ndev->dev,
1127 "dsi: Hblank is smaller than HS phy timing: %u pix\n",
1128 (t_phy_ps - h_blank_ps) / t_pix_ps);
1137 static int tegra_dsi_constraint_phy_timing(struct tegra_dc_dsi_data *dsi,
1138 struct dsi_phy_timing_inclk *phy_timing,
1139 u32 clk_ps, u8 lphs)
1143 err = tegra_dsi_mipi_phy_timing_range(dsi, phy_timing, clk_ps, lphs);
1145 dev_warn(&dsi->dc->ndev->dev, "dsi: mipi range violated\n");
1149 err = tegra_dsi_hs_phy_len(dsi, phy_timing, clk_ps, lphs);
1151 dev_err(&dsi->dc->ndev->dev, "dsi: Hblank too short\n");
1155 /* TODO: add more contraints */
1160 static void tegra_dsi_set_phy_timing(struct tegra_dc_dsi_data *dsi, u8 lphs)
1163 struct dsi_phy_timing_inclk phy_timing = dsi->phy_timing;
1165 tegra_dsi_get_phy_timing
1166 (dsi, &phy_timing, dsi->current_bit_clk_ps, lphs);
1168 tegra_dsi_constraint_phy_timing(dsi, &phy_timing,
1169 dsi->current_bit_clk_ps, lphs);
1171 if (tegra_platform_is_fpga() && dsi->info.ganged_type) {
1172 phy_timing.t_hsdexit += T_HSEXIT_HW_INC;
1173 phy_timing.t_hstrail += T_HSTRAIL_HW_INC + 3;
1174 phy_timing.t_datzero += T_DATZERO_HW_INC;
1175 phy_timing.t_hsprepare += T_HSPREPARE_HW_INC;
1177 phy_timing.t_clktrail += T_CLKTRAIL_HW_INC;
1178 phy_timing.t_clkpost += T_CLKPOST_HW_INC;
1179 phy_timing.t_clkzero += T_CLKZERO_HW_INC;
1180 phy_timing.t_tlpx += T_TLPX_HW_INC;
1182 phy_timing.t_clkprepare += T_CLKPREPARE_HW_INC;
1183 phy_timing.t_clkpre += T_CLKPRE_HW_INC;
1184 phy_timing.t_wakeup += T_WAKEUP_HW_INC;
1186 phy_timing.t_taget += T_TAGET_HW_INC;
1187 phy_timing.t_tasure += T_TASURE_HW_INC;
1188 phy_timing.t_tago += T_TAGO_HW_INC;
1190 val = DSI_PHY_TIMING_0_THSDEXIT(phy_timing.t_hsdexit) |
1191 DSI_PHY_TIMING_0_THSTRAIL(phy_timing.t_hstrail) |
1192 DSI_PHY_TIMING_0_TDATZERO(phy_timing.t_datzero) |
1193 DSI_PHY_TIMING_0_THSPREPR(phy_timing.t_hsprepare);
1194 tegra_dsi_writel(dsi, val, DSI_PHY_TIMING_0);
1196 val = DSI_PHY_TIMING_1_TCLKTRAIL(phy_timing.t_clktrail) |
1197 DSI_PHY_TIMING_1_TCLKPOST(phy_timing.t_clkpost) |
1198 DSI_PHY_TIMING_1_TCLKZERO(phy_timing.t_clkzero) |
1199 DSI_PHY_TIMING_1_TTLPX(phy_timing.t_tlpx);
1200 tegra_dsi_writel(dsi, val, DSI_PHY_TIMING_1);
1202 val = DSI_PHY_TIMING_2_TCLKPREPARE(phy_timing.t_clkprepare) |
1203 DSI_PHY_TIMING_2_TCLKPRE(phy_timing.t_clkpre) |
1204 DSI_PHY_TIMING_2_TWAKEUP(phy_timing.t_wakeup);
1205 tegra_dsi_writel(dsi, val, DSI_PHY_TIMING_2);
1207 val = DSI_BTA_TIMING_TTAGET(phy_timing.t_taget) |
1208 DSI_BTA_TIMING_TTASURE(phy_timing.t_tasure) |
1209 DSI_BTA_TIMING_TTAGO(phy_timing.t_tago);
1210 tegra_dsi_writel(dsi, val, DSI_BTA_TIMING);
1212 dsi->phy_timing = phy_timing;
1215 static u32 tegra_dsi_sol_delay_burst(struct tegra_dc *dc,
1216 struct tegra_dc_dsi_data *dsi)
1218 u32 dsi_to_pixel_clk_ratio;
1221 u32 mipi_clk_adj_kHz = 0;
1223 struct tegra_dc_mode *dc_modes = &dc->mode;
1225 /* Get Fdsi/Fpixel ration (note: Fdsi is in bit format) */
1226 dsi_to_pixel_clk_ratio = (dsi->current_dsi_clk_khz * 2 +
1227 dsi->default_pixel_clk_khz - 1) / dsi->default_pixel_clk_khz;
1229 /* Convert Fdsi to byte format */
1230 dsi_to_pixel_clk_ratio *= 1000/8;
1232 /* Multiplying by 1000 so that we don't loose the fraction part */
1233 temp = dc_modes->h_active * 1000;
1234 temp1 = dc_modes->h_active + dc_modes->h_back_porch +
1235 dc_modes->h_sync_width;
1237 sol_delay = temp1 * dsi_to_pixel_clk_ratio -
1238 temp * dsi->pixel_scaler_mul /
1239 (dsi->pixel_scaler_div * dsi->info.n_data_lanes);
1241 /* Do rounding on sol delay */
1242 sol_delay = (sol_delay + 1000 - 1)/1000;
1245 * 1. find out the correct sol fifo depth to use
1246 * 2. verify with hw about the clamping function
1248 if (sol_delay > (480 * 4)) {
1249 sol_delay = (480 * 4);
1250 mipi_clk_adj_kHz = sol_delay +
1251 (dc_modes->h_active * dsi->pixel_scaler_mul) /
1252 (dsi->info.n_data_lanes * dsi->pixel_scaler_div);
1254 mipi_clk_adj_kHz *= (dsi->default_pixel_clk_khz / temp1);
1256 mipi_clk_adj_kHz *= 4;
1259 dsi->target_hs_clk_khz = mipi_clk_adj_kHz;
1264 static void tegra_dsi_set_sol_delay(struct tegra_dc *dc,
1265 struct tegra_dc_dsi_data *dsi)
1269 u32 h_width_byte_clk;
1271 u32 h_width_ganged_byte_clk;
1272 u8 n_data_lanes_this_cont = 0;
1273 u8 n_data_lanes_ganged = 0;
1275 if (!(dsi->info.ganged_type)) {
1276 if (dsi->info.video_burst_mode ==
1277 TEGRA_DSI_VIDEO_NONE_BURST_MODE ||
1278 dsi->info.video_burst_mode ==
1279 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END) {
1280 #define VIDEO_FIFO_LATENCY_PIXEL_CLK 8
1281 sol_delay = VIDEO_FIFO_LATENCY_PIXEL_CLK *
1282 dsi->pixel_scaler_mul / dsi->pixel_scaler_div;
1283 #undef VIDEO_FIFO_LATENCY_PIXEL_CLK
1284 dsi->status.clk_burst = DSI_CLK_BURST_NONE_BURST;
1286 sol_delay = tegra_dsi_sol_delay_burst(dc, dsi);
1287 dsi->status.clk_burst = DSI_CLK_BURST_BURST_MODE;
1290 #define SOL_TO_VALID_PIX_CLK_DELAY 4
1291 #define VALID_TO_FIFO_PIX_CLK_DELAY 4
1292 #define FIFO_WR_PIX_CLK_DELAY 2
1293 #define FIFO_RD_BYTE_CLK_DELAY 6
1294 #define TOT_INTERNAL_PIX_DELAY (SOL_TO_VALID_PIX_CLK_DELAY + \
1295 VALID_TO_FIFO_PIX_CLK_DELAY + \
1296 FIFO_WR_PIX_CLK_DELAY)
1298 internal_delay = DIV_ROUND_UP(
1299 TOT_INTERNAL_PIX_DELAY * dsi->pixel_scaler_mul,
1300 dsi->pixel_scaler_div * dsi->info.n_data_lanes)
1301 + FIFO_RD_BYTE_CLK_DELAY;
1303 h_width_pixels = dc->mode.h_sync_width +
1304 dc->mode.h_back_porch +
1306 dc->mode.h_front_porch;
1308 h_width_byte_clk = DIV_ROUND_UP(h_width_pixels *
1309 dsi->pixel_scaler_mul,
1310 dsi->pixel_scaler_div *
1311 dsi->info.n_data_lanes);
1313 if (dsi->info.ganged_type ==
1314 TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT ||
1315 dsi->info.ganged_type ==
1316 TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD) {
1317 n_data_lanes_this_cont = dsi->info.n_data_lanes / 2;
1318 n_data_lanes_ganged = dsi->info.n_data_lanes;
1321 h_width_ganged_byte_clk = DIV_ROUND_UP(
1322 n_data_lanes_this_cont *
1324 n_data_lanes_ganged);
1326 sol_delay = h_width_byte_clk - h_width_ganged_byte_clk +
1328 sol_delay = (dsi->info.video_data_type ==
1329 TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE) ?
1330 sol_delay + 20 : sol_delay;
1332 #undef SOL_TO_VALID_PIX_CLK_DELAY
1333 #undef VALID_TO_FIFO_PIX_CLK_DELAY
1334 #undef FIFO_WR_PIX_CLK_DELAY
1335 #undef FIFO_RD_BYTE_CLK_DELAY
1336 #undef TOT_INTERNAL_PIX_DELAY
1339 tegra_dsi_writel(dsi, DSI_SOL_DELAY_SOL_DELAY(sol_delay),
1343 static void tegra_dsi_set_timeout(struct tegra_dc_dsi_data *dsi)
1346 u32 bytes_per_frame;
1349 /* TODO: verify the following equation */
1350 bytes_per_frame = dsi->current_dsi_clk_khz * 1000 * 2 /
1351 (dsi->info.refresh_rate * 8);
1352 timeout = bytes_per_frame / DSI_CYCLE_COUNTER_VALUE;
1353 timeout = (timeout + DSI_HTX_TO_MARGIN) & 0xffff;
1355 val = DSI_TIMEOUT_0_LRXH_TO(DSI_LRXH_TO_VALUE) |
1356 DSI_TIMEOUT_0_HTX_TO(timeout);
1357 tegra_dsi_writel(dsi, val, DSI_TIMEOUT_0);
1359 if (dsi->info.panel_reset_timeout_msec)
1360 timeout = (dsi->info.panel_reset_timeout_msec * 1000 * 1000 *
1361 1000) / dsi->current_bit_clk_ps;
1363 timeout = DSI_PR_TO_VALUE;
1365 val = DSI_TIMEOUT_1_PR_TO(timeout) |
1366 DSI_TIMEOUT_1_TA_TO(DSI_TA_TO_VALUE);
1367 tegra_dsi_writel(dsi, val, DSI_TIMEOUT_1);
1369 val = DSI_TO_TALLY_P_RESET_STATUS(IN_RESET) |
1370 DSI_TO_TALLY_TA_TALLY(DSI_TA_TALLY_VALUE)|
1371 DSI_TO_TALLY_LRXH_TALLY(DSI_LRXH_TALLY_VALUE)|
1372 DSI_TO_TALLY_HTX_TALLY(DSI_HTX_TALLY_VALUE);
1373 tegra_dsi_writel(dsi, val, DSI_TO_TALLY);
1376 static void tegra_dsi_setup_ganged_mode_pkt_length(struct tegra_dc *dc,
1377 struct tegra_dc_dsi_data *dsi)
1379 u32 hact_pkt_len_pix_orig = dc->mode.h_active;
1380 u32 hact_pkt_len_pix = 0;
1381 u32 hact_pkt_len_bytes = 0;
1382 u32 hfp_pkt_len_bytes = 0;
1383 u32 pix_per_line_orig = 0;
1384 u32 pix_per_line = 0;
1388 /* hsync + hact + hfp = (4) + (4+2) + (4+2) */
1389 #define HEADER_OVERHEAD 16
1391 pix_per_line_orig = dc->mode.h_sync_width + dc->mode.h_back_porch +
1392 dc->mode.h_active + dc->mode.h_front_porch;
1394 val = DSI_PKT_LEN_0_1_LENGTH_0(0) |
1395 DSI_PKT_LEN_0_1_LENGTH_1(0);
1396 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_0_1);
1398 switch (dsi->info.ganged_type) {
1399 case TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT: /* fall through */
1400 case TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD: /* fall through */
1401 hact_pkt_len_pix = DIV_ROUND_UP(hact_pkt_len_pix_orig, 2);
1402 pix_per_line = DIV_ROUND_UP(pix_per_line_orig, 2);
1405 dev_err(&dc->ndev->dev, "dsi: invalid ganged type\n");
1408 for (i = 0; i < dsi->max_instances; i++) {
1409 hact_pkt_len_bytes = hact_pkt_len_pix *
1410 dsi->pixel_scaler_mul / dsi->pixel_scaler_div;
1411 hfp_pkt_len_bytes = pix_per_line *
1412 dsi->pixel_scaler_mul / dsi->pixel_scaler_div -
1413 hact_pkt_len_bytes - HEADER_OVERHEAD;
1415 val = DSI_PKT_LEN_2_3_LENGTH_2(0x0) |
1416 DSI_PKT_LEN_2_3_LENGTH_3(hact_pkt_len_bytes);
1417 tegra_dsi_controller_writel(dsi, val, DSI_PKT_LEN_2_3, i);
1419 val = DSI_PKT_LEN_4_5_LENGTH_4(hfp_pkt_len_bytes) |
1420 DSI_PKT_LEN_4_5_LENGTH_5(0);
1421 tegra_dsi_controller_writel(dsi, val, DSI_PKT_LEN_4_5, i);
1424 hact_pkt_len_pix_orig - hact_pkt_len_pix;
1425 pix_per_line = pix_per_line_orig - pix_per_line;
1428 val = DSI_PKT_LEN_6_7_LENGTH_6(0) |
1429 DSI_PKT_LEN_6_7_LENGTH_7(0x0f0f);
1430 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_6_7);
1432 #undef HEADER_OVERHEAD
1435 static void tegra_dsi_setup_video_mode_pkt_length(struct tegra_dc *dc,
1436 struct tegra_dc_dsi_data *dsi)
1444 hact_pkt_len = dc->mode.h_active * dsi->pixel_scaler_mul /
1445 dsi->pixel_scaler_div;
1446 hsa_pkt_len = dc->mode.h_sync_width * dsi->pixel_scaler_mul /
1447 dsi->pixel_scaler_div;
1448 hbp_pkt_len = dc->mode.h_back_porch * dsi->pixel_scaler_mul /
1449 dsi->pixel_scaler_div;
1450 hfp_pkt_len = dc->mode.h_front_porch * dsi->pixel_scaler_mul /
1451 dsi->pixel_scaler_div;
1453 if (dsi->info.video_burst_mode !=
1454 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END)
1455 hbp_pkt_len += hsa_pkt_len;
1457 hsa_pkt_len -= DSI_HSYNC_BLNK_PKT_OVERHEAD;
1458 hbp_pkt_len -= DSI_HBACK_PORCH_PKT_OVERHEAD;
1459 hfp_pkt_len -= DSI_HFRONT_PORCH_PKT_OVERHEAD;
1461 val = DSI_PKT_LEN_0_1_LENGTH_0(0) |
1462 DSI_PKT_LEN_0_1_LENGTH_1(hsa_pkt_len);
1463 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_0_1);
1465 val = DSI_PKT_LEN_2_3_LENGTH_2(hbp_pkt_len) |
1466 DSI_PKT_LEN_2_3_LENGTH_3(hact_pkt_len);
1467 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_2_3);
1469 val = DSI_PKT_LEN_4_5_LENGTH_4(hfp_pkt_len) |
1470 DSI_PKT_LEN_4_5_LENGTH_5(0);
1471 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_4_5);
1473 val = DSI_PKT_LEN_6_7_LENGTH_6(0) | DSI_PKT_LEN_6_7_LENGTH_7(0x0f0f);
1474 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_6_7);
1477 static void tegra_dsi_setup_cmd_mode_pkt_length(struct tegra_dc *dc,
1478 struct tegra_dc_dsi_data *dsi)
1481 unsigned long act_bytes;
1483 if (dsi->info.ganged_type) {
1484 act_bytes = DIV_ROUND_UP(dc->mode.h_active, 2);
1485 act_bytes = (act_bytes) * dsi->pixel_scaler_mul /
1486 dsi->pixel_scaler_div + 1;
1488 act_bytes = dc->mode.h_active * dsi->pixel_scaler_mul /
1489 dsi->pixel_scaler_div + 1;
1491 val = DSI_PKT_LEN_0_1_LENGTH_0(0) | DSI_PKT_LEN_0_1_LENGTH_1(0);
1492 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_0_1);
1494 val = DSI_PKT_LEN_2_3_LENGTH_2(0) | DSI_PKT_LEN_2_3_LENGTH_3(act_bytes);
1495 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_2_3);
1497 val = DSI_PKT_LEN_4_5_LENGTH_4(0) | DSI_PKT_LEN_4_5_LENGTH_5(act_bytes);
1498 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_4_5);
1500 val = DSI_PKT_LEN_6_7_LENGTH_6(0) | DSI_PKT_LEN_6_7_LENGTH_7(0x0f0f);
1501 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_6_7);
1504 static void tegra_dsi_set_pkt_length(struct tegra_dc *dc,
1505 struct tegra_dc_dsi_data *dsi)
1507 if (dsi->driven_mode == TEGRA_DSI_DRIVEN_BY_HOST)
1510 if (dsi->info.video_data_type == TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE) {
1511 if (dsi->info.ganged_type)
1512 tegra_dsi_setup_ganged_mode_pkt_length(dc, dsi);
1514 tegra_dsi_setup_video_mode_pkt_length(dc, dsi);
1516 tegra_dsi_setup_cmd_mode_pkt_length(dc, dsi);
1520 static void tegra_dsi_set_pkt_seq(struct tegra_dc *dc,
1521 struct tegra_dc_dsi_data *dsi)
1525 u32 pkt_seq_3_5_rgb_lo;
1526 u32 pkt_seq_3_5_rgb_hi;
1531 if (dsi->driven_mode == TEGRA_DSI_DRIVEN_BY_HOST)
1534 switch (dsi->info.pixel_format) {
1535 case TEGRA_DSI_PIXEL_FORMAT_16BIT_P:
1536 rgb_info = CMD_RGB_16BPP;
1538 case TEGRA_DSI_PIXEL_FORMAT_18BIT_P:
1539 rgb_info = CMD_RGB_18BPP;
1541 case TEGRA_DSI_PIXEL_FORMAT_18BIT_NP:
1542 rgb_info = CMD_RGB_18BPPNP;
1544 case TEGRA_DSI_PIXEL_FORMAT_24BIT_P:
1546 rgb_info = CMD_RGB_24BPP;
1550 pkt_seq_3_5_rgb_lo = 0;
1551 pkt_seq_3_5_rgb_hi = 0;
1552 if (dsi->info.pkt_seq)
1553 pkt_seq = dsi->info.pkt_seq;
1554 else if (dsi->info.video_data_type ==
1555 TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE) {
1556 pkt_seq = dsi_pkt_seq_cmd_mode;
1558 switch (dsi->info.video_burst_mode) {
1559 case TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED:
1560 case TEGRA_DSI_VIDEO_BURST_MODE_LOW_SPEED:
1561 case TEGRA_DSI_VIDEO_BURST_MODE_MEDIUM_SPEED:
1562 case TEGRA_DSI_VIDEO_BURST_MODE_FAST_SPEED:
1563 case TEGRA_DSI_VIDEO_BURST_MODE_FASTEST_SPEED:
1564 pkt_seq_3_5_rgb_lo =
1565 DSI_PKT_SEQ_3_LO_PKT_32_ID(rgb_info);
1566 if (!dsi->info.no_pkt_seq_eot)
1567 pkt_seq = dsi_pkt_seq_video_burst;
1569 pkt_seq = dsi_pkt_seq_video_burst_no_eot;
1571 case TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END:
1572 pkt_seq_3_5_rgb_hi =
1573 DSI_PKT_SEQ_3_HI_PKT_34_ID(rgb_info);
1574 pkt_seq = dsi_pkt_seq_video_non_burst_syne;
1576 case TEGRA_DSI_VIDEO_NONE_BURST_MODE:
1578 if (dsi->info.ganged_type) {
1579 pkt_seq_3_5_rgb_lo =
1580 DSI_PKT_SEQ_3_LO_PKT_31_ID(rgb_info);
1582 dsi_pkt_seq_video_non_burst_no_eot_no_lp_no_hbp;
1584 pkt_seq_3_5_rgb_lo =
1585 DSI_PKT_SEQ_3_LO_PKT_32_ID(rgb_info);
1586 pkt_seq = dsi_pkt_seq_video_non_burst;
1589 /* Simulator does not support EOT packet yet */
1590 if (tegra_cpu_is_asim())
1591 pkt_seq = dsi_pkt_seq_video_non_burst_no_eot;
1596 for (i = 0; i < NUMOF_PKT_SEQ; i++) {
1598 reg = dsi_pkt_seq_reg[i];
1599 if ((reg == DSI_PKT_SEQ_3_LO) || (reg == DSI_PKT_SEQ_5_LO))
1600 val |= pkt_seq_3_5_rgb_lo;
1601 if ((reg == DSI_PKT_SEQ_3_HI) || (reg == DSI_PKT_SEQ_5_HI))
1602 val |= pkt_seq_3_5_rgb_hi;
1603 tegra_dsi_writel(dsi, val, reg);
1607 static void tegra_dsi_reset_underflow_overflow
1608 (struct tegra_dc_dsi_data *dsi)
1612 val = tegra_dsi_readl(dsi, DSI_STATUS);
1613 val &= (DSI_STATUS_LB_OVERFLOW(0x1) | DSI_STATUS_LB_UNDERFLOW(0x1));
1615 if (val & DSI_STATUS_LB_OVERFLOW(0x1))
1616 dev_warn(&dsi->dc->ndev->dev,
1617 "dsi: video fifo overflow. Resetting flag\n");
1618 if (val & DSI_STATUS_LB_UNDERFLOW(0x1))
1619 dev_warn(&dsi->dc->ndev->dev,
1620 "dsi: video fifo underflow. Resetting flag\n");
1621 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
1622 val |= DSI_HOST_CONTROL_FIFO_STAT_RESET(0x1);
1623 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
1628 static void tegra_dsi_soft_reset(struct tegra_dc_dsi_data *dsi)
1632 u32 frame_period = DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
1633 struct tegra_dc_mode mode = dsi->dc->mode;
1634 u32 tot_lines = mode.v_sync_width + mode.v_back_porch +
1635 mode.v_active + mode.v_front_porch;
1636 u32 line_period = DIV_ROUND_UP(MS_TO_US(frame_period), tot_lines);
1637 u32 timeout_cnt = 0;
1639 /* wait for 1 frame duration + few extra cycles for dsi to go idle */
1640 #define DSI_IDLE_TIMEOUT (tot_lines + 5)
1642 val = tegra_dsi_readl(dsi, DSI_STATUS);
1643 while (!(val & DSI_STATUS_IDLE(0x1))) {
1645 udelay(line_period);
1646 val = tegra_dsi_readl(dsi, DSI_STATUS);
1647 if (timeout_cnt++ > DSI_IDLE_TIMEOUT) {
1648 dev_warn(&dsi->dc->ndev->dev, "dsi not idle when soft reset\n");
1653 tegra_dsi_writel(dsi,
1654 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE),
1656 /* stabilization delay */
1659 tegra_dsi_writel(dsi,
1660 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_ENABLE),
1662 /* stabilization delay */
1665 /* dsi HW does not clear host trigger bit automatically
1666 * on dsi interface disable if host fifo is empty or in mid
1667 * of host transmission
1669 trigger = tegra_dsi_readl(dsi, DSI_TRIGGER);
1671 tegra_dsi_writel(dsi, 0x0, DSI_TRIGGER);
1673 #undef DSI_IDLE_TIMEOUT
1676 static void tegra_dsi_stop_dc_stream(struct tegra_dc *dc,
1677 struct tegra_dc_dsi_data *dsi)
1681 tegra_dc_writel(dc, DISP_CTRL_MODE_STOP, DC_CMD_DISPLAY_COMMAND);
1682 tegra_dc_writel(dc, 0, DC_DISP_DISP_WIN_OPTIONS);
1683 tegra_dc_writel(dc, GENERAL_UPDATE, DC_CMD_STATE_CONTROL);
1684 tegra_dc_writel(dc, GENERAL_ACT_REQ , DC_CMD_STATE_CONTROL);
1688 dsi->status.dc_stream = DSI_DC_STREAM_DISABLE;
1691 /* wait for frame end interrupt or (timeout_n_frames * 1 frame duration)
1692 * whichever happens to occur first
1694 static int tegra_dsi_wait_frame_end(struct tegra_dc *dc,
1695 struct tegra_dc_dsi_data *dsi,
1696 u32 timeout_n_frames)
1699 u32 frame_period = DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
1700 struct tegra_dc_mode mode = dc->mode;
1701 u32 line_period = DIV_ROUND_UP(
1702 MS_TO_US(frame_period),
1703 mode.v_sync_width + mode.v_back_porch +
1704 mode.v_active + mode.v_front_porch);
1706 if (timeout_n_frames < 2)
1707 dev_WARN(&dc->ndev->dev,
1708 "dsi: to stop at next frame give at least 2 frame delay\n");
1710 timeout = tegra_dc_wait_for_frame_end(dc, timeout_n_frames *
1713 /* wait for v_ref_to_sync no. of lines after frame end interrupt */
1714 udelay(mode.v_ref_to_sync * line_period);
1719 static void tegra_dsi_stop_dc_stream_at_frame_end(struct tegra_dc *dc,
1720 struct tegra_dc_dsi_data *dsi,
1721 u32 timeout_n_frames)
1723 tegra_dsi_stop_dc_stream(dc, dsi);
1725 tegra_dsi_wait_frame_end(dc, dsi, timeout_n_frames);
1727 tegra_dsi_soft_reset(dsi);
1729 tegra_dsi_reset_underflow_overflow(dsi);
1732 static void tegra_dc_gpio_to_spio(struct tegra_dc_dsi_data *dsi, unsigned gpio)
1736 /* convert to spio */
1737 err = gpio_request(gpio, "temp_request");
1739 dev_err(&dsi->dc->ndev->dev,
1740 "dsi: %s: gpio request failed %d\n", __func__, err);
1746 static void tegra_dsi_start_dc_stream(struct tegra_dc *dc,
1747 struct tegra_dc_dsi_data *dsi)
1752 tegra_dvfs_set_rate(dc->clk, dc->mode.pclk);
1754 tegra_dc_writel(dc, DSI_ENABLE, DC_DISP_DISP_WIN_OPTIONS);
1756 /* TODO: clean up */
1757 tegra_dc_writel(dc, PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
1758 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE,
1759 DC_CMD_DISPLAY_POWER_CONTROL);
1761 /* Configure one-shot mode or continuous mode */
1762 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_MODE) {
1763 /* disable LSPI/LCD_DE output */
1764 val = PIN_OUTPUT_LSPI_OUTPUT_DIS;
1765 tegra_dc_writel(dc, val, DC_COM_PIN_OUTPUT_ENABLE3);
1767 /* enable MSF & set MSF polarity */
1768 val = MSF_ENABLE | MSF_LSPI;
1769 if (!dsi->info.te_polarity_low)
1770 val |= MSF_POLARITY_HIGH;
1772 val |= MSF_POLARITY_LOW;
1773 tegra_dc_writel(dc, val, DC_CMD_DISPLAY_COMMAND_OPTION0);
1775 /* set non-continuous mode */
1776 tegra_dc_writel(dc, DISP_CTRL_MODE_NC_DISPLAY,
1777 DC_CMD_DISPLAY_COMMAND);
1779 tegra_dc_writel(dc, GENERAL_UPDATE, DC_CMD_STATE_CONTROL);
1780 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
1782 if (dsi->info.te_gpio)
1783 tegra_dc_gpio_to_spio(dsi, dsi->info.te_gpio);
1785 /* set continuous mode */
1786 tegra_dc_writel(dc, DISP_CTRL_MODE_C_DISPLAY,
1787 DC_CMD_DISPLAY_COMMAND);
1788 tegra_dc_writel(dc, GENERAL_UPDATE, DC_CMD_STATE_CONTROL);
1789 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
1794 dsi->status.dc_stream = DSI_DC_STREAM_ENABLE;
1797 static void tegra_dsi_set_dc_clk(struct tegra_dc *dc,
1798 struct tegra_dc_dsi_data *dsi)
1800 u32 shift_clk_div_register;
1803 /* formula: (dsi->shift_clk_div - 1) * 2 */
1804 shift_clk_div_register = DIV_ROUND_CLOSEST(
1805 ((dsi->shift_clk_div.mul -
1806 dsi->shift_clk_div.div) * 2),
1807 dsi->shift_clk_div.div);
1809 if (tegra_platform_is_fpga()) {
1810 shift_clk_div_register = 1;
1811 if (dsi->info.ganged_type)
1812 shift_clk_div_register = 0;
1817 val = PIXEL_CLK_DIVIDER_PCD1 |
1818 SHIFT_CLK_DIVIDER(shift_clk_div_register + 2);
1820 /* SW WAR for bug 1045373. To make the shift clk dividor effect under
1821 * all circumstances, write N+2 to SHIFT_CLK_DIVIDER and activate it.
1822 * After 2us delay, write the target values to it. */
1823 #if defined(CONFIG_ARCH_TEGRA_14x_SOC) || defined(CONFIG_ARCH_11x_SOC)
1824 tegra_dc_writel(dc, val, DC_DISP_DISP_CLOCK_CONTROL);
1825 tegra_dc_writel(dc, GENERAL_UPDATE, DC_CMD_STATE_CONTROL);
1826 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
1831 /* TODO: find out if PCD3 option is required */
1832 val = PIXEL_CLK_DIVIDER_PCD1 |
1833 SHIFT_CLK_DIVIDER(shift_clk_div_register);
1835 tegra_dc_writel(dc, val, DC_DISP_DISP_CLOCK_CONTROL);
1840 static void tegra_dsi_set_dsi_clk(struct tegra_dc *dc,
1841 struct tegra_dc_dsi_data *dsi, u32 clk)
1846 /* Round up to MHz */
1851 /* Set up pixel clock */
1852 pclk_khz = (clk * dsi->shift_clk_div.div) /
1853 dsi->shift_clk_div.mul;
1855 dc->mode.pclk = pclk_khz * 1000;
1857 dc->shift_clk_div.mul = dsi->shift_clk_div.mul;
1858 dc->shift_clk_div.div = dsi->shift_clk_div.div;
1860 /* TODO: Define one shot work delay in board file. */
1861 /* Since for one-shot mode, refresh rate is usually set larger than
1862 * expected refresh rate, it needs at least 3 frame period. Less
1863 * delay one shot work is, more powering saving we have. */
1864 dc->one_shot_delay_ms = 4 *
1865 DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
1867 tegra_dsi_setup_clk(dc, dsi);
1868 tegra_dsi_reset_deassert(dsi);
1870 dsi->current_dsi_clk_khz =
1871 clk_get_rate(dsi->dsi_clk[0]) / 1000;
1872 dsi->current_bit_clk_ps = DIV_ROUND_CLOSEST((1000 * 1000 * 1000),
1873 (dsi->current_dsi_clk_khz * 2));
1876 static void tegra_dsi_hs_clk_out_enable(struct tegra_dc_dsi_data *dsi)
1880 val = tegra_dsi_readl(dsi, DSI_CONTROL);
1881 val &= ~DSI_CONTROL_HS_CLK_CTRL(1);
1883 if (dsi->info.video_clock_mode == TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS) {
1884 val |= DSI_CONTROL_HS_CLK_CTRL(CONTINUOUS);
1885 dsi->status.clk_mode = DSI_PHYCLK_CONTINUOUS;
1887 val |= DSI_CONTROL_HS_CLK_CTRL(TX_ONLY);
1888 dsi->status.clk_mode = DSI_PHYCLK_TX_ONLY;
1890 tegra_dsi_writel(dsi, val, DSI_CONTROL);
1892 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
1893 val &= ~DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(1);
1894 val |= DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(TEGRA_DSI_HIGH);
1895 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
1897 dsi->status.clk_out = DSI_PHYCLK_OUT_EN;
1900 static void tegra_dsi_hs_clk_out_enable_in_lp(struct tegra_dc_dsi_data *dsi)
1903 tegra_dsi_hs_clk_out_enable(dsi);
1905 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
1906 val &= ~DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(1);
1907 val |= DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(TEGRA_DSI_LOW);
1908 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
1911 static void tegra_dsi_hs_clk_out_disable(struct tegra_dc *dc,
1912 struct tegra_dc_dsi_data *dsi)
1916 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
1917 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
1919 tegra_dsi_writel(dsi, TEGRA_DSI_DISABLE, DSI_POWER_CONTROL);
1920 /* stabilization delay */
1923 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
1924 val &= ~DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(1);
1925 val |= DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(TEGRA_DSI_LOW);
1926 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
1928 tegra_dsi_writel(dsi, TEGRA_DSI_ENABLE, DSI_POWER_CONTROL);
1929 /* stabilization delay */
1932 dsi->status.clk_mode = DSI_PHYCLK_NOT_INIT;
1933 dsi->status.clk_out = DSI_PHYCLK_OUT_DIS;
1936 static void tegra_dsi_set_control_reg_lp(struct tegra_dc_dsi_data *dsi)
1939 u32 host_dsi_control;
1942 dsi_control = dsi->dsi_control_val | DSI_CTRL_HOST_DRIVEN;
1943 host_dsi_control = HOST_DSI_CTRL_COMMON |
1944 HOST_DSI_CTRL_HOST_DRIVEN |
1945 DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(TEGRA_DSI_LOW);
1946 max_threshold = DSI_MAX_THRESHOLD_MAX_THRESHOLD(DSI_HOST_FIFO_DEPTH);
1948 tegra_dsi_writel(dsi, max_threshold, DSI_MAX_THRESHOLD);
1949 tegra_dsi_writel(dsi, dsi_control, DSI_CONTROL);
1950 tegra_dsi_writel(dsi, host_dsi_control, DSI_HOST_DSI_CONTROL);
1952 dsi->status.driven = DSI_DRIVEN_MODE_HOST;
1953 dsi->status.clk_burst = DSI_CLK_BURST_NOT_INIT;
1954 dsi->status.vtype = DSI_VIDEO_TYPE_NOT_INIT;
1957 static void tegra_dsi_set_control_reg_hs(struct tegra_dc_dsi_data *dsi,
1961 u32 host_dsi_control;
1965 dsi_control = dsi->dsi_control_val;
1966 host_dsi_control = HOST_DSI_CTRL_COMMON;
1970 if (driven_mode == TEGRA_DSI_DRIVEN_BY_HOST) {
1971 dsi_control |= DSI_CTRL_HOST_DRIVEN;
1972 host_dsi_control |= HOST_DSI_CTRL_HOST_DRIVEN;
1974 DSI_MAX_THRESHOLD_MAX_THRESHOLD(DSI_HOST_FIFO_DEPTH);
1975 dsi->status.driven = DSI_DRIVEN_MODE_HOST;
1977 dsi_control |= DSI_CTRL_DC_DRIVEN;
1978 host_dsi_control |= HOST_DSI_CTRL_DC_DRIVEN;
1980 DSI_MAX_THRESHOLD_MAX_THRESHOLD(DSI_VIDEO_FIFO_DEPTH);
1981 dsi->status.driven = DSI_DRIVEN_MODE_DC;
1983 if (dsi->info.video_data_type ==
1984 TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE) {
1985 dsi_control |= DSI_CTRL_CMD_MODE;
1986 dcs_cmd = DSI_DCS_CMDS_LT5_DCS_CMD(
1987 DSI_WRITE_MEMORY_START)|
1988 DSI_DCS_CMDS_LT3_DCS_CMD(
1989 DSI_WRITE_MEMORY_CONTINUE);
1990 dsi->status.vtype = DSI_VIDEO_TYPE_CMD_MODE;
1992 dsi_control |= DSI_CTRL_VIDEO_MODE;
1993 dsi->status.vtype = DSI_VIDEO_TYPE_VIDEO_MODE;
1997 tegra_dsi_writel(dsi, max_threshold, DSI_MAX_THRESHOLD);
1998 tegra_dsi_writel(dsi, dcs_cmd, DSI_DCS_CMDS);
1999 tegra_dsi_writel(dsi, dsi_control, DSI_CONTROL);
2000 tegra_dsi_writel(dsi, host_dsi_control, DSI_HOST_DSI_CONTROL);
2003 static void tegra_dsi_pad_disable(struct tegra_dc_dsi_data *dsi)
2007 if (dsi->info.controller_vs == DSI_VS_1) {
2008 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_0_VS1);
2009 val &= ~(DSI_PAD_CONTROL_0_VS1_PAD_PDIO(0xf) |
2010 DSI_PAD_CONTROL_0_VS1_PAD_PDIO_CLK(0x1) |
2011 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_ENAB(0xf) |
2012 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_CLK_ENAB(0x1));
2013 val |= DSI_PAD_CONTROL_0_VS1_PAD_PDIO(0xf) |
2014 DSI_PAD_CONTROL_0_VS1_PAD_PDIO_CLK
2015 (TEGRA_DSI_PAD_DISABLE) |
2016 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_ENAB(0xf) |
2017 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_CLK_ENAB
2018 (TEGRA_DSI_PAD_DISABLE);
2019 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_0_VS1);
2021 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL);
2022 val &= ~(DSI_PAD_CONTROL_PAD_PDIO(0x3) |
2023 DSI_PAD_CONTROL_PAD_PDIO_CLK(0x1) |
2024 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(0x1));
2025 val |= DSI_PAD_CONTROL_PAD_PDIO(0x3) |
2026 DSI_PAD_CONTROL_PAD_PDIO_CLK(TEGRA_DSI_PAD_DISABLE) |
2027 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(TEGRA_DSI_PAD_DISABLE);
2028 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL);
2032 static void tegra_dsi_pad_enable(struct tegra_dc_dsi_data *dsi)
2036 if (dsi->info.controller_vs == DSI_VS_1) {
2037 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_0_VS1);
2038 val &= ~(DSI_PAD_CONTROL_0_VS1_PAD_PDIO(0xf) |
2039 DSI_PAD_CONTROL_0_VS1_PAD_PDIO_CLK(0x1) |
2040 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_ENAB(0xf) |
2041 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_CLK_ENAB(0x1));
2042 val |= DSI_PAD_CONTROL_0_VS1_PAD_PDIO(TEGRA_DSI_PAD_ENABLE) |
2043 DSI_PAD_CONTROL_0_VS1_PAD_PDIO_CLK(
2044 TEGRA_DSI_PAD_ENABLE) |
2045 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_ENAB(
2046 TEGRA_DSI_PAD_ENABLE) |
2047 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_CLK_ENAB(
2048 TEGRA_DSI_PAD_ENABLE);
2049 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_0_VS1);
2051 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL);
2052 val &= ~(DSI_PAD_CONTROL_PAD_PDIO(0x3) |
2053 DSI_PAD_CONTROL_PAD_PDIO_CLK(0x1) |
2054 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(0x1));
2055 val |= DSI_PAD_CONTROL_PAD_PDIO(TEGRA_DSI_PAD_ENABLE) |
2056 DSI_PAD_CONTROL_PAD_PDIO_CLK(TEGRA_DSI_PAD_ENABLE) |
2057 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(TEGRA_DSI_PAD_ENABLE);
2058 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL);
2062 static void __maybe_unused
2063 tegra_dsi_mipi_calibration_status(struct tegra_dc_dsi_data *dsi)
2067 /* Start calibration */
2068 val = tegra_mipi_cal_read(dsi->mipi_cal,
2069 MIPI_CAL_MIPI_CAL_CTRL_0);
2070 val |= (MIPI_CAL_STARTCAL(0x1));
2071 tegra_mipi_cal_write(dsi->mipi_cal, val,
2072 MIPI_CAL_MIPI_CAL_CTRL_0);
2074 for (timeout = MIPI_DSI_AUTOCAL_TIMEOUT_USEC;
2075 timeout; timeout -= 100) {
2076 val = tegra_mipi_cal_read(dsi->mipi_cal,
2077 MIPI_CAL_CIL_MIPI_CAL_STATUS_0);
2078 if (!(val & MIPI_CAL_ACTIVE(0x1)) &&
2079 (val & MIPI_AUTO_CAL_DONE(0x1))) {
2080 dev_info(&dsi->dc->ndev->dev, "DSI pad calibration done\n");
2083 usleep_range(10, 100);
2086 dev_info(&dsi->dc->ndev->dev, "DSI calibration timed out\n");
2089 #ifdef CONFIG_ARCH_TEGRA_12x_SOC
2090 static void tegra_dsi_mipi_calibration_12x(struct tegra_dc_dsi_data *dsi)
2093 struct clk *clk72mhz = NULL;
2095 clk72mhz = clk_get_sys("clk72mhz", NULL);
2096 if (IS_ERR_OR_NULL(clk72mhz)) {
2097 dev_err(&dsi->dc->ndev->dev, "dsi: can't get clk72mhz clock\n");
2100 clk_prepare_enable(clk72mhz);
2102 /* Calibration settings begin */
2103 val = tegra_mipi_cal_read(dsi->mipi_cal,
2104 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2105 val &= ~PAD_DRIV_UP_REF(0x7);
2106 val |= PAD_DRIV_UP_REF(0x3);
2107 tegra_mipi_cal_write(dsi->mipi_cal, val,
2108 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2109 /*Bug 1445912: override tap delay for panel-a-1200-1920-7-0 */
2110 if (dsi->info.boardinfo.platform_boardid == BOARD_P1761 &&
2111 dsi->info.boardinfo.display_boardversion == 1) {
2112 val = (DSI_PAD_OUTADJ3(0x4) | DSI_PAD_OUTADJ2(0x4) |
2113 DSI_PAD_OUTADJ1(0x4) | DSI_PAD_OUTADJ0(0x4));
2114 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_1_VS1);
2117 val = (DSI_PAD_SLEWUPADJ(0x7) | DSI_PAD_SLEWDNADJ(0x7) |
2118 DSI_PAD_LPUPADJ(0x1) | DSI_PAD_LPDNADJ(0x1) |
2119 DSI_PAD_OUTADJCLK(0x0));
2120 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_2_VS1);
2122 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_3_VS1);
2123 val |= (DSI_PAD_PREEMP_PD_CLK(0x3) | DSI_PAD_PREEMP_PU_CLK(0x3) |
2124 DSI_PAD_PREEMP_PD(0x3) | DSI_PAD_PREEMP_PU(0x3));
2125 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
2127 /* Calibrate DSI 0 */
2128 if (dsi->info.ganged_type ||
2129 dsi->info.dsi_instance == DSI_INSTANCE_0) {
2130 val = MIPI_CAL_OVERIDEDSIA(0x0) |
2131 MIPI_CAL_SELDSIA(0x1) |
2132 MIPI_CAL_HSPDOSDSIA(0x0) |
2133 MIPI_CAL_HSPUOSDSIA(0x0) |
2134 MIPI_CAL_TERMOSDSIA(0x0);
2135 tegra_mipi_cal_write(dsi->mipi_cal, val,
2136 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2137 tegra_mipi_cal_write(dsi->mipi_cal, val,
2138 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2140 val = (MIPI_CAL_CLKSELDSIA(0x1) |
2141 MIPI_CAL_HSCLKPDOSDSIA(0x1) |
2142 MIPI_CAL_HSCLKPUOSDSIA(0x2));
2143 tegra_mipi_cal_write(dsi->mipi_cal, val,
2144 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2145 tegra_mipi_cal_write(dsi->mipi_cal, val,
2146 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2148 /* Deselect PAD C */
2149 val = tegra_mipi_cal_read(dsi->mipi_cal,
2150 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2151 val &= ~(MIPI_CAL_SELDSIC(0x1));
2152 tegra_mipi_cal_write(dsi->mipi_cal, val,
2153 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2155 /* Deselect PAD D */
2156 val = tegra_mipi_cal_read(dsi->mipi_cal,
2157 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2158 val &= ~(MIPI_CAL_SELDSID(0x1));
2159 tegra_mipi_cal_write(dsi->mipi_cal, val,
2160 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2162 val = MIPI_CAL_NOISE_FLT(0xa) |
2163 MIPI_CAL_PRESCALE(0x2) |
2164 MIPI_CAL_CLKEN_OVR(0x1) |
2165 MIPI_CAL_AUTOCAL_EN(0x0);
2166 tegra_mipi_cal_write(dsi->mipi_cal, val,
2167 MIPI_CAL_MIPI_CAL_CTRL_0);
2169 tegra_dsi_mipi_calibration_status(dsi);
2171 /* Calibrate DSI 1 */
2172 if (dsi->info.ganged_type ||
2173 dsi->info.dsi_instance == DSI_INSTANCE_1) {
2174 val = MIPI_CAL_OVERIDEC(0x0) |
2175 MIPI_CAL_SELC(0x1) |
2176 MIPI_CAL_HSPDOSC(0x0) |
2177 MIPI_CAL_HSPUOSC(0x0) |
2178 MIPI_CAL_TERMOSC(0x0);
2179 tegra_mipi_cal_write(dsi->mipi_cal, val,
2180 MIPI_CAL_CILC_MIPI_CAL_CONFIG_0);
2181 tegra_mipi_cal_write(dsi->mipi_cal, val,
2182 MIPI_CAL_CILD_MIPI_CAL_CONFIG_0);
2184 val = (MIPI_CAL_CLKSELDSIA(0x1) |
2185 MIPI_CAL_HSCLKPDOSDSIA(0x1) |
2186 MIPI_CAL_HSCLKPUOSDSIA(0x2));
2187 tegra_mipi_cal_write(dsi->mipi_cal, val,
2188 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2189 tegra_mipi_cal_write(dsi->mipi_cal, val,
2190 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2192 /* Deselect PAD A */
2193 val = tegra_mipi_cal_read(dsi->mipi_cal,
2194 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2195 val &= ~(MIPI_CAL_SELDSIC(0x1));
2196 tegra_mipi_cal_write(dsi->mipi_cal, val,
2197 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2199 /* Deselect PAD B */
2200 val = tegra_mipi_cal_read(dsi->mipi_cal,
2201 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2202 val &= ~(MIPI_CAL_SELDSID(0x1));
2203 tegra_mipi_cal_write(dsi->mipi_cal, val,
2204 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2206 val = MIPI_CAL_NOISE_FLT(0xa) |
2207 MIPI_CAL_PRESCALE(0x2) |
2208 MIPI_CAL_CLKEN_OVR(0x1) |
2209 MIPI_CAL_AUTOCAL_EN(0x0);
2210 tegra_mipi_cal_write(dsi->mipi_cal, val,
2211 MIPI_CAL_MIPI_CAL_CTRL_0);
2213 tegra_dsi_mipi_calibration_status(dsi);
2216 clk_disable_unprepare(clk72mhz);
2220 #ifdef CONFIG_ARCH_TEGRA_14x_SOC
2221 void tegra_dsi_mipi_calibration_14x(struct tegra_dc_dsi_data *dsi)
2224 struct clk *clk72mhz = NULL;
2226 clk72mhz = clk_get_sys("clk72mhz", NULL);
2227 if (IS_ERR_OR_NULL(clk72mhz)) {
2228 dev_err(&dsi->dc->ndev->dev, "dsi: can't get clk72mhz clock\n");
2231 clk_prepare_enable(clk72mhz);
2233 tegra_mipi_cal_write(dsi->mipi_cal,
2234 PAD_DRIV_DN_REF(0x2),
2235 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2237 val = (DSI_PAD_SLEWUPADJ(0x7) | DSI_PAD_SLEWDNADJ(0x7) |
2238 DSI_PAD_LPUPADJ(0x1) | DSI_PAD_LPDNADJ(0x1));
2239 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_2_VS1);
2241 val = (DSI_PAD_PREEMP_PD(0x3) | DSI_PAD_PREEMP_PU(0x3));
2242 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
2244 val = MIPI_CAL_HSCLKPDOSDSIA(0x2) |
2245 MIPI_CAL_HSCLKPUOSDSIA(0x2);
2246 tegra_mipi_cal_write(dsi->mipi_cal, val,
2247 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2248 tegra_mipi_cal_write(dsi->mipi_cal, val,
2249 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2251 val = MIPI_CAL_OVERIDEDSIA(0x0) |
2252 MIPI_CAL_SELDSIA(0x1) |
2253 MIPI_CAL_HSPDOSDSIA(0x0) |
2254 MIPI_CAL_HSPUOSDSIA(0x0) |
2255 MIPI_CAL_TERMOSDSIA(0x0);
2256 tegra_mipi_cal_write(dsi->mipi_cal, val,
2257 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2258 tegra_mipi_cal_write(dsi->mipi_cal, val,
2259 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2261 val = MIPI_CAL_NOISE_FLT(0xa) |
2262 MIPI_CAL_PRESCALE(0x2) |
2263 MIPI_CAL_CLKEN_OVR(0x1) |
2264 MIPI_CAL_AUTOCAL_EN(0x0);
2265 tegra_mipi_cal_write(dsi->mipi_cal, val,
2266 MIPI_CAL_MIPI_CAL_CTRL_0);
2268 tegra_dsi_mipi_calibration_status(dsi);
2270 clk_disable_unprepare(clk72mhz);
2274 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
2275 static void tegra_dsi_mipi_calibration_11x(struct tegra_dc_dsi_data *dsi)
2278 /* Calibration settings begin */
2279 val = (DSI_PAD_SLEWUPADJ(0x7) | DSI_PAD_SLEWDNADJ(0x7) |
2280 DSI_PAD_LPUPADJ(0x1) | DSI_PAD_LPDNADJ(0x1) |
2281 DSI_PAD_OUTADJCLK(0x0));
2282 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_2_VS1);
2284 /* Calibrate DSI 0 */
2285 if (dsi->info.ganged_type ||
2286 dsi->info.dsi_instance == DSI_INSTANCE_0) {
2287 val = tegra_mipi_cal_read(dsi->mipi_cal,
2288 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2289 val = MIPI_CAL_OVERIDEDSIA(0x0) |
2290 MIPI_CAL_SELDSIA(0x1) |
2291 MIPI_CAL_HSPDOSDSIA(0x0) |
2292 MIPI_CAL_HSPUOSDSIA(0x4) |
2293 MIPI_CAL_TERMOSDSIA(0x5);
2294 tegra_mipi_cal_write(dsi->mipi_cal, val,
2295 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2296 tegra_mipi_cal_write(dsi->mipi_cal, val,
2297 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2299 /* Deselect PAD C */
2300 val = tegra_mipi_cal_read(dsi->mipi_cal,
2301 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2302 val &= ~(MIPI_CAL_SELDSIC(0x1));
2303 tegra_mipi_cal_write(dsi->mipi_cal, val,
2304 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2306 /* Deselect PAD D */
2307 val = tegra_mipi_cal_read(dsi->mipi_cal,
2308 MIPI_CAL_DSID_MIPI_CAL_CONFIG_0);
2309 val &= ~(MIPI_CAL_SELDSID(0x1));
2310 tegra_mipi_cal_write(dsi->mipi_cal, val,
2311 MIPI_CAL_DSID_MIPI_CAL_CONFIG_0);
2313 val = tegra_mipi_cal_read(dsi->mipi_cal,
2314 MIPI_CAL_MIPI_CAL_CTRL_0);
2315 val = MIPI_CAL_NOISE_FLT(0xa) |
2316 MIPI_CAL_PRESCALE(0x2) |
2317 MIPI_CAL_CLKEN_OVR(0x1) |
2318 MIPI_CAL_AUTOCAL_EN(0x0);
2319 tegra_mipi_cal_write(dsi->mipi_cal, val,
2320 MIPI_CAL_MIPI_CAL_CTRL_0);
2322 tegra_dsi_mipi_calibration_status(dsi);
2325 /* Calibrate DSI 1 */
2326 if (dsi->info.ganged_type ||
2327 dsi->info.dsi_instance == DSI_INSTANCE_1) {
2328 val = tegra_mipi_cal_read(dsi->mipi_cal,
2329 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2330 val = MIPI_CAL_OVERIDEDSIC(0x0) |
2331 MIPI_CAL_SELDSIC(0x1) |
2332 MIPI_CAL_HSPDOSDSIC(0x0) |
2333 MIPI_CAL_HSPUOSDSIC(0x4) |
2334 MIPI_CAL_TERMOSDSIC(0x5);
2335 tegra_mipi_cal_write(dsi->mipi_cal, val,
2336 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2337 tegra_mipi_cal_write(dsi->mipi_cal, val,
2338 MIPI_CAL_DSID_MIPI_CAL_CONFIG_0);
2340 /* Deselect PAD A */
2341 val = tegra_mipi_cal_read(dsi->mipi_cal,
2342 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2343 val &= ~(MIPI_CAL_SELDSIA(0x1));
2344 tegra_mipi_cal_write(dsi->mipi_cal, val,
2345 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2347 /* Deselect PAD B */
2348 val = tegra_mipi_cal_read(dsi->mipi_cal,
2349 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2350 val &= ~(MIPI_CAL_SELDSIB(0x1));
2351 tegra_mipi_cal_write(dsi->mipi_cal, val,
2352 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2354 val = tegra_mipi_cal_read(dsi->mipi_cal,
2355 MIPI_CAL_MIPI_CAL_CTRL_0);
2356 val = MIPI_CAL_NOISE_FLT(0xa) |
2357 MIPI_CAL_PRESCALE(0x2) |
2358 MIPI_CAL_CLKEN_OVR(0x1) |
2359 MIPI_CAL_AUTOCAL_EN(0x0);
2360 tegra_mipi_cal_write(dsi->mipi_cal, val,
2361 MIPI_CAL_MIPI_CAL_CTRL_0);
2363 tegra_dsi_mipi_calibration_status(dsi);
2367 static void tegra_dsi_pad_calibration(struct tegra_dc_dsi_data *dsi)
2370 tegra_dsi_pad_enable(dsi);
2372 tegra_dsi_pad_disable(dsi);
2374 if (dsi->info.controller_vs == DSI_VS_1) {
2376 tegra_mipi_cal_init_hw(dsi->mipi_cal);
2378 tegra_mipi_cal_clk_enable(dsi->mipi_cal);
2380 tegra_mipi_cal_write(dsi->mipi_cal,
2381 MIPI_BIAS_PAD_E_VCLAMP_REF(0x1),
2382 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2383 tegra_mipi_cal_write(dsi->mipi_cal,
2384 PAD_PDVREG(0x0) | PAD_VCLAMP_LEVEL(0x0),
2385 MIPI_CAL_MIPI_BIAS_PAD_CFG2_0);
2386 #if defined(CONFIG_ARCH_TEGRA_11x_SOC)
2387 tegra_dsi_mipi_calibration_11x(dsi);
2388 #elif defined(CONFIG_ARCH_TEGRA_14x_SOC)
2389 tegra_dsi_mipi_calibration_14x(dsi);
2390 #elif defined(CONFIG_ARCH_TEGRA_12x_SOC)
2391 tegra_dsi_mipi_calibration_12x(dsi);
2393 tegra_mipi_cal_clk_disable(dsi->mipi_cal);
2395 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
2398 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL);
2399 val &= ~(DSI_PAD_CONTROL_PAD_LPUPADJ(0x3) |
2400 DSI_PAD_CONTROL_PAD_LPDNADJ(0x3) |
2401 DSI_PAD_CONTROL_PAD_PREEMP_EN(0x1) |
2402 DSI_PAD_CONTROL_PAD_SLEWDNADJ(0x7) |
2403 DSI_PAD_CONTROL_PAD_SLEWUPADJ(0x7));
2405 val |= DSI_PAD_CONTROL_PAD_LPUPADJ(0x1) |
2406 DSI_PAD_CONTROL_PAD_LPDNADJ(0x1) |
2407 DSI_PAD_CONTROL_PAD_PREEMP_EN(0x1) |
2408 DSI_PAD_CONTROL_PAD_SLEWDNADJ(0x6) |
2409 DSI_PAD_CONTROL_PAD_SLEWUPADJ(0x6);
2411 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL);
2413 val = MIPI_CAL_TERMOSA(0x4);
2414 tegra_vi_csi_writel(val, CSI_CILA_MIPI_CAL_CONFIG_0);
2416 val = MIPI_CAL_TERMOSB(0x4);
2417 tegra_vi_csi_writel(val, CSI_CILB_MIPI_CAL_CONFIG_0);
2419 val = MIPI_CAL_HSPUOSD(0x3) | MIPI_CAL_HSPDOSD(0x4);
2420 tegra_vi_csi_writel(val, CSI_DSI_MIPI_CAL_CONFIG);
2422 val = PAD_DRIV_DN_REF(0x5) | PAD_DRIV_UP_REF(0x7);
2423 tegra_vi_csi_writel(val, CSI_MIPIBIAS_PAD_CONFIG);
2425 val = PAD_CIL_PDVREG(0x0);
2426 tegra_vi_csi_writel(val, CSI_CIL_PAD_CONFIG);
2431 static void tegra_dsi_panelB_enable(void)
2435 val = readl(IO_ADDRESS(APB_MISC_GP_MIPI_PAD_CTRL_0));
2436 val |= DSIB_MODE_ENABLE;
2437 writel(val, (IO_ADDRESS(APB_MISC_GP_MIPI_PAD_CTRL_0)));
2440 static int tegra_dsi_init_hw(struct tegra_dc *dc,
2441 struct tegra_dc_dsi_data *dsi)
2446 if (dsi->avdd_dsi_csi)
2447 err = regulator_enable(dsi->avdd_dsi_csi);
2448 if (WARN(err, "unable to enable regulator"))
2450 /* stablization delay */
2452 /* Enable DSI clocks */
2453 tegra_dsi_clk_enable(dsi);
2454 tegra_dsi_set_dsi_clk(dc, dsi, dsi->target_lp_clk_khz);
2456 /* Stop DC stream before configuring DSI registers
2457 * to avoid visible glitches on panel during transition
2458 * from bootloader to kernel driver
2460 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
2462 tegra_dsi_writel(dsi,
2463 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE),
2465 /* stabilization delay */
2468 if (dsi->info.dsi_instance || dsi->info.ganged_type)
2469 tegra_dsi_panelB_enable();
2471 tegra_dsi_set_phy_timing(dsi, DSI_LPHS_IN_LP_MODE);
2473 /* Initialize DSI registers */
2474 for (i = 0; i < ARRAY_SIZE(init_reg); i++)
2475 tegra_dsi_writel(dsi, 0, init_reg[i]);
2476 if (dsi->info.controller_vs == DSI_VS_1) {
2477 for (i = 0; i < ARRAY_SIZE(init_reg_vs1_ext); i++)
2478 tegra_dsi_writel(dsi, 0, init_reg_vs1_ext[i]);
2481 tegra_dsi_pad_calibration(dsi);
2483 tegra_dsi_writel(dsi,
2484 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_ENABLE),
2486 /* stabilization delay */
2489 dsi->status.init = DSI_MODULE_INIT;
2490 dsi->status.lphs = DSI_LPHS_NOT_INIT;
2491 dsi->status.vtype = DSI_VIDEO_TYPE_NOT_INIT;
2492 dsi->status.driven = DSI_DRIVEN_MODE_NOT_INIT;
2493 dsi->status.clk_out = DSI_PHYCLK_OUT_DIS;
2494 dsi->status.clk_mode = DSI_PHYCLK_NOT_INIT;
2495 dsi->status.clk_burst = DSI_CLK_BURST_NOT_INIT;
2496 dsi->status.dc_stream = DSI_DC_STREAM_DISABLE;
2497 dsi->status.lp_op = DSI_LP_OP_NOT_INIT;
2499 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
2500 tegra_dsi_syncpt_reset(dsi);
2505 static int tegra_dsi_set_to_lp_mode(struct tegra_dc *dc,
2506 struct tegra_dc_dsi_data *dsi, u8 lp_op)
2510 if (dsi->status.init != DSI_MODULE_INIT) {
2515 if (dsi->status.lphs == DSI_LPHS_IN_LP_MODE &&
2516 dsi->status.lp_op == lp_op)
2519 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
2520 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
2522 /* disable/enable hs clk according to enable_hs_clock_on_lp_cmd_mode */
2523 if ((dsi->status.clk_out == DSI_PHYCLK_OUT_EN) &&
2524 (!dsi->info.enable_hs_clock_on_lp_cmd_mode))
2525 tegra_dsi_hs_clk_out_disable(dc, dsi);
2527 dsi->target_lp_clk_khz = tegra_dsi_get_lp_clk_rate(dsi, lp_op);
2528 if (dsi->current_dsi_clk_khz != dsi->target_lp_clk_khz) {
2529 tegra_dsi_set_dsi_clk(dc, dsi, dsi->target_lp_clk_khz);
2530 tegra_dsi_set_timeout(dsi);
2533 tegra_dsi_set_phy_timing(dsi, DSI_LPHS_IN_LP_MODE);
2535 tegra_dsi_set_control_reg_lp(dsi);
2537 if ((dsi->status.clk_out == DSI_PHYCLK_OUT_DIS) &&
2538 (dsi->info.enable_hs_clock_on_lp_cmd_mode))
2539 tegra_dsi_hs_clk_out_enable_in_lp(dsi);
2541 dsi->status.lphs = DSI_LPHS_IN_LP_MODE;
2542 dsi->status.lp_op = lp_op;
2543 dsi->driven_mode = TEGRA_DSI_DRIVEN_BY_HOST;
2550 static void tegra_dsi_ganged(struct tegra_dc *dc,
2551 struct tegra_dc_dsi_data *dsi)
2555 u32 h_active = dc->out->modes->h_active;
2558 if (dsi->info.controller_vs < DSI_VS_1) {
2559 dev_err(&dc->ndev->dev, "dsi: ganged mode not"
2560 "supported with current controller version\n");
2564 if (dsi->info.ganged_type ==
2565 TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT) {
2567 tegra_dsi_controller_writel(dsi,
2568 DSI_GANGED_MODE_START_POINTER(0),
2569 DSI_GANGED_MODE_START, DSI_INSTANCE_0);
2571 tegra_dsi_controller_writel(dsi,
2572 DSI_GANGED_MODE_START_POINTER(h_active / 2),
2573 DSI_GANGED_MODE_START, DSI_INSTANCE_1);
2575 low_width = DIV_ROUND_UP(h_active, 2);
2576 high_width = h_active - low_width;
2577 val = DSI_GANGED_MODE_SIZE_VALID_LOW_WIDTH(low_width) |
2578 DSI_GANGED_MODE_SIZE_VALID_HIGH_WIDTH(high_width);
2580 } else if (dsi->info.ganged_type ==
2581 TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD) {
2583 tegra_dsi_controller_writel(dsi,
2584 DSI_GANGED_MODE_START_POINTER(0),
2585 DSI_GANGED_MODE_START, DSI_INSTANCE_0);
2587 tegra_dsi_controller_writel(dsi,
2588 DSI_GANGED_MODE_START_POINTER(1),
2589 DSI_GANGED_MODE_START, DSI_INSTANCE_1);
2593 val = DSI_GANGED_MODE_SIZE_VALID_LOW_WIDTH(low_width) |
2594 DSI_GANGED_MODE_SIZE_VALID_HIGH_WIDTH(high_width);
2597 tegra_dsi_writel(dsi, val, DSI_GANGED_MODE_SIZE);
2599 tegra_dsi_writel(dsi, DSI_GANGED_MODE_CONTROL_EN(TEGRA_DSI_ENABLE),
2600 DSI_GANGED_MODE_CONTROL);
2603 static int tegra_dsi_set_to_hs_mode(struct tegra_dc *dc,
2604 struct tegra_dc_dsi_data *dsi,
2609 if (dsi->status.init != DSI_MODULE_INIT) {
2614 if (dsi->status.lphs == DSI_LPHS_IN_HS_MODE &&
2615 dsi->driven_mode == driven_mode)
2618 dsi->driven_mode = driven_mode;
2620 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
2621 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
2623 if ((dsi->status.clk_out == DSI_PHYCLK_OUT_EN) &&
2624 (!dsi->info.enable_hs_clock_on_lp_cmd_mode))
2625 tegra_dsi_hs_clk_out_disable(dc, dsi);
2627 if (dsi->current_dsi_clk_khz != dsi->target_hs_clk_khz) {
2628 tegra_dsi_set_dsi_clk(dc, dsi, dsi->target_hs_clk_khz);
2629 tegra_dsi_set_timeout(dsi);
2632 tegra_dsi_set_phy_timing(dsi, DSI_LPHS_IN_HS_MODE);
2634 if (driven_mode == TEGRA_DSI_DRIVEN_BY_DC) {
2635 tegra_dsi_set_pkt_seq(dc, dsi);
2636 tegra_dsi_set_pkt_length(dc, dsi);
2637 tegra_dsi_set_sol_delay(dc, dsi);
2638 tegra_dsi_set_dc_clk(dc, dsi);
2641 tegra_dsi_set_control_reg_hs(dsi, driven_mode);
2643 if (dsi->info.ganged_type)
2644 tegra_dsi_ganged(dc, dsi);
2646 if (dsi->status.clk_out == DSI_PHYCLK_OUT_DIS ||
2647 dsi->info.enable_hs_clock_on_lp_cmd_mode)
2648 tegra_dsi_hs_clk_out_enable(dsi);
2650 dsi->status.lphs = DSI_LPHS_IN_HS_MODE;
2652 dsi->status.lp_op = DSI_LP_OP_NOT_INIT;
2658 static bool tegra_dsi_write_busy(struct tegra_dc_dsi_data *dsi, u8 link_id)
2663 while (timeout <= DSI_MAX_COMMAND_DELAY_USEC) {
2664 if (!(DSI_TRIGGER_HOST_TRIGGER(0x1) &
2665 tegra_dsi_controller_readl(dsi,
2666 DSI_TRIGGER, link_id))) {
2670 udelay(DSI_COMMAND_DELAY_STEPS_USEC);
2671 timeout += DSI_COMMAND_DELAY_STEPS_USEC;
2677 static bool tegra_dsi_read_busy(struct tegra_dc_dsi_data *dsi, u8 link_id)
2682 while (timeout < DSI_STATUS_POLLING_DURATION_USEC) {
2683 if (!(DSI_HOST_DSI_CONTROL_IMM_BTA(0x1) &
2684 tegra_dsi_controller_readl(dsi,
2685 DSI_HOST_DSI_CONTROL, link_id))) {
2689 udelay(DSI_STATUS_POLLING_DELAY_USEC);
2690 timeout += DSI_STATUS_POLLING_DELAY_USEC;
2696 static bool tegra_dsi_host_busy(struct tegra_dc_dsi_data *dsi, u8 link_id)
2700 if (tegra_dsi_write_busy(dsi, link_id)) {
2702 dev_err(&dsi->dc->ndev->dev,
2703 "DSI trigger bit already set\n");
2707 if (tegra_dsi_read_busy(dsi, link_id)) {
2709 dev_err(&dsi->dc->ndev->dev,
2710 "DSI immediate bta bit already set\n");
2714 return (err < 0 ? true : false);
2717 static void tegra_dsi_reset_read_count(struct tegra_dc_dsi_data *dsi)
2721 val = tegra_dsi_readl(dsi, DSI_STATUS);
2722 val &= DSI_STATUS_RD_FIFO_COUNT(0x1f);
2724 dev_warn(&dsi->dc->ndev->dev,
2725 "DSI read count not zero, resetting\n");
2726 tegra_dsi_soft_reset(dsi);
2730 static struct dsi_status *tegra_dsi_save_state_switch_to_host_cmd_mode(
2731 struct tegra_dc_dsi_data *dsi,
2732 struct tegra_dc *dc,
2735 struct dsi_status *init_status = NULL;
2738 if (dsi->status.init != DSI_MODULE_INIT ||
2739 dsi->status.lphs == DSI_LPHS_NOT_INIT) {
2744 init_status = kzalloc(sizeof(*init_status), GFP_KERNEL);
2746 return ERR_PTR(-ENOMEM);
2748 *init_status = dsi->status;
2750 if (dsi->info.hs_cmd_mode_supported) {
2751 err = tegra_dsi_set_to_hs_mode(dc, dsi,
2752 TEGRA_DSI_DRIVEN_BY_HOST);
2754 dev_err(&dc->ndev->dev,
2755 "Switch to HS host mode failed\n");
2762 if (dsi->status.lp_op != lp_op) {
2763 err = tegra_dsi_set_to_lp_mode(dc, dsi, lp_op);
2765 dev_err(&dc->ndev->dev,
2766 "DSI failed to go to LP mode\n");
2774 return ERR_PTR(err);
2777 static struct dsi_status *tegra_dsi_prepare_host_transmission(
2778 struct tegra_dc *dc,
2779 struct tegra_dc_dsi_data *dsi,
2784 struct dsi_status *init_status;
2785 bool restart_dc_stream = false;
2787 if (dsi->status.init != DSI_MODULE_INIT ||
2793 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE) {
2794 restart_dc_stream = true;
2795 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
2798 for (i = 0; i < dsi->max_instances; i++) {
2799 if (tegra_dsi_host_busy(dsi, i)) {
2800 tegra_dsi_soft_reset(dsi);
2801 if (tegra_dsi_host_busy(dsi, i)) {
2803 dev_err(&dc->ndev->dev, "DSI host busy\n");
2809 if (lp_op == DSI_LP_OP_READ)
2810 tegra_dsi_reset_read_count(dsi);
2812 if (dsi->status.lphs == DSI_LPHS_NOT_INIT) {
2813 err = tegra_dsi_set_to_lp_mode(dc, dsi, lp_op);
2815 dev_err(&dc->ndev->dev, "Failed to config LP write\n");
2820 init_status = tegra_dsi_save_state_switch_to_host_cmd_mode
2822 if (IS_ERR_OR_NULL(init_status)) {
2823 err = PTR_ERR(init_status);
2824 dev_err(&dc->ndev->dev, "DSI state saving failed\n");
2828 if (restart_dc_stream)
2829 init_status->dc_stream = DSI_DC_STREAM_ENABLE;
2831 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
2832 if (atomic_read(&dsi_syncpt_rst))
2833 tegra_dsi_syncpt_reset(dsi);
2837 return ERR_PTR(err);
2840 static int tegra_dsi_restore_state(struct tegra_dc *dc,
2841 struct tegra_dc_dsi_data *dsi,
2842 struct dsi_status *init_status)
2846 if (init_status->lphs == DSI_LPHS_IN_LP_MODE) {
2847 err = tegra_dsi_set_to_lp_mode(dc, dsi, init_status->lp_op);
2849 dev_err(&dc->ndev->dev,
2850 "Failed to config LP mode\n");
2856 if (init_status->lphs == DSI_LPHS_IN_HS_MODE) {
2857 u8 driven = (init_status->driven == DSI_DRIVEN_MODE_DC) ?
2858 TEGRA_DSI_DRIVEN_BY_DC : TEGRA_DSI_DRIVEN_BY_HOST;
2859 err = tegra_dsi_set_to_hs_mode(dc, dsi, driven);
2861 dev_err(&dc->ndev->dev, "Failed to config HS mode\n");
2866 if (init_status->dc_stream == DSI_DC_STREAM_ENABLE)
2867 tegra_dsi_start_dc_stream(dc, dsi);
2874 static int tegra_dsi_host_trigger(struct tegra_dc_dsi_data *dsi, u8 link_id)
2878 if (tegra_dsi_controller_readl(dsi, DSI_TRIGGER, link_id)) {
2883 tegra_dsi_controller_writel(dsi,
2884 DSI_TRIGGER_HOST_TRIGGER(TEGRA_DSI_ENABLE),
2885 DSI_TRIGGER, link_id);
2887 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS) {
2888 status = tegra_dsi_syncpt(dsi, link_id);
2890 dev_err(&dsi->dc->ndev->dev,
2891 "DSI syncpt for host trigger failed\n");
2895 if (tegra_dsi_write_busy(dsi, link_id)) {
2897 dev_err(&dsi->dc->ndev->dev,
2898 "Timeout waiting on write completion\n");
2906 static int _tegra_dsi_write_data(struct tegra_dc_dsi_data *dsi,
2907 struct tegra_dsi_cmd *cmd)
2912 u8 *pdata = cmd->pdata;
2913 u8 data_id = cmd->data_id;
2914 u16 data_len = cmd->sp_len_dly.data_len;
2918 if (!dsi->info.ganged_type && cmd->link_id == TEGRA_DSI_LINK1) {
2919 dev_err(&dsi->dc->ndev->dev, "DSI invalid command\n");
2923 virtual_channel = dsi->info.virtual_channel <<
2924 DSI_VIR_CHANNEL_BIT_POSITION;
2926 /* always use hw for ecc */
2927 val = (virtual_channel | data_id) << 0 |
2929 tegra_dsi_controller_writel(dsi, val, DSI_WR_DATA, cmd->link_id);
2931 /* if pdata != NULL, pkt type is long pkt */
2932 if (pdata != NULL) {
2934 if (data_len >= 4) {
2935 val = ((u32 *) pdata)[0];
2940 memcpy(&val, pdata, data_len);
2944 tegra_dsi_controller_writel(dsi, val,
2945 DSI_WR_DATA, cmd->link_id);
2949 if (cmd->cmd_type != TEGRA_DSI_PACKET_VIDEO_VBLANK_CMD) {
2950 err = tegra_dsi_host_trigger(dsi, cmd->link_id);
2952 dev_err(&dsi->dc->ndev->dev, "DSI host trigger failed\n");
2958 static void tegra_dc_dsi_hold_host(struct tegra_dc *dc)
2960 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
2962 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_LP_MODE) {
2963 atomic_inc(&dsi->host_ref);
2964 tegra_dsi_host_resume(dc);
2968 static void tegra_dc_dsi_release_host(struct tegra_dc *dc)
2970 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
2972 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_LP_MODE) {
2973 atomic_dec(&dsi->host_ref);
2975 if (!atomic_read(&dsi->host_ref) &&
2976 (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE))
2977 schedule_delayed_work(&dsi->idle_work, dsi->idle_delay);
2981 static void tegra_dc_dsi_idle_work(struct work_struct *work)
2983 struct tegra_dc_dsi_data *dsi = container_of(
2984 to_delayed_work(work), struct tegra_dc_dsi_data, idle_work);
2986 if (dsi->dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_LP_MODE)
2987 tegra_dsi_host_suspend(dsi->dc);
2990 static int tegra_dsi_write_data_nosync(struct tegra_dc *dc,
2991 struct tegra_dc_dsi_data *dsi,
2992 struct tegra_dsi_cmd *cmd, u8 delay_ms)
2995 struct dsi_status *init_status;
2997 init_status = tegra_dsi_prepare_host_transmission(
2998 dc, dsi, DSI_LP_OP_WRITE);
2999 if (IS_ERR_OR_NULL(init_status)) {
3000 err = PTR_ERR(init_status);
3001 dev_err(&dc->ndev->dev, "DSI host config failed\n");
3005 err = _tegra_dsi_write_data(dsi, cmd);
3008 err = tegra_dsi_restore_state(dc, dsi, init_status);
3010 dev_err(&dc->ndev->dev, "Failed to restore prev state\n");
3015 int tegra_dsi_write_data(struct tegra_dc *dc,
3016 struct tegra_dc_dsi_data *dsi,
3017 struct tegra_dsi_cmd *cmd, u8 delay_ms)
3021 tegra_dc_io_start(dc);
3022 tegra_dc_dsi_hold_host(dc);
3024 err = tegra_dsi_write_data_nosync(dc, dsi, cmd, delay_ms);
3026 tegra_dc_dsi_release_host(dc);
3027 tegra_dc_io_end(dc);
3032 EXPORT_SYMBOL(tegra_dsi_write_data);
3034 int tegra_dsi_start_host_cmd_v_blank_video(struct tegra_dc_dsi_data *dsi,
3035 struct tegra_dsi_cmd *cmd)
3037 struct tegra_dc *dc = dsi->dc;
3041 if (!dsi->enabled) {
3042 dev_err(&dsi->dc->ndev->dev, "DSI controller suspended\n");
3046 tegra_dc_io_start(dc);
3047 tegra_dc_dsi_hold_host(dc);
3048 val = (DSI_CMD_PKT_VID_ENABLE(1) | DSI_LINE_TYPE(4));
3049 tegra_dsi_writel(dsi, val, DSI_VID_MODE_CONTROL);
3050 _tegra_dsi_write_data(dsi, cmd);
3051 if (dsi->status.lphs != DSI_LPHS_IN_HS_MODE) {
3052 err = tegra_dsi_set_to_hs_mode(dc, dsi,
3053 TEGRA_DSI_DRIVEN_BY_DC);
3055 dev_err(&dc->ndev->dev,
3056 "dsi: not able to set to hs mode\n");
3060 tegra_dsi_start_dc_stream(dc, dsi);
3061 tegra_dsi_wait_frame_end(dc, dsi, 2);
3063 tegra_dc_dsi_release_host(dc);
3064 tegra_dc_io_end(dc);
3068 EXPORT_SYMBOL(tegra_dsi_start_host_cmd_v_blank_video);
3070 int tegra_dsi_end_host_cmd_v_blank_video(struct tegra_dc *dc,
3071 struct tegra_dc_dsi_data *dsi)
3073 if (!dsi->enabled) {
3074 dev_err(&dsi->dc->ndev->dev, "DSI controller suspended\n");
3078 tegra_dc_io_start(dc);
3079 tegra_dsi_writel(dsi, 0, DSI_VID_MODE_CONTROL);
3080 tegra_dc_io_end(dc);
3084 EXPORT_SYMBOL(tegra_dsi_end_host_cmd_v_blank_video);
3086 static int tegra_dsi_send_panel_cmd(struct tegra_dc *dc,
3087 struct tegra_dc_dsi_data *dsi,
3088 struct tegra_dsi_cmd *cmd,
3091 #define DEFAULT_DELAY_MS 1
3097 for (i = 0; i < n_cmd; i++) {
3098 struct tegra_dsi_cmd *cur_cmd;
3102 * Some Panels need reset midway in the command sequence.
3104 if (cur_cmd->cmd_type == TEGRA_DSI_GPIO_SET) {
3105 gpio_set_value(cur_cmd->sp_len_dly.gpio,
3107 } else if (cur_cmd->cmd_type == TEGRA_DSI_DELAY_MS) {
3108 mdelay(cur_cmd->sp_len_dly.delay_ms);
3109 } else if (cur_cmd->cmd_type == TEGRA_DSI_SEND_FRAME) {
3110 tegra_dsi_send_dc_frames(dc,
3112 cur_cmd->sp_len_dly.frame_cnt);
3113 } else if (cur_cmd->cmd_type ==
3114 TEGRA_DSI_PACKET_VIDEO_VBLANK_CMD) {
3115 tegra_dsi_start_host_cmd_v_blank_video(dsi, cur_cmd);
3116 tegra_dsi_end_host_cmd_v_blank_video(dc, dsi);
3118 delay_ms = DEFAULT_DELAY_MS;
3119 if ((i + 1 < n_cmd) &&
3120 (cmd[i + 1].cmd_type == TEGRA_DSI_DELAY_MS)) {
3121 delay_ms = cmd[i + 1].sp_len_dly.delay_ms;
3124 err = tegra_dsi_write_data_nosync(dc, dsi,
3131 #undef DEFAULT_DELAY_MS
3134 static u8 tegra_dsi_ecc(u32 header)
3136 char ecc_parity[24] = {
3137 0x07, 0x0b, 0x0d, 0x0e, 0x13, 0x15, 0x16, 0x19,
3138 0x1a, 0x1c, 0x23, 0x25, 0x26, 0x29, 0x2a, 0x2c,
3139 0x31, 0x32, 0x34, 0x38, 0x1f, 0x2f, 0x37, 0x3b
3145 for (i = 0; i < 24; i++)
3146 ecc_byte ^= ((header >> i) & 1) ? ecc_parity[i] : 0x00;
3151 static u16 tegra_dsi_cs(char *pdata, u16 data_len)
3160 for (byte_cnt = 0; byte_cnt < data_len; byte_cnt++) {
3161 curr_byte = pdata[byte_cnt];
3162 for (bit_cnt = 0; bit_cnt < 8; bit_cnt++) {
3163 if (((crc & 0x0001 ) ^
3164 (curr_byte & 0x0001)) > 0)
3165 crc = ((crc >> 1) & 0x7FFF) ^ poly;
3167 crc = (crc >> 1) & 0x7FFF;
3169 curr_byte = (curr_byte >> 1 ) & 0x7F;
3176 static int tegra_dsi_dcs_pkt_seq_ctrl_init(struct tegra_dc_dsi_data *dsi,
3177 struct tegra_dsi_cmd *cmd)
3181 u16 data_len = cmd->sp_len_dly.data_len;
3182 u8 seq_ctrl_reg = 0;
3184 virtual_channel = dsi->info.virtual_channel <<
3185 DSI_VIR_CHANNEL_BIT_POSITION;
3187 val = (virtual_channel | cmd->data_id) << 0 |
3190 val |= tegra_dsi_ecc(val) << 24;
3192 tegra_dsi_writel(dsi, val, DSI_INIT_SEQ_DATA_0 + seq_ctrl_reg++);
3194 /* if pdata != NULL, pkt type is long pkt */
3195 if (cmd->pdata != NULL) {
3198 /* allocate memory for pdata + 2 bytes checksum */
3199 pdata_mem = kzalloc(sizeof(u8) * data_len + 2, GFP_KERNEL);
3201 dev_err(&dsi->dc->ndev->dev, "dsi: memory err\n");
3202 tegra_dsi_soft_reset(dsi);
3206 memcpy(pdata_mem, cmd->pdata, data_len);
3208 *((u16 *)(pdata + data_len)) = tegra_dsi_cs(pdata, data_len);
3210 /* data_len = length of pdata + 2 byte checksum */
3214 if (data_len >= 4) {
3215 val = ((u32 *) pdata)[0];
3220 memcpy(&val, pdata, data_len);
3224 tegra_dsi_writel(dsi, val, DSI_INIT_SEQ_DATA_0 +
3233 int tegra_dsi_start_host_cmd_v_blank_dcs(struct tegra_dc_dsi_data *dsi,
3234 struct tegra_dsi_cmd *cmd)
3236 #define PKT_HEADER_LEN_BYTE 4
3237 #define CHECKSUM_LEN_BYTE 2
3241 u16 tot_pkt_len = PKT_HEADER_LEN_BYTE;
3242 struct tegra_dc *dc = dsi->dc;
3244 if (cmd->cmd_type != TEGRA_DSI_PACKET_CMD)
3247 mutex_lock(&dsi->lock);
3248 tegra_dc_io_start(dc);
3249 tegra_dc_dsi_hold_host(dc);
3251 #if DSI_USE_SYNC_POINTS
3252 atomic_set(&dsi_syncpt_rst, 1);
3255 err = tegra_dsi_dcs_pkt_seq_ctrl_init(dsi, cmd);
3257 dev_err(&dsi->dc->ndev->dev,
3258 "dsi: dcs pkt seq ctrl init failed\n");
3263 u16 data_len = cmd->sp_len_dly.data_len;
3264 tot_pkt_len += data_len + CHECKSUM_LEN_BYTE;
3267 val = DSI_INIT_SEQ_CONTROL_DSI_FRAME_INIT_BYTE_COUNT(tot_pkt_len) |
3268 DSI_INIT_SEQ_CONTROL_DSI_SEND_INIT_SEQUENCE(
3270 tegra_dsi_writel(dsi, val, DSI_INIT_SEQ_CONTROL);
3273 tegra_dc_dsi_release_host(dc);
3274 tegra_dc_io_end(dc);
3275 mutex_unlock(&dsi->lock);
3278 #undef PKT_HEADER_LEN_BYTE
3279 #undef CHECKSUM_LEN_BYTE
3281 EXPORT_SYMBOL(tegra_dsi_start_host_cmd_v_blank_dcs);
3283 void tegra_dsi_stop_host_cmd_v_blank_dcs(struct tegra_dc_dsi_data *dsi)
3285 struct tegra_dc *dc = dsi->dc;
3288 mutex_lock(&dsi->lock);
3289 tegra_dc_io_start(dc);
3290 tegra_dc_dsi_hold_host(dc);
3292 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
3293 if (atomic_read(&dsi_syncpt_rst)) {
3294 tegra_dsi_wait_frame_end(dc, dsi, 2);
3295 tegra_dsi_syncpt_reset(dsi);
3296 atomic_set(&dsi_syncpt_rst, 0);
3299 tegra_dsi_writel(dsi, TEGRA_DSI_DISABLE, DSI_INIT_SEQ_CONTROL);
3301 /* clear seq data registers */
3302 for (cnt = 0; cnt < 8; cnt++)
3303 tegra_dsi_writel(dsi, 0, DSI_INIT_SEQ_DATA_0 + cnt);
3305 tegra_dc_dsi_release_host(dc);
3306 tegra_dc_io_end(dc);
3308 mutex_unlock(&dsi->lock);
3310 EXPORT_SYMBOL(tegra_dsi_stop_host_cmd_v_blank_dcs);
3312 static int tegra_dsi_bta(struct tegra_dc_dsi_data *dsi)
3317 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
3318 val |= DSI_HOST_DSI_CONTROL_IMM_BTA(TEGRA_DSI_ENABLE);
3319 tegra_dsi_controller_writel(dsi, val,
3320 DSI_HOST_DSI_CONTROL, TEGRA_DSI_LINK0);
3322 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS) {
3323 err = tegra_dsi_syncpt(dsi, TEGRA_DSI_LINK0);
3325 dev_err(&dsi->dc->ndev->dev,
3326 "DSI syncpt for bta failed\n");
3329 if (tegra_dsi_read_busy(dsi, TEGRA_DSI_LINK0)) {
3331 dev_err(&dsi->dc->ndev->dev,
3332 "Timeout wating on read completion\n");
3339 static int tegra_dsi_parse_read_response(struct tegra_dc *dc,
3340 u32 rd_fifo_cnt, u8 *read_fifo)
3348 switch (read_fifo[0]) {
3349 case DSI_ESCAPE_CMD:
3350 dev_info(&dc->ndev->dev, "escape cmd[0x%x]\n", read_fifo[0]);
3352 case DSI_ACK_NO_ERR:
3353 dev_info(&dc->ndev->dev,
3354 "Panel ack, no err[0x%x]\n", read_fifo[0]);
3357 dev_info(&dc->ndev->dev, "Invalid read response\n");
3361 switch (read_fifo[4] & 0xff) {
3362 case GEN_LONG_RD_RES:
3364 case DCS_LONG_RD_RES:
3365 payload_size = (read_fifo[5] |
3366 (read_fifo[6] << 8)) & 0xFFFF;
3367 dev_info(&dc->ndev->dev, "Long read response Packet\n"
3368 "payload_size[0x%x]\n", payload_size);
3370 case GEN_1_BYTE_SHORT_RD_RES:
3372 case DCS_1_BYTE_SHORT_RD_RES:
3374 dev_info(&dc->ndev->dev, "Short read response Packet\n"
3375 "payload_size[0x%x]\n", payload_size);
3377 case GEN_2_BYTE_SHORT_RD_RES:
3379 case DCS_2_BYTE_SHORT_RD_RES:
3381 dev_info(&dc->ndev->dev, "Short read response Packet\n"
3382 "payload_size[0x%x]\n", payload_size);
3386 dev_info(&dc->ndev->dev, "Acknowledge error report response\n"
3387 "Packet payload_size[0x%x]\n", payload_size);
3390 dev_info(&dc->ndev->dev, "Invalid response packet\n");
3397 static int tegra_dsi_read_fifo(struct tegra_dc *dc,
3398 struct tegra_dc_dsi_data *dsi,
3406 u8 *read_fifo_cp = read_fifo;
3408 while (poll_time < DSI_DELAY_FOR_READ_FIFO) {
3410 val = tegra_dsi_readl(dsi, DSI_STATUS);
3411 rd_fifo_cnt = val & DSI_STATUS_RD_FIFO_COUNT(0x1f);
3412 if (rd_fifo_cnt << 2 > DSI_READ_FIFO_DEPTH) {
3413 dev_err(&dc->ndev->dev,
3414 "DSI RD_FIFO_CNT is greater than RD_FIFO_DEPTH\n");
3420 if (rd_fifo_cnt == 0) {
3421 dev_info(&dc->ndev->dev,
3422 "DSI RD_FIFO_CNT is zero\n");
3427 if (val & (DSI_STATUS_LB_UNDERFLOW(0x1) |
3428 DSI_STATUS_LB_OVERFLOW(0x1))) {
3429 dev_warn(&dc->ndev->dev,
3430 "DSI overflow/underflow error\n");
3433 /* Read data from FIFO */
3434 for (i = 0; i < rd_fifo_cnt; i++) {
3435 val = tegra_dsi_readl(dsi, DSI_RD_DATA);
3436 if (enable_read_debug)
3437 dev_info(&dc->ndev->dev,
3438 "Read data[%d]: 0x%x\n", i, val);
3439 memcpy(read_fifo, &val, 4);
3443 /* Make sure all the data is read from the FIFO */
3444 val = tegra_dsi_readl(dsi, DSI_STATUS);
3445 val &= DSI_STATUS_RD_FIFO_COUNT(0x1f);
3447 dev_err(&dc->ndev->dev, "DSI FIFO_RD_CNT not zero"
3448 " even after reading FIFO_RD_CNT words from read fifo\n");
3450 if (enable_read_debug) {
3452 tegra_dsi_parse_read_response(dc, rd_fifo_cnt, read_fifo_cp);
3454 dev_warn(&dc->ndev->dev, "Unexpected read data\n");
3460 int tegra_dsi_read_data(struct tegra_dc *dc,
3461 struct tegra_dc_dsi_data *dsi,
3462 u16 max_ret_payload_size,
3463 u8 panel_reg_addr, u8 *read_data)
3466 struct dsi_status *init_status;
3467 static struct tegra_dsi_cmd temp_cmd;
3469 if (!dsi->enabled) {
3470 dev_err(&dc->ndev->dev, "DSI controller suspended\n");
3473 tegra_dc_dsi_hold_host(dc);
3474 mutex_lock(&dsi->lock);
3475 tegra_dc_io_start(dc);
3476 clk_prepare_enable(dsi->dsi_fixed_clk);
3477 tegra_dsi_lp_clk_enable(dsi);
3478 init_status = tegra_dsi_prepare_host_transmission(
3479 dc, dsi, DSI_LP_OP_WRITE);
3480 if (IS_ERR_OR_NULL(init_status)) {
3481 err = PTR_ERR(init_status);
3482 dev_err(&dc->ndev->dev, "DSI host config failed\n");
3486 /* Set max return payload size in words */
3487 temp_cmd.data_id = dsi_command_max_return_pkt_size;
3488 temp_cmd.sp_len_dly.data_len = max_ret_payload_size;
3489 err = _tegra_dsi_write_data(dsi, &temp_cmd);
3491 dev_err(&dc->ndev->dev,
3492 "DSI write failed\n");
3496 /* DCS to read given panel register */
3497 temp_cmd.data_id = dsi_command_dcs_read_with_no_params;
3498 temp_cmd.sp_len_dly.sp.data0 = panel_reg_addr;
3499 temp_cmd.sp_len_dly.sp.data1 = 0;
3500 err = _tegra_dsi_write_data(dsi, &temp_cmd);
3502 dev_err(&dc->ndev->dev,
3503 "DSI write failed\n");
3507 tegra_dsi_reset_read_count(dsi);
3509 if (dsi->status.lp_op == DSI_LP_OP_WRITE) {
3510 err = tegra_dsi_set_to_lp_mode(dc, dsi, DSI_LP_OP_READ);
3512 dev_err(&dc->ndev->dev,
3513 "DSI failed to go to LP read mode\n");
3518 err = tegra_dsi_bta(dsi);
3520 dev_err(&dc->ndev->dev,
3521 "DSI IMM BTA timeout\n");
3525 err = tegra_dsi_read_fifo(dc, dsi, read_data);
3527 dev_err(&dc->ndev->dev, "DSI read fifo failure\n");
3531 err = tegra_dsi_restore_state(dc, dsi, init_status);
3533 dev_err(&dc->ndev->dev, "Failed to restore prev state\n");
3534 tegra_dsi_lp_clk_disable(dsi);
3535 clk_disable_unprepare(dsi->dsi_fixed_clk);
3536 tegra_dc_io_end(dc);
3537 mutex_unlock(&dsi->lock);
3538 tegra_dc_dsi_release_host(dc);
3541 EXPORT_SYMBOL(tegra_dsi_read_data);
3543 static const char * const error_sanity[] = {
3547 "Escape Mode Entry Comand Error",
3548 "Low-Power Transmit Sync Error",
3549 "HS Receive Timeout Error",
3550 "False Control Error",
3552 "ECC Error,Single Bit",
3553 "ECC Error, Multi Bit",
3555 "DSI Data Type Not recognized",
3556 "DSI VC ID Invalid",
3557 "DSI Protocol Violation",
3562 int tegra_dsi_panel_sanity_check(struct tegra_dc *dc,
3563 struct tegra_dc_dsi_data *dsi,
3564 struct sanity_status *san)
3568 u8 read_fifo[DSI_READ_FIFO_DEPTH];
3569 struct dsi_status *init_status;
3570 static struct tegra_dsi_cmd dsi_nop_cmd =
3571 DSI_CMD_SHORT(0x05, 0x0, 0x0);
3573 if (!dsi->enabled) {
3574 dev_err(&dc->ndev->dev, "DSI controller suspended\n");
3577 tegra_dc_dsi_hold_host(dc);
3578 tegra_dc_io_start(dc);
3579 clk_prepare_enable(dsi->dsi_fixed_clk);
3580 tegra_dsi_lp_clk_enable(dsi);
3581 memset(flagset, 0, sizeof(flagset));
3582 init_status = tegra_dsi_prepare_host_transmission(
3583 dc, dsi, DSI_LP_OP_WRITE);
3584 if (IS_ERR_OR_NULL(init_status)) {
3585 err = PTR_ERR(init_status);
3586 dev_err(&dc->ndev->dev, "DSI host config failed\n");
3590 err = _tegra_dsi_write_data(dsi, &dsi_nop_cmd);
3592 dev_err(&dc->ndev->dev, "DSI nop write failed\n");
3596 tegra_dsi_reset_read_count(dsi);
3598 if (dsi->status.lp_op == DSI_LP_OP_WRITE) {
3599 err = tegra_dsi_set_to_lp_mode(dc, dsi, DSI_LP_OP_READ);
3601 dev_err(&dc->ndev->dev,
3602 "DSI failed to go to LP read mode\n");
3607 err = tegra_dsi_bta(dsi);
3609 dev_err(&dc->ndev->dev, "DSI BTA failed\n");
3613 err = tegra_dsi_read_fifo(dc, dsi, read_fifo);
3615 dev_err(&dc->ndev->dev, "DSI read fifo failure\n");
3619 if (read_fifo[0] != DSI_ACK_NO_ERR) {
3620 if (read_fifo[4] == ACK_ERR_RES) {
3621 u16 payload = read_fifo[5] | (read_fifo[6] << 8);
3623 for (; payload; payload >>= 1, i++) {
3626 if (enable_read_debug)
3627 dev_info(&dc->ndev->dev,
3628 " %s => error flag number %d\n",
3629 error_sanity[i], i);
3633 san->sot_error = flagset[0];
3634 san->sot_sync_error = flagset[1];
3635 san->eot_sync_error = flagset[2];
3636 san->escape_mode_entry_comand_error =
3638 san->low_power_transmit_sync_error = flagset[4];
3639 san->hs_receive_timeout_error = flagset[5];
3640 san->false_control_error = flagset[6];
3641 san->reserved1 = flagset[7];
3642 san->ecc_error_single_bit = flagset[8];
3643 san->ecc_error_multi_bit = flagset[9];
3644 san->checksum_error = flagset[10];
3645 san->dsi_data_type_not_recognized = flagset[11];
3646 san->dsi_vc_id_invalid = flagset[12];
3647 san->dsi_protocol_violation = flagset[13];
3648 san->reserved2 = flagset[14];
3649 san->reserved3 = flagset[15];
3652 dev_warn(&dc->ndev->dev,
3653 "Ack no error trigger message not received\n");
3658 err = tegra_dsi_restore_state(dc, dsi, init_status);
3660 dev_err(&dc->ndev->dev, "Failed to restore prev state\n");
3661 tegra_dsi_lp_clk_disable(dsi);
3662 clk_disable_unprepare(dsi->dsi_fixed_clk);
3663 tegra_dc_io_end(dc);
3664 tegra_dc_dsi_release_host(dc);
3667 EXPORT_SYMBOL(tegra_dsi_panel_sanity_check);
3669 static int tegra_dsi_enter_ulpm(struct tegra_dc_dsi_data *dsi)
3674 if (dsi->info.ulpm_not_supported)
3677 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
3678 if (atomic_read(&dsi_syncpt_rst))
3679 tegra_dsi_syncpt_reset(dsi);
3681 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
3682 val &= ~DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(3);
3683 val |= DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(ENTER_ULPM);
3684 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
3686 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS) {
3687 ret = tegra_dsi_syncpt(dsi, TEGRA_DSI_LINK0);
3689 dev_err(&dsi->dc->ndev->dev,
3690 "DSI syncpt for ulpm enter failed\n");
3694 /* TODO: Find exact delay required */
3702 static int tegra_dsi_exit_ulpm(struct tegra_dc_dsi_data *dsi)
3707 if (dsi->info.ulpm_not_supported)
3710 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
3711 if (atomic_read(&dsi_syncpt_rst))
3712 tegra_dsi_syncpt_reset(dsi);
3714 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
3715 val &= ~DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(3);
3716 val |= DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(EXIT_ULPM);
3717 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
3719 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS) {
3720 ret = tegra_dsi_syncpt(dsi, TEGRA_DSI_LINK0);
3722 dev_err(&dsi->dc->ndev->dev,
3723 "DSI syncpt for ulpm exit failed\n");
3727 /* TODO: Find exact delay required */
3732 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
3733 val &= ~DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(0x3);
3734 val |= DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(NORMAL);
3735 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
3740 static void tegra_dsi_send_dc_frames(struct tegra_dc *dc,
3741 struct tegra_dc_dsi_data *dsi,
3745 u32 frame_period = DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
3746 u8 lp_op = dsi->status.lp_op;
3747 bool switch_to_lp = (dsi->status.lphs == DSI_LPHS_IN_LP_MODE);
3749 if (dsi->status.lphs != DSI_LPHS_IN_HS_MODE) {
3750 err = tegra_dsi_set_to_hs_mode(dc, dsi,
3751 TEGRA_DSI_DRIVEN_BY_DC);
3753 dev_err(&dc->ndev->dev,
3754 "Switch to HS host mode failed\n");
3760 * Some panels need DC frames be sent under certain
3761 * conditions. We are working on the right fix for this
3762 * requirement, while using this current fix.
3764 tegra_dsi_start_dc_stream(dc, dsi);
3767 * Send frames in Continuous or One-shot mode.
3769 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_MODE) {
3770 /* FIX ME: tegra_dc_blank() implicitly takes lock */
3771 int flag = mutex_is_locked(&dc->lock);
3773 mutex_unlock(&dc->lock);
3774 while (no_of_frames--)
3775 tegra_dc_blank(dc, BLANK_ALL);
3777 mutex_lock(&dc->lock);
3779 mdelay(no_of_frames * frame_period);
3781 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
3784 err = tegra_dsi_set_to_lp_mode(dc, dsi, lp_op);
3786 dev_err(&dc->ndev->dev,
3787 "DSI failed to go to LP mode\n");
3791 static void tegra_dsi_setup_initialized_panel(struct tegra_dc_dsi_data *dsi)
3795 if (dsi->avdd_dsi_csi)
3796 err = regulator_enable(dsi->avdd_dsi_csi);
3797 WARN(err, "unable to enable regulator");
3799 dsi->status.init = DSI_MODULE_INIT;
3800 dsi->status.lphs = DSI_LPHS_IN_HS_MODE;
3801 dsi->status.driven = DSI_DRIVEN_MODE_DC;
3802 dsi->driven_mode = TEGRA_DSI_DRIVEN_BY_DC;
3803 dsi->status.clk_out = DSI_PHYCLK_OUT_EN;
3804 dsi->status.lp_op = DSI_LP_OP_NOT_INIT;
3805 dsi->status.dc_stream = DSI_DC_STREAM_ENABLE;
3807 if (dsi->info.video_clock_mode == TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS)
3808 dsi->status.clk_mode = DSI_PHYCLK_CONTINUOUS;
3810 dsi->status.clk_mode = DSI_PHYCLK_TX_ONLY;
3812 if (!(dsi->info.ganged_type)) {
3813 if (dsi->info.video_burst_mode ==
3814 TEGRA_DSI_VIDEO_NONE_BURST_MODE ||
3815 dsi->info.video_burst_mode ==
3816 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END)
3817 dsi->status.clk_burst = DSI_CLK_BURST_NONE_BURST;
3819 dsi->status.clk_burst = DSI_CLK_BURST_BURST_MODE;
3822 if (dsi->info.video_data_type == TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE)
3823 dsi->status.vtype = DSI_VIDEO_TYPE_CMD_MODE;
3825 dsi->status.vtype = DSI_VIDEO_TYPE_VIDEO_MODE;
3827 tegra_dsi_clk_enable(dsi);
3829 dsi->enabled = true;
3832 static void tegra_dc_dsi_enable(struct tegra_dc *dc)
3834 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
3837 mutex_lock(&dsi->lock);
3838 tegra_dc_io_start(dc);
3841 * Do not program this panel as the bootloader as has already
3842 * initialized it. This avoids periods of blanking during boot.
3844 if (dc->out->flags & TEGRA_DC_OUT_INITIALIZED_MODE) {
3845 tegra_dsi_setup_initialized_panel(dsi);
3849 /* Stop DC stream before configuring DSI registers
3850 * to avoid visible glitches on panel during transition
3851 * from bootloader to kernel driver
3853 tegra_dsi_stop_dc_stream(dc, dsi);
3857 if (tegra_dsi_exit_ulpm(dsi) < 0) {
3858 dev_err(&dc->ndev->dev,
3859 "DSI failed to exit ulpm\n");
3864 if (dsi->info.panel_reset) {
3866 * Certain panels need dc frames be sent before
3869 if (dsi->info.panel_send_dc_frames)
3870 tegra_dsi_send_dc_frames(dc, dsi, 2);
3872 err = tegra_dsi_send_panel_cmd(dc, dsi,
3873 dsi->info.dsi_init_cmd,
3874 dsi->info.n_init_cmd);
3876 dev_err(&dc->ndev->dev,
3877 "dsi: error sending dsi init cmd\n");
3880 } else if (dsi->info.dsi_late_resume_cmd) {
3881 err = tegra_dsi_send_panel_cmd(dc, dsi,
3882 dsi->info.dsi_late_resume_cmd,
3883 dsi->info.n_late_resume_cmd);
3885 dev_err(&dc->ndev->dev,
3886 "dsi: error sending late resume cmd\n");
3891 err = tegra_dsi_init_hw(dc, dsi);
3893 dev_err(&dc->ndev->dev,
3894 "dsi: not able to init dsi hardware\n");
3899 if (tegra_dsi_enter_ulpm(dsi) < 0) {
3900 dev_err(&dc->ndev->dev,
3901 "DSI failed to enter ulpm\n");
3905 tegra_dsi_pad_enable(dsi);
3907 if (tegra_dsi_exit_ulpm(dsi) < 0) {
3908 dev_err(&dc->ndev->dev,
3909 "DSI failed to exit ulpm\n");
3915 * Certain panels need dc frames be sent before
3918 if (dsi->info.panel_send_dc_frames)
3919 tegra_dsi_send_dc_frames(dc, dsi, 2);
3921 err = tegra_dsi_set_to_lp_mode(dc, dsi, DSI_LP_OP_WRITE);
3923 dev_err(&dc->ndev->dev,
3924 "dsi: not able to set to lp mode\n");
3928 if (dsi->info.lp00_pre_panel_wakeup)
3929 tegra_dsi_pad_disable(dsi);
3931 dsi->enabled = true;
3934 if (dsi->out_ops && dsi->out_ops->enable)
3935 dsi->out_ops->enable(dsi);
3937 tegra_dc_io_end(dc);
3938 mutex_unlock(&dsi->lock);
3941 static void tegra_dc_dsi_postpoweron(struct tegra_dc *dc)
3943 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
3947 * Do not configure. Use bootloader configuration.
3948 * This avoids periods of blanking during boot.
3950 if (dc->out->flags & TEGRA_DC_OUT_INITIALIZED_MODE)
3953 mutex_lock(&dsi->lock);
3954 tegra_dc_io_start(dc);
3957 if (dsi->info.lp00_pre_panel_wakeup)
3958 tegra_dsi_pad_enable(dsi);
3960 err = tegra_dsi_send_panel_cmd(dc, dsi, dsi->info.dsi_init_cmd,
3961 dsi->info.n_init_cmd);
3963 dev_err(&dc->ndev->dev,
3964 "dsi: error while sending dsi init cmd\n");
3968 err = tegra_dsi_set_to_hs_mode(dc, dsi,
3969 TEGRA_DSI_DRIVEN_BY_DC);
3971 dev_err(&dc->ndev->dev,
3972 "dsi: not able to set to hs mode\n");
3976 if (dsi->status.driven == DSI_DRIVEN_MODE_DC)
3977 tegra_dsi_start_dc_stream(dc, dsi);
3979 dsi->host_suspended = false;
3982 tegra_dc_io_end(dc);
3983 mutex_unlock(&dsi->lock);
3986 static void __tegra_dc_dsi_init(struct tegra_dc *dc)
3988 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
3990 #ifdef CONFIG_DEBUG_FS
3991 tegra_dc_dsi_debug_create(dsi);
3994 if (dsi->info.dsi2lvds_bridge_enable)
3995 dsi->out_ops = &tegra_dsi2lvds_ops;
3996 else if (dsi->info.dsi2edp_bridge_enable)
3997 dsi->out_ops = &tegra_dsi2edp_ops;
3999 dsi->out_ops = NULL;
4001 if (dsi->out_ops && dsi->out_ops->init)
4002 dsi->out_ops->init(dsi);
4004 tegra_dsi_init_sw(dc, dsi);
4007 static int tegra_dc_dsi_cp_p_cmd(struct tegra_dsi_cmd *src,
4008 struct tegra_dsi_cmd *dst, u16 n_cmd)
4013 memcpy(dst, src, sizeof(*dst) * n_cmd);
4015 for (i = 0; i < n_cmd; i++)
4017 len = sizeof(*src[i].pdata) *
4018 src[i].sp_len_dly.data_len;
4019 dst[i].pdata = kzalloc(len, GFP_KERNEL);
4021 goto free_cmd_pdata;
4022 memcpy(dst[i].pdata, src[i].pdata, len);
4030 kfree(dst[i].pdata);
4034 static int tegra_dc_dsi_cp_info(struct tegra_dc_dsi_data *dsi,
4035 struct tegra_dsi_out *p_dsi)
4037 struct tegra_dsi_cmd *p_init_cmd;
4038 struct tegra_dsi_cmd *p_early_suspend_cmd = NULL;
4039 struct tegra_dsi_cmd *p_late_resume_cmd = NULL;
4040 struct tegra_dsi_cmd *p_suspend_cmd;
4043 if (dsi->info.n_data_lanes > MAX_DSI_DATA_LANES)
4046 p_init_cmd = kzalloc(sizeof(*p_init_cmd) *
4047 p_dsi->n_init_cmd, GFP_KERNEL);
4051 if (p_dsi->dsi_early_suspend_cmd) {
4052 p_early_suspend_cmd = kzalloc(sizeof(*p_early_suspend_cmd) *
4053 p_dsi->n_early_suspend_cmd,
4055 if (!p_early_suspend_cmd) {
4057 goto err_free_init_cmd;
4061 if (p_dsi->dsi_late_resume_cmd) {
4062 p_late_resume_cmd = kzalloc(sizeof(*p_late_resume_cmd) *
4063 p_dsi->n_late_resume_cmd,
4065 if (!p_late_resume_cmd) {
4067 goto err_free_p_early_suspend_cmd;
4071 p_suspend_cmd = kzalloc(sizeof(*p_suspend_cmd) * p_dsi->n_suspend_cmd,
4073 if (!p_suspend_cmd) {
4075 goto err_free_p_late_resume_cmd;
4078 memcpy(&dsi->info, p_dsi, sizeof(dsi->info));
4080 /* Copy panel init cmd */
4081 err = tegra_dc_dsi_cp_p_cmd(p_dsi->dsi_init_cmd,
4082 p_init_cmd, p_dsi->n_init_cmd);
4085 dsi->info.dsi_init_cmd = p_init_cmd;
4087 /* Copy panel early suspend cmd */
4088 if (p_dsi->dsi_early_suspend_cmd) {
4089 err = tegra_dc_dsi_cp_p_cmd(p_dsi->dsi_early_suspend_cmd,
4090 p_early_suspend_cmd,
4091 p_dsi->n_early_suspend_cmd);
4094 dsi->info.dsi_early_suspend_cmd = p_early_suspend_cmd;
4097 /* Copy panel late resume cmd */
4098 if (p_dsi->dsi_late_resume_cmd) {
4099 err = tegra_dc_dsi_cp_p_cmd(p_dsi->dsi_late_resume_cmd,
4101 p_dsi->n_late_resume_cmd);
4104 dsi->info.dsi_late_resume_cmd = p_late_resume_cmd;
4107 /* Copy panel suspend cmd */
4108 err = tegra_dc_dsi_cp_p_cmd(p_dsi->dsi_suspend_cmd, p_suspend_cmd,
4109 p_dsi->n_suspend_cmd);
4112 dsi->info.dsi_suspend_cmd = p_suspend_cmd;
4114 if (!dsi->info.panel_reset_timeout_msec)
4115 dsi->info.panel_reset_timeout_msec =
4116 DEFAULT_PANEL_RESET_TIMEOUT;
4117 if (!dsi->info.panel_buffer_size_byte)
4118 dsi->info.panel_buffer_size_byte = DEFAULT_PANEL_BUFFER_BYTE;
4120 if (!dsi->info.max_panel_freq_khz) {
4121 dsi->info.max_panel_freq_khz = DEFAULT_MAX_DSI_PHY_CLK_KHZ;
4123 if (dsi->info.video_burst_mode >
4124 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END){
4125 dev_err(&dsi->dc->ndev->dev, "DSI: max_panel_freq_khz"
4126 "is not set for DSI burst mode.\n");
4127 dsi->info.video_burst_mode =
4128 TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED;
4132 if (!dsi->info.lp_cmd_mode_freq_khz)
4133 dsi->info.lp_cmd_mode_freq_khz = DEFAULT_LP_CMD_MODE_CLK_KHZ;
4135 if (!dsi->info.lp_read_cmd_mode_freq_khz)
4136 dsi->info.lp_read_cmd_mode_freq_khz =
4137 dsi->info.lp_cmd_mode_freq_khz;
4139 /* host mode is for testing only */
4140 dsi->driven_mode = TEGRA_DSI_DRIVEN_BY_DC;
4144 kfree(p_suspend_cmd);
4145 err_free_p_late_resume_cmd:
4146 kfree(p_late_resume_cmd);
4147 err_free_p_early_suspend_cmd:
4148 kfree(p_early_suspend_cmd);
4154 static int _tegra_dc_dsi_init(struct tegra_dc *dc)
4156 struct tegra_dc_dsi_data *dsi;
4157 struct resource *res;
4158 struct resource *base_res;
4159 struct resource dsi_res;
4161 struct clk *dc_clk = NULL;
4162 struct clk *dsi_clk;
4163 struct clk *dsi_fixed_clk = NULL;
4164 struct clk *dsi_lp_clk = NULL;
4165 struct tegra_dsi_out *dsi_pdata;
4167 char *ganged_reg_name[2] = {"ganged_dsia_regs", "ganged_dsib_regs"};
4168 char *dsi_clk_name[2] = {"dsia", "dsib"};
4169 char *dsi_lp_clk_name[2] = {"dsialp", "dsiblp"};
4170 struct device_node *np = dc->ndev->dev.of_node;
4171 #ifdef CONFIG_USE_OF
4172 struct device_node *np_dsi =
4173 of_find_node_by_path("/host1x/dsi");
4175 struct device_node *np_dsi = NULL;
4177 dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
4179 dev_err(&dc->ndev->dev, "dsi: memory allocation failed\n");
4183 dsi->max_instances = dc->out->dsi->ganged_type ? MAX_DSI_INSTANCE : 1;
4184 for (i = 0; i < dsi->max_instances; i++) {
4186 if (np_dsi && of_device_is_available(np_dsi)) {
4187 of_address_to_resource(np_dsi, i, &dsi_res);
4194 res = platform_get_resource_byname(dc->ndev,
4196 dc->out->dsi->ganged_type ?
4197 ganged_reg_name[i] : "dsi_regs");
4200 dev_err(&dc->ndev->dev, "dsi: no mem resource\n");
4205 base_res = request_mem_region(res->start, resource_size(res),
4208 dev_err(&dc->ndev->dev,
4209 "dsi: request_mem_region failed\n");
4214 base = ioremap(res->start, resource_size(res));
4216 dev_err(&dc->ndev->dev,
4217 "dsi: registers can't be mapped\n");
4219 goto err_release_regs;
4222 dsi_pdata = dc->pdata->default_out->dsi;
4224 dev_err(&dc->ndev->dev, "dsi: dsi data not available\n");
4225 goto err_release_regs;
4228 dsi_clk = dsi->info.dsi_instance ?
4229 clk_get(&dc->ndev->dev,
4230 dsi_clk_name[DSI_INSTANCE_1]) :
4231 clk_get(&dc->ndev->dev, dsi_clk_name[i]);
4232 dsi_lp_clk = dsi->info.dsi_instance ?
4233 clk_get(&dc->ndev->dev,
4234 dsi_lp_clk_name[DSI_INSTANCE_1]) :
4235 clk_get(&dc->ndev->dev, dsi_lp_clk_name[i]);
4237 if (IS_ERR_OR_NULL(dsi_clk) || IS_ERR_OR_NULL(dsi_lp_clk)) {
4238 dev_err(&dc->ndev->dev, "dsi: can't get clock\n");
4240 goto err_dsi_clk_put;
4243 dsi->base[i] = base;
4244 dsi->base_res[i] = base_res;
4245 dsi->dsi_clk[i] = dsi_clk;
4246 dsi->dsi_lp_clk[i] = dsi_lp_clk;
4249 dsi_fixed_clk = clk_get(&dc->ndev->dev, "dsi-fixed");
4251 if (IS_ERR_OR_NULL(dsi_fixed_clk)) {
4252 dev_err(&dc->ndev->dev, "dsi: can't get fixed clock\n");
4254 goto err_release_regs;
4257 dc_clk = clk_get_sys(dev_name(&dc->ndev->dev), NULL);
4258 if (IS_ERR_OR_NULL(dc_clk)) {
4259 dev_err(&dc->ndev->dev, "dsi: dc clock %s unavailable\n",
4260 dev_name(&dc->ndev->dev));
4262 goto err_dsi_fixed_clk_put;
4265 mutex_init(&dsi->lock);
4267 dsi->dc_clk = dc_clk;
4268 dsi->dsi_fixed_clk = dsi_fixed_clk;
4270 err = tegra_dc_dsi_cp_info(dsi, dsi_pdata);
4272 goto err_dc_clk_put;
4274 tegra_dc_set_outdata(dc, dsi);
4275 __tegra_dc_dsi_init(dc);
4281 err_dsi_fixed_clk_put:
4282 clk_put(dsi_fixed_clk);
4284 for (i = 0; i < dsi->max_instances; i++) {
4285 clk_put(dsi->dsi_lp_clk[i]);
4286 clk_put(dsi->dsi_clk[i]);
4289 for (i = 0; i < dsi->max_instances; i++)
4290 release_resource(dsi->base_res[i]);
4297 static void _tegra_dc_dsi_destroy(struct tegra_dc *dc)
4299 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4303 mutex_lock(&dsi->lock);
4304 tegra_dc_io_start(dc);
4306 if (dsi->out_ops && dsi->out_ops->destroy)
4307 dsi->out_ops->destroy(dsi);
4309 /* free up the pdata */
4310 for (i = 0; i < dsi->info.n_init_cmd; i++) {
4311 if (dsi->info.dsi_init_cmd[i].pdata)
4312 kfree(dsi->info.dsi_init_cmd[i].pdata);
4314 kfree(dsi->info.dsi_init_cmd);
4316 /* Disable dc stream */
4317 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
4318 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
4320 /* Disable dsi phy clock */
4321 if (dsi->status.clk_out == DSI_PHYCLK_OUT_EN)
4322 tegra_dsi_hs_clk_out_disable(dc, dsi);
4324 val = DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE);
4325 tegra_dsi_writel(dsi, val, DSI_POWER_CONTROL);
4327 for (i = 0; i < dsi->max_instances; i++) {
4328 iounmap(dsi->base[i]);
4329 release_resource(dsi->base_res[i]);
4331 clk_put(dsi->dc_clk);
4332 for (i = 0; i < dsi->max_instances; i++)
4333 clk_put(dsi->dsi_clk[i]);
4335 tegra_dc_io_end(dc);
4336 mutex_unlock(&dsi->lock);
4337 mutex_destroy(&dsi->lock);
4341 static void tegra_dsi_config_phy_clk(struct tegra_dc_dsi_data *dsi,
4344 struct clk *parent_clk = NULL;
4345 struct clk *base_clk = NULL;
4348 for (i = 0; i < dsi->max_instances; i++) {
4349 parent_clk = clk_get_parent(dsi->dsi_clk[i]);
4350 base_clk = clk_get_parent(parent_clk);
4352 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
4353 if (dsi->info.dsi_instance)
4354 tegra_clk_cfg_ex(base_clk,
4355 TEGRA_CLK_PLLD_CSI_OUT_ENB,
4358 tegra_clk_cfg_ex(base_clk,
4359 TEGRA_CLK_PLLD_DSI_OUT_ENB,
4362 tegra_clk_cfg_ex(base_clk,
4363 TEGRA_CLK_PLLD_DSI_OUT_ENB,
4369 static int tegra_dsi_te_on_off(struct tegra_dc_dsi_data *dsi, bool flag)
4373 struct tegra_dsi_cmd te_enable[] = {
4374 DSI_CMD_SHORT(DSI_DCS_WRITE_0_PARAM,
4375 DSI_DCS_SET_TEARING_EFFECT_ON, 0x0),
4379 struct tegra_dsi_cmd te_disable[] = {
4380 DSI_CMD_SHORT(DSI_DCS_WRITE_0_PARAM,
4381 DSI_DCS_SET_TEARING_EFFECT_OFF, 0x0),
4386 ret = tegra_dsi_send_panel_cmd(dsi->dc, dsi, te_enable,
4387 ARRAY_SIZE(te_enable));
4389 ret = tegra_dsi_send_panel_cmd(dsi->dc, dsi, te_disable,
4390 ARRAY_SIZE(te_disable));
4395 static int _tegra_dsi_host_suspend(struct tegra_dc *dc,
4396 struct tegra_dc_dsi_data *dsi,
4402 switch (suspend_aggr) {
4403 case DSI_HOST_SUSPEND_LV2:
4405 err = tegra_dsi_enter_ulpm(dsi);
4407 dev_err(&dc->ndev->dev,
4408 "DSI failed to enter ulpm\n");
4413 tegra_dsi_pad_disable(dsi);
4415 /* Suspend core-logic */
4416 val = DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE);
4417 tegra_dsi_writel(dsi, val, DSI_POWER_CONTROL);
4419 /* disable HS logic */
4420 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_3_VS1);
4421 val |= DSI_PAD_PDVCLAMP(0x1);
4422 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
4424 /* disable mipi bias pad */
4425 tegra_mipi_cal_clk_enable(dsi->mipi_cal);
4426 val = tegra_mipi_cal_read(dsi->mipi_cal,
4427 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
4428 val |= MIPI_BIAS_PAD_PDVCLAMP(0x1);
4429 tegra_mipi_cal_write(dsi->mipi_cal, val,
4430 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
4431 tegra_mipi_cal_clk_disable(dsi->mipi_cal);
4434 case DSI_HOST_SUSPEND_LV1:
4435 /* Disable dsi fast and slow clock */
4436 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_DISABLE);
4438 case DSI_HOST_SUSPEND_LV0:
4439 /* Disable dsi source clock */
4440 tegra_dsi_clk_disable(dsi);
4442 case DSI_NO_SUSPEND:
4445 dev_err(&dc->ndev->dev, "DSI suspend aggressiveness"
4446 "is not supported.\n");
4449 tegra_dvfs_set_rate(dc->clk, 0);
4456 static int _tegra_dsi_host_resume(struct tegra_dc *dc,
4457 struct tegra_dc_dsi_data *dsi,
4463 switch (dsi->info.suspend_aggr) {
4464 case DSI_HOST_SUSPEND_LV0:
4465 tegra_dsi_clk_enable(dsi);
4467 case DSI_HOST_SUSPEND_LV1:
4468 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_ENABLE);
4469 tegra_dsi_clk_enable(dsi);
4471 case DSI_HOST_SUSPEND_LV2:
4472 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_ENABLE);
4473 tegra_dsi_clk_enable(dsi);
4475 /* enable mipi bias pad */
4476 tegra_mipi_cal_clk_enable(dsi->mipi_cal);
4477 val = tegra_mipi_cal_read(dsi->mipi_cal,
4478 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
4479 val &= ~MIPI_BIAS_PAD_PDVCLAMP(0x1);
4480 tegra_mipi_cal_write(dsi->mipi_cal, val,
4481 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
4482 tegra_mipi_cal_clk_disable(dsi->mipi_cal);
4484 /* enable HS logic */
4485 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_3_VS1);
4486 val &= ~DSI_PAD_PDVCLAMP(0x1);
4487 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
4489 tegra_dsi_writel(dsi,
4490 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_ENABLE),
4494 err = tegra_dsi_enter_ulpm(dsi);
4496 dev_err(&dc->ndev->dev,
4497 "DSI failed to enter ulpm\n");
4501 tegra_dsi_pad_enable(dsi);
4503 if (tegra_dsi_exit_ulpm(dsi) < 0) {
4504 dev_err(&dc->ndev->dev,
4505 "DSI failed to exit ulpm\n");
4509 tegra_dsi_pad_enable(dsi);
4512 case DSI_NO_SUSPEND:
4515 dev_err(&dc->ndev->dev, "DSI suspend aggressivenes"
4516 "is not supported.\n");
4519 tegra_dvfs_set_rate(dc->clk, dc->mode.pclk);
4526 static int tegra_dsi_host_suspend_trylock(struct tegra_dc *dc,
4527 struct tegra_dc_dsi_data *dsi)
4529 if (!mutex_trylock(&dc->lp_lock))
4531 if (!mutex_trylock(&dc->lock))
4532 goto unlock_one_shot_lp;
4533 if (!mutex_trylock(&dsi->host_lock))
4534 goto unlock_dc_lock;
4535 if (!mutex_trylock(&dc->one_shot_lock))
4536 goto unlock_host_lock;
4541 mutex_unlock(&dsi->host_lock);
4543 mutex_unlock(&dc->lock);
4545 mutex_unlock(&dc->lp_lock);
4550 static void tegra_dsi_host_suspend_unlock(struct tegra_dc *dc,
4551 struct tegra_dc_dsi_data *dsi)
4553 mutex_unlock(&dc->one_shot_lock);
4554 mutex_unlock(&dsi->host_lock);
4555 mutex_unlock(&dc->lock);
4556 mutex_unlock(&dc->lp_lock);
4559 static int tegra_dsi_host_suspend(struct tegra_dc *dc)
4562 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4567 while (!tegra_dsi_host_suspend_trylock(dc, dsi))
4570 if (dsi->host_suspended || atomic_read(&dsi->host_ref)) {
4571 tegra_dsi_host_suspend_unlock(dc, dsi);
4575 tegra_dc_io_start(dc);
4577 dsi->host_suspended = true;
4579 tegra_dsi_stop_dc_stream(dc, dsi);
4581 tegra_dsi_te_on_off(dsi, false);
4583 err = _tegra_dsi_host_suspend(dc, dsi, dsi->info.suspend_aggr);
4585 dev_err(&dc->ndev->dev,
4586 "DSI host suspend failed\n");
4590 /* Shutting down. Drop any reference to dc clk */
4591 while (tegra_is_clk_enabled(dc->clk))
4594 pm_runtime_put_sync(&dc->ndev->dev);
4596 tegra_dc_io_end(dc);
4597 tegra_dsi_host_suspend_unlock(dc, dsi);
4601 static bool tegra_dc_dsi_osidle(struct tegra_dc *dc)
4603 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4605 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_MODE)
4606 return dsi->host_suspended;
4611 static void tegra_dsi_bl_off(struct backlight_device *bd)
4616 bd->props.brightness = 0;
4617 backlight_update_status(bd);
4620 static int tegra_dsi_deep_sleep(struct tegra_dc *dc,
4621 struct tegra_dc_dsi_data *dsi)
4629 cancel_delayed_work(&dsi->idle_work);
4631 tegra_dsi_bl_off(get_backlight_device_by_name(dsi->info.bl_name));
4633 err = tegra_dsi_set_to_lp_mode(dc, dsi, DSI_LP_OP_WRITE);
4635 dev_err(&dc->ndev->dev,
4636 "DSI failed to go to LP mode\n");
4640 /* Suspend DSI panel */
4641 err = tegra_dsi_send_panel_cmd(dc, dsi,
4642 dsi->info.dsi_suspend_cmd,
4643 dsi->info.n_suspend_cmd);
4646 * Certain panels need dc frames be sent after
4647 * putting panel to sleep.
4649 if (dsi->info.panel_send_dc_frames)
4650 tegra_dsi_send_dc_frames(dc, dsi, 2);
4653 dev_err(&dc->ndev->dev,
4654 "dsi: Error sending suspend cmd\n");
4659 err = tegra_dsi_enter_ulpm(dsi);
4661 dev_err(&dc->ndev->dev,
4662 "DSI failed to enter ulpm\n");
4667 tegra_dsi_pad_disable(dsi);
4669 /* Suspend core-logic */
4670 val = DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE);
4671 tegra_dsi_writel(dsi, val, DSI_POWER_CONTROL);
4673 /* Disable dsi fast and slow clock */
4674 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_DISABLE);
4676 /* Disable dsi source clock */
4677 tegra_dsi_clk_disable(dsi);
4679 dsi->enabled = false;
4680 dsi->host_suspended = true;
4687 static void tegra_dc_dsi_postpoweroff(struct tegra_dc *dc)
4689 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4692 regulator_disable(dsi->avdd_dsi_csi);
4695 static int tegra_dsi_host_resume(struct tegra_dc *dc)
4698 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4703 cancel_delayed_work(&dsi->idle_work);
4705 mutex_lock(&dsi->host_lock);
4706 if (!dsi->host_suspended) {
4707 mutex_unlock(&dsi->host_lock);
4711 tegra_dc_io_start(dc);
4713 pm_runtime_get_sync(&dc->ndev->dev);
4715 err = _tegra_dsi_host_resume(dc, dsi, dsi->info.suspend_aggr);
4717 dev_err(&dc->ndev->dev,
4718 "DSI host resume failed\n");
4722 tegra_dsi_te_on_off(dsi, true);
4724 tegra_dsi_start_dc_stream(dc, dsi);
4725 dsi->host_suspended = false;
4727 tegra_dc_io_end(dc);
4728 mutex_unlock(&dsi->host_lock);
4732 static void tegra_dc_dsi_disable(struct tegra_dc *dc)
4735 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4737 if (dsi->host_suspended)
4738 tegra_dsi_host_resume(dc);
4740 mutex_lock(&dsi->lock);
4741 tegra_dc_io_start(dc);
4743 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
4744 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
4746 if (dsi->out_ops && dsi->out_ops->disable)
4747 dsi->out_ops->disable(dsi);
4749 if (dsi->info.power_saving_suspend) {
4750 if (tegra_dsi_deep_sleep(dc, dsi) < 0) {
4751 dev_err(&dc->ndev->dev,
4752 "DSI failed to enter deep sleep\n");
4756 if (dsi->info.dsi_early_suspend_cmd) {
4757 err = tegra_dsi_send_panel_cmd(dc, dsi,
4758 dsi->info.dsi_early_suspend_cmd,
4759 dsi->info.n_early_suspend_cmd);
4761 dev_err(&dc->ndev->dev,
4762 "dsi: Error sending early suspend cmd\n");
4768 if (tegra_dsi_enter_ulpm(dsi) < 0) {
4769 dev_err(&dc->ndev->dev,
4770 "DSI failed to enter ulpm\n");
4776 mutex_unlock(&dsi->lock);
4777 tegra_dc_io_end(dc);
4781 static void tegra_dc_dsi_suspend(struct tegra_dc *dc)
4783 struct tegra_dc_dsi_data *dsi;
4785 dsi = tegra_dc_get_outdata(dc);
4790 if (dsi->host_suspended)
4791 tegra_dsi_host_resume(dc);
4793 tegra_dc_io_start(dc);
4794 mutex_lock(&dsi->lock);
4796 if (dsi->out_ops && dsi->out_ops->suspend)
4797 dsi->out_ops->suspend(dsi);
4799 if (!dsi->info.power_saving_suspend) {
4801 if (tegra_dsi_exit_ulpm(dsi) < 0) {
4802 dev_err(&dc->ndev->dev,
4803 "DSI failed to exit ulpm");
4808 if (tegra_dsi_deep_sleep(dc, dsi) < 0) {
4809 dev_err(&dc->ndev->dev,
4810 "DSI failed to enter deep sleep\n");
4815 mutex_unlock(&dsi->lock);
4816 tegra_dc_io_end(dc);
4819 static void tegra_dc_dsi_resume(struct tegra_dc *dc)
4821 struct tegra_dc_dsi_data *dsi;
4823 dsi = tegra_dc_get_outdata(dc);
4825 /* No dsi config required since tegra_dc_dsi_enable
4826 * will reconfigure the controller from scratch
4829 if (dsi->out_ops && dsi->out_ops->resume)
4830 dsi->out_ops->resume(dsi);
4834 static int tegra_dc_dsi_init(struct tegra_dc *dc)
4836 struct tegra_dc_dsi_data *dsi;
4839 err = _tegra_dc_dsi_init(dc);
4841 dev_err(&dc->ndev->dev,
4842 "dsi: Instance A init failed\n");
4846 dsi = tegra_dc_get_outdata(dc);
4848 dsi->avdd_dsi_csi = regulator_get(&dc->ndev->dev, "avdd_dsi_csi");
4849 if (IS_ERR_OR_NULL(dsi->avdd_dsi_csi)) {
4850 dev_err(&dc->ndev->dev, "dsi: avdd_dsi_csi reg get failed\n");
4855 dsi->mipi_cal = tegra_mipi_cal_init_sw(dc);
4856 if (IS_ERR(dsi->mipi_cal)) {
4857 dev_err(&dc->ndev->dev, "dsi: mipi_cal sw init failed\n");
4858 err = PTR_ERR(dsi->mipi_cal);
4863 regulator_put(dsi->avdd_dsi_csi);
4865 _tegra_dc_dsi_destroy(dc);
4866 tegra_dc_set_outdata(dc, NULL);
4871 static void tegra_dc_dsi_destroy(struct tegra_dc *dc)
4873 struct regulator *avdd_dsi_csi;
4874 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4876 avdd_dsi_csi = dsi->avdd_dsi_csi;
4878 _tegra_dc_dsi_destroy(dc);
4879 regulator_put(avdd_dsi_csi);
4880 tegra_mipi_cal_destroy(dc);
4883 static long tegra_dc_dsi_setup_clk(struct tegra_dc *dc, struct clk *clk)
4886 struct clk *parent_clk;
4887 struct clk *base_clk;
4888 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4890 /* divide by 1000 to avoid overflow */
4891 dc->mode.pclk /= 1000;
4892 rate = (dc->mode.pclk * dc->shift_clk_div.mul * 2)
4893 / dc->shift_clk_div.div;
4895 dc->mode.pclk *= 1000;
4897 if (dc->out->flags & TEGRA_DC_OUT_INITIALIZED_MODE)
4900 if (clk == dc->clk) {
4901 parent_clk = clk_get_sys(NULL,
4902 dc->out->parent_clk ? : "pll_d_out0");
4903 base_clk = clk_get_parent(parent_clk);
4905 if (dc->pdata->default_out->dsi->dsi_instance) {
4906 parent_clk = clk_get_sys(NULL,
4907 dc->out->parent_clk ? : "pll_d2_out0");
4908 base_clk = clk_get_parent(parent_clk);
4910 parent_clk = clk_get_sys(NULL,
4911 dc->out->parent_clk ? : "pll_d_out0");
4912 base_clk = clk_get_parent(parent_clk);
4915 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_ENABLE);
4917 if (rate != clk_get_rate(base_clk))
4918 clk_set_rate(base_clk, rate);
4920 if (clk_get_parent(clk) != parent_clk)
4921 clk_set_parent(clk, parent_clk);
4924 tegra_dvfs_set_rate(dc->clk, dc->mode.pclk);
4926 return tegra_dc_pclk_round_rate(dc, dc->mode.pclk);
4929 struct tegra_dc_out_ops tegra_dc_dsi_ops = {
4930 .init = tegra_dc_dsi_init,
4931 .destroy = tegra_dc_dsi_destroy,
4932 .enable = tegra_dc_dsi_enable,
4933 .postpoweron = tegra_dc_dsi_postpoweron,
4934 .disable = tegra_dc_dsi_disable,
4935 .postpoweroff = tegra_dc_dsi_postpoweroff,
4936 .hold = tegra_dc_dsi_hold_host,
4937 .release = tegra_dc_dsi_release_host,
4939 .suspend = tegra_dc_dsi_suspend,
4940 .resume = tegra_dc_dsi_resume,
4942 .setup_clk = tegra_dc_dsi_setup_clk,
4943 .osidle = tegra_dc_dsi_osidle,