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