2 * Copyright (C) 2012 Avionic Design GmbH
3 * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <linux/clk.h>
11 #include <linux/clk/tegra.h>
12 #include <linux/debugfs.h>
13 #include <linux/hdmi.h>
14 #include <linux/regulator/consumer.h>
29 struct tegra_hdmi_config
{
30 const struct tmds_config
*tmds
;
31 unsigned int num_tmds
;
33 unsigned long fuse_override_offset
;
34 unsigned long fuse_override_value
;
36 bool has_sor_io_peak_current
;
40 struct host1x_client client
;
41 struct tegra_output output
;
44 struct regulator
*vdd
;
45 struct regulator
*pll
;
50 struct clk
*clk_parent
;
53 const struct tegra_hdmi_config
*config
;
55 unsigned int audio_source
;
56 unsigned int audio_freq
;
60 struct drm_info_list
*debugfs_files
;
61 struct drm_minor
*minor
;
62 struct dentry
*debugfs
;
65 static inline struct tegra_hdmi
*
66 host1x_client_to_hdmi(struct host1x_client
*client
)
68 return container_of(client
, struct tegra_hdmi
, client
);
71 static inline struct tegra_hdmi
*to_hdmi(struct tegra_output
*output
)
73 return container_of(output
, struct tegra_hdmi
, output
);
76 #define HDMI_AUDIOCLK_FREQ 216000000
77 #define HDMI_REKEY_DEFAULT 56
85 static inline unsigned long tegra_hdmi_readl(struct tegra_hdmi
*hdmi
,
88 return readl(hdmi
->regs
+ (reg
<< 2));
91 static inline void tegra_hdmi_writel(struct tegra_hdmi
*hdmi
, unsigned long val
,
94 writel(val
, hdmi
->regs
+ (reg
<< 2));
97 struct tegra_hdmi_audio_config
{
104 static const struct tegra_hdmi_audio_config tegra_hdmi_audio_32k
[] = {
105 { 25200000, 4096, 25200, 24000 },
106 { 27000000, 4096, 27000, 24000 },
107 { 74250000, 4096, 74250, 24000 },
108 { 148500000, 4096, 148500, 24000 },
112 static const struct tegra_hdmi_audio_config tegra_hdmi_audio_44_1k
[] = {
113 { 25200000, 5880, 26250, 25000 },
114 { 27000000, 5880, 28125, 25000 },
115 { 74250000, 4704, 61875, 20000 },
116 { 148500000, 4704, 123750, 20000 },
120 static const struct tegra_hdmi_audio_config tegra_hdmi_audio_48k
[] = {
121 { 25200000, 6144, 25200, 24000 },
122 { 27000000, 6144, 27000, 24000 },
123 { 74250000, 6144, 74250, 24000 },
124 { 148500000, 6144, 148500, 24000 },
128 static const struct tegra_hdmi_audio_config tegra_hdmi_audio_88_2k
[] = {
129 { 25200000, 11760, 26250, 25000 },
130 { 27000000, 11760, 28125, 25000 },
131 { 74250000, 9408, 61875, 20000 },
132 { 148500000, 9408, 123750, 20000 },
136 static const struct tegra_hdmi_audio_config tegra_hdmi_audio_96k
[] = {
137 { 25200000, 12288, 25200, 24000 },
138 { 27000000, 12288, 27000, 24000 },
139 { 74250000, 12288, 74250, 24000 },
140 { 148500000, 12288, 148500, 24000 },
144 static const struct tegra_hdmi_audio_config tegra_hdmi_audio_176_4k
[] = {
145 { 25200000, 23520, 26250, 25000 },
146 { 27000000, 23520, 28125, 25000 },
147 { 74250000, 18816, 61875, 20000 },
148 { 148500000, 18816, 123750, 20000 },
152 static const struct tegra_hdmi_audio_config tegra_hdmi_audio_192k
[] = {
153 { 25200000, 24576, 25200, 24000 },
154 { 27000000, 24576, 27000, 24000 },
155 { 74250000, 24576, 74250, 24000 },
156 { 148500000, 24576, 148500, 24000 },
160 static const struct tmds_config tegra20_tmds_config
[] = {
161 { /* slow pixel clock modes */
163 .pll0
= SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
164 SOR_PLL_RESISTORSEL
| SOR_PLL_VCOCAP(0) |
165 SOR_PLL_TX_REG_LOAD(3),
166 .pll1
= SOR_PLL_TMDS_TERM_ENABLE
,
167 .pe_current
= PE_CURRENT0(PE_CURRENT_0_0_mA
) |
168 PE_CURRENT1(PE_CURRENT_0_0_mA
) |
169 PE_CURRENT2(PE_CURRENT_0_0_mA
) |
170 PE_CURRENT3(PE_CURRENT_0_0_mA
),
171 .drive_current
= DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA
) |
172 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA
) |
173 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA
) |
174 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA
),
176 { /* high pixel clock modes */
178 .pll0
= SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
179 SOR_PLL_RESISTORSEL
| SOR_PLL_VCOCAP(1) |
180 SOR_PLL_TX_REG_LOAD(3),
181 .pll1
= SOR_PLL_TMDS_TERM_ENABLE
| SOR_PLL_PE_EN
,
182 .pe_current
= PE_CURRENT0(PE_CURRENT_6_0_mA
) |
183 PE_CURRENT1(PE_CURRENT_6_0_mA
) |
184 PE_CURRENT2(PE_CURRENT_6_0_mA
) |
185 PE_CURRENT3(PE_CURRENT_6_0_mA
),
186 .drive_current
= DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA
) |
187 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA
) |
188 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA
) |
189 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA
),
193 static const struct tmds_config tegra30_tmds_config
[] = {
196 .pll0
= SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
197 SOR_PLL_RESISTORSEL
| SOR_PLL_VCOCAP(0) |
198 SOR_PLL_TX_REG_LOAD(0),
199 .pll1
= SOR_PLL_TMDS_TERM_ENABLE
,
200 .pe_current
= PE_CURRENT0(PE_CURRENT_0_0_mA
) |
201 PE_CURRENT1(PE_CURRENT_0_0_mA
) |
202 PE_CURRENT2(PE_CURRENT_0_0_mA
) |
203 PE_CURRENT3(PE_CURRENT_0_0_mA
),
204 .drive_current
= DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA
) |
205 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA
) |
206 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA
) |
207 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA
),
208 }, { /* 720p modes */
210 .pll0
= SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
211 SOR_PLL_RESISTORSEL
| SOR_PLL_VCOCAP(1) |
212 SOR_PLL_TX_REG_LOAD(0),
213 .pll1
= SOR_PLL_TMDS_TERM_ENABLE
| SOR_PLL_PE_EN
,
214 .pe_current
= PE_CURRENT0(PE_CURRENT_5_0_mA
) |
215 PE_CURRENT1(PE_CURRENT_5_0_mA
) |
216 PE_CURRENT2(PE_CURRENT_5_0_mA
) |
217 PE_CURRENT3(PE_CURRENT_5_0_mA
),
218 .drive_current
= DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA
) |
219 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA
) |
220 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA
) |
221 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA
),
222 }, { /* 1080p modes */
224 .pll0
= SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
225 SOR_PLL_RESISTORSEL
| SOR_PLL_VCOCAP(3) |
226 SOR_PLL_TX_REG_LOAD(0),
227 .pll1
= SOR_PLL_TMDS_TERM_ENABLE
| SOR_PLL_PE_EN
,
228 .pe_current
= PE_CURRENT0(PE_CURRENT_5_0_mA
) |
229 PE_CURRENT1(PE_CURRENT_5_0_mA
) |
230 PE_CURRENT2(PE_CURRENT_5_0_mA
) |
231 PE_CURRENT3(PE_CURRENT_5_0_mA
),
232 .drive_current
= DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA
) |
233 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA
) |
234 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA
) |
235 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA
),
239 static const struct tmds_config tegra114_tmds_config
[] = {
240 { /* 480p/576p / 25.2MHz/27MHz modes */
242 .pll0
= SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
243 SOR_PLL_VCOCAP(0) | SOR_PLL_RESISTORSEL
,
244 .pll1
= SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(0),
245 .pe_current
= PE_CURRENT0(PE_CURRENT_0_mA_T114
) |
246 PE_CURRENT1(PE_CURRENT_0_mA_T114
) |
247 PE_CURRENT2(PE_CURRENT_0_mA_T114
) |
248 PE_CURRENT3(PE_CURRENT_0_mA_T114
),
250 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114
) |
251 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114
) |
252 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114
) |
253 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114
),
254 .peak_current
= PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA
) |
255 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA
) |
256 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA
) |
257 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA
),
258 }, { /* 720p / 74.25MHz modes */
260 .pll0
= SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
261 SOR_PLL_VCOCAP(1) | SOR_PLL_RESISTORSEL
,
262 .pll1
= SOR_PLL_PE_EN
| SOR_PLL_LOADADJ(3) |
263 SOR_PLL_TMDS_TERMADJ(0),
264 .pe_current
= PE_CURRENT0(PE_CURRENT_15_mA_T114
) |
265 PE_CURRENT1(PE_CURRENT_15_mA_T114
) |
266 PE_CURRENT2(PE_CURRENT_15_mA_T114
) |
267 PE_CURRENT3(PE_CURRENT_15_mA_T114
),
269 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114
) |
270 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114
) |
271 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114
) |
272 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114
),
273 .peak_current
= PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA
) |
274 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA
) |
275 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA
) |
276 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA
),
277 }, { /* 1080p / 148.5MHz modes */
279 .pll0
= SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
280 SOR_PLL_VCOCAP(3) | SOR_PLL_RESISTORSEL
,
281 .pll1
= SOR_PLL_PE_EN
| SOR_PLL_LOADADJ(3) |
282 SOR_PLL_TMDS_TERMADJ(0),
283 .pe_current
= PE_CURRENT0(PE_CURRENT_10_mA_T114
) |
284 PE_CURRENT1(PE_CURRENT_10_mA_T114
) |
285 PE_CURRENT2(PE_CURRENT_10_mA_T114
) |
286 PE_CURRENT3(PE_CURRENT_10_mA_T114
),
288 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_12_400_mA_T114
) |
289 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_12_400_mA_T114
) |
290 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_12_400_mA_T114
) |
291 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_12_400_mA_T114
),
292 .peak_current
= PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA
) |
293 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA
) |
294 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA
) |
295 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA
),
296 }, { /* 225/297MHz modes */
298 .pll0
= SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
299 SOR_PLL_VCOCAP(0xf) | SOR_PLL_RESISTORSEL
,
300 .pll1
= SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(7)
301 | SOR_PLL_TMDS_TERM_ENABLE
,
302 .pe_current
= PE_CURRENT0(PE_CURRENT_0_mA_T114
) |
303 PE_CURRENT1(PE_CURRENT_0_mA_T114
) |
304 PE_CURRENT2(PE_CURRENT_0_mA_T114
) |
305 PE_CURRENT3(PE_CURRENT_0_mA_T114
),
307 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_25_200_mA_T114
) |
308 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_25_200_mA_T114
) |
309 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_25_200_mA_T114
) |
310 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_19_200_mA_T114
),
311 .peak_current
= PEAK_CURRENT_LANE0(PEAK_CURRENT_3_000_mA
) |
312 PEAK_CURRENT_LANE1(PEAK_CURRENT_3_000_mA
) |
313 PEAK_CURRENT_LANE2(PEAK_CURRENT_3_000_mA
) |
314 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_800_mA
),
318 static const struct tegra_hdmi_audio_config
*
319 tegra_hdmi_get_audio_config(unsigned int audio_freq
, unsigned int pclk
)
321 const struct tegra_hdmi_audio_config
*table
;
323 switch (audio_freq
) {
325 table
= tegra_hdmi_audio_32k
;
329 table
= tegra_hdmi_audio_44_1k
;
333 table
= tegra_hdmi_audio_48k
;
337 table
= tegra_hdmi_audio_88_2k
;
341 table
= tegra_hdmi_audio_96k
;
345 table
= tegra_hdmi_audio_176_4k
;
349 table
= tegra_hdmi_audio_192k
;
356 while (table
->pclk
) {
357 if (table
->pclk
== pclk
)
366 static void tegra_hdmi_setup_audio_fs_tables(struct tegra_hdmi
*hdmi
)
368 const unsigned int freqs
[] = {
369 32000, 44100, 48000, 88200, 96000, 176400, 192000
373 for (i
= 0; i
< ARRAY_SIZE(freqs
); i
++) {
374 unsigned int f
= freqs
[i
];
375 unsigned int eight_half
;
386 eight_half
= (8 * HDMI_AUDIOCLK_FREQ
) / (f
* 128);
387 value
= AUDIO_FS_LOW(eight_half
- delta
) |
388 AUDIO_FS_HIGH(eight_half
+ delta
);
389 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_AUDIO_FS(i
));
393 static int tegra_hdmi_setup_audio(struct tegra_hdmi
*hdmi
, unsigned int pclk
)
395 struct device_node
*node
= hdmi
->dev
->of_node
;
396 const struct tegra_hdmi_audio_config
*config
;
397 unsigned int offset
= 0;
400 switch (hdmi
->audio_source
) {
402 value
= AUDIO_CNTRL0_SOURCE_SELECT_HDAL
;
406 value
= AUDIO_CNTRL0_SOURCE_SELECT_SPDIF
;
410 value
= AUDIO_CNTRL0_SOURCE_SELECT_AUTO
;
414 if (of_device_is_compatible(node
, "nvidia,tegra30-hdmi")) {
415 value
|= AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
416 AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
417 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_AUDIO_CNTRL0
);
419 value
|= AUDIO_CNTRL0_INJECT_NULLSMPL
;
420 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_SOR_AUDIO_CNTRL0
);
422 value
= AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
423 AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
424 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_AUDIO_CNTRL0
);
427 config
= tegra_hdmi_get_audio_config(hdmi
->audio_freq
, pclk
);
429 dev_err(hdmi
->dev
, "cannot set audio to %u at %u pclk\n",
430 hdmi
->audio_freq
, pclk
);
434 tegra_hdmi_writel(hdmi
, 0, HDMI_NV_PDISP_HDMI_ACR_CTRL
);
436 value
= AUDIO_N_RESETF
| AUDIO_N_GENERATE_ALTERNATE
|
437 AUDIO_N_VALUE(config
->n
- 1);
438 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_AUDIO_N
);
440 tegra_hdmi_writel(hdmi
, ACR_SUBPACK_N(config
->n
) | ACR_ENABLE
,
441 HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH
);
443 value
= ACR_SUBPACK_CTS(config
->cts
);
444 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW
);
446 value
= SPARE_HW_CTS
| SPARE_FORCE_SW_CTS
| SPARE_CTS_RESET_VAL(1);
447 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_HDMI_SPARE
);
449 value
= tegra_hdmi_readl(hdmi
, HDMI_NV_PDISP_AUDIO_N
);
450 value
&= ~AUDIO_N_RESETF
;
451 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_AUDIO_N
);
453 if (of_device_is_compatible(node
, "nvidia,tegra30-hdmi")) {
454 switch (hdmi
->audio_freq
) {
456 offset
= HDMI_NV_PDISP_SOR_AUDIO_AVAL_0320
;
460 offset
= HDMI_NV_PDISP_SOR_AUDIO_AVAL_0441
;
464 offset
= HDMI_NV_PDISP_SOR_AUDIO_AVAL_0480
;
468 offset
= HDMI_NV_PDISP_SOR_AUDIO_AVAL_0882
;
472 offset
= HDMI_NV_PDISP_SOR_AUDIO_AVAL_0960
;
476 offset
= HDMI_NV_PDISP_SOR_AUDIO_AVAL_1764
;
480 offset
= HDMI_NV_PDISP_SOR_AUDIO_AVAL_1920
;
484 tegra_hdmi_writel(hdmi
, config
->aval
, offset
);
487 tegra_hdmi_setup_audio_fs_tables(hdmi
);
492 static inline unsigned long tegra_hdmi_subpack(const u8
*ptr
, size_t size
)
494 unsigned long value
= 0;
497 for (i
= size
; i
> 0; i
--)
498 value
= (value
<< 8) | ptr
[i
- 1];
503 static void tegra_hdmi_write_infopack(struct tegra_hdmi
*hdmi
, const void *data
,
506 const u8
*ptr
= data
;
507 unsigned long offset
;
512 case HDMI_INFOFRAME_TYPE_AVI
:
513 offset
= HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER
;
516 case HDMI_INFOFRAME_TYPE_AUDIO
:
517 offset
= HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER
;
520 case HDMI_INFOFRAME_TYPE_VENDOR
:
521 offset
= HDMI_NV_PDISP_HDMI_GENERIC_HEADER
;
525 dev_err(hdmi
->dev
, "unsupported infoframe type: %02x\n",
530 value
= INFOFRAME_HEADER_TYPE(ptr
[0]) |
531 INFOFRAME_HEADER_VERSION(ptr
[1]) |
532 INFOFRAME_HEADER_LEN(ptr
[2]);
533 tegra_hdmi_writel(hdmi
, value
, offset
);
537 * Each subpack contains 7 bytes, divided into:
538 * - subpack_low: bytes 0 - 3
539 * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00)
541 for (i
= 3, j
= 0; i
< size
; i
+= 7, j
+= 8) {
542 size_t rem
= size
- i
, num
= min_t(size_t, rem
, 4);
544 value
= tegra_hdmi_subpack(&ptr
[i
], num
);
545 tegra_hdmi_writel(hdmi
, value
, offset
++);
547 num
= min_t(size_t, rem
- num
, 3);
549 value
= tegra_hdmi_subpack(&ptr
[i
+ 4], num
);
550 tegra_hdmi_writel(hdmi
, value
, offset
++);
554 static void tegra_hdmi_setup_avi_infoframe(struct tegra_hdmi
*hdmi
,
555 struct drm_display_mode
*mode
)
557 struct hdmi_avi_infoframe frame
;
562 tegra_hdmi_writel(hdmi
, 0,
563 HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL
);
567 err
= drm_hdmi_avi_infoframe_from_display_mode(&frame
, mode
);
569 dev_err(hdmi
->dev
, "failed to setup AVI infoframe: %zd\n", err
);
573 err
= hdmi_avi_infoframe_pack(&frame
, buffer
, sizeof(buffer
));
575 dev_err(hdmi
->dev
, "failed to pack AVI infoframe: %zd\n", err
);
579 tegra_hdmi_write_infopack(hdmi
, buffer
, err
);
581 tegra_hdmi_writel(hdmi
, INFOFRAME_CTRL_ENABLE
,
582 HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL
);
585 static void tegra_hdmi_setup_audio_infoframe(struct tegra_hdmi
*hdmi
)
587 struct hdmi_audio_infoframe frame
;
592 tegra_hdmi_writel(hdmi
, 0,
593 HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL
);
597 err
= hdmi_audio_infoframe_init(&frame
);
599 dev_err(hdmi
->dev
, "failed to setup audio infoframe: %zd\n",
606 err
= hdmi_audio_infoframe_pack(&frame
, buffer
, sizeof(buffer
));
608 dev_err(hdmi
->dev
, "failed to pack audio infoframe: %zd\n",
614 * The audio infoframe has only one set of subpack registers, so the
615 * infoframe needs to be truncated. One set of subpack registers can
616 * contain 7 bytes. Including the 3 byte header only the first 10
617 * bytes can be programmed.
619 tegra_hdmi_write_infopack(hdmi
, buffer
, min_t(size_t, 10, err
));
621 tegra_hdmi_writel(hdmi
, INFOFRAME_CTRL_ENABLE
,
622 HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL
);
625 static void tegra_hdmi_setup_stereo_infoframe(struct tegra_hdmi
*hdmi
)
627 struct hdmi_vendor_infoframe frame
;
633 value
= tegra_hdmi_readl(hdmi
, HDMI_NV_PDISP_HDMI_GENERIC_CTRL
);
634 value
&= ~GENERIC_CTRL_ENABLE
;
635 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_HDMI_GENERIC_CTRL
);
639 hdmi_vendor_infoframe_init(&frame
);
640 frame
.s3d_struct
= HDMI_3D_STRUCTURE_FRAME_PACKING
;
642 err
= hdmi_vendor_infoframe_pack(&frame
, buffer
, sizeof(buffer
));
644 dev_err(hdmi
->dev
, "failed to pack vendor infoframe: %zd\n",
649 tegra_hdmi_write_infopack(hdmi
, buffer
, err
);
651 value
= tegra_hdmi_readl(hdmi
, HDMI_NV_PDISP_HDMI_GENERIC_CTRL
);
652 value
|= GENERIC_CTRL_ENABLE
;
653 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_HDMI_GENERIC_CTRL
);
656 static void tegra_hdmi_setup_tmds(struct tegra_hdmi
*hdmi
,
657 const struct tmds_config
*tmds
)
661 tegra_hdmi_writel(hdmi
, tmds
->pll0
, HDMI_NV_PDISP_SOR_PLL0
);
662 tegra_hdmi_writel(hdmi
, tmds
->pll1
, HDMI_NV_PDISP_SOR_PLL1
);
663 tegra_hdmi_writel(hdmi
, tmds
->pe_current
, HDMI_NV_PDISP_PE_CURRENT
);
665 tegra_hdmi_writel(hdmi
, tmds
->drive_current
,
666 HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT
);
668 value
= tegra_hdmi_readl(hdmi
, hdmi
->config
->fuse_override_offset
);
669 value
|= hdmi
->config
->fuse_override_value
;
670 tegra_hdmi_writel(hdmi
, value
, hdmi
->config
->fuse_override_offset
);
672 if (hdmi
->config
->has_sor_io_peak_current
)
673 tegra_hdmi_writel(hdmi
, tmds
->peak_current
,
674 HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT
);
677 static bool tegra_output_is_hdmi(struct tegra_output
*output
)
681 if (!output
->connector
.edid_blob_ptr
)
684 edid
= (struct edid
*)output
->connector
.edid_blob_ptr
->data
;
686 return drm_detect_hdmi_monitor(edid
);
689 static int tegra_output_hdmi_enable(struct tegra_output
*output
)
691 unsigned int h_sync_width
, h_front_porch
, h_back_porch
, i
, rekey
;
692 struct tegra_dc
*dc
= to_tegra_dc(output
->encoder
.crtc
);
693 struct drm_display_mode
*mode
= &dc
->base
.mode
;
694 struct tegra_hdmi
*hdmi
= to_hdmi(output
);
695 struct device_node
*node
= hdmi
->dev
->of_node
;
696 unsigned int pulse_start
, div82
, pclk
;
701 hdmi
->dvi
= !tegra_output_is_hdmi(output
);
703 pclk
= mode
->clock
* 1000;
704 h_sync_width
= mode
->hsync_end
- mode
->hsync_start
;
705 h_back_porch
= mode
->htotal
- mode
->hsync_end
;
706 h_front_porch
= mode
->hsync_start
- mode
->hdisplay
;
708 err
= regulator_enable(hdmi
->pll
);
710 dev_err(hdmi
->dev
, "failed to enable PLL regulator: %d\n", err
);
715 * This assumes that the display controller will divide its parent
716 * clock by 2 to generate the pixel clock.
718 err
= tegra_output_setup_clock(output
, hdmi
->clk
, pclk
* 2);
720 dev_err(hdmi
->dev
, "failed to setup clock: %d\n", err
);
724 err
= clk_set_rate(hdmi
->clk
, pclk
);
728 err
= clk_enable(hdmi
->clk
);
730 dev_err(hdmi
->dev
, "failed to enable clock: %d\n", err
);
734 tegra_periph_reset_assert(hdmi
->clk
);
735 usleep_range(1000, 2000);
736 tegra_periph_reset_deassert(hdmi
->clk
);
738 tegra_dc_writel(dc
, VSYNC_H_POSITION(1),
739 DC_DISP_DISP_TIMING_OPTIONS
);
740 tegra_dc_writel(dc
, DITHER_CONTROL_DISABLE
| BASE_COLOR_SIZE888
,
741 DC_DISP_DISP_COLOR_CONTROL
);
743 /* video_preamble uses h_pulse2 */
744 pulse_start
= 1 + h_sync_width
+ h_back_porch
- 10;
746 tegra_dc_writel(dc
, H_PULSE_2_ENABLE
, DC_DISP_DISP_SIGNAL_OPTIONS0
);
748 value
= PULSE_MODE_NORMAL
| PULSE_POLARITY_HIGH
| PULSE_QUAL_VACTIVE
|
750 tegra_dc_writel(dc
, value
, DC_DISP_H_PULSE2_CONTROL
);
752 value
= PULSE_START(pulse_start
) | PULSE_END(pulse_start
+ 8);
753 tegra_dc_writel(dc
, value
, DC_DISP_H_PULSE2_POSITION_A
);
755 value
= VSYNC_WINDOW_END(0x210) | VSYNC_WINDOW_START(0x200) |
757 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW
);
760 value
= HDMI_SRC_DISPLAYB
;
762 value
= HDMI_SRC_DISPLAYA
;
764 if ((mode
->hdisplay
== 720) && ((mode
->vdisplay
== 480) ||
765 (mode
->vdisplay
== 576)))
766 tegra_hdmi_writel(hdmi
,
767 value
| ARM_VIDEO_RANGE_FULL
,
768 HDMI_NV_PDISP_INPUT_CONTROL
);
770 tegra_hdmi_writel(hdmi
,
771 value
| ARM_VIDEO_RANGE_LIMITED
,
772 HDMI_NV_PDISP_INPUT_CONTROL
);
774 div82
= clk_get_rate(hdmi
->clk
) / 1000000 * 4;
775 value
= SOR_REFCLK_DIV_INT(div82
>> 2) | SOR_REFCLK_DIV_FRAC(div82
);
776 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_SOR_REFCLK
);
779 err
= tegra_hdmi_setup_audio(hdmi
, pclk
);
784 if (of_device_is_compatible(node
, "nvidia,tegra20-hdmi")) {
786 * TODO: add ELD support
790 rekey
= HDMI_REKEY_DEFAULT
;
791 value
= HDMI_CTRL_REKEY(rekey
);
792 value
|= HDMI_CTRL_MAX_AC_PACKET((h_sync_width
+ h_back_porch
+
793 h_front_porch
- rekey
- 18) / 32);
796 value
|= HDMI_CTRL_ENABLE
;
798 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_HDMI_CTRL
);
801 tegra_hdmi_writel(hdmi
, 0x0,
802 HDMI_NV_PDISP_HDMI_GENERIC_CTRL
);
804 tegra_hdmi_writel(hdmi
, GENERIC_CTRL_AUDIO
,
805 HDMI_NV_PDISP_HDMI_GENERIC_CTRL
);
807 tegra_hdmi_setup_avi_infoframe(hdmi
, mode
);
808 tegra_hdmi_setup_audio_infoframe(hdmi
);
809 tegra_hdmi_setup_stereo_infoframe(hdmi
);
812 for (i
= 0; i
< hdmi
->config
->num_tmds
; i
++) {
813 if (pclk
<= hdmi
->config
->tmds
[i
].pclk
) {
814 tegra_hdmi_setup_tmds(hdmi
, &hdmi
->config
->tmds
[i
]);
819 tegra_hdmi_writel(hdmi
,
820 SOR_SEQ_CTL_PU_PC(0) |
821 SOR_SEQ_PU_PC_ALT(0) |
823 SOR_SEQ_PD_PC_ALT(8),
824 HDMI_NV_PDISP_SOR_SEQ_CTL
);
826 value
= SOR_SEQ_INST_WAIT_TIME(1) |
827 SOR_SEQ_INST_WAIT_UNITS_VSYNC
|
829 SOR_SEQ_INST_PIN_A_LOW
|
830 SOR_SEQ_INST_PIN_B_LOW
|
831 SOR_SEQ_INST_DRIVE_PWM_OUT_LO
;
833 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_SOR_SEQ_INST(0));
834 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_SOR_SEQ_INST(8));
837 value
&= ~SOR_CSTM_ROTCLK(~0);
838 value
|= SOR_CSTM_ROTCLK(2);
839 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_SOR_CSTM
);
841 tegra_dc_writel(dc
, DISP_CTRL_MODE_STOP
, DC_CMD_DISPLAY_COMMAND
);
842 tegra_dc_writel(dc
, GENERAL_ACT_REQ
<< 8, DC_CMD_STATE_CONTROL
);
843 tegra_dc_writel(dc
, GENERAL_ACT_REQ
, DC_CMD_STATE_CONTROL
);
846 tegra_hdmi_writel(hdmi
,
847 SOR_PWR_NORMAL_STATE_PU
|
848 SOR_PWR_NORMAL_START_NORMAL
|
849 SOR_PWR_SAFE_STATE_PD
|
850 SOR_PWR_SETTING_NEW_TRIGGER
,
851 HDMI_NV_PDISP_SOR_PWR
);
852 tegra_hdmi_writel(hdmi
,
853 SOR_PWR_NORMAL_STATE_PU
|
854 SOR_PWR_NORMAL_START_NORMAL
|
855 SOR_PWR_SAFE_STATE_PD
|
856 SOR_PWR_SETTING_NEW_DONE
,
857 HDMI_NV_PDISP_SOR_PWR
);
860 BUG_ON(--retries
< 0);
861 value
= tegra_hdmi_readl(hdmi
, HDMI_NV_PDISP_SOR_PWR
);
862 } while (value
& SOR_PWR_SETTING_NEW_PENDING
);
864 value
= SOR_STATE_ASY_CRCMODE_COMPLETE
|
865 SOR_STATE_ASY_OWNER_HEAD0
|
866 SOR_STATE_ASY_SUBOWNER_BOTH
|
867 SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A
|
868 SOR_STATE_ASY_DEPOL_POS
;
870 /* setup sync polarities */
871 if (mode
->flags
& DRM_MODE_FLAG_PHSYNC
)
872 value
|= SOR_STATE_ASY_HSYNCPOL_POS
;
874 if (mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
875 value
|= SOR_STATE_ASY_HSYNCPOL_NEG
;
877 if (mode
->flags
& DRM_MODE_FLAG_PVSYNC
)
878 value
|= SOR_STATE_ASY_VSYNCPOL_POS
;
880 if (mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
881 value
|= SOR_STATE_ASY_VSYNCPOL_NEG
;
883 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_SOR_STATE2
);
885 value
= SOR_STATE_ASY_HEAD_OPMODE_AWAKE
| SOR_STATE_ASY_ORMODE_NORMAL
;
886 tegra_hdmi_writel(hdmi
, value
, HDMI_NV_PDISP_SOR_STATE1
);
888 tegra_hdmi_writel(hdmi
, 0, HDMI_NV_PDISP_SOR_STATE0
);
889 tegra_hdmi_writel(hdmi
, SOR_STATE_UPDATE
, HDMI_NV_PDISP_SOR_STATE0
);
890 tegra_hdmi_writel(hdmi
, value
| SOR_STATE_ATTACHED
,
891 HDMI_NV_PDISP_SOR_STATE1
);
892 tegra_hdmi_writel(hdmi
, 0, HDMI_NV_PDISP_SOR_STATE0
);
894 tegra_dc_writel(dc
, HDMI_ENABLE
, DC_DISP_DISP_WIN_OPTIONS
);
896 value
= PW0_ENABLE
| PW1_ENABLE
| PW2_ENABLE
| PW3_ENABLE
|
897 PW4_ENABLE
| PM0_ENABLE
| PM1_ENABLE
;
898 tegra_dc_writel(dc
, value
, DC_CMD_DISPLAY_POWER_CONTROL
);
900 value
= DISP_CTRL_MODE_C_DISPLAY
;
901 tegra_dc_writel(dc
, value
, DC_CMD_DISPLAY_COMMAND
);
903 tegra_dc_writel(dc
, GENERAL_ACT_REQ
<< 8, DC_CMD_STATE_CONTROL
);
904 tegra_dc_writel(dc
, GENERAL_ACT_REQ
, DC_CMD_STATE_CONTROL
);
906 /* TODO: add HDCP support */
911 static int tegra_output_hdmi_disable(struct tegra_output
*output
)
913 struct tegra_hdmi
*hdmi
= to_hdmi(output
);
915 tegra_periph_reset_assert(hdmi
->clk
);
916 clk_disable(hdmi
->clk
);
917 regulator_disable(hdmi
->pll
);
922 static int tegra_output_hdmi_setup_clock(struct tegra_output
*output
,
923 struct clk
*clk
, unsigned long pclk
)
925 struct tegra_hdmi
*hdmi
= to_hdmi(output
);
929 err
= clk_set_parent(clk
, hdmi
->clk_parent
);
931 dev_err(output
->dev
, "failed to set parent: %d\n", err
);
935 base
= clk_get_parent(hdmi
->clk_parent
);
938 * This assumes that the parent clock is pll_d_out0 or pll_d2_out
939 * respectively, each of which divides the base pll_d by 2.
941 err
= clk_set_rate(base
, pclk
* 2);
944 "failed to set base clock rate to %lu Hz\n",
950 static int tegra_output_hdmi_check_mode(struct tegra_output
*output
,
951 struct drm_display_mode
*mode
,
952 enum drm_mode_status
*status
)
954 struct tegra_hdmi
*hdmi
= to_hdmi(output
);
955 unsigned long pclk
= mode
->clock
* 1000;
959 parent
= clk_get_parent(hdmi
->clk_parent
);
961 err
= clk_round_rate(parent
, pclk
* 4);
963 *status
= MODE_NOCLOCK
;
970 static const struct tegra_output_ops hdmi_ops
= {
971 .enable
= tegra_output_hdmi_enable
,
972 .disable
= tegra_output_hdmi_disable
,
973 .setup_clock
= tegra_output_hdmi_setup_clock
,
974 .check_mode
= tegra_output_hdmi_check_mode
,
977 static int tegra_hdmi_show_regs(struct seq_file
*s
, void *data
)
979 struct drm_info_node
*node
= s
->private;
980 struct tegra_hdmi
*hdmi
= node
->info_ent
->data
;
983 err
= clk_enable(hdmi
->clk
);
987 #define DUMP_REG(name) \
988 seq_printf(s, "%-56s %#05x %08lx\n", #name, name, \
989 tegra_hdmi_readl(hdmi, name))
991 DUMP_REG(HDMI_CTXSW
);
992 DUMP_REG(HDMI_NV_PDISP_SOR_STATE0
);
993 DUMP_REG(HDMI_NV_PDISP_SOR_STATE1
);
994 DUMP_REG(HDMI_NV_PDISP_SOR_STATE2
);
995 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_MSB
);
996 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_LSB
);
997 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_MSB
);
998 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_LSB
);
999 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_MSB
);
1000 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_LSB
);
1001 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_MSB
);
1002 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_LSB
);
1003 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_MSB
);
1004 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_LSB
);
1005 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_MSB
);
1006 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_LSB
);
1007 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CTRL
);
1008 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CMODE
);
1009 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_MSB
);
1010 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_LSB
);
1011 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_MSB
);
1012 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB2
);
1013 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB1
);
1014 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_RI
);
1015 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_MSB
);
1016 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_LSB
);
1017 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU0
);
1018 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU_RDATA0
);
1019 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU1
);
1020 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU2
);
1021 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL
);
1022 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_STATUS
);
1023 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER
);
1024 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_LOW
);
1025 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_HIGH
);
1026 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL
);
1027 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_STATUS
);
1028 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER
);
1029 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_LOW
);
1030 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_HIGH
);
1031 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_LOW
);
1032 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_HIGH
);
1033 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_CTRL
);
1034 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_STATUS
);
1035 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_HEADER
);
1036 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_LOW
);
1037 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_HIGH
);
1038 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_LOW
);
1039 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_HIGH
);
1040 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_LOW
);
1041 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_HIGH
);
1042 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_LOW
);
1043 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_HIGH
);
1044 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_CTRL
);
1045 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_LOW
);
1046 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_HIGH
);
1047 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW
);
1048 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH
);
1049 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_LOW
);
1050 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_HIGH
);
1051 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_LOW
);
1052 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_HIGH
);
1053 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_LOW
);
1054 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_HIGH
);
1055 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_LOW
);
1056 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_HIGH
);
1057 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_LOW
);
1058 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_HIGH
);
1059 DUMP_REG(HDMI_NV_PDISP_HDMI_CTRL
);
1060 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_KEEPOUT
);
1061 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_WINDOW
);
1062 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_CTRL
);
1063 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_STATUS
);
1064 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_SUBPACK
);
1065 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS1
);
1066 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS2
);
1067 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU0
);
1068 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1
);
1069 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1_RDATA
);
1070 DUMP_REG(HDMI_NV_PDISP_HDMI_SPARE
);
1071 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS1
);
1072 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS2
);
1073 DUMP_REG(HDMI_NV_PDISP_HDMI_HDCPRIF_ROM_CTRL
);
1074 DUMP_REG(HDMI_NV_PDISP_SOR_CAP
);
1075 DUMP_REG(HDMI_NV_PDISP_SOR_PWR
);
1076 DUMP_REG(HDMI_NV_PDISP_SOR_TEST
);
1077 DUMP_REG(HDMI_NV_PDISP_SOR_PLL0
);
1078 DUMP_REG(HDMI_NV_PDISP_SOR_PLL1
);
1079 DUMP_REG(HDMI_NV_PDISP_SOR_PLL2
);
1080 DUMP_REG(HDMI_NV_PDISP_SOR_CSTM
);
1081 DUMP_REG(HDMI_NV_PDISP_SOR_LVDS
);
1082 DUMP_REG(HDMI_NV_PDISP_SOR_CRCA
);
1083 DUMP_REG(HDMI_NV_PDISP_SOR_CRCB
);
1084 DUMP_REG(HDMI_NV_PDISP_SOR_BLANK
);
1085 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_CTL
);
1086 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(0));
1087 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(1));
1088 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(2));
1089 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(3));
1090 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(4));
1091 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(5));
1092 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(6));
1093 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(7));
1094 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(8));
1095 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(9));
1096 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(10));
1097 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(11));
1098 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(12));
1099 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(13));
1100 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(14));
1101 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(15));
1102 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA0
);
1103 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA1
);
1104 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA0
);
1105 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA1
);
1106 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA0
);
1107 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA1
);
1108 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA0
);
1109 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA1
);
1110 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA0
);
1111 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA1
);
1112 DUMP_REG(HDMI_NV_PDISP_SOR_TRIG
);
1113 DUMP_REG(HDMI_NV_PDISP_SOR_MSCHECK
);
1114 DUMP_REG(HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT
);
1115 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG0
);
1116 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG1
);
1117 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG2
);
1118 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(0));
1119 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(1));
1120 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(2));
1121 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(3));
1122 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(4));
1123 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(5));
1124 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(6));
1125 DUMP_REG(HDMI_NV_PDISP_AUDIO_PULSE_WIDTH
);
1126 DUMP_REG(HDMI_NV_PDISP_AUDIO_THRESHOLD
);
1127 DUMP_REG(HDMI_NV_PDISP_AUDIO_CNTRL0
);
1128 DUMP_REG(HDMI_NV_PDISP_AUDIO_N
);
1129 DUMP_REG(HDMI_NV_PDISP_HDCPRIF_ROM_TIMING
);
1130 DUMP_REG(HDMI_NV_PDISP_SOR_REFCLK
);
1131 DUMP_REG(HDMI_NV_PDISP_CRC_CONTROL
);
1132 DUMP_REG(HDMI_NV_PDISP_INPUT_CONTROL
);
1133 DUMP_REG(HDMI_NV_PDISP_SCRATCH
);
1134 DUMP_REG(HDMI_NV_PDISP_PE_CURRENT
);
1135 DUMP_REG(HDMI_NV_PDISP_KEY_CTRL
);
1136 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG0
);
1137 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG1
);
1138 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG2
);
1139 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_0
);
1140 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_1
);
1141 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_2
);
1142 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_3
);
1143 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_TRIG
);
1144 DUMP_REG(HDMI_NV_PDISP_KEY_SKEY_INDEX
);
1145 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_CNTRL0
);
1146 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR
);
1147 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE
);
1148 DUMP_REG(HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT
);
1152 clk_disable(hdmi
->clk
);
1157 static struct drm_info_list debugfs_files
[] = {
1158 { "regs", tegra_hdmi_show_regs
, 0, NULL
},
1161 static int tegra_hdmi_debugfs_init(struct tegra_hdmi
*hdmi
,
1162 struct drm_minor
*minor
)
1167 hdmi
->debugfs
= debugfs_create_dir("hdmi", minor
->debugfs_root
);
1171 hdmi
->debugfs_files
= kmemdup(debugfs_files
, sizeof(debugfs_files
),
1173 if (!hdmi
->debugfs_files
) {
1178 for (i
= 0; i
< ARRAY_SIZE(debugfs_files
); i
++)
1179 hdmi
->debugfs_files
[i
].data
= hdmi
;
1181 err
= drm_debugfs_create_files(hdmi
->debugfs_files
,
1182 ARRAY_SIZE(debugfs_files
),
1183 hdmi
->debugfs
, minor
);
1187 hdmi
->minor
= minor
;
1192 kfree(hdmi
->debugfs_files
);
1193 hdmi
->debugfs_files
= NULL
;
1195 debugfs_remove(hdmi
->debugfs
);
1196 hdmi
->debugfs
= NULL
;
1201 static int tegra_hdmi_debugfs_exit(struct tegra_hdmi
*hdmi
)
1203 drm_debugfs_remove_files(hdmi
->debugfs_files
, ARRAY_SIZE(debugfs_files
),
1207 kfree(hdmi
->debugfs_files
);
1208 hdmi
->debugfs_files
= NULL
;
1210 debugfs_remove(hdmi
->debugfs
);
1211 hdmi
->debugfs
= NULL
;
1216 static int tegra_hdmi_init(struct host1x_client
*client
)
1218 struct tegra_drm
*tegra
= dev_get_drvdata(client
->parent
);
1219 struct tegra_hdmi
*hdmi
= host1x_client_to_hdmi(client
);
1222 err
= regulator_enable(hdmi
->vdd
);
1224 dev_err(client
->dev
, "failed to enable VDD regulator: %d\n",
1229 hdmi
->output
.type
= TEGRA_OUTPUT_HDMI
;
1230 hdmi
->output
.dev
= client
->dev
;
1231 hdmi
->output
.ops
= &hdmi_ops
;
1233 err
= tegra_output_init(tegra
->drm
, &hdmi
->output
);
1235 dev_err(client
->dev
, "output setup failed: %d\n", err
);
1239 if (IS_ENABLED(CONFIG_DEBUG_FS
)) {
1240 err
= tegra_hdmi_debugfs_init(hdmi
, tegra
->drm
->primary
);
1242 dev_err(client
->dev
, "debugfs setup failed: %d\n", err
);
1248 static int tegra_hdmi_exit(struct host1x_client
*client
)
1250 struct tegra_hdmi
*hdmi
= host1x_client_to_hdmi(client
);
1253 if (IS_ENABLED(CONFIG_DEBUG_FS
)) {
1254 err
= tegra_hdmi_debugfs_exit(hdmi
);
1256 dev_err(client
->dev
, "debugfs cleanup failed: %d\n",
1260 err
= tegra_output_disable(&hdmi
->output
);
1262 dev_err(client
->dev
, "output failed to disable: %d\n", err
);
1266 err
= tegra_output_exit(&hdmi
->output
);
1268 dev_err(client
->dev
, "output cleanup failed: %d\n", err
);
1272 regulator_disable(hdmi
->vdd
);
1277 static const struct host1x_client_ops hdmi_client_ops
= {
1278 .init
= tegra_hdmi_init
,
1279 .exit
= tegra_hdmi_exit
,
1282 static const struct tegra_hdmi_config tegra20_hdmi_config
= {
1283 .tmds
= tegra20_tmds_config
,
1284 .num_tmds
= ARRAY_SIZE(tegra20_tmds_config
),
1285 .fuse_override_offset
= HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT
,
1286 .fuse_override_value
= 1 << 31,
1287 .has_sor_io_peak_current
= false,
1290 static const struct tegra_hdmi_config tegra30_hdmi_config
= {
1291 .tmds
= tegra30_tmds_config
,
1292 .num_tmds
= ARRAY_SIZE(tegra30_tmds_config
),
1293 .fuse_override_offset
= HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT
,
1294 .fuse_override_value
= 1 << 31,
1295 .has_sor_io_peak_current
= false,
1298 static const struct tegra_hdmi_config tegra114_hdmi_config
= {
1299 .tmds
= tegra114_tmds_config
,
1300 .num_tmds
= ARRAY_SIZE(tegra114_tmds_config
),
1301 .fuse_override_offset
= HDMI_NV_PDISP_SOR_PAD_CTLS0
,
1302 .fuse_override_value
= 1 << 31,
1303 .has_sor_io_peak_current
= true,
1306 static const struct of_device_id tegra_hdmi_of_match
[] = {
1307 { .compatible
= "nvidia,tegra114-hdmi", .data
= &tegra114_hdmi_config
},
1308 { .compatible
= "nvidia,tegra30-hdmi", .data
= &tegra30_hdmi_config
},
1309 { .compatible
= "nvidia,tegra20-hdmi", .data
= &tegra20_hdmi_config
},
1313 static int tegra_hdmi_probe(struct platform_device
*pdev
)
1315 const struct of_device_id
*match
;
1316 struct tegra_hdmi
*hdmi
;
1317 struct resource
*regs
;
1320 match
= of_match_node(tegra_hdmi_of_match
, pdev
->dev
.of_node
);
1324 hdmi
= devm_kzalloc(&pdev
->dev
, sizeof(*hdmi
), GFP_KERNEL
);
1328 hdmi
->config
= match
->data
;
1329 hdmi
->dev
= &pdev
->dev
;
1330 hdmi
->audio_source
= AUTO
;
1331 hdmi
->audio_freq
= 44100;
1332 hdmi
->stereo
= false;
1335 hdmi
->clk
= devm_clk_get(&pdev
->dev
, NULL
);
1336 if (IS_ERR(hdmi
->clk
)) {
1337 dev_err(&pdev
->dev
, "failed to get clock\n");
1338 return PTR_ERR(hdmi
->clk
);
1341 err
= clk_prepare(hdmi
->clk
);
1345 hdmi
->clk_parent
= devm_clk_get(&pdev
->dev
, "parent");
1346 if (IS_ERR(hdmi
->clk_parent
))
1347 return PTR_ERR(hdmi
->clk_parent
);
1349 err
= clk_prepare(hdmi
->clk_parent
);
1353 err
= clk_set_parent(hdmi
->clk
, hdmi
->clk_parent
);
1355 dev_err(&pdev
->dev
, "failed to setup clocks: %d\n", err
);
1359 hdmi
->vdd
= devm_regulator_get(&pdev
->dev
, "vdd");
1360 if (IS_ERR(hdmi
->vdd
)) {
1361 dev_err(&pdev
->dev
, "failed to get VDD regulator\n");
1362 return PTR_ERR(hdmi
->vdd
);
1365 hdmi
->pll
= devm_regulator_get(&pdev
->dev
, "pll");
1366 if (IS_ERR(hdmi
->pll
)) {
1367 dev_err(&pdev
->dev
, "failed to get PLL regulator\n");
1368 return PTR_ERR(hdmi
->pll
);
1371 hdmi
->output
.dev
= &pdev
->dev
;
1373 err
= tegra_output_probe(&hdmi
->output
);
1377 regs
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1381 hdmi
->regs
= devm_ioremap_resource(&pdev
->dev
, regs
);
1382 if (IS_ERR(hdmi
->regs
))
1383 return PTR_ERR(hdmi
->regs
);
1385 err
= platform_get_irq(pdev
, 0);
1391 INIT_LIST_HEAD(&hdmi
->client
.list
);
1392 hdmi
->client
.ops
= &hdmi_client_ops
;
1393 hdmi
->client
.dev
= &pdev
->dev
;
1395 err
= host1x_client_register(&hdmi
->client
);
1397 dev_err(&pdev
->dev
, "failed to register host1x client: %d\n",
1402 platform_set_drvdata(pdev
, hdmi
);
1407 static int tegra_hdmi_remove(struct platform_device
*pdev
)
1409 struct tegra_hdmi
*hdmi
= platform_get_drvdata(pdev
);
1412 err
= host1x_client_unregister(&hdmi
->client
);
1414 dev_err(&pdev
->dev
, "failed to unregister host1x client: %d\n",
1419 err
= tegra_output_remove(&hdmi
->output
);
1421 dev_err(&pdev
->dev
, "failed to remove output: %d\n", err
);
1425 clk_unprepare(hdmi
->clk_parent
);
1426 clk_unprepare(hdmi
->clk
);
1431 struct platform_driver tegra_hdmi_driver
= {
1433 .name
= "tegra-hdmi",
1434 .owner
= THIS_MODULE
,
1435 .of_match_table
= tegra_hdmi_of_match
,
1437 .probe
= tegra_hdmi_probe
,
1438 .remove
= tegra_hdmi_remove
,