blob: 2beb9ec9f247400ac6c3ba33ecc39679ace5052c [file] [log] [blame]
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2013 NVIDIA Corporation
4 * Copyright (c) 2022 Svyatoslav Ryhel <clamor95@gmail.com>
5 */
6
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +03007#include <dm.h>
Svyatoslav Ryhel71f2c362024-11-24 14:26:08 +02008#include <clk.h>
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +03009#include <log.h>
10#include <misc.h>
11#include <mipi_display.h>
12#include <mipi_dsi.h>
13#include <backlight.h>
14#include <panel.h>
Svyatoslav Ryhelfe0a53a2024-01-23 19:16:30 +020015#include <reset.h>
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +030016#include <linux/delay.h>
17#include <linux/err.h>
Igor Prusovc3421ea2023-11-09 20:10:04 +030018#include <linux/time.h>
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +030019#include <power/regulator.h>
20
21#include <asm/gpio.h>
22#include <asm/io.h>
23#include <asm/arch/clock.h>
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +030024#include <asm/arch-tegra/clk_rst.h>
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +030025
Svyatoslav Ryhel75fec412024-01-23 19:16:18 +020026#include "tegra-dc.h"
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +020027#include "tegra-dsi.h"
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +030028#include "mipi-phy.h"
29
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +020030/* List of supported DSI bridges */
31enum {
32 DSI_V0,
33 DSI_V1,
34};
35
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +030036struct tegra_dsi_priv {
37 struct mipi_dsi_host host;
38 struct mipi_dsi_device device;
39 struct mipi_dphy_timing dphy_timing;
40
41 struct udevice *panel;
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +020042 struct udevice *mipi;
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +030043 struct display_timing timing;
44
45 struct dsi_ctlr *dsi;
46 struct udevice *avdd;
47
48 enum tegra_dsi_format format;
49
Svyatoslav Ryhel71f2c362024-11-24 14:26:08 +020050 struct clk *clk;
51 struct clk *clk_parent;
52
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +030053 int video_fifo_depth;
54 int host_fifo_depth;
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +020055
56 u32 version;
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +030057
58 /* for ganged-mode support */
59 struct udevice *master;
60 struct udevice *slave;
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +030061};
62
63static void tegra_dc_enable_controller(struct udevice *dev)
64{
65 struct tegra_dc_plat *dc_plat = dev_get_plat(dev);
66 struct dc_ctlr *dc = dc_plat->dc;
67 u32 value;
68
69 value = readl(&dc->disp.disp_win_opt);
70 value |= DSI_ENABLE;
71 writel(value, &dc->disp.disp_win_opt);
72
73 writel(GENERAL_UPDATE, &dc->cmd.state_ctrl);
74 writel(GENERAL_ACT_REQ, &dc->cmd.state_ctrl);
75}
76
77static const char * const error_report[16] = {
78 "SoT Error",
79 "SoT Sync Error",
80 "EoT Sync Error",
81 "Escape Mode Entry Command Error",
82 "Low-Power Transmit Sync Error",
83 "Peripheral Timeout Error",
84 "False Control Error",
85 "Contention Detected",
86 "ECC Error, single-bit",
87 "ECC Error, multi-bit",
88 "Checksum Error",
89 "DSI Data Type Not Recognized",
90 "DSI VC ID Invalid",
91 "Invalid Transmission Length",
92 "Reserved",
93 "DSI Protocol Violation",
94};
95
96static ssize_t tegra_dsi_read_response(struct dsi_misc_reg *misc,
97 const struct mipi_dsi_msg *msg,
98 size_t count)
99{
100 u8 *rx = msg->rx_buf;
101 unsigned int i, j, k;
102 size_t size = 0;
103 u16 errors;
104 u32 value;
105
106 /* read and parse packet header */
107 value = readl(&misc->dsi_rd_data);
108
109 switch (value & 0x3f) {
110 case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT:
111 errors = (value >> 8) & 0xffff;
112 printf("%s: Acknowledge and error report: %04x\n",
113 __func__, errors);
114 for (i = 0; i < ARRAY_SIZE(error_report); i++)
115 if (errors & BIT(i))
116 printf("%s: %2u: %s\n", __func__, i,
117 error_report[i]);
118 break;
119
120 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE:
121 rx[0] = (value >> 8) & 0xff;
122 size = 1;
123 break;
124
125 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE:
126 rx[0] = (value >> 8) & 0xff;
127 rx[1] = (value >> 16) & 0xff;
128 size = 2;
129 break;
130
131 case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE:
132 size = ((value >> 8) & 0xff00) | ((value >> 8) & 0xff);
133 break;
134
135 case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE:
136 size = ((value >> 8) & 0xff00) | ((value >> 8) & 0xff);
137 break;
138
139 default:
140 printf("%s: unhandled response type: %02x\n",
141 __func__, value & 0x3f);
142 return -EPROTO;
143 }
144
145 size = min(size, msg->rx_len);
146
147 if (msg->rx_buf && size > 0) {
148 for (i = 0, j = 0; i < count - 1; i++, j += 4) {
149 u8 *rx = msg->rx_buf + j;
150
151 value = readl(&misc->dsi_rd_data);
152
153 for (k = 0; k < 4 && (j + k) < msg->rx_len; k++)
154 rx[j + k] = (value >> (k << 3)) & 0xff;
155 }
156 }
157
158 return size;
159}
160
161static int tegra_dsi_transmit(struct dsi_misc_reg *misc,
162 unsigned long timeout)
163{
164 writel(DSI_TRIGGER_HOST, &misc->dsi_trigger);
165
166 while (timeout--) {
167 u32 value = readl(&misc->dsi_trigger);
168
169 if ((value & DSI_TRIGGER_HOST) == 0)
170 return 0;
171
172 udelay(1000);
173 }
174
175 debug("timeout waiting for transmission to complete\n");
176 return -ETIMEDOUT;
177}
178
179static int tegra_dsi_wait_for_response(struct dsi_misc_reg *misc,
180 unsigned long timeout)
181{
182 while (timeout--) {
183 u32 value = readl(&misc->dsi_status);
184 u8 count = value & 0x1f;
185
186 if (count > 0)
187 return count;
188
189 udelay(1000);
190 }
191
192 debug("peripheral returned no data\n");
193 return -ETIMEDOUT;
194}
195
196static void tegra_dsi_writesl(struct dsi_misc_reg *misc,
197 const void *buffer, size_t size)
198{
199 const u8 *buf = buffer;
200 size_t i, j;
201 u32 value;
202
203 for (j = 0; j < size; j += 4) {
204 value = 0;
205
206 for (i = 0; i < 4 && j + i < size; i++)
207 value |= buf[j + i] << (i << 3);
208
209 writel(value, &misc->dsi_wr_data);
210 }
211}
212
213static ssize_t tegra_dsi_host_transfer(struct mipi_dsi_host *host,
214 const struct mipi_dsi_msg *msg)
215{
216 struct udevice *dev = (struct udevice *)host->dev;
217 struct tegra_dsi_priv *priv = dev_get_priv(dev);
218 struct dsi_misc_reg *misc = &priv->dsi->misc;
219 struct mipi_dsi_packet packet;
220 const u8 *header;
221 size_t count;
222 ssize_t err;
223 u32 value;
224
225 err = mipi_dsi_create_packet(&packet, msg);
226 if (err < 0)
227 return err;
228
229 header = packet.header;
230
231 /* maximum FIFO depth is 1920 words */
232 if (packet.size > priv->video_fifo_depth * 4)
233 return -ENOSPC;
234
235 /* reset underflow/overflow flags */
236 value = readl(&misc->dsi_status);
237 if (value & (DSI_STATUS_UNDERFLOW | DSI_STATUS_OVERFLOW)) {
238 value = DSI_HOST_CONTROL_FIFO_RESET;
239 writel(value, &misc->host_dsi_ctrl);
240 udelay(10);
241 }
242
243 value = readl(&misc->dsi_pwr_ctrl);
244 value |= DSI_POWER_CONTROL_ENABLE;
245 writel(value, &misc->dsi_pwr_ctrl);
246
247 mdelay(5);
248
249 value = DSI_HOST_CONTROL_CRC_RESET | DSI_HOST_CONTROL_TX_TRIG_HOST |
250 DSI_HOST_CONTROL_CS | DSI_HOST_CONTROL_ECC;
251
252 /*
253 * The host FIFO has a maximum of 64 words, so larger transmissions
254 * need to use the video FIFO.
255 */
256 if (packet.size > priv->host_fifo_depth * 4)
257 value |= DSI_HOST_CONTROL_FIFO_SEL;
258
259 writel(value, &misc->host_dsi_ctrl);
260
261 /*
262 * For reads and messages with explicitly requested ACK, generate a
263 * BTA sequence after the transmission of the packet.
264 */
265 if ((msg->flags & MIPI_DSI_MSG_REQ_ACK) ||
266 (msg->rx_buf && msg->rx_len > 0)) {
267 value = readl(&misc->host_dsi_ctrl);
268 value |= DSI_HOST_CONTROL_PKT_BTA;
269 writel(value, &misc->host_dsi_ctrl);
270 }
271
272 value = DSI_CONTROL_LANES(0) | DSI_CONTROL_HOST_ENABLE;
273 writel(value, &misc->dsi_ctrl);
274
275 /* write packet header, ECC is generated by hardware */
276 value = header[2] << 16 | header[1] << 8 | header[0];
277 writel(value, &misc->dsi_wr_data);
278
279 /* write payload (if any) */
280 if (packet.payload_length > 0)
281 tegra_dsi_writesl(misc, packet.payload,
282 packet.payload_length);
283
284 err = tegra_dsi_transmit(misc, 250);
285 if (err < 0)
286 return err;
287
288 if ((msg->flags & MIPI_DSI_MSG_REQ_ACK) ||
289 (msg->rx_buf && msg->rx_len > 0)) {
290 err = tegra_dsi_wait_for_response(misc, 250);
291 if (err < 0)
292 return err;
293
294 count = err;
295
296 value = readl(&misc->dsi_rd_data);
297 switch (value) {
298 case 0x84:
299 debug("%s: ACK\n", __func__);
300 break;
301
302 case 0x87:
303 debug("%s: ESCAPE\n", __func__);
304 break;
305
306 default:
307 printf("%s: unknown status: %08x\n", __func__, value);
308 break;
309 }
310
311 if (count > 1) {
312 err = tegra_dsi_read_response(misc, msg, count);
313 if (err < 0) {
314 printf("%s: failed to parse response: %zd\n",
315 __func__, err);
316 } else {
317 /*
318 * For read commands, return the number of
319 * bytes returned by the peripheral.
320 */
321 count = err;
322 }
323 }
324 } else {
325 /*
326 * For write commands, we have transmitted the 4-byte header
327 * plus the variable-length payload.
328 */
329 count = 4 + packet.payload_length;
330 }
331
332 return count;
333}
334
335struct mipi_dsi_host_ops tegra_dsi_bridge_host_ops = {
336 .transfer = tegra_dsi_host_transfer,
337};
338
339#define PKT_ID0(id) ((((id) & 0x3f) << 3) | (1 << 9))
340#define PKT_LEN0(len) (((len) & 0x07) << 0)
341#define PKT_ID1(id) ((((id) & 0x3f) << 13) | (1 << 19))
342#define PKT_LEN1(len) (((len) & 0x07) << 10)
343#define PKT_ID2(id) ((((id) & 0x3f) << 23) | (1 << 29))
344#define PKT_LEN2(len) (((len) & 0x07) << 20)
345
346#define PKT_LP BIT(30)
347#define NUM_PKT_SEQ 12
348
349/*
350 * non-burst mode with sync pulses
351 */
352static const u32 pkt_seq_video_non_burst_sync_pulses[NUM_PKT_SEQ] = {
353 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START) | PKT_LEN0(0) |
354 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
355 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
356 PKT_LP,
357 [ 1] = 0,
358 [ 2] = PKT_ID0(MIPI_DSI_V_SYNC_END) | PKT_LEN0(0) |
359 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
360 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
361 PKT_LP,
362 [ 3] = 0,
363 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
364 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
365 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
366 PKT_LP,
367 [ 5] = 0,
368 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
369 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
370 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0),
371 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(2) |
372 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN1(3) |
373 PKT_ID2(MIPI_DSI_BLANKING_PACKET) | PKT_LEN2(4),
374 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
375 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
376 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
377 PKT_LP,
378 [ 9] = 0,
379 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
380 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
381 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0),
382 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(2) |
383 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN1(3) |
384 PKT_ID2(MIPI_DSI_BLANKING_PACKET) | PKT_LEN2(4),
385};
386
387/*
388 * non-burst mode with sync events
389 */
390static const u32 pkt_seq_video_non_burst_sync_events[NUM_PKT_SEQ] = {
391 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START) | PKT_LEN0(0) |
392 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
393 PKT_LP,
394 [ 1] = 0,
395 [ 2] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
396 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
397 PKT_LP,
398 [ 3] = 0,
399 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
400 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
401 PKT_LP,
402 [ 5] = 0,
403 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
404 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(2) |
405 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN2(3),
406 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(4),
407 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
408 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
409 PKT_LP,
410 [ 9] = 0,
411 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
412 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(2) |
413 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN2(3),
414 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(4),
415};
416
417static const u32 pkt_seq_command_mode[NUM_PKT_SEQ] = {
418 [ 0] = 0,
419 [ 1] = 0,
420 [ 2] = 0,
421 [ 3] = 0,
422 [ 4] = 0,
423 [ 5] = 0,
424 [ 6] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE) | PKT_LEN0(3) | PKT_LP,
425 [ 7] = 0,
426 [ 8] = 0,
427 [ 9] = 0,
428 [10] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE) | PKT_LEN0(5) | PKT_LP,
429 [11] = 0,
430};
431
432static void tegra_dsi_get_muldiv(enum mipi_dsi_pixel_format format,
433 unsigned int *mulp, unsigned int *divp)
434{
435 switch (format) {
436 case MIPI_DSI_FMT_RGB666_PACKED:
437 case MIPI_DSI_FMT_RGB888:
438 *mulp = 3;
439 *divp = 1;
440 break;
441
442 case MIPI_DSI_FMT_RGB565:
443 *mulp = 2;
444 *divp = 1;
445 break;
446
447 case MIPI_DSI_FMT_RGB666:
448 *mulp = 9;
449 *divp = 4;
450 break;
451
452 default:
453 break;
454 }
455}
456
457static int tegra_dsi_get_format(enum mipi_dsi_pixel_format format,
458 enum tegra_dsi_format *fmt)
459{
460 switch (format) {
461 case MIPI_DSI_FMT_RGB888:
462 *fmt = TEGRA_DSI_FORMAT_24P;
463 break;
464
465 case MIPI_DSI_FMT_RGB666:
466 *fmt = TEGRA_DSI_FORMAT_18NP;
467 break;
468
469 case MIPI_DSI_FMT_RGB666_PACKED:
470 *fmt = TEGRA_DSI_FORMAT_18P;
471 break;
472
473 case MIPI_DSI_FMT_RGB565:
474 *fmt = TEGRA_DSI_FORMAT_16P;
475 break;
476
477 default:
478 return -EINVAL;
479 }
480
481 return 0;
482}
483
484static void tegra_dsi_pad_calibrate(struct dsi_pad_ctrl_reg *pad)
485{
486 u32 value;
487
488 /* start calibration */
489 value = DSI_PAD_CONTROL_PAD_LPUPADJ(0x1) |
490 DSI_PAD_CONTROL_PAD_LPDNADJ(0x1) |
491 DSI_PAD_CONTROL_PAD_PREEMP_EN(0x1) |
492 DSI_PAD_CONTROL_PAD_SLEWDNADJ(0x6) |
493 DSI_PAD_CONTROL_PAD_SLEWUPADJ(0x6) |
494 DSI_PAD_CONTROL_PAD_PDIO(0) |
495 DSI_PAD_CONTROL_PAD_PDIO_CLK(0) |
496 DSI_PAD_CONTROL_PAD_PULLDN_ENAB(0);
497 writel(value, &pad->pad_ctrl);
498
499 clock_enable(PERIPH_ID_VI);
500 clock_enable(PERIPH_ID_CSI);
501 udelay(2);
502 reset_set_enable(PERIPH_ID_VI, 0);
503 reset_set_enable(PERIPH_ID_CSI, 0);
504
505 value = MIPI_CAL_TERMOSA(0x4);
506 writel(value, TEGRA_VI_BASE + (CSI_CILA_MIPI_CAL_CONFIG_0 << 2));
507
508 value = MIPI_CAL_TERMOSB(0x4);
509 writel(value, TEGRA_VI_BASE + (CSI_CILB_MIPI_CAL_CONFIG_0 << 2));
510
511 value = MIPI_CAL_HSPUOSD(0x3) | MIPI_CAL_HSPDOSD(0x4);
512 writel(value, TEGRA_VI_BASE + (CSI_DSI_MIPI_CAL_CONFIG << 2));
513
514 value = PAD_DRIV_DN_REF(0x5) | PAD_DRIV_UP_REF(0x7);
515 writel(value, TEGRA_VI_BASE + (CSI_MIPIBIAS_PAD_CONFIG << 2));
516
517 value = PAD_CIL_PDVREG(0x0);
518 writel(value, TEGRA_VI_BASE + (CSI_CIL_PAD_CONFIG << 2));
519}
520
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200521static void tegra_dsi_mipi_calibrate(struct udevice *dev)
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +0200522{
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200523 struct tegra_dsi_priv *priv = dev_get_priv(dev);
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +0200524 struct dsi_pad_ctrl_reg *pad = &priv->dsi->pad;
525 u32 value;
526 int ret;
527
528 ret = misc_set_enabled(priv->mipi, true);
529 if (ret)
530 log_debug("%s: failed to enable MIPI calibration: %d\n",
531 __func__, ret);
532
533 writel(0, &pad->pad_ctrl);
534 writel(0, &pad->pad_ctrl_1);
535 writel(0, &pad->pad_ctrl_2);
536 writel(0, &pad->pad_ctrl_3);
537 writel(0, &pad->pad_ctrl_4);
538
539 /* DSI pad enable */
540 value = DSI_PAD_CONTROL_VS1_PULLDN(0) | DSI_PAD_CONTROL_VS1_PDIO(0);
541 writel(value, &pad->pad_ctrl);
542
543 value = DSI_PAD_SLEW_UP(0x7) | DSI_PAD_SLEW_DN(0x7) |
544 DSI_PAD_LP_UP(0x1) | DSI_PAD_LP_DN(0x1) |
545 DSI_PAD_OUT_CLK(0x0);
546 writel(value, &pad->pad_ctrl_2);
547
548 value = DSI_PAD_PREEMP_PD_CLK(0x3) | DSI_PAD_PREEMP_PU_CLK(0x3) |
549 DSI_PAD_PREEMP_PD(0x03) | DSI_PAD_PREEMP_PU(0x3);
550 writel(value, &pad->pad_ctrl_3);
551
552 ret = misc_write(priv->mipi, 0, NULL, 0);
553 if (ret)
554 log_debug("%s: MIPI calibration failed %d\n", __func__, ret);
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200555
556 if (priv->slave)
557 tegra_dsi_mipi_calibrate(priv->slave);
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +0200558}
559
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200560static void tegra_dsi_set_timeout(struct udevice *dev,
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300561 unsigned long bclk,
562 unsigned int vrefresh)
563{
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200564 struct tegra_dsi_priv *priv = dev_get_priv(dev);
565 struct dsi_timeout_reg *rtimeout = &priv->dsi->timeout;
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300566 unsigned int timeout;
567 u32 value;
568
569 /* one frame high-speed transmission timeout */
570 timeout = (bclk / vrefresh) / 512;
571 value = DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(timeout);
572 writel(value, &rtimeout->dsi_timeout_0);
573
574 /* 2 ms peripheral timeout for panel */
575 timeout = 2 * bclk / 512 * 1000;
576 value = DSI_TIMEOUT_PR(timeout) | DSI_TIMEOUT_TA(0x2000);
577 writel(value, &rtimeout->dsi_timeout_1);
578
579 value = DSI_TALLY_TA(0) | DSI_TALLY_LRX(0) | DSI_TALLY_HTX(0);
580 writel(value, &rtimeout->dsi_to_tally);
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200581
582 if (priv->slave)
583 tegra_dsi_set_timeout(priv->slave, bclk, vrefresh);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300584}
585
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200586static void tegra_dsi_set_phy_timing(struct udevice *dev,
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300587 unsigned long period,
588 const struct mipi_dphy_timing *dphy_timing)
589{
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200590 struct tegra_dsi_priv *priv = dev_get_priv(dev);
591 struct dsi_timing_reg *ptiming = &priv->dsi->ptiming;
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300592 u32 value;
593
594 value = DSI_TIMING_FIELD(dphy_timing->hsexit, period, 1) << 24 |
595 DSI_TIMING_FIELD(dphy_timing->hstrail, period, 0) << 16 |
596 DSI_TIMING_FIELD(dphy_timing->hszero, period, 3) << 8 |
597 DSI_TIMING_FIELD(dphy_timing->hsprepare, period, 1);
598 writel(value, &ptiming->dsi_phy_timing_0);
599
600 value = DSI_TIMING_FIELD(dphy_timing->clktrail, period, 1) << 24 |
601 DSI_TIMING_FIELD(dphy_timing->clkpost, period, 1) << 16 |
602 DSI_TIMING_FIELD(dphy_timing->clkzero, period, 1) << 8 |
603 DSI_TIMING_FIELD(dphy_timing->lpx, period, 1);
604 writel(value, &ptiming->dsi_phy_timing_1);
605
606 value = DSI_TIMING_FIELD(dphy_timing->clkprepare, period, 1) << 16 |
607 DSI_TIMING_FIELD(dphy_timing->clkpre, period, 1) << 8 |
608 DSI_TIMING_FIELD(0xff * period, period, 0) << 0;
609 writel(value, &ptiming->dsi_phy_timing_2);
610
611 value = DSI_TIMING_FIELD(dphy_timing->taget, period, 1) << 16 |
612 DSI_TIMING_FIELD(dphy_timing->tasure, period, 1) << 8 |
613 DSI_TIMING_FIELD(dphy_timing->tago, period, 1);
614 writel(value, &ptiming->dsi_bta_timing);
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200615
616 if (priv->slave)
617 tegra_dsi_set_phy_timing(priv->slave, period, dphy_timing);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300618}
619
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +0300620static void tegra_dsi_ganged_enable(struct udevice *dev, unsigned int start,
621 unsigned int size)
622{
623 struct tegra_dsi_priv *priv = dev_get_priv(dev);
624 struct dsi_ganged_mode_reg *ganged = &priv->dsi->ganged;
625
626 writel(start, &ganged->ganged_mode_start);
627 writel(size << 16 | size, &ganged->ganged_mode_size);
628 writel(DSI_GANGED_MODE_CONTROL_ENABLE, &ganged->ganged_mode_ctrl);
629}
630
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300631static void tegra_dsi_configure(struct udevice *dev,
632 unsigned long mode_flags)
633{
634 struct tegra_dsi_priv *priv = dev_get_priv(dev);
635 struct mipi_dsi_device *device = &priv->device;
636 struct display_timing *timing = &priv->timing;
637
638 struct dsi_misc_reg *misc = &priv->dsi->misc;
639 struct dsi_pkt_seq_reg *pkt = &priv->dsi->pkt;
640 struct dsi_pkt_len_reg *len = &priv->dsi->len;
641
642 unsigned int hact, hsw, hbp, hfp, i, mul, div;
643 const u32 *pkt_seq;
644 u32 value;
645
646 tegra_dsi_get_muldiv(device->format, &mul, &div);
647
648 if (mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) {
649 printf("[DSI] Non-burst video mode with sync pulses\n");
650 pkt_seq = pkt_seq_video_non_burst_sync_pulses;
651 } else if (mode_flags & MIPI_DSI_MODE_VIDEO) {
652 printf("[DSI] Non-burst video mode with sync events\n");
653 pkt_seq = pkt_seq_video_non_burst_sync_events;
654 } else {
655 printf("[DSI] Command mode\n");
656 pkt_seq = pkt_seq_command_mode;
657 }
658
659 value = DSI_CONTROL_CHANNEL(0) |
660 DSI_CONTROL_FORMAT(priv->format) |
661 DSI_CONTROL_LANES(device->lanes - 1) |
662 DSI_CONTROL_SOURCE(0);
663 writel(value, &misc->dsi_ctrl);
664
665 writel(priv->video_fifo_depth, &misc->dsi_max_threshold);
666
667 value = DSI_HOST_CONTROL_HS;
668 writel(value, &misc->host_dsi_ctrl);
669
670 value = readl(&misc->dsi_ctrl);
671
672 if (mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS)
673 value |= DSI_CONTROL_HS_CLK_CTRL;
674
675 value &= ~DSI_CONTROL_TX_TRIG(3);
676
677 /* enable DCS commands for command mode */
678 if (mode_flags & MIPI_DSI_MODE_VIDEO)
679 value &= ~DSI_CONTROL_DCS_ENABLE;
680 else
681 value |= DSI_CONTROL_DCS_ENABLE;
682
683 value |= DSI_CONTROL_VIDEO_ENABLE;
684 value &= ~DSI_CONTROL_HOST_ENABLE;
685 writel(value, &misc->dsi_ctrl);
686
687 for (i = 0; i < NUM_PKT_SEQ; i++)
688 writel(pkt_seq[i], &pkt->dsi_pkt_seq_0_lo + i);
689
690 if (mode_flags & MIPI_DSI_MODE_VIDEO) {
691 /* horizontal active pixels */
692 hact = timing->hactive.typ * mul / div;
693
694 /* horizontal sync width */
695 hsw = timing->hsync_len.typ * mul / div;
696
697 /* horizontal back porch */
698 hbp = timing->hback_porch.typ * mul / div;
699
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300700 /* horizontal front porch */
701 hfp = timing->hfront_porch.typ * mul / div;
702
Svyatoslav Ryhel10833fb2024-12-02 08:12:36 +0200703 if (priv->master || priv->slave) {
704 hact /= 2;
705 hsw /= 2;
706 hbp = hbp / 2 - 1;
707 hfp /= 2;
708 }
709
710 if ((mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) == 0)
711 hbp += hsw;
712
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300713 /* subtract packet overhead */
714 hsw -= 10;
715 hbp -= 14;
716 hfp -= 8;
717
718 writel(hsw << 16 | 0, &len->dsi_pkt_len_0_1);
719 writel(hact << 16 | hbp, &len->dsi_pkt_len_2_3);
720 writel(hfp, &len->dsi_pkt_len_4_5);
721 writel(0x0f0f << 16, &len->dsi_pkt_len_6_7);
722 } else {
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +0300723 if (priv->master || priv->slave) {
724 /*
725 * For ganged mode, assume symmetric left-right mode.
726 */
727 value = 1 + (timing->hactive.typ / 2) * mul / div;
728 } else {
729 /* 1 byte (DCS command) + pixel data */
730 value = 1 + timing->hactive.typ * mul / div;
731 }
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300732
733 writel(0, &len->dsi_pkt_len_0_1);
734 writel(value << 16, &len->dsi_pkt_len_2_3);
735 writel(value << 16, &len->dsi_pkt_len_4_5);
736 writel(0, &len->dsi_pkt_len_6_7);
737
738 value = MIPI_DCS_WRITE_MEMORY_START << 8 |
739 MIPI_DCS_WRITE_MEMORY_CONTINUE;
740 writel(value, &len->dsi_dcs_cmds);
Svyatoslav Ryhel18e4dcf2024-12-02 08:08:03 +0200741 }
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +0300742
Svyatoslav Ryhel18e4dcf2024-12-02 08:08:03 +0200743 /* set SOL delay */
744 if (priv->master || priv->slave) {
745 unsigned long delay, bclk, bclk_ganged;
746 unsigned int lanes = device->lanes;
747 unsigned long htotal = timing->hactive.typ + timing->hfront_porch.typ +
748 timing->hback_porch.typ + timing->hsync_len.typ;
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +0300749
Svyatoslav Ryhel18e4dcf2024-12-02 08:08:03 +0200750 /* SOL to valid, valid to FIFO and FIFO write delay */
751 delay = 4 + 4 + 2;
752 delay = DIV_ROUND_UP(delay * mul, div * lanes);
753 /* FIFO read delay */
754 delay = delay + 6;
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +0300755
Svyatoslav Ryhel18e4dcf2024-12-02 08:08:03 +0200756 bclk = DIV_ROUND_UP(htotal * mul, div * lanes);
757 bclk_ganged = DIV_ROUND_UP(bclk * lanes / 2, lanes);
758 value = bclk - bclk_ganged + delay + 20;
759 } else {
760 /* set SOL delay (for non-burst mode only) */
761 value = 8 * mul / div;
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300762 }
763
Svyatoslav Ryhel18e4dcf2024-12-02 08:08:03 +0200764 writel(value, &misc->dsi_sol_delay);
765
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +0300766 if (priv->slave) {
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200767 tegra_dsi_configure(priv->slave, mode_flags);
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +0300768 /*
769 * TODO: Support modes other than symmetrical left-right
770 * split.
771 */
772 tegra_dsi_ganged_enable(dev, 0, timing->hactive.typ / 2);
773 tegra_dsi_ganged_enable(priv->slave, timing->hactive.typ / 2,
774 timing->hactive.typ / 2);
775 }
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300776}
777
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200778static void tegra_dsi_enable(struct udevice *dev)
779{
780 struct tegra_dsi_priv *priv = dev_get_priv(dev);
781 struct dsi_misc_reg *misc = &priv->dsi->misc;
782 u32 value;
783
784 /* enable DSI controller */
785 value = readl(&misc->dsi_pwr_ctrl);
786 value |= DSI_POWER_CONTROL_ENABLE;
787 writel(value, &misc->dsi_pwr_ctrl);
788
789 if (priv->slave)
790 tegra_dsi_enable(priv->slave);
791}
792
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300793static int tegra_dsi_encoder_enable(struct udevice *dev)
794{
795 struct tegra_dsi_priv *priv = dev_get_priv(dev);
796 struct mipi_dsi_device *device = &priv->device;
797 struct display_timing *timing = &priv->timing;
798 struct dsi_misc_reg *misc = &priv->dsi->misc;
799 unsigned int mul, div;
800 unsigned long bclk, plld, period;
801 u32 value;
802 int ret;
803
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +0200804 /* If for some reasone DSI is enabled then it needs to
805 * be disabled in order for the panel initialization
806 * commands to be properly sent.
807 */
808 value = readl(&misc->dsi_pwr_ctrl);
809
810 if (value & DSI_POWER_CONTROL_ENABLE) {
811 value = readl(&misc->dsi_pwr_ctrl);
812 value &= ~DSI_POWER_CONTROL_ENABLE;
813 writel(value, &misc->dsi_pwr_ctrl);
814 }
815
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300816 /* Disable interrupt */
817 writel(0, &misc->int_enable);
818
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +0200819 if (priv->version)
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200820 tegra_dsi_mipi_calibrate(dev);
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +0200821 else
822 tegra_dsi_pad_calibrate(&priv->dsi->pad);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300823
824 tegra_dsi_get_muldiv(device->format, &mul, &div);
825
826 /* compute byte clock */
827 bclk = (timing->pixelclock.typ * mul) / (div * device->lanes);
828
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200829 tegra_dsi_set_timeout(dev, bclk, 60);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300830
831 /*
832 * Compute bit clock and round up to the next MHz.
833 */
834 plld = DIV_ROUND_UP(bclk * 8, USEC_PER_SEC) * USEC_PER_SEC;
835 period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, plld);
836
837 ret = mipi_dphy_timing_get_default(&priv->dphy_timing, period);
838 if (ret < 0) {
839 printf("%s: failed to get D-PHY timing: %d\n", __func__, ret);
840 return ret;
841 }
842
843 ret = mipi_dphy_timing_validate(&priv->dphy_timing, period);
844 if (ret < 0) {
845 printf("%s: failed to validate D-PHY timing: %d\n", __func__, ret);
846 return ret;
847 }
848
849 /*
850 * The D-PHY timing fields are expressed in byte-clock cycles, so
851 * multiply the period by 8.
852 */
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200853 tegra_dsi_set_phy_timing(dev, period * 8, &priv->dphy_timing);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300854
855 /* Perform panel HW setup */
856 ret = panel_enable_backlight(priv->panel);
857 if (ret)
858 return ret;
859
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300860 tegra_dsi_configure(dev, device->mode_flags);
861
862 tegra_dc_enable_controller(dev);
863
Svyatoslav Ryhel8e50b622024-12-31 09:50:03 +0200864 tegra_dsi_enable(dev);
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +0300865
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300866 return 0;
867}
868
869static int tegra_dsi_bridge_set_panel(struct udevice *dev, int percent)
870{
Jonas Schwöbeldea5d962024-01-23 19:16:33 +0200871 struct tegra_dsi_priv *priv = dev_get_priv(dev);
872
873 /* Turn on/off backlight */
874 return panel_set_backlight(priv->panel, percent);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300875}
876
877static int tegra_dsi_panel_timings(struct udevice *dev,
878 struct display_timing *timing)
879{
880 struct tegra_dsi_priv *priv = dev_get_priv(dev);
881
882 memcpy(timing, &priv->timing, sizeof(*timing));
883
884 return 0;
885}
886
887static void tegra_dsi_init_clocks(struct udevice *dev)
888{
889 struct tegra_dsi_priv *priv = dev_get_priv(dev);
Svyatoslav Ryheld16c1052024-01-23 19:16:23 +0200890 struct tegra_dc_plat *dc_plat = dev_get_plat(dev);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300891 struct mipi_dsi_device *device = &priv->device;
892 unsigned int mul, div;
893 unsigned long bclk, plld;
894
Svyatoslav Ryhel71f2c362024-11-24 14:26:08 +0200895 /* Switch parents of DSI clocks in case of not standard parent */
896 if (priv->clk->id == PERIPH_ID_DSI &&
897 priv->clk_parent->id == CLOCK_ID_DISPLAY2) {
898 /* Change DSIA clock parent to PLLD2 */
899 struct clk_rst_ctlr *clkrst =
900 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
901
902 /* DSIA_CLK_SRC */
903 setbits_le32(&clkrst->crc_pll[CLOCK_ID_DISPLAY].pll_base,
904 BIT(25));
905 }
906
907 if (priv->clk->id == PERIPH_ID_DSIB &&
908 priv->clk_parent->id == CLOCK_ID_DISPLAY) {
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +0300909 /* Change DSIB clock parent to match DSIA */
910 struct clk_rst_ctlr *clkrst =
911 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
912
Svyatoslav Ryhel71f2c362024-11-24 14:26:08 +0200913 /* DSIB_CLK_SRC */
914 clrbits_le32(&clkrst->plld2.pll_base, BIT(25));
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +0300915 }
916
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300917 tegra_dsi_get_muldiv(device->format, &mul, &div);
918
919 bclk = (priv->timing.pixelclock.typ * mul) /
920 (div * device->lanes);
921
922 plld = DIV_ROUND_UP(bclk * 8, USEC_PER_SEC);
923
Svyatoslav Ryheld16c1052024-01-23 19:16:23 +0200924 dc_plat->scdiv = ((plld * USEC_PER_SEC +
925 priv->timing.pixelclock.typ / 2) /
926 priv->timing.pixelclock.typ) - 2;
927
928 /*
929 * BUG: If DISP1 is a PLLD/D2 child, it cannot go over 370MHz. The
930 * cause of this is not quite clear. This can be overcomed by
931 * halving the PLLD/D2 if the target rate is > 800MHz. This way
932 * DISP1 and DSI clocks will be equal.
933 */
934 if (plld > 800)
935 plld /= 2;
936
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300937 switch (clock_get_osc_freq()) {
938 case CLOCK_OSC_FREQ_12_0: /* OSC is 12Mhz */
939 case CLOCK_OSC_FREQ_48_0: /* OSC is 48Mhz */
Svyatoslav Ryhel71f2c362024-11-24 14:26:08 +0200940 clock_set_rate(priv->clk_parent->id, plld, 12, 0, 8);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300941 break;
942
943 case CLOCK_OSC_FREQ_26_0: /* OSC is 26Mhz */
Svyatoslav Ryhel71f2c362024-11-24 14:26:08 +0200944 clock_set_rate(priv->clk_parent->id, plld, 26, 0, 8);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300945 break;
946
947 case CLOCK_OSC_FREQ_13_0: /* OSC is 13Mhz */
948 case CLOCK_OSC_FREQ_16_8: /* OSC is 16.8Mhz */
Svyatoslav Ryhel71f2c362024-11-24 14:26:08 +0200949 clock_set_rate(priv->clk_parent->id, plld, 13, 0, 8);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300950 break;
951
952 case CLOCK_OSC_FREQ_19_2:
953 case CLOCK_OSC_FREQ_38_4:
954 default:
955 /*
956 * These are not supported.
957 */
958 break;
959 }
960
Svyatoslav Ryhel71f2c362024-11-24 14:26:08 +0200961 clk_enable(priv->clk);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300962}
963
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +0300964static int tegra_dsi_ganged_probe(struct udevice *dev)
965{
966 struct tegra_dsi_priv *mpriv = dev_get_priv(dev);
967 struct udevice *gangster;
968
969 uclass_get_device_by_phandle(UCLASS_PANEL, dev,
970 "nvidia,ganged-mode", &gangster);
971 if (gangster) {
972 /* Ganged mode is set */
973 struct tegra_dsi_priv *spriv = dev_get_priv(gangster);
974
975 mpriv->slave = gangster;
976 spriv->master = dev;
977 }
978
979 return 0;
980}
981
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300982static int tegra_dsi_bridge_probe(struct udevice *dev)
983{
984 struct tegra_dsi_priv *priv = dev_get_priv(dev);
985 struct mipi_dsi_device *device = &priv->device;
986 struct mipi_dsi_panel_plat *mipi_plat;
Svyatoslav Ryhelfe0a53a2024-01-23 19:16:30 +0200987 struct reset_ctl reset_ctl;
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300988 int ret;
989
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +0200990 priv->version = dev_get_driver_data(dev);
991
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +0300992 priv->dsi = (struct dsi_ctlr *)dev_read_addr_ptr(dev);
993 if (!priv->dsi) {
994 printf("%s: No display controller address\n", __func__);
995 return -EINVAL;
996 }
997
Svyatoslav Ryhel71f2c362024-11-24 14:26:08 +0200998 priv->clk = devm_clk_get(dev, NULL);
999 if (IS_ERR(priv->clk)) {
1000 log_debug("%s: Could not get DSI clock: %ld\n",
1001 __func__, PTR_ERR(priv->clk));
1002 return PTR_ERR(priv->clk);
1003 }
1004
1005 priv->clk_parent = devm_clk_get(dev, "parent");
1006 if (IS_ERR(priv->clk_parent)) {
1007 log_debug("%s: Could not get DSI clock parent: %ld\n",
1008 __func__, PTR_ERR(priv->clk_parent));
1009 return PTR_ERR(priv->clk_parent);
1010 }
1011
Jonas Schwöbel0cccf902024-01-23 19:16:32 +02001012 priv->video_fifo_depth = 1920;
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +03001013 priv->host_fifo_depth = 64;
1014
Svyatoslav Ryhelab120e52024-07-30 13:35:45 +03001015 tegra_dsi_ganged_probe(dev);
1016
Svyatoslav Ryhelfe0a53a2024-01-23 19:16:30 +02001017 ret = reset_get_by_name(dev, "dsi", &reset_ctl);
1018 if (ret) {
1019 log_debug("%s: reset_get_by_name() failed: %d\n",
1020 __func__, ret);
1021 return ret;
1022 }
1023
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +03001024 ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
1025 "avdd-dsi-csi-supply", &priv->avdd);
1026 if (ret)
1027 debug("%s: Cannot get avdd-dsi-csi-supply: error %d\n",
1028 __func__, ret);
1029
Svyatoslav Ryhelf6b2ab42024-11-24 09:38:03 +02001030 /* Check all DSI children */
1031 device_foreach_child(priv->panel, dev) {
1032 if (device_get_uclass_id(priv->panel) == UCLASS_PANEL)
1033 break;
1034 }
1035
1036 /* if loop exits without panel device return error */
1037 if (device_get_uclass_id(priv->panel) != UCLASS_PANEL) {
1038 log_debug("%s: panel not found, ret %d\n", __func__, ret);
1039 return -EINVAL;
1040 }
1041
1042 ret = uclass_get_device_by_ofnode(UCLASS_PANEL, dev_ofnode(priv->panel),
1043 &priv->panel);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +03001044 if (ret) {
Svyatoslav Ryhelf6b2ab42024-11-24 09:38:03 +02001045 log_debug("%s: Cannot get panel: error %d\n", __func__, ret);
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +03001046 return log_ret(ret);
1047 }
1048
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +02001049 if (priv->version) {
1050 ret = uclass_get_device_by_phandle(UCLASS_MISC, dev,
1051 "nvidia,mipi-calibrate",
1052 &priv->mipi);
1053 if (ret) {
1054 log_debug("%s: cannot get MIPI: error %d\n", __func__, ret);
1055 return ret;
1056 }
1057 }
1058
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +03001059 panel_get_display_timing(priv->panel, &priv->timing);
1060
1061 mipi_plat = dev_get_plat(priv->panel);
1062 mipi_plat->device = device;
1063
1064 priv->host.dev = (struct device *)dev;
1065 priv->host.ops = &tegra_dsi_bridge_host_ops;
1066
1067 device->host = &priv->host;
1068 device->lanes = mipi_plat->lanes;
1069 device->format = mipi_plat->format;
1070 device->mode_flags = mipi_plat->mode_flags;
1071
1072 tegra_dsi_get_format(device->format, &priv->format);
1073
Svyatoslav Ryhelfe0a53a2024-01-23 19:16:30 +02001074 reset_assert(&reset_ctl);
1075
Svyatoslav Ryheldaab7d92023-10-03 09:25:34 +03001076 ret = regulator_set_enable_if_allowed(priv->avdd, true);
1077 if (ret && ret != -ENOSYS)
1078 return ret;
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +03001079
1080 tegra_dsi_init_clocks(dev);
1081
Svyatoslav Ryhelfe0a53a2024-01-23 19:16:30 +02001082 mdelay(2);
1083 reset_deassert(&reset_ctl);
1084
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +03001085 return 0;
1086}
1087
1088static const struct panel_ops tegra_dsi_bridge_ops = {
1089 .enable_backlight = tegra_dsi_encoder_enable,
1090 .set_backlight = tegra_dsi_bridge_set_panel,
1091 .get_display_timing = tegra_dsi_panel_timings,
1092};
1093
1094static const struct udevice_id tegra_dsi_bridge_ids[] = {
Svyatoslav Ryhel094d4f92024-01-23 19:16:29 +02001095 { .compatible = "nvidia,tegra30-dsi", .data = DSI_V0 },
1096 { .compatible = "nvidia,tegra114-dsi", .data = DSI_V1 },
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +03001097 { }
1098};
1099
1100U_BOOT_DRIVER(tegra_dsi) = {
1101 .name = "tegra_dsi",
1102 .id = UCLASS_PANEL,
1103 .of_match = tegra_dsi_bridge_ids,
1104 .ops = &tegra_dsi_bridge_ops,
Svyatoslav Ryhelf6b2ab42024-11-24 09:38:03 +02001105 .bind = dm_scan_fdt_dev,
Svyatoslav Ryhelfeddf9f2023-03-27 11:11:48 +03001106 .probe = tegra_dsi_bridge_probe,
1107 .plat_auto = sizeof(struct tegra_dc_plat),
1108 .priv_auto = sizeof(struct tegra_dsi_priv),
1109};