blob: 8b797913470a6df0b94c5318e39c9f38547591d3 [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 *vdd;
47 struct regulator *pll;
48
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 Redingfb50a112014-02-28 16:57:34 +0100714 err = regulator_enable(hdmi->vdd);
715 if (err < 0) {
716 dev_err(hdmi->dev, "failed to enable VDD regulator: %d\n", err);
717 return err;
718 }
719
Thierry Redingedec4af2012-11-15 21:28:23 +0000720 err = regulator_enable(hdmi->pll);
721 if (err < 0) {
722 dev_err(hdmi->dev, "failed to enable PLL regulator: %d\n", err);
723 return err;
724 }
725
726 /*
727 * This assumes that the display controller will divide its parent
728 * clock by 2 to generate the pixel clock.
729 */
730 err = tegra_output_setup_clock(output, hdmi->clk, pclk * 2);
731 if (err < 0) {
732 dev_err(hdmi->dev, "failed to setup clock: %d\n", err);
733 return err;
734 }
735
736 err = clk_set_rate(hdmi->clk, pclk);
737 if (err < 0)
738 return err;
739
740 err = clk_enable(hdmi->clk);
741 if (err < 0) {
742 dev_err(hdmi->dev, "failed to enable clock: %d\n", err);
743 return err;
744 }
745
Stephen Warrenca480802013-11-06 16:20:54 -0700746 reset_control_assert(hdmi->rst);
Thierry Redingedec4af2012-11-15 21:28:23 +0000747 usleep_range(1000, 2000);
Stephen Warrenca480802013-11-06 16:20:54 -0700748 reset_control_deassert(hdmi->rst);
Thierry Redingedec4af2012-11-15 21:28:23 +0000749
750 tegra_dc_writel(dc, VSYNC_H_POSITION(1),
751 DC_DISP_DISP_TIMING_OPTIONS);
752 tegra_dc_writel(dc, DITHER_CONTROL_DISABLE | BASE_COLOR_SIZE888,
753 DC_DISP_DISP_COLOR_CONTROL);
754
755 /* video_preamble uses h_pulse2 */
756 pulse_start = 1 + h_sync_width + h_back_porch - 10;
757
758 tegra_dc_writel(dc, H_PULSE_2_ENABLE, DC_DISP_DISP_SIGNAL_OPTIONS0);
759
760 value = PULSE_MODE_NORMAL | PULSE_POLARITY_HIGH | PULSE_QUAL_VACTIVE |
761 PULSE_LAST_END_A;
762 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL);
763
764 value = PULSE_START(pulse_start) | PULSE_END(pulse_start + 8);
765 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A);
766
767 value = VSYNC_WINDOW_END(0x210) | VSYNC_WINDOW_START(0x200) |
768 VSYNC_WINDOW_ENABLE;
769 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
770
771 if (dc->pipe)
772 value = HDMI_SRC_DISPLAYB;
773 else
774 value = HDMI_SRC_DISPLAYA;
775
776 if ((mode->hdisplay == 720) && ((mode->vdisplay == 480) ||
777 (mode->vdisplay == 576)))
778 tegra_hdmi_writel(hdmi,
779 value | ARM_VIDEO_RANGE_FULL,
780 HDMI_NV_PDISP_INPUT_CONTROL);
781 else
782 tegra_hdmi_writel(hdmi,
783 value | ARM_VIDEO_RANGE_LIMITED,
784 HDMI_NV_PDISP_INPUT_CONTROL);
785
786 div82 = clk_get_rate(hdmi->clk) / 1000000 * 4;
787 value = SOR_REFCLK_DIV_INT(div82 >> 2) | SOR_REFCLK_DIV_FRAC(div82);
788 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_REFCLK);
789
790 if (!hdmi->dvi) {
791 err = tegra_hdmi_setup_audio(hdmi, pclk);
792 if (err < 0)
793 hdmi->dvi = true;
794 }
795
796 if (of_device_is_compatible(node, "nvidia,tegra20-hdmi")) {
797 /*
798 * TODO: add ELD support
799 */
800 }
801
802 rekey = HDMI_REKEY_DEFAULT;
803 value = HDMI_CTRL_REKEY(rekey);
804 value |= HDMI_CTRL_MAX_AC_PACKET((h_sync_width + h_back_porch +
805 h_front_porch - rekey - 18) / 32);
806
807 if (!hdmi->dvi)
808 value |= HDMI_CTRL_ENABLE;
809
810 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_CTRL);
811
812 if (hdmi->dvi)
813 tegra_hdmi_writel(hdmi, 0x0,
814 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
815 else
816 tegra_hdmi_writel(hdmi, GENERIC_CTRL_AUDIO,
817 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
818
819 tegra_hdmi_setup_avi_infoframe(hdmi, mode);
820 tegra_hdmi_setup_audio_infoframe(hdmi);
821 tegra_hdmi_setup_stereo_infoframe(hdmi);
822
823 /* TMDS CONFIG */
Thierry Reding59af0592013-10-14 09:43:05 +0200824 for (i = 0; i < hdmi->config->num_tmds; i++) {
825 if (pclk <= hdmi->config->tmds[i].pclk) {
826 tegra_hdmi_setup_tmds(hdmi, &hdmi->config->tmds[i]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000827 break;
828 }
829 }
830
831 tegra_hdmi_writel(hdmi,
832 SOR_SEQ_CTL_PU_PC(0) |
833 SOR_SEQ_PU_PC_ALT(0) |
834 SOR_SEQ_PD_PC(8) |
835 SOR_SEQ_PD_PC_ALT(8),
836 HDMI_NV_PDISP_SOR_SEQ_CTL);
837
838 value = SOR_SEQ_INST_WAIT_TIME(1) |
839 SOR_SEQ_INST_WAIT_UNITS_VSYNC |
840 SOR_SEQ_INST_HALT |
841 SOR_SEQ_INST_PIN_A_LOW |
842 SOR_SEQ_INST_PIN_B_LOW |
843 SOR_SEQ_INST_DRIVE_PWM_OUT_LO;
844
845 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(0));
846 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(8));
847
848 value = 0x1c800;
849 value &= ~SOR_CSTM_ROTCLK(~0);
850 value |= SOR_CSTM_ROTCLK(2);
851 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_CSTM);
852
Thierry Redingedec4af2012-11-15 21:28:23 +0000853 /* start SOR */
854 tegra_hdmi_writel(hdmi,
855 SOR_PWR_NORMAL_STATE_PU |
856 SOR_PWR_NORMAL_START_NORMAL |
857 SOR_PWR_SAFE_STATE_PD |
858 SOR_PWR_SETTING_NEW_TRIGGER,
859 HDMI_NV_PDISP_SOR_PWR);
860 tegra_hdmi_writel(hdmi,
861 SOR_PWR_NORMAL_STATE_PU |
862 SOR_PWR_NORMAL_START_NORMAL |
863 SOR_PWR_SAFE_STATE_PD |
864 SOR_PWR_SETTING_NEW_DONE,
865 HDMI_NV_PDISP_SOR_PWR);
866
867 do {
868 BUG_ON(--retries < 0);
869 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PWR);
870 } while (value & SOR_PWR_SETTING_NEW_PENDING);
871
872 value = SOR_STATE_ASY_CRCMODE_COMPLETE |
873 SOR_STATE_ASY_OWNER_HEAD0 |
874 SOR_STATE_ASY_SUBOWNER_BOTH |
875 SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A |
876 SOR_STATE_ASY_DEPOL_POS;
877
878 /* setup sync polarities */
879 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
880 value |= SOR_STATE_ASY_HSYNCPOL_POS;
881
882 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
883 value |= SOR_STATE_ASY_HSYNCPOL_NEG;
884
885 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
886 value |= SOR_STATE_ASY_VSYNCPOL_POS;
887
888 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
889 value |= SOR_STATE_ASY_VSYNCPOL_NEG;
890
891 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE2);
892
893 value = SOR_STATE_ASY_HEAD_OPMODE_AWAKE | SOR_STATE_ASY_ORMODE_NORMAL;
894 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE1);
895
896 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
897 tegra_hdmi_writel(hdmi, SOR_STATE_UPDATE, HDMI_NV_PDISP_SOR_STATE0);
898 tegra_hdmi_writel(hdmi, value | SOR_STATE_ATTACHED,
899 HDMI_NV_PDISP_SOR_STATE1);
900 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
901
Thierry Reding72d30282013-12-12 11:06:55 +0100902 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
903 value |= HDMI_ENABLE;
904 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
Thierry Redingedec4af2012-11-15 21:28:23 +0000905
Thierry Reding72d30282013-12-12 11:06:55 +0100906 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
907 value &= ~DISP_CTRL_MODE_MASK;
908 value |= DISP_CTRL_MODE_C_DISPLAY;
Thierry Redingedec4af2012-11-15 21:28:23 +0000909 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
910
Thierry Reding72d30282013-12-12 11:06:55 +0100911 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
912 value |= PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
913 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
914 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
915
Thierry Redingedec4af2012-11-15 21:28:23 +0000916 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
917 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
918
919 /* TODO: add HDCP support */
920
Thierry Reding365765f2013-10-29 16:00:42 +0100921 hdmi->enabled = true;
922
Thierry Redingedec4af2012-11-15 21:28:23 +0000923 return 0;
924}
925
926static int tegra_output_hdmi_disable(struct tegra_output *output)
927{
Thierry Reding72d30282013-12-12 11:06:55 +0100928 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
Thierry Redingedec4af2012-11-15 21:28:23 +0000929 struct tegra_hdmi *hdmi = to_hdmi(output);
Thierry Reding72d30282013-12-12 11:06:55 +0100930 unsigned long value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000931
Thierry Reding365765f2013-10-29 16:00:42 +0100932 if (!hdmi->enabled)
933 return 0;
934
Thierry Reding72d30282013-12-12 11:06:55 +0100935 /*
936 * The following accesses registers of the display controller, so make
937 * sure it's only executed when the output is attached to one.
938 */
939 if (dc) {
940 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
941 value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
942 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE);
943 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
944
945 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
946 value &= ~DISP_CTRL_MODE_MASK;
947 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
948
949 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
950 value &= ~HDMI_ENABLE;
951 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
952
953 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
954 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
955 }
956
Stephen Warrenca480802013-11-06 16:20:54 -0700957 reset_control_assert(hdmi->rst);
Thierry Redingedec4af2012-11-15 21:28:23 +0000958 clk_disable(hdmi->clk);
959 regulator_disable(hdmi->pll);
Thierry Redingfb50a112014-02-28 16:57:34 +0100960 regulator_disable(hdmi->vdd);
Thierry Redingedec4af2012-11-15 21:28:23 +0000961
Thierry Reding365765f2013-10-29 16:00:42 +0100962 hdmi->enabled = false;
963
Thierry Redingedec4af2012-11-15 21:28:23 +0000964 return 0;
965}
966
967static int tegra_output_hdmi_setup_clock(struct tegra_output *output,
968 struct clk *clk, unsigned long pclk)
969{
970 struct tegra_hdmi *hdmi = to_hdmi(output);
971 struct clk *base;
972 int err;
973
974 err = clk_set_parent(clk, hdmi->clk_parent);
975 if (err < 0) {
976 dev_err(output->dev, "failed to set parent: %d\n", err);
977 return err;
978 }
979
980 base = clk_get_parent(hdmi->clk_parent);
981
982 /*
983 * This assumes that the parent clock is pll_d_out0 or pll_d2_out
984 * respectively, each of which divides the base pll_d by 2.
985 */
986 err = clk_set_rate(base, pclk * 2);
987 if (err < 0)
988 dev_err(output->dev,
989 "failed to set base clock rate to %lu Hz\n",
990 pclk * 2);
991
992 return 0;
993}
994
995static int tegra_output_hdmi_check_mode(struct tegra_output *output,
996 struct drm_display_mode *mode,
997 enum drm_mode_status *status)
998{
999 struct tegra_hdmi *hdmi = to_hdmi(output);
1000 unsigned long pclk = mode->clock * 1000;
1001 struct clk *parent;
1002 long err;
1003
1004 parent = clk_get_parent(hdmi->clk_parent);
1005
1006 err = clk_round_rate(parent, pclk * 4);
Paul Walmsley23a0e272013-12-09 18:00:12 -08001007 if (err <= 0)
Thierry Redingedec4af2012-11-15 21:28:23 +00001008 *status = MODE_NOCLOCK;
1009 else
1010 *status = MODE_OK;
1011
1012 return 0;
1013}
1014
1015static const struct tegra_output_ops hdmi_ops = {
1016 .enable = tegra_output_hdmi_enable,
1017 .disable = tegra_output_hdmi_disable,
1018 .setup_clock = tegra_output_hdmi_setup_clock,
1019 .check_mode = tegra_output_hdmi_check_mode,
1020};
1021
1022static int tegra_hdmi_show_regs(struct seq_file *s, void *data)
1023{
1024 struct drm_info_node *node = s->private;
1025 struct tegra_hdmi *hdmi = node->info_ent->data;
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001026 int err;
1027
1028 err = clk_enable(hdmi->clk);
1029 if (err)
1030 return err;
Thierry Redingedec4af2012-11-15 21:28:23 +00001031
1032#define DUMP_REG(name) \
1033 seq_printf(s, "%-56s %#05x %08lx\n", #name, name, \
1034 tegra_hdmi_readl(hdmi, name))
1035
1036 DUMP_REG(HDMI_CTXSW);
1037 DUMP_REG(HDMI_NV_PDISP_SOR_STATE0);
1038 DUMP_REG(HDMI_NV_PDISP_SOR_STATE1);
1039 DUMP_REG(HDMI_NV_PDISP_SOR_STATE2);
1040 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_MSB);
1041 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_LSB);
1042 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_MSB);
1043 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_LSB);
1044 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_MSB);
1045 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_LSB);
1046 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_MSB);
1047 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_LSB);
1048 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_MSB);
1049 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_LSB);
1050 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_MSB);
1051 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_LSB);
1052 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CTRL);
1053 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CMODE);
1054 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_MSB);
1055 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_LSB);
1056 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_MSB);
1057 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB2);
1058 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB1);
1059 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_RI);
1060 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_MSB);
1061 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_LSB);
1062 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU0);
1063 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU_RDATA0);
1064 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU1);
1065 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU2);
1066 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
1067 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_STATUS);
1068 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER);
1069 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_LOW);
1070 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_HIGH);
1071 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
1072 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_STATUS);
1073 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER);
1074 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_LOW);
1075 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_HIGH);
1076 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_LOW);
1077 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_HIGH);
1078 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
1079 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_STATUS);
1080 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_HEADER);
1081 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_LOW);
1082 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_HIGH);
1083 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_LOW);
1084 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_HIGH);
1085 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_LOW);
1086 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_HIGH);
1087 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_LOW);
1088 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_HIGH);
1089 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_CTRL);
1090 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_LOW);
1091 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_HIGH);
1092 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
1093 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
1094 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_LOW);
1095 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_HIGH);
1096 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_LOW);
1097 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_HIGH);
1098 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_LOW);
1099 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_HIGH);
1100 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_LOW);
1101 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_HIGH);
1102 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_LOW);
1103 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_HIGH);
1104 DUMP_REG(HDMI_NV_PDISP_HDMI_CTRL);
1105 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_KEEPOUT);
1106 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
1107 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_CTRL);
1108 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_STATUS);
1109 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_SUBPACK);
1110 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS1);
1111 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS2);
1112 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU0);
1113 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1);
1114 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1_RDATA);
1115 DUMP_REG(HDMI_NV_PDISP_HDMI_SPARE);
1116 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS1);
1117 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS2);
1118 DUMP_REG(HDMI_NV_PDISP_HDMI_HDCPRIF_ROM_CTRL);
1119 DUMP_REG(HDMI_NV_PDISP_SOR_CAP);
1120 DUMP_REG(HDMI_NV_PDISP_SOR_PWR);
1121 DUMP_REG(HDMI_NV_PDISP_SOR_TEST);
1122 DUMP_REG(HDMI_NV_PDISP_SOR_PLL0);
1123 DUMP_REG(HDMI_NV_PDISP_SOR_PLL1);
1124 DUMP_REG(HDMI_NV_PDISP_SOR_PLL2);
1125 DUMP_REG(HDMI_NV_PDISP_SOR_CSTM);
1126 DUMP_REG(HDMI_NV_PDISP_SOR_LVDS);
1127 DUMP_REG(HDMI_NV_PDISP_SOR_CRCA);
1128 DUMP_REG(HDMI_NV_PDISP_SOR_CRCB);
1129 DUMP_REG(HDMI_NV_PDISP_SOR_BLANK);
1130 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_CTL);
1131 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(0));
1132 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(1));
1133 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(2));
1134 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(3));
1135 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(4));
1136 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(5));
1137 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(6));
1138 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(7));
1139 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(8));
1140 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(9));
1141 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(10));
1142 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(11));
1143 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(12));
1144 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(13));
1145 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(14));
1146 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(15));
1147 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA0);
1148 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA1);
1149 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA0);
1150 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA1);
1151 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA0);
1152 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA1);
1153 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA0);
1154 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA1);
1155 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA0);
1156 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA1);
1157 DUMP_REG(HDMI_NV_PDISP_SOR_TRIG);
1158 DUMP_REG(HDMI_NV_PDISP_SOR_MSCHECK);
1159 DUMP_REG(HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
1160 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG0);
1161 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG1);
1162 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG2);
1163 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(0));
1164 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(1));
1165 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(2));
1166 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(3));
1167 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(4));
1168 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(5));
1169 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(6));
1170 DUMP_REG(HDMI_NV_PDISP_AUDIO_PULSE_WIDTH);
1171 DUMP_REG(HDMI_NV_PDISP_AUDIO_THRESHOLD);
1172 DUMP_REG(HDMI_NV_PDISP_AUDIO_CNTRL0);
1173 DUMP_REG(HDMI_NV_PDISP_AUDIO_N);
1174 DUMP_REG(HDMI_NV_PDISP_HDCPRIF_ROM_TIMING);
1175 DUMP_REG(HDMI_NV_PDISP_SOR_REFCLK);
1176 DUMP_REG(HDMI_NV_PDISP_CRC_CONTROL);
1177 DUMP_REG(HDMI_NV_PDISP_INPUT_CONTROL);
1178 DUMP_REG(HDMI_NV_PDISP_SCRATCH);
1179 DUMP_REG(HDMI_NV_PDISP_PE_CURRENT);
1180 DUMP_REG(HDMI_NV_PDISP_KEY_CTRL);
1181 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG0);
1182 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG1);
1183 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG2);
1184 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_0);
1185 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_1);
1186 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_2);
1187 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_3);
1188 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_TRIG);
1189 DUMP_REG(HDMI_NV_PDISP_KEY_SKEY_INDEX);
1190 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
1191 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR);
1192 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001193 DUMP_REG(HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +00001194
1195#undef DUMP_REG
1196
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001197 clk_disable(hdmi->clk);
1198
Thierry Redingedec4af2012-11-15 21:28:23 +00001199 return 0;
1200}
1201
1202static struct drm_info_list debugfs_files[] = {
1203 { "regs", tegra_hdmi_show_regs, 0, NULL },
1204};
1205
1206static int tegra_hdmi_debugfs_init(struct tegra_hdmi *hdmi,
1207 struct drm_minor *minor)
1208{
1209 unsigned int i;
1210 int err;
1211
1212 hdmi->debugfs = debugfs_create_dir("hdmi", minor->debugfs_root);
1213 if (!hdmi->debugfs)
1214 return -ENOMEM;
1215
1216 hdmi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
1217 GFP_KERNEL);
1218 if (!hdmi->debugfs_files) {
1219 err = -ENOMEM;
1220 goto remove;
1221 }
1222
1223 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
1224 hdmi->debugfs_files[i].data = hdmi;
1225
1226 err = drm_debugfs_create_files(hdmi->debugfs_files,
1227 ARRAY_SIZE(debugfs_files),
1228 hdmi->debugfs, minor);
1229 if (err < 0)
1230 goto free;
1231
1232 hdmi->minor = minor;
1233
1234 return 0;
1235
1236free:
1237 kfree(hdmi->debugfs_files);
1238 hdmi->debugfs_files = NULL;
1239remove:
1240 debugfs_remove(hdmi->debugfs);
1241 hdmi->debugfs = NULL;
1242
1243 return err;
1244}
1245
1246static int tegra_hdmi_debugfs_exit(struct tegra_hdmi *hdmi)
1247{
1248 drm_debugfs_remove_files(hdmi->debugfs_files, ARRAY_SIZE(debugfs_files),
1249 hdmi->minor);
1250 hdmi->minor = NULL;
1251
1252 kfree(hdmi->debugfs_files);
1253 hdmi->debugfs_files = NULL;
1254
1255 debugfs_remove(hdmi->debugfs);
1256 hdmi->debugfs = NULL;
1257
1258 return 0;
1259}
1260
Thierry Reding53fa7f72013-09-24 15:35:40 +02001261static int tegra_hdmi_init(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001262{
Thierry Reding776dc382013-10-14 14:43:22 +02001263 struct tegra_drm *tegra = dev_get_drvdata(client->parent);
1264 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001265 int err;
1266
1267 hdmi->output.type = TEGRA_OUTPUT_HDMI;
1268 hdmi->output.dev = client->dev;
1269 hdmi->output.ops = &hdmi_ops;
1270
Thierry Reding776dc382013-10-14 14:43:22 +02001271 err = tegra_output_init(tegra->drm, &hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001272 if (err < 0) {
1273 dev_err(client->dev, "output setup failed: %d\n", err);
1274 return err;
1275 }
1276
1277 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding776dc382013-10-14 14:43:22 +02001278 err = tegra_hdmi_debugfs_init(hdmi, tegra->drm->primary);
Thierry Redingedec4af2012-11-15 21:28:23 +00001279 if (err < 0)
1280 dev_err(client->dev, "debugfs setup failed: %d\n", err);
1281 }
1282
Thierry Redingfb50a112014-02-28 16:57:34 +01001283 err = regulator_enable(hdmi->hdmi);
1284 if (err < 0) {
1285 dev_err(client->dev, "failed to enable HDMI regulator: %d\n",
1286 err);
1287 return err;
1288 }
1289
Thierry Redingedec4af2012-11-15 21:28:23 +00001290 return 0;
1291}
1292
Thierry Reding53fa7f72013-09-24 15:35:40 +02001293static int tegra_hdmi_exit(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001294{
Thierry Reding776dc382013-10-14 14:43:22 +02001295 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001296 int err;
1297
Thierry Redingfb50a112014-02-28 16:57:34 +01001298 regulator_disable(hdmi->hdmi);
1299
Thierry Redingedec4af2012-11-15 21:28:23 +00001300 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
1301 err = tegra_hdmi_debugfs_exit(hdmi);
1302 if (err < 0)
1303 dev_err(client->dev, "debugfs cleanup failed: %d\n",
1304 err);
1305 }
1306
1307 err = tegra_output_disable(&hdmi->output);
1308 if (err < 0) {
1309 dev_err(client->dev, "output failed to disable: %d\n", err);
1310 return err;
1311 }
1312
1313 err = tegra_output_exit(&hdmi->output);
1314 if (err < 0) {
1315 dev_err(client->dev, "output cleanup failed: %d\n", err);
1316 return err;
1317 }
1318
1319 return 0;
1320}
1321
1322static const struct host1x_client_ops hdmi_client_ops = {
Thierry Reding53fa7f72013-09-24 15:35:40 +02001323 .init = tegra_hdmi_init,
1324 .exit = tegra_hdmi_exit,
Thierry Redingedec4af2012-11-15 21:28:23 +00001325};
1326
Thierry Reding59af0592013-10-14 09:43:05 +02001327static const struct tegra_hdmi_config tegra20_hdmi_config = {
1328 .tmds = tegra20_tmds_config,
1329 .num_tmds = ARRAY_SIZE(tegra20_tmds_config),
1330 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1331 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001332 .has_sor_io_peak_current = false,
Thierry Reding59af0592013-10-14 09:43:05 +02001333};
1334
1335static const struct tegra_hdmi_config tegra30_hdmi_config = {
1336 .tmds = tegra30_tmds_config,
1337 .num_tmds = ARRAY_SIZE(tegra30_tmds_config),
1338 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1339 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001340 .has_sor_io_peak_current = false,
1341};
1342
1343static const struct tegra_hdmi_config tegra114_hdmi_config = {
1344 .tmds = tegra114_tmds_config,
1345 .num_tmds = ARRAY_SIZE(tegra114_tmds_config),
1346 .fuse_override_offset = HDMI_NV_PDISP_SOR_PAD_CTLS0,
1347 .fuse_override_value = 1 << 31,
1348 .has_sor_io_peak_current = true,
Thierry Reding59af0592013-10-14 09:43:05 +02001349};
1350
1351static const struct of_device_id tegra_hdmi_of_match[] = {
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001352 { .compatible = "nvidia,tegra114-hdmi", .data = &tegra114_hdmi_config },
Thierry Reding59af0592013-10-14 09:43:05 +02001353 { .compatible = "nvidia,tegra30-hdmi", .data = &tegra30_hdmi_config },
1354 { .compatible = "nvidia,tegra20-hdmi", .data = &tegra20_hdmi_config },
1355 { },
1356};
1357
Thierry Redingedec4af2012-11-15 21:28:23 +00001358static int tegra_hdmi_probe(struct platform_device *pdev)
1359{
Thierry Reding59af0592013-10-14 09:43:05 +02001360 const struct of_device_id *match;
Thierry Redingedec4af2012-11-15 21:28:23 +00001361 struct tegra_hdmi *hdmi;
1362 struct resource *regs;
1363 int err;
1364
Thierry Reding59af0592013-10-14 09:43:05 +02001365 match = of_match_node(tegra_hdmi_of_match, pdev->dev.of_node);
1366 if (!match)
1367 return -ENODEV;
1368
Thierry Redingedec4af2012-11-15 21:28:23 +00001369 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
1370 if (!hdmi)
1371 return -ENOMEM;
1372
Thierry Reding59af0592013-10-14 09:43:05 +02001373 hdmi->config = match->data;
Thierry Redingedec4af2012-11-15 21:28:23 +00001374 hdmi->dev = &pdev->dev;
1375 hdmi->audio_source = AUTO;
1376 hdmi->audio_freq = 44100;
1377 hdmi->stereo = false;
1378 hdmi->dvi = false;
1379
1380 hdmi->clk = devm_clk_get(&pdev->dev, NULL);
1381 if (IS_ERR(hdmi->clk)) {
1382 dev_err(&pdev->dev, "failed to get clock\n");
1383 return PTR_ERR(hdmi->clk);
1384 }
1385
Stephen Warrenca480802013-11-06 16:20:54 -07001386 hdmi->rst = devm_reset_control_get(&pdev->dev, "hdmi");
1387 if (IS_ERR(hdmi->rst)) {
1388 dev_err(&pdev->dev, "failed to get reset\n");
1389 return PTR_ERR(hdmi->rst);
1390 }
1391
Thierry Redingedec4af2012-11-15 21:28:23 +00001392 err = clk_prepare(hdmi->clk);
1393 if (err < 0)
1394 return err;
1395
1396 hdmi->clk_parent = devm_clk_get(&pdev->dev, "parent");
1397 if (IS_ERR(hdmi->clk_parent))
1398 return PTR_ERR(hdmi->clk_parent);
1399
1400 err = clk_prepare(hdmi->clk_parent);
1401 if (err < 0)
1402 return err;
1403
1404 err = clk_set_parent(hdmi->clk, hdmi->clk_parent);
1405 if (err < 0) {
1406 dev_err(&pdev->dev, "failed to setup clocks: %d\n", err);
1407 return err;
1408 }
1409
Thierry Redingfb50a112014-02-28 16:57:34 +01001410 hdmi->hdmi = devm_regulator_get(&pdev->dev, "hdmi");
1411 if (IS_ERR(hdmi->hdmi)) {
1412 dev_err(&pdev->dev, "failed to get HDMI regulator\n");
1413 return PTR_ERR(hdmi->hdmi);
1414 }
1415
Thierry Redingedec4af2012-11-15 21:28:23 +00001416 hdmi->vdd = devm_regulator_get(&pdev->dev, "vdd");
1417 if (IS_ERR(hdmi->vdd)) {
1418 dev_err(&pdev->dev, "failed to get VDD regulator\n");
1419 return PTR_ERR(hdmi->vdd);
1420 }
1421
1422 hdmi->pll = devm_regulator_get(&pdev->dev, "pll");
1423 if (IS_ERR(hdmi->pll)) {
1424 dev_err(&pdev->dev, "failed to get PLL regulator\n");
1425 return PTR_ERR(hdmi->pll);
1426 }
1427
1428 hdmi->output.dev = &pdev->dev;
1429
Thierry Reding59d29c02013-10-14 14:26:42 +02001430 err = tegra_output_probe(&hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001431 if (err < 0)
1432 return err;
1433
1434 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Thierry Redingd4ed6022013-01-21 11:09:02 +01001435 hdmi->regs = devm_ioremap_resource(&pdev->dev, regs);
1436 if (IS_ERR(hdmi->regs))
1437 return PTR_ERR(hdmi->regs);
Thierry Redingedec4af2012-11-15 21:28:23 +00001438
1439 err = platform_get_irq(pdev, 0);
1440 if (err < 0)
1441 return err;
1442
1443 hdmi->irq = err;
1444
Thierry Reding776dc382013-10-14 14:43:22 +02001445 INIT_LIST_HEAD(&hdmi->client.list);
1446 hdmi->client.ops = &hdmi_client_ops;
1447 hdmi->client.dev = &pdev->dev;
Thierry Redingedec4af2012-11-15 21:28:23 +00001448
Thierry Reding776dc382013-10-14 14:43:22 +02001449 err = host1x_client_register(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001450 if (err < 0) {
1451 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1452 err);
1453 return err;
1454 }
1455
1456 platform_set_drvdata(pdev, hdmi);
1457
1458 return 0;
1459}
1460
1461static int tegra_hdmi_remove(struct platform_device *pdev)
1462{
Thierry Redingedec4af2012-11-15 21:28:23 +00001463 struct tegra_hdmi *hdmi = platform_get_drvdata(pdev);
1464 int err;
1465
Thierry Reding776dc382013-10-14 14:43:22 +02001466 err = host1x_client_unregister(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001467 if (err < 0) {
1468 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1469 err);
1470 return err;
1471 }
1472
Thierry Reding59d29c02013-10-14 14:26:42 +02001473 err = tegra_output_remove(&hdmi->output);
1474 if (err < 0) {
1475 dev_err(&pdev->dev, "failed to remove output: %d\n", err);
1476 return err;
1477 }
1478
Thierry Redingedec4af2012-11-15 21:28:23 +00001479 clk_unprepare(hdmi->clk_parent);
1480 clk_unprepare(hdmi->clk);
1481
1482 return 0;
1483}
1484
Thierry Redingedec4af2012-11-15 21:28:23 +00001485struct platform_driver tegra_hdmi_driver = {
1486 .driver = {
1487 .name = "tegra-hdmi",
1488 .owner = THIS_MODULE,
1489 .of_match_table = tegra_hdmi_of_match,
1490 },
1491 .probe = tegra_hdmi_probe,
1492 .remove = tegra_hdmi_remove,
1493};