blob: 056bb2c1c426a1f2e1f9b6e1398fe5b6ffd8fde0 [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 Reding59682712014-11-28 16:50:59 +010017#include <drm/drm_crtc.h>
18#include <drm/drm_crtc_helper.h>
19
Thierry Redingedec4af2012-11-15 21:28:23 +000020#include "hdmi.h"
21#include "drm.h"
22#include "dc.h"
23
Thierry Reding59af0592013-10-14 09:43:05 +020024struct tmds_config {
25 unsigned int pclk;
26 u32 pll0;
27 u32 pll1;
28 u32 pe_current;
29 u32 drive_current;
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +020030 u32 peak_current;
Thierry Reding59af0592013-10-14 09:43:05 +020031};
32
33struct tegra_hdmi_config {
34 const struct tmds_config *tmds;
35 unsigned int num_tmds;
36
37 unsigned long fuse_override_offset;
Thierry Reding4ee8cee2014-12-08 16:25:14 +010038 u32 fuse_override_value;
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +020039
40 bool has_sor_io_peak_current;
Thierry Reding59af0592013-10-14 09:43:05 +020041};
42
Thierry Redingedec4af2012-11-15 21:28:23 +000043struct tegra_hdmi {
Thierry Reding776dc382013-10-14 14:43:22 +020044 struct host1x_client client;
Thierry Redingedec4af2012-11-15 21:28:23 +000045 struct tegra_output output;
46 struct device *dev;
47
Thierry Redingfb50a112014-02-28 16:57:34 +010048 struct regulator *hdmi;
Thierry Redingedec4af2012-11-15 21:28:23 +000049 struct regulator *pll;
Thierry Reding88685682014-04-16 10:24:12 +020050 struct regulator *vdd;
Thierry Redingedec4af2012-11-15 21:28:23 +000051
52 void __iomem *regs;
53 unsigned int irq;
54
55 struct clk *clk_parent;
56 struct clk *clk;
Stephen Warrenca480802013-11-06 16:20:54 -070057 struct reset_control *rst;
Thierry Redingedec4af2012-11-15 21:28:23 +000058
Thierry Reding59af0592013-10-14 09:43:05 +020059 const struct tegra_hdmi_config *config;
60
Thierry Redingedec4af2012-11-15 21:28:23 +000061 unsigned int audio_source;
62 unsigned int audio_freq;
63 bool stereo;
64 bool dvi;
65
66 struct drm_info_list *debugfs_files;
67 struct drm_minor *minor;
68 struct dentry *debugfs;
69};
70
71static inline struct tegra_hdmi *
Thierry Reding776dc382013-10-14 14:43:22 +020072host1x_client_to_hdmi(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +000073{
74 return container_of(client, struct tegra_hdmi, client);
75}
76
77static inline struct tegra_hdmi *to_hdmi(struct tegra_output *output)
78{
79 return container_of(output, struct tegra_hdmi, output);
80}
81
82#define HDMI_AUDIOCLK_FREQ 216000000
83#define HDMI_REKEY_DEFAULT 56
84
85enum {
86 AUTO = 0,
87 SPDIF,
88 HDA,
89};
90
Thierry Reding4ee8cee2014-12-08 16:25:14 +010091static inline u32 tegra_hdmi_readl(struct tegra_hdmi *hdmi,
92 unsigned long offset)
Thierry Redingedec4af2012-11-15 21:28:23 +000093{
Thierry Reding4ee8cee2014-12-08 16:25:14 +010094 return readl(hdmi->regs + (offset << 2));
Thierry Redingedec4af2012-11-15 21:28:23 +000095}
96
Thierry Reding4ee8cee2014-12-08 16:25:14 +010097static inline void tegra_hdmi_writel(struct tegra_hdmi *hdmi, u32 value,
98 unsigned long offset)
Thierry Redingedec4af2012-11-15 21:28:23 +000099{
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100100 writel(value, hdmi->regs + (offset << 2));
Thierry Redingedec4af2012-11-15 21:28:23 +0000101}
102
103struct tegra_hdmi_audio_config {
104 unsigned int pclk;
105 unsigned int n;
106 unsigned int cts;
107 unsigned int aval;
108};
109
110static const struct tegra_hdmi_audio_config tegra_hdmi_audio_32k[] = {
111 { 25200000, 4096, 25200, 24000 },
112 { 27000000, 4096, 27000, 24000 },
113 { 74250000, 4096, 74250, 24000 },
114 { 148500000, 4096, 148500, 24000 },
115 { 0, 0, 0, 0 },
116};
117
118static const struct tegra_hdmi_audio_config tegra_hdmi_audio_44_1k[] = {
119 { 25200000, 5880, 26250, 25000 },
120 { 27000000, 5880, 28125, 25000 },
121 { 74250000, 4704, 61875, 20000 },
122 { 148500000, 4704, 123750, 20000 },
123 { 0, 0, 0, 0 },
124};
125
126static const struct tegra_hdmi_audio_config tegra_hdmi_audio_48k[] = {
127 { 25200000, 6144, 25200, 24000 },
128 { 27000000, 6144, 27000, 24000 },
129 { 74250000, 6144, 74250, 24000 },
130 { 148500000, 6144, 148500, 24000 },
131 { 0, 0, 0, 0 },
132};
133
134static const struct tegra_hdmi_audio_config tegra_hdmi_audio_88_2k[] = {
135 { 25200000, 11760, 26250, 25000 },
136 { 27000000, 11760, 28125, 25000 },
137 { 74250000, 9408, 61875, 20000 },
138 { 148500000, 9408, 123750, 20000 },
139 { 0, 0, 0, 0 },
140};
141
142static const struct tegra_hdmi_audio_config tegra_hdmi_audio_96k[] = {
143 { 25200000, 12288, 25200, 24000 },
144 { 27000000, 12288, 27000, 24000 },
145 { 74250000, 12288, 74250, 24000 },
146 { 148500000, 12288, 148500, 24000 },
147 { 0, 0, 0, 0 },
148};
149
150static const struct tegra_hdmi_audio_config tegra_hdmi_audio_176_4k[] = {
151 { 25200000, 23520, 26250, 25000 },
152 { 27000000, 23520, 28125, 25000 },
153 { 74250000, 18816, 61875, 20000 },
154 { 148500000, 18816, 123750, 20000 },
155 { 0, 0, 0, 0 },
156};
157
158static const struct tegra_hdmi_audio_config tegra_hdmi_audio_192k[] = {
159 { 25200000, 24576, 25200, 24000 },
160 { 27000000, 24576, 27000, 24000 },
161 { 74250000, 24576, 74250, 24000 },
162 { 148500000, 24576, 148500, 24000 },
163 { 0, 0, 0, 0 },
164};
165
Thierry Redingf27db962013-09-30 15:14:41 +0200166static const struct tmds_config tegra20_tmds_config[] = {
Lucas Stachfa416dd2012-12-19 21:38:55 +0000167 { /* slow pixel clock modes */
Thierry Redingedec4af2012-11-15 21:28:23 +0000168 .pclk = 27000000,
169 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
170 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) |
171 SOR_PLL_TX_REG_LOAD(3),
172 .pll1 = SOR_PLL_TMDS_TERM_ENABLE,
173 .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) |
174 PE_CURRENT1(PE_CURRENT_0_0_mA) |
175 PE_CURRENT2(PE_CURRENT_0_0_mA) |
176 PE_CURRENT3(PE_CURRENT_0_0_mA),
177 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) |
178 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) |
179 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) |
180 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA),
Lucas Stachfa416dd2012-12-19 21:38:55 +0000181 },
182 { /* high pixel clock modes */
Thierry Redingedec4af2012-11-15 21:28:23 +0000183 .pclk = UINT_MAX,
184 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
185 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) |
186 SOR_PLL_TX_REG_LOAD(3),
187 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
188 .pe_current = PE_CURRENT0(PE_CURRENT_6_0_mA) |
189 PE_CURRENT1(PE_CURRENT_6_0_mA) |
190 PE_CURRENT2(PE_CURRENT_6_0_mA) |
191 PE_CURRENT3(PE_CURRENT_6_0_mA),
192 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_7_125_mA) |
193 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_7_125_mA) |
194 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_7_125_mA) |
195 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_7_125_mA),
196 },
197};
198
Thierry Redingf27db962013-09-30 15:14:41 +0200199static const struct tmds_config tegra30_tmds_config[] = {
Thierry Redingedec4af2012-11-15 21:28:23 +0000200 { /* 480p modes */
201 .pclk = 27000000,
202 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
203 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(0) |
204 SOR_PLL_TX_REG_LOAD(0),
205 .pll1 = SOR_PLL_TMDS_TERM_ENABLE,
206 .pe_current = PE_CURRENT0(PE_CURRENT_0_0_mA) |
207 PE_CURRENT1(PE_CURRENT_0_0_mA) |
208 PE_CURRENT2(PE_CURRENT_0_0_mA) |
209 PE_CURRENT3(PE_CURRENT_0_0_mA),
210 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
211 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
212 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
213 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
214 }, { /* 720p modes */
215 .pclk = 74250000,
216 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
217 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(1) |
218 SOR_PLL_TX_REG_LOAD(0),
219 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
220 .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) |
221 PE_CURRENT1(PE_CURRENT_5_0_mA) |
222 PE_CURRENT2(PE_CURRENT_5_0_mA) |
223 PE_CURRENT3(PE_CURRENT_5_0_mA),
224 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
225 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
226 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
227 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
228 }, { /* 1080p modes */
229 .pclk = UINT_MAX,
230 .pll0 = SOR_PLL_BG_V17_S(3) | SOR_PLL_ICHPMP(1) |
231 SOR_PLL_RESISTORSEL | SOR_PLL_VCOCAP(3) |
232 SOR_PLL_TX_REG_LOAD(0),
233 .pll1 = SOR_PLL_TMDS_TERM_ENABLE | SOR_PLL_PE_EN,
234 .pe_current = PE_CURRENT0(PE_CURRENT_5_0_mA) |
235 PE_CURRENT1(PE_CURRENT_5_0_mA) |
236 PE_CURRENT2(PE_CURRENT_5_0_mA) |
237 PE_CURRENT3(PE_CURRENT_5_0_mA),
238 .drive_current = DRIVE_CURRENT_LANE0(DRIVE_CURRENT_5_250_mA) |
239 DRIVE_CURRENT_LANE1(DRIVE_CURRENT_5_250_mA) |
240 DRIVE_CURRENT_LANE2(DRIVE_CURRENT_5_250_mA) |
241 DRIVE_CURRENT_LANE3(DRIVE_CURRENT_5_250_mA),
242 },
243};
244
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +0200245static const struct tmds_config tegra114_tmds_config[] = {
246 { /* 480p/576p / 25.2MHz/27MHz modes */
247 .pclk = 27000000,
248 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
249 SOR_PLL_VCOCAP(0) | SOR_PLL_RESISTORSEL,
250 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(0),
251 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
252 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
253 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
254 PE_CURRENT3(PE_CURRENT_0_mA_T114),
255 .drive_current =
256 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
257 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
258 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
259 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
260 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
261 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
262 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
263 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
264 }, { /* 720p / 74.25MHz modes */
265 .pclk = 74250000,
266 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
267 SOR_PLL_VCOCAP(1) | SOR_PLL_RESISTORSEL,
268 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
269 SOR_PLL_TMDS_TERMADJ(0),
270 .pe_current = PE_CURRENT0(PE_CURRENT_15_mA_T114) |
271 PE_CURRENT1(PE_CURRENT_15_mA_T114) |
272 PE_CURRENT2(PE_CURRENT_15_mA_T114) |
273 PE_CURRENT3(PE_CURRENT_15_mA_T114),
274 .drive_current =
275 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
276 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
277 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
278 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
279 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
280 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
281 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
282 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
283 }, { /* 1080p / 148.5MHz modes */
284 .pclk = 148500000,
285 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
286 SOR_PLL_VCOCAP(3) | SOR_PLL_RESISTORSEL,
287 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
288 SOR_PLL_TMDS_TERMADJ(0),
289 .pe_current = PE_CURRENT0(PE_CURRENT_10_mA_T114) |
290 PE_CURRENT1(PE_CURRENT_10_mA_T114) |
291 PE_CURRENT2(PE_CURRENT_10_mA_T114) |
292 PE_CURRENT3(PE_CURRENT_10_mA_T114),
293 .drive_current =
294 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_12_400_mA_T114) |
295 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_12_400_mA_T114) |
296 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_12_400_mA_T114) |
297 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_12_400_mA_T114),
298 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
299 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
300 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
301 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
302 }, { /* 225/297MHz modes */
303 .pclk = UINT_MAX,
304 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
305 SOR_PLL_VCOCAP(0xf) | SOR_PLL_RESISTORSEL,
306 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(7)
307 | SOR_PLL_TMDS_TERM_ENABLE,
308 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
309 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
310 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
311 PE_CURRENT3(PE_CURRENT_0_mA_T114),
312 .drive_current =
313 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_25_200_mA_T114) |
314 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_25_200_mA_T114) |
315 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_25_200_mA_T114) |
316 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_19_200_mA_T114),
317 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_3_000_mA) |
318 PEAK_CURRENT_LANE1(PEAK_CURRENT_3_000_mA) |
319 PEAK_CURRENT_LANE2(PEAK_CURRENT_3_000_mA) |
320 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_800_mA),
321 },
322};
323
Thierry Redingfb7be702013-11-15 16:07:32 +0100324static const struct tmds_config tegra124_tmds_config[] = {
325 { /* 480p/576p / 25.2MHz/27MHz modes */
326 .pclk = 27000000,
327 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
328 SOR_PLL_VCOCAP(0) | SOR_PLL_RESISTORSEL,
329 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(0),
330 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
331 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
332 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
333 PE_CURRENT3(PE_CURRENT_0_mA_T114),
334 .drive_current =
335 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
336 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
337 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
338 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
339 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
340 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
341 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
342 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
343 }, { /* 720p / 74.25MHz modes */
344 .pclk = 74250000,
345 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
346 SOR_PLL_VCOCAP(1) | SOR_PLL_RESISTORSEL,
347 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
348 SOR_PLL_TMDS_TERMADJ(0),
349 .pe_current = PE_CURRENT0(PE_CURRENT_15_mA_T114) |
350 PE_CURRENT1(PE_CURRENT_15_mA_T114) |
351 PE_CURRENT2(PE_CURRENT_15_mA_T114) |
352 PE_CURRENT3(PE_CURRENT_15_mA_T114),
353 .drive_current =
354 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_10_400_mA_T114) |
355 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_10_400_mA_T114) |
356 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_10_400_mA_T114) |
357 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_10_400_mA_T114),
358 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
359 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
360 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
361 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
362 }, { /* 1080p / 148.5MHz modes */
363 .pclk = 148500000,
364 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
365 SOR_PLL_VCOCAP(3) | SOR_PLL_RESISTORSEL,
366 .pll1 = SOR_PLL_PE_EN | SOR_PLL_LOADADJ(3) |
367 SOR_PLL_TMDS_TERMADJ(0),
368 .pe_current = PE_CURRENT0(PE_CURRENT_10_mA_T114) |
369 PE_CURRENT1(PE_CURRENT_10_mA_T114) |
370 PE_CURRENT2(PE_CURRENT_10_mA_T114) |
371 PE_CURRENT3(PE_CURRENT_10_mA_T114),
372 .drive_current =
373 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_12_400_mA_T114) |
374 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_12_400_mA_T114) |
375 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_12_400_mA_T114) |
376 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_12_400_mA_T114),
377 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_0_000_mA) |
378 PEAK_CURRENT_LANE1(PEAK_CURRENT_0_000_mA) |
379 PEAK_CURRENT_LANE2(PEAK_CURRENT_0_000_mA) |
380 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_000_mA),
381 }, { /* 225/297MHz modes */
382 .pclk = UINT_MAX,
383 .pll0 = SOR_PLL_ICHPMP(1) | SOR_PLL_BG_V17_S(3) |
384 SOR_PLL_VCOCAP(0xf) | SOR_PLL_RESISTORSEL,
385 .pll1 = SOR_PLL_LOADADJ(3) | SOR_PLL_TMDS_TERMADJ(7)
386 | SOR_PLL_TMDS_TERM_ENABLE,
387 .pe_current = PE_CURRENT0(PE_CURRENT_0_mA_T114) |
388 PE_CURRENT1(PE_CURRENT_0_mA_T114) |
389 PE_CURRENT2(PE_CURRENT_0_mA_T114) |
390 PE_CURRENT3(PE_CURRENT_0_mA_T114),
391 .drive_current =
392 DRIVE_CURRENT_LANE0_T114(DRIVE_CURRENT_25_200_mA_T114) |
393 DRIVE_CURRENT_LANE1_T114(DRIVE_CURRENT_25_200_mA_T114) |
394 DRIVE_CURRENT_LANE2_T114(DRIVE_CURRENT_25_200_mA_T114) |
395 DRIVE_CURRENT_LANE3_T114(DRIVE_CURRENT_19_200_mA_T114),
396 .peak_current = PEAK_CURRENT_LANE0(PEAK_CURRENT_3_000_mA) |
397 PEAK_CURRENT_LANE1(PEAK_CURRENT_3_000_mA) |
398 PEAK_CURRENT_LANE2(PEAK_CURRENT_3_000_mA) |
399 PEAK_CURRENT_LANE3(PEAK_CURRENT_0_800_mA),
400 },
401};
402
Thierry Redingedec4af2012-11-15 21:28:23 +0000403static const struct tegra_hdmi_audio_config *
404tegra_hdmi_get_audio_config(unsigned int audio_freq, unsigned int pclk)
405{
406 const struct tegra_hdmi_audio_config *table;
407
408 switch (audio_freq) {
409 case 32000:
410 table = tegra_hdmi_audio_32k;
411 break;
412
413 case 44100:
414 table = tegra_hdmi_audio_44_1k;
415 break;
416
417 case 48000:
418 table = tegra_hdmi_audio_48k;
419 break;
420
421 case 88200:
422 table = tegra_hdmi_audio_88_2k;
423 break;
424
425 case 96000:
426 table = tegra_hdmi_audio_96k;
427 break;
428
429 case 176400:
430 table = tegra_hdmi_audio_176_4k;
431 break;
432
433 case 192000:
434 table = tegra_hdmi_audio_192k;
435 break;
436
437 default:
438 return NULL;
439 }
440
441 while (table->pclk) {
442 if (table->pclk == pclk)
443 return table;
444
445 table++;
446 }
447
448 return NULL;
449}
450
451static void tegra_hdmi_setup_audio_fs_tables(struct tegra_hdmi *hdmi)
452{
453 const unsigned int freqs[] = {
454 32000, 44100, 48000, 88200, 96000, 176400, 192000
455 };
456 unsigned int i;
457
458 for (i = 0; i < ARRAY_SIZE(freqs); i++) {
459 unsigned int f = freqs[i];
460 unsigned int eight_half;
Thierry Redingedec4af2012-11-15 21:28:23 +0000461 unsigned int delta;
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100462 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000463
464 if (f > 96000)
465 delta = 2;
Thierry Reding17a8b6b2013-12-16 10:01:24 +0100466 else if (f > 48000)
Thierry Redingedec4af2012-11-15 21:28:23 +0000467 delta = 6;
468 else
469 delta = 9;
470
471 eight_half = (8 * HDMI_AUDIOCLK_FREQ) / (f * 128);
472 value = AUDIO_FS_LOW(eight_half - delta) |
473 AUDIO_FS_HIGH(eight_half + delta);
474 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_FS(i));
475 }
476}
477
478static int tegra_hdmi_setup_audio(struct tegra_hdmi *hdmi, unsigned int pclk)
479{
480 struct device_node *node = hdmi->dev->of_node;
481 const struct tegra_hdmi_audio_config *config;
482 unsigned int offset = 0;
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100483 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000484
485 switch (hdmi->audio_source) {
486 case HDA:
487 value = AUDIO_CNTRL0_SOURCE_SELECT_HDAL;
488 break;
489
490 case SPDIF:
491 value = AUDIO_CNTRL0_SOURCE_SELECT_SPDIF;
492 break;
493
494 default:
495 value = AUDIO_CNTRL0_SOURCE_SELECT_AUTO;
496 break;
497 }
498
499 if (of_device_is_compatible(node, "nvidia,tegra30-hdmi")) {
500 value |= AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
501 AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
502 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0);
503 } else {
504 value |= AUDIO_CNTRL0_INJECT_NULLSMPL;
505 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
506
507 value = AUDIO_CNTRL0_ERROR_TOLERANCE(6) |
508 AUDIO_CNTRL0_FRAMES_PER_BLOCK(0xc0);
509 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_CNTRL0);
510 }
511
512 config = tegra_hdmi_get_audio_config(hdmi->audio_freq, pclk);
513 if (!config) {
514 dev_err(hdmi->dev, "cannot set audio to %u at %u pclk\n",
515 hdmi->audio_freq, pclk);
516 return -EINVAL;
517 }
518
519 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_HDMI_ACR_CTRL);
520
521 value = AUDIO_N_RESETF | AUDIO_N_GENERATE_ALTERNATE |
522 AUDIO_N_VALUE(config->n - 1);
523 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N);
524
525 tegra_hdmi_writel(hdmi, ACR_SUBPACK_N(config->n) | ACR_ENABLE,
526 HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
527
528 value = ACR_SUBPACK_CTS(config->cts);
529 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
530
531 value = SPARE_HW_CTS | SPARE_FORCE_SW_CTS | SPARE_CTS_RESET_VAL(1);
532 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_SPARE);
533
534 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_AUDIO_N);
535 value &= ~AUDIO_N_RESETF;
536 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_AUDIO_N);
537
538 if (of_device_is_compatible(node, "nvidia,tegra30-hdmi")) {
539 switch (hdmi->audio_freq) {
540 case 32000:
541 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0320;
542 break;
543
544 case 44100:
545 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0441;
546 break;
547
548 case 48000:
549 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0480;
550 break;
551
552 case 88200:
553 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0882;
554 break;
555
556 case 96000:
557 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_0960;
558 break;
559
560 case 176400:
561 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_1764;
562 break;
563
564 case 192000:
565 offset = HDMI_NV_PDISP_SOR_AUDIO_AVAL_1920;
566 break;
567 }
568
569 tegra_hdmi_writel(hdmi, config->aval, offset);
570 }
571
572 tegra_hdmi_setup_audio_fs_tables(hdmi);
573
574 return 0;
575}
576
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100577static inline u32 tegra_hdmi_subpack(const u8 *ptr, size_t size)
Thierry Redingedec4af2012-11-15 21:28:23 +0000578{
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100579 u32 value = 0;
Thierry Redingedec4af2012-11-15 21:28:23 +0000580 size_t i;
Thierry Redingedec4af2012-11-15 21:28:23 +0000581
Thierry Redingac24c222012-11-23 15:14:00 +0100582 for (i = size; i > 0; i--)
583 value = (value << 8) | ptr[i - 1];
Thierry Redingedec4af2012-11-15 21:28:23 +0000584
Thierry Redingac24c222012-11-23 15:14:00 +0100585 return value;
586}
Thierry Redingedec4af2012-11-15 21:28:23 +0000587
Thierry Redingac24c222012-11-23 15:14:00 +0100588static void tegra_hdmi_write_infopack(struct tegra_hdmi *hdmi, const void *data,
589 size_t size)
590{
591 const u8 *ptr = data;
592 unsigned long offset;
Thierry Redingac24c222012-11-23 15:14:00 +0100593 size_t i, j;
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100594 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000595
Thierry Redingac24c222012-11-23 15:14:00 +0100596 switch (ptr[0]) {
597 case HDMI_INFOFRAME_TYPE_AVI:
598 offset = HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER;
599 break;
600
601 case HDMI_INFOFRAME_TYPE_AUDIO:
602 offset = HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER;
603 break;
604
605 case HDMI_INFOFRAME_TYPE_VENDOR:
606 offset = HDMI_NV_PDISP_HDMI_GENERIC_HEADER;
607 break;
608
609 default:
610 dev_err(hdmi->dev, "unsupported infoframe type: %02x\n",
611 ptr[0]);
612 return;
613 }
614
615 value = INFOFRAME_HEADER_TYPE(ptr[0]) |
616 INFOFRAME_HEADER_VERSION(ptr[1]) |
617 INFOFRAME_HEADER_LEN(ptr[2]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000618 tegra_hdmi_writel(hdmi, value, offset);
Thierry Redingac24c222012-11-23 15:14:00 +0100619 offset++;
Thierry Redingedec4af2012-11-15 21:28:23 +0000620
Thierry Redingac24c222012-11-23 15:14:00 +0100621 /*
622 * Each subpack contains 7 bytes, divided into:
623 * - subpack_low: bytes 0 - 3
624 * - subpack_high: bytes 4 - 6 (with byte 7 padded to 0x00)
Thierry Redingedec4af2012-11-15 21:28:23 +0000625 */
Thierry Redingac24c222012-11-23 15:14:00 +0100626 for (i = 3, j = 0; i < size; i += 7, j += 8) {
627 size_t rem = size - i, num = min_t(size_t, rem, 4);
Thierry Redingedec4af2012-11-15 21:28:23 +0000628
Thierry Redingac24c222012-11-23 15:14:00 +0100629 value = tegra_hdmi_subpack(&ptr[i], num);
630 tegra_hdmi_writel(hdmi, value, offset++);
Thierry Redingedec4af2012-11-15 21:28:23 +0000631
Thierry Redingac24c222012-11-23 15:14:00 +0100632 num = min_t(size_t, rem - num, 3);
Thierry Redingedec4af2012-11-15 21:28:23 +0000633
Thierry Redingac24c222012-11-23 15:14:00 +0100634 value = tegra_hdmi_subpack(&ptr[i + 4], num);
635 tegra_hdmi_writel(hdmi, value, offset++);
Thierry Redingedec4af2012-11-15 21:28:23 +0000636 }
637}
638
639static void tegra_hdmi_setup_avi_infoframe(struct tegra_hdmi *hdmi,
640 struct drm_display_mode *mode)
641{
642 struct hdmi_avi_infoframe frame;
Thierry Redingac24c222012-11-23 15:14:00 +0100643 u8 buffer[17];
644 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000645
646 if (hdmi->dvi) {
647 tegra_hdmi_writel(hdmi, 0,
648 HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
649 return;
650 }
651
Thierry Redingac24c222012-11-23 15:14:00 +0100652 err = drm_hdmi_avi_infoframe_from_display_mode(&frame, mode);
653 if (err < 0) {
654 dev_err(hdmi->dev, "failed to setup AVI infoframe: %zd\n", err);
655 return;
Thierry Redingedec4af2012-11-15 21:28:23 +0000656 }
657
Thierry Redingac24c222012-11-23 15:14:00 +0100658 err = hdmi_avi_infoframe_pack(&frame, buffer, sizeof(buffer));
659 if (err < 0) {
660 dev_err(hdmi->dev, "failed to pack AVI infoframe: %zd\n", err);
661 return;
662 }
663
664 tegra_hdmi_write_infopack(hdmi, buffer, err);
Thierry Redingedec4af2012-11-15 21:28:23 +0000665
666 tegra_hdmi_writel(hdmi, INFOFRAME_CTRL_ENABLE,
667 HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
668}
669
670static void tegra_hdmi_setup_audio_infoframe(struct tegra_hdmi *hdmi)
671{
672 struct hdmi_audio_infoframe frame;
Thierry Redingac24c222012-11-23 15:14:00 +0100673 u8 buffer[14];
674 ssize_t err;
Thierry Redingedec4af2012-11-15 21:28:23 +0000675
676 if (hdmi->dvi) {
677 tegra_hdmi_writel(hdmi, 0,
678 HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
679 return;
680 }
681
Thierry Redingac24c222012-11-23 15:14:00 +0100682 err = hdmi_audio_infoframe_init(&frame);
683 if (err < 0) {
Thierry Redingef284c72013-10-16 19:51:22 +0200684 dev_err(hdmi->dev, "failed to setup audio infoframe: %zd\n",
Thierry Redingac24c222012-11-23 15:14:00 +0100685 err);
686 return;
687 }
Thierry Redingedec4af2012-11-15 21:28:23 +0000688
Thierry Redingac24c222012-11-23 15:14:00 +0100689 frame.channels = 2;
690
691 err = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
692 if (err < 0) {
693 dev_err(hdmi->dev, "failed to pack audio infoframe: %zd\n",
694 err);
695 return;
696 }
697
698 /*
699 * The audio infoframe has only one set of subpack registers, so the
700 * infoframe needs to be truncated. One set of subpack registers can
701 * contain 7 bytes. Including the 3 byte header only the first 10
702 * bytes can be programmed.
703 */
Thierry Redingef284c72013-10-16 19:51:22 +0200704 tegra_hdmi_write_infopack(hdmi, buffer, min_t(size_t, 10, err));
Thierry Redingedec4af2012-11-15 21:28:23 +0000705
706 tegra_hdmi_writel(hdmi, INFOFRAME_CTRL_ENABLE,
707 HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
708}
709
710static void tegra_hdmi_setup_stereo_infoframe(struct tegra_hdmi *hdmi)
711{
Lespiau, Damienae84b902013-08-19 16:59:02 +0100712 struct hdmi_vendor_infoframe frame;
Thierry Redingac24c222012-11-23 15:14:00 +0100713 u8 buffer[10];
714 ssize_t err;
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100715 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000716
717 if (!hdmi->stereo) {
718 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
719 value &= ~GENERIC_CTRL_ENABLE;
720 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
721 return;
722 }
723
Lespiau, Damienae84b902013-08-19 16:59:02 +0100724 hdmi_vendor_infoframe_init(&frame);
Lespiau, Damiena26a58e82013-08-19 16:58:59 +0100725 frame.s3d_struct = HDMI_3D_STRUCTURE_FRAME_PACKING;
Thierry Redingac24c222012-11-23 15:14:00 +0100726
Lespiau, Damienae84b902013-08-19 16:59:02 +0100727 err = hdmi_vendor_infoframe_pack(&frame, buffer, sizeof(buffer));
Thierry Redingac24c222012-11-23 15:14:00 +0100728 if (err < 0) {
729 dev_err(hdmi->dev, "failed to pack vendor infoframe: %zd\n",
730 err);
731 return;
732 }
733
734 tegra_hdmi_write_infopack(hdmi, buffer, err);
Thierry Redingedec4af2012-11-15 21:28:23 +0000735
736 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
737 value |= GENERIC_CTRL_ENABLE;
738 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
739}
740
741static void tegra_hdmi_setup_tmds(struct tegra_hdmi *hdmi,
742 const struct tmds_config *tmds)
743{
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100744 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000745
746 tegra_hdmi_writel(hdmi, tmds->pll0, HDMI_NV_PDISP_SOR_PLL0);
747 tegra_hdmi_writel(hdmi, tmds->pll1, HDMI_NV_PDISP_SOR_PLL1);
748 tegra_hdmi_writel(hdmi, tmds->pe_current, HDMI_NV_PDISP_PE_CURRENT);
749
Thierry Reding59af0592013-10-14 09:43:05 +0200750 tegra_hdmi_writel(hdmi, tmds->drive_current,
751 HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
752
753 value = tegra_hdmi_readl(hdmi, hdmi->config->fuse_override_offset);
754 value |= hdmi->config->fuse_override_value;
755 tegra_hdmi_writel(hdmi, value, hdmi->config->fuse_override_offset);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +0200756
757 if (hdmi->config->has_sor_io_peak_current)
758 tegra_hdmi_writel(hdmi, tmds->peak_current,
759 HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +0000760}
761
Mikko Perttunen9f159122013-08-28 18:48:38 +0300762static bool tegra_output_is_hdmi(struct tegra_output *output)
763{
764 struct edid *edid;
765
766 if (!output->connector.edid_blob_ptr)
767 return false;
768
769 edid = (struct edid *)output->connector.edid_blob_ptr->data;
770
771 return drm_detect_hdmi_monitor(edid);
772}
773
Thierry Reding59682712014-11-28 16:50:59 +0100774static void tegra_hdmi_connector_dpms(struct drm_connector *connector,
775 int mode)
776{
777}
778
779static const struct drm_connector_funcs tegra_hdmi_connector_funcs = {
780 .dpms = tegra_hdmi_connector_dpms,
781 .detect = tegra_output_connector_detect,
782 .fill_modes = drm_helper_probe_single_connector_modes,
783 .destroy = tegra_output_connector_destroy,
784};
785
786static enum drm_mode_status
787tegra_hdmi_connector_mode_valid(struct drm_connector *connector,
788 struct drm_display_mode *mode)
789{
790 struct tegra_output *output = connector_to_output(connector);
791 struct tegra_hdmi *hdmi = to_hdmi(output);
792 unsigned long pclk = mode->clock * 1000;
793 enum drm_mode_status status = MODE_OK;
794 struct clk *parent;
795 long err;
796
797 parent = clk_get_parent(hdmi->clk_parent);
798
799 err = clk_round_rate(parent, pclk * 4);
800 if (err <= 0)
801 status = MODE_NOCLOCK;
802
803 return status;
804}
805
806static const struct drm_connector_helper_funcs
807tegra_hdmi_connector_helper_funcs = {
808 .get_modes = tegra_output_connector_get_modes,
809 .mode_valid = tegra_hdmi_connector_mode_valid,
810 .best_encoder = tegra_output_connector_best_encoder,
811};
812
813static const struct drm_encoder_funcs tegra_hdmi_encoder_funcs = {
814 .destroy = tegra_output_encoder_destroy,
815};
816
817static void tegra_hdmi_encoder_dpms(struct drm_encoder *encoder, int mode)
818{
819}
820
821static bool tegra_hdmi_encoder_mode_fixup(struct drm_encoder *encoder,
822 const struct drm_display_mode *mode,
823 struct drm_display_mode *adjusted)
824{
825 struct tegra_output *output = encoder_to_output(encoder);
826 struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
827 struct tegra_hdmi *hdmi = to_hdmi(output);
828 unsigned long pclk = mode->clock * 1000;
829 int err;
830
831 err = tegra_dc_setup_clock(dc, hdmi->clk_parent, pclk, 0);
832 if (err < 0) {
833 dev_err(output->dev, "failed to setup DC clock: %d\n", err);
834 return false;
835 }
836
837 err = clk_set_rate(hdmi->clk_parent, pclk);
838 if (err < 0) {
839 dev_err(output->dev, "failed to set clock rate to %lu Hz\n",
840 pclk);
841 return false;
842 }
843
844 return true;
845}
846
847static void tegra_hdmi_encoder_prepare(struct drm_encoder *encoder)
848{
849}
850
851static void tegra_hdmi_encoder_commit(struct drm_encoder *encoder)
852{
853}
854
855static void tegra_hdmi_encoder_mode_set(struct drm_encoder *encoder,
856 struct drm_display_mode *mode,
857 struct drm_display_mode *adjusted)
Thierry Redingedec4af2012-11-15 21:28:23 +0000858{
859 unsigned int h_sync_width, h_front_porch, h_back_porch, i, rekey;
Thierry Reding59682712014-11-28 16:50:59 +0100860 struct tegra_output *output = encoder_to_output(encoder);
861 struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
862 struct device_node *node = output->dev->of_node;
Thierry Redingedec4af2012-11-15 21:28:23 +0000863 struct tegra_hdmi *hdmi = to_hdmi(output);
Thierry Redingedec4af2012-11-15 21:28:23 +0000864 unsigned int pulse_start, div82, pclk;
Thierry Redingedec4af2012-11-15 21:28:23 +0000865 int retries = 1000;
Thierry Reding4ee8cee2014-12-08 16:25:14 +0100866 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +0000867 int err;
868
Mikko Perttunen9f159122013-08-28 18:48:38 +0300869 hdmi->dvi = !tegra_output_is_hdmi(output);
870
Thierry Redingedec4af2012-11-15 21:28:23 +0000871 pclk = mode->clock * 1000;
872 h_sync_width = mode->hsync_end - mode->hsync_start;
Lucas Stach40495082012-12-19 21:38:52 +0000873 h_back_porch = mode->htotal - mode->hsync_end;
874 h_front_porch = mode->hsync_start - mode->hdisplay;
Thierry Redingedec4af2012-11-15 21:28:23 +0000875
Thierry Reding8c8282c2014-04-16 10:46:24 +0200876 /* power up sequence */
877 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0);
878 value &= ~SOR_PLL_PDBG;
879 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0);
880
881 usleep_range(10, 20);
882
883 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PLL0);
884 value &= ~SOR_PLL_PWR;
885 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_PLL0);
886
Thierry Redingedec4af2012-11-15 21:28:23 +0000887 tegra_dc_writel(dc, VSYNC_H_POSITION(1),
888 DC_DISP_DISP_TIMING_OPTIONS);
889 tegra_dc_writel(dc, DITHER_CONTROL_DISABLE | BASE_COLOR_SIZE888,
890 DC_DISP_DISP_COLOR_CONTROL);
891
892 /* video_preamble uses h_pulse2 */
893 pulse_start = 1 + h_sync_width + h_back_porch - 10;
894
895 tegra_dc_writel(dc, H_PULSE_2_ENABLE, DC_DISP_DISP_SIGNAL_OPTIONS0);
896
897 value = PULSE_MODE_NORMAL | PULSE_POLARITY_HIGH | PULSE_QUAL_VACTIVE |
898 PULSE_LAST_END_A;
899 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_CONTROL);
900
901 value = PULSE_START(pulse_start) | PULSE_END(pulse_start + 8);
902 tegra_dc_writel(dc, value, DC_DISP_H_PULSE2_POSITION_A);
903
904 value = VSYNC_WINDOW_END(0x210) | VSYNC_WINDOW_START(0x200) |
905 VSYNC_WINDOW_ENABLE;
906 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
907
908 if (dc->pipe)
909 value = HDMI_SRC_DISPLAYB;
910 else
911 value = HDMI_SRC_DISPLAYA;
912
913 if ((mode->hdisplay == 720) && ((mode->vdisplay == 480) ||
914 (mode->vdisplay == 576)))
915 tegra_hdmi_writel(hdmi,
916 value | ARM_VIDEO_RANGE_FULL,
917 HDMI_NV_PDISP_INPUT_CONTROL);
918 else
919 tegra_hdmi_writel(hdmi,
920 value | ARM_VIDEO_RANGE_LIMITED,
921 HDMI_NV_PDISP_INPUT_CONTROL);
922
923 div82 = clk_get_rate(hdmi->clk) / 1000000 * 4;
924 value = SOR_REFCLK_DIV_INT(div82 >> 2) | SOR_REFCLK_DIV_FRAC(div82);
925 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_REFCLK);
926
927 if (!hdmi->dvi) {
928 err = tegra_hdmi_setup_audio(hdmi, pclk);
929 if (err < 0)
930 hdmi->dvi = true;
931 }
932
933 if (of_device_is_compatible(node, "nvidia,tegra20-hdmi")) {
934 /*
935 * TODO: add ELD support
936 */
937 }
938
939 rekey = HDMI_REKEY_DEFAULT;
940 value = HDMI_CTRL_REKEY(rekey);
941 value |= HDMI_CTRL_MAX_AC_PACKET((h_sync_width + h_back_porch +
942 h_front_porch - rekey - 18) / 32);
943
944 if (!hdmi->dvi)
945 value |= HDMI_CTRL_ENABLE;
946
947 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_HDMI_CTRL);
948
949 if (hdmi->dvi)
950 tegra_hdmi_writel(hdmi, 0x0,
951 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
952 else
953 tegra_hdmi_writel(hdmi, GENERIC_CTRL_AUDIO,
954 HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
955
956 tegra_hdmi_setup_avi_infoframe(hdmi, mode);
957 tegra_hdmi_setup_audio_infoframe(hdmi);
958 tegra_hdmi_setup_stereo_infoframe(hdmi);
959
960 /* TMDS CONFIG */
Thierry Reding59af0592013-10-14 09:43:05 +0200961 for (i = 0; i < hdmi->config->num_tmds; i++) {
962 if (pclk <= hdmi->config->tmds[i].pclk) {
963 tegra_hdmi_setup_tmds(hdmi, &hdmi->config->tmds[i]);
Thierry Redingedec4af2012-11-15 21:28:23 +0000964 break;
965 }
966 }
967
968 tegra_hdmi_writel(hdmi,
969 SOR_SEQ_CTL_PU_PC(0) |
970 SOR_SEQ_PU_PC_ALT(0) |
971 SOR_SEQ_PD_PC(8) |
972 SOR_SEQ_PD_PC_ALT(8),
973 HDMI_NV_PDISP_SOR_SEQ_CTL);
974
975 value = SOR_SEQ_INST_WAIT_TIME(1) |
976 SOR_SEQ_INST_WAIT_UNITS_VSYNC |
977 SOR_SEQ_INST_HALT |
978 SOR_SEQ_INST_PIN_A_LOW |
979 SOR_SEQ_INST_PIN_B_LOW |
980 SOR_SEQ_INST_DRIVE_PWM_OUT_LO;
981
982 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(0));
983 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_SEQ_INST(8));
984
Thierry Reding9cbfc732014-04-16 10:47:36 +0200985 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_CSTM);
Thierry Redingedec4af2012-11-15 21:28:23 +0000986 value &= ~SOR_CSTM_ROTCLK(~0);
987 value |= SOR_CSTM_ROTCLK(2);
Thierry Reding9cbfc732014-04-16 10:47:36 +0200988 value |= SOR_CSTM_PLLDIV;
989 value &= ~SOR_CSTM_LVDS_ENABLE;
990 value &= ~SOR_CSTM_MODE_MASK;
991 value |= SOR_CSTM_MODE_TMDS;
Thierry Redingedec4af2012-11-15 21:28:23 +0000992 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_CSTM);
993
Thierry Redingedec4af2012-11-15 21:28:23 +0000994 /* start SOR */
995 tegra_hdmi_writel(hdmi,
996 SOR_PWR_NORMAL_STATE_PU |
997 SOR_PWR_NORMAL_START_NORMAL |
998 SOR_PWR_SAFE_STATE_PD |
999 SOR_PWR_SETTING_NEW_TRIGGER,
1000 HDMI_NV_PDISP_SOR_PWR);
1001 tegra_hdmi_writel(hdmi,
1002 SOR_PWR_NORMAL_STATE_PU |
1003 SOR_PWR_NORMAL_START_NORMAL |
1004 SOR_PWR_SAFE_STATE_PD |
1005 SOR_PWR_SETTING_NEW_DONE,
1006 HDMI_NV_PDISP_SOR_PWR);
1007
1008 do {
1009 BUG_ON(--retries < 0);
1010 value = tegra_hdmi_readl(hdmi, HDMI_NV_PDISP_SOR_PWR);
1011 } while (value & SOR_PWR_SETTING_NEW_PENDING);
1012
1013 value = SOR_STATE_ASY_CRCMODE_COMPLETE |
1014 SOR_STATE_ASY_OWNER_HEAD0 |
1015 SOR_STATE_ASY_SUBOWNER_BOTH |
1016 SOR_STATE_ASY_PROTOCOL_SINGLE_TMDS_A |
1017 SOR_STATE_ASY_DEPOL_POS;
1018
1019 /* setup sync polarities */
1020 if (mode->flags & DRM_MODE_FLAG_PHSYNC)
1021 value |= SOR_STATE_ASY_HSYNCPOL_POS;
1022
1023 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1024 value |= SOR_STATE_ASY_HSYNCPOL_NEG;
1025
1026 if (mode->flags & DRM_MODE_FLAG_PVSYNC)
1027 value |= SOR_STATE_ASY_VSYNCPOL_POS;
1028
1029 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1030 value |= SOR_STATE_ASY_VSYNCPOL_NEG;
1031
1032 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE2);
1033
1034 value = SOR_STATE_ASY_HEAD_OPMODE_AWAKE | SOR_STATE_ASY_ORMODE_NORMAL;
1035 tegra_hdmi_writel(hdmi, value, HDMI_NV_PDISP_SOR_STATE1);
1036
1037 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
1038 tegra_hdmi_writel(hdmi, SOR_STATE_UPDATE, HDMI_NV_PDISP_SOR_STATE0);
1039 tegra_hdmi_writel(hdmi, value | SOR_STATE_ATTACHED,
1040 HDMI_NV_PDISP_SOR_STATE1);
1041 tegra_hdmi_writel(hdmi, 0, HDMI_NV_PDISP_SOR_STATE0);
1042
Thierry Reding72d30282013-12-12 11:06:55 +01001043 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
1044 value |= HDMI_ENABLE;
1045 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
Thierry Redingedec4af2012-11-15 21:28:23 +00001046
Thierry Reding72d30282013-12-12 11:06:55 +01001047 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_COMMAND);
1048 value &= ~DISP_CTRL_MODE_MASK;
1049 value |= DISP_CTRL_MODE_C_DISPLAY;
Thierry Redingedec4af2012-11-15 21:28:23 +00001050 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_COMMAND);
1051
Thierry Reding72d30282013-12-12 11:06:55 +01001052 value = tegra_dc_readl(dc, DC_CMD_DISPLAY_POWER_CONTROL);
1053 value |= PW0_ENABLE | PW1_ENABLE | PW2_ENABLE | PW3_ENABLE |
1054 PW4_ENABLE | PM0_ENABLE | PM1_ENABLE;
1055 tegra_dc_writel(dc, value, DC_CMD_DISPLAY_POWER_CONTROL);
1056
Thierry Reding62b9e062014-11-21 17:33:33 +01001057 tegra_dc_commit(dc);
Thierry Redingedec4af2012-11-15 21:28:23 +00001058
1059 /* TODO: add HDCP support */
Thierry Redingedec4af2012-11-15 21:28:23 +00001060}
1061
Thierry Reding59682712014-11-28 16:50:59 +01001062static void tegra_hdmi_encoder_disable(struct drm_encoder *encoder)
Thierry Redingedec4af2012-11-15 21:28:23 +00001063{
Thierry Reding59682712014-11-28 16:50:59 +01001064 struct tegra_dc *dc = to_tegra_dc(encoder->crtc);
Thierry Reding4ee8cee2014-12-08 16:25:14 +01001065 u32 value;
Thierry Redingedec4af2012-11-15 21:28:23 +00001066
Thierry Reding72d30282013-12-12 11:06:55 +01001067 /*
1068 * The following accesses registers of the display controller, so make
1069 * sure it's only executed when the output is attached to one.
1070 */
1071 if (dc) {
Thierry Reding72d30282013-12-12 11:06:55 +01001072 value = tegra_dc_readl(dc, DC_DISP_DISP_WIN_OPTIONS);
1073 value &= ~HDMI_ENABLE;
1074 tegra_dc_writel(dc, value, DC_DISP_DISP_WIN_OPTIONS);
1075
Thierry Reding62b9e062014-11-21 17:33:33 +01001076 tegra_dc_commit(dc);
Thierry Reding72d30282013-12-12 11:06:55 +01001077 }
Thierry Redingedec4af2012-11-15 21:28:23 +00001078}
1079
Thierry Reding59682712014-11-28 16:50:59 +01001080static const struct drm_encoder_helper_funcs tegra_hdmi_encoder_helper_funcs = {
1081 .dpms = tegra_hdmi_encoder_dpms,
1082 .mode_fixup = tegra_hdmi_encoder_mode_fixup,
1083 .prepare = tegra_hdmi_encoder_prepare,
1084 .commit = tegra_hdmi_encoder_commit,
1085 .mode_set = tegra_hdmi_encoder_mode_set,
1086 .disable = tegra_hdmi_encoder_disable,
Thierry Redingedec4af2012-11-15 21:28:23 +00001087};
1088
1089static int tegra_hdmi_show_regs(struct seq_file *s, void *data)
1090{
1091 struct drm_info_node *node = s->private;
1092 struct tegra_hdmi *hdmi = node->info_ent->data;
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001093 int err;
1094
Thierry Redingd06e7f8f62014-04-16 10:43:41 +02001095 err = clk_prepare_enable(hdmi->clk);
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001096 if (err)
1097 return err;
Thierry Redingedec4af2012-11-15 21:28:23 +00001098
1099#define DUMP_REG(name) \
Thierry Reding4ee8cee2014-12-08 16:25:14 +01001100 seq_printf(s, "%-56s %#05x %08x\n", #name, name, \
1101 tegra_hdmi_readl(hdmi, name))
Thierry Redingedec4af2012-11-15 21:28:23 +00001102
1103 DUMP_REG(HDMI_CTXSW);
1104 DUMP_REG(HDMI_NV_PDISP_SOR_STATE0);
1105 DUMP_REG(HDMI_NV_PDISP_SOR_STATE1);
1106 DUMP_REG(HDMI_NV_PDISP_SOR_STATE2);
1107 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_MSB);
1108 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AN_LSB);
1109 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_MSB);
1110 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CN_LSB);
1111 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_MSB);
1112 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_AKSV_LSB);
1113 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_MSB);
1114 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_BKSV_LSB);
1115 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_MSB);
1116 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CKSV_LSB);
1117 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_MSB);
1118 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_DKSV_LSB);
1119 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CTRL);
1120 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CMODE);
1121 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_MSB);
1122 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_MPRIME_LSB);
1123 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_MSB);
1124 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB2);
1125 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_SPRIME_LSB1);
1126 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_RI);
1127 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_MSB);
1128 DUMP_REG(HDMI_NV_PDISP_RG_HDCP_CS_LSB);
1129 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU0);
1130 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU_RDATA0);
1131 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU1);
1132 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_EMU2);
1133 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_CTRL);
1134 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_STATUS);
1135 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_HEADER);
1136 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_LOW);
1137 DUMP_REG(HDMI_NV_PDISP_HDMI_AUDIO_INFOFRAME_SUBPACK0_HIGH);
1138 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_CTRL);
1139 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_STATUS);
1140 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_HEADER);
1141 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_LOW);
1142 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK0_HIGH);
1143 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_LOW);
1144 DUMP_REG(HDMI_NV_PDISP_HDMI_AVI_INFOFRAME_SUBPACK1_HIGH);
1145 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_CTRL);
1146 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_STATUS);
1147 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_HEADER);
1148 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_LOW);
1149 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK0_HIGH);
1150 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_LOW);
1151 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK1_HIGH);
1152 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_LOW);
1153 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK2_HIGH);
1154 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_LOW);
1155 DUMP_REG(HDMI_NV_PDISP_HDMI_GENERIC_SUBPACK3_HIGH);
1156 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_CTRL);
1157 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_LOW);
1158 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0320_SUBPACK_HIGH);
1159 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_LOW);
1160 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0441_SUBPACK_HIGH);
1161 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_LOW);
1162 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0882_SUBPACK_HIGH);
1163 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_LOW);
1164 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1764_SUBPACK_HIGH);
1165 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_LOW);
1166 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0480_SUBPACK_HIGH);
1167 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_LOW);
1168 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_0960_SUBPACK_HIGH);
1169 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_LOW);
1170 DUMP_REG(HDMI_NV_PDISP_HDMI_ACR_1920_SUBPACK_HIGH);
1171 DUMP_REG(HDMI_NV_PDISP_HDMI_CTRL);
1172 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_KEEPOUT);
1173 DUMP_REG(HDMI_NV_PDISP_HDMI_VSYNC_WINDOW);
1174 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_CTRL);
1175 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_STATUS);
1176 DUMP_REG(HDMI_NV_PDISP_HDMI_GCP_SUBPACK);
1177 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS1);
1178 DUMP_REG(HDMI_NV_PDISP_HDMI_CHANNEL_STATUS2);
1179 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU0);
1180 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1);
1181 DUMP_REG(HDMI_NV_PDISP_HDMI_EMU1_RDATA);
1182 DUMP_REG(HDMI_NV_PDISP_HDMI_SPARE);
1183 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS1);
1184 DUMP_REG(HDMI_NV_PDISP_HDMI_SPDIF_CHN_STATUS2);
1185 DUMP_REG(HDMI_NV_PDISP_HDMI_HDCPRIF_ROM_CTRL);
1186 DUMP_REG(HDMI_NV_PDISP_SOR_CAP);
1187 DUMP_REG(HDMI_NV_PDISP_SOR_PWR);
1188 DUMP_REG(HDMI_NV_PDISP_SOR_TEST);
1189 DUMP_REG(HDMI_NV_PDISP_SOR_PLL0);
1190 DUMP_REG(HDMI_NV_PDISP_SOR_PLL1);
1191 DUMP_REG(HDMI_NV_PDISP_SOR_PLL2);
1192 DUMP_REG(HDMI_NV_PDISP_SOR_CSTM);
1193 DUMP_REG(HDMI_NV_PDISP_SOR_LVDS);
1194 DUMP_REG(HDMI_NV_PDISP_SOR_CRCA);
1195 DUMP_REG(HDMI_NV_PDISP_SOR_CRCB);
1196 DUMP_REG(HDMI_NV_PDISP_SOR_BLANK);
1197 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_CTL);
1198 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(0));
1199 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(1));
1200 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(2));
1201 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(3));
1202 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(4));
1203 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(5));
1204 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(6));
1205 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(7));
1206 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(8));
1207 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(9));
1208 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(10));
1209 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(11));
1210 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(12));
1211 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(13));
1212 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(14));
1213 DUMP_REG(HDMI_NV_PDISP_SOR_SEQ_INST(15));
1214 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA0);
1215 DUMP_REG(HDMI_NV_PDISP_SOR_VCRCA1);
1216 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA0);
1217 DUMP_REG(HDMI_NV_PDISP_SOR_CCRCA1);
1218 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA0);
1219 DUMP_REG(HDMI_NV_PDISP_SOR_EDATAA1);
1220 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA0);
1221 DUMP_REG(HDMI_NV_PDISP_SOR_COUNTA1);
1222 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA0);
1223 DUMP_REG(HDMI_NV_PDISP_SOR_DEBUGA1);
1224 DUMP_REG(HDMI_NV_PDISP_SOR_TRIG);
1225 DUMP_REG(HDMI_NV_PDISP_SOR_MSCHECK);
1226 DUMP_REG(HDMI_NV_PDISP_SOR_LANE_DRIVE_CURRENT);
1227 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG0);
1228 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG1);
1229 DUMP_REG(HDMI_NV_PDISP_AUDIO_DEBUG2);
1230 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(0));
1231 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(1));
1232 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(2));
1233 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(3));
1234 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(4));
1235 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(5));
1236 DUMP_REG(HDMI_NV_PDISP_AUDIO_FS(6));
1237 DUMP_REG(HDMI_NV_PDISP_AUDIO_PULSE_WIDTH);
1238 DUMP_REG(HDMI_NV_PDISP_AUDIO_THRESHOLD);
1239 DUMP_REG(HDMI_NV_PDISP_AUDIO_CNTRL0);
1240 DUMP_REG(HDMI_NV_PDISP_AUDIO_N);
1241 DUMP_REG(HDMI_NV_PDISP_HDCPRIF_ROM_TIMING);
1242 DUMP_REG(HDMI_NV_PDISP_SOR_REFCLK);
1243 DUMP_REG(HDMI_NV_PDISP_CRC_CONTROL);
1244 DUMP_REG(HDMI_NV_PDISP_INPUT_CONTROL);
1245 DUMP_REG(HDMI_NV_PDISP_SCRATCH);
1246 DUMP_REG(HDMI_NV_PDISP_PE_CURRENT);
1247 DUMP_REG(HDMI_NV_PDISP_KEY_CTRL);
1248 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG0);
1249 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG1);
1250 DUMP_REG(HDMI_NV_PDISP_KEY_DEBUG2);
1251 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_0);
1252 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_1);
1253 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_2);
1254 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_3);
1255 DUMP_REG(HDMI_NV_PDISP_KEY_HDCP_KEY_TRIG);
1256 DUMP_REG(HDMI_NV_PDISP_KEY_SKEY_INDEX);
1257 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_CNTRL0);
1258 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_ELD_BUFWR);
1259 DUMP_REG(HDMI_NV_PDISP_SOR_AUDIO_HDA_PRESENSE);
Mikko Perttunen7d1d28a2013-09-30 16:54:47 +02001260 DUMP_REG(HDMI_NV_PDISP_SOR_IO_PEAK_CURRENT);
Thierry Redingedec4af2012-11-15 21:28:23 +00001261
1262#undef DUMP_REG
1263
Thierry Redingd06e7f8f62014-04-16 10:43:41 +02001264 clk_disable_unprepare(hdmi->clk);
Mikko Perttunenccaddfe2013-07-30 11:35:03 +03001265
Thierry Redingedec4af2012-11-15 21:28:23 +00001266 return 0;
1267}
1268
1269static struct drm_info_list debugfs_files[] = {
1270 { "regs", tegra_hdmi_show_regs, 0, NULL },
1271};
1272
1273static int tegra_hdmi_debugfs_init(struct tegra_hdmi *hdmi,
1274 struct drm_minor *minor)
1275{
1276 unsigned int i;
1277 int err;
1278
1279 hdmi->debugfs = debugfs_create_dir("hdmi", minor->debugfs_root);
1280 if (!hdmi->debugfs)
1281 return -ENOMEM;
1282
1283 hdmi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files),
1284 GFP_KERNEL);
1285 if (!hdmi->debugfs_files) {
1286 err = -ENOMEM;
1287 goto remove;
1288 }
1289
1290 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
1291 hdmi->debugfs_files[i].data = hdmi;
1292
1293 err = drm_debugfs_create_files(hdmi->debugfs_files,
1294 ARRAY_SIZE(debugfs_files),
1295 hdmi->debugfs, minor);
1296 if (err < 0)
1297 goto free;
1298
1299 hdmi->minor = minor;
1300
1301 return 0;
1302
1303free:
1304 kfree(hdmi->debugfs_files);
1305 hdmi->debugfs_files = NULL;
1306remove:
1307 debugfs_remove(hdmi->debugfs);
1308 hdmi->debugfs = NULL;
1309
1310 return err;
1311}
1312
1313static int tegra_hdmi_debugfs_exit(struct tegra_hdmi *hdmi)
1314{
1315 drm_debugfs_remove_files(hdmi->debugfs_files, ARRAY_SIZE(debugfs_files),
1316 hdmi->minor);
1317 hdmi->minor = NULL;
1318
1319 kfree(hdmi->debugfs_files);
1320 hdmi->debugfs_files = NULL;
1321
1322 debugfs_remove(hdmi->debugfs);
1323 hdmi->debugfs = NULL;
1324
1325 return 0;
1326}
1327
Thierry Reding53fa7f72013-09-24 15:35:40 +02001328static int tegra_hdmi_init(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001329{
Thierry Reding9910f5c2014-05-22 09:57:15 +02001330 struct drm_device *drm = dev_get_drvdata(client->parent);
Thierry Reding776dc382013-10-14 14:43:22 +02001331 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001332 int err;
1333
Thierry Redingedec4af2012-11-15 21:28:23 +00001334 hdmi->output.dev = client->dev;
Thierry Redingedec4af2012-11-15 21:28:23 +00001335
Thierry Reding59682712014-11-28 16:50:59 +01001336 drm_connector_init(drm, &hdmi->output.connector,
1337 &tegra_hdmi_connector_funcs,
1338 DRM_MODE_CONNECTOR_HDMIA);
1339 drm_connector_helper_add(&hdmi->output.connector,
1340 &tegra_hdmi_connector_helper_funcs);
1341 hdmi->output.connector.dpms = DRM_MODE_DPMS_OFF;
1342
1343 drm_encoder_init(drm, &hdmi->output.encoder, &tegra_hdmi_encoder_funcs,
1344 DRM_MODE_ENCODER_TMDS);
1345 drm_encoder_helper_add(&hdmi->output.encoder,
1346 &tegra_hdmi_encoder_helper_funcs);
1347
1348 drm_mode_connector_attach_encoder(&hdmi->output.connector,
1349 &hdmi->output.encoder);
1350 drm_connector_register(&hdmi->output.connector);
1351
1352 hdmi->output.encoder.possible_crtcs = 0x3;
1353
1354 if (gpio_is_valid(hdmi->output.hpd_gpio))
1355 enable_irq(hdmi->output.hpd_irq);
Thierry Redingedec4af2012-11-15 21:28:23 +00001356
1357 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
Thierry Reding9910f5c2014-05-22 09:57:15 +02001358 err = tegra_hdmi_debugfs_init(hdmi, drm->primary);
Thierry Redingedec4af2012-11-15 21:28:23 +00001359 if (err < 0)
1360 dev_err(client->dev, "debugfs setup failed: %d\n", err);
1361 }
1362
Thierry Redingfb50a112014-02-28 16:57:34 +01001363 err = regulator_enable(hdmi->hdmi);
1364 if (err < 0) {
1365 dev_err(client->dev, "failed to enable HDMI regulator: %d\n",
1366 err);
1367 return err;
1368 }
1369
Thierry Reding59682712014-11-28 16:50:59 +01001370 err = regulator_enable(hdmi->pll);
1371 if (err < 0) {
1372 dev_err(hdmi->dev, "failed to enable PLL regulator: %d\n", err);
1373 return err;
1374 }
1375
1376 err = regulator_enable(hdmi->vdd);
1377 if (err < 0) {
1378 dev_err(hdmi->dev, "failed to enable VDD regulator: %d\n", err);
1379 return err;
1380 }
1381
1382 err = clk_prepare_enable(hdmi->clk);
1383 if (err < 0) {
1384 dev_err(hdmi->dev, "failed to enable clock: %d\n", err);
1385 return err;
1386 }
1387
1388 reset_control_deassert(hdmi->rst);
1389
Thierry Redingedec4af2012-11-15 21:28:23 +00001390 return 0;
1391}
1392
Thierry Reding53fa7f72013-09-24 15:35:40 +02001393static int tegra_hdmi_exit(struct host1x_client *client)
Thierry Redingedec4af2012-11-15 21:28:23 +00001394{
Thierry Reding776dc382013-10-14 14:43:22 +02001395 struct tegra_hdmi *hdmi = host1x_client_to_hdmi(client);
Thierry Redingedec4af2012-11-15 21:28:23 +00001396 int err;
1397
Thierry Reding59682712014-11-28 16:50:59 +01001398 tegra_output_exit(&hdmi->output);
1399
1400 clk_disable_unprepare(hdmi->clk);
1401 reset_control_assert(hdmi->rst);
1402
1403 regulator_disable(hdmi->vdd);
1404 regulator_disable(hdmi->pll);
Thierry Redingfb50a112014-02-28 16:57:34 +01001405 regulator_disable(hdmi->hdmi);
1406
Thierry Redingedec4af2012-11-15 21:28:23 +00001407 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
1408 err = tegra_hdmi_debugfs_exit(hdmi);
1409 if (err < 0)
1410 dev_err(client->dev, "debugfs cleanup failed: %d\n",
1411 err);
1412 }
1413
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 Reding59d29c02013-10-14 14:26:42 +02001570 err = tegra_output_remove(&hdmi->output);
1571 if (err < 0) {
1572 dev_err(&pdev->dev, "failed to remove output: %d\n", err);
1573 return err;
1574 }
1575
Thierry Redingd06e7f8f62014-04-16 10:43:41 +02001576 clk_disable_unprepare(hdmi->clk_parent);
1577 clk_disable_unprepare(hdmi->clk);
Thierry Redingedec4af2012-11-15 21:28:23 +00001578
1579 return 0;
1580}
1581
Thierry Redingedec4af2012-11-15 21:28:23 +00001582struct platform_driver tegra_hdmi_driver = {
1583 .driver = {
1584 .name = "tegra-hdmi",
1585 .owner = THIS_MODULE,
1586 .of_match_table = tegra_hdmi_of_match,
1587 },
1588 .probe = tegra_hdmi_probe,
1589 .remove = tegra_hdmi_remove,
1590};