2 * drivers/video/tegra/dc/dsi.c
4 * Copyright (c) 2011-2014, NVIDIA CORPORATION, All rights reserved.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/kernel.h>
18 #include <linux/clk.h>
19 #include <linux/delay.h>
20 #include <linux/err.h>
22 #include <linux/gpio.h>
23 #include <linux/interrupt.h>
24 #include <linux/slab.h>
25 #include <linux/spinlock.h>
26 #include <linux/workqueue.h>
27 #include <linux/moduleparam.h>
28 #include <linux/export.h>
29 #include <linux/debugfs.h>
30 #include <linux/seq_file.h>
31 #include <linux/nvhost.h>
32 #include <linux/lcm.h>
33 #include <linux/gcd.h>
34 #include <linux/regulator/consumer.h>
35 #include <linux/pm_runtime.h>
36 #include <linux/clk/tegra.h>
37 #include <linux/tegra-soc.h>
38 #include <linux/nvhost.h>
39 #include <linux/of_address.h>
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 const u32 dsi_pkt_seq_reg[NUMOF_PKT_SEQ] = {
166 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 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 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 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 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 const u32 init_reg[] = {
299 DSI_INIT_SEQ_DATA_15,
314 DSI_HOST_DSI_CONTROL,
321 DSI_INIT_SEQ_CONTROL,
328 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 ret = readl(dsi->base[index] + reg * 4);
355 trace_display_readl(dsi->dc, ret, dsi->base[index] + reg * 4);
358 EXPORT_SYMBOL(tegra_dsi_controller_readl);
360 void tegra_dsi_controller_writel(struct tegra_dc_dsi_data *dsi,
361 u32 val, u32 reg, int index)
363 BUG_ON(!nvhost_module_powered_ext(dsi->dc->ndev));
364 trace_display_writel(dsi->dc, val, dsi->base[index] + reg * 4);
365 writel(val, dsi->base[index] + reg * 4);
367 EXPORT_SYMBOL(tegra_dsi_controller_writel);
369 unsigned long tegra_dsi_readl(struct tegra_dc_dsi_data *dsi, u32 reg)
372 BUG_ON(!nvhost_module_powered_ext(dsi->dc->ndev));
373 ret = readl(dsi->base[DSI_INSTANCE_0] + reg * 4);
374 trace_display_readl(dsi->dc, ret, dsi->base[DSI_INSTANCE_0] + reg * 4);
377 EXPORT_SYMBOL(tegra_dsi_readl);
379 void tegra_dsi_writel(struct tegra_dc_dsi_data *dsi, u32 val, u32 reg)
382 BUG_ON(!nvhost_module_powered_ext(dsi->dc->ndev));
383 for (i = 0; i < dsi->max_instances; i++) {
384 trace_display_writel(dsi->dc, val, dsi->base[i] + reg * 4);
385 writel(val, dsi->base[i] + reg * 4);
388 EXPORT_SYMBOL(tegra_dsi_writel);
390 inline void tegra_dsi_reset_deassert(struct tegra_dc_dsi_data *dsi)
393 for (i = 0; i < dsi->max_instances; i++)
394 tegra_periph_reset_deassert(dsi->dsi_clk[i]);
397 inline void tegra_dsi_reset_assert(struct tegra_dc_dsi_data *dsi)
400 for (i = 0; i < dsi->max_instances; i++)
401 tegra_periph_reset_assert(dsi->dsi_clk[i]);
404 static inline void tegra_dsi_lp_clk_enable(struct tegra_dc_dsi_data *dsi);
405 static inline void tegra_dsi_lp_clk_disable(struct tegra_dc_dsi_data *dsi);
407 void tegra_dsi_clk_enable(struct tegra_dc_dsi_data *dsi)
410 for (i = 0; i < dsi->max_instances; i++) {
411 clk_prepare_enable(dsi->dsi_clk[i]);
416 void tegra_dsi_clk_disable(struct tegra_dc_dsi_data *dsi)
419 for (i = 0; i < dsi->max_instances; i++) {
420 clk_disable_unprepare(dsi->dsi_clk[i]);
425 static inline void tegra_dsi_lp_clk_enable(struct tegra_dc_dsi_data *dsi)
428 for (i = 0; i < dsi->max_instances; i++) {
429 clk_prepare_enable(dsi->dsi_lp_clk[i]);
434 static inline void tegra_dsi_lp_clk_disable(struct tegra_dc_dsi_data *dsi)
437 for (i = 0; i < dsi->max_instances; i++) {
438 clk_disable_unprepare(dsi->dsi_lp_clk[i]);
443 static void tegra_dsi_setup_clk(struct tegra_dc *dc,
444 struct tegra_dc_dsi_data *dsi)
448 for (i = 0; i < dsi->max_instances; i++) {
449 tegra_dc_setup_clk(dc, dsi->dsi_clk[i]);
454 static void __maybe_unused tegra_dsi_syncpt_reset(
455 struct tegra_dc_dsi_data *dsi)
457 tegra_dsi_writel(dsi, 0x1, DSI_INCR_SYNCPT_CNTRL);
458 /* stabilization delay */
460 tegra_dsi_writel(dsi, 0x0, DSI_INCR_SYNCPT_CNTRL);
461 /* stabilization delay */
465 static int __maybe_unused tegra_dsi_syncpt
466 (struct tegra_dc_dsi_data *dsi, u8 link_id)
471 if (!nvhost_syncpt_read_ext_check(dsi->dc->ndev, dsi->syncpt_id, &val))
472 dsi->syncpt_val = val;
474 val = DSI_INCR_SYNCPT_COND(OP_DONE) |
475 DSI_INCR_SYNCPT_INDX(dsi->syncpt_id);
476 tegra_dsi_controller_writel(dsi, val, DSI_INCR_SYNCPT, link_id);
478 ret = nvhost_syncpt_wait_timeout_ext(dsi->dc->ndev, dsi->syncpt_id,
479 dsi->syncpt_val + 1, (u32)MAX_SCHEDULE_TIMEOUT, NULL, NULL);
481 dev_err(&dsi->dc->ndev->dev, "DSI sync point failure\n");
491 static u32 tegra_dsi_get_hs_clk_rate(struct tegra_dc_dsi_data *dsi)
493 u32 dsi_clock_rate_khz;
495 switch (dsi->info.video_burst_mode) {
496 case TEGRA_DSI_VIDEO_BURST_MODE_LOW_SPEED:
497 case TEGRA_DSI_VIDEO_BURST_MODE_MEDIUM_SPEED:
498 case TEGRA_DSI_VIDEO_BURST_MODE_FAST_SPEED:
499 case TEGRA_DSI_VIDEO_BURST_MODE_FASTEST_SPEED:
500 /* Calculate DSI HS clock rate for DSI burst mode */
501 dsi_clock_rate_khz = dsi->default_pixel_clk_khz *
502 dsi->shift_clk_div.mul /
503 dsi->shift_clk_div.div;
505 case TEGRA_DSI_VIDEO_NONE_BURST_MODE:
506 case TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END:
507 case TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED:
509 /* Clock rate is default DSI clock rate for non-burst mode */
510 dsi_clock_rate_khz = dsi->default_hs_clk_khz;
514 return dsi_clock_rate_khz;
517 static u32 tegra_dsi_get_lp_clk_rate(struct tegra_dc_dsi_data *dsi, u8 lp_op)
519 u32 dsi_clock_rate_khz;
521 if (dsi->info.enable_hs_clock_on_lp_cmd_mode)
522 if (dsi->info.hs_clk_in_lp_cmd_mode_freq_khz)
524 dsi->info.hs_clk_in_lp_cmd_mode_freq_khz;
526 dsi_clock_rate_khz = tegra_dsi_get_hs_clk_rate(dsi);
528 if (lp_op == DSI_LP_OP_READ)
530 dsi->info.lp_read_cmd_mode_freq_khz;
533 dsi->info.lp_cmd_mode_freq_khz;
535 return dsi_clock_rate_khz;
538 static struct tegra_dc_shift_clk_div tegra_dsi_get_shift_clk_div(
539 struct tegra_dc_dsi_data *dsi)
541 struct tegra_dc_shift_clk_div shift_clk_div;
542 struct tegra_dc_shift_clk_div max_shift_clk_div;
543 struct tegra_dc_shift_clk_div delta_shift_clk_div;
548 u32 default_hs_clk_mhz =
549 DIV_ROUND_CLOSEST(dsi->default_hs_clk_khz, 1000);
550 u32 max_panel_freq_mhz =
551 DIV_ROUND_CLOSEST(dsi->info.max_panel_freq_khz, 1000);
553 /* Get the real value of default shift_clk_div. default_shift_clk_div
554 * holds the real value of shift_clk_div.
556 shift_clk_div = dsi->default_shift_clk_div;
558 /* Calculate shift_clk_div which can match the video_burst_mode. */
559 if (dsi->info.video_burst_mode >=
560 TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED) {
561 if (max_panel_freq_mhz >= default_hs_clk_mhz) {
563 * dsi->info.max_panel_freq_khz * shift_clk_div /
564 * dsi->default_hs_clk_khz
566 max_shift_clk_div.mul = max_panel_freq_mhz *
568 max_shift_clk_div.div = default_hs_clk_mhz *
571 max_shift_clk_div = shift_clk_div;
574 burst_width = dsi->info.video_burst_mode
575 - TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED;
576 burst_width_max = TEGRA_DSI_VIDEO_BURST_MODE_FASTEST_SPEED
577 - TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED;
580 * (max_shift_clk_div - shift_clk_div) *
581 * burst_width / burst_width_max
583 temp_lcm = lcm(max_shift_clk_div.div, shift_clk_div.div);
584 delta_shift_clk_div.mul = (temp_lcm / max_shift_clk_div.div *
585 max_shift_clk_div.mul -
586 temp_lcm / shift_clk_div.div *
589 delta_shift_clk_div.div = temp_lcm * burst_width_max;
592 * shift_clk_div + delta_shift_clk_div
594 temp_lcm = lcm(shift_clk_div.div, delta_shift_clk_div.div);
595 shift_clk_div.mul = temp_lcm / shift_clk_div.div *
597 temp_lcm / delta_shift_clk_div.div *
598 delta_shift_clk_div.mul;
599 shift_clk_div.div = temp_lcm;
601 /* crunch shift clk numerator and denominator */
602 temp_gcd = gcd(shift_clk_div.mul, shift_clk_div.div);
603 shift_clk_div.mul /= temp_gcd;
604 shift_clk_div.div /= temp_gcd;
607 return shift_clk_div;
610 static void tegra_dsi_pix_correction(struct tegra_dc *dc,
611 struct tegra_dc_dsi_data *dsi)
618 h_width_pixels = dc->mode.h_back_porch + dc->mode.h_front_porch +
619 dc->mode.h_sync_width + dc->mode.h_active;
621 if (WARN(!dsi->info.n_data_lanes, "dsi n_data_lanes is 0\n"))
624 if (dsi->info.ganged_type == TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD) {
625 temp = dc->mode.h_active % dsi->info.n_data_lanes;
627 h_act_corr = dsi->info.n_data_lanes - temp;
628 h_width_pixels += h_act_corr;
632 temp = h_width_pixels % dsi->info.n_data_lanes;
634 hfp_corr = dsi->info.n_data_lanes - temp;
635 h_width_pixels += hfp_corr;
639 if (WARN(!dsi->pixel_scaler_div, "dsi pixel_scaler_div is 0"))
642 temp = (h_width_pixels * dsi->pixel_scaler_mul /
643 dsi->pixel_scaler_div) % dsi->info.n_data_lanes;
645 hfp_corr += dsi->info.n_data_lanes;
646 h_width_pixels += dsi->info.n_data_lanes;
652 dc->mode.h_front_porch += hfp_corr;
653 dc->mode.h_active += h_act_corr;
656 void tegra_dsi_init_clock_param(struct tegra_dc *dc)
665 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
667 switch (dsi->info.pixel_format) {
668 case TEGRA_DSI_PIXEL_FORMAT_16BIT_P:
669 /* 2 bytes per pixel */
670 dsi->pixel_scaler_mul = 2;
671 dsi->pixel_scaler_div = 1;
673 case TEGRA_DSI_PIXEL_FORMAT_18BIT_P:
674 /* 2.25 bytes per pixel */
675 dsi->pixel_scaler_mul = 9;
676 dsi->pixel_scaler_div = 4;
678 case TEGRA_DSI_PIXEL_FORMAT_18BIT_NP:
679 case TEGRA_DSI_PIXEL_FORMAT_24BIT_P:
680 /* 3 bytes per pixel */
681 dsi->pixel_scaler_mul = 3;
682 dsi->pixel_scaler_div = 1;
688 n_data_lanes = dsi->info.n_data_lanes;
689 if (dsi->info.ganged_type == TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT ||
690 dsi->info.ganged_type == TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD)
693 dsi->dsi_control_val =
694 DSI_CONTROL_VIRTUAL_CHANNEL(dsi->info.virtual_channel) |
695 DSI_CONTROL_NUM_DATA_LANES(n_data_lanes - 1) |
696 DSI_CONTROL_VID_SOURCE(dc->ctrl_num) |
697 DSI_CONTROL_DATA_FORMAT(dsi->info.pixel_format);
699 if (dsi->info.ganged_type)
700 tegra_dsi_pix_correction(dc, dsi);
702 /* Below we are going to calculate dsi and dc clock rate.
703 * Calcuate the horizontal and vertical width.
705 h_width_pixels = dc->mode.h_back_porch + dc->mode.h_front_porch +
706 dc->mode.h_sync_width + dc->mode.h_active;
708 v_width_lines = dc->mode.v_back_porch + dc->mode.v_front_porch +
709 dc->mode.v_sync_width + dc->mode.v_active;
711 /* Calculate minimum required pixel rate. */
712 pixel_clk_hz = h_width_pixels * v_width_lines * dsi->info.refresh_rate;
713 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_MODE) {
714 if (dsi->info.rated_refresh_rate >= dsi->info.refresh_rate)
715 dev_info(&dc->ndev->dev, "DSI: measured refresh rate "
716 "should be larger than rated refresh rate.\n");
717 dc->mode.rated_pclk = h_width_pixels * v_width_lines *
718 dsi->info.rated_refresh_rate;
721 /* Calculate minimum byte rate on DSI interface. */
722 byte_clk_hz = (pixel_clk_hz * dsi->pixel_scaler_mul) /
723 (dsi->pixel_scaler_div * dsi->info.n_data_lanes);
725 /* Round up to multiple of mega hz. */
726 plld_clk_mhz = DIV_ROUND_UP((byte_clk_hz * NUMOF_BIT_PER_BYTE),
729 /* Calculate default real shift_clk_div. */
730 dsi->default_shift_clk_div.mul = NUMOF_BIT_PER_BYTE *
731 dsi->pixel_scaler_mul;
732 dsi->default_shift_clk_div.div = 2 * dsi->pixel_scaler_div *
733 dsi->info.n_data_lanes;
736 /* Calculate default DSI hs clock. DSI interface is double data rate.
737 * Data is transferred on both rising and falling edge of clk, div by 2
738 * to get the actual clock rate.
740 dsi->default_hs_clk_khz = plld_clk_mhz * 1000 / 2;
742 dsi->default_pixel_clk_khz = (plld_clk_mhz * 1000 *
743 dsi->default_shift_clk_div.div) /
744 (2 * dsi->default_shift_clk_div.mul);
746 /* Get the actual shift_clk_div and clock rates. */
747 dsi->shift_clk_div = tegra_dsi_get_shift_clk_div(dsi);
748 dsi->target_lp_clk_khz =
749 tegra_dsi_get_lp_clk_rate(dsi, DSI_LP_OP_WRITE);
750 dsi->target_hs_clk_khz = tegra_dsi_get_hs_clk_rate(dsi);
752 dev_info(&dc->ndev->dev, "DSI: HS clock rate is %d\n",
753 dsi->target_hs_clk_khz);
756 * Force video clock to be continuous mode if
757 * enable_hs_clock_on_lp_cmd_mode is set
759 if (dsi->info.enable_hs_clock_on_lp_cmd_mode) {
760 if (dsi->info.video_clock_mode !=
761 TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS)
762 dev_warn(&dc->ndev->dev,
763 "Force clock continuous mode\n");
765 dsi->info.video_clock_mode = TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS;
769 static void tegra_dsi_init_sw(struct tegra_dc *dc,
770 struct tegra_dc_dsi_data *dsi)
773 dsi->enabled = false;
774 dsi->clk_ref = false;
776 #if DSI_USE_SYNC_POINTS
777 dsi->syncpt_id = nvhost_get_syncpt_client_managed("dsi");
780 tegra_dsi_init_clock_param(dc);
782 atomic_set(&dsi->host_ref, 0);
783 dsi->host_suspended = false;
784 mutex_init(&dsi->host_lock);
785 init_completion(&dc->out->user_vblank_comp);
786 INIT_DELAYED_WORK(&dsi->idle_work, tegra_dc_dsi_idle_work);
787 dsi->idle_delay = msecs_to_jiffies(DSI_HOST_IDLE_PERIOD);
790 #define SELECT_T_PHY(platform_t_phy_ps, default_phy, clk_ps, hw_inc) ( \
791 (platform_t_phy_ps) ? ( \
792 ((DSI_CONVERT_T_PHY_PS_TO_T_PHY(platform_t_phy_ps, clk_ps, hw_inc)) < 0 ? 0 : \
793 (DSI_CONVERT_T_PHY_PS_TO_T_PHY(platform_t_phy_ps, clk_ps, hw_inc)))) : \
794 ((default_phy) < 0 ? 0 : (default_phy)))
796 static void tegra_dsi_get_clk_phy_timing(struct tegra_dc_dsi_data *dsi,
797 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
799 phy_timing_clk->t_tlpx = SELECT_T_PHY(
800 dsi->info.phy_timing.t_tlpx_ns * 1000,
801 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
803 phy_timing_clk->t_clktrail = SELECT_T_PHY(
804 dsi->info.phy_timing.t_clktrail_ns * 1000,
805 T_CLKTRAIL_DEFAULT(clk_ps), clk_ps, T_CLKTRAIL_HW_INC);
807 phy_timing_clk->t_clkpost = SELECT_T_PHY(
808 dsi->info.phy_timing.t_clkpost_ns * 1000,
809 T_CLKPOST_DEFAULT(clk_ps), clk_ps, T_CLKPOST_HW_INC);
811 phy_timing_clk->t_clkzero = SELECT_T_PHY(
812 dsi->info.phy_timing.t_clkzero_ns * 1000,
813 T_CLKZERO_DEFAULT(clk_ps), clk_ps, T_CLKZERO_HW_INC);
815 phy_timing_clk->t_clkprepare = SELECT_T_PHY(
816 dsi->info.phy_timing.t_clkprepare_ns * 1000,
817 T_CLKPREPARE_DEFAULT(clk_ps), clk_ps, T_CLKPREPARE_HW_INC);
819 phy_timing_clk->t_clkpre = SELECT_T_PHY(
820 dsi->info.phy_timing.t_clkpre_ns * 1000,
821 T_CLKPRE_DEFAULT, clk_ps, T_CLKPRE_HW_INC);
824 static void tegra_dsi_get_hs_phy_timing(struct tegra_dc_dsi_data *dsi,
825 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
827 phy_timing_clk->t_tlpx = SELECT_T_PHY(
828 dsi->info.phy_timing.t_tlpx_ns * 1000,
829 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
831 phy_timing_clk->t_hsdexit = SELECT_T_PHY(
832 dsi->info.phy_timing.t_hsdexit_ns * 1000,
833 T_HSEXIT_DEFAULT(clk_ps), clk_ps, T_HSEXIT_HW_INC);
835 phy_timing_clk->t_hstrail = SELECT_T_PHY(
836 dsi->info.phy_timing.t_hstrail_ns * 1000,
837 T_HSTRAIL_DEFAULT(clk_ps), clk_ps, T_HSTRAIL_HW_INC);
839 phy_timing_clk->t_datzero = SELECT_T_PHY(
840 dsi->info.phy_timing.t_datzero_ns * 1000,
841 T_DATZERO_DEFAULT(clk_ps), clk_ps, T_DATZERO_HW_INC);
843 phy_timing_clk->t_hsprepare = SELECT_T_PHY(
844 dsi->info.phy_timing.t_hsprepare_ns * 1000,
845 T_HSPREPARE_DEFAULT(clk_ps), clk_ps, T_HSPREPARE_HW_INC);
848 static void tegra_dsi_get_escape_phy_timing(struct tegra_dc_dsi_data *dsi,
849 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
851 phy_timing_clk->t_tlpx = SELECT_T_PHY(
852 dsi->info.phy_timing.t_tlpx_ns * 1000,
853 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
856 static void tegra_dsi_get_bta_phy_timing(struct tegra_dc_dsi_data *dsi,
857 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
859 phy_timing_clk->t_tlpx = SELECT_T_PHY(
860 dsi->info.phy_timing.t_tlpx_ns * 1000,
861 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
863 phy_timing_clk->t_taget = SELECT_T_PHY(
864 dsi->info.phy_timing.t_taget_ns * 1000,
865 T_TAGET_DEFAULT(clk_ps), clk_ps, T_TAGET_HW_INC);
867 phy_timing_clk->t_tasure = SELECT_T_PHY(
868 dsi->info.phy_timing.t_tasure_ns * 1000,
869 T_TASURE_DEFAULT(clk_ps), clk_ps, T_TASURE_HW_INC);
871 phy_timing_clk->t_tago = SELECT_T_PHY(
872 dsi->info.phy_timing.t_tago_ns * 1000,
873 T_TAGO_DEFAULT(clk_ps), clk_ps, T_TAGO_HW_INC);
876 static void tegra_dsi_get_ulps_phy_timing(struct tegra_dc_dsi_data *dsi,
877 struct dsi_phy_timing_inclk *phy_timing_clk, u32 clk_ps)
879 phy_timing_clk->t_tlpx = SELECT_T_PHY(
880 dsi->info.phy_timing.t_tlpx_ns * 1000,
881 T_TLPX_DEFAULT(clk_ps), clk_ps, T_TLPX_HW_INC);
883 phy_timing_clk->t_wakeup = SELECT_T_PHY(
884 dsi->info.phy_timing.t_wakeup_ns * 1000,
885 T_WAKEUP_DEFAULT, clk_ps, T_WAKEUP_HW_INC);
890 static void tegra_dsi_get_phy_timing(struct tegra_dc_dsi_data *dsi,
891 struct dsi_phy_timing_inclk *phy_timing_clk,
894 if (tegra_platform_is_fpga()) {
895 clk_ps = (1000 * 1000 * 1000) / (dsi->info.fpga_freq_khz ?
896 dsi->info.fpga_freq_khz : DEFAULT_FPGA_FREQ_KHZ);
899 if (lphs == DSI_LPHS_IN_HS_MODE) {
900 tegra_dsi_get_clk_phy_timing(dsi, phy_timing_clk, clk_ps);
901 tegra_dsi_get_hs_phy_timing(dsi, phy_timing_clk, clk_ps);
903 /* default is LP mode */
904 tegra_dsi_get_escape_phy_timing(dsi, phy_timing_clk, clk_ps);
905 tegra_dsi_get_bta_phy_timing(dsi, phy_timing_clk, clk_ps);
906 tegra_dsi_get_ulps_phy_timing(dsi, phy_timing_clk, clk_ps);
907 if (dsi->info.enable_hs_clock_on_lp_cmd_mode)
908 tegra_dsi_get_clk_phy_timing(dsi,
909 phy_timing_clk, clk_ps);
913 static int tegra_dsi_mipi_phy_timing_range(struct tegra_dc_dsi_data *dsi,
914 struct dsi_phy_timing_inclk *phy_timing,
919 #define CHECK_RANGE(val, min, max) ( \
920 ((min) == NOT_DEFINED ? 0 : (val) < (min)) || \
921 ((max) == NOT_DEFINED ? 0 : (val) > (max)) ? -EINVAL : 0)
923 if (tegra_platform_is_fpga())
924 clk_ps = dsi->info.fpga_freq_khz ?
925 ((1000 * 1000 * 1000) / dsi->info.fpga_freq_khz) :
926 DEFAULT_FPGA_FREQ_KHZ;
929 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
930 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC),
931 MIPI_T_TLPX_PS_MIN, MIPI_T_TLPX_PS_MAX);
933 dev_warn(&dsi->dc->ndev->dev,
934 "dsi: Tlpx mipi range violated\n");
938 if (lphs == DSI_LPHS_IN_HS_MODE) {
940 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
941 phy_timing->t_hsdexit, clk_ps, T_HSEXIT_HW_INC),
942 MIPI_T_HSEXIT_PS_MIN, MIPI_T_HSEXIT_PS_MAX);
944 dev_warn(&dsi->dc->ndev->dev,
945 "dsi: HsExit mipi range violated\n");
950 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
951 phy_timing->t_hstrail, clk_ps, T_HSTRAIL_HW_INC),
952 MIPI_T_HSTRAIL_PS_MIN(clk_ps), MIPI_T_HSTRAIL_PS_MAX);
954 dev_warn(&dsi->dc->ndev->dev,
955 "dsi: HsTrail mipi range violated\n");
960 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
961 phy_timing->t_datzero, clk_ps, T_DATZERO_HW_INC),
962 MIPI_T_HSZERO_PS_MIN, MIPI_T_HSZERO_PS_MAX);
964 dev_warn(&dsi->dc->ndev->dev,
965 "dsi: HsZero mipi range violated\n");
970 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
971 phy_timing->t_hsprepare, clk_ps, T_HSPREPARE_HW_INC),
972 MIPI_T_HSPREPARE_PS_MIN(clk_ps),
973 MIPI_T_HSPREPARE_PS_MAX(clk_ps));
975 dev_warn(&dsi->dc->ndev->dev,
976 "dsi: HsPrepare mipi range violated\n");
981 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
982 phy_timing->t_hsprepare, clk_ps, T_HSPREPARE_HW_INC) +
983 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
984 phy_timing->t_datzero, clk_ps, T_DATZERO_HW_INC),
985 MIPI_T_HSPREPARE_ADD_HSZERO_PS_MIN(clk_ps),
986 MIPI_T_HSPREPARE_ADD_HSZERO_PS_MAX);
988 dev_warn(&dsi->dc->ndev->dev,
989 "dsi: HsPrepare + HsZero mipi range violated\n");
993 /* default is LP mode */
995 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
996 phy_timing->t_wakeup, clk_ps, T_WAKEUP_HW_INC),
997 MIPI_T_WAKEUP_PS_MIN, MIPI_T_WAKEUP_PS_MAX);
999 dev_warn(&dsi->dc->ndev->dev,
1000 "dsi: WakeUp mipi range violated\n");
1005 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1006 phy_timing->t_tasure, clk_ps, T_TASURE_HW_INC),
1007 MIPI_T_TASURE_PS_MIN(DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1008 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC)),
1009 MIPI_T_TASURE_PS_MAX(DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1010 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC)));
1012 dev_warn(&dsi->dc->ndev->dev,
1013 "dsi: TaSure mipi range violated\n");
1018 if (lphs == DSI_LPHS_IN_HS_MODE ||
1019 dsi->info.enable_hs_clock_on_lp_cmd_mode) {
1021 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1022 phy_timing->t_clktrail, clk_ps, T_CLKTRAIL_HW_INC),
1023 MIPI_T_CLKTRAIL_PS_MIN, MIPI_T_CLKTRAIL_PS_MAX);
1025 dev_warn(&dsi->dc->ndev->dev,
1026 "dsi: ClkTrail mipi range violated\n");
1031 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1032 phy_timing->t_clkpost, clk_ps, T_CLKPOST_HW_INC),
1033 MIPI_T_CLKPOST_PS_MIN(clk_ps), MIPI_T_CLKPOST_PS_MAX);
1035 dev_warn(&dsi->dc->ndev->dev,
1036 "dsi: ClkPost mipi range violated\n");
1041 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1042 phy_timing->t_clkzero, clk_ps, T_CLKZERO_HW_INC),
1043 MIPI_T_CLKZERO_PS_MIN, MIPI_T_CLKZERO_PS_MAX);
1045 dev_warn(&dsi->dc->ndev->dev,
1046 "dsi: ClkZero mipi range violated\n");
1051 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1052 phy_timing->t_clkprepare, clk_ps, T_CLKPREPARE_HW_INC),
1053 MIPI_T_CLKPREPARE_PS_MIN, MIPI_T_CLKPREPARE_PS_MAX);
1055 dev_warn(&dsi->dc->ndev->dev,
1056 "dsi: ClkPrepare mipi range violated\n");
1061 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1062 phy_timing->t_clkpre, clk_ps, T_CLKPRE_HW_INC),
1063 MIPI_T_CLKPRE_PS_MIN, MIPI_T_CLKPRE_PS_MAX);
1065 dev_warn(&dsi->dc->ndev->dev,
1066 "dsi: ClkPre mipi range violated\n");
1071 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1072 phy_timing->t_clkprepare, clk_ps, T_CLKPREPARE_HW_INC) +
1073 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1074 phy_timing->t_clkzero, clk_ps, T_CLKZERO_HW_INC),
1075 MIPI_T_CLKPREPARE_ADD_CLKZERO_PS_MIN,
1076 MIPI_T_CLKPREPARE_ADD_CLKZERO_PS_MAX);
1078 dev_warn(&dsi->dc->ndev->dev,
1079 "dsi: ClkPrepare + ClkZero mipi range violated\n");
1088 static int tegra_dsi_hs_phy_len(struct tegra_dc_dsi_data *dsi,
1089 struct dsi_phy_timing_inclk *phy_timing,
1090 u32 clk_ps, u8 lphs)
1092 u32 hs_t_phy_ps = 0;
1093 u32 clk_t_phy_ps = 0;
1096 struct tegra_dc_mode *modes;
1100 if (!(lphs == DSI_LPHS_IN_HS_MODE))
1103 if (dsi->info.video_data_type ==
1104 TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE &&
1105 dsi->info.video_burst_mode <=
1106 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END)
1109 modes = dsi->dc->out->modes;
1110 t_pix_ps = clk_ps * BITS_PER_BYTE *
1111 dsi->pixel_scaler_mul / dsi->pixel_scaler_div;
1114 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1115 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC) +
1116 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1117 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC) +
1118 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1119 phy_timing->t_hsprepare, clk_ps, T_HSPREPARE_HW_INC) +
1120 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1121 phy_timing->t_datzero, clk_ps, T_DATZERO_HW_INC) +
1122 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1123 phy_timing->t_hstrail, clk_ps, T_HSTRAIL_HW_INC) +
1124 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1125 phy_timing->t_hsdexit, clk_ps, T_HSEXIT_HW_INC);
1127 if (dsi->info.video_clock_mode == TEGRA_DSI_VIDEO_CLOCK_TX_ONLY) {
1129 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1130 phy_timing->t_clkpost, clk_ps, T_CLKPOST_HW_INC) +
1131 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1132 phy_timing->t_clktrail, clk_ps, T_CLKTRAIL_HW_INC) +
1133 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1134 phy_timing->t_hsdexit, clk_ps, T_HSEXIT_HW_INC) +
1135 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1136 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC) +
1137 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1138 phy_timing->t_clkprepare, clk_ps, T_CLKPREPARE_HW_INC) +
1139 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1140 phy_timing->t_clkzero, clk_ps, T_CLKZERO_HW_INC) +
1141 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1142 phy_timing->t_clkpre, clk_ps, T_CLKPRE_HW_INC);
1144 /* clk_pre overlaps LP-11 hs mode start sequence */
1145 hs_t_phy_ps -= DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1146 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC);
1149 h_blank_ps = t_pix_ps * (modes->h_sync_width + modes->h_back_porch +
1150 modes->h_front_porch);
1152 /* Extra tlpx and byte cycle required by dsi HW */
1153 t_phy_ps = dsi->info.n_data_lanes * (hs_t_phy_ps + clk_t_phy_ps +
1154 DSI_CONVERT_T_PHY_TO_T_PHY_PS(
1155 phy_timing->t_tlpx, clk_ps, T_TLPX_HW_INC) +
1156 clk_ps * BITS_PER_BYTE);
1158 if (h_blank_ps < t_phy_ps) {
1160 dev_WARN(&dsi->dc->ndev->dev,
1161 "dsi: Hblank is smaller than HS phy timing: %u pix\n",
1162 (t_phy_ps - h_blank_ps) / t_pix_ps);
1171 static int tegra_dsi_constraint_phy_timing(struct tegra_dc_dsi_data *dsi,
1172 struct dsi_phy_timing_inclk *phy_timing,
1173 u32 clk_ps, u8 lphs)
1177 err = tegra_dsi_mipi_phy_timing_range(dsi, phy_timing, clk_ps, lphs);
1179 dev_warn(&dsi->dc->ndev->dev, "dsi: mipi range violated\n");
1183 err = tegra_dsi_hs_phy_len(dsi, phy_timing, clk_ps, lphs);
1185 dev_err(&dsi->dc->ndev->dev, "dsi: Hblank too short\n");
1189 /* TODO: add more contraints */
1194 static void tegra_dsi_set_phy_timing(struct tegra_dc_dsi_data *dsi, u8 lphs)
1197 struct dsi_phy_timing_inclk phy_timing = dsi->phy_timing;
1199 tegra_dsi_get_phy_timing
1200 (dsi, &phy_timing, dsi->current_bit_clk_ps, lphs);
1202 tegra_dsi_constraint_phy_timing(dsi, &phy_timing,
1203 dsi->current_bit_clk_ps, lphs);
1205 if (tegra_platform_is_fpga() && dsi->info.ganged_type) {
1206 phy_timing.t_hsdexit += T_HSEXIT_HW_INC;
1207 phy_timing.t_hstrail += T_HSTRAIL_HW_INC + 3;
1208 phy_timing.t_datzero += T_DATZERO_HW_INC;
1209 phy_timing.t_hsprepare += T_HSPREPARE_HW_INC;
1211 phy_timing.t_clktrail += T_CLKTRAIL_HW_INC;
1212 phy_timing.t_clkpost += T_CLKPOST_HW_INC;
1213 phy_timing.t_clkzero += T_CLKZERO_HW_INC;
1214 phy_timing.t_tlpx += T_TLPX_HW_INC;
1216 phy_timing.t_clkprepare += T_CLKPREPARE_HW_INC;
1217 phy_timing.t_clkpre += T_CLKPRE_HW_INC;
1218 phy_timing.t_wakeup += T_WAKEUP_HW_INC;
1220 phy_timing.t_taget += T_TAGET_HW_INC;
1221 phy_timing.t_tasure += T_TASURE_HW_INC;
1222 phy_timing.t_tago += T_TAGO_HW_INC;
1224 val = DSI_PHY_TIMING_0_THSDEXIT(phy_timing.t_hsdexit) |
1225 DSI_PHY_TIMING_0_THSTRAIL(phy_timing.t_hstrail) |
1226 DSI_PHY_TIMING_0_TDATZERO(phy_timing.t_datzero) |
1227 DSI_PHY_TIMING_0_THSPREPR(phy_timing.t_hsprepare);
1228 tegra_dsi_writel(dsi, val, DSI_PHY_TIMING_0);
1230 val = DSI_PHY_TIMING_1_TCLKTRAIL(phy_timing.t_clktrail) |
1231 DSI_PHY_TIMING_1_TCLKPOST(phy_timing.t_clkpost) |
1232 DSI_PHY_TIMING_1_TCLKZERO(phy_timing.t_clkzero) |
1233 DSI_PHY_TIMING_1_TTLPX(phy_timing.t_tlpx);
1234 tegra_dsi_writel(dsi, val, DSI_PHY_TIMING_1);
1236 val = DSI_PHY_TIMING_2_TCLKPREPARE(phy_timing.t_clkprepare) |
1237 DSI_PHY_TIMING_2_TCLKPRE(phy_timing.t_clkpre) |
1238 DSI_PHY_TIMING_2_TWAKEUP(phy_timing.t_wakeup);
1239 tegra_dsi_writel(dsi, val, DSI_PHY_TIMING_2);
1241 val = DSI_BTA_TIMING_TTAGET(phy_timing.t_taget) |
1242 DSI_BTA_TIMING_TTASURE(phy_timing.t_tasure) |
1243 DSI_BTA_TIMING_TTAGO(phy_timing.t_tago);
1244 tegra_dsi_writel(dsi, val, DSI_BTA_TIMING);
1246 dsi->phy_timing = phy_timing;
1249 static u32 tegra_dsi_sol_delay_burst(struct tegra_dc *dc,
1250 struct tegra_dc_dsi_data *dsi)
1252 u32 dsi_to_pixel_clk_ratio;
1255 u32 mipi_clk_adj_kHz = 0;
1257 struct tegra_dc_mode *dc_modes = &dc->mode;
1259 /* Get Fdsi/Fpixel ration (note: Fdsi is in bit format) */
1260 dsi_to_pixel_clk_ratio = (dsi->current_dsi_clk_khz * 2 +
1261 dsi->default_pixel_clk_khz - 1) / dsi->default_pixel_clk_khz;
1263 /* Convert Fdsi to byte format */
1264 dsi_to_pixel_clk_ratio *= 1000/8;
1266 /* Multiplying by 1000 so that we don't loose the fraction part */
1267 temp = dc_modes->h_active * 1000;
1268 temp1 = dc_modes->h_active + dc_modes->h_back_porch +
1269 dc_modes->h_sync_width;
1271 sol_delay = temp1 * dsi_to_pixel_clk_ratio -
1272 temp * dsi->pixel_scaler_mul /
1273 (dsi->pixel_scaler_div * dsi->info.n_data_lanes);
1275 /* Do rounding on sol delay */
1276 sol_delay = (sol_delay + 1000 - 1)/1000;
1279 * 1. find out the correct sol fifo depth to use
1280 * 2. verify with hw about the clamping function
1282 if (sol_delay > (480 * 4)) {
1283 sol_delay = (480 * 4);
1284 mipi_clk_adj_kHz = sol_delay +
1285 (dc_modes->h_active * dsi->pixel_scaler_mul) /
1286 (dsi->info.n_data_lanes * dsi->pixel_scaler_div);
1288 mipi_clk_adj_kHz *= (dsi->default_pixel_clk_khz / temp1);
1290 mipi_clk_adj_kHz *= 4;
1293 dsi->target_hs_clk_khz = mipi_clk_adj_kHz;
1298 static void tegra_dsi_set_sol_delay(struct tegra_dc *dc,
1299 struct tegra_dc_dsi_data *dsi)
1303 u32 h_width_byte_clk;
1305 u32 h_width_ganged_byte_clk;
1306 u8 n_data_lanes_this_cont = 0;
1307 u8 n_data_lanes_ganged = 0;
1309 if (!(dsi->info.ganged_type)) {
1310 if (dsi->info.video_burst_mode ==
1311 TEGRA_DSI_VIDEO_NONE_BURST_MODE ||
1312 dsi->info.video_burst_mode ==
1313 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END) {
1314 #define VIDEO_FIFO_LATENCY_PIXEL_CLK 8
1315 sol_delay = VIDEO_FIFO_LATENCY_PIXEL_CLK *
1316 dsi->pixel_scaler_mul / dsi->pixel_scaler_div;
1317 #undef VIDEO_FIFO_LATENCY_PIXEL_CLK
1318 dsi->status.clk_burst = DSI_CLK_BURST_NONE_BURST;
1320 sol_delay = tegra_dsi_sol_delay_burst(dc, dsi);
1321 dsi->status.clk_burst = DSI_CLK_BURST_BURST_MODE;
1324 #define SOL_TO_VALID_PIX_CLK_DELAY 4
1325 #define VALID_TO_FIFO_PIX_CLK_DELAY 4
1326 #define FIFO_WR_PIX_CLK_DELAY 2
1327 #define FIFO_RD_BYTE_CLK_DELAY 6
1328 #define TOT_INTERNAL_PIX_DELAY (SOL_TO_VALID_PIX_CLK_DELAY + \
1329 VALID_TO_FIFO_PIX_CLK_DELAY + \
1330 FIFO_WR_PIX_CLK_DELAY)
1332 internal_delay = DIV_ROUND_UP(
1333 TOT_INTERNAL_PIX_DELAY * dsi->pixel_scaler_mul,
1334 dsi->pixel_scaler_div * dsi->info.n_data_lanes)
1335 + FIFO_RD_BYTE_CLK_DELAY;
1337 h_width_pixels = dc->mode.h_sync_width +
1338 dc->mode.h_back_porch +
1340 dc->mode.h_front_porch;
1342 h_width_byte_clk = DIV_ROUND_UP(h_width_pixels *
1343 dsi->pixel_scaler_mul,
1344 dsi->pixel_scaler_div *
1345 dsi->info.n_data_lanes);
1347 if (dsi->info.ganged_type ==
1348 TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT ||
1349 dsi->info.ganged_type ==
1350 TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD) {
1351 n_data_lanes_this_cont = dsi->info.n_data_lanes / 2;
1352 n_data_lanes_ganged = dsi->info.n_data_lanes;
1355 h_width_ganged_byte_clk = DIV_ROUND_UP(
1356 n_data_lanes_this_cont *
1358 n_data_lanes_ganged);
1360 sol_delay = h_width_byte_clk - h_width_ganged_byte_clk +
1362 sol_delay = (dsi->info.video_data_type ==
1363 TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE) ?
1364 sol_delay + 20 : sol_delay;
1366 #undef SOL_TO_VALID_PIX_CLK_DELAY
1367 #undef VALID_TO_FIFO_PIX_CLK_DELAY
1368 #undef FIFO_WR_PIX_CLK_DELAY
1369 #undef FIFO_RD_BYTE_CLK_DELAY
1370 #undef TOT_INTERNAL_PIX_DELAY
1373 tegra_dsi_writel(dsi, DSI_SOL_DELAY_SOL_DELAY(sol_delay),
1377 static void tegra_dsi_set_timeout(struct tegra_dc_dsi_data *dsi)
1380 u32 bytes_per_frame;
1383 /* TODO: verify the following equation */
1384 bytes_per_frame = dsi->current_dsi_clk_khz * 1000 * 2 /
1385 (dsi->info.refresh_rate * 8);
1386 timeout = bytes_per_frame / DSI_CYCLE_COUNTER_VALUE;
1387 timeout = (timeout + DSI_HTX_TO_MARGIN) & 0xffff;
1389 val = DSI_TIMEOUT_0_LRXH_TO(DSI_LRXH_TO_VALUE) |
1390 DSI_TIMEOUT_0_HTX_TO(timeout);
1391 tegra_dsi_writel(dsi, val, DSI_TIMEOUT_0);
1393 if (dsi->info.panel_reset_timeout_msec)
1394 timeout = (dsi->info.panel_reset_timeout_msec * 1000 * 1000 *
1395 1000) / dsi->current_bit_clk_ps;
1397 timeout = DSI_PR_TO_VALUE;
1399 val = DSI_TIMEOUT_1_PR_TO(timeout) |
1400 DSI_TIMEOUT_1_TA_TO(DSI_TA_TO_VALUE);
1401 tegra_dsi_writel(dsi, val, DSI_TIMEOUT_1);
1403 val = DSI_TO_TALLY_P_RESET_STATUS(IN_RESET) |
1404 DSI_TO_TALLY_TA_TALLY(DSI_TA_TALLY_VALUE)|
1405 DSI_TO_TALLY_LRXH_TALLY(DSI_LRXH_TALLY_VALUE)|
1406 DSI_TO_TALLY_HTX_TALLY(DSI_HTX_TALLY_VALUE);
1407 tegra_dsi_writel(dsi, val, DSI_TO_TALLY);
1410 static void tegra_dsi_setup_ganged_mode_pkt_length(struct tegra_dc *dc,
1411 struct tegra_dc_dsi_data *dsi)
1413 u32 hact_pkt_len_pix_orig = dc->mode.h_active;
1414 u32 hact_pkt_len_pix = 0;
1415 u32 hact_pkt_len_bytes = 0;
1416 u32 hfp_pkt_len_bytes = 0;
1417 u32 pix_per_line_orig = 0;
1418 u32 pix_per_line = 0;
1422 /* hsync + hact + hfp = (4) + (4+2) + (4+2) */
1423 #define HEADER_OVERHEAD 16
1425 pix_per_line_orig = dc->mode.h_sync_width + dc->mode.h_back_porch +
1426 dc->mode.h_active + dc->mode.h_front_porch;
1428 val = DSI_PKT_LEN_0_1_LENGTH_0(0) |
1429 DSI_PKT_LEN_0_1_LENGTH_1(0);
1430 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_0_1);
1432 switch (dsi->info.ganged_type) {
1433 case TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT: /* fall through */
1434 case TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD: /* fall through */
1435 hact_pkt_len_pix = DIV_ROUND_UP(hact_pkt_len_pix_orig, 2);
1436 pix_per_line = DIV_ROUND_UP(pix_per_line_orig, 2);
1439 dev_err(&dc->ndev->dev, "dsi: invalid ganged type\n");
1442 for (i = 0; i < dsi->max_instances; i++) {
1443 hact_pkt_len_bytes = hact_pkt_len_pix *
1444 dsi->pixel_scaler_mul / dsi->pixel_scaler_div;
1445 hfp_pkt_len_bytes = pix_per_line *
1446 dsi->pixel_scaler_mul / dsi->pixel_scaler_div -
1447 hact_pkt_len_bytes - HEADER_OVERHEAD;
1449 val = DSI_PKT_LEN_2_3_LENGTH_2(0x0) |
1450 DSI_PKT_LEN_2_3_LENGTH_3(hact_pkt_len_bytes);
1451 tegra_dsi_controller_writel(dsi, val, DSI_PKT_LEN_2_3, i);
1453 val = DSI_PKT_LEN_4_5_LENGTH_4(hfp_pkt_len_bytes) |
1454 DSI_PKT_LEN_4_5_LENGTH_5(0);
1455 tegra_dsi_controller_writel(dsi, val, DSI_PKT_LEN_4_5, i);
1458 hact_pkt_len_pix_orig - hact_pkt_len_pix;
1459 pix_per_line = pix_per_line_orig - pix_per_line;
1462 val = DSI_PKT_LEN_6_7_LENGTH_6(0) |
1463 DSI_PKT_LEN_6_7_LENGTH_7(0x0f0f);
1464 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_6_7);
1466 #undef HEADER_OVERHEAD
1469 static void tegra_dsi_setup_video_mode_pkt_length(struct tegra_dc *dc,
1470 struct tegra_dc_dsi_data *dsi)
1478 hact_pkt_len = dc->mode.h_active * dsi->pixel_scaler_mul /
1479 dsi->pixel_scaler_div;
1480 hsa_pkt_len = dc->mode.h_sync_width * dsi->pixel_scaler_mul /
1481 dsi->pixel_scaler_div;
1482 hbp_pkt_len = dc->mode.h_back_porch * dsi->pixel_scaler_mul /
1483 dsi->pixel_scaler_div;
1484 hfp_pkt_len = dc->mode.h_front_porch * dsi->pixel_scaler_mul /
1485 dsi->pixel_scaler_div;
1487 if (dsi->info.video_burst_mode !=
1488 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END)
1489 hbp_pkt_len += hsa_pkt_len;
1491 hsa_pkt_len -= DSI_HSYNC_BLNK_PKT_OVERHEAD;
1492 hbp_pkt_len -= DSI_HBACK_PORCH_PKT_OVERHEAD;
1493 hfp_pkt_len -= DSI_HFRONT_PORCH_PKT_OVERHEAD;
1495 val = DSI_PKT_LEN_0_1_LENGTH_0(0) |
1496 DSI_PKT_LEN_0_1_LENGTH_1(hsa_pkt_len);
1497 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_0_1);
1499 val = DSI_PKT_LEN_2_3_LENGTH_2(hbp_pkt_len) |
1500 DSI_PKT_LEN_2_3_LENGTH_3(hact_pkt_len);
1501 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_2_3);
1503 val = DSI_PKT_LEN_4_5_LENGTH_4(hfp_pkt_len) |
1504 DSI_PKT_LEN_4_5_LENGTH_5(0);
1505 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_4_5);
1507 val = DSI_PKT_LEN_6_7_LENGTH_6(0) | DSI_PKT_LEN_6_7_LENGTH_7(0x0f0f);
1508 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_6_7);
1511 static void tegra_dsi_setup_cmd_mode_pkt_length(struct tegra_dc *dc,
1512 struct tegra_dc_dsi_data *dsi)
1515 unsigned long act_bytes;
1517 if (dsi->info.ganged_type) {
1518 act_bytes = DIV_ROUND_UP(dc->mode.h_active, 2);
1519 act_bytes = (act_bytes) * dsi->pixel_scaler_mul /
1520 dsi->pixel_scaler_div + 1;
1522 act_bytes = dc->mode.h_active * dsi->pixel_scaler_mul /
1523 dsi->pixel_scaler_div + 1;
1525 val = DSI_PKT_LEN_0_1_LENGTH_0(0) | DSI_PKT_LEN_0_1_LENGTH_1(0);
1526 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_0_1);
1528 val = DSI_PKT_LEN_2_3_LENGTH_2(0) | DSI_PKT_LEN_2_3_LENGTH_3(act_bytes);
1529 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_2_3);
1531 val = DSI_PKT_LEN_4_5_LENGTH_4(0) | DSI_PKT_LEN_4_5_LENGTH_5(act_bytes);
1532 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_4_5);
1534 val = DSI_PKT_LEN_6_7_LENGTH_6(0) | DSI_PKT_LEN_6_7_LENGTH_7(0x0f0f);
1535 tegra_dsi_writel(dsi, val, DSI_PKT_LEN_6_7);
1538 static void tegra_dsi_set_pkt_length(struct tegra_dc *dc,
1539 struct tegra_dc_dsi_data *dsi)
1541 if (dsi->driven_mode == TEGRA_DSI_DRIVEN_BY_HOST)
1544 if (dsi->info.video_data_type == TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE) {
1545 if (dsi->info.ganged_type)
1546 tegra_dsi_setup_ganged_mode_pkt_length(dc, dsi);
1548 tegra_dsi_setup_video_mode_pkt_length(dc, dsi);
1550 tegra_dsi_setup_cmd_mode_pkt_length(dc, dsi);
1554 static void tegra_dsi_set_pkt_seq(struct tegra_dc *dc,
1555 struct tegra_dc_dsi_data *dsi)
1559 u32 pkt_seq_3_5_rgb_lo;
1560 u32 pkt_seq_3_5_rgb_hi;
1565 if (dsi->driven_mode == TEGRA_DSI_DRIVEN_BY_HOST)
1568 switch (dsi->info.pixel_format) {
1569 case TEGRA_DSI_PIXEL_FORMAT_16BIT_P:
1570 rgb_info = CMD_RGB_16BPP;
1572 case TEGRA_DSI_PIXEL_FORMAT_18BIT_P:
1573 rgb_info = CMD_RGB_18BPP;
1575 case TEGRA_DSI_PIXEL_FORMAT_18BIT_NP:
1576 rgb_info = CMD_RGB_18BPPNP;
1578 case TEGRA_DSI_PIXEL_FORMAT_24BIT_P:
1580 rgb_info = CMD_RGB_24BPP;
1584 pkt_seq_3_5_rgb_lo = 0;
1585 pkt_seq_3_5_rgb_hi = 0;
1586 if (dsi->info.pkt_seq)
1587 pkt_seq = dsi->info.pkt_seq;
1588 else if (dsi->info.video_data_type ==
1589 TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE) {
1590 pkt_seq = dsi_pkt_seq_cmd_mode;
1592 switch (dsi->info.video_burst_mode) {
1593 case TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED:
1594 case TEGRA_DSI_VIDEO_BURST_MODE_LOW_SPEED:
1595 case TEGRA_DSI_VIDEO_BURST_MODE_MEDIUM_SPEED:
1596 case TEGRA_DSI_VIDEO_BURST_MODE_FAST_SPEED:
1597 case TEGRA_DSI_VIDEO_BURST_MODE_FASTEST_SPEED:
1598 pkt_seq_3_5_rgb_lo =
1599 DSI_PKT_SEQ_3_LO_PKT_32_ID(rgb_info);
1600 if (!dsi->info.no_pkt_seq_eot)
1601 pkt_seq = dsi_pkt_seq_video_burst;
1603 pkt_seq = dsi_pkt_seq_video_burst_no_eot;
1605 case TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END:
1606 pkt_seq_3_5_rgb_hi =
1607 DSI_PKT_SEQ_3_HI_PKT_34_ID(rgb_info);
1608 pkt_seq = dsi_pkt_seq_video_non_burst_syne;
1610 case TEGRA_DSI_VIDEO_NONE_BURST_MODE:
1612 if (dsi->info.ganged_type) {
1613 pkt_seq_3_5_rgb_lo =
1614 DSI_PKT_SEQ_3_LO_PKT_31_ID(rgb_info);
1616 dsi_pkt_seq_video_non_burst_no_eot_no_lp_no_hbp;
1618 pkt_seq_3_5_rgb_lo =
1619 DSI_PKT_SEQ_3_LO_PKT_32_ID(rgb_info);
1620 pkt_seq = dsi_pkt_seq_video_non_burst;
1623 /* Simulator does not support EOT packet yet */
1624 if (tegra_cpu_is_asim())
1625 pkt_seq = dsi_pkt_seq_video_non_burst_no_eot;
1630 for (i = 0; i < NUMOF_PKT_SEQ; i++) {
1632 reg = dsi_pkt_seq_reg[i];
1633 if ((reg == DSI_PKT_SEQ_3_LO) || (reg == DSI_PKT_SEQ_5_LO))
1634 val |= pkt_seq_3_5_rgb_lo;
1635 if ((reg == DSI_PKT_SEQ_3_HI) || (reg == DSI_PKT_SEQ_5_HI))
1636 val |= pkt_seq_3_5_rgb_hi;
1637 tegra_dsi_writel(dsi, val, reg);
1641 static void tegra_dsi_reset_underflow_overflow
1642 (struct tegra_dc_dsi_data *dsi)
1646 val = tegra_dsi_readl(dsi, DSI_STATUS);
1647 val &= (DSI_STATUS_LB_OVERFLOW(0x1) | DSI_STATUS_LB_UNDERFLOW(0x1));
1649 if (val & DSI_STATUS_LB_OVERFLOW(0x1))
1650 dev_warn(&dsi->dc->ndev->dev,
1651 "dsi: video fifo overflow. Resetting flag\n");
1652 if (val & DSI_STATUS_LB_UNDERFLOW(0x1))
1653 dev_warn(&dsi->dc->ndev->dev,
1654 "dsi: video fifo underflow. Resetting flag\n");
1655 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
1656 val |= DSI_HOST_CONTROL_FIFO_STAT_RESET(0x1);
1657 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
1662 static void tegra_dsi_soft_reset(struct tegra_dc_dsi_data *dsi)
1666 u32 frame_period = DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
1667 struct tegra_dc_mode mode = dsi->dc->mode;
1668 u32 tot_lines = mode.v_sync_width + mode.v_back_porch +
1669 mode.v_active + mode.v_front_porch;
1670 u32 line_period = DIV_ROUND_UP(MS_TO_US(frame_period), tot_lines);
1671 u32 timeout_cnt = 0;
1673 /* wait for 1 frame duration + few extra cycles for dsi to go idle */
1674 #define DSI_IDLE_TIMEOUT (tot_lines + 5)
1676 val = tegra_dsi_readl(dsi, DSI_STATUS);
1677 while (!(val & DSI_STATUS_IDLE(0x1))) {
1679 udelay(line_period);
1680 val = tegra_dsi_readl(dsi, DSI_STATUS);
1681 if (timeout_cnt++ > DSI_IDLE_TIMEOUT) {
1682 dev_warn(&dsi->dc->ndev->dev, "dsi not idle when soft reset\n");
1687 tegra_dsi_writel(dsi,
1688 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE),
1690 /* stabilization delay */
1693 tegra_dsi_writel(dsi,
1694 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_ENABLE),
1696 /* stabilization delay */
1699 /* dsi HW does not clear host trigger bit automatically
1700 * on dsi interface disable if host fifo is empty or in mid
1701 * of host transmission
1703 trigger = tegra_dsi_readl(dsi, DSI_TRIGGER);
1705 tegra_dsi_writel(dsi, 0x0, DSI_TRIGGER);
1707 #undef DSI_IDLE_TIMEOUT
1710 static void tegra_dsi_stop_dc_stream(struct tegra_dc *dc,
1711 struct tegra_dc_dsi_data *dsi)
1715 tegra_dc_writel(dc, DISP_CTRL_MODE_STOP, DC_CMD_DISPLAY_COMMAND);
1716 tegra_dc_writel(dc, 0, DC_DISP_DISP_WIN_OPTIONS);
1717 tegra_dc_writel(dc, GENERAL_ACT_REQ , DC_CMD_STATE_CONTROL);
1721 dsi->status.dc_stream = DSI_DC_STREAM_DISABLE;
1724 /* wait for frame end interrupt or (timeout_n_frames * 1 frame duration)
1725 * whichever happens to occur first
1727 static int tegra_dsi_wait_frame_end(struct tegra_dc *dc,
1728 struct tegra_dc_dsi_data *dsi,
1729 u32 timeout_n_frames)
1732 u32 frame_period = DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
1733 struct tegra_dc_mode mode = dc->mode;
1734 u32 line_period = DIV_ROUND_UP(
1735 MS_TO_US(frame_period),
1736 mode.v_sync_width + mode.v_back_porch +
1737 mode.v_active + mode.v_front_porch);
1739 if (timeout_n_frames < 2)
1740 dev_WARN(&dc->ndev->dev,
1741 "dsi: to stop at next frame give at least 2 frame delay\n");
1743 timeout = tegra_dc_wait_for_frame_end(dc, timeout_n_frames *
1746 /* wait for v_ref_to_sync no. of lines after frame end interrupt */
1747 udelay(mode.v_ref_to_sync * line_period);
1752 static void tegra_dsi_stop_dc_stream_at_frame_end(struct tegra_dc *dc,
1753 struct tegra_dc_dsi_data *dsi,
1754 u32 timeout_n_frames)
1756 tegra_dsi_stop_dc_stream(dc, dsi);
1758 tegra_dsi_wait_frame_end(dc, dsi, timeout_n_frames);
1760 tegra_dsi_soft_reset(dsi);
1762 tegra_dsi_reset_underflow_overflow(dsi);
1765 static void tegra_dc_gpio_to_spio(struct tegra_dc_dsi_data *dsi, unsigned gpio)
1769 /* convert to spio */
1770 err = gpio_request(gpio, "temp_request");
1772 dev_err(&dsi->dc->ndev->dev,
1773 "dsi: %s: gpio request failed %d\n", __func__, err);
1779 static void tegra_dsi_start_dc_stream(struct tegra_dc *dc,
1780 struct tegra_dc_dsi_data *dsi)
1785 tegra_dvfs_set_rate(dc->clk, dc->mode.pclk);
1787 tegra_dc_writel(dc, DSI_ENABLE, DC_DISP_DISP_WIN_OPTIONS);
1789 /* TODO: clean up */
1790 tegra_dc_writel(dc, PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
1791 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE,
1792 DC_CMD_DISPLAY_POWER_CONTROL);
1794 /* Configure one-shot mode or continuous mode */
1795 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_MODE) {
1796 /* disable LSPI/LCD_DE output */
1797 val = PIN_OUTPUT_LSPI_OUTPUT_DIS;
1798 tegra_dc_writel(dc, val, DC_COM_PIN_OUTPUT_ENABLE3);
1800 /* enable MSF & set MSF polarity */
1801 val = MSF_ENABLE | MSF_LSPI;
1802 if (!dsi->info.te_polarity_low)
1803 val |= MSF_POLARITY_HIGH;
1805 val |= MSF_POLARITY_LOW;
1806 tegra_dc_writel(dc, val, DC_CMD_DISPLAY_COMMAND_OPTION0);
1808 /* set non-continuous mode */
1809 tegra_dc_writel(dc, DISP_CTRL_MODE_NC_DISPLAY,
1810 DC_CMD_DISPLAY_COMMAND);
1812 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
1814 if (dsi->info.te_gpio)
1815 tegra_dc_gpio_to_spio(dsi, dsi->info.te_gpio);
1817 /* set continuous mode */
1818 tegra_dc_writel(dc, DISP_CTRL_MODE_C_DISPLAY,
1819 DC_CMD_DISPLAY_COMMAND);
1820 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
1825 dsi->status.dc_stream = DSI_DC_STREAM_ENABLE;
1828 static void tegra_dsi_set_dc_clk(struct tegra_dc *dc,
1829 struct tegra_dc_dsi_data *dsi)
1831 u32 shift_clk_div_register;
1834 /* formula: (dsi->shift_clk_div - 1) * 2 */
1835 shift_clk_div_register = DIV_ROUND_CLOSEST(
1836 ((dsi->shift_clk_div.mul -
1837 dsi->shift_clk_div.div) * 2),
1838 dsi->shift_clk_div.div);
1840 if (tegra_platform_is_fpga()) {
1841 shift_clk_div_register = 1;
1842 if (dsi->info.ganged_type)
1843 shift_clk_div_register = 0;
1848 val = PIXEL_CLK_DIVIDER_PCD1 |
1849 SHIFT_CLK_DIVIDER(shift_clk_div_register + 2);
1851 /* SW WAR for bug 1045373. To make the shift clk dividor effect under
1852 * all circumstances, write N+2 to SHIFT_CLK_DIVIDER and activate it.
1853 * After 2us delay, write the target values to it. */
1854 #if defined(CONFIG_ARCH_TEGRA_14x_SOC) || defined(CONFIG_ARCH_11x_SOC)
1855 tegra_dc_writel(dc, val, DC_DISP_DISP_CLOCK_CONTROL);
1856 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
1861 /* TODO: find out if PCD3 option is required */
1862 val = PIXEL_CLK_DIVIDER_PCD1 |
1863 SHIFT_CLK_DIVIDER(shift_clk_div_register);
1865 tegra_dc_writel(dc, val, DC_DISP_DISP_CLOCK_CONTROL);
1870 static void tegra_dsi_set_dsi_clk(struct tegra_dc *dc,
1871 struct tegra_dc_dsi_data *dsi, u32 clk)
1876 /* Round up to MHz */
1881 /* Set up pixel clock */
1882 pclk_khz = (clk * dsi->shift_clk_div.div) /
1883 dsi->shift_clk_div.mul;
1885 dc->mode.pclk = pclk_khz * 1000;
1887 dc->shift_clk_div.mul = dsi->shift_clk_div.mul;
1888 dc->shift_clk_div.div = dsi->shift_clk_div.div;
1890 /* TODO: Define one shot work delay in board file. */
1891 /* Since for one-shot mode, refresh rate is usually set larger than
1892 * expected refresh rate, it needs at least 3 frame period. Less
1893 * delay one shot work is, more powering saving we have. */
1894 dc->one_shot_delay_ms = 4 *
1895 DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
1897 tegra_dsi_setup_clk(dc, dsi);
1898 tegra_dsi_reset_deassert(dsi);
1900 dsi->current_dsi_clk_khz =
1901 clk_get_rate(dsi->dsi_clk[0]) / 1000;
1902 dsi->current_bit_clk_ps = DIV_ROUND_CLOSEST((1000 * 1000 * 1000),
1903 (dsi->current_dsi_clk_khz * 2));
1906 static void tegra_dsi_hs_clk_out_enable(struct tegra_dc_dsi_data *dsi)
1910 val = tegra_dsi_readl(dsi, DSI_CONTROL);
1911 val &= ~DSI_CONTROL_HS_CLK_CTRL(1);
1913 if (dsi->info.video_clock_mode == TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS) {
1914 val |= DSI_CONTROL_HS_CLK_CTRL(CONTINUOUS);
1915 dsi->status.clk_mode = DSI_PHYCLK_CONTINUOUS;
1917 val |= DSI_CONTROL_HS_CLK_CTRL(TX_ONLY);
1918 dsi->status.clk_mode = DSI_PHYCLK_TX_ONLY;
1920 tegra_dsi_writel(dsi, val, DSI_CONTROL);
1922 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
1923 val &= ~DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(1);
1924 val |= DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(TEGRA_DSI_HIGH);
1925 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
1927 dsi->status.clk_out = DSI_PHYCLK_OUT_EN;
1930 static void tegra_dsi_hs_clk_out_enable_in_lp(struct tegra_dc_dsi_data *dsi)
1933 tegra_dsi_hs_clk_out_enable(dsi);
1935 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
1936 val &= ~DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(1);
1937 val |= DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(TEGRA_DSI_LOW);
1938 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
1941 static void tegra_dsi_hs_clk_out_disable(struct tegra_dc *dc,
1942 struct tegra_dc_dsi_data *dsi)
1946 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
1947 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
1949 tegra_dsi_writel(dsi, TEGRA_DSI_DISABLE, DSI_POWER_CONTROL);
1950 /* stabilization delay */
1953 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
1954 val &= ~DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(1);
1955 val |= DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(TEGRA_DSI_LOW);
1956 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
1958 tegra_dsi_writel(dsi, TEGRA_DSI_ENABLE, DSI_POWER_CONTROL);
1959 /* stabilization delay */
1962 dsi->status.clk_mode = DSI_PHYCLK_NOT_INIT;
1963 dsi->status.clk_out = DSI_PHYCLK_OUT_DIS;
1966 static void tegra_dsi_set_control_reg_lp(struct tegra_dc_dsi_data *dsi)
1969 u32 host_dsi_control;
1972 dsi_control = dsi->dsi_control_val | DSI_CTRL_HOST_DRIVEN;
1973 host_dsi_control = HOST_DSI_CTRL_COMMON |
1974 HOST_DSI_CTRL_HOST_DRIVEN |
1975 DSI_HOST_DSI_CONTROL_HIGH_SPEED_TRANS(TEGRA_DSI_LOW);
1976 max_threshold = DSI_MAX_THRESHOLD_MAX_THRESHOLD(DSI_HOST_FIFO_DEPTH);
1978 tegra_dsi_writel(dsi, max_threshold, DSI_MAX_THRESHOLD);
1979 tegra_dsi_writel(dsi, dsi_control, DSI_CONTROL);
1980 tegra_dsi_writel(dsi, host_dsi_control, DSI_HOST_DSI_CONTROL);
1982 dsi->status.driven = DSI_DRIVEN_MODE_HOST;
1983 dsi->status.clk_burst = DSI_CLK_BURST_NOT_INIT;
1984 dsi->status.vtype = DSI_VIDEO_TYPE_NOT_INIT;
1987 static void tegra_dsi_set_control_reg_hs(struct tegra_dc_dsi_data *dsi,
1991 u32 host_dsi_control;
1995 dsi_control = dsi->dsi_control_val;
1996 host_dsi_control = HOST_DSI_CTRL_COMMON;
2000 if (driven_mode == TEGRA_DSI_DRIVEN_BY_HOST) {
2001 dsi_control |= DSI_CTRL_HOST_DRIVEN;
2002 host_dsi_control |= HOST_DSI_CTRL_HOST_DRIVEN;
2004 DSI_MAX_THRESHOLD_MAX_THRESHOLD(DSI_HOST_FIFO_DEPTH);
2005 dsi->status.driven = DSI_DRIVEN_MODE_HOST;
2007 dsi_control |= DSI_CTRL_DC_DRIVEN;
2008 host_dsi_control |= HOST_DSI_CTRL_DC_DRIVEN;
2010 DSI_MAX_THRESHOLD_MAX_THRESHOLD(DSI_VIDEO_FIFO_DEPTH);
2011 dsi->status.driven = DSI_DRIVEN_MODE_DC;
2013 if (dsi->info.video_data_type ==
2014 TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE) {
2015 dsi_control |= DSI_CTRL_CMD_MODE;
2016 dcs_cmd = DSI_DCS_CMDS_LT5_DCS_CMD(
2017 DSI_WRITE_MEMORY_START)|
2018 DSI_DCS_CMDS_LT3_DCS_CMD(
2019 DSI_WRITE_MEMORY_CONTINUE);
2020 dsi->status.vtype = DSI_VIDEO_TYPE_CMD_MODE;
2022 dsi_control |= DSI_CTRL_VIDEO_MODE;
2023 dsi->status.vtype = DSI_VIDEO_TYPE_VIDEO_MODE;
2027 tegra_dsi_writel(dsi, max_threshold, DSI_MAX_THRESHOLD);
2028 tegra_dsi_writel(dsi, dcs_cmd, DSI_DCS_CMDS);
2029 tegra_dsi_writel(dsi, dsi_control, DSI_CONTROL);
2030 tegra_dsi_writel(dsi, host_dsi_control, DSI_HOST_DSI_CONTROL);
2033 static void tegra_dsi_pad_disable(struct tegra_dc_dsi_data *dsi)
2037 if (dsi->info.controller_vs == DSI_VS_1) {
2038 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_0_VS1);
2039 val &= ~(DSI_PAD_CONTROL_0_VS1_PAD_PDIO(0xf) |
2040 DSI_PAD_CONTROL_0_VS1_PAD_PDIO_CLK(0x1) |
2041 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_ENAB(0xf) |
2042 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_CLK_ENAB(0x1));
2043 val |= DSI_PAD_CONTROL_0_VS1_PAD_PDIO(0xf) |
2044 DSI_PAD_CONTROL_0_VS1_PAD_PDIO_CLK
2045 (TEGRA_DSI_PAD_DISABLE) |
2046 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_ENAB(0xf) |
2047 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_CLK_ENAB
2048 (TEGRA_DSI_PAD_DISABLE);
2049 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_0_VS1);
2051 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL);
2052 val &= ~(DSI_PAD_CONTROL_PAD_PDIO(0x3) |
2053 DSI_PAD_CONTROL_PAD_PDIO_CLK(0x1) |
2054 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(0x1));
2055 val |= DSI_PAD_CONTROL_PAD_PDIO(0x3) |
2056 DSI_PAD_CONTROL_PAD_PDIO_CLK(TEGRA_DSI_PAD_DISABLE) |
2057 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(TEGRA_DSI_PAD_DISABLE);
2058 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL);
2062 static void tegra_dsi_pad_enable(struct tegra_dc_dsi_data *dsi)
2066 if (dsi->info.controller_vs == DSI_VS_1) {
2067 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_0_VS1);
2068 val &= ~(DSI_PAD_CONTROL_0_VS1_PAD_PDIO(0xf) |
2069 DSI_PAD_CONTROL_0_VS1_PAD_PDIO_CLK(0x1) |
2070 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_ENAB(0xf) |
2071 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_CLK_ENAB(0x1));
2072 val |= DSI_PAD_CONTROL_0_VS1_PAD_PDIO(TEGRA_DSI_PAD_ENABLE) |
2073 DSI_PAD_CONTROL_0_VS1_PAD_PDIO_CLK(
2074 TEGRA_DSI_PAD_ENABLE) |
2075 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_ENAB(
2076 TEGRA_DSI_PAD_ENABLE) |
2077 DSI_PAD_CONTROL_0_VS1_PAD_PULLDN_CLK_ENAB(
2078 TEGRA_DSI_PAD_ENABLE);
2079 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_0_VS1);
2081 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL);
2082 val &= ~(DSI_PAD_CONTROL_PAD_PDIO(0x3) |
2083 DSI_PAD_CONTROL_PAD_PDIO_CLK(0x1) |
2084 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(0x1));
2085 val |= DSI_PAD_CONTROL_PAD_PDIO(TEGRA_DSI_PAD_ENABLE) |
2086 DSI_PAD_CONTROL_PAD_PDIO_CLK(TEGRA_DSI_PAD_ENABLE) |
2087 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(TEGRA_DSI_PAD_ENABLE);
2088 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL);
2092 static void __maybe_unused
2093 tegra_dsi_mipi_calibration_status(struct tegra_dc_dsi_data *dsi)
2097 /* Start calibration */
2098 val = tegra_mipi_cal_read(dsi->mipi_cal,
2099 MIPI_CAL_MIPI_CAL_CTRL_0);
2100 val |= (MIPI_CAL_STARTCAL(0x1));
2101 tegra_mipi_cal_write(dsi->mipi_cal, val,
2102 MIPI_CAL_MIPI_CAL_CTRL_0);
2104 for (timeout = MIPI_DSI_AUTOCAL_TIMEOUT_USEC;
2105 timeout; timeout -= 100) {
2106 val = tegra_mipi_cal_read(dsi->mipi_cal,
2107 MIPI_CAL_CIL_MIPI_CAL_STATUS_0);
2108 if (!(val & MIPI_CAL_ACTIVE(0x1)) &&
2109 (val & MIPI_AUTO_CAL_DONE(0x1))) {
2110 dev_info(&dsi->dc->ndev->dev, "DSI pad calibration done\n");
2113 usleep_range(10, 100);
2116 dev_info(&dsi->dc->ndev->dev, "DSI calibration timed out\n");
2119 #if defined(CONFIG_ARCH_TEGRA_13x_SOC) || defined(CONFIG_ARCH_TEGRA_21x_SOC)
2120 void tegra_dsi_mipi_calibration_13x(struct tegra_dc_dsi_data *dsi)
2123 struct clk *clk72mhz = NULL;
2125 clk72mhz = clk_get_sys("clk72mhz", NULL);
2126 if (IS_ERR_OR_NULL(clk72mhz)) {
2127 dev_err(&dsi->dc->ndev->dev, "dsi: can't get clk72mhz clock\n");
2130 clk_prepare_enable(clk72mhz);
2132 /* Calibration settings begin */
2133 val = tegra_mipi_cal_read(dsi->mipi_cal,
2134 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2135 val &= ~(PAD_DRIV_UP_REF(0x7) | PAD_DRIV_DN_REF(0x7));
2136 val |= (PAD_DRIV_UP_REF(0x3) | PAD_DRIV_DN_REF(0x0));
2137 tegra_mipi_cal_write(dsi->mipi_cal, val,
2138 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2140 val = (DSI_PAD_SLEWUPADJ(0x7) | DSI_PAD_SLEWDNADJ(0x7) |
2141 DSI_PAD_LPUPADJ(0x1) | DSI_PAD_LPDNADJ(0x1) |
2142 DSI_PAD_OUTADJCLK(0x0));
2143 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_2_VS1);
2145 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_3_VS1);
2146 val |= (DSI_PAD_PREEMP_PD_CLK(0x3) | DSI_PAD_PREEMP_PU_CLK(0x3) |
2147 DSI_PAD_PREEMP_PD(0x3) | DSI_PAD_PREEMP_PU(0x3));
2148 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
2150 /* Calibrate DSI 0 */
2151 if (dsi->info.ganged_type ||
2152 dsi->info.dsi_instance == DSI_INSTANCE_0) {
2153 val = MIPI_CAL_OVERIDEDSIA(0x0) |
2154 MIPI_CAL_SELDSIA(0x1) |
2155 MIPI_CAL_HSPDOSDSIA(0x0) |
2156 MIPI_CAL_HSPUOSDSIA(0x0) |
2157 MIPI_CAL_TERMOSDSIA(0x0);
2158 tegra_mipi_cal_write(dsi->mipi_cal, val,
2159 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2160 tegra_mipi_cal_write(dsi->mipi_cal, val,
2161 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2163 val = (MIPI_CAL_CLKSELDSIA(0x1) |
2164 MIPI_CAL_HSCLKPDOSDSIA(0x3) |
2165 MIPI_CAL_HSCLKPUOSDSIA(0x2));
2166 tegra_mipi_cal_write(dsi->mipi_cal, val,
2167 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2168 tegra_mipi_cal_write(dsi->mipi_cal, val,
2169 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2171 /* Deselect PAD C */
2172 val = tegra_mipi_cal_read(dsi->mipi_cal,
2173 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2174 val &= ~(MIPI_CAL_SELDSIC(0x1));
2175 tegra_mipi_cal_write(dsi->mipi_cal, val,
2176 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2178 /* Deselect PAD D */
2179 val = tegra_mipi_cal_read(dsi->mipi_cal,
2180 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2181 val &= ~(MIPI_CAL_SELDSID(0x1));
2182 tegra_mipi_cal_write(dsi->mipi_cal, val,
2183 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2185 val = MIPI_CAL_NOISE_FLT(0xa) |
2186 MIPI_CAL_PRESCALE(0x2) |
2187 MIPI_CAL_CLKEN_OVR(0x1) |
2188 MIPI_CAL_AUTOCAL_EN(0x0);
2189 tegra_mipi_cal_write(dsi->mipi_cal, val,
2190 MIPI_CAL_MIPI_CAL_CTRL_0);
2192 tegra_dsi_mipi_calibration_status(dsi);
2194 /* Calibrate DSI 1 */
2195 if (dsi->info.ganged_type ||
2196 dsi->info.dsi_instance == DSI_INSTANCE_1) {
2197 val = MIPI_CAL_OVERIDEC(0x0) |
2198 MIPI_CAL_SELC(0x1) |
2199 MIPI_CAL_HSPDOSC(0x0) |
2200 MIPI_CAL_HSPUOSC(0x0) |
2201 MIPI_CAL_TERMOSC(0x0);
2202 tegra_mipi_cal_write(dsi->mipi_cal, val,
2203 MIPI_CAL_CILC_MIPI_CAL_CONFIG_0);
2204 tegra_mipi_cal_write(dsi->mipi_cal, val,
2205 MIPI_CAL_CILD_MIPI_CAL_CONFIG_0);
2207 val = (MIPI_CAL_CLKSELDSIA(0x1) |
2208 MIPI_CAL_HSCLKPDOSDSIA(0x3) |
2209 MIPI_CAL_HSCLKPUOSDSIA(0x2));
2210 tegra_mipi_cal_write(dsi->mipi_cal, val,
2211 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2212 tegra_mipi_cal_write(dsi->mipi_cal, val,
2213 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2215 /* Deselect PAD A */
2216 val = tegra_mipi_cal_read(dsi->mipi_cal,
2217 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2218 val &= ~(MIPI_CAL_SELDSIC(0x1));
2219 tegra_mipi_cal_write(dsi->mipi_cal, val,
2220 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2222 /* Deselect PAD B */
2223 val = tegra_mipi_cal_read(dsi->mipi_cal,
2224 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2225 val &= ~(MIPI_CAL_SELDSID(0x1));
2226 tegra_mipi_cal_write(dsi->mipi_cal, val,
2227 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2229 val = MIPI_CAL_NOISE_FLT(0xa) |
2230 MIPI_CAL_PRESCALE(0x2) |
2231 MIPI_CAL_CLKEN_OVR(0x1) |
2232 MIPI_CAL_AUTOCAL_EN(0x0);
2233 tegra_mipi_cal_write(dsi->mipi_cal, val,
2234 MIPI_CAL_MIPI_CAL_CTRL_0);
2236 tegra_dsi_mipi_calibration_status(dsi);
2239 clk_disable_unprepare(clk72mhz);
2243 #ifdef CONFIG_ARCH_TEGRA_12x_SOC
2244 static void __maybe_unused
2245 tegra_dsi_mipi_calibration_12x(struct tegra_dc_dsi_data *dsi)
2248 struct clk *clk72mhz = NULL;
2250 clk72mhz = clk_get_sys("clk72mhz", NULL);
2251 if (IS_ERR_OR_NULL(clk72mhz)) {
2252 dev_err(&dsi->dc->ndev->dev, "dsi: can't get clk72mhz clock\n");
2255 clk_prepare_enable(clk72mhz);
2257 /* Calibration settings begin */
2258 val = tegra_mipi_cal_read(dsi->mipi_cal,
2259 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2260 val &= ~PAD_DRIV_UP_REF(0x7);
2261 val |= PAD_DRIV_UP_REF(0x3);
2262 tegra_mipi_cal_write(dsi->mipi_cal, val,
2263 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2264 /*Bug 1445912: override tap delay for panel-a-1200-1920-7-0 */
2265 if (dsi->info.boardinfo.platform_boardid == BOARD_P1761 &&
2266 dsi->info.boardinfo.display_boardversion == 1) {
2267 val = (DSI_PAD_OUTADJ3(0x4) | DSI_PAD_OUTADJ2(0x4) |
2268 DSI_PAD_OUTADJ1(0x4) | DSI_PAD_OUTADJ0(0x4));
2269 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_1_VS1);
2272 val = (DSI_PAD_SLEWUPADJ(0x7) | DSI_PAD_SLEWDNADJ(0x7) |
2273 DSI_PAD_LPUPADJ(0x1) | DSI_PAD_LPDNADJ(0x1) |
2274 DSI_PAD_OUTADJCLK(0x0));
2275 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_2_VS1);
2277 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_3_VS1);
2278 val |= (DSI_PAD_PREEMP_PD_CLK(0x3) | DSI_PAD_PREEMP_PU_CLK(0x3) |
2279 DSI_PAD_PREEMP_PD(0x3) | DSI_PAD_PREEMP_PU(0x3));
2280 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
2282 /* Calibrate DSI 0 */
2283 if (dsi->info.ganged_type ||
2284 dsi->info.dsi_instance == DSI_INSTANCE_0) {
2285 val = MIPI_CAL_OVERIDEDSIA(0x0) |
2286 MIPI_CAL_SELDSIA(0x1) |
2287 MIPI_CAL_HSPDOSDSIA(0x0) |
2288 MIPI_CAL_HSPUOSDSIA(0x0) |
2289 MIPI_CAL_TERMOSDSIA(0x0);
2290 tegra_mipi_cal_write(dsi->mipi_cal, val,
2291 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2292 tegra_mipi_cal_write(dsi->mipi_cal, val,
2293 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2295 val = (MIPI_CAL_CLKSELDSIA(0x1) |
2296 MIPI_CAL_HSCLKPDOSDSIA(0x1) |
2297 MIPI_CAL_HSCLKPUOSDSIA(0x2));
2298 tegra_mipi_cal_write(dsi->mipi_cal, val,
2299 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2300 tegra_mipi_cal_write(dsi->mipi_cal, val,
2301 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2303 /* Deselect PAD C */
2304 val = tegra_mipi_cal_read(dsi->mipi_cal,
2305 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2306 val &= ~(MIPI_CAL_SELDSIC(0x1));
2307 tegra_mipi_cal_write(dsi->mipi_cal, val,
2308 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2310 /* Deselect PAD D */
2311 val = tegra_mipi_cal_read(dsi->mipi_cal,
2312 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2313 val &= ~(MIPI_CAL_SELDSID(0x1));
2314 tegra_mipi_cal_write(dsi->mipi_cal, val,
2315 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2317 val = MIPI_CAL_NOISE_FLT(0xa) |
2318 MIPI_CAL_PRESCALE(0x2) |
2319 MIPI_CAL_CLKEN_OVR(0x1) |
2320 MIPI_CAL_AUTOCAL_EN(0x0);
2321 tegra_mipi_cal_write(dsi->mipi_cal, val,
2322 MIPI_CAL_MIPI_CAL_CTRL_0);
2324 tegra_dsi_mipi_calibration_status(dsi);
2326 /* Calibrate DSI 1 */
2327 if (dsi->info.ganged_type ||
2328 dsi->info.dsi_instance == DSI_INSTANCE_1) {
2329 val = MIPI_CAL_OVERIDEC(0x0) |
2330 MIPI_CAL_SELC(0x1) |
2331 MIPI_CAL_HSPDOSC(0x0) |
2332 MIPI_CAL_HSPUOSC(0x0) |
2333 MIPI_CAL_TERMOSC(0x0);
2334 tegra_mipi_cal_write(dsi->mipi_cal, val,
2335 MIPI_CAL_CILC_MIPI_CAL_CONFIG_0);
2336 tegra_mipi_cal_write(dsi->mipi_cal, val,
2337 MIPI_CAL_CILD_MIPI_CAL_CONFIG_0);
2339 val = (MIPI_CAL_CLKSELDSIA(0x1) |
2340 MIPI_CAL_HSCLKPDOSDSIA(0x1) |
2341 MIPI_CAL_HSCLKPUOSDSIA(0x2));
2342 tegra_mipi_cal_write(dsi->mipi_cal, val,
2343 MIPI_CAL_CILC_MIPI_CAL_CONFIG_2_0);
2344 tegra_mipi_cal_write(dsi->mipi_cal, val,
2345 MIPI_CAL_CILD_MIPI_CAL_CONFIG_2_0);
2347 /* Deselect PAD A */
2348 val = tegra_mipi_cal_read(dsi->mipi_cal,
2349 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2350 val &= ~(MIPI_CAL_SELDSIC(0x1));
2351 tegra_mipi_cal_write(dsi->mipi_cal, val,
2352 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2354 /* Deselect PAD B */
2355 val = tegra_mipi_cal_read(dsi->mipi_cal,
2356 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2357 val &= ~(MIPI_CAL_SELDSID(0x1));
2358 tegra_mipi_cal_write(dsi->mipi_cal, val,
2359 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2361 val = MIPI_CAL_NOISE_FLT(0xa) |
2362 MIPI_CAL_PRESCALE(0x2) |
2363 MIPI_CAL_CLKEN_OVR(0x1) |
2364 MIPI_CAL_AUTOCAL_EN(0x0);
2365 tegra_mipi_cal_write(dsi->mipi_cal, val,
2366 MIPI_CAL_MIPI_CAL_CTRL_0);
2368 tegra_dsi_mipi_calibration_status(dsi);
2371 clk_disable_unprepare(clk72mhz);
2375 #ifdef CONFIG_ARCH_TEGRA_14x_SOC
2376 void tegra_dsi_mipi_calibration_14x(struct tegra_dc_dsi_data *dsi)
2379 struct clk *clk72mhz = NULL;
2381 clk72mhz = clk_get_sys("clk72mhz", NULL);
2382 if (IS_ERR_OR_NULL(clk72mhz)) {
2383 dev_err(&dsi->dc->ndev->dev, "dsi: can't get clk72mhz clock\n");
2386 clk_prepare_enable(clk72mhz);
2388 tegra_mipi_cal_write(dsi->mipi_cal,
2389 PAD_DRIV_DN_REF(0x2),
2390 MIPI_CAL_MIPI_BIAS_PAD_CFG1_0);
2392 val = (DSI_PAD_SLEWUPADJ(0x7) | DSI_PAD_SLEWDNADJ(0x7) |
2393 DSI_PAD_LPUPADJ(0x1) | DSI_PAD_LPDNADJ(0x1));
2394 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_2_VS1);
2396 val = (DSI_PAD_PREEMP_PD(0x3) | DSI_PAD_PREEMP_PU(0x3));
2397 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
2399 val = MIPI_CAL_HSCLKPDOSDSIA(0x2) |
2400 MIPI_CAL_HSCLKPUOSDSIA(0x2);
2401 tegra_mipi_cal_write(dsi->mipi_cal, val,
2402 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_2_0);
2403 tegra_mipi_cal_write(dsi->mipi_cal, val,
2404 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_2_0);
2406 val = MIPI_CAL_OVERIDEDSIA(0x0) |
2407 MIPI_CAL_SELDSIA(0x1) |
2408 MIPI_CAL_HSPDOSDSIA(0x0) |
2409 MIPI_CAL_HSPUOSDSIA(0x0) |
2410 MIPI_CAL_TERMOSDSIA(0x0);
2411 tegra_mipi_cal_write(dsi->mipi_cal, val,
2412 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2413 tegra_mipi_cal_write(dsi->mipi_cal, val,
2414 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2416 val = MIPI_CAL_NOISE_FLT(0xa) |
2417 MIPI_CAL_PRESCALE(0x2) |
2418 MIPI_CAL_CLKEN_OVR(0x1) |
2419 MIPI_CAL_AUTOCAL_EN(0x0);
2420 tegra_mipi_cal_write(dsi->mipi_cal, val,
2421 MIPI_CAL_MIPI_CAL_CTRL_0);
2423 tegra_dsi_mipi_calibration_status(dsi);
2425 clk_disable_unprepare(clk72mhz);
2429 #ifdef CONFIG_ARCH_TEGRA_11x_SOC
2430 static void tegra_dsi_mipi_calibration_11x(struct tegra_dc_dsi_data *dsi)
2433 /* Calibration settings begin */
2434 val = (DSI_PAD_SLEWUPADJ(0x7) | DSI_PAD_SLEWDNADJ(0x7) |
2435 DSI_PAD_LPUPADJ(0x1) | DSI_PAD_LPDNADJ(0x1) |
2436 DSI_PAD_OUTADJCLK(0x0));
2437 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_2_VS1);
2439 /* Calibrate DSI 0 */
2440 if (dsi->info.ganged_type ||
2441 dsi->info.dsi_instance == DSI_INSTANCE_0) {
2442 val = tegra_mipi_cal_read(dsi->mipi_cal,
2443 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2444 val = MIPI_CAL_OVERIDEDSIA(0x0) |
2445 MIPI_CAL_SELDSIA(0x1) |
2446 MIPI_CAL_HSPDOSDSIA(0x0) |
2447 MIPI_CAL_HSPUOSDSIA(0x4) |
2448 MIPI_CAL_TERMOSDSIA(0x5);
2449 tegra_mipi_cal_write(dsi->mipi_cal, val,
2450 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2451 tegra_mipi_cal_write(dsi->mipi_cal, val,
2452 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2454 /* Deselect PAD C */
2455 val = tegra_mipi_cal_read(dsi->mipi_cal,
2456 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2457 val &= ~(MIPI_CAL_SELDSIC(0x1));
2458 tegra_mipi_cal_write(dsi->mipi_cal, val,
2459 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2461 /* Deselect PAD D */
2462 val = tegra_mipi_cal_read(dsi->mipi_cal,
2463 MIPI_CAL_DSID_MIPI_CAL_CONFIG_0);
2464 val &= ~(MIPI_CAL_SELDSID(0x1));
2465 tegra_mipi_cal_write(dsi->mipi_cal, val,
2466 MIPI_CAL_DSID_MIPI_CAL_CONFIG_0);
2468 val = tegra_mipi_cal_read(dsi->mipi_cal,
2469 MIPI_CAL_MIPI_CAL_CTRL_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);
2480 /* Calibrate DSI 1 */
2481 if (dsi->info.ganged_type ||
2482 dsi->info.dsi_instance == DSI_INSTANCE_1) {
2483 val = tegra_mipi_cal_read(dsi->mipi_cal,
2484 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2485 val = MIPI_CAL_OVERIDEDSIC(0x0) |
2486 MIPI_CAL_SELDSIC(0x1) |
2487 MIPI_CAL_HSPDOSDSIC(0x0) |
2488 MIPI_CAL_HSPUOSDSIC(0x4) |
2489 MIPI_CAL_TERMOSDSIC(0x5);
2490 tegra_mipi_cal_write(dsi->mipi_cal, val,
2491 MIPI_CAL_DSIC_MIPI_CAL_CONFIG_0);
2492 tegra_mipi_cal_write(dsi->mipi_cal, val,
2493 MIPI_CAL_DSID_MIPI_CAL_CONFIG_0);
2495 /* Deselect PAD A */
2496 val = tegra_mipi_cal_read(dsi->mipi_cal,
2497 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2498 val &= ~(MIPI_CAL_SELDSIA(0x1));
2499 tegra_mipi_cal_write(dsi->mipi_cal, val,
2500 MIPI_CAL_DSIA_MIPI_CAL_CONFIG_0);
2502 /* Deselect PAD B */
2503 val = tegra_mipi_cal_read(dsi->mipi_cal,
2504 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2505 val &= ~(MIPI_CAL_SELDSIB(0x1));
2506 tegra_mipi_cal_write(dsi->mipi_cal, val,
2507 MIPI_CAL_DSIB_MIPI_CAL_CONFIG_0);
2509 val = tegra_mipi_cal_read(dsi->mipi_cal,
2510 MIPI_CAL_MIPI_CAL_CTRL_0);
2511 val = MIPI_CAL_NOISE_FLT(0xa) |
2512 MIPI_CAL_PRESCALE(0x2) |
2513 MIPI_CAL_CLKEN_OVR(0x1) |
2514 MIPI_CAL_AUTOCAL_EN(0x0);
2515 tegra_mipi_cal_write(dsi->mipi_cal, val,
2516 MIPI_CAL_MIPI_CAL_CTRL_0);
2518 tegra_dsi_mipi_calibration_status(dsi);
2522 static void tegra_dsi_pad_calibration(struct tegra_dc_dsi_data *dsi)
2527 tegra_dsi_pad_enable(dsi);
2529 tegra_dsi_pad_disable(dsi);
2531 if (dsi->info.controller_vs == DSI_VS_1) {
2533 tegra_mipi_cal_init_hw(dsi->mipi_cal);
2535 tegra_mipi_cal_clk_enable(dsi->mipi_cal);
2537 /* enable mipi bias pad */
2538 val = tegra_mipi_cal_read(dsi->mipi_cal,
2539 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2540 val &= ~MIPI_BIAS_PAD_PDVCLAMP(0x1);
2541 tegra_mipi_cal_write(dsi->mipi_cal, val,
2542 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2544 #if defined(CONFIG_ARCH_TEGRA_11x_SOC) || \
2545 defined(CONFIG_ARCH_TEGRA_14x_SOC) || \
2546 defined(CONFIG_ARCH_TEGRA_12x_SOC)
2547 tegra_mipi_cal_write(dsi->mipi_cal,
2548 MIPI_BIAS_PAD_E_VCLAMP_REF(0x1),
2549 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2551 tegra_mipi_cal_write(dsi->mipi_cal,
2552 MIPI_BIAS_PAD_E_VCLAMP_REF(0x0),
2553 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2555 tegra_mipi_cal_write(dsi->mipi_cal,
2556 PAD_PDVREG(0x0) | PAD_VCLAMP_LEVEL(0x0),
2557 MIPI_CAL_MIPI_BIAS_PAD_CFG2_0);
2558 #if defined(CONFIG_ARCH_TEGRA_11x_SOC)
2559 tegra_dsi_mipi_calibration_11x(dsi);
2560 #elif defined(CONFIG_ARCH_TEGRA_14x_SOC)
2561 tegra_dsi_mipi_calibration_14x(dsi);
2562 #elif defined(CONFIG_ARCH_TEGRA_13x_SOC) || defined(CONFIG_ARCH_TEGRA_21x_SOC)
2563 tegra_dsi_mipi_calibration_13x(dsi);
2564 #elif defined(CONFIG_ARCH_TEGRA_12x_SOC)
2565 tegra_dsi_mipi_calibration_12x(dsi);
2567 /* disable mipi bias pad */
2568 val = tegra_mipi_cal_read(dsi->mipi_cal,
2569 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2570 val |= MIPI_BIAS_PAD_PDVCLAMP(0x1);
2571 tegra_mipi_cal_write(dsi->mipi_cal, val,
2572 MIPI_CAL_MIPI_BIAS_PAD_CFG0_0);
2574 tegra_mipi_cal_clk_disable(dsi->mipi_cal);
2576 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
2579 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL);
2580 val &= ~(DSI_PAD_CONTROL_PAD_LPUPADJ(0x3) |
2581 DSI_PAD_CONTROL_PAD_LPDNADJ(0x3) |
2582 DSI_PAD_CONTROL_PAD_PREEMP_EN(0x1) |
2583 DSI_PAD_CONTROL_PAD_SLEWDNADJ(0x7) |
2584 DSI_PAD_CONTROL_PAD_SLEWUPADJ(0x7));
2586 val |= DSI_PAD_CONTROL_PAD_LPUPADJ(0x1) |
2587 DSI_PAD_CONTROL_PAD_LPDNADJ(0x1) |
2588 DSI_PAD_CONTROL_PAD_PREEMP_EN(0x1) |
2589 DSI_PAD_CONTROL_PAD_SLEWDNADJ(0x6) |
2590 DSI_PAD_CONTROL_PAD_SLEWUPADJ(0x6);
2592 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL);
2594 val = MIPI_CAL_TERMOSA(0x4);
2595 tegra_vi_csi_writel(val, CSI_CILA_MIPI_CAL_CONFIG_0);
2597 val = MIPI_CAL_TERMOSB(0x4);
2598 tegra_vi_csi_writel(val, CSI_CILB_MIPI_CAL_CONFIG_0);
2600 val = MIPI_CAL_HSPUOSD(0x3) | MIPI_CAL_HSPDOSD(0x4);
2601 tegra_vi_csi_writel(val, CSI_DSI_MIPI_CAL_CONFIG);
2603 val = PAD_DRIV_DN_REF(0x5) | PAD_DRIV_UP_REF(0x7);
2604 tegra_vi_csi_writel(val, CSI_MIPIBIAS_PAD_CONFIG);
2606 val = PAD_CIL_PDVREG(0x0);
2607 tegra_vi_csi_writel(val, CSI_CIL_PAD_CONFIG);
2612 static void tegra_dsi_panelB_enable(void)
2616 val = readl(IO_ADDRESS(APB_MISC_GP_MIPI_PAD_CTRL_0));
2617 val |= DSIB_MODE_ENABLE;
2618 writel(val, (IO_ADDRESS(APB_MISC_GP_MIPI_PAD_CTRL_0)));
2621 static int tegra_dsi_init_hw(struct tegra_dc *dc,
2622 struct tegra_dc_dsi_data *dsi)
2627 if (dsi->avdd_dsi_csi)
2628 err = regulator_enable(dsi->avdd_dsi_csi);
2629 if (WARN(err, "unable to enable regulator"))
2631 /* stablization delay */
2633 /* Enable DSI clocks */
2634 tegra_dsi_clk_enable(dsi);
2635 tegra_dsi_set_dsi_clk(dc, dsi, dsi->target_lp_clk_khz);
2637 /* Stop DC stream before configuring DSI registers
2638 * to avoid visible glitches on panel during transition
2639 * from bootloader to kernel driver
2641 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
2643 tegra_dsi_writel(dsi,
2644 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE),
2646 /* stabilization delay */
2649 if (dsi->info.dsi_instance || dsi->info.ganged_type)
2650 tegra_dsi_panelB_enable();
2652 tegra_dsi_set_phy_timing(dsi, DSI_LPHS_IN_LP_MODE);
2654 /* Initialize DSI registers */
2655 for (i = 0; i < ARRAY_SIZE(init_reg); i++)
2656 tegra_dsi_writel(dsi, 0, init_reg[i]);
2657 if (dsi->info.controller_vs == DSI_VS_1) {
2658 for (i = 0; i < ARRAY_SIZE(init_reg_vs1_ext); i++)
2659 tegra_dsi_writel(dsi, 0, init_reg_vs1_ext[i]);
2662 #ifdef CONFIG_ARCH_TEGRA_21x_SOC
2663 if (tegra_platform_is_fpga()) {
2664 if (dsi->info.video_data_type ==
2665 TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE) {
2666 /* HW fpga WAR: dsi byte clk to dsi pixel clk ratio */
2667 tegra_dsi_writel(dsi, 0x8, DSI_INIT_SEQ_DATA_15);
2672 tegra_dsi_pad_calibration(dsi);
2674 tegra_dsi_writel(dsi,
2675 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_ENABLE),
2677 /* stabilization delay */
2680 dsi->status.init = DSI_MODULE_INIT;
2681 dsi->status.lphs = DSI_LPHS_NOT_INIT;
2682 dsi->status.vtype = DSI_VIDEO_TYPE_NOT_INIT;
2683 dsi->status.driven = DSI_DRIVEN_MODE_NOT_INIT;
2684 dsi->status.clk_out = DSI_PHYCLK_OUT_DIS;
2685 dsi->status.clk_mode = DSI_PHYCLK_NOT_INIT;
2686 dsi->status.clk_burst = DSI_CLK_BURST_NOT_INIT;
2687 dsi->status.dc_stream = DSI_DC_STREAM_DISABLE;
2688 dsi->status.lp_op = DSI_LP_OP_NOT_INIT;
2690 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
2691 tegra_dsi_syncpt_reset(dsi);
2696 static int tegra_dsi_set_to_lp_mode(struct tegra_dc *dc,
2697 struct tegra_dc_dsi_data *dsi, u8 lp_op)
2701 if (dsi->status.init != DSI_MODULE_INIT) {
2706 if (dsi->status.lphs == DSI_LPHS_IN_LP_MODE &&
2707 dsi->status.lp_op == lp_op)
2710 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
2711 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
2713 /* disable/enable hs clk according to enable_hs_clock_on_lp_cmd_mode */
2714 if ((dsi->status.clk_out == DSI_PHYCLK_OUT_EN) &&
2715 (!dsi->info.enable_hs_clock_on_lp_cmd_mode))
2716 tegra_dsi_hs_clk_out_disable(dc, dsi);
2718 dsi->target_lp_clk_khz = tegra_dsi_get_lp_clk_rate(dsi, lp_op);
2719 if (dsi->current_dsi_clk_khz != dsi->target_lp_clk_khz) {
2720 tegra_dsi_set_dsi_clk(dc, dsi, dsi->target_lp_clk_khz);
2721 tegra_dsi_set_timeout(dsi);
2724 tegra_dsi_set_phy_timing(dsi, DSI_LPHS_IN_LP_MODE);
2726 tegra_dsi_set_control_reg_lp(dsi);
2728 if ((dsi->status.clk_out == DSI_PHYCLK_OUT_DIS) &&
2729 (dsi->info.enable_hs_clock_on_lp_cmd_mode))
2730 tegra_dsi_hs_clk_out_enable_in_lp(dsi);
2732 dsi->status.lphs = DSI_LPHS_IN_LP_MODE;
2733 dsi->status.lp_op = lp_op;
2734 dsi->driven_mode = TEGRA_DSI_DRIVEN_BY_HOST;
2741 static void tegra_dsi_ganged(struct tegra_dc *dc,
2742 struct tegra_dc_dsi_data *dsi)
2746 u32 h_active = dc->out->modes->h_active;
2749 if (dsi->info.controller_vs < DSI_VS_1) {
2750 dev_err(&dc->ndev->dev, "dsi: ganged mode not"
2751 "supported with current controller version\n");
2755 if (dsi->info.ganged_type ==
2756 TEGRA_DSI_GANGED_SYMMETRIC_LEFT_RIGHT) {
2758 tegra_dsi_controller_writel(dsi,
2759 DSI_GANGED_MODE_START_POINTER(0),
2760 DSI_GANGED_MODE_START, DSI_INSTANCE_0);
2762 tegra_dsi_controller_writel(dsi,
2763 DSI_GANGED_MODE_START_POINTER(h_active / 2),
2764 DSI_GANGED_MODE_START, DSI_INSTANCE_1);
2766 low_width = DIV_ROUND_UP(h_active, 2);
2767 high_width = h_active - low_width;
2768 val = DSI_GANGED_MODE_SIZE_VALID_LOW_WIDTH(low_width) |
2769 DSI_GANGED_MODE_SIZE_VALID_HIGH_WIDTH(high_width);
2771 } else if (dsi->info.ganged_type ==
2772 TEGRA_DSI_GANGED_SYMMETRIC_EVEN_ODD) {
2774 tegra_dsi_controller_writel(dsi,
2775 DSI_GANGED_MODE_START_POINTER(0),
2776 DSI_GANGED_MODE_START, DSI_INSTANCE_0);
2778 tegra_dsi_controller_writel(dsi,
2779 DSI_GANGED_MODE_START_POINTER(1),
2780 DSI_GANGED_MODE_START, DSI_INSTANCE_1);
2784 val = DSI_GANGED_MODE_SIZE_VALID_LOW_WIDTH(low_width) |
2785 DSI_GANGED_MODE_SIZE_VALID_HIGH_WIDTH(high_width);
2788 tegra_dsi_writel(dsi, val, DSI_GANGED_MODE_SIZE);
2790 tegra_dsi_writel(dsi, DSI_GANGED_MODE_CONTROL_EN(TEGRA_DSI_ENABLE),
2791 DSI_GANGED_MODE_CONTROL);
2794 static int tegra_dsi_set_to_hs_mode(struct tegra_dc *dc,
2795 struct tegra_dc_dsi_data *dsi,
2800 if (dsi->status.init != DSI_MODULE_INIT) {
2805 if (dsi->status.lphs == DSI_LPHS_IN_HS_MODE &&
2806 dsi->driven_mode == driven_mode)
2809 dsi->driven_mode = driven_mode;
2811 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
2812 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
2814 if ((dsi->status.clk_out == DSI_PHYCLK_OUT_EN) &&
2815 (!dsi->info.enable_hs_clock_on_lp_cmd_mode))
2816 tegra_dsi_hs_clk_out_disable(dc, dsi);
2818 if (dsi->current_dsi_clk_khz != dsi->target_hs_clk_khz) {
2819 tegra_dsi_set_dsi_clk(dc, dsi, dsi->target_hs_clk_khz);
2820 tegra_dsi_set_timeout(dsi);
2823 tegra_dsi_set_phy_timing(dsi, DSI_LPHS_IN_HS_MODE);
2825 if (driven_mode == TEGRA_DSI_DRIVEN_BY_DC) {
2826 tegra_dsi_set_pkt_seq(dc, dsi);
2827 tegra_dsi_set_pkt_length(dc, dsi);
2828 tegra_dsi_set_sol_delay(dc, dsi);
2829 tegra_dsi_set_dc_clk(dc, dsi);
2832 tegra_dsi_set_control_reg_hs(dsi, driven_mode);
2834 if (dsi->info.ganged_type)
2835 tegra_dsi_ganged(dc, dsi);
2837 if (dsi->status.clk_out == DSI_PHYCLK_OUT_DIS ||
2838 dsi->info.enable_hs_clock_on_lp_cmd_mode)
2839 tegra_dsi_hs_clk_out_enable(dsi);
2841 dsi->status.lphs = DSI_LPHS_IN_HS_MODE;
2843 dsi->status.lp_op = DSI_LP_OP_NOT_INIT;
2849 static bool tegra_dsi_write_busy(struct tegra_dc_dsi_data *dsi, u8 link_id)
2854 while (timeout <= DSI_MAX_COMMAND_DELAY_USEC) {
2855 if (!(DSI_TRIGGER_HOST_TRIGGER(0x1) &
2856 tegra_dsi_controller_readl(dsi,
2857 DSI_TRIGGER, link_id))) {
2861 udelay(DSI_COMMAND_DELAY_STEPS_USEC);
2862 timeout += DSI_COMMAND_DELAY_STEPS_USEC;
2868 static bool tegra_dsi_read_busy(struct tegra_dc_dsi_data *dsi, u8 link_id)
2873 while (timeout < DSI_STATUS_POLLING_DURATION_USEC) {
2874 if (!(DSI_HOST_DSI_CONTROL_IMM_BTA(0x1) &
2875 tegra_dsi_controller_readl(dsi,
2876 DSI_HOST_DSI_CONTROL, link_id))) {
2880 udelay(DSI_STATUS_POLLING_DELAY_USEC);
2881 timeout += DSI_STATUS_POLLING_DELAY_USEC;
2887 static bool tegra_dsi_host_busy(struct tegra_dc_dsi_data *dsi, u8 link_id)
2891 if (tegra_dsi_write_busy(dsi, link_id)) {
2893 dev_err(&dsi->dc->ndev->dev,
2894 "DSI trigger bit already set\n");
2898 if (tegra_dsi_read_busy(dsi, link_id)) {
2900 dev_err(&dsi->dc->ndev->dev,
2901 "DSI immediate bta bit already set\n");
2905 return (err < 0 ? true : false);
2908 static void tegra_dsi_reset_read_count(struct tegra_dc_dsi_data *dsi)
2912 val = tegra_dsi_readl(dsi, DSI_STATUS);
2913 val &= DSI_STATUS_RD_FIFO_COUNT(0x1f);
2915 dev_warn(&dsi->dc->ndev->dev,
2916 "DSI read count not zero, resetting\n");
2917 tegra_dsi_soft_reset(dsi);
2921 static struct dsi_status *tegra_dsi_save_state_switch_to_host_cmd_mode(
2922 struct tegra_dc_dsi_data *dsi,
2923 struct tegra_dc *dc,
2926 struct dsi_status *init_status = NULL;
2929 if (dsi->status.init != DSI_MODULE_INIT ||
2930 dsi->status.lphs == DSI_LPHS_NOT_INIT) {
2935 init_status = kzalloc(sizeof(*init_status), GFP_KERNEL);
2937 return ERR_PTR(-ENOMEM);
2939 *init_status = dsi->status;
2941 if (dsi->info.hs_cmd_mode_supported) {
2942 err = tegra_dsi_set_to_hs_mode(dc, dsi,
2943 TEGRA_DSI_DRIVEN_BY_HOST);
2945 dev_err(&dc->ndev->dev,
2946 "Switch to HS host mode failed\n");
2953 if (dsi->status.lp_op != lp_op) {
2954 err = tegra_dsi_set_to_lp_mode(dc, dsi, lp_op);
2956 dev_err(&dc->ndev->dev,
2957 "DSI failed to go to LP mode\n");
2965 return ERR_PTR(err);
2968 static struct dsi_status *tegra_dsi_prepare_host_transmission(
2969 struct tegra_dc *dc,
2970 struct tegra_dc_dsi_data *dsi,
2975 struct dsi_status *init_status;
2976 bool restart_dc_stream = false;
2978 if (dsi->status.init != DSI_MODULE_INIT ||
2984 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE) {
2985 restart_dc_stream = true;
2986 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
2989 for (i = 0; i < dsi->max_instances; i++) {
2990 if (tegra_dsi_host_busy(dsi, i)) {
2991 tegra_dsi_soft_reset(dsi);
2992 if (tegra_dsi_host_busy(dsi, i)) {
2994 dev_err(&dc->ndev->dev, "DSI host busy\n");
3000 if (lp_op == DSI_LP_OP_READ)
3001 tegra_dsi_reset_read_count(dsi);
3003 if (dsi->status.lphs == DSI_LPHS_NOT_INIT) {
3004 err = tegra_dsi_set_to_lp_mode(dc, dsi, lp_op);
3006 dev_err(&dc->ndev->dev, "Failed to config LP write\n");
3011 init_status = tegra_dsi_save_state_switch_to_host_cmd_mode
3013 if (IS_ERR_OR_NULL(init_status)) {
3014 err = PTR_ERR(init_status);
3015 dev_err(&dc->ndev->dev, "DSI state saving failed\n");
3019 if (restart_dc_stream)
3020 init_status->dc_stream = DSI_DC_STREAM_ENABLE;
3022 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
3023 if (atomic_read(&dsi_syncpt_rst))
3024 tegra_dsi_syncpt_reset(dsi);
3028 return ERR_PTR(err);
3031 static int tegra_dsi_restore_state(struct tegra_dc *dc,
3032 struct tegra_dc_dsi_data *dsi,
3033 struct dsi_status *init_status)
3037 if (init_status->lphs == DSI_LPHS_IN_LP_MODE) {
3038 err = tegra_dsi_set_to_lp_mode(dc, dsi, init_status->lp_op);
3040 dev_err(&dc->ndev->dev,
3041 "Failed to config LP mode\n");
3047 if (init_status->lphs == DSI_LPHS_IN_HS_MODE) {
3048 u8 driven = (init_status->driven == DSI_DRIVEN_MODE_DC) ?
3049 TEGRA_DSI_DRIVEN_BY_DC : TEGRA_DSI_DRIVEN_BY_HOST;
3050 err = tegra_dsi_set_to_hs_mode(dc, dsi, driven);
3052 dev_err(&dc->ndev->dev, "Failed to config HS mode\n");
3057 if (init_status->dc_stream == DSI_DC_STREAM_ENABLE)
3058 tegra_dsi_start_dc_stream(dc, dsi);
3065 static int tegra_dsi_host_trigger(struct tegra_dc_dsi_data *dsi, u8 link_id)
3069 if (tegra_dsi_controller_readl(dsi, DSI_TRIGGER, link_id)) {
3074 tegra_dsi_controller_writel(dsi,
3075 DSI_TRIGGER_HOST_TRIGGER(TEGRA_DSI_ENABLE),
3076 DSI_TRIGGER, link_id);
3078 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS) {
3079 status = tegra_dsi_syncpt(dsi, link_id);
3081 dev_err(&dsi->dc->ndev->dev,
3082 "DSI syncpt for host trigger failed\n");
3086 if (tegra_dsi_write_busy(dsi, link_id)) {
3088 dev_err(&dsi->dc->ndev->dev,
3089 "Timeout waiting on write completion\n");
3097 static int _tegra_dsi_write_data(struct tegra_dc_dsi_data *dsi,
3098 struct tegra_dsi_cmd *cmd)
3103 u8 *pdata = cmd->pdata;
3104 u8 data_id = cmd->data_id;
3105 u16 data_len = cmd->sp_len_dly.data_len;
3109 if (!dsi->info.ganged_type && cmd->link_id == TEGRA_DSI_LINK1) {
3110 dev_err(&dsi->dc->ndev->dev, "DSI invalid command\n");
3114 virtual_channel = dsi->info.virtual_channel <<
3115 DSI_VIR_CHANNEL_BIT_POSITION;
3117 /* always use hw for ecc */
3118 val = (virtual_channel | data_id) << 0 |
3120 tegra_dsi_controller_writel(dsi, val, DSI_WR_DATA, cmd->link_id);
3122 /* if pdata != NULL, pkt type is long pkt */
3123 if (pdata != NULL) {
3125 if (data_len >= 4) {
3126 val = ((u32 *) pdata)[0];
3131 memcpy(&val, pdata, data_len);
3135 tegra_dsi_controller_writel(dsi, val,
3136 DSI_WR_DATA, cmd->link_id);
3140 if (cmd->cmd_type != TEGRA_DSI_PACKET_VIDEO_VBLANK_CMD) {
3141 err = tegra_dsi_host_trigger(dsi, cmd->link_id);
3143 dev_err(&dsi->dc->ndev->dev, "DSI host trigger failed\n");
3149 static void tegra_dc_dsi_hold_host(struct tegra_dc *dc)
3151 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
3153 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_LP_MODE) {
3154 atomic_inc(&dsi->host_ref);
3155 tegra_dsi_host_resume(dc);
3159 static void tegra_dc_dsi_release_host(struct tegra_dc *dc)
3161 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
3163 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_LP_MODE) {
3164 atomic_dec(&dsi->host_ref);
3166 if (!atomic_read(&dsi->host_ref) &&
3167 (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE))
3168 schedule_delayed_work(&dsi->idle_work, dsi->idle_delay);
3172 static void tegra_dc_dsi_idle_work(struct work_struct *work)
3174 struct tegra_dc_dsi_data *dsi = container_of(
3175 to_delayed_work(work), struct tegra_dc_dsi_data, idle_work);
3177 if (dsi->dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_LP_MODE)
3178 tegra_dsi_host_suspend(dsi->dc);
3181 static int tegra_dsi_write_data_nosync(struct tegra_dc *dc,
3182 struct tegra_dc_dsi_data *dsi,
3183 struct tegra_dsi_cmd *cmd, u8 delay_ms)
3186 struct dsi_status *init_status;
3188 init_status = tegra_dsi_prepare_host_transmission(
3189 dc, dsi, DSI_LP_OP_WRITE);
3190 if (IS_ERR_OR_NULL(init_status)) {
3191 err = PTR_ERR(init_status);
3192 dev_err(&dc->ndev->dev, "DSI host config failed\n");
3196 err = _tegra_dsi_write_data(dsi, cmd);
3199 err = tegra_dsi_restore_state(dc, dsi, init_status);
3201 dev_err(&dc->ndev->dev, "Failed to restore prev state\n");
3206 int tegra_dsi_write_data(struct tegra_dc *dc,
3207 struct tegra_dc_dsi_data *dsi,
3208 struct tegra_dsi_cmd *cmd, u8 delay_ms)
3212 tegra_dc_io_start(dc);
3213 tegra_dc_dsi_hold_host(dc);
3215 err = tegra_dsi_write_data_nosync(dc, dsi, cmd, delay_ms);
3217 tegra_dc_dsi_release_host(dc);
3218 tegra_dc_io_end(dc);
3223 EXPORT_SYMBOL(tegra_dsi_write_data);
3225 int tegra_dsi_start_host_cmd_v_blank_video(struct tegra_dc_dsi_data *dsi,
3226 struct tegra_dsi_cmd *cmd, u8 clubbed_cmd_no)
3228 struct tegra_dc *dc = dsi->dc;
3233 if (!dsi->enabled) {
3234 dev_err(&dsi->dc->ndev->dev, "DSI controller suspended\n");
3238 tegra_dc_io_start(dc);
3239 tegra_dc_dsi_hold_host(dc);
3241 val = (DSI_CMD_PKT_VID_ENABLE(1) | DSI_LINE_TYPE(4));
3242 tegra_dsi_writel(dsi, val, DSI_VID_MODE_CONTROL);
3244 for (i = 0; i < clubbed_cmd_no; i++)
3245 _tegra_dsi_write_data(dsi, &cmd[i]);
3247 _tegra_dsi_write_data(dsi, &cmd[0]);
3249 if (dsi->status.lphs != DSI_LPHS_IN_HS_MODE) {
3250 err = tegra_dsi_set_to_hs_mode(dc, dsi,
3251 TEGRA_DSI_DRIVEN_BY_DC);
3253 dev_err(&dc->ndev->dev,
3254 "dsi: not able to set to hs mode\n");
3259 tegra_dsi_start_dc_stream(dc, dsi);
3260 tegra_dsi_wait_frame_end(dc, dsi, 2);
3262 tegra_dc_dsi_release_host(dc);
3263 tegra_dc_io_end(dc);
3267 EXPORT_SYMBOL(tegra_dsi_start_host_cmd_v_blank_video);
3269 int tegra_dsi_end_host_cmd_v_blank_video(struct tegra_dc *dc,
3270 struct tegra_dc_dsi_data *dsi)
3272 if (!dsi->enabled) {
3273 dev_err(&dsi->dc->ndev->dev, "DSI controller suspended\n");
3277 tegra_dc_io_start(dc);
3278 tegra_dsi_writel(dsi, 0, DSI_VID_MODE_CONTROL);
3279 tegra_dc_io_end(dc);
3283 EXPORT_SYMBOL(tegra_dsi_end_host_cmd_v_blank_video);
3285 int tegra_dsi_send_panel_cmd(struct tegra_dc *dc,
3286 struct tegra_dc_dsi_data *dsi,
3287 struct tegra_dsi_cmd *cmd,
3290 #define DEFAULT_DELAY_MS 1
3296 for (i = 0; i < n_cmd; i++) {
3297 struct tegra_dsi_cmd *cur_cmd;
3300 if (cur_cmd->cmd_type == TEGRA_DSI_GPIO_SET) {
3301 gpio_set_value(cur_cmd->sp_len_dly.gpio,
3303 } else if (cur_cmd->cmd_type == TEGRA_DSI_DELAY_MS) {
3304 usleep_range(cur_cmd->sp_len_dly.delay_ms * 1000,
3305 (cur_cmd->sp_len_dly.delay_ms * 1000) + 500);
3306 } else if (cur_cmd->cmd_type == TEGRA_DSI_SEND_FRAME) {
3307 tegra_dsi_send_dc_frames(dc,
3309 cur_cmd->sp_len_dly.frame_cnt);
3310 } else if (cur_cmd->cmd_type ==
3311 TEGRA_DSI_PACKET_VIDEO_VBLANK_CMD) {
3313 for (j = i; j < n_cmd; j++) {
3314 if (!IS_DSI_SHORT_PKT(cmd[j]))
3316 if (cmd[j].club_cmd != CMD_CLUBBED)
3318 if (j - i + 1 > DSI_HOST_FIFO_DEPTH)
3321 /* i..j-1: clubbable streak */
3322 tegra_dsi_start_host_cmd_v_blank_video(dsi, cur_cmd,
3324 tegra_dsi_end_host_cmd_v_blank_video(dc, dsi);
3328 delay_ms = DEFAULT_DELAY_MS;
3329 if ((i + 1 < n_cmd) &&
3330 (cmd[i + 1].cmd_type == TEGRA_DSI_DELAY_MS)) {
3331 delay_ms = cmd[i + 1].sp_len_dly.delay_ms;
3334 err = tegra_dsi_write_data_nosync(dc, dsi,
3341 #undef DEFAULT_DELAY_MS
3344 static u8 tegra_dsi_ecc(u32 header)
3346 char ecc_parity[24] = {
3347 0x07, 0x0b, 0x0d, 0x0e, 0x13, 0x15, 0x16, 0x19,
3348 0x1a, 0x1c, 0x23, 0x25, 0x26, 0x29, 0x2a, 0x2c,
3349 0x31, 0x32, 0x34, 0x38, 0x1f, 0x2f, 0x37, 0x3b
3355 for (i = 0; i < 24; i++)
3356 ecc_byte ^= ((header >> i) & 1) ? ecc_parity[i] : 0x00;
3361 static u16 tegra_dsi_cs(char *pdata, u16 data_len)
3370 for (byte_cnt = 0; byte_cnt < data_len; byte_cnt++) {
3371 curr_byte = pdata[byte_cnt];
3372 for (bit_cnt = 0; bit_cnt < 8; bit_cnt++) {
3373 if (((crc & 0x0001 ) ^
3374 (curr_byte & 0x0001)) > 0)
3375 crc = ((crc >> 1) & 0x7FFF) ^ poly;
3377 crc = (crc >> 1) & 0x7FFF;
3379 curr_byte = (curr_byte >> 1 ) & 0x7F;
3386 static int tegra_dsi_dcs_pkt_seq_ctrl_init(struct tegra_dc_dsi_data *dsi,
3387 struct tegra_dsi_cmd *cmd)
3391 u16 data_len = cmd->sp_len_dly.data_len;
3392 u8 seq_ctrl_reg = 0;
3394 virtual_channel = dsi->info.virtual_channel <<
3395 DSI_VIR_CHANNEL_BIT_POSITION;
3397 val = (virtual_channel | cmd->data_id) << 0 |
3400 val |= tegra_dsi_ecc(val) << 24;
3402 tegra_dsi_writel(dsi, val, DSI_INIT_SEQ_DATA_0 + seq_ctrl_reg++);
3404 /* if pdata != NULL, pkt type is long pkt */
3405 if (cmd->pdata != NULL) {
3408 /* allocate memory for pdata + 2 bytes checksum */
3409 pdata_mem = kzalloc(sizeof(u8) * data_len + 2, GFP_KERNEL);
3411 dev_err(&dsi->dc->ndev->dev, "dsi: memory err\n");
3412 tegra_dsi_soft_reset(dsi);
3416 memcpy(pdata_mem, cmd->pdata, data_len);
3418 *((u16 *)(pdata + data_len)) = tegra_dsi_cs(pdata, data_len);
3420 /* data_len = length of pdata + 2 byte checksum */
3424 if (data_len >= 4) {
3425 val = ((u32 *) pdata)[0];
3430 memcpy(&val, pdata, data_len);
3434 tegra_dsi_writel(dsi, val, DSI_INIT_SEQ_DATA_0 +
3443 int tegra_dsi_start_host_cmd_v_blank_dcs(struct tegra_dc_dsi_data *dsi,
3444 struct tegra_dsi_cmd *cmd)
3446 #define PKT_HEADER_LEN_BYTE 4
3447 #define CHECKSUM_LEN_BYTE 2
3451 u16 tot_pkt_len = PKT_HEADER_LEN_BYTE;
3452 struct tegra_dc *dc = dsi->dc;
3454 if (cmd->cmd_type != TEGRA_DSI_PACKET_CMD)
3457 mutex_lock(&dsi->lock);
3458 tegra_dc_io_start(dc);
3459 tegra_dc_dsi_hold_host(dc);
3461 #if DSI_USE_SYNC_POINTS
3462 atomic_set(&dsi_syncpt_rst, 1);
3465 err = tegra_dsi_dcs_pkt_seq_ctrl_init(dsi, cmd);
3467 dev_err(&dsi->dc->ndev->dev,
3468 "dsi: dcs pkt seq ctrl init failed\n");
3473 u16 data_len = cmd->sp_len_dly.data_len;
3474 tot_pkt_len += data_len + CHECKSUM_LEN_BYTE;
3477 val = DSI_INIT_SEQ_CONTROL_DSI_FRAME_INIT_BYTE_COUNT(tot_pkt_len) |
3478 DSI_INIT_SEQ_CONTROL_DSI_SEND_INIT_SEQUENCE(
3480 tegra_dsi_writel(dsi, val, DSI_INIT_SEQ_CONTROL);
3483 tegra_dc_dsi_release_host(dc);
3484 tegra_dc_io_end(dc);
3485 mutex_unlock(&dsi->lock);
3488 #undef PKT_HEADER_LEN_BYTE
3489 #undef CHECKSUM_LEN_BYTE
3491 EXPORT_SYMBOL(tegra_dsi_start_host_cmd_v_blank_dcs);
3493 void tegra_dsi_stop_host_cmd_v_blank_dcs(struct tegra_dc_dsi_data *dsi)
3495 struct tegra_dc *dc = dsi->dc;
3498 mutex_lock(&dsi->lock);
3499 tegra_dc_io_start(dc);
3500 tegra_dc_dsi_hold_host(dc);
3502 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
3503 if (atomic_read(&dsi_syncpt_rst)) {
3504 tegra_dsi_wait_frame_end(dc, dsi, 2);
3505 tegra_dsi_syncpt_reset(dsi);
3506 atomic_set(&dsi_syncpt_rst, 0);
3509 tegra_dsi_writel(dsi, TEGRA_DSI_DISABLE, DSI_INIT_SEQ_CONTROL);
3511 /* clear seq data registers */
3512 for (cnt = 0; cnt < 8; cnt++)
3513 tegra_dsi_writel(dsi, 0, DSI_INIT_SEQ_DATA_0 + cnt);
3515 tegra_dc_dsi_release_host(dc);
3516 tegra_dc_io_end(dc);
3518 mutex_unlock(&dsi->lock);
3520 EXPORT_SYMBOL(tegra_dsi_stop_host_cmd_v_blank_dcs);
3522 static int tegra_dsi_bta(struct tegra_dc_dsi_data *dsi)
3527 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
3528 val |= DSI_HOST_DSI_CONTROL_IMM_BTA(TEGRA_DSI_ENABLE);
3529 tegra_dsi_controller_writel(dsi, val,
3530 DSI_HOST_DSI_CONTROL, TEGRA_DSI_LINK0);
3532 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS) {
3533 err = tegra_dsi_syncpt(dsi, TEGRA_DSI_LINK0);
3535 dev_err(&dsi->dc->ndev->dev,
3536 "DSI syncpt for bta failed\n");
3539 if (tegra_dsi_read_busy(dsi, TEGRA_DSI_LINK0)) {
3541 dev_err(&dsi->dc->ndev->dev,
3542 "Timeout wating on read completion\n");
3549 static int tegra_dsi_parse_read_response(struct tegra_dc *dc,
3550 u32 rd_fifo_cnt, u8 *read_fifo)
3558 switch (read_fifo[0]) {
3559 case DSI_ESCAPE_CMD:
3560 dev_info(&dc->ndev->dev, "escape cmd[0x%x]\n", read_fifo[0]);
3562 case DSI_ACK_NO_ERR:
3563 dev_info(&dc->ndev->dev,
3564 "Panel ack, no err[0x%x]\n", read_fifo[0]);
3567 dev_info(&dc->ndev->dev, "Invalid read response\n");
3571 switch (read_fifo[4] & 0xff) {
3572 case GEN_LONG_RD_RES:
3574 case DCS_LONG_RD_RES:
3575 payload_size = (read_fifo[5] |
3576 (read_fifo[6] << 8)) & 0xFFFF;
3577 dev_info(&dc->ndev->dev, "Long read response Packet\n"
3578 "payload_size[0x%x]\n", payload_size);
3580 case GEN_1_BYTE_SHORT_RD_RES:
3582 case DCS_1_BYTE_SHORT_RD_RES:
3584 dev_info(&dc->ndev->dev, "Short read response Packet\n"
3585 "payload_size[0x%x]\n", payload_size);
3587 case GEN_2_BYTE_SHORT_RD_RES:
3589 case DCS_2_BYTE_SHORT_RD_RES:
3591 dev_info(&dc->ndev->dev, "Short read response Packet\n"
3592 "payload_size[0x%x]\n", payload_size);
3596 dev_info(&dc->ndev->dev, "Acknowledge error report response\n"
3597 "Packet payload_size[0x%x]\n", payload_size);
3600 dev_info(&dc->ndev->dev, "Invalid response packet\n");
3607 static int tegra_dsi_read_fifo(struct tegra_dc *dc,
3608 struct tegra_dc_dsi_data *dsi,
3616 u8 *read_fifo_cp = read_fifo;
3618 while (poll_time < DSI_DELAY_FOR_READ_FIFO) {
3620 val = tegra_dsi_readl(dsi, DSI_STATUS);
3621 rd_fifo_cnt = val & DSI_STATUS_RD_FIFO_COUNT(0x1f);
3622 if (rd_fifo_cnt << 2 > DSI_READ_FIFO_DEPTH) {
3623 dev_err(&dc->ndev->dev,
3624 "DSI RD_FIFO_CNT is greater than RD_FIFO_DEPTH\n");
3630 if (rd_fifo_cnt == 0) {
3631 dev_info(&dc->ndev->dev,
3632 "DSI RD_FIFO_CNT is zero\n");
3637 if (val & (DSI_STATUS_LB_UNDERFLOW(0x1) |
3638 DSI_STATUS_LB_OVERFLOW(0x1))) {
3639 dev_warn(&dc->ndev->dev,
3640 "DSI overflow/underflow error\n");
3643 /* Read data from FIFO */
3644 for (i = 0; i < rd_fifo_cnt; i++) {
3645 val = tegra_dsi_readl(dsi, DSI_RD_DATA);
3646 if (enable_read_debug)
3647 dev_info(&dc->ndev->dev,
3648 "Read data[%d]: 0x%x\n", i, val);
3649 memcpy(read_fifo, &val, 4);
3653 /* Make sure all the data is read from the FIFO */
3654 val = tegra_dsi_readl(dsi, DSI_STATUS);
3655 val &= DSI_STATUS_RD_FIFO_COUNT(0x1f);
3657 dev_err(&dc->ndev->dev, "DSI FIFO_RD_CNT not zero"
3658 " even after reading FIFO_RD_CNT words from read fifo\n");
3660 if (enable_read_debug) {
3662 tegra_dsi_parse_read_response(dc, rd_fifo_cnt, read_fifo_cp);
3664 dev_warn(&dc->ndev->dev, "Unexpected read data\n");
3670 int tegra_dsi_read_data(struct tegra_dc *dc,
3671 struct tegra_dc_dsi_data *dsi,
3672 u16 max_ret_payload_size,
3673 u8 panel_reg_addr, u8 *read_data)
3676 struct dsi_status *init_status;
3677 static struct tegra_dsi_cmd temp_cmd;
3679 if (!dsi->enabled) {
3680 dev_err(&dc->ndev->dev, "DSI controller suspended\n");
3683 tegra_dc_dsi_hold_host(dc);
3684 mutex_lock(&dsi->lock);
3685 tegra_dc_io_start(dc);
3686 clk_prepare_enable(dsi->dsi_fixed_clk);
3687 tegra_dsi_lp_clk_enable(dsi);
3688 init_status = tegra_dsi_prepare_host_transmission(
3689 dc, dsi, DSI_LP_OP_WRITE);
3690 if (IS_ERR_OR_NULL(init_status)) {
3691 err = PTR_ERR(init_status);
3692 dev_err(&dc->ndev->dev, "DSI host config failed\n");
3696 /* Set max return payload size in words */
3697 temp_cmd.data_id = dsi_command_max_return_pkt_size;
3698 temp_cmd.sp_len_dly.data_len = max_ret_payload_size;
3699 err = _tegra_dsi_write_data(dsi, &temp_cmd);
3701 dev_err(&dc->ndev->dev,
3702 "DSI write failed\n");
3706 /* DCS to read given panel register */
3707 temp_cmd.data_id = dsi_command_dcs_read_with_no_params;
3708 temp_cmd.sp_len_dly.sp.data0 = panel_reg_addr;
3709 temp_cmd.sp_len_dly.sp.data1 = 0;
3710 err = _tegra_dsi_write_data(dsi, &temp_cmd);
3712 dev_err(&dc->ndev->dev,
3713 "DSI write failed\n");
3717 tegra_dsi_reset_read_count(dsi);
3719 if (dsi->status.lp_op == DSI_LP_OP_WRITE) {
3720 err = tegra_dsi_set_to_lp_mode(dc, dsi, DSI_LP_OP_READ);
3722 dev_err(&dc->ndev->dev,
3723 "DSI failed to go to LP read mode\n");
3728 err = tegra_dsi_bta(dsi);
3730 dev_err(&dc->ndev->dev,
3731 "DSI IMM BTA timeout\n");
3735 err = tegra_dsi_read_fifo(dc, dsi, read_data);
3737 dev_err(&dc->ndev->dev, "DSI read fifo failure\n");
3741 err = tegra_dsi_restore_state(dc, dsi, init_status);
3743 dev_err(&dc->ndev->dev, "Failed to restore prev state\n");
3744 tegra_dsi_lp_clk_disable(dsi);
3745 clk_disable_unprepare(dsi->dsi_fixed_clk);
3746 tegra_dc_io_end(dc);
3747 mutex_unlock(&dsi->lock);
3748 tegra_dc_dsi_release_host(dc);
3751 EXPORT_SYMBOL(tegra_dsi_read_data);
3753 static const char * const error_sanity[] = {
3757 "Escape Mode Entry Comand Error",
3758 "Low-Power Transmit Sync Error",
3759 "HS Receive Timeout Error",
3760 "False Control Error",
3762 "ECC Error,Single Bit",
3763 "ECC Error, Multi Bit",
3765 "DSI Data Type Not recognized",
3766 "DSI VC ID Invalid",
3767 "DSI Protocol Violation",
3772 int tegra_dsi_panel_sanity_check(struct tegra_dc *dc,
3773 struct tegra_dc_dsi_data *dsi,
3774 struct sanity_status *san)
3778 u8 read_fifo[DSI_READ_FIFO_DEPTH];
3779 struct dsi_status *init_status;
3780 static struct tegra_dsi_cmd dsi_nop_cmd =
3781 DSI_CMD_SHORT(0x05, 0x0, 0x0);
3783 if (!dsi->enabled) {
3784 dev_err(&dc->ndev->dev, "DSI controller suspended\n");
3787 tegra_dc_dsi_hold_host(dc);
3788 tegra_dc_io_start(dc);
3789 clk_prepare_enable(dsi->dsi_fixed_clk);
3790 tegra_dsi_lp_clk_enable(dsi);
3791 memset(flagset, 0, sizeof(flagset));
3792 init_status = tegra_dsi_prepare_host_transmission(
3793 dc, dsi, DSI_LP_OP_WRITE);
3794 if (IS_ERR_OR_NULL(init_status)) {
3795 err = PTR_ERR(init_status);
3796 dev_err(&dc->ndev->dev, "DSI host config failed\n");
3800 err = _tegra_dsi_write_data(dsi, &dsi_nop_cmd);
3802 dev_err(&dc->ndev->dev, "DSI nop write failed\n");
3806 tegra_dsi_reset_read_count(dsi);
3808 if (dsi->status.lp_op == DSI_LP_OP_WRITE) {
3809 err = tegra_dsi_set_to_lp_mode(dc, dsi, DSI_LP_OP_READ);
3811 dev_err(&dc->ndev->dev,
3812 "DSI failed to go to LP read mode\n");
3817 err = tegra_dsi_bta(dsi);
3819 dev_err(&dc->ndev->dev, "DSI BTA failed\n");
3823 err = tegra_dsi_read_fifo(dc, dsi, read_fifo);
3825 dev_err(&dc->ndev->dev, "DSI read fifo failure\n");
3829 if (read_fifo[0] != DSI_ACK_NO_ERR) {
3830 if (read_fifo[4] == ACK_ERR_RES) {
3831 u16 payload = read_fifo[5] | (read_fifo[6] << 8);
3833 for (; payload; payload >>= 1, i++) {
3836 if (enable_read_debug)
3837 dev_info(&dc->ndev->dev,
3838 " %s => error flag number %d\n",
3839 error_sanity[i], i);
3843 san->sot_error = flagset[0];
3844 san->sot_sync_error = flagset[1];
3845 san->eot_sync_error = flagset[2];
3846 san->escape_mode_entry_comand_error =
3848 san->low_power_transmit_sync_error = flagset[4];
3849 san->hs_receive_timeout_error = flagset[5];
3850 san->false_control_error = flagset[6];
3851 san->reserved1 = flagset[7];
3852 san->ecc_error_single_bit = flagset[8];
3853 san->ecc_error_multi_bit = flagset[9];
3854 san->checksum_error = flagset[10];
3855 san->dsi_data_type_not_recognized = flagset[11];
3856 san->dsi_vc_id_invalid = flagset[12];
3857 san->dsi_protocol_violation = flagset[13];
3858 san->reserved2 = flagset[14];
3859 san->reserved3 = flagset[15];
3862 dev_warn(&dc->ndev->dev,
3863 "Ack no error trigger message not received\n");
3868 err = tegra_dsi_restore_state(dc, dsi, init_status);
3870 dev_err(&dc->ndev->dev, "Failed to restore prev state\n");
3871 tegra_dsi_lp_clk_disable(dsi);
3872 clk_disable_unprepare(dsi->dsi_fixed_clk);
3873 tegra_dc_io_end(dc);
3874 tegra_dc_dsi_release_host(dc);
3877 EXPORT_SYMBOL(tegra_dsi_panel_sanity_check);
3879 static int tegra_dsi_enter_ulpm(struct tegra_dc_dsi_data *dsi)
3884 if (dsi->info.ulpm_not_supported)
3887 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
3888 if (atomic_read(&dsi_syncpt_rst))
3889 tegra_dsi_syncpt_reset(dsi);
3891 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
3892 val &= ~DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(3);
3893 val |= DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(ENTER_ULPM);
3894 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
3896 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS) {
3897 ret = tegra_dsi_syncpt(dsi, TEGRA_DSI_LINK0);
3899 dev_err(&dsi->dc->ndev->dev,
3900 "DSI syncpt for ulpm enter failed\n");
3904 /* TODO: Find exact delay required */
3912 static int tegra_dsi_exit_ulpm(struct tegra_dc_dsi_data *dsi)
3917 if (dsi->info.ulpm_not_supported)
3920 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS)
3921 if (atomic_read(&dsi_syncpt_rst))
3922 tegra_dsi_syncpt_reset(dsi);
3924 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
3925 val &= ~DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(3);
3926 val |= DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(EXIT_ULPM);
3927 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
3929 if (!tegra_cpu_is_asim() && DSI_USE_SYNC_POINTS) {
3930 ret = tegra_dsi_syncpt(dsi, TEGRA_DSI_LINK0);
3932 dev_err(&dsi->dc->ndev->dev,
3933 "DSI syncpt for ulpm exit failed\n");
3937 /* TODO: Find exact delay required */
3942 val = tegra_dsi_readl(dsi, DSI_HOST_DSI_CONTROL);
3943 val &= ~DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(0x3);
3944 val |= DSI_HOST_DSI_CONTROL_ULTRA_LOW_POWER(NORMAL);
3945 tegra_dsi_writel(dsi, val, DSI_HOST_DSI_CONTROL);
3950 static void tegra_dsi_send_dc_frames(struct tegra_dc *dc,
3951 struct tegra_dc_dsi_data *dsi,
3955 u32 frame_period = DIV_ROUND_UP(S_TO_MS(1), dsi->info.refresh_rate);
3956 u8 lp_op = dsi->status.lp_op;
3957 bool switch_to_lp = (dsi->status.lphs == DSI_LPHS_IN_LP_MODE);
3959 if (dsi->status.lphs != DSI_LPHS_IN_HS_MODE) {
3960 err = tegra_dsi_set_to_hs_mode(dc, dsi,
3961 TEGRA_DSI_DRIVEN_BY_DC);
3963 dev_err(&dc->ndev->dev,
3964 "Switch to HS host mode failed\n");
3970 * Some panels need DC frames be sent under certain
3971 * conditions. We are working on the right fix for this
3972 * requirement, while using this current fix.
3974 tegra_dsi_start_dc_stream(dc, dsi);
3977 * Send frames in Continuous or One-shot mode.
3979 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_MODE) {
3980 /* FIX ME: tegra_dc_blank() implicitly takes lock */
3981 int flag = mutex_is_locked(&dc->lock);
3983 mutex_unlock(&dc->lock);
3984 while (no_of_frames--)
3985 tegra_dc_blank(dc, BLANK_ALL);
3987 mutex_lock(&dc->lock);
3989 mdelay(no_of_frames * frame_period);
3991 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
3994 err = tegra_dsi_set_to_lp_mode(dc, dsi, lp_op);
3996 dev_err(&dc->ndev->dev,
3997 "DSI failed to go to LP mode\n");
4001 static void tegra_dsi_setup_initialized_panel(struct tegra_dc_dsi_data *dsi)
4005 if (dsi->avdd_dsi_csi)
4006 err = regulator_enable(dsi->avdd_dsi_csi);
4007 WARN(err, "unable to enable regulator");
4009 dsi->status.init = DSI_MODULE_INIT;
4010 dsi->status.lphs = DSI_LPHS_IN_HS_MODE;
4011 dsi->status.driven = DSI_DRIVEN_MODE_DC;
4012 dsi->driven_mode = TEGRA_DSI_DRIVEN_BY_DC;
4013 dsi->status.clk_out = DSI_PHYCLK_OUT_EN;
4014 dsi->status.lp_op = DSI_LP_OP_NOT_INIT;
4015 dsi->status.dc_stream = DSI_DC_STREAM_ENABLE;
4017 if (dsi->info.video_clock_mode == TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS)
4018 dsi->status.clk_mode = DSI_PHYCLK_CONTINUOUS;
4020 dsi->status.clk_mode = DSI_PHYCLK_TX_ONLY;
4022 if (!(dsi->info.ganged_type)) {
4023 if (dsi->info.video_burst_mode ==
4024 TEGRA_DSI_VIDEO_NONE_BURST_MODE ||
4025 dsi->info.video_burst_mode ==
4026 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END)
4027 dsi->status.clk_burst = DSI_CLK_BURST_NONE_BURST;
4029 dsi->status.clk_burst = DSI_CLK_BURST_BURST_MODE;
4032 if (dsi->info.video_data_type == TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE)
4033 dsi->status.vtype = DSI_VIDEO_TYPE_CMD_MODE;
4035 dsi->status.vtype = DSI_VIDEO_TYPE_VIDEO_MODE;
4037 tegra_dsi_clk_enable(dsi);
4039 dsi->enabled = true;
4042 static void tegra_dc_dsi_enable(struct tegra_dc *dc)
4044 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4047 mutex_lock(&dsi->lock);
4048 tegra_dc_io_start(dc);
4051 * Do not program this panel as the bootloader as has already
4052 * initialized it. This avoids periods of blanking during boot.
4054 if (dc->out->flags & TEGRA_DC_OUT_INITIALIZED_MODE) {
4055 tegra_dsi_setup_initialized_panel(dsi);
4059 /* Stop DC stream before configuring DSI registers
4060 * to avoid visible glitches on panel during transition
4061 * from bootloader to kernel driver
4063 tegra_dsi_stop_dc_stream(dc, dsi);
4067 if (tegra_dsi_exit_ulpm(dsi) < 0) {
4068 dev_err(&dc->ndev->dev,
4069 "DSI failed to exit ulpm\n");
4074 if (dsi->info.panel_reset) {
4076 * Certain panels need dc frames be sent before
4079 if (dsi->info.panel_send_dc_frames)
4080 tegra_dsi_send_dc_frames(dc, dsi, 2);
4082 err = tegra_dsi_send_panel_cmd(dc, dsi,
4083 dsi->info.dsi_init_cmd,
4084 dsi->info.n_init_cmd);
4086 dev_err(&dc->ndev->dev,
4087 "dsi: error sending dsi init cmd\n");
4090 } else if (dsi->info.dsi_late_resume_cmd) {
4091 err = tegra_dsi_send_panel_cmd(dc, dsi,
4092 dsi->info.dsi_late_resume_cmd,
4093 dsi->info.n_late_resume_cmd);
4095 dev_err(&dc->ndev->dev,
4096 "dsi: error sending late resume cmd\n");
4101 err = tegra_dsi_init_hw(dc, dsi);
4103 dev_err(&dc->ndev->dev,
4104 "dsi: not able to init dsi hardware\n");
4109 if (tegra_dsi_enter_ulpm(dsi) < 0) {
4110 dev_err(&dc->ndev->dev,
4111 "DSI failed to enter ulpm\n");
4115 tegra_dsi_pad_enable(dsi);
4117 if (tegra_dsi_exit_ulpm(dsi) < 0) {
4118 dev_err(&dc->ndev->dev,
4119 "DSI failed to exit ulpm\n");
4125 * Certain panels need dc frames be sent before
4128 if (dsi->info.panel_send_dc_frames)
4129 tegra_dsi_send_dc_frames(dc, dsi, 2);
4131 err = tegra_dsi_set_to_lp_mode(dc, dsi, DSI_LP_OP_WRITE);
4133 dev_err(&dc->ndev->dev,
4134 "dsi: not able to set to lp mode\n");
4138 if (dsi->info.lp00_pre_panel_wakeup)
4139 tegra_dsi_pad_disable(dsi);
4141 dsi->enabled = true;
4144 if (dsi->out_ops && dsi->out_ops->enable)
4145 dsi->out_ops->enable(dsi);
4147 tegra_dc_io_end(dc);
4148 mutex_unlock(&dsi->lock);
4151 static void tegra_dc_dsi_postpoweron(struct tegra_dc *dc)
4153 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4157 * Do not configure. Use bootloader configuration.
4158 * This avoids periods of blanking during boot.
4160 if (dc->out->flags & TEGRA_DC_OUT_INITIALIZED_MODE)
4163 mutex_lock(&dsi->lock);
4164 tegra_dc_io_start(dc);
4167 if (dsi->info.lp00_pre_panel_wakeup)
4168 tegra_dsi_pad_enable(dsi);
4170 err = tegra_dsi_send_panel_cmd(dc, dsi, dsi->info.dsi_init_cmd,
4171 dsi->info.n_init_cmd);
4173 dev_err(&dc->ndev->dev,
4174 "dsi: error while sending dsi init cmd\n");
4178 err = tegra_dsi_set_to_hs_mode(dc, dsi,
4179 TEGRA_DSI_DRIVEN_BY_DC);
4181 dev_err(&dc->ndev->dev,
4182 "dsi: not able to set to hs mode\n");
4186 if (dsi->status.driven == DSI_DRIVEN_MODE_DC)
4187 tegra_dsi_start_dc_stream(dc, dsi);
4189 dsi->host_suspended = false;
4192 tegra_dc_io_end(dc);
4193 mutex_unlock(&dsi->lock);
4196 static void __tegra_dc_dsi_init(struct tegra_dc *dc)
4198 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4200 #ifdef CONFIG_DEBUG_FS
4201 tegra_dc_dsi_debug_create(dsi);
4204 if (dsi->info.dsi2lvds_bridge_enable)
4205 dsi->out_ops = &tegra_dsi2lvds_ops;
4206 else if (dsi->info.dsi2edp_bridge_enable)
4207 dsi->out_ops = &tegra_dsi2edp_ops;
4209 dsi->out_ops = NULL;
4211 if (dsi->out_ops && dsi->out_ops->init)
4212 dsi->out_ops->init(dsi);
4214 tegra_dsi_init_sw(dc, dsi);
4217 static int tegra_dc_dsi_cp_p_cmd(struct tegra_dsi_cmd *src,
4218 struct tegra_dsi_cmd *dst, u16 n_cmd)
4223 memcpy(dst, src, sizeof(*dst) * n_cmd);
4225 for (i = 0; i < n_cmd; i++)
4227 len = sizeof(*src[i].pdata) *
4228 src[i].sp_len_dly.data_len;
4229 dst[i].pdata = kzalloc(len, GFP_KERNEL);
4231 goto free_cmd_pdata;
4232 memcpy(dst[i].pdata, src[i].pdata, len);
4240 kfree(dst[i].pdata);
4244 static int tegra_dc_dsi_cp_info(struct tegra_dc_dsi_data *dsi,
4245 struct tegra_dsi_out *p_dsi)
4247 struct tegra_dsi_cmd *p_init_cmd;
4248 struct tegra_dsi_cmd *p_early_suspend_cmd = NULL;
4249 struct tegra_dsi_cmd *p_late_resume_cmd = NULL;
4250 struct tegra_dsi_cmd *p_suspend_cmd;
4253 if (p_dsi->n_data_lanes > MAX_DSI_DATA_LANES)
4256 p_init_cmd = kzalloc(sizeof(*p_init_cmd) *
4257 p_dsi->n_init_cmd, GFP_KERNEL);
4261 if (p_dsi->dsi_early_suspend_cmd) {
4262 p_early_suspend_cmd = kzalloc(sizeof(*p_early_suspend_cmd) *
4263 p_dsi->n_early_suspend_cmd,
4265 if (!p_early_suspend_cmd) {
4267 goto err_free_init_cmd;
4271 if (p_dsi->dsi_late_resume_cmd) {
4272 p_late_resume_cmd = kzalloc(sizeof(*p_late_resume_cmd) *
4273 p_dsi->n_late_resume_cmd,
4275 if (!p_late_resume_cmd) {
4277 goto err_free_p_early_suspend_cmd;
4281 p_suspend_cmd = kzalloc(sizeof(*p_suspend_cmd) * p_dsi->n_suspend_cmd,
4283 if (!p_suspend_cmd) {
4285 goto err_free_p_late_resume_cmd;
4288 memcpy(&dsi->info, p_dsi, sizeof(dsi->info));
4290 /* Copy panel init cmd */
4291 err = tegra_dc_dsi_cp_p_cmd(p_dsi->dsi_init_cmd,
4292 p_init_cmd, p_dsi->n_init_cmd);
4295 dsi->info.dsi_init_cmd = p_init_cmd;
4297 /* Copy panel early suspend cmd */
4298 if (p_dsi->dsi_early_suspend_cmd) {
4299 err = tegra_dc_dsi_cp_p_cmd(p_dsi->dsi_early_suspend_cmd,
4300 p_early_suspend_cmd,
4301 p_dsi->n_early_suspend_cmd);
4304 dsi->info.dsi_early_suspend_cmd = p_early_suspend_cmd;
4307 /* Copy panel late resume cmd */
4308 if (p_dsi->dsi_late_resume_cmd) {
4309 err = tegra_dc_dsi_cp_p_cmd(p_dsi->dsi_late_resume_cmd,
4311 p_dsi->n_late_resume_cmd);
4314 dsi->info.dsi_late_resume_cmd = p_late_resume_cmd;
4317 /* Copy panel suspend cmd */
4318 err = tegra_dc_dsi_cp_p_cmd(p_dsi->dsi_suspend_cmd, p_suspend_cmd,
4319 p_dsi->n_suspend_cmd);
4322 dsi->info.dsi_suspend_cmd = p_suspend_cmd;
4324 if (!dsi->info.panel_reset_timeout_msec)
4325 dsi->info.panel_reset_timeout_msec =
4326 DEFAULT_PANEL_RESET_TIMEOUT;
4327 if (!dsi->info.panel_buffer_size_byte)
4328 dsi->info.panel_buffer_size_byte = DEFAULT_PANEL_BUFFER_BYTE;
4330 if (!dsi->info.max_panel_freq_khz) {
4331 dsi->info.max_panel_freq_khz = DEFAULT_MAX_DSI_PHY_CLK_KHZ;
4333 if (dsi->info.video_burst_mode >
4334 TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END){
4335 dev_err(&dsi->dc->ndev->dev, "DSI: max_panel_freq_khz"
4336 "is not set for DSI burst mode.\n");
4337 dsi->info.video_burst_mode =
4338 TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED;
4342 if (!dsi->info.lp_cmd_mode_freq_khz)
4343 dsi->info.lp_cmd_mode_freq_khz = DEFAULT_LP_CMD_MODE_CLK_KHZ;
4345 if (!dsi->info.lp_read_cmd_mode_freq_khz)
4346 dsi->info.lp_read_cmd_mode_freq_khz =
4347 dsi->info.lp_cmd_mode_freq_khz;
4349 /* host mode is for testing only */
4350 dsi->driven_mode = TEGRA_DSI_DRIVEN_BY_DC;
4354 kfree(p_suspend_cmd);
4355 err_free_p_late_resume_cmd:
4356 kfree(p_late_resume_cmd);
4357 err_free_p_early_suspend_cmd:
4358 kfree(p_early_suspend_cmd);
4364 static int _tegra_dc_dsi_init(struct tegra_dc *dc)
4366 struct tegra_dc_dsi_data *dsi;
4367 struct resource *res;
4368 struct resource *base_res;
4369 struct resource dsi_res;
4371 struct clk *dc_clk = NULL;
4372 struct clk *dsi_clk;
4373 struct clk *dsi_fixed_clk = NULL;
4374 struct clk *dsi_lp_clk = NULL;
4375 struct tegra_dsi_out *dsi_pdata = NULL;
4378 char *ganged_reg_name[2] = {"ganged_dsia_regs", "ganged_dsib_regs"};
4379 char *dsi_clk_name[2] = {"dsia", "dsib"};
4380 char *dsi_lp_clk_name[2] = {"dsialp", "dsiblp"};
4381 struct device_node *np = dc->ndev->dev.of_node;
4382 #ifdef CONFIG_USE_OF
4383 struct device_node *np_dsi =
4384 of_find_node_by_path(DSI_NODE);
4386 struct device_node *np_dsi = NULL;
4388 dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
4390 dev_err(&dc->ndev->dev, "dsi: memory allocation failed\n");
4394 dsi->max_instances = dc->out->dsi->ganged_type ? MAX_DSI_INSTANCE : 1;
4395 dsi_instance = (int)dc->out->dsi->dsi_instance;
4396 for (i = 0; i < dsi->max_instances; i++) {
4398 if (np_dsi && of_device_is_available(np_dsi)) {
4399 if (!dc->out->dsi->ganged_type)
4400 of_address_to_resource(np_dsi,
4401 dsi_instance, &dsi_res);
4402 else /* ganged type */
4403 of_address_to_resource(np_dsi,
4411 res = platform_get_resource_byname(dc->ndev,
4413 dc->out->dsi->ganged_type ?
4414 ganged_reg_name[i] : "dsi_regs");
4417 dev_err(&dc->ndev->dev, "dsi: no mem resource\n");
4422 base_res = request_mem_region(res->start, resource_size(res),
4425 dev_err(&dc->ndev->dev,
4426 "dsi: request_mem_region failed\n");
4431 base = ioremap(res->start, resource_size(res));
4433 dev_err(&dc->ndev->dev,
4434 "dsi: registers can't be mapped\n");
4436 goto err_release_regs;
4439 dsi_pdata = dc->pdata->default_out->dsi;
4441 dev_err(&dc->ndev->dev, "dsi: dsi data not available\n");
4442 goto err_release_regs;
4445 dsi_clk = dsi_pdata->dsi_instance ?
4446 clk_get(&dc->ndev->dev,
4447 dsi_clk_name[DSI_INSTANCE_1]) :
4448 clk_get(&dc->ndev->dev, dsi_clk_name[i]);
4449 dsi_lp_clk = dsi_pdata->dsi_instance ?
4450 clk_get(&dc->ndev->dev,
4451 dsi_lp_clk_name[DSI_INSTANCE_1]) :
4452 clk_get(&dc->ndev->dev, dsi_lp_clk_name[i]);
4454 if (IS_ERR_OR_NULL(dsi_clk) || IS_ERR_OR_NULL(dsi_lp_clk)) {
4455 dev_err(&dc->ndev->dev, "dsi: can't get clock\n");
4457 goto err_dsi_clk_put;
4460 dsi->base[i] = base;
4461 dsi->base_res[i] = base_res;
4462 dsi->dsi_clk[i] = dsi_clk;
4463 dsi->dsi_lp_clk[i] = dsi_lp_clk;
4466 dsi_fixed_clk = clk_get(&dc->ndev->dev, "dsi-fixed");
4468 if (IS_ERR_OR_NULL(dsi_fixed_clk)) {
4469 dev_err(&dc->ndev->dev, "dsi: can't get fixed clock\n");
4471 goto err_release_regs;
4474 dc_clk = clk_get_sys(dev_name(&dc->ndev->dev), NULL);
4475 if (IS_ERR_OR_NULL(dc_clk)) {
4476 dev_err(&dc->ndev->dev, "dsi: dc clock %s unavailable\n",
4477 dev_name(&dc->ndev->dev));
4479 goto err_dsi_fixed_clk_put;
4482 mutex_init(&dsi->lock);
4484 dsi->dc_clk = dc_clk;
4485 dsi->dsi_fixed_clk = dsi_fixed_clk;
4487 err = tegra_dc_dsi_cp_info(dsi, dsi_pdata);
4489 goto err_dc_clk_put;
4491 tegra_dc_set_outdata(dc, dsi);
4492 __tegra_dc_dsi_init(dc);
4495 * Enable DPD mode for DSI pads if required.
4497 if (!dsi->info.ganged_type &&
4498 (dsi->info.controller_vs >= DSI_VS_1)) {
4499 if (dsi->info.dpd_dsi_pads & DSI_DPD_EN)
4500 tegra_io_dpd_enable(&dsi_io);
4501 if (dsi->info.dpd_dsi_pads & DSIB_DPD_EN)
4502 tegra_io_dpd_enable(&dsib_io);
4503 if (dsi->info.dpd_dsi_pads & DSIC_DPD_EN)
4504 tegra_io_dpd_enable(&dsic_io);
4505 if (dsi->info.dpd_dsi_pads & DSID_DPD_EN)
4506 tegra_io_dpd_enable(&dsid_io);
4513 err_dsi_fixed_clk_put:
4514 clk_put(dsi_fixed_clk);
4516 for (i = 0; i < dsi->max_instances; i++) {
4517 clk_put(dsi->dsi_lp_clk[i]);
4518 clk_put(dsi->dsi_clk[i]);
4521 for (i = 0; i < dsi->max_instances; i++)
4522 release_resource(dsi->base_res[i]);
4529 static void _tegra_dc_dsi_destroy(struct tegra_dc *dc)
4531 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4535 mutex_lock(&dsi->lock);
4536 tegra_dc_io_start(dc);
4538 if (dsi->out_ops && dsi->out_ops->destroy)
4539 dsi->out_ops->destroy(dsi);
4541 /* free up the pdata */
4542 for (i = 0; i < dsi->info.n_init_cmd; i++) {
4543 if (dsi->info.dsi_init_cmd[i].pdata)
4544 kfree(dsi->info.dsi_init_cmd[i].pdata);
4546 kfree(dsi->info.dsi_init_cmd);
4548 /* Disable dc stream */
4549 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
4550 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
4552 /* Disable dsi phy clock */
4553 if (dsi->status.clk_out == DSI_PHYCLK_OUT_EN)
4554 tegra_dsi_hs_clk_out_disable(dc, dsi);
4556 val = DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE);
4557 tegra_dsi_writel(dsi, val, DSI_POWER_CONTROL);
4559 for (i = 0; i < dsi->max_instances; i++) {
4560 iounmap(dsi->base[i]);
4561 release_resource(dsi->base_res[i]);
4563 clk_put(dsi->dc_clk);
4564 for (i = 0; i < dsi->max_instances; i++)
4565 clk_put(dsi->dsi_clk[i]);
4567 tegra_dc_io_end(dc);
4568 mutex_unlock(&dsi->lock);
4569 mutex_destroy(&dsi->lock);
4573 static void tegra_dsi_config_phy_clk(struct tegra_dc_dsi_data *dsi,
4576 struct clk *parent_clk = NULL;
4577 struct clk *base_clk = NULL;
4580 for (i = 0; i < dsi->max_instances; i++) {
4581 parent_clk = clk_get_parent(dsi->dsi_clk[i]);
4582 base_clk = clk_get_parent(parent_clk);
4584 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
4585 if (dsi->info.dsi_instance)
4586 tegra_clk_cfg_ex(base_clk,
4587 TEGRA_CLK_PLLD_CSI_OUT_ENB,
4590 tegra_clk_cfg_ex(base_clk,
4591 TEGRA_CLK_PLLD_DSI_OUT_ENB,
4594 tegra_clk_cfg_ex(base_clk,
4595 TEGRA_CLK_PLLD_DSI_OUT_ENB,
4601 static int tegra_dsi_te_on_off(struct tegra_dc_dsi_data *dsi, bool flag)
4605 struct tegra_dsi_cmd te_enable[] = {
4606 DSI_CMD_SHORT(DSI_DCS_WRITE_0_PARAM,
4607 DSI_DCS_SET_TEARING_EFFECT_ON, 0x0),
4611 struct tegra_dsi_cmd te_disable[] = {
4612 DSI_CMD_SHORT(DSI_DCS_WRITE_0_PARAM,
4613 DSI_DCS_SET_TEARING_EFFECT_OFF, 0x0),
4618 ret = tegra_dsi_send_panel_cmd(dsi->dc, dsi, te_enable,
4619 ARRAY_SIZE(te_enable));
4621 ret = tegra_dsi_send_panel_cmd(dsi->dc, dsi, te_disable,
4622 ARRAY_SIZE(te_disable));
4627 static int _tegra_dsi_host_suspend(struct tegra_dc *dc,
4628 struct tegra_dc_dsi_data *dsi,
4634 switch (suspend_aggr) {
4635 case DSI_HOST_SUSPEND_LV2:
4637 err = tegra_dsi_enter_ulpm(dsi);
4639 dev_err(&dc->ndev->dev,
4640 "DSI failed to enter ulpm\n");
4645 tegra_dsi_pad_disable(dsi);
4647 /* Suspend core-logic */
4648 val = DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE);
4649 tegra_dsi_writel(dsi, val, DSI_POWER_CONTROL);
4651 /* disable HS logic */
4652 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_3_VS1);
4653 val |= DSI_PAD_PDVCLAMP(0x1);
4654 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
4657 case DSI_HOST_SUSPEND_LV1:
4658 /* Disable dsi fast and slow clock */
4659 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_DISABLE);
4661 case DSI_HOST_SUSPEND_LV0:
4662 /* Disable dsi source clock */
4663 tegra_dsi_clk_disable(dsi);
4665 case DSI_NO_SUSPEND:
4668 dev_err(&dc->ndev->dev, "DSI suspend aggressiveness"
4669 "is not supported.\n");
4672 tegra_dvfs_set_rate(dc->clk, 0);
4679 static int _tegra_dsi_host_resume(struct tegra_dc *dc,
4680 struct tegra_dc_dsi_data *dsi,
4686 switch (dsi->info.suspend_aggr) {
4687 case DSI_HOST_SUSPEND_LV0:
4688 tegra_dsi_clk_enable(dsi);
4690 case DSI_HOST_SUSPEND_LV1:
4691 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_ENABLE);
4692 tegra_dsi_clk_enable(dsi);
4694 case DSI_HOST_SUSPEND_LV2:
4695 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_ENABLE);
4696 tegra_dsi_clk_enable(dsi);
4698 /* enable HS logic */
4699 val = tegra_dsi_readl(dsi, DSI_PAD_CONTROL_3_VS1);
4700 val &= ~DSI_PAD_PDVCLAMP(0x1);
4701 tegra_dsi_writel(dsi, val, DSI_PAD_CONTROL_3_VS1);
4703 tegra_dsi_writel(dsi,
4704 DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_ENABLE),
4708 err = tegra_dsi_enter_ulpm(dsi);
4710 dev_err(&dc->ndev->dev,
4711 "DSI failed to enter ulpm\n");
4715 tegra_dsi_pad_enable(dsi);
4717 if (tegra_dsi_exit_ulpm(dsi) < 0) {
4718 dev_err(&dc->ndev->dev,
4719 "DSI failed to exit ulpm\n");
4723 tegra_dsi_pad_enable(dsi);
4726 case DSI_NO_SUSPEND:
4729 dev_err(&dc->ndev->dev, "DSI suspend aggressivenes"
4730 "is not supported.\n");
4733 tegra_dvfs_set_rate(dc->clk, dc->mode.pclk);
4740 static int tegra_dsi_host_suspend_trylock(struct tegra_dc *dc,
4741 struct tegra_dc_dsi_data *dsi)
4743 if (!mutex_trylock(&dc->one_shot_lock))
4745 if (!mutex_trylock(&dc->lp_lock))
4746 goto unlock_one_shot_lock;
4747 if (!mutex_trylock(&dc->lock))
4748 goto unlock_lp_lock;
4749 if (!mutex_trylock(&dsi->host_lock))
4750 goto unlock_dc_lock;
4755 mutex_unlock(&dc->lock);
4757 mutex_unlock(&dc->lp_lock);
4758 unlock_one_shot_lock:
4759 mutex_unlock(&dc->one_shot_lock);
4764 static void tegra_dsi_host_suspend_unlock(struct tegra_dc *dc,
4765 struct tegra_dc_dsi_data *dsi)
4767 mutex_unlock(&dsi->host_lock);
4768 mutex_unlock(&dc->lock);
4769 mutex_unlock(&dc->lp_lock);
4770 mutex_unlock(&dc->one_shot_lock);
4773 static int tegra_dsi_host_suspend(struct tegra_dc *dc)
4776 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4781 while (!tegra_dsi_host_suspend_trylock(dc, dsi))
4784 if (dsi->host_suspended || atomic_read(&dsi->host_ref)) {
4785 tegra_dsi_host_suspend_unlock(dc, dsi);
4789 tegra_dc_io_start(dc);
4791 dsi->host_suspended = true;
4793 tegra_dsi_stop_dc_stream(dc, dsi);
4795 tegra_dsi_te_on_off(dsi, false);
4797 err = _tegra_dsi_host_suspend(dc, dsi, dsi->info.suspend_aggr);
4799 dev_err(&dc->ndev->dev,
4800 "DSI host suspend failed\n");
4804 /* Shutting down. Drop any reference to dc clk */
4805 while (tegra_is_clk_enabled(dc->clk))
4808 pm_runtime_put_sync(&dc->ndev->dev);
4810 tegra_dc_io_end(dc);
4811 tegra_dsi_host_suspend_unlock(dc, dsi);
4815 static bool tegra_dc_dsi_osidle(struct tegra_dc *dc)
4817 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4819 if (dc->out->flags & TEGRA_DC_OUT_ONE_SHOT_MODE)
4820 return dsi->host_suspended;
4825 static void tegra_dsi_bl_off(struct backlight_device *bd)
4830 bd->props.brightness = 0;
4831 backlight_update_status(bd);
4834 static int tegra_dsi_deep_sleep(struct tegra_dc *dc,
4835 struct tegra_dc_dsi_data *dsi)
4843 cancel_delayed_work(&dsi->idle_work);
4845 tegra_dsi_bl_off(get_backlight_device_by_name(dsi->info.bl_name));
4847 /* Suspend DSI panel */
4848 err = tegra_dsi_send_panel_cmd(dc, dsi,
4849 dsi->info.dsi_suspend_cmd,
4850 dsi->info.n_suspend_cmd);
4852 err = tegra_dsi_set_to_lp_mode(dc, dsi, DSI_LP_OP_WRITE);
4854 dev_err(&dc->ndev->dev,
4855 "DSI failed to go to LP mode\n");
4860 * Certain panels need dc frames be sent after
4861 * putting panel to sleep.
4863 if (dsi->info.panel_send_dc_frames)
4864 tegra_dsi_send_dc_frames(dc, dsi, 2);
4867 err = tegra_dsi_enter_ulpm(dsi);
4869 dev_err(&dc->ndev->dev,
4870 "DSI failed to enter ulpm\n");
4875 tegra_dsi_pad_disable(dsi);
4877 /* Suspend core-logic */
4878 val = DSI_POWER_CONTROL_LEG_DSI_ENABLE(TEGRA_DSI_DISABLE);
4879 tegra_dsi_writel(dsi, val, DSI_POWER_CONTROL);
4881 /* Disable dsi fast and slow clock */
4882 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_DISABLE);
4884 /* Disable dsi source clock */
4885 tegra_dsi_clk_disable(dsi);
4887 dsi->enabled = false;
4888 dsi->host_suspended = true;
4895 static void tegra_dc_dsi_postpoweroff(struct tegra_dc *dc)
4897 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4899 if (!dsi->enabled && dsi->avdd_dsi_csi)
4900 regulator_disable(dsi->avdd_dsi_csi);
4903 static int tegra_dsi_host_resume(struct tegra_dc *dc)
4906 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4911 cancel_delayed_work(&dsi->idle_work);
4913 mutex_lock(&dsi->host_lock);
4914 if (!dsi->host_suspended) {
4915 mutex_unlock(&dsi->host_lock);
4919 tegra_dc_io_start(dc);
4921 pm_runtime_get_sync(&dc->ndev->dev);
4923 err = _tegra_dsi_host_resume(dc, dsi, dsi->info.suspend_aggr);
4925 dev_err(&dc->ndev->dev,
4926 "DSI host resume failed\n");
4930 tegra_dsi_te_on_off(dsi, true);
4932 tegra_dsi_start_dc_stream(dc, dsi);
4933 dsi->host_suspended = false;
4935 tegra_dc_io_end(dc);
4936 mutex_unlock(&dsi->host_lock);
4940 static void tegra_dc_dsi_disable(struct tegra_dc *dc)
4943 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
4945 if (dsi->host_suspended)
4946 tegra_dsi_host_resume(dc);
4948 mutex_lock(&dsi->lock);
4949 tegra_dc_io_start(dc);
4951 if (dsi->status.dc_stream == DSI_DC_STREAM_ENABLE)
4952 tegra_dsi_stop_dc_stream_at_frame_end(dc, dsi, 2);
4954 if (dsi->out_ops && dsi->out_ops->disable)
4955 dsi->out_ops->disable(dsi);
4957 if (dsi->info.power_saving_suspend) {
4958 if (tegra_dsi_deep_sleep(dc, dsi) < 0) {
4959 dev_err(&dc->ndev->dev,
4960 "DSI failed to enter deep sleep\n");
4964 if (dsi->info.dsi_early_suspend_cmd) {
4965 err = tegra_dsi_send_panel_cmd(dc, dsi,
4966 dsi->info.dsi_early_suspend_cmd,
4967 dsi->info.n_early_suspend_cmd);
4969 dev_err(&dc->ndev->dev,
4970 "dsi: Error sending early suspend cmd\n");
4976 if (tegra_dsi_enter_ulpm(dsi) < 0) {
4977 dev_err(&dc->ndev->dev,
4978 "DSI failed to enter ulpm\n");
4984 mutex_unlock(&dsi->lock);
4985 tegra_dc_io_end(dc);
4989 static void tegra_dc_dsi_suspend(struct tegra_dc *dc)
4991 struct tegra_dc_dsi_data *dsi;
4993 dsi = tegra_dc_get_outdata(dc);
4998 if (dsi->host_suspended)
4999 tegra_dsi_host_resume(dc);
5001 tegra_dc_io_start(dc);
5002 mutex_lock(&dsi->lock);
5004 if (dsi->out_ops && dsi->out_ops->suspend)
5005 dsi->out_ops->suspend(dsi);
5007 if (!dsi->info.power_saving_suspend) {
5009 if (tegra_dsi_exit_ulpm(dsi) < 0) {
5010 dev_err(&dc->ndev->dev,
5011 "DSI failed to exit ulpm");
5016 if (tegra_dsi_deep_sleep(dc, dsi) < 0) {
5017 dev_err(&dc->ndev->dev,
5018 "DSI failed to enter deep sleep\n");
5023 mutex_unlock(&dsi->lock);
5024 tegra_dc_io_end(dc);
5027 static void tegra_dc_dsi_resume(struct tegra_dc *dc)
5029 struct tegra_dc_dsi_data *dsi;
5031 dsi = tegra_dc_get_outdata(dc);
5033 /* No dsi config required since tegra_dc_dsi_enable
5034 * will reconfigure the controller from scratch
5037 if (dsi->out_ops && dsi->out_ops->resume)
5038 dsi->out_ops->resume(dsi);
5042 static int tegra_dc_dsi_init(struct tegra_dc *dc)
5044 struct tegra_dc_dsi_data *dsi;
5047 err = _tegra_dc_dsi_init(dc);
5049 dev_err(&dc->ndev->dev,
5050 "dsi: Instance A init failed\n");
5054 dsi = tegra_dc_get_outdata(dc);
5056 dsi->avdd_dsi_csi = regulator_get(&dc->ndev->dev, "avdd_dsi_csi");
5057 if (IS_ERR_OR_NULL(dsi->avdd_dsi_csi)) {
5058 dev_err(&dc->ndev->dev, "dsi: avdd_dsi_csi reg get failed\n");
5063 dsi->mipi_cal = tegra_mipi_cal_init_sw(dc);
5064 if (IS_ERR(dsi->mipi_cal)) {
5065 dev_err(&dc->ndev->dev, "dsi: mipi_cal sw init failed\n");
5066 err = PTR_ERR(dsi->mipi_cal);
5071 if (dsi->avdd_dsi_csi)
5072 regulator_put(dsi->avdd_dsi_csi);
5074 _tegra_dc_dsi_destroy(dc);
5075 tegra_dc_set_outdata(dc, NULL);
5080 static void tegra_dc_dsi_destroy(struct tegra_dc *dc)
5082 struct regulator *avdd_dsi_csi;
5083 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
5085 avdd_dsi_csi = dsi->avdd_dsi_csi;
5087 _tegra_dc_dsi_destroy(dc);
5088 regulator_put(avdd_dsi_csi);
5089 tegra_mipi_cal_destroy(dc);
5092 static long tegra_dc_dsi_setup_clk(struct tegra_dc *dc, struct clk *clk)
5095 struct clk *parent_clk;
5096 struct clk *base_clk;
5097 struct tegra_dc_dsi_data *dsi = tegra_dc_get_outdata(dc);
5100 /* divide by 1000 to avoid overflow */
5101 dc->mode.pclk /= 1000;
5102 rate = (dc->mode.pclk * dc->shift_clk_div.mul * 2)
5103 / dc->shift_clk_div.div;
5105 dc->mode.pclk *= 1000;
5107 if (dc->out->flags & TEGRA_DC_OUT_INITIALIZED_MODE)
5110 if (clk == dc->clk) {
5111 parent_clk = clk_get_sys(NULL,
5112 dc->out->parent_clk ? : "pll_d_out0");
5113 base_clk = clk_get_parent(parent_clk);
5115 if (dc->pdata->default_out->dsi->dsi_instance) {
5116 parent_clk = clk_get_sys(NULL,
5117 dc->out->parent_clk ? : "pll_d2_out0");
5118 base_clk = clk_get_parent(parent_clk);
5120 parent_clk = clk_get_sys(NULL,
5121 dc->out->parent_clk ? : "pll_d_out0");
5122 base_clk = clk_get_parent(parent_clk);
5125 tegra_dsi_config_phy_clk(dsi, TEGRA_DSI_ENABLE);
5127 if (rate != clk_get_rate(base_clk))
5128 clk_set_rate(base_clk, rate);
5130 if (clk_get_parent(clk) != parent_clk)
5131 clk_set_parent(clk, parent_clk);
5134 tegra_dvfs_set_rate(dc->clk, dc->mode.pclk);
5136 return tegra_dc_pclk_round_rate(dc, dc->mode.pclk);
5139 struct tegra_dc_out_ops tegra_dc_dsi_ops = {
5140 .init = tegra_dc_dsi_init,
5141 .destroy = tegra_dc_dsi_destroy,
5142 .enable = tegra_dc_dsi_enable,
5143 .postpoweron = tegra_dc_dsi_postpoweron,
5144 .disable = tegra_dc_dsi_disable,
5145 .postpoweroff = tegra_dc_dsi_postpoweroff,
5146 .hold = tegra_dc_dsi_hold_host,
5147 .release = tegra_dc_dsi_release_host,
5149 .suspend = tegra_dc_dsi_suspend,
5150 .resume = tegra_dc_dsi_resume,
5152 .setup_clk = tegra_dc_dsi_setup_clk,
5153 .osidle = tegra_dc_dsi_osidle,