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_atomic_helper.h>
21 #include <drm/drm_mipi_dsi.h>
22 #include <drm/drm_panel.h>
24 #include <video/mipi_display.h>
31 struct tegra_dsi_state
{
32 struct drm_connector_state base
;
34 struct mipi_dphy_timing timing
;
37 unsigned int vrefresh
;
42 enum tegra_dsi_format format
;
47 static inline struct tegra_dsi_state
*
48 to_dsi_state(struct drm_connector_state
*state
)
50 return container_of(state
, struct tegra_dsi_state
, base
);
54 struct host1x_client client
;
55 struct tegra_output output
;
60 struct reset_control
*rst
;
61 struct clk
*clk_parent
;
65 struct drm_info_list
*debugfs_files
;
66 struct drm_minor
*minor
;
67 struct dentry
*debugfs
;
70 enum mipi_dsi_pixel_format format
;
73 struct tegra_mipi_device
*mipi
;
74 struct mipi_dsi_host host
;
76 struct regulator
*vdd
;
78 unsigned int video_fifo_depth
;
79 unsigned int host_fifo_depth
;
81 /* for ganged-mode support */
82 struct tegra_dsi
*master
;
83 struct tegra_dsi
*slave
;
86 static inline struct tegra_dsi
*
87 host1x_client_to_dsi(struct host1x_client
*client
)
89 return container_of(client
, struct tegra_dsi
, client
);
92 static inline struct tegra_dsi
*host_to_tegra(struct mipi_dsi_host
*host
)
94 return container_of(host
, struct tegra_dsi
, host
);
97 static inline struct tegra_dsi
*to_dsi(struct tegra_output
*output
)
99 return container_of(output
, struct tegra_dsi
, output
);
102 static struct tegra_dsi_state
*tegra_dsi_get_state(struct tegra_dsi
*dsi
)
104 return to_dsi_state(dsi
->output
.connector
.state
);
107 static inline u32
tegra_dsi_readl(struct tegra_dsi
*dsi
, unsigned long reg
)
109 return readl(dsi
->regs
+ (reg
<< 2));
112 static inline void tegra_dsi_writel(struct tegra_dsi
*dsi
, u32 value
,
115 writel(value
, dsi
->regs
+ (reg
<< 2));
118 static int tegra_dsi_show_regs(struct seq_file
*s
, void *data
)
120 struct drm_info_node
*node
= s
->private;
121 struct tegra_dsi
*dsi
= node
->info_ent
->data
;
122 struct drm_crtc
*crtc
= dsi
->output
.encoder
.crtc
;
123 struct drm_device
*drm
= node
->minor
->dev
;
126 drm_modeset_lock_all(drm
);
128 if (!crtc
|| !crtc
->state
->active
) {
133 #define DUMP_REG(name) \
134 seq_printf(s, "%-32s %#05x %08x\n", #name, name, \
135 tegra_dsi_readl(dsi, name))
137 DUMP_REG(DSI_INCR_SYNCPT
);
138 DUMP_REG(DSI_INCR_SYNCPT_CONTROL
);
139 DUMP_REG(DSI_INCR_SYNCPT_ERROR
);
141 DUMP_REG(DSI_RD_DATA
);
142 DUMP_REG(DSI_WR_DATA
);
143 DUMP_REG(DSI_POWER_CONTROL
);
144 DUMP_REG(DSI_INT_ENABLE
);
145 DUMP_REG(DSI_INT_STATUS
);
146 DUMP_REG(DSI_INT_MASK
);
147 DUMP_REG(DSI_HOST_CONTROL
);
148 DUMP_REG(DSI_CONTROL
);
149 DUMP_REG(DSI_SOL_DELAY
);
150 DUMP_REG(DSI_MAX_THRESHOLD
);
151 DUMP_REG(DSI_TRIGGER
);
152 DUMP_REG(DSI_TX_CRC
);
153 DUMP_REG(DSI_STATUS
);
155 DUMP_REG(DSI_INIT_SEQ_CONTROL
);
156 DUMP_REG(DSI_INIT_SEQ_DATA_0
);
157 DUMP_REG(DSI_INIT_SEQ_DATA_1
);
158 DUMP_REG(DSI_INIT_SEQ_DATA_2
);
159 DUMP_REG(DSI_INIT_SEQ_DATA_3
);
160 DUMP_REG(DSI_INIT_SEQ_DATA_4
);
161 DUMP_REG(DSI_INIT_SEQ_DATA_5
);
162 DUMP_REG(DSI_INIT_SEQ_DATA_6
);
163 DUMP_REG(DSI_INIT_SEQ_DATA_7
);
165 DUMP_REG(DSI_PKT_SEQ_0_LO
);
166 DUMP_REG(DSI_PKT_SEQ_0_HI
);
167 DUMP_REG(DSI_PKT_SEQ_1_LO
);
168 DUMP_REG(DSI_PKT_SEQ_1_HI
);
169 DUMP_REG(DSI_PKT_SEQ_2_LO
);
170 DUMP_REG(DSI_PKT_SEQ_2_HI
);
171 DUMP_REG(DSI_PKT_SEQ_3_LO
);
172 DUMP_REG(DSI_PKT_SEQ_3_HI
);
173 DUMP_REG(DSI_PKT_SEQ_4_LO
);
174 DUMP_REG(DSI_PKT_SEQ_4_HI
);
175 DUMP_REG(DSI_PKT_SEQ_5_LO
);
176 DUMP_REG(DSI_PKT_SEQ_5_HI
);
178 DUMP_REG(DSI_DCS_CMDS
);
180 DUMP_REG(DSI_PKT_LEN_0_1
);
181 DUMP_REG(DSI_PKT_LEN_2_3
);
182 DUMP_REG(DSI_PKT_LEN_4_5
);
183 DUMP_REG(DSI_PKT_LEN_6_7
);
185 DUMP_REG(DSI_PHY_TIMING_0
);
186 DUMP_REG(DSI_PHY_TIMING_1
);
187 DUMP_REG(DSI_PHY_TIMING_2
);
188 DUMP_REG(DSI_BTA_TIMING
);
190 DUMP_REG(DSI_TIMEOUT_0
);
191 DUMP_REG(DSI_TIMEOUT_1
);
192 DUMP_REG(DSI_TO_TALLY
);
194 DUMP_REG(DSI_PAD_CONTROL_0
);
195 DUMP_REG(DSI_PAD_CONTROL_CD
);
196 DUMP_REG(DSI_PAD_CD_STATUS
);
197 DUMP_REG(DSI_VIDEO_MODE_CONTROL
);
198 DUMP_REG(DSI_PAD_CONTROL_1
);
199 DUMP_REG(DSI_PAD_CONTROL_2
);
200 DUMP_REG(DSI_PAD_CONTROL_3
);
201 DUMP_REG(DSI_PAD_CONTROL_4
);
203 DUMP_REG(DSI_GANGED_MODE_CONTROL
);
204 DUMP_REG(DSI_GANGED_MODE_START
);
205 DUMP_REG(DSI_GANGED_MODE_SIZE
);
207 DUMP_REG(DSI_RAW_DATA_BYTE_COUNT
);
208 DUMP_REG(DSI_ULTRA_LOW_POWER_CONTROL
);
210 DUMP_REG(DSI_INIT_SEQ_DATA_8
);
211 DUMP_REG(DSI_INIT_SEQ_DATA_9
);
212 DUMP_REG(DSI_INIT_SEQ_DATA_10
);
213 DUMP_REG(DSI_INIT_SEQ_DATA_11
);
214 DUMP_REG(DSI_INIT_SEQ_DATA_12
);
215 DUMP_REG(DSI_INIT_SEQ_DATA_13
);
216 DUMP_REG(DSI_INIT_SEQ_DATA_14
);
217 DUMP_REG(DSI_INIT_SEQ_DATA_15
);
222 drm_modeset_unlock_all(drm
);
226 static struct drm_info_list debugfs_files
[] = {
227 { "regs", tegra_dsi_show_regs
, 0, NULL
},
230 static int tegra_dsi_debugfs_init(struct tegra_dsi
*dsi
,
231 struct drm_minor
*minor
)
233 const char *name
= dev_name(dsi
->dev
);
237 dsi
->debugfs
= debugfs_create_dir(name
, minor
->debugfs_root
);
241 dsi
->debugfs_files
= kmemdup(debugfs_files
, sizeof(debugfs_files
),
243 if (!dsi
->debugfs_files
) {
248 for (i
= 0; i
< ARRAY_SIZE(debugfs_files
); i
++)
249 dsi
->debugfs_files
[i
].data
= dsi
;
251 err
= drm_debugfs_create_files(dsi
->debugfs_files
,
252 ARRAY_SIZE(debugfs_files
),
253 dsi
->debugfs
, minor
);
262 kfree(dsi
->debugfs_files
);
263 dsi
->debugfs_files
= NULL
;
265 debugfs_remove(dsi
->debugfs
);
271 static void tegra_dsi_debugfs_exit(struct tegra_dsi
*dsi
)
273 drm_debugfs_remove_files(dsi
->debugfs_files
, ARRAY_SIZE(debugfs_files
),
277 kfree(dsi
->debugfs_files
);
278 dsi
->debugfs_files
= NULL
;
280 debugfs_remove(dsi
->debugfs
);
284 #define PKT_ID0(id) ((((id) & 0x3f) << 3) | (1 << 9))
285 #define PKT_LEN0(len) (((len) & 0x07) << 0)
286 #define PKT_ID1(id) ((((id) & 0x3f) << 13) | (1 << 19))
287 #define PKT_LEN1(len) (((len) & 0x07) << 10)
288 #define PKT_ID2(id) ((((id) & 0x3f) << 23) | (1 << 29))
289 #define PKT_LEN2(len) (((len) & 0x07) << 20)
291 #define PKT_LP (1 << 30)
292 #define NUM_PKT_SEQ 12
295 * non-burst mode with sync pulses
297 static const u32 pkt_seq_video_non_burst_sync_pulses
[NUM_PKT_SEQ
] = {
298 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START
) | PKT_LEN0(0) |
299 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
300 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0) |
303 [ 2] = PKT_ID0(MIPI_DSI_V_SYNC_END
) | PKT_LEN0(0) |
304 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
305 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0) |
308 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
309 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
310 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0) |
313 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
314 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
315 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0),
316 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN0(2) |
317 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24
) | PKT_LEN1(3) |
318 PKT_ID2(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN2(4),
319 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
320 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
321 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0) |
324 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
325 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(1) |
326 PKT_ID2(MIPI_DSI_H_SYNC_END
) | PKT_LEN2(0),
327 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN0(2) |
328 PKT_ID1(MIPI_DSI_PACKED_PIXEL_STREAM_24
) | PKT_LEN1(3) |
329 PKT_ID2(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN2(4),
333 * non-burst mode with sync events
335 static const u32 pkt_seq_video_non_burst_sync_events
[NUM_PKT_SEQ
] = {
336 [ 0] = PKT_ID0(MIPI_DSI_V_SYNC_START
) | PKT_LEN0(0) |
337 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION
) | PKT_LEN1(7) |
340 [ 2] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
341 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION
) | PKT_LEN1(7) |
344 [ 4] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
345 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION
) | PKT_LEN1(7) |
348 [ 6] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
349 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(2) |
350 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24
) | PKT_LEN2(3),
351 [ 7] = PKT_ID0(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN0(4),
352 [ 8] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
353 PKT_ID1(MIPI_DSI_END_OF_TRANSMISSION
) | PKT_LEN1(7) |
356 [10] = PKT_ID0(MIPI_DSI_H_SYNC_START
) | PKT_LEN0(0) |
357 PKT_ID1(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN1(2) |
358 PKT_ID2(MIPI_DSI_PACKED_PIXEL_STREAM_24
) | PKT_LEN2(3),
359 [11] = PKT_ID0(MIPI_DSI_BLANKING_PACKET
) | PKT_LEN0(4),
362 static const u32 pkt_seq_command_mode
[NUM_PKT_SEQ
] = {
369 [ 6] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE
) | PKT_LEN0(3) | PKT_LP
,
373 [10] = PKT_ID0(MIPI_DSI_DCS_LONG_WRITE
) | PKT_LEN0(5) | PKT_LP
,
377 static void tegra_dsi_set_phy_timing(struct tegra_dsi
*dsi
,
378 unsigned long period
,
379 const struct mipi_dphy_timing
*timing
)
383 value
= DSI_TIMING_FIELD(timing
->hsexit
, period
, 1) << 24 |
384 DSI_TIMING_FIELD(timing
->hstrail
, period
, 0) << 16 |
385 DSI_TIMING_FIELD(timing
->hszero
, period
, 3) << 8 |
386 DSI_TIMING_FIELD(timing
->hsprepare
, period
, 1);
387 tegra_dsi_writel(dsi
, value
, DSI_PHY_TIMING_0
);
389 value
= DSI_TIMING_FIELD(timing
->clktrail
, period
, 1) << 24 |
390 DSI_TIMING_FIELD(timing
->clkpost
, period
, 1) << 16 |
391 DSI_TIMING_FIELD(timing
->clkzero
, period
, 1) << 8 |
392 DSI_TIMING_FIELD(timing
->lpx
, period
, 1);
393 tegra_dsi_writel(dsi
, value
, DSI_PHY_TIMING_1
);
395 value
= DSI_TIMING_FIELD(timing
->clkprepare
, period
, 1) << 16 |
396 DSI_TIMING_FIELD(timing
->clkpre
, period
, 1) << 8 |
397 DSI_TIMING_FIELD(0xff * period
, period
, 0) << 0;
398 tegra_dsi_writel(dsi
, value
, DSI_PHY_TIMING_2
);
400 value
= DSI_TIMING_FIELD(timing
->taget
, period
, 1) << 16 |
401 DSI_TIMING_FIELD(timing
->tasure
, period
, 1) << 8 |
402 DSI_TIMING_FIELD(timing
->tago
, period
, 1);
403 tegra_dsi_writel(dsi
, value
, DSI_BTA_TIMING
);
406 tegra_dsi_set_phy_timing(dsi
->slave
, period
, timing
);
409 static int tegra_dsi_get_muldiv(enum mipi_dsi_pixel_format format
,
410 unsigned int *mulp
, unsigned int *divp
)
413 case MIPI_DSI_FMT_RGB666_PACKED
:
414 case MIPI_DSI_FMT_RGB888
:
419 case MIPI_DSI_FMT_RGB565
:
424 case MIPI_DSI_FMT_RGB666
:
436 static int tegra_dsi_get_format(enum mipi_dsi_pixel_format format
,
437 enum tegra_dsi_format
*fmt
)
440 case MIPI_DSI_FMT_RGB888
:
441 *fmt
= TEGRA_DSI_FORMAT_24P
;
444 case MIPI_DSI_FMT_RGB666
:
445 *fmt
= TEGRA_DSI_FORMAT_18NP
;
448 case MIPI_DSI_FMT_RGB666_PACKED
:
449 *fmt
= TEGRA_DSI_FORMAT_18P
;
452 case MIPI_DSI_FMT_RGB565
:
453 *fmt
= TEGRA_DSI_FORMAT_16P
;
463 static void tegra_dsi_ganged_enable(struct tegra_dsi
*dsi
, unsigned int start
,
468 tegra_dsi_writel(dsi
, start
, DSI_GANGED_MODE_START
);
469 tegra_dsi_writel(dsi
, size
<< 16 | size
, DSI_GANGED_MODE_SIZE
);
471 value
= DSI_GANGED_MODE_CONTROL_ENABLE
;
472 tegra_dsi_writel(dsi
, value
, DSI_GANGED_MODE_CONTROL
);
475 static void tegra_dsi_enable(struct tegra_dsi
*dsi
)
479 value
= tegra_dsi_readl(dsi
, DSI_POWER_CONTROL
);
480 value
|= DSI_POWER_CONTROL_ENABLE
;
481 tegra_dsi_writel(dsi
, value
, DSI_POWER_CONTROL
);
484 tegra_dsi_enable(dsi
->slave
);
487 static unsigned int tegra_dsi_get_lanes(struct tegra_dsi
*dsi
)
490 return dsi
->master
->lanes
+ dsi
->lanes
;
493 return dsi
->lanes
+ dsi
->slave
->lanes
;
498 static void tegra_dsi_configure(struct tegra_dsi
*dsi
, unsigned int pipe
,
499 const struct drm_display_mode
*mode
)
501 unsigned int hact
, hsw
, hbp
, hfp
, i
, mul
, div
;
502 struct tegra_dsi_state
*state
;
506 /* XXX: pass in state into this function? */
508 state
= tegra_dsi_get_state(dsi
->master
);
510 state
= tegra_dsi_get_state(dsi
);
515 if (dsi
->flags
& MIPI_DSI_MODE_VIDEO_SYNC_PULSE
) {
516 DRM_DEBUG_KMS("Non-burst video mode with sync pulses\n");
517 pkt_seq
= pkt_seq_video_non_burst_sync_pulses
;
518 } else if (dsi
->flags
& MIPI_DSI_MODE_VIDEO
) {
519 DRM_DEBUG_KMS("Non-burst video mode with sync events\n");
520 pkt_seq
= pkt_seq_video_non_burst_sync_events
;
522 DRM_DEBUG_KMS("Command mode\n");
523 pkt_seq
= pkt_seq_command_mode
;
526 value
= DSI_CONTROL_CHANNEL(0) |
527 DSI_CONTROL_FORMAT(state
->format
) |
528 DSI_CONTROL_LANES(dsi
->lanes
- 1) |
529 DSI_CONTROL_SOURCE(pipe
);
530 tegra_dsi_writel(dsi
, value
, DSI_CONTROL
);
532 tegra_dsi_writel(dsi
, dsi
->video_fifo_depth
, DSI_MAX_THRESHOLD
);
534 value
= DSI_HOST_CONTROL_HS
;
535 tegra_dsi_writel(dsi
, value
, DSI_HOST_CONTROL
);
537 value
= tegra_dsi_readl(dsi
, DSI_CONTROL
);
539 if (dsi
->flags
& MIPI_DSI_CLOCK_NON_CONTINUOUS
)
540 value
|= DSI_CONTROL_HS_CLK_CTRL
;
542 value
&= ~DSI_CONTROL_TX_TRIG(3);
544 /* enable DCS commands for command mode */
545 if (dsi
->flags
& MIPI_DSI_MODE_VIDEO
)
546 value
&= ~DSI_CONTROL_DCS_ENABLE
;
548 value
|= DSI_CONTROL_DCS_ENABLE
;
550 value
|= DSI_CONTROL_VIDEO_ENABLE
;
551 value
&= ~DSI_CONTROL_HOST_ENABLE
;
552 tegra_dsi_writel(dsi
, value
, DSI_CONTROL
);
554 for (i
= 0; i
< NUM_PKT_SEQ
; i
++)
555 tegra_dsi_writel(dsi
, pkt_seq
[i
], DSI_PKT_SEQ_0_LO
+ i
);
557 if (dsi
->flags
& MIPI_DSI_MODE_VIDEO
) {
558 /* horizontal active pixels */
559 hact
= mode
->hdisplay
* mul
/ div
;
561 /* horizontal sync width */
562 hsw
= (mode
->hsync_end
- mode
->hsync_start
) * mul
/ div
;
564 /* horizontal back porch */
565 hbp
= (mode
->htotal
- mode
->hsync_end
) * mul
/ div
;
567 if ((dsi
->flags
& MIPI_DSI_MODE_VIDEO_SYNC_PULSE
) == 0)
570 /* horizontal front porch */
571 hfp
= (mode
->hsync_start
- mode
->hdisplay
) * mul
/ div
;
573 /* subtract packet overhead */
578 tegra_dsi_writel(dsi
, hsw
<< 16 | 0, DSI_PKT_LEN_0_1
);
579 tegra_dsi_writel(dsi
, hact
<< 16 | hbp
, DSI_PKT_LEN_2_3
);
580 tegra_dsi_writel(dsi
, hfp
, DSI_PKT_LEN_4_5
);
581 tegra_dsi_writel(dsi
, 0x0f0f << 16, DSI_PKT_LEN_6_7
);
583 /* set SOL delay (for non-burst mode only) */
584 tegra_dsi_writel(dsi
, 8 * mul
/ div
, DSI_SOL_DELAY
);
586 /* TODO: implement ganged mode */
590 if (dsi
->master
|| dsi
->slave
) {
592 * For ganged mode, assume symmetric left-right mode.
594 bytes
= 1 + (mode
->hdisplay
/ 2) * mul
/ div
;
596 /* 1 byte (DCS command) + pixel data */
597 bytes
= 1 + mode
->hdisplay
* mul
/ div
;
600 tegra_dsi_writel(dsi
, 0, DSI_PKT_LEN_0_1
);
601 tegra_dsi_writel(dsi
, bytes
<< 16, DSI_PKT_LEN_2_3
);
602 tegra_dsi_writel(dsi
, bytes
<< 16, DSI_PKT_LEN_4_5
);
603 tegra_dsi_writel(dsi
, 0, DSI_PKT_LEN_6_7
);
605 value
= MIPI_DCS_WRITE_MEMORY_START
<< 8 |
606 MIPI_DCS_WRITE_MEMORY_CONTINUE
;
607 tegra_dsi_writel(dsi
, value
, DSI_DCS_CMDS
);
610 if (dsi
->master
|| dsi
->slave
) {
611 unsigned long delay
, bclk
, bclk_ganged
;
612 unsigned int lanes
= state
->lanes
;
614 /* SOL to valid, valid to FIFO and FIFO write delay */
616 delay
= DIV_ROUND_UP(delay
* mul
, div
* lanes
);
617 /* FIFO read delay */
620 bclk
= DIV_ROUND_UP(mode
->htotal
* mul
, div
* lanes
);
621 bclk_ganged
= DIV_ROUND_UP(bclk
* lanes
/ 2, lanes
);
622 value
= bclk
- bclk_ganged
+ delay
+ 20;
624 /* TODO: revisit for non-ganged mode */
625 value
= 8 * mul
/ div
;
628 tegra_dsi_writel(dsi
, value
, DSI_SOL_DELAY
);
632 tegra_dsi_configure(dsi
->slave
, pipe
, mode
);
635 * TODO: Support modes other than symmetrical left-right
638 tegra_dsi_ganged_enable(dsi
, 0, mode
->hdisplay
/ 2);
639 tegra_dsi_ganged_enable(dsi
->slave
, mode
->hdisplay
/ 2,
644 static int tegra_dsi_wait_idle(struct tegra_dsi
*dsi
, unsigned long timeout
)
648 timeout
= jiffies
+ msecs_to_jiffies(timeout
);
650 while (time_before(jiffies
, timeout
)) {
651 value
= tegra_dsi_readl(dsi
, DSI_STATUS
);
652 if (value
& DSI_STATUS_IDLE
)
655 usleep_range(1000, 2000);
661 static void tegra_dsi_video_disable(struct tegra_dsi
*dsi
)
665 value
= tegra_dsi_readl(dsi
, DSI_CONTROL
);
666 value
&= ~DSI_CONTROL_VIDEO_ENABLE
;
667 tegra_dsi_writel(dsi
, value
, DSI_CONTROL
);
670 tegra_dsi_video_disable(dsi
->slave
);
673 static void tegra_dsi_ganged_disable(struct tegra_dsi
*dsi
)
675 tegra_dsi_writel(dsi
, 0, DSI_GANGED_MODE_START
);
676 tegra_dsi_writel(dsi
, 0, DSI_GANGED_MODE_SIZE
);
677 tegra_dsi_writel(dsi
, 0, DSI_GANGED_MODE_CONTROL
);
680 static void tegra_dsi_set_timeout(struct tegra_dsi
*dsi
, unsigned long bclk
,
681 unsigned int vrefresh
)
683 unsigned int timeout
;
686 /* one frame high-speed transmission timeout */
687 timeout
= (bclk
/ vrefresh
) / 512;
688 value
= DSI_TIMEOUT_LRX(0x2000) | DSI_TIMEOUT_HTX(timeout
);
689 tegra_dsi_writel(dsi
, value
, DSI_TIMEOUT_0
);
691 /* 2 ms peripheral timeout for panel */
692 timeout
= 2 * bclk
/ 512 * 1000;
693 value
= DSI_TIMEOUT_PR(timeout
) | DSI_TIMEOUT_TA(0x2000);
694 tegra_dsi_writel(dsi
, value
, DSI_TIMEOUT_1
);
696 value
= DSI_TALLY_TA(0) | DSI_TALLY_LRX(0) | DSI_TALLY_HTX(0);
697 tegra_dsi_writel(dsi
, value
, DSI_TO_TALLY
);
700 tegra_dsi_set_timeout(dsi
->slave
, bclk
, vrefresh
);
703 static void tegra_dsi_disable(struct tegra_dsi
*dsi
)
708 tegra_dsi_ganged_disable(dsi
->slave
);
709 tegra_dsi_ganged_disable(dsi
);
712 value
= tegra_dsi_readl(dsi
, DSI_POWER_CONTROL
);
713 value
&= ~DSI_POWER_CONTROL_ENABLE
;
714 tegra_dsi_writel(dsi
, value
, DSI_POWER_CONTROL
);
717 tegra_dsi_disable(dsi
->slave
);
719 usleep_range(5000, 10000);
722 static void tegra_dsi_soft_reset(struct tegra_dsi
*dsi
)
726 value
= tegra_dsi_readl(dsi
, DSI_POWER_CONTROL
);
727 value
&= ~DSI_POWER_CONTROL_ENABLE
;
728 tegra_dsi_writel(dsi
, value
, DSI_POWER_CONTROL
);
730 usleep_range(300, 1000);
732 value
= tegra_dsi_readl(dsi
, DSI_POWER_CONTROL
);
733 value
|= DSI_POWER_CONTROL_ENABLE
;
734 tegra_dsi_writel(dsi
, value
, DSI_POWER_CONTROL
);
736 usleep_range(300, 1000);
738 value
= tegra_dsi_readl(dsi
, DSI_TRIGGER
);
740 tegra_dsi_writel(dsi
, 0, DSI_TRIGGER
);
743 tegra_dsi_soft_reset(dsi
->slave
);
746 static void tegra_dsi_connector_reset(struct drm_connector
*connector
)
748 struct tegra_dsi_state
*state
;
750 kfree(connector
->state
);
751 connector
->state
= NULL
;
753 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
755 connector
->state
= &state
->base
;
758 static struct drm_connector_state
*
759 tegra_dsi_connector_duplicate_state(struct drm_connector
*connector
)
761 struct tegra_dsi_state
*state
= to_dsi_state(connector
->state
);
762 struct tegra_dsi_state
*copy
;
764 copy
= kmemdup(state
, sizeof(*state
), GFP_KERNEL
);
771 static const struct drm_connector_funcs tegra_dsi_connector_funcs
= {
772 .dpms
= drm_atomic_helper_connector_dpms
,
773 .reset
= tegra_dsi_connector_reset
,
774 .detect
= tegra_output_connector_detect
,
775 .fill_modes
= drm_helper_probe_single_connector_modes
,
776 .destroy
= tegra_output_connector_destroy
,
777 .atomic_duplicate_state
= tegra_dsi_connector_duplicate_state
,
778 .atomic_destroy_state
= drm_atomic_helper_connector_destroy_state
,
781 static enum drm_mode_status
782 tegra_dsi_connector_mode_valid(struct drm_connector
*connector
,
783 struct drm_display_mode
*mode
)
788 static const struct drm_connector_helper_funcs tegra_dsi_connector_helper_funcs
= {
789 .get_modes
= tegra_output_connector_get_modes
,
790 .mode_valid
= tegra_dsi_connector_mode_valid
,
791 .best_encoder
= tegra_output_connector_best_encoder
,
794 static const struct drm_encoder_funcs tegra_dsi_encoder_funcs
= {
795 .destroy
= tegra_output_encoder_destroy
,
798 static void tegra_dsi_encoder_disable(struct drm_encoder
*encoder
)
800 struct tegra_output
*output
= encoder_to_output(encoder
);
801 struct tegra_dc
*dc
= to_tegra_dc(encoder
->crtc
);
802 struct tegra_dsi
*dsi
= to_dsi(output
);
807 drm_panel_disable(output
->panel
);
809 tegra_dsi_video_disable(dsi
);
812 * The following accesses registers of the display controller, so make
813 * sure it's only executed when the output is attached to one.
816 value
= tegra_dc_readl(dc
, DC_DISP_DISP_WIN_OPTIONS
);
817 value
&= ~DSI_ENABLE
;
818 tegra_dc_writel(dc
, value
, DC_DISP_DISP_WIN_OPTIONS
);
823 err
= tegra_dsi_wait_idle(dsi
, 100);
825 dev_dbg(dsi
->dev
, "failed to idle DSI: %d\n", err
);
827 tegra_dsi_soft_reset(dsi
);
830 drm_panel_unprepare(output
->panel
);
832 tegra_dsi_disable(dsi
);
837 static void tegra_dsi_encoder_enable(struct drm_encoder
*encoder
)
839 struct drm_display_mode
*mode
= &encoder
->crtc
->state
->adjusted_mode
;
840 struct tegra_output
*output
= encoder_to_output(encoder
);
841 struct tegra_dc
*dc
= to_tegra_dc(encoder
->crtc
);
842 struct tegra_dsi
*dsi
= to_dsi(output
);
843 struct tegra_dsi_state
*state
;
846 state
= tegra_dsi_get_state(dsi
);
848 tegra_dsi_set_timeout(dsi
, state
->bclk
, state
->vrefresh
);
851 * The D-PHY timing fields are expressed in byte-clock cycles, so
852 * multiply the period by 8.
854 tegra_dsi_set_phy_timing(dsi
, state
->period
* 8, &state
->timing
);
857 drm_panel_prepare(output
->panel
);
859 tegra_dsi_configure(dsi
, dc
->pipe
, mode
);
861 /* enable display controller */
862 value
= tegra_dc_readl(dc
, DC_DISP_DISP_WIN_OPTIONS
);
864 tegra_dc_writel(dc
, value
, DC_DISP_DISP_WIN_OPTIONS
);
868 /* enable DSI controller */
869 tegra_dsi_enable(dsi
);
872 drm_panel_enable(output
->panel
);
878 tegra_dsi_encoder_atomic_check(struct drm_encoder
*encoder
,
879 struct drm_crtc_state
*crtc_state
,
880 struct drm_connector_state
*conn_state
)
882 struct tegra_output
*output
= encoder_to_output(encoder
);
883 struct tegra_dsi_state
*state
= to_dsi_state(conn_state
);
884 struct tegra_dc
*dc
= to_tegra_dc(conn_state
->crtc
);
885 struct tegra_dsi
*dsi
= to_dsi(output
);
890 state
->pclk
= crtc_state
->mode
.clock
* 1000;
892 err
= tegra_dsi_get_muldiv(dsi
->format
, &state
->mul
, &state
->div
);
896 state
->lanes
= tegra_dsi_get_lanes(dsi
);
898 err
= tegra_dsi_get_format(dsi
->format
, &state
->format
);
902 state
->vrefresh
= drm_mode_vrefresh(&crtc_state
->mode
);
904 /* compute byte clock */
905 state
->bclk
= (state
->pclk
* state
->mul
) / (state
->div
* state
->lanes
);
907 DRM_DEBUG_KMS("mul: %u, div: %u, lanes: %u\n", state
->mul
, state
->div
,
909 DRM_DEBUG_KMS("format: %u, vrefresh: %u\n", state
->format
,
911 DRM_DEBUG_KMS("bclk: %lu\n", state
->bclk
);
914 * Compute bit clock and round up to the next MHz.
916 plld
= DIV_ROUND_UP(state
->bclk
* 8, USEC_PER_SEC
) * USEC_PER_SEC
;
917 state
->period
= DIV_ROUND_CLOSEST(NSEC_PER_SEC
, plld
);
919 err
= mipi_dphy_timing_get_default(&state
->timing
, state
->period
);
923 err
= mipi_dphy_timing_validate(&state
->timing
, state
->period
);
925 dev_err(dsi
->dev
, "failed to validate D-PHY timing: %d\n", err
);
930 * We divide the frequency by two here, but we make up for that by
931 * setting the shift clock divider (further below) to half of the
937 * Derive pixel clock from bit clock using the shift clock divider.
938 * Note that this is only half of what we would expect, but we need
939 * that to make up for the fact that we divided the bit clock by a
940 * factor of two above.
942 * It's not clear exactly why this is necessary, but the display is
943 * not working properly otherwise. Perhaps the PLLs cannot generate
944 * frequencies sufficiently high.
946 scdiv
= ((8 * state
->mul
) / (state
->div
* state
->lanes
)) - 2;
948 err
= tegra_dc_state_setup_clock(dc
, crtc_state
, dsi
->clk_parent
,
951 dev_err(output
->dev
, "failed to setup CRTC state: %d\n", err
);
958 static const struct drm_encoder_helper_funcs tegra_dsi_encoder_helper_funcs
= {
959 .disable
= tegra_dsi_encoder_disable
,
960 .enable
= tegra_dsi_encoder_enable
,
961 .atomic_check
= tegra_dsi_encoder_atomic_check
,
964 static int tegra_dsi_pad_enable(struct tegra_dsi
*dsi
)
968 value
= DSI_PAD_CONTROL_VS1_PULLDN(0) | DSI_PAD_CONTROL_VS1_PDIO(0);
969 tegra_dsi_writel(dsi
, value
, DSI_PAD_CONTROL_0
);
974 static int tegra_dsi_pad_calibrate(struct tegra_dsi
*dsi
)
978 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_0
);
979 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_1
);
980 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_2
);
981 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_3
);
982 tegra_dsi_writel(dsi
, 0, DSI_PAD_CONTROL_4
);
984 /* start calibration */
985 tegra_dsi_pad_enable(dsi
);
987 value
= DSI_PAD_SLEW_UP(0x7) | DSI_PAD_SLEW_DN(0x7) |
988 DSI_PAD_LP_UP(0x1) | DSI_PAD_LP_DN(0x1) |
989 DSI_PAD_OUT_CLK(0x0);
990 tegra_dsi_writel(dsi
, value
, DSI_PAD_CONTROL_2
);
992 value
= DSI_PAD_PREEMP_PD_CLK(0x3) | DSI_PAD_PREEMP_PU_CLK(0x3) |
993 DSI_PAD_PREEMP_PD(0x03) | DSI_PAD_PREEMP_PU(0x3);
994 tegra_dsi_writel(dsi
, value
, DSI_PAD_CONTROL_3
);
996 return tegra_mipi_calibrate(dsi
->mipi
);
999 static int tegra_dsi_init(struct host1x_client
*client
)
1001 struct drm_device
*drm
= dev_get_drvdata(client
->parent
);
1002 struct tegra_dsi
*dsi
= host1x_client_to_dsi(client
);
1005 reset_control_deassert(dsi
->rst
);
1007 err
= tegra_dsi_pad_calibrate(dsi
);
1009 dev_err(dsi
->dev
, "MIPI calibration failed: %d\n", err
);
1013 /* Gangsters must not register their own outputs. */
1015 dsi
->output
.dev
= client
->dev
;
1017 drm_connector_init(drm
, &dsi
->output
.connector
,
1018 &tegra_dsi_connector_funcs
,
1019 DRM_MODE_CONNECTOR_DSI
);
1020 drm_connector_helper_add(&dsi
->output
.connector
,
1021 &tegra_dsi_connector_helper_funcs
);
1022 dsi
->output
.connector
.dpms
= DRM_MODE_DPMS_OFF
;
1024 drm_encoder_init(drm
, &dsi
->output
.encoder
,
1025 &tegra_dsi_encoder_funcs
,
1026 DRM_MODE_ENCODER_DSI
);
1027 drm_encoder_helper_add(&dsi
->output
.encoder
,
1028 &tegra_dsi_encoder_helper_funcs
);
1030 drm_mode_connector_attach_encoder(&dsi
->output
.connector
,
1031 &dsi
->output
.encoder
);
1032 drm_connector_register(&dsi
->output
.connector
);
1034 err
= tegra_output_init(drm
, &dsi
->output
);
1036 dev_err(client
->dev
,
1037 "failed to initialize output: %d\n",
1042 dsi
->output
.encoder
.possible_crtcs
= 0x3;
1045 if (IS_ENABLED(CONFIG_DEBUG_FS
)) {
1046 err
= tegra_dsi_debugfs_init(dsi
, drm
->primary
);
1048 dev_err(dsi
->dev
, "debugfs setup failed: %d\n", err
);
1054 reset_control_assert(dsi
->rst
);
1058 static int tegra_dsi_exit(struct host1x_client
*client
)
1060 struct tegra_dsi
*dsi
= host1x_client_to_dsi(client
);
1062 tegra_output_exit(&dsi
->output
);
1064 if (IS_ENABLED(CONFIG_DEBUG_FS
))
1065 tegra_dsi_debugfs_exit(dsi
);
1067 reset_control_assert(dsi
->rst
);
1072 static const struct host1x_client_ops dsi_client_ops
= {
1073 .init
= tegra_dsi_init
,
1074 .exit
= tegra_dsi_exit
,
1077 static int tegra_dsi_setup_clocks(struct tegra_dsi
*dsi
)
1082 parent
= clk_get_parent(dsi
->clk
);
1086 err
= clk_set_parent(parent
, dsi
->clk_parent
);
1093 static const char * const error_report
[16] = {
1097 "Escape Mode Entry Command Error",
1098 "Low-Power Transmit Sync Error",
1099 "Peripheral Timeout Error",
1100 "False Control Error",
1101 "Contention Detected",
1102 "ECC Error, single-bit",
1103 "ECC Error, multi-bit",
1105 "DSI Data Type Not Recognized",
1106 "DSI VC ID Invalid",
1107 "Invalid Transmission Length",
1109 "DSI Protocol Violation",
1112 static ssize_t
tegra_dsi_read_response(struct tegra_dsi
*dsi
,
1113 const struct mipi_dsi_msg
*msg
,
1116 u8
*rx
= msg
->rx_buf
;
1117 unsigned int i
, j
, k
;
1122 /* read and parse packet header */
1123 value
= tegra_dsi_readl(dsi
, DSI_RD_DATA
);
1125 switch (value
& 0x3f) {
1126 case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT
:
1127 errors
= (value
>> 8) & 0xffff;
1128 dev_dbg(dsi
->dev
, "Acknowledge and error report: %04x\n",
1130 for (i
= 0; i
< ARRAY_SIZE(error_report
); i
++)
1131 if (errors
& BIT(i
))
1132 dev_dbg(dsi
->dev
, " %2u: %s\n", i
,
1136 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE
:
1137 rx
[0] = (value
>> 8) & 0xff;
1141 case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE
:
1142 rx
[0] = (value
>> 8) & 0xff;
1143 rx
[1] = (value
>> 16) & 0xff;
1147 case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE
:
1148 size
= ((value
>> 8) & 0xff00) | ((value
>> 8) & 0xff);
1151 case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE
:
1152 size
= ((value
>> 8) & 0xff00) | ((value
>> 8) & 0xff);
1156 dev_err(dsi
->dev
, "unhandled response type: %02x\n",
1161 size
= min(size
, msg
->rx_len
);
1163 if (msg
->rx_buf
&& size
> 0) {
1164 for (i
= 0, j
= 0; i
< count
- 1; i
++, j
+= 4) {
1165 u8
*rx
= msg
->rx_buf
+ j
;
1167 value
= tegra_dsi_readl(dsi
, DSI_RD_DATA
);
1169 for (k
= 0; k
< 4 && (j
+ k
) < msg
->rx_len
; k
++)
1170 rx
[j
+ k
] = (value
>> (k
<< 3)) & 0xff;
1177 static int tegra_dsi_transmit(struct tegra_dsi
*dsi
, unsigned long timeout
)
1179 tegra_dsi_writel(dsi
, DSI_TRIGGER_HOST
, DSI_TRIGGER
);
1181 timeout
= jiffies
+ msecs_to_jiffies(timeout
);
1183 while (time_before(jiffies
, timeout
)) {
1184 u32 value
= tegra_dsi_readl(dsi
, DSI_TRIGGER
);
1185 if ((value
& DSI_TRIGGER_HOST
) == 0)
1188 usleep_range(1000, 2000);
1191 DRM_DEBUG_KMS("timeout waiting for transmission to complete\n");
1195 static int tegra_dsi_wait_for_response(struct tegra_dsi
*dsi
,
1196 unsigned long timeout
)
1198 timeout
= jiffies
+ msecs_to_jiffies(250);
1200 while (time_before(jiffies
, timeout
)) {
1201 u32 value
= tegra_dsi_readl(dsi
, DSI_STATUS
);
1202 u8 count
= value
& 0x1f;
1207 usleep_range(1000, 2000);
1210 DRM_DEBUG_KMS("peripheral returned no data\n");
1214 static void tegra_dsi_writesl(struct tegra_dsi
*dsi
, unsigned long offset
,
1215 const void *buffer
, size_t size
)
1217 const u8
*buf
= buffer
;
1221 for (j
= 0; j
< size
; j
+= 4) {
1224 for (i
= 0; i
< 4 && j
+ i
< size
; i
++)
1225 value
|= buf
[j
+ i
] << (i
<< 3);
1227 tegra_dsi_writel(dsi
, value
, DSI_WR_DATA
);
1231 static ssize_t
tegra_dsi_host_transfer(struct mipi_dsi_host
*host
,
1232 const struct mipi_dsi_msg
*msg
)
1234 struct tegra_dsi
*dsi
= host_to_tegra(host
);
1235 struct mipi_dsi_packet packet
;
1241 err
= mipi_dsi_create_packet(&packet
, msg
);
1245 header
= packet
.header
;
1247 /* maximum FIFO depth is 1920 words */
1248 if (packet
.size
> dsi
->video_fifo_depth
* 4)
1251 /* reset underflow/overflow flags */
1252 value
= tegra_dsi_readl(dsi
, DSI_STATUS
);
1253 if (value
& (DSI_STATUS_UNDERFLOW
| DSI_STATUS_OVERFLOW
)) {
1254 value
= DSI_HOST_CONTROL_FIFO_RESET
;
1255 tegra_dsi_writel(dsi
, value
, DSI_HOST_CONTROL
);
1256 usleep_range(10, 20);
1259 value
= tegra_dsi_readl(dsi
, DSI_POWER_CONTROL
);
1260 value
|= DSI_POWER_CONTROL_ENABLE
;
1261 tegra_dsi_writel(dsi
, value
, DSI_POWER_CONTROL
);
1263 usleep_range(5000, 10000);
1265 value
= DSI_HOST_CONTROL_CRC_RESET
| DSI_HOST_CONTROL_TX_TRIG_HOST
|
1266 DSI_HOST_CONTROL_CS
| DSI_HOST_CONTROL_ECC
;
1268 if ((msg
->flags
& MIPI_DSI_MSG_USE_LPM
) == 0)
1269 value
|= DSI_HOST_CONTROL_HS
;
1272 * The host FIFO has a maximum of 64 words, so larger transmissions
1273 * need to use the video FIFO.
1275 if (packet
.size
> dsi
->host_fifo_depth
* 4)
1276 value
|= DSI_HOST_CONTROL_FIFO_SEL
;
1278 tegra_dsi_writel(dsi
, value
, DSI_HOST_CONTROL
);
1281 * For reads and messages with explicitly requested ACK, generate a
1282 * BTA sequence after the transmission of the packet.
1284 if ((msg
->flags
& MIPI_DSI_MSG_REQ_ACK
) ||
1285 (msg
->rx_buf
&& msg
->rx_len
> 0)) {
1286 value
= tegra_dsi_readl(dsi
, DSI_HOST_CONTROL
);
1287 value
|= DSI_HOST_CONTROL_PKT_BTA
;
1288 tegra_dsi_writel(dsi
, value
, DSI_HOST_CONTROL
);
1291 value
= DSI_CONTROL_LANES(0) | DSI_CONTROL_HOST_ENABLE
;
1292 tegra_dsi_writel(dsi
, value
, DSI_CONTROL
);
1294 /* write packet header, ECC is generated by hardware */
1295 value
= header
[2] << 16 | header
[1] << 8 | header
[0];
1296 tegra_dsi_writel(dsi
, value
, DSI_WR_DATA
);
1298 /* write payload (if any) */
1299 if (packet
.payload_length
> 0)
1300 tegra_dsi_writesl(dsi
, DSI_WR_DATA
, packet
.payload
,
1301 packet
.payload_length
);
1303 err
= tegra_dsi_transmit(dsi
, 250);
1307 if ((msg
->flags
& MIPI_DSI_MSG_REQ_ACK
) ||
1308 (msg
->rx_buf
&& msg
->rx_len
> 0)) {
1309 err
= tegra_dsi_wait_for_response(dsi
, 250);
1315 value
= tegra_dsi_readl(dsi
, DSI_RD_DATA
);
1319 dev_dbg(dsi->dev, "ACK\n");
1325 dev_dbg(dsi->dev, "ESCAPE\n");
1330 dev_err(dsi
->dev
, "unknown status: %08x\n", value
);
1335 err
= tegra_dsi_read_response(dsi
, msg
, count
);
1338 "failed to parse response: %zd\n",
1342 * For read commands, return the number of
1343 * bytes returned by the peripheral.
1350 * For write commands, we have transmitted the 4-byte header
1351 * plus the variable-length payload.
1353 count
= 4 + packet
.payload_length
;
1359 static int tegra_dsi_ganged_setup(struct tegra_dsi
*dsi
)
1364 /* make sure both DSI controllers share the same PLL */
1365 parent
= clk_get_parent(dsi
->slave
->clk
);
1369 err
= clk_set_parent(parent
, dsi
->clk_parent
);
1376 static int tegra_dsi_host_attach(struct mipi_dsi_host
*host
,
1377 struct mipi_dsi_device
*device
)
1379 struct tegra_dsi
*dsi
= host_to_tegra(host
);
1381 dsi
->flags
= device
->mode_flags
;
1382 dsi
->format
= device
->format
;
1383 dsi
->lanes
= device
->lanes
;
1388 dev_dbg(dsi
->dev
, "attaching dual-channel device %s\n",
1389 dev_name(&device
->dev
));
1391 err
= tegra_dsi_ganged_setup(dsi
);
1393 dev_err(dsi
->dev
, "failed to set up ganged mode: %d\n",
1400 * Slaves don't have a panel associated with them, so they provide
1401 * merely the second channel.
1404 struct tegra_output
*output
= &dsi
->output
;
1406 output
->panel
= of_drm_find_panel(device
->dev
.of_node
);
1407 if (output
->panel
&& output
->connector
.dev
) {
1408 drm_panel_attach(output
->panel
, &output
->connector
);
1409 drm_helper_hpd_irq_event(output
->connector
.dev
);
1416 static int tegra_dsi_host_detach(struct mipi_dsi_host
*host
,
1417 struct mipi_dsi_device
*device
)
1419 struct tegra_dsi
*dsi
= host_to_tegra(host
);
1420 struct tegra_output
*output
= &dsi
->output
;
1422 if (output
->panel
&& &device
->dev
== output
->panel
->dev
) {
1423 output
->panel
= NULL
;
1425 if (output
->connector
.dev
)
1426 drm_helper_hpd_irq_event(output
->connector
.dev
);
1432 static const struct mipi_dsi_host_ops tegra_dsi_host_ops
= {
1433 .attach
= tegra_dsi_host_attach
,
1434 .detach
= tegra_dsi_host_detach
,
1435 .transfer
= tegra_dsi_host_transfer
,
1438 static int tegra_dsi_ganged_probe(struct tegra_dsi
*dsi
)
1440 struct device_node
*np
;
1442 np
= of_parse_phandle(dsi
->dev
->of_node
, "nvidia,ganged-mode", 0);
1444 struct platform_device
*gangster
= of_find_device_by_node(np
);
1446 dsi
->slave
= platform_get_drvdata(gangster
);
1450 return -EPROBE_DEFER
;
1452 dsi
->slave
->master
= dsi
;
1458 static int tegra_dsi_probe(struct platform_device
*pdev
)
1460 struct tegra_dsi
*dsi
;
1461 struct resource
*regs
;
1464 dsi
= devm_kzalloc(&pdev
->dev
, sizeof(*dsi
), GFP_KERNEL
);
1468 dsi
->output
.dev
= dsi
->dev
= &pdev
->dev
;
1469 dsi
->video_fifo_depth
= 1920;
1470 dsi
->host_fifo_depth
= 64;
1472 err
= tegra_dsi_ganged_probe(dsi
);
1476 err
= tegra_output_probe(&dsi
->output
);
1480 dsi
->output
.connector
.polled
= DRM_CONNECTOR_POLL_HPD
;
1483 * Assume these values by default. When a DSI peripheral driver
1484 * attaches to the DSI host, the parameters will be taken from
1485 * the attached device.
1487 dsi
->flags
= MIPI_DSI_MODE_VIDEO
;
1488 dsi
->format
= MIPI_DSI_FMT_RGB888
;
1491 dsi
->rst
= devm_reset_control_get(&pdev
->dev
, "dsi");
1492 if (IS_ERR(dsi
->rst
))
1493 return PTR_ERR(dsi
->rst
);
1495 dsi
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
1496 if (IS_ERR(dsi
->clk
)) {
1497 dev_err(&pdev
->dev
, "cannot get DSI clock\n");
1498 err
= PTR_ERR(dsi
->clk
);
1502 err
= clk_prepare_enable(dsi
->clk
);
1504 dev_err(&pdev
->dev
, "cannot enable DSI clock\n");
1508 dsi
->clk_lp
= devm_clk_get(&pdev
->dev
, "lp");
1509 if (IS_ERR(dsi
->clk_lp
)) {
1510 dev_err(&pdev
->dev
, "cannot get low-power clock\n");
1511 err
= PTR_ERR(dsi
->clk_lp
);
1515 err
= clk_prepare_enable(dsi
->clk_lp
);
1517 dev_err(&pdev
->dev
, "cannot enable low-power clock\n");
1521 dsi
->clk_parent
= devm_clk_get(&pdev
->dev
, "parent");
1522 if (IS_ERR(dsi
->clk_parent
)) {
1523 dev_err(&pdev
->dev
, "cannot get parent clock\n");
1524 err
= PTR_ERR(dsi
->clk_parent
);
1525 goto disable_clk_lp
;
1528 dsi
->vdd
= devm_regulator_get(&pdev
->dev
, "avdd-dsi-csi");
1529 if (IS_ERR(dsi
->vdd
)) {
1530 dev_err(&pdev
->dev
, "cannot get VDD supply\n");
1531 err
= PTR_ERR(dsi
->vdd
);
1532 goto disable_clk_lp
;
1535 err
= regulator_enable(dsi
->vdd
);
1537 dev_err(&pdev
->dev
, "cannot enable VDD supply\n");
1538 goto disable_clk_lp
;
1541 err
= tegra_dsi_setup_clocks(dsi
);
1543 dev_err(&pdev
->dev
, "cannot setup clocks\n");
1547 regs
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1548 dsi
->regs
= devm_ioremap_resource(&pdev
->dev
, regs
);
1549 if (IS_ERR(dsi
->regs
)) {
1550 err
= PTR_ERR(dsi
->regs
);
1554 dsi
->mipi
= tegra_mipi_request(&pdev
->dev
);
1555 if (IS_ERR(dsi
->mipi
)) {
1556 err
= PTR_ERR(dsi
->mipi
);
1560 dsi
->host
.ops
= &tegra_dsi_host_ops
;
1561 dsi
->host
.dev
= &pdev
->dev
;
1563 err
= mipi_dsi_host_register(&dsi
->host
);
1565 dev_err(&pdev
->dev
, "failed to register DSI host: %d\n", err
);
1569 INIT_LIST_HEAD(&dsi
->client
.list
);
1570 dsi
->client
.ops
= &dsi_client_ops
;
1571 dsi
->client
.dev
= &pdev
->dev
;
1573 err
= host1x_client_register(&dsi
->client
);
1575 dev_err(&pdev
->dev
, "failed to register host1x client: %d\n",
1580 platform_set_drvdata(pdev
, dsi
);
1585 mipi_dsi_host_unregister(&dsi
->host
);
1587 tegra_mipi_free(dsi
->mipi
);
1589 regulator_disable(dsi
->vdd
);
1591 clk_disable_unprepare(dsi
->clk_lp
);
1593 clk_disable_unprepare(dsi
->clk
);
1595 reset_control_assert(dsi
->rst
);
1599 static int tegra_dsi_remove(struct platform_device
*pdev
)
1601 struct tegra_dsi
*dsi
= platform_get_drvdata(pdev
);
1604 err
= host1x_client_unregister(&dsi
->client
);
1606 dev_err(&pdev
->dev
, "failed to unregister host1x client: %d\n",
1611 tegra_output_remove(&dsi
->output
);
1613 mipi_dsi_host_unregister(&dsi
->host
);
1614 tegra_mipi_free(dsi
->mipi
);
1616 regulator_disable(dsi
->vdd
);
1617 clk_disable_unprepare(dsi
->clk_lp
);
1618 clk_disable_unprepare(dsi
->clk
);
1619 reset_control_assert(dsi
->rst
);
1624 static const struct of_device_id tegra_dsi_of_match
[] = {
1625 { .compatible
= "nvidia,tegra210-dsi", },
1626 { .compatible
= "nvidia,tegra132-dsi", },
1627 { .compatible
= "nvidia,tegra124-dsi", },
1628 { .compatible
= "nvidia,tegra114-dsi", },
1631 MODULE_DEVICE_TABLE(of
, tegra_dsi_of_match
);
1633 struct platform_driver tegra_dsi_driver
= {
1635 .name
= "tegra-dsi",
1636 .of_match_table
= tegra_dsi_of_match
,
1638 .probe
= tegra_dsi_probe
,
1639 .remove
= tegra_dsi_remove
,