2 * This file is part of the coreboot project.
4 * Copyright 2014 Google Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
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.
15 #include <console/console.h>
22 #include <soc/addressmap.h>
23 #include <soc/clock.h>
24 #include <device/device.h>
26 #include <soc/nvidia/tegra/types.h>
27 #include <soc/nvidia/tegra/dc.h>
29 #include <soc/display.h>
30 #include <soc/mipi_dsi.h>
31 #include <soc/mipi_display.h>
32 #include <soc/tegra_dsi.h>
33 #include <soc/mipi-phy.h>
34 #include "jdi_25x18_display/panel-jdi-lpm102a188a.h"
36 struct tegra_mipi_device mipi_device_data
[NUM_DSI
];
38 struct tegra_dsi dsi_data
[NUM_DSI
] = {
40 .regs
= (void *)TEGRA_DSIA_BASE
,
42 .slave
= &dsi_data
[DSI_B
],
44 .video_fifo_depth
= MAX_DSI_VIDEO_FIFO_DEPTH
,
45 .host_fifo_depth
= MAX_DSI_HOST_FIFO_DEPTH
,
48 .regs
= (void *)TEGRA_DSIB_BASE
,
51 .master
= &dsi_data
[DSI_A
],
52 .video_fifo_depth
= MAX_DSI_VIDEO_FIFO_DEPTH
,
53 .host_fifo_depth
= MAX_DSI_HOST_FIFO_DEPTH
,
57 static const u32 init_reg
[] = {
98 static inline struct tegra_dsi
*host_to_tegra(struct mipi_dsi_host
*host
)
100 return container_of(host
, struct tegra_dsi
, host
);
104 * non-burst mode with sync pulses
106 static const u32 pkt_seq_video_non_burst_sync_pulses
[NUM_PKT_SEQ
] = {
107 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START
) | PKT_LEN0(0) |
108 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
109 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0) |
112 [ 2] = PKT_ID0(MIPI_DSI_V_SYNC_END
) | PKT_LEN0(0) |
113 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
114 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0) |
117 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
118 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
119 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0) |
122 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
123 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
124 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0),
125 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN0(2) |
126 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24
) | PKT_LEN1(3) |
127 PKT_ID2(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN2(4),
128 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
129 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
130 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0) |
133 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
134 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
135 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0),
136 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN0(2) |
137 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24
) | PKT_LEN1(3) |
138 PKT_ID2(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN2(4),
142 * non-burst mode with sync events
144 static const u32 pkt_seq_video_non_burst_sync_events
[NUM_PKT_SEQ
] = {
145 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START
) | PKT_LEN0(0) |
146 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION
) | PKT_LEN1(7) |
149 [ 2] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
150 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION
) | PKT_LEN1(7) |
153 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
154 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION
) | PKT_LEN1(7) |
158 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
159 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(2) |
160 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24
) | PKT_LEN2(3),
162 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN0(4),
163 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
164 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION
) | PKT_LEN1(7) |
168 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
169 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(2) |
170 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24
) | PKT_LEN2(3),
172 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN0(4),
175 static const u32 pkt_seq_command_mode
[NUM_PKT_SEQ
] = {
182 [ 6] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE
) | PKT_LEN0(3) | PKT_LP
,
186 [10] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE
) | PKT_LEN0(5) | PKT_LP
,
190 static int tegra_dsi_set_phy_timing(struct tegra_dsi
*dsi
)
194 err
= mipi_dphy_set_timing(dsi
);
196 printk(BIOS_ERR
, "failed to set D-PHY timing: %d\n", err
);
201 tegra_dsi_set_phy_timing(dsi
->slave
);
205 static int tegra_dsi_get_muldiv(enum mipi_dsi_pixel_format format
,
206 unsigned int *mulp
, unsigned int *divp
)
209 case MIPI_DSI_FMT_RGB666_PACKED
:
210 case MIPI_DSI_FMT_RGB888
:
215 case MIPI_DSI_FMT_RGB565
:
220 case MIPI_DSI_FMT_RGB666
:
231 static int tegra_dsi_get_format(enum mipi_dsi_pixel_format format
,
232 enum tegra_dsi_format
*fmt
)
235 case MIPI_DSI_FMT_RGB888
:
236 *fmt
= TEGRA_DSI_FORMAT_24P
;
239 case MIPI_DSI_FMT_RGB666
:
240 *fmt
= TEGRA_DSI_FORMAT_18NP
;
243 case MIPI_DSI_FMT_RGB666_PACKED
:
244 *fmt
= TEGRA_DSI_FORMAT_18P
;
247 case MIPI_DSI_FMT_RGB565
:
248 *fmt
= TEGRA_DSI_FORMAT_16P
;
257 static void tegra_dsi_ganged_enable(struct tegra_dsi
*dsi
, unsigned int start
,
262 tegra_dsi_writel(dsi
, start
, DSI_GANGED_MODE_START
);
263 tegra_dsi_writel(dsi
, size
<< 16 | size
, DSI_GANGED_MODE_SIZE
);
265 value
= DSI_GANGED_MODE_CONTROL_ENABLE
;
266 tegra_dsi_writel(dsi
, value
, DSI_GANGED_MODE_CONTROL
);
269 static void tegra_dsi_enable(struct tegra_dsi
*dsi
)
273 value
= tegra_dsi_readl(dsi
, DSI_POWER_CONTROL
);
274 value
|= DSI_POWER_CONTROL_ENABLE
;
275 tegra_dsi_writel(dsi
, value
, DSI_POWER_CONTROL
);
278 tegra_dsi_enable(dsi
->slave
);
281 static int tegra_dsi_configure(struct tegra_dsi
*dsi
, unsigned int pipe
,
282 const struct soc_nvidia_tegra210_config
*mode
)
284 unsigned int hact
, hsw
, hbp
, hfp
, i
, mul
, div
;
285 enum tegra_dsi_format format
;
290 if (dsi
->flags
& MIPI_DSI_MODE_VIDEO_SYNC_PULSE
) {
291 printk(BIOS_SPEW
, "Non-burst video mode with sync pulses\n");
292 pkt_seq
= pkt_seq_video_non_burst_sync_pulses
;
293 } else if (dsi
->flags
& MIPI_DSI_MODE_VIDEO
) {
294 printk(BIOS_SPEW
, "Non-burst video mode with sync events\n");
295 pkt_seq
= pkt_seq_video_non_burst_sync_events
;
297 printk(BIOS_SPEW
, "Command mode\n");
298 pkt_seq
= pkt_seq_command_mode
;
301 err
= tegra_dsi_get_muldiv(dsi
->format
, &mul
, &div
);
305 err
= tegra_dsi_get_format(dsi
->format
, &format
);
309 value
= DSI_CONTROL_CHANNEL(0) | DSI_CONTROL_FORMAT(format
) |
310 DSI_CONTROL_LANES(dsi
->lanes
- 1) |
311 DSI_CONTROL_SOURCE(pipe
);
312 tegra_dsi_writel(dsi
, value
, DSI_CONTROL
);
314 tegra_dsi_writel(dsi
, dsi
->video_fifo_depth
, DSI_MAX_THRESHOLD
);
316 value
= DSI_HOST_CONTROL_HS
;
317 tegra_dsi_writel(dsi
, value
, DSI_HOST_CONTROL
);
319 value
= tegra_dsi_readl(dsi
, DSI_CONTROL
);
321 if (dsi
->flags
& MIPI_DSI_CLOCK_NON_CONTINUOUS
)
322 value
|= DSI_CONTROL_HS_CLK_CTRL
;
324 value
&= ~DSI_CONTROL_TX_TRIG(3);
326 /* enable DCS commands for command mode */
327 if (dsi
->flags
& MIPI_DSI_MODE_VIDEO
)
328 value
&= ~DSI_CONTROL_DCS_ENABLE
;
330 value
|= DSI_CONTROL_DCS_ENABLE
;
332 value
|= DSI_CONTROL_VIDEO_ENABLE
;
333 value
&= ~DSI_CONTROL_HOST_ENABLE
;
334 tegra_dsi_writel(dsi
, value
, DSI_CONTROL
);
336 for (i
= 0; i
< NUM_PKT_SEQ
; i
++)
337 tegra_dsi_writel(dsi
, pkt_seq
[i
], DSI_PKT_SEQ_0_LO
+ i
);
339 if (dsi
->flags
& MIPI_DSI_MODE_VIDEO
) {
340 /* horizontal active pixels */
341 hact
= mode
->xres
* mul
/ div
;
343 /* horizontal sync width */
344 hsw
= (hsync_end(mode
) - hsync_start(mode
)) * mul
/ div
;
346 /* horizontal back porch */
347 hbp
= (htotal(mode
) - hsync_end(mode
)) * mul
/ div
;
348 if ((dsi
->flags
& MIPI_DSI_MODE_VIDEO_SYNC_PULSE
) == 0)
351 /* horizontal front porch */
352 hfp
= (hsync_start(mode
) - mode
->xres
) * mul
/ div
;
354 /* subtract packet overhead */
359 tegra_dsi_writel(dsi
, hsw
<< 16 | 0, DSI_PKT_LEN_0_1
);
360 tegra_dsi_writel(dsi
, hact
<< 16 | hbp
, DSI_PKT_LEN_2_3
);
361 tegra_dsi_writel(dsi
, hfp
, DSI_PKT_LEN_4_5
);
362 tegra_dsi_writel(dsi
, 0x0f0f << 16, DSI_PKT_LEN_6_7
);
364 /* set SOL delay (for non-burst mode only) */
365 tegra_dsi_writel(dsi
, 8 * mul
/ div
, DSI_SOL_DELAY
);
367 /* TODO: implement ganged mode */
370 if (dsi
->ganged_mode
) {
372 * For ganged mode, assume symmetric left-right mode.
374 bytes
= 1 + (mode
->xres
/ 2) * mul
/ div
;
376 /* 1 byte (DCS command) + pixel data */
377 bytes
= 1 + mode
->xres
* mul
/ div
;
380 tegra_dsi_writel(dsi
, 0, DSI_PKT_LEN_0_1
);
381 tegra_dsi_writel(dsi
, bytes
<< 16, DSI_PKT_LEN_2_3
);
382 tegra_dsi_writel(dsi
, bytes
<< 16, DSI_PKT_LEN_4_5
);
383 tegra_dsi_writel(dsi
, 0, DSI_PKT_LEN_6_7
);
385 value
= MIPI_DCS_WRITE_MEMORY_START
<< 8 |
386 MIPI_DCS_WRITE_MEMORY_CONTINUE
;
387 tegra_dsi_writel(dsi
, value
, DSI_DCS_CMDS
);
390 if (dsi
->ganged_mode
) {
391 unsigned long delay
, bclk
, bclk_ganged
;
392 unsigned int lanes
= dsi
->ganged_lanes
;
394 /* SOL to valid, valid to FIFO and FIFO write delay */
396 delay
= DIV_ROUND_UP(delay
* mul
, div
* lanes
);
397 /* FIFO read delay */
400 bclk
= DIV_ROUND_UP(htotal(mode
) * mul
, div
* lanes
);
401 bclk_ganged
= DIV_ROUND_UP(bclk
* lanes
/ 2, lanes
);
402 value
= bclk
- bclk_ganged
+ delay
+ 20;
404 /* TODO: revisit for non-ganged mode */
405 value
= 8 * mul
/ div
;
408 tegra_dsi_writel(dsi
, value
, DSI_SOL_DELAY
);
412 err
= tegra_dsi_configure(dsi
->slave
, pipe
, mode
);
419 if (dsi
->ganged_mode
) {
420 tegra_dsi_ganged_enable(dsi
, mode
->xres
/ 2,
422 tegra_dsi_ganged_enable(dsi
->slave
, 0, mode
->xres
/ 2);
428 static int tegra_output_dsi_enable(struct tegra_dsi
*dsi
,
429 const struct soc_nvidia_tegra210_config
*config
)
436 err
= tegra_dsi_configure(dsi
, 0, config
);
438 printk(BIOS_ERR
, "DSI configuration failed\n");
442 /* enable DSI controller */
443 tegra_dsi_enable(dsi
);
450 static void tegra_dsi_set_timeout(struct tegra_dsi
*dsi
, unsigned long bclk
,
451 unsigned int vrefresh
)
453 unsigned int timeout
;
456 /* one frame high-speed transmission timeout */
457 timeout
= (bclk
/ vrefresh
) / 512;
458 value
= DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(timeout
);
459 tegra_dsi_writel(dsi
, value
, DSI_TIMEOUT_0
);
461 /* 2 ms peripheral timeout for panel */
462 timeout
= 2 * bclk
/ 512 * 1000;
463 value
= DSI_TIMEOUT_PR(timeout
) | DSI_TIMEOUT_TA(0x2000);
464 tegra_dsi_writel(dsi
, value
, DSI_TIMEOUT_1
);
466 value
= DSI_TALLY_TA(0) | DSI_TALLY_LRX(0) | DSI_TALLY_HTX(0);
467 tegra_dsi_writel(dsi
, value
, DSI_TO_TALLY
);
470 tegra_dsi_set_timeout(dsi
->slave
, bclk
, vrefresh
);
473 static int tegra_output_dsi_setup_clock(struct tegra_dsi
*dsi
,
474 const struct soc_nvidia_tegra210_config
*config
)
476 unsigned int mul
, div
, num_lanes
;
478 unsigned long pclk
= config
->pixel_clock
;
481 struct display_controller
*disp_ctrl
=
482 (void *)config
->display_controller
;
483 unsigned int shift_clk_div
;
485 err
= tegra_dsi_get_muldiv(dsi
->format
, &mul
, &div
);
490 * In ganged mode, account for the total number of lanes across both
491 * DSI channels so that the bit clock is properly computed.
493 if (dsi
->ganged_mode
)
494 num_lanes
= dsi
->ganged_lanes
;
496 num_lanes
= dsi
->lanes
;
498 /* compute byte clock */
499 bclk
= (pclk
* mul
) / (div
* num_lanes
);
502 * Compute bit clock and round up to the next MHz.
504 plld
= DIV_ROUND_UP(bclk
* 8, USECS_PER_SEC
) * USECS_PER_SEC
;
507 * the actual rate on PLLD_OUT0 is 1/2 plld
509 dsi
->clk_rate
= plld
/ 2;
511 dsi
->slave
->clk_rate
= dsi
->clk_rate
;
514 plld
= clock_configure_plld(plld
);
516 printk(BIOS_ERR
, "%s: clock init failed\n", __func__
);
519 printk(BIOS_INFO
, "%s: plld is configured to: %u\n",
523 * Derive pixel clock from bit clock using the shift clock divider.
524 * Note that this is only half of what we would expect, but we need
525 * that to make up for the fact that we divided the bit clock by a
526 * factor of two above.
528 shift_clk_div
= ((8 * mul
) / (div
* num_lanes
)) - 2;
529 update_display_shift_clock_divider(disp_ctrl
, shift_clk_div
);
531 tegra_dsi_set_timeout(dsi
, bclk
, config
->refresh
);
537 static int tegra_dsi_pad_enable(struct tegra_dsi
*dsi
)
541 value
= DSI_PAD_CONTROL_VS1_PULLDN(0) | DSI_PAD_CONTROL_VS1_PDIO(0);
542 tegra_dsi_writel(dsi
, value
, DSI_PAD_CONTROL_0
);
546 static int tegra_dsi_pad_calibrate(struct tegra_dsi
*dsi
)
550 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_0
);
551 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_1
);
552 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_2
);
553 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_3
);
554 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_4
);
556 /* start calibration */
557 tegra_dsi_pad_enable(dsi
);
559 value
= DSI_PAD_SLEW_UP(0x7) | DSI_PAD_SLEW_DN(0x7) |
560 DSI_PAD_LP_UP(0x1) | DSI_PAD_LP_DN(0x1) |
561 DSI_PAD_OUT_CLK(0x0);
562 tegra_dsi_writel(dsi
, value
, DSI_PAD_CONTROL_2
);
564 value
= DSI_PAD_PREEMP_PD_CLK(0x3) | DSI_PAD_PREEMP_PU_CLK(0x3) |
565 DSI_PAD_PREEMP_PD(0x03) | DSI_PAD_PREEMP_PU(0x3);
566 tegra_dsi_writel(dsi
, value
, DSI_PAD_CONTROL_3
);
568 return tegra_mipi_calibrate(dsi
->mipi
);
571 static const char * const error_report
[16] = {
575 "Escape Mode Entry Command Error",
576 "Low-Power Transmit Sync Error",
577 "Peripheral Timeout Error",
578 "False Control Error",
579 "Contention Detected",
580 "ECC Error, single-bit",
581 "ECC Error, multi-bit",
583 "DSI Data Type Not Recognized",
585 "Invalid Transmission Length",
587 "DSI Protocol Violation",
590 static int tegra_dsi_read_response(struct tegra_dsi
*dsi
,
591 const struct mipi_dsi_msg
*msg
,
594 u8
*rx
= msg
->rx_buf
;
595 unsigned int i
, j
, k
;
600 /* read and parse packet header */
601 value
= tegra_dsi_readl(dsi
, DSI_RD_DATA
);
603 switch (value
& 0x3f) {
604 case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT
:
605 errors
= (value
>> 8) & 0xffff;
606 printk(BIOS_ERR
, "Acknowledge and error report: %04x\n",
608 for (i
= 0; i
< ARRAY_SIZE(error_report
); i
++)
610 printk(BIOS_INFO
, " %2u: %s\n", i
,
614 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE
:
615 rx
[0] = (value
>> 8) & 0xff;
618 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE
:
619 rx
[0] = (value
>> 8) & 0xff;
620 rx
[1] = (value
>> 16) & 0xff;
623 case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE
:
624 size
= ((value
>> 8) & 0xff00) | ((value
>> 8) & 0xff);
627 case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE
:
628 size
= ((value
>> 8) & 0xff00) | ((value
>> 8) & 0xff);
632 printk(BIOS_ERR
, "unhandled response type: %02x\n",
637 size
= MIN(size
, msg
->rx_len
);
639 if (msg
->rx_buf
&& size
> 0) {
640 for (i
= 0, j
= 0; i
< count
- 1; i
++, j
+= 4) {
641 value
= tegra_dsi_readl(dsi
, DSI_RD_DATA
);
643 for (k
= 0; k
< 4 && (j
+ k
) < msg
->rx_len
; k
++)
644 rx
[j
+ k
] = (value
>> (k
<< 3)) & 0xff;
650 static int tegra_dsi_transmit(struct tegra_dsi
*dsi
, unsigned long timeout_ms
)
652 u32 poll_interval_us
= 2000;
653 u32 timeout_us
= timeout_ms
* 1000;
655 tegra_dsi_writel(dsi
, DSI_TRIGGER_HOST
, DSI_TRIGGER
);
656 udelay(poll_interval_us
);
659 u32 value
= tegra_dsi_readl(dsi
, DSI_TRIGGER
);
660 if ((value
& DSI_TRIGGER_HOST
) == 0)
663 //usleep_range(1000, 2000);
664 if (timeout_us
> poll_interval_us
)
665 timeout_us
-= poll_interval_us
;
669 udelay(poll_interval_us
);
672 printk(BIOS_ERR
, "%s: ERROR: timeout waiting for transmission"
673 " to complete\n", __func__
);
677 static int tegra_dsi_wait_for_response(struct tegra_dsi
*dsi
,
678 unsigned long timeout_ms
)
680 u32 poll_interval_us
= 2000;
681 u32 timeout_us
= timeout_ms
* 1000;
684 u32 value
= tegra_dsi_readl(dsi
, DSI_STATUS
);
685 u8 count
= value
& 0x1f;
690 if (timeout_us
> poll_interval_us
)
691 timeout_us
-= poll_interval_us
;
695 udelay(poll_interval_us
);
698 printk(BIOS_ERR
, "%s: ERROR: timeout\n", __func__
);
703 static ssize_t
tegra_dsi_host_transfer(struct mipi_dsi_host
*host
,
704 const struct mipi_dsi_msg
*msg
)
706 struct tegra_dsi
*dsi
= host_to_tegra(host
);
707 const u8
*tx
= msg
->tx_buf
;
708 unsigned int count
, i
, j
;
712 if (msg
->tx_len
> dsi
->video_fifo_depth
* 4)
715 /* reset underflow/overflow flags */
716 value
= tegra_dsi_readl(dsi
, DSI_STATUS
);
717 if (value
& (DSI_STATUS_UNDERFLOW
| DSI_STATUS_OVERFLOW
)) {
718 value
= DSI_HOST_CONTROL_FIFO_RESET
;
719 tegra_dsi_writel(dsi
, value
, DSI_HOST_CONTROL
);
720 udelay(20); // usleep_range(10, 20);
723 value
= tegra_dsi_readl(dsi
, DSI_POWER_CONTROL
);
724 value
|= DSI_POWER_CONTROL_ENABLE
;
725 tegra_dsi_writel(dsi
, value
, DSI_POWER_CONTROL
);
727 udelay(7000); //usleep_range(5000, 10000);
729 value
= DSI_HOST_CONTROL_CRC_RESET
| DSI_HOST_CONTROL_TX_TRIG_HOST
|
730 DSI_HOST_CONTROL_CS
| DSI_HOST_CONTROL_ECC
;
732 if ((msg
->flags
& MIPI_DSI_MSG_USE_LPM
) == 0)
733 value
|= DSI_HOST_CONTROL_HS
;
736 * The host FIFO has a maximum of 64 words, so larger transmissions
737 * need to use the video FIFO.
739 if (msg
->tx_len
> dsi
->host_fifo_depth
* 4)
740 value
|= DSI_HOST_CONTROL_FIFO_SEL
;
742 tegra_dsi_writel(dsi
, value
, DSI_HOST_CONTROL
);
745 * For reads and messages with explicitly requested ACK, generate a
746 * BTA sequence after the transmission of the packet.
748 if ((msg
->flags
& MIPI_DSI_MSG_REQ_ACK
) ||
749 (msg
->rx_buf
&& msg
->rx_len
> 0)) {
750 value
= tegra_dsi_readl(dsi
, DSI_HOST_CONTROL
);
751 value
|= DSI_HOST_CONTROL_PKT_BTA
;
752 tegra_dsi_writel(dsi
, value
, DSI_HOST_CONTROL
);
755 value
= DSI_CONTROL_LANES(0) | DSI_CONTROL_HOST_ENABLE
;
756 tegra_dsi_writel(dsi
, value
, DSI_CONTROL
);
758 /* write packet header */
759 value
= ((msg
->channel
& 0x3) << 6) | (msg
->type
& 0x3f);
761 if (tx
&& msg
->tx_len
> 0)
764 if (tx
&& msg
->tx_len
> 1)
765 value
|= tx
[1] << 16;
767 tegra_dsi_writel(dsi
, value
, DSI_WR_DATA
);
769 /* write payload (if any) */
770 if (msg
->tx_len
> 2) {
771 for (j
= 2; j
< msg
->tx_len
; j
+= 4) {
774 for (i
= 0; i
< 4 && j
+ i
< msg
->tx_len
; i
++)
775 value
|= tx
[j
+ i
] << (i
<< 3);
777 tegra_dsi_writel(dsi
, value
, DSI_WR_DATA
);
781 err
= tegra_dsi_transmit(dsi
, 250);
783 printk(BIOS_INFO
, "Failed to transmit. %d\n", err
);
787 if ((msg
->flags
& MIPI_DSI_MSG_REQ_ACK
) ||
788 (msg
->rx_buf
&& msg
->rx_len
> 0)) {
789 err
= tegra_dsi_wait_for_response(dsi
, 250);
791 printk(BIOS_INFO
, "Failed to read response. %d\n", err
);
796 value
= tegra_dsi_readl(dsi
, DSI_RD_DATA
);
799 printk(BIOS_INFO
, "ACK\n");
803 printk(BIOS_INFO
, "ESCAPE\n");
807 printk(BIOS_INFO
, "unknown status: %08x\n", value
);
812 err
= tegra_dsi_read_response(dsi
, msg
, count
);
815 "failed to parse response: %d\n",
819 * For read commands, return the number of
820 * bytes returned by the peripheral.
827 * For write commands, we have transmitted the 4-byte header
828 * plus the variable-length payload.
830 count
= 4 + msg
->tx_len
;
836 static int tegra_dsi_ganged_setup(struct tegra_dsi
*dsi
,
837 struct tegra_dsi
*slave
)
840 * The number of ganged lanes is the sum of lanes of all peripherals
843 dsi
->slave
->ganged_lanes
= dsi
->lanes
+ dsi
->slave
->lanes
;
844 dsi
->slave
->ganged_mode
= 1;
846 dsi
->ganged_lanes
= dsi
->lanes
+ dsi
->slave
->lanes
;
847 dsi
->ganged_mode
= 1;
851 static int tegra_dsi_host_attach(struct mipi_dsi_host
*host
,
852 struct mipi_dsi_device
*device
)
854 struct tegra_dsi
*dsi
= host_to_tegra(host
);
857 dsi
->flags
= device
->mode_flags
;
858 dsi
->format
= device
->format
;
859 dsi
->lanes
= device
->lanes
;
862 err
= tegra_dsi_ganged_setup(dsi
->master
, dsi
);
864 printk(BIOS_ERR
, "failed to set up ganged mode: %d\n",
872 static const struct mipi_dsi_host_ops tegra_dsi_host_ops
= {
873 .attach
= tegra_dsi_host_attach
,
874 .transfer
= tegra_dsi_host_transfer
,
877 static int dsi_probe_if(int dsi_index
,
878 struct soc_nvidia_tegra210_config
*config
)
880 struct tegra_dsi
*dsi
= &dsi_data
[dsi_index
];
883 tegra_dsi_writel(dsi
, 0, DSI_INIT_SEQ_CONTROL
);
886 * Set default value. Will be taken from attached device once detected
889 dsi
->format
= MIPI_DSI_FMT_RGB888
;
892 /* get tegra_mipi_device */
893 dsi
->mipi
= tegra_mipi_request(&mipi_device_data
[dsi_index
], dsi_index
);
896 err
= tegra_dsi_pad_calibrate(dsi
);
898 printk(BIOS_ERR
, "MIPI calibration failed: %d\n", err
);
902 dsi
->host
.ops
= &tegra_dsi_host_ops
;
903 err
= mipi_dsi_host_register(&dsi
->host
);
905 printk(BIOS_ERR
, "failed to register DSI host: %d\n", err
);
910 dsi
->panel
= panel_jdi_dsi_probe((struct mipi_dsi_device
*)dsi
->host
.dev
);
911 if (IS_ERR_PTR(dsi
->panel
)) {
912 printk(BIOS_ERR
, "failed to get dsi panel\n");
915 dsi
->panel
->mode
= config
;
919 static int dsi_probe(struct soc_nvidia_tegra210_config
*config
)
921 dsi_probe_if(DSI_A
, config
);
922 dsi_probe_if(DSI_B
, config
);
926 static void tegra_dsi_init_regs(struct tegra_dsi
*dsi
)
929 for (i
= 0; i
< ARRAY_SIZE(init_reg
); i
++)
930 tegra_dsi_writel(dsi
, 0, init_reg
[i
]);
933 tegra_dsi_init_regs(dsi
->slave
);
936 static int dsi_enable(struct soc_nvidia_tegra210_config
*config
)
938 struct tegra_dsi
*dsi_a
= &dsi_data
[DSI_A
];
942 /* set up clock and TimeOutRegisters */
943 tegra_output_dsi_setup_clock(dsi_a
, config
);
945 /* configure APB_MISC_GP_MIPI_PAD_CTRL_0 */
946 write32((unsigned int *)APB_MISC_GP_MIPI_PAD_CTRL_0
, DSIB_MODE_DSI
);
948 /* configure phy interface timing registers */
949 tegra_dsi_set_phy_timing(dsi_a
);
951 /* Initialize DSI registers */
952 tegra_dsi_init_regs(dsi_a
);
955 panel_jdi_prepare(dsi_a
->panel
);
958 if (tegra_output_dsi_enable(dsi_a
, config
)) {
959 printk(BIOS_ERR
,"%s: Error: failed to enable dsi output.\n",
967 void dsi_display_startup(device_t dev
)
969 struct soc_nvidia_tegra210_config
*config
= dev
->chip_info
;
970 struct display_controller
*disp_ctrl
=
971 (void *)config
->display_controller
;
974 u32 framebuffer_size_mb
= config
->framebuffer_size
/ MiB
;
975 u32 framebuffer_base_mb
= config
->framebuffer_base
/ MiB
;
977 printk(BIOS_INFO
, "%s: entry: disp_ctrl: %p.\n",
978 __func__
, disp_ctrl
);
980 if (disp_ctrl
== NULL
) {
981 printk(BIOS_ERR
, "Error: No dc is assigned by dt.\n");
985 if (framebuffer_size_mb
== 0){
986 framebuffer_size_mb
= ALIGN_UP(config
->display_xres
*
987 config
->display_yres
*
988 (config
->framebuffer_bits_per_pixel
/ 8), MiB
)/MiB
;
991 config
->framebuffer_size
= framebuffer_size_mb
* MiB
;
992 config
->framebuffer_base
= framebuffer_base_mb
* MiB
;
995 * The plld is programmed with the assumption of the SHIFT_CLK_DIVIDER
996 * and PIXEL_CLK_DIVIDER are zero (divide by 1). See the
997 * update_display_mode() for detail.
999 /* set default plld */
1000 plld_rate
= clock_configure_plld(config
->pixel_clock
* 2);
1001 if (plld_rate
== 0) {
1002 printk(BIOS_ERR
, "dc: clock init failed\n");
1006 /* set disp1's clock source to PLLD_OUT0 */
1007 clock_configure_source(disp1
, PLLD_OUT0
, (plld_rate
/KHz
));
1010 if (tegra_dc_init(disp_ctrl
)) {
1011 printk(BIOS_ERR
, "dc: init failed\n");
1015 /* Configure dc mode */
1016 if (update_display_mode(disp_ctrl
, config
)) {
1017 printk(BIOS_ERR
, "dc: failed to configure display mode.\n");
1021 /* Configure and enable dsi controller and panel */
1022 if (dsi_enable(config
)) {
1023 printk(BIOS_ERR
, "%s: failed to enable dsi controllers.\n",
1029 update_window(config
);
1030 printk(BIOS_INFO
, "%s: display init done.\n", __func__
);
1032 /* Save panel information to cb tables */
1033 pass_mode_info_to_payload(config
);
1036 * After this point, it is payload's responsibility to allocate
1037 * framebuffer and sets the base address to dc's
1038 * WINBUF_START_ADDR register and enables window by setting dc's
1039 * DISP_DISP_WIN_OPTIONS register.