blob: 728681a3f8c9d6fc23bc1b5842c123069bc90739 [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>
Thierry Reding59682712014-11-28 16:50:59 +010012#include <linux/gpio.h>
Thierry Reding9eb9b222013-09-24 16:32:47 +020013#include <linux/hdmi.h>
14#include <linux/regulator/consumer.h>
Stephen Warrenca480802013-11-06 16:20:54 -070015#include <linux/reset.h>
Thierry Redingac24c222012-11-23 15:14:00 +010016
Thierry Reding4aa3df72014-11-24 16:27:13 +010017#include <drm/drm_atomic_helper.h>
Thierry Reding59682712014-11-28 16:50:59 +010018#include <drm/drm_crtc.h>
19#include <drm/drm_crtc_helper.h>
20
Thierry Redingedec4af2012-11-15 21:28:23 +000021#include "hdmi.h"
22#include "drm.h"
23#include "dc.h"
24
Thierry Reding59af0592013-10-14 09:43:05 +020025struct tmds_config {
26 unsigned int pclk;
27 u32 pll0;
28 u32 pll1;
29 u32 pe_current;
30 u32 drive_current;
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +020031 u32 peak_current;
Thierry Reding59af0592013-10-14 09:43:05 +020032};
33
34struct tegra_hdmi_config {
35 const struct tmds_config *tmds;
36 unsigned int num_tmds;
37
38 unsigned long fuse_override_offset;
Thierry Reding4ee8cee2014-12-08 16:25:14 +010039 u32 fuse_override_value;
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +020040
41 bool has_sor_io_peak_current;
Thierry Reding59af0592013-10-14 09:43:05 +020042};
43
Thierry Redingedec4af2012-11-15 21:28:23 +000044struct tegra_hdmi {
Thierry Reding776dc382013-10-14 14:43:22 +020045 struct host1x_client client;
Thierry Redingedec4af2012-11-15 21:28:23 +000046 struct tegra_output output;
47 struct device *dev;
48
Thierry Redingfb50a112014-02-28 16:57:34 +010049 struct regulator *hdmi;
Thierry Redingedec4af2012-11-15 21:28:23 +000050 struct regulator *pll;
Thierry Reding88685682014-04-16 10:24:12 +020051 struct regulator *vdd;
Thierry Redingedec4af2012-11-15 21:28:23 +000052
53 void __iomem *regs;
54 unsigned int irq;
55
56 struct clk *clk_parent;
57 struct clk *clk;
Stephen Warrenca480802013-11-06 16:20:54 -070058 struct reset_control *rst;
Thierry Redingedec4af2012-11-15 21:28:23 +000059
Thierry Reding59af0592013-10-14 09:43:05 +020060 const struct tegra_hdmi_config *config;
61
Thierry Redingedec4af2012-11-15 21:28:23 +000062 unsigned int audio_source;
63 unsigned int audio_freq;
64 bool stereo;
65 bool dvi;
66
67 struct drm_info_list *debugfs_files;
68 struct drm_minor *minor;
69 struct dentry *debugfs;
70};
71
72static inline struct tegra_hdmi *
Thierry Reding776dc382013-10-14 14:43:22 +020073host1x_client_to_hdmi(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +000074{
75 return container_of(client, struct tegra_hdmi, client);
76}
77
78static inline struct tegra_hdmi *to_hdmi(struct tegra_output *output)
79{
80 return container_of(output, struct tegra_hdmi, output);
81}
82
83#define HDMI_AUDIOCLK_FREQ 216000000
84#define HDMI_REKEY_DEFAULT 56
85
86enum {
87 AUTO = 0,
88 SPDIF,
89 HDA,
90};
91
Thierry Reding4ee8cee2014-12-08 16:25:14 +010092static inline u32 tegra_hdmi_readl(struct tegra_hdmi *hdmi,
93 unsigned long offset)
Thierry Redingedec4af2012-11-15 21:28:23 +000094{
Thierry Reding4ee8cee2014-12-08 16:25:14 +010095 return readl(hdmi->regs + (offset << 2));
Thierry Redingedec4af2012-11-15 21:28:23 +000096}
97
Thierry Reding4ee8cee2014-12-08 16:25:14 +010098static inline void tegra_hdmi_writel(struct tegra_hdmi *hdmi, u32 value,
99 unsigned long offset)
Thierry Redingedec4af2012-11-15 21:28:23 +0000100{
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100101 writel(value, hdmi->regs + (offset << 2));
Thierry Redingedec4af2012-11-15 21:28:23 +0000102}
103
104struct tegra_hdmi_audio_config {
105 unsigned int pclk;
106 unsigned int n;
107 unsigned int cts;
108 unsigned int aval;
109};
110
111static const struct tegra_hdmi_audio_config tegra_hdmi_audio_32k[] = {
112 { 25200000, 4096, 25200, 24000 },
113 { 27000000, 4096, 27000, 24000 },
114 { 74250000, 4096, 74250, 24000 },
115 { 148500000, 4096, 148500, 24000 },
116 { 0, 0, 0, 0 },
117};
118
119static const struct tegra_hdmi_audio_config tegra_hdmi_audio_44_1k[] = {
120 { 25200000, 5880, 26250, 25000 },
121 { 27000000, 5880, 28125, 25000 },
122 { 74250000, 4704, 61875, 20000 },
123 { 148500000, 4704, 123750, 20000 },
124 { 0, 0, 0, 0 },
125};
126
127static const struct tegra_hdmi_audio_config tegra_hdmi_audio_48k[] = {
128 { 25200000, 6144, 25200, 24000 },
129 { 27000000, 6144, 27000, 24000 },
130 { 74250000, 6144, 74250, 24000 },
131 { 148500000, 6144, 148500, 24000 },
132 { 0, 0, 0, 0 },
133};
134
135static const struct tegra_hdmi_audio_config tegra_hdmi_audio_88_2k[] = {
136 { 25200000, 11760, 26250, 25000 },
137 { 27000000, 11760, 28125, 25000 },
138 { 74250000, 9408, 61875, 20000 },
139 { 148500000, 9408, 123750, 20000 },
140 { 0, 0, 0, 0 },
141};
142
143static const struct tegra_hdmi_audio_config tegra_hdmi_audio_96k[] = {
144 { 25200000, 12288, 25200, 24000 },
145 { 27000000, 12288, 27000, 24000 },
146 { 74250000, 12288, 74250, 24000 },
147 { 148500000, 12288, 148500, 24000 },
148 { 0, 0, 0, 0 },
149};
150
151static const struct tegra_hdmi_audio_config tegra_hdmi_audio_176_4k[] = {
152 { 25200000, 23520, 26250, 25000 },
153 { 27000000, 23520, 28125, 25000 },
154 { 74250000, 18816, 61875, 20000 },
155 { 148500000, 18816, 123750, 20000 },
156 { 0, 0, 0, 0 },
157};
158
159static const struct tegra_hdmi_audio_config tegra_hdmi_audio_192k[] = {
160 { 25200000, 24576, 25200, 24000 },
161 { 27000000, 24576, 27000, 24000 },
162 { 74250000, 24576, 74250, 24000 },
163 { 148500000, 24576, 148500, 24000 },
164 { 0, 0, 0, 0 },
165};
166
Thierry Redingf27db962013-09-30 15:14:41 +0200167static const struct tmds_config tegra20_tmds_config[] = {
Lucas Stachfa416dd2012-12-19 21:38:55 +0000168 { /* slow pixel clock modes */
Thierry Redingedec4af2012-11-15 21:28:23 +0000169 .pclk = 27000000,
170 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
171 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) |
172 SOR_PLL_TX_REG_LOAD(3),
173 .pll1 = SOR_PLL_TMDS_TERM_ENABLE,
174 .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) |
175 PE_CURRENT1(PE_CURRENT_0_0_mA) |
176 PE_CURRENT2(PE_CURRENT_0_0_mA) |
177 PE_CURRENT3(PE_CURRENT_0_0_mA),
178 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) |
179 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) |
180 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) |
181 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA),
Lucas Stachfa416dd2012-12-19 21:38:55 +0000182 },
183 { /* high pixel clock modes */
Thierry Redingedec4af2012-11-15 21:28:23 +0000184 .pclk = UINT_MAX,
185 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
186 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) |
187 SOR_PLL_TX_REG_LOAD(3),
188 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
189 .pe_current = PE_CURRENT0(PE_CURRENT_6_0_mA) |
190 PE_CURRENT1(PE_CURRENT_6_0_mA) |
191 PE_CURRENT2(PE_CURRENT_6_0_mA) |
192 PE_CURRENT3(PE_CURRENT_6_0_mA),
193 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) |
194 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) |
195 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) |
196 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA),
197 },
198};
199
Thierry Redingf27db962013-09-30 15:14:41 +0200200static const struct tmds_config tegra30_tmds_config[] = {
Thierry Redingedec4af2012-11-15 21:28:23 +0000201 { /* 480p modes */
202 .pclk = 27000000,
203 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
204 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) |
205 SOR_PLL_TX_REG_LOAD(0),
206 .pll1 = SOR_PLL_TMDS_TERM_ENABLE,
207 .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) |
208 PE_CURRENT1(PE_CURRENT_0_0_mA) |
209 PE_CURRENT2(PE_CURRENT_0_0_mA) |
210 PE_CURRENT3(PE_CURRENT_0_0_mA),
211 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
212 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
213 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
214 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
215 }, { /* 720p modes */
216 .pclk = 74250000,
217 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
218 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) |
219 SOR_PLL_TX_REG_LOAD(0),
220 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
221 .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) |
222 PE_CURRENT1(PE_CURRENT_5_0_mA) |
223 PE_CURRENT2(PE_CURRENT_5_0_mA) |
224 PE_CURRENT3(PE_CURRENT_5_0_mA),
225 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
226 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
227 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
228 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
229 }, { /* 1080p modes */
230 .pclk = UINT_MAX,
231 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
232 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(3) |
233 SOR_PLL_TX_REG_LOAD(0),
234 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
235 .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) |
236 PE_CURRENT1(PE_CURRENT_5_0_mA) |
237 PE_CURRENT2(PE_CURRENT_5_0_mA) |
238 PE_CURRENT3(PE_CURRENT_5_0_mA),
239 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
240 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
241 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
242 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
243 },
244};
245
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +0200246static const struct tmds_config tegra114_tmds_config[] = {
247 { /* 480p/576p / 25.2MHz/27MHz modes */
248 .pclk = 27000000,
249 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
250 SOR_PLL_VCOCAP(0) | SOR_PLL_RESISTORSEL,
251 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(0),
252 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
253 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
254 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
255 PE_CURRENT3(PE_CURRENT_0_mA_T114),
256 .drive_current =
257 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
258 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
259 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
260 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
261 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
262 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
263 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
264 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
265 }, { /* 720p / 74.25MHz modes */
266 .pclk = 74250000,
267 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
268 SOR_PLL_VCOCAP(1) | SOR_PLL_RESISTORSEL,
269 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
270 SOR_PLL_TMDS_TERMADJ(0),
271 .pe_current = PE_CURRENT0(PE_CURRENT_15_mA_T114) |
272 PE_CURRENT1(PE_CURRENT_15_mA_T114) |
273 PE_CURRENT2(PE_CURRENT_15_mA_T114) |
274 PE_CURRENT3(PE_CURRENT_15_mA_T114),
275 .drive_current =
276 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
277 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
278 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
279 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
280 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
281 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
282 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
283 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
284 }, { /* 1080p / 148.5MHz modes */
285 .pclk = 148500000,
286 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
287 SOR_PLL_VCOCAP(3) | SOR_PLL_RESISTORSEL,
288 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
289 SOR_PLL_TMDS_TERMADJ(0),
290 .pe_current = PE_CURRENT0(PE_CURRENT_10_mA_T114) |
291 PE_CURRENT1(PE_CURRENT_10_mA_T114) |
292 PE_CURRENT2(PE_CURRENT_10_mA_T114) |
293 PE_CURRENT3(PE_CURRENT_10_mA_T114),
294 .drive_current =
295 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_12_400_mA_T114) |
296 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_12_400_mA_T114) |
297 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_12_400_mA_T114) |
298 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_12_400_mA_T114),
299 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
300 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
301 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
302 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
303 }, { /* 225/297MHz modes */
304 .pclk = UINT_MAX,
305 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
306 SOR_PLL_VCOCAP(0xf) | SOR_PLL_RESISTORSEL,
307 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(7)
308 | SOR_PLL_TMDS_TERM_ENABLE,
309 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
310 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
311 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
312 PE_CURRENT3(PE_CURRENT_0_mA_T114),
313 .drive_current =
314 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_25_200_mA_T114) |
315 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_25_200_mA_T114) |
316 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_25_200_mA_T114) |
317 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_19_200_mA_T114),
318 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_3_000_mA) |
319 PEAK_CURRENT_LANE1(PEAK_CURRENT_3_000_mA) |
320 PEAK_CURRENT_LANE2(PEAK_CURRENT_3_000_mA) |
321 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_800_mA),
322 },
323};
324
Thierry Redingfb7be702013-11-15 16:07:32 +0100325static const struct tmds_config tegra124_tmds_config[] = {
326 { /* 480p/576p / 25.2MHz/27MHz modes */
327 .pclk = 27000000,
328 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
329 SOR_PLL_VCOCAP(0) | SOR_PLL_RESISTORSEL,
330 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(0),
331 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
332 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
333 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
334 PE_CURRENT3(PE_CURRENT_0_mA_T114),
335 .drive_current =
336 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
337 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
338 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
339 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
340 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
341 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
342 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
343 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
344 }, { /* 720p / 74.25MHz modes */
345 .pclk = 74250000,
346 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
347 SOR_PLL_VCOCAP(1) | SOR_PLL_RESISTORSEL,
348 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
349 SOR_PLL_TMDS_TERMADJ(0),
350 .pe_current = PE_CURRENT0(PE_CURRENT_15_mA_T114) |
351 PE_CURRENT1(PE_CURRENT_15_mA_T114) |
352 PE_CURRENT2(PE_CURRENT_15_mA_T114) |
353 PE_CURRENT3(PE_CURRENT_15_mA_T114),
354 .drive_current =
355 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
356 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
357 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
358 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
359 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
360 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
361 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
362 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
363 }, { /* 1080p / 148.5MHz modes */
364 .pclk = 148500000,
365 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
366 SOR_PLL_VCOCAP(3) | SOR_PLL_RESISTORSEL,
367 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
368 SOR_PLL_TMDS_TERMADJ(0),
369 .pe_current = PE_CURRENT0(PE_CURRENT_10_mA_T114) |
370 PE_CURRENT1(PE_CURRENT_10_mA_T114) |
371 PE_CURRENT2(PE_CURRENT_10_mA_T114) |
372 PE_CURRENT3(PE_CURRENT_10_mA_T114),
373 .drive_current =
374 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_12_400_mA_T114) |
375 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_12_400_mA_T114) |
376 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_12_400_mA_T114) |
377 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_12_400_mA_T114),
378 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
379 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
380 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
381 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
382 }, { /* 225/297MHz modes */
383 .pclk = UINT_MAX,
384 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
385 SOR_PLL_VCOCAP(0xf) | SOR_PLL_RESISTORSEL,
386 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(7)
387 | SOR_PLL_TMDS_TERM_ENABLE,
388 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
389 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
390 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
391 PE_CURRENT3(PE_CURRENT_0_mA_T114),
392 .drive_current =
393 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_25_200_mA_T114) |
394 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_25_200_mA_T114) |
395 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_25_200_mA_T114) |
396 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_19_200_mA_T114),
397 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_3_000_mA) |
398 PEAK_CURRENT_LANE1(PEAK_CURRENT_3_000_mA) |
399 PEAK_CURRENT_LANE2(PEAK_CURRENT_3_000_mA) |
400 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_800_mA),
401 },
402};
403
Thierry Redingedec4af2012-11-15 21:28:23 +0000404static const struct tegra_hdmi_audio_config *
405tegra_hdmi_get_audio_config(unsigned int audio_freq, unsigned int pclk)
406{
407 const struct tegra_hdmi_audio_config *table;
408
409 switch (audio_freq) {
410 case 32000:
411 table = tegra_hdmi_audio_32k;
412 break;
413
414 case 44100:
415 table = tegra_hdmi_audio_44_1k;
416 break;
417
418 case 48000:
419 table = tegra_hdmi_audio_48k;
420 break;
421
422 case 88200:
423 table = tegra_hdmi_audio_88_2k;
424 break;
425
426 case 96000:
427 table = tegra_hdmi_audio_96k;
428 break;
429
430 case 176400:
431 table = tegra_hdmi_audio_176_4k;
432 break;
433
434 case 192000:
435 table = tegra_hdmi_audio_192k;
436 break;
437
438 default:
439 return NULL;
440 }
441
442 while (table->pclk) {
443 if (table->pclk == pclk)
444 return table;
445
446 table++;
447 }
448
449 return NULL;
450}
451
452static void tegra_hdmi_setup_audio_fs_tables(struct tegra_hdmi *hdmi)
453{
454 const unsigned int freqs[] = {
455 32000, 44100, 48000, 88200, 96000, 176400, 192000
456 };
457 unsigned int i;
458
459 for (i = 0; i < ARRAY_SIZE(freqs); i++) {
460 unsigned int f = freqs[i];
461 unsigned int eight_half;
Thierry Redingedec4af2012-11-15 21:28:23 +0000462 unsigned int delta;
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100463 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000464
465 if (f > 96000)
466 delta = 2;
Thierry Reding17a8b6b2013-12-16 10:01:24 +0100467 else if (f > 48000)
Thierry Redingedec4af2012-11-15 21:28:23 +0000468 delta = 6;
469 else
470 delta = 9;
471
472 eight_half = (8 * HDMI_AUDIOCLK_FREQ) / (f * 128);
473 value = AUDIO_FS_LOW(eight_half - delta) |
474 AUDIO_FS_HIGH(eight_half + delta);
475 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_FS(i));
476 }
477}
478
479static int tegra_hdmi_setup_audio(struct tegra_hdmi *hdmi, unsigned int pclk)
480{
481 struct device_node *node = hdmi->dev->of_node;
482 const struct tegra_hdmi_audio_config *config;
483 unsigned int offset = 0;
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100484 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000485
486 switch (hdmi->audio_source) {
487 case HDA:
488 value = AUDIO_CNTRL0_SOURCE_SELECT_HDAL;
489 break;
490
491 case SPDIF:
492 value = AUDIO_CNTRL0_SOURCE_SELECT_SPDIF;
493 break;
494
495 default:
496 value = AUDIO_CNTRL0_SOURCE_SELECT_AUTO;
497 break;
498 }
499
500 if (of_device_is_compatible(node, "nvidia,tegra30-hdmi")) {
501 value |= AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
502 AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
503 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0);
504 } else {
505 value |= AUDIO_CNTRL0_INJECT_NULLSMPL;
506 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
507
508 value = AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
509 AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
510 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0);
511 }
512
513 config = tegra_hdmi_get_audio_config(hdmi->audio_freq, pclk);
514 if (!config) {
515 dev_err(hdmi->dev, "cannot set audio to %u at %u pclk\n",
516 hdmi->audio_freq, pclk);
517 return -EINVAL;
518 }
519
520 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_HDMI_ACR_CTRL);
521
522 value = AUDIO_N_RESETF | AUDIO_N_GENERATE_ALTERNATE |
523 AUDIO_N_VALUE(config->n - 1);
524 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N);
525
526 tegra_hdmi_writel(hdmi, ACR_SUBPACK_N(config->n) | ACR_ENABLE,
527 HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
528
529 value = ACR_SUBPACK_CTS(config->cts);
530 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
531
532 value = SPARE_HW_CTS | SPARE_FORCE_SW_CTS | SPARE_CTS_RESET_VAL(1);
533 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_SPARE);
534
535 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_AUDIO_N);
536 value &= ~AUDIO_N_RESETF;
537 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N);
538
539 if (of_device_is_compatible(node, "nvidia,tegra30-hdmi")) {
540 switch (hdmi->audio_freq) {
541 case 32000:
542 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0320;
543 break;
544
545 case 44100:
546 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0441;
547 break;
548
549 case 48000:
550 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0480;
551 break;
552
553 case 88200:
554 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0882;
555 break;
556
557 case 96000:
558 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0960;
559 break;
560
561 case 176400:
562 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_1764;
563 break;
564
565 case 192000:
566 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_1920;
567 break;
568 }
569
570 tegra_hdmi_writel(hdmi, config->aval, offset);
571 }
572
573 tegra_hdmi_setup_audio_fs_tables(hdmi);
574
575 return 0;
576}
577
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100578static inline u32 tegra_hdmi_subpack(const u8 *ptr, size_t size)
Thierry Redingedec4af2012-11-15 21:28:23 +0000579{
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100580 u32 value = 0;
Thierry Redingedec4af2012-11-15 21:28:23 +0000581 size_t i;
Thierry Redingedec4af2012-11-15 21:28:23 +0000582
Thierry Redingac24c222012-11-23 15:14:00 +0100583 for (i = size; i > 0; i--)
584 value = (value << 8) | ptr[i - 1];
Thierry Redingedec4af2012-11-15 21:28:23 +0000585
Thierry Redingac24c222012-11-23 15:14:00 +0100586 return value;
587}
Thierry Redingedec4af2012-11-15 21:28:23 +0000588
Thierry Redingac24c222012-11-23 15:14:00 +0100589static void tegra_hdmi_write_infopack(struct tegra_hdmi *hdmi, const void *data,
590 size_t size)
591{
592 const u8 *ptr = data;
593 unsigned long offset;
Thierry Redingac24c222012-11-23 15:14:00 +0100594 size_t i, j;
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100595 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000596
Thierry Redingac24c222012-11-23 15:14:00 +0100597 switch (ptr[0]) {
598 case HDMI_INFOFRAME_TYPE_AVI:
599 offset = HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER;
600 break;
601
602 case HDMI_INFOFRAME_TYPE_AUDIO:
603 offset = HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER;
604 break;
605
606 case HDMI_INFOFRAME_TYPE_VENDOR:
607 offset = HDMI_NV_PDISP_HDMI_GENERIC_HEADER;
608 break;
609
610 default:
611 dev_err(hdmi->dev, "unsupported infoframe type: %02x\n",
612 ptr[0]);
613 return;
614 }
615
616 value = INFOFRAME_HEADER_TYPE(ptr[0]) |
617 INFOFRAME_HEADER_VERSION(ptr[1]) |
618 INFOFRAME_HEADER_LEN(ptr[2]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000619 tegra_hdmi_writel(hdmi, value, offset);
Thierry Redingac24c222012-11-23 15:14:00 +0100620 offset++;
Thierry Redingedec4af2012-11-15 21:28:23 +0000621
Thierry Redingac24c222012-11-23 15:14:00 +0100622 /*
623 * Each subpack contains 7 bytes, divided into:
624 * - subpack_low: bytes 0 - 3
625 * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00)
Thierry Redingedec4af2012-11-15 21:28:23 +0000626 */
Thierry Redingac24c222012-11-23 15:14:00 +0100627 for (i = 3, j = 0; i < size; i += 7, j += 8) {
628 size_t rem = size - i, num = min_t(size_t, rem, 4);
Thierry Redingedec4af2012-11-15 21:28:23 +0000629
Thierry Redingac24c222012-11-23 15:14:00 +0100630 value = tegra_hdmi_subpack(&ptr[i], num);
631 tegra_hdmi_writel(hdmi, value, offset++);
Thierry Redingedec4af2012-11-15 21:28:23 +0000632
Thierry Redingac24c222012-11-23 15:14:00 +0100633 num = min_t(size_t, rem - num, 3);
Thierry Redingedec4af2012-11-15 21:28:23 +0000634
Thierry Redingac24c222012-11-23 15:14:00 +0100635 value = tegra_hdmi_subpack(&ptr[i + 4], num);
636 tegra_hdmi_writel(hdmi, value, offset++);
Thierry Redingedec4af2012-11-15 21:28:23 +0000637 }
638}
639
640static void tegra_hdmi_setup_avi_infoframe(struct tegra_hdmi *hdmi,
641 struct drm_display_mode *mode)
642{
643 struct hdmi_avi_infoframe frame;
Thierry Redingac24c222012-11-23 15:14:00 +0100644 u8 buffer[17];
645 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000646
647 if (hdmi->dvi) {
648 tegra_hdmi_writel(hdmi, 0,
649 HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
650 return;
651 }
652
Thierry Redingac24c222012-11-23 15:14:00 +0100653 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
654 if (err < 0) {
655 dev_err(hdmi->dev, "failed to setup AVI infoframe: %zd\n", err);
656 return;
Thierry Redingedec4af2012-11-15 21:28:23 +0000657 }
658
Thierry Redingac24c222012-11-23 15:14:00 +0100659 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
660 if (err < 0) {
661 dev_err(hdmi->dev, "failed to pack AVI infoframe: %zd\n", err);
662 return;
663 }
664
665 tegra_hdmi_write_infopack(hdmi, buffer, err);
Thierry Redingedec4af2012-11-15 21:28:23 +0000666
667 tegra_hdmi_writel(hdmi, INFOFRAME_CTRL_ENABLE,
668 HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
669}
670
671static void tegra_hdmi_setup_audio_infoframe(struct tegra_hdmi *hdmi)
672{
673 struct hdmi_audio_infoframe frame;
Thierry Redingac24c222012-11-23 15:14:00 +0100674 u8 buffer[14];
675 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000676
677 if (hdmi->dvi) {
678 tegra_hdmi_writel(hdmi, 0,
679 HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
680 return;
681 }
682
Thierry Redingac24c222012-11-23 15:14:00 +0100683 err = hdmi_audio_infoframe_init(&frame);
684 if (err < 0) {
Thierry Redingef284c72013-10-16 19:51:22 +0200685 dev_err(hdmi->dev, "failed to setup audio infoframe: %zd\n",
Thierry Redingac24c222012-11-23 15:14:00 +0100686 err);
687 return;
688 }
Thierry Redingedec4af2012-11-15 21:28:23 +0000689
Thierry Redingac24c222012-11-23 15:14:00 +0100690 frame.channels = 2;
691
692 err = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
693 if (err < 0) {
694 dev_err(hdmi->dev, "failed to pack audio infoframe: %zd\n",
695 err);
696 return;
697 }
698
699 /*
700 * The audio infoframe has only one set of subpack registers, so the
701 * infoframe needs to be truncated. One set of subpack registers can
702 * contain 7 bytes. Including the 3 byte header only the first 10
703 * bytes can be programmed.
704 */
Thierry Redingef284c72013-10-16 19:51:22 +0200705 tegra_hdmi_write_infopack(hdmi, buffer, min_t(size_t, 10, err));
Thierry Redingedec4af2012-11-15 21:28:23 +0000706
707 tegra_hdmi_writel(hdmi, INFOFRAME_CTRL_ENABLE,
708 HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
709}
710
711static void tegra_hdmi_setup_stereo_infoframe(struct tegra_hdmi *hdmi)
712{
Lespiau, Damienae84b902013-08-19 16:59:02 +0100713 struct hdmi_vendor_infoframe frame;
Thierry Redingac24c222012-11-23 15:14:00 +0100714 u8 buffer[10];
715 ssize_t err;
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100716 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000717
718 if (!hdmi->stereo) {
719 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
720 value &= ~GENERIC_CTRL_ENABLE;
721 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
722 return;
723 }
724
Lespiau, Damienae84b902013-08-19 16:59:02 +0100725 hdmi_vendor_infoframe_init(&frame);
Lespiau, Damiena26a58e82013-08-19 16:58:59 +0100726 frame.s3d_struct = HDMI_3D_STRUCTURE_FRAME_PACKING;
Thierry Redingac24c222012-11-23 15:14:00 +0100727
Lespiau, Damienae84b902013-08-19 16:59:02 +0100728 err = hdmi_vendor_infoframe_pack(&frame, buffer, sizeof(buffer));
Thierry Redingac24c222012-11-23 15:14:00 +0100729 if (err < 0) {
730 dev_err(hdmi->dev, "failed to pack vendor infoframe: %zd\n",
731 err);
732 return;
733 }
734
735 tegra_hdmi_write_infopack(hdmi, buffer, err);
Thierry Redingedec4af2012-11-15 21:28:23 +0000736
737 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
738 value |= GENERIC_CTRL_ENABLE;
739 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
740}
741
742static void tegra_hdmi_setup_tmds(struct tegra_hdmi *hdmi,
743 const struct tmds_config *tmds)
744{
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100745 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000746
747 tegra_hdmi_writel(hdmi, tmds->pll0, HDMI_NV_PDISP_SOR_PLL0);
748 tegra_hdmi_writel(hdmi, tmds->pll1, HDMI_NV_PDISP_SOR_PLL1);
749 tegra_hdmi_writel(hdmi, tmds->pe_current, HDMI_NV_PDISP_PE_CURRENT);
750
Thierry Reding59af0592013-10-14 09:43:05 +0200751 tegra_hdmi_writel(hdmi, tmds->drive_current,
752 HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
753
754 value = tegra_hdmi_readl(hdmi, hdmi->config->fuse_override_offset);
755 value |= hdmi->config->fuse_override_value;
756 tegra_hdmi_writel(hdmi, value, hdmi->config->fuse_override_offset);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +0200757
758 if (hdmi->config->has_sor_io_peak_current)
759 tegra_hdmi_writel(hdmi, tmds->peak_current,
760 HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +0000761}
762
Mikko Perttunen9f159122013-08-28 18:48:38 +0300763static bool tegra_output_is_hdmi(struct tegra_output *output)
764{
765 struct edid *edid;
766
767 if (!output->connector.edid_blob_ptr)
768 return false;
769
770 edid = (struct edid *)output->connector.edid_blob_ptr->data;
771
772 return drm_detect_hdmi_monitor(edid);
773}
774
Thierry Reding59682712014-11-28 16:50:59 +0100775static void tegra_hdmi_connector_dpms(struct drm_connector *connector,
776 int mode)
777{
778}
779
780static const struct drm_connector_funcs tegra_hdmi_connector_funcs = {
781 .dpms = tegra_hdmi_connector_dpms,
Thierry Reding9d441892014-11-24 17:02:53 +0100782 .reset = drm_atomic_helper_connector_reset,
Thierry Reding59682712014-11-28 16:50:59 +0100783 .detect = tegra_output_connector_detect,
784 .fill_modes = drm_helper_probe_single_connector_modes,
785 .destroy = tegra_output_connector_destroy,
Thierry Reding9d441892014-11-24 17:02:53 +0100786 .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
Thierry Reding4aa3df72014-11-24 16:27:13 +0100787 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
Thierry Reding59682712014-11-28 16:50:59 +0100788};
789
790static enum drm_mode_status
791tegra_hdmi_connector_mode_valid(struct drm_connector *connector,
792 struct drm_display_mode *mode)
793{
794 struct tegra_output *output = connector_to_output(connector);
795 struct tegra_hdmi *hdmi = to_hdmi(output);
796 unsigned long pclk = mode->clock * 1000;
797 enum drm_mode_status status = MODE_OK;
798 struct clk *parent;
799 long err;
800
801 parent = clk_get_parent(hdmi->clk_parent);
802
803 err = clk_round_rate(parent, pclk * 4);
804 if (err <= 0)
805 status = MODE_NOCLOCK;
806
807 return status;
808}
809
810static const struct drm_connector_helper_funcs
811tegra_hdmi_connector_helper_funcs = {
812 .get_modes = tegra_output_connector_get_modes,
813 .mode_valid = tegra_hdmi_connector_mode_valid,
814 .best_encoder = tegra_output_connector_best_encoder,
815};
816
817static const struct drm_encoder_funcs tegra_hdmi_encoder_funcs = {
818 .destroy = tegra_output_encoder_destroy,
819};
820
821static void tegra_hdmi_encoder_dpms(struct drm_encoder *encoder, int mode)
822{
823}
824
825static bool tegra_hdmi_encoder_mode_fixup(struct drm_encoder *encoder,
826 const struct drm_display_mode *mode,
827 struct drm_display_mode *adjusted)
828{
829 struct tegra_output *output = encoder_to_output(encoder);
830 struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
831 struct tegra_hdmi *hdmi = to_hdmi(output);
832 unsigned long pclk = mode->clock * 1000;
833 int err;
834
835 err = tegra_dc_setup_clock(dc, hdmi->clk_parent, pclk, 0);
836 if (err < 0) {
837 dev_err(output->dev, "failed to setup DC clock: %d\n", err);
838 return false;
839 }
840
841 err = clk_set_rate(hdmi->clk_parent, pclk);
842 if (err < 0) {
843 dev_err(output->dev, "failed to set clock rate to %lu Hz\n",
844 pclk);
845 return false;
846 }
847
848 return true;
849}
850
851static void tegra_hdmi_encoder_prepare(struct drm_encoder *encoder)
852{
853}
854
855static void tegra_hdmi_encoder_commit(struct drm_encoder *encoder)
856{
857}
858
859static void tegra_hdmi_encoder_mode_set(struct drm_encoder *encoder,
860 struct drm_display_mode *mode,
861 struct drm_display_mode *adjusted)
Thierry Redingedec4af2012-11-15 21:28:23 +0000862{
863 unsigned int h_sync_width, h_front_porch, h_back_porch, i, rekey;
Thierry Reding59682712014-11-28 16:50:59 +0100864 struct tegra_output *output = encoder_to_output(encoder);
865 struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
866 struct device_node *node = output->dev->of_node;
Thierry Redingedec4af2012-11-15 21:28:23 +0000867 struct tegra_hdmi *hdmi = to_hdmi(output);
Thierry Redingedec4af2012-11-15 21:28:23 +0000868 unsigned int pulse_start, div82, pclk;
Thierry Redingedec4af2012-11-15 21:28:23 +0000869 int retries = 1000;
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100870 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000871 int err;
872
Mikko Perttunen9f159122013-08-28 18:48:38 +0300873 hdmi->dvi = !tegra_output_is_hdmi(output);
874
Thierry Redingedec4af2012-11-15 21:28:23 +0000875 pclk = mode->clock * 1000;
876 h_sync_width = mode->hsync_end - mode->hsync_start;
Lucas Stach40495082012-12-19 21:38:52 +0000877 h_back_porch = mode->htotal - mode->hsync_end;
878 h_front_porch = mode->hsync_start - mode->hdisplay;
Thierry Redingedec4af2012-11-15 21:28:23 +0000879
Thierry Reding8c8282c2014-04-16 10:46:24 +0200880 /* power up sequence */
881 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0);
882 value &= ~SOR_PLL_PDBG;
883 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0);
884
885 usleep_range(10, 20);
886
887 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0);
888 value &= ~SOR_PLL_PWR;
889 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0);
890
Thierry Redingedec4af2012-11-15 21:28:23 +0000891 tegra_dc_writel(dc, VSYNC_H_POSITION(1),
892 DC_DISP_DISP_TIMING_OPTIONS);
893 tegra_dc_writel(dc, DITHER_CONTROL_DISABLE | BASE_COLOR_SIZE888,
894 DC_DISP_DISP_COLOR_CONTROL);
895
896 /* video_preamble uses h_pulse2 */
897 pulse_start = 1 + h_sync_width + h_back_porch - 10;
898
899 tegra_dc_writel(dc, H_PULSE_2_ENABLE, DC_DISP_DISP_SIGNAL_OPTIONS0);
900
901 value = PULSE_MODE_NORMAL | PULSE_POLARITY_HIGH | PULSE_QUAL_VACTIVE |
902 PULSE_LAST_END_A;
903 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL);
904
905 value = PULSE_START(pulse_start) | PULSE_END(pulse_start + 8);
906 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A);
907
908 value = VSYNC_WINDOW_END(0x210) | VSYNC_WINDOW_START(0x200) |
909 VSYNC_WINDOW_ENABLE;
910 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
911
912 if (dc->pipe)
913 value = HDMI_SRC_DISPLAYB;
914 else
915 value = HDMI_SRC_DISPLAYA;
916
917 if ((mode->hdisplay == 720) && ((mode->vdisplay == 480) ||
918 (mode->vdisplay == 576)))
919 tegra_hdmi_writel(hdmi,
920 value | ARM_VIDEO_RANGE_FULL,
921 HDMI_NV_PDISP_INPUT_CONTROL);
922 else
923 tegra_hdmi_writel(hdmi,
924 value | ARM_VIDEO_RANGE_LIMITED,
925 HDMI_NV_PDISP_INPUT_CONTROL);
926
927 div82 = clk_get_rate(hdmi->clk) / 1000000 * 4;
928 value = SOR_REFCLK_DIV_INT(div82 >> 2) | SOR_REFCLK_DIV_FRAC(div82);
929 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_REFCLK);
930
931 if (!hdmi->dvi) {
932 err = tegra_hdmi_setup_audio(hdmi, pclk);
933 if (err < 0)
934 hdmi->dvi = true;
935 }
936
937 if (of_device_is_compatible(node, "nvidia,tegra20-hdmi")) {
938 /*
939 * TODO: add ELD support
940 */
941 }
942
943 rekey = HDMI_REKEY_DEFAULT;
944 value = HDMI_CTRL_REKEY(rekey);
945 value |= HDMI_CTRL_MAX_AC_PACKET((h_sync_width + h_back_porch +
946 h_front_porch - rekey - 18) / 32);
947
948 if (!hdmi->dvi)
949 value |= HDMI_CTRL_ENABLE;
950
951 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_CTRL);
952
953 if (hdmi->dvi)
954 tegra_hdmi_writel(hdmi, 0x0,
955 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
956 else
957 tegra_hdmi_writel(hdmi, GENERIC_CTRL_AUDIO,
958 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
959
960 tegra_hdmi_setup_avi_infoframe(hdmi, mode);
961 tegra_hdmi_setup_audio_infoframe(hdmi);
962 tegra_hdmi_setup_stereo_infoframe(hdmi);
963
964 /* TMDS CONFIG */
Thierry Reding59af0592013-10-14 09:43:05 +0200965 for (i = 0; i < hdmi->config->num_tmds; i++) {
966 if (pclk <= hdmi->config->tmds[i].pclk) {
967 tegra_hdmi_setup_tmds(hdmi, &hdmi->config->tmds[i]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000968 break;
969 }
970 }
971
972 tegra_hdmi_writel(hdmi,
973 SOR_SEQ_CTL_PU_PC(0) |
974 SOR_SEQ_PU_PC_ALT(0) |
975 SOR_SEQ_PD_PC(8) |
976 SOR_SEQ_PD_PC_ALT(8),
977 HDMI_NV_PDISP_SOR_SEQ_CTL);
978
979 value = SOR_SEQ_INST_WAIT_TIME(1) |
980 SOR_SEQ_INST_WAIT_UNITS_VSYNC |
981 SOR_SEQ_INST_HALT |
982 SOR_SEQ_INST_PIN_A_LOW |
983 SOR_SEQ_INST_PIN_B_LOW |
984 SOR_SEQ_INST_DRIVE_PWM_OUT_LO;
985
986 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(0));
987 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(8));
988
Thierry Reding9cbfc732014-04-16 10:47:36 +0200989 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_CSTM);
Thierry Redingedec4af2012-11-15 21:28:23 +0000990 value &= ~SOR_CSTM_ROTCLK(~0);
991 value |= SOR_CSTM_ROTCLK(2);
Thierry Reding9cbfc732014-04-16 10:47:36 +0200992 value |= SOR_CSTM_PLLDIV;
993 value &= ~SOR_CSTM_LVDS_ENABLE;
994 value &= ~SOR_CSTM_MODE_MASK;
995 value |= SOR_CSTM_MODE_TMDS;
Thierry Redingedec4af2012-11-15 21:28:23 +0000996 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_CSTM);
997
Thierry Redingedec4af2012-11-15 21:28:23 +0000998 /* start SOR */
999 tegra_hdmi_writel(hdmi,
1000 SOR_PWR_NORMAL_STATE_PU |
1001 SOR_PWR_NORMAL_START_NORMAL |
1002 SOR_PWR_SAFE_STATE_PD |
1003 SOR_PWR_SETTING_NEW_TRIGGER,
1004 HDMI_NV_PDISP_SOR_PWR);
1005 tegra_hdmi_writel(hdmi,
1006 SOR_PWR_NORMAL_STATE_PU |
1007 SOR_PWR_NORMAL_START_NORMAL |
1008 SOR_PWR_SAFE_STATE_PD |
1009 SOR_PWR_SETTING_NEW_DONE,
1010 HDMI_NV_PDISP_SOR_PWR);
1011
1012 do {
1013 BUG_ON(--retries < 0);
1014 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PWR);
1015 } while (value & SOR_PWR_SETTING_NEW_PENDING);
1016
1017 value = SOR_STATE_ASY_CRCMODE_COMPLETE |
1018 SOR_STATE_ASY_OWNER_HEAD0 |
1019 SOR_STATE_ASY_SUBOWNER_BOTH |
1020 SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A |
1021 SOR_STATE_ASY_DEPOL_POS;
1022
1023 /* setup sync polarities */
1024 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
1025 value |= SOR_STATE_ASY_HSYNCPOL_POS;
1026
1027 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1028 value |= SOR_STATE_ASY_HSYNCPOL_NEG;
1029
1030 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
1031 value |= SOR_STATE_ASY_VSYNCPOL_POS;
1032
1033 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1034 value |= SOR_STATE_ASY_VSYNCPOL_NEG;
1035
1036 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE2);
1037
1038 value = SOR_STATE_ASY_HEAD_OPMODE_AWAKE | SOR_STATE_ASY_ORMODE_NORMAL;
1039 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE1);
1040
1041 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
1042 tegra_hdmi_writel(hdmi, SOR_STATE_UPDATE, HDMI_NV_PDISP_SOR_STATE0);
1043 tegra_hdmi_writel(hdmi, value | SOR_STATE_ATTACHED,
1044 HDMI_NV_PDISP_SOR_STATE1);
1045 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
1046
Thierry Reding72d30282013-12-12 11:06:55 +01001047 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
1048 value |= HDMI_ENABLE;
1049 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
Thierry Redingedec4af2012-11-15 21:28:23 +00001050
Thierry Reding72d30282013-12-12 11:06:55 +01001051 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
1052 value &= ~DISP_CTRL_MODE_MASK;
1053 value |= DISP_CTRL_MODE_C_DISPLAY;
Thierry Redingedec4af2012-11-15 21:28:23 +00001054 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
1055
Thierry Reding72d30282013-12-12 11:06:55 +01001056 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
1057 value |= PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
1058 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
1059 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
1060
Thierry Reding62b9e062014-11-21 17:33:33 +01001061 tegra_dc_commit(dc);
Thierry Redingedec4af2012-11-15 21:28:23 +00001062
1063 /* TODO: add HDCP support */
Thierry Redingedec4af2012-11-15 21:28:23 +00001064}
1065
Thierry Reding59682712014-11-28 16:50:59 +01001066static void tegra_hdmi_encoder_disable(struct drm_encoder *encoder)
Thierry Redingedec4af2012-11-15 21:28:23 +00001067{
Thierry Reding59682712014-11-28 16:50:59 +01001068 struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
Thierry Reding4ee8cee2014-12-08 16:25:14 +01001069 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +00001070
Thierry Reding72d30282013-12-12 11:06:55 +01001071 /*
1072 * The following accesses registers of the display controller, so make
1073 * sure it's only executed when the output is attached to one.
1074 */
1075 if (dc) {
Thierry Reding72d30282013-12-12 11:06:55 +01001076 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
1077 value &= ~HDMI_ENABLE;
1078 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
1079
Thierry Reding62b9e062014-11-21 17:33:33 +01001080 tegra_dc_commit(dc);
Thierry Reding72d30282013-12-12 11:06:55 +01001081 }
Thierry Redingedec4af2012-11-15 21:28:23 +00001082}
1083
Thierry Reding59682712014-11-28 16:50:59 +01001084static const struct drm_encoder_helper_funcs tegra_hdmi_encoder_helper_funcs = {
1085 .dpms = tegra_hdmi_encoder_dpms,
1086 .mode_fixup = tegra_hdmi_encoder_mode_fixup,
1087 .prepare = tegra_hdmi_encoder_prepare,
1088 .commit = tegra_hdmi_encoder_commit,
1089 .mode_set = tegra_hdmi_encoder_mode_set,
1090 .disable = tegra_hdmi_encoder_disable,
Thierry Redingedec4af2012-11-15 21:28:23 +00001091};
1092
1093static int tegra_hdmi_show_regs(struct seq_file *s, void *data)
1094{
1095 struct drm_info_node *node = s->private;
1096 struct tegra_hdmi *hdmi = node->info_ent->data;
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001097 int err;
1098
Thierry Redingd06e7f8f62014-04-16 10:43:41 +02001099 err = clk_prepare_enable(hdmi->clk);
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001100 if (err)
1101 return err;
Thierry Redingedec4af2012-11-15 21:28:23 +00001102
1103#define DUMP_REG(name) \
Thierry Reding4ee8cee2014-12-08 16:25:14 +01001104 seq_printf(s, "%-56s %#05x %08x\n", #name, name, \
1105 tegra_hdmi_readl(hdmi, name))
Thierry Redingedec4af2012-11-15 21:28:23 +00001106
1107 DUMP_REG(HDMI_CTXSW);
1108 DUMP_REG(HDMI_NV_PDISP_SOR_STATE0);
1109 DUMP_REG(HDMI_NV_PDISP_SOR_STATE1);
1110 DUMP_REG(HDMI_NV_PDISP_SOR_STATE2);
1111 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_MSB);
1112 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_LSB);
1113 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_MSB);
1114 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_LSB);
1115 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_MSB);
1116 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_LSB);
1117 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_MSB);
1118 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_LSB);
1119 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_MSB);
1120 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_LSB);
1121 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_MSB);
1122 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_LSB);
1123 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CTRL);
1124 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CMODE);
1125 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_MSB);
1126 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_LSB);
1127 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_MSB);
1128 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB2);
1129 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB1);
1130 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_RI);
1131 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_MSB);
1132 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_LSB);
1133 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU0);
1134 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU_RDATA0);
1135 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU1);
1136 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU2);
1137 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
1138 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_STATUS);
1139 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER);
1140 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_LOW);
1141 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_HIGH);
1142 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
1143 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_STATUS);
1144 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER);
1145 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_LOW);
1146 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_HIGH);
1147 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_LOW);
1148 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_HIGH);
1149 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
1150 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_STATUS);
1151 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_HEADER);
1152 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_LOW);
1153 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_HIGH);
1154 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_LOW);
1155 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_HIGH);
1156 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_LOW);
1157 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_HIGH);
1158 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_LOW);
1159 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_HIGH);
1160 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_CTRL);
1161 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_LOW);
1162 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_HIGH);
1163 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
1164 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
1165 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_LOW);
1166 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_HIGH);
1167 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_LOW);
1168 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_HIGH);
1169 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_LOW);
1170 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_HIGH);
1171 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_LOW);
1172 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_HIGH);
1173 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_LOW);
1174 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_HIGH);
1175 DUMP_REG(HDMI_NV_PDISP_HDMI_CTRL);
1176 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_KEEPOUT);
1177 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
1178 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_CTRL);
1179 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_STATUS);
1180 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_SUBPACK);
1181 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS1);
1182 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS2);
1183 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU0);
1184 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1);
1185 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1_RDATA);
1186 DUMP_REG(HDMI_NV_PDISP_HDMI_SPARE);
1187 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS1);
1188 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS2);
1189 DUMP_REG(HDMI_NV_PDISP_HDMI_HDCPRIF_ROM_CTRL);
1190 DUMP_REG(HDMI_NV_PDISP_SOR_CAP);
1191 DUMP_REG(HDMI_NV_PDISP_SOR_PWR);
1192 DUMP_REG(HDMI_NV_PDISP_SOR_TEST);
1193 DUMP_REG(HDMI_NV_PDISP_SOR_PLL0);
1194 DUMP_REG(HDMI_NV_PDISP_SOR_PLL1);
1195 DUMP_REG(HDMI_NV_PDISP_SOR_PLL2);
1196 DUMP_REG(HDMI_NV_PDISP_SOR_CSTM);
1197 DUMP_REG(HDMI_NV_PDISP_SOR_LVDS);
1198 DUMP_REG(HDMI_NV_PDISP_SOR_CRCA);
1199 DUMP_REG(HDMI_NV_PDISP_SOR_CRCB);
1200 DUMP_REG(HDMI_NV_PDISP_SOR_BLANK);
1201 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_CTL);
1202 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(0));
1203 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(1));
1204 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(2));
1205 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(3));
1206 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(4));
1207 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(5));
1208 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(6));
1209 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(7));
1210 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(8));
1211 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(9));
1212 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(10));
1213 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(11));
1214 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(12));
1215 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(13));
1216 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(14));
1217 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(15));
1218 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA0);
1219 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA1);
1220 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA0);
1221 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA1);
1222 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA0);
1223 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA1);
1224 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA0);
1225 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA1);
1226 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA0);
1227 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA1);
1228 DUMP_REG(HDMI_NV_PDISP_SOR_TRIG);
1229 DUMP_REG(HDMI_NV_PDISP_SOR_MSCHECK);
1230 DUMP_REG(HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
1231 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG0);
1232 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG1);
1233 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG2);
1234 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(0));
1235 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(1));
1236 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(2));
1237 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(3));
1238 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(4));
1239 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(5));
1240 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(6));
1241 DUMP_REG(HDMI_NV_PDISP_AUDIO_PULSE_WIDTH);
1242 DUMP_REG(HDMI_NV_PDISP_AUDIO_THRESHOLD);
1243 DUMP_REG(HDMI_NV_PDISP_AUDIO_CNTRL0);
1244 DUMP_REG(HDMI_NV_PDISP_AUDIO_N);
1245 DUMP_REG(HDMI_NV_PDISP_HDCPRIF_ROM_TIMING);
1246 DUMP_REG(HDMI_NV_PDISP_SOR_REFCLK);
1247 DUMP_REG(HDMI_NV_PDISP_CRC_CONTROL);
1248 DUMP_REG(HDMI_NV_PDISP_INPUT_CONTROL);
1249 DUMP_REG(HDMI_NV_PDISP_SCRATCH);
1250 DUMP_REG(HDMI_NV_PDISP_PE_CURRENT);
1251 DUMP_REG(HDMI_NV_PDISP_KEY_CTRL);
1252 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG0);
1253 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG1);
1254 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG2);
1255 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_0);
1256 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_1);
1257 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_2);
1258 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_3);
1259 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_TRIG);
1260 DUMP_REG(HDMI_NV_PDISP_KEY_SKEY_INDEX);
1261 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
1262 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR);
1263 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001264 DUMP_REG(HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +00001265
1266#undef DUMP_REG
1267
Thierry Redingd06e7f8f62014-04-16 10:43:41 +02001268 clk_disable_unprepare(hdmi->clk);
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001269
Thierry Redingedec4af2012-11-15 21:28:23 +00001270 return 0;
1271}
1272
1273static struct drm_info_list debugfs_files[] = {
1274 { "regs", tegra_hdmi_show_regs, 0, NULL },
1275};
1276
1277static int tegra_hdmi_debugfs_init(struct tegra_hdmi *hdmi,
1278 struct drm_minor *minor)
1279{
1280 unsigned int i;
1281 int err;
1282
1283 hdmi->debugfs = debugfs_create_dir("hdmi", minor->debugfs_root);
1284 if (!hdmi->debugfs)
1285 return -ENOMEM;
1286
1287 hdmi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
1288 GFP_KERNEL);
1289 if (!hdmi->debugfs_files) {
1290 err = -ENOMEM;
1291 goto remove;
1292 }
1293
1294 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
1295 hdmi->debugfs_files[i].data = hdmi;
1296
1297 err = drm_debugfs_create_files(hdmi->debugfs_files,
1298 ARRAY_SIZE(debugfs_files),
1299 hdmi->debugfs, minor);
1300 if (err < 0)
1301 goto free;
1302
1303 hdmi->minor = minor;
1304
1305 return 0;
1306
1307free:
1308 kfree(hdmi->debugfs_files);
1309 hdmi->debugfs_files = NULL;
1310remove:
1311 debugfs_remove(hdmi->debugfs);
1312 hdmi->debugfs = NULL;
1313
1314 return err;
1315}
1316
Thierry Reding4009c222014-12-19 15:47:30 +01001317static void tegra_hdmi_debugfs_exit(struct tegra_hdmi *hdmi)
Thierry Redingedec4af2012-11-15 21:28:23 +00001318{
1319 drm_debugfs_remove_files(hdmi->debugfs_files, ARRAY_SIZE(debugfs_files),
1320 hdmi->minor);
1321 hdmi->minor = NULL;
1322
1323 kfree(hdmi->debugfs_files);
1324 hdmi->debugfs_files = NULL;
1325
1326 debugfs_remove(hdmi->debugfs);
1327 hdmi->debugfs = NULL;
Thierry Redingedec4af2012-11-15 21:28:23 +00001328}
1329
Thierry Reding53fa7f72013-09-24 15:35:40 +02001330static int tegra_hdmi_init(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001331{
Thierry Reding9910f5c2014-05-22 09:57:15 +02001332 struct drm_device *drm = dev_get_drvdata(client->parent);
Thierry Reding776dc382013-10-14 14:43:22 +02001333 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001334 int err;
1335
Thierry Redingedec4af2012-11-15 21:28:23 +00001336 hdmi->output.dev = client->dev;
Thierry Redingedec4af2012-11-15 21:28:23 +00001337
Thierry Reding59682712014-11-28 16:50:59 +01001338 drm_connector_init(drm, &hdmi->output.connector,
1339 &tegra_hdmi_connector_funcs,
1340 DRM_MODE_CONNECTOR_HDMIA);
1341 drm_connector_helper_add(&hdmi->output.connector,
1342 &tegra_hdmi_connector_helper_funcs);
1343 hdmi->output.connector.dpms = DRM_MODE_DPMS_OFF;
1344
1345 drm_encoder_init(drm, &hdmi->output.encoder, &tegra_hdmi_encoder_funcs,
1346 DRM_MODE_ENCODER_TMDS);
1347 drm_encoder_helper_add(&hdmi->output.encoder,
1348 &tegra_hdmi_encoder_helper_funcs);
1349
1350 drm_mode_connector_attach_encoder(&hdmi->output.connector,
1351 &hdmi->output.encoder);
1352 drm_connector_register(&hdmi->output.connector);
1353
Thierry Redingea130b22014-12-19 15:51:35 +01001354 err = tegra_output_init(drm, &hdmi->output);
1355 if (err < 0) {
1356 dev_err(client->dev, "failed to initialize output: %d\n", err);
1357 return err;
1358 }
Thierry Reding59682712014-11-28 16:50:59 +01001359
Thierry Redingea130b22014-12-19 15:51:35 +01001360 hdmi->output.encoder.possible_crtcs = 0x3;
Thierry Redingedec4af2012-11-15 21:28:23 +00001361
1362 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding9910f5c2014-05-22 09:57:15 +02001363 err = tegra_hdmi_debugfs_init(hdmi, drm->primary);
Thierry Redingedec4af2012-11-15 21:28:23 +00001364 if (err < 0)
1365 dev_err(client->dev, "debugfs setup failed: %d\n", err);
1366 }
1367
Thierry Redingfb50a112014-02-28 16:57:34 +01001368 err = regulator_enable(hdmi->hdmi);
1369 if (err < 0) {
1370 dev_err(client->dev, "failed to enable HDMI regulator: %d\n",
1371 err);
1372 return err;
1373 }
1374
Thierry Reding59682712014-11-28 16:50:59 +01001375 err = regulator_enable(hdmi->pll);
1376 if (err < 0) {
1377 dev_err(hdmi->dev, "failed to enable PLL regulator: %d\n", err);
1378 return err;
1379 }
1380
1381 err = regulator_enable(hdmi->vdd);
1382 if (err < 0) {
1383 dev_err(hdmi->dev, "failed to enable VDD regulator: %d\n", err);
1384 return err;
1385 }
1386
1387 err = clk_prepare_enable(hdmi->clk);
1388 if (err < 0) {
1389 dev_err(hdmi->dev, "failed to enable clock: %d\n", err);
1390 return err;
1391 }
1392
1393 reset_control_deassert(hdmi->rst);
1394
Thierry Redingedec4af2012-11-15 21:28:23 +00001395 return 0;
1396}
1397
Thierry Reding53fa7f72013-09-24 15:35:40 +02001398static int tegra_hdmi_exit(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001399{
Thierry Reding776dc382013-10-14 14:43:22 +02001400 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001401
Thierry Reding59682712014-11-28 16:50:59 +01001402 tegra_output_exit(&hdmi->output);
1403
1404 clk_disable_unprepare(hdmi->clk);
1405 reset_control_assert(hdmi->rst);
1406
1407 regulator_disable(hdmi->vdd);
1408 regulator_disable(hdmi->pll);
Thierry Redingfb50a112014-02-28 16:57:34 +01001409 regulator_disable(hdmi->hdmi);
1410
Thierry Reding4009c222014-12-19 15:47:30 +01001411 if (IS_ENABLED(CONFIG_DEBUG_FS))
1412 tegra_hdmi_debugfs_exit(hdmi);
Thierry Redingedec4af2012-11-15 21:28:23 +00001413
Thierry Redingedec4af2012-11-15 21:28:23 +00001414 return 0;
1415}
1416
1417static const struct host1x_client_ops hdmi_client_ops = {
Thierry Reding53fa7f72013-09-24 15:35:40 +02001418 .init = tegra_hdmi_init,
1419 .exit = tegra_hdmi_exit,
Thierry Redingedec4af2012-11-15 21:28:23 +00001420};
1421
Thierry Reding59af0592013-10-14 09:43:05 +02001422static const struct tegra_hdmi_config tegra20_hdmi_config = {
1423 .tmds = tegra20_tmds_config,
1424 .num_tmds = ARRAY_SIZE(tegra20_tmds_config),
1425 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1426 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001427 .has_sor_io_peak_current = false,
Thierry Reding59af0592013-10-14 09:43:05 +02001428};
1429
1430static const struct tegra_hdmi_config tegra30_hdmi_config = {
1431 .tmds = tegra30_tmds_config,
1432 .num_tmds = ARRAY_SIZE(tegra30_tmds_config),
1433 .fuse_override_offset = HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT,
1434 .fuse_override_value = 1 << 31,
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001435 .has_sor_io_peak_current = false,
1436};
1437
1438static const struct tegra_hdmi_config tegra114_hdmi_config = {
1439 .tmds = tegra114_tmds_config,
1440 .num_tmds = ARRAY_SIZE(tegra114_tmds_config),
1441 .fuse_override_offset = HDMI_NV_PDISP_SOR_PAD_CTLS0,
1442 .fuse_override_value = 1 << 31,
1443 .has_sor_io_peak_current = true,
Thierry Reding59af0592013-10-14 09:43:05 +02001444};
1445
Thierry Redingfb7be702013-11-15 16:07:32 +01001446static const struct tegra_hdmi_config tegra124_hdmi_config = {
1447 .tmds = tegra124_tmds_config,
1448 .num_tmds = ARRAY_SIZE(tegra124_tmds_config),
1449 .fuse_override_offset = HDMI_NV_PDISP_SOR_PAD_CTLS0,
1450 .fuse_override_value = 1 << 31,
1451 .has_sor_io_peak_current = true,
1452};
1453
Thierry Reding59af0592013-10-14 09:43:05 +02001454static const struct of_device_id tegra_hdmi_of_match[] = {
Thierry Redingfb7be702013-11-15 16:07:32 +01001455 { .compatible = "nvidia,tegra124-hdmi", .data = &tegra124_hdmi_config },
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001456 { .compatible = "nvidia,tegra114-hdmi", .data = &tegra114_hdmi_config },
Thierry Reding59af0592013-10-14 09:43:05 +02001457 { .compatible = "nvidia,tegra30-hdmi", .data = &tegra30_hdmi_config },
1458 { .compatible = "nvidia,tegra20-hdmi", .data = &tegra20_hdmi_config },
1459 { },
1460};
Stephen Warrenef707282014-06-18 16:21:55 -06001461MODULE_DEVICE_TABLE(of, tegra_hdmi_of_match);
Thierry Reding59af0592013-10-14 09:43:05 +02001462
Thierry Redingedec4af2012-11-15 21:28:23 +00001463static int tegra_hdmi_probe(struct platform_device *pdev)
1464{
Thierry Reding59af0592013-10-14 09:43:05 +02001465 const struct of_device_id *match;
Thierry Redingedec4af2012-11-15 21:28:23 +00001466 struct tegra_hdmi *hdmi;
1467 struct resource *regs;
1468 int err;
1469
Thierry Reding59af0592013-10-14 09:43:05 +02001470 match = of_match_node(tegra_hdmi_of_match, pdev->dev.of_node);
1471 if (!match)
1472 return -ENODEV;
1473
Thierry Redingedec4af2012-11-15 21:28:23 +00001474 hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
1475 if (!hdmi)
1476 return -ENOMEM;
1477
Thierry Reding59af0592013-10-14 09:43:05 +02001478 hdmi->config = match->data;
Thierry Redingedec4af2012-11-15 21:28:23 +00001479 hdmi->dev = &pdev->dev;
1480 hdmi->audio_source = AUTO;
1481 hdmi->audio_freq = 44100;
1482 hdmi->stereo = false;
1483 hdmi->dvi = false;
1484
1485 hdmi->clk = devm_clk_get(&pdev->dev, NULL);
1486 if (IS_ERR(hdmi->clk)) {
1487 dev_err(&pdev->dev, "failed to get clock\n");
1488 return PTR_ERR(hdmi->clk);
1489 }
1490
Stephen Warrenca480802013-11-06 16:20:54 -07001491 hdmi->rst = devm_reset_control_get(&pdev->dev, "hdmi");
1492 if (IS_ERR(hdmi->rst)) {
1493 dev_err(&pdev->dev, "failed to get reset\n");
1494 return PTR_ERR(hdmi->rst);
1495 }
1496
Thierry Redingedec4af2012-11-15 21:28:23 +00001497 hdmi->clk_parent = devm_clk_get(&pdev->dev, "parent");
1498 if (IS_ERR(hdmi->clk_parent))
1499 return PTR_ERR(hdmi->clk_parent);
1500
Thierry Redingedec4af2012-11-15 21:28:23 +00001501 err = clk_set_parent(hdmi->clk, hdmi->clk_parent);
1502 if (err < 0) {
1503 dev_err(&pdev->dev, "failed to setup clocks: %d\n", err);
1504 return err;
1505 }
1506
Thierry Redingfb50a112014-02-28 16:57:34 +01001507 hdmi->hdmi = devm_regulator_get(&pdev->dev, "hdmi");
1508 if (IS_ERR(hdmi->hdmi)) {
1509 dev_err(&pdev->dev, "failed to get HDMI regulator\n");
1510 return PTR_ERR(hdmi->hdmi);
1511 }
1512
Thierry Redingedec4af2012-11-15 21:28:23 +00001513 hdmi->pll = devm_regulator_get(&pdev->dev, "pll");
1514 if (IS_ERR(hdmi->pll)) {
1515 dev_err(&pdev->dev, "failed to get PLL regulator\n");
1516 return PTR_ERR(hdmi->pll);
1517 }
1518
Thierry Reding88685682014-04-16 10:24:12 +02001519 hdmi->vdd = devm_regulator_get(&pdev->dev, "vdd");
1520 if (IS_ERR(hdmi->vdd)) {
1521 dev_err(&pdev->dev, "failed to get VDD regulator\n");
1522 return PTR_ERR(hdmi->vdd);
1523 }
1524
Thierry Redingedec4af2012-11-15 21:28:23 +00001525 hdmi->output.dev = &pdev->dev;
1526
Thierry Reding59d29c02013-10-14 14:26:42 +02001527 err = tegra_output_probe(&hdmi->output);
Thierry Redingedec4af2012-11-15 21:28:23 +00001528 if (err < 0)
1529 return err;
1530
1531 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Thierry Redingd4ed6022013-01-21 11:09:02 +01001532 hdmi->regs = devm_ioremap_resource(&pdev->dev, regs);
1533 if (IS_ERR(hdmi->regs))
1534 return PTR_ERR(hdmi->regs);
Thierry Redingedec4af2012-11-15 21:28:23 +00001535
1536 err = platform_get_irq(pdev, 0);
1537 if (err < 0)
1538 return err;
1539
1540 hdmi->irq = err;
1541
Thierry Reding776dc382013-10-14 14:43:22 +02001542 INIT_LIST_HEAD(&hdmi->client.list);
1543 hdmi->client.ops = &hdmi_client_ops;
1544 hdmi->client.dev = &pdev->dev;
Thierry Redingedec4af2012-11-15 21:28:23 +00001545
Thierry Reding776dc382013-10-14 14:43:22 +02001546 err = host1x_client_register(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001547 if (err < 0) {
1548 dev_err(&pdev->dev, "failed to register host1x client: %d\n",
1549 err);
1550 return err;
1551 }
1552
1553 platform_set_drvdata(pdev, hdmi);
1554
1555 return 0;
1556}
1557
1558static int tegra_hdmi_remove(struct platform_device *pdev)
1559{
Thierry Redingedec4af2012-11-15 21:28:23 +00001560 struct tegra_hdmi *hdmi = platform_get_drvdata(pdev);
1561 int err;
1562
Thierry Reding776dc382013-10-14 14:43:22 +02001563 err = host1x_client_unregister(&hdmi->client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001564 if (err < 0) {
1565 dev_err(&pdev->dev, "failed to unregister host1x client: %d\n",
1566 err);
1567 return err;
1568 }
1569
Thierry Reding328ec692014-12-19 15:55:08 +01001570 tegra_output_remove(&hdmi->output);
Thierry Reding59d29c02013-10-14 14:26:42 +02001571
Thierry Redingd06e7f8f62014-04-16 10:43:41 +02001572 clk_disable_unprepare(hdmi->clk_parent);
1573 clk_disable_unprepare(hdmi->clk);
Thierry Redingedec4af2012-11-15 21:28:23 +00001574
1575 return 0;
1576}
1577
Thierry Redingedec4af2012-11-15 21:28:23 +00001578struct platform_driver tegra_hdmi_driver = {
1579 .driver = {
1580 .name = "tegra-hdmi",
1581 .owner = THIS_MODULE,
1582 .of_match_table = tegra_hdmi_of_match,
1583 },
1584 .probe = tegra_hdmi_probe,
1585 .remove = tegra_hdmi_remove,
1586};