blob: 7f6253ea5cb5ea264319e98800b6d3783e1becb3 [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;
43
44 struct regulator *vdd;
45 struct regulator *pll;
46
47 void __iomem *regs;
48 unsigned int irq;
49
50 struct clk *clk_parent;
51 struct clk *clk;
Stephen Warrenca480802013-11-06 16:20:54 -070052 struct reset_control *rst;
Thierry Redingedec4af2012-11-15 21:28:23 +000053
Thierry Reding59af0592013-10-14 09:43:05 +020054 const struct tegra_hdmi_config *config;
55
Thierry Redingedec4af2012-11-15 21:28:23 +000056 unsigned int audio_source;
57 unsigned int audio_freq;
58 bool stereo;
59 bool dvi;
60
61 struct drm_info_list *debugfs_files;
62 struct drm_minor *minor;
63 struct dentry *debugfs;
64};
65
66static inline struct tegra_hdmi *
Thierry Reding776dc382013-10-14 14:43:22 +020067host1x_client_to_hdmi(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +000068{
69 return container_of(client, struct tegra_hdmi, client);
70}
71
72static inline struct tegra_hdmi *to_hdmi(struct tegra_output *output)
73{
74 return container_of(output, struct tegra_hdmi, output);
75}
76
77#define HDMI_AUDIOCLK_FREQ 216000000
78#define HDMI_REKEY_DEFAULT 56
79
80enum {
81 AUTO = 0,
82 SPDIF,
83 HDA,
84};
85
86static inline unsigned long tegra_hdmi_readl(struct tegra_hdmi *hdmi,
87 unsigned long reg)
88{
89 return readl(hdmi->regs + (reg << 2));
90}
91
92static inline void tegra_hdmi_writel(struct tegra_hdmi *hdmi, unsigned long val,
93 unsigned long reg)
94{
95 writel(val, hdmi->regs + (reg << 2));
96}
97
98struct tegra_hdmi_audio_config {
99 unsigned int pclk;
100 unsigned int n;
101 unsigned int cts;
102 unsigned int aval;
103};
104
105static const struct tegra_hdmi_audio_config tegra_hdmi_audio_32k[] = {
106 { 25200000, 4096, 25200, 24000 },
107 { 27000000, 4096, 27000, 24000 },
108 { 74250000, 4096, 74250, 24000 },
109 { 148500000, 4096, 148500, 24000 },
110 { 0, 0, 0, 0 },
111};
112
113static const struct tegra_hdmi_audio_config tegra_hdmi_audio_44_1k[] = {
114 { 25200000, 5880, 26250, 25000 },
115 { 27000000, 5880, 28125, 25000 },
116 { 74250000, 4704, 61875, 20000 },
117 { 148500000, 4704, 123750, 20000 },
118 { 0, 0, 0, 0 },
119};
120
121static const struct tegra_hdmi_audio_config tegra_hdmi_audio_48k[] = {
122 { 25200000, 6144, 25200, 24000 },
123 { 27000000, 6144, 27000, 24000 },
124 { 74250000, 6144, 74250, 24000 },
125 { 148500000, 6144, 148500, 24000 },
126 { 0, 0, 0, 0 },
127};
128
129static const struct tegra_hdmi_audio_config tegra_hdmi_audio_88_2k[] = {
130 { 25200000, 11760, 26250, 25000 },
131 { 27000000, 11760, 28125, 25000 },
132 { 74250000, 9408, 61875, 20000 },
133 { 148500000, 9408, 123750, 20000 },
134 { 0, 0, 0, 0 },
135};
136
137static const struct tegra_hdmi_audio_config tegra_hdmi_audio_96k[] = {
138 { 25200000, 12288, 25200, 24000 },
139 { 27000000, 12288, 27000, 24000 },
140 { 74250000, 12288, 74250, 24000 },
141 { 148500000, 12288, 148500, 24000 },
142 { 0, 0, 0, 0 },
143};
144
145static const struct tegra_hdmi_audio_config tegra_hdmi_audio_176_4k[] = {
146 { 25200000, 23520, 26250, 25000 },
147 { 27000000, 23520, 28125, 25000 },
148 { 74250000, 18816, 61875, 20000 },
149 { 148500000, 18816, 123750, 20000 },
150 { 0, 0, 0, 0 },
151};
152
153static const struct tegra_hdmi_audio_config tegra_hdmi_audio_192k[] = {
154 { 25200000, 24576, 25200, 24000 },
155 { 27000000, 24576, 27000, 24000 },
156 { 74250000, 24576, 74250, 24000 },
157 { 148500000, 24576, 148500, 24000 },
158 { 0, 0, 0, 0 },
159};
160
Thierry Redingf27db962013-09-30 15:14:41 +0200161static const struct tmds_config tegra20_tmds_config[] = {
Lucas Stachfa416dd2012-12-19 21:38:55 +0000162 { /* slow pixel clock modes */
Thierry Redingedec4af2012-11-15 21:28:23 +0000163 .pclk = 27000000,
164 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
165 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) |
166 SOR_PLL_TX_REG_LOAD(3),
167 .pll1 = SOR_PLL_TMDS_TERM_ENABLE,
168 .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) |
169 PE_CURRENT1(PE_CURRENT_0_0_mA) |
170 PE_CURRENT2(PE_CURRENT_0_0_mA) |
171 PE_CURRENT3(PE_CURRENT_0_0_mA),
172 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) |
173 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) |
174 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) |
175 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA),
Lucas Stachfa416dd2012-12-19 21:38:55 +0000176 },
177 { /* high pixel clock modes */
Thierry Redingedec4af2012-11-15 21:28:23 +0000178 .pclk = UINT_MAX,
179 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
180 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) |
181 SOR_PLL_TX_REG_LOAD(3),
182 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
183 .pe_current = PE_CURRENT0(PE_CURRENT_6_0_mA) |
184 PE_CURRENT1(PE_CURRENT_6_0_mA) |
185 PE_CURRENT2(PE_CURRENT_6_0_mA) |
186 PE_CURRENT3(PE_CURRENT_6_0_mA),
187 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) |
188 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) |
189 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) |
190 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA),
191 },
192};
193
Thierry Redingf27db962013-09-30 15:14:41 +0200194static const struct tmds_config tegra30_tmds_config[] = {
Thierry Redingedec4af2012-11-15 21:28:23 +0000195 { /* 480p modes */
196 .pclk = 27000000,
197 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
198 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) |
199 SOR_PLL_TX_REG_LOAD(0),
200 .pll1 = SOR_PLL_TMDS_TERM_ENABLE,
201 .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) |
202 PE_CURRENT1(PE_CURRENT_0_0_mA) |
203 PE_CURRENT2(PE_CURRENT_0_0_mA) |
204 PE_CURRENT3(PE_CURRENT_0_0_mA),
205 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
206 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
207 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
208 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
209 }, { /* 720p modes */
210 .pclk = 74250000,
211 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
212 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) |
213 SOR_PLL_TX_REG_LOAD(0),
214 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
215 .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) |
216 PE_CURRENT1(PE_CURRENT_5_0_mA) |
217 PE_CURRENT2(PE_CURRENT_5_0_mA) |
218 PE_CURRENT3(PE_CURRENT_5_0_mA),
219 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
220 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
221 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
222 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
223 }, { /* 1080p modes */
224 .pclk = UINT_MAX,
225 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
226 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(3) |
227 SOR_PLL_TX_REG_LOAD(0),
228 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
229 .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) |
230 PE_CURRENT1(PE_CURRENT_5_0_mA) |
231 PE_CURRENT2(PE_CURRENT_5_0_mA) |
232 PE_CURRENT3(PE_CURRENT_5_0_mA),
233 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
234 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
235 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
236 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
237 },
238};
239
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +0200240static const struct tmds_config tegra114_tmds_config[] = {
241 { /* 480p/576p / 25.2MHz/27MHz modes */
242 .pclk = 27000000,
243 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
244 SOR_PLL_VCOCAP(0) | SOR_PLL_RESISTORSEL,
245 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(0),
246 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
247 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
248 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
249 PE_CURRENT3(PE_CURRENT_0_mA_T114),
250 .drive_current =
251 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
252 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
253 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
254 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
255 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
256 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
257 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
258 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
259 }, { /* 720p / 74.25MHz modes */
260 .pclk = 74250000,
261 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
262 SOR_PLL_VCOCAP(1) | SOR_PLL_RESISTORSEL,
263 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
264 SOR_PLL_TMDS_TERMADJ(0),
265 .pe_current = PE_CURRENT0(PE_CURRENT_15_mA_T114) |
266 PE_CURRENT1(PE_CURRENT_15_mA_T114) |
267 PE_CURRENT2(PE_CURRENT_15_mA_T114) |
268 PE_CURRENT3(PE_CURRENT_15_mA_T114),
269 .drive_current =
270 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
271 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
272 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
273 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
274 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
275 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
276 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
277 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
278 }, { /* 1080p / 148.5MHz modes */
279 .pclk = 148500000,
280 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
281 SOR_PLL_VCOCAP(3) | SOR_PLL_RESISTORSEL,
282 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
283 SOR_PLL_TMDS_TERMADJ(0),
284 .pe_current = PE_CURRENT0(PE_CURRENT_10_mA_T114) |
285 PE_CURRENT1(PE_CURRENT_10_mA_T114) |
286 PE_CURRENT2(PE_CURRENT_10_mA_T114) |
287 PE_CURRENT3(PE_CURRENT_10_mA_T114),
288 .drive_current =
289 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_12_400_mA_T114) |
290 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_12_400_mA_T114) |
291 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_12_400_mA_T114) |
292 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_12_400_mA_T114),
293 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
294 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
295 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
296 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
297 }, { /* 225/297MHz modes */
298 .pclk = UINT_MAX,
299 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
300 SOR_PLL_VCOCAP(0xf) | SOR_PLL_RESISTORSEL,
301 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(7)
302 | SOR_PLL_TMDS_TERM_ENABLE,
303 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
304 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
305 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
306 PE_CURRENT3(PE_CURRENT_0_mA_T114),
307 .drive_current =
308 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_25_200_mA_T114) |
309 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_25_200_mA_T114) |
310 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_25_200_mA_T114) |
311 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_19_200_mA_T114),
312 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_3_000_mA) |
313 PEAK_CURRENT_LANE1(PEAK_CURRENT_3_000_mA) |
314 PEAK_CURRENT_LANE2(PEAK_CURRENT_3_000_mA) |
315 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_800_mA),
316 },
317};
318
Thierry Redingedec4af2012-11-15 21:28:23 +0000319static const struct tegra_hdmi_audio_config *
320tegra_hdmi_get_audio_config(unsigned int audio_freq, unsigned int pclk)
321{
322 const struct tegra_hdmi_audio_config *table;
323
324 switch (audio_freq) {
325 case 32000:
326 table = tegra_hdmi_audio_32k;
327 break;
328
329 case 44100:
330 table = tegra_hdmi_audio_44_1k;
331 break;
332
333 case 48000:
334 table = tegra_hdmi_audio_48k;
335 break;
336
337 case 88200:
338 table = tegra_hdmi_audio_88_2k;
339 break;
340
341 case 96000:
342 table = tegra_hdmi_audio_96k;
343 break;
344
345 case 176400:
346 table = tegra_hdmi_audio_176_4k;
347 break;
348
349 case 192000:
350 table = tegra_hdmi_audio_192k;
351 break;
352
353 default:
354 return NULL;
355 }
356
357 while (table->pclk) {
358 if (table->pclk == pclk)
359 return table;
360
361 table++;
362 }
363
364 return NULL;
365}
366
367static void tegra_hdmi_setup_audio_fs_tables(struct tegra_hdmi *hdmi)
368{
369 const unsigned int freqs[] = {
370 32000, 44100, 48000, 88200, 96000, 176400, 192000
371 };
372 unsigned int i;
373
374 for (i = 0; i < ARRAY_SIZE(freqs); i++) {
375 unsigned int f = freqs[i];
376 unsigned int eight_half;
377 unsigned long value;
378 unsigned int delta;
379
380 if (f > 96000)
381 delta = 2;
382 else if (f > 480000)
383 delta = 6;
384 else
385 delta = 9;
386
387 eight_half = (8 * HDMI_AUDIOCLK_FREQ) / (f * 128);
388 value = AUDIO_FS_LOW(eight_half - delta) |
389 AUDIO_FS_HIGH(eight_half + delta);
390 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_FS(i));
391 }
392}
393
394static int tegra_hdmi_setup_audio(struct tegra_hdmi *hdmi, unsigned int pclk)
395{
396 struct device_node *node = hdmi->dev->of_node;
397 const struct tegra_hdmi_audio_config *config;
398 unsigned int offset = 0;
399 unsigned long value;
400
401 switch (hdmi->audio_source) {
402 case HDA:
403 value = AUDIO_CNTRL0_SOURCE_SELECT_HDAL;
404 break;
405
406 case SPDIF:
407 value = AUDIO_CNTRL0_SOURCE_SELECT_SPDIF;
408 break;
409
410 default:
411 value = AUDIO_CNTRL0_SOURCE_SELECT_AUTO;
412 break;
413 }
414
415 if (of_device_is_compatible(node, "nvidia,tegra30-hdmi")) {
416 value |= AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
417 AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
418 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0);
419 } else {
420 value |= AUDIO_CNTRL0_INJECT_NULLSMPL;
421 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
422
423 value = AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
424 AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
425 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0);
426 }
427
428 config = tegra_hdmi_get_audio_config(hdmi->audio_freq, pclk);
429 if (!config) {
430 dev_err(hdmi->dev, "cannot set audio to %u at %u pclk\n",
431 hdmi->audio_freq, pclk);
432 return -EINVAL;
433 }
434
435 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_HDMI_ACR_CTRL);
436
437 value = AUDIO_N_RESETF | AUDIO_N_GENERATE_ALTERNATE |
438 AUDIO_N_VALUE(config->n - 1);
439 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N);
440
441 tegra_hdmi_writel(hdmi, ACR_SUBPACK_N(config->n) | ACR_ENABLE,
442 HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
443
444 value = ACR_SUBPACK_CTS(config->cts);
445 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
446
447 value = SPARE_HW_CTS | SPARE_FORCE_SW_CTS | SPARE_CTS_RESET_VAL(1);
448 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_SPARE);
449
450 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_AUDIO_N);
451 value &= ~AUDIO_N_RESETF;
452 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N);
453
454 if (of_device_is_compatible(node, "nvidia,tegra30-hdmi")) {
455 switch (hdmi->audio_freq) {
456 case 32000:
457 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0320;
458 break;
459
460 case 44100:
461 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0441;
462 break;
463
464 case 48000:
465 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0480;
466 break;
467
468 case 88200:
469 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0882;
470 break;
471
472 case 96000:
473 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0960;
474 break;
475
476 case 176400:
477 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_1764;
478 break;
479
480 case 192000:
481 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_1920;
482 break;
483 }
484
485 tegra_hdmi_writel(hdmi, config->aval, offset);
486 }
487
488 tegra_hdmi_setup_audio_fs_tables(hdmi);
489
490 return 0;
491}
492
Thierry Redingac24c222012-11-23 15:14:00 +0100493static inline unsigned long tegra_hdmi_subpack(const u8 *ptr, size_t size)
Thierry Redingedec4af2012-11-15 21:28:23 +0000494{
Thierry Redingac24c222012-11-23 15:14:00 +0100495 unsigned long value = 0;
Thierry Redingedec4af2012-11-15 21:28:23 +0000496 size_t i;
Thierry Redingedec4af2012-11-15 21:28:23 +0000497
Thierry Redingac24c222012-11-23 15:14:00 +0100498 for (i = size; i > 0; i--)
499 value = (value << 8) | ptr[i - 1];
Thierry Redingedec4af2012-11-15 21:28:23 +0000500
Thierry Redingac24c222012-11-23 15:14:00 +0100501 return value;
502}
Thierry Redingedec4af2012-11-15 21:28:23 +0000503
Thierry Redingac24c222012-11-23 15:14:00 +0100504static void tegra_hdmi_write_infopack(struct tegra_hdmi *hdmi, const void *data,
505 size_t size)
506{
507 const u8 *ptr = data;
508 unsigned long offset;
509 unsigned long value;
510 size_t i, j;
Thierry Redingedec4af2012-11-15 21:28:23 +0000511
Thierry Redingac24c222012-11-23 15:14:00 +0100512 switch (ptr[0]) {
513 case HDMI_INFOFRAME_TYPE_AVI:
514 offset = HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER;
515 break;
516
517 case HDMI_INFOFRAME_TYPE_AUDIO:
518 offset = HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER;
519 break;
520
521 case HDMI_INFOFRAME_TYPE_VENDOR:
522 offset = HDMI_NV_PDISP_HDMI_GENERIC_HEADER;
523 break;
524
525 default:
526 dev_err(hdmi->dev, "unsupported infoframe type: %02x\n",
527 ptr[0]);
528 return;
529 }
530
531 value = INFOFRAME_HEADER_TYPE(ptr[0]) |
532 INFOFRAME_HEADER_VERSION(ptr[1]) |
533 INFOFRAME_HEADER_LEN(ptr[2]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000534 tegra_hdmi_writel(hdmi, value, offset);
Thierry Redingac24c222012-11-23 15:14:00 +0100535 offset++;
Thierry Redingedec4af2012-11-15 21:28:23 +0000536
Thierry Redingac24c222012-11-23 15:14:00 +0100537 /*
538 * Each subpack contains 7 bytes, divided into:
539 * - subpack_low: bytes 0 - 3
540 * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00)
Thierry Redingedec4af2012-11-15 21:28:23 +0000541 */
Thierry Redingac24c222012-11-23 15:14:00 +0100542 for (i = 3, j = 0; i < size; i += 7, j += 8) {
543 size_t rem = size - i, num = min_t(size_t, rem, 4);
Thierry Redingedec4af2012-11-15 21:28:23 +0000544
Thierry Redingac24c222012-11-23 15:14:00 +0100545 value = tegra_hdmi_subpack(&ptr[i], num);
546 tegra_hdmi_writel(hdmi, value, offset++);
Thierry Redingedec4af2012-11-15 21:28:23 +0000547
Thierry Redingac24c222012-11-23 15:14:00 +0100548 num = min_t(size_t, rem - num, 3);
Thierry Redingedec4af2012-11-15 21:28:23 +0000549
Thierry Redingac24c222012-11-23 15:14:00 +0100550 value = tegra_hdmi_subpack(&ptr[i + 4], num);
551 tegra_hdmi_writel(hdmi, value, offset++);
Thierry Redingedec4af2012-11-15 21:28:23 +0000552 }
553}
554
555static void tegra_hdmi_setup_avi_infoframe(struct tegra_hdmi *hdmi,
556 struct drm_display_mode *mode)
557{
558 struct hdmi_avi_infoframe frame;
Thierry Redingac24c222012-11-23 15:14:00 +0100559 u8 buffer[17];
560 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000561
562 if (hdmi->dvi) {
563 tegra_hdmi_writel(hdmi, 0,
564 HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
565 return;
566 }
567
Thierry Redingac24c222012-11-23 15:14:00 +0100568 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
569 if (err < 0) {
570 dev_err(hdmi->dev, "failed to setup AVI infoframe: %zd\n", err);
571 return;
Thierry Redingedec4af2012-11-15 21:28:23 +0000572 }
573
Thierry Redingac24c222012-11-23 15:14:00 +0100574 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
575 if (err < 0) {
576 dev_err(hdmi->dev, "failed to pack AVI infoframe: %zd\n", err);
577 return;
578 }
579
580 tegra_hdmi_write_infopack(hdmi, buffer, err);
Thierry Redingedec4af2012-11-15 21:28:23 +0000581
582 tegra_hdmi_writel(hdmi, INFOFRAME_CTRL_ENABLE,
583 HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
584}
585
586static void tegra_hdmi_setup_audio_infoframe(struct tegra_hdmi *hdmi)
587{
588 struct hdmi_audio_infoframe frame;
Thierry Redingac24c222012-11-23 15:14:00 +0100589 u8 buffer[14];
590 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000591
592 if (hdmi->dvi) {
593 tegra_hdmi_writel(hdmi, 0,
594 HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
595 return;
596 }
597
Thierry Redingac24c222012-11-23 15:14:00 +0100598 err = hdmi_audio_infoframe_init(&frame);
599 if (err < 0) {
Thierry Redingef284c72013-10-16 19:51:22 +0200600 dev_err(hdmi->dev, "failed to setup audio infoframe: %zd\n",
Thierry Redingac24c222012-11-23 15:14:00 +0100601 err);
602 return;
603 }
Thierry Redingedec4af2012-11-15 21:28:23 +0000604
Thierry Redingac24c222012-11-23 15:14:00 +0100605 frame.channels = 2;
606
607 err = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
608 if (err < 0) {
609 dev_err(hdmi->dev, "failed to pack audio infoframe: %zd\n",
610 err);
611 return;
612 }
613
614 /*
615 * The audio infoframe has only one set of subpack registers, so the
616 * infoframe needs to be truncated. One set of subpack registers can
617 * contain 7 bytes. Including the 3 byte header only the first 10
618 * bytes can be programmed.
619 */
Thierry Redingef284c72013-10-16 19:51:22 +0200620 tegra_hdmi_write_infopack(hdmi, buffer, min_t(size_t, 10, err));
Thierry Redingedec4af2012-11-15 21:28:23 +0000621
622 tegra_hdmi_writel(hdmi, INFOFRAME_CTRL_ENABLE,
623 HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
624}
625
626static void tegra_hdmi_setup_stereo_infoframe(struct tegra_hdmi *hdmi)
627{
Lespiau, Damienae84b902013-08-19 16:59:02 +0100628 struct hdmi_vendor_infoframe frame;
Thierry Redingedec4af2012-11-15 21:28:23 +0000629 unsigned long value;
Thierry Redingac24c222012-11-23 15:14:00 +0100630 u8 buffer[10];
631 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000632
633 if (!hdmi->stereo) {
634 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
635 value &= ~GENERIC_CTRL_ENABLE;
636 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
637 return;
638 }
639
Lespiau, Damienae84b902013-08-19 16:59:02 +0100640 hdmi_vendor_infoframe_init(&frame);
Lespiau, Damiena26a58e82013-08-19 16:58:59 +0100641 frame.s3d_struct = HDMI_3D_STRUCTURE_FRAME_PACKING;
Thierry Redingac24c222012-11-23 15:14:00 +0100642
Lespiau, Damienae84b902013-08-19 16:59:02 +0100643 err = hdmi_vendor_infoframe_pack(&frame, buffer, sizeof(buffer));
Thierry Redingac24c222012-11-23 15:14:00 +0100644 if (err < 0) {
645 dev_err(hdmi->dev, "failed to pack vendor infoframe: %zd\n",
646 err);
647 return;
648 }
649
650 tegra_hdmi_write_infopack(hdmi, buffer, err);
Thierry Redingedec4af2012-11-15 21:28:23 +0000651
652 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
653 value |= GENERIC_CTRL_ENABLE;
654 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
655}
656
657static void tegra_hdmi_setup_tmds(struct tegra_hdmi *hdmi,
658 const struct tmds_config *tmds)
659{
660 unsigned long value;
661
662 tegra_hdmi_writel(hdmi, tmds->pll0, HDMI_NV_PDISP_SOR_PLL0);
663 tegra_hdmi_writel(hdmi, tmds->pll1, HDMI_NV_PDISP_SOR_PLL1);
664 tegra_hdmi_writel(hdmi, tmds->pe_current, HDMI_NV_PDISP_PE_CURRENT);
665
Thierry Reding59af0592013-10-14 09:43:05 +0200666 tegra_hdmi_writel(hdmi, tmds->drive_current,
667 HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
668
669 value = tegra_hdmi_readl(hdmi, hdmi->config->fuse_override_offset);
670 value |= hdmi->config->fuse_override_value;
671 tegra_hdmi_writel(hdmi, value, hdmi->config->fuse_override_offset);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +0200672
673 if (hdmi->config->has_sor_io_peak_current)
674 tegra_hdmi_writel(hdmi, tmds->peak_current,
675 HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +0000676}
677
Mikko Perttunen9f159122013-08-28 18:48:38 +0300678static bool tegra_output_is_hdmi(struct tegra_output *output)
679{
680 struct edid *edid;
681
682 if (!output->connector.edid_blob_ptr)
683 return false;
684
685 edid = (struct edid *)output->connector.edid_blob_ptr->data;
686
687 return drm_detect_hdmi_monitor(edid);
688}
689
Thierry Redingedec4af2012-11-15 21:28:23 +0000690static int tegra_output_hdmi_enable(struct tegra_output *output)
691{
692 unsigned int h_sync_width, h_front_porch, h_back_porch, i, rekey;
693 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
694 struct drm_display_mode *mode = &dc->base.mode;
695 struct tegra_hdmi *hdmi = to_hdmi(output);
696 struct device_node *node = hdmi->dev->of_node;
697 unsigned int pulse_start, div82, pclk;
Thierry Redingedec4af2012-11-15 21:28:23 +0000698 unsigned long value;
699 int retries = 1000;
700 int err;
701
Mikko Perttunen9f159122013-08-28 18:48:38 +0300702 hdmi->dvi = !tegra_output_is_hdmi(output);
703
Thierry Redingedec4af2012-11-15 21:28:23 +0000704 pclk = mode->clock * 1000;
705 h_sync_width = mode->hsync_end - mode->hsync_start;
Lucas Stach40495082012-12-19 21:38:52 +0000706 h_back_porch = mode->htotal - mode->hsync_end;
707 h_front_porch = mode->hsync_start - mode->hdisplay;
Thierry Redingedec4af2012-11-15 21:28:23 +0000708
Thierry Redingedec4af2012-11-15 21:28:23 +0000709 err = regulator_enable(hdmi->pll);
710 if (err < 0) {
711 dev_err(hdmi->dev, "failed to enable PLL regulator: %d\n", err);
712 return err;
713 }
714
715 /*
716 * This assumes that the display controller will divide its parent
717 * clock by 2 to generate the pixel clock.
718 */
719 err = tegra_output_setup_clock(output, hdmi->clk, pclk * 2);
720 if (err < 0) {
721 dev_err(hdmi->dev, "failed to setup clock: %d\n", err);
722 return err;
723 }
724
725 err = clk_set_rate(hdmi->clk, pclk);
726 if (err < 0)
727 return err;
728
729 err = clk_enable(hdmi->clk);
730 if (err < 0) {
731 dev_err(hdmi->dev, "failed to enable clock: %d\n", err);
732 return err;
733 }
734
Stephen Warrenca480802013-11-06 16:20:54 -0700735 reset_control_assert(hdmi->rst);
Thierry Redingedec4af2012-11-15 21:28:23 +0000736 usleep_range(1000, 2000);
Stephen Warrenca480802013-11-06 16:20:54 -0700737 reset_control_deassert(hdmi->rst);
Thierry Redingedec4af2012-11-15 21:28:23 +0000738
739 tegra_dc_writel(dc, VSYNC_H_POSITION(1),
740 DC_DISP_DISP_TIMING_OPTIONS);
741 tegra_dc_writel(dc, DITHER_CONTROL_DISABLE | BASE_COLOR_SIZE888,
742 DC_DISP_DISP_COLOR_CONTROL);
743
744 /* video_preamble uses h_pulse2 */
745 pulse_start = 1 + h_sync_width + h_back_porch - 10;
746
747 tegra_dc_writel(dc, H_PULSE_2_ENABLE, DC_DISP_DISP_SIGNAL_OPTIONS0);
748
749 value = PULSE_MODE_NORMAL | PULSE_POLARITY_HIGH | PULSE_QUAL_VACTIVE |
750 PULSE_LAST_END_A;
751 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL);
752
753 value = PULSE_START(pulse_start) | PULSE_END(pulse_start + 8);
754 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A);
755
756 value = VSYNC_WINDOW_END(0x210) | VSYNC_WINDOW_START(0x200) |
757 VSYNC_WINDOW_ENABLE;
758 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
759
760 if (dc->pipe)
761 value = HDMI_SRC_DISPLAYB;
762 else
763 value = HDMI_SRC_DISPLAYA;
764
765 if ((mode->hdisplay == 720) && ((mode->vdisplay == 480) ||
766 (mode->vdisplay == 576)))
767 tegra_hdmi_writel(hdmi,
768 value | ARM_VIDEO_RANGE_FULL,
769 HDMI_NV_PDISP_INPUT_CONTROL);
770 else
771 tegra_hdmi_writel(hdmi,
772 value | ARM_VIDEO_RANGE_LIMITED,
773 HDMI_NV_PDISP_INPUT_CONTROL);
774
775 div82 = clk_get_rate(hdmi->clk) / 1000000 * 4;
776 value = SOR_REFCLK_DIV_INT(div82 >> 2) | SOR_REFCLK_DIV_FRAC(div82);
777 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_REFCLK);
778
779 if (!hdmi->dvi) {
780 err = tegra_hdmi_setup_audio(hdmi, pclk);
781 if (err < 0)
782 hdmi->dvi = true;
783 }
784
785 if (of_device_is_compatible(node, "nvidia,tegra20-hdmi")) {
786 /*
787 * TODO: add ELD support
788 */
789 }
790
791 rekey = HDMI_REKEY_DEFAULT;
792 value = HDMI_CTRL_REKEY(rekey);
793 value |= HDMI_CTRL_MAX_AC_PACKET((h_sync_width + h_back_porch +
794 h_front_porch - rekey - 18) / 32);
795
796 if (!hdmi->dvi)
797 value |= HDMI_CTRL_ENABLE;
798
799 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_CTRL);
800
801 if (hdmi->dvi)
802 tegra_hdmi_writel(hdmi, 0x0,
803 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
804 else
805 tegra_hdmi_writel(hdmi, GENERIC_CTRL_AUDIO,
806 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
807
808 tegra_hdmi_setup_avi_infoframe(hdmi, mode);
809 tegra_hdmi_setup_audio_infoframe(hdmi);
810 tegra_hdmi_setup_stereo_infoframe(hdmi);
811
812 /* TMDS CONFIG */
Thierry Reding59af0592013-10-14 09:43:05 +0200813 for (i = 0; i < hdmi->config->num_tmds; i++) {
814 if (pclk <= hdmi->config->tmds[i].pclk) {
815 tegra_hdmi_setup_tmds(hdmi, &hdmi->config->tmds[i]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000816 break;
817 }
818 }
819
820 tegra_hdmi_writel(hdmi,
821 SOR_SEQ_CTL_PU_PC(0) |
822 SOR_SEQ_PU_PC_ALT(0) |
823 SOR_SEQ_PD_PC(8) |
824 SOR_SEQ_PD_PC_ALT(8),
825 HDMI_NV_PDISP_SOR_SEQ_CTL);
826
827 value = SOR_SEQ_INST_WAIT_TIME(1) |
828 SOR_SEQ_INST_WAIT_UNITS_VSYNC |
829 SOR_SEQ_INST_HALT |
830 SOR_SEQ_INST_PIN_A_LOW |
831 SOR_SEQ_INST_PIN_B_LOW |
832 SOR_SEQ_INST_DRIVE_PWM_OUT_LO;
833
834 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(0));
835 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(8));
836
837 value = 0x1c800;
838 value &= ~SOR_CSTM_ROTCLK(~0);
839 value |= SOR_CSTM_ROTCLK(2);
840 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_CSTM);
841
842 tegra_dc_writel(dc, DISP_CTRL_MODE_STOP, DC_CMD_DISPLAY_COMMAND);
843 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
844 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
845
846 /* start SOR */
847 tegra_hdmi_writel(hdmi,
848 SOR_PWR_NORMAL_STATE_PU |
849 SOR_PWR_NORMAL_START_NORMAL |
850 SOR_PWR_SAFE_STATE_PD |
851 SOR_PWR_SETTING_NEW_TRIGGER,
852 HDMI_NV_PDISP_SOR_PWR);
853 tegra_hdmi_writel(hdmi,
854 SOR_PWR_NORMAL_STATE_PU |
855 SOR_PWR_NORMAL_START_NORMAL |
856 SOR_PWR_SAFE_STATE_PD |
857 SOR_PWR_SETTING_NEW_DONE,
858 HDMI_NV_PDISP_SOR_PWR);
859
860 do {
861 BUG_ON(--retries < 0);
862 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PWR);
863 } while (value & SOR_PWR_SETTING_NEW_PENDING);
864
865 value = SOR_STATE_ASY_CRCMODE_COMPLETE |
866 SOR_STATE_ASY_OWNER_HEAD0 |
867 SOR_STATE_ASY_SUBOWNER_BOTH |
868 SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A |
869 SOR_STATE_ASY_DEPOL_POS;
870
871 /* setup sync polarities */
872 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
873 value |= SOR_STATE_ASY_HSYNCPOL_POS;
874
875 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
876 value |= SOR_STATE_ASY_HSYNCPOL_NEG;
877
878 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
879 value |= SOR_STATE_ASY_VSYNCPOL_POS;
880
881 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
882 value |= SOR_STATE_ASY_VSYNCPOL_NEG;
883
884 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE2);
885
886 value = SOR_STATE_ASY_HEAD_OPMODE_AWAKE | SOR_STATE_ASY_ORMODE_NORMAL;
887 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE1);
888
889 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
890 tegra_hdmi_writel(hdmi, SOR_STATE_UPDATE, HDMI_NV_PDISP_SOR_STATE0);
891 tegra_hdmi_writel(hdmi, value | SOR_STATE_ATTACHED,
892 HDMI_NV_PDISP_SOR_STATE1);
893 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
894
895 tegra_dc_writel(dc, HDMI_ENABLE, DC_DISP_DISP_WIN_OPTIONS);
896
897 value = PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
898 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
899 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
900
901 value = DISP_CTRL_MODE_C_DISPLAY;
902 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
903
904 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
905 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
906
907 /* TODO: add HDCP support */
908
909 return 0;
910}
911
912static int tegra_output_hdmi_disable(struct tegra_output *output)
913{
914 struct tegra_hdmi *hdmi = to_hdmi(output);
915
Stephen Warrenca480802013-11-06 16:20:54 -0700916 reset_control_assert(hdmi->rst);
Thierry Redingedec4af2012-11-15 21:28:23 +0000917 clk_disable(hdmi->clk);
918 regulator_disable(hdmi->pll);
Thierry Redingedec4af2012-11-15 21:28:23 +0000919
920 return 0;
921}
922
923static int tegra_output_hdmi_setup_clock(struct tegra_output *output,
924 struct clk *clk, unsigned long pclk)
925{
926 struct tegra_hdmi *hdmi = to_hdmi(output);
927 struct clk *base;
928 int err;
929
930 err = clk_set_parent(clk, hdmi->clk_parent);
931 if (err < 0) {
932 dev_err(output->dev, "failed to set parent: %d\n", err);
933 return err;
934 }
935
936 base = clk_get_parent(hdmi->clk_parent);
937
938 /*
939 * This assumes that the parent clock is pll_d_out0 or pll_d2_out
940 * respectively, each of which divides the base pll_d by 2.
941 */
942 err = clk_set_rate(base, pclk * 2);
943 if (err < 0)
944 dev_err(output->dev,
945 "failed to set base clock rate to %lu Hz\n",
946 pclk * 2);
947
948 return 0;
949}
950
951static int tegra_output_hdmi_check_mode(struct tegra_output *output,
952 struct drm_display_mode *mode,
953 enum drm_mode_status *status)
954{
955 struct tegra_hdmi *hdmi = to_hdmi(output);
956 unsigned long pclk = mode->clock * 1000;
957 struct clk *parent;
958 long err;
959
960 parent = clk_get_parent(hdmi->clk_parent);
961
962 err = clk_round_rate(parent, pclk * 4);
963 if (err < 0)
964 *status = MODE_NOCLOCK;
965 else
966 *status = MODE_OK;
967
968 return 0;
969}
970
971static const struct tegra_output_ops hdmi_ops = {
972 .enable = tegra_output_hdmi_enable,
973 .disable = tegra_output_hdmi_disable,
974 .setup_clock = tegra_output_hdmi_setup_clock,
975 .check_mode = tegra_output_hdmi_check_mode,
976};
977
978static int tegra_hdmi_show_regs(struct seq_file *s, void *data)
979{
980 struct drm_info_node *node = s->private;
981 struct tegra_hdmi *hdmi = node->info_ent->data;
Mikko Perttunenccaddfe2013-07-30 11:35:03 +0300982 int err;
983
984 err = clk_enable(hdmi->clk);
985 if (err)
986 return err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000987
988#define DUMP_REG(name) \
989 seq_printf(s, "%-56s %#05x %08lx\n", #name, name, \
990 tegra_hdmi_readl(hdmi, name))
991
992 DUMP_REG(HDMI_CTXSW);
993 DUMP_REG(HDMI_NV_PDISP_SOR_STATE0);
994 DUMP_REG(HDMI_NV_PDISP_SOR_STATE1);
995 DUMP_REG(HDMI_NV_PDISP_SOR_STATE2);
996 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_MSB);
997 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_LSB);
998 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_MSB);
999 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_LSB);
1000 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_MSB);
1001 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_LSB);
1002 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_MSB);
1003 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_LSB);
1004 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_MSB);
1005 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_LSB);
1006 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_MSB);
1007 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_LSB);
1008 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CTRL);
1009 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CMODE);
1010 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_MSB);
1011 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_LSB);
1012 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_MSB);
1013 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB2);
1014 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB1);
1015 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_RI);
1016 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_MSB);
1017 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_LSB);
1018 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU0);
1019 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU_RDATA0);
1020 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU1);
1021 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU2);
1022 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
1023 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_STATUS);
1024 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER);
1025 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_LOW);
1026 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_HIGH);
1027 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
1028 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_STATUS);
1029 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER);
1030 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_LOW);
1031 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_HIGH);
1032 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_LOW);
1033 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_HIGH);
1034 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
1035 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_STATUS);
1036 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_HEADER);
1037 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_LOW);
1038 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_HIGH);
1039 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_LOW);
1040 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_HIGH);
1041 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_LOW);
1042 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_HIGH);
1043 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_LOW);
1044 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_HIGH);
1045 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_CTRL);
1046 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_LOW);
1047 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_HIGH);
1048 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
1049 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
1050 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_LOW);
1051 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_HIGH);
1052 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_LOW);
1053 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_HIGH);
1054 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_LOW);
1055 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_HIGH);
1056 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_LOW);
1057 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_HIGH);
1058 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_LOW);
1059 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_HIGH);
1060 DUMP_REG(HDMI_NV_PDISP_HDMI_CTRL);
1061 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_KEEPOUT);
1062 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
1063 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_CTRL);
1064 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_STATUS);
1065 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_SUBPACK);
1066 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS1);
1067 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS2);
1068 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU0);
1069 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1);
1070 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1_RDATA);
1071 DUMP_REG(HDMI_NV_PDISP_HDMI_SPARE);
1072 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS1);
1073 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS2);
1074 DUMP_REG(HDMI_NV_PDISP_HDMI_HDCPRIF_ROM_CTRL);
1075 DUMP_REG(HDMI_NV_PDISP_SOR_CAP);
1076 DUMP_REG(HDMI_NV_PDISP_SOR_PWR);
1077 DUMP_REG(HDMI_NV_PDISP_SOR_TEST);
1078 DUMP_REG(HDMI_NV_PDISP_SOR_PLL0);
1079 DUMP_REG(HDMI_NV_PDISP_SOR_PLL1);
1080 DUMP_REG(HDMI_NV_PDISP_SOR_PLL2);
1081 DUMP_REG(HDMI_NV_PDISP_SOR_CSTM);
1082 DUMP_REG(HDMI_NV_PDISP_SOR_LVDS);
1083 DUMP_REG(HDMI_NV_PDISP_SOR_CRCA);
1084 DUMP_REG(HDMI_NV_PDISP_SOR_CRCB);
1085 DUMP_REG(HDMI_NV_PDISP_SOR_BLANK);
1086 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_CTL);
1087 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(0));
1088 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(1));
1089 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(2));
1090 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(3));
1091 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(4));
1092 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(5));
1093 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(6));
1094 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(7));
1095 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(8));
1096 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(9));
1097 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(10));
1098 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(11));
1099 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(12));
1100 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(13));
1101 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(14));
1102 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(15));
1103 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA0);
1104 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA1);
1105 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA0);
1106 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA1);
1107 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA0);
1108 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA1);
1109 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA0);
1110 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA1);
1111 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA0);
1112 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA1);
1113 DUMP_REG(HDMI_NV_PDISP_SOR_TRIG);
1114 DUMP_REG(HDMI_NV_PDISP_SOR_MSCHECK);
1115 DUMP_REG(HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
1116 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG0);
1117 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG1);
1118 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG2);
1119 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(0));
1120 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(1));
1121 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(2));
1122 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(3));
1123 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(4));
1124 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(5));
1125 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(6));
1126 DUMP_REG(HDMI_NV_PDISP_AUDIO_PULSE_WIDTH);
1127 DUMP_REG(HDMI_NV_PDISP_AUDIO_THRESHOLD);
1128 DUMP_REG(HDMI_NV_PDISP_AUDIO_CNTRL0);
1129 DUMP_REG(HDMI_NV_PDISP_AUDIO_N);
1130 DUMP_REG(HDMI_NV_PDISP_HDCPRIF_ROM_TIMING);
1131 DUMP_REG(HDMI_NV_PDISP_SOR_REFCLK);
1132 DUMP_REG(HDMI_NV_PDISP_CRC_CONTROL);
1133 DUMP_REG(HDMI_NV_PDISP_INPUT_CONTROL);
1134 DUMP_REG(HDMI_NV_PDISP_SCRATCH);
1135 DUMP_REG(HDMI_NV_PDISP_PE_CURRENT);
1136 DUMP_REG(HDMI_NV_PDISP_KEY_CTRL);
1137 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG0);
1138 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG1);
1139 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG2);
1140 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_0);
1141 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_1);
1142 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_2);
1143 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_3);
1144 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_TRIG);
1145 DUMP_REG(HDMI_NV_PDISP_KEY_SKEY_INDEX);
1146 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
1147 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR);
1148 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001149 DUMP_REG(HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +00001150
1151#undef DUMP_REG
1152
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001153 clk_disable(hdmi->clk);
1154
Thierry Redingedec4af2012-11-15 21:28:23 +00001155 return 0;
1156}
1157
1158static struct drm_info_list debugfs_files[] = {
1159 { "regs", tegra_hdmi_show_regs, 0, NULL },
1160};
1161
1162static int tegra_hdmi_debugfs_init(struct tegra_hdmi *hdmi,
1163 struct drm_minor *minor)
1164{
1165 unsigned int i;
1166 int err;
1167
1168 hdmi->debugfs = debugfs_create_dir("hdmi", minor->debugfs_root);
1169 if (!hdmi->debugfs)
1170 return -ENOMEM;
1171
1172 hdmi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
1173 GFP_KERNEL);
1174 if (!hdmi->debugfs_files) {
1175 err = -ENOMEM;
1176 goto remove;
1177 }
1178
1179 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
1180 hdmi->debugfs_files[i].data = hdmi;
1181
1182 err = drm_debugfs_create_files(hdmi->debugfs_files,
1183 ARRAY_SIZE(debugfs_files),
1184 hdmi->debugfs, minor);
1185 if (err < 0)
1186 goto free;
1187
1188 hdmi->minor = minor;
1189
1190 return 0;
1191
1192free:
1193 kfree(hdmi->debugfs_files);
1194 hdmi->debugfs_files = NULL;
1195remove:
1196 debugfs_remove(hdmi->debugfs);
1197 hdmi->debugfs = NULL;
1198
1199 return err;
1200}
1201
1202static int tegra_hdmi_debugfs_exit(struct tegra_hdmi *hdmi)
1203{
1204 drm_debugfs_remove_files(hdmi->debugfs_files, ARRAY_SIZE(debugfs_files),
1205 hdmi->minor);
1206 hdmi->minor = NULL;
1207
1208 kfree(hdmi->debugfs_files);
1209 hdmi->debugfs_files = NULL;
1210
1211 debugfs_remove(hdmi->debugfs);
1212 hdmi->debugfs = NULL;
1213
1214 return 0;
1215}
1216
Thierry Reding53fa7f72013-09-24 15:35:40 +02001217static int tegra_hdmi_init(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001218{
Thierry Reding776dc382013-10-14 14:43:22 +02001219 struct tegra_drm *tegra = dev_get_drvdata(client->parent);
1220 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001221 int err;
1222
Mikko Perttunen18ebc0f2013-08-28 18:48:39 +03001223 err = regulator_enable(hdmi->vdd);
1224 if (err < 0) {
1225 dev_err(client->dev, "failed to enable VDD regulator: %d\n",
1226 err);
1227 return err;
1228 }
1229
Thierry Redingedec4af2012-11-15 21:28:23 +00001230 hdmi->output.type = TEGRA_OUTPUT_HDMI;
1231 hdmi->output.dev = client->dev;
1232 hdmi->output.ops = &hdmi_ops;
1233
Thierry Reding776dc382013-10-14 14:43:22 +02001234 err = tegra_output_init(tegra->drm, &hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001235 if (err < 0) {
1236 dev_err(client->dev, "output setup failed: %d\n", err);
1237 return err;
1238 }
1239
1240 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding776dc382013-10-14 14:43:22 +02001241 err = tegra_hdmi_debugfs_init(hdmi, tegra->drm->primary);
Thierry Redingedec4af2012-11-15 21:28:23 +00001242 if (err < 0)
1243 dev_err(client->dev, "debugfs setup failed: %d\n", err);
1244 }
1245
1246 return 0;
1247}
1248
Thierry Reding53fa7f72013-09-24 15:35:40 +02001249static int tegra_hdmi_exit(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001250{
Thierry Reding776dc382013-10-14 14:43:22 +02001251 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001252 int err;
1253
1254 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
1255 err = tegra_hdmi_debugfs_exit(hdmi);
1256 if (err < 0)
1257 dev_err(client->dev, "debugfs cleanup failed: %d\n",
1258 err);
1259 }
1260
1261 err = tegra_output_disable(&hdmi->output);
1262 if (err < 0) {
1263 dev_err(client->dev, "output failed to disable: %d\n", err);
1264 return err;
1265 }
1266
1267 err = tegra_output_exit(&hdmi->output);
1268 if (err < 0) {
1269 dev_err(client->dev, "output cleanup failed: %d\n", err);
1270 return err;
1271 }
1272
Mikko Perttunen18ebc0f2013-08-28 18:48:39 +03001273 regulator_disable(hdmi->vdd);
1274
Thierry Redingedec4af2012-11-15 21:28:23 +00001275 return 0;
1276}
1277
1278static const struct host1x_client_ops hdmi_client_ops = {
Thierry Reding53fa7f72013-09-24 15:35:40 +02001279 .init = tegra_hdmi_init,
1280 .exit = tegra_hdmi_exit,
Thierry Redingedec4af2012-11-15 21:28:23 +00001281};
1282
Thierry Reding59af0592013-10-14 09:43:05 +02001283static const struct tegra_hdmi_config tegra20_hdmi_config = {
1284 .tmds = tegra20_tmds_config,
1285 .num_tmds = ARRAY_SIZE(tegra20_tmds_config),
1286 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1287 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001288 .has_sor_io_peak_current = false,
Thierry Reding59af0592013-10-14 09:43:05 +02001289};
1290
1291static const struct tegra_hdmi_config tegra30_hdmi_config = {
1292 .tmds = tegra30_tmds_config,
1293 .num_tmds = ARRAY_SIZE(tegra30_tmds_config),
1294 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1295 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001296 .has_sor_io_peak_current = false,
1297};
1298
1299static const struct tegra_hdmi_config tegra114_hdmi_config = {
1300 .tmds = tegra114_tmds_config,
1301 .num_tmds = ARRAY_SIZE(tegra114_tmds_config),
1302 .fuse_override_offset = HDMI_NV_PDISP_SOR_PAD_CTLS0,
1303 .fuse_override_value = 1 << 31,
1304 .has_sor_io_peak_current = true,
Thierry Reding59af0592013-10-14 09:43:05 +02001305};
1306
1307static const struct of_device_id tegra_hdmi_of_match[] = {
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001308 { .compatible = "nvidia,tegra114-hdmi", .data = &tegra114_hdmi_config },
Thierry Reding59af0592013-10-14 09:43:05 +02001309 { .compatible = "nvidia,tegra30-hdmi", .data = &tegra30_hdmi_config },
1310 { .compatible = "nvidia,tegra20-hdmi", .data = &tegra20_hdmi_config },
1311 { },
1312};
1313
Thierry Redingedec4af2012-11-15 21:28:23 +00001314static int tegra_hdmi_probe(struct platform_device *pdev)
1315{
Thierry Reding59af0592013-10-14 09:43:05 +02001316 const struct of_device_id *match;
Thierry Redingedec4af2012-11-15 21:28:23 +00001317 struct tegra_hdmi *hdmi;
1318 struct resource *regs;
1319 int err;
1320
Thierry Reding59af0592013-10-14 09:43:05 +02001321 match = of_match_node(tegra_hdmi_of_match, pdev->dev.of_node);
1322 if (!match)
1323 return -ENODEV;
1324
Thierry Redingedec4af2012-11-15 21:28:23 +00001325 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
1326 if (!hdmi)
1327 return -ENOMEM;
1328
Thierry Reding59af0592013-10-14 09:43:05 +02001329 hdmi->config = match->data;
Thierry Redingedec4af2012-11-15 21:28:23 +00001330 hdmi->dev = &pdev->dev;
1331 hdmi->audio_source = AUTO;
1332 hdmi->audio_freq = 44100;
1333 hdmi->stereo = false;
1334 hdmi->dvi = false;
1335
1336 hdmi->clk = devm_clk_get(&pdev->dev, NULL);
1337 if (IS_ERR(hdmi->clk)) {
1338 dev_err(&pdev->dev, "failed to get clock\n");
1339 return PTR_ERR(hdmi->clk);
1340 }
1341
Stephen Warrenca480802013-11-06 16:20:54 -07001342 hdmi->rst = devm_reset_control_get(&pdev->dev, "hdmi");
1343 if (IS_ERR(hdmi->rst)) {
1344 dev_err(&pdev->dev, "failed to get reset\n");
1345 return PTR_ERR(hdmi->rst);
1346 }
1347
Thierry Redingedec4af2012-11-15 21:28:23 +00001348 err = clk_prepare(hdmi->clk);
1349 if (err < 0)
1350 return err;
1351
1352 hdmi->clk_parent = devm_clk_get(&pdev->dev, "parent");
1353 if (IS_ERR(hdmi->clk_parent))
1354 return PTR_ERR(hdmi->clk_parent);
1355
1356 err = clk_prepare(hdmi->clk_parent);
1357 if (err < 0)
1358 return err;
1359
1360 err = clk_set_parent(hdmi->clk, hdmi->clk_parent);
1361 if (err < 0) {
1362 dev_err(&pdev->dev, "failed to setup clocks: %d\n", err);
1363 return err;
1364 }
1365
1366 hdmi->vdd = devm_regulator_get(&pdev->dev, "vdd");
1367 if (IS_ERR(hdmi->vdd)) {
1368 dev_err(&pdev->dev, "failed to get VDD regulator\n");
1369 return PTR_ERR(hdmi->vdd);
1370 }
1371
1372 hdmi->pll = devm_regulator_get(&pdev->dev, "pll");
1373 if (IS_ERR(hdmi->pll)) {
1374 dev_err(&pdev->dev, "failed to get PLL regulator\n");
1375 return PTR_ERR(hdmi->pll);
1376 }
1377
1378 hdmi->output.dev = &pdev->dev;
1379
Thierry Reding59d29c02013-10-14 14:26:42 +02001380 err = tegra_output_probe(&hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001381 if (err < 0)
1382 return err;
1383
1384 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1385 if (!regs)
1386 return -ENXIO;
1387
Thierry Redingd4ed6022013-01-21 11:09:02 +01001388 hdmi->regs = devm_ioremap_resource(&pdev->dev, regs);
1389 if (IS_ERR(hdmi->regs))
1390 return PTR_ERR(hdmi->regs);
Thierry Redingedec4af2012-11-15 21:28:23 +00001391
1392 err = platform_get_irq(pdev, 0);
1393 if (err < 0)
1394 return err;
1395
1396 hdmi->irq = err;
1397
Thierry Reding776dc382013-10-14 14:43:22 +02001398 INIT_LIST_HEAD(&hdmi->client.list);
1399 hdmi->client.ops = &hdmi_client_ops;
1400 hdmi->client.dev = &pdev->dev;
Thierry Redingedec4af2012-11-15 21:28:23 +00001401
Thierry Reding776dc382013-10-14 14:43:22 +02001402 err = host1x_client_register(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001403 if (err < 0) {
1404 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1405 err);
1406 return err;
1407 }
1408
1409 platform_set_drvdata(pdev, hdmi);
1410
1411 return 0;
1412}
1413
1414static int tegra_hdmi_remove(struct platform_device *pdev)
1415{
Thierry Redingedec4af2012-11-15 21:28:23 +00001416 struct tegra_hdmi *hdmi = platform_get_drvdata(pdev);
1417 int err;
1418
Thierry Reding776dc382013-10-14 14:43:22 +02001419 err = host1x_client_unregister(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001420 if (err < 0) {
1421 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1422 err);
1423 return err;
1424 }
1425
Thierry Reding59d29c02013-10-14 14:26:42 +02001426 err = tegra_output_remove(&hdmi->output);
1427 if (err < 0) {
1428 dev_err(&pdev->dev, "failed to remove output: %d\n", err);
1429 return err;
1430 }
1431
Thierry Redingedec4af2012-11-15 21:28:23 +00001432 clk_unprepare(hdmi->clk_parent);
1433 clk_unprepare(hdmi->clk);
1434
1435 return 0;
1436}
1437
Thierry Redingedec4af2012-11-15 21:28:23 +00001438struct platform_driver tegra_hdmi_driver = {
1439 .driver = {
1440 .name = "tegra-hdmi",
1441 .owner = THIS_MODULE,
1442 .of_match_table = tegra_hdmi_of_match,
1443 },
1444 .probe = tegra_hdmi_probe,
1445 .remove = tegra_hdmi_remove,
1446};