blob: 96fa838d60a415edc872ef041a514e32678ff3e7 [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
730 err = clk_enable(hdmi->clk);
731 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
740 tegra_dc_writel(dc, VSYNC_H_POSITION(1),
741 DC_DISP_DISP_TIMING_OPTIONS);
742 tegra_dc_writel(dc, DITHER_CONTROL_DISABLE | BASE_COLOR_SIZE888,
743 DC_DISP_DISP_COLOR_CONTROL);
744
745 /* video_preamble uses h_pulse2 */
746 pulse_start = 1 + h_sync_width + h_back_porch - 10;
747
748 tegra_dc_writel(dc, H_PULSE_2_ENABLE, DC_DISP_DISP_SIGNAL_OPTIONS0);
749
750 value = PULSE_MODE_NORMAL | PULSE_POLARITY_HIGH | PULSE_QUAL_VACTIVE |
751 PULSE_LAST_END_A;
752 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL);
753
754 value = PULSE_START(pulse_start) | PULSE_END(pulse_start + 8);
755 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A);
756
757 value = VSYNC_WINDOW_END(0x210) | VSYNC_WINDOW_START(0x200) |
758 VSYNC_WINDOW_ENABLE;
759 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
760
761 if (dc->pipe)
762 value = HDMI_SRC_DISPLAYB;
763 else
764 value = HDMI_SRC_DISPLAYA;
765
766 if ((mode->hdisplay == 720) && ((mode->vdisplay == 480) ||
767 (mode->vdisplay == 576)))
768 tegra_hdmi_writel(hdmi,
769 value | ARM_VIDEO_RANGE_FULL,
770 HDMI_NV_PDISP_INPUT_CONTROL);
771 else
772 tegra_hdmi_writel(hdmi,
773 value | ARM_VIDEO_RANGE_LIMITED,
774 HDMI_NV_PDISP_INPUT_CONTROL);
775
776 div82 = clk_get_rate(hdmi->clk) / 1000000 * 4;
777 value = SOR_REFCLK_DIV_INT(div82 >> 2) | SOR_REFCLK_DIV_FRAC(div82);
778 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_REFCLK);
779
780 if (!hdmi->dvi) {
781 err = tegra_hdmi_setup_audio(hdmi, pclk);
782 if (err < 0)
783 hdmi->dvi = true;
784 }
785
786 if (of_device_is_compatible(node, "nvidia,tegra20-hdmi")) {
787 /*
788 * TODO: add ELD support
789 */
790 }
791
792 rekey = HDMI_REKEY_DEFAULT;
793 value = HDMI_CTRL_REKEY(rekey);
794 value |= HDMI_CTRL_MAX_AC_PACKET((h_sync_width + h_back_porch +
795 h_front_porch - rekey - 18) / 32);
796
797 if (!hdmi->dvi)
798 value |= HDMI_CTRL_ENABLE;
799
800 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_CTRL);
801
802 if (hdmi->dvi)
803 tegra_hdmi_writel(hdmi, 0x0,
804 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
805 else
806 tegra_hdmi_writel(hdmi, GENERIC_CTRL_AUDIO,
807 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
808
809 tegra_hdmi_setup_avi_infoframe(hdmi, mode);
810 tegra_hdmi_setup_audio_infoframe(hdmi);
811 tegra_hdmi_setup_stereo_infoframe(hdmi);
812
813 /* TMDS CONFIG */
Thierry Reding59af0592013-10-14 09:43:05 +0200814 for (i = 0; i < hdmi->config->num_tmds; i++) {
815 if (pclk <= hdmi->config->tmds[i].pclk) {
816 tegra_hdmi_setup_tmds(hdmi, &hdmi->config->tmds[i]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000817 break;
818 }
819 }
820
821 tegra_hdmi_writel(hdmi,
822 SOR_SEQ_CTL_PU_PC(0) |
823 SOR_SEQ_PU_PC_ALT(0) |
824 SOR_SEQ_PD_PC(8) |
825 SOR_SEQ_PD_PC_ALT(8),
826 HDMI_NV_PDISP_SOR_SEQ_CTL);
827
828 value = SOR_SEQ_INST_WAIT_TIME(1) |
829 SOR_SEQ_INST_WAIT_UNITS_VSYNC |
830 SOR_SEQ_INST_HALT |
831 SOR_SEQ_INST_PIN_A_LOW |
832 SOR_SEQ_INST_PIN_B_LOW |
833 SOR_SEQ_INST_DRIVE_PWM_OUT_LO;
834
835 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(0));
836 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(8));
837
838 value = 0x1c800;
839 value &= ~SOR_CSTM_ROTCLK(~0);
840 value |= SOR_CSTM_ROTCLK(2);
841 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_CSTM);
842
Thierry Redingedec4af2012-11-15 21:28:23 +0000843 /* start SOR */
844 tegra_hdmi_writel(hdmi,
845 SOR_PWR_NORMAL_STATE_PU |
846 SOR_PWR_NORMAL_START_NORMAL |
847 SOR_PWR_SAFE_STATE_PD |
848 SOR_PWR_SETTING_NEW_TRIGGER,
849 HDMI_NV_PDISP_SOR_PWR);
850 tegra_hdmi_writel(hdmi,
851 SOR_PWR_NORMAL_STATE_PU |
852 SOR_PWR_NORMAL_START_NORMAL |
853 SOR_PWR_SAFE_STATE_PD |
854 SOR_PWR_SETTING_NEW_DONE,
855 HDMI_NV_PDISP_SOR_PWR);
856
857 do {
858 BUG_ON(--retries < 0);
859 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PWR);
860 } while (value & SOR_PWR_SETTING_NEW_PENDING);
861
862 value = SOR_STATE_ASY_CRCMODE_COMPLETE |
863 SOR_STATE_ASY_OWNER_HEAD0 |
864 SOR_STATE_ASY_SUBOWNER_BOTH |
865 SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A |
866 SOR_STATE_ASY_DEPOL_POS;
867
868 /* setup sync polarities */
869 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
870 value |= SOR_STATE_ASY_HSYNCPOL_POS;
871
872 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
873 value |= SOR_STATE_ASY_HSYNCPOL_NEG;
874
875 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
876 value |= SOR_STATE_ASY_VSYNCPOL_POS;
877
878 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
879 value |= SOR_STATE_ASY_VSYNCPOL_NEG;
880
881 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE2);
882
883 value = SOR_STATE_ASY_HEAD_OPMODE_AWAKE | SOR_STATE_ASY_ORMODE_NORMAL;
884 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE1);
885
886 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
887 tegra_hdmi_writel(hdmi, SOR_STATE_UPDATE, HDMI_NV_PDISP_SOR_STATE0);
888 tegra_hdmi_writel(hdmi, value | SOR_STATE_ATTACHED,
889 HDMI_NV_PDISP_SOR_STATE1);
890 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
891
Thierry Reding72d30282013-12-12 11:06:55 +0100892 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
893 value |= HDMI_ENABLE;
894 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
Thierry Redingedec4af2012-11-15 21:28:23 +0000895
Thierry Reding72d30282013-12-12 11:06:55 +0100896 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
897 value &= ~DISP_CTRL_MODE_MASK;
898 value |= DISP_CTRL_MODE_C_DISPLAY;
Thierry Redingedec4af2012-11-15 21:28:23 +0000899 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
900
Thierry Reding72d30282013-12-12 11:06:55 +0100901 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
902 value |= PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
903 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
904 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
905
Thierry Redingedec4af2012-11-15 21:28:23 +0000906 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
907 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
908
909 /* TODO: add HDCP support */
910
Thierry Reding365765f2013-10-29 16:00:42 +0100911 hdmi->enabled = true;
912
Thierry Redingedec4af2012-11-15 21:28:23 +0000913 return 0;
914}
915
916static int tegra_output_hdmi_disable(struct tegra_output *output)
917{
Thierry Reding72d30282013-12-12 11:06:55 +0100918 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
Thierry Redingedec4af2012-11-15 21:28:23 +0000919 struct tegra_hdmi *hdmi = to_hdmi(output);
Thierry Reding72d30282013-12-12 11:06:55 +0100920 unsigned long value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000921
Thierry Reding365765f2013-10-29 16:00:42 +0100922 if (!hdmi->enabled)
923 return 0;
924
Thierry Reding72d30282013-12-12 11:06:55 +0100925 /*
926 * The following accesses registers of the display controller, so make
927 * sure it's only executed when the output is attached to one.
928 */
929 if (dc) {
930 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
931 value &= ~(PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
932 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE);
933 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
934
935 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
936 value &= ~DISP_CTRL_MODE_MASK;
937 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
938
939 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
940 value &= ~HDMI_ENABLE;
941 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
942
943 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
944 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
945 }
946
Stephen Warrenca480802013-11-06 16:20:54 -0700947 reset_control_assert(hdmi->rst);
Thierry Redingedec4af2012-11-15 21:28:23 +0000948 clk_disable(hdmi->clk);
Thierry Redingfb50a112014-02-28 16:57:34 +0100949 regulator_disable(hdmi->vdd);
Thierry Reding88685682014-04-16 10:24:12 +0200950 regulator_disable(hdmi->pll);
Thierry Redingedec4af2012-11-15 21:28:23 +0000951
Thierry Reding365765f2013-10-29 16:00:42 +0100952 hdmi->enabled = false;
953
Thierry Redingedec4af2012-11-15 21:28:23 +0000954 return 0;
955}
956
957static int tegra_output_hdmi_setup_clock(struct tegra_output *output,
958 struct clk *clk, unsigned long pclk)
959{
960 struct tegra_hdmi *hdmi = to_hdmi(output);
961 struct clk *base;
962 int err;
963
964 err = clk_set_parent(clk, hdmi->clk_parent);
965 if (err < 0) {
966 dev_err(output->dev, "failed to set parent: %d\n", err);
967 return err;
968 }
969
970 base = clk_get_parent(hdmi->clk_parent);
971
972 /*
973 * This assumes that the parent clock is pll_d_out0 or pll_d2_out
974 * respectively, each of which divides the base pll_d by 2.
975 */
976 err = clk_set_rate(base, pclk * 2);
977 if (err < 0)
978 dev_err(output->dev,
979 "failed to set base clock rate to %lu Hz\n",
980 pclk * 2);
981
982 return 0;
983}
984
985static int tegra_output_hdmi_check_mode(struct tegra_output *output,
986 struct drm_display_mode *mode,
987 enum drm_mode_status *status)
988{
989 struct tegra_hdmi *hdmi = to_hdmi(output);
990 unsigned long pclk = mode->clock * 1000;
991 struct clk *parent;
992 long err;
993
994 parent = clk_get_parent(hdmi->clk_parent);
995
996 err = clk_round_rate(parent, pclk * 4);
Paul Walmsley23a0e272013-12-09 18:00:12 -0800997 if (err <= 0)
Thierry Redingedec4af2012-11-15 21:28:23 +0000998 *status = MODE_NOCLOCK;
999 else
1000 *status = MODE_OK;
1001
1002 return 0;
1003}
1004
1005static const struct tegra_output_ops hdmi_ops = {
1006 .enable = tegra_output_hdmi_enable,
1007 .disable = tegra_output_hdmi_disable,
1008 .setup_clock = tegra_output_hdmi_setup_clock,
1009 .check_mode = tegra_output_hdmi_check_mode,
1010};
1011
1012static int tegra_hdmi_show_regs(struct seq_file *s, void *data)
1013{
1014 struct drm_info_node *node = s->private;
1015 struct tegra_hdmi *hdmi = node->info_ent->data;
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001016 int err;
1017
1018 err = clk_enable(hdmi->clk);
1019 if (err)
1020 return err;
Thierry Redingedec4af2012-11-15 21:28:23 +00001021
1022#define DUMP_REG(name) \
1023 seq_printf(s, "%-56s %#05x %08lx\n", #name, name, \
1024 tegra_hdmi_readl(hdmi, name))
1025
1026 DUMP_REG(HDMI_CTXSW);
1027 DUMP_REG(HDMI_NV_PDISP_SOR_STATE0);
1028 DUMP_REG(HDMI_NV_PDISP_SOR_STATE1);
1029 DUMP_REG(HDMI_NV_PDISP_SOR_STATE2);
1030 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_MSB);
1031 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_LSB);
1032 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_MSB);
1033 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_LSB);
1034 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_MSB);
1035 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_LSB);
1036 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_MSB);
1037 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_LSB);
1038 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_MSB);
1039 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_LSB);
1040 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_MSB);
1041 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_LSB);
1042 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CTRL);
1043 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CMODE);
1044 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_MSB);
1045 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_LSB);
1046 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_MSB);
1047 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB2);
1048 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB1);
1049 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_RI);
1050 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_MSB);
1051 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_LSB);
1052 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU0);
1053 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU_RDATA0);
1054 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU1);
1055 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU2);
1056 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
1057 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_STATUS);
1058 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER);
1059 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_LOW);
1060 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_HIGH);
1061 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
1062 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_STATUS);
1063 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER);
1064 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_LOW);
1065 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_HIGH);
1066 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_LOW);
1067 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_HIGH);
1068 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
1069 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_STATUS);
1070 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_HEADER);
1071 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_LOW);
1072 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_HIGH);
1073 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_LOW);
1074 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_HIGH);
1075 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_LOW);
1076 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_HIGH);
1077 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_LOW);
1078 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_HIGH);
1079 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_CTRL);
1080 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_LOW);
1081 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_HIGH);
1082 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
1083 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
1084 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_LOW);
1085 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_HIGH);
1086 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_LOW);
1087 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_HIGH);
1088 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_LOW);
1089 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_HIGH);
1090 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_LOW);
1091 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_HIGH);
1092 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_LOW);
1093 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_HIGH);
1094 DUMP_REG(HDMI_NV_PDISP_HDMI_CTRL);
1095 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_KEEPOUT);
1096 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
1097 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_CTRL);
1098 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_STATUS);
1099 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_SUBPACK);
1100 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS1);
1101 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS2);
1102 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU0);
1103 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1);
1104 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1_RDATA);
1105 DUMP_REG(HDMI_NV_PDISP_HDMI_SPARE);
1106 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS1);
1107 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS2);
1108 DUMP_REG(HDMI_NV_PDISP_HDMI_HDCPRIF_ROM_CTRL);
1109 DUMP_REG(HDMI_NV_PDISP_SOR_CAP);
1110 DUMP_REG(HDMI_NV_PDISP_SOR_PWR);
1111 DUMP_REG(HDMI_NV_PDISP_SOR_TEST);
1112 DUMP_REG(HDMI_NV_PDISP_SOR_PLL0);
1113 DUMP_REG(HDMI_NV_PDISP_SOR_PLL1);
1114 DUMP_REG(HDMI_NV_PDISP_SOR_PLL2);
1115 DUMP_REG(HDMI_NV_PDISP_SOR_CSTM);
1116 DUMP_REG(HDMI_NV_PDISP_SOR_LVDS);
1117 DUMP_REG(HDMI_NV_PDISP_SOR_CRCA);
1118 DUMP_REG(HDMI_NV_PDISP_SOR_CRCB);
1119 DUMP_REG(HDMI_NV_PDISP_SOR_BLANK);
1120 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_CTL);
1121 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(0));
1122 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(1));
1123 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(2));
1124 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(3));
1125 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(4));
1126 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(5));
1127 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(6));
1128 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(7));
1129 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(8));
1130 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(9));
1131 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(10));
1132 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(11));
1133 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(12));
1134 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(13));
1135 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(14));
1136 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(15));
1137 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA0);
1138 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA1);
1139 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA0);
1140 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA1);
1141 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA0);
1142 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA1);
1143 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA0);
1144 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA1);
1145 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA0);
1146 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA1);
1147 DUMP_REG(HDMI_NV_PDISP_SOR_TRIG);
1148 DUMP_REG(HDMI_NV_PDISP_SOR_MSCHECK);
1149 DUMP_REG(HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
1150 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG0);
1151 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG1);
1152 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG2);
1153 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(0));
1154 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(1));
1155 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(2));
1156 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(3));
1157 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(4));
1158 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(5));
1159 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(6));
1160 DUMP_REG(HDMI_NV_PDISP_AUDIO_PULSE_WIDTH);
1161 DUMP_REG(HDMI_NV_PDISP_AUDIO_THRESHOLD);
1162 DUMP_REG(HDMI_NV_PDISP_AUDIO_CNTRL0);
1163 DUMP_REG(HDMI_NV_PDISP_AUDIO_N);
1164 DUMP_REG(HDMI_NV_PDISP_HDCPRIF_ROM_TIMING);
1165 DUMP_REG(HDMI_NV_PDISP_SOR_REFCLK);
1166 DUMP_REG(HDMI_NV_PDISP_CRC_CONTROL);
1167 DUMP_REG(HDMI_NV_PDISP_INPUT_CONTROL);
1168 DUMP_REG(HDMI_NV_PDISP_SCRATCH);
1169 DUMP_REG(HDMI_NV_PDISP_PE_CURRENT);
1170 DUMP_REG(HDMI_NV_PDISP_KEY_CTRL);
1171 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG0);
1172 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG1);
1173 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG2);
1174 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_0);
1175 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_1);
1176 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_2);
1177 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_3);
1178 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_TRIG);
1179 DUMP_REG(HDMI_NV_PDISP_KEY_SKEY_INDEX);
1180 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
1181 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR);
1182 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001183 DUMP_REG(HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +00001184
1185#undef DUMP_REG
1186
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001187 clk_disable(hdmi->clk);
1188
Thierry Redingedec4af2012-11-15 21:28:23 +00001189 return 0;
1190}
1191
1192static struct drm_info_list debugfs_files[] = {
1193 { "regs", tegra_hdmi_show_regs, 0, NULL },
1194};
1195
1196static int tegra_hdmi_debugfs_init(struct tegra_hdmi *hdmi,
1197 struct drm_minor *minor)
1198{
1199 unsigned int i;
1200 int err;
1201
1202 hdmi->debugfs = debugfs_create_dir("hdmi", minor->debugfs_root);
1203 if (!hdmi->debugfs)
1204 return -ENOMEM;
1205
1206 hdmi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
1207 GFP_KERNEL);
1208 if (!hdmi->debugfs_files) {
1209 err = -ENOMEM;
1210 goto remove;
1211 }
1212
1213 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
1214 hdmi->debugfs_files[i].data = hdmi;
1215
1216 err = drm_debugfs_create_files(hdmi->debugfs_files,
1217 ARRAY_SIZE(debugfs_files),
1218 hdmi->debugfs, minor);
1219 if (err < 0)
1220 goto free;
1221
1222 hdmi->minor = minor;
1223
1224 return 0;
1225
1226free:
1227 kfree(hdmi->debugfs_files);
1228 hdmi->debugfs_files = NULL;
1229remove:
1230 debugfs_remove(hdmi->debugfs);
1231 hdmi->debugfs = NULL;
1232
1233 return err;
1234}
1235
1236static int tegra_hdmi_debugfs_exit(struct tegra_hdmi *hdmi)
1237{
1238 drm_debugfs_remove_files(hdmi->debugfs_files, ARRAY_SIZE(debugfs_files),
1239 hdmi->minor);
1240 hdmi->minor = NULL;
1241
1242 kfree(hdmi->debugfs_files);
1243 hdmi->debugfs_files = NULL;
1244
1245 debugfs_remove(hdmi->debugfs);
1246 hdmi->debugfs = NULL;
1247
1248 return 0;
1249}
1250
Thierry Reding53fa7f72013-09-24 15:35:40 +02001251static int tegra_hdmi_init(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001252{
Thierry Reding776dc382013-10-14 14:43:22 +02001253 struct tegra_drm *tegra = dev_get_drvdata(client->parent);
1254 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001255 int err;
1256
1257 hdmi->output.type = TEGRA_OUTPUT_HDMI;
1258 hdmi->output.dev = client->dev;
1259 hdmi->output.ops = &hdmi_ops;
1260
Thierry Reding776dc382013-10-14 14:43:22 +02001261 err = tegra_output_init(tegra->drm, &hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001262 if (err < 0) {
1263 dev_err(client->dev, "output setup failed: %d\n", err);
1264 return err;
1265 }
1266
1267 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding776dc382013-10-14 14:43:22 +02001268 err = tegra_hdmi_debugfs_init(hdmi, tegra->drm->primary);
Thierry Redingedec4af2012-11-15 21:28:23 +00001269 if (err < 0)
1270 dev_err(client->dev, "debugfs setup failed: %d\n", err);
1271 }
1272
Thierry Redingfb50a112014-02-28 16:57:34 +01001273 err = regulator_enable(hdmi->hdmi);
1274 if (err < 0) {
1275 dev_err(client->dev, "failed to enable HDMI regulator: %d\n",
1276 err);
1277 return err;
1278 }
1279
Thierry Redingedec4af2012-11-15 21:28:23 +00001280 return 0;
1281}
1282
Thierry Reding53fa7f72013-09-24 15:35:40 +02001283static int tegra_hdmi_exit(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001284{
Thierry Reding776dc382013-10-14 14:43:22 +02001285 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001286 int err;
1287
Thierry Redingfb50a112014-02-28 16:57:34 +01001288 regulator_disable(hdmi->hdmi);
1289
Thierry Redingedec4af2012-11-15 21:28:23 +00001290 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
1291 err = tegra_hdmi_debugfs_exit(hdmi);
1292 if (err < 0)
1293 dev_err(client->dev, "debugfs cleanup failed: %d\n",
1294 err);
1295 }
1296
1297 err = tegra_output_disable(&hdmi->output);
1298 if (err < 0) {
1299 dev_err(client->dev, "output failed to disable: %d\n", err);
1300 return err;
1301 }
1302
1303 err = tegra_output_exit(&hdmi->output);
1304 if (err < 0) {
1305 dev_err(client->dev, "output cleanup failed: %d\n", err);
1306 return err;
1307 }
1308
1309 return 0;
1310}
1311
1312static const struct host1x_client_ops hdmi_client_ops = {
Thierry Reding53fa7f72013-09-24 15:35:40 +02001313 .init = tegra_hdmi_init,
1314 .exit = tegra_hdmi_exit,
Thierry Redingedec4af2012-11-15 21:28:23 +00001315};
1316
Thierry Reding59af0592013-10-14 09:43:05 +02001317static const struct tegra_hdmi_config tegra20_hdmi_config = {
1318 .tmds = tegra20_tmds_config,
1319 .num_tmds = ARRAY_SIZE(tegra20_tmds_config),
1320 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1321 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001322 .has_sor_io_peak_current = false,
Thierry Reding59af0592013-10-14 09:43:05 +02001323};
1324
1325static const struct tegra_hdmi_config tegra30_hdmi_config = {
1326 .tmds = tegra30_tmds_config,
1327 .num_tmds = ARRAY_SIZE(tegra30_tmds_config),
1328 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1329 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001330 .has_sor_io_peak_current = false,
1331};
1332
1333static const struct tegra_hdmi_config tegra114_hdmi_config = {
1334 .tmds = tegra114_tmds_config,
1335 .num_tmds = ARRAY_SIZE(tegra114_tmds_config),
1336 .fuse_override_offset = HDMI_NV_PDISP_SOR_PAD_CTLS0,
1337 .fuse_override_value = 1 << 31,
1338 .has_sor_io_peak_current = true,
Thierry Reding59af0592013-10-14 09:43:05 +02001339};
1340
1341static const struct of_device_id tegra_hdmi_of_match[] = {
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001342 { .compatible = "nvidia,tegra114-hdmi", .data = &tegra114_hdmi_config },
Thierry Reding59af0592013-10-14 09:43:05 +02001343 { .compatible = "nvidia,tegra30-hdmi", .data = &tegra30_hdmi_config },
1344 { .compatible = "nvidia,tegra20-hdmi", .data = &tegra20_hdmi_config },
1345 { },
1346};
1347
Thierry Redingedec4af2012-11-15 21:28:23 +00001348static int tegra_hdmi_probe(struct platform_device *pdev)
1349{
Thierry Reding59af0592013-10-14 09:43:05 +02001350 const struct of_device_id *match;
Thierry Redingedec4af2012-11-15 21:28:23 +00001351 struct tegra_hdmi *hdmi;
1352 struct resource *regs;
1353 int err;
1354
Thierry Reding59af0592013-10-14 09:43:05 +02001355 match = of_match_node(tegra_hdmi_of_match, pdev->dev.of_node);
1356 if (!match)
1357 return -ENODEV;
1358
Thierry Redingedec4af2012-11-15 21:28:23 +00001359 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
1360 if (!hdmi)
1361 return -ENOMEM;
1362
Thierry Reding59af0592013-10-14 09:43:05 +02001363 hdmi->config = match->data;
Thierry Redingedec4af2012-11-15 21:28:23 +00001364 hdmi->dev = &pdev->dev;
1365 hdmi->audio_source = AUTO;
1366 hdmi->audio_freq = 44100;
1367 hdmi->stereo = false;
1368 hdmi->dvi = false;
1369
1370 hdmi->clk = devm_clk_get(&pdev->dev, NULL);
1371 if (IS_ERR(hdmi->clk)) {
1372 dev_err(&pdev->dev, "failed to get clock\n");
1373 return PTR_ERR(hdmi->clk);
1374 }
1375
Stephen Warrenca480802013-11-06 16:20:54 -07001376 hdmi->rst = devm_reset_control_get(&pdev->dev, "hdmi");
1377 if (IS_ERR(hdmi->rst)) {
1378 dev_err(&pdev->dev, "failed to get reset\n");
1379 return PTR_ERR(hdmi->rst);
1380 }
1381
Thierry Redingedec4af2012-11-15 21:28:23 +00001382 err = clk_prepare(hdmi->clk);
1383 if (err < 0)
1384 return err;
1385
1386 hdmi->clk_parent = devm_clk_get(&pdev->dev, "parent");
1387 if (IS_ERR(hdmi->clk_parent))
1388 return PTR_ERR(hdmi->clk_parent);
1389
1390 err = clk_prepare(hdmi->clk_parent);
1391 if (err < 0)
1392 return err;
1393
1394 err = clk_set_parent(hdmi->clk, hdmi->clk_parent);
1395 if (err < 0) {
1396 dev_err(&pdev->dev, "failed to setup clocks: %d\n", err);
1397 return err;
1398 }
1399
Thierry Redingfb50a112014-02-28 16:57:34 +01001400 hdmi->hdmi = devm_regulator_get(&pdev->dev, "hdmi");
1401 if (IS_ERR(hdmi->hdmi)) {
1402 dev_err(&pdev->dev, "failed to get HDMI regulator\n");
1403 return PTR_ERR(hdmi->hdmi);
1404 }
1405
Thierry Redingedec4af2012-11-15 21:28:23 +00001406 hdmi->pll = devm_regulator_get(&pdev->dev, "pll");
1407 if (IS_ERR(hdmi->pll)) {
1408 dev_err(&pdev->dev, "failed to get PLL regulator\n");
1409 return PTR_ERR(hdmi->pll);
1410 }
1411
Thierry Reding88685682014-04-16 10:24:12 +02001412 hdmi->vdd = devm_regulator_get(&pdev->dev, "vdd");
1413 if (IS_ERR(hdmi->vdd)) {
1414 dev_err(&pdev->dev, "failed to get VDD regulator\n");
1415 return PTR_ERR(hdmi->vdd);
1416 }
1417
Thierry Redingedec4af2012-11-15 21:28:23 +00001418 hdmi->output.dev = &pdev->dev;
1419
Thierry Reding59d29c02013-10-14 14:26:42 +02001420 err = tegra_output_probe(&hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001421 if (err < 0)
1422 return err;
1423
1424 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Thierry Redingd4ed6022013-01-21 11:09:02 +01001425 hdmi->regs = devm_ioremap_resource(&pdev->dev, regs);
1426 if (IS_ERR(hdmi->regs))
1427 return PTR_ERR(hdmi->regs);
Thierry Redingedec4af2012-11-15 21:28:23 +00001428
1429 err = platform_get_irq(pdev, 0);
1430 if (err < 0)
1431 return err;
1432
1433 hdmi->irq = err;
1434
Thierry Reding776dc382013-10-14 14:43:22 +02001435 INIT_LIST_HEAD(&hdmi->client.list);
1436 hdmi->client.ops = &hdmi_client_ops;
1437 hdmi->client.dev = &pdev->dev;
Thierry Redingedec4af2012-11-15 21:28:23 +00001438
Thierry Reding776dc382013-10-14 14:43:22 +02001439 err = host1x_client_register(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001440 if (err < 0) {
1441 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1442 err);
1443 return err;
1444 }
1445
1446 platform_set_drvdata(pdev, hdmi);
1447
1448 return 0;
1449}
1450
1451static int tegra_hdmi_remove(struct platform_device *pdev)
1452{
Thierry Redingedec4af2012-11-15 21:28:23 +00001453 struct tegra_hdmi *hdmi = platform_get_drvdata(pdev);
1454 int err;
1455
Thierry Reding776dc382013-10-14 14:43:22 +02001456 err = host1x_client_unregister(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001457 if (err < 0) {
1458 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1459 err);
1460 return err;
1461 }
1462
Thierry Reding59d29c02013-10-14 14:26:42 +02001463 err = tegra_output_remove(&hdmi->output);
1464 if (err < 0) {
1465 dev_err(&pdev->dev, "failed to remove output: %d\n", err);
1466 return err;
1467 }
1468
Thierry Redingedec4af2012-11-15 21:28:23 +00001469 clk_unprepare(hdmi->clk_parent);
1470 clk_unprepare(hdmi->clk);
1471
1472 return 0;
1473}
1474
Thierry Redingedec4af2012-11-15 21:28:23 +00001475struct platform_driver tegra_hdmi_driver = {
1476 .driver = {
1477 .name = "tegra-hdmi",
1478 .owner = THIS_MODULE,
1479 .of_match_table = tegra_hdmi_of_match,
1480 },
1481 .probe = tegra_hdmi_probe,
1482 .remove = tegra_hdmi_remove,
1483};