2 * Copyright (C) 2013 NVIDIA Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
10 #include <linux/debugfs.h>
11 #include <linux/host1x.h>
12 #include <linux/module.h>
14 #include <linux/of_platform.h>
15 #include <linux/platform_device.h>
16 #include <linux/reset.h>
18 #include <linux/regulator/consumer.h>
20 #include <drm/drm_mipi_dsi.h>
21 #include <drm/drm_panel.h>
23 #include <video/mipi_display.h>
31 struct host1x_client client;
32 struct tegra_output output;
37 struct reset_control *rst;
38 struct clk *clk_parent;
42 struct drm_info_list *debugfs_files;
43 struct drm_minor *minor;
44 struct dentry *debugfs;
47 enum mipi_dsi_pixel_format format;
50 struct tegra_mipi_device *mipi;
51 struct mipi_dsi_host host;
53 struct regulator *vdd;
56 unsigned int video_fifo_depth;
57 unsigned int host_fifo_depth;
59 /* for ganged-mode support */
60 struct tegra_dsi *master;
61 struct tegra_dsi *slave;
64 static inline struct tegra_dsi *
65 host1x_client_to_dsi(struct host1x_client *client)
67 return container_of(client, struct tegra_dsi, client);
70 static inline struct tegra_dsi *host_to_tegra(struct mipi_dsi_host *host)
72 return container_of(host, struct tegra_dsi, host);
75 static inline struct tegra_dsi *to_dsi(struct tegra_output *output)
77 return container_of(output, struct tegra_dsi, output);
80 static inline u32 tegra_dsi_readl(struct tegra_dsi *dsi, unsigned long reg)
82 return readl(dsi->regs + (reg << 2));
85 static inline void tegra_dsi_writel(struct tegra_dsi *dsi, u32 value,
88 writel(value, dsi->regs + (reg << 2));
91 static int tegra_dsi_show_regs(struct seq_file *s, void *data)
93 struct drm_info_node *node = s->private;
94 struct tegra_dsi *dsi = node->info_ent->data;
96 #define DUMP_REG(name) \
97 seq_printf(s, "%-32s %#05x %08x\n", #name, name, \
98 tegra_dsi_readl(dsi, name))
100 DUMP_REG(DSI_INCR_SYNCPT);
101 DUMP_REG(DSI_INCR_SYNCPT_CONTROL);
102 DUMP_REG(DSI_INCR_SYNCPT_ERROR);
104 DUMP_REG(DSI_RD_DATA);
105 DUMP_REG(DSI_WR_DATA);
106 DUMP_REG(DSI_POWER_CONTROL);
107 DUMP_REG(DSI_INT_ENABLE);
108 DUMP_REG(DSI_INT_STATUS);
109 DUMP_REG(DSI_INT_MASK);
110 DUMP_REG(DSI_HOST_CONTROL);
111 DUMP_REG(DSI_CONTROL);
112 DUMP_REG(DSI_SOL_DELAY);
113 DUMP_REG(DSI_MAX_THRESHOLD);
114 DUMP_REG(DSI_TRIGGER);
115 DUMP_REG(DSI_TX_CRC);
116 DUMP_REG(DSI_STATUS);
118 DUMP_REG(DSI_INIT_SEQ_CONTROL);
119 DUMP_REG(DSI_INIT_SEQ_DATA_0);
120 DUMP_REG(DSI_INIT_SEQ_DATA_1);
121 DUMP_REG(DSI_INIT_SEQ_DATA_2);
122 DUMP_REG(DSI_INIT_SEQ_DATA_3);
123 DUMP_REG(DSI_INIT_SEQ_DATA_4);
124 DUMP_REG(DSI_INIT_SEQ_DATA_5);
125 DUMP_REG(DSI_INIT_SEQ_DATA_6);
126 DUMP_REG(DSI_INIT_SEQ_DATA_7);
128 DUMP_REG(DSI_PKT_SEQ_0_LO);
129 DUMP_REG(DSI_PKT_SEQ_0_HI);
130 DUMP_REG(DSI_PKT_SEQ_1_LO);
131 DUMP_REG(DSI_PKT_SEQ_1_HI);
132 DUMP_REG(DSI_PKT_SEQ_2_LO);
133 DUMP_REG(DSI_PKT_SEQ_2_HI);
134 DUMP_REG(DSI_PKT_SEQ_3_LO);
135 DUMP_REG(DSI_PKT_SEQ_3_HI);
136 DUMP_REG(DSI_PKT_SEQ_4_LO);
137 DUMP_REG(DSI_PKT_SEQ_4_HI);
138 DUMP_REG(DSI_PKT_SEQ_5_LO);
139 DUMP_REG(DSI_PKT_SEQ_5_HI);
141 DUMP_REG(DSI_DCS_CMDS);
143 DUMP_REG(DSI_PKT_LEN_0_1);
144 DUMP_REG(DSI_PKT_LEN_2_3);
145 DUMP_REG(DSI_PKT_LEN_4_5);
146 DUMP_REG(DSI_PKT_LEN_6_7);
148 DUMP_REG(DSI_PHY_TIMING_0);
149 DUMP_REG(DSI_PHY_TIMING_1);
150 DUMP_REG(DSI_PHY_TIMING_2);
151 DUMP_REG(DSI_BTA_TIMING);
153 DUMP_REG(DSI_TIMEOUT_0);
154 DUMP_REG(DSI_TIMEOUT_1);
155 DUMP_REG(DSI_TO_TALLY);
157 DUMP_REG(DSI_PAD_CONTROL_0);
158 DUMP_REG(DSI_PAD_CONTROL_CD);
159 DUMP_REG(DSI_PAD_CD_STATUS);
160 DUMP_REG(DSI_VIDEO_MODE_CONTROL);
161 DUMP_REG(DSI_PAD_CONTROL_1);
162 DUMP_REG(DSI_PAD_CONTROL_2);
163 DUMP_REG(DSI_PAD_CONTROL_3);
164 DUMP_REG(DSI_PAD_CONTROL_4);
166 DUMP_REG(DSI_GANGED_MODE_CONTROL);
167 DUMP_REG(DSI_GANGED_MODE_START);
168 DUMP_REG(DSI_GANGED_MODE_SIZE);
170 DUMP_REG(DSI_RAW_DATA_BYTE_COUNT);
171 DUMP_REG(DSI_ULTRA_LOW_POWER_CONTROL);
173 DUMP_REG(DSI_INIT_SEQ_DATA_8);
174 DUMP_REG(DSI_INIT_SEQ_DATA_9);
175 DUMP_REG(DSI_INIT_SEQ_DATA_10);
176 DUMP_REG(DSI_INIT_SEQ_DATA_11);
177 DUMP_REG(DSI_INIT_SEQ_DATA_12);
178 DUMP_REG(DSI_INIT_SEQ_DATA_13);
179 DUMP_REG(DSI_INIT_SEQ_DATA_14);
180 DUMP_REG(DSI_INIT_SEQ_DATA_15);
187 static struct drm_info_list debugfs_files[] = {
188 { "regs", tegra_dsi_show_regs, 0, NULL },
191 static int tegra_dsi_debugfs_init(struct tegra_dsi *dsi,
192 struct drm_minor *minor)
194 const char *name = dev_name(dsi->dev);
198 dsi->debugfs = debugfs_create_dir(name, minor->debugfs_root);
202 dsi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
204 if (!dsi->debugfs_files) {
209 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
210 dsi->debugfs_files[i].data = dsi;
212 err = drm_debugfs_create_files(dsi->debugfs_files,
213 ARRAY_SIZE(debugfs_files),
214 dsi->debugfs, minor);
223 kfree(dsi->debugfs_files);
224 dsi->debugfs_files = NULL;
226 debugfs_remove(dsi->debugfs);
232 static int tegra_dsi_debugfs_exit(struct tegra_dsi *dsi)
234 drm_debugfs_remove_files(dsi->debugfs_files, ARRAY_SIZE(debugfs_files),
238 kfree(dsi->debugfs_files);
239 dsi->debugfs_files = NULL;
241 debugfs_remove(dsi->debugfs);
247 #define PKT_ID0(id) ((((id) & 0x3f) << 3) | (1 << 9))
248 #define PKT_LEN0(len) (((len) & 0x07) << 0)
249 #define PKT_ID1(id) ((((id) & 0x3f) << 13) | (1 << 19))
250 #define PKT_LEN1(len) (((len) & 0x07) << 10)
251 #define PKT_ID2(id) ((((id) & 0x3f) << 23) | (1 << 29))
252 #define PKT_LEN2(len) (((len) & 0x07) << 20)
254 #define PKT_LP (1 << 30)
255 #define NUM_PKT_SEQ 12
258 * non-burst mode with sync pulses
260 static const u32 pkt_seq_video_non_burst_sync_pulses[NUM_PKT_SEQ] = {
261 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START) | PKT_LEN0(0) |
262 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
263 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
266 [ 2] = PKT_ID0(MIPI_DSI_V_SYNC_END) | PKT_LEN0(0) |
267 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
268 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
271 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
272 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
273 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
276 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
277 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
278 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0),
279 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(2) |
280 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN1(3) |
281 PKT_ID2(MIPI_DSI_BLANKING_PACKET) | PKT_LEN2(4),
282 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
283 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
284 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0) |
287 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
288 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(1) |
289 PKT_ID2(MIPI_DSI_H_SYNC_END) | PKT_LEN2(0),
290 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(2) |
291 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN1(3) |
292 PKT_ID2(MIPI_DSI_BLANKING_PACKET) | PKT_LEN2(4),
296 * non-burst mode with sync events
298 static const u32 pkt_seq_video_non_burst_sync_events[NUM_PKT_SEQ] = {
299 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START) | PKT_LEN0(0) |
300 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
303 [ 2] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
304 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
307 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
308 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
311 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
312 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(2) |
313 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN2(3),
314 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(4),
315 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
316 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION) | PKT_LEN1(7) |
319 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START) | PKT_LEN0(0) |
320 PKT_ID1(MIPI_DSI_BLANKING_PACKET) | PKT_LEN1(2) |
321 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24) | PKT_LEN2(3),
322 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET) | PKT_LEN0(4),
325 static const u32 pkt_seq_command_mode[NUM_PKT_SEQ] = {
332 [ 6] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE) | PKT_LEN0(3) | PKT_LP,
336 [10] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE) | PKT_LEN0(5) | PKT_LP,
340 static int tegra_dsi_set_phy_timing(struct tegra_dsi *dsi)
342 struct mipi_dphy_timing timing;
343 unsigned long period;
348 rate = clk_get_rate(dsi->clk);
352 period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, rate * 2);
354 err = mipi_dphy_timing_get_default(&timing, period);
358 err = mipi_dphy_timing_validate(&timing, period);
360 dev_err(dsi->dev, "failed to validate D-PHY timing: %d\n", err);
365 * The D-PHY timing fields below are expressed in byte-clock cycles,
366 * so multiply the period by 8.
370 value = DSI_TIMING_FIELD(timing.hsexit, period, 1) << 24 |
371 DSI_TIMING_FIELD(timing.hstrail, period, 0) << 16 |
372 DSI_TIMING_FIELD(timing.hszero, period, 3) << 8 |
373 DSI_TIMING_FIELD(timing.hsprepare, period, 1);
374 tegra_dsi_writel(dsi, value, DSI_PHY_TIMING_0);
376 value = DSI_TIMING_FIELD(timing.clktrail, period, 1) << 24 |
377 DSI_TIMING_FIELD(timing.clkpost, period, 1) << 16 |
378 DSI_TIMING_FIELD(timing.clkzero, period, 1) << 8 |
379 DSI_TIMING_FIELD(timing.lpx, period, 1);
380 tegra_dsi_writel(dsi, value, DSI_PHY_TIMING_1);
382 value = DSI_TIMING_FIELD(timing.clkprepare, period, 1) << 16 |
383 DSI_TIMING_FIELD(timing.clkpre, period, 1) << 8 |
384 DSI_TIMING_FIELD(0xff * period, period, 0) << 0;
385 tegra_dsi_writel(dsi, value, DSI_PHY_TIMING_2);
387 value = DSI_TIMING_FIELD(timing.taget, period, 1) << 16 |
388 DSI_TIMING_FIELD(timing.tasure, period, 1) << 8 |
389 DSI_TIMING_FIELD(timing.tago, period, 1);
390 tegra_dsi_writel(dsi, value, DSI_BTA_TIMING);
393 return tegra_dsi_set_phy_timing(dsi->slave);
398 static int tegra_dsi_get_muldiv(enum mipi_dsi_pixel_format format,
399 unsigned int *mulp, unsigned int *divp)
402 case MIPI_DSI_FMT_RGB666_PACKED:
403 case MIPI_DSI_FMT_RGB888:
408 case MIPI_DSI_FMT_RGB565:
413 case MIPI_DSI_FMT_RGB666:
425 static int tegra_dsi_get_format(enum mipi_dsi_pixel_format format,
426 enum tegra_dsi_format *fmt)
429 case MIPI_DSI_FMT_RGB888:
430 *fmt = TEGRA_DSI_FORMAT_24P;
433 case MIPI_DSI_FMT_RGB666:
434 *fmt = TEGRA_DSI_FORMAT_18NP;
437 case MIPI_DSI_FMT_RGB666_PACKED:
438 *fmt = TEGRA_DSI_FORMAT_18P;
441 case MIPI_DSI_FMT_RGB565:
442 *fmt = TEGRA_DSI_FORMAT_16P;
452 static void tegra_dsi_ganged_enable(struct tegra_dsi *dsi, unsigned int start,
457 tegra_dsi_writel(dsi, start, DSI_GANGED_MODE_START);
458 tegra_dsi_writel(dsi, size << 16 | size, DSI_GANGED_MODE_SIZE);
460 value = DSI_GANGED_MODE_CONTROL_ENABLE;
461 tegra_dsi_writel(dsi, value, DSI_GANGED_MODE_CONTROL);
464 static void tegra_dsi_enable(struct tegra_dsi *dsi)
468 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
469 value |= DSI_POWER_CONTROL_ENABLE;
470 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
473 tegra_dsi_enable(dsi->slave);
476 static unsigned int tegra_dsi_get_lanes(struct tegra_dsi *dsi)
479 return dsi->master->lanes + dsi->lanes;
482 return dsi->lanes + dsi->slave->lanes;
487 static int tegra_dsi_configure(struct tegra_dsi *dsi, unsigned int pipe,
488 const struct drm_display_mode *mode)
490 unsigned int hact, hsw, hbp, hfp, i, mul, div;
491 enum tegra_dsi_format format;
496 if (dsi->flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) {
497 DRM_DEBUG_KMS("Non-burst video mode with sync pulses\n");
498 pkt_seq = pkt_seq_video_non_burst_sync_pulses;
499 } else if (dsi->flags & MIPI_DSI_MODE_VIDEO) {
500 DRM_DEBUG_KMS("Non-burst video mode with sync events\n");
501 pkt_seq = pkt_seq_video_non_burst_sync_events;
503 DRM_DEBUG_KMS("Command mode\n");
504 pkt_seq = pkt_seq_command_mode;
507 err = tegra_dsi_get_muldiv(dsi->format, &mul, &div);
511 err = tegra_dsi_get_format(dsi->format, &format);
515 value = DSI_CONTROL_CHANNEL(0) | DSI_CONTROL_FORMAT(format) |
516 DSI_CONTROL_LANES(dsi->lanes - 1) |
517 DSI_CONTROL_SOURCE(pipe);
518 tegra_dsi_writel(dsi, value, DSI_CONTROL);
520 tegra_dsi_writel(dsi, dsi->video_fifo_depth, DSI_MAX_THRESHOLD);
522 value = DSI_HOST_CONTROL_HS;
523 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL);
525 value = tegra_dsi_readl(dsi, DSI_CONTROL);
527 if (dsi->flags & MIPI_DSI_CLOCK_NON_CONTINUOUS)
528 value |= DSI_CONTROL_HS_CLK_CTRL;
530 value &= ~DSI_CONTROL_TX_TRIG(3);
532 /* enable DCS commands for command mode */
533 if (dsi->flags & MIPI_DSI_MODE_VIDEO)
534 value &= ~DSI_CONTROL_DCS_ENABLE;
536 value |= DSI_CONTROL_DCS_ENABLE;
538 value |= DSI_CONTROL_VIDEO_ENABLE;
539 value &= ~DSI_CONTROL_HOST_ENABLE;
540 tegra_dsi_writel(dsi, value, DSI_CONTROL);
542 for (i = 0; i < NUM_PKT_SEQ; i++)
543 tegra_dsi_writel(dsi, pkt_seq[i], DSI_PKT_SEQ_0_LO + i);
545 if (dsi->flags & MIPI_DSI_MODE_VIDEO) {
546 /* horizontal active pixels */
547 hact = mode->hdisplay * mul / div;
549 /* horizontal sync width */
550 hsw = (mode->hsync_end - mode->hsync_start) * mul / div;
553 /* horizontal back porch */
554 hbp = (mode->htotal - mode->hsync_end) * mul / div;
557 /* horizontal front porch */
558 hfp = (mode->hsync_start - mode->hdisplay) * mul / div;
561 tegra_dsi_writel(dsi, hsw << 16 | 0, DSI_PKT_LEN_0_1);
562 tegra_dsi_writel(dsi, hact << 16 | hbp, DSI_PKT_LEN_2_3);
563 tegra_dsi_writel(dsi, hfp, DSI_PKT_LEN_4_5);
564 tegra_dsi_writel(dsi, 0x0f0f << 16, DSI_PKT_LEN_6_7);
566 /* set SOL delay (for non-burst mode only) */
567 tegra_dsi_writel(dsi, 8 * mul / div, DSI_SOL_DELAY);
569 /* TODO: implement ganged mode */
573 if (dsi->master || dsi->slave) {
575 * For ganged mode, assume symmetric left-right mode.
577 bytes = 1 + (mode->hdisplay / 2) * mul / div;
579 /* 1 byte (DCS command) + pixel data */
580 bytes = 1 + mode->hdisplay * mul / div;
583 tegra_dsi_writel(dsi, 0, DSI_PKT_LEN_0_1);
584 tegra_dsi_writel(dsi, bytes << 16, DSI_PKT_LEN_2_3);
585 tegra_dsi_writel(dsi, bytes << 16, DSI_PKT_LEN_4_5);
586 tegra_dsi_writel(dsi, 0, DSI_PKT_LEN_6_7);
588 value = MIPI_DCS_WRITE_MEMORY_START << 8 |
589 MIPI_DCS_WRITE_MEMORY_CONTINUE;
590 tegra_dsi_writel(dsi, value, DSI_DCS_CMDS);
593 if (dsi->master || dsi->slave) {
594 unsigned int lanes = tegra_dsi_get_lanes(dsi);
595 unsigned long delay, bclk, bclk_ganged;
597 /* SOL to valid, valid to FIFO and FIFO write delay */
599 delay = DIV_ROUND_UP(delay * mul, div * lanes);
600 /* FIFO read delay */
603 bclk = DIV_ROUND_UP(mode->htotal * mul, div * lanes);
604 bclk_ganged = DIV_ROUND_UP(bclk * lanes / 2, lanes);
605 value = bclk - bclk_ganged + delay + 20;
607 /* TODO: revisit for non-ganged mode */
608 value = 8 * mul / div;
611 tegra_dsi_writel(dsi, value, DSI_SOL_DELAY);
615 err = tegra_dsi_configure(dsi->slave, pipe, mode);
620 * TODO: Support modes other than symmetrical left-right
623 tegra_dsi_ganged_enable(dsi, 0, mode->hdisplay / 2);
624 tegra_dsi_ganged_enable(dsi->slave, mode->hdisplay / 2,
631 static int tegra_output_dsi_enable(struct tegra_output *output)
633 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
634 const struct drm_display_mode *mode = &dc->base.mode;
635 struct tegra_dsi *dsi = to_dsi(output);
642 err = tegra_dsi_configure(dsi, dc->pipe, mode);
646 /* enable display controller */
647 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
649 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
651 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
652 value &= ~DISP_CTRL_MODE_MASK;
653 value |= DISP_CTRL_MODE_C_DISPLAY;
654 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
656 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
657 value |= PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
658 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
659 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
661 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
662 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
664 /* enable DSI controller */
665 tegra_dsi_enable(dsi);
672 static int tegra_dsi_wait_idle(struct tegra_dsi *dsi, unsigned long timeout)
676 timeout = jiffies + msecs_to_jiffies(timeout);
678 while (time_before(jiffies, timeout)) {
679 value = tegra_dsi_readl(dsi, DSI_STATUS);
680 if (value & DSI_STATUS_IDLE)
683 usleep_range(1000, 2000);
689 static void tegra_dsi_video_disable(struct tegra_dsi *dsi)
693 value = tegra_dsi_readl(dsi, DSI_CONTROL);
694 value &= ~DSI_CONTROL_VIDEO_ENABLE;
695 tegra_dsi_writel(dsi, value, DSI_CONTROL);
698 tegra_dsi_video_disable(dsi->slave);
701 static void tegra_dsi_ganged_disable(struct tegra_dsi *dsi)
703 tegra_dsi_writel(dsi, 0, DSI_GANGED_MODE_START);
704 tegra_dsi_writel(dsi, 0, DSI_GANGED_MODE_SIZE);
705 tegra_dsi_writel(dsi, 0, DSI_GANGED_MODE_CONTROL);
708 static void tegra_dsi_disable(struct tegra_dsi *dsi)
713 tegra_dsi_ganged_disable(dsi->slave);
714 tegra_dsi_ganged_disable(dsi);
717 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
718 value &= ~DSI_POWER_CONTROL_ENABLE;
719 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
722 tegra_dsi_disable(dsi->slave);
724 usleep_range(5000, 10000);
727 static void tegra_dsi_soft_reset(struct tegra_dsi *dsi)
731 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
732 value &= ~DSI_POWER_CONTROL_ENABLE;
733 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
735 usleep_range(300, 1000);
737 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
738 value |= DSI_POWER_CONTROL_ENABLE;
739 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
741 usleep_range(300, 1000);
743 value = tegra_dsi_readl(dsi, DSI_TRIGGER);
745 tegra_dsi_writel(dsi, 0, DSI_TRIGGER);
748 tegra_dsi_soft_reset(dsi->slave);
751 static int tegra_output_dsi_disable(struct tegra_output *output)
753 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
754 struct tegra_dsi *dsi = to_dsi(output);
761 tegra_dsi_video_disable(dsi);
764 * The following accesses registers of the display controller, so make
765 * sure it's only executed when the output is attached to one.
768 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
769 value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
770 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE);
771 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
773 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
774 value &= ~DISP_CTRL_MODE_MASK;
775 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
777 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
778 value &= ~DSI_ENABLE;
779 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
781 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
782 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
785 err = tegra_dsi_wait_idle(dsi, 100);
787 dev_dbg(dsi->dev, "failed to idle DSI: %d\n", err);
789 tegra_dsi_soft_reset(dsi);
790 tegra_dsi_disable(dsi);
792 dsi->enabled = false;
797 static void tegra_dsi_set_timeout(struct tegra_dsi *dsi, unsigned long bclk,
798 unsigned int vrefresh)
800 unsigned int timeout;
803 /* one frame high-speed transmission timeout */
804 timeout = (bclk / vrefresh) / 512;
805 value = DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(timeout);
806 tegra_dsi_writel(dsi, value, DSI_TIMEOUT_0);
808 /* 2 ms peripheral timeout for panel */
809 timeout = 2 * bclk / 512 * 1000;
810 value = DSI_TIMEOUT_PR(timeout) | DSI_TIMEOUT_TA(0x2000);
811 tegra_dsi_writel(dsi, value, DSI_TIMEOUT_1);
813 value = DSI_TALLY_TA(0) | DSI_TALLY_LRX(0) | DSI_TALLY_HTX(0);
814 tegra_dsi_writel(dsi, value, DSI_TO_TALLY);
817 tegra_dsi_set_timeout(dsi->slave, bclk, vrefresh);
820 static int tegra_output_dsi_setup_clock(struct tegra_output *output,
821 struct clk *clk, unsigned long pclk,
824 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
825 struct drm_display_mode *mode = &dc->base.mode;
826 struct tegra_dsi *dsi = to_dsi(output);
827 unsigned int mul, div, vrefresh, lanes;
828 unsigned long bclk, plld;
831 lanes = tegra_dsi_get_lanes(dsi);
833 err = tegra_dsi_get_muldiv(dsi->format, &mul, &div);
837 DRM_DEBUG_KMS("mul: %u, div: %u, lanes: %u\n", mul, div, lanes);
838 vrefresh = drm_mode_vrefresh(mode);
839 DRM_DEBUG_KMS("vrefresh: %u\n", vrefresh);
841 /* compute byte clock */
842 bclk = (pclk * mul) / (div * lanes);
845 * Compute bit clock and round up to the next MHz.
847 plld = DIV_ROUND_UP(bclk * 8, USEC_PER_SEC) * USEC_PER_SEC;
850 * We divide the frequency by two here, but we make up for that by
851 * setting the shift clock divider (further below) to half of the
856 err = clk_set_parent(clk, dsi->clk_parent);
858 dev_err(dsi->dev, "failed to set parent clock: %d\n", err);
862 err = clk_set_rate(dsi->clk_parent, plld);
864 dev_err(dsi->dev, "failed to set base clock rate to %lu Hz\n",
870 * Derive pixel clock from bit clock using the shift clock divider.
871 * Note that this is only half of what we would expect, but we need
872 * that to make up for the fact that we divided the bit clock by a
873 * factor of two above.
875 * It's not clear exactly why this is necessary, but the display is
876 * not working properly otherwise. Perhaps the PLLs cannot generate
877 * frequencies sufficiently high.
879 *divp = ((8 * mul) / (div * lanes)) - 2;
882 * XXX: Move the below somewhere else so that we don't need to have
883 * access to the vrefresh in this function?
885 tegra_dsi_set_timeout(dsi, bclk, vrefresh);
887 err = tegra_dsi_set_phy_timing(dsi);
894 static int tegra_output_dsi_check_mode(struct tegra_output *output,
895 struct drm_display_mode *mode,
896 enum drm_mode_status *status)
899 * FIXME: For now, always assume that the mode is okay.
907 static const struct tegra_output_ops dsi_ops = {
908 .enable = tegra_output_dsi_enable,
909 .disable = tegra_output_dsi_disable,
910 .setup_clock = tegra_output_dsi_setup_clock,
911 .check_mode = tegra_output_dsi_check_mode,
914 static int tegra_dsi_pad_enable(struct tegra_dsi *dsi)
918 value = DSI_PAD_CONTROL_VS1_PULLDN(0) | DSI_PAD_CONTROL_VS1_PDIO(0);
919 tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_0);
924 static int tegra_dsi_pad_calibrate(struct tegra_dsi *dsi)
928 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_0);
929 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_1);
930 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_2);
931 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_3);
932 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_4);
934 /* start calibration */
935 tegra_dsi_pad_enable(dsi);
937 value = DSI_PAD_SLEW_UP(0x7) | DSI_PAD_SLEW_DN(0x7) |
938 DSI_PAD_LP_UP(0x1) | DSI_PAD_LP_DN(0x1) |
939 DSI_PAD_OUT_CLK(0x0);
940 tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_2);
942 return tegra_mipi_calibrate(dsi->mipi);
945 static int tegra_dsi_init(struct host1x_client *client)
947 struct drm_device *drm = dev_get_drvdata(client->parent);
948 struct tegra_dsi *dsi = host1x_client_to_dsi(client);
951 /* Gangsters must not register their own outputs. */
953 dsi->output.type = TEGRA_OUTPUT_DSI;
954 dsi->output.dev = client->dev;
955 dsi->output.ops = &dsi_ops;
957 err = tegra_output_init(drm, &dsi->output);
959 dev_err(client->dev, "output setup failed: %d\n", err);
964 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
965 err = tegra_dsi_debugfs_init(dsi, drm->primary);
967 dev_err(dsi->dev, "debugfs setup failed: %d\n", err);
973 static int tegra_dsi_exit(struct host1x_client *client)
975 struct tegra_dsi *dsi = host1x_client_to_dsi(client);
978 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
979 err = tegra_dsi_debugfs_exit(dsi);
981 dev_err(dsi->dev, "debugfs cleanup failed: %d\n", err);
985 err = tegra_output_disable(&dsi->output);
987 dev_err(client->dev, "output failed to disable: %d\n",
992 err = tegra_output_exit(&dsi->output);
994 dev_err(client->dev, "output cleanup failed: %d\n",
1003 static const struct host1x_client_ops dsi_client_ops = {
1004 .init = tegra_dsi_init,
1005 .exit = tegra_dsi_exit,
1008 static int tegra_dsi_setup_clocks(struct tegra_dsi *dsi)
1013 parent = clk_get_parent(dsi->clk);
1017 err = clk_set_parent(parent, dsi->clk_parent);
1024 static const char * const error_report[16] = {
1028 "Escape Mode Entry Command Error",
1029 "Low-Power Transmit Sync Error",
1030 "Peripheral Timeout Error",
1031 "False Control Error",
1032 "Contention Detected",
1033 "ECC Error, single-bit",
1034 "ECC Error, multi-bit",
1036 "DSI Data Type Not Recognized",
1037 "DSI VC ID Invalid",
1038 "Invalid Transmission Length",
1040 "DSI Protocol Violation",
1043 static ssize_t tegra_dsi_read_response(struct tegra_dsi *dsi,
1044 const struct mipi_dsi_msg *msg,
1047 u8 *rx = msg->rx_buf;
1048 unsigned int i, j, k;
1053 /* read and parse packet header */
1054 value = tegra_dsi_readl(dsi, DSI_RD_DATA);
1056 switch (value & 0x3f) {
1057 case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT:
1058 errors = (value >> 8) & 0xffff;
1059 dev_dbg(dsi->dev, "Acknowledge and error report: %04x\n",
1061 for (i = 0; i < ARRAY_SIZE(error_report); i++)
1062 if (errors & BIT(i))
1063 dev_dbg(dsi->dev, " %2u: %s\n", i,
1067 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE:
1068 rx[0] = (value >> 8) & 0xff;
1072 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE:
1073 rx[0] = (value >> 8) & 0xff;
1074 rx[1] = (value >> 16) & 0xff;
1078 case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE:
1079 size = ((value >> 8) & 0xff00) | ((value >> 8) & 0xff);
1082 case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE:
1083 size = ((value >> 8) & 0xff00) | ((value >> 8) & 0xff);
1087 dev_err(dsi->dev, "unhandled response type: %02x\n",
1092 size = min(size, msg->rx_len);
1094 if (msg->rx_buf && size > 0) {
1095 for (i = 0, j = 0; i < count - 1; i++, j += 4) {
1096 u8 *rx = msg->rx_buf + j;
1098 value = tegra_dsi_readl(dsi, DSI_RD_DATA);
1100 for (k = 0; k < 4 && (j + k) < msg->rx_len; k++)
1101 rx[j + k] = (value >> (k << 3)) & 0xff;
1108 static int tegra_dsi_transmit(struct tegra_dsi *dsi, unsigned long timeout)
1110 tegra_dsi_writel(dsi, DSI_TRIGGER_HOST, DSI_TRIGGER);
1112 timeout = jiffies + msecs_to_jiffies(timeout);
1114 while (time_before(jiffies, timeout)) {
1115 u32 value = tegra_dsi_readl(dsi, DSI_TRIGGER);
1116 if ((value & DSI_TRIGGER_HOST) == 0)
1119 usleep_range(1000, 2000);
1122 DRM_DEBUG_KMS("timeout waiting for transmission to complete\n");
1126 static int tegra_dsi_wait_for_response(struct tegra_dsi *dsi,
1127 unsigned long timeout)
1129 timeout = jiffies + msecs_to_jiffies(250);
1131 while (time_before(jiffies, timeout)) {
1132 u32 value = tegra_dsi_readl(dsi, DSI_STATUS);
1133 u8 count = value & 0x1f;
1138 usleep_range(1000, 2000);
1141 DRM_DEBUG_KMS("peripheral returned no data\n");
1145 static void tegra_dsi_writesl(struct tegra_dsi *dsi, unsigned long offset,
1146 const void *buffer, size_t size)
1148 const u8 *buf = buffer;
1152 for (j = 0; j < size; j += 4) {
1155 for (i = 0; i < 4 && j + i < size; i++)
1156 value |= buf[j + i] << (i << 3);
1158 tegra_dsi_writel(dsi, value, DSI_WR_DATA);
1162 static ssize_t tegra_dsi_host_transfer(struct mipi_dsi_host *host,
1163 const struct mipi_dsi_msg *msg)
1165 struct tegra_dsi *dsi = host_to_tegra(host);
1166 struct mipi_dsi_packet packet;
1172 err = mipi_dsi_create_packet(&packet, msg);
1176 header = packet.header;
1178 /* maximum FIFO depth is 1920 words */
1179 if (packet.size > dsi->video_fifo_depth * 4)
1182 /* reset underflow/overflow flags */
1183 value = tegra_dsi_readl(dsi, DSI_STATUS);
1184 if (value & (DSI_STATUS_UNDERFLOW | DSI_STATUS_OVERFLOW)) {
1185 value = DSI_HOST_CONTROL_FIFO_RESET;
1186 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL);
1187 usleep_range(10, 20);
1190 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL);
1191 value |= DSI_POWER_CONTROL_ENABLE;
1192 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL);
1194 usleep_range(5000, 10000);
1196 value = DSI_HOST_CONTROL_CRC_RESET | DSI_HOST_CONTROL_TX_TRIG_HOST |
1197 DSI_HOST_CONTROL_CS | DSI_HOST_CONTROL_ECC;
1199 if ((msg->flags & MIPI_DSI_MSG_USE_LPM) == 0)
1200 value |= DSI_HOST_CONTROL_HS;
1203 * The host FIFO has a maximum of 64 words, so larger transmissions
1204 * need to use the video FIFO.
1206 if (packet.size > dsi->host_fifo_depth * 4)
1207 value |= DSI_HOST_CONTROL_FIFO_SEL;
1209 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL);
1212 * For reads and messages with explicitly requested ACK, generate a
1213 * BTA sequence after the transmission of the packet.
1215 if ((msg->flags & MIPI_DSI_MSG_REQ_ACK) ||
1216 (msg->rx_buf && msg->rx_len > 0)) {
1217 value = tegra_dsi_readl(dsi, DSI_HOST_CONTROL);
1218 value |= DSI_HOST_CONTROL_PKT_BTA;
1219 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL);
1222 value = DSI_CONTROL_LANES(0) | DSI_CONTROL_HOST_ENABLE;
1223 tegra_dsi_writel(dsi, value, DSI_CONTROL);
1225 /* write packet header, ECC is generated by hardware */
1226 value = header[2] << 16 | header[1] << 8 | header[0];
1227 tegra_dsi_writel(dsi, value, DSI_WR_DATA);
1229 /* write payload (if any) */
1230 if (packet.payload_length > 0)
1231 tegra_dsi_writesl(dsi, DSI_WR_DATA, packet.payload,
1232 packet.payload_length);
1234 err = tegra_dsi_transmit(dsi, 250);
1238 if ((msg->flags & MIPI_DSI_MSG_REQ_ACK) ||
1239 (msg->rx_buf && msg->rx_len > 0)) {
1240 err = tegra_dsi_wait_for_response(dsi, 250);
1246 value = tegra_dsi_readl(dsi, DSI_RD_DATA);
1250 dev_dbg(dsi->dev, "ACK\n");
1256 dev_dbg(dsi->dev, "ESCAPE\n");
1261 dev_err(dsi->dev, "unknown status: %08x\n", value);
1266 err = tegra_dsi_read_response(dsi, msg, count);
1269 "failed to parse response: %zd\n",
1273 * For read commands, return the number of
1274 * bytes returned by the peripheral.
1281 * For write commands, we have transmitted the 4-byte header
1282 * plus the variable-length payload.
1284 count = 4 + packet.payload_length;
1290 static int tegra_dsi_ganged_setup(struct tegra_dsi *dsi)
1295 /* make sure both DSI controllers share the same PLL */
1296 parent = clk_get_parent(dsi->slave->clk);
1300 err = clk_set_parent(parent, dsi->clk_parent);
1307 static int tegra_dsi_host_attach(struct mipi_dsi_host *host,
1308 struct mipi_dsi_device *device)
1310 struct tegra_dsi *dsi = host_to_tegra(host);
1312 dsi->flags = device->mode_flags;
1313 dsi->format = device->format;
1314 dsi->lanes = device->lanes;
1319 dev_dbg(dsi->dev, "attaching dual-channel device %s\n",
1320 dev_name(&device->dev));
1322 err = tegra_dsi_ganged_setup(dsi);
1324 dev_err(dsi->dev, "failed to set up ganged mode: %d\n",
1331 * Slaves don't have a panel associated with them, so they provide
1332 * merely the second channel.
1335 struct tegra_output *output = &dsi->output;
1337 output->panel = of_drm_find_panel(device->dev.of_node);
1338 if (output->panel && output->connector.dev) {
1339 drm_panel_attach(output->panel, &output->connector);
1340 drm_helper_hpd_irq_event(output->connector.dev);
1347 static int tegra_dsi_host_detach(struct mipi_dsi_host *host,
1348 struct mipi_dsi_device *device)
1350 struct tegra_dsi *dsi = host_to_tegra(host);
1351 struct tegra_output *output = &dsi->output;
1353 if (output->panel && &device->dev == output->panel->dev) {
1354 output->panel = NULL;
1356 if (output->connector.dev)
1357 drm_helper_hpd_irq_event(output->connector.dev);
1363 static const struct mipi_dsi_host_ops tegra_dsi_host_ops = {
1364 .attach = tegra_dsi_host_attach,
1365 .detach = tegra_dsi_host_detach,
1366 .transfer = tegra_dsi_host_transfer,
1369 static int tegra_dsi_ganged_probe(struct tegra_dsi *dsi)
1371 struct device_node *np;
1373 np = of_parse_phandle(dsi->dev->of_node, "nvidia,ganged-mode", 0);
1375 struct platform_device *gangster = of_find_device_by_node(np);
1377 dsi->slave = platform_get_drvdata(gangster);
1381 return -EPROBE_DEFER;
1383 dsi->slave->master = dsi;
1389 static int tegra_dsi_probe(struct platform_device *pdev)
1391 struct tegra_dsi *dsi;
1392 struct resource *regs;
1395 dsi = devm_kzalloc(&pdev->dev, sizeof(*dsi), GFP_KERNEL);
1399 dsi->output.dev = dsi->dev = &pdev->dev;
1400 dsi->video_fifo_depth = 1920;
1401 dsi->host_fifo_depth = 64;
1403 err = tegra_dsi_ganged_probe(dsi);
1407 err = tegra_output_probe(&dsi->output);
1411 dsi->output.connector.polled = DRM_CONNECTOR_POLL_HPD;
1414 * Assume these values by default. When a DSI peripheral driver
1415 * attaches to the DSI host, the parameters will be taken from
1416 * the attached device.
1418 dsi->flags = MIPI_DSI_MODE_VIDEO;
1419 dsi->format = MIPI_DSI_FMT_RGB888;
1422 dsi->rst = devm_reset_control_get(&pdev->dev, "dsi");
1423 if (IS_ERR(dsi->rst))
1424 return PTR_ERR(dsi->rst);
1426 err = reset_control_deassert(dsi->rst);
1428 dev_err(&pdev->dev, "failed to bring DSI out of reset: %d\n",
1433 dsi->clk = devm_clk_get(&pdev->dev, NULL);
1434 if (IS_ERR(dsi->clk)) {
1435 dev_err(&pdev->dev, "cannot get DSI clock\n");
1436 err = PTR_ERR(dsi->clk);
1440 err = clk_prepare_enable(dsi->clk);
1442 dev_err(&pdev->dev, "cannot enable DSI clock\n");
1446 dsi->clk_lp = devm_clk_get(&pdev->dev, "lp");
1447 if (IS_ERR(dsi->clk_lp)) {
1448 dev_err(&pdev->dev, "cannot get low-power clock\n");
1449 err = PTR_ERR(dsi->clk_lp);
1453 err = clk_prepare_enable(dsi->clk_lp);
1455 dev_err(&pdev->dev, "cannot enable low-power clock\n");
1459 dsi->clk_parent = devm_clk_get(&pdev->dev, "parent");
1460 if (IS_ERR(dsi->clk_parent)) {
1461 dev_err(&pdev->dev, "cannot get parent clock\n");
1462 err = PTR_ERR(dsi->clk_parent);
1463 goto disable_clk_lp;
1466 dsi->vdd = devm_regulator_get(&pdev->dev, "avdd-dsi-csi");
1467 if (IS_ERR(dsi->vdd)) {
1468 dev_err(&pdev->dev, "cannot get VDD supply\n");
1469 err = PTR_ERR(dsi->vdd);
1470 goto disable_clk_lp;
1473 err = regulator_enable(dsi->vdd);
1475 dev_err(&pdev->dev, "cannot enable VDD supply\n");
1476 goto disable_clk_lp;
1479 err = tegra_dsi_setup_clocks(dsi);
1481 dev_err(&pdev->dev, "cannot setup clocks\n");
1485 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1486 dsi->regs = devm_ioremap_resource(&pdev->dev, regs);
1487 if (IS_ERR(dsi->regs)) {
1488 err = PTR_ERR(dsi->regs);
1492 dsi->mipi = tegra_mipi_request(&pdev->dev);
1493 if (IS_ERR(dsi->mipi)) {
1494 err = PTR_ERR(dsi->mipi);
1498 err = tegra_dsi_pad_calibrate(dsi);
1500 dev_err(dsi->dev, "MIPI calibration failed: %d\n", err);
1504 dsi->host.ops = &tegra_dsi_host_ops;
1505 dsi->host.dev = &pdev->dev;
1507 err = mipi_dsi_host_register(&dsi->host);
1509 dev_err(&pdev->dev, "failed to register DSI host: %d\n", err);
1513 INIT_LIST_HEAD(&dsi->client.list);
1514 dsi->client.ops = &dsi_client_ops;
1515 dsi->client.dev = &pdev->dev;
1517 err = host1x_client_register(&dsi->client);
1519 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1524 platform_set_drvdata(pdev, dsi);
1529 mipi_dsi_host_unregister(&dsi->host);
1531 tegra_mipi_free(dsi->mipi);
1533 regulator_disable(dsi->vdd);
1535 clk_disable_unprepare(dsi->clk_lp);
1537 clk_disable_unprepare(dsi->clk);
1539 reset_control_assert(dsi->rst);
1543 static int tegra_dsi_remove(struct platform_device *pdev)
1545 struct tegra_dsi *dsi = platform_get_drvdata(pdev);
1548 err = host1x_client_unregister(&dsi->client);
1550 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1555 mipi_dsi_host_unregister(&dsi->host);
1556 tegra_mipi_free(dsi->mipi);
1558 regulator_disable(dsi->vdd);
1559 clk_disable_unprepare(dsi->clk_lp);
1560 clk_disable_unprepare(dsi->clk);
1561 reset_control_assert(dsi->rst);
1563 err = tegra_output_remove(&dsi->output);
1565 dev_err(&pdev->dev, "failed to remove output: %d\n", err);
1572 static const struct of_device_id tegra_dsi_of_match[] = {
1573 { .compatible = "nvidia,tegra114-dsi", },
1576 MODULE_DEVICE_TABLE(of, tegra_dsi_of_match);
1578 struct platform_driver tegra_dsi_driver = {
1580 .name = "tegra-dsi",
1581 .of_match_table = tegra_dsi_of_match,
1583 .probe = tegra_dsi_probe,
1584 .remove = tegra_dsi_remove,