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 inline struct tegra_dsi
*host_to_tegra(struct mipi_dsi_host
*host
)
59 return container_of(host
, struct tegra_dsi
, host
);
63 * non-burst mode with sync pulses
65 static const u32 pkt_seq_video_non_burst_sync_pulses
[NUM_PKT_SEQ
] = {
66 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START
) | PKT_LEN0(0) |
67 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
68 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0) |
71 [ 2] = PKT_ID0(MIPI_DSI_V_SYNC_END
) | PKT_LEN0(0) |
72 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
73 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0) |
76 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
77 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
78 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0) |
81 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
82 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
83 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0),
84 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN0(2) |
85 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24
) | PKT_LEN1(3) |
86 PKT_ID2(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN2(4),
87 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
88 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
89 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0) |
92 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
93 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
94 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0),
95 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN0(2) |
96 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24
) | PKT_LEN1(3) |
97 PKT_ID2(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN2(4),
101 * non-burst mode with sync events
103 static const u32 pkt_seq_video_non_burst_sync_events
[NUM_PKT_SEQ
] = {
104 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START
) | PKT_LEN0(0) |
105 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION
) | PKT_LEN1(7) |
108 [ 2] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
109 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION
) | PKT_LEN1(7) |
112 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
113 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION
) | PKT_LEN1(7) |
117 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
118 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(2) |
119 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24
) | PKT_LEN2(3),
121 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN0(4),
122 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
123 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION
) | PKT_LEN1(7) |
127 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
128 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(2) |
129 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24
) | PKT_LEN2(3),
131 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN0(4),
134 static const u32 pkt_seq_command_mode
[NUM_PKT_SEQ
] = {
141 [ 6] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE
) | PKT_LEN0(3) | PKT_LP
,
145 [10] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE
) | PKT_LEN0(5) | PKT_LP
,
149 static int tegra_dsi_set_phy_timing(struct tegra_dsi
*dsi
)
153 err
= mipi_dphy_set_timing(dsi
);
155 printk(BIOS_ERR
, "failed to set D-PHY timing: %d\n", err
);
160 tegra_dsi_set_phy_timing(dsi
->slave
);
164 static int tegra_dsi_get_muldiv(enum mipi_dsi_pixel_format format
,
165 unsigned int *mulp
, unsigned int *divp
)
168 case MIPI_DSI_FMT_RGB666_PACKED
:
169 case MIPI_DSI_FMT_RGB888
:
174 case MIPI_DSI_FMT_RGB565
:
179 case MIPI_DSI_FMT_RGB666
:
190 static int tegra_dsi_get_format(enum mipi_dsi_pixel_format format
,
191 enum tegra_dsi_format
*fmt
)
194 case MIPI_DSI_FMT_RGB888
:
195 *fmt
= TEGRA_DSI_FORMAT_24P
;
198 case MIPI_DSI_FMT_RGB666
:
199 *fmt
= TEGRA_DSI_FORMAT_18NP
;
202 case MIPI_DSI_FMT_RGB666_PACKED
:
203 *fmt
= TEGRA_DSI_FORMAT_18P
;
206 case MIPI_DSI_FMT_RGB565
:
207 *fmt
= TEGRA_DSI_FORMAT_16P
;
216 static void tegra_dsi_ganged_enable(struct tegra_dsi
*dsi
, unsigned int start
,
221 tegra_dsi_writel(dsi
, start
, DSI_GANGED_MODE_START
);
222 tegra_dsi_writel(dsi
, size
<< 16 | size
, DSI_GANGED_MODE_SIZE
);
224 value
= DSI_GANGED_MODE_CONTROL_ENABLE
;
225 tegra_dsi_writel(dsi
, value
, DSI_GANGED_MODE_CONTROL
);
228 static void tegra_dsi_enable(struct tegra_dsi
*dsi
)
232 value
= tegra_dsi_readl(dsi
, DSI_POWER_CONTROL
);
233 value
|= DSI_POWER_CONTROL_ENABLE
;
234 tegra_dsi_writel(dsi
, value
, DSI_POWER_CONTROL
);
237 tegra_dsi_enable(dsi
->slave
);
240 static int tegra_dsi_configure(struct tegra_dsi
*dsi
, unsigned int pipe
,
241 const struct soc_nvidia_tegra132_config
*mode
)
243 unsigned int hact
, hsw
, hbp
, hfp
, i
, mul
, div
;
244 enum tegra_dsi_format format
;
249 if (dsi
->flags
& MIPI_DSI_MODE_VIDEO_SYNC_PULSE
) {
250 printk(BIOS_SPEW
, "Non-burst video mode with sync pulses\n");
251 pkt_seq
= pkt_seq_video_non_burst_sync_pulses
;
252 } else if (dsi
->flags
& MIPI_DSI_MODE_VIDEO
) {
253 printk(BIOS_SPEW
, "Non-burst video mode with sync events\n");
254 pkt_seq
= pkt_seq_video_non_burst_sync_events
;
256 printk(BIOS_SPEW
, "Command mode\n");
257 pkt_seq
= pkt_seq_command_mode
;
260 err
= tegra_dsi_get_muldiv(dsi
->format
, &mul
, &div
);
264 err
= tegra_dsi_get_format(dsi
->format
, &format
);
268 value
= DSI_CONTROL_CHANNEL(0) | DSI_CONTROL_FORMAT(format
) |
269 DSI_CONTROL_LANES(dsi
->lanes
- 1) |
270 DSI_CONTROL_SOURCE(pipe
);
271 tegra_dsi_writel(dsi
, value
, DSI_CONTROL
);
273 tegra_dsi_writel(dsi
, dsi
->video_fifo_depth
, DSI_MAX_THRESHOLD
);
275 value
= DSI_HOST_CONTROL_HS
;
276 tegra_dsi_writel(dsi
, value
, DSI_HOST_CONTROL
);
278 value
= tegra_dsi_readl(dsi
, DSI_CONTROL
);
280 if (dsi
->flags
& MIPI_DSI_CLOCK_NON_CONTINUOUS
)
281 value
|= DSI_CONTROL_HS_CLK_CTRL
;
283 value
&= ~DSI_CONTROL_TX_TRIG(3);
285 /* enable DCS commands for command mode */
286 if (dsi
->flags
& MIPI_DSI_MODE_VIDEO
)
287 value
&= ~DSI_CONTROL_DCS_ENABLE
;
289 value
|= DSI_CONTROL_DCS_ENABLE
;
291 value
|= DSI_CONTROL_VIDEO_ENABLE
;
292 value
&= ~DSI_CONTROL_HOST_ENABLE
;
293 tegra_dsi_writel(dsi
, value
, DSI_CONTROL
);
295 for (i
= 0; i
< NUM_PKT_SEQ
; i
++)
296 tegra_dsi_writel(dsi
, pkt_seq
[i
], DSI_PKT_SEQ_0_LO
+ i
);
298 if (dsi
->flags
& MIPI_DSI_MODE_VIDEO
) {
299 /* horizontal active pixels */
300 hact
= mode
->xres
* mul
/ div
;
302 /* horizontal sync width */
303 hsw
= (hsync_end(mode
) - hsync_start(mode
)) * mul
/ div
;
306 /* horizontal back porch */
307 hbp
= (htotal(mode
) - hsync_end(mode
)) * mul
/ div
;
310 /* horizontal front porch */
311 hfp
= (hsync_start(mode
) - mode
->xres
) * mul
/ div
;
314 tegra_dsi_writel(dsi
, hsw
<< 16 | 0, DSI_PKT_LEN_0_1
);
315 tegra_dsi_writel(dsi
, hact
<< 16 | hbp
, DSI_PKT_LEN_2_3
);
316 tegra_dsi_writel(dsi
, hfp
, DSI_PKT_LEN_4_5
);
317 tegra_dsi_writel(dsi
, 0x0f0f << 16, DSI_PKT_LEN_6_7
);
319 /* set SOL delay (for non-burst mode only) */
320 tegra_dsi_writel(dsi
, 8 * mul
/ div
, DSI_SOL_DELAY
);
322 /* TODO: implement ganged mode */
325 if (dsi
->ganged_mode
) {
327 * For ganged mode, assume symmetric left-right mode.
329 bytes
= 1 + (mode
->xres
/ 2) * mul
/ div
;
331 /* 1 byte (DCS command) + pixel data */
332 bytes
= 1 + mode
->xres
* mul
/ div
;
335 tegra_dsi_writel(dsi
, 0, DSI_PKT_LEN_0_1
);
336 tegra_dsi_writel(dsi
, bytes
<< 16, DSI_PKT_LEN_2_3
);
337 tegra_dsi_writel(dsi
, bytes
<< 16, DSI_PKT_LEN_4_5
);
338 tegra_dsi_writel(dsi
, 0, DSI_PKT_LEN_6_7
);
340 value
= MIPI_DCS_WRITE_MEMORY_START
<< 8 |
341 MIPI_DCS_WRITE_MEMORY_CONTINUE
;
342 tegra_dsi_writel(dsi
, value
, DSI_DCS_CMDS
);
345 if (dsi
->ganged_mode
) {
346 unsigned long delay
, bclk
, bclk_ganged
;
347 unsigned int lanes
= dsi
->ganged_lanes
;
349 /* SOL to valid, valid to FIFO and FIFO write delay */
351 delay
= DIV_ROUND_UP(delay
* mul
, div
* lanes
);
352 /* FIFO read delay */
355 bclk
= DIV_ROUND_UP(htotal(mode
) * mul
, div
* lanes
);
356 bclk_ganged
= DIV_ROUND_UP(bclk
* lanes
/ 2, lanes
);
357 value
= bclk
- bclk_ganged
+ delay
+ 20;
359 /* TODO: revisit for non-ganged mode */
360 value
= 8 * mul
/ div
;
363 tegra_dsi_writel(dsi
, value
, DSI_SOL_DELAY
);
367 err
= tegra_dsi_configure(dsi
->slave
, pipe
, mode
);
374 if (dsi
->ganged_mode
) {
375 tegra_dsi_ganged_enable(dsi
, mode
->xres
/ 2,
377 tegra_dsi_ganged_enable(dsi
->slave
, 0, mode
->xres
/ 2);
383 static int tegra_output_dsi_enable(struct tegra_dsi
*dsi
,
384 const struct soc_nvidia_tegra132_config
*config
)
391 err
= tegra_dsi_configure(dsi
, 0, config
);
395 /* enable DSI controller */
396 tegra_dsi_enable(dsi
);
403 static void tegra_dsi_set_timeout(struct tegra_dsi
*dsi
, unsigned long bclk
,
404 unsigned int vrefresh
)
406 unsigned int timeout
;
409 /* one frame high-speed transmission timeout */
410 timeout
= (bclk
/ vrefresh
) / 512;
411 value
= DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(timeout
);
412 tegra_dsi_writel(dsi
, value
, DSI_TIMEOUT_0
);
414 /* 2 ms peripheral timeout for panel */
415 timeout
= 2 * bclk
/ 512 * 1000;
416 value
= DSI_TIMEOUT_PR(timeout
) | DSI_TIMEOUT_TA(0x2000);
417 tegra_dsi_writel(dsi
, value
, DSI_TIMEOUT_1
);
419 value
= DSI_TALLY_TA(0) | DSI_TALLY_LRX(0) | DSI_TALLY_HTX(0);
420 tegra_dsi_writel(dsi
, value
, DSI_TO_TALLY
);
423 tegra_dsi_set_timeout(dsi
->slave
, bclk
, vrefresh
);
426 static int tegra_output_dsi_setup_clock(struct tegra_dsi
*dsi
,
427 const struct soc_nvidia_tegra132_config
*config
)
429 unsigned int mul
, div
, num_lanes
;
431 unsigned long pclk
= config
->pixel_clock
;
434 struct display_controller
*disp_ctrl
=
435 (void *)config
->display_controller
;
436 unsigned int shift_clk_div
;
438 err
= tegra_dsi_get_muldiv(dsi
->format
, &mul
, &div
);
443 * In ganged mode, account for the total number of lanes across both
444 * DSI channels so that the bit clock is properly computed.
446 if (dsi
->ganged_mode
)
447 num_lanes
= dsi
->ganged_lanes
;
449 num_lanes
= dsi
->lanes
;
451 /* compute byte clock */
452 bclk
= (pclk
* mul
) / (div
* num_lanes
);
455 * Compute bit clock and round up to the next MHz.
457 plld
= DIV_ROUND_UP(bclk
* 8, USECS_PER_SEC
) * USECS_PER_SEC
;
460 * the actual rate on PLLD_OUT0 is 1/2 plld
462 dsi
->clk_rate
= plld
/ 2;
464 dsi
->slave
->clk_rate
= dsi
->clk_rate
;
467 plld
= clock_configure_plld(plld
);
469 printk(BIOS_ERR
, "%s: clock init failed\n", __func__
);
474 * Derive pixel clock from bit clock using the shift clock divider.
475 * Note that this is only half of what we would expect, but we need
476 * that to make up for the fact that we divided the bit clock by a
477 * factor of two above.
479 shift_clk_div
= ((8 * mul
) / (div
* num_lanes
)) - 2;
480 update_display_shift_clock_divider(disp_ctrl
, shift_clk_div
);
482 tegra_dsi_set_timeout(dsi
, bclk
, config
->refresh
);
488 static int tegra_dsi_pad_enable(struct tegra_dsi
*dsi
)
492 value
= DSI_PAD_CONTROL_VS1_PULLDN(0) | DSI_PAD_CONTROL_VS1_PDIO(0);
493 tegra_dsi_writel(dsi
, value
, DSI_PAD_CONTROL_0
);
497 static int tegra_dsi_pad_calibrate(struct tegra_dsi
*dsi
)
501 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_0
);
502 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_1
);
503 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_2
);
504 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_3
);
505 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_4
);
507 /* start calibration */
508 tegra_dsi_pad_enable(dsi
);
510 value
= DSI_PAD_SLEW_UP(0x7) | DSI_PAD_SLEW_DN(0x7) |
511 DSI_PAD_LP_UP(0x1) | DSI_PAD_LP_DN(0x1) |
512 DSI_PAD_OUT_CLK(0x0);
513 tegra_dsi_writel(dsi
, value
, DSI_PAD_CONTROL_2
);
515 return tegra_mipi_calibrate(dsi
->mipi
);
518 static const char * const error_report
[16] = {
522 "Escape Mode Entry Command Error",
523 "Low-Power Transmit Sync Error",
524 "Peripheral Timeout Error",
525 "False Control Error",
526 "Contention Detected",
527 "ECC Error, single-bit",
528 "ECC Error, multi-bit",
530 "DSI Data Type Not Recognized",
532 "Invalid Transmission Length",
534 "DSI Protocol Violation",
537 static int tegra_dsi_read_response(struct tegra_dsi
*dsi
,
538 const struct mipi_dsi_msg
*msg
,
541 u8
*rx
= msg
->rx_buf
;
542 unsigned int i
, j
, k
;
547 /* read and parse packet header */
548 value
= tegra_dsi_readl(dsi
, DSI_RD_DATA
);
550 switch (value
& 0x3f) {
551 case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT
:
552 errors
= (value
>> 8) & 0xffff;
553 printk(BIOS_ERR
, "Acknowledge and error report: %04x\n",
555 for (i
= 0; i
< ARRAY_SIZE(error_report
); i
++)
557 printk(BIOS_INFO
, " %2u: %s\n", i
,
561 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE
:
562 rx
[0] = (value
>> 8) & 0xff;
565 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE
:
566 rx
[0] = (value
>> 8) & 0xff;
567 rx
[1] = (value
>> 16) & 0xff;
570 case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE
:
571 size
= ((value
>> 8) & 0xff00) | ((value
>> 8) & 0xff);
574 case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE
:
575 size
= ((value
>> 8) & 0xff00) | ((value
>> 8) & 0xff);
579 printk(BIOS_ERR
, "unhandled response type: %02x\n",
584 size
= MIN(size
, msg
->rx_len
);
586 if (msg
->rx_buf
&& size
> 0) {
587 for (i
= 0, j
= 0; i
< count
- 1; i
++, j
+= 4) {
588 value
= tegra_dsi_readl(dsi
, DSI_RD_DATA
);
590 for (k
= 0; k
< 4 && (j
+ k
) < msg
->rx_len
; k
++)
591 rx
[j
+ k
] = (value
>> (k
<< 3)) & 0xff;
597 static int tegra_dsi_transmit(struct tegra_dsi
*dsi
, unsigned long timeout_ms
)
599 u32 poll_interval_us
= 2000;
600 u32 timeout_us
= timeout_ms
* 1000;
602 tegra_dsi_writel(dsi
, DSI_TRIGGER_HOST
, DSI_TRIGGER
);
603 udelay(poll_interval_us
);
606 u32 value
= tegra_dsi_readl(dsi
, DSI_TRIGGER
);
607 if ((value
& DSI_TRIGGER_HOST
) == 0)
610 //usleep_range(1000, 2000);
611 if (timeout_us
> poll_interval_us
)
612 timeout_us
-= poll_interval_us
;
616 udelay(poll_interval_us
);
619 printk(BIOS_ERR
, "%s: ERROR: timeout waiting for transmission"
620 " to complete\n", __func__
);
624 static int tegra_dsi_wait_for_response(struct tegra_dsi
*dsi
,
625 unsigned long timeout_ms
)
627 u32 poll_interval_us
= 2000;
628 u32 timeout_us
= timeout_ms
* 1000;
631 u32 value
= tegra_dsi_readl(dsi
, DSI_STATUS
);
632 u8 count
= value
& 0x1f;
637 if (timeout_us
> poll_interval_us
)
638 timeout_us
-= poll_interval_us
;
642 udelay(poll_interval_us
);
645 printk(BIOS_ERR
, "%s: ERROR: timeout\n", __func__
);
650 static ssize_t
tegra_dsi_host_transfer(struct mipi_dsi_host
*host
,
651 const struct mipi_dsi_msg
*msg
)
653 struct tegra_dsi
*dsi
= host_to_tegra(host
);
654 const u8
*tx
= msg
->tx_buf
;
655 unsigned int count
, i
, j
;
659 if (msg
->tx_len
> dsi
->video_fifo_depth
* 4)
662 /* reset underflow/overflow flags */
663 value
= tegra_dsi_readl(dsi
, DSI_STATUS
);
664 if (value
& (DSI_STATUS_UNDERFLOW
| DSI_STATUS_OVERFLOW
)) {
665 value
= DSI_HOST_CONTROL_FIFO_RESET
;
666 tegra_dsi_writel(dsi
, value
, DSI_HOST_CONTROL
);
667 udelay(20); // usleep_range(10, 20);
670 value
= tegra_dsi_readl(dsi
, DSI_POWER_CONTROL
);
671 value
|= DSI_POWER_CONTROL_ENABLE
;
672 tegra_dsi_writel(dsi
, value
, DSI_POWER_CONTROL
);
674 udelay(7000); //usleep_range(5000, 10000);
676 value
= DSI_HOST_CONTROL_CRC_RESET
| DSI_HOST_CONTROL_TX_TRIG_HOST
|
677 DSI_HOST_CONTROL_CS
| DSI_HOST_CONTROL_ECC
;
679 if ((msg
->flags
& MIPI_DSI_MSG_USE_LPM
) == 0)
680 value
|= DSI_HOST_CONTROL_HS
;
683 * The host FIFO has a maximum of 64 words, so larger transmissions
684 * need to use the video FIFO.
686 if (msg
->tx_len
> dsi
->host_fifo_depth
* 4)
687 value
|= DSI_HOST_CONTROL_FIFO_SEL
;
689 tegra_dsi_writel(dsi
, value
, DSI_HOST_CONTROL
);
692 * For reads and messages with explicitly requested ACK, generate a
693 * BTA sequence after the transmission of the packet.
695 if ((msg
->flags
& MIPI_DSI_MSG_REQ_ACK
) ||
696 (msg
->rx_buf
&& msg
->rx_len
> 0)) {
697 value
= tegra_dsi_readl(dsi
, DSI_HOST_CONTROL
);
698 value
|= DSI_HOST_CONTROL_PKT_BTA
;
699 tegra_dsi_writel(dsi
, value
, DSI_HOST_CONTROL
);
702 value
= DSI_CONTROL_LANES(0) | DSI_CONTROL_HOST_ENABLE
;
703 tegra_dsi_writel(dsi
, value
, DSI_CONTROL
);
705 /* write packet header */
706 value
= ((msg
->channel
& 0x3) << 6) | (msg
->type
& 0x3f);
708 if (tx
&& msg
->tx_len
> 0)
711 if (tx
&& msg
->tx_len
> 1)
712 value
|= tx
[1] << 16;
714 tegra_dsi_writel(dsi
, value
, DSI_WR_DATA
);
716 /* write payload (if any) */
717 if (msg
->tx_len
> 2) {
718 for (j
= 2; j
< msg
->tx_len
; j
+= 4) {
721 for (i
= 0; i
< 4 && j
+ i
< msg
->tx_len
; i
++)
722 value
|= tx
[j
+ i
] << (i
<< 3);
724 tegra_dsi_writel(dsi
, value
, DSI_WR_DATA
);
728 err
= tegra_dsi_transmit(dsi
, 250);
732 if ((msg
->flags
& MIPI_DSI_MSG_REQ_ACK
) ||
733 (msg
->rx_buf
&& msg
->rx_len
> 0)) {
734 err
= tegra_dsi_wait_for_response(dsi
, 250);
740 value
= tegra_dsi_readl(dsi
, DSI_RD_DATA
);
744 dev_dbg(dsi->dev, "ACK\n");
750 dev_dbg(dsi->dev, "ESCAPE\n");
755 printk(BIOS_INFO
, "unknown status: %08x\n", value
);
760 err
= tegra_dsi_read_response(dsi
, msg
, count
);
763 "failed to parse response: %d\n",
770 static int tegra_dsi_ganged_setup(struct tegra_dsi
*dsi
,
771 struct tegra_dsi
*slave
)
774 * The number of ganged lanes is the sum of lanes of all peripherals
777 dsi
->slave
->ganged_lanes
= dsi
->lanes
+ dsi
->slave
->lanes
;
778 dsi
->slave
->ganged_mode
= 1;
780 dsi
->ganged_lanes
= dsi
->lanes
+ dsi
->slave
->lanes
;
781 dsi
->ganged_mode
= 1;
785 static int tegra_dsi_host_attach(struct mipi_dsi_host
*host
,
786 struct mipi_dsi_device
*device
)
788 struct tegra_dsi
*dsi
= host_to_tegra(host
);
791 dsi
->flags
= device
->mode_flags
;
792 dsi
->format
= device
->format
;
793 dsi
->lanes
= device
->lanes
;
796 err
= tegra_dsi_ganged_setup(dsi
->master
, dsi
);
798 printk(BIOS_ERR
, "failed to set up ganged mode: %d\n",
806 static const struct mipi_dsi_host_ops tegra_dsi_host_ops
= {
807 .attach
= tegra_dsi_host_attach
,
808 .transfer
= tegra_dsi_host_transfer
,
811 static int dsi_probe_if(int dsi_index
,
812 struct soc_nvidia_tegra132_config
*config
)
814 struct tegra_dsi
*dsi
= &dsi_data
[dsi_index
];
818 * Set default value. Will be taken from attached device once detected
821 dsi
->format
= MIPI_DSI_FMT_RGB888
;
824 /* get tegra_mipi_device */
825 dsi
->mipi
= tegra_mipi_request(&mipi_device_data
[dsi_index
], dsi_index
);
828 err
= tegra_dsi_pad_calibrate(dsi
);
830 printk(BIOS_ERR
, "MIPI calibration failed: %d\n", err
);
834 dsi
->host
.ops
= &tegra_dsi_host_ops
;
835 err
= mipi_dsi_host_register(&dsi
->host
);
837 printk(BIOS_ERR
, "failed to register DSI host: %d\n", err
);
842 dsi
->panel
= panel_jdi_dsi_probe((struct mipi_dsi_device
*)dsi
->host
.dev
);
843 if (IS_ERR_PTR(dsi
->panel
)) {
844 printk(BIOS_ERR
, "failed to get dsi panel\n");
847 dsi
->panel
->mode
= config
;
851 static int dsi_probe(struct soc_nvidia_tegra132_config
*config
)
853 dsi_probe_if(DSI_A
, config
);
854 dsi_probe_if(DSI_B
, config
);
858 static int dsi_enable(struct soc_nvidia_tegra132_config
*config
)
860 struct tegra_dsi
*dsi_a
= &dsi_data
[DSI_A
];
864 /* set up clock and TimeOutRegisters */
865 tegra_output_dsi_setup_clock(dsi_a
, config
);
867 /* configure APB_MISC_GP_MIPI_PAD_CTRL_0 */
868 write32((unsigned int *)APB_MISC_GP_MIPI_PAD_CTRL_0
, DSIB_MODE_DSI
);
870 /* configure phy interface timing registers */
871 tegra_dsi_set_phy_timing(dsi_a
);
874 panel_jdi_prepare(dsi_a
->panel
);
877 if (tegra_output_dsi_enable(dsi_a
, config
)) {
878 printk(BIOS_ERR
,"%s: Error: failed to enable dsi output.\n",
886 void dsi_display_startup(device_t dev
)
888 struct soc_nvidia_tegra132_config
*config
= dev
->chip_info
;
889 struct display_controller
*disp_ctrl
=
890 (void *)config
->display_controller
;
893 u32 framebuffer_size_mb
= config
->framebuffer_size
/ MiB
;
894 u32 framebuffer_base_mb
= config
->framebuffer_base
/ MiB
;
896 printk(BIOS_INFO
, "%s: entry: disp_ctrl: %p.\n",
897 __func__
, disp_ctrl
);
899 if (disp_ctrl
== NULL
) {
900 printk(BIOS_ERR
, "Error: No dc is assigned by dt.\n");
904 if (framebuffer_size_mb
== 0){
905 framebuffer_size_mb
= ALIGN_UP(config
->display_xres
*
906 config
->display_yres
*
907 (config
->framebuffer_bits_per_pixel
/ 8), MiB
)/MiB
;
910 config
->framebuffer_size
= framebuffer_size_mb
* MiB
;
911 config
->framebuffer_base
= framebuffer_base_mb
* MiB
;
914 * The plld is programmed with the assumption of the SHIFT_CLK_DIVIDER
915 * and PIXEL_CLK_DIVIDER are zero (divide by 1). See the
916 * update_display_mode() for detail.
918 /* set default plld */
919 plld_rate
= clock_configure_plld(config
->pixel_clock
* 2);
920 if (plld_rate
== 0) {
921 printk(BIOS_ERR
, "dc: clock init failed\n");
925 /* set disp1's clock source to PLLD_OUT0 */
926 clock_configure_source(disp1
, PLLD
, (plld_rate
/KHz
)/2);
929 if (tegra_dc_init(disp_ctrl
)) {
930 printk(BIOS_ERR
, "dc: init failed\n");
934 /* Configure dc mode */
935 if (update_display_mode(disp_ctrl
, config
)) {
936 printk(BIOS_ERR
, "dc: failed to configure display mode.\n");
940 /* Configure and enable dsi controller and panel */
941 if (dsi_enable(config
)) {
942 printk(BIOS_ERR
, "%s: failed to enable dsi controllers.\n",
948 update_window(config
);
949 printk(BIOS_INFO
, "%s: display init done.\n", __func__
);
951 /* Save panel information to cb tables */
952 pass_mode_info_to_payload(config
);
955 * After this point, it is payload's responsibility to allocate
956 * framebuffer and sets the base address to dc's
957 * WINBUF_START_ADDR register and enables window by setting dc's
958 * DISP_DISP_WIN_OPTIONS register.