blob: 19ce750e48561a060a92870dc36da1532407f1ae [file] [log] [blame]
Thierry Redingedec4af2012-11-15 21:28:23 +00001/*
2 * Copyright (C) 2012 Avionic Design GmbH
3 * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/clk.h>
Thierry Reding9eb9b222013-09-24 16:32:47 +020011#include <linux/debugfs.h>
12#include <linux/hdmi.h>
13#include <linux/regulator/consumer.h>
Stephen Warrenca480802013-11-06 16:20:54 -070014#include <linux/reset.h>
Thierry Redingac24c222012-11-23 15:14:00 +010015
Thierry Redingedec4af2012-11-15 21:28:23 +000016#include "hdmi.h"
17#include "drm.h"
18#include "dc.h"
19
Thierry Reding59af0592013-10-14 09:43:05 +020020struct tmds_config {
21 unsigned int pclk;
22 u32 pll0;
23 u32 pll1;
24 u32 pe_current;
25 u32 drive_current;
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +020026 u32 peak_current;
Thierry Reding59af0592013-10-14 09:43:05 +020027};
28
29struct tegra_hdmi_config {
30 const struct tmds_config *tmds;
31 unsigned int num_tmds;
32
33 unsigned long fuse_override_offset;
34 unsigned long fuse_override_value;
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +020035
36 bool has_sor_io_peak_current;
Thierry Reding59af0592013-10-14 09:43:05 +020037};
38
Thierry Redingedec4af2012-11-15 21:28:23 +000039struct tegra_hdmi {
Thierry Reding776dc382013-10-14 14:43:22 +020040 struct host1x_client client;
Thierry Redingedec4af2012-11-15 21:28:23 +000041 struct tegra_output output;
42 struct device *dev;
Thierry Reding365765f2013-10-29 16:00:42 +010043 bool enabled;
Thierry Redingedec4af2012-11-15 21:28:23 +000044
45 struct regulator *vdd;
46 struct regulator *pll;
47
48 void __iomem *regs;
49 unsigned int irq;
50
51 struct clk *clk_parent;
52 struct clk *clk;
Stephen Warrenca480802013-11-06 16:20:54 -070053 struct reset_control *rst;
Thierry Redingedec4af2012-11-15 21:28:23 +000054
Thierry Reding59af0592013-10-14 09:43:05 +020055 const struct tegra_hdmi_config *config;
56
Thierry Redingedec4af2012-11-15 21:28:23 +000057 unsigned int audio_source;
58 unsigned int audio_freq;
59 bool stereo;
60 bool dvi;
61
62 struct drm_info_list *debugfs_files;
63 struct drm_minor *minor;
64 struct dentry *debugfs;
65};
66
67static inline struct tegra_hdmi *
Thierry Reding776dc382013-10-14 14:43:22 +020068host1x_client_to_hdmi(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +000069{
70 return container_of(client, struct tegra_hdmi, client);
71}
72
73static inline struct tegra_hdmi *to_hdmi(struct tegra_output *output)
74{
75 return container_of(output, struct tegra_hdmi, output);
76}
77
78#define HDMI_AUDIOCLK_FREQ 216000000
79#define HDMI_REKEY_DEFAULT 56
80
81enum {
82 AUTO = 0,
83 SPDIF,
84 HDA,
85};
86
87static inline unsigned long tegra_hdmi_readl(struct tegra_hdmi *hdmi,
88 unsigned long reg)
89{
90 return readl(hdmi->regs + (reg << 2));
91}
92
93static inline void tegra_hdmi_writel(struct tegra_hdmi *hdmi, unsigned long val,
94 unsigned long reg)
95{
96 writel(val, hdmi->regs + (reg << 2));
97}
98
99struct tegra_hdmi_audio_config {
100 unsigned int pclk;
101 unsigned int n;
102 unsigned int cts;
103 unsigned int aval;
104};
105
106static const struct tegra_hdmi_audio_config tegra_hdmi_audio_32k[] = {
107 { 25200000, 4096, 25200, 24000 },
108 { 27000000, 4096, 27000, 24000 },
109 { 74250000, 4096, 74250, 24000 },
110 { 148500000, 4096, 148500, 24000 },
111 { 0, 0, 0, 0 },
112};
113
114static const struct tegra_hdmi_audio_config tegra_hdmi_audio_44_1k[] = {
115 { 25200000, 5880, 26250, 25000 },
116 { 27000000, 5880, 28125, 25000 },
117 { 74250000, 4704, 61875, 20000 },
118 { 148500000, 4704, 123750, 20000 },
119 { 0, 0, 0, 0 },
120};
121
122static const struct tegra_hdmi_audio_config tegra_hdmi_audio_48k[] = {
123 { 25200000, 6144, 25200, 24000 },
124 { 27000000, 6144, 27000, 24000 },
125 { 74250000, 6144, 74250, 24000 },
126 { 148500000, 6144, 148500, 24000 },
127 { 0, 0, 0, 0 },
128};
129
130static const struct tegra_hdmi_audio_config tegra_hdmi_audio_88_2k[] = {
131 { 25200000, 11760, 26250, 25000 },
132 { 27000000, 11760, 28125, 25000 },
133 { 74250000, 9408, 61875, 20000 },
134 { 148500000, 9408, 123750, 20000 },
135 { 0, 0, 0, 0 },
136};
137
138static const struct tegra_hdmi_audio_config tegra_hdmi_audio_96k[] = {
139 { 25200000, 12288, 25200, 24000 },
140 { 27000000, 12288, 27000, 24000 },
141 { 74250000, 12288, 74250, 24000 },
142 { 148500000, 12288, 148500, 24000 },
143 { 0, 0, 0, 0 },
144};
145
146static const struct tegra_hdmi_audio_config tegra_hdmi_audio_176_4k[] = {
147 { 25200000, 23520, 26250, 25000 },
148 { 27000000, 23520, 28125, 25000 },
149 { 74250000, 18816, 61875, 20000 },
150 { 148500000, 18816, 123750, 20000 },
151 { 0, 0, 0, 0 },
152};
153
154static const struct tegra_hdmi_audio_config tegra_hdmi_audio_192k[] = {
155 { 25200000, 24576, 25200, 24000 },
156 { 27000000, 24576, 27000, 24000 },
157 { 74250000, 24576, 74250, 24000 },
158 { 148500000, 24576, 148500, 24000 },
159 { 0, 0, 0, 0 },
160};
161
Thierry Redingf27db962013-09-30 15:14:41 +0200162static const struct tmds_config tegra20_tmds_config[] = {
Lucas Stachfa416dd2012-12-19 21:38:55 +0000163 { /* slow pixel clock modes */
Thierry Redingedec4af2012-11-15 21:28:23 +0000164 .pclk = 27000000,
165 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
166 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) |
167 SOR_PLL_TX_REG_LOAD(3),
168 .pll1 = SOR_PLL_TMDS_TERM_ENABLE,
169 .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) |
170 PE_CURRENT1(PE_CURRENT_0_0_mA) |
171 PE_CURRENT2(PE_CURRENT_0_0_mA) |
172 PE_CURRENT3(PE_CURRENT_0_0_mA),
173 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) |
174 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) |
175 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) |
176 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA),
Lucas Stachfa416dd2012-12-19 21:38:55 +0000177 },
178 { /* high pixel clock modes */
Thierry Redingedec4af2012-11-15 21:28:23 +0000179 .pclk = UINT_MAX,
180 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
181 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) |
182 SOR_PLL_TX_REG_LOAD(3),
183 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
184 .pe_current = PE_CURRENT0(PE_CURRENT_6_0_mA) |
185 PE_CURRENT1(PE_CURRENT_6_0_mA) |
186 PE_CURRENT2(PE_CURRENT_6_0_mA) |
187 PE_CURRENT3(PE_CURRENT_6_0_mA),
188 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) |
189 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) |
190 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) |
191 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA),
192 },
193};
194
Thierry Redingf27db962013-09-30 15:14:41 +0200195static const struct tmds_config tegra30_tmds_config[] = {
Thierry Redingedec4af2012-11-15 21:28:23 +0000196 { /* 480p modes */
197 .pclk = 27000000,
198 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
199 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) |
200 SOR_PLL_TX_REG_LOAD(0),
201 .pll1 = SOR_PLL_TMDS_TERM_ENABLE,
202 .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) |
203 PE_CURRENT1(PE_CURRENT_0_0_mA) |
204 PE_CURRENT2(PE_CURRENT_0_0_mA) |
205 PE_CURRENT3(PE_CURRENT_0_0_mA),
206 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
207 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
208 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
209 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
210 }, { /* 720p modes */
211 .pclk = 74250000,
212 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
213 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) |
214 SOR_PLL_TX_REG_LOAD(0),
215 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
216 .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) |
217 PE_CURRENT1(PE_CURRENT_5_0_mA) |
218 PE_CURRENT2(PE_CURRENT_5_0_mA) |
219 PE_CURRENT3(PE_CURRENT_5_0_mA),
220 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
221 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
222 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
223 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
224 }, { /* 1080p modes */
225 .pclk = UINT_MAX,
226 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
227 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(3) |
228 SOR_PLL_TX_REG_LOAD(0),
229 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
230 .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) |
231 PE_CURRENT1(PE_CURRENT_5_0_mA) |
232 PE_CURRENT2(PE_CURRENT_5_0_mA) |
233 PE_CURRENT3(PE_CURRENT_5_0_mA),
234 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
235 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
236 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
237 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
238 },
239};
240
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +0200241static const struct tmds_config tegra114_tmds_config[] = {
242 { /* 480p/576p / 25.2MHz/27MHz modes */
243 .pclk = 27000000,
244 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
245 SOR_PLL_VCOCAP(0) | SOR_PLL_RESISTORSEL,
246 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(0),
247 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
248 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
249 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
250 PE_CURRENT3(PE_CURRENT_0_mA_T114),
251 .drive_current =
252 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
253 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
254 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
255 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
256 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
257 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
258 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
259 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
260 }, { /* 720p / 74.25MHz modes */
261 .pclk = 74250000,
262 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
263 SOR_PLL_VCOCAP(1) | SOR_PLL_RESISTORSEL,
264 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
265 SOR_PLL_TMDS_TERMADJ(0),
266 .pe_current = PE_CURRENT0(PE_CURRENT_15_mA_T114) |
267 PE_CURRENT1(PE_CURRENT_15_mA_T114) |
268 PE_CURRENT2(PE_CURRENT_15_mA_T114) |
269 PE_CURRENT3(PE_CURRENT_15_mA_T114),
270 .drive_current =
271 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
272 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
273 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
274 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
275 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
276 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
277 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
278 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
279 }, { /* 1080p / 148.5MHz modes */
280 .pclk = 148500000,
281 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
282 SOR_PLL_VCOCAP(3) | SOR_PLL_RESISTORSEL,
283 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
284 SOR_PLL_TMDS_TERMADJ(0),
285 .pe_current = PE_CURRENT0(PE_CURRENT_10_mA_T114) |
286 PE_CURRENT1(PE_CURRENT_10_mA_T114) |
287 PE_CURRENT2(PE_CURRENT_10_mA_T114) |
288 PE_CURRENT3(PE_CURRENT_10_mA_T114),
289 .drive_current =
290 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_12_400_mA_T114) |
291 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_12_400_mA_T114) |
292 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_12_400_mA_T114) |
293 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_12_400_mA_T114),
294 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
295 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
296 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
297 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
298 }, { /* 225/297MHz modes */
299 .pclk = UINT_MAX,
300 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
301 SOR_PLL_VCOCAP(0xf) | SOR_PLL_RESISTORSEL,
302 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(7)
303 | SOR_PLL_TMDS_TERM_ENABLE,
304 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
305 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
306 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
307 PE_CURRENT3(PE_CURRENT_0_mA_T114),
308 .drive_current =
309 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_25_200_mA_T114) |
310 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_25_200_mA_T114) |
311 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_25_200_mA_T114) |
312 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_19_200_mA_T114),
313 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_3_000_mA) |
314 PEAK_CURRENT_LANE1(PEAK_CURRENT_3_000_mA) |
315 PEAK_CURRENT_LANE2(PEAK_CURRENT_3_000_mA) |
316 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_800_mA),
317 },
318};
319
Thierry Redingedec4af2012-11-15 21:28:23 +0000320static const struct tegra_hdmi_audio_config *
321tegra_hdmi_get_audio_config(unsigned int audio_freq, unsigned int pclk)
322{
323 const struct tegra_hdmi_audio_config *table;
324
325 switch (audio_freq) {
326 case 32000:
327 table = tegra_hdmi_audio_32k;
328 break;
329
330 case 44100:
331 table = tegra_hdmi_audio_44_1k;
332 break;
333
334 case 48000:
335 table = tegra_hdmi_audio_48k;
336 break;
337
338 case 88200:
339 table = tegra_hdmi_audio_88_2k;
340 break;
341
342 case 96000:
343 table = tegra_hdmi_audio_96k;
344 break;
345
346 case 176400:
347 table = tegra_hdmi_audio_176_4k;
348 break;
349
350 case 192000:
351 table = tegra_hdmi_audio_192k;
352 break;
353
354 default:
355 return NULL;
356 }
357
358 while (table->pclk) {
359 if (table->pclk == pclk)
360 return table;
361
362 table++;
363 }
364
365 return NULL;
366}
367
368static void tegra_hdmi_setup_audio_fs_tables(struct tegra_hdmi *hdmi)
369{
370 const unsigned int freqs[] = {
371 32000, 44100, 48000, 88200, 96000, 176400, 192000
372 };
373 unsigned int i;
374
375 for (i = 0; i < ARRAY_SIZE(freqs); i++) {
376 unsigned int f = freqs[i];
377 unsigned int eight_half;
378 unsigned long value;
379 unsigned int delta;
380
381 if (f > 96000)
382 delta = 2;
Thierry Reding17a8b6b2013-12-16 10:01:24 +0100383 else if (f > 48000)
Thierry Redingedec4af2012-11-15 21:28:23 +0000384 delta = 6;
385 else
386 delta = 9;
387
388 eight_half = (8 * HDMI_AUDIOCLK_FREQ) / (f * 128);
389 value = AUDIO_FS_LOW(eight_half - delta) |
390 AUDIO_FS_HIGH(eight_half + delta);
391 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_FS(i));
392 }
393}
394
395static int tegra_hdmi_setup_audio(struct tegra_hdmi *hdmi, unsigned int pclk)
396{
397 struct device_node *node = hdmi->dev->of_node;
398 const struct tegra_hdmi_audio_config *config;
399 unsigned int offset = 0;
400 unsigned long value;
401
402 switch (hdmi->audio_source) {
403 case HDA:
404 value = AUDIO_CNTRL0_SOURCE_SELECT_HDAL;
405 break;
406
407 case SPDIF:
408 value = AUDIO_CNTRL0_SOURCE_SELECT_SPDIF;
409 break;
410
411 default:
412 value = AUDIO_CNTRL0_SOURCE_SELECT_AUTO;
413 break;
414 }
415
416 if (of_device_is_compatible(node, "nvidia,tegra30-hdmi")) {
417 value |= AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
418 AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
419 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0);
420 } else {
421 value |= AUDIO_CNTRL0_INJECT_NULLSMPL;
422 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
423
424 value = AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
425 AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
426 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0);
427 }
428
429 config = tegra_hdmi_get_audio_config(hdmi->audio_freq, pclk);
430 if (!config) {
431 dev_err(hdmi->dev, "cannot set audio to %u at %u pclk\n",
432 hdmi->audio_freq, pclk);
433 return -EINVAL;
434 }
435
436 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_HDMI_ACR_CTRL);
437
438 value = AUDIO_N_RESETF | AUDIO_N_GENERATE_ALTERNATE |
439 AUDIO_N_VALUE(config->n - 1);
440 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N);
441
442 tegra_hdmi_writel(hdmi, ACR_SUBPACK_N(config->n) | ACR_ENABLE,
443 HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
444
445 value = ACR_SUBPACK_CTS(config->cts);
446 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
447
448 value = SPARE_HW_CTS | SPARE_FORCE_SW_CTS | SPARE_CTS_RESET_VAL(1);
449 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_SPARE);
450
451 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_AUDIO_N);
452 value &= ~AUDIO_N_RESETF;
453 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N);
454
455 if (of_device_is_compatible(node, "nvidia,tegra30-hdmi")) {
456 switch (hdmi->audio_freq) {
457 case 32000:
458 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0320;
459 break;
460
461 case 44100:
462 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0441;
463 break;
464
465 case 48000:
466 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0480;
467 break;
468
469 case 88200:
470 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0882;
471 break;
472
473 case 96000:
474 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0960;
475 break;
476
477 case 176400:
478 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_1764;
479 break;
480
481 case 192000:
482 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_1920;
483 break;
484 }
485
486 tegra_hdmi_writel(hdmi, config->aval, offset);
487 }
488
489 tegra_hdmi_setup_audio_fs_tables(hdmi);
490
491 return 0;
492}
493
Thierry Redingac24c222012-11-23 15:14:00 +0100494static inline unsigned long tegra_hdmi_subpack(const u8 *ptr, size_t size)
Thierry Redingedec4af2012-11-15 21:28:23 +0000495{
Thierry Redingac24c222012-11-23 15:14:00 +0100496 unsigned long value = 0;
Thierry Redingedec4af2012-11-15 21:28:23 +0000497 size_t i;
Thierry Redingedec4af2012-11-15 21:28:23 +0000498
Thierry Redingac24c222012-11-23 15:14:00 +0100499 for (i = size; i > 0; i--)
500 value = (value << 8) | ptr[i - 1];
Thierry Redingedec4af2012-11-15 21:28:23 +0000501
Thierry Redingac24c222012-11-23 15:14:00 +0100502 return value;
503}
Thierry Redingedec4af2012-11-15 21:28:23 +0000504
Thierry Redingac24c222012-11-23 15:14:00 +0100505static void tegra_hdmi_write_infopack(struct tegra_hdmi *hdmi, const void *data,
506 size_t size)
507{
508 const u8 *ptr = data;
509 unsigned long offset;
510 unsigned long value;
511 size_t i, j;
Thierry Redingedec4af2012-11-15 21:28:23 +0000512
Thierry Redingac24c222012-11-23 15:14:00 +0100513 switch (ptr[0]) {
514 case HDMI_INFOFRAME_TYPE_AVI:
515 offset = HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER;
516 break;
517
518 case HDMI_INFOFRAME_TYPE_AUDIO:
519 offset = HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER;
520 break;
521
522 case HDMI_INFOFRAME_TYPE_VENDOR:
523 offset = HDMI_NV_PDISP_HDMI_GENERIC_HEADER;
524 break;
525
526 default:
527 dev_err(hdmi->dev, "unsupported infoframe type: %02x\n",
528 ptr[0]);
529 return;
530 }
531
532 value = INFOFRAME_HEADER_TYPE(ptr[0]) |
533 INFOFRAME_HEADER_VERSION(ptr[1]) |
534 INFOFRAME_HEADER_LEN(ptr[2]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000535 tegra_hdmi_writel(hdmi, value, offset);
Thierry Redingac24c222012-11-23 15:14:00 +0100536 offset++;
Thierry Redingedec4af2012-11-15 21:28:23 +0000537
Thierry Redingac24c222012-11-23 15:14:00 +0100538 /*
539 * Each subpack contains 7 bytes, divided into:
540 * - subpack_low: bytes 0 - 3
541 * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00)
Thierry Redingedec4af2012-11-15 21:28:23 +0000542 */
Thierry Redingac24c222012-11-23 15:14:00 +0100543 for (i = 3, j = 0; i < size; i += 7, j += 8) {
544 size_t rem = size - i, num = min_t(size_t, rem, 4);
Thierry Redingedec4af2012-11-15 21:28:23 +0000545
Thierry Redingac24c222012-11-23 15:14:00 +0100546 value = tegra_hdmi_subpack(&ptr[i], num);
547 tegra_hdmi_writel(hdmi, value, offset++);
Thierry Redingedec4af2012-11-15 21:28:23 +0000548
Thierry Redingac24c222012-11-23 15:14:00 +0100549 num = min_t(size_t, rem - num, 3);
Thierry Redingedec4af2012-11-15 21:28:23 +0000550
Thierry Redingac24c222012-11-23 15:14:00 +0100551 value = tegra_hdmi_subpack(&ptr[i + 4], num);
552 tegra_hdmi_writel(hdmi, value, offset++);
Thierry Redingedec4af2012-11-15 21:28:23 +0000553 }
554}
555
556static void tegra_hdmi_setup_avi_infoframe(struct tegra_hdmi *hdmi,
557 struct drm_display_mode *mode)
558{
559 struct hdmi_avi_infoframe frame;
Thierry Redingac24c222012-11-23 15:14:00 +0100560 u8 buffer[17];
561 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000562
563 if (hdmi->dvi) {
564 tegra_hdmi_writel(hdmi, 0,
565 HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
566 return;
567 }
568
Thierry Redingac24c222012-11-23 15:14:00 +0100569 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
570 if (err < 0) {
571 dev_err(hdmi->dev, "failed to setup AVI infoframe: %zd\n", err);
572 return;
Thierry Redingedec4af2012-11-15 21:28:23 +0000573 }
574
Thierry Redingac24c222012-11-23 15:14:00 +0100575 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
576 if (err < 0) {
577 dev_err(hdmi->dev, "failed to pack AVI infoframe: %zd\n", err);
578 return;
579 }
580
581 tegra_hdmi_write_infopack(hdmi, buffer, err);
Thierry Redingedec4af2012-11-15 21:28:23 +0000582
583 tegra_hdmi_writel(hdmi, INFOFRAME_CTRL_ENABLE,
584 HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
585}
586
587static void tegra_hdmi_setup_audio_infoframe(struct tegra_hdmi *hdmi)
588{
589 struct hdmi_audio_infoframe frame;
Thierry Redingac24c222012-11-23 15:14:00 +0100590 u8 buffer[14];
591 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000592
593 if (hdmi->dvi) {
594 tegra_hdmi_writel(hdmi, 0,
595 HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
596 return;
597 }
598
Thierry Redingac24c222012-11-23 15:14:00 +0100599 err = hdmi_audio_infoframe_init(&frame);
600 if (err < 0) {
Thierry Redingef284c72013-10-16 19:51:22 +0200601 dev_err(hdmi->dev, "failed to setup audio infoframe: %zd\n",
Thierry Redingac24c222012-11-23 15:14:00 +0100602 err);
603 return;
604 }
Thierry Redingedec4af2012-11-15 21:28:23 +0000605
Thierry Redingac24c222012-11-23 15:14:00 +0100606 frame.channels = 2;
607
608 err = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
609 if (err < 0) {
610 dev_err(hdmi->dev, "failed to pack audio infoframe: %zd\n",
611 err);
612 return;
613 }
614
615 /*
616 * The audio infoframe has only one set of subpack registers, so the
617 * infoframe needs to be truncated. One set of subpack registers can
618 * contain 7 bytes. Including the 3 byte header only the first 10
619 * bytes can be programmed.
620 */
Thierry Redingef284c72013-10-16 19:51:22 +0200621 tegra_hdmi_write_infopack(hdmi, buffer, min_t(size_t, 10, err));
Thierry Redingedec4af2012-11-15 21:28:23 +0000622
623 tegra_hdmi_writel(hdmi, INFOFRAME_CTRL_ENABLE,
624 HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
625}
626
627static void tegra_hdmi_setup_stereo_infoframe(struct tegra_hdmi *hdmi)
628{
Lespiau, Damienae84b902013-08-19 16:59:02 +0100629 struct hdmi_vendor_infoframe frame;
Thierry Redingedec4af2012-11-15 21:28:23 +0000630 unsigned long value;
Thierry Redingac24c222012-11-23 15:14:00 +0100631 u8 buffer[10];
632 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000633
634 if (!hdmi->stereo) {
635 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
636 value &= ~GENERIC_CTRL_ENABLE;
637 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
638 return;
639 }
640
Lespiau, Damienae84b902013-08-19 16:59:02 +0100641 hdmi_vendor_infoframe_init(&frame);
Lespiau, Damiena26a58e82013-08-19 16:58:59 +0100642 frame.s3d_struct = HDMI_3D_STRUCTURE_FRAME_PACKING;
Thierry Redingac24c222012-11-23 15:14:00 +0100643
Lespiau, Damienae84b902013-08-19 16:59:02 +0100644 err = hdmi_vendor_infoframe_pack(&frame, buffer, sizeof(buffer));
Thierry Redingac24c222012-11-23 15:14:00 +0100645 if (err < 0) {
646 dev_err(hdmi->dev, "failed to pack vendor infoframe: %zd\n",
647 err);
648 return;
649 }
650
651 tegra_hdmi_write_infopack(hdmi, buffer, err);
Thierry Redingedec4af2012-11-15 21:28:23 +0000652
653 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
654 value |= GENERIC_CTRL_ENABLE;
655 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
656}
657
658static void tegra_hdmi_setup_tmds(struct tegra_hdmi *hdmi,
659 const struct tmds_config *tmds)
660{
661 unsigned long value;
662
663 tegra_hdmi_writel(hdmi, tmds->pll0, HDMI_NV_PDISP_SOR_PLL0);
664 tegra_hdmi_writel(hdmi, tmds->pll1, HDMI_NV_PDISP_SOR_PLL1);
665 tegra_hdmi_writel(hdmi, tmds->pe_current, HDMI_NV_PDISP_PE_CURRENT);
666
Thierry Reding59af0592013-10-14 09:43:05 +0200667 tegra_hdmi_writel(hdmi, tmds->drive_current,
668 HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
669
670 value = tegra_hdmi_readl(hdmi, hdmi->config->fuse_override_offset);
671 value |= hdmi->config->fuse_override_value;
672 tegra_hdmi_writel(hdmi, value, hdmi->config->fuse_override_offset);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +0200673
674 if (hdmi->config->has_sor_io_peak_current)
675 tegra_hdmi_writel(hdmi, tmds->peak_current,
676 HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +0000677}
678
Mikko Perttunen9f159122013-08-28 18:48:38 +0300679static bool tegra_output_is_hdmi(struct tegra_output *output)
680{
681 struct edid *edid;
682
683 if (!output->connector.edid_blob_ptr)
684 return false;
685
686 edid = (struct edid *)output->connector.edid_blob_ptr->data;
687
688 return drm_detect_hdmi_monitor(edid);
689}
690
Thierry Redingedec4af2012-11-15 21:28:23 +0000691static int tegra_output_hdmi_enable(struct tegra_output *output)
692{
693 unsigned int h_sync_width, h_front_porch, h_back_porch, i, rekey;
694 struct tegra_dc *dc = to_tegra_dc(output->encoder.crtc);
695 struct drm_display_mode *mode = &dc->base.mode;
696 struct tegra_hdmi *hdmi = to_hdmi(output);
697 struct device_node *node = hdmi->dev->of_node;
698 unsigned int pulse_start, div82, pclk;
Thierry Redingedec4af2012-11-15 21:28:23 +0000699 unsigned long value;
700 int retries = 1000;
701 int err;
702
Thierry Reding365765f2013-10-29 16:00:42 +0100703 if (hdmi->enabled)
704 return 0;
705
Mikko Perttunen9f159122013-08-28 18:48:38 +0300706 hdmi->dvi = !tegra_output_is_hdmi(output);
707
Thierry Redingedec4af2012-11-15 21:28:23 +0000708 pclk = mode->clock * 1000;
709 h_sync_width = mode->hsync_end - mode->hsync_start;
Lucas Stach40495082012-12-19 21:38:52 +0000710 h_back_porch = mode->htotal - mode->hsync_end;
711 h_front_porch = mode->hsync_start - mode->hdisplay;
Thierry Redingedec4af2012-11-15 21:28:23 +0000712
Thierry Redingedec4af2012-11-15 21:28:23 +0000713 err = regulator_enable(hdmi->pll);
714 if (err < 0) {
715 dev_err(hdmi->dev, "failed to enable PLL regulator: %d\n", err);
716 return err;
717 }
718
719 /*
720 * This assumes that the display controller will divide its parent
721 * clock by 2 to generate the pixel clock.
722 */
723 err = tegra_output_setup_clock(output, hdmi->clk, pclk * 2);
724 if (err < 0) {
725 dev_err(hdmi->dev, "failed to setup clock: %d\n", err);
726 return err;
727 }
728
729 err = clk_set_rate(hdmi->clk, pclk);
730 if (err < 0)
731 return err;
732
733 err = clk_enable(hdmi->clk);
734 if (err < 0) {
735 dev_err(hdmi->dev, "failed to enable clock: %d\n", err);
736 return err;
737 }
738
Stephen Warrenca480802013-11-06 16:20:54 -0700739 reset_control_assert(hdmi->rst);
Thierry Redingedec4af2012-11-15 21:28:23 +0000740 usleep_range(1000, 2000);
Stephen Warrenca480802013-11-06 16:20:54 -0700741 reset_control_deassert(hdmi->rst);
Thierry Redingedec4af2012-11-15 21:28:23 +0000742
743 tegra_dc_writel(dc, VSYNC_H_POSITION(1),
744 DC_DISP_DISP_TIMING_OPTIONS);
745 tegra_dc_writel(dc, DITHER_CONTROL_DISABLE | BASE_COLOR_SIZE888,
746 DC_DISP_DISP_COLOR_CONTROL);
747
748 /* video_preamble uses h_pulse2 */
749 pulse_start = 1 + h_sync_width + h_back_porch - 10;
750
751 tegra_dc_writel(dc, H_PULSE_2_ENABLE, DC_DISP_DISP_SIGNAL_OPTIONS0);
752
753 value = PULSE_MODE_NORMAL | PULSE_POLARITY_HIGH | PULSE_QUAL_VACTIVE |
754 PULSE_LAST_END_A;
755 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL);
756
757 value = PULSE_START(pulse_start) | PULSE_END(pulse_start + 8);
758 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A);
759
760 value = VSYNC_WINDOW_END(0x210) | VSYNC_WINDOW_START(0x200) |
761 VSYNC_WINDOW_ENABLE;
762 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
763
764 if (dc->pipe)
765 value = HDMI_SRC_DISPLAYB;
766 else
767 value = HDMI_SRC_DISPLAYA;
768
769 if ((mode->hdisplay == 720) && ((mode->vdisplay == 480) ||
770 (mode->vdisplay == 576)))
771 tegra_hdmi_writel(hdmi,
772 value | ARM_VIDEO_RANGE_FULL,
773 HDMI_NV_PDISP_INPUT_CONTROL);
774 else
775 tegra_hdmi_writel(hdmi,
776 value | ARM_VIDEO_RANGE_LIMITED,
777 HDMI_NV_PDISP_INPUT_CONTROL);
778
779 div82 = clk_get_rate(hdmi->clk) / 1000000 * 4;
780 value = SOR_REFCLK_DIV_INT(div82 >> 2) | SOR_REFCLK_DIV_FRAC(div82);
781 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_REFCLK);
782
783 if (!hdmi->dvi) {
784 err = tegra_hdmi_setup_audio(hdmi, pclk);
785 if (err < 0)
786 hdmi->dvi = true;
787 }
788
789 if (of_device_is_compatible(node, "nvidia,tegra20-hdmi")) {
790 /*
791 * TODO: add ELD support
792 */
793 }
794
795 rekey = HDMI_REKEY_DEFAULT;
796 value = HDMI_CTRL_REKEY(rekey);
797 value |= HDMI_CTRL_MAX_AC_PACKET((h_sync_width + h_back_porch +
798 h_front_porch - rekey - 18) / 32);
799
800 if (!hdmi->dvi)
801 value |= HDMI_CTRL_ENABLE;
802
803 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_CTRL);
804
805 if (hdmi->dvi)
806 tegra_hdmi_writel(hdmi, 0x0,
807 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
808 else
809 tegra_hdmi_writel(hdmi, GENERIC_CTRL_AUDIO,
810 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
811
812 tegra_hdmi_setup_avi_infoframe(hdmi, mode);
813 tegra_hdmi_setup_audio_infoframe(hdmi);
814 tegra_hdmi_setup_stereo_infoframe(hdmi);
815
816 /* TMDS CONFIG */
Thierry Reding59af0592013-10-14 09:43:05 +0200817 for (i = 0; i < hdmi->config->num_tmds; i++) {
818 if (pclk <= hdmi->config->tmds[i].pclk) {
819 tegra_hdmi_setup_tmds(hdmi, &hdmi->config->tmds[i]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000820 break;
821 }
822 }
823
824 tegra_hdmi_writel(hdmi,
825 SOR_SEQ_CTL_PU_PC(0) |
826 SOR_SEQ_PU_PC_ALT(0) |
827 SOR_SEQ_PD_PC(8) |
828 SOR_SEQ_PD_PC_ALT(8),
829 HDMI_NV_PDISP_SOR_SEQ_CTL);
830
831 value = SOR_SEQ_INST_WAIT_TIME(1) |
832 SOR_SEQ_INST_WAIT_UNITS_VSYNC |
833 SOR_SEQ_INST_HALT |
834 SOR_SEQ_INST_PIN_A_LOW |
835 SOR_SEQ_INST_PIN_B_LOW |
836 SOR_SEQ_INST_DRIVE_PWM_OUT_LO;
837
838 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(0));
839 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(8));
840
841 value = 0x1c800;
842 value &= ~SOR_CSTM_ROTCLK(~0);
843 value |= SOR_CSTM_ROTCLK(2);
844 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_CSTM);
845
846 tegra_dc_writel(dc, DISP_CTRL_MODE_STOP, DC_CMD_DISPLAY_COMMAND);
847 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
848 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
849
850 /* start SOR */
851 tegra_hdmi_writel(hdmi,
852 SOR_PWR_NORMAL_STATE_PU |
853 SOR_PWR_NORMAL_START_NORMAL |
854 SOR_PWR_SAFE_STATE_PD |
855 SOR_PWR_SETTING_NEW_TRIGGER,
856 HDMI_NV_PDISP_SOR_PWR);
857 tegra_hdmi_writel(hdmi,
858 SOR_PWR_NORMAL_STATE_PU |
859 SOR_PWR_NORMAL_START_NORMAL |
860 SOR_PWR_SAFE_STATE_PD |
861 SOR_PWR_SETTING_NEW_DONE,
862 HDMI_NV_PDISP_SOR_PWR);
863
864 do {
865 BUG_ON(--retries < 0);
866 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PWR);
867 } while (value & SOR_PWR_SETTING_NEW_PENDING);
868
869 value = SOR_STATE_ASY_CRCMODE_COMPLETE |
870 SOR_STATE_ASY_OWNER_HEAD0 |
871 SOR_STATE_ASY_SUBOWNER_BOTH |
872 SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A |
873 SOR_STATE_ASY_DEPOL_POS;
874
875 /* setup sync polarities */
876 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
877 value |= SOR_STATE_ASY_HSYNCPOL_POS;
878
879 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
880 value |= SOR_STATE_ASY_HSYNCPOL_NEG;
881
882 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
883 value |= SOR_STATE_ASY_VSYNCPOL_POS;
884
885 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
886 value |= SOR_STATE_ASY_VSYNCPOL_NEG;
887
888 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE2);
889
890 value = SOR_STATE_ASY_HEAD_OPMODE_AWAKE | SOR_STATE_ASY_ORMODE_NORMAL;
891 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE1);
892
893 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
894 tegra_hdmi_writel(hdmi, SOR_STATE_UPDATE, HDMI_NV_PDISP_SOR_STATE0);
895 tegra_hdmi_writel(hdmi, value | SOR_STATE_ATTACHED,
896 HDMI_NV_PDISP_SOR_STATE1);
897 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
898
899 tegra_dc_writel(dc, HDMI_ENABLE, DC_DISP_DISP_WIN_OPTIONS);
900
901 value = PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
902 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
903 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
904
905 value = DISP_CTRL_MODE_C_DISPLAY;
906 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
907
908 tegra_dc_writel(dc, GENERAL_ACT_REQ << 8, DC_CMD_STATE_CONTROL);
909 tegra_dc_writel(dc, GENERAL_ACT_REQ, DC_CMD_STATE_CONTROL);
910
911 /* TODO: add HDCP support */
912
Thierry Reding365765f2013-10-29 16:00:42 +0100913 hdmi->enabled = true;
914
Thierry Redingedec4af2012-11-15 21:28:23 +0000915 return 0;
916}
917
918static int tegra_output_hdmi_disable(struct tegra_output *output)
919{
920 struct tegra_hdmi *hdmi = to_hdmi(output);
921
Thierry Reding365765f2013-10-29 16:00:42 +0100922 if (!hdmi->enabled)
923 return 0;
924
Stephen Warrenca480802013-11-06 16:20:54 -0700925 reset_control_assert(hdmi->rst);
Thierry Redingedec4af2012-11-15 21:28:23 +0000926 clk_disable(hdmi->clk);
927 regulator_disable(hdmi->pll);
Thierry Redingedec4af2012-11-15 21:28:23 +0000928
Thierry Reding365765f2013-10-29 16:00:42 +0100929 hdmi->enabled = false;
930
Thierry Redingedec4af2012-11-15 21:28:23 +0000931 return 0;
932}
933
934static int tegra_output_hdmi_setup_clock(struct tegra_output *output,
935 struct clk *clk, unsigned long pclk)
936{
937 struct tegra_hdmi *hdmi = to_hdmi(output);
938 struct clk *base;
939 int err;
940
941 err = clk_set_parent(clk, hdmi->clk_parent);
942 if (err < 0) {
943 dev_err(output->dev, "failed to set parent: %d\n", err);
944 return err;
945 }
946
947 base = clk_get_parent(hdmi->clk_parent);
948
949 /*
950 * This assumes that the parent clock is pll_d_out0 or pll_d2_out
951 * respectively, each of which divides the base pll_d by 2.
952 */
953 err = clk_set_rate(base, pclk * 2);
954 if (err < 0)
955 dev_err(output->dev,
956 "failed to set base clock rate to %lu Hz\n",
957 pclk * 2);
958
959 return 0;
960}
961
962static int tegra_output_hdmi_check_mode(struct tegra_output *output,
963 struct drm_display_mode *mode,
964 enum drm_mode_status *status)
965{
966 struct tegra_hdmi *hdmi = to_hdmi(output);
967 unsigned long pclk = mode->clock * 1000;
968 struct clk *parent;
969 long err;
970
971 parent = clk_get_parent(hdmi->clk_parent);
972
973 err = clk_round_rate(parent, pclk * 4);
Paul Walmsley23a0e272013-12-09 18:00:12 -0800974 if (err <= 0)
Thierry Redingedec4af2012-11-15 21:28:23 +0000975 *status = MODE_NOCLOCK;
976 else
977 *status = MODE_OK;
978
979 return 0;
980}
981
982static const struct tegra_output_ops hdmi_ops = {
983 .enable = tegra_output_hdmi_enable,
984 .disable = tegra_output_hdmi_disable,
985 .setup_clock = tegra_output_hdmi_setup_clock,
986 .check_mode = tegra_output_hdmi_check_mode,
987};
988
989static int tegra_hdmi_show_regs(struct seq_file *s, void *data)
990{
991 struct drm_info_node *node = s->private;
992 struct tegra_hdmi *hdmi = node->info_ent->data;
Mikko Perttunenccaddfe2013-07-30 11:35:03 +0300993 int err;
994
995 err = clk_enable(hdmi->clk);
996 if (err)
997 return err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000998
999#define DUMP_REG(name) \
1000 seq_printf(s, "%-56s %#05x %08lx\n", #name, name, \
1001 tegra_hdmi_readl(hdmi, name))
1002
1003 DUMP_REG(HDMI_CTXSW);
1004 DUMP_REG(HDMI_NV_PDISP_SOR_STATE0);
1005 DUMP_REG(HDMI_NV_PDISP_SOR_STATE1);
1006 DUMP_REG(HDMI_NV_PDISP_SOR_STATE2);
1007 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_MSB);
1008 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_LSB);
1009 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_MSB);
1010 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_LSB);
1011 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_MSB);
1012 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_LSB);
1013 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_MSB);
1014 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_LSB);
1015 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_MSB);
1016 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_LSB);
1017 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_MSB);
1018 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_LSB);
1019 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CTRL);
1020 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CMODE);
1021 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_MSB);
1022 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_LSB);
1023 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_MSB);
1024 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB2);
1025 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB1);
1026 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_RI);
1027 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_MSB);
1028 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_LSB);
1029 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU0);
1030 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU_RDATA0);
1031 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU1);
1032 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU2);
1033 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
1034 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_STATUS);
1035 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER);
1036 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_LOW);
1037 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_HIGH);
1038 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
1039 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_STATUS);
1040 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER);
1041 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_LOW);
1042 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_HIGH);
1043 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_LOW);
1044 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_HIGH);
1045 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
1046 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_STATUS);
1047 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_HEADER);
1048 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_LOW);
1049 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_HIGH);
1050 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_LOW);
1051 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_HIGH);
1052 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_LOW);
1053 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_HIGH);
1054 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_LOW);
1055 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_HIGH);
1056 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_CTRL);
1057 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_LOW);
1058 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_HIGH);
1059 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
1060 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
1061 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_LOW);
1062 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_HIGH);
1063 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_LOW);
1064 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_HIGH);
1065 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_LOW);
1066 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_HIGH);
1067 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_LOW);
1068 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_HIGH);
1069 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_LOW);
1070 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_HIGH);
1071 DUMP_REG(HDMI_NV_PDISP_HDMI_CTRL);
1072 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_KEEPOUT);
1073 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
1074 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_CTRL);
1075 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_STATUS);
1076 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_SUBPACK);
1077 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS1);
1078 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS2);
1079 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU0);
1080 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1);
1081 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1_RDATA);
1082 DUMP_REG(HDMI_NV_PDISP_HDMI_SPARE);
1083 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS1);
1084 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS2);
1085 DUMP_REG(HDMI_NV_PDISP_HDMI_HDCPRIF_ROM_CTRL);
1086 DUMP_REG(HDMI_NV_PDISP_SOR_CAP);
1087 DUMP_REG(HDMI_NV_PDISP_SOR_PWR);
1088 DUMP_REG(HDMI_NV_PDISP_SOR_TEST);
1089 DUMP_REG(HDMI_NV_PDISP_SOR_PLL0);
1090 DUMP_REG(HDMI_NV_PDISP_SOR_PLL1);
1091 DUMP_REG(HDMI_NV_PDISP_SOR_PLL2);
1092 DUMP_REG(HDMI_NV_PDISP_SOR_CSTM);
1093 DUMP_REG(HDMI_NV_PDISP_SOR_LVDS);
1094 DUMP_REG(HDMI_NV_PDISP_SOR_CRCA);
1095 DUMP_REG(HDMI_NV_PDISP_SOR_CRCB);
1096 DUMP_REG(HDMI_NV_PDISP_SOR_BLANK);
1097 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_CTL);
1098 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(0));
1099 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(1));
1100 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(2));
1101 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(3));
1102 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(4));
1103 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(5));
1104 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(6));
1105 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(7));
1106 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(8));
1107 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(9));
1108 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(10));
1109 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(11));
1110 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(12));
1111 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(13));
1112 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(14));
1113 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(15));
1114 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA0);
1115 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA1);
1116 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA0);
1117 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA1);
1118 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA0);
1119 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA1);
1120 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA0);
1121 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA1);
1122 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA0);
1123 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA1);
1124 DUMP_REG(HDMI_NV_PDISP_SOR_TRIG);
1125 DUMP_REG(HDMI_NV_PDISP_SOR_MSCHECK);
1126 DUMP_REG(HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
1127 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG0);
1128 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG1);
1129 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG2);
1130 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(0));
1131 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(1));
1132 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(2));
1133 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(3));
1134 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(4));
1135 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(5));
1136 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(6));
1137 DUMP_REG(HDMI_NV_PDISP_AUDIO_PULSE_WIDTH);
1138 DUMP_REG(HDMI_NV_PDISP_AUDIO_THRESHOLD);
1139 DUMP_REG(HDMI_NV_PDISP_AUDIO_CNTRL0);
1140 DUMP_REG(HDMI_NV_PDISP_AUDIO_N);
1141 DUMP_REG(HDMI_NV_PDISP_HDCPRIF_ROM_TIMING);
1142 DUMP_REG(HDMI_NV_PDISP_SOR_REFCLK);
1143 DUMP_REG(HDMI_NV_PDISP_CRC_CONTROL);
1144 DUMP_REG(HDMI_NV_PDISP_INPUT_CONTROL);
1145 DUMP_REG(HDMI_NV_PDISP_SCRATCH);
1146 DUMP_REG(HDMI_NV_PDISP_PE_CURRENT);
1147 DUMP_REG(HDMI_NV_PDISP_KEY_CTRL);
1148 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG0);
1149 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG1);
1150 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG2);
1151 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_0);
1152 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_1);
1153 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_2);
1154 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_3);
1155 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_TRIG);
1156 DUMP_REG(HDMI_NV_PDISP_KEY_SKEY_INDEX);
1157 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
1158 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR);
1159 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001160 DUMP_REG(HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +00001161
1162#undef DUMP_REG
1163
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001164 clk_disable(hdmi->clk);
1165
Thierry Redingedec4af2012-11-15 21:28:23 +00001166 return 0;
1167}
1168
1169static struct drm_info_list debugfs_files[] = {
1170 { "regs", tegra_hdmi_show_regs, 0, NULL },
1171};
1172
1173static int tegra_hdmi_debugfs_init(struct tegra_hdmi *hdmi,
1174 struct drm_minor *minor)
1175{
1176 unsigned int i;
1177 int err;
1178
1179 hdmi->debugfs = debugfs_create_dir("hdmi", minor->debugfs_root);
1180 if (!hdmi->debugfs)
1181 return -ENOMEM;
1182
1183 hdmi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
1184 GFP_KERNEL);
1185 if (!hdmi->debugfs_files) {
1186 err = -ENOMEM;
1187 goto remove;
1188 }
1189
1190 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
1191 hdmi->debugfs_files[i].data = hdmi;
1192
1193 err = drm_debugfs_create_files(hdmi->debugfs_files,
1194 ARRAY_SIZE(debugfs_files),
1195 hdmi->debugfs, minor);
1196 if (err < 0)
1197 goto free;
1198
1199 hdmi->minor = minor;
1200
1201 return 0;
1202
1203free:
1204 kfree(hdmi->debugfs_files);
1205 hdmi->debugfs_files = NULL;
1206remove:
1207 debugfs_remove(hdmi->debugfs);
1208 hdmi->debugfs = NULL;
1209
1210 return err;
1211}
1212
1213static int tegra_hdmi_debugfs_exit(struct tegra_hdmi *hdmi)
1214{
1215 drm_debugfs_remove_files(hdmi->debugfs_files, ARRAY_SIZE(debugfs_files),
1216 hdmi->minor);
1217 hdmi->minor = NULL;
1218
1219 kfree(hdmi->debugfs_files);
1220 hdmi->debugfs_files = NULL;
1221
1222 debugfs_remove(hdmi->debugfs);
1223 hdmi->debugfs = NULL;
1224
1225 return 0;
1226}
1227
Thierry Reding53fa7f72013-09-24 15:35:40 +02001228static int tegra_hdmi_init(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001229{
Thierry Reding776dc382013-10-14 14:43:22 +02001230 struct tegra_drm *tegra = dev_get_drvdata(client->parent);
1231 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001232 int err;
1233
Mikko Perttunen18ebc0f2013-08-28 18:48:39 +03001234 err = regulator_enable(hdmi->vdd);
1235 if (err < 0) {
1236 dev_err(client->dev, "failed to enable VDD regulator: %d\n",
1237 err);
1238 return err;
1239 }
1240
Thierry Redingedec4af2012-11-15 21:28:23 +00001241 hdmi->output.type = TEGRA_OUTPUT_HDMI;
1242 hdmi->output.dev = client->dev;
1243 hdmi->output.ops = &hdmi_ops;
1244
Thierry Reding776dc382013-10-14 14:43:22 +02001245 err = tegra_output_init(tegra->drm, &hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001246 if (err < 0) {
1247 dev_err(client->dev, "output setup failed: %d\n", err);
1248 return err;
1249 }
1250
1251 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding776dc382013-10-14 14:43:22 +02001252 err = tegra_hdmi_debugfs_init(hdmi, tegra->drm->primary);
Thierry Redingedec4af2012-11-15 21:28:23 +00001253 if (err < 0)
1254 dev_err(client->dev, "debugfs setup failed: %d\n", err);
1255 }
1256
1257 return 0;
1258}
1259
Thierry Reding53fa7f72013-09-24 15:35:40 +02001260static int tegra_hdmi_exit(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001261{
Thierry Reding776dc382013-10-14 14:43:22 +02001262 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001263 int err;
1264
1265 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
1266 err = tegra_hdmi_debugfs_exit(hdmi);
1267 if (err < 0)
1268 dev_err(client->dev, "debugfs cleanup failed: %d\n",
1269 err);
1270 }
1271
1272 err = tegra_output_disable(&hdmi->output);
1273 if (err < 0) {
1274 dev_err(client->dev, "output failed to disable: %d\n", err);
1275 return err;
1276 }
1277
1278 err = tegra_output_exit(&hdmi->output);
1279 if (err < 0) {
1280 dev_err(client->dev, "output cleanup failed: %d\n", err);
1281 return err;
1282 }
1283
Mikko Perttunen18ebc0f2013-08-28 18:48:39 +03001284 regulator_disable(hdmi->vdd);
1285
Thierry Redingedec4af2012-11-15 21:28:23 +00001286 return 0;
1287}
1288
1289static const struct host1x_client_ops hdmi_client_ops = {
Thierry Reding53fa7f72013-09-24 15:35:40 +02001290 .init = tegra_hdmi_init,
1291 .exit = tegra_hdmi_exit,
Thierry Redingedec4af2012-11-15 21:28:23 +00001292};
1293
Thierry Reding59af0592013-10-14 09:43:05 +02001294static const struct tegra_hdmi_config tegra20_hdmi_config = {
1295 .tmds = tegra20_tmds_config,
1296 .num_tmds = ARRAY_SIZE(tegra20_tmds_config),
1297 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1298 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001299 .has_sor_io_peak_current = false,
Thierry Reding59af0592013-10-14 09:43:05 +02001300};
1301
1302static const struct tegra_hdmi_config tegra30_hdmi_config = {
1303 .tmds = tegra30_tmds_config,
1304 .num_tmds = ARRAY_SIZE(tegra30_tmds_config),
1305 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1306 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001307 .has_sor_io_peak_current = false,
1308};
1309
1310static const struct tegra_hdmi_config tegra114_hdmi_config = {
1311 .tmds = tegra114_tmds_config,
1312 .num_tmds = ARRAY_SIZE(tegra114_tmds_config),
1313 .fuse_override_offset = HDMI_NV_PDISP_SOR_PAD_CTLS0,
1314 .fuse_override_value = 1 << 31,
1315 .has_sor_io_peak_current = true,
Thierry Reding59af0592013-10-14 09:43:05 +02001316};
1317
1318static const struct of_device_id tegra_hdmi_of_match[] = {
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001319 { .compatible = "nvidia,tegra114-hdmi", .data = &tegra114_hdmi_config },
Thierry Reding59af0592013-10-14 09:43:05 +02001320 { .compatible = "nvidia,tegra30-hdmi", .data = &tegra30_hdmi_config },
1321 { .compatible = "nvidia,tegra20-hdmi", .data = &tegra20_hdmi_config },
1322 { },
1323};
1324
Thierry Redingedec4af2012-11-15 21:28:23 +00001325static int tegra_hdmi_probe(struct platform_device *pdev)
1326{
Thierry Reding59af0592013-10-14 09:43:05 +02001327 const struct of_device_id *match;
Thierry Redingedec4af2012-11-15 21:28:23 +00001328 struct tegra_hdmi *hdmi;
1329 struct resource *regs;
1330 int err;
1331
Thierry Reding59af0592013-10-14 09:43:05 +02001332 match = of_match_node(tegra_hdmi_of_match, pdev->dev.of_node);
1333 if (!match)
1334 return -ENODEV;
1335
Thierry Redingedec4af2012-11-15 21:28:23 +00001336 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
1337 if (!hdmi)
1338 return -ENOMEM;
1339
Thierry Reding59af0592013-10-14 09:43:05 +02001340 hdmi->config = match->data;
Thierry Redingedec4af2012-11-15 21:28:23 +00001341 hdmi->dev = &pdev->dev;
1342 hdmi->audio_source = AUTO;
1343 hdmi->audio_freq = 44100;
1344 hdmi->stereo = false;
1345 hdmi->dvi = false;
1346
1347 hdmi->clk = devm_clk_get(&pdev->dev, NULL);
1348 if (IS_ERR(hdmi->clk)) {
1349 dev_err(&pdev->dev, "failed to get clock\n");
1350 return PTR_ERR(hdmi->clk);
1351 }
1352
Stephen Warrenca480802013-11-06 16:20:54 -07001353 hdmi->rst = devm_reset_control_get(&pdev->dev, "hdmi");
1354 if (IS_ERR(hdmi->rst)) {
1355 dev_err(&pdev->dev, "failed to get reset\n");
1356 return PTR_ERR(hdmi->rst);
1357 }
1358
Thierry Redingedec4af2012-11-15 21:28:23 +00001359 err = clk_prepare(hdmi->clk);
1360 if (err < 0)
1361 return err;
1362
1363 hdmi->clk_parent = devm_clk_get(&pdev->dev, "parent");
1364 if (IS_ERR(hdmi->clk_parent))
1365 return PTR_ERR(hdmi->clk_parent);
1366
1367 err = clk_prepare(hdmi->clk_parent);
1368 if (err < 0)
1369 return err;
1370
1371 err = clk_set_parent(hdmi->clk, hdmi->clk_parent);
1372 if (err < 0) {
1373 dev_err(&pdev->dev, "failed to setup clocks: %d\n", err);
1374 return err;
1375 }
1376
1377 hdmi->vdd = devm_regulator_get(&pdev->dev, "vdd");
1378 if (IS_ERR(hdmi->vdd)) {
1379 dev_err(&pdev->dev, "failed to get VDD regulator\n");
1380 return PTR_ERR(hdmi->vdd);
1381 }
1382
1383 hdmi->pll = devm_regulator_get(&pdev->dev, "pll");
1384 if (IS_ERR(hdmi->pll)) {
1385 dev_err(&pdev->dev, "failed to get PLL regulator\n");
1386 return PTR_ERR(hdmi->pll);
1387 }
1388
1389 hdmi->output.dev = &pdev->dev;
1390
Thierry Reding59d29c02013-10-14 14:26:42 +02001391 err = tegra_output_probe(&hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001392 if (err < 0)
1393 return err;
1394
1395 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1396 if (!regs)
1397 return -ENXIO;
1398
Thierry Redingd4ed6022013-01-21 11:09:02 +01001399 hdmi->regs = devm_ioremap_resource(&pdev->dev, regs);
1400 if (IS_ERR(hdmi->regs))
1401 return PTR_ERR(hdmi->regs);
Thierry Redingedec4af2012-11-15 21:28:23 +00001402
1403 err = platform_get_irq(pdev, 0);
1404 if (err < 0)
1405 return err;
1406
1407 hdmi->irq = err;
1408
Thierry Reding776dc382013-10-14 14:43:22 +02001409 INIT_LIST_HEAD(&hdmi->client.list);
1410 hdmi->client.ops = &hdmi_client_ops;
1411 hdmi->client.dev = &pdev->dev;
Thierry Redingedec4af2012-11-15 21:28:23 +00001412
Thierry Reding776dc382013-10-14 14:43:22 +02001413 err = host1x_client_register(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001414 if (err < 0) {
1415 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1416 err);
1417 return err;
1418 }
1419
1420 platform_set_drvdata(pdev, hdmi);
1421
1422 return 0;
1423}
1424
1425static int tegra_hdmi_remove(struct platform_device *pdev)
1426{
Thierry Redingedec4af2012-11-15 21:28:23 +00001427 struct tegra_hdmi *hdmi = platform_get_drvdata(pdev);
1428 int err;
1429
Thierry Reding776dc382013-10-14 14:43:22 +02001430 err = host1x_client_unregister(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001431 if (err < 0) {
1432 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1433 err);
1434 return err;
1435 }
1436
Thierry Reding59d29c02013-10-14 14:26:42 +02001437 err = tegra_output_remove(&hdmi->output);
1438 if (err < 0) {
1439 dev_err(&pdev->dev, "failed to remove output: %d\n", err);
1440 return err;
1441 }
1442
Thierry Redingedec4af2012-11-15 21:28:23 +00001443 clk_unprepare(hdmi->clk_parent);
1444 clk_unprepare(hdmi->clk);
1445
1446 return 0;
1447}
1448
Thierry Redingedec4af2012-11-15 21:28:23 +00001449struct platform_driver tegra_hdmi_driver = {
1450 .driver = {
1451 .name = "tegra-hdmi",
1452 .owner = THIS_MODULE,
1453 .of_match_table = tegra_hdmi_of_match,
1454 },
1455 .probe = tegra_hdmi_probe,
1456 .remove = tegra_hdmi_remove,
1457};