blob: ce32bfb7f86d626981535b6ce11f07f58083ecc1 [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) {
599 dev_err(hdmi->dev, "failed to initialize audio infoframe: %d\n",
600 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 */
619 tegra_hdmi_write_infopack(hdmi, buffer, min(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
677static int tegra_output_hdmi_enable(struct tegra_output *output)
678{
679 unsigned int h_sync_width, h_front_porch, h_back_porch, i, rekey;
680 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
681 struct drm_display_mode *mode = &dc->base.mode;
682 struct tegra_hdmi *hdmi = to_hdmi(output);
683 struct device_node *node = hdmi->dev->of_node;
684 unsigned int pulse_start, div82, pclk;
Thierry Redingedec4af2012-11-15 21:28:23 +0000685 unsigned long value;
686 int retries = 1000;
687 int err;
688
689 pclk = mode->clock * 1000;
690 h_sync_width = mode->hsync_end - mode->hsync_start;
Lucas Stach40495082012-12-19 21:38:52 +0000691 h_back_porch = mode->htotal - mode->hsync_end;
692 h_front_porch = mode->hsync_start - mode->hdisplay;
Thierry Redingedec4af2012-11-15 21:28:23 +0000693
694 err = regulator_enable(hdmi->vdd);
695 if (err < 0) {
696 dev_err(hdmi->dev, "failed to enable VDD regulator: %d\n", err);
697 return err;
698 }
699
700 err = regulator_enable(hdmi->pll);
701 if (err < 0) {
702 dev_err(hdmi->dev, "failed to enable PLL regulator: %d\n", err);
703 return err;
704 }
705
706 /*
707 * This assumes that the display controller will divide its parent
708 * clock by 2 to generate the pixel clock.
709 */
710 err = tegra_output_setup_clock(output, hdmi->clk, pclk * 2);
711 if (err < 0) {
712 dev_err(hdmi->dev, "failed to setup clock: %d\n", err);
713 return err;
714 }
715
716 err = clk_set_rate(hdmi->clk, pclk);
717 if (err < 0)
718 return err;
719
720 err = clk_enable(hdmi->clk);
721 if (err < 0) {
722 dev_err(hdmi->dev, "failed to enable clock: %d\n", err);
723 return err;
724 }
725
726 tegra_periph_reset_assert(hdmi->clk);
727 usleep_range(1000, 2000);
728 tegra_periph_reset_deassert(hdmi->clk);
729
730 tegra_dc_writel(dc, VSYNC_H_POSITION(1),
731 DC_DISP_DISP_TIMING_OPTIONS);
732 tegra_dc_writel(dc, DITHER_CONTROL_DISABLE | BASE_COLOR_SIZE888,
733 DC_DISP_DISP_COLOR_CONTROL);
734
735 /* video_preamble uses h_pulse2 */
736 pulse_start = 1 + h_sync_width + h_back_porch - 10;
737
738 tegra_dc_writel(dc, H_PULSE_2_ENABLE, DC_DISP_DISP_SIGNAL_OPTIONS0);
739
740 value = PULSE_MODE_NORMAL | PULSE_POLARITY_HIGH | PULSE_QUAL_VACTIVE |
741 PULSE_LAST_END_A;
742 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL);
743
744 value = PULSE_START(pulse_start) | PULSE_END(pulse_start + 8);
745 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A);
746
747 value = VSYNC_WINDOW_END(0x210) | VSYNC_WINDOW_START(0x200) |
748 VSYNC_WINDOW_ENABLE;
749 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
750
751 if (dc->pipe)
752 value = HDMI_SRC_DISPLAYB;
753 else
754 value = HDMI_SRC_DISPLAYA;
755
756 if ((mode->hdisplay == 720) && ((mode->vdisplay == 480) ||
757 (mode->vdisplay == 576)))
758 tegra_hdmi_writel(hdmi,
759 value | ARM_VIDEO_RANGE_FULL,
760 HDMI_NV_PDISP_INPUT_CONTROL);
761 else
762 tegra_hdmi_writel(hdmi,
763 value | ARM_VIDEO_RANGE_LIMITED,
764 HDMI_NV_PDISP_INPUT_CONTROL);
765
766 div82 = clk_get_rate(hdmi->clk) / 1000000 * 4;
767 value = SOR_REFCLK_DIV_INT(div82 >> 2) | SOR_REFCLK_DIV_FRAC(div82);
768 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_REFCLK);
769
770 if (!hdmi->dvi) {
771 err = tegra_hdmi_setup_audio(hdmi, pclk);
772 if (err < 0)
773 hdmi->dvi = true;
774 }
775
776 if (of_device_is_compatible(node, "nvidia,tegra20-hdmi")) {
777 /*
778 * TODO: add ELD support
779 */
780 }
781
782 rekey = HDMI_REKEY_DEFAULT;
783 value = HDMI_CTRL_REKEY(rekey);
784 value |= HDMI_CTRL_MAX_AC_PACKET((h_sync_width + h_back_porch +
785 h_front_porch - rekey - 18) / 32);
786
787 if (!hdmi->dvi)
788 value |= HDMI_CTRL_ENABLE;
789
790 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_CTRL);
791
792 if (hdmi->dvi)
793 tegra_hdmi_writel(hdmi, 0x0,
794 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
795 else
796 tegra_hdmi_writel(hdmi, GENERIC_CTRL_AUDIO,
797 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
798
799 tegra_hdmi_setup_avi_infoframe(hdmi, mode);
800 tegra_hdmi_setup_audio_infoframe(hdmi);
801 tegra_hdmi_setup_stereo_infoframe(hdmi);
802
803 /* TMDS CONFIG */
Thierry Reding59af0592013-10-14 09:43:05 +0200804 for (i = 0; i < hdmi->config->num_tmds; i++) {
805 if (pclk <= hdmi->config->tmds[i].pclk) {
806 tegra_hdmi_setup_tmds(hdmi, &hdmi->config->tmds[i]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000807 break;
808 }
809 }
810
811 tegra_hdmi_writel(hdmi,
812 SOR_SEQ_CTL_PU_PC(0) |
813 SOR_SEQ_PU_PC_ALT(0) |
814 SOR_SEQ_PD_PC(8) |
815 SOR_SEQ_PD_PC_ALT(8),
816 HDMI_NV_PDISP_SOR_SEQ_CTL);
817
818 value = SOR_SEQ_INST_WAIT_TIME(1) |
819 SOR_SEQ_INST_WAIT_UNITS_VSYNC |
820 SOR_SEQ_INST_HALT |
821 SOR_SEQ_INST_PIN_A_LOW |
822 SOR_SEQ_INST_PIN_B_LOW |
823 SOR_SEQ_INST_DRIVE_PWM_OUT_LO;
824
825 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(0));
826 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(8));
827
828 value = 0x1c800;
829 value &= ~SOR_CSTM_ROTCLK(~0);
830 value |= SOR_CSTM_ROTCLK(2);
831 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_CSTM);
832
833 tegra_dc_writel(dc, DISP_CTRL_MODE_STOP, DC_CMD_DISPLAY_COMMAND);
834 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
835 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
836
837 /* start SOR */
838 tegra_hdmi_writel(hdmi,
839 SOR_PWR_NORMAL_STATE_PU |
840 SOR_PWR_NORMAL_START_NORMAL |
841 SOR_PWR_SAFE_STATE_PD |
842 SOR_PWR_SETTING_NEW_TRIGGER,
843 HDMI_NV_PDISP_SOR_PWR);
844 tegra_hdmi_writel(hdmi,
845 SOR_PWR_NORMAL_STATE_PU |
846 SOR_PWR_NORMAL_START_NORMAL |
847 SOR_PWR_SAFE_STATE_PD |
848 SOR_PWR_SETTING_NEW_DONE,
849 HDMI_NV_PDISP_SOR_PWR);
850
851 do {
852 BUG_ON(--retries < 0);
853 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PWR);
854 } while (value & SOR_PWR_SETTING_NEW_PENDING);
855
856 value = SOR_STATE_ASY_CRCMODE_COMPLETE |
857 SOR_STATE_ASY_OWNER_HEAD0 |
858 SOR_STATE_ASY_SUBOWNER_BOTH |
859 SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A |
860 SOR_STATE_ASY_DEPOL_POS;
861
862 /* setup sync polarities */
863 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
864 value |= SOR_STATE_ASY_HSYNCPOL_POS;
865
866 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
867 value |= SOR_STATE_ASY_HSYNCPOL_NEG;
868
869 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
870 value |= SOR_STATE_ASY_VSYNCPOL_POS;
871
872 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
873 value |= SOR_STATE_ASY_VSYNCPOL_NEG;
874
875 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE2);
876
877 value = SOR_STATE_ASY_HEAD_OPMODE_AWAKE | SOR_STATE_ASY_ORMODE_NORMAL;
878 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE1);
879
880 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
881 tegra_hdmi_writel(hdmi, SOR_STATE_UPDATE, HDMI_NV_PDISP_SOR_STATE0);
882 tegra_hdmi_writel(hdmi, value | SOR_STATE_ATTACHED,
883 HDMI_NV_PDISP_SOR_STATE1);
884 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
885
886 tegra_dc_writel(dc, HDMI_ENABLE, DC_DISP_DISP_WIN_OPTIONS);
887
888 value = PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
889 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
890 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
891
892 value = DISP_CTRL_MODE_C_DISPLAY;
893 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
894
895 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
896 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
897
898 /* TODO: add HDCP support */
899
900 return 0;
901}
902
903static int tegra_output_hdmi_disable(struct tegra_output *output)
904{
905 struct tegra_hdmi *hdmi = to_hdmi(output);
906
907 tegra_periph_reset_assert(hdmi->clk);
908 clk_disable(hdmi->clk);
909 regulator_disable(hdmi->pll);
910 regulator_disable(hdmi->vdd);
911
912 return 0;
913}
914
915static int tegra_output_hdmi_setup_clock(struct tegra_output *output,
916 struct clk *clk, unsigned long pclk)
917{
918 struct tegra_hdmi *hdmi = to_hdmi(output);
919 struct clk *base;
920 int err;
921
922 err = clk_set_parent(clk, hdmi->clk_parent);
923 if (err < 0) {
924 dev_err(output->dev, "failed to set parent: %d\n", err);
925 return err;
926 }
927
928 base = clk_get_parent(hdmi->clk_parent);
929
930 /*
931 * This assumes that the parent clock is pll_d_out0 or pll_d2_out
932 * respectively, each of which divides the base pll_d by 2.
933 */
934 err = clk_set_rate(base, pclk * 2);
935 if (err < 0)
936 dev_err(output->dev,
937 "failed to set base clock rate to %lu Hz\n",
938 pclk * 2);
939
940 return 0;
941}
942
943static int tegra_output_hdmi_check_mode(struct tegra_output *output,
944 struct drm_display_mode *mode,
945 enum drm_mode_status *status)
946{
947 struct tegra_hdmi *hdmi = to_hdmi(output);
948 unsigned long pclk = mode->clock * 1000;
949 struct clk *parent;
950 long err;
951
952 parent = clk_get_parent(hdmi->clk_parent);
953
954 err = clk_round_rate(parent, pclk * 4);
955 if (err < 0)
956 *status = MODE_NOCLOCK;
957 else
958 *status = MODE_OK;
959
960 return 0;
961}
962
963static const struct tegra_output_ops hdmi_ops = {
964 .enable = tegra_output_hdmi_enable,
965 .disable = tegra_output_hdmi_disable,
966 .setup_clock = tegra_output_hdmi_setup_clock,
967 .check_mode = tegra_output_hdmi_check_mode,
968};
969
970static int tegra_hdmi_show_regs(struct seq_file *s, void *data)
971{
972 struct drm_info_node *node = s->private;
973 struct tegra_hdmi *hdmi = node->info_ent->data;
Mikko Perttunenccaddfe2013-07-30 11:35:03 +0300974 int err;
975
976 err = clk_enable(hdmi->clk);
977 if (err)
978 return err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000979
980#define DUMP_REG(name) \
981 seq_printf(s, "%-56s %#05x %08lx\n", #name, name, \
982 tegra_hdmi_readl(hdmi, name))
983
984 DUMP_REG(HDMI_CTXSW);
985 DUMP_REG(HDMI_NV_PDISP_SOR_STATE0);
986 DUMP_REG(HDMI_NV_PDISP_SOR_STATE1);
987 DUMP_REG(HDMI_NV_PDISP_SOR_STATE2);
988 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_MSB);
989 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_LSB);
990 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_MSB);
991 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_LSB);
992 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_MSB);
993 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_LSB);
994 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_MSB);
995 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_LSB);
996 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_MSB);
997 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_LSB);
998 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_MSB);
999 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_LSB);
1000 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CTRL);
1001 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CMODE);
1002 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_MSB);
1003 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_LSB);
1004 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_MSB);
1005 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB2);
1006 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB1);
1007 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_RI);
1008 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_MSB);
1009 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_LSB);
1010 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU0);
1011 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU_RDATA0);
1012 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU1);
1013 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU2);
1014 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
1015 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_STATUS);
1016 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER);
1017 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_LOW);
1018 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_HIGH);
1019 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
1020 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_STATUS);
1021 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER);
1022 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_LOW);
1023 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_HIGH);
1024 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_LOW);
1025 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_HIGH);
1026 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
1027 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_STATUS);
1028 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_HEADER);
1029 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_LOW);
1030 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_HIGH);
1031 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_LOW);
1032 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_HIGH);
1033 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_LOW);
1034 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_HIGH);
1035 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_LOW);
1036 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_HIGH);
1037 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_CTRL);
1038 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_LOW);
1039 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_HIGH);
1040 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
1041 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
1042 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_LOW);
1043 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_HIGH);
1044 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_LOW);
1045 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_HIGH);
1046 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_LOW);
1047 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_HIGH);
1048 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_LOW);
1049 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_HIGH);
1050 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_LOW);
1051 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_HIGH);
1052 DUMP_REG(HDMI_NV_PDISP_HDMI_CTRL);
1053 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_KEEPOUT);
1054 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
1055 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_CTRL);
1056 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_STATUS);
1057 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_SUBPACK);
1058 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS1);
1059 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS2);
1060 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU0);
1061 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1);
1062 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1_RDATA);
1063 DUMP_REG(HDMI_NV_PDISP_HDMI_SPARE);
1064 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS1);
1065 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS2);
1066 DUMP_REG(HDMI_NV_PDISP_HDMI_HDCPRIF_ROM_CTRL);
1067 DUMP_REG(HDMI_NV_PDISP_SOR_CAP);
1068 DUMP_REG(HDMI_NV_PDISP_SOR_PWR);
1069 DUMP_REG(HDMI_NV_PDISP_SOR_TEST);
1070 DUMP_REG(HDMI_NV_PDISP_SOR_PLL0);
1071 DUMP_REG(HDMI_NV_PDISP_SOR_PLL1);
1072 DUMP_REG(HDMI_NV_PDISP_SOR_PLL2);
1073 DUMP_REG(HDMI_NV_PDISP_SOR_CSTM);
1074 DUMP_REG(HDMI_NV_PDISP_SOR_LVDS);
1075 DUMP_REG(HDMI_NV_PDISP_SOR_CRCA);
1076 DUMP_REG(HDMI_NV_PDISP_SOR_CRCB);
1077 DUMP_REG(HDMI_NV_PDISP_SOR_BLANK);
1078 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_CTL);
1079 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(0));
1080 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(1));
1081 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(2));
1082 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(3));
1083 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(4));
1084 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(5));
1085 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(6));
1086 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(7));
1087 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(8));
1088 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(9));
1089 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(10));
1090 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(11));
1091 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(12));
1092 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(13));
1093 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(14));
1094 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(15));
1095 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA0);
1096 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA1);
1097 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA0);
1098 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA1);
1099 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA0);
1100 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA1);
1101 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA0);
1102 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA1);
1103 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA0);
1104 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA1);
1105 DUMP_REG(HDMI_NV_PDISP_SOR_TRIG);
1106 DUMP_REG(HDMI_NV_PDISP_SOR_MSCHECK);
1107 DUMP_REG(HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
1108 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG0);
1109 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG1);
1110 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG2);
1111 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(0));
1112 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(1));
1113 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(2));
1114 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(3));
1115 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(4));
1116 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(5));
1117 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(6));
1118 DUMP_REG(HDMI_NV_PDISP_AUDIO_PULSE_WIDTH);
1119 DUMP_REG(HDMI_NV_PDISP_AUDIO_THRESHOLD);
1120 DUMP_REG(HDMI_NV_PDISP_AUDIO_CNTRL0);
1121 DUMP_REG(HDMI_NV_PDISP_AUDIO_N);
1122 DUMP_REG(HDMI_NV_PDISP_HDCPRIF_ROM_TIMING);
1123 DUMP_REG(HDMI_NV_PDISP_SOR_REFCLK);
1124 DUMP_REG(HDMI_NV_PDISP_CRC_CONTROL);
1125 DUMP_REG(HDMI_NV_PDISP_INPUT_CONTROL);
1126 DUMP_REG(HDMI_NV_PDISP_SCRATCH);
1127 DUMP_REG(HDMI_NV_PDISP_PE_CURRENT);
1128 DUMP_REG(HDMI_NV_PDISP_KEY_CTRL);
1129 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG0);
1130 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG1);
1131 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG2);
1132 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_0);
1133 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_1);
1134 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_2);
1135 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_3);
1136 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_TRIG);
1137 DUMP_REG(HDMI_NV_PDISP_KEY_SKEY_INDEX);
1138 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
1139 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR);
1140 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001141 DUMP_REG(HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +00001142
1143#undef DUMP_REG
1144
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001145 clk_disable(hdmi->clk);
1146
Thierry Redingedec4af2012-11-15 21:28:23 +00001147 return 0;
1148}
1149
1150static struct drm_info_list debugfs_files[] = {
1151 { "regs", tegra_hdmi_show_regs, 0, NULL },
1152};
1153
1154static int tegra_hdmi_debugfs_init(struct tegra_hdmi *hdmi,
1155 struct drm_minor *minor)
1156{
1157 unsigned int i;
1158 int err;
1159
1160 hdmi->debugfs = debugfs_create_dir("hdmi", minor->debugfs_root);
1161 if (!hdmi->debugfs)
1162 return -ENOMEM;
1163
1164 hdmi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
1165 GFP_KERNEL);
1166 if (!hdmi->debugfs_files) {
1167 err = -ENOMEM;
1168 goto remove;
1169 }
1170
1171 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
1172 hdmi->debugfs_files[i].data = hdmi;
1173
1174 err = drm_debugfs_create_files(hdmi->debugfs_files,
1175 ARRAY_SIZE(debugfs_files),
1176 hdmi->debugfs, minor);
1177 if (err < 0)
1178 goto free;
1179
1180 hdmi->minor = minor;
1181
1182 return 0;
1183
1184free:
1185 kfree(hdmi->debugfs_files);
1186 hdmi->debugfs_files = NULL;
1187remove:
1188 debugfs_remove(hdmi->debugfs);
1189 hdmi->debugfs = NULL;
1190
1191 return err;
1192}
1193
1194static int tegra_hdmi_debugfs_exit(struct tegra_hdmi *hdmi)
1195{
1196 drm_debugfs_remove_files(hdmi->debugfs_files, ARRAY_SIZE(debugfs_files),
1197 hdmi->minor);
1198 hdmi->minor = NULL;
1199
1200 kfree(hdmi->debugfs_files);
1201 hdmi->debugfs_files = NULL;
1202
1203 debugfs_remove(hdmi->debugfs);
1204 hdmi->debugfs = NULL;
1205
1206 return 0;
1207}
1208
Thierry Reding53fa7f72013-09-24 15:35:40 +02001209static int tegra_hdmi_init(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001210{
Thierry Reding776dc382013-10-14 14:43:22 +02001211 struct tegra_drm *tegra = dev_get_drvdata(client->parent);
1212 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001213 int err;
1214
1215 hdmi->output.type = TEGRA_OUTPUT_HDMI;
1216 hdmi->output.dev = client->dev;
1217 hdmi->output.ops = &hdmi_ops;
1218
Thierry Reding776dc382013-10-14 14:43:22 +02001219 err = tegra_output_init(tegra->drm, &hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001220 if (err < 0) {
1221 dev_err(client->dev, "output setup failed: %d\n", err);
1222 return err;
1223 }
1224
1225 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding776dc382013-10-14 14:43:22 +02001226 err = tegra_hdmi_debugfs_init(hdmi, tegra->drm->primary);
Thierry Redingedec4af2012-11-15 21:28:23 +00001227 if (err < 0)
1228 dev_err(client->dev, "debugfs setup failed: %d\n", err);
1229 }
1230
1231 return 0;
1232}
1233
Thierry Reding53fa7f72013-09-24 15:35:40 +02001234static int tegra_hdmi_exit(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001235{
Thierry Reding776dc382013-10-14 14:43:22 +02001236 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001237 int err;
1238
1239 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
1240 err = tegra_hdmi_debugfs_exit(hdmi);
1241 if (err < 0)
1242 dev_err(client->dev, "debugfs cleanup failed: %d\n",
1243 err);
1244 }
1245
1246 err = tegra_output_disable(&hdmi->output);
1247 if (err < 0) {
1248 dev_err(client->dev, "output failed to disable: %d\n", err);
1249 return err;
1250 }
1251
1252 err = tegra_output_exit(&hdmi->output);
1253 if (err < 0) {
1254 dev_err(client->dev, "output cleanup failed: %d\n", err);
1255 return err;
1256 }
1257
1258 return 0;
1259}
1260
1261static const struct host1x_client_ops hdmi_client_ops = {
Thierry Reding53fa7f72013-09-24 15:35:40 +02001262 .init = tegra_hdmi_init,
1263 .exit = tegra_hdmi_exit,
Thierry Redingedec4af2012-11-15 21:28:23 +00001264};
1265
Thierry Reding59af0592013-10-14 09:43:05 +02001266static const struct tegra_hdmi_config tegra20_hdmi_config = {
1267 .tmds = tegra20_tmds_config,
1268 .num_tmds = ARRAY_SIZE(tegra20_tmds_config),
1269 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1270 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001271 .has_sor_io_peak_current = false,
Thierry Reding59af0592013-10-14 09:43:05 +02001272};
1273
1274static const struct tegra_hdmi_config tegra30_hdmi_config = {
1275 .tmds = tegra30_tmds_config,
1276 .num_tmds = ARRAY_SIZE(tegra30_tmds_config),
1277 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1278 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001279 .has_sor_io_peak_current = false,
1280};
1281
1282static const struct tegra_hdmi_config tegra114_hdmi_config = {
1283 .tmds = tegra114_tmds_config,
1284 .num_tmds = ARRAY_SIZE(tegra114_tmds_config),
1285 .fuse_override_offset = HDMI_NV_PDISP_SOR_PAD_CTLS0,
1286 .fuse_override_value = 1 << 31,
1287 .has_sor_io_peak_current = true,
Thierry Reding59af0592013-10-14 09:43:05 +02001288};
1289
1290static const struct of_device_id tegra_hdmi_of_match[] = {
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001291 { .compatible = "nvidia,tegra114-hdmi", .data = &tegra114_hdmi_config },
Thierry Reding59af0592013-10-14 09:43:05 +02001292 { .compatible = "nvidia,tegra30-hdmi", .data = &tegra30_hdmi_config },
1293 { .compatible = "nvidia,tegra20-hdmi", .data = &tegra20_hdmi_config },
1294 { },
1295};
1296
Thierry Redingedec4af2012-11-15 21:28:23 +00001297static int tegra_hdmi_probe(struct platform_device *pdev)
1298{
Thierry Reding59af0592013-10-14 09:43:05 +02001299 const struct of_device_id *match;
Thierry Redingedec4af2012-11-15 21:28:23 +00001300 struct tegra_hdmi *hdmi;
1301 struct resource *regs;
1302 int err;
1303
Thierry Reding59af0592013-10-14 09:43:05 +02001304 match = of_match_node(tegra_hdmi_of_match, pdev->dev.of_node);
1305 if (!match)
1306 return -ENODEV;
1307
Thierry Redingedec4af2012-11-15 21:28:23 +00001308 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
1309 if (!hdmi)
1310 return -ENOMEM;
1311
Thierry Reding59af0592013-10-14 09:43:05 +02001312 hdmi->config = match->data;
Thierry Redingedec4af2012-11-15 21:28:23 +00001313 hdmi->dev = &pdev->dev;
1314 hdmi->audio_source = AUTO;
1315 hdmi->audio_freq = 44100;
1316 hdmi->stereo = false;
1317 hdmi->dvi = false;
1318
1319 hdmi->clk = devm_clk_get(&pdev->dev, NULL);
1320 if (IS_ERR(hdmi->clk)) {
1321 dev_err(&pdev->dev, "failed to get clock\n");
1322 return PTR_ERR(hdmi->clk);
1323 }
1324
1325 err = clk_prepare(hdmi->clk);
1326 if (err < 0)
1327 return err;
1328
1329 hdmi->clk_parent = devm_clk_get(&pdev->dev, "parent");
1330 if (IS_ERR(hdmi->clk_parent))
1331 return PTR_ERR(hdmi->clk_parent);
1332
1333 err = clk_prepare(hdmi->clk_parent);
1334 if (err < 0)
1335 return err;
1336
1337 err = clk_set_parent(hdmi->clk, hdmi->clk_parent);
1338 if (err < 0) {
1339 dev_err(&pdev->dev, "failed to setup clocks: %d\n", err);
1340 return err;
1341 }
1342
1343 hdmi->vdd = devm_regulator_get(&pdev->dev, "vdd");
1344 if (IS_ERR(hdmi->vdd)) {
1345 dev_err(&pdev->dev, "failed to get VDD regulator\n");
1346 return PTR_ERR(hdmi->vdd);
1347 }
1348
1349 hdmi->pll = devm_regulator_get(&pdev->dev, "pll");
1350 if (IS_ERR(hdmi->pll)) {
1351 dev_err(&pdev->dev, "failed to get PLL regulator\n");
1352 return PTR_ERR(hdmi->pll);
1353 }
1354
1355 hdmi->output.dev = &pdev->dev;
1356
Thierry Reding59d29c02013-10-14 14:26:42 +02001357 err = tegra_output_probe(&hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001358 if (err < 0)
1359 return err;
1360
1361 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1362 if (!regs)
1363 return -ENXIO;
1364
Thierry Redingd4ed6022013-01-21 11:09:02 +01001365 hdmi->regs = devm_ioremap_resource(&pdev->dev, regs);
1366 if (IS_ERR(hdmi->regs))
1367 return PTR_ERR(hdmi->regs);
Thierry Redingedec4af2012-11-15 21:28:23 +00001368
1369 err = platform_get_irq(pdev, 0);
1370 if (err < 0)
1371 return err;
1372
1373 hdmi->irq = err;
1374
Thierry Reding776dc382013-10-14 14:43:22 +02001375 INIT_LIST_HEAD(&hdmi->client.list);
1376 hdmi->client.ops = &hdmi_client_ops;
1377 hdmi->client.dev = &pdev->dev;
Thierry Redingedec4af2012-11-15 21:28:23 +00001378
Thierry Reding776dc382013-10-14 14:43:22 +02001379 err = host1x_client_register(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001380 if (err < 0) {
1381 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1382 err);
1383 return err;
1384 }
1385
1386 platform_set_drvdata(pdev, hdmi);
1387
1388 return 0;
1389}
1390
1391static int tegra_hdmi_remove(struct platform_device *pdev)
1392{
Thierry Redingedec4af2012-11-15 21:28:23 +00001393 struct tegra_hdmi *hdmi = platform_get_drvdata(pdev);
1394 int err;
1395
Thierry Reding776dc382013-10-14 14:43:22 +02001396 err = host1x_client_unregister(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001397 if (err < 0) {
1398 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1399 err);
1400 return err;
1401 }
1402
Thierry Reding59d29c02013-10-14 14:26:42 +02001403 err = tegra_output_remove(&hdmi->output);
1404 if (err < 0) {
1405 dev_err(&pdev->dev, "failed to remove output: %d\n", err);
1406 return err;
1407 }
1408
Thierry Redingedec4af2012-11-15 21:28:23 +00001409 clk_unprepare(hdmi->clk_parent);
1410 clk_unprepare(hdmi->clk);
1411
1412 return 0;
1413}
1414
Thierry Redingedec4af2012-11-15 21:28:23 +00001415struct platform_driver tegra_hdmi_driver = {
1416 .driver = {
1417 .name = "tegra-hdmi",
1418 .owner = THIS_MODULE,
1419 .of_match_table = tegra_hdmi_of_match,
1420 },
1421 .probe = tegra_hdmi_probe,
1422 .remove = tegra_hdmi_remove,
1423};