2 * drivers/video/tegra/dc/dsi.c
4 * Copyright (c) 2011-2016, 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>
44 #include <mach/io_dpd.h>
53 /* HACK! This needs to come from DT */
54 #include "../../../../arch/arm/mach-tegra/iomap.h"
56 #define APB_MISC_GP_MIPI_PAD_CTRL_0 (TEGRA_APB_MISC_BASE + 0x820)
57 #define DSIB_MODE_ENABLE 0x2
59 #if !defined(CONFIG_ARCH_TEGRA_2x_SOC) && \
60 !defined(CONFIG_ARCH_TEGRA_3x_SOC) && \
61 !defined(CONFIG_ARCH_TEGRA_11x_SOC) && \
62 !defined(CONFIG_ARCH_TEGRA_14x_SOC)
63 #define DSI_USE_SYNC_POINTS 1
65 #define DSI_USE_SYNC_POINTS 0
68 #define S_TO_MS(x) (1000 * (x))
69 #define MS_TO_US(x) (1000 * (x))
71 #define DSI_MODULE_NOT_INIT 0x0
72 #define DSI_MODULE_INIT 0x1
74 #define DSI_LPHS_NOT_INIT 0x0
75 #define DSI_LPHS_IN_LP_MODE 0x1
76 #define DSI_LPHS_IN_HS_MODE 0x2
78 #define DSI_VIDEO_TYPE_NOT_INIT 0x0
79 #define DSI_VIDEO_TYPE_VIDEO_MODE 0x1
80 #define DSI_VIDEO_TYPE_CMD_MODE 0x2
82 #define DSI_DRIVEN_MODE_NOT_INIT 0x0
83 #define DSI_DRIVEN_MODE_DC 0x1
84 #define DSI_DRIVEN_MODE_HOST 0x2
86 #define DSI_PHYCLK_OUT_DIS 0x0
87 #define DSI_PHYCLK_OUT_EN 0x1
89 #define DSI_PHYCLK_NOT_INIT 0x0
90 #define DSI_PHYCLK_CONTINUOUS 0x1
91 #define DSI_PHYCLK_TX_ONLY 0x2
93 #define DSI_CLK_BURST_NOT_INIT 0x0
94 #define DSI_CLK_BURST_NONE_BURST 0x1
95 #define DSI_CLK_BURST_BURST_MODE 0x2
97 #define DSI_DC_STREAM_DISABLE 0x0
98 #define DSI_DC_STREAM_ENABLE 0x1
100 #define DSI_LP_OP_NOT_INIT 0x0
101 #define DSI_LP_OP_WRITE 0x1
102 #define DSI_LP_OP_READ 0x2
104 #define DSI_HOST_IDLE_PERIOD 1000
105 static atomic_t dsi_syncpt_rst = ATOMIC_INIT(0);
107 static bool enable_read_debug;
108 module_param(enable_read_debug, bool, 0644);
109 MODULE_PARM_DESC(enable_read_debug,
110 "Enable to print read fifo and return packet type");
112 static struct tegra_io_dpd dsi_io = {
114 .io_dpd_reg_index = 0,
117 static struct tegra_io_dpd dsib_io = {
119 .io_dpd_reg_index = 1,
122 static struct tegra_io_dpd dsic_io = {
124 .io_dpd_reg_index = 1,
127 static struct tegra_io_dpd dsid_io = {
129 .io_dpd_reg_index = 1,
133 bool tegra_dsi_enable_read_debug(struct tegra_dc_dsi_data *dsi)
135 enable_read_debug = true;
136 return enable_read_debug;
139 bool tegra_dsi_disable_read_debug(struct tegra_dc_dsi_data *dsi)
141 enable_read_debug = false;
142 return enable_read_debug;
145 /* source of video data */
147 TEGRA_DSI_DRIVEN_BY_DC,
148 TEGRA_DSI_DRIVEN_BY_HOST,
151 static const u32 dsi_pkt_seq_reg[NUMOF_PKT_SEQ] = {
166 static const u32 dsi_pkt_seq_video_non_burst_syne[NUMOF_PKT_SEQ] = {
167 PKT_ID0(CMD_VS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
169 PKT_ID0(CMD_VE) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
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(1) |
174 PKT_ID2(CMD_HE) | PKT_LEN2(0),
175 PKT_ID3(CMD_BLNK) | PKT_LEN3(2) | PKT_ID4(CMD_RGB) | PKT_LEN4(3) |
176 PKT_ID5(CMD_BLNK) | PKT_LEN5(4),
177 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
179 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(1) |
180 PKT_ID2(CMD_HE) | PKT_LEN2(0),
181 PKT_ID3(CMD_BLNK) | PKT_LEN3(2) | PKT_ID4(CMD_RGB) | PKT_LEN4(3) |
182 PKT_ID5(CMD_BLNK) | PKT_LEN5(4),
185 static const u32 dsi_pkt_seq_video_non_burst[NUMOF_PKT_SEQ] = {
186 PKT_ID0(CMD_VS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
188 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
190 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
192 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2) |
193 PKT_ID2(CMD_RGB) | PKT_LEN2(3),
194 PKT_ID3(CMD_BLNK) | PKT_LEN3(4),
195 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
197 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2) |
198 PKT_ID2(CMD_RGB) | PKT_LEN2(3),
199 PKT_ID3(CMD_BLNK) | PKT_LEN3(4),
202 static const u32 dsi_pkt_seq_video_non_burst_no_eot_no_lp_no_hbp[NUMOF_PKT_SEQ] = {
203 PKT_ID0(CMD_VS) | PKT_LEN0(0),
205 PKT_ID0(CMD_HS) | PKT_LEN0(0),
207 PKT_ID0(CMD_HS) | PKT_LEN0(0),
209 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_RGB) | PKT_LEN1(3) |
210 PKT_ID2(CMD_BLNK) | PKT_LEN2(4),
212 PKT_ID0(CMD_HS) | PKT_LEN0(0),
214 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_RGB) | PKT_LEN1(3) |
215 PKT_ID2(CMD_BLNK) | PKT_LEN2(4),
219 static const u32 dsi_pkt_seq_video_burst[NUMOF_PKT_SEQ] = {
220 PKT_ID0(CMD_VS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
222 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
224 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
226 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2)|
227 PKT_ID2(CMD_RGB) | PKT_LEN2(3) | PKT_LP,
228 PKT_ID0(CMD_EOT) | PKT_LEN0(7),
229 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_EOT) | PKT_LEN1(7) | PKT_LP,
231 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2)|
232 PKT_ID2(CMD_RGB) | PKT_LEN2(3) | PKT_LP,
233 PKT_ID0(CMD_EOT) | PKT_LEN0(7),
236 static const u32 dsi_pkt_seq_video_burst_no_eot[NUMOF_PKT_SEQ] = {
237 PKT_ID0(CMD_VS) | PKT_LEN0(0) | PKT_LP,
239 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_LP,
241 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_LP,
243 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2)|
244 PKT_ID2(CMD_RGB) | PKT_LEN2(3) | PKT_LP,
246 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_LP,
248 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2)|
249 PKT_ID2(CMD_RGB) | PKT_LEN2(3) | PKT_LP,
253 static const u32 dsi_pkt_seq_video_non_burst_no_eot[NUMOF_PKT_SEQ] = {
254 PKT_ID0(CMD_VS) | PKT_LEN0(0) | PKT_LP,
256 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_LP,
258 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_LP,
260 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2) |
261 PKT_ID2(CMD_RGB) | PKT_LEN2(3),
262 PKT_ID3(CMD_BLNK) | PKT_LEN3(4),
263 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_LP,
265 PKT_ID0(CMD_HS) | PKT_LEN0(0) | PKT_ID1(CMD_BLNK) | PKT_LEN1(2) |
266 PKT_ID2(CMD_RGB) | PKT_LEN2(3),
267 PKT_ID3(CMD_BLNK) | PKT_LEN3(4),
270 static const u32 dsi_pkt_seq_cmd_mode[NUMOF_PKT_SEQ] = {
277 PKT_ID0(CMD_LONGW) | PKT_LEN0(3) | PKT_ID1(CMD_EOT) |
278 PKT_LEN1(7) | PKT_LP,
282 PKT_ID0(CMD_LONGW) | PKT_LEN0(3) | PKT_ID1(CMD_EOT) |
283 PKT_LEN1(7) | PKT_LP,
287 static const u32 init_reg[] = {
299 DSI_INIT_SEQ_DATA_15,
314 DSI_HOST_DSI_CONTROL,
321 DSI_INIT_SEQ_CONTROL,
328 static const u32 init_reg_vs1_ext[] = {
329 DSI_PAD_CONTROL_0_VS1,
330 DSI_PAD_CONTROL_CD_VS1,
331 DSI_PAD_CD_STATUS_VS1,
332 DSI_PAD_CONTROL_1_VS1,
333 DSI_PAD_CONTROL_2_VS1,
334 DSI_PAD_CONTROL_3_VS1,
335 DSI_PAD_CONTROL_4_VS1,
336 DSI_GANGED_MODE_CONTROL,
337 DSI_GANGED_MODE_START,
338 DSI_GANGED_MODE_SIZE,
341 static int tegra_dsi_host_suspend(struct tegra_dc *dc);
342 static int tegra_dsi_host_resume(struct tegra_dc *dc);
343 static void tegra_dc_dsi_idle_work(struct work_struct *work);
344 static void tegra_dsi_send_dc_frames(struct tegra_dc *dc,
345 struct tegra_dc_dsi_data *dsi,
348 unsigned long tegra_dsi_controller_readl(struct tegra_dc_dsi_data *dsi,
353 BUG_ON(!nvhost_module_powered_ext(dsi->dc->ndev));
354 if (likely(tegra_platform_is_silicon())) {
355 if (WARN(!tegra_is_clk_enabled(dsi->dsi_clk[index]),
356 "DSI is clock gated!"))
359 ret = readl(dsi->base[index] + reg * 4);
360 trace_display_readl(dsi->dc, ret, dsi->base[index] + reg * 4);
363 EXPORT_SYMBOL(tegra_dsi_controller_readl);
365 void tegra_dsi_controller_writel(struct tegra_dc_dsi_data *dsi,
366 u32 val, u32 reg, int index)
368 BUG_ON(!nvhost_module_powered_ext(dsi->dc->ndev));
369 if (likely(tegra_platform_is_silicon())) {
370 if (WARN(!tegra_is_clk_enabled(dsi->dsi_clk[index]),
371 "DSI is clock gated!"))
374 trace_display_writel(dsi->dc, val, dsi->base[index] + reg * 4);
375 writel(val, dsi->base[index] + reg * 4);
377 EXPORT_SYMBOL(tegra_dsi_controller_writel);
379 unsigned long tegra_dsi_readl(struct tegra_dc_dsi_data *dsi, u32 reg)
382 BUG_ON(!nvhost_module_powered_ext(dsi->dc->ndev));
383 ret = readl(dsi->base[DSI_INSTANCE_0] + reg * 4);
384 trace_display_readl(dsi->dc, ret, dsi->base[DSI_INSTANCE_0] + reg * 4);
387 EXPORT_SYMBOL(tegra_dsi_readl);
389 void tegra_dsi_writel(struct tegra_dc_dsi_data *dsi, u32 val, u32 reg)
392 BUG_ON(!nvhost_module_powered_ext(dsi->dc->ndev));
393 for (i = 0; i < dsi->max_instances; i++) {
394 trace_display_writel(dsi->dc, val, dsi->base[i] + reg * 4);
395 writel(val, dsi->base[i] + reg * 4);
398 EXPORT_SYMBOL(tegra_dsi_writel);
400 inline void tegra_dsi_reset_deassert(struct tegra_dc_dsi_data *dsi)
403 for (i = 0; i < dsi->max_instances; i++)
404 tegra_periph_reset_deassert(dsi->dsi_clk[i]);
407 inline void tegra_dsi_reset_assert(struct tegra_dc_dsi_data *dsi)
410 for (i = 0; i < dsi->max_instances; i++)
411 tegra_periph_reset_assert(dsi->dsi_clk[i]);
414 static inline void tegra_dsi_lp_clk_enable(struct tegra_dc_dsi_data *dsi);
415 static inline void tegra_dsi_lp_clk_disable(struct tegra_dc_dsi_data *dsi);
417 void tegra_dsi_clk_enable(struct tegra_dc_dsi_data *dsi)
420 for (i = 0; i < dsi->max_instances; i++) {
421 tegra_disp_clk_prepare_enable(dsi->dsi_clk[i]);
426 void tegra_dsi_clk_disable(struct tegra_dc_dsi_data *dsi)
429 for (i = 0; i < dsi->max_instances; i++) {
430 tegra_disp_clk_disable_unprepare(dsi->dsi_clk[i]);
435 static inline void tegra_dsi_lp_clk_enable(struct tegra_dc_dsi_data *dsi)
438 for (i = 0; i < dsi->max_instances; i++) {
439 tegra_disp_clk_prepare_enable(dsi->dsi_lp_clk[i]);
444 static inline void tegra_dsi_lp_clk_disable(struct tegra_dc_dsi_data *dsi)
447 for (i = 0; i < dsi->max_instances; i++) {
448 tegra_disp_clk_disable_unprepare(dsi->dsi_lp_clk[i]);
453 static void tegra_dsi_setup_clk(struct tegra_dc *dc,
454 struct tegra_dc_dsi_data *dsi)
458 for (i = 0; i < dsi->max_instances; i++) {
459 tegra_dc_setup_clk(dc, dsi->dsi_clk[i]);
464 static void __maybe_unused tegra_dsi_syncpt_reset(
465 struct tegra_dc_dsi_data *dsi)
467 tegra_dsi_writel(dsi, 0x1, DSI_INCR_SYNCPT_CNTRL);
468 /* stabilization delay */
470 tegra_dsi_writel(dsi, 0x0, DSI_INCR_SYNCPT_CNTRL);
471 /* stabilization delay */
475 static int __maybe_unused tegra_dsi_syncpt
476 (struct tegra_dc_dsi_data *dsi, u8 link_id)
481 if (!nvhost_syncpt_read_ext_check(dsi->dc->ndev, dsi->syncpt_id, &val))
482 dsi->syncpt_val = val;
484 val = DSI_INCR_SYNCPT_COND(OP_DONE) |
485 DSI_INCR_SYNCPT_INDX(dsi->syncpt_id);
486 if (dsi->info.ganged_type && dsi->info.ganged_write_to_all_links)
487 tegra_dsi_writel(dsi, val, DSI_INCR_SYNCPT);
489 tegra_dsi_controller_writel(dsi, val, DSI_INCR_SYNCPT, link_id);
491 ret = nvhost_syncpt_wait_timeout_ext(dsi->dc->ndev, dsi->syncpt_id,
492 dsi->syncpt_val + 1, msecs_to_jiffies(500), NULL, NULL);
494 dev_err(&dsi->dc->ndev->dev, "DSI sync point failure\n");
504 static u32 tegra_dsi_get_hs_clk_rate(struct tegra_dc_dsi_data *dsi)
506 u32 dsi_clock_rate_khz;
508 switch (dsi->info.video_burst_mode) {
509 case TEGRA_DSI_VIDEO_BURST_MODE_LOW_SPEED:
510 case TEGRA_DSI_VIDEO_BURST_MODE_MEDIUM_SPEED:
511 case TEGRA_DSI_VIDEO_BURST_MODE_FAST_SPEED:
512 case TEGRA_DSI_VIDEO_BURST_MODE_FASTEST_SPEED:
513 /* Calculate DSI HS clock rate for DSI burst mode */
514 dsi_clock_rate_khz = dsi->default_pixel_clk_khz *
515 dsi->shift_clk_div.mul /
516 dsi->shift_clk_div.div;
518 case TEGRA_DSI_VIDEO_NONE_BURST_MODE:
519 case TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END:
520 case TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED:
522 /* Clock rate is default DSI clock rate for non-burst mode */
523 dsi_clock_rate_khz = dsi->default_hs_clk_khz;
527 return dsi_clock_rate_khz;
530 static u32 tegra_dsi_get_lp_clk_rate(struct tegra_dc_dsi_data *dsi, u8 lp_op)
532 u32 dsi_clock_rate_khz;
534 if (dsi->info.enable_hs_clock_on_lp_cmd_mode)
535 if (dsi->info.hs_clk_in_lp_cmd_mode_freq_khz)
537 dsi->info.hs_clk_in_lp_cmd_mode_freq_khz;
539 dsi_clock_rate_khz = tegra_dsi_get_hs_clk_rate(dsi);
541 if (lp_op == DSI_LP_OP_READ)
543 dsi->info.lp_read_cmd_mode_freq_khz;
546 dsi->info.lp_cmd_mode_freq_khz;
548 return dsi_clock_rate_khz;
551 static struct tegra_dc_shift_clk_div tegra_dsi_get_shift_clk_div(
552 struct tegra_dc_dsi_data *dsi)
554 struct tegra_dc_shift_clk_div shift_clk_div;
555 struct tegra_dc_shift_clk_div max_shift_clk_div;
556 struct tegra_dc_shift_clk_div delta_shift_clk_div;
561 u32 default_hs_clk_mhz =
562 DIV_ROUND_CLOSEST(dsi->default_hs_clk_khz, 1000);
563 u32 max_panel_freq_mhz =
564 DIV_ROUND_CLOSEST(dsi->info.max_panel_freq_khz, 1000);
566 /* Get the real value of default shift_clk_div. default_shift_clk_div
567 * holds the real value of shift_clk_div.
569 shift_clk_div = dsi->default_shift_clk_div;
571 /* Calculate shift_clk_div which can match the video_burst_mode. */
572 if (dsi->info.video_burst_mode >=
573 TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED) {
574 if (max_panel_freq_mhz >= default_hs_clk_mhz) {
576 * dsi->info.max_panel_freq_khz * shift_clk_div /
577 * dsi->default_hs_clk_khz
579 max_shift_clk_div.mul = max_panel_freq_mhz *
581 max_shift_clk_div.div = default_hs_clk_mhz *
584 max_shift_clk_div = shift_clk_div;
587 burst_width = dsi->info.video_burst_mode
588 - TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED;
589 burst_width_max = TEGRA_DSI_VIDEO_BURST_MODE_FASTEST_SPEED
590 - TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED;
593 * (max_shift_clk_div - shift_clk_div) *
594 * burst_width / burst_width_max
596 temp_lcm = lcm(max_shift_clk_div.div, shift_clk_div.div);
597 delta_shift_clk_div.mul = (temp_lcm / max_shift_clk_div.div *
598 max_shift_clk_div.mul -
599 temp_lcm / shift_clk_div.div *
602 delta_shift_clk_div.div = temp_lcm * burst_width_max;
605 * shift_clk_div + delta_shift_clk_div
607 temp_lcm = lcm(shift_clk_div.div, delta_shift_clk_div.div);
608 shift_clk_div.mul = temp_lcm / shift_clk_div.div *
610 temp_lcm / delta_shift_clk_div.div *
611 delta_shift_clk_div.mul;
612 shift_clk_div.div = temp_lcm;
614 /* crunch shift clk numerator and denominator */
615 temp_gcd = gcd(shift_clk_div.mul, shift_clk_div.div);
616 shift_clk_div.mul /= temp_gcd;
617 shift_clk_div.div /= temp_gcd;
620 return shift_clk_div;
623 static void tegra_dsi_pix_correction(struct tegra_dc *dc,
624 struct tegra_dc_dsi_data *dsi)
631 h_width_pixels = dc->mode.h_back_porch + dc->mode.h_front_porch +
632 dc->mode.h_sync_width + dc->mode.h_active;
634 if (WARN(!dsi->info.n_data_lanes, "dsi n_data_lanes is 0\n"))
637 if (dsi->info.ganged_type == TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD) {
638 temp = dc->mode.h_active % dsi->info.n_data_lanes;
640 h_act_corr = dsi->info.n_data_lanes - temp;
641 h_width_pixels += h_act_corr;
645 temp = h_width_pixels % dsi->info.n_data_lanes;
647 hfp_corr = dsi->info.n_data_lanes - temp;
648 h_width_pixels += hfp_corr;
652 if (WARN(!dsi->pixel_scaler_div, "dsi pixel_scaler_div is 0"))
655 temp = (h_width_pixels * dsi->pixel_scaler_mul /
656 dsi->pixel_scaler_div) % dsi->info.n_data_lanes;
658 hfp_corr += dsi->info.n_data_lanes;
659 h_width_pixels += dsi->info.n_data_lanes;
664 dc->mode.h_front_porch += hfp_corr;
665 dc->mode.h_active += h_act_corr;
668 void tegra_dsi_init_clock_param(struct tegra_dc *dc)
677 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
679 switch (dsi->info.pixel_format) {
680 case TEGRA_DSI_PIXEL_FORMAT_16BIT_P:
681 /* 2 bytes per pixel */
682 dsi->pixel_scaler_mul = 2;
683 dsi->pixel_scaler_div = 1;
685 case TEGRA_DSI_PIXEL_FORMAT_18BIT_P:
686 /* 2.25 bytes per pixel */
687 dsi->pixel_scaler_mul = 9;
688 dsi->pixel_scaler_div = 4;
690 case TEGRA_DSI_PIXEL_FORMAT_18BIT_NP:
691 case TEGRA_DSI_PIXEL_FORMAT_24BIT_P:
692 /* 3 bytes per pixel */
693 dsi->pixel_scaler_mul = 3;
694 dsi->pixel_scaler_div = 1;
700 n_data_lanes = dsi->info.n_data_lanes;
701 if (dsi->info.ganged_type == TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT ||
702 dsi->info.ganged_type == TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD ||
703 dsi->info.ganged_type ==
704 TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT_OVERLAP)
707 dsi->dsi_control_val =
708 DSI_CONTROL_VIRTUAL_CHANNEL(dsi->info.virtual_channel) |
709 DSI_CONTROL_NUM_DATA_LANES(n_data_lanes - 1) |
710 DSI_CONTROL_VID_SOURCE(dc->ctrl_num) |
711 DSI_CONTROL_DATA_FORMAT(dsi->info.pixel_format);
713 if (dsi->info.ganged_type)
714 tegra_dsi_pix_correction(dc, dsi);
716 /* Below we are going to calculate dsi and dc clock rate.
717 * Calcuate the horizontal and vertical width.
719 h_width_pixels = dc->mode.h_back_porch + dc->mode.h_front_porch +
720 dc->mode.h_sync_width + dc->mode.h_active;
722 v_width_lines = dc->mode.v_back_porch + dc->mode.v_front_porch +
723 dc->mode.v_sync_width + dc->mode.v_active;
725 /* Calculate minimum required pixel rate. */
726 pixel_clk_hz = h_width_pixels * v_width_lines * dsi->info.refresh_rate;
727 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_MODE) {
728 if (dsi->info.rated_refresh_rate >= dsi->info.refresh_rate)
729 dev_info(&dc->ndev->dev, "DSI: measured refresh rate "
730 "should be larger than rated refresh rate.\n");
731 dc->mode.rated_pclk = h_width_pixels * v_width_lines *
732 dsi->info.rated_refresh_rate;
735 /* Calculate minimum byte rate on DSI interface. */
736 byte_clk_hz = (pixel_clk_hz * dsi->pixel_scaler_mul) /
737 (dsi->pixel_scaler_div * dsi->info.n_data_lanes);
739 /* Round up to multiple of mega hz. */
740 plld_clk_mhz = DIV_ROUND_UP((byte_clk_hz * NUMOF_BIT_PER_BYTE),
743 /* Calculate default real shift_clk_div. */
744 dsi->default_shift_clk_div.mul = NUMOF_BIT_PER_BYTE *
745 dsi->pixel_scaler_mul;
746 dsi->default_shift_clk_div.div = 2 * dsi->pixel_scaler_div *
747 dsi->info.n_data_lanes;
750 /* Calculate default DSI hs clock. DSI interface is double data rate.
751 * Data is transferred on both rising and falling edge of clk, div by 2
752 * to get the actual clock rate.
754 dsi->default_hs_clk_khz = plld_clk_mhz * 1000 / 2;
756 dsi->default_pixel_clk_khz = (plld_clk_mhz * 1000 *
757 dsi->default_shift_clk_div.div) /
758 (2 * dsi->default_shift_clk_div.mul);
760 /* Get the actual shift_clk_div and clock rates. */
761 dsi->shift_clk_div = tegra_dsi_get_shift_clk_div(dsi);
762 dsi->target_lp_clk_khz =
763 tegra_dsi_get_lp_clk_rate(dsi, DSI_LP_OP_WRITE);
764 dsi->target_hs_clk_khz = tegra_dsi_get_hs_clk_rate(dsi);
766 dev_info(&dc->ndev->dev, "DSI: HS clock rate is %d\n",
767 dsi->target_hs_clk_khz);
770 * Force video clock to be continuous mode if
771 * enable_hs_clock_on_lp_cmd_mode is set
773 if (dsi->info.enable_hs_clock_on_lp_cmd_mode) {
774 if (dsi->info.video_clock_mode !=
775 TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS)
776 dev_warn(&dc->ndev->dev,
777 "Force clock continuous mode\n");
779 dsi->info.video_clock_mode = TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS;
783 static void tegra_dsi_init_sw(struct tegra_dc *dc,
784 struct tegra_dc_dsi_data *dsi)
787 dsi->enabled = false;
788 dsi->clk_ref = false;
790 #if DSI_USE_SYNC_POINTS
791 dsi->syncpt_id = nvhost_get_syncpt_client_managed(dc->ndev, "dsi");
794 tegra_dsi_init_clock_param(dc);
796 atomic_set(&dsi->host_ref, 0);
797 dsi->host_suspended = false;
798 mutex_init(&dsi->host_lock);
799 init_completion(&dc->out->user_vblank_comp);
800 INIT_DELAYED_WORK(&dsi->idle_work, tegra_dc_dsi_idle_work);
801 dsi->idle_delay = msecs_to_jiffies(DSI_HOST_IDLE_PERIOD);
804 #define SELECT_T_PHY(platform_t_phy_ps, default_phy, clk_ps, hw_inc) ( \
805 (platform_t_phy_ps) ? ( \
806 ((DSI_CONVERT_T_PHY_PS_TO_T_PHY(platform_t_phy_ps, clk_ps, hw_inc)) < 0 ? 0 : \
807 (DSI_CONVERT_T_PHY_PS_TO_T_PHY(platform_t_phy_ps, clk_ps, hw_inc)))) : \
808 ((default_phy) < 0 ? 0 : (default_phy)))
810 static void tegra_dsi_get_clk_phy_timing(struct tegra_dc_dsi_data *dsi,
811 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
813 phy_timing_clk->t_tlpx = SELECT_T_PHY(
814 dsi->info.phy_timing.t_tlpx_ns * 1000,
815 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
817 phy_timing_clk->t_clktrail = SELECT_T_PHY(
818 dsi->info.phy_timing.t_clktrail_ns * 1000,
819 T_CLKTRAIL_DEFAULT(clk_ps), clk_ps, T_CLKTRAIL_HW_INC);
821 phy_timing_clk->t_clkpost = SELECT_T_PHY(
822 dsi->info.phy_timing.t_clkpost_ns * 1000,
823 T_CLKPOST_DEFAULT(clk_ps), clk_ps, T_CLKPOST_HW_INC);
825 phy_timing_clk->t_clkzero = SELECT_T_PHY(
826 dsi->info.phy_timing.t_clkzero_ns * 1000,
827 T_CLKZERO_DEFAULT(clk_ps), clk_ps, T_CLKZERO_HW_INC);
829 phy_timing_clk->t_clkprepare = SELECT_T_PHY(
830 dsi->info.phy_timing.t_clkprepare_ns * 1000,
831 T_CLKPREPARE_DEFAULT(clk_ps), clk_ps, T_CLKPREPARE_HW_INC);
833 phy_timing_clk->t_clkpre = SELECT_T_PHY(
834 dsi->info.phy_timing.t_clkpre_ns * 1000,
835 T_CLKPRE_DEFAULT, clk_ps, T_CLKPRE_HW_INC);
838 static void tegra_dsi_get_hs_phy_timing(struct tegra_dc_dsi_data *dsi,
839 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
841 phy_timing_clk->t_tlpx = SELECT_T_PHY(
842 dsi->info.phy_timing.t_tlpx_ns * 1000,
843 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
845 phy_timing_clk->t_hsdexit = SELECT_T_PHY(
846 dsi->info.phy_timing.t_hsdexit_ns * 1000,
847 T_HSEXIT_DEFAULT(clk_ps), clk_ps, T_HSEXIT_HW_INC);
849 phy_timing_clk->t_hstrail = SELECT_T_PHY(
850 dsi->info.phy_timing.t_hstrail_ns * 1000,
851 T_HSTRAIL_DEFAULT(clk_ps), clk_ps, T_HSTRAIL_HW_INC);
853 phy_timing_clk->t_datzero = SELECT_T_PHY(
854 dsi->info.phy_timing.t_datzero_ns * 1000,
855 T_DATZERO_DEFAULT(clk_ps), clk_ps, T_DATZERO_HW_INC);
857 phy_timing_clk->t_hsprepare = SELECT_T_PHY(
858 dsi->info.phy_timing.t_hsprepare_ns * 1000,
859 T_HSPREPARE_DEFAULT(clk_ps), clk_ps, T_HSPREPARE_HW_INC);
862 static void tegra_dsi_get_escape_phy_timing(struct tegra_dc_dsi_data *dsi,
863 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
865 phy_timing_clk->t_tlpx = SELECT_T_PHY(
866 dsi->info.phy_timing.t_tlpx_ns * 1000,
867 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
870 static void tegra_dsi_get_bta_phy_timing(struct tegra_dc_dsi_data *dsi,
871 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
873 phy_timing_clk->t_tlpx = SELECT_T_PHY(
874 dsi->info.phy_timing.t_tlpx_ns * 1000,
875 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
877 phy_timing_clk->t_taget = SELECT_T_PHY(
878 dsi->info.phy_timing.t_taget_ns * 1000,
879 T_TAGET_DEFAULT(clk_ps), clk_ps, T_TAGET_HW_INC);
881 phy_timing_clk->t_tasure = SELECT_T_PHY(
882 dsi->info.phy_timing.t_tasure_ns * 1000,
883 T_TASURE_DEFAULT(clk_ps), clk_ps, T_TASURE_HW_INC);
885 phy_timing_clk->t_tago = SELECT_T_PHY(
886 dsi->info.phy_timing.t_tago_ns * 1000,
887 T_TAGO_DEFAULT(clk_ps), clk_ps, T_TAGO_HW_INC);
890 static void tegra_dsi_get_ulps_phy_timing(struct tegra_dc_dsi_data *dsi,
891 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
893 phy_timing_clk->t_tlpx = SELECT_T_PHY(
894 dsi->info.phy_timing.t_tlpx_ns * 1000,
895 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
897 phy_timing_clk->t_wakeup = SELECT_T_PHY(
898 dsi->info.phy_timing.t_wakeup_ns * 1000,
899 T_WAKEUP_DEFAULT, clk_ps, T_WAKEUP_HW_INC);
904 static void tegra_dsi_get_phy_timing(struct tegra_dc_dsi_data *dsi,
905 struct dsi_phy_timing_inclk *phy_timing_clk,
908 if (tegra_platform_is_fpga()) {
909 clk_ps = (1000 * 1000 * 1000) / (dsi->info.fpga_freq_khz ?
910 dsi->info.fpga_freq_khz : DEFAULT_FPGA_FREQ_KHZ);
913 if (lphs == DSI_LPHS_IN_HS_MODE) {
914 tegra_dsi_get_clk_phy_timing(dsi, phy_timing_clk, clk_ps);
915 tegra_dsi_get_hs_phy_timing(dsi, phy_timing_clk, clk_ps);
917 /* default is LP mode */
918 tegra_dsi_get_escape_phy_timing(dsi, phy_timing_clk, clk_ps);
919 tegra_dsi_get_bta_phy_timing(dsi, phy_timing_clk, clk_ps);
920 tegra_dsi_get_ulps_phy_timing(dsi, phy_timing_clk, clk_ps);
921 if (dsi->info.enable_hs_clock_on_lp_cmd_mode)
922 tegra_dsi_get_clk_phy_timing(dsi,
923 phy_timing_clk, clk_ps);
927 static int tegra_dsi_mipi_phy_timing_range(struct tegra_dc_dsi_data *dsi,
928 struct dsi_phy_timing_inclk *phy_timing,
933 #define CHECK_RANGE(val, min, max) ( \
934 ((min) == NOT_DEFINED ? 0 : (val) < (min)) || \
935 ((max) == NOT_DEFINED ? 0 : (val) > (max)) ? -EINVAL : 0)
937 if (tegra_platform_is_fpga())
938 clk_ps = dsi->info.fpga_freq_khz ?
939 ((1000 * 1000 * 1000) / dsi->info.fpga_freq_khz) :
940 DEFAULT_FPGA_FREQ_KHZ;
943 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
944 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC),
945 MIPI_T_TLPX_PS_MIN, MIPI_T_TLPX_PS_MAX);
947 dev_warn(&dsi->dc->ndev->dev,
948 "dsi: Tlpx mipi range violated\n");
952 if (lphs == DSI_LPHS_IN_HS_MODE) {
954 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
955 phy_timing->t_hsdexit, clk_ps, T_HSEXIT_HW_INC),
956 MIPI_T_HSEXIT_PS_MIN, MIPI_T_HSEXIT_PS_MAX);
958 dev_warn(&dsi->dc->ndev->dev,
959 "dsi: HsExit mipi range violated\n");
964 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
965 phy_timing->t_hstrail, clk_ps, T_HSTRAIL_HW_INC),
966 MIPI_T_HSTRAIL_PS_MIN(clk_ps), MIPI_T_HSTRAIL_PS_MAX);
968 dev_warn(&dsi->dc->ndev->dev,
969 "dsi: HsTrail mipi range violated\n");
974 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
975 phy_timing->t_datzero, clk_ps, T_DATZERO_HW_INC),
976 MIPI_T_HSZERO_PS_MIN, MIPI_T_HSZERO_PS_MAX);
978 dev_warn(&dsi->dc->ndev->dev,
979 "dsi: HsZero mipi range violated\n");
984 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
985 phy_timing->t_hsprepare, clk_ps, T_HSPREPARE_HW_INC),
986 MIPI_T_HSPREPARE_PS_MIN(clk_ps),
987 MIPI_T_HSPREPARE_PS_MAX(clk_ps));
989 dev_warn(&dsi->dc->ndev->dev,
990 "dsi: HsPrepare mipi range violated\n");
995 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
996 phy_timing->t_hsprepare, clk_ps, T_HSPREPARE_HW_INC) +
997 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
998 phy_timing->t_datzero, clk_ps, T_DATZERO_HW_INC),
999 MIPI_T_HSPREPARE_ADD_HSZERO_PS_MIN(clk_ps),
1000 MIPI_T_HSPREPARE_ADD_HSZERO_PS_MAX);
1002 dev_warn(&dsi->dc->ndev->dev,
1003 "dsi: HsPrepare + HsZero mipi range violated\n");
1007 /* default is LP mode */
1009 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1010 phy_timing->t_wakeup, clk_ps, T_WAKEUP_HW_INC),
1011 MIPI_T_WAKEUP_PS_MIN, MIPI_T_WAKEUP_PS_MAX);
1013 dev_warn(&dsi->dc->ndev->dev,
1014 "dsi: WakeUp mipi range violated\n");
1019 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1020 phy_timing->t_tasure, clk_ps, T_TASURE_HW_INC),
1021 MIPI_T_TASURE_PS_MIN(DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1022 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC)),
1023 MIPI_T_TASURE_PS_MAX(DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1024 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC)));
1026 dev_warn(&dsi->dc->ndev->dev,
1027 "dsi: TaSure mipi range violated\n");
1032 if (lphs == DSI_LPHS_IN_HS_MODE ||
1033 dsi->info.enable_hs_clock_on_lp_cmd_mode) {
1035 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1036 phy_timing->t_clktrail, clk_ps, T_CLKTRAIL_HW_INC),
1037 MIPI_T_CLKTRAIL_PS_MIN, MIPI_T_CLKTRAIL_PS_MAX);
1039 dev_warn(&dsi->dc->ndev->dev,
1040 "dsi: ClkTrail mipi range violated\n");
1045 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1046 phy_timing->t_clkpost, clk_ps, T_CLKPOST_HW_INC),
1047 MIPI_T_CLKPOST_PS_MIN(clk_ps), MIPI_T_CLKPOST_PS_MAX);
1049 dev_warn(&dsi->dc->ndev->dev,
1050 "dsi: ClkPost mipi range violated\n");
1055 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1056 phy_timing->t_clkzero, clk_ps, T_CLKZERO_HW_INC),
1057 MIPI_T_CLKZERO_PS_MIN, MIPI_T_CLKZERO_PS_MAX);
1059 dev_warn(&dsi->dc->ndev->dev,
1060 "dsi: ClkZero mipi range violated\n");
1065 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1066 phy_timing->t_clkprepare, clk_ps, T_CLKPREPARE_HW_INC),
1067 MIPI_T_CLKPREPARE_PS_MIN, MIPI_T_CLKPREPARE_PS_MAX);
1069 dev_warn(&dsi->dc->ndev->dev,
1070 "dsi: ClkPrepare mipi range violated\n");
1075 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1076 phy_timing->t_clkpre, clk_ps, T_CLKPRE_HW_INC),
1077 MIPI_T_CLKPRE_PS_MIN, MIPI_T_CLKPRE_PS_MAX);
1079 dev_warn(&dsi->dc->ndev->dev,
1080 "dsi: ClkPre mipi range violated\n");
1085 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1086 phy_timing->t_clkprepare, clk_ps, T_CLKPREPARE_HW_INC) +
1087 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1088 phy_timing->t_clkzero, clk_ps, T_CLKZERO_HW_INC),
1089 MIPI_T_CLKPREPARE_ADD_CLKZERO_PS_MIN,
1090 MIPI_T_CLKPREPARE_ADD_CLKZERO_PS_MAX);
1092 dev_warn(&dsi->dc->ndev->dev,
1093 "dsi: ClkPrepare + ClkZero mipi range violated\n");
1102 static int tegra_dsi_hs_phy_len(struct tegra_dc_dsi_data *dsi,
1103 struct dsi_phy_timing_inclk *phy_timing,
1104 u32 clk_ps, u8 lphs)
1106 u32 hs_t_phy_ps = 0;
1107 u32 clk_t_phy_ps = 0;
1110 struct tegra_dc_mode *modes;
1114 if (!(lphs == DSI_LPHS_IN_HS_MODE))
1117 if (dsi->info.video_data_type ==
1118 TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE &&
1119 dsi->info.video_burst_mode <=
1120 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END)
1123 modes = dsi->dc->out->modes;
1124 t_pix_ps = clk_ps * BITS_PER_BYTE *
1125 dsi->pixel_scaler_mul / dsi->pixel_scaler_div;
1128 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1129 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC) +
1130 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1131 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC) +
1132 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1133 phy_timing->t_hsprepare, clk_ps, T_HSPREPARE_HW_INC) +
1134 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1135 phy_timing->t_datzero, clk_ps, T_DATZERO_HW_INC) +
1136 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1137 phy_timing->t_hstrail, clk_ps, T_HSTRAIL_HW_INC) +
1138 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1139 phy_timing->t_hsdexit, clk_ps, T_HSEXIT_HW_INC);
1141 if (dsi->info.video_clock_mode == TEGRA_DSI_VIDEO_CLOCK_TX_ONLY) {
1143 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1144 phy_timing->t_clkpost, clk_ps, T_CLKPOST_HW_INC) +
1145 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1146 phy_timing->t_clktrail, clk_ps, T_CLKTRAIL_HW_INC) +
1147 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1148 phy_timing->t_hsdexit, clk_ps, T_HSEXIT_HW_INC) +
1149 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1150 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC) +
1151 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1152 phy_timing->t_clkprepare, clk_ps, T_CLKPREPARE_HW_INC) +
1153 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1154 phy_timing->t_clkzero, clk_ps, T_CLKZERO_HW_INC) +
1155 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1156 phy_timing->t_clkpre, clk_ps, T_CLKPRE_HW_INC);
1158 /* clk_pre overlaps LP-11 hs mode start sequence */
1159 hs_t_phy_ps -= DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1160 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC);
1163 h_blank_ps = t_pix_ps * (modes->h_sync_width + modes->h_back_porch +
1164 modes->h_front_porch);
1166 /* Extra tlpx and byte cycle required by dsi HW */
1167 t_phy_ps = dsi->info.n_data_lanes * (hs_t_phy_ps + clk_t_phy_ps +
1168 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1169 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC) +
1170 clk_ps * BITS_PER_BYTE);
1172 if (h_blank_ps < t_phy_ps) {
1174 dev_WARN(&dsi->dc->ndev->dev,
1175 "dsi: Hblank is smaller than HS phy timing: %u pix\n",
1176 (t_phy_ps - h_blank_ps) / t_pix_ps);
1185 static int tegra_dsi_constraint_phy_timing(struct tegra_dc_dsi_data *dsi,
1186 struct dsi_phy_timing_inclk *phy_timing,
1187 u32 clk_ps, u8 lphs)
1191 err = tegra_dsi_mipi_phy_timing_range(dsi, phy_timing, clk_ps, lphs);
1193 dev_warn(&dsi->dc->ndev->dev, "dsi: mipi range violated\n");
1197 err = tegra_dsi_hs_phy_len(dsi, phy_timing, clk_ps, lphs);
1199 dev_err(&dsi->dc->ndev->dev, "dsi: Hblank too short\n");
1203 /* TODO: add more contraints */
1208 static void tegra_dsi_set_phy_timing(struct tegra_dc_dsi_data *dsi, u8 lphs)
1211 struct dsi_phy_timing_inclk phy_timing = dsi->phy_timing;
1213 tegra_dsi_get_phy_timing
1214 (dsi, &phy_timing, dsi->current_bit_clk_ps, lphs);
1216 tegra_dsi_constraint_phy_timing(dsi, &phy_timing,
1217 dsi->current_bit_clk_ps, lphs);
1219 if (tegra_platform_is_fpga() && dsi->info.ganged_type) {
1220 phy_timing.t_hsdexit += T_HSEXIT_HW_INC;
1221 phy_timing.t_hstrail += T_HSTRAIL_HW_INC + 3;
1222 phy_timing.t_datzero += T_DATZERO_HW_INC;
1223 phy_timing.t_hsprepare += T_HSPREPARE_HW_INC;
1225 phy_timing.t_clktrail += T_CLKTRAIL_HW_INC;
1226 phy_timing.t_clkpost += T_CLKPOST_HW_INC;
1227 phy_timing.t_clkzero += T_CLKZERO_HW_INC;
1228 phy_timing.t_tlpx += T_TLPX_HW_INC;
1230 phy_timing.t_clkprepare += T_CLKPREPARE_HW_INC;
1231 phy_timing.t_clkpre += T_CLKPRE_HW_INC;
1232 phy_timing.t_wakeup += T_WAKEUP_HW_INC;
1234 phy_timing.t_taget += T_TAGET_HW_INC;
1235 phy_timing.t_tasure += T_TASURE_HW_INC;
1236 phy_timing.t_tago += T_TAGO_HW_INC;
1238 val = DSI_PHY_TIMING_0_THSDEXIT(phy_timing.t_hsdexit) |
1239 DSI_PHY_TIMING_0_THSTRAIL(phy_timing.t_hstrail) |
1240 DSI_PHY_TIMING_0_TDATZERO(phy_timing.t_datzero) |
1241 DSI_PHY_TIMING_0_THSPREPR(phy_timing.t_hsprepare);
1242 tegra_dsi_writel(dsi, val, DSI_PHY_TIMING_0);
1244 val = DSI_PHY_TIMING_1_TCLKTRAIL(phy_timing.t_clktrail) |
1245 DSI_PHY_TIMING_1_TCLKPOST(phy_timing.t_clkpost) |
1246 DSI_PHY_TIMING_1_TCLKZERO(phy_timing.t_clkzero) |
1247 DSI_PHY_TIMING_1_TTLPX(phy_timing.t_tlpx);
1248 tegra_dsi_writel(dsi, val, DSI_PHY_TIMING_1);
1250 val = DSI_PHY_TIMING_2_TCLKPREPARE(phy_timing.t_clkprepare) |
1251 DSI_PHY_TIMING_2_TCLKPRE(phy_timing.t_clkpre) |
1252 DSI_PHY_TIMING_2_TWAKEUP(phy_timing.t_wakeup);
1253 tegra_dsi_writel(dsi, val, DSI_PHY_TIMING_2);
1255 val = DSI_BTA_TIMING_TTAGET(phy_timing.t_taget) |
1256 DSI_BTA_TIMING_TTASURE(phy_timing.t_tasure) |
1257 DSI_BTA_TIMING_TTAGO(phy_timing.t_tago);
1258 tegra_dsi_writel(dsi, val, DSI_BTA_TIMING);
1260 dsi->phy_timing = phy_timing;
1263 static u32 tegra_dsi_sol_delay_burst(struct tegra_dc *dc,
1264 struct tegra_dc_dsi_data *dsi)
1266 u32 dsi_to_pixel_clk_ratio;
1269 u32 mipi_clk_adj_kHz = 0;
1271 struct tegra_dc_mode *dc_modes = &dc->mode;
1273 /* Get Fdsi/Fpixel ration (note: Fdsi is in bit format) */
1274 dsi_to_pixel_clk_ratio = (dsi->current_dsi_clk_khz * 2 +
1275 dsi->default_pixel_clk_khz - 1) / dsi->default_pixel_clk_khz;
1277 /* Convert Fdsi to byte format */
1278 dsi_to_pixel_clk_ratio *= 1000/8;
1280 /* Multiplying by 1000 so that we don't loose the fraction part */
1281 temp = dc_modes->h_active * 1000;
1282 temp1 = dc_modes->h_active + dc_modes->h_back_porch +
1283 dc_modes->h_sync_width;
1285 sol_delay = temp1 * dsi_to_pixel_clk_ratio -
1286 temp * dsi->pixel_scaler_mul /
1287 (dsi->pixel_scaler_div * dsi->info.n_data_lanes);
1289 /* Do rounding on sol delay */
1290 sol_delay = (sol_delay + 1000 - 1)/1000;
1293 * 1. find out the correct sol fifo depth to use
1294 * 2. verify with hw about the clamping function
1296 if (sol_delay > (480 * 4)) {
1297 sol_delay = (480 * 4);
1298 mipi_clk_adj_kHz = sol_delay +
1299 (dc_modes->h_active * dsi->pixel_scaler_mul) /
1300 (dsi->info.n_data_lanes * dsi->pixel_scaler_div);
1302 mipi_clk_adj_kHz *= (dsi->default_pixel_clk_khz / temp1);
1304 mipi_clk_adj_kHz *= 4;
1307 dsi->target_hs_clk_khz = mipi_clk_adj_kHz;
1312 static void tegra_dsi_set_sol_delay(struct tegra_dc *dc,
1313 struct tegra_dc_dsi_data *dsi)
1317 u32 h_width_byte_clk;
1319 u32 h_width_ganged_byte_clk;
1320 u8 n_data_lanes_this_cont = 0;
1321 u8 n_data_lanes_ganged = 0;
1323 if (!(dsi->info.ganged_type)) {
1324 if (dsi->info.video_burst_mode ==
1325 TEGRA_DSI_VIDEO_NONE_BURST_MODE ||
1326 dsi->info.video_burst_mode ==
1327 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END) {
1328 #define VIDEO_FIFO_LATENCY_PIXEL_CLK 8
1329 sol_delay = VIDEO_FIFO_LATENCY_PIXEL_CLK *
1330 dsi->pixel_scaler_mul / dsi->pixel_scaler_div;
1331 #undef VIDEO_FIFO_LATENCY_PIXEL_CLK
1332 dsi->status.clk_burst = DSI_CLK_BURST_NONE_BURST;
1334 sol_delay = tegra_dsi_sol_delay_burst(dc, dsi);
1335 dsi->status.clk_burst = DSI_CLK_BURST_BURST_MODE;
1338 #define SOL_TO_VALID_PIX_CLK_DELAY 4
1339 #define VALID_TO_FIFO_PIX_CLK_DELAY 4
1340 #define FIFO_WR_PIX_CLK_DELAY 2
1341 #define FIFO_RD_BYTE_CLK_DELAY 6
1342 #define TOT_INTERNAL_PIX_DELAY (SOL_TO_VALID_PIX_CLK_DELAY + \
1343 VALID_TO_FIFO_PIX_CLK_DELAY + \
1344 FIFO_WR_PIX_CLK_DELAY)
1346 internal_delay = DIV_ROUND_UP(
1347 TOT_INTERNAL_PIX_DELAY * dsi->pixel_scaler_mul,
1348 dsi->pixel_scaler_div * dsi->info.n_data_lanes)
1349 + FIFO_RD_BYTE_CLK_DELAY;
1351 h_width_pixels = dc->mode.h_sync_width +
1352 dc->mode.h_back_porch +
1354 dc->mode.h_front_porch;
1356 h_width_byte_clk = DIV_ROUND_UP(h_width_pixels *
1357 dsi->pixel_scaler_mul,
1358 dsi->pixel_scaler_div *
1359 dsi->info.n_data_lanes);
1361 if (dsi->info.ganged_type ==
1362 TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT ||
1363 dsi->info.ganged_type ==
1364 TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD ||
1365 dsi->info.ganged_type ==
1366 TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT_OVERLAP) {
1367 n_data_lanes_this_cont = dsi->info.n_data_lanes / 2;
1368 n_data_lanes_ganged = dsi->info.n_data_lanes;
1371 h_width_ganged_byte_clk = DIV_ROUND_UP(
1372 n_data_lanes_this_cont *
1374 n_data_lanes_ganged);
1376 sol_delay = h_width_byte_clk - h_width_ganged_byte_clk +
1378 sol_delay = (dsi->info.video_data_type ==
1379 TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE) ?
1380 sol_delay + 20 : sol_delay;
1382 #undef SOL_TO_VALID_PIX_CLK_DELAY
1383 #undef VALID_TO_FIFO_PIX_CLK_DELAY
1384 #undef FIFO_WR_PIX_CLK_DELAY
1385 #undef FIFO_RD_BYTE_CLK_DELAY
1386 #undef TOT_INTERNAL_PIX_DELAY
1389 tegra_dsi_writel(dsi, DSI_SOL_DELAY_SOL_DELAY(sol_delay),
1393 static void tegra_dsi_set_timeout(struct tegra_dc_dsi_data *dsi)
1396 u32 bytes_per_frame;
1399 /* TODO: verify the following equation */
1400 bytes_per_frame = dsi->current_dsi_clk_khz * 1000 * 2 /
1401 (dsi->info.refresh_rate * 8);
1402 timeout = bytes_per_frame / DSI_CYCLE_COUNTER_VALUE;
1403 timeout = (timeout + DSI_HTX_TO_MARGIN) & 0xffff;
1405 val = DSI_TIMEOUT_0_LRXH_TO(DSI_LRXH_TO_VALUE) |
1406 DSI_TIMEOUT_0_HTX_TO(timeout);
1407 tegra_dsi_writel(dsi, val, DSI_TIMEOUT_0);
1409 if (dsi->info.panel_reset_timeout_msec)
1410 timeout = (dsi->info.panel_reset_timeout_msec * 1000 * 1000 *
1411 1000) / dsi->current_bit_clk_ps;
1413 timeout = DSI_PR_TO_VALUE;
1415 val = DSI_TIMEOUT_1_PR_TO(timeout) |
1416 DSI_TIMEOUT_1_TA_TO(DSI_TA_TO_VALUE);
1417 tegra_dsi_writel(dsi, val, DSI_TIMEOUT_1);
1419 val = DSI_TO_TALLY_P_RESET_STATUS(IN_RESET) |
1420 DSI_TO_TALLY_TA_TALLY(DSI_TA_TALLY_VALUE)|
1421 DSI_TO_TALLY_LRXH_TALLY(DSI_LRXH_TALLY_VALUE)|
1422 DSI_TO_TALLY_HTX_TALLY(DSI_HTX_TALLY_VALUE);
1423 tegra_dsi_writel(dsi, val, DSI_TO_TALLY);
1426 static void tegra_dsi_setup_ganged_mode_pkt_length(struct tegra_dc *dc,
1427 struct tegra_dc_dsi_data *dsi)
1429 u32 hact_pkt_len_pix_orig = dc->mode.h_active;
1430 u32 hact_pkt_len_pix = 0;
1431 u32 hact_pkt_len_bytes = 0;
1432 u32 hfp_pkt_len_bytes = 0;
1433 u32 pix_per_line_orig = 0;
1434 u32 pix_per_line = 0;
1438 /* hsync + hact + hfp = (4) + (4+2) + (4+2) */
1439 #define HEADER_OVERHEAD 16
1441 pix_per_line_orig = dc->mode.h_sync_width + dc->mode.h_back_porch +
1442 dc->mode.h_active + dc->mode.h_front_porch;
1444 val = DSI_PKT_LEN_0_1_LENGTH_0(0) |
1445 DSI_PKT_LEN_0_1_LENGTH_1(0);
1446 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_0_1);
1448 switch (dsi->info.ganged_type) {
1449 case TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT: /* fall through */
1450 case TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD: /* fall through */
1451 hact_pkt_len_pix = DIV_ROUND_UP(hact_pkt_len_pix_orig, 2);
1452 pix_per_line = DIV_ROUND_UP(pix_per_line_orig, 2);
1454 case TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT_OVERLAP:
1455 hact_pkt_len_pix = DIV_ROUND_UP(hact_pkt_len_pix_orig, 2) +
1456 dsi->info.ganged_overlap;
1457 pix_per_line = DIV_ROUND_UP(pix_per_line_orig, 2);
1460 dev_err(&dc->ndev->dev, "dsi: invalid ganged type\n");
1463 for (i = 0; i < dsi->max_instances; i++) {
1464 hact_pkt_len_bytes = hact_pkt_len_pix *
1465 dsi->pixel_scaler_mul / dsi->pixel_scaler_div;
1466 hfp_pkt_len_bytes = pix_per_line *
1467 dsi->pixel_scaler_mul / dsi->pixel_scaler_div -
1468 hact_pkt_len_bytes - HEADER_OVERHEAD;
1470 val = DSI_PKT_LEN_2_3_LENGTH_2(0x0) |
1471 DSI_PKT_LEN_2_3_LENGTH_3(hact_pkt_len_bytes);
1472 tegra_dsi_controller_writel(dsi, val, DSI_PKT_LEN_2_3, i);
1474 val = DSI_PKT_LEN_4_5_LENGTH_4(hfp_pkt_len_bytes) |
1475 DSI_PKT_LEN_4_5_LENGTH_5(0);
1476 tegra_dsi_controller_writel(dsi, val, DSI_PKT_LEN_4_5, i);
1478 if (dsi->info.ganged_type !=
1479 TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT_OVERLAP) {
1481 hact_pkt_len_pix_orig - hact_pkt_len_pix;
1482 pix_per_line = pix_per_line_orig - pix_per_line;
1486 val = DSI_PKT_LEN_6_7_LENGTH_6(0) |
1487 DSI_PKT_LEN_6_7_LENGTH_7(0x0f0f);
1488 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_6_7);
1490 #undef HEADER_OVERHEAD
1493 static void tegra_dsi_setup_video_mode_pkt_length(struct tegra_dc *dc,
1494 struct tegra_dc_dsi_data *dsi)
1502 hact_pkt_len = dc->mode.h_active * dsi->pixel_scaler_mul /
1503 dsi->pixel_scaler_div;
1504 hsa_pkt_len = dc->mode.h_sync_width * dsi->pixel_scaler_mul /
1505 dsi->pixel_scaler_div;
1506 hbp_pkt_len = dc->mode.h_back_porch * dsi->pixel_scaler_mul /
1507 dsi->pixel_scaler_div;
1508 hfp_pkt_len = dc->mode.h_front_porch * dsi->pixel_scaler_mul /
1509 dsi->pixel_scaler_div;
1511 if (dsi->info.video_burst_mode !=
1512 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END)
1513 hbp_pkt_len += hsa_pkt_len;
1515 hsa_pkt_len -= DSI_HSYNC_BLNK_PKT_OVERHEAD;
1516 hbp_pkt_len -= DSI_HBACK_PORCH_PKT_OVERHEAD;
1517 hfp_pkt_len -= DSI_HFRONT_PORCH_PKT_OVERHEAD;
1519 val = DSI_PKT_LEN_0_1_LENGTH_0(0) |
1520 DSI_PKT_LEN_0_1_LENGTH_1(hsa_pkt_len);
1521 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_0_1);
1523 val = DSI_PKT_LEN_2_3_LENGTH_2(hbp_pkt_len) |
1524 DSI_PKT_LEN_2_3_LENGTH_3(hact_pkt_len);
1525 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_2_3);
1527 val = DSI_PKT_LEN_4_5_LENGTH_4(hfp_pkt_len) |
1528 DSI_PKT_LEN_4_5_LENGTH_5(0);
1529 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_4_5);
1531 val = DSI_PKT_LEN_6_7_LENGTH_6(0) | DSI_PKT_LEN_6_7_LENGTH_7(0x0f0f);
1532 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_6_7);
1535 static void tegra_dsi_setup_cmd_mode_pkt_length(struct tegra_dc *dc,
1536 struct tegra_dc_dsi_data *dsi)
1539 unsigned long act_bytes;
1541 if (dsi->info.ganged_type) {
1542 act_bytes = DIV_ROUND_UP(dc->mode.h_active, 2);
1543 act_bytes = (act_bytes) * dsi->pixel_scaler_mul /
1544 dsi->pixel_scaler_div + 1;
1546 act_bytes = dc->mode.h_active * dsi->pixel_scaler_mul /
1547 dsi->pixel_scaler_div + 1;
1549 val = DSI_PKT_LEN_0_1_LENGTH_0(0) | DSI_PKT_LEN_0_1_LENGTH_1(0);
1550 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_0_1);
1552 val = DSI_PKT_LEN_2_3_LENGTH_2(0) | DSI_PKT_LEN_2_3_LENGTH_3(act_bytes);
1553 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_2_3);
1555 val = DSI_PKT_LEN_4_5_LENGTH_4(0) | DSI_PKT_LEN_4_5_LENGTH_5(act_bytes);
1556 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_4_5);
1558 val = DSI_PKT_LEN_6_7_LENGTH_6(0) | DSI_PKT_LEN_6_7_LENGTH_7(0x0f0f);
1559 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_6_7);
1562 static void tegra_dsi_set_pkt_length(struct tegra_dc *dc,
1563 struct tegra_dc_dsi_data *dsi)
1565 if (dsi->driven_mode == TEGRA_DSI_DRIVEN_BY_HOST)
1568 if (dsi->info.video_data_type == TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE) {
1569 if (dsi->info.ganged_type)
1570 tegra_dsi_setup_ganged_mode_pkt_length(dc, dsi);
1572 tegra_dsi_setup_video_mode_pkt_length(dc, dsi);
1574 tegra_dsi_setup_cmd_mode_pkt_length(dc, dsi);
1578 static void tegra_dsi_set_pkt_seq(struct tegra_dc *dc,
1579 struct tegra_dc_dsi_data *dsi)
1583 u32 pkt_seq_3_5_rgb_lo;
1584 u32 pkt_seq_3_5_rgb_hi;
1589 if (dsi->driven_mode == TEGRA_DSI_DRIVEN_BY_HOST)
1592 switch (dsi->info.pixel_format) {
1593 case TEGRA_DSI_PIXEL_FORMAT_16BIT_P:
1594 rgb_info = CMD_RGB_16BPP;
1596 case TEGRA_DSI_PIXEL_FORMAT_18BIT_P:
1597 rgb_info = CMD_RGB_18BPP;
1599 case TEGRA_DSI_PIXEL_FORMAT_18BIT_NP:
1600 rgb_info = CMD_RGB_18BPPNP;
1602 case TEGRA_DSI_PIXEL_FORMAT_24BIT_P:
1604 rgb_info = CMD_RGB_24BPP;
1608 pkt_seq_3_5_rgb_lo = 0;
1609 pkt_seq_3_5_rgb_hi = 0;
1610 if (dsi->info.pkt_seq)
1611 pkt_seq = dsi->info.pkt_seq;
1612 else if (dsi->info.video_data_type ==
1613 TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE) {
1614 pkt_seq = dsi_pkt_seq_cmd_mode;
1616 switch (dsi->info.video_burst_mode) {
1617 case TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED:
1618 case TEGRA_DSI_VIDEO_BURST_MODE_LOW_SPEED:
1619 case TEGRA_DSI_VIDEO_BURST_MODE_MEDIUM_SPEED:
1620 case TEGRA_DSI_VIDEO_BURST_MODE_FAST_SPEED:
1621 case TEGRA_DSI_VIDEO_BURST_MODE_FASTEST_SPEED:
1622 pkt_seq_3_5_rgb_lo =
1623 DSI_PKT_SEQ_3_LO_PKT_32_ID(rgb_info);
1624 if (!dsi->info.no_pkt_seq_eot)
1625 pkt_seq = dsi_pkt_seq_video_burst;
1627 pkt_seq = dsi_pkt_seq_video_burst_no_eot;
1629 case TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END:
1630 pkt_seq_3_5_rgb_hi =
1631 DSI_PKT_SEQ_3_HI_PKT_34_ID(rgb_info);
1632 pkt_seq = dsi_pkt_seq_video_non_burst_syne;
1634 case TEGRA_DSI_VIDEO_NONE_BURST_MODE:
1636 if (dsi->info.ganged_type) {
1637 pkt_seq_3_5_rgb_lo =
1638 DSI_PKT_SEQ_3_LO_PKT_31_ID(rgb_info);
1640 dsi_pkt_seq_video_non_burst_no_eot_no_lp_no_hbp;
1642 pkt_seq_3_5_rgb_lo =
1643 DSI_PKT_SEQ_3_LO_PKT_32_ID(rgb_info);
1644 pkt_seq = dsi_pkt_seq_video_non_burst;
1647 /* Simulator does not support EOT packet yet */
1648 if (tegra_cpu_is_asim())
1649 pkt_seq = dsi_pkt_seq_video_non_burst_no_eot;
1654 for (i = 0; i < NUMOF_PKT_SEQ; i++) {
1656 reg = dsi_pkt_seq_reg[i];
1657 if ((reg == DSI_PKT_SEQ_3_LO) || (reg == DSI_PKT_SEQ_5_LO))
1658 val |= pkt_seq_3_5_rgb_lo;
1659 if ((reg == DSI_PKT_SEQ_3_HI) || (reg == DSI_PKT_SEQ_5_HI))
1660 val |= pkt_seq_3_5_rgb_hi;
1661 tegra_dsi_writel(dsi, val, reg);
1665 static void tegra_dsi_reset_underflow_overflow
1666 (struct tegra_dc_dsi_data *dsi)
1670 val = tegra_dsi_readl(dsi, DSI_STATUS);
1671 val &= (DSI_STATUS_LB_OVERFLOW(0x1) | DSI_STATUS_LB_UNDERFLOW(0x1));
1673 if (val & DSI_STATUS_LB_OVERFLOW(0x1))
1674 dev_warn(&dsi->dc->ndev->dev,
1675 "dsi: video fifo overflow. Resetting flag\n");
1676 if (val & DSI_STATUS_LB_UNDERFLOW(0x1))
1677 dev_warn(&dsi->dc->ndev->dev,
1678 "dsi: video fifo underflow. Resetting flag\n");
1679 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
1680 val |= DSI_HOST_CONTROL_FIFO_STAT_RESET(0x1);
1681 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
1686 static void tegra_dsi_soft_reset(struct tegra_dc_dsi_data *dsi)
1690 u32 frame_period = DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
1691 struct tegra_dc_mode mode = dsi->dc->mode;
1692 u32 tot_lines = mode.v_sync_width + mode.v_back_porch +
1693 mode.v_active + mode.v_front_porch;
1694 u32 line_period = DIV_ROUND_UP(MS_TO_US(frame_period), tot_lines);
1695 u32 timeout_cnt = 0;
1697 /* wait for 1 frame duration + few extra cycles for dsi to go idle */
1698 #define DSI_IDLE_TIMEOUT (tot_lines + 5)
1700 val = tegra_dsi_readl(dsi, DSI_STATUS);
1701 while (!(val & DSI_STATUS_IDLE(0x1))) {
1703 udelay(line_period);
1704 val = tegra_dsi_readl(dsi, DSI_STATUS);
1705 if (timeout_cnt++ > DSI_IDLE_TIMEOUT) {
1706 dev_warn(&dsi->dc->ndev->dev, "dsi not idle when soft reset\n");
1711 tegra_dsi_writel(dsi,
1712 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE),
1714 /* stabilization delay */
1717 tegra_dsi_writel(dsi,
1718 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_ENABLE),
1720 /* stabilization delay */
1723 /* dsi HW does not clear host trigger bit automatically
1724 * on dsi interface disable if host fifo is empty or in mid
1725 * of host transmission
1727 trigger = tegra_dsi_readl(dsi, DSI_TRIGGER);
1729 tegra_dsi_writel(dsi, 0x0, DSI_TRIGGER);
1731 #undef DSI_IDLE_TIMEOUT
1734 static void tegra_dsi_stop_dc_stream(struct tegra_dc *dc,
1735 struct tegra_dc_dsi_data *dsi)
1739 tegra_dc_writel(dc, DISP_CTRL_MODE_STOP, DC_CMD_DISPLAY_COMMAND);
1740 tegra_dc_writel(dc, 0, DC_DISP_DISP_WIN_OPTIONS);
1741 tegra_dc_writel(dc, GENERAL_ACT_REQ , DC_CMD_STATE_CONTROL);
1743 /* stabilization delay */
1748 dsi->status.dc_stream = DSI_DC_STREAM_DISABLE;
1751 /* wait for frame end interrupt or (timeout_n_frames * 1 frame duration)
1752 * whichever happens to occur first
1754 static int tegra_dsi_wait_frame_end(struct tegra_dc *dc,
1755 struct tegra_dc_dsi_data *dsi,
1756 u32 timeout_n_frames)
1759 u32 frame_period = DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
1760 struct tegra_dc_mode mode = dc->mode;
1761 u32 line_period = DIV_ROUND_UP(
1762 MS_TO_US(frame_period),
1763 mode.v_sync_width + mode.v_back_porch +
1764 mode.v_active + mode.v_front_porch);
1766 if (timeout_n_frames < 2)
1767 dev_WARN(&dc->ndev->dev,
1768 "dsi: to stop at next frame give at least 2 frame delay\n");
1770 timeout = _tegra_dc_wait_for_frame_end(dc, timeout_n_frames *
1773 /* wait for v_ref_to_sync no. of lines after frame end interrupt */
1774 udelay(mode.v_ref_to_sync * line_period);
1779 static void tegra_dsi_stop_dc_stream_at_frame_end(struct tegra_dc *dc,
1780 struct tegra_dc_dsi_data *dsi,
1781 u32 timeout_n_frames)
1783 u32 frame_period = DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
1785 tegra_dsi_stop_dc_stream(dc, dsi);
1787 if (tegra_dc_poll_register(dc, DC_CMD_STATE_CONTROL,
1788 GENERAL_ACT_REQ, 0, 100,
1789 timeout_n_frames * frame_period))
1790 dev_err(&dsi->dc->ndev->dev,
1791 "dc timeout waiting for DC to stop\n");
1793 tegra_dsi_soft_reset(dsi);
1795 tegra_dsi_reset_underflow_overflow(dsi);
1798 static void tegra_dc_gpio_to_spio(struct tegra_dc_dsi_data *dsi, unsigned gpio)
1802 /* convert to spio */
1803 err = gpio_request(gpio, "temp_request");
1805 dev_err(&dsi->dc->ndev->dev,
1806 "dsi: %s: gpio request failed %d\n", __func__, err);
1812 static void tegra_dsi_start_dc_stream(struct tegra_dc *dc,
1813 struct tegra_dc_dsi_data *dsi)
1818 tegra_dvfs_set_rate(dc->clk, dc->mode.pclk);
1820 tegra_dc_writel(dc, DSI_ENABLE, DC_DISP_DISP_WIN_OPTIONS);
1822 /* TODO: clean up */
1823 tegra_dc_writel(dc, PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
1824 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE,
1825 DC_CMD_DISPLAY_POWER_CONTROL);
1827 /* Configure one-shot mode or continuous mode */
1828 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_MODE) {
1829 /* disable LSPI/LCD_DE output */
1830 val = PIN_OUTPUT_LSPI_OUTPUT_DIS;
1831 tegra_dc_writel(dc, val, DC_COM_PIN_OUTPUT_ENABLE3);
1833 /* enable MSF & set MSF polarity */
1834 val = MSF_ENABLE | MSF_LSPI;
1835 if (!dsi->info.te_polarity_low)
1836 val |= MSF_POLARITY_HIGH;
1838 val |= MSF_POLARITY_LOW;
1839 tegra_dc_writel(dc, val, DC_CMD_DISPLAY_COMMAND_OPTION0);
1841 /* set non-continuous mode */
1842 tegra_dc_writel(dc, DISP_CTRL_MODE_NC_DISPLAY,
1843 DC_CMD_DISPLAY_COMMAND);
1845 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
1847 if (dsi->info.te_gpio)
1848 tegra_dc_gpio_to_spio(dsi, dsi->info.te_gpio);
1850 /* set continuous mode */
1851 tegra_dc_writel(dc, DISP_CTRL_MODE_C_DISPLAY,
1852 DC_CMD_DISPLAY_COMMAND);
1853 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
1858 dsi->status.dc_stream = DSI_DC_STREAM_ENABLE;
1861 static void tegra_dsi_set_dc_clk(struct tegra_dc *dc,
1862 struct tegra_dc_dsi_data *dsi)
1864 u32 shift_clk_div_register;
1867 /* formula: (dsi->shift_clk_div - 1) * 2 */
1868 shift_clk_div_register = DIV_ROUND_CLOSEST(
1869 ((dsi->shift_clk_div.mul -
1870 dsi->shift_clk_div.div) * 2),
1871 dsi->shift_clk_div.div);
1873 if (tegra_platform_is_fpga()) {
1874 shift_clk_div_register = 1;
1875 if (dsi->info.ganged_type)
1876 shift_clk_div_register = 0;
1881 val = PIXEL_CLK_DIVIDER_PCD1 |
1882 SHIFT_CLK_DIVIDER(shift_clk_div_register + 2);
1884 /* SW WAR for bug 1045373. To make the shift clk dividor effect under
1885 * all circumstances, write N+2 to SHIFT_CLK_DIVIDER and activate it.
1886 * After 2us delay, write the target values to it. */
1887 #if defined(CONFIG_ARCH_TEGRA_14x_SOC) || defined(CONFIG_ARCH_11x_SOC)
1888 tegra_dc_writel(dc, val, DC_DISP_DISP_CLOCK_CONTROL);
1889 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
1894 /* TODO: find out if PCD3 option is required */
1895 val = PIXEL_CLK_DIVIDER_PCD1 |
1896 SHIFT_CLK_DIVIDER(shift_clk_div_register);
1898 tegra_dc_writel(dc, val, DC_DISP_DISP_CLOCK_CONTROL);
1903 static void tegra_dsi_set_dsi_clk(struct tegra_dc *dc,
1904 struct tegra_dc_dsi_data *dsi, u32 clk)
1909 /* Round up to MHz */
1914 /* Set up pixel clock */
1915 pclk_khz = (clk * dsi->shift_clk_div.div) /
1916 dsi->shift_clk_div.mul;
1918 dc->mode.pclk = pclk_khz * 1000;
1920 dc->shift_clk_div.mul = dsi->shift_clk_div.mul;
1921 dc->shift_clk_div.div = dsi->shift_clk_div.div;
1923 /* TODO: Define one shot work delay in board file. */
1924 /* Since for one-shot mode, refresh rate is usually set larger than
1925 * expected refresh rate, it needs at least 3 frame period. Less
1926 * delay one shot work is, more powering saving we have. */
1927 dc->one_shot_delay_ms = 4 *
1928 DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
1930 tegra_dsi_setup_clk(dc, dsi);
1931 tegra_dsi_reset_deassert(dsi);
1933 dsi->current_dsi_clk_khz =
1934 clk_get_rate(dsi->dsi_clk[0]) / 1000;
1935 dsi->current_bit_clk_ps = DIV_ROUND_CLOSEST((1000 * 1000 * 1000),
1936 (dsi->current_dsi_clk_khz * 2));
1939 static void tegra_dsi_hs_clk_out_enable(struct tegra_dc_dsi_data *dsi)
1943 val = tegra_dsi_readl(dsi, DSI_CONTROL);
1944 val &= ~DSI_CONTROL_HS_CLK_CTRL(1);
1946 if (dsi->info.video_clock_mode == TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS) {
1947 val |= DSI_CONTROL_HS_CLK_CTRL(CONTINUOUS);
1948 dsi->status.clk_mode = DSI_PHYCLK_CONTINUOUS;
1950 val |= DSI_CONTROL_HS_CLK_CTRL(TX_ONLY);
1951 dsi->status.clk_mode = DSI_PHYCLK_TX_ONLY;
1953 tegra_dsi_writel(dsi, val, DSI_CONTROL);
1955 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
1956 val &= ~DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(1);
1957 val |= DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(TEGRA_DSI_HIGH);
1958 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
1960 dsi->status.clk_out = DSI_PHYCLK_OUT_EN;
1963 static void tegra_dsi_hs_clk_out_enable_in_lp(struct tegra_dc_dsi_data *dsi)
1966 tegra_dsi_hs_clk_out_enable(dsi);
1968 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
1969 val &= ~DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(1);
1970 val |= DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(TEGRA_DSI_LOW);
1971 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
1974 static void tegra_dsi_hs_clk_out_disable(struct tegra_dc *dc,
1975 struct tegra_dc_dsi_data *dsi)
1979 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
1980 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
1982 tegra_dsi_writel(dsi, TEGRA_DSI_DISABLE, DSI_POWER_CONTROL);
1983 /* stabilization delay */
1986 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
1987 val &= ~DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(1);
1988 val |= DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(TEGRA_DSI_LOW);
1989 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
1991 tegra_dsi_writel(dsi, TEGRA_DSI_ENABLE, DSI_POWER_CONTROL);
1992 /* stabilization delay */
1995 dsi->status.clk_mode = DSI_PHYCLK_NOT_INIT;
1996 dsi->status.clk_out = DSI_PHYCLK_OUT_DIS;
1999 static void tegra_dsi_set_control_reg_lp(struct tegra_dc_dsi_data *dsi)
2002 u32 host_dsi_control;
2005 dsi_control = dsi->dsi_control_val | DSI_CTRL_HOST_DRIVEN;
2006 host_dsi_control = HOST_DSI_CTRL_COMMON |
2007 HOST_DSI_CTRL_HOST_DRIVEN |
2008 DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(TEGRA_DSI_LOW);
2009 max_threshold = DSI_MAX_THRESHOLD_MAX_THRESHOLD(DSI_HOST_FIFO_DEPTH);
2011 tegra_dsi_writel(dsi, max_threshold, DSI_MAX_THRESHOLD);
2012 tegra_dsi_writel(dsi, dsi_control, DSI_CONTROL);
2013 tegra_dsi_writel(dsi, host_dsi_control, DSI_HOST_DSI_CONTROL);
2015 dsi->status.driven = DSI_DRIVEN_MODE_HOST;
2016 dsi->status.clk_burst = DSI_CLK_BURST_NOT_INIT;
2017 dsi->status.vtype = DSI_VIDEO_TYPE_NOT_INIT;
2020 static void tegra_dsi_set_control_reg_hs(struct tegra_dc_dsi_data *dsi,
2024 u32 host_dsi_control;
2028 dsi_control = dsi->dsi_control_val;
2029 host_dsi_control = HOST_DSI_CTRL_COMMON;
2033 if (driven_mode == TEGRA_DSI_DRIVEN_BY_HOST) {
2034 dsi_control |= DSI_CTRL_HOST_DRIVEN;
2035 host_dsi_control |= HOST_DSI_CTRL_HOST_DRIVEN;
2037 DSI_MAX_THRESHOLD_MAX_THRESHOLD(DSI_HOST_FIFO_DEPTH);
2038 dsi->status.driven = DSI_DRIVEN_MODE_HOST;
2040 dsi_control |= DSI_CTRL_DC_DRIVEN;
2041 host_dsi_control |= HOST_DSI_CTRL_DC_DRIVEN;
2043 DSI_MAX_THRESHOLD_MAX_THRESHOLD(DSI_VIDEO_FIFO_DEPTH);
2044 dsi->status.driven = DSI_DRIVEN_MODE_DC;
2046 if (dsi->info.video_data_type ==
2047 TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE) {
2048 dsi_control |= DSI_CTRL_CMD_MODE;
2049 dcs_cmd = DSI_DCS_CMDS_LT5_DCS_CMD(
2050 DSI_WRITE_MEMORY_START)|
2051 DSI_DCS_CMDS_LT3_DCS_CMD(
2052 DSI_WRITE_MEMORY_CONTINUE);
2053 dsi->status.vtype = DSI_VIDEO_TYPE_CMD_MODE;
2055 dsi_control |= DSI_CTRL_VIDEO_MODE;
2056 dsi->status.vtype = DSI_VIDEO_TYPE_VIDEO_MODE;
2060 tegra_dsi_writel(dsi, max_threshold, DSI_MAX_THRESHOLD);
2061 tegra_dsi_writel(dsi, dcs_cmd, DSI_DCS_CMDS);
2062 tegra_dsi_writel(dsi, dsi_control, DSI_CONTROL);
2063 tegra_dsi_writel(dsi, host_dsi_control, DSI_HOST_DSI_CONTROL);
2066 static void tegra_dsi_pad_disable(struct tegra_dc_dsi_data *dsi)
2070 if (dsi->info.controller_vs == DSI_VS_1) {
2071 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_0_VS1);
2072 val &= ~(DSI_PAD_CONTROL_0_VS1_PAD_PDIO(0xf) |
2073 DSI_PAD_CONTROL_0_VS1_PAD_PDIO_CLK(0x1) |
2074 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_ENAB(0xf) |
2075 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_CLK_ENAB(0x1));
2076 val |= DSI_PAD_CONTROL_0_VS1_PAD_PDIO(0xf) |
2077 DSI_PAD_CONTROL_0_VS1_PAD_PDIO_CLK
2078 (TEGRA_DSI_PAD_DISABLE) |
2079 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_ENAB(0xf) |
2080 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_CLK_ENAB
2081 (TEGRA_DSI_PAD_DISABLE);
2082 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_0_VS1);
2084 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL);
2085 val &= ~(DSI_PAD_CONTROL_PAD_PDIO(0x3) |
2086 DSI_PAD_CONTROL_PAD_PDIO_CLK(0x1) |
2087 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(0x1));
2088 val |= DSI_PAD_CONTROL_PAD_PDIO(0x3) |
2089 DSI_PAD_CONTROL_PAD_PDIO_CLK(TEGRA_DSI_PAD_DISABLE) |
2090 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(TEGRA_DSI_PAD_DISABLE);
2091 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL);
2095 static void tegra_dsi_pad_enable(struct tegra_dc_dsi_data *dsi)
2099 if (dsi->info.controller_vs == DSI_VS_1) {
2100 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_0_VS1);
2101 val &= ~(DSI_PAD_CONTROL_0_VS1_PAD_PDIO(0xf) |
2102 DSI_PAD_CONTROL_0_VS1_PAD_PDIO_CLK(0x1) |
2103 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_ENAB(0xf) |
2104 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_CLK_ENAB(0x1));
2105 val |= DSI_PAD_CONTROL_0_VS1_PAD_PDIO(TEGRA_DSI_PAD_ENABLE) |
2106 DSI_PAD_CONTROL_0_VS1_PAD_PDIO_CLK(
2107 TEGRA_DSI_PAD_ENABLE) |
2108 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_ENAB(
2109 TEGRA_DSI_PAD_ENABLE) |
2110 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_CLK_ENAB(
2111 TEGRA_DSI_PAD_ENABLE);
2112 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_0_VS1);
2114 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL);
2115 val &= ~(DSI_PAD_CONTROL_PAD_PDIO(0x3) |
2116 DSI_PAD_CONTROL_PAD_PDIO_CLK(0x1) |
2117 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(0x1));
2118 val |= DSI_PAD_CONTROL_PAD_PDIO(TEGRA_DSI_PAD_ENABLE) |
2119 DSI_PAD_CONTROL_PAD_PDIO_CLK(TEGRA_DSI_PAD_ENABLE) |
2120 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(TEGRA_DSI_PAD_ENABLE);
2121 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL);
2125 static void __maybe_unused
2126 tegra_dsi_mipi_calibration_status(struct tegra_dc_dsi_data *dsi)
2130 /* Start calibration */
2131 val = tegra_mipi_cal_read(dsi->mipi_cal,
2132 MIPI_CAL_MIPI_CAL_CTRL_0);
2133 val |= (MIPI_CAL_STARTCAL(0x1));
2134 tegra_mipi_cal_write(dsi->mipi_cal, val,
2135 MIPI_CAL_MIPI_CAL_CTRL_0);
2137 for (timeout = MIPI_DSI_AUTOCAL_TIMEOUT_USEC;
2138 timeout; timeout -= 100) {
2139 val = tegra_mipi_cal_read(dsi->mipi_cal,
2140 MIPI_CAL_CIL_MIPI_CAL_STATUS_0);
2141 if (!(val & MIPI_CAL_ACTIVE(0x1)) &&
2142 (val & MIPI_AUTO_CAL_DONE(0x1))) {
2143 dev_info(&dsi->dc->ndev->dev, "DSI pad calibration done\n");
2146 usleep_range(10, 100);
2149 dev_info(&dsi->dc->ndev->dev, "DSI calibration timed out\n");
2152 #if defined(CONFIG_ARCH_TEGRA_13x_SOC)
2153 void tegra_dsi_mipi_calibration_13x(struct tegra_dc_dsi_data *dsi)
2156 struct clk *clk72mhz = NULL;
2158 clk72mhz = clk_get_sys("clk72mhz", NULL);
2159 if (IS_ERR_OR_NULL(clk72mhz)) {
2160 dev_err(&dsi->dc->ndev->dev, "dsi: can't get clk72mhz clock\n");
2163 tegra_disp_clk_prepare_enable(clk72mhz);
2165 /* Calibration settings begin */
2166 val = tegra_mipi_cal_read(dsi->mipi_cal,
2167 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2168 val &= ~(PAD_DRIV_UP_REF(0x7) | PAD_DRIV_DN_REF(0x7));
2169 val |= (PAD_DRIV_UP_REF(0x3) | PAD_DRIV_DN_REF(0x0));
2170 tegra_mipi_cal_write(dsi->mipi_cal, val,
2171 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2173 val = (DSI_PAD_SLEWUPADJ(0x7) | DSI_PAD_SLEWDNADJ(0x7) |
2174 DSI_PAD_LPUPADJ(0x1) | DSI_PAD_LPDNADJ(0x1) |
2175 DSI_PAD_OUTADJCLK(0x0));
2176 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_2_VS1);
2178 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_3_VS1);
2179 val |= (DSI_PAD_PREEMP_PD_CLK(0x3) | DSI_PAD_PREEMP_PU_CLK(0x3) |
2180 DSI_PAD_PREEMP_PD(0x3) | DSI_PAD_PREEMP_PU(0x3));
2181 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
2183 /* Deselect shared clk lane with DSI pads */
2184 for (reg = MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0;
2185 reg <= MIPI_CAL_CSIE_MIPI_CAL_CONFIG_2_0;
2187 val = tegra_mipi_cal_read(dsi->mipi_cal, reg);
2188 val &= ~(MIPI_CAL_SELA(0x1));
2189 tegra_mipi_cal_write(dsi->mipi_cal, val, reg);
2192 /* Calibrate DSI 0 */
2193 if (dsi->info.ganged_type ||
2194 dsi->info.dsi_instance == DSI_INSTANCE_0) {
2195 val = MIPI_CAL_OVERIDEDSIA(0x0) |
2196 MIPI_CAL_SELDSIA(0x1) |
2197 MIPI_CAL_HSPDOSDSIA(0x0) |
2198 MIPI_CAL_HSPUOSDSIA(0x0) |
2199 MIPI_CAL_TERMOSDSIA(0x0);
2200 tegra_mipi_cal_write(dsi->mipi_cal, val,
2201 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2202 tegra_mipi_cal_write(dsi->mipi_cal, val,
2203 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2205 val = (MIPI_CAL_CLKSELDSIA(0x1) |
2206 MIPI_CAL_HSCLKPDOSDSIA(0x3) |
2207 MIPI_CAL_HSCLKPUOSDSIA(0x2));
2208 tegra_mipi_cal_write(dsi->mipi_cal, val,
2209 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2210 tegra_mipi_cal_write(dsi->mipi_cal, val,
2211 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2213 /* Deselect PAD C */
2214 val = tegra_mipi_cal_read(dsi->mipi_cal,
2215 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2216 val &= ~(MIPI_CAL_SELDSIC(0x1));
2217 tegra_mipi_cal_write(dsi->mipi_cal, val,
2218 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2220 /* Deselect PAD D */
2221 val = tegra_mipi_cal_read(dsi->mipi_cal,
2222 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2223 val &= ~(MIPI_CAL_SELDSID(0x1));
2224 tegra_mipi_cal_write(dsi->mipi_cal, val,
2225 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2227 val = MIPI_CAL_NOISE_FLT(0xa) |
2228 MIPI_CAL_PRESCALE(0x2) |
2229 MIPI_CAL_CLKEN_OVR(0x1) |
2230 MIPI_CAL_AUTOCAL_EN(0x0);
2231 tegra_mipi_cal_write(dsi->mipi_cal, val,
2232 MIPI_CAL_MIPI_CAL_CTRL_0);
2234 tegra_dsi_mipi_calibration_status(dsi);
2236 /* Calibrate DSI 1 */
2237 if (dsi->info.ganged_type ||
2238 dsi->info.dsi_instance == DSI_INSTANCE_1) {
2239 val = MIPI_CAL_OVERIDEC(0x0) |
2240 MIPI_CAL_SELC(0x1) |
2241 MIPI_CAL_HSPDOSC(0x0) |
2242 MIPI_CAL_HSPUOSC(0x0) |
2243 MIPI_CAL_TERMOSC(0x0);
2244 tegra_mipi_cal_write(dsi->mipi_cal, val,
2245 MIPI_CAL_CILC_MIPI_CAL_CONFIG_0);
2246 tegra_mipi_cal_write(dsi->mipi_cal, val,
2247 MIPI_CAL_CILD_MIPI_CAL_CONFIG_0);
2249 val = (MIPI_CAL_CLKSELDSIA(0x1) |
2250 MIPI_CAL_HSCLKPDOSDSIA(0x3) |
2251 MIPI_CAL_HSCLKPUOSDSIA(0x2));
2252 tegra_mipi_cal_write(dsi->mipi_cal, val,
2253 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2254 tegra_mipi_cal_write(dsi->mipi_cal, val,
2255 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2257 /* Deselect PAD A */
2258 val = tegra_mipi_cal_read(dsi->mipi_cal,
2259 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2260 val &= ~(MIPI_CAL_SELDSIC(0x1));
2261 tegra_mipi_cal_write(dsi->mipi_cal, val,
2262 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2264 /* Deselect PAD B */
2265 val = tegra_mipi_cal_read(dsi->mipi_cal,
2266 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2267 val &= ~(MIPI_CAL_SELDSID(0x1));
2268 tegra_mipi_cal_write(dsi->mipi_cal, val,
2269 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2271 val = MIPI_CAL_NOISE_FLT(0xa) |
2272 MIPI_CAL_PRESCALE(0x2) |
2273 MIPI_CAL_CLKEN_OVR(0x1) |
2274 MIPI_CAL_AUTOCAL_EN(0x0);
2275 tegra_mipi_cal_write(dsi->mipi_cal, val,
2276 MIPI_CAL_MIPI_CAL_CTRL_0);
2278 tegra_dsi_mipi_calibration_status(dsi);
2281 tegra_disp_clk_disable_unprepare(clk72mhz);
2285 #if defined(CONFIG_ARCH_TEGRA_21x_SOC)
2286 static void tegra_dsi_mipi_calibration_21x(struct tegra_dc_dsi_data *dsi)
2289 struct clk *clk72mhz = NULL;
2290 clk72mhz = clk_get_sys("clk72mhz", NULL);
2291 if (IS_ERR_OR_NULL(clk72mhz)) {
2292 dev_err(&dsi->dc->ndev->dev, "dsi: can't get clk72mhz clock\n");
2295 tegra_disp_clk_prepare_enable(clk72mhz);
2297 /* Calibration settings begin */
2298 val = tegra_mipi_cal_read(dsi->mipi_cal,
2299 MIPI_CAL_MIPI_BIAS_PAD_CFG2_0);
2300 val &= ~(PAD_VCLAMP_LEVEL(0x7) | PAD_VAUXP_LEVEL(0x7));
2301 val |= (PAD_VCLAMP_LEVEL(0x1) | PAD_VAUXP_LEVEL(0x1));
2302 tegra_mipi_cal_write(dsi->mipi_cal, val,
2303 MIPI_CAL_MIPI_BIAS_PAD_CFG2_0);
2305 val = tegra_mipi_cal_read(dsi->mipi_cal,
2306 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2307 val &= ~(PAD_DRIV_UP_REF(0x7) | PAD_DRIV_DN_REF(0x7));
2308 val |= (PAD_DRIV_UP_REF(0x3) | PAD_DRIV_DN_REF(0x0));
2309 tegra_mipi_cal_write(dsi->mipi_cal, val,
2310 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2312 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_1_VS1);
2313 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_2_VS1);
2315 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_3_VS1);
2316 val |= (DSI_PAD_PREEMP_PD_CLK(0x3) | DSI_PAD_PREEMP_PU_CLK(0x3) |
2317 DSI_PAD_PREEMP_PD(0x3) | DSI_PAD_PREEMP_PU(0x3));
2318 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
2320 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_4_VS1);
2322 /* Calibrate DSI 0 */
2323 if (dsi->info.ganged_type ||
2324 dsi->info.dsi_instance == DSI_INSTANCE_0) {
2325 val = MIPI_CAL_OVERIDEDSIA(0x0) |
2326 MIPI_CAL_SELDSIA(0x1) |
2327 MIPI_CAL_HSPDOSDSIA(0x0) |
2328 MIPI_CAL_HSPUOSDSIA(0x2) |
2329 MIPI_CAL_TERMOSDSIA(0x0);
2330 tegra_mipi_cal_write(dsi->mipi_cal, val,
2331 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2332 tegra_mipi_cal_write(dsi->mipi_cal, val,
2333 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2335 val = (MIPI_CAL_CLKSELDSIA(0x1) |
2336 MIPI_CAL_HSCLKPDOSDSIA(0x0) |
2337 MIPI_CAL_HSCLKPUOSDSIA(0x2));
2338 tegra_mipi_cal_write(dsi->mipi_cal, val,
2339 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2340 tegra_mipi_cal_write(dsi->mipi_cal, val,
2341 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2343 val = MIPI_CAL_NOISE_FLT(0xa) |
2344 MIPI_CAL_PRESCALE(0x2) |
2345 MIPI_CAL_CLKEN_OVR(0x0) |
2346 MIPI_CAL_AUTOCAL_EN(0x0);
2347 tegra_mipi_cal_write(dsi->mipi_cal, val,
2348 MIPI_CAL_MIPI_CAL_CTRL_0);
2350 tegra_dsi_mipi_calibration_status(dsi);
2352 /* Calibrate DSI 1 */
2353 if (dsi->info.ganged_type ||
2354 dsi->info.dsi_instance == DSI_INSTANCE_1) {
2355 val = MIPI_CAL_OVERIDEDSIC(0x0) |
2356 MIPI_CAL_SELDSIC(0x1) |
2357 MIPI_CAL_HSPDOSDSIC(0x0) |
2358 MIPI_CAL_HSPUOSDSIC(0x2) |
2359 MIPI_CAL_TERMOSDSIC(0x0);
2360 tegra_mipi_cal_write(dsi->mipi_cal, val,
2361 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2362 tegra_mipi_cal_write(dsi->mipi_cal, val,
2363 MIPI_CAL_DSID_MIPI_CAL_CONFIG_0);
2365 val = (MIPI_CAL_CLKSELDSIC(0x1) |
2366 MIPI_CAL_HSCLKPDOSDSIC(0x0) |
2367 MIPI_CAL_HSCLKPUOSDSIC(0x2));
2368 tegra_mipi_cal_write(dsi->mipi_cal, val,
2369 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_2_0);
2370 tegra_mipi_cal_write(dsi->mipi_cal, val,
2371 MIPI_CAL_DSID_MIPI_CAL_CONFIG_2_0);
2373 val = MIPI_CAL_NOISE_FLT(0xa) |
2374 MIPI_CAL_PRESCALE(0x2) |
2375 MIPI_CAL_CLKEN_OVR(0x0) |
2376 MIPI_CAL_AUTOCAL_EN(0x0);
2377 tegra_mipi_cal_write(dsi->mipi_cal, val,
2378 MIPI_CAL_MIPI_CAL_CTRL_0);
2380 tegra_dsi_mipi_calibration_status(dsi);
2383 tegra_disp_clk_disable_unprepare(clk72mhz);
2387 #ifdef CONFIG_ARCH_TEGRA_12x_SOC
2388 static void __maybe_unused
2389 tegra_dsi_mipi_calibration_12x(struct tegra_dc_dsi_data *dsi)
2392 struct clk *clk72mhz = NULL;
2394 clk72mhz = clk_get_sys("clk72mhz", NULL);
2395 if (IS_ERR_OR_NULL(clk72mhz)) {
2396 dev_err(&dsi->dc->ndev->dev, "dsi: can't get clk72mhz clock\n");
2399 tegra_disp_clk_prepare_enable(clk72mhz);
2401 /* Calibration settings begin */
2402 val = tegra_mipi_cal_read(dsi->mipi_cal,
2403 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2404 val &= ~PAD_DRIV_UP_REF(0x7);
2405 val |= PAD_DRIV_UP_REF(0x3);
2406 tegra_mipi_cal_write(dsi->mipi_cal, val,
2407 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2408 /*Bug 1445912: override tap delay for panel-a-1200-1920-7-0 */
2409 if (dsi->info.boardinfo.platform_boardid == BOARD_P1761 &&
2410 dsi->info.boardinfo.display_boardversion == 1) {
2411 val = (DSI_PAD_OUTADJ3(0x4) | DSI_PAD_OUTADJ2(0x4) |
2412 DSI_PAD_OUTADJ1(0x4) | DSI_PAD_OUTADJ0(0x4));
2413 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_1_VS1);
2416 val = (DSI_PAD_SLEWUPADJ(0x7) | DSI_PAD_SLEWDNADJ(0x7) |
2417 DSI_PAD_LPUPADJ(0x1) | DSI_PAD_LPDNADJ(0x1) |
2418 DSI_PAD_OUTADJCLK(0x0));
2419 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_2_VS1);
2421 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_3_VS1);
2422 val |= (DSI_PAD_PREEMP_PD_CLK(0x3) | DSI_PAD_PREEMP_PU_CLK(0x3) |
2423 DSI_PAD_PREEMP_PD(0x3) | DSI_PAD_PREEMP_PU(0x3));
2424 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
2426 /* Deselect shared clk lane with DSI pads */
2427 for (reg = MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0;
2428 reg <= MIPI_CAL_CSIE_MIPI_CAL_CONFIG_2_0;
2430 val = tegra_mipi_cal_read(dsi->mipi_cal, reg);
2431 val &= ~(MIPI_CAL_SELA(0x1));
2432 tegra_mipi_cal_write(dsi->mipi_cal, val, reg);
2435 /* Calibrate DSI 0 */
2436 if (dsi->info.ganged_type ||
2437 dsi->info.dsi_instance == DSI_INSTANCE_0) {
2438 val = MIPI_CAL_OVERIDEDSIA(0x0) |
2439 MIPI_CAL_SELDSIA(0x1) |
2440 MIPI_CAL_HSPDOSDSIA(0x0) |
2441 MIPI_CAL_HSPUOSDSIA(0x0) |
2442 MIPI_CAL_TERMOSDSIA(0x0);
2443 tegra_mipi_cal_write(dsi->mipi_cal, val,
2444 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2445 tegra_mipi_cal_write(dsi->mipi_cal, val,
2446 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2448 val = (MIPI_CAL_CLKSELDSIA(0x1) |
2449 MIPI_CAL_HSCLKPDOSDSIA(0x1) |
2450 MIPI_CAL_HSCLKPUOSDSIA(0x2));
2451 tegra_mipi_cal_write(dsi->mipi_cal, val,
2452 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2453 tegra_mipi_cal_write(dsi->mipi_cal, val,
2454 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2456 /* Deselect PAD C */
2457 val = tegra_mipi_cal_read(dsi->mipi_cal,
2458 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2459 val &= ~(MIPI_CAL_SELDSIC(0x1));
2460 tegra_mipi_cal_write(dsi->mipi_cal, val,
2461 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2463 /* Deselect PAD D */
2464 val = tegra_mipi_cal_read(dsi->mipi_cal,
2465 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2466 val &= ~(MIPI_CAL_SELDSID(0x1));
2467 tegra_mipi_cal_write(dsi->mipi_cal, val,
2468 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2470 val = MIPI_CAL_NOISE_FLT(0xa) |
2471 MIPI_CAL_PRESCALE(0x2) |
2472 MIPI_CAL_CLKEN_OVR(0x1) |
2473 MIPI_CAL_AUTOCAL_EN(0x0);
2474 tegra_mipi_cal_write(dsi->mipi_cal, val,
2475 MIPI_CAL_MIPI_CAL_CTRL_0);
2477 tegra_dsi_mipi_calibration_status(dsi);
2479 /* Calibrate DSI 1 */
2480 if (dsi->info.ganged_type ||
2481 dsi->info.dsi_instance == DSI_INSTANCE_1) {
2482 val = MIPI_CAL_OVERIDEC(0x0) |
2483 MIPI_CAL_SELC(0x1) |
2484 MIPI_CAL_HSPDOSC(0x0) |
2485 MIPI_CAL_HSPUOSC(0x0) |
2486 MIPI_CAL_TERMOSC(0x0);
2487 tegra_mipi_cal_write(dsi->mipi_cal, val,
2488 MIPI_CAL_CILC_MIPI_CAL_CONFIG_0);
2489 tegra_mipi_cal_write(dsi->mipi_cal, val,
2490 MIPI_CAL_CILD_MIPI_CAL_CONFIG_0);
2492 val = (MIPI_CAL_CLKSELDSIA(0x1) |
2493 MIPI_CAL_HSCLKPDOSDSIA(0x1) |
2494 MIPI_CAL_HSCLKPUOSDSIA(0x2));
2495 tegra_mipi_cal_write(dsi->mipi_cal, val,
2496 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2497 tegra_mipi_cal_write(dsi->mipi_cal, val,
2498 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2500 /* Deselect PAD A */
2501 val = tegra_mipi_cal_read(dsi->mipi_cal,
2502 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2503 val &= ~(MIPI_CAL_SELDSIC(0x1));
2504 tegra_mipi_cal_write(dsi->mipi_cal, val,
2505 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2507 /* Deselect PAD B */
2508 val = tegra_mipi_cal_read(dsi->mipi_cal,
2509 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2510 val &= ~(MIPI_CAL_SELDSID(0x1));
2511 tegra_mipi_cal_write(dsi->mipi_cal, val,
2512 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2514 val = MIPI_CAL_NOISE_FLT(0xa) |
2515 MIPI_CAL_PRESCALE(0x2) |
2516 MIPI_CAL_CLKEN_OVR(0x1) |
2517 MIPI_CAL_AUTOCAL_EN(0x0);
2518 tegra_mipi_cal_write(dsi->mipi_cal, val,
2519 MIPI_CAL_MIPI_CAL_CTRL_0);
2521 tegra_dsi_mipi_calibration_status(dsi);
2524 tegra_disp_clk_disable_unprepare(clk72mhz);
2528 #ifdef CONFIG_ARCH_TEGRA_14x_SOC
2529 void tegra_dsi_mipi_calibration_14x(struct tegra_dc_dsi_data *dsi)
2532 struct clk *clk72mhz = NULL;
2534 clk72mhz = clk_get_sys("clk72mhz", NULL);
2535 if (IS_ERR_OR_NULL(clk72mhz)) {
2536 dev_err(&dsi->dc->ndev->dev, "dsi: can't get clk72mhz clock\n");
2539 tegra_disp_clk_prepare_enable(clk72mhz);
2541 tegra_mipi_cal_write(dsi->mipi_cal,
2542 PAD_DRIV_DN_REF(0x2),
2543 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2545 val = (DSI_PAD_SLEWUPADJ(0x7) | DSI_PAD_SLEWDNADJ(0x7) |
2546 DSI_PAD_LPUPADJ(0x1) | DSI_PAD_LPDNADJ(0x1));
2547 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_2_VS1);
2549 val = (DSI_PAD_PREEMP_PD(0x3) | DSI_PAD_PREEMP_PU(0x3));
2550 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
2552 val = MIPI_CAL_HSCLKPDOSDSIA(0x2) |
2553 MIPI_CAL_HSCLKPUOSDSIA(0x2);
2554 tegra_mipi_cal_write(dsi->mipi_cal, val,
2555 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2556 tegra_mipi_cal_write(dsi->mipi_cal, val,
2557 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2559 val = MIPI_CAL_OVERIDEDSIA(0x0) |
2560 MIPI_CAL_SELDSIA(0x1) |
2561 MIPI_CAL_HSPDOSDSIA(0x0) |
2562 MIPI_CAL_HSPUOSDSIA(0x0) |
2563 MIPI_CAL_TERMOSDSIA(0x0);
2564 tegra_mipi_cal_write(dsi->mipi_cal, val,
2565 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2566 tegra_mipi_cal_write(dsi->mipi_cal, val,
2567 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2569 val = MIPI_CAL_NOISE_FLT(0xa) |
2570 MIPI_CAL_PRESCALE(0x2) |
2571 MIPI_CAL_CLKEN_OVR(0x1) |
2572 MIPI_CAL_AUTOCAL_EN(0x0);
2573 tegra_mipi_cal_write(dsi->mipi_cal, val,
2574 MIPI_CAL_MIPI_CAL_CTRL_0);
2576 tegra_dsi_mipi_calibration_status(dsi);
2578 tegra_disp_clk_disable_unprepare(clk72mhz);
2582 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
2583 static void tegra_dsi_mipi_calibration_11x(struct tegra_dc_dsi_data *dsi)
2586 /* Calibration settings begin */
2587 val = (DSI_PAD_SLEWUPADJ(0x7) | DSI_PAD_SLEWDNADJ(0x7) |
2588 DSI_PAD_LPUPADJ(0x1) | DSI_PAD_LPDNADJ(0x1) |
2589 DSI_PAD_OUTADJCLK(0x0));
2590 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_2_VS1);
2592 /* Calibrate DSI 0 */
2593 if (dsi->info.ganged_type ||
2594 dsi->info.dsi_instance == DSI_INSTANCE_0) {
2595 val = tegra_mipi_cal_read(dsi->mipi_cal,
2596 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2597 val = MIPI_CAL_OVERIDEDSIA(0x0) |
2598 MIPI_CAL_SELDSIA(0x1) |
2599 MIPI_CAL_HSPDOSDSIA(0x0) |
2600 MIPI_CAL_HSPUOSDSIA(0x4) |
2601 MIPI_CAL_TERMOSDSIA(0x5);
2602 tegra_mipi_cal_write(dsi->mipi_cal, val,
2603 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2604 tegra_mipi_cal_write(dsi->mipi_cal, val,
2605 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2607 /* Deselect PAD C */
2608 val = tegra_mipi_cal_read(dsi->mipi_cal,
2609 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2610 val &= ~(MIPI_CAL_SELDSIC(0x1));
2611 tegra_mipi_cal_write(dsi->mipi_cal, val,
2612 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2614 /* Deselect PAD D */
2615 val = tegra_mipi_cal_read(dsi->mipi_cal,
2616 MIPI_CAL_DSID_MIPI_CAL_CONFIG_0);
2617 val &= ~(MIPI_CAL_SELDSID(0x1));
2618 tegra_mipi_cal_write(dsi->mipi_cal, val,
2619 MIPI_CAL_DSID_MIPI_CAL_CONFIG_0);
2621 val = tegra_mipi_cal_read(dsi->mipi_cal,
2622 MIPI_CAL_MIPI_CAL_CTRL_0);
2623 val = MIPI_CAL_NOISE_FLT(0xa) |
2624 MIPI_CAL_PRESCALE(0x2) |
2625 MIPI_CAL_CLKEN_OVR(0x1) |
2626 MIPI_CAL_AUTOCAL_EN(0x0);
2627 tegra_mipi_cal_write(dsi->mipi_cal, val,
2628 MIPI_CAL_MIPI_CAL_CTRL_0);
2630 tegra_dsi_mipi_calibration_status(dsi);
2633 /* Calibrate DSI 1 */
2634 if (dsi->info.ganged_type ||
2635 dsi->info.dsi_instance == DSI_INSTANCE_1) {
2636 val = tegra_mipi_cal_read(dsi->mipi_cal,
2637 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2638 val = MIPI_CAL_OVERIDEDSIC(0x0) |
2639 MIPI_CAL_SELDSIC(0x1) |
2640 MIPI_CAL_HSPDOSDSIC(0x0) |
2641 MIPI_CAL_HSPUOSDSIC(0x4) |
2642 MIPI_CAL_TERMOSDSIC(0x5);
2643 tegra_mipi_cal_write(dsi->mipi_cal, val,
2644 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2645 tegra_mipi_cal_write(dsi->mipi_cal, val,
2646 MIPI_CAL_DSID_MIPI_CAL_CONFIG_0);
2648 /* Deselect PAD A */
2649 val = tegra_mipi_cal_read(dsi->mipi_cal,
2650 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2651 val &= ~(MIPI_CAL_SELDSIA(0x1));
2652 tegra_mipi_cal_write(dsi->mipi_cal, val,
2653 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2655 /* Deselect PAD B */
2656 val = tegra_mipi_cal_read(dsi->mipi_cal,
2657 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2658 val &= ~(MIPI_CAL_SELDSIB(0x1));
2659 tegra_mipi_cal_write(dsi->mipi_cal, val,
2660 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2662 val = tegra_mipi_cal_read(dsi->mipi_cal,
2663 MIPI_CAL_MIPI_CAL_CTRL_0);
2664 val = MIPI_CAL_NOISE_FLT(0xa) |
2665 MIPI_CAL_PRESCALE(0x2) |
2666 MIPI_CAL_CLKEN_OVR(0x1) |
2667 MIPI_CAL_AUTOCAL_EN(0x0);
2668 tegra_mipi_cal_write(dsi->mipi_cal, val,
2669 MIPI_CAL_MIPI_CAL_CTRL_0);
2671 tegra_dsi_mipi_calibration_status(dsi);
2675 static void tegra_dsi_pad_calibration(struct tegra_dc_dsi_data *dsi)
2680 tegra_dsi_pad_enable(dsi);
2682 tegra_dsi_pad_disable(dsi);
2684 if (dsi->info.controller_vs == DSI_VS_1) {
2686 tegra_mipi_cal_init_hw(dsi->mipi_cal);
2688 tegra_mipi_cal_clk_enable(dsi->mipi_cal);
2690 /* Deselect CSI pads */
2691 for (reg = MIPI_CAL_CILA_MIPI_CAL_CONFIG_0;
2692 reg <= MIPI_CAL_CILF_MIPI_CAL_CONFIG_0;
2694 val = tegra_mipi_cal_read(dsi->mipi_cal, reg);
2695 val &= ~(MIPI_CAL_SELA(0x1));
2696 tegra_mipi_cal_write(dsi->mipi_cal, val, reg);
2699 /* enable mipi bias pad */
2700 val = tegra_mipi_cal_read(dsi->mipi_cal,
2701 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2702 val &= ~MIPI_BIAS_PAD_PDVCLAMP(0x1);
2703 tegra_mipi_cal_write(dsi->mipi_cal, val,
2704 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2706 #if defined(CONFIG_ARCH_TEGRA_11x_SOC) || \
2707 defined(CONFIG_ARCH_TEGRA_14x_SOC) || \
2708 defined(CONFIG_ARCH_TEGRA_12x_SOC)
2709 tegra_mipi_cal_write(dsi->mipi_cal,
2710 MIPI_BIAS_PAD_E_VCLAMP_REF(0x1),
2711 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2713 tegra_mipi_cal_write(dsi->mipi_cal,
2714 MIPI_BIAS_PAD_E_VCLAMP_REF(0x0),
2715 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2717 tegra_mipi_cal_write(dsi->mipi_cal,
2718 PAD_PDVREG(0x0) | PAD_VCLAMP_LEVEL(0x0),
2719 MIPI_CAL_MIPI_BIAS_PAD_CFG2_0);
2720 #if defined(CONFIG_ARCH_TEGRA_11x_SOC)
2721 tegra_dsi_mipi_calibration_11x(dsi);
2722 #elif defined(CONFIG_ARCH_TEGRA_14x_SOC)
2723 tegra_dsi_mipi_calibration_14x(dsi);
2724 #elif defined(CONFIG_ARCH_TEGRA_13x_SOC)
2725 tegra_dsi_mipi_calibration_13x(dsi);
2726 #elif defined(CONFIG_ARCH_TEGRA_12x_SOC)
2727 tegra_dsi_mipi_calibration_12x(dsi);
2728 #elif defined(CONFIG_ARCH_TEGRA_21x_SOC)
2729 tegra_dsi_mipi_calibration_21x(dsi);
2731 /* disable mipi bias pad */
2732 val = tegra_mipi_cal_read(dsi->mipi_cal,
2733 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2734 val |= MIPI_BIAS_PAD_PDVCLAMP(0x1);
2735 tegra_mipi_cal_write(dsi->mipi_cal, val,
2736 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2738 tegra_mipi_cal_clk_disable(dsi->mipi_cal);
2740 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
2743 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL);
2744 val &= ~(DSI_PAD_CONTROL_PAD_LPUPADJ(0x3) |
2745 DSI_PAD_CONTROL_PAD_LPDNADJ(0x3) |
2746 DSI_PAD_CONTROL_PAD_PREEMP_EN(0x1) |
2747 DSI_PAD_CONTROL_PAD_SLEWDNADJ(0x7) |
2748 DSI_PAD_CONTROL_PAD_SLEWUPADJ(0x7));
2750 val |= DSI_PAD_CONTROL_PAD_LPUPADJ(0x1) |
2751 DSI_PAD_CONTROL_PAD_LPDNADJ(0x1) |
2752 DSI_PAD_CONTROL_PAD_PREEMP_EN(0x1) |
2753 DSI_PAD_CONTROL_PAD_SLEWDNADJ(0x6) |
2754 DSI_PAD_CONTROL_PAD_SLEWUPADJ(0x6);
2756 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL);
2758 val = MIPI_CAL_TERMOSA(0x4);
2759 tegra_vi_csi_writel(val, CSI_CILA_MIPI_CAL_CONFIG_0);
2761 val = MIPI_CAL_TERMOSB(0x4);
2762 tegra_vi_csi_writel(val, CSI_CILB_MIPI_CAL_CONFIG_0);
2764 val = MIPI_CAL_HSPUOSD(0x3) | MIPI_CAL_HSPDOSD(0x4);
2765 tegra_vi_csi_writel(val, CSI_DSI_MIPI_CAL_CONFIG);
2767 val = PAD_DRIV_DN_REF(0x5) | PAD_DRIV_UP_REF(0x7);
2768 tegra_vi_csi_writel(val, CSI_MIPIBIAS_PAD_CONFIG);
2770 val = PAD_CIL_PDVREG(0x0);
2771 tegra_vi_csi_writel(val, CSI_CIL_PAD_CONFIG);
2776 static void tegra_dsi_panelB_enable(void)
2780 val = readl(IO_ADDRESS(APB_MISC_GP_MIPI_PAD_CTRL_0));
2781 val |= DSIB_MODE_ENABLE;
2782 writel(val, (IO_ADDRESS(APB_MISC_GP_MIPI_PAD_CTRL_0)));
2785 static int tegra_dsi_init_hw(struct tegra_dc *dc,
2786 struct tegra_dc_dsi_data *dsi)
2791 if (dsi->avdd_dsi_csi)
2792 err = regulator_enable(dsi->avdd_dsi_csi);
2793 if (WARN(err, "unable to enable regulator"))
2795 /* stablization delay */
2797 /* Enable DSI clocks */
2798 tegra_dsi_clk_enable(dsi);
2799 tegra_dsi_set_dsi_clk(dc, dsi, dsi->target_lp_clk_khz);
2801 /* Stop DC stream before configuring DSI registers
2802 * to avoid visible glitches on panel during transition
2803 * from bootloader to kernel driver
2805 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
2807 tegra_dsi_writel(dsi,
2808 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE),
2810 /* stabilization delay */
2813 if (dsi->info.dsi_instance || dsi->info.ganged_type)
2814 tegra_dsi_panelB_enable();
2816 tegra_dsi_set_phy_timing(dsi, DSI_LPHS_IN_LP_MODE);
2818 /* Initialize DSI registers */
2819 for (i = 0; i < ARRAY_SIZE(init_reg); i++)
2820 tegra_dsi_writel(dsi, 0, init_reg[i]);
2821 if (dsi->info.controller_vs == DSI_VS_1) {
2822 for (i = 0; i < ARRAY_SIZE(init_reg_vs1_ext); i++)
2823 tegra_dsi_writel(dsi, 0, init_reg_vs1_ext[i]);
2826 #ifdef CONFIG_ARCH_TEGRA_21x_SOC
2827 if (tegra_platform_is_fpga()) {
2828 if (dsi->info.video_data_type ==
2829 TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE) {
2830 /* HW fpga WAR: dsi byte clk to dsi pixel clk ratio */
2831 tegra_dsi_writel(dsi, 0x8, DSI_INIT_SEQ_DATA_15);
2836 tegra_dsi_pad_calibration(dsi);
2838 tegra_dsi_writel(dsi,
2839 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_ENABLE),
2841 /* stabilization delay */
2844 dsi->status.init = DSI_MODULE_INIT;
2845 dsi->status.lphs = DSI_LPHS_NOT_INIT;
2846 dsi->status.vtype = DSI_VIDEO_TYPE_NOT_INIT;
2847 dsi->status.driven = DSI_DRIVEN_MODE_NOT_INIT;
2848 dsi->status.clk_out = DSI_PHYCLK_OUT_DIS;
2849 dsi->status.clk_mode = DSI_PHYCLK_NOT_INIT;
2850 dsi->status.clk_burst = DSI_CLK_BURST_NOT_INIT;
2851 dsi->status.dc_stream = DSI_DC_STREAM_DISABLE;
2852 dsi->status.lp_op = DSI_LP_OP_NOT_INIT;
2854 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
2855 tegra_dsi_syncpt_reset(dsi);
2860 static int tegra_dsi_set_to_lp_mode(struct tegra_dc *dc,
2861 struct tegra_dc_dsi_data *dsi, u8 lp_op)
2865 if (dsi->status.init != DSI_MODULE_INIT) {
2870 if (dsi->status.lphs == DSI_LPHS_IN_LP_MODE &&
2871 dsi->status.lp_op == lp_op)
2874 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
2875 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
2877 /* disable/enable hs clk according to enable_hs_clock_on_lp_cmd_mode */
2878 if ((dsi->status.clk_out == DSI_PHYCLK_OUT_EN) &&
2879 (!dsi->info.enable_hs_clock_on_lp_cmd_mode))
2880 tegra_dsi_hs_clk_out_disable(dc, dsi);
2882 dsi->target_lp_clk_khz = tegra_dsi_get_lp_clk_rate(dsi, lp_op);
2883 if (dsi->current_dsi_clk_khz != dsi->target_lp_clk_khz) {
2884 tegra_dsi_set_dsi_clk(dc, dsi, dsi->target_lp_clk_khz);
2885 tegra_dsi_set_timeout(dsi);
2888 tegra_dsi_set_phy_timing(dsi, DSI_LPHS_IN_LP_MODE);
2890 tegra_dsi_set_control_reg_lp(dsi);
2892 if ((dsi->status.clk_out == DSI_PHYCLK_OUT_DIS) &&
2893 (dsi->info.enable_hs_clock_on_lp_cmd_mode))
2894 tegra_dsi_hs_clk_out_enable_in_lp(dsi);
2896 dsi->status.lphs = DSI_LPHS_IN_LP_MODE;
2897 dsi->status.lp_op = lp_op;
2898 dsi->driven_mode = TEGRA_DSI_DRIVEN_BY_HOST;
2905 static void tegra_dsi_ganged(struct tegra_dc *dc,
2906 struct tegra_dc_dsi_data *dsi)
2910 u32 h_active = dc->out->modes->h_active;
2912 int dsi_instances[2];
2913 u16 ganged_pointer = DIV_ROUND_UP(h_active, 2);
2915 if (dsi->info.controller_vs < DSI_VS_1) {
2916 dev_err(&dc->ndev->dev, "dsi: ganged mode not"
2917 "supported with current controller version\n");
2921 if (dsi->info.ganged_swap_links) {
2922 dsi_instances[0] = DSI_INSTANCE_1;
2923 dsi_instances[1] = DSI_INSTANCE_0;
2925 dsi_instances[0] = DSI_INSTANCE_0;
2926 dsi_instances[1] = DSI_INSTANCE_1;
2929 if (dsi->info.ganged_type ==
2930 TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT_OVERLAP &&
2931 dsi->info.ganged_overlap)
2932 ganged_pointer -= dsi->info.ganged_overlap;
2934 if (dsi->info.ganged_type ==
2935 TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT ||
2936 dsi->info.ganged_type ==
2937 TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT_OVERLAP) {
2939 tegra_dsi_controller_writel(dsi,
2940 DSI_GANGED_MODE_START_POINTER(0),
2941 DSI_GANGED_MODE_START, dsi_instances[0]);
2943 tegra_dsi_controller_writel(dsi,
2944 DSI_GANGED_MODE_START_POINTER(ganged_pointer),
2945 DSI_GANGED_MODE_START, dsi_instances[1]);
2947 low_width = ganged_pointer;
2948 high_width = h_active - low_width;
2949 val = DSI_GANGED_MODE_SIZE_VALID_LOW_WIDTH(low_width) |
2950 DSI_GANGED_MODE_SIZE_VALID_HIGH_WIDTH(high_width);
2952 } else if (dsi->info.ganged_type ==
2953 TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD) {
2955 tegra_dsi_controller_writel(dsi,
2956 DSI_GANGED_MODE_START_POINTER(0),
2957 DSI_GANGED_MODE_START, dsi_instances[0]);
2959 tegra_dsi_controller_writel(dsi,
2960 DSI_GANGED_MODE_START_POINTER(
2961 dsi->info.even_odd_split_width),
2962 DSI_GANGED_MODE_START, dsi_instances[1]);
2964 low_width = dsi->info.even_odd_split_width;
2965 high_width = dsi->info.even_odd_split_width;
2966 val = DSI_GANGED_MODE_SIZE_VALID_LOW_WIDTH(low_width) |
2967 DSI_GANGED_MODE_SIZE_VALID_HIGH_WIDTH(high_width);
2970 tegra_dsi_writel(dsi, val, DSI_GANGED_MODE_SIZE);
2972 tegra_dsi_writel(dsi, DSI_GANGED_MODE_CONTROL_EN(TEGRA_DSI_ENABLE),
2973 DSI_GANGED_MODE_CONTROL);
2976 static int tegra_dsi_set_to_hs_mode(struct tegra_dc *dc,
2977 struct tegra_dc_dsi_data *dsi,
2982 if (dsi->status.init != DSI_MODULE_INIT) {
2987 if (dsi->status.lphs == DSI_LPHS_IN_HS_MODE &&
2988 dsi->driven_mode == driven_mode)
2991 dsi->driven_mode = driven_mode;
2993 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
2994 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
2996 if ((dsi->status.clk_out == DSI_PHYCLK_OUT_EN) &&
2997 (!dsi->info.enable_hs_clock_on_lp_cmd_mode))
2998 tegra_dsi_hs_clk_out_disable(dc, dsi);
3000 if (dsi->current_dsi_clk_khz != dsi->target_hs_clk_khz) {
3001 tegra_dsi_set_dsi_clk(dc, dsi, dsi->target_hs_clk_khz);
3002 tegra_dsi_set_timeout(dsi);
3005 tegra_dsi_set_phy_timing(dsi, DSI_LPHS_IN_HS_MODE);
3007 if (driven_mode == TEGRA_DSI_DRIVEN_BY_DC) {
3008 tegra_dsi_set_pkt_seq(dc, dsi);
3009 tegra_dsi_set_pkt_length(dc, dsi);
3010 tegra_dsi_set_sol_delay(dc, dsi);
3011 tegra_dsi_set_dc_clk(dc, dsi);
3014 tegra_dsi_set_control_reg_hs(dsi, driven_mode);
3016 if (dsi->info.ganged_type)
3017 tegra_dsi_ganged(dc, dsi);
3019 if (dsi->status.clk_out == DSI_PHYCLK_OUT_DIS ||
3020 dsi->info.enable_hs_clock_on_lp_cmd_mode)
3021 tegra_dsi_hs_clk_out_enable(dsi);
3023 dsi->status.lphs = DSI_LPHS_IN_HS_MODE;
3025 dsi->status.lp_op = DSI_LP_OP_NOT_INIT;
3031 static bool tegra_dsi_write_busy(struct tegra_dc_dsi_data *dsi, u8 link_id)
3036 while (timeout <= DSI_MAX_COMMAND_DELAY_USEC) {
3037 if (!(DSI_TRIGGER_HOST_TRIGGER(0x1) &
3038 tegra_dsi_controller_readl(dsi,
3039 DSI_TRIGGER, link_id))) {
3043 udelay(DSI_COMMAND_DELAY_STEPS_USEC);
3044 timeout += DSI_COMMAND_DELAY_STEPS_USEC;
3050 static bool tegra_dsi_read_busy(struct tegra_dc_dsi_data *dsi, u8 link_id)
3055 while (timeout < DSI_STATUS_POLLING_DURATION_USEC) {
3056 if (!(DSI_HOST_DSI_CONTROL_IMM_BTA(0x1) &
3057 tegra_dsi_controller_readl(dsi,
3058 DSI_HOST_DSI_CONTROL, link_id))) {
3062 udelay(DSI_STATUS_POLLING_DELAY_USEC);
3063 timeout += DSI_STATUS_POLLING_DELAY_USEC;
3069 static bool tegra_dsi_host_busy(struct tegra_dc_dsi_data *dsi, u8 link_id)
3073 if (tegra_dsi_write_busy(dsi, link_id)) {
3075 dev_err(&dsi->dc->ndev->dev,
3076 "DSI trigger bit already set\n");
3080 if (tegra_dsi_read_busy(dsi, link_id)) {
3082 dev_err(&dsi->dc->ndev->dev,
3083 "DSI immediate bta bit already set\n");
3087 return (err < 0 ? true : false);
3090 static void tegra_dsi_reset_read_count(struct tegra_dc_dsi_data *dsi)
3094 val = tegra_dsi_readl(dsi, DSI_STATUS);
3095 val &= DSI_STATUS_RD_FIFO_COUNT(0x1f);
3097 dev_warn(&dsi->dc->ndev->dev,
3098 "DSI read count not zero, resetting\n");
3099 tegra_dsi_soft_reset(dsi);
3103 static struct dsi_status *tegra_dsi_save_state_switch_to_host_cmd_mode(
3104 struct tegra_dc_dsi_data *dsi,
3105 struct tegra_dc *dc,
3108 struct dsi_status *init_status = NULL;
3111 if (dsi->status.init != DSI_MODULE_INIT ||
3112 dsi->status.lphs == DSI_LPHS_NOT_INIT) {
3117 init_status = kzalloc(sizeof(*init_status), GFP_KERNEL);
3119 return ERR_PTR(-ENOMEM);
3121 *init_status = dsi->status;
3123 if (dsi->info.hs_cmd_mode_supported) {
3124 err = tegra_dsi_set_to_hs_mode(dc, dsi,
3125 TEGRA_DSI_DRIVEN_BY_HOST);
3127 dev_err(&dc->ndev->dev,
3128 "Switch to HS host mode failed\n");
3135 if (dsi->status.lp_op != lp_op) {
3136 err = tegra_dsi_set_to_lp_mode(dc, dsi, lp_op);
3138 dev_err(&dc->ndev->dev,
3139 "DSI failed to go to LP mode\n");
3147 return ERR_PTR(err);
3150 static struct dsi_status *tegra_dsi_prepare_host_transmission(
3151 struct tegra_dc *dc,
3152 struct tegra_dc_dsi_data *dsi,
3157 struct dsi_status *init_status;
3158 bool restart_dc_stream = false;
3160 if (dsi->status.init != DSI_MODULE_INIT ||
3166 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE) {
3167 restart_dc_stream = true;
3168 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
3171 for (i = 0; i < dsi->max_instances; i++) {
3172 if (tegra_dsi_host_busy(dsi, i)) {
3173 tegra_dsi_soft_reset(dsi);
3174 if (tegra_dsi_host_busy(dsi, i)) {
3176 dev_err(&dc->ndev->dev, "DSI host busy\n");
3182 if (lp_op == DSI_LP_OP_READ)
3183 tegra_dsi_reset_read_count(dsi);
3185 if (dsi->status.lphs == DSI_LPHS_NOT_INIT) {
3186 err = tegra_dsi_set_to_lp_mode(dc, dsi, lp_op);
3188 dev_err(&dc->ndev->dev, "Failed to config LP write\n");
3193 init_status = tegra_dsi_save_state_switch_to_host_cmd_mode
3195 if (IS_ERR_OR_NULL(init_status)) {
3196 err = PTR_ERR(init_status);
3197 dev_err(&dc->ndev->dev, "DSI state saving failed\n");
3201 if (restart_dc_stream)
3202 init_status->dc_stream = DSI_DC_STREAM_ENABLE;
3204 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
3205 if (atomic_read(&dsi_syncpt_rst))
3206 tegra_dsi_syncpt_reset(dsi);
3210 return ERR_PTR(err);
3213 static int tegra_dsi_restore_state(struct tegra_dc *dc,
3214 struct tegra_dc_dsi_data *dsi,
3215 struct dsi_status *init_status)
3219 if (init_status->lphs == DSI_LPHS_IN_LP_MODE) {
3220 err = tegra_dsi_set_to_lp_mode(dc, dsi, init_status->lp_op);
3222 dev_err(&dc->ndev->dev,
3223 "Failed to config LP mode\n");
3229 if (init_status->lphs == DSI_LPHS_IN_HS_MODE) {
3230 u8 driven = (init_status->driven == DSI_DRIVEN_MODE_DC) ?
3231 TEGRA_DSI_DRIVEN_BY_DC : TEGRA_DSI_DRIVEN_BY_HOST;
3232 err = tegra_dsi_set_to_hs_mode(dc, dsi, driven);
3234 dev_err(&dc->ndev->dev, "Failed to config HS mode\n");
3239 if (init_status->dc_stream == DSI_DC_STREAM_ENABLE)
3240 tegra_dsi_start_dc_stream(dc, dsi);
3247 static int tegra_dsi_host_trigger(struct tegra_dc_dsi_data *dsi, u8 link_id)
3251 if (tegra_dsi_controller_readl(dsi, DSI_TRIGGER, link_id)) {
3256 tegra_dsi_controller_writel(dsi,
3257 DSI_TRIGGER_HOST_TRIGGER(TEGRA_DSI_ENABLE),
3258 DSI_TRIGGER, link_id);
3260 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS) {
3261 status = tegra_dsi_syncpt(dsi, link_id);
3263 dev_err(&dsi->dc->ndev->dev,
3264 "DSI syncpt for host trigger failed\n");
3268 if (tegra_dsi_write_busy(dsi, link_id)) {
3270 dev_err(&dsi->dc->ndev->dev,
3271 "Timeout waiting on write completion\n");
3279 static int _tegra_dsi_controller_write_data(struct tegra_dc_dsi_data *dsi,
3280 struct tegra_dsi_cmd *cmd, int link_id)
3285 u8 *pdata = cmd->pdata;
3286 u8 data_id = cmd->data_id;
3287 u16 data_len = cmd->sp_len_dly.data_len;
3291 if (!dsi->info.ganged_type && link_id == TEGRA_DSI_LINK1) {
3292 dev_err(&dsi->dc->ndev->dev, "DSI invalid command\n");
3296 virtual_channel = dsi->info.virtual_channel <<
3297 DSI_VIR_CHANNEL_BIT_POSITION;
3299 /* always use hw for ecc */
3300 val = (virtual_channel | data_id) << 0 |
3302 tegra_dsi_controller_writel(dsi, val, DSI_WR_DATA, link_id);
3304 /* if pdata != NULL, pkt type is long pkt */
3305 if (pdata != NULL) {
3307 if (data_len >= 4) {
3308 val = ((u32 *) pdata)[0];
3313 memcpy(&val, pdata, data_len);
3317 tegra_dsi_controller_writel(dsi, val,
3318 DSI_WR_DATA, link_id);
3322 if (cmd->cmd_type != TEGRA_DSI_PACKET_VIDEO_VBLANK_CMD) {
3323 err = tegra_dsi_host_trigger(dsi, link_id);
3325 dev_err(&dsi->dc->ndev->dev, "DSI host trigger failed\n");
3331 static int _tegra_dsi_write_data(struct tegra_dc_dsi_data *dsi,
3332 struct tegra_dsi_cmd *cmd)
3336 if (dsi->info.ganged_type && dsi->info.ganged_write_to_all_links)
3337 for (i = 0; i < dsi->max_instances; i++) {
3338 err = _tegra_dsi_controller_write_data(dsi, cmd, i);
3343 err = _tegra_dsi_controller_write_data(dsi, cmd, cmd->link_id);
3348 static void tegra_dc_dsi_hold_host(struct tegra_dc *dc)
3350 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
3352 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_LP_MODE) {
3353 atomic_inc(&dsi->host_ref);
3354 tegra_dsi_host_resume(dc);
3358 static void tegra_dc_dsi_release_host(struct tegra_dc *dc)
3360 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
3362 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_LP_MODE) {
3363 atomic_dec(&dsi->host_ref);
3365 if (!atomic_read(&dsi->host_ref) &&
3366 (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE))
3367 schedule_delayed_work(&dsi->idle_work, dsi->idle_delay);
3371 static void tegra_dc_dsi_idle_work(struct work_struct *work)
3373 struct tegra_dc_dsi_data *dsi = container_of(
3374 to_delayed_work(work), struct tegra_dc_dsi_data, idle_work);
3376 if (dsi->dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_LP_MODE)
3377 tegra_dsi_host_suspend(dsi->dc);
3380 static int tegra_dsi_write_data_nosync(struct tegra_dc *dc,
3381 struct tegra_dc_dsi_data *dsi,
3382 struct tegra_dsi_cmd *cmd, u8 delay_ms)
3385 int restore_err = 0;
3386 struct dsi_status *init_status;
3388 init_status = tegra_dsi_prepare_host_transmission(
3389 dc, dsi, DSI_LP_OP_WRITE);
3390 if (IS_ERR_OR_NULL(init_status)) {
3391 err = PTR_ERR(init_status);
3392 dev_err(&dc->ndev->dev, "DSI host config failed\n");
3396 err = _tegra_dsi_write_data(dsi, cmd);
3398 dev_err(&dc->ndev->dev, "Failed DSI write\n");
3399 restore_err = tegra_dsi_restore_state(dc, dsi, init_status);
3400 if (restore_err < 0)
3401 dev_err(&dc->ndev->dev, "Failed to restore prev state\n");
3407 err = tegra_dsi_restore_state(dc, dsi, init_status);
3409 dev_err(&dc->ndev->dev, "Failed to restore prev state\n");
3415 int tegra_dsi_write_data(struct tegra_dc *dc,
3416 struct tegra_dc_dsi_data *dsi,
3417 struct tegra_dsi_cmd *cmd, u8 delay_ms)
3421 tegra_dc_io_start(dc);
3422 tegra_dc_dsi_hold_host(dc);
3424 err = tegra_dsi_write_data_nosync(dc, dsi, cmd, delay_ms);
3426 tegra_dc_dsi_release_host(dc);
3427 tegra_dc_io_end(dc);
3432 EXPORT_SYMBOL(tegra_dsi_write_data);
3434 int tegra_dsi_start_host_cmd_v_blank_video(struct tegra_dc_dsi_data *dsi,
3435 struct tegra_dsi_cmd *cmd, u8 clubbed_cmd_no)
3437 struct tegra_dc *dc = dsi->dc;
3442 if (!dsi->enabled) {
3443 dev_err(&dsi->dc->ndev->dev, "DSI controller suspended\n");
3447 tegra_dc_io_start(dc);
3448 tegra_dc_dsi_hold_host(dc);
3450 val = (DSI_CMD_PKT_VID_ENABLE(1) | DSI_LINE_TYPE(4));
3451 tegra_dsi_writel(dsi, val, DSI_VID_MODE_CONTROL);
3453 for (i = 0; i < clubbed_cmd_no; i++)
3454 _tegra_dsi_write_data(dsi, &cmd[i]);
3456 _tegra_dsi_write_data(dsi, &cmd[0]);
3458 if (dsi->status.lphs != DSI_LPHS_IN_HS_MODE) {
3459 err = tegra_dsi_set_to_hs_mode(dc, dsi,
3460 TEGRA_DSI_DRIVEN_BY_DC);
3462 dev_err(&dc->ndev->dev,
3463 "dsi: not able to set to hs mode\n");
3468 tegra_dsi_start_dc_stream(dc, dsi);
3469 tegra_dsi_wait_frame_end(dc, dsi, 2);
3471 tegra_dc_dsi_release_host(dc);
3472 tegra_dc_io_end(dc);
3476 EXPORT_SYMBOL(tegra_dsi_start_host_cmd_v_blank_video);
3478 int tegra_dsi_end_host_cmd_v_blank_video(struct tegra_dc *dc,
3479 struct tegra_dc_dsi_data *dsi)
3481 if (!dsi->enabled) {
3482 dev_err(&dsi->dc->ndev->dev, "DSI controller suspended\n");
3486 tegra_dc_io_start(dc);
3487 tegra_dsi_writel(dsi, 0, DSI_VID_MODE_CONTROL);
3488 tegra_dc_io_end(dc);
3492 EXPORT_SYMBOL(tegra_dsi_end_host_cmd_v_blank_video);
3494 int tegra_dsi_send_panel_cmd(struct tegra_dc *dc,
3495 struct tegra_dc_dsi_data *dsi,
3496 struct tegra_dsi_cmd *cmd,
3499 #define DEFAULT_DELAY_MS 1
3506 for (i = 0; i < n_cmd; i++) {
3507 struct tegra_dsi_cmd *cur_cmd;
3510 if (cur_cmd->cmd_type == TEGRA_DSI_GPIO_SET) {
3511 gpio_set_value(cur_cmd->sp_len_dly.gpio,
3513 } else if (cur_cmd->cmd_type == TEGRA_DSI_DELAY_MS) {
3514 usleep_range(cur_cmd->sp_len_dly.delay_ms * 1000,
3515 (cur_cmd->sp_len_dly.delay_ms * 1000) + 500);
3516 } else if (cur_cmd->cmd_type == TEGRA_DSI_SEND_FRAME) {
3517 tegra_dsi_send_dc_frames(dc,
3519 cur_cmd->sp_len_dly.frame_cnt);
3520 } else if (cur_cmd->cmd_type ==
3521 TEGRA_DSI_PACKET_VIDEO_VBLANK_CMD) {
3523 for (j = i; j < n_cmd; j++) {
3524 if (!IS_DSI_SHORT_PKT(cmd[j]))
3526 if (cmd[j].club_cmd != CMD_CLUBBED)
3528 if (j - i + 1 > DSI_HOST_FIFO_DEPTH)
3531 /* i..j-1: clubbable streak */
3532 tegra_dsi_start_host_cmd_v_blank_video(dsi, cur_cmd,
3534 tegra_dsi_end_host_cmd_v_blank_video(dc, dsi);
3538 delay_ms = DEFAULT_DELAY_MS;
3539 if ((i + 1 < n_cmd) &&
3540 (cmd[i + 1].cmd_type == TEGRA_DSI_DELAY_MS)) {
3541 delay_ms = cmd[i + 1].sp_len_dly.delay_ms;
3544 retry_count = DSI_WRITE_DATA_RETRY_ATTEMPTS;
3546 err = tegra_dsi_write_data_nosync(dc, dsi,
3550 dev_err(&dsi->dc->ndev->dev,
3551 "dsi: %s failed, retrying...\n",__func__);
3555 } while (retry_count);
3559 #undef DEFAULT_DELAY_MS
3562 static u8 tegra_dsi_ecc(u32 header)
3564 char ecc_parity[24] = {
3565 0x07, 0x0b, 0x0d, 0x0e, 0x13, 0x15, 0x16, 0x19,
3566 0x1a, 0x1c, 0x23, 0x25, 0x26, 0x29, 0x2a, 0x2c,
3567 0x31, 0x32, 0x34, 0x38, 0x1f, 0x2f, 0x37, 0x3b
3573 for (i = 0; i < 24; i++)
3574 ecc_byte ^= ((header >> i) & 1) ? ecc_parity[i] : 0x00;
3579 static u16 tegra_dsi_cs(char *pdata, u16 data_len)
3588 for (byte_cnt = 0; byte_cnt < data_len; byte_cnt++) {
3589 curr_byte = pdata[byte_cnt];
3590 for (bit_cnt = 0; bit_cnt < 8; bit_cnt++) {
3591 if (((crc & 0x0001) ^
3592 (curr_byte & 0x0001)) > 0)
3593 crc = ((crc >> 1) & 0x7FFF) ^ poly;
3595 crc = (crc >> 1) & 0x7FFF;
3597 curr_byte = (curr_byte >> 1) & 0x7F;
3604 static int tegra_dsi_dcs_pkt_seq_ctrl_init(struct tegra_dc_dsi_data *dsi,
3605 struct tegra_dsi_cmd *cmd)
3609 u16 data_len = cmd->sp_len_dly.data_len;
3610 u8 seq_ctrl_reg = 0;
3612 virtual_channel = dsi->info.virtual_channel <<
3613 DSI_VIR_CHANNEL_BIT_POSITION;
3615 val = (virtual_channel | cmd->data_id) << 0 |
3618 val |= tegra_dsi_ecc(val) << 24;
3620 tegra_dsi_writel(dsi, val, DSI_INIT_SEQ_DATA_0 + seq_ctrl_reg++);
3622 /* if pdata != NULL, pkt type is long pkt */
3623 if (cmd->pdata != NULL) {
3626 /* allocate memory for pdata + 2 bytes checksum */
3627 pdata_mem = kzalloc(sizeof(u8) * data_len + 2, GFP_KERNEL);
3629 dev_err(&dsi->dc->ndev->dev, "dsi: memory err\n");
3630 tegra_dsi_soft_reset(dsi);
3634 memcpy(pdata_mem, cmd->pdata, data_len);
3636 *((u16 *)(pdata + data_len)) = tegra_dsi_cs(pdata, data_len);
3638 /* data_len = length of pdata + 2 byte checksum */
3642 if (data_len >= 4) {
3643 val = ((u32 *) pdata)[0];
3648 memcpy(&val, pdata, data_len);
3652 tegra_dsi_writel(dsi, val, DSI_INIT_SEQ_DATA_0 +
3661 int tegra_dsi_start_host_cmd_v_blank_dcs(struct tegra_dc_dsi_data *dsi,
3662 struct tegra_dsi_cmd *cmd)
3664 #define PKT_HEADER_LEN_BYTE 4
3665 #define CHECKSUM_LEN_BYTE 2
3669 u16 tot_pkt_len = PKT_HEADER_LEN_BYTE;
3670 struct tegra_dc *dc = dsi->dc;
3672 if (cmd->cmd_type != TEGRA_DSI_PACKET_CMD)
3675 mutex_lock(&dsi->lock);
3676 tegra_dc_io_start(dc);
3677 tegra_dc_dsi_hold_host(dc);
3679 #if DSI_USE_SYNC_POINTS
3680 atomic_set(&dsi_syncpt_rst, 1);
3683 err = tegra_dsi_dcs_pkt_seq_ctrl_init(dsi, cmd);
3685 dev_err(&dsi->dc->ndev->dev,
3686 "dsi: dcs pkt seq ctrl init failed\n");
3691 u16 data_len = cmd->sp_len_dly.data_len;
3692 tot_pkt_len += data_len + CHECKSUM_LEN_BYTE;
3695 val = DSI_INIT_SEQ_CONTROL_DSI_FRAME_INIT_BYTE_COUNT(tot_pkt_len) |
3696 DSI_INIT_SEQ_CONTROL_DSI_SEND_INIT_SEQUENCE(
3698 tegra_dsi_writel(dsi, val, DSI_INIT_SEQ_CONTROL);
3701 tegra_dc_dsi_release_host(dc);
3702 tegra_dc_io_end(dc);
3703 mutex_unlock(&dsi->lock);
3706 #undef PKT_HEADER_LEN_BYTE
3707 #undef CHECKSUM_LEN_BYTE
3709 EXPORT_SYMBOL(tegra_dsi_start_host_cmd_v_blank_dcs);
3711 void tegra_dsi_stop_host_cmd_v_blank_dcs(struct tegra_dc_dsi_data *dsi)
3713 struct tegra_dc *dc = dsi->dc;
3716 mutex_lock(&dsi->lock);
3717 tegra_dc_io_start(dc);
3718 tegra_dc_dsi_hold_host(dc);
3720 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
3721 if (atomic_read(&dsi_syncpt_rst)) {
3722 tegra_dsi_wait_frame_end(dc, dsi, 2);
3723 tegra_dsi_syncpt_reset(dsi);
3724 atomic_set(&dsi_syncpt_rst, 0);
3727 tegra_dsi_writel(dsi, TEGRA_DSI_DISABLE, DSI_INIT_SEQ_CONTROL);
3729 /* clear seq data registers */
3730 for (cnt = 0; cnt < 8; cnt++)
3731 tegra_dsi_writel(dsi, 0, DSI_INIT_SEQ_DATA_0 + cnt);
3733 tegra_dc_dsi_release_host(dc);
3734 tegra_dc_io_end(dc);
3736 mutex_unlock(&dsi->lock);
3738 EXPORT_SYMBOL(tegra_dsi_stop_host_cmd_v_blank_dcs);
3740 static int tegra_dsi_bta(struct tegra_dc_dsi_data *dsi)
3745 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
3746 val |= DSI_HOST_DSI_CONTROL_IMM_BTA(TEGRA_DSI_ENABLE);
3748 if (dsi->info.ganged_type && dsi->info.ganged_write_to_all_links)
3749 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
3751 tegra_dsi_controller_writel(dsi, val,
3752 DSI_HOST_DSI_CONTROL, TEGRA_DSI_LINK0);
3754 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS) {
3755 err = tegra_dsi_syncpt(dsi, TEGRA_DSI_LINK0);
3757 dev_err(&dsi->dc->ndev->dev,
3758 "DSI syncpt for bta failed\n");
3761 if (tegra_dsi_read_busy(dsi, TEGRA_DSI_LINK0)) {
3763 dev_err(&dsi->dc->ndev->dev,
3764 "Timeout wating on read completion\n");
3771 static int tegra_dsi_parse_read_response(struct tegra_dc *dc,
3772 u32 rd_fifo_cnt, u8 *read_fifo)
3780 switch (read_fifo[0]) {
3781 case DSI_ESCAPE_CMD:
3782 dev_info(&dc->ndev->dev, "escape cmd[0x%x]\n", read_fifo[0]);
3784 case DSI_ACK_NO_ERR:
3785 dev_info(&dc->ndev->dev,
3786 "Panel ack, no err[0x%x]\n", read_fifo[0]);
3789 dev_info(&dc->ndev->dev, "Invalid read response\n");
3793 switch (read_fifo[4] & 0xff) {
3794 case GEN_LONG_RD_RES:
3796 case DCS_LONG_RD_RES:
3797 payload_size = (read_fifo[5] |
3798 (read_fifo[6] << 8)) & 0xFFFF;
3799 dev_info(&dc->ndev->dev, "Long read response Packet\n"
3800 "payload_size[0x%x]\n", payload_size);
3802 case GEN_1_BYTE_SHORT_RD_RES:
3804 case DCS_1_BYTE_SHORT_RD_RES:
3806 dev_info(&dc->ndev->dev, "Short read response Packet\n"
3807 "payload_size[0x%x]\n", payload_size);
3809 case GEN_2_BYTE_SHORT_RD_RES:
3811 case DCS_2_BYTE_SHORT_RD_RES:
3813 dev_info(&dc->ndev->dev, "Short read response Packet\n"
3814 "payload_size[0x%x]\n", payload_size);
3818 dev_info(&dc->ndev->dev, "Acknowledge error report response\n"
3819 "Packet payload_size[0x%x]\n", payload_size);
3822 dev_info(&dc->ndev->dev, "Invalid response packet\n");
3829 static int tegra_dsi_read_fifo(struct tegra_dc *dc,
3830 struct tegra_dc_dsi_data *dsi,
3838 u8 *read_fifo_cp = read_fifo;
3840 while (poll_time < DSI_DELAY_FOR_READ_FIFO) {
3842 val = tegra_dsi_readl(dsi, DSI_STATUS);
3843 rd_fifo_cnt = val & DSI_STATUS_RD_FIFO_COUNT(0x1f);
3844 if (rd_fifo_cnt << 2 > DSI_READ_FIFO_DEPTH) {
3845 dev_err(&dc->ndev->dev,
3846 "DSI RD_FIFO_CNT is greater than RD_FIFO_DEPTH\n");
3852 if (rd_fifo_cnt == 0) {
3853 dev_info(&dc->ndev->dev,
3854 "DSI RD_FIFO_CNT is zero\n");
3859 if (val & (DSI_STATUS_LB_UNDERFLOW(0x1) |
3860 DSI_STATUS_LB_OVERFLOW(0x1))) {
3861 dev_warn(&dc->ndev->dev,
3862 "DSI overflow/underflow error\n");
3865 /* Read data from FIFO */
3866 for (i = 0; i < rd_fifo_cnt; i++) {
3867 val = tegra_dsi_readl(dsi, DSI_RD_DATA);
3868 if (enable_read_debug)
3869 dev_info(&dc->ndev->dev,
3870 "Read data[%d]: 0x%x\n", i, val);
3871 memcpy(read_fifo, &val, 4);
3875 /* Make sure all the data is read from the FIFO */
3876 val = tegra_dsi_readl(dsi, DSI_STATUS);
3877 val &= DSI_STATUS_RD_FIFO_COUNT(0x1f);
3879 dev_err(&dc->ndev->dev, "DSI FIFO_RD_CNT not zero"
3880 " even after reading FIFO_RD_CNT words from read fifo\n");
3882 if (enable_read_debug) {
3884 tegra_dsi_parse_read_response(dc, rd_fifo_cnt, read_fifo_cp);
3886 dev_warn(&dc->ndev->dev, "Unexpected read data\n");
3892 int tegra_dsi_read_data(struct tegra_dc *dc,
3893 struct tegra_dc_dsi_data *dsi,
3894 u16 max_ret_payload_size,
3895 u8 panel_reg_addr, u8 *read_data)
3898 struct dsi_status *init_status;
3899 static struct tegra_dsi_cmd temp_cmd;
3901 if (!dsi->enabled) {
3902 dev_err(&dc->ndev->dev, "DSI controller suspended\n");
3905 tegra_dc_dsi_hold_host(dc);
3906 mutex_lock(&dsi->lock);
3907 tegra_dc_io_start(dc);
3908 tegra_disp_clk_prepare_enable(dsi->dsi_fixed_clk);
3909 tegra_dsi_lp_clk_enable(dsi);
3910 init_status = tegra_dsi_prepare_host_transmission(
3911 dc, dsi, DSI_LP_OP_WRITE);
3912 if (IS_ERR_OR_NULL(init_status)) {
3913 err = PTR_ERR(init_status);
3914 dev_err(&dc->ndev->dev, "DSI host config failed\n");
3918 /* Set max return payload size in words */
3919 temp_cmd.data_id = dsi_command_max_return_pkt_size;
3920 temp_cmd.sp_len_dly.data_len = max_ret_payload_size;
3921 err = _tegra_dsi_write_data(dsi, &temp_cmd);
3923 dev_err(&dc->ndev->dev,
3924 "DSI write failed\n");
3928 /* DCS to read given panel register */
3929 temp_cmd.data_id = dsi_command_dcs_read_with_no_params;
3930 temp_cmd.sp_len_dly.sp.data0 = panel_reg_addr;
3931 temp_cmd.sp_len_dly.sp.data1 = 0;
3932 err = _tegra_dsi_write_data(dsi, &temp_cmd);
3934 dev_err(&dc->ndev->dev,
3935 "DSI write failed\n");
3939 tegra_dsi_reset_read_count(dsi);
3941 if (dsi->status.lp_op == DSI_LP_OP_WRITE) {
3942 err = tegra_dsi_set_to_lp_mode(dc, dsi, DSI_LP_OP_READ);
3944 dev_err(&dc->ndev->dev,
3945 "DSI failed to go to LP read mode\n");
3950 err = tegra_dsi_bta(dsi);
3952 dev_err(&dc->ndev->dev,
3953 "DSI IMM BTA timeout\n");
3957 err = tegra_dsi_read_fifo(dc, dsi, read_data);
3959 dev_err(&dc->ndev->dev, "DSI read fifo failure\n");
3963 err = tegra_dsi_restore_state(dc, dsi, init_status);
3965 dev_err(&dc->ndev->dev, "Failed to restore prev state\n");
3966 tegra_dsi_lp_clk_disable(dsi);
3967 tegra_disp_clk_disable_unprepare(dsi->dsi_fixed_clk);
3968 tegra_dc_io_end(dc);
3969 mutex_unlock(&dsi->lock);
3970 tegra_dc_dsi_release_host(dc);
3973 EXPORT_SYMBOL(tegra_dsi_read_data);
3975 static const char * const error_sanity[] = {
3979 "Escape Mode Entry Comand Error",
3980 "Low-Power Transmit Sync Error",
3981 "HS Receive Timeout Error",
3982 "False Control Error",
3984 "ECC Error,Single Bit",
3985 "ECC Error, Multi Bit",
3987 "DSI Data Type Not recognized",
3988 "DSI VC ID Invalid",
3989 "DSI Protocol Violation",
3994 int tegra_dsi_panel_sanity_check(struct tegra_dc *dc,
3995 struct tegra_dc_dsi_data *dsi,
3996 struct sanity_status *san)
4000 u8 read_fifo[DSI_READ_FIFO_DEPTH];
4001 struct dsi_status *init_status;
4002 static struct tegra_dsi_cmd dsi_nop_cmd =
4003 DSI_CMD_SHORT(0x05, 0x0, 0x0);
4005 if (!dsi->enabled) {
4006 dev_err(&dc->ndev->dev, "DSI controller suspended\n");
4009 tegra_dc_dsi_hold_host(dc);
4010 tegra_dc_io_start(dc);
4011 tegra_disp_clk_prepare_enable(dsi->dsi_fixed_clk);
4012 tegra_dsi_lp_clk_enable(dsi);
4013 memset(flagset, 0, sizeof(flagset));
4014 init_status = tegra_dsi_prepare_host_transmission(
4015 dc, dsi, DSI_LP_OP_WRITE);
4016 if (IS_ERR_OR_NULL(init_status)) {
4017 err = PTR_ERR(init_status);
4018 dev_err(&dc->ndev->dev, "DSI host config failed\n");
4022 err = _tegra_dsi_write_data(dsi, &dsi_nop_cmd);
4024 dev_err(&dc->ndev->dev, "DSI nop write failed\n");
4028 tegra_dsi_reset_read_count(dsi);
4030 if (dsi->status.lp_op == DSI_LP_OP_WRITE) {
4031 err = tegra_dsi_set_to_lp_mode(dc, dsi, DSI_LP_OP_READ);
4033 dev_err(&dc->ndev->dev,
4034 "DSI failed to go to LP read mode\n");
4039 err = tegra_dsi_bta(dsi);
4041 dev_err(&dc->ndev->dev, "DSI BTA failed\n");
4045 err = tegra_dsi_read_fifo(dc, dsi, read_fifo);
4047 dev_err(&dc->ndev->dev, "DSI read fifo failure\n");
4051 if (read_fifo[0] != DSI_ACK_NO_ERR) {
4052 if (read_fifo[4] == ACK_ERR_RES) {
4053 u16 payload = read_fifo[5] | (read_fifo[6] << 8);
4055 for (; payload; payload >>= 1, i++) {
4058 if (enable_read_debug)
4059 dev_info(&dc->ndev->dev,
4060 " %s => error flag number %d\n",
4061 error_sanity[i], i);
4065 san->sot_error = flagset[0];
4066 san->sot_sync_error = flagset[1];
4067 san->eot_sync_error = flagset[2];
4068 san->escape_mode_entry_comand_error =
4070 san->low_power_transmit_sync_error = flagset[4];
4071 san->hs_receive_timeout_error = flagset[5];
4072 san->false_control_error = flagset[6];
4073 san->reserved1 = flagset[7];
4074 san->ecc_error_single_bit = flagset[8];
4075 san->ecc_error_multi_bit = flagset[9];
4076 san->checksum_error = flagset[10];
4077 san->dsi_data_type_not_recognized = flagset[11];
4078 san->dsi_vc_id_invalid = flagset[12];
4079 san->dsi_protocol_violation = flagset[13];
4080 san->reserved2 = flagset[14];
4081 san->reserved3 = flagset[15];
4084 dev_warn(&dc->ndev->dev,
4085 "Ack no error trigger message not received\n");
4090 err = tegra_dsi_restore_state(dc, dsi, init_status);
4092 dev_err(&dc->ndev->dev, "Failed to restore prev state\n");
4093 tegra_dsi_lp_clk_disable(dsi);
4094 tegra_disp_clk_disable_unprepare(dsi->dsi_fixed_clk);
4095 tegra_dc_io_end(dc);
4096 tegra_dc_dsi_release_host(dc);
4099 EXPORT_SYMBOL(tegra_dsi_panel_sanity_check);
4101 static int tegra_dsi_enter_ulpm(struct tegra_dc_dsi_data *dsi)
4106 if (dsi->info.ulpm_not_supported)
4109 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
4110 if (atomic_read(&dsi_syncpt_rst))
4111 tegra_dsi_syncpt_reset(dsi);
4113 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
4114 val &= ~DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(3);
4115 val |= DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(ENTER_ULPM);
4116 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
4118 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS) {
4119 ret = tegra_dsi_syncpt(dsi, TEGRA_DSI_LINK0);
4121 dev_err(&dsi->dc->ndev->dev,
4122 "DSI syncpt for ulpm enter failed\n");
4126 /* TODO: Find exact delay required */
4134 static int tegra_dsi_exit_ulpm(struct tegra_dc_dsi_data *dsi)
4139 if (dsi->info.ulpm_not_supported)
4142 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
4143 if (atomic_read(&dsi_syncpt_rst))
4144 tegra_dsi_syncpt_reset(dsi);
4146 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
4147 val &= ~DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(3);
4148 val |= DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(EXIT_ULPM);
4149 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
4151 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS) {
4152 ret = tegra_dsi_syncpt(dsi, TEGRA_DSI_LINK0);
4154 dev_err(&dsi->dc->ndev->dev,
4155 "DSI syncpt for ulpm exit failed\n");
4159 /* TODO: Find exact delay required */
4164 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
4165 val &= ~DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(0x3);
4166 val |= DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(NORMAL);
4167 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
4172 static void tegra_dsi_send_dc_frames(struct tegra_dc *dc,
4173 struct tegra_dc_dsi_data *dsi,
4177 u32 frame_period = DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
4178 u8 lp_op = dsi->status.lp_op;
4179 bool switch_to_lp = (dsi->status.lphs == DSI_LPHS_IN_LP_MODE);
4181 if (dsi->status.lphs != DSI_LPHS_IN_HS_MODE) {
4182 err = tegra_dsi_set_to_hs_mode(dc, dsi,
4183 TEGRA_DSI_DRIVEN_BY_DC);
4185 dev_err(&dc->ndev->dev,
4186 "Switch to HS host mode failed\n");
4192 * Some panels need DC frames be sent under certain
4193 * conditions. We are working on the right fix for this
4194 * requirement, while using this current fix.
4196 tegra_dsi_start_dc_stream(dc, dsi);
4199 * Send frames in Continuous or One-shot mode.
4201 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_MODE) {
4202 /* FIX ME: tegra_dc_blank() implicitly takes lock */
4203 int flag = mutex_is_locked(&dc->lock);
4205 mutex_unlock(&dc->lock);
4206 while (no_of_frames--)
4207 tegra_dc_blank(dc, BLANK_ALL);
4209 mutex_lock(&dc->lock);
4211 mdelay(no_of_frames * frame_period);
4213 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
4216 err = tegra_dsi_set_to_lp_mode(dc, dsi, lp_op);
4218 dev_err(&dc->ndev->dev,
4219 "DSI failed to go to LP mode\n");
4223 static void tegra_dsi_setup_initialized_panel(struct tegra_dc_dsi_data *dsi)
4227 if (dsi->avdd_dsi_csi)
4228 err = regulator_enable(dsi->avdd_dsi_csi);
4229 WARN(err, "unable to enable regulator");
4231 dsi->status.init = DSI_MODULE_INIT;
4232 dsi->status.lphs = DSI_LPHS_IN_HS_MODE;
4233 dsi->status.driven = DSI_DRIVEN_MODE_DC;
4234 dsi->driven_mode = TEGRA_DSI_DRIVEN_BY_DC;
4235 dsi->status.clk_out = DSI_PHYCLK_OUT_EN;
4236 dsi->status.lp_op = DSI_LP_OP_NOT_INIT;
4237 dsi->status.dc_stream = DSI_DC_STREAM_ENABLE;
4239 if (dsi->info.video_clock_mode == TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS)
4240 dsi->status.clk_mode = DSI_PHYCLK_CONTINUOUS;
4242 dsi->status.clk_mode = DSI_PHYCLK_TX_ONLY;
4244 if (!(dsi->info.ganged_type)) {
4245 if (dsi->info.video_burst_mode ==
4246 TEGRA_DSI_VIDEO_NONE_BURST_MODE ||
4247 dsi->info.video_burst_mode ==
4248 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END)
4249 dsi->status.clk_burst = DSI_CLK_BURST_NONE_BURST;
4251 dsi->status.clk_burst = DSI_CLK_BURST_BURST_MODE;
4254 if (dsi->info.video_data_type == TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE)
4255 dsi->status.vtype = DSI_VIDEO_TYPE_CMD_MODE;
4257 dsi->status.vtype = DSI_VIDEO_TYPE_VIDEO_MODE;
4259 tegra_dsi_clk_enable(dsi);
4261 dsi->enabled = true;
4264 static void tegra_dc_dsi_enable(struct tegra_dc *dc)
4266 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4269 sysedp_set_state(dsi->sysedpc, 1);
4270 mutex_lock(&dsi->lock);
4271 tegra_dc_io_start(dc);
4274 * Do not program this panel as the bootloader as has already
4275 * initialized it. This avoids periods of blanking during boot.
4277 if (dc->initialized) {
4278 tegra_dsi_setup_initialized_panel(dsi);
4282 /* Stop DC stream before configuring DSI registers
4283 * to avoid visible glitches on panel during transition
4284 * from bootloader to kernel driver
4286 tegra_dsi_stop_dc_stream(dc, dsi);
4290 if (tegra_dsi_exit_ulpm(dsi) < 0) {
4291 dev_err(&dc->ndev->dev,
4292 "DSI failed to exit ulpm\n");
4297 if (dsi->info.panel_reset) {
4299 * Certain panels need dc frames be sent before
4302 if (dsi->info.panel_send_dc_frames)
4303 tegra_dsi_send_dc_frames(dc, dsi, 2);
4305 err = tegra_dsi_send_panel_cmd(dc, dsi,
4306 dsi->info.dsi_init_cmd,
4307 dsi->info.n_init_cmd);
4309 dev_err(&dc->ndev->dev,
4310 "dsi: error sending dsi init cmd\n");
4313 } else if (dsi->info.dsi_late_resume_cmd) {
4314 err = tegra_dsi_send_panel_cmd(dc, dsi,
4315 dsi->info.dsi_late_resume_cmd,
4316 dsi->info.n_late_resume_cmd);
4318 dev_err(&dc->ndev->dev,
4319 "dsi: error sending late resume cmd\n");
4324 err = tegra_dsi_init_hw(dc, dsi);
4326 dev_err(&dc->ndev->dev,
4327 "dsi: not able to init dsi hardware\n");
4332 if (tegra_dsi_enter_ulpm(dsi) < 0) {
4333 dev_err(&dc->ndev->dev,
4334 "DSI failed to enter ulpm\n");
4338 tegra_dsi_pad_enable(dsi);
4340 if (tegra_dsi_exit_ulpm(dsi) < 0) {
4341 dev_err(&dc->ndev->dev,
4342 "DSI failed to exit ulpm\n");
4348 * Certain panels need dc frames be sent before
4351 if (dsi->info.panel_send_dc_frames)
4352 tegra_dsi_send_dc_frames(dc, dsi, 2);
4354 err = tegra_dsi_set_to_lp_mode(dc, dsi, DSI_LP_OP_WRITE);
4356 dev_err(&dc->ndev->dev,
4357 "dsi: not able to set to lp mode\n");
4361 if (dsi->info.lp00_pre_panel_wakeup)
4362 tegra_dsi_pad_disable(dsi);
4364 dsi->enabled = true;
4367 if (dsi->out_ops && dsi->out_ops->enable)
4368 dsi->out_ops->enable(dsi);
4370 tegra_dc_io_end(dc);
4371 mutex_unlock(&dsi->lock);
4374 static void tegra_dc_dsi_postpoweron(struct tegra_dc *dc)
4376 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4380 * Do not configure. Use bootloader configuration.
4381 * This avoids periods of blanking during boot.
4383 if (dc->initialized)
4386 mutex_lock(&dsi->lock);
4387 tegra_dc_io_start(dc);
4390 if (dsi->info.lp00_pre_panel_wakeup)
4391 tegra_dsi_pad_enable(dsi);
4393 err = tegra_dsi_send_panel_cmd(dc, dsi, dsi->info.dsi_init_cmd,
4394 dsi->info.n_init_cmd);
4396 dev_err(&dc->ndev->dev,
4397 "dsi: error while sending dsi init cmd\n");
4401 err = tegra_dsi_set_to_hs_mode(dc, dsi,
4402 TEGRA_DSI_DRIVEN_BY_DC);
4404 dev_err(&dc->ndev->dev,
4405 "dsi: not able to set to hs mode\n");
4409 if (dsi->status.driven == DSI_DRIVEN_MODE_DC)
4410 tegra_dsi_start_dc_stream(dc, dsi);
4412 dsi->host_suspended = false;
4415 tegra_dc_io_end(dc);
4416 mutex_unlock(&dsi->lock);
4419 static void __tegra_dc_dsi_init(struct tegra_dc *dc)
4421 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4423 #ifdef CONFIG_DEBUG_FS
4424 tegra_dc_dsi_debug_create(dsi);
4427 if (dsi->info.dsi2lvds_bridge_enable)
4428 dsi->out_ops = &tegra_dsi2lvds_ops;
4429 else if (dsi->info.dsi2edp_bridge_enable)
4430 dsi->out_ops = &tegra_dsi2edp_ops;
4432 dsi->out_ops = NULL;
4434 if (dsi->out_ops && dsi->out_ops->init)
4435 dsi->out_ops->init(dsi);
4437 tegra_dsi_init_sw(dc, dsi);
4440 static int tegra_dc_dsi_cp_p_cmd(struct tegra_dsi_cmd *src,
4441 struct tegra_dsi_cmd *dst, u16 n_cmd)
4446 memcpy(dst, src, sizeof(*dst) * n_cmd);
4448 for (i = 0; i < n_cmd; i++)
4450 len = sizeof(*src[i].pdata) *
4451 src[i].sp_len_dly.data_len;
4452 dst[i].pdata = kzalloc(len, GFP_KERNEL);
4454 goto free_cmd_pdata;
4455 memcpy(dst[i].pdata, src[i].pdata, len);
4463 kfree(dst[i].pdata);
4467 static int tegra_dc_dsi_cp_info(struct tegra_dc_dsi_data *dsi,
4468 struct tegra_dsi_out *p_dsi)
4470 struct tegra_dsi_cmd *p_init_cmd;
4471 struct tegra_dsi_cmd *p_early_suspend_cmd = NULL;
4472 struct tegra_dsi_cmd *p_late_resume_cmd = NULL;
4473 struct tegra_dsi_cmd *p_suspend_cmd;
4476 if (p_dsi->n_data_lanes > MAX_DSI_DATA_LANES)
4479 p_init_cmd = kzalloc(sizeof(*p_init_cmd) *
4480 p_dsi->n_init_cmd, GFP_KERNEL);
4484 if (p_dsi->dsi_early_suspend_cmd) {
4485 p_early_suspend_cmd = kzalloc(sizeof(*p_early_suspend_cmd) *
4486 p_dsi->n_early_suspend_cmd,
4488 if (!p_early_suspend_cmd) {
4490 goto err_free_init_cmd;
4494 if (p_dsi->dsi_late_resume_cmd) {
4495 p_late_resume_cmd = kzalloc(sizeof(*p_late_resume_cmd) *
4496 p_dsi->n_late_resume_cmd,
4498 if (!p_late_resume_cmd) {
4500 goto err_free_p_early_suspend_cmd;
4504 p_suspend_cmd = kzalloc(sizeof(*p_suspend_cmd) * p_dsi->n_suspend_cmd,
4506 if (!p_suspend_cmd) {
4508 goto err_free_p_late_resume_cmd;
4511 memcpy(&dsi->info, p_dsi, sizeof(dsi->info));
4513 /* Copy panel init cmd */
4514 err = tegra_dc_dsi_cp_p_cmd(p_dsi->dsi_init_cmd,
4515 p_init_cmd, p_dsi->n_init_cmd);
4518 dsi->info.dsi_init_cmd = p_init_cmd;
4520 /* Copy panel early suspend cmd */
4521 if (p_dsi->dsi_early_suspend_cmd) {
4522 err = tegra_dc_dsi_cp_p_cmd(p_dsi->dsi_early_suspend_cmd,
4523 p_early_suspend_cmd,
4524 p_dsi->n_early_suspend_cmd);
4527 dsi->info.dsi_early_suspend_cmd = p_early_suspend_cmd;
4530 /* Copy panel late resume cmd */
4531 if (p_dsi->dsi_late_resume_cmd) {
4532 err = tegra_dc_dsi_cp_p_cmd(p_dsi->dsi_late_resume_cmd,
4534 p_dsi->n_late_resume_cmd);
4537 dsi->info.dsi_late_resume_cmd = p_late_resume_cmd;
4540 /* Copy panel suspend cmd */
4541 err = tegra_dc_dsi_cp_p_cmd(p_dsi->dsi_suspend_cmd, p_suspend_cmd,
4542 p_dsi->n_suspend_cmd);
4545 dsi->info.dsi_suspend_cmd = p_suspend_cmd;
4547 if (!dsi->info.panel_reset_timeout_msec)
4548 dsi->info.panel_reset_timeout_msec =
4549 DEFAULT_PANEL_RESET_TIMEOUT;
4550 if (!dsi->info.panel_buffer_size_byte)
4551 dsi->info.panel_buffer_size_byte = DEFAULT_PANEL_BUFFER_BYTE;
4553 if (!dsi->info.max_panel_freq_khz) {
4554 dsi->info.max_panel_freq_khz = DEFAULT_MAX_DSI_PHY_CLK_KHZ;
4556 if (dsi->info.video_burst_mode >
4557 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END){
4558 dev_err(&dsi->dc->ndev->dev, "DSI: max_panel_freq_khz"
4559 "is not set for DSI burst mode.\n");
4560 dsi->info.video_burst_mode =
4561 TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED;
4565 if (!dsi->info.lp_cmd_mode_freq_khz)
4566 dsi->info.lp_cmd_mode_freq_khz = DEFAULT_LP_CMD_MODE_CLK_KHZ;
4568 if (!dsi->info.lp_read_cmd_mode_freq_khz)
4569 dsi->info.lp_read_cmd_mode_freq_khz =
4570 dsi->info.lp_cmd_mode_freq_khz;
4572 /* host mode is for testing only */
4573 dsi->driven_mode = TEGRA_DSI_DRIVEN_BY_DC;
4577 kfree(p_suspend_cmd);
4578 err_free_p_late_resume_cmd:
4579 kfree(p_late_resume_cmd);
4580 err_free_p_early_suspend_cmd:
4581 kfree(p_early_suspend_cmd);
4587 static int _tegra_dc_dsi_init(struct tegra_dc *dc)
4589 struct tegra_dc_dsi_data *dsi;
4590 struct resource *res;
4591 struct resource *base_res;
4592 struct resource dsi_res;
4594 struct clk *dc_clk = NULL;
4595 struct clk *dsi_clk;
4596 struct clk *dsi_fixed_clk = NULL;
4597 struct clk *dsi_lp_clk = NULL;
4598 struct tegra_dsi_out *dsi_pdata = NULL;
4601 char *ganged_reg_name[2] = {"ganged_dsia_regs", "ganged_dsib_regs"};
4602 char *dsi_clk_name[2] = {"dsia", "dsib"};
4603 char *dsi_lp_clk_name[2] = {"dsialp", "dsiblp"};
4604 struct device_node *np = dc->ndev->dev.of_node;
4606 struct device_node *np_dsi =
4607 of_find_node_by_path(DSI_NODE);
4609 struct device_node *np_dsi = NULL;
4611 dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
4613 dev_err(&dc->ndev->dev, "dsi: memory allocation failed\n");
4614 of_node_put(np_dsi);
4618 dsi->max_instances = dc->out->dsi->ganged_type ? MAX_DSI_INSTANCE : 1;
4619 dsi_instance = (int)dc->out->dsi->dsi_instance;
4620 for (i = 0; i < dsi->max_instances; i++) {
4622 if (np_dsi && of_device_is_available(np_dsi)) {
4623 if (!dc->out->dsi->ganged_type)
4624 of_address_to_resource(np_dsi,
4625 dsi_instance, &dsi_res);
4626 else /* ganged type */
4627 of_address_to_resource(np_dsi,
4635 res = platform_get_resource_byname(dc->ndev,
4637 dc->out->dsi->ganged_type ?
4638 ganged_reg_name[i] : "dsi_regs");
4641 dev_err(&dc->ndev->dev, "dsi: no mem resource\n");
4646 base_res = request_mem_region(res->start, resource_size(res),
4649 dev_err(&dc->ndev->dev,
4650 "dsi: request_mem_region failed\n");
4655 base = ioremap(res->start, resource_size(res));
4657 dev_err(&dc->ndev->dev,
4658 "dsi: registers can't be mapped\n");
4660 goto err_release_regs;
4663 dsi_pdata = dc->pdata->default_out->dsi;
4665 dev_err(&dc->ndev->dev, "dsi: dsi data not available\n");
4666 goto err_release_regs;
4669 dsi_clk = dsi_pdata->dsi_instance ?
4670 clk_get(&dc->ndev->dev,
4671 dsi_clk_name[DSI_INSTANCE_1]) :
4672 clk_get(&dc->ndev->dev, dsi_clk_name[i]);
4673 dsi_lp_clk = dsi_pdata->dsi_instance ?
4674 clk_get(&dc->ndev->dev,
4675 dsi_lp_clk_name[DSI_INSTANCE_1]) :
4676 clk_get(&dc->ndev->dev, dsi_lp_clk_name[i]);
4678 if (IS_ERR_OR_NULL(dsi_clk) || IS_ERR_OR_NULL(dsi_lp_clk)) {
4679 dev_err(&dc->ndev->dev, "dsi: can't get clock\n");
4681 goto err_dsi_clk_put;
4684 dsi->base[i] = base;
4685 dsi->base_res[i] = base_res;
4686 dsi->dsi_clk[i] = dsi_clk;
4687 dsi->dsi_lp_clk[i] = dsi_lp_clk;
4690 dsi_fixed_clk = clk_get(&dc->ndev->dev, "dsi-fixed");
4692 if (IS_ERR_OR_NULL(dsi_fixed_clk)) {
4693 dev_err(&dc->ndev->dev, "dsi: can't get fixed clock\n");
4695 goto err_release_regs;
4698 dc_clk = clk_get_sys(dev_name(&dc->ndev->dev), NULL);
4699 if (IS_ERR_OR_NULL(dc_clk)) {
4700 dev_err(&dc->ndev->dev, "dsi: dc clock %s unavailable\n",
4701 dev_name(&dc->ndev->dev));
4703 goto err_dsi_fixed_clk_put;
4706 mutex_init(&dsi->lock);
4708 dsi->dc_clk = dc_clk;
4709 dsi->dsi_fixed_clk = dsi_fixed_clk;
4711 err = tegra_dc_dsi_cp_info(dsi, dsi_pdata);
4713 goto err_dc_clk_put;
4715 tegra_dc_set_outdata(dc, dsi);
4716 __tegra_dc_dsi_init(dc);
4719 * Enable DPD mode for DSI pads if required.
4721 if (!dsi->info.ganged_type &&
4722 (dsi->info.controller_vs >= DSI_VS_1)) {
4723 if (dsi->info.dpd_dsi_pads & DSI_DPD_EN)
4724 tegra_io_dpd_enable(&dsi_io);
4725 if (dsi->info.dpd_dsi_pads & DSIB_DPD_EN)
4726 tegra_io_dpd_enable(&dsib_io);
4727 if (dsi->info.dpd_dsi_pads & DSIC_DPD_EN)
4728 tegra_io_dpd_enable(&dsic_io);
4729 if (dsi->info.dpd_dsi_pads & DSID_DPD_EN)
4730 tegra_io_dpd_enable(&dsid_io);
4733 of_node_put(np_dsi);
4738 err_dsi_fixed_clk_put:
4739 clk_put(dsi_fixed_clk);
4741 for (i = 0; i < dsi->max_instances; i++) {
4742 clk_put(dsi->dsi_lp_clk[i]);
4743 clk_put(dsi->dsi_clk[i]);
4746 for (i = 0; i < dsi->max_instances; i++)
4747 release_resource(dsi->base_res[i]);
4751 of_node_put(np_dsi);
4755 static void _tegra_dc_dsi_destroy(struct tegra_dc *dc)
4757 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4761 mutex_lock(&dsi->lock);
4762 tegra_dc_io_start(dc);
4764 if (dsi->out_ops && dsi->out_ops->destroy)
4765 dsi->out_ops->destroy(dsi);
4767 /* free up the pdata */
4768 for (i = 0; i < dsi->info.n_init_cmd; i++) {
4769 if (dsi->info.dsi_init_cmd[i].pdata)
4770 kfree(dsi->info.dsi_init_cmd[i].pdata);
4772 kfree(dsi->info.dsi_init_cmd);
4774 /* Disable dc stream */
4775 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
4776 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
4778 /* Disable dsi phy clock */
4779 if (dsi->status.clk_out == DSI_PHYCLK_OUT_EN)
4780 tegra_dsi_hs_clk_out_disable(dc, dsi);
4782 val = DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE);
4783 tegra_dsi_writel(dsi, val, DSI_POWER_CONTROL);
4785 for (i = 0; i < dsi->max_instances; i++) {
4786 iounmap(dsi->base[i]);
4787 release_resource(dsi->base_res[i]);
4789 clk_put(dsi->dc_clk);
4790 for (i = 0; i < dsi->max_instances; i++)
4791 clk_put(dsi->dsi_clk[i]);
4793 tegra_dc_io_end(dc);
4794 mutex_unlock(&dsi->lock);
4795 mutex_destroy(&dsi->lock);
4799 static void tegra_dsi_config_phy_clk(struct tegra_dc_dsi_data *dsi,
4802 struct clk *parent_clk = NULL;
4803 struct clk *base_clk = NULL;
4806 for (i = 0; i < dsi->max_instances; i++) {
4807 parent_clk = clk_get_parent(dsi->dsi_clk[i]);
4808 base_clk = clk_get_parent(parent_clk);
4810 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
4811 if (dsi->info.dsi_instance)
4812 tegra_clk_cfg_ex(base_clk,
4813 TEGRA_CLK_PLLD_CSI_OUT_ENB,
4816 tegra_clk_cfg_ex(base_clk,
4817 TEGRA_CLK_PLLD_DSI_OUT_ENB,
4820 tegra_clk_cfg_ex(base_clk,
4821 TEGRA_CLK_PLLD_DSI_OUT_ENB,
4827 static int tegra_dsi_te_on_off(struct tegra_dc_dsi_data *dsi, bool flag)
4831 struct tegra_dsi_cmd te_enable[] = {
4832 DSI_CMD_SHORT(DSI_DCS_WRITE_0_PARAM,
4833 DSI_DCS_SET_TEARING_EFFECT_ON, 0x0),
4837 struct tegra_dsi_cmd te_disable[] = {
4838 DSI_CMD_SHORT(DSI_DCS_WRITE_0_PARAM,
4839 DSI_DCS_SET_TEARING_EFFECT_OFF, 0x0),
4844 ret = tegra_dsi_send_panel_cmd(dsi->dc, dsi, te_enable,
4845 ARRAY_SIZE(te_enable));
4847 ret = tegra_dsi_send_panel_cmd(dsi->dc, dsi, te_disable,
4848 ARRAY_SIZE(te_disable));
4853 static int _tegra_dsi_host_suspend(struct tegra_dc *dc,
4854 struct tegra_dc_dsi_data *dsi,
4860 switch (suspend_aggr) {
4861 case DSI_HOST_SUSPEND_LV2:
4863 err = tegra_dsi_enter_ulpm(dsi);
4865 dev_err(&dc->ndev->dev,
4866 "DSI failed to enter ulpm\n");
4871 tegra_dsi_pad_disable(dsi);
4873 /* Suspend core-logic */
4874 val = DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE);
4875 tegra_dsi_writel(dsi, val, DSI_POWER_CONTROL);
4877 /* disable HS logic */
4878 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_3_VS1);
4879 val |= DSI_PAD_PDVCLAMP(0x1);
4880 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
4883 case DSI_HOST_SUSPEND_LV1:
4884 /* Disable dsi fast and slow clock */
4885 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_DISABLE);
4887 case DSI_HOST_SUSPEND_LV0:
4888 /* Disable dsi source clock */
4889 tegra_dsi_clk_disable(dsi);
4891 case DSI_NO_SUSPEND:
4894 dev_err(&dc->ndev->dev, "DSI suspend aggressiveness"
4895 "is not supported.\n");
4898 tegra_dvfs_set_rate(dc->clk, 0);
4905 static int _tegra_dsi_host_resume(struct tegra_dc *dc,
4906 struct tegra_dc_dsi_data *dsi,
4912 switch (dsi->info.suspend_aggr) {
4913 case DSI_HOST_SUSPEND_LV0:
4914 tegra_dsi_clk_enable(dsi);
4916 case DSI_HOST_SUSPEND_LV1:
4917 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_ENABLE);
4918 tegra_dsi_clk_enable(dsi);
4920 case DSI_HOST_SUSPEND_LV2:
4921 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_ENABLE);
4922 tegra_dsi_clk_enable(dsi);
4924 /* enable HS logic */
4925 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_3_VS1);
4926 val &= ~DSI_PAD_PDVCLAMP(0x1);
4927 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
4929 tegra_dsi_writel(dsi,
4930 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_ENABLE),
4934 err = tegra_dsi_enter_ulpm(dsi);
4936 dev_err(&dc->ndev->dev,
4937 "DSI failed to enter ulpm\n");
4941 tegra_dsi_pad_enable(dsi);
4943 if (tegra_dsi_exit_ulpm(dsi) < 0) {
4944 dev_err(&dc->ndev->dev,
4945 "DSI failed to exit ulpm\n");
4949 tegra_dsi_pad_enable(dsi);
4952 case DSI_NO_SUSPEND:
4955 dev_err(&dc->ndev->dev, "DSI suspend aggressivenes"
4956 "is not supported.\n");
4959 tegra_dvfs_set_rate(dc->clk, dc->mode.pclk);
4966 static int tegra_dsi_host_suspend_trylock(struct tegra_dc *dc,
4967 struct tegra_dc_dsi_data *dsi)
4969 if (!mutex_trylock(&dc->one_shot_lock))
4971 if (!mutex_trylock(&dc->lp_lock))
4972 goto unlock_one_shot_lock;
4973 if (!mutex_trylock(&dc->lock))
4974 goto unlock_lp_lock;
4975 if (!mutex_trylock(&dsi->host_lock))
4976 goto unlock_dc_lock;
4981 mutex_unlock(&dc->lock);
4983 mutex_unlock(&dc->lp_lock);
4984 unlock_one_shot_lock:
4985 mutex_unlock(&dc->one_shot_lock);
4990 static void tegra_dsi_host_suspend_unlock(struct tegra_dc *dc,
4991 struct tegra_dc_dsi_data *dsi)
4993 mutex_unlock(&dsi->host_lock);
4994 mutex_unlock(&dc->lock);
4995 mutex_unlock(&dc->lp_lock);
4996 mutex_unlock(&dc->one_shot_lock);
4999 static int tegra_dsi_host_suspend(struct tegra_dc *dc)
5002 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
5007 while (!tegra_dsi_host_suspend_trylock(dc, dsi))
5010 if (dsi->host_suspended || atomic_read(&dsi->host_ref)) {
5011 tegra_dsi_host_suspend_unlock(dc, dsi);
5015 tegra_dc_io_start(dc);
5017 dsi->host_suspended = true;
5019 tegra_dsi_stop_dc_stream(dc, dsi);
5021 tegra_dsi_te_on_off(dsi, false);
5023 err = _tegra_dsi_host_suspend(dc, dsi, dsi->info.suspend_aggr);
5025 dev_err(&dc->ndev->dev,
5026 "DSI host suspend failed\n");
5030 /* Shutting down. Drop any reference to dc clk */
5031 while (tegra_is_clk_enabled(dc->clk))
5034 pm_runtime_put_sync(&dc->ndev->dev);
5036 tegra_dc_io_end(dc);
5037 tegra_dsi_host_suspend_unlock(dc, dsi);
5041 static bool tegra_dc_dsi_osidle(struct tegra_dc *dc)
5043 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
5045 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_MODE)
5046 return dsi->host_suspended;
5051 static void tegra_dsi_bl_off(struct backlight_device *bd)
5056 bd->props.brightness = 0;
5057 backlight_update_status(bd);
5060 static int tegra_dsi_deep_sleep(struct tegra_dc *dc,
5061 struct tegra_dc_dsi_data *dsi)
5069 cancel_delayed_work(&dsi->idle_work);
5071 tegra_dsi_bl_off(get_backlight_device_by_name(dsi->info.bl_name));
5073 /* Suspend DSI panel */
5074 err = tegra_dsi_send_panel_cmd(dc, dsi,
5075 dsi->info.dsi_suspend_cmd,
5076 dsi->info.n_suspend_cmd);
5078 err = tegra_dsi_set_to_lp_mode(dc, dsi, DSI_LP_OP_WRITE);
5080 dev_err(&dc->ndev->dev,
5081 "DSI failed to go to LP mode\n");
5086 * Certain panels need dc frames be sent after
5087 * putting panel to sleep.
5089 if (dsi->info.panel_send_dc_frames)
5090 tegra_dsi_send_dc_frames(dc, dsi, 2);
5093 err = tegra_dsi_enter_ulpm(dsi);
5095 dev_err(&dc->ndev->dev,
5096 "DSI failed to enter ulpm\n");
5101 tegra_dsi_pad_disable(dsi);
5103 /* Suspend core-logic */
5104 val = DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE);
5105 tegra_dsi_writel(dsi, val, DSI_POWER_CONTROL);
5107 /* Disable dsi fast and slow clock */
5108 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_DISABLE);
5110 /* Disable dsi source clock */
5111 tegra_dsi_clk_disable(dsi);
5113 dsi->enabled = false;
5114 dsi->host_suspended = true;
5121 static void tegra_dc_dsi_postpoweroff(struct tegra_dc *dc)
5123 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
5125 /* Do not disable regulator when device is shutting down */
5126 if (!dsi->device_shutdown && !dsi->enabled && dsi->avdd_dsi_csi)
5127 regulator_disable(dsi->avdd_dsi_csi);
5129 static void tegra_dc_dsi_shutdown(struct tegra_dc *dc)
5131 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
5133 dsi->device_shutdown = true;
5135 static int tegra_dsi_host_resume(struct tegra_dc *dc)
5138 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
5143 cancel_delayed_work(&dsi->idle_work);
5145 mutex_lock(&dsi->host_lock);
5146 if (!dsi->host_suspended) {
5147 mutex_unlock(&dsi->host_lock);
5151 tegra_dc_io_start(dc);
5153 pm_runtime_get_sync(&dc->ndev->dev);
5155 err = _tegra_dsi_host_resume(dc, dsi, dsi->info.suspend_aggr);
5157 dev_err(&dc->ndev->dev,
5158 "DSI host resume failed\n");
5162 tegra_dsi_te_on_off(dsi, true);
5164 tegra_dsi_start_dc_stream(dc, dsi);
5165 dsi->host_suspended = false;
5167 tegra_dc_io_end(dc);
5168 mutex_unlock(&dsi->host_lock);
5172 static void tegra_dc_dsi_disable(struct tegra_dc *dc)
5175 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
5177 if (dsi->host_suspended)
5178 tegra_dsi_host_resume(dc);
5180 sysedp_set_state(dsi->sysedpc, 0);
5181 mutex_lock(&dsi->lock);
5182 tegra_dc_io_start(dc);
5184 if (!dsi->info.suspend_stop_stream_late)
5185 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
5186 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
5188 if (dsi->out_ops && dsi->out_ops->disable)
5189 dsi->out_ops->disable(dsi);
5191 if (dsi->info.power_saving_suspend) {
5192 if (tegra_dsi_deep_sleep(dc, dsi) < 0) {
5193 dev_err(&dc->ndev->dev,
5194 "DSI failed to enter deep sleep\n");
5198 if (dsi->info.dsi_early_suspend_cmd) {
5199 err = tegra_dsi_send_panel_cmd(dc, dsi,
5200 dsi->info.dsi_early_suspend_cmd,
5201 dsi->info.n_early_suspend_cmd);
5203 dev_err(&dc->ndev->dev,
5204 "dsi: Error sending early suspend cmd\n");
5210 if (tegra_dsi_enter_ulpm(dsi) < 0) {
5211 dev_err(&dc->ndev->dev,
5212 "DSI failed to enter ulpm\n");
5218 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
5219 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
5222 mutex_unlock(&dsi->lock);
5223 tegra_dc_io_end(dc);
5227 static void tegra_dc_dsi_suspend(struct tegra_dc *dc)
5229 struct tegra_dc_dsi_data *dsi;
5231 dsi = tegra_dc_get_outdata(dc);
5236 if (dsi->host_suspended)
5237 tegra_dsi_host_resume(dc);
5239 tegra_dc_io_start(dc);
5240 mutex_lock(&dsi->lock);
5242 if (dsi->out_ops && dsi->out_ops->suspend)
5243 dsi->out_ops->suspend(dsi);
5245 if (!dsi->info.power_saving_suspend) {
5247 if (tegra_dsi_exit_ulpm(dsi) < 0) {
5248 dev_err(&dc->ndev->dev,
5249 "DSI failed to exit ulpm");
5254 if (tegra_dsi_deep_sleep(dc, dsi) < 0) {
5255 dev_err(&dc->ndev->dev,
5256 "DSI failed to enter deep sleep\n");
5261 mutex_unlock(&dsi->lock);
5262 tegra_dc_io_end(dc);
5265 static void tegra_dc_dsi_resume(struct tegra_dc *dc)
5267 struct tegra_dc_dsi_data *dsi;
5269 dsi = tegra_dc_get_outdata(dc);
5271 /* No dsi config required since tegra_dc_dsi_enable
5272 * will reconfigure the controller from scratch
5275 if (dsi->out_ops && dsi->out_ops->resume)
5276 dsi->out_ops->resume(dsi);
5280 static int tegra_dc_dsi_init(struct tegra_dc *dc)
5282 struct tegra_dc_dsi_data *dsi;
5283 char sysedp_name[50];
5286 err = _tegra_dc_dsi_init(dc);
5288 dev_err(&dc->ndev->dev,
5289 "dsi: Instance A init failed\n");
5293 dsi = tegra_dc_get_outdata(dc);
5295 dsi->avdd_dsi_csi = regulator_get(&dc->ndev->dev, "avdd_dsi_csi");
5296 if (IS_ERR_OR_NULL(dsi->avdd_dsi_csi)) {
5297 dev_err(&dc->ndev->dev, "dsi: avdd_dsi_csi reg get failed\n");
5302 dsi->mipi_cal = tegra_mipi_cal_init_sw(dc);
5303 if (IS_ERR(dsi->mipi_cal)) {
5304 dev_err(&dc->ndev->dev, "dsi: mipi_cal sw init failed\n");
5305 err = PTR_ERR(dsi->mipi_cal);
5309 sprintf(sysedp_name, "dsi_%d", dsi->dc->ndev->id);
5310 dsi->sysedpc = sysedp_create_consumer(sysedp_name, sysedp_name);
5314 if (dsi->avdd_dsi_csi)
5315 regulator_put(dsi->avdd_dsi_csi);
5317 _tegra_dc_dsi_destroy(dc);
5318 tegra_dc_set_outdata(dc, NULL);
5323 static void tegra_dc_dsi_destroy(struct tegra_dc *dc)
5325 struct regulator *avdd_dsi_csi;
5326 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
5328 avdd_dsi_csi = dsi->avdd_dsi_csi;
5330 _tegra_dc_dsi_destroy(dc);
5331 regulator_put(avdd_dsi_csi);
5332 tegra_mipi_cal_destroy(dc);
5335 static long tegra_dc_dsi_setup_clk(struct tegra_dc *dc, struct clk *clk)
5338 struct clk *parent_clk;
5339 struct clk *base_clk;
5340 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
5343 /* divide by 1000 to avoid overflow */
5344 dc->mode.pclk /= 1000;
5345 rate = (dc->mode.pclk * dc->shift_clk_div.mul * 2)
5346 / dc->shift_clk_div.div;
5348 dc->mode.pclk *= 1000;
5350 if (dc->initialized)
5353 if (clk == dc->clk) {
5354 parent_clk = clk_get_sys(NULL,
5355 dc->out->parent_clk ? : "pll_d_out0");
5356 base_clk = clk_get_parent(parent_clk);
5358 if (dc->pdata->default_out->dsi->dsi_instance) {
5359 parent_clk = clk_get_sys(NULL,
5360 dc->out->parent_clk ? : "pll_d2");
5361 base_clk = clk_get_parent(parent_clk);
5363 parent_clk = clk_get_sys(NULL,
5364 dc->out->parent_clk ? : "pll_d_out0");
5365 base_clk = clk_get_parent(parent_clk);
5368 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_ENABLE);
5370 if (rate != clk_get_rate(base_clk))
5371 clk_set_rate(base_clk, rate);
5373 if (clk_get_parent(clk) != parent_clk)
5374 clk_set_parent(clk, parent_clk);
5377 tegra_dvfs_set_rate(dc->clk, dc->mode.pclk);
5379 return tegra_dc_pclk_round_rate(dc, dc->mode.pclk);
5382 static void tegra_dc_dsi_vrr_enable(struct tegra_dc *dc, bool enable)
5384 struct tegra_vrr *vrr = dc->out->vrr;
5387 vrr->enable = enable;
5390 void tegra_dsi_vrr_update_monspecs(struct tegra_dc *dc,
5391 struct list_head *head)
5393 struct tegra_vrr *vrr;
5394 struct list_head *pos;
5395 struct fb_modelist *modelist;
5396 struct fb_videomode *m;
5397 struct fb_videomode m_vrr;
5399 if (!head || !head->next)
5404 if (!vrr || !vrr->capability)
5407 /* Check whether VRR modes were already added */
5408 list_for_each(pos, head) {
5409 modelist = list_entry(pos, struct fb_modelist, list);
5410 m = &modelist->mode;
5412 if (m->vmode & FB_VMODE_VRR)
5416 /* For DSI VRR, the runtime mode (as opposed to initialization
5417 * mode) is the first mode in the list. We mark that first mode
5418 * as VRR-compatible by adding FB_VMODE_VRR to a duplicated instance
5420 modelist = list_entry(head->next, struct fb_modelist, list);
5421 m = &modelist->mode;
5423 m_vrr.vmode |= FB_VMODE_VRR;
5424 fb_add_videomode(&m_vrr, head);
5427 static void tegra_dc_dsi_modeset_notifier(struct tegra_dc *dc)
5429 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
5431 if (dsi->info.ganged_type)
5432 tegra_dsi_pix_correction(dc, dsi);
5435 struct tegra_dc_out_ops tegra_dc_dsi_ops = {
5436 .init = tegra_dc_dsi_init,
5437 .destroy = tegra_dc_dsi_destroy,
5438 .enable = tegra_dc_dsi_enable,
5439 .postpoweron = tegra_dc_dsi_postpoweron,
5440 .disable = tegra_dc_dsi_disable,
5441 .postpoweroff = tegra_dc_dsi_postpoweroff,
5442 .hold = tegra_dc_dsi_hold_host,
5443 .release = tegra_dc_dsi_release_host,
5444 .shutdown = tegra_dc_dsi_shutdown,
5446 .suspend = tegra_dc_dsi_suspend,
5447 .resume = tegra_dc_dsi_resume,
5449 .setup_clk = tegra_dc_dsi_setup_clk,
5450 .osidle = tegra_dc_dsi_osidle,
5451 .vrr_enable = tegra_dc_dsi_vrr_enable,
5452 .vrr_update_monspecs = tegra_dsi_vrr_update_monspecs,
5453 .modeset_notifier = tegra_dc_dsi_modeset_notifier,