blob: 4116b08acabb73388943812b8ba0739c7cf9a985 [file] [log] [blame]
Thierry Redingedec4af2012-11-15 21:28:23 +00001/*
2 * Copyright (C) 2012 Avionic Design GmbH
3 * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
4 *
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.
8 */
9
10#include <linux/clk.h>
Thierry Reding9eb9b222013-09-24 16:32:47 +020011#include <linux/debugfs.h>
12#include <linux/hdmi.h>
13#include <linux/regulator/consumer.h>
Stephen Warrenca480802013-11-06 16:20:54 -070014#include <linux/reset.h>
Thierry Redingac24c222012-11-23 15:14:00 +010015
Thierry Redingedec4af2012-11-15 21:28:23 +000016#include "hdmi.h"
17#include "drm.h"
18#include "dc.h"
19
Thierry Reding59af0592013-10-14 09:43:05 +020020struct tmds_config {
21 unsigned int pclk;
22 u32 pll0;
23 u32 pll1;
24 u32 pe_current;
25 u32 drive_current;
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +020026 u32 peak_current;
Thierry Reding59af0592013-10-14 09:43:05 +020027};
28
29struct tegra_hdmi_config {
30 const struct tmds_config *tmds;
31 unsigned int num_tmds;
32
33 unsigned long fuse_override_offset;
34 unsigned long fuse_override_value;
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +020035
36 bool has_sor_io_peak_current;
Thierry Reding59af0592013-10-14 09:43:05 +020037};
38
Thierry Redingedec4af2012-11-15 21:28:23 +000039struct tegra_hdmi {
Thierry Reding776dc382013-10-14 14:43:22 +020040 struct host1x_client client;
Thierry Redingedec4af2012-11-15 21:28:23 +000041 struct tegra_output output;
42 struct device *dev;
Thierry Reding365765f2013-10-29 16:00:42 +010043 bool enabled;
Thierry Redingedec4af2012-11-15 21:28:23 +000044
Thierry Redingfb50a112014-02-28 16:57:34 +010045 struct regulator *hdmi;
Thierry Redingedec4af2012-11-15 21:28:23 +000046 struct regulator *pll;
Thierry Reding88685682014-04-16 10:24:12 +020047 struct regulator *vdd;
Thierry Redingedec4af2012-11-15 21:28:23 +000048
49 void __iomem *regs;
50 unsigned int irq;
51
52 struct clk *clk_parent;
53 struct clk *clk;
Stephen Warrenca480802013-11-06 16:20:54 -070054 struct reset_control *rst;
Thierry Redingedec4af2012-11-15 21:28:23 +000055
Thierry Reding59af0592013-10-14 09:43:05 +020056 const struct tegra_hdmi_config *config;
57
Thierry Redingedec4af2012-11-15 21:28:23 +000058 unsigned int audio_source;
59 unsigned int audio_freq;
60 bool stereo;
61 bool dvi;
62
63 struct drm_info_list *debugfs_files;
64 struct drm_minor *minor;
65 struct dentry *debugfs;
66};
67
68static inline struct tegra_hdmi *
Thierry Reding776dc382013-10-14 14:43:22 +020069host1x_client_to_hdmi(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +000070{
71 return container_of(client, struct tegra_hdmi, client);
72}
73
74static inline struct tegra_hdmi *to_hdmi(struct tegra_output *output)
75{
76 return container_of(output, struct tegra_hdmi, output);
77}
78
79#define HDMI_AUDIOCLK_FREQ 216000000
80#define HDMI_REKEY_DEFAULT 56
81
82enum {
83 AUTO = 0,
84 SPDIF,
85 HDA,
86};
87
88static inline unsigned long tegra_hdmi_readl(struct tegra_hdmi *hdmi,
89 unsigned long reg)
90{
91 return readl(hdmi->regs + (reg << 2));
92}
93
94static inline void tegra_hdmi_writel(struct tegra_hdmi *hdmi, unsigned long val,
95 unsigned long reg)
96{
97 writel(val, hdmi->regs + (reg << 2));
98}
99
100struct tegra_hdmi_audio_config {
101 unsigned int pclk;
102 unsigned int n;
103 unsigned int cts;
104 unsigned int aval;
105};
106
107static const struct tegra_hdmi_audio_config tegra_hdmi_audio_32k[] = {
108 { 25200000, 4096, 25200, 24000 },
109 { 27000000, 4096, 27000, 24000 },
110 { 74250000, 4096, 74250, 24000 },
111 { 148500000, 4096, 148500, 24000 },
112 { 0, 0, 0, 0 },
113};
114
115static const struct tegra_hdmi_audio_config tegra_hdmi_audio_44_1k[] = {
116 { 25200000, 5880, 26250, 25000 },
117 { 27000000, 5880, 28125, 25000 },
118 { 74250000, 4704, 61875, 20000 },
119 { 148500000, 4704, 123750, 20000 },
120 { 0, 0, 0, 0 },
121};
122
123static const struct tegra_hdmi_audio_config tegra_hdmi_audio_48k[] = {
124 { 25200000, 6144, 25200, 24000 },
125 { 27000000, 6144, 27000, 24000 },
126 { 74250000, 6144, 74250, 24000 },
127 { 148500000, 6144, 148500, 24000 },
128 { 0, 0, 0, 0 },
129};
130
131static const struct tegra_hdmi_audio_config tegra_hdmi_audio_88_2k[] = {
132 { 25200000, 11760, 26250, 25000 },
133 { 27000000, 11760, 28125, 25000 },
134 { 74250000, 9408, 61875, 20000 },
135 { 148500000, 9408, 123750, 20000 },
136 { 0, 0, 0, 0 },
137};
138
139static const struct tegra_hdmi_audio_config tegra_hdmi_audio_96k[] = {
140 { 25200000, 12288, 25200, 24000 },
141 { 27000000, 12288, 27000, 24000 },
142 { 74250000, 12288, 74250, 24000 },
143 { 148500000, 12288, 148500, 24000 },
144 { 0, 0, 0, 0 },
145};
146
147static const struct tegra_hdmi_audio_config tegra_hdmi_audio_176_4k[] = {
148 { 25200000, 23520, 26250, 25000 },
149 { 27000000, 23520, 28125, 25000 },
150 { 74250000, 18816, 61875, 20000 },
151 { 148500000, 18816, 123750, 20000 },
152 { 0, 0, 0, 0 },
153};
154
155static const struct tegra_hdmi_audio_config tegra_hdmi_audio_192k[] = {
156 { 25200000, 24576, 25200, 24000 },
157 { 27000000, 24576, 27000, 24000 },
158 { 74250000, 24576, 74250, 24000 },
159 { 148500000, 24576, 148500, 24000 },
160 { 0, 0, 0, 0 },
161};
162
Thierry Redingf27db962013-09-30 15:14:41 +0200163static const struct tmds_config tegra20_tmds_config[] = {
Lucas Stachfa416dd2012-12-19 21:38:55 +0000164 { /* slow pixel clock modes */
Thierry Redingedec4af2012-11-15 21:28:23 +0000165 .pclk = 27000000,
166 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
167 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) |
168 SOR_PLL_TX_REG_LOAD(3),
169 .pll1 = SOR_PLL_TMDS_TERM_ENABLE,
170 .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) |
171 PE_CURRENT1(PE_CURRENT_0_0_mA) |
172 PE_CURRENT2(PE_CURRENT_0_0_mA) |
173 PE_CURRENT3(PE_CURRENT_0_0_mA),
174 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) |
175 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) |
176 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) |
177 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA),
Lucas Stachfa416dd2012-12-19 21:38:55 +0000178 },
179 { /* high pixel clock modes */
Thierry Redingedec4af2012-11-15 21:28:23 +0000180 .pclk = UINT_MAX,
181 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
182 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) |
183 SOR_PLL_TX_REG_LOAD(3),
184 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
185 .pe_current = PE_CURRENT0(PE_CURRENT_6_0_mA) |
186 PE_CURRENT1(PE_CURRENT_6_0_mA) |
187 PE_CURRENT2(PE_CURRENT_6_0_mA) |
188 PE_CURRENT3(PE_CURRENT_6_0_mA),
189 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) |
190 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) |
191 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) |
192 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA),
193 },
194};
195
Thierry Redingf27db962013-09-30 15:14:41 +0200196static const struct tmds_config tegra30_tmds_config[] = {
Thierry Redingedec4af2012-11-15 21:28:23 +0000197 { /* 480p modes */
198 .pclk = 27000000,
199 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
200 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) |
201 SOR_PLL_TX_REG_LOAD(0),
202 .pll1 = SOR_PLL_TMDS_TERM_ENABLE,
203 .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) |
204 PE_CURRENT1(PE_CURRENT_0_0_mA) |
205 PE_CURRENT2(PE_CURRENT_0_0_mA) |
206 PE_CURRENT3(PE_CURRENT_0_0_mA),
207 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
208 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
209 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
210 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
211 }, { /* 720p modes */
212 .pclk = 74250000,
213 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
214 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) |
215 SOR_PLL_TX_REG_LOAD(0),
216 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
217 .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) |
218 PE_CURRENT1(PE_CURRENT_5_0_mA) |
219 PE_CURRENT2(PE_CURRENT_5_0_mA) |
220 PE_CURRENT3(PE_CURRENT_5_0_mA),
221 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
222 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
223 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
224 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
225 }, { /* 1080p modes */
226 .pclk = UINT_MAX,
227 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
228 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(3) |
229 SOR_PLL_TX_REG_LOAD(0),
230 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
231 .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) |
232 PE_CURRENT1(PE_CURRENT_5_0_mA) |
233 PE_CURRENT2(PE_CURRENT_5_0_mA) |
234 PE_CURRENT3(PE_CURRENT_5_0_mA),
235 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
236 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
237 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
238 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
239 },
240};
241
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +0200242static const struct tmds_config tegra114_tmds_config[] = {
243 { /* 480p/576p / 25.2MHz/27MHz modes */
244 .pclk = 27000000,
245 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
246 SOR_PLL_VCOCAP(0) | SOR_PLL_RESISTORSEL,
247 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(0),
248 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
249 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
250 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
251 PE_CURRENT3(PE_CURRENT_0_mA_T114),
252 .drive_current =
253 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
254 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
255 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
256 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
257 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
258 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
259 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
260 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
261 }, { /* 720p / 74.25MHz modes */
262 .pclk = 74250000,
263 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
264 SOR_PLL_VCOCAP(1) | SOR_PLL_RESISTORSEL,
265 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
266 SOR_PLL_TMDS_TERMADJ(0),
267 .pe_current = PE_CURRENT0(PE_CURRENT_15_mA_T114) |
268 PE_CURRENT1(PE_CURRENT_15_mA_T114) |
269 PE_CURRENT2(PE_CURRENT_15_mA_T114) |
270 PE_CURRENT3(PE_CURRENT_15_mA_T114),
271 .drive_current =
272 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
273 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
274 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
275 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
276 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
277 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
278 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
279 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
280 }, { /* 1080p / 148.5MHz modes */
281 .pclk = 148500000,
282 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
283 SOR_PLL_VCOCAP(3) | SOR_PLL_RESISTORSEL,
284 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
285 SOR_PLL_TMDS_TERMADJ(0),
286 .pe_current = PE_CURRENT0(PE_CURRENT_10_mA_T114) |
287 PE_CURRENT1(PE_CURRENT_10_mA_T114) |
288 PE_CURRENT2(PE_CURRENT_10_mA_T114) |
289 PE_CURRENT3(PE_CURRENT_10_mA_T114),
290 .drive_current =
291 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_12_400_mA_T114) |
292 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_12_400_mA_T114) |
293 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_12_400_mA_T114) |
294 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_12_400_mA_T114),
295 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
296 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
297 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
298 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
299 }, { /* 225/297MHz modes */
300 .pclk = UINT_MAX,
301 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
302 SOR_PLL_VCOCAP(0xf) | SOR_PLL_RESISTORSEL,
303 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(7)
304 | SOR_PLL_TMDS_TERM_ENABLE,
305 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
306 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
307 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
308 PE_CURRENT3(PE_CURRENT_0_mA_T114),
309 .drive_current =
310 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_25_200_mA_T114) |
311 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_25_200_mA_T114) |
312 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_25_200_mA_T114) |
313 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_19_200_mA_T114),
314 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_3_000_mA) |
315 PEAK_CURRENT_LANE1(PEAK_CURRENT_3_000_mA) |
316 PEAK_CURRENT_LANE2(PEAK_CURRENT_3_000_mA) |
317 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_800_mA),
318 },
319};
320
Thierry Redingedec4af2012-11-15 21:28:23 +0000321static const struct tegra_hdmi_audio_config *
322tegra_hdmi_get_audio_config(unsigned int audio_freq, unsigned int pclk)
323{
324 const struct tegra_hdmi_audio_config *table;
325
326 switch (audio_freq) {
327 case 32000:
328 table = tegra_hdmi_audio_32k;
329 break;
330
331 case 44100:
332 table = tegra_hdmi_audio_44_1k;
333 break;
334
335 case 48000:
336 table = tegra_hdmi_audio_48k;
337 break;
338
339 case 88200:
340 table = tegra_hdmi_audio_88_2k;
341 break;
342
343 case 96000:
344 table = tegra_hdmi_audio_96k;
345 break;
346
347 case 176400:
348 table = tegra_hdmi_audio_176_4k;
349 break;
350
351 case 192000:
352 table = tegra_hdmi_audio_192k;
353 break;
354
355 default:
356 return NULL;
357 }
358
359 while (table->pclk) {
360 if (table->pclk == pclk)
361 return table;
362
363 table++;
364 }
365
366 return NULL;
367}
368
369static void tegra_hdmi_setup_audio_fs_tables(struct tegra_hdmi *hdmi)
370{
371 const unsigned int freqs[] = {
372 32000, 44100, 48000, 88200, 96000, 176400, 192000
373 };
374 unsigned int i;
375
376 for (i = 0; i < ARRAY_SIZE(freqs); i++) {
377 unsigned int f = freqs[i];
378 unsigned int eight_half;
379 unsigned long value;
380 unsigned int delta;
381
382 if (f > 96000)
383 delta = 2;
Thierry Reding17a8b6b2013-12-16 10:01:24 +0100384 else if (f > 48000)
Thierry Redingedec4af2012-11-15 21:28:23 +0000385 delta = 6;
386 else
387 delta = 9;
388
389 eight_half = (8 * HDMI_AUDIOCLK_FREQ) / (f * 128);
390 value = AUDIO_FS_LOW(eight_half - delta) |
391 AUDIO_FS_HIGH(eight_half + delta);
392 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_FS(i));
393 }
394}
395
396static int tegra_hdmi_setup_audio(struct tegra_hdmi *hdmi, unsigned int pclk)
397{
398 struct device_node *node = hdmi->dev->of_node;
399 const struct tegra_hdmi_audio_config *config;
400 unsigned int offset = 0;
401 unsigned long value;
402
403 switch (hdmi->audio_source) {
404 case HDA:
405 value = AUDIO_CNTRL0_SOURCE_SELECT_HDAL;
406 break;
407
408 case SPDIF:
409 value = AUDIO_CNTRL0_SOURCE_SELECT_SPDIF;
410 break;
411
412 default:
413 value = AUDIO_CNTRL0_SOURCE_SELECT_AUTO;
414 break;
415 }
416
417 if (of_device_is_compatible(node, "nvidia,tegra30-hdmi")) {
418 value |= AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
419 AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
420 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0);
421 } else {
422 value |= AUDIO_CNTRL0_INJECT_NULLSMPL;
423 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
424
425 value = AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
426 AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
427 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0);
428 }
429
430 config = tegra_hdmi_get_audio_config(hdmi->audio_freq, pclk);
431 if (!config) {
432 dev_err(hdmi->dev, "cannot set audio to %u at %u pclk\n",
433 hdmi->audio_freq, pclk);
434 return -EINVAL;
435 }
436
437 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_HDMI_ACR_CTRL);
438
439 value = AUDIO_N_RESETF | AUDIO_N_GENERATE_ALTERNATE |
440 AUDIO_N_VALUE(config->n - 1);
441 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N);
442
443 tegra_hdmi_writel(hdmi, ACR_SUBPACK_N(config->n) | ACR_ENABLE,
444 HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
445
446 value = ACR_SUBPACK_CTS(config->cts);
447 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
448
449 value = SPARE_HW_CTS | SPARE_FORCE_SW_CTS | SPARE_CTS_RESET_VAL(1);
450 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_SPARE);
451
452 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_AUDIO_N);
453 value &= ~AUDIO_N_RESETF;
454 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N);
455
456 if (of_device_is_compatible(node, "nvidia,tegra30-hdmi")) {
457 switch (hdmi->audio_freq) {
458 case 32000:
459 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0320;
460 break;
461
462 case 44100:
463 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0441;
464 break;
465
466 case 48000:
467 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0480;
468 break;
469
470 case 88200:
471 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0882;
472 break;
473
474 case 96000:
475 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0960;
476 break;
477
478 case 176400:
479 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_1764;
480 break;
481
482 case 192000:
483 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_1920;
484 break;
485 }
486
487 tegra_hdmi_writel(hdmi, config->aval, offset);
488 }
489
490 tegra_hdmi_setup_audio_fs_tables(hdmi);
491
492 return 0;
493}
494
Thierry Redingac24c222012-11-23 15:14:00 +0100495static inline unsigned long tegra_hdmi_subpack(const u8 *ptr, size_t size)
Thierry Redingedec4af2012-11-15 21:28:23 +0000496{
Thierry Redingac24c222012-11-23 15:14:00 +0100497 unsigned long value = 0;
Thierry Redingedec4af2012-11-15 21:28:23 +0000498 size_t i;
Thierry Redingedec4af2012-11-15 21:28:23 +0000499
Thierry Redingac24c222012-11-23 15:14:00 +0100500 for (i = size; i > 0; i--)
501 value = (value << 8) | ptr[i - 1];
Thierry Redingedec4af2012-11-15 21:28:23 +0000502
Thierry Redingac24c222012-11-23 15:14:00 +0100503 return value;
504}
Thierry Redingedec4af2012-11-15 21:28:23 +0000505
Thierry Redingac24c222012-11-23 15:14:00 +0100506static void tegra_hdmi_write_infopack(struct tegra_hdmi *hdmi, const void *data,
507 size_t size)
508{
509 const u8 *ptr = data;
510 unsigned long offset;
511 unsigned long value;
512 size_t i, j;
Thierry Redingedec4af2012-11-15 21:28:23 +0000513
Thierry Redingac24c222012-11-23 15:14:00 +0100514 switch (ptr[0]) {
515 case HDMI_INFOFRAME_TYPE_AVI:
516 offset = HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER;
517 break;
518
519 case HDMI_INFOFRAME_TYPE_AUDIO:
520 offset = HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER;
521 break;
522
523 case HDMI_INFOFRAME_TYPE_VENDOR:
524 offset = HDMI_NV_PDISP_HDMI_GENERIC_HEADER;
525 break;
526
527 default:
528 dev_err(hdmi->dev, "unsupported infoframe type: %02x\n",
529 ptr[0]);
530 return;
531 }
532
533 value = INFOFRAME_HEADER_TYPE(ptr[0]) |
534 INFOFRAME_HEADER_VERSION(ptr[1]) |
535 INFOFRAME_HEADER_LEN(ptr[2]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000536 tegra_hdmi_writel(hdmi, value, offset);
Thierry Redingac24c222012-11-23 15:14:00 +0100537 offset++;
Thierry Redingedec4af2012-11-15 21:28:23 +0000538
Thierry Redingac24c222012-11-23 15:14:00 +0100539 /*
540 * Each subpack contains 7 bytes, divided into:
541 * - subpack_low: bytes 0 - 3
542 * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00)
Thierry Redingedec4af2012-11-15 21:28:23 +0000543 */
Thierry Redingac24c222012-11-23 15:14:00 +0100544 for (i = 3, j = 0; i < size; i += 7, j += 8) {
545 size_t rem = size - i, num = min_t(size_t, rem, 4);
Thierry Redingedec4af2012-11-15 21:28:23 +0000546
Thierry Redingac24c222012-11-23 15:14:00 +0100547 value = tegra_hdmi_subpack(&ptr[i], num);
548 tegra_hdmi_writel(hdmi, value, offset++);
Thierry Redingedec4af2012-11-15 21:28:23 +0000549
Thierry Redingac24c222012-11-23 15:14:00 +0100550 num = min_t(size_t, rem - num, 3);
Thierry Redingedec4af2012-11-15 21:28:23 +0000551
Thierry Redingac24c222012-11-23 15:14:00 +0100552 value = tegra_hdmi_subpack(&ptr[i + 4], num);
553 tegra_hdmi_writel(hdmi, value, offset++);
Thierry Redingedec4af2012-11-15 21:28:23 +0000554 }
555}
556
557static void tegra_hdmi_setup_avi_infoframe(struct tegra_hdmi *hdmi,
558 struct drm_display_mode *mode)
559{
560 struct hdmi_avi_infoframe frame;
Thierry Redingac24c222012-11-23 15:14:00 +0100561 u8 buffer[17];
562 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000563
564 if (hdmi->dvi) {
565 tegra_hdmi_writel(hdmi, 0,
566 HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
567 return;
568 }
569
Thierry Redingac24c222012-11-23 15:14:00 +0100570 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
571 if (err < 0) {
572 dev_err(hdmi->dev, "failed to setup AVI infoframe: %zd\n", err);
573 return;
Thierry Redingedec4af2012-11-15 21:28:23 +0000574 }
575
Thierry Redingac24c222012-11-23 15:14:00 +0100576 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
577 if (err < 0) {
578 dev_err(hdmi->dev, "failed to pack AVI infoframe: %zd\n", err);
579 return;
580 }
581
582 tegra_hdmi_write_infopack(hdmi, buffer, err);
Thierry Redingedec4af2012-11-15 21:28:23 +0000583
584 tegra_hdmi_writel(hdmi, INFOFRAME_CTRL_ENABLE,
585 HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
586}
587
588static void tegra_hdmi_setup_audio_infoframe(struct tegra_hdmi *hdmi)
589{
590 struct hdmi_audio_infoframe frame;
Thierry Redingac24c222012-11-23 15:14:00 +0100591 u8 buffer[14];
592 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000593
594 if (hdmi->dvi) {
595 tegra_hdmi_writel(hdmi, 0,
596 HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
597 return;
598 }
599
Thierry Redingac24c222012-11-23 15:14:00 +0100600 err = hdmi_audio_infoframe_init(&frame);
601 if (err < 0) {
Thierry Redingef284c72013-10-16 19:51:22 +0200602 dev_err(hdmi->dev, "failed to setup audio infoframe: %zd\n",
Thierry Redingac24c222012-11-23 15:14:00 +0100603 err);
604 return;
605 }
Thierry Redingedec4af2012-11-15 21:28:23 +0000606
Thierry Redingac24c222012-11-23 15:14:00 +0100607 frame.channels = 2;
608
609 err = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
610 if (err < 0) {
611 dev_err(hdmi->dev, "failed to pack audio infoframe: %zd\n",
612 err);
613 return;
614 }
615
616 /*
617 * The audio infoframe has only one set of subpack registers, so the
618 * infoframe needs to be truncated. One set of subpack registers can
619 * contain 7 bytes. Including the 3 byte header only the first 10
620 * bytes can be programmed.
621 */
Thierry Redingef284c72013-10-16 19:51:22 +0200622 tegra_hdmi_write_infopack(hdmi, buffer, min_t(size_t, 10, err));
Thierry Redingedec4af2012-11-15 21:28:23 +0000623
624 tegra_hdmi_writel(hdmi, INFOFRAME_CTRL_ENABLE,
625 HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
626}
627
628static void tegra_hdmi_setup_stereo_infoframe(struct tegra_hdmi *hdmi)
629{
Lespiau, Damienae84b902013-08-19 16:59:02 +0100630 struct hdmi_vendor_infoframe frame;
Thierry Redingedec4af2012-11-15 21:28:23 +0000631 unsigned long value;
Thierry Redingac24c222012-11-23 15:14:00 +0100632 u8 buffer[10];
633 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000634
635 if (!hdmi->stereo) {
636 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
637 value &= ~GENERIC_CTRL_ENABLE;
638 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
639 return;
640 }
641
Lespiau, Damienae84b902013-08-19 16:59:02 +0100642 hdmi_vendor_infoframe_init(&frame);
Lespiau, Damiena26a58e82013-08-19 16:58:59 +0100643 frame.s3d_struct = HDMI_3D_STRUCTURE_FRAME_PACKING;
Thierry Redingac24c222012-11-23 15:14:00 +0100644
Lespiau, Damienae84b902013-08-19 16:59:02 +0100645 err = hdmi_vendor_infoframe_pack(&frame, buffer, sizeof(buffer));
Thierry Redingac24c222012-11-23 15:14:00 +0100646 if (err < 0) {
647 dev_err(hdmi->dev, "failed to pack vendor infoframe: %zd\n",
648 err);
649 return;
650 }
651
652 tegra_hdmi_write_infopack(hdmi, buffer, err);
Thierry Redingedec4af2012-11-15 21:28:23 +0000653
654 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
655 value |= GENERIC_CTRL_ENABLE;
656 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
657}
658
659static void tegra_hdmi_setup_tmds(struct tegra_hdmi *hdmi,
660 const struct tmds_config *tmds)
661{
662 unsigned long value;
663
664 tegra_hdmi_writel(hdmi, tmds->pll0, HDMI_NV_PDISP_SOR_PLL0);
665 tegra_hdmi_writel(hdmi, tmds->pll1, HDMI_NV_PDISP_SOR_PLL1);
666 tegra_hdmi_writel(hdmi, tmds->pe_current, HDMI_NV_PDISP_PE_CURRENT);
667
Thierry Reding59af0592013-10-14 09:43:05 +0200668 tegra_hdmi_writel(hdmi, tmds->drive_current,
669 HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
670
671 value = tegra_hdmi_readl(hdmi, hdmi->config->fuse_override_offset);
672 value |= hdmi->config->fuse_override_value;
673 tegra_hdmi_writel(hdmi, value, hdmi->config->fuse_override_offset);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +0200674
675 if (hdmi->config->has_sor_io_peak_current)
676 tegra_hdmi_writel(hdmi, tmds->peak_current,
677 HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +0000678}
679
Mikko Perttunen9f159122013-08-28 18:48:38 +0300680static bool tegra_output_is_hdmi(struct tegra_output *output)
681{
682 struct edid *edid;
683
684 if (!output->connector.edid_blob_ptr)
685 return false;
686
687 edid = (struct edid *)output->connector.edid_blob_ptr->data;
688
689 return drm_detect_hdmi_monitor(edid);
690}
691
Thierry Redingedec4af2012-11-15 21:28:23 +0000692static int tegra_output_hdmi_enable(struct tegra_output *output)
693{
694 unsigned int h_sync_width, h_front_porch, h_back_porch, i, rekey;
695 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
696 struct drm_display_mode *mode = &dc->base.mode;
697 struct tegra_hdmi *hdmi = to_hdmi(output);
698 struct device_node *node = hdmi->dev->of_node;
699 unsigned int pulse_start, div82, pclk;
Thierry Redingedec4af2012-11-15 21:28:23 +0000700 unsigned long value;
701 int retries = 1000;
702 int err;
703
Thierry Reding365765f2013-10-29 16:00:42 +0100704 if (hdmi->enabled)
705 return 0;
706
Mikko Perttunen9f159122013-08-28 18:48:38 +0300707 hdmi->dvi = !tegra_output_is_hdmi(output);
708
Thierry Redingedec4af2012-11-15 21:28:23 +0000709 pclk = mode->clock * 1000;
710 h_sync_width = mode->hsync_end - mode->hsync_start;
Lucas Stach40495082012-12-19 21:38:52 +0000711 h_back_porch = mode->htotal - mode->hsync_end;
712 h_front_porch = mode->hsync_start - mode->hdisplay;
Thierry Redingedec4af2012-11-15 21:28:23 +0000713
Thierry Redingedec4af2012-11-15 21:28:23 +0000714 err = regulator_enable(hdmi->pll);
715 if (err < 0) {
716 dev_err(hdmi->dev, "failed to enable PLL regulator: %d\n", err);
717 return err;
718 }
719
Thierry Reding88685682014-04-16 10:24:12 +0200720 err = regulator_enable(hdmi->vdd);
721 if (err < 0) {
722 dev_err(hdmi->dev, "failed to enable VDD regulator: %d\n", err);
723 return err;
724 }
725
Thierry Redingedec4af2012-11-15 21:28:23 +0000726 err = clk_set_rate(hdmi->clk, pclk);
727 if (err < 0)
728 return err;
729
Thierry Redingd06e7f8f62014-04-16 10:43:41 +0200730 err = clk_prepare_enable(hdmi->clk);
Thierry Redingedec4af2012-11-15 21:28:23 +0000731 if (err < 0) {
732 dev_err(hdmi->dev, "failed to enable clock: %d\n", err);
733 return err;
734 }
735
Stephen Warrenca480802013-11-06 16:20:54 -0700736 reset_control_assert(hdmi->rst);
Thierry Redingedec4af2012-11-15 21:28:23 +0000737 usleep_range(1000, 2000);
Stephen Warrenca480802013-11-06 16:20:54 -0700738 reset_control_deassert(hdmi->rst);
Thierry Redingedec4af2012-11-15 21:28:23 +0000739
Thierry Reding8c8282c2014-04-16 10:46:24 +0200740 /* power up sequence */
741 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0);
742 value &= ~SOR_PLL_PDBG;
743 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0);
744
745 usleep_range(10, 20);
746
747 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0);
748 value &= ~SOR_PLL_PWR;
749 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0);
750
Thierry Redingedec4af2012-11-15 21:28:23 +0000751 tegra_dc_writel(dc, VSYNC_H_POSITION(1),
752 DC_DISP_DISP_TIMING_OPTIONS);
753 tegra_dc_writel(dc, DITHER_CONTROL_DISABLE | BASE_COLOR_SIZE888,
754 DC_DISP_DISP_COLOR_CONTROL);
755
756 /* video_preamble uses h_pulse2 */
757 pulse_start = 1 + h_sync_width + h_back_porch - 10;
758
759 tegra_dc_writel(dc, H_PULSE_2_ENABLE, DC_DISP_DISP_SIGNAL_OPTIONS0);
760
761 value = PULSE_MODE_NORMAL | PULSE_POLARITY_HIGH | PULSE_QUAL_VACTIVE |
762 PULSE_LAST_END_A;
763 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL);
764
765 value = PULSE_START(pulse_start) | PULSE_END(pulse_start + 8);
766 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A);
767
768 value = VSYNC_WINDOW_END(0x210) | VSYNC_WINDOW_START(0x200) |
769 VSYNC_WINDOW_ENABLE;
770 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
771
772 if (dc->pipe)
773 value = HDMI_SRC_DISPLAYB;
774 else
775 value = HDMI_SRC_DISPLAYA;
776
777 if ((mode->hdisplay == 720) && ((mode->vdisplay == 480) ||
778 (mode->vdisplay == 576)))
779 tegra_hdmi_writel(hdmi,
780 value | ARM_VIDEO_RANGE_FULL,
781 HDMI_NV_PDISP_INPUT_CONTROL);
782 else
783 tegra_hdmi_writel(hdmi,
784 value | ARM_VIDEO_RANGE_LIMITED,
785 HDMI_NV_PDISP_INPUT_CONTROL);
786
787 div82 = clk_get_rate(hdmi->clk) / 1000000 * 4;
788 value = SOR_REFCLK_DIV_INT(div82 >> 2) | SOR_REFCLK_DIV_FRAC(div82);
789 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_REFCLK);
790
791 if (!hdmi->dvi) {
792 err = tegra_hdmi_setup_audio(hdmi, pclk);
793 if (err < 0)
794 hdmi->dvi = true;
795 }
796
797 if (of_device_is_compatible(node, "nvidia,tegra20-hdmi")) {
798 /*
799 * TODO: add ELD support
800 */
801 }
802
803 rekey = HDMI_REKEY_DEFAULT;
804 value = HDMI_CTRL_REKEY(rekey);
805 value |= HDMI_CTRL_MAX_AC_PACKET((h_sync_width + h_back_porch +
806 h_front_porch - rekey - 18) / 32);
807
808 if (!hdmi->dvi)
809 value |= HDMI_CTRL_ENABLE;
810
811 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_CTRL);
812
813 if (hdmi->dvi)
814 tegra_hdmi_writel(hdmi, 0x0,
815 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
816 else
817 tegra_hdmi_writel(hdmi, GENERIC_CTRL_AUDIO,
818 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
819
820 tegra_hdmi_setup_avi_infoframe(hdmi, mode);
821 tegra_hdmi_setup_audio_infoframe(hdmi);
822 tegra_hdmi_setup_stereo_infoframe(hdmi);
823
824 /* TMDS CONFIG */
Thierry Reding59af0592013-10-14 09:43:05 +0200825 for (i = 0; i < hdmi->config->num_tmds; i++) {
826 if (pclk <= hdmi->config->tmds[i].pclk) {
827 tegra_hdmi_setup_tmds(hdmi, &hdmi->config->tmds[i]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000828 break;
829 }
830 }
831
832 tegra_hdmi_writel(hdmi,
833 SOR_SEQ_CTL_PU_PC(0) |
834 SOR_SEQ_PU_PC_ALT(0) |
835 SOR_SEQ_PD_PC(8) |
836 SOR_SEQ_PD_PC_ALT(8),
837 HDMI_NV_PDISP_SOR_SEQ_CTL);
838
839 value = SOR_SEQ_INST_WAIT_TIME(1) |
840 SOR_SEQ_INST_WAIT_UNITS_VSYNC |
841 SOR_SEQ_INST_HALT |
842 SOR_SEQ_INST_PIN_A_LOW |
843 SOR_SEQ_INST_PIN_B_LOW |
844 SOR_SEQ_INST_DRIVE_PWM_OUT_LO;
845
846 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(0));
847 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(8));
848
849 value = 0x1c800;
850 value &= ~SOR_CSTM_ROTCLK(~0);
851 value |= SOR_CSTM_ROTCLK(2);
852 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_CSTM);
853
Thierry Redingedec4af2012-11-15 21:28:23 +0000854 /* start SOR */
855 tegra_hdmi_writel(hdmi,
856 SOR_PWR_NORMAL_STATE_PU |
857 SOR_PWR_NORMAL_START_NORMAL |
858 SOR_PWR_SAFE_STATE_PD |
859 SOR_PWR_SETTING_NEW_TRIGGER,
860 HDMI_NV_PDISP_SOR_PWR);
861 tegra_hdmi_writel(hdmi,
862 SOR_PWR_NORMAL_STATE_PU |
863 SOR_PWR_NORMAL_START_NORMAL |
864 SOR_PWR_SAFE_STATE_PD |
865 SOR_PWR_SETTING_NEW_DONE,
866 HDMI_NV_PDISP_SOR_PWR);
867
868 do {
869 BUG_ON(--retries < 0);
870 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PWR);
871 } while (value & SOR_PWR_SETTING_NEW_PENDING);
872
873 value = SOR_STATE_ASY_CRCMODE_COMPLETE |
874 SOR_STATE_ASY_OWNER_HEAD0 |
875 SOR_STATE_ASY_SUBOWNER_BOTH |
876 SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A |
877 SOR_STATE_ASY_DEPOL_POS;
878
879 /* setup sync polarities */
880 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
881 value |= SOR_STATE_ASY_HSYNCPOL_POS;
882
883 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
884 value |= SOR_STATE_ASY_HSYNCPOL_NEG;
885
886 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
887 value |= SOR_STATE_ASY_VSYNCPOL_POS;
888
889 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
890 value |= SOR_STATE_ASY_VSYNCPOL_NEG;
891
892 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE2);
893
894 value = SOR_STATE_ASY_HEAD_OPMODE_AWAKE | SOR_STATE_ASY_ORMODE_NORMAL;
895 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE1);
896
897 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
898 tegra_hdmi_writel(hdmi, SOR_STATE_UPDATE, HDMI_NV_PDISP_SOR_STATE0);
899 tegra_hdmi_writel(hdmi, value | SOR_STATE_ATTACHED,
900 HDMI_NV_PDISP_SOR_STATE1);
901 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
902
Thierry Reding72d30282013-12-12 11:06:55 +0100903 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
904 value |= HDMI_ENABLE;
905 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
Thierry Redingedec4af2012-11-15 21:28:23 +0000906
Thierry Reding72d30282013-12-12 11:06:55 +0100907 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
908 value &= ~DISP_CTRL_MODE_MASK;
909 value |= DISP_CTRL_MODE_C_DISPLAY;
Thierry Redingedec4af2012-11-15 21:28:23 +0000910 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
911
Thierry Reding72d30282013-12-12 11:06:55 +0100912 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
913 value |= PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
914 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
915 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
916
Thierry Redingedec4af2012-11-15 21:28:23 +0000917 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
918 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
919
920 /* TODO: add HDCP support */
921
Thierry Reding365765f2013-10-29 16:00:42 +0100922 hdmi->enabled = true;
923
Thierry Redingedec4af2012-11-15 21:28:23 +0000924 return 0;
925}
926
927static int tegra_output_hdmi_disable(struct tegra_output *output)
928{
Thierry Reding72d30282013-12-12 11:06:55 +0100929 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
Thierry Redingedec4af2012-11-15 21:28:23 +0000930 struct tegra_hdmi *hdmi = to_hdmi(output);
Thierry Reding72d30282013-12-12 11:06:55 +0100931 unsigned long value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000932
Thierry Reding365765f2013-10-29 16:00:42 +0100933 if (!hdmi->enabled)
934 return 0;
935
Thierry Reding72d30282013-12-12 11:06:55 +0100936 /*
937 * The following accesses registers of the display controller, so make
938 * sure it's only executed when the output is attached to one.
939 */
940 if (dc) {
941 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
942 value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
943 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE);
944 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
945
946 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
947 value &= ~DISP_CTRL_MODE_MASK;
948 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
949
950 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
951 value &= ~HDMI_ENABLE;
952 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
953
954 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
955 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
956 }
957
Thierry Redingd06e7f8f62014-04-16 10:43:41 +0200958 clk_disable_unprepare(hdmi->clk);
Stephen Warrenca480802013-11-06 16:20:54 -0700959 reset_control_assert(hdmi->rst);
Thierry Redingfb50a112014-02-28 16:57:34 +0100960 regulator_disable(hdmi->vdd);
Thierry Reding88685682014-04-16 10:24:12 +0200961 regulator_disable(hdmi->pll);
Thierry Redingedec4af2012-11-15 21:28:23 +0000962
Thierry Reding365765f2013-10-29 16:00:42 +0100963 hdmi->enabled = false;
964
Thierry Redingedec4af2012-11-15 21:28:23 +0000965 return 0;
966}
967
968static int tegra_output_hdmi_setup_clock(struct tegra_output *output,
969 struct clk *clk, unsigned long pclk)
970{
971 struct tegra_hdmi *hdmi = to_hdmi(output);
972 struct clk *base;
973 int err;
974
975 err = clk_set_parent(clk, hdmi->clk_parent);
976 if (err < 0) {
977 dev_err(output->dev, "failed to set parent: %d\n", err);
978 return err;
979 }
980
981 base = clk_get_parent(hdmi->clk_parent);
982
983 /*
984 * This assumes that the parent clock is pll_d_out0 or pll_d2_out
985 * respectively, each of which divides the base pll_d by 2.
986 */
987 err = clk_set_rate(base, pclk * 2);
988 if (err < 0)
989 dev_err(output->dev,
990 "failed to set base clock rate to %lu Hz\n",
991 pclk * 2);
992
993 return 0;
994}
995
996static int tegra_output_hdmi_check_mode(struct tegra_output *output,
997 struct drm_display_mode *mode,
998 enum drm_mode_status *status)
999{
1000 struct tegra_hdmi *hdmi = to_hdmi(output);
1001 unsigned long pclk = mode->clock * 1000;
1002 struct clk *parent;
1003 long err;
1004
1005 parent = clk_get_parent(hdmi->clk_parent);
1006
1007 err = clk_round_rate(parent, pclk * 4);
Paul Walmsley23a0e272013-12-09 18:00:12 -08001008 if (err <= 0)
Thierry Redingedec4af2012-11-15 21:28:23 +00001009 *status = MODE_NOCLOCK;
1010 else
1011 *status = MODE_OK;
1012
1013 return 0;
1014}
1015
1016static const struct tegra_output_ops hdmi_ops = {
1017 .enable = tegra_output_hdmi_enable,
1018 .disable = tegra_output_hdmi_disable,
1019 .setup_clock = tegra_output_hdmi_setup_clock,
1020 .check_mode = tegra_output_hdmi_check_mode,
1021};
1022
1023static int tegra_hdmi_show_regs(struct seq_file *s, void *data)
1024{
1025 struct drm_info_node *node = s->private;
1026 struct tegra_hdmi *hdmi = node->info_ent->data;
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001027 int err;
1028
Thierry Redingd06e7f8f62014-04-16 10:43:41 +02001029 err = clk_prepare_enable(hdmi->clk);
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001030 if (err)
1031 return err;
Thierry Redingedec4af2012-11-15 21:28:23 +00001032
1033#define DUMP_REG(name) \
1034 seq_printf(s, "%-56s %#05x %08lx\n", #name, name, \
1035 tegra_hdmi_readl(hdmi, name))
1036
1037 DUMP_REG(HDMI_CTXSW);
1038 DUMP_REG(HDMI_NV_PDISP_SOR_STATE0);
1039 DUMP_REG(HDMI_NV_PDISP_SOR_STATE1);
1040 DUMP_REG(HDMI_NV_PDISP_SOR_STATE2);
1041 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_MSB);
1042 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_LSB);
1043 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_MSB);
1044 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_LSB);
1045 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_MSB);
1046 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_LSB);
1047 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_MSB);
1048 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_LSB);
1049 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_MSB);
1050 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_LSB);
1051 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_MSB);
1052 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_LSB);
1053 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CTRL);
1054 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CMODE);
1055 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_MSB);
1056 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_LSB);
1057 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_MSB);
1058 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB2);
1059 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB1);
1060 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_RI);
1061 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_MSB);
1062 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_LSB);
1063 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU0);
1064 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU_RDATA0);
1065 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU1);
1066 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU2);
1067 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
1068 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_STATUS);
1069 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER);
1070 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_LOW);
1071 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_HIGH);
1072 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
1073 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_STATUS);
1074 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER);
1075 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_LOW);
1076 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_HIGH);
1077 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_LOW);
1078 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_HIGH);
1079 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
1080 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_STATUS);
1081 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_HEADER);
1082 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_LOW);
1083 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_HIGH);
1084 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_LOW);
1085 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_HIGH);
1086 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_LOW);
1087 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_HIGH);
1088 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_LOW);
1089 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_HIGH);
1090 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_CTRL);
1091 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_LOW);
1092 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_HIGH);
1093 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
1094 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
1095 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_LOW);
1096 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_HIGH);
1097 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_LOW);
1098 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_HIGH);
1099 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_LOW);
1100 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_HIGH);
1101 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_LOW);
1102 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_HIGH);
1103 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_LOW);
1104 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_HIGH);
1105 DUMP_REG(HDMI_NV_PDISP_HDMI_CTRL);
1106 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_KEEPOUT);
1107 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
1108 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_CTRL);
1109 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_STATUS);
1110 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_SUBPACK);
1111 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS1);
1112 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS2);
1113 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU0);
1114 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1);
1115 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1_RDATA);
1116 DUMP_REG(HDMI_NV_PDISP_HDMI_SPARE);
1117 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS1);
1118 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS2);
1119 DUMP_REG(HDMI_NV_PDISP_HDMI_HDCPRIF_ROM_CTRL);
1120 DUMP_REG(HDMI_NV_PDISP_SOR_CAP);
1121 DUMP_REG(HDMI_NV_PDISP_SOR_PWR);
1122 DUMP_REG(HDMI_NV_PDISP_SOR_TEST);
1123 DUMP_REG(HDMI_NV_PDISP_SOR_PLL0);
1124 DUMP_REG(HDMI_NV_PDISP_SOR_PLL1);
1125 DUMP_REG(HDMI_NV_PDISP_SOR_PLL2);
1126 DUMP_REG(HDMI_NV_PDISP_SOR_CSTM);
1127 DUMP_REG(HDMI_NV_PDISP_SOR_LVDS);
1128 DUMP_REG(HDMI_NV_PDISP_SOR_CRCA);
1129 DUMP_REG(HDMI_NV_PDISP_SOR_CRCB);
1130 DUMP_REG(HDMI_NV_PDISP_SOR_BLANK);
1131 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_CTL);
1132 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(0));
1133 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(1));
1134 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(2));
1135 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(3));
1136 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(4));
1137 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(5));
1138 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(6));
1139 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(7));
1140 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(8));
1141 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(9));
1142 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(10));
1143 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(11));
1144 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(12));
1145 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(13));
1146 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(14));
1147 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(15));
1148 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA0);
1149 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA1);
1150 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA0);
1151 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA1);
1152 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA0);
1153 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA1);
1154 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA0);
1155 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA1);
1156 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA0);
1157 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA1);
1158 DUMP_REG(HDMI_NV_PDISP_SOR_TRIG);
1159 DUMP_REG(HDMI_NV_PDISP_SOR_MSCHECK);
1160 DUMP_REG(HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
1161 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG0);
1162 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG1);
1163 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG2);
1164 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(0));
1165 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(1));
1166 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(2));
1167 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(3));
1168 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(4));
1169 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(5));
1170 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(6));
1171 DUMP_REG(HDMI_NV_PDISP_AUDIO_PULSE_WIDTH);
1172 DUMP_REG(HDMI_NV_PDISP_AUDIO_THRESHOLD);
1173 DUMP_REG(HDMI_NV_PDISP_AUDIO_CNTRL0);
1174 DUMP_REG(HDMI_NV_PDISP_AUDIO_N);
1175 DUMP_REG(HDMI_NV_PDISP_HDCPRIF_ROM_TIMING);
1176 DUMP_REG(HDMI_NV_PDISP_SOR_REFCLK);
1177 DUMP_REG(HDMI_NV_PDISP_CRC_CONTROL);
1178 DUMP_REG(HDMI_NV_PDISP_INPUT_CONTROL);
1179 DUMP_REG(HDMI_NV_PDISP_SCRATCH);
1180 DUMP_REG(HDMI_NV_PDISP_PE_CURRENT);
1181 DUMP_REG(HDMI_NV_PDISP_KEY_CTRL);
1182 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG0);
1183 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG1);
1184 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG2);
1185 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_0);
1186 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_1);
1187 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_2);
1188 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_3);
1189 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_TRIG);
1190 DUMP_REG(HDMI_NV_PDISP_KEY_SKEY_INDEX);
1191 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
1192 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR);
1193 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001194 DUMP_REG(HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +00001195
1196#undef DUMP_REG
1197
Thierry Redingd06e7f8f62014-04-16 10:43:41 +02001198 clk_disable_unprepare(hdmi->clk);
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001199
Thierry Redingedec4af2012-11-15 21:28:23 +00001200 return 0;
1201}
1202
1203static struct drm_info_list debugfs_files[] = {
1204 { "regs", tegra_hdmi_show_regs, 0, NULL },
1205};
1206
1207static int tegra_hdmi_debugfs_init(struct tegra_hdmi *hdmi,
1208 struct drm_minor *minor)
1209{
1210 unsigned int i;
1211 int err;
1212
1213 hdmi->debugfs = debugfs_create_dir("hdmi", minor->debugfs_root);
1214 if (!hdmi->debugfs)
1215 return -ENOMEM;
1216
1217 hdmi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
1218 GFP_KERNEL);
1219 if (!hdmi->debugfs_files) {
1220 err = -ENOMEM;
1221 goto remove;
1222 }
1223
1224 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
1225 hdmi->debugfs_files[i].data = hdmi;
1226
1227 err = drm_debugfs_create_files(hdmi->debugfs_files,
1228 ARRAY_SIZE(debugfs_files),
1229 hdmi->debugfs, minor);
1230 if (err < 0)
1231 goto free;
1232
1233 hdmi->minor = minor;
1234
1235 return 0;
1236
1237free:
1238 kfree(hdmi->debugfs_files);
1239 hdmi->debugfs_files = NULL;
1240remove:
1241 debugfs_remove(hdmi->debugfs);
1242 hdmi->debugfs = NULL;
1243
1244 return err;
1245}
1246
1247static int tegra_hdmi_debugfs_exit(struct tegra_hdmi *hdmi)
1248{
1249 drm_debugfs_remove_files(hdmi->debugfs_files, ARRAY_SIZE(debugfs_files),
1250 hdmi->minor);
1251 hdmi->minor = NULL;
1252
1253 kfree(hdmi->debugfs_files);
1254 hdmi->debugfs_files = NULL;
1255
1256 debugfs_remove(hdmi->debugfs);
1257 hdmi->debugfs = NULL;
1258
1259 return 0;
1260}
1261
Thierry Reding53fa7f72013-09-24 15:35:40 +02001262static int tegra_hdmi_init(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001263{
Thierry Reding776dc382013-10-14 14:43:22 +02001264 struct tegra_drm *tegra = dev_get_drvdata(client->parent);
1265 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001266 int err;
1267
1268 hdmi->output.type = TEGRA_OUTPUT_HDMI;
1269 hdmi->output.dev = client->dev;
1270 hdmi->output.ops = &hdmi_ops;
1271
Thierry Reding776dc382013-10-14 14:43:22 +02001272 err = tegra_output_init(tegra->drm, &hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001273 if (err < 0) {
1274 dev_err(client->dev, "output setup failed: %d\n", err);
1275 return err;
1276 }
1277
1278 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding776dc382013-10-14 14:43:22 +02001279 err = tegra_hdmi_debugfs_init(hdmi, tegra->drm->primary);
Thierry Redingedec4af2012-11-15 21:28:23 +00001280 if (err < 0)
1281 dev_err(client->dev, "debugfs setup failed: %d\n", err);
1282 }
1283
Thierry Redingfb50a112014-02-28 16:57:34 +01001284 err = regulator_enable(hdmi->hdmi);
1285 if (err < 0) {
1286 dev_err(client->dev, "failed to enable HDMI regulator: %d\n",
1287 err);
1288 return err;
1289 }
1290
Thierry Redingedec4af2012-11-15 21:28:23 +00001291 return 0;
1292}
1293
Thierry Reding53fa7f72013-09-24 15:35:40 +02001294static int tegra_hdmi_exit(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001295{
Thierry Reding776dc382013-10-14 14:43:22 +02001296 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001297 int err;
1298
Thierry Redingfb50a112014-02-28 16:57:34 +01001299 regulator_disable(hdmi->hdmi);
1300
Thierry Redingedec4af2012-11-15 21:28:23 +00001301 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
1302 err = tegra_hdmi_debugfs_exit(hdmi);
1303 if (err < 0)
1304 dev_err(client->dev, "debugfs cleanup failed: %d\n",
1305 err);
1306 }
1307
1308 err = tegra_output_disable(&hdmi->output);
1309 if (err < 0) {
1310 dev_err(client->dev, "output failed to disable: %d\n", err);
1311 return err;
1312 }
1313
1314 err = tegra_output_exit(&hdmi->output);
1315 if (err < 0) {
1316 dev_err(client->dev, "output cleanup failed: %d\n", err);
1317 return err;
1318 }
1319
1320 return 0;
1321}
1322
1323static const struct host1x_client_ops hdmi_client_ops = {
Thierry Reding53fa7f72013-09-24 15:35:40 +02001324 .init = tegra_hdmi_init,
1325 .exit = tegra_hdmi_exit,
Thierry Redingedec4af2012-11-15 21:28:23 +00001326};
1327
Thierry Reding59af0592013-10-14 09:43:05 +02001328static const struct tegra_hdmi_config tegra20_hdmi_config = {
1329 .tmds = tegra20_tmds_config,
1330 .num_tmds = ARRAY_SIZE(tegra20_tmds_config),
1331 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1332 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001333 .has_sor_io_peak_current = false,
Thierry Reding59af0592013-10-14 09:43:05 +02001334};
1335
1336static const struct tegra_hdmi_config tegra30_hdmi_config = {
1337 .tmds = tegra30_tmds_config,
1338 .num_tmds = ARRAY_SIZE(tegra30_tmds_config),
1339 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1340 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001341 .has_sor_io_peak_current = false,
1342};
1343
1344static const struct tegra_hdmi_config tegra114_hdmi_config = {
1345 .tmds = tegra114_tmds_config,
1346 .num_tmds = ARRAY_SIZE(tegra114_tmds_config),
1347 .fuse_override_offset = HDMI_NV_PDISP_SOR_PAD_CTLS0,
1348 .fuse_override_value = 1 << 31,
1349 .has_sor_io_peak_current = true,
Thierry Reding59af0592013-10-14 09:43:05 +02001350};
1351
1352static const struct of_device_id tegra_hdmi_of_match[] = {
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001353 { .compatible = "nvidia,tegra114-hdmi", .data = &tegra114_hdmi_config },
Thierry Reding59af0592013-10-14 09:43:05 +02001354 { .compatible = "nvidia,tegra30-hdmi", .data = &tegra30_hdmi_config },
1355 { .compatible = "nvidia,tegra20-hdmi", .data = &tegra20_hdmi_config },
1356 { },
1357};
1358
Thierry Redingedec4af2012-11-15 21:28:23 +00001359static int tegra_hdmi_probe(struct platform_device *pdev)
1360{
Thierry Reding59af0592013-10-14 09:43:05 +02001361 const struct of_device_id *match;
Thierry Redingedec4af2012-11-15 21:28:23 +00001362 struct tegra_hdmi *hdmi;
1363 struct resource *regs;
1364 int err;
1365
Thierry Reding59af0592013-10-14 09:43:05 +02001366 match = of_match_node(tegra_hdmi_of_match, pdev->dev.of_node);
1367 if (!match)
1368 return -ENODEV;
1369
Thierry Redingedec4af2012-11-15 21:28:23 +00001370 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
1371 if (!hdmi)
1372 return -ENOMEM;
1373
Thierry Reding59af0592013-10-14 09:43:05 +02001374 hdmi->config = match->data;
Thierry Redingedec4af2012-11-15 21:28:23 +00001375 hdmi->dev = &pdev->dev;
1376 hdmi->audio_source = AUTO;
1377 hdmi->audio_freq = 44100;
1378 hdmi->stereo = false;
1379 hdmi->dvi = false;
1380
1381 hdmi->clk = devm_clk_get(&pdev->dev, NULL);
1382 if (IS_ERR(hdmi->clk)) {
1383 dev_err(&pdev->dev, "failed to get clock\n");
1384 return PTR_ERR(hdmi->clk);
1385 }
1386
Stephen Warrenca480802013-11-06 16:20:54 -07001387 hdmi->rst = devm_reset_control_get(&pdev->dev, "hdmi");
1388 if (IS_ERR(hdmi->rst)) {
1389 dev_err(&pdev->dev, "failed to get reset\n");
1390 return PTR_ERR(hdmi->rst);
1391 }
1392
Thierry Redingedec4af2012-11-15 21:28:23 +00001393 hdmi->clk_parent = devm_clk_get(&pdev->dev, "parent");
1394 if (IS_ERR(hdmi->clk_parent))
1395 return PTR_ERR(hdmi->clk_parent);
1396
Thierry Redingedec4af2012-11-15 21:28:23 +00001397 err = clk_set_parent(hdmi->clk, hdmi->clk_parent);
1398 if (err < 0) {
1399 dev_err(&pdev->dev, "failed to setup clocks: %d\n", err);
1400 return err;
1401 }
1402
Thierry Redingfb50a112014-02-28 16:57:34 +01001403 hdmi->hdmi = devm_regulator_get(&pdev->dev, "hdmi");
1404 if (IS_ERR(hdmi->hdmi)) {
1405 dev_err(&pdev->dev, "failed to get HDMI regulator\n");
1406 return PTR_ERR(hdmi->hdmi);
1407 }
1408
Thierry Redingedec4af2012-11-15 21:28:23 +00001409 hdmi->pll = devm_regulator_get(&pdev->dev, "pll");
1410 if (IS_ERR(hdmi->pll)) {
1411 dev_err(&pdev->dev, "failed to get PLL regulator\n");
1412 return PTR_ERR(hdmi->pll);
1413 }
1414
Thierry Reding88685682014-04-16 10:24:12 +02001415 hdmi->vdd = devm_regulator_get(&pdev->dev, "vdd");
1416 if (IS_ERR(hdmi->vdd)) {
1417 dev_err(&pdev->dev, "failed to get VDD regulator\n");
1418 return PTR_ERR(hdmi->vdd);
1419 }
1420
Thierry Redingedec4af2012-11-15 21:28:23 +00001421 hdmi->output.dev = &pdev->dev;
1422
Thierry Reding59d29c02013-10-14 14:26:42 +02001423 err = tegra_output_probe(&hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001424 if (err < 0)
1425 return err;
1426
1427 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Thierry Redingd4ed6022013-01-21 11:09:02 +01001428 hdmi->regs = devm_ioremap_resource(&pdev->dev, regs);
1429 if (IS_ERR(hdmi->regs))
1430 return PTR_ERR(hdmi->regs);
Thierry Redingedec4af2012-11-15 21:28:23 +00001431
1432 err = platform_get_irq(pdev, 0);
1433 if (err < 0)
1434 return err;
1435
1436 hdmi->irq = err;
1437
Thierry Reding776dc382013-10-14 14:43:22 +02001438 INIT_LIST_HEAD(&hdmi->client.list);
1439 hdmi->client.ops = &hdmi_client_ops;
1440 hdmi->client.dev = &pdev->dev;
Thierry Redingedec4af2012-11-15 21:28:23 +00001441
Thierry Reding776dc382013-10-14 14:43:22 +02001442 err = host1x_client_register(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001443 if (err < 0) {
1444 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1445 err);
1446 return err;
1447 }
1448
1449 platform_set_drvdata(pdev, hdmi);
1450
1451 return 0;
1452}
1453
1454static int tegra_hdmi_remove(struct platform_device *pdev)
1455{
Thierry Redingedec4af2012-11-15 21:28:23 +00001456 struct tegra_hdmi *hdmi = platform_get_drvdata(pdev);
1457 int err;
1458
Thierry Reding776dc382013-10-14 14:43:22 +02001459 err = host1x_client_unregister(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001460 if (err < 0) {
1461 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1462 err);
1463 return err;
1464 }
1465
Thierry Reding59d29c02013-10-14 14:26:42 +02001466 err = tegra_output_remove(&hdmi->output);
1467 if (err < 0) {
1468 dev_err(&pdev->dev, "failed to remove output: %d\n", err);
1469 return err;
1470 }
1471
Thierry Redingd06e7f8f62014-04-16 10:43:41 +02001472 clk_disable_unprepare(hdmi->clk_parent);
1473 clk_disable_unprepare(hdmi->clk);
Thierry Redingedec4af2012-11-15 21:28:23 +00001474
1475 return 0;
1476}
1477
Thierry Redingedec4af2012-11-15 21:28:23 +00001478struct platform_driver tegra_hdmi_driver = {
1479 .driver = {
1480 .name = "tegra-hdmi",
1481 .owner = THIS_MODULE,
1482 .of_match_table = tegra_hdmi_of_match,
1483 },
1484 .probe = tegra_hdmi_probe,
1485 .remove = tegra_hdmi_remove,
1486};